diff options
Diffstat (limited to 'drivers/input/keyboard/adp5589-keys.c')
-rw-r--r-- | drivers/input/keyboard/adp5589-keys.c | 216 |
1 files changed, 71 insertions, 145 deletions
diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c index eb0e9cd66bcb..654e0476406b 100644 --- a/drivers/input/keyboard/adp5589-keys.c +++ b/drivers/input/keyboard/adp5589-keys.c @@ -7,12 +7,14 @@ * Copyright (C) 2010-2011 Analog Devices Inc. */ +#include <linux/bitops.h> #include <linux/module.h> #include <linux/interrupt.h> #include <linux/irq.h> #include <linux/workqueue.h> #include <linux/errno.h> #include <linux/pm.h> +#include <linux/pm_wakeirq.h> #include <linux/platform_device.h> #include <linux/input.h> #include <linux/i2c.h> @@ -153,48 +155,48 @@ #define ADP5589_5_MAN_ID 0x02 /* GENERAL_CFG Register */ -#define OSC_EN (1 << 7) +#define OSC_EN BIT(7) #define CORE_CLK(x) (((x) & 0x3) << 5) -#define LCK_TRK_LOGIC (1 << 4) /* ADP5589 only */ -#define LCK_TRK_GPI (1 << 3) /* ADP5589 only */ -#define INT_CFG (1 << 1) -#define RST_CFG (1 << 0) +#define LCK_TRK_LOGIC BIT(4) /* ADP5589 only */ +#define LCK_TRK_GPI BIT(3) /* ADP5589 only */ +#define INT_CFG BIT(1) +#define RST_CFG BIT(0) /* INT_EN Register */ -#define LOGIC2_IEN (1 << 5) /* ADP5589 only */ -#define LOGIC1_IEN (1 << 4) -#define LOCK_IEN (1 << 3) /* ADP5589 only */ -#define OVRFLOW_IEN (1 << 2) -#define GPI_IEN (1 << 1) -#define EVENT_IEN (1 << 0) +#define LOGIC2_IEN BIT(5) /* ADP5589 only */ +#define LOGIC1_IEN BIT(4) +#define LOCK_IEN BIT(3) /* ADP5589 only */ +#define OVRFLOW_IEN BIT(2) +#define GPI_IEN BIT(1) +#define EVENT_IEN BIT(0) /* Interrupt Status Register */ -#define LOGIC2_INT (1 << 5) /* ADP5589 only */ -#define LOGIC1_INT (1 << 4) -#define LOCK_INT (1 << 3) /* ADP5589 only */ -#define OVRFLOW_INT (1 << 2) -#define GPI_INT (1 << 1) -#define EVENT_INT (1 << 0) +#define LOGIC2_INT BIT(5) /* ADP5589 only */ +#define LOGIC1_INT BIT(4) +#define LOCK_INT BIT(3) /* ADP5589 only */ +#define OVRFLOW_INT BIT(2) +#define GPI_INT BIT(1) +#define EVENT_INT BIT(0) /* STATUS Register */ -#define LOGIC2_STAT (1 << 7) /* ADP5589 only */ -#define LOGIC1_STAT (1 << 6) -#define LOCK_STAT (1 << 5) /* ADP5589 only */ +#define LOGIC2_STAT BIT(7) /* ADP5589 only */ +#define LOGIC1_STAT BIT(6) +#define LOCK_STAT BIT(5) /* ADP5589 only */ #define KEC 0x1F /* PIN_CONFIG_D Register */ -#define C4_EXTEND_CFG (1 << 6) /* RESET2 */ -#define R4_EXTEND_CFG (1 << 5) /* RESET1 */ +#define C4_EXTEND_CFG BIT(6) /* RESET2 */ +#define R4_EXTEND_CFG BIT(5) /* RESET1 */ /* LOCK_CFG */ -#define LOCK_EN (1 << 0) +#define LOCK_EN BIT(0) #define PTIME_MASK 0x3 #define LTIME_MASK 0x3 /* ADP5589 only */ /* Key Event Register xy */ -#define KEY_EV_PRESSED (1 << 7) -#define KEY_EV_MASK (0x7F) +#define KEY_EV_PRESSED BIT(7) +#define KEY_EV_MASK 0x7F #define KEYP_MAX_EVENT 16 #define ADP5589_MAXGPIO 19 @@ -238,7 +240,6 @@ struct adp5589_kpad { bool support_row5; #ifdef CONFIG_GPIOLIB unsigned char gpiomap[ADP5589_MAXGPIO]; - bool export_gpio; struct gpio_chip gc; struct mutex gpio_lock; /* Protect cached dir, dat_out */ u8 dat_out[3]; @@ -473,7 +474,7 @@ static int adp5589_build_gpiomap(struct adp5589_kpad *kpad, memset(pin_used, false, sizeof(pin_used)); for (i = 0; i < kpad->var->maxgpio; i++) - if (pdata->keypad_en_mask & (1 << i)) + if (pdata->keypad_en_mask & BIT(i)) pin_used[i] = true; for (i = 0; i < kpad->gpimapsize; i++) @@ -512,8 +513,6 @@ static int adp5589_gpio_add(struct adp5589_kpad *kpad) return 0; } - kpad->export_gpio = true; - kpad->gc.direction_input = adp5589_gpio_direction_input; kpad->gc.direction_output = adp5589_gpio_direction_output; kpad->gc.get = adp5589_gpio_get_value; @@ -526,11 +525,9 @@ static int adp5589_gpio_add(struct adp5589_kpad *kpad) mutex_init(&kpad->gpio_lock); - error = gpiochip_add_data(&kpad->gc, kpad); - if (error) { - dev_err(dev, "gpiochip_add_data() failed, err: %d\n", error); + error = devm_gpiochip_add_data(dev, &kpad->gc, kpad); + if (error) return error; - } for (i = 0; i <= kpad->var->bank(kpad->var->maxgpio); i++) { kpad->dat_out[i] = adp5589_read(kpad->client, kpad->var->reg( @@ -539,46 +536,13 @@ static int adp5589_gpio_add(struct adp5589_kpad *kpad) ADP5589_GPIO_DIRECTION_A) + i); } - if (gpio_data->setup) { - error = gpio_data->setup(kpad->client, - kpad->gc.base, kpad->gc.ngpio, - gpio_data->context); - if (error) - dev_warn(dev, "setup failed, %d\n", error); - } - return 0; } - -static void adp5589_gpio_remove(struct adp5589_kpad *kpad) -{ - struct device *dev = &kpad->client->dev; - const struct adp5589_kpad_platform_data *pdata = dev_get_platdata(dev); - const struct adp5589_gpio_platform_data *gpio_data = pdata->gpio_data; - int error; - - if (!kpad->export_gpio) - return; - - if (gpio_data->teardown) { - error = gpio_data->teardown(kpad->client, - kpad->gc.base, kpad->gc.ngpio, - gpio_data->context); - if (error) - dev_warn(dev, "teardown failed %d\n", error); - } - - gpiochip_remove(&kpad->gc); -} #else static inline int adp5589_gpio_add(struct adp5589_kpad *kpad) { return 0; } - -static inline void adp5589_gpio_remove(struct adp5589_kpad *kpad) -{ -} #endif static void adp5589_report_switches(struct adp5589_kpad *kpad, @@ -689,13 +653,13 @@ static int adp5589_setup(struct adp5589_kpad *kpad) unsigned short pin = pdata->gpimap[i].pin; if (pin <= kpad->var->gpi_pin_row_end) { - evt_mode1 |= (1 << (pin - kpad->var->gpi_pin_row_base)); + evt_mode1 |= BIT(pin - kpad->var->gpi_pin_row_base); } else { evt_mode2 |= - ((1 << (pin - kpad->var->gpi_pin_col_base)) & 0xFF); + BIT(pin - kpad->var->gpi_pin_col_base) & 0xFF; if (!kpad->is_adp5585) - evt_mode3 |= ((1 << (pin - - kpad->var->gpi_pin_col_base)) >> 8); + evt_mode3 |= + BIT(pin - kpad->var->gpi_pin_col_base) >> 8; } } @@ -715,7 +679,7 @@ static int adp5589_setup(struct adp5589_kpad *kpad) dev_warn(&client->dev, "Conflicting pull resistor config\n"); for (i = 0; i <= kpad->var->max_row_num; i++) { - unsigned val = 0, bit = (1 << i); + unsigned int val = 0, bit = BIT(i); if (pdata->pullup_en_300k & bit) val = 0; else if (pdata->pulldown_en_300k & bit) @@ -735,7 +699,7 @@ static int adp5589_setup(struct adp5589_kpad *kpad) } for (i = 0; i <= kpad->var->max_col_num; i++) { - unsigned val = 0, bit = 1 << (i + kpad->var->col_shift); + unsigned int val = 0, bit = BIT(i + kpad->var->col_shift); if (pdata->pullup_en_300k & bit) val = 0; else if (pdata->pulldown_en_300k & bit) @@ -851,7 +815,7 @@ static void adp5589_report_switch_state(struct adp5589_kpad *kpad) input_report_switch(kpad->input, kpad->gpimap[i].sw_evt, - !(gpi_stat_tmp & (1 << pin_loc))); + !(gpi_stat_tmp & BIT(pin_loc))); } input_sync(kpad->input); @@ -897,7 +861,7 @@ static int adp5589_keypad_add(struct adp5589_kpad *kpad, unsigned int revid) return -EINVAL; } - if ((1 << (pin - kpad->var->gpi_pin_row_base)) & + if (BIT(pin - kpad->var->gpi_pin_row_base) & pdata->keypad_en_mask) { dev_err(&client->dev, "invalid gpi row/col data\n"); return -EINVAL; @@ -909,7 +873,7 @@ static int adp5589_keypad_add(struct adp5589_kpad *kpad, unsigned int revid) return -EINVAL; } - input = input_allocate_device(); + input = devm_input_allocate_device(&client->dev); if (!input) return -ENOMEM; @@ -955,36 +919,27 @@ static int adp5589_keypad_add(struct adp5589_kpad *kpad, unsigned int revid) error = input_register_device(input); if (error) { dev_err(&client->dev, "unable to register input device\n"); - goto err_free_input; + return error; } - error = request_threaded_irq(client->irq, NULL, adp5589_irq, - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, - client->dev.driver->name, kpad); + error = devm_request_threaded_irq(&client->dev, client->irq, + NULL, adp5589_irq, + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, + client->dev.driver->name, kpad); if (error) { - dev_err(&client->dev, "irq %d busy?\n", client->irq); - goto err_unreg_dev; + dev_err(&client->dev, "unable to request irq %d\n", client->irq); + return error; } - device_init_wakeup(&client->dev, 1); - return 0; - -err_unreg_dev: - input_unregister_device(input); - input = NULL; -err_free_input: - input_free_device(input); - - return error; } -static void adp5589_keypad_remove(struct adp5589_kpad *kpad) +static void adp5589_clear_config(void *data) { - if (kpad->input) { - free_irq(kpad->client->irq, kpad); - input_unregister_device(kpad->input); - } + struct i2c_client *client = data; + struct adp5589_kpad *kpad = i2c_get_clientdata(client); + + adp5589_write(client, kpad->var->reg(ADP5589_GENERAL_CFG), 0); } static int adp5589_probe(struct i2c_client *client, @@ -1007,7 +962,7 @@ static int adp5589_probe(struct i2c_client *client, return -EINVAL; } - kpad = kzalloc(sizeof(*kpad), GFP_KERNEL); + kpad = devm_kzalloc(&client->dev, sizeof(*kpad), GFP_KERNEL); if (!kpad) return -ENOMEM; @@ -1027,89 +982,61 @@ static int adp5589_probe(struct i2c_client *client, break; } + error = devm_add_action_or_reset(&client->dev, adp5589_clear_config, + client); + if (error) + return error; + ret = adp5589_read(client, ADP5589_5_ID); - if (ret < 0) { - error = ret; - goto err_free_mem; - } + if (ret < 0) + return ret; revid = (u8) ret & ADP5589_5_DEVICE_ID_MASK; if (pdata->keymapsize) { error = adp5589_keypad_add(kpad, revid); if (error) - goto err_free_mem; + return error; } error = adp5589_setup(kpad); if (error) - goto err_keypad_remove; + return error; if (kpad->gpimapsize) adp5589_report_switch_state(kpad); error = adp5589_gpio_add(kpad); if (error) - goto err_keypad_remove; + return error; i2c_set_clientdata(client, kpad); dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq); return 0; - -err_keypad_remove: - adp5589_keypad_remove(kpad); -err_free_mem: - kfree(kpad); - - return error; } -static int adp5589_remove(struct i2c_client *client) +static int __maybe_unused adp5589_suspend(struct device *dev) { + struct i2c_client *client = to_i2c_client(dev); struct adp5589_kpad *kpad = i2c_get_clientdata(client); - adp5589_write(client, kpad->var->reg(ADP5589_GENERAL_CFG), 0); - adp5589_keypad_remove(kpad); - adp5589_gpio_remove(kpad); - kfree(kpad); + if (kpad->input) + disable_irq(client->irq); return 0; } -#ifdef CONFIG_PM_SLEEP -static int adp5589_suspend(struct device *dev) +static int __maybe_unused adp5589_resume(struct device *dev) { - struct adp5589_kpad *kpad = dev_get_drvdata(dev); - struct i2c_client *client = kpad->client; - - if (!kpad->input) - return 0; - - disable_irq(client->irq); - - if (device_may_wakeup(&client->dev)) - enable_irq_wake(client->irq); - - return 0; -} - -static int adp5589_resume(struct device *dev) -{ - struct adp5589_kpad *kpad = dev_get_drvdata(dev); - struct i2c_client *client = kpad->client; - - if (!kpad->input) - return 0; - - if (device_may_wakeup(&client->dev)) - disable_irq_wake(client->irq); + struct i2c_client *client = to_i2c_client(dev); + struct adp5589_kpad *kpad = i2c_get_clientdata(client); - enable_irq(client->irq); + if (kpad->input) + enable_irq(client->irq); return 0; } -#endif static SIMPLE_DEV_PM_OPS(adp5589_dev_pm_ops, adp5589_suspend, adp5589_resume); @@ -1128,7 +1055,6 @@ static struct i2c_driver adp5589_driver = { .pm = &adp5589_dev_pm_ops, }, .probe = adp5589_probe, - .remove = adp5589_remove, .id_table = adp5589_id, }; |