diff --git a/drivers/input/misc/hisi_powerkey.c b/drivers/input/misc/hisi_powerkey.c index 99f6f711510154..73807979b851fa 100644 --- a/drivers/input/misc/hisi_powerkey.c +++ b/drivers/input/misc/hisi_powerkey.c @@ -24,41 +24,69 @@ #include #include -/* irq_info : names match the device tree */ -const char *pressed_name = "down"; -const char *held_name = "hold 4s"; -const char *released_name = "up"; - /* the above held interrupt will trigger after 4 seconds */ #define MAX_HELD_TIME (4 * HZ) +#define irq_handler_id(x) button_irq_##x +#define irq_handler_declaration(x) \ +static irqreturn_t irq_handler_id(x)(int irq, void *q) + +irq_handler_declaration(released); +irq_handler_declaration(pressed); +irq_handler_declaration(held); + typedef irqreturn_t (*hi65xx_irq_handler) (int irq, void *data); enum { id_pressed, id_released, id_held, id_last }; + +/* + * power key irq information + */ static struct hi65xx_pkey_irq_info { hi65xx_irq_handler handler; - const char *name; + const char *const name; int irq; -} irq_info[id_last]; - -#define INIT_IRQINFO(x) \ -do { \ - irq_info[id_##x].handler = irq_handler_id(x); \ - irq_info[id_##x].name = x##_name; \ - irq_info[id_##x].irq = -1; \ -} while (0) - -struct hi65xx_priv { - struct wake_lock wlock; - struct input_dev *idev; +} irq_info[id_last] ={ + [id_pressed] = { + .handler = irq_handler_id(pressed), + .name = "down", + .irq = -1, + }, + [id_released] = { + .handler = irq_handler_id(released), + .name = "up", + .irq = -1, + }, + [id_held] = { + .handler = irq_handler_id(held), + .name = "hold 4s", + .irq = -1, + }, }; +/* + * power key events + */ static struct key_report_pairs { int code; int value; } pkey_report[id_last] = { - [id_released] = { .code = KEY_POWER, .value = 0 }, - [id_pressed] = { .code = KEY_POWER, .value = 1 }, - [id_held] = { .code = KEY_RESTART, .value = 0 }, + [id_released] = { + .code = KEY_POWER, + .value = 0 + }, + [id_pressed] = { + .code = KEY_POWER, + .value = 1 + }, + [id_held] = { + .code = KEY_RESTART, + .value = 0 + }, +}; + +struct hi65xx_priv { + struct input_dev *input; + struct wake_lock wlock; }; static inline void report_key(struct input_dev *dev, int id_action) @@ -79,10 +107,8 @@ static inline void report_key(struct input_dev *dev, int id_action) pkey_report[id_action].value); } -/* irq handlers */ -#define irq_handler_id(x) button_irq_##x #define irq_handler_definition(action) \ -static irqreturn_t button_irq_##action(int irq, void *q) \ +irq_handler_declaration(action) \ { \ struct hi65xx_priv *p = q; \ \ @@ -91,8 +117,8 @@ static irqreturn_t button_irq_##action(int irq, void *q) \ \ wake_lock_timeout(&p->wlock, MAX_HELD_TIME); \ \ - report_key(p->idev, id_##action); \ - input_sync(p->idev); \ + report_key(p->input, id_##action); \ + input_sync(p->input); \ \ return IRQ_HANDLED; \ } @@ -116,28 +142,23 @@ static int hi65xx_powerkey_probe(struct platform_device *pdev) return -EINVAL; } - /* interrupt names must match the device tree */ - INIT_IRQINFO(released); - INIT_IRQINFO(pressed); - INIT_IRQINFO(held); - priv = devm_kzalloc(dev, sizeof(struct hi65xx_priv), GFP_KERNEL); if (!priv) return -ENOMEM; - priv->idev = input_allocate_device(); - if (!priv->idev) { + priv->input = input_allocate_device(); + if (!priv->input) { dev_err(&pdev->dev, "failed to allocate input device\n"); return -ENOENT; } - priv->idev->evbit[0] = BIT_MASK(EV_KEY); - priv->idev->dev.parent = &pdev->dev; - priv->idev->phys = "hisi_on/input0"; - priv->idev->name = "hisi_on"; + priv->input->evbit[0] = BIT_MASK(EV_KEY); + priv->input->dev.parent = &pdev->dev; + priv->input->phys = "hisi_on/input0"; + priv->input->name = "HISI 65xx PowerOn Key"; for (i = 0; i < ARRAY_SIZE(pkey_report); i++) - input_set_capability(priv->idev, EV_KEY, pkey_report[i].code); + input_set_capability(priv->input, EV_KEY, pkey_report[i].code); for (i = 0; i < ARRAY_SIZE(irq_info); i++) { @@ -160,7 +181,7 @@ static int hi65xx_powerkey_probe(struct platform_device *pdev) wake_lock_init(&priv->wlock, WAKE_LOCK_SUSPEND, "hisi-powerkey"); - ret = input_register_device(priv->idev); + ret = input_register_device(priv->input); if (ret) { dev_err(&pdev->dev, "failed to register input device: %d\n", ret); @@ -175,7 +196,7 @@ static int hi65xx_powerkey_probe(struct platform_device *pdev) err_register: wake_lock_destroy(&priv->wlock); err_irq: - input_free_device(priv->idev); + input_free_device(priv->input); return ret; } @@ -185,7 +206,7 @@ static int hi65xx_powerkey_remove(struct platform_device *pdev) struct hi65xx_priv *priv = platform_get_drvdata(pdev); wake_lock_destroy(&priv->wlock); - input_unregister_device(priv->idev); + input_unregister_device(priv->input); return 0; }