Skip to content

Commit

Permalink
Merge pull request torvalds#144 from 96boards/hikey-powerkey
Browse files Browse the repository at this point in the history
drivers: input: powerkey HISI cleanup
  • Loading branch information
ldts committed Nov 6, 2015
2 parents 6766ad6 + afc1c8b commit 7f9696d
Showing 1 changed file with 62 additions and 41 deletions.
103 changes: 62 additions & 41 deletions drivers/input/misc/hisi_powerkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,69 @@
#include <linux/input.h>
#include <linux/slab.h>

/* 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)
Expand All @@ -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; \
\
Expand All @@ -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; \
}
Expand All @@ -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++) {

Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 7f9696d

Please sign in to comment.