aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorMichael Hennerich <michael.hennerich@analog.com>2009-10-10 13:54:02 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2009-12-13 13:20:53 -0500
commitfba65fe0ededc538771e47f6d099d7c853f4776e (patch)
tree62b0309e1001d57c40ae009c467c5ba1e164bad3 /drivers/input
parenta5736e0b62fcb7c1b20892c62e1c5fe5e9387c86 (diff)
input/keyboard: new driver for ADP5520 MFD PMICs
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> Signed-off-by: Bryan Wu <cooloney@kernel.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org> Acked-by: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/keyboard/Kconfig10
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/adp5520-keys.c220
3 files changed, 231 insertions, 0 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 203b88a82b5..02c836e1181 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -24,6 +24,16 @@ config KEYBOARD_AAED2000
24 To compile this driver as a module, choose M here: the 24 To compile this driver as a module, choose M here: the
25 module will be called aaed2000_kbd. 25 module will be called aaed2000_kbd.
26 26
27config KEYBOARD_ADP5520
28 tristate "Keypad Support for ADP5520 PMIC"
29 depends on PMIC_ADP5520
30 help
31 This option enables support for the keypad scan matrix
32 on Analog Devices ADP5520 PMICs.
33
34 To compile this driver as a module, choose M here: the module will
35 be called adp5520-keys.
36
27config KEYBOARD_ADP5588 37config KEYBOARD_ADP5588
28 tristate "ADP5588 I2C QWERTY Keypad and IO Expander" 38 tristate "ADP5588 I2C QWERTY Keypad and IO Expander"
29 depends on I2C 39 depends on I2C
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 68c017235ce..78654ef6520 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -5,6 +5,7 @@
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o 7obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o
8obj-$(CONFIG_KEYBOARD_ADP5520) += adp5520-keys.o
8obj-$(CONFIG_KEYBOARD_ADP5588) += adp5588-keys.o 9obj-$(CONFIG_KEYBOARD_ADP5588) += adp5588-keys.o
9obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o 10obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o
10obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o 11obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o
diff --git a/drivers/input/keyboard/adp5520-keys.c b/drivers/input/keyboard/adp5520-keys.c
new file mode 100644
index 00000000000..a7ba27fb410
--- /dev/null
+++ b/drivers/input/keyboard/adp5520-keys.c
@@ -0,0 +1,220 @@
1/*
2 * Keypad driver for Analog Devices ADP5520 MFD PMICs
3 *
4 * Copyright 2009 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/module.h>
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/platform_device.h>
13#include <linux/input.h>
14#include <linux/mfd/adp5520.h>
15
16struct adp5520_keys {
17 struct input_dev *input;
18 struct notifier_block notifier;
19 struct device *master;
20 unsigned short keycode[ADP5520_KEYMAPSIZE];
21};
22
23static void adp5520_keys_report_event(struct adp5520_keys *dev,
24 unsigned short keymask, int value)
25{
26 int i;
27
28 for (i = 0; i < ADP5520_MAXKEYS; i++)
29 if (keymask & (1 << i))
30 input_report_key(dev->input, dev->keycode[i], value);
31
32 input_sync(dev->input);
33}
34
35static int adp5520_keys_notifier(struct notifier_block *nb,
36 unsigned long event, void *data)
37{
38 struct adp5520_keys *dev;
39 uint8_t reg_val_lo, reg_val_hi;
40 unsigned short keymask;
41
42 dev = container_of(nb, struct adp5520_keys, notifier);
43
44 if (event & ADP5520_KP_INT) {
45 adp5520_read(dev->master, ADP5520_KP_INT_STAT_1, &reg_val_lo);
46 adp5520_read(dev->master, ADP5520_KP_INT_STAT_2, &reg_val_hi);
47
48 keymask = (reg_val_hi << 8) | reg_val_lo;
49 /* Read twice to clear */
50 adp5520_read(dev->master, ADP5520_KP_INT_STAT_1, &reg_val_lo);
51 adp5520_read(dev->master, ADP5520_KP_INT_STAT_2, &reg_val_hi);
52 keymask |= (reg_val_hi << 8) | reg_val_lo;
53 adp5520_keys_report_event(dev, keymask, 1);
54 }
55
56 if (event & ADP5520_KR_INT) {
57 adp5520_read(dev->master, ADP5520_KR_INT_STAT_1, &reg_val_lo);
58 adp5520_read(dev->master, ADP5520_KR_INT_STAT_2, &reg_val_hi);
59
60 keymask = (reg_val_hi << 8) | reg_val_lo;
61 /* Read twice to clear */
62 adp5520_read(dev->master, ADP5520_KR_INT_STAT_1, &reg_val_lo);
63 adp5520_read(dev->master, ADP5520_KR_INT_STAT_2, &reg_val_hi);
64 keymask |= (reg_val_hi << 8) | reg_val_lo;
65 adp5520_keys_report_event(dev, keymask, 0);
66 }
67
68 return 0;
69}
70
71static int __devinit adp5520_keys_probe(struct platform_device *pdev)
72{
73 struct adp5520_keys_platform_data *pdata = pdev->dev.platform_data;
74 struct input_dev *input;
75 struct adp5520_keys *dev;
76 int ret, i;
77 unsigned char en_mask, ctl_mask = 0;
78
79 if (pdev->id != ID_ADP5520) {
80 dev_err(&pdev->dev, "only ADP5520 supports Keypad\n");
81 return -EINVAL;
82 }
83
84 if (pdata == NULL) {
85 dev_err(&pdev->dev, "missing platform data\n");
86 return -EINVAL;
87 }
88
89 if (!(pdata->rows_en_mask && pdata->cols_en_mask))
90 return -EINVAL;
91
92 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
93 if (dev == NULL) {
94 dev_err(&pdev->dev, "failed to alloc memory\n");
95 return -ENOMEM;
96 }
97
98 input = input_allocate_device();
99 if (!input) {
100 ret = -ENOMEM;
101 goto err;
102 }
103
104 dev->master = pdev->dev.parent;
105 dev->input = input;
106
107 input->name = pdev->name;
108 input->phys = "adp5520-keys/input0";
109 input->dev.parent = &pdev->dev;
110
111 input_set_drvdata(input, dev);
112
113 input->id.bustype = BUS_I2C;
114 input->id.vendor = 0x0001;
115 input->id.product = 0x5520;
116 input->id.version = 0x0001;
117
118 input->keycodesize = sizeof(dev->keycode[0]);
119 input->keycodemax = pdata->keymapsize;
120 input->keycode = dev->keycode;
121
122 memcpy(dev->keycode, pdata->keymap,
123 pdata->keymapsize * input->keycodesize);
124
125 /* setup input device */
126 __set_bit(EV_KEY, input->evbit);
127
128 if (pdata->repeat)
129 __set_bit(EV_REP, input->evbit);
130
131 for (i = 0; i < input->keycodemax; i++)
132 __set_bit(dev->keycode[i], input->keybit);
133 __clear_bit(KEY_RESERVED, input->keybit);
134
135 ret = input_register_device(input);
136 if (ret) {
137 dev_err(&pdev->dev, "unable to register input device\n");
138 goto err;
139 }
140
141 en_mask = pdata->rows_en_mask | pdata->cols_en_mask;
142
143 ret = adp5520_set_bits(dev->master, ADP5520_GPIO_CFG_1, en_mask);
144
145 if (en_mask & ADP5520_COL_C3)
146 ctl_mask |= ADP5520_C3_MODE;
147
148 if (en_mask & ADP5520_ROW_R3)
149 ctl_mask |= ADP5520_R3_MODE;
150
151 if (ctl_mask)
152 ret |= adp5520_set_bits(dev->master, ADP5520_LED_CONTROL,
153 ctl_mask);
154
155 ret |= adp5520_set_bits(dev->master, ADP5520_GPIO_PULLUP,
156 pdata->rows_en_mask);
157
158 if (ret) {
159 dev_err(&pdev->dev, "failed to write\n");
160 ret = -EIO;
161 goto err1;
162 }
163
164 dev->notifier.notifier_call = adp5520_keys_notifier;
165 ret = adp5520_register_notifier(dev->master, &dev->notifier,
166 ADP5520_KP_IEN | ADP5520_KR_IEN);
167 if (ret) {
168 dev_err(&pdev->dev, "failed to register notifier\n");
169 goto err1;
170 }
171
172 platform_set_drvdata(pdev, dev);
173 return 0;
174
175err1:
176 input_unregister_device(input);
177 input = NULL;
178err:
179 input_free_device(input);
180 kfree(dev);
181 return ret;
182}
183
184static int __devexit adp5520_keys_remove(struct platform_device *pdev)
185{
186 struct adp5520_keys *dev = platform_get_drvdata(pdev);
187
188 adp5520_unregister_notifier(dev->master, &dev->notifier,
189 ADP5520_KP_IEN | ADP5520_KR_IEN);
190
191 input_unregister_device(dev->input);
192 kfree(dev);
193 return 0;
194}
195
196static struct platform_driver adp5520_keys_driver = {
197 .driver = {
198 .name = "adp5520-keys",
199 .owner = THIS_MODULE,
200 },
201 .probe = adp5520_keys_probe,
202 .remove = __devexit_p(adp5520_keys_remove),
203};
204
205static int __init adp5520_keys_init(void)
206{
207 return platform_driver_register(&adp5520_keys_driver);
208}
209module_init(adp5520_keys_init);
210
211static void __exit adp5520_keys_exit(void)
212{
213 platform_driver_unregister(&adp5520_keys_driver);
214}
215module_exit(adp5520_keys_exit);
216
217MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
218MODULE_DESCRIPTION("Keys ADP5520 Driver");
219MODULE_LICENSE("GPL");
220MODULE_ALIAS("platform:adp5520-keys");