Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * OnKey device driver for DA9063, DA9062 and DA9061 PMICs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2015  Dialog Semiconductor Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mfd/da9063/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/mfd/da9063/registers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/mfd/da9062/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mfd/da9062/registers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) struct da906x_chip_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	/* REGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	int onkey_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	int onkey_pwr_signalling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	int onkey_fault_log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int onkey_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	/* MASKS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	int onkey_nonkey_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	int onkey_nonkey_lock_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	int onkey_key_reset_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	int onkey_shutdown_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	/* NAMES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) struct da9063_onkey {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct delayed_work work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	const struct da906x_chip_config *config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	bool key_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static const struct da906x_chip_config da9063_regs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	/* REGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	.onkey_status = DA9063_REG_STATUS_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.onkey_pwr_signalling = DA9063_REG_CONTROL_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.onkey_fault_log = DA9063_REG_FAULT_LOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.onkey_shutdown = DA9063_REG_CONTROL_F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	/* MASKS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.onkey_nonkey_mask = DA9063_NONKEY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.onkey_nonkey_lock_mask = DA9063_NONKEY_LOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.onkey_key_reset_mask = DA9063_KEY_RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.onkey_shutdown_mask = DA9063_SHUTDOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/* NAMES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.name = DA9063_DRVNAME_ONKEY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static const struct da906x_chip_config da9062_regs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	/* REGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	.onkey_status = DA9062AA_STATUS_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	.onkey_pwr_signalling = DA9062AA_CONTROL_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	.onkey_fault_log = DA9062AA_FAULT_LOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	.onkey_shutdown = DA9062AA_CONTROL_F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/* MASKS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	.onkey_nonkey_mask = DA9062AA_NONKEY_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	.onkey_nonkey_lock_mask = DA9062AA_NONKEY_LOCK_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	.onkey_key_reset_mask = DA9062AA_KEY_RESET_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	.onkey_shutdown_mask = DA9062AA_SHUTDOWN_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	/* NAMES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	.name = "da9062-onkey",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static const struct of_device_id da9063_compatible_reg_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	{ .compatible = "dlg,da9063-onkey", .data = &da9063_regs },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	{ .compatible = "dlg,da9062-onkey", .data = &da9062_regs },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) MODULE_DEVICE_TABLE(of, da9063_compatible_reg_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static void da9063_poll_on(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct da9063_onkey *onkey = container_of(work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 						struct da9063_onkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 						work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	const struct da906x_chip_config *config = onkey->config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int fault_log = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	bool poll = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	/* Poll to see when the pin is released */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	error = regmap_read(onkey->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			    config->onkey_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			    &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		dev_err(onkey->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			"Failed to read ON status: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		goto err_poll;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (!(val & config->onkey_nonkey_mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		error = regmap_update_bits(onkey->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 					   config->onkey_pwr_signalling,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 					   config->onkey_nonkey_lock_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 					   0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			dev_err(onkey->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 				"Failed to reset the Key Delay %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			goto err_poll;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		input_report_key(onkey->input, KEY_POWER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		input_sync(onkey->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		poll = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 * If the fault log KEY_RESET is detected, then clear it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 * and shut down the system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	error = regmap_read(onkey->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			    config->onkey_fault_log,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			    &fault_log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		dev_warn(&onkey->input->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			 "Cannot read FAULT_LOG: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	} else if (fault_log & config->onkey_key_reset_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		error = regmap_write(onkey->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 				     config->onkey_fault_log,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 				     config->onkey_key_reset_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			dev_warn(&onkey->input->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 				 "Cannot reset KEY_RESET fault log: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 				 error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			/* at this point we do any S/W housekeeping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			 * and then send shutdown command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			dev_dbg(&onkey->input->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 				"Sending SHUTDOWN to PMIC ...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			error = regmap_write(onkey->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 					     config->onkey_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 					     config->onkey_shutdown_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 				dev_err(&onkey->input->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 					"Cannot SHUTDOWN PMIC: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 					error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) err_poll:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (poll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		schedule_delayed_work(&onkey->work, msecs_to_jiffies(50));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static irqreturn_t da9063_onkey_irq_handler(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct da9063_onkey *onkey = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	const struct da906x_chip_config *config = onkey->config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	error = regmap_read(onkey->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			    config->onkey_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			    &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (onkey->key_power && !error && (val & config->onkey_nonkey_mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		input_report_key(onkey->input, KEY_POWER, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		input_sync(onkey->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		schedule_delayed_work(&onkey->work, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		dev_dbg(onkey->dev, "KEY_POWER long press.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		input_report_key(onkey->input, KEY_POWER, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		input_sync(onkey->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		input_report_key(onkey->input, KEY_POWER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		input_sync(onkey->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		dev_dbg(onkey->dev, "KEY_POWER short press.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static void da9063_cancel_poll(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct da9063_onkey *onkey = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	cancel_delayed_work_sync(&onkey->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static int da9063_onkey_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	struct da9063_onkey *onkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	const struct of_device_id *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	match = of_match_node(da9063_compatible_reg_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			      pdev->dev.of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (!match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	onkey = devm_kzalloc(&pdev->dev, sizeof(struct da9063_onkey),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			     GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (!onkey) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		dev_err(&pdev->dev, "Failed to allocate memory.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	onkey->config = match->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	onkey->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	onkey->regmap = dev_get_regmap(pdev->dev.parent, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (!onkey->regmap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		dev_err(&pdev->dev, "Parent regmap unavailable.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	onkey->key_power = !of_property_read_bool(pdev->dev.of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 						  "dlg,disable-key-power");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	onkey->input = devm_input_allocate_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	if (!onkey->input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		dev_err(&pdev->dev, "Failed to allocated input device.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	onkey->input->name = onkey->config->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	snprintf(onkey->phys, sizeof(onkey->phys), "%s/input0",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		 onkey->config->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	onkey->input->phys = onkey->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	onkey->input->dev.parent = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	input_set_capability(onkey->input, EV_KEY, KEY_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	INIT_DELAYED_WORK(&onkey->work, da9063_poll_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	error = devm_add_action(&pdev->dev, da9063_cancel_poll, onkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			"Failed to add cancel poll action: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	irq = platform_get_irq_byname(pdev, "ONKEY");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	error = devm_request_threaded_irq(&pdev->dev, irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 					  NULL, da9063_onkey_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 					  IRQF_TRIGGER_LOW | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 					  "ONKEY", onkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			"Failed to request IRQ %d: %d\n", irq, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	error = input_register_device(onkey->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			"Failed to register input device: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static struct platform_driver da9063_onkey_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	.probe	= da9063_onkey_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		.name	= DA9063_DRVNAME_ONKEY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		.of_match_table = da9063_compatible_reg_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) module_platform_driver(da9063_onkey_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) MODULE_AUTHOR("S Twiss <stwiss.opensource@diasemi.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) MODULE_DESCRIPTION("Onkey device driver for Dialog DA9063, DA9062 and DA9061");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) MODULE_ALIAS("platform:" DA9063_DRVNAME_ONKEY);