diff options
author | Haojian Zhuang <haojian.zhuang@gmail.com> | 2010-09-08 09:44:35 -0400 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2010-10-28 18:29:46 -0400 |
commit | 2d95ae3bbffe54b2e73e0d291e1d67e09d5e448f (patch) | |
tree | d02d8d7b29575f7e2acac2dab070ffb8942f2111 /drivers/input | |
parent | f5d59fc575e22f54069628586bf4b31c85bb2f31 (diff) |
input: Monitor both onkey up and down event
Remove original 3-second ONKEY event. Detect ONKEY changing event directly.
So both UP and DOWN event of ONKEY in max8925 are monitered.
Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/misc/max8925_onkey.c | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/drivers/input/misc/max8925_onkey.c b/drivers/input/misc/max8925_onkey.c index 80af44608018..7de0ded4ccc3 100644 --- a/drivers/input/misc/max8925_onkey.c +++ b/drivers/input/misc/max8925_onkey.c | |||
@@ -27,27 +27,37 @@ | |||
27 | #include <linux/mfd/max8925.h> | 27 | #include <linux/mfd/max8925.h> |
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | 29 | ||
30 | #define SW_INPUT (1 << 7) /* 0/1 -- up/down */ | ||
30 | #define HARDRESET_EN (1 << 7) | 31 | #define HARDRESET_EN (1 << 7) |
31 | #define PWREN_EN (1 << 7) | 32 | #define PWREN_EN (1 << 7) |
32 | 33 | ||
33 | struct max8925_onkey_info { | 34 | struct max8925_onkey_info { |
34 | struct input_dev *idev; | 35 | struct input_dev *idev; |
35 | struct i2c_client *i2c; | 36 | struct i2c_client *i2c; |
36 | int irq; | 37 | struct device *dev; |
38 | int irq[2]; | ||
37 | }; | 39 | }; |
38 | 40 | ||
39 | /* | 41 | /* |
40 | * MAX8925 gives us an interrupt when ONKEY is held for 3 seconds. | 42 | * MAX8925 gives us an interrupt when ONKEY is pressed or released. |
41 | * max8925_set_bits() operates I2C bus and may sleep. So implement | 43 | * max8925_set_bits() operates I2C bus and may sleep. So implement |
42 | * it in thread IRQ handler. | 44 | * it in thread IRQ handler. |
43 | */ | 45 | */ |
44 | static irqreturn_t max8925_onkey_handler(int irq, void *data) | 46 | static irqreturn_t max8925_onkey_handler(int irq, void *data) |
45 | { | 47 | { |
46 | struct max8925_onkey_info *info = data; | 48 | struct max8925_onkey_info *info = data; |
47 | 49 | int ret, event; | |
48 | input_report_key(info->idev, KEY_POWER, 1); | 50 | |
51 | ret = max8925_reg_read(info->i2c, MAX8925_ON_OFF_STATUS); | ||
52 | if (ret & SW_INPUT) | ||
53 | event = 1; | ||
54 | else | ||
55 | event = 0; | ||
56 | input_report_key(info->idev, KEY_POWER, event); | ||
49 | input_sync(info->idev); | 57 | input_sync(info->idev); |
50 | 58 | ||
59 | dev_dbg(info->dev, "onkey event:%d\n", event); | ||
60 | |||
51 | /* Enable hardreset to halt if system isn't shutdown on time */ | 61 | /* Enable hardreset to halt if system isn't shutdown on time */ |
52 | max8925_set_bits(info->i2c, MAX8925_SYSENSEL, | 62 | max8925_set_bits(info->i2c, MAX8925_SYSENSEL, |
53 | HARDRESET_EN, HARDRESET_EN); | 63 | HARDRESET_EN, HARDRESET_EN); |
@@ -59,14 +69,42 @@ static int __devinit max8925_onkey_probe(struct platform_device *pdev) | |||
59 | { | 69 | { |
60 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); | 70 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); |
61 | struct max8925_onkey_info *info; | 71 | struct max8925_onkey_info *info; |
62 | int error; | 72 | int irq[2], error; |
73 | |||
74 | irq[0] = platform_get_irq(pdev, 0); | ||
75 | if (irq[0] < 0) { | ||
76 | dev_err(&pdev->dev, "No IRQ resource!\n"); | ||
77 | return -EINVAL; | ||
78 | } | ||
79 | irq[1] = platform_get_irq(pdev, 1); | ||
80 | if (irq[1] < 0) { | ||
81 | dev_err(&pdev->dev, "No IRQ resource!\n"); | ||
82 | return -EINVAL; | ||
83 | } | ||
63 | 84 | ||
64 | info = kzalloc(sizeof(struct max8925_onkey_info), GFP_KERNEL); | 85 | info = kzalloc(sizeof(struct max8925_onkey_info), GFP_KERNEL); |
65 | if (!info) | 86 | if (!info) |
66 | return -ENOMEM; | 87 | return -ENOMEM; |
67 | 88 | ||
68 | info->i2c = chip->i2c; | 89 | info->i2c = chip->i2c; |
69 | info->irq = chip->irq_base + MAX8925_IRQ_GPM_SW_3SEC; | 90 | info->dev = &pdev->dev; |
91 | irq[0] += chip->irq_base; | ||
92 | irq[1] += chip->irq_base; | ||
93 | |||
94 | error = request_threaded_irq(irq[0], NULL, max8925_onkey_handler, | ||
95 | IRQF_ONESHOT, "onkey-down", info); | ||
96 | if (error < 0) { | ||
97 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", | ||
98 | irq[0], error); | ||
99 | goto out; | ||
100 | } | ||
101 | error = request_threaded_irq(irq[1], NULL, max8925_onkey_handler, | ||
102 | IRQF_ONESHOT, "onkey-up", info); | ||
103 | if (error < 0) { | ||
104 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", | ||
105 | irq[1], error); | ||
106 | goto out_irq; | ||
107 | } | ||
70 | 108 | ||
71 | info->idev = input_allocate_device(); | 109 | info->idev = input_allocate_device(); |
72 | if (!info->idev) { | 110 | if (!info->idev) { |
@@ -79,32 +117,29 @@ static int __devinit max8925_onkey_probe(struct platform_device *pdev) | |||
79 | info->idev->phys = "max8925_on/input0"; | 117 | info->idev->phys = "max8925_on/input0"; |
80 | info->idev->id.bustype = BUS_I2C; | 118 | info->idev->id.bustype = BUS_I2C; |
81 | info->idev->dev.parent = &pdev->dev; | 119 | info->idev->dev.parent = &pdev->dev; |
120 | info->irq[0] = irq[0]; | ||
121 | info->irq[1] = irq[1]; | ||
82 | info->idev->evbit[0] = BIT_MASK(EV_KEY); | 122 | info->idev->evbit[0] = BIT_MASK(EV_KEY); |
83 | info->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER); | 123 | info->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER); |
84 | 124 | ||
85 | error = request_threaded_irq(info->irq, NULL, max8925_onkey_handler, | ||
86 | IRQF_ONESHOT, "onkey", info); | ||
87 | if (error < 0) { | ||
88 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", | ||
89 | info->irq, error); | ||
90 | goto out_irq; | ||
91 | } | ||
92 | 125 | ||
93 | error = input_register_device(info->idev); | 126 | error = input_register_device(info->idev); |
94 | if (error) { | 127 | if (error) { |
95 | dev_err(chip->dev, "Can't register input device: %d\n", error); | 128 | dev_err(chip->dev, "Can't register input device: %d\n", error); |
96 | goto out; | 129 | goto out_reg; |
97 | } | 130 | } |
98 | 131 | ||
99 | platform_set_drvdata(pdev, info); | 132 | platform_set_drvdata(pdev, info); |
100 | 133 | ||
101 | return 0; | 134 | return 0; |
102 | 135 | ||
103 | out: | 136 | out_reg: |
104 | free_irq(info->irq, info); | ||
105 | out_irq: | ||
106 | input_free_device(info->idev); | 137 | input_free_device(info->idev); |
107 | out_input: | 138 | out_input: |
139 | free_irq(info->irq[1], info); | ||
140 | out_irq: | ||
141 | free_irq(info->irq[0], info); | ||
142 | out: | ||
108 | kfree(info); | 143 | kfree(info); |
109 | return error; | 144 | return error; |
110 | } | 145 | } |
@@ -113,7 +148,8 @@ static int __devexit max8925_onkey_remove(struct platform_device *pdev) | |||
113 | { | 148 | { |
114 | struct max8925_onkey_info *info = platform_get_drvdata(pdev); | 149 | struct max8925_onkey_info *info = platform_get_drvdata(pdev); |
115 | 150 | ||
116 | free_irq(info->irq, info); | 151 | free_irq(info->irq[0], info); |
152 | free_irq(info->irq[1], info); | ||
117 | input_unregister_device(info->idev); | 153 | input_unregister_device(info->idev); |
118 | kfree(info); | 154 | kfree(info); |
119 | 155 | ||