aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@arm.linux.org.uk>2011-01-03 05:31:54 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2011-01-03 05:31:58 -0500
commitcde9efef401563943d5a58eb9b7274bfdc08ca9b (patch)
tree858a436055612db6282dc63db0fe3ba41147056a /drivers
parent50401d77ee4904673042dd737eed436067cc23f5 (diff)
parent60ebe1568fd15b7ffa101acc645069e27d546ed6 (diff)
Merge branch 'ux500-core' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-stericsson into devel-stable
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpio/Kconfig8
-rw-r--r--drivers/gpio/Makefile2
-rw-r--r--drivers/gpio/tc35892-gpio.c389
-rw-r--r--drivers/gpio/tc3589x-gpio.c389
-rw-r--r--drivers/input/keyboard/Kconfig10
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/tc3589x-keypad.c472
-rw-r--r--drivers/mfd/Kconfig6
-rw-r--r--drivers/mfd/Makefile2
-rw-r--r--drivers/mfd/tc35892.c345
-rw-r--r--drivers/mfd/tc3589x.c422
-rw-r--r--drivers/net/caif/caif_shm_u5500.c2
12 files changed, 1304 insertions, 744 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 3143ac795eb0..082495bb08a7 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -230,11 +230,11 @@ config GPIO_STMPE
230 This enables support for the GPIOs found on the STMPE I/O 230 This enables support for the GPIOs found on the STMPE I/O
231 Expanders. 231 Expanders.
232 232
233config GPIO_TC35892 233config GPIO_TC3589X
234 bool "TC35892 GPIOs" 234 bool "TC3589X GPIOs"
235 depends on MFD_TC35892 235 depends on MFD_TC3589X
236 help 236 help
237 This enables support for the GPIOs found on the TC35892 237 This enables support for the GPIOs found on the TC3589X
238 I/O Expander. 238 I/O Expander.
239 239
240config GPIO_TWL4030 240config GPIO_TWL4030
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index bdf3ddec0652..39bfd7a37650 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -24,7 +24,7 @@ obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
24obj-$(CONFIG_GPIO_PCH) += pch_gpio.o 24obj-$(CONFIG_GPIO_PCH) += pch_gpio.o
25obj-$(CONFIG_GPIO_PL061) += pl061.o 25obj-$(CONFIG_GPIO_PL061) += pl061.o
26obj-$(CONFIG_GPIO_STMPE) += stmpe-gpio.o 26obj-$(CONFIG_GPIO_STMPE) += stmpe-gpio.o
27obj-$(CONFIG_GPIO_TC35892) += tc35892-gpio.o 27obj-$(CONFIG_GPIO_TC3589X) += tc3589x-gpio.o
28obj-$(CONFIG_GPIO_TIMBERDALE) += timbgpio.o 28obj-$(CONFIG_GPIO_TIMBERDALE) += timbgpio.o
29obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o 29obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o
30obj-$(CONFIG_GPIO_UCB1400) += ucb1400_gpio.o 30obj-$(CONFIG_GPIO_UCB1400) += ucb1400_gpio.o
diff --git a/drivers/gpio/tc35892-gpio.c b/drivers/gpio/tc35892-gpio.c
deleted file mode 100644
index 7e10c935a047..000000000000
--- a/drivers/gpio/tc35892-gpio.c
+++ /dev/null
@@ -1,389 +0,0 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Hanumath Prasad <hanumath.prasad@stericsson.com> for ST-Ericsson
6 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
7 */
8
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/platform_device.h>
12#include <linux/slab.h>
13#include <linux/gpio.h>
14#include <linux/irq.h>
15#include <linux/interrupt.h>
16#include <linux/mfd/tc35892.h>
17
18/*
19 * These registers are modified under the irq bus lock and cached to avoid
20 * unnecessary writes in bus_sync_unlock.
21 */
22enum { REG_IBE, REG_IEV, REG_IS, REG_IE };
23
24#define CACHE_NR_REGS 4
25#define CACHE_NR_BANKS 3
26
27struct tc35892_gpio {
28 struct gpio_chip chip;
29 struct tc35892 *tc35892;
30 struct device *dev;
31 struct mutex irq_lock;
32
33 int irq_base;
34
35 /* Caches of interrupt control registers for bus_lock */
36 u8 regs[CACHE_NR_REGS][CACHE_NR_BANKS];
37 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS];
38};
39
40static inline struct tc35892_gpio *to_tc35892_gpio(struct gpio_chip *chip)
41{
42 return container_of(chip, struct tc35892_gpio, chip);
43}
44
45static int tc35892_gpio_get(struct gpio_chip *chip, unsigned offset)
46{
47 struct tc35892_gpio *tc35892_gpio = to_tc35892_gpio(chip);
48 struct tc35892 *tc35892 = tc35892_gpio->tc35892;
49 u8 reg = TC35892_GPIODATA0 + (offset / 8) * 2;
50 u8 mask = 1 << (offset % 8);
51 int ret;
52
53 ret = tc35892_reg_read(tc35892, reg);
54 if (ret < 0)
55 return ret;
56
57 return ret & mask;
58}
59
60static void tc35892_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
61{
62 struct tc35892_gpio *tc35892_gpio = to_tc35892_gpio(chip);
63 struct tc35892 *tc35892 = tc35892_gpio->tc35892;
64 u8 reg = TC35892_GPIODATA0 + (offset / 8) * 2;
65 unsigned pos = offset % 8;
66 u8 data[] = {!!val << pos, 1 << pos};
67
68 tc35892_block_write(tc35892, reg, ARRAY_SIZE(data), data);
69}
70
71static int tc35892_gpio_direction_output(struct gpio_chip *chip,
72 unsigned offset, int val)
73{
74 struct tc35892_gpio *tc35892_gpio = to_tc35892_gpio(chip);
75 struct tc35892 *tc35892 = tc35892_gpio->tc35892;
76 u8 reg = TC35892_GPIODIR0 + offset / 8;
77 unsigned pos = offset % 8;
78
79 tc35892_gpio_set(chip, offset, val);
80
81 return tc35892_set_bits(tc35892, reg, 1 << pos, 1 << pos);
82}
83
84static int tc35892_gpio_direction_input(struct gpio_chip *chip,
85 unsigned offset)
86{
87 struct tc35892_gpio *tc35892_gpio = to_tc35892_gpio(chip);
88 struct tc35892 *tc35892 = tc35892_gpio->tc35892;
89 u8 reg = TC35892_GPIODIR0 + offset / 8;
90 unsigned pos = offset % 8;
91
92 return tc35892_set_bits(tc35892, reg, 1 << pos, 0);
93}
94
95static int tc35892_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
96{
97 struct tc35892_gpio *tc35892_gpio = to_tc35892_gpio(chip);
98
99 return tc35892_gpio->irq_base + offset;
100}
101
102static struct gpio_chip template_chip = {
103 .label = "tc35892",
104 .owner = THIS_MODULE,
105 .direction_input = tc35892_gpio_direction_input,
106 .get = tc35892_gpio_get,
107 .direction_output = tc35892_gpio_direction_output,
108 .set = tc35892_gpio_set,
109 .to_irq = tc35892_gpio_to_irq,
110 .can_sleep = 1,
111};
112
113static int tc35892_gpio_irq_set_type(unsigned int irq, unsigned int type)
114{
115 struct tc35892_gpio *tc35892_gpio = get_irq_chip_data(irq);
116 int offset = irq - tc35892_gpio->irq_base;
117 int regoffset = offset / 8;
118 int mask = 1 << (offset % 8);
119
120 if (type == IRQ_TYPE_EDGE_BOTH) {
121 tc35892_gpio->regs[REG_IBE][regoffset] |= mask;
122 return 0;
123 }
124
125 tc35892_gpio->regs[REG_IBE][regoffset] &= ~mask;
126
127 if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH)
128 tc35892_gpio->regs[REG_IS][regoffset] |= mask;
129 else
130 tc35892_gpio->regs[REG_IS][regoffset] &= ~mask;
131
132 if (type == IRQ_TYPE_EDGE_RISING || type == IRQ_TYPE_LEVEL_HIGH)
133 tc35892_gpio->regs[REG_IEV][regoffset] |= mask;
134 else
135 tc35892_gpio->regs[REG_IEV][regoffset] &= ~mask;
136
137 return 0;
138}
139
140static void tc35892_gpio_irq_lock(unsigned int irq)
141{
142 struct tc35892_gpio *tc35892_gpio = get_irq_chip_data(irq);
143
144 mutex_lock(&tc35892_gpio->irq_lock);
145}
146
147static void tc35892_gpio_irq_sync_unlock(unsigned int irq)
148{
149 struct tc35892_gpio *tc35892_gpio = get_irq_chip_data(irq);
150 struct tc35892 *tc35892 = tc35892_gpio->tc35892;
151 static const u8 regmap[] = {
152 [REG_IBE] = TC35892_GPIOIBE0,
153 [REG_IEV] = TC35892_GPIOIEV0,
154 [REG_IS] = TC35892_GPIOIS0,
155 [REG_IE] = TC35892_GPIOIE0,
156 };
157 int i, j;
158
159 for (i = 0; i < CACHE_NR_REGS; i++) {
160 for (j = 0; j < CACHE_NR_BANKS; j++) {
161 u8 old = tc35892_gpio->oldregs[i][j];
162 u8 new = tc35892_gpio->regs[i][j];
163
164 if (new == old)
165 continue;
166
167 tc35892_gpio->oldregs[i][j] = new;
168 tc35892_reg_write(tc35892, regmap[i] + j * 8, new);
169 }
170 }
171
172 mutex_unlock(&tc35892_gpio->irq_lock);
173}
174
175static void tc35892_gpio_irq_mask(unsigned int irq)
176{
177 struct tc35892_gpio *tc35892_gpio = get_irq_chip_data(irq);
178 int offset = irq - tc35892_gpio->irq_base;
179 int regoffset = offset / 8;
180 int mask = 1 << (offset % 8);
181
182 tc35892_gpio->regs[REG_IE][regoffset] &= ~mask;
183}
184
185static void tc35892_gpio_irq_unmask(unsigned int irq)
186{
187 struct tc35892_gpio *tc35892_gpio = get_irq_chip_data(irq);
188 int offset = irq - tc35892_gpio->irq_base;
189 int regoffset = offset / 8;
190 int mask = 1 << (offset % 8);
191
192 tc35892_gpio->regs[REG_IE][regoffset] |= mask;
193}
194
195static struct irq_chip tc35892_gpio_irq_chip = {
196 .name = "tc35892-gpio",
197 .bus_lock = tc35892_gpio_irq_lock,
198 .bus_sync_unlock = tc35892_gpio_irq_sync_unlock,
199 .mask = tc35892_gpio_irq_mask,
200 .unmask = tc35892_gpio_irq_unmask,
201 .set_type = tc35892_gpio_irq_set_type,
202};
203
204static irqreturn_t tc35892_gpio_irq(int irq, void *dev)
205{
206 struct tc35892_gpio *tc35892_gpio = dev;
207 struct tc35892 *tc35892 = tc35892_gpio->tc35892;
208 u8 status[CACHE_NR_BANKS];
209 int ret;
210 int i;
211
212 ret = tc35892_block_read(tc35892, TC35892_GPIOMIS0,
213 ARRAY_SIZE(status), status);
214 if (ret < 0)
215 return IRQ_NONE;
216
217 for (i = 0; i < ARRAY_SIZE(status); i++) {
218 unsigned int stat = status[i];
219 if (!stat)
220 continue;
221
222 while (stat) {
223 int bit = __ffs(stat);
224 int line = i * 8 + bit;
225
226 handle_nested_irq(tc35892_gpio->irq_base + line);
227 stat &= ~(1 << bit);
228 }
229
230 tc35892_reg_write(tc35892, TC35892_GPIOIC0 + i, status[i]);
231 }
232
233 return IRQ_HANDLED;
234}
235
236static int tc35892_gpio_irq_init(struct tc35892_gpio *tc35892_gpio)
237{
238 int base = tc35892_gpio->irq_base;
239 int irq;
240
241 for (irq = base; irq < base + tc35892_gpio->chip.ngpio; irq++) {
242 set_irq_chip_data(irq, tc35892_gpio);
243 set_irq_chip_and_handler(irq, &tc35892_gpio_irq_chip,
244 handle_simple_irq);
245 set_irq_nested_thread(irq, 1);
246#ifdef CONFIG_ARM
247 set_irq_flags(irq, IRQF_VALID);
248#else
249 set_irq_noprobe(irq);
250#endif
251 }
252
253 return 0;
254}
255
256static void tc35892_gpio_irq_remove(struct tc35892_gpio *tc35892_gpio)
257{
258 int base = tc35892_gpio->irq_base;
259 int irq;
260
261 for (irq = base; irq < base + tc35892_gpio->chip.ngpio; irq++) {
262#ifdef CONFIG_ARM
263 set_irq_flags(irq, 0);
264#endif
265 set_irq_chip_and_handler(irq, NULL, NULL);
266 set_irq_chip_data(irq, NULL);
267 }
268}
269
270static int __devinit tc35892_gpio_probe(struct platform_device *pdev)
271{
272 struct tc35892 *tc35892 = dev_get_drvdata(pdev->dev.parent);
273 struct tc35892_gpio_platform_data *pdata;
274 struct tc35892_gpio *tc35892_gpio;
275 int ret;
276 int irq;
277
278 pdata = tc35892->pdata->gpio;
279 if (!pdata)
280 return -ENODEV;
281
282 irq = platform_get_irq(pdev, 0);
283 if (irq < 0)
284 return irq;
285
286 tc35892_gpio = kzalloc(sizeof(struct tc35892_gpio), GFP_KERNEL);
287 if (!tc35892_gpio)
288 return -ENOMEM;
289
290 mutex_init(&tc35892_gpio->irq_lock);
291
292 tc35892_gpio->dev = &pdev->dev;
293 tc35892_gpio->tc35892 = tc35892;
294
295 tc35892_gpio->chip = template_chip;
296 tc35892_gpio->chip.ngpio = tc35892->num_gpio;
297 tc35892_gpio->chip.dev = &pdev->dev;
298 tc35892_gpio->chip.base = pdata->gpio_base;
299
300 tc35892_gpio->irq_base = tc35892->irq_base + TC35892_INT_GPIO(0);
301
302 /* Bring the GPIO module out of reset */
303 ret = tc35892_set_bits(tc35892, TC35892_RSTCTRL,
304 TC35892_RSTCTRL_GPIRST, 0);
305 if (ret < 0)
306 goto out_free;
307
308 ret = tc35892_gpio_irq_init(tc35892_gpio);
309 if (ret)
310 goto out_free;
311
312 ret = request_threaded_irq(irq, NULL, tc35892_gpio_irq, IRQF_ONESHOT,
313 "tc35892-gpio", tc35892_gpio);
314 if (ret) {
315 dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
316 goto out_removeirq;
317 }
318
319 ret = gpiochip_add(&tc35892_gpio->chip);
320 if (ret) {
321 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
322 goto out_freeirq;
323 }
324
325 if (pdata->setup)
326 pdata->setup(tc35892, tc35892_gpio->chip.base);
327
328 platform_set_drvdata(pdev, tc35892_gpio);
329
330 return 0;
331
332out_freeirq:
333 free_irq(irq, tc35892_gpio);
334out_removeirq:
335 tc35892_gpio_irq_remove(tc35892_gpio);
336out_free:
337 kfree(tc35892_gpio);
338 return ret;
339}
340
341static int __devexit tc35892_gpio_remove(struct platform_device *pdev)
342{
343 struct tc35892_gpio *tc35892_gpio = platform_get_drvdata(pdev);
344 struct tc35892 *tc35892 = tc35892_gpio->tc35892;
345 struct tc35892_gpio_platform_data *pdata = tc35892->pdata->gpio;
346 int irq = platform_get_irq(pdev, 0);
347 int ret;
348
349 if (pdata->remove)
350 pdata->remove(tc35892, tc35892_gpio->chip.base);
351
352 ret = gpiochip_remove(&tc35892_gpio->chip);
353 if (ret < 0) {
354 dev_err(tc35892_gpio->dev,
355 "unable to remove gpiochip: %d\n", ret);
356 return ret;
357 }
358
359 free_irq(irq, tc35892_gpio);
360 tc35892_gpio_irq_remove(tc35892_gpio);
361
362 platform_set_drvdata(pdev, NULL);
363 kfree(tc35892_gpio);
364
365 return 0;
366}
367
368static struct platform_driver tc35892_gpio_driver = {
369 .driver.name = "tc35892-gpio",
370 .driver.owner = THIS_MODULE,
371 .probe = tc35892_gpio_probe,
372 .remove = __devexit_p(tc35892_gpio_remove),
373};
374
375static int __init tc35892_gpio_init(void)
376{
377 return platform_driver_register(&tc35892_gpio_driver);
378}
379subsys_initcall(tc35892_gpio_init);
380
381static void __exit tc35892_gpio_exit(void)
382{
383 platform_driver_unregister(&tc35892_gpio_driver);
384}
385module_exit(tc35892_gpio_exit);
386
387MODULE_LICENSE("GPL v2");
388MODULE_DESCRIPTION("TC35892 GPIO driver");
389MODULE_AUTHOR("Hanumath Prasad, Rabin Vincent");
diff --git a/drivers/gpio/tc3589x-gpio.c b/drivers/gpio/tc3589x-gpio.c
new file mode 100644
index 000000000000..180d584454fb
--- /dev/null
+++ b/drivers/gpio/tc3589x-gpio.c
@@ -0,0 +1,389 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Hanumath Prasad <hanumath.prasad@stericsson.com> for ST-Ericsson
6 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
7 */
8
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/platform_device.h>
12#include <linux/slab.h>
13#include <linux/gpio.h>
14#include <linux/irq.h>
15#include <linux/interrupt.h>
16#include <linux/mfd/tc3589x.h>
17
18/*
19 * These registers are modified under the irq bus lock and cached to avoid
20 * unnecessary writes in bus_sync_unlock.
21 */
22enum { REG_IBE, REG_IEV, REG_IS, REG_IE };
23
24#define CACHE_NR_REGS 4
25#define CACHE_NR_BANKS 3
26
27struct tc3589x_gpio {
28 struct gpio_chip chip;
29 struct tc3589x *tc3589x;
30 struct device *dev;
31 struct mutex irq_lock;
32
33 int irq_base;
34
35 /* Caches of interrupt control registers for bus_lock */
36 u8 regs[CACHE_NR_REGS][CACHE_NR_BANKS];
37 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS];
38};
39
40static inline struct tc3589x_gpio *to_tc3589x_gpio(struct gpio_chip *chip)
41{
42 return container_of(chip, struct tc3589x_gpio, chip);
43}
44
45static int tc3589x_gpio_get(struct gpio_chip *chip, unsigned offset)
46{
47 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
48 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
49 u8 reg = TC3589x_GPIODATA0 + (offset / 8) * 2;
50 u8 mask = 1 << (offset % 8);
51 int ret;
52
53 ret = tc3589x_reg_read(tc3589x, reg);
54 if (ret < 0)
55 return ret;
56
57 return ret & mask;
58}
59
60static void tc3589x_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
61{
62 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
63 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
64 u8 reg = TC3589x_GPIODATA0 + (offset / 8) * 2;
65 unsigned pos = offset % 8;
66 u8 data[] = {!!val << pos, 1 << pos};
67
68 tc3589x_block_write(tc3589x, reg, ARRAY_SIZE(data), data);
69}
70
71static int tc3589x_gpio_direction_output(struct gpio_chip *chip,
72 unsigned offset, int val)
73{
74 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
75 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
76 u8 reg = TC3589x_GPIODIR0 + offset / 8;
77 unsigned pos = offset % 8;
78
79 tc3589x_gpio_set(chip, offset, val);
80
81 return tc3589x_set_bits(tc3589x, reg, 1 << pos, 1 << pos);
82}
83
84static int tc3589x_gpio_direction_input(struct gpio_chip *chip,
85 unsigned offset)
86{
87 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
88 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
89 u8 reg = TC3589x_GPIODIR0 + offset / 8;
90 unsigned pos = offset % 8;
91
92 return tc3589x_set_bits(tc3589x, reg, 1 << pos, 0);
93}
94
95static int tc3589x_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
96{
97 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
98
99 return tc3589x_gpio->irq_base + offset;
100}
101
102static struct gpio_chip template_chip = {
103 .label = "tc3589x",
104 .owner = THIS_MODULE,
105 .direction_input = tc3589x_gpio_direction_input,
106 .get = tc3589x_gpio_get,
107 .direction_output = tc3589x_gpio_direction_output,
108 .set = tc3589x_gpio_set,
109 .to_irq = tc3589x_gpio_to_irq,
110 .can_sleep = 1,
111};
112
113static int tc3589x_gpio_irq_set_type(unsigned int irq, unsigned int type)
114{
115 struct tc3589x_gpio *tc3589x_gpio = get_irq_chip_data(irq);
116 int offset = irq - tc3589x_gpio->irq_base;
117 int regoffset = offset / 8;
118 int mask = 1 << (offset % 8);
119
120 if (type == IRQ_TYPE_EDGE_BOTH) {
121 tc3589x_gpio->regs[REG_IBE][regoffset] |= mask;
122 return 0;
123 }
124
125 tc3589x_gpio->regs[REG_IBE][regoffset] &= ~mask;
126
127 if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH)
128 tc3589x_gpio->regs[REG_IS][regoffset] |= mask;
129 else
130 tc3589x_gpio->regs[REG_IS][regoffset] &= ~mask;
131
132 if (type == IRQ_TYPE_EDGE_RISING || type == IRQ_TYPE_LEVEL_HIGH)
133 tc3589x_gpio->regs[REG_IEV][regoffset] |= mask;
134 else
135 tc3589x_gpio->regs[REG_IEV][regoffset] &= ~mask;
136
137 return 0;
138}
139
140static void tc3589x_gpio_irq_lock(unsigned int irq)
141{
142 struct tc3589x_gpio *tc3589x_gpio = get_irq_chip_data(irq);
143
144 mutex_lock(&tc3589x_gpio->irq_lock);
145}
146
147static void tc3589x_gpio_irq_sync_unlock(unsigned int irq)
148{
149 struct tc3589x_gpio *tc3589x_gpio = get_irq_chip_data(irq);
150 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
151 static const u8 regmap[] = {
152 [REG_IBE] = TC3589x_GPIOIBE0,
153 [REG_IEV] = TC3589x_GPIOIEV0,
154 [REG_IS] = TC3589x_GPIOIS0,
155 [REG_IE] = TC3589x_GPIOIE0,
156 };
157 int i, j;
158
159 for (i = 0; i < CACHE_NR_REGS; i++) {
160 for (j = 0; j < CACHE_NR_BANKS; j++) {
161 u8 old = tc3589x_gpio->oldregs[i][j];
162 u8 new = tc3589x_gpio->regs[i][j];
163
164 if (new == old)
165 continue;
166
167 tc3589x_gpio->oldregs[i][j] = new;
168 tc3589x_reg_write(tc3589x, regmap[i] + j * 8, new);
169 }
170 }
171
172 mutex_unlock(&tc3589x_gpio->irq_lock);
173}
174
175static void tc3589x_gpio_irq_mask(unsigned int irq)
176{
177 struct tc3589x_gpio *tc3589x_gpio = get_irq_chip_data(irq);
178 int offset = irq - tc3589x_gpio->irq_base;
179 int regoffset = offset / 8;
180 int mask = 1 << (offset % 8);
181
182 tc3589x_gpio->regs[REG_IE][regoffset] &= ~mask;
183}
184
185static void tc3589x_gpio_irq_unmask(unsigned int irq)
186{
187 struct tc3589x_gpio *tc3589x_gpio = get_irq_chip_data(irq);
188 int offset = irq - tc3589x_gpio->irq_base;
189 int regoffset = offset / 8;
190 int mask = 1 << (offset % 8);
191
192 tc3589x_gpio->regs[REG_IE][regoffset] |= mask;
193}
194
195static struct irq_chip tc3589x_gpio_irq_chip = {
196 .name = "tc3589x-gpio",
197 .bus_lock = tc3589x_gpio_irq_lock,
198 .bus_sync_unlock = tc3589x_gpio_irq_sync_unlock,
199 .mask = tc3589x_gpio_irq_mask,
200 .unmask = tc3589x_gpio_irq_unmask,
201 .set_type = tc3589x_gpio_irq_set_type,
202};
203
204static irqreturn_t tc3589x_gpio_irq(int irq, void *dev)
205{
206 struct tc3589x_gpio *tc3589x_gpio = dev;
207 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
208 u8 status[CACHE_NR_BANKS];
209 int ret;
210 int i;
211
212 ret = tc3589x_block_read(tc3589x, TC3589x_GPIOMIS0,
213 ARRAY_SIZE(status), status);
214 if (ret < 0)
215 return IRQ_NONE;
216
217 for (i = 0; i < ARRAY_SIZE(status); i++) {
218 unsigned int stat = status[i];
219 if (!stat)
220 continue;
221
222 while (stat) {
223 int bit = __ffs(stat);
224 int line = i * 8 + bit;
225
226 handle_nested_irq(tc3589x_gpio->irq_base + line);
227 stat &= ~(1 << bit);
228 }
229
230 tc3589x_reg_write(tc3589x, TC3589x_GPIOIC0 + i, status[i]);
231 }
232
233 return IRQ_HANDLED;
234}
235
236static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio)
237{
238 int base = tc3589x_gpio->irq_base;
239 int irq;
240
241 for (irq = base; irq < base + tc3589x_gpio->chip.ngpio; irq++) {
242 set_irq_chip_data(irq, tc3589x_gpio);
243 set_irq_chip_and_handler(irq, &tc3589x_gpio_irq_chip,
244 handle_simple_irq);
245 set_irq_nested_thread(irq, 1);
246#ifdef CONFIG_ARM
247 set_irq_flags(irq, IRQF_VALID);
248#else
249 set_irq_noprobe(irq);
250#endif
251 }
252
253 return 0;
254}
255
256static void tc3589x_gpio_irq_remove(struct tc3589x_gpio *tc3589x_gpio)
257{
258 int base = tc3589x_gpio->irq_base;
259 int irq;
260
261 for (irq = base; irq < base + tc3589x_gpio->chip.ngpio; irq++) {
262#ifdef CONFIG_ARM
263 set_irq_flags(irq, 0);
264#endif
265 set_irq_chip_and_handler(irq, NULL, NULL);
266 set_irq_chip_data(irq, NULL);
267 }
268}
269
270static int __devinit tc3589x_gpio_probe(struct platform_device *pdev)
271{
272 struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent);
273 struct tc3589x_gpio_platform_data *pdata;
274 struct tc3589x_gpio *tc3589x_gpio;
275 int ret;
276 int irq;
277
278 pdata = tc3589x->pdata->gpio;
279 if (!pdata)
280 return -ENODEV;
281
282 irq = platform_get_irq(pdev, 0);
283 if (irq < 0)
284 return irq;
285
286 tc3589x_gpio = kzalloc(sizeof(struct tc3589x_gpio), GFP_KERNEL);
287 if (!tc3589x_gpio)
288 return -ENOMEM;
289
290 mutex_init(&tc3589x_gpio->irq_lock);
291
292 tc3589x_gpio->dev = &pdev->dev;
293 tc3589x_gpio->tc3589x = tc3589x;
294
295 tc3589x_gpio->chip = template_chip;
296 tc3589x_gpio->chip.ngpio = tc3589x->num_gpio;
297 tc3589x_gpio->chip.dev = &pdev->dev;
298 tc3589x_gpio->chip.base = pdata->gpio_base;
299
300 tc3589x_gpio->irq_base = tc3589x->irq_base + TC3589x_INT_GPIO(0);
301
302 /* Bring the GPIO module out of reset */
303 ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL,
304 TC3589x_RSTCTRL_GPIRST, 0);
305 if (ret < 0)
306 goto out_free;
307
308 ret = tc3589x_gpio_irq_init(tc3589x_gpio);
309 if (ret)
310 goto out_free;
311
312 ret = request_threaded_irq(irq, NULL, tc3589x_gpio_irq, IRQF_ONESHOT,
313 "tc3589x-gpio", tc3589x_gpio);
314 if (ret) {
315 dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
316 goto out_removeirq;
317 }
318
319 ret = gpiochip_add(&tc3589x_gpio->chip);
320 if (ret) {
321 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
322 goto out_freeirq;
323 }
324
325 if (pdata->setup)
326 pdata->setup(tc3589x, tc3589x_gpio->chip.base);
327
328 platform_set_drvdata(pdev, tc3589x_gpio);
329
330 return 0;
331
332out_freeirq:
333 free_irq(irq, tc3589x_gpio);
334out_removeirq:
335 tc3589x_gpio_irq_remove(tc3589x_gpio);
336out_free:
337 kfree(tc3589x_gpio);
338 return ret;
339}
340
341static int __devexit tc3589x_gpio_remove(struct platform_device *pdev)
342{
343 struct tc3589x_gpio *tc3589x_gpio = platform_get_drvdata(pdev);
344 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
345 struct tc3589x_gpio_platform_data *pdata = tc3589x->pdata->gpio;
346 int irq = platform_get_irq(pdev, 0);
347 int ret;
348
349 if (pdata->remove)
350 pdata->remove(tc3589x, tc3589x_gpio->chip.base);
351
352 ret = gpiochip_remove(&tc3589x_gpio->chip);
353 if (ret < 0) {
354 dev_err(tc3589x_gpio->dev,
355 "unable to remove gpiochip: %d\n", ret);
356 return ret;
357 }
358
359 free_irq(irq, tc3589x_gpio);
360 tc3589x_gpio_irq_remove(tc3589x_gpio);
361
362 platform_set_drvdata(pdev, NULL);
363 kfree(tc3589x_gpio);
364
365 return 0;
366}
367
368static struct platform_driver tc3589x_gpio_driver = {
369 .driver.name = "tc3589x-gpio",
370 .driver.owner = THIS_MODULE,
371 .probe = tc3589x_gpio_probe,
372 .remove = __devexit_p(tc3589x_gpio_remove),
373};
374
375static int __init tc3589x_gpio_init(void)
376{
377 return platform_driver_register(&tc3589x_gpio_driver);
378}
379subsys_initcall(tc3589x_gpio_init);
380
381static void __exit tc3589x_gpio_exit(void)
382{
383 platform_driver_unregister(&tc3589x_gpio_driver);
384}
385module_exit(tc3589x_gpio_exit);
386
387MODULE_LICENSE("GPL v2");
388MODULE_DESCRIPTION("TC3589x GPIO driver");
389MODULE_AUTHOR("Hanumath Prasad, Rabin Vincent");
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 3a87f3ba5f75..c76bd3183beb 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -459,6 +459,16 @@ config KEYBOARD_OMAP4
459 To compile this driver as a module, choose M here: the 459 To compile this driver as a module, choose M here: the
460 module will be called omap4-keypad. 460 module will be called omap4-keypad.
461 461
462config KEYBOARD_TC3589X
463 tristate "TC3589X Keypad support"
464 depends on MFD_TC3589X
465 help
466 Say Y here if you want to use the keypad controller on
467 TC35892/3 I/O expander.
468
469 To compile this driver as a module, choose M here: the
470 module will be called tc3589x-keypad.
471
462config KEYBOARD_TNETV107X 472config KEYBOARD_TNETV107X
463 tristate "TI TNETV107X keypad support" 473 tristate "TI TNETV107X keypad support"
464 depends on ARCH_DAVINCI_TNETV107X 474 depends on ARCH_DAVINCI_TNETV107X
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 622de73a445d..2aa6ce248b71 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o
41obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o 41obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o
42obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o 42obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o
43obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o 43obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o
44obj-$(CONFIG_KEYBOARD_TC3589X) += tc3589x-keypad.o
44obj-$(CONFIG_KEYBOARD_TNETV107X) += tnetv107x-keypad.o 45obj-$(CONFIG_KEYBOARD_TNETV107X) += tnetv107x-keypad.o
45obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o 46obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o
46obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o 47obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o
diff --git a/drivers/input/keyboard/tc3589x-keypad.c b/drivers/input/keyboard/tc3589x-keypad.c
new file mode 100644
index 000000000000..69dc0cb20a00
--- /dev/null
+++ b/drivers/input/keyboard/tc3589x-keypad.c
@@ -0,0 +1,472 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * Author: Jayeeta Banerjee <jayeeta.banerjee@stericsson.com>
5 * Author: Sundar Iyer <sundar.iyer@stericsson.com>
6 *
7 * License Terms: GNU General Public License, version 2
8 *
9 * TC35893 MFD Keypad Controller driver
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/interrupt.h>
15#include <linux/input.h>
16#include <linux/platform_device.h>
17#include <linux/input/matrix_keypad.h>
18#include <linux/i2c.h>
19#include <linux/slab.h>
20#include <linux/mfd/tc3589x.h>
21
22/* Maximum supported keypad matrix row/columns size */
23#define TC3589x_MAX_KPROW 8
24#define TC3589x_MAX_KPCOL 12
25
26/* keypad related Constants */
27#define TC3589x_MAX_DEBOUNCE_SETTLE 0xFF
28#define DEDICATED_KEY_VAL 0xFF
29
30/* Pull up/down masks */
31#define TC3589x_NO_PULL_MASK 0x0
32#define TC3589x_PULL_DOWN_MASK 0x1
33#define TC3589x_PULL_UP_MASK 0x2
34#define TC3589x_PULLUP_ALL_MASK 0xAA
35#define TC3589x_IO_PULL_VAL(index, mask) ((mask)<<((index)%4)*2))
36
37/* Bit masks for IOCFG register */
38#define IOCFG_BALLCFG 0x01
39#define IOCFG_IG 0x08
40
41#define KP_EVCODE_COL_MASK 0x0F
42#define KP_EVCODE_ROW_MASK 0x70
43#define KP_RELEASE_EVT_MASK 0x80
44
45#define KP_ROW_SHIFT 4
46
47#define KP_NO_VALID_KEY_MASK 0x7F
48
49/* bit masks for RESTCTRL register */
50#define TC3589x_KBDRST 0x2
51#define TC3589x_IRQRST 0x10
52#define TC3589x_RESET_ALL 0x1B
53
54/* KBDMFS register bit mask */
55#define TC3589x_KBDMFS_EN 0x1
56
57/* CLKEN register bitmask */
58#define KPD_CLK_EN 0x1
59
60/* RSTINTCLR register bit mask */
61#define IRQ_CLEAR 0x1
62
63/* bit masks for keyboard interrupts*/
64#define TC3589x_EVT_LOSS_INT 0x8
65#define TC3589x_EVT_INT 0x4
66#define TC3589x_KBD_LOSS_INT 0x2
67#define TC3589x_KBD_INT 0x1
68
69/* bit masks for keyboard interrupt clear*/
70#define TC3589x_EVT_INT_CLR 0x2
71#define TC3589x_KBD_INT_CLR 0x1
72
73#define TC3589x_KBD_KEYMAP_SIZE 64
74
75/**
76 * struct tc_keypad - data structure used by keypad driver
77 * @input: pointer to input device object
78 * @board: keypad platform device
79 * @krow: number of rows
80 * @kcol: number of coloumns
81 * @keymap: matrix scan code table for keycodes
82 */
83struct tc_keypad {
84 struct tc3589x *tc3589x;
85 struct input_dev *input;
86 const struct tc3589x_keypad_platform_data *board;
87 unsigned int krow;
88 unsigned int kcol;
89 unsigned short keymap[TC3589x_KBD_KEYMAP_SIZE];
90 bool keypad_stopped;
91};
92
93static int __devinit tc3589x_keypad_init_key_hardware(struct tc_keypad *keypad)
94{
95 int ret;
96 struct tc3589x *tc3589x = keypad->tc3589x;
97 u8 settle_time = keypad->board->settle_time;
98 u8 dbounce_period = keypad->board->debounce_period;
99 u8 rows = keypad->board->krow & 0xf; /* mask out the nibble */
100 u8 column = keypad->board->kcol & 0xf; /* mask out the nibble */
101
102 /* validate platform configurations */
103 if (keypad->board->kcol > TC3589x_MAX_KPCOL ||
104 keypad->board->krow > TC3589x_MAX_KPROW ||
105 keypad->board->debounce_period > TC3589x_MAX_DEBOUNCE_SETTLE ||
106 keypad->board->settle_time > TC3589x_MAX_DEBOUNCE_SETTLE)
107 return -EINVAL;
108
109 /* configure KBDSIZE 4 LSbits for cols and 4 MSbits for rows */
110 ret = tc3589x_reg_write(tc3589x, TC3589x_KBDSIZE,
111 (rows << KP_ROW_SHIFT) | column);
112 if (ret < 0)
113 return ret;
114
115 /* configure dedicated key config, no dedicated key selected */
116 ret = tc3589x_reg_write(tc3589x, TC3589x_KBCFG_LSB, DEDICATED_KEY_VAL);
117 if (ret < 0)
118 return ret;
119
120 ret = tc3589x_reg_write(tc3589x, TC3589x_KBCFG_MSB, DEDICATED_KEY_VAL);
121 if (ret < 0)
122 return ret;
123
124 /* Configure settle time */
125 ret = tc3589x_reg_write(tc3589x, TC3589x_KBDSETTLE_REG, settle_time);
126 if (ret < 0)
127 return ret;
128
129 /* Configure debounce time */
130 ret = tc3589x_reg_write(tc3589x, TC3589x_KBDBOUNCE, dbounce_period);
131 if (ret < 0)
132 return ret;
133
134 /* Start of initialise keypad GPIOs */
135 ret = tc3589x_set_bits(tc3589x, TC3589x_IOCFG, 0x0, IOCFG_IG);
136 if (ret < 0)
137 return ret;
138
139 /* Configure pull-up resistors for all row GPIOs */
140 ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG0_LSB,
141 TC3589x_PULLUP_ALL_MASK);
142 if (ret < 0)
143 return ret;
144
145 ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG0_MSB,
146 TC3589x_PULLUP_ALL_MASK);
147 if (ret < 0)
148 return ret;
149
150 /* Configure pull-up resistors for all column GPIOs */
151 ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG1_LSB,
152 TC3589x_PULLUP_ALL_MASK);
153 if (ret < 0)
154 return ret;
155
156 ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG1_MSB,
157 TC3589x_PULLUP_ALL_MASK);
158 if (ret < 0)
159 return ret;
160
161 ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG2_LSB,
162 TC3589x_PULLUP_ALL_MASK);
163
164 return ret;
165}
166
167#define TC35893_DATA_REGS 4
168#define TC35893_KEYCODE_FIFO_EMPTY 0x7f
169#define TC35893_KEYCODE_FIFO_CLEAR 0xff
170#define TC35893_KEYPAD_ROW_SHIFT 0x3
171
172static irqreturn_t tc3589x_keypad_irq(int irq, void *dev)
173{
174 struct tc_keypad *keypad = dev;
175 struct tc3589x *tc3589x = keypad->tc3589x;
176 u8 i, row_index, col_index, kbd_code, up;
177 u8 code;
178
179 for (i = 0; i < TC35893_DATA_REGS * 2; i++) {
180 kbd_code = tc3589x_reg_read(tc3589x, TC3589x_EVTCODE_FIFO);
181
182 /* loop till fifo is empty and no more keys are pressed */
183 if (kbd_code == TC35893_KEYCODE_FIFO_EMPTY ||
184 kbd_code == TC35893_KEYCODE_FIFO_CLEAR)
185 continue;
186
187 /* valid key is found */
188 col_index = kbd_code & KP_EVCODE_COL_MASK;
189 row_index = (kbd_code & KP_EVCODE_ROW_MASK) >> KP_ROW_SHIFT;
190 code = MATRIX_SCAN_CODE(row_index, col_index,
191 TC35893_KEYPAD_ROW_SHIFT);
192 up = kbd_code & KP_RELEASE_EVT_MASK;
193
194 input_event(keypad->input, EV_MSC, MSC_SCAN, code);
195 input_report_key(keypad->input, keypad->keymap[code], !up);
196 input_sync(keypad->input);
197 }
198
199 /* clear IRQ */
200 tc3589x_set_bits(tc3589x, TC3589x_KBDIC,
201 0x0, TC3589x_EVT_INT_CLR | TC3589x_KBD_INT_CLR);
202 /* enable IRQ */
203 tc3589x_set_bits(tc3589x, TC3589x_KBDMSK,
204 0x0, TC3589x_EVT_LOSS_INT | TC3589x_EVT_INT);
205
206 return IRQ_HANDLED;
207}
208
209static int tc3589x_keypad_enable(struct tc_keypad *keypad)
210{
211 struct tc3589x *tc3589x = keypad->tc3589x;
212 int ret;
213
214 /* pull the keypad module out of reset */
215 ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, TC3589x_KBDRST, 0x0);
216 if (ret < 0)
217 return ret;
218
219 /* configure KBDMFS */
220 ret = tc3589x_set_bits(tc3589x, TC3589x_KBDMFS, 0x0, TC3589x_KBDMFS_EN);
221 if (ret < 0)
222 return ret;
223
224 /* enable the keypad clock */
225 ret = tc3589x_set_bits(tc3589x, TC3589x_CLKEN, 0x0, KPD_CLK_EN);
226 if (ret < 0)
227 return ret;
228
229 /* clear pending IRQs */
230 ret = tc3589x_set_bits(tc3589x, TC3589x_RSTINTCLR, 0x0, 0x1);
231 if (ret < 0)
232 return ret;
233
234 /* enable the IRQs */
235 ret = tc3589x_set_bits(tc3589x, TC3589x_KBDMSK, 0x0,
236 TC3589x_EVT_LOSS_INT | TC3589x_EVT_INT);
237 if (ret < 0)
238 return ret;
239
240 keypad->keypad_stopped = false;
241
242 return ret;
243}
244
245static int tc3589x_keypad_disable(struct tc_keypad *keypad)
246{
247 struct tc3589x *tc3589x = keypad->tc3589x;
248 int ret;
249
250 /* clear IRQ */
251 ret = tc3589x_set_bits(tc3589x, TC3589x_KBDIC,
252 0x0, TC3589x_EVT_INT_CLR | TC3589x_KBD_INT_CLR);
253 if (ret < 0)
254 return ret;
255
256 /* disable all interrupts */
257 ret = tc3589x_set_bits(tc3589x, TC3589x_KBDMSK,
258 ~(TC3589x_EVT_LOSS_INT | TC3589x_EVT_INT), 0x0);
259 if (ret < 0)
260 return ret;
261
262 /* disable the keypad module */
263 ret = tc3589x_set_bits(tc3589x, TC3589x_CLKEN, 0x1, 0x0);
264 if (ret < 0)
265 return ret;
266
267 /* put the keypad module into reset */
268 ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, TC3589x_KBDRST, 0x1);
269
270 keypad->keypad_stopped = true;
271
272 return ret;
273}
274
275static int tc3589x_keypad_open(struct input_dev *input)
276{
277 int error;
278 struct tc_keypad *keypad = input_get_drvdata(input);
279
280 /* enable the keypad module */
281 error = tc3589x_keypad_enable(keypad);
282 if (error < 0) {
283 dev_err(&input->dev, "failed to enable keypad module\n");
284 return error;
285 }
286
287 error = tc3589x_keypad_init_key_hardware(keypad);
288 if (error < 0) {
289 dev_err(&input->dev, "failed to configure keypad module\n");
290 return error;
291 }
292
293 return 0;
294}
295
296static void tc3589x_keypad_close(struct input_dev *input)
297{
298 struct tc_keypad *keypad = input_get_drvdata(input);
299
300 /* disable the keypad module */
301 tc3589x_keypad_disable(keypad);
302}
303
304static int __devinit tc3589x_keypad_probe(struct platform_device *pdev)
305{
306 struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent);
307 struct tc_keypad *keypad;
308 struct input_dev *input;
309 const struct tc3589x_keypad_platform_data *plat;
310 int error, irq;
311
312 plat = tc3589x->pdata->keypad;
313 if (!plat) {
314 dev_err(&pdev->dev, "invalid keypad platform data\n");
315 return -EINVAL;
316 }
317
318 irq = platform_get_irq(pdev, 0);
319 if (irq < 0)
320 return irq;
321
322 keypad = kzalloc(sizeof(struct tc_keypad), GFP_KERNEL);
323 input = input_allocate_device();
324 if (!keypad || !input) {
325 dev_err(&pdev->dev, "failed to allocate keypad memory\n");
326 error = -ENOMEM;
327 goto err_free_mem;
328 }
329
330 keypad->board = plat;
331 keypad->input = input;
332 keypad->tc3589x = tc3589x;
333
334 input->id.bustype = BUS_I2C;
335 input->name = pdev->name;
336 input->dev.parent = &pdev->dev;
337
338 input->keycode = keypad->keymap;
339 input->keycodesize = sizeof(keypad->keymap[0]);
340 input->keycodemax = ARRAY_SIZE(keypad->keymap);
341
342 input->open = tc3589x_keypad_open;
343 input->close = tc3589x_keypad_close;
344
345 input_set_drvdata(input, keypad);
346
347 input_set_capability(input, EV_MSC, MSC_SCAN);
348
349 __set_bit(EV_KEY, input->evbit);
350 if (!plat->no_autorepeat)
351 __set_bit(EV_REP, input->evbit);
352
353 matrix_keypad_build_keymap(plat->keymap_data, 0x3,
354 input->keycode, input->keybit);
355
356 error = request_threaded_irq(irq, NULL,
357 tc3589x_keypad_irq, plat->irqtype,
358 "tc3589x-keypad", keypad);
359 if (error < 0) {
360 dev_err(&pdev->dev,
361 "Could not allocate irq %d,error %d\n",
362 irq, error);
363 goto err_free_mem;
364 }
365
366 error = input_register_device(input);
367 if (error) {
368 dev_err(&pdev->dev, "Could not register input device\n");
369 goto err_free_irq;
370 }
371
372 /* let platform decide if keypad is a wakeup source or not */
373 device_init_wakeup(&pdev->dev, plat->enable_wakeup);
374 device_set_wakeup_capable(&pdev->dev, plat->enable_wakeup);
375
376 platform_set_drvdata(pdev, keypad);
377
378 return 0;
379
380err_free_irq:
381 free_irq(irq, keypad);
382err_free_mem:
383 input_free_device(input);
384 kfree(keypad);
385 return error;
386}
387
388static int __devexit tc3589x_keypad_remove(struct platform_device *pdev)
389{
390 struct tc_keypad *keypad = platform_get_drvdata(pdev);
391 int irq = platform_get_irq(pdev, 0);
392
393 if (!keypad->keypad_stopped)
394 tc3589x_keypad_disable(keypad);
395
396 free_irq(irq, keypad);
397
398 input_unregister_device(keypad->input);
399
400 kfree(keypad);
401
402 return 0;
403}
404
405#ifdef CONFIG_PM
406static int tc3589x_keypad_suspend(struct device *dev)
407{
408 struct platform_device *pdev = to_platform_device(dev);
409 struct tc_keypad *keypad = platform_get_drvdata(pdev);
410 int irq = platform_get_irq(pdev, 0);
411
412 /* keypad is already off; we do nothing */
413 if (keypad->keypad_stopped)
414 return 0;
415
416 /* if device is not a wakeup source, disable it for powersave */
417 if (!device_may_wakeup(&pdev->dev))
418 tc3589x_keypad_disable(keypad);
419 else
420 enable_irq_wake(irq);
421
422 return 0;
423}
424
425static int tc3589x_keypad_resume(struct device *dev)
426{
427 struct platform_device *pdev = to_platform_device(dev);
428 struct tc_keypad *keypad = platform_get_drvdata(pdev);
429 int irq = platform_get_irq(pdev, 0);
430
431 if (!keypad->keypad_stopped)
432 return 0;
433
434 /* enable the device to resume normal operations */
435 if (!device_may_wakeup(&pdev->dev))
436 tc3589x_keypad_enable(keypad);
437 else
438 disable_irq_wake(irq);
439
440 return 0;
441}
442
443static const SIMPLE_DEV_PM_OPS(tc3589x_keypad_dev_pm_ops,
444 tc3589x_keypad_suspend, tc3589x_keypad_resume);
445#endif
446
447static struct platform_driver tc3589x_keypad_driver = {
448 .driver.name = "tc3589x-keypad",
449 .driver.owner = THIS_MODULE,
450#ifdef CONFIG_PM
451 .driver.pm = &tc3589x_keypad_dev_pm_ops,
452#endif
453 .probe = tc3589x_keypad_probe,
454 .remove = __devexit_p(tc3589x_keypad_remove),
455};
456
457static int __init tc3589x_keypad_init(void)
458{
459 return platform_driver_register(&tc3589x_keypad_driver);
460}
461module_init(tc3589x_keypad_init);
462
463static void __exit tc3589x_keypad_exit(void)
464{
465 return platform_driver_unregister(&tc3589x_keypad_driver);
466}
467module_exit(tc3589x_keypad_exit);
468
469MODULE_LICENSE("GPL v2");
470MODULE_AUTHOR("Jayeeta Banerjee/Sundar Iyer");
471MODULE_DESCRIPTION("TC35893 Keypad Driver");
472MODULE_ALIAS("platform:tc3589x-keypad")
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 3a1493b8b5e5..e8e704f52746 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -218,12 +218,12 @@ config MFD_STMPE
218 Keypad: stmpe-keypad 218 Keypad: stmpe-keypad
219 Touchscreen: stmpe-ts 219 Touchscreen: stmpe-ts
220 220
221config MFD_TC35892 221config MFD_TC3589X
222 bool "Support Toshiba TC35892" 222 bool "Support Toshiba TC35892 and variants"
223 depends on I2C=y && GENERIC_HARDIRQS 223 depends on I2C=y && GENERIC_HARDIRQS
224 select MFD_CORE 224 select MFD_CORE
225 help 225 help
226 Support for the Toshiba TC35892 I/O Expander. 226 Support for the Toshiba TC35892 and variants I/O Expander.
227 227
228 This driver provides common support for accessing the device, 228 This driver provides common support for accessing the device,
229 additional drivers must be enabled in order to use the 229 additional drivers must be enabled in order to use the
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index f54b3659abbb..e590d1e44cf0 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -16,7 +16,7 @@ obj-$(CONFIG_MFD_DAVINCI_VOICECODEC) += davinci_voicecodec.o
16obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o 16obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o
17 17
18obj-$(CONFIG_MFD_STMPE) += stmpe.o 18obj-$(CONFIG_MFD_STMPE) += stmpe.o
19obj-$(CONFIG_MFD_TC35892) += tc35892.o 19obj-$(CONFIG_MFD_TC3589X) += tc3589x.o
20obj-$(CONFIG_MFD_T7L66XB) += t7l66xb.o tmio_core.o 20obj-$(CONFIG_MFD_T7L66XB) += t7l66xb.o tmio_core.o
21obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o tmio_core.o 21obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o tmio_core.o
22obj-$(CONFIG_MFD_TC6393XB) += tc6393xb.o tmio_core.o 22obj-$(CONFIG_MFD_TC6393XB) += tc6393xb.o tmio_core.o
diff --git a/drivers/mfd/tc35892.c b/drivers/mfd/tc35892.c
deleted file mode 100644
index e619e2a55997..000000000000
--- a/drivers/mfd/tc35892.c
+++ /dev/null
@@ -1,345 +0,0 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Hanumath Prasad <hanumath.prasad@stericsson.com> for ST-Ericsson
6 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
7 */
8
9#include <linux/module.h>
10#include <linux/interrupt.h>
11#include <linux/irq.h>
12#include <linux/slab.h>
13#include <linux/i2c.h>
14#include <linux/mfd/core.h>
15#include <linux/mfd/tc35892.h>
16
17/**
18 * tc35892_reg_read() - read a single TC35892 register
19 * @tc35892: Device to read from
20 * @reg: Register to read
21 */
22int tc35892_reg_read(struct tc35892 *tc35892, u8 reg)
23{
24 int ret;
25
26 ret = i2c_smbus_read_byte_data(tc35892->i2c, reg);
27 if (ret < 0)
28 dev_err(tc35892->dev, "failed to read reg %#x: %d\n",
29 reg, ret);
30
31 return ret;
32}
33EXPORT_SYMBOL_GPL(tc35892_reg_read);
34
35/**
36 * tc35892_reg_read() - write a single TC35892 register
37 * @tc35892: Device to write to
38 * @reg: Register to read
39 * @data: Value to write
40 */
41int tc35892_reg_write(struct tc35892 *tc35892, u8 reg, u8 data)
42{
43 int ret;
44
45 ret = i2c_smbus_write_byte_data(tc35892->i2c, reg, data);
46 if (ret < 0)
47 dev_err(tc35892->dev, "failed to write reg %#x: %d\n",
48 reg, ret);
49
50 return ret;
51}
52EXPORT_SYMBOL_GPL(tc35892_reg_write);
53
54/**
55 * tc35892_block_read() - read multiple TC35892 registers
56 * @tc35892: Device to read from
57 * @reg: First register
58 * @length: Number of registers
59 * @values: Buffer to write to
60 */
61int tc35892_block_read(struct tc35892 *tc35892, u8 reg, u8 length, u8 *values)
62{
63 int ret;
64
65 ret = i2c_smbus_read_i2c_block_data(tc35892->i2c, reg, length, values);
66 if (ret < 0)
67 dev_err(tc35892->dev, "failed to read regs %#x: %d\n",
68 reg, ret);
69
70 return ret;
71}
72EXPORT_SYMBOL_GPL(tc35892_block_read);
73
74/**
75 * tc35892_block_write() - write multiple TC35892 registers
76 * @tc35892: Device to write to
77 * @reg: First register
78 * @length: Number of registers
79 * @values: Values to write
80 */
81int tc35892_block_write(struct tc35892 *tc35892, u8 reg, u8 length,
82 const u8 *values)
83{
84 int ret;
85
86 ret = i2c_smbus_write_i2c_block_data(tc35892->i2c, reg, length,
87 values);
88 if (ret < 0)
89 dev_err(tc35892->dev, "failed to write regs %#x: %d\n",
90 reg, ret);
91
92 return ret;
93}
94EXPORT_SYMBOL_GPL(tc35892_block_write);
95
96/**
97 * tc35892_set_bits() - set the value of a bitfield in a TC35892 register
98 * @tc35892: Device to write to
99 * @reg: Register to write
100 * @mask: Mask of bits to set
101 * @values: Value to set
102 */
103int tc35892_set_bits(struct tc35892 *tc35892, u8 reg, u8 mask, u8 val)
104{
105 int ret;
106
107 mutex_lock(&tc35892->lock);
108
109 ret = tc35892_reg_read(tc35892, reg);
110 if (ret < 0)
111 goto out;
112
113 ret &= ~mask;
114 ret |= val;
115
116 ret = tc35892_reg_write(tc35892, reg, ret);
117
118out:
119 mutex_unlock(&tc35892->lock);
120 return ret;
121}
122EXPORT_SYMBOL_GPL(tc35892_set_bits);
123
124static struct resource gpio_resources[] = {
125 {
126 .start = TC35892_INT_GPIIRQ,
127 .end = TC35892_INT_GPIIRQ,
128 .flags = IORESOURCE_IRQ,
129 },
130};
131
132static struct mfd_cell tc35892_devs[] = {
133 {
134 .name = "tc35892-gpio",
135 .num_resources = ARRAY_SIZE(gpio_resources),
136 .resources = &gpio_resources[0],
137 },
138};
139
140static irqreturn_t tc35892_irq(int irq, void *data)
141{
142 struct tc35892 *tc35892 = data;
143 int status;
144
145 status = tc35892_reg_read(tc35892, TC35892_IRQST);
146 if (status < 0)
147 return IRQ_NONE;
148
149 while (status) {
150 int bit = __ffs(status);
151
152 handle_nested_irq(tc35892->irq_base + bit);
153 status &= ~(1 << bit);
154 }
155
156 /*
157 * A dummy read or write (to any register) appears to be necessary to
158 * have the last interrupt clear (for example, GPIO IC write) take
159 * effect.
160 */
161 tc35892_reg_read(tc35892, TC35892_IRQST);
162
163 return IRQ_HANDLED;
164}
165
166static void tc35892_irq_dummy(unsigned int irq)
167{
168 /* No mask/unmask at this level */
169}
170
171static struct irq_chip tc35892_irq_chip = {
172 .name = "tc35892",
173 .mask = tc35892_irq_dummy,
174 .unmask = tc35892_irq_dummy,
175};
176
177static int tc35892_irq_init(struct tc35892 *tc35892)
178{
179 int base = tc35892->irq_base;
180 int irq;
181
182 for (irq = base; irq < base + TC35892_NR_INTERNAL_IRQS; irq++) {
183 set_irq_chip_data(irq, tc35892);
184 set_irq_chip_and_handler(irq, &tc35892_irq_chip,
185 handle_edge_irq);
186 set_irq_nested_thread(irq, 1);
187#ifdef CONFIG_ARM
188 set_irq_flags(irq, IRQF_VALID);
189#else
190 set_irq_noprobe(irq);
191#endif
192 }
193
194 return 0;
195}
196
197static void tc35892_irq_remove(struct tc35892 *tc35892)
198{
199 int base = tc35892->irq_base;
200 int irq;
201
202 for (irq = base; irq < base + TC35892_NR_INTERNAL_IRQS; irq++) {
203#ifdef CONFIG_ARM
204 set_irq_flags(irq, 0);
205#endif
206 set_irq_chip_and_handler(irq, NULL, NULL);
207 set_irq_chip_data(irq, NULL);
208 }
209}
210
211static int tc35892_chip_init(struct tc35892 *tc35892)
212{
213 int manf, ver, ret;
214
215 manf = tc35892_reg_read(tc35892, TC35892_MANFCODE);
216 if (manf < 0)
217 return manf;
218
219 ver = tc35892_reg_read(tc35892, TC35892_VERSION);
220 if (ver < 0)
221 return ver;
222
223 if (manf != TC35892_MANFCODE_MAGIC) {
224 dev_err(tc35892->dev, "unknown manufacturer: %#x\n", manf);
225 return -EINVAL;
226 }
227
228 dev_info(tc35892->dev, "manufacturer: %#x, version: %#x\n", manf, ver);
229
230 /* Put everything except the IRQ module into reset */
231 ret = tc35892_reg_write(tc35892, TC35892_RSTCTRL,
232 TC35892_RSTCTRL_TIMRST
233 | TC35892_RSTCTRL_ROTRST
234 | TC35892_RSTCTRL_KBDRST
235 | TC35892_RSTCTRL_GPIRST);
236 if (ret < 0)
237 return ret;
238
239 /* Clear the reset interrupt. */
240 return tc35892_reg_write(tc35892, TC35892_RSTINTCLR, 0x1);
241}
242
243static int __devinit tc35892_probe(struct i2c_client *i2c,
244 const struct i2c_device_id *id)
245{
246 struct tc35892_platform_data *pdata = i2c->dev.platform_data;
247 struct tc35892 *tc35892;
248 int ret;
249
250 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA
251 | I2C_FUNC_SMBUS_I2C_BLOCK))
252 return -EIO;
253
254 tc35892 = kzalloc(sizeof(struct tc35892), GFP_KERNEL);
255 if (!tc35892)
256 return -ENOMEM;
257
258 mutex_init(&tc35892->lock);
259
260 tc35892->dev = &i2c->dev;
261 tc35892->i2c = i2c;
262 tc35892->pdata = pdata;
263 tc35892->irq_base = pdata->irq_base;
264 tc35892->num_gpio = id->driver_data;
265
266 i2c_set_clientdata(i2c, tc35892);
267
268 ret = tc35892_chip_init(tc35892);
269 if (ret)
270 goto out_free;
271
272 ret = tc35892_irq_init(tc35892);
273 if (ret)
274 goto out_free;
275
276 ret = request_threaded_irq(tc35892->i2c->irq, NULL, tc35892_irq,
277 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
278 "tc35892", tc35892);
279 if (ret) {
280 dev_err(tc35892->dev, "failed to request IRQ: %d\n", ret);
281 goto out_removeirq;
282 }
283
284 ret = mfd_add_devices(tc35892->dev, -1, tc35892_devs,
285 ARRAY_SIZE(tc35892_devs), NULL,
286 tc35892->irq_base);
287 if (ret) {
288 dev_err(tc35892->dev, "failed to add children\n");
289 goto out_freeirq;
290 }
291
292 return 0;
293
294out_freeirq:
295 free_irq(tc35892->i2c->irq, tc35892);
296out_removeirq:
297 tc35892_irq_remove(tc35892);
298out_free:
299 kfree(tc35892);
300 return ret;
301}
302
303static int __devexit tc35892_remove(struct i2c_client *client)
304{
305 struct tc35892 *tc35892 = i2c_get_clientdata(client);
306
307 mfd_remove_devices(tc35892->dev);
308
309 free_irq(tc35892->i2c->irq, tc35892);
310 tc35892_irq_remove(tc35892);
311
312 kfree(tc35892);
313
314 return 0;
315}
316
317static const struct i2c_device_id tc35892_id[] = {
318 { "tc35892", 24 },
319 { }
320};
321MODULE_DEVICE_TABLE(i2c, tc35892_id);
322
323static struct i2c_driver tc35892_driver = {
324 .driver.name = "tc35892",
325 .driver.owner = THIS_MODULE,
326 .probe = tc35892_probe,
327 .remove = __devexit_p(tc35892_remove),
328 .id_table = tc35892_id,
329};
330
331static int __init tc35892_init(void)
332{
333 return i2c_add_driver(&tc35892_driver);
334}
335subsys_initcall(tc35892_init);
336
337static void __exit tc35892_exit(void)
338{
339 i2c_del_driver(&tc35892_driver);
340}
341module_exit(tc35892_exit);
342
343MODULE_LICENSE("GPL v2");
344MODULE_DESCRIPTION("TC35892 MFD core driver");
345MODULE_AUTHOR("Hanumath Prasad, Rabin Vincent");
diff --git a/drivers/mfd/tc3589x.c b/drivers/mfd/tc3589x.c
new file mode 100644
index 000000000000..729dbeed2ce0
--- /dev/null
+++ b/drivers/mfd/tc3589x.c
@@ -0,0 +1,422 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Hanumath Prasad <hanumath.prasad@stericsson.com> for ST-Ericsson
6 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
7 */
8
9#include <linux/module.h>
10#include <linux/interrupt.h>
11#include <linux/irq.h>
12#include <linux/slab.h>
13#include <linux/i2c.h>
14#include <linux/mfd/core.h>
15#include <linux/mfd/tc3589x.h>
16
17#define TC3589x_CLKMODE_MODCTL_SLEEP 0x0
18#define TC3589x_CLKMODE_MODCTL_OPERATION (1 << 0)
19
20/**
21 * tc3589x_reg_read() - read a single TC3589x register
22 * @tc3589x: Device to read from
23 * @reg: Register to read
24 */
25int tc3589x_reg_read(struct tc3589x *tc3589x, u8 reg)
26{
27 int ret;
28
29 ret = i2c_smbus_read_byte_data(tc3589x->i2c, reg);
30 if (ret < 0)
31 dev_err(tc3589x->dev, "failed to read reg %#x: %d\n",
32 reg, ret);
33
34 return ret;
35}
36EXPORT_SYMBOL_GPL(tc3589x_reg_read);
37
38/**
39 * tc3589x_reg_read() - write a single TC3589x register
40 * @tc3589x: Device to write to
41 * @reg: Register to read
42 * @data: Value to write
43 */
44int tc3589x_reg_write(struct tc3589x *tc3589x, u8 reg, u8 data)
45{
46 int ret;
47
48 ret = i2c_smbus_write_byte_data(tc3589x->i2c, reg, data);
49 if (ret < 0)
50 dev_err(tc3589x->dev, "failed to write reg %#x: %d\n",
51 reg, ret);
52
53 return ret;
54}
55EXPORT_SYMBOL_GPL(tc3589x_reg_write);
56
57/**
58 * tc3589x_block_read() - read multiple TC3589x registers
59 * @tc3589x: Device to read from
60 * @reg: First register
61 * @length: Number of registers
62 * @values: Buffer to write to
63 */
64int tc3589x_block_read(struct tc3589x *tc3589x, u8 reg, u8 length, u8 *values)
65{
66 int ret;
67
68 ret = i2c_smbus_read_i2c_block_data(tc3589x->i2c, reg, length, values);
69 if (ret < 0)
70 dev_err(tc3589x->dev, "failed to read regs %#x: %d\n",
71 reg, ret);
72
73 return ret;
74}
75EXPORT_SYMBOL_GPL(tc3589x_block_read);
76
77/**
78 * tc3589x_block_write() - write multiple TC3589x registers
79 * @tc3589x: Device to write to
80 * @reg: First register
81 * @length: Number of registers
82 * @values: Values to write
83 */
84int tc3589x_block_write(struct tc3589x *tc3589x, u8 reg, u8 length,
85 const u8 *values)
86{
87 int ret;
88
89 ret = i2c_smbus_write_i2c_block_data(tc3589x->i2c, reg, length,
90 values);
91 if (ret < 0)
92 dev_err(tc3589x->dev, "failed to write regs %#x: %d\n",
93 reg, ret);
94
95 return ret;
96}
97EXPORT_SYMBOL_GPL(tc3589x_block_write);
98
99/**
100 * tc3589x_set_bits() - set the value of a bitfield in a TC3589x register
101 * @tc3589x: Device to write to
102 * @reg: Register to write
103 * @mask: Mask of bits to set
104 * @values: Value to set
105 */
106int tc3589x_set_bits(struct tc3589x *tc3589x, u8 reg, u8 mask, u8 val)
107{
108 int ret;
109
110 mutex_lock(&tc3589x->lock);
111
112 ret = tc3589x_reg_read(tc3589x, reg);
113 if (ret < 0)
114 goto out;
115
116 ret &= ~mask;
117 ret |= val;
118
119 ret = tc3589x_reg_write(tc3589x, reg, ret);
120
121out:
122 mutex_unlock(&tc3589x->lock);
123 return ret;
124}
125EXPORT_SYMBOL_GPL(tc3589x_set_bits);
126
127static struct resource gpio_resources[] = {
128 {
129 .start = TC3589x_INT_GPIIRQ,
130 .end = TC3589x_INT_GPIIRQ,
131 .flags = IORESOURCE_IRQ,
132 },
133};
134
135static struct resource keypad_resources[] = {
136 {
137 .start = TC3589x_INT_KBDIRQ,
138 .end = TC3589x_INT_KBDIRQ,
139 .flags = IORESOURCE_IRQ,
140 },
141};
142
143static struct mfd_cell tc3589x_dev_gpio[] = {
144 {
145 .name = "tc3589x-gpio",
146 .num_resources = ARRAY_SIZE(gpio_resources),
147 .resources = &gpio_resources[0],
148 },
149};
150
151static struct mfd_cell tc3589x_dev_keypad[] = {
152 {
153 .name = "tc3589x-keypad",
154 .num_resources = ARRAY_SIZE(keypad_resources),
155 .resources = &keypad_resources[0],
156 },
157};
158
159static irqreturn_t tc3589x_irq(int irq, void *data)
160{
161 struct tc3589x *tc3589x = data;
162 int status;
163
164again:
165 status = tc3589x_reg_read(tc3589x, TC3589x_IRQST);
166 if (status < 0)
167 return IRQ_NONE;
168
169 while (status) {
170 int bit = __ffs(status);
171
172 handle_nested_irq(tc3589x->irq_base + bit);
173 status &= ~(1 << bit);
174 }
175
176 /*
177 * A dummy read or write (to any register) appears to be necessary to
178 * have the last interrupt clear (for example, GPIO IC write) take
179 * effect. In such a case, recheck for any interrupt which is still
180 * pending.
181 */
182 status = tc3589x_reg_read(tc3589x, TC3589x_IRQST);
183 if (status)
184 goto again;
185
186 return IRQ_HANDLED;
187}
188
189static int tc3589x_irq_init(struct tc3589x *tc3589x)
190{
191 int base = tc3589x->irq_base;
192 int irq;
193
194 for (irq = base; irq < base + TC3589x_NR_INTERNAL_IRQS; irq++) {
195 set_irq_chip_data(irq, tc3589x);
196 set_irq_chip_and_handler(irq, &dummy_irq_chip,
197 handle_edge_irq);
198 set_irq_nested_thread(irq, 1);
199#ifdef CONFIG_ARM
200 set_irq_flags(irq, IRQF_VALID);
201#else
202 set_irq_noprobe(irq);
203#endif
204 }
205
206 return 0;
207}
208
209static void tc3589x_irq_remove(struct tc3589x *tc3589x)
210{
211 int base = tc3589x->irq_base;
212 int irq;
213
214 for (irq = base; irq < base + TC3589x_NR_INTERNAL_IRQS; irq++) {
215#ifdef CONFIG_ARM
216 set_irq_flags(irq, 0);
217#endif
218 set_irq_chip_and_handler(irq, NULL, NULL);
219 set_irq_chip_data(irq, NULL);
220 }
221}
222
223static int tc3589x_chip_init(struct tc3589x *tc3589x)
224{
225 int manf, ver, ret;
226
227 manf = tc3589x_reg_read(tc3589x, TC3589x_MANFCODE);
228 if (manf < 0)
229 return manf;
230
231 ver = tc3589x_reg_read(tc3589x, TC3589x_VERSION);
232 if (ver < 0)
233 return ver;
234
235 if (manf != TC3589x_MANFCODE_MAGIC) {
236 dev_err(tc3589x->dev, "unknown manufacturer: %#x\n", manf);
237 return -EINVAL;
238 }
239
240 dev_info(tc3589x->dev, "manufacturer: %#x, version: %#x\n", manf, ver);
241
242 /*
243 * Put everything except the IRQ module into reset;
244 * also spare the GPIO module for any pin initialization
245 * done during pre-kernel boot
246 */
247 ret = tc3589x_reg_write(tc3589x, TC3589x_RSTCTRL,
248 TC3589x_RSTCTRL_TIMRST
249 | TC3589x_RSTCTRL_ROTRST
250 | TC3589x_RSTCTRL_KBDRST);
251 if (ret < 0)
252 return ret;
253
254 /* Clear the reset interrupt. */
255 return tc3589x_reg_write(tc3589x, TC3589x_RSTINTCLR, 0x1);
256}
257
258static int __devinit tc3589x_device_init(struct tc3589x *tc3589x)
259{
260 int ret = 0;
261 unsigned int blocks = tc3589x->pdata->block;
262
263 if (blocks & TC3589x_BLOCK_GPIO) {
264 ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_gpio,
265 ARRAY_SIZE(tc3589x_dev_gpio), NULL,
266 tc3589x->irq_base);
267 if (ret) {
268 dev_err(tc3589x->dev, "failed to add gpio child\n");
269 return ret;
270 }
271 dev_info(tc3589x->dev, "added gpio block\n");
272 }
273
274 if (blocks & TC3589x_BLOCK_KEYPAD) {
275 ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_keypad,
276 ARRAY_SIZE(tc3589x_dev_keypad), NULL,
277 tc3589x->irq_base);
278 if (ret) {
279 dev_err(tc3589x->dev, "failed to keypad child\n");
280 return ret;
281 }
282 dev_info(tc3589x->dev, "added keypad block\n");
283 }
284
285 return ret;
286}
287
288static int __devinit tc3589x_probe(struct i2c_client *i2c,
289 const struct i2c_device_id *id)
290{
291 struct tc3589x_platform_data *pdata = i2c->dev.platform_data;
292 struct tc3589x *tc3589x;
293 int ret;
294
295 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA
296 | I2C_FUNC_SMBUS_I2C_BLOCK))
297 return -EIO;
298
299 tc3589x = kzalloc(sizeof(struct tc3589x), GFP_KERNEL);
300 if (!tc3589x)
301 return -ENOMEM;
302
303 mutex_init(&tc3589x->lock);
304
305 tc3589x->dev = &i2c->dev;
306 tc3589x->i2c = i2c;
307 tc3589x->pdata = pdata;
308 tc3589x->irq_base = pdata->irq_base;
309 tc3589x->num_gpio = id->driver_data;
310
311 i2c_set_clientdata(i2c, tc3589x);
312
313 ret = tc3589x_chip_init(tc3589x);
314 if (ret)
315 goto out_free;
316
317 ret = tc3589x_irq_init(tc3589x);
318 if (ret)
319 goto out_free;
320
321 ret = request_threaded_irq(tc3589x->i2c->irq, NULL, tc3589x_irq,
322 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
323 "tc3589x", tc3589x);
324 if (ret) {
325 dev_err(tc3589x->dev, "failed to request IRQ: %d\n", ret);
326 goto out_removeirq;
327 }
328
329 ret = tc3589x_device_init(tc3589x);
330 if (ret) {
331 dev_err(tc3589x->dev, "failed to add child devices\n");
332 goto out_freeirq;
333 }
334
335 return 0;
336
337out_freeirq:
338 free_irq(tc3589x->i2c->irq, tc3589x);
339out_removeirq:
340 tc3589x_irq_remove(tc3589x);
341out_free:
342 kfree(tc3589x);
343 return ret;
344}
345
346static int __devexit tc3589x_remove(struct i2c_client *client)
347{
348 struct tc3589x *tc3589x = i2c_get_clientdata(client);
349
350 mfd_remove_devices(tc3589x->dev);
351
352 free_irq(tc3589x->i2c->irq, tc3589x);
353 tc3589x_irq_remove(tc3589x);
354
355 kfree(tc3589x);
356
357 return 0;
358}
359
360static int tc3589x_suspend(struct device *dev)
361{
362 struct tc3589x *tc3589x = dev_get_drvdata(dev);
363 struct i2c_client *client = tc3589x->i2c;
364 int ret = 0;
365
366 /* put the system to sleep mode */
367 if (!device_may_wakeup(&client->dev))
368 ret = tc3589x_reg_write(tc3589x, TC3589x_CLKMODE,
369 TC3589x_CLKMODE_MODCTL_SLEEP);
370
371 return ret;
372}
373
374static int tc3589x_resume(struct device *dev)
375{
376 struct tc3589x *tc3589x = dev_get_drvdata(dev);
377 struct i2c_client *client = tc3589x->i2c;
378 int ret = 0;
379
380 /* enable the system into operation */
381 if (!device_may_wakeup(&client->dev))
382 ret = tc3589x_reg_write(tc3589x, TC3589x_CLKMODE,
383 TC3589x_CLKMODE_MODCTL_OPERATION);
384
385 return ret;
386}
387
388static const SIMPLE_DEV_PM_OPS(tc3589x_dev_pm_ops, tc3589x_suspend,
389 tc3589x_resume);
390
391static const struct i2c_device_id tc3589x_id[] = {
392 { "tc3589x", 24 },
393 { }
394};
395MODULE_DEVICE_TABLE(i2c, tc3589x_id);
396
397static struct i2c_driver tc3589x_driver = {
398 .driver.name = "tc3589x",
399 .driver.owner = THIS_MODULE,
400#ifdef CONFIG_PM
401 .driver.pm = &tc3589x_dev_pm_ops,
402#endif
403 .probe = tc3589x_probe,
404 .remove = __devexit_p(tc3589x_remove),
405 .id_table = tc3589x_id,
406};
407
408static int __init tc3589x_init(void)
409{
410 return i2c_add_driver(&tc3589x_driver);
411}
412subsys_initcall(tc3589x_init);
413
414static void __exit tc3589x_exit(void)
415{
416 i2c_del_driver(&tc3589x_driver);
417}
418module_exit(tc3589x_exit);
419
420MODULE_LICENSE("GPL v2");
421MODULE_DESCRIPTION("TC3589x MFD core driver");
422MODULE_AUTHOR("Hanumath Prasad, Rabin Vincent");
diff --git a/drivers/net/caif/caif_shm_u5500.c b/drivers/net/caif/caif_shm_u5500.c
index 32b1c6fb2de1..5f771ab712c4 100644
--- a/drivers/net/caif/caif_shm_u5500.c
+++ b/drivers/net/caif/caif_shm_u5500.c
@@ -11,7 +11,7 @@
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/netdevice.h> 13#include <linux/netdevice.h>
14#include <mach/mbox.h> 14#include <mach/mbox-db5500.h>
15#include <net/caif/caif_shm.h> 15#include <net/caif/caif_shm.h>
16 16
17MODULE_LICENSE("GPL"); 17MODULE_LICENSE("GPL");