aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/Kconfig16
-rw-r--r--drivers/mfd/Makefile2
-rw-r--r--drivers/mfd/da903x.c563
-rw-r--r--drivers/mfd/htc-egpio.c2
-rw-r--r--drivers/mfd/mfd-core.c15
-rw-r--r--drivers/mfd/sm501.c6
-rw-r--r--drivers/mfd/t7l66xb.c40
-rw-r--r--drivers/mfd/tc6387xb.c47
-rw-r--r--drivers/mfd/tc6393xb.c296
-rw-r--r--drivers/mfd/twl4030-core.c1193
-rw-r--r--drivers/mfd/wm8350-core.c2
11 files changed, 2100 insertions, 82 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 5eff8ad834d6..5a79d2d4cdae 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -52,6 +52,8 @@ config HTC_PASIC3
52 52
53config UCB1400_CORE 53config UCB1400_CORE
54 tristate "Philips UCB1400 Core driver" 54 tristate "Philips UCB1400 Core driver"
55 depends on AC97_BUS
56 depends on GPIOLIB
55 help 57 help
56 This enables support for the Philips UCB1400 core functions. 58 This enables support for the Philips UCB1400 core functions.
57 The UCB1400 is an AC97 audio codec. 59 The UCB1400 is an AC97 audio codec.
@@ -59,6 +61,20 @@ config UCB1400_CORE
59 To compile this driver as a module, choose M here: the 61 To compile this driver as a module, choose M here: the
60 module will be called ucb1400_core. 62 module will be called ucb1400_core.
61 63
64config TWL4030_CORE
65 bool "Texas Instruments TWL4030/TPS659x0 Support"
66 depends on I2C=y && GENERIC_HARDIRQS && (ARCH_OMAP2 || ARCH_OMAP3)
67 help
68 Say yes here if you have TWL4030 family chip on your board.
69 This core driver provides register access and IRQ handling
70 facilities, and registers devices for the various functions
71 so that function-specific drivers can bind to them.
72
73 These multi-function chips are found on many OMAP2 and OMAP3
74 boards, providing power management, RTC, GPIO, keypad, a
75 high speed USB OTG transceiver, an audio codec (on most
76 versions) and many other features.
77
62config MFD_TMIO 78config MFD_TMIO
63 bool 79 bool
64 default n 80 default n
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 759b1fe1c891..68e237b830ad 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -17,6 +17,8 @@ wm8350-objs := wm8350-core.o wm8350-regmap.o wm8350-gpio.o
17obj-$(CONFIG_MFD_WM8350) += wm8350.o 17obj-$(CONFIG_MFD_WM8350) += wm8350.o
18obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o 18obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o
19 19
20obj-$(CONFIG_TWL4030_CORE) += twl4030-core.o
21
20obj-$(CONFIG_MFD_CORE) += mfd-core.o 22obj-$(CONFIG_MFD_CORE) += mfd-core.o
21 23
22obj-$(CONFIG_MCP) += mcp-core.o 24obj-$(CONFIG_MCP) += mcp-core.o
diff --git a/drivers/mfd/da903x.c b/drivers/mfd/da903x.c
new file mode 100644
index 000000000000..b57326ae464d
--- /dev/null
+++ b/drivers/mfd/da903x.c
@@ -0,0 +1,563 @@
1/*
2 * Base driver for Dialog Semiconductor DA9030/DA9034
3 *
4 * Copyright (C) 2008 Compulab, Ltd.
5 * Mike Rapoport <mike@compulab.co.il>
6 *
7 * Copyright (C) 2006-2008 Marvell International Ltd.
8 * Eric Miao <eric.miao@marvell.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/interrupt.h>
18#include <linux/platform_device.h>
19#include <linux/i2c.h>
20#include <linux/mfd/da903x.h>
21
22#define DA9030_CHIP_ID 0x00
23#define DA9030_EVENT_A 0x01
24#define DA9030_EVENT_B 0x02
25#define DA9030_EVENT_C 0x03
26#define DA9030_STATUS 0x04
27#define DA9030_IRQ_MASK_A 0x05
28#define DA9030_IRQ_MASK_B 0x06
29#define DA9030_IRQ_MASK_C 0x07
30#define DA9030_SYS_CTRL_A 0x08
31#define DA9030_SYS_CTRL_B 0x09
32#define DA9030_FAULT_LOG 0x0a
33
34#define DA9034_CHIP_ID 0x00
35#define DA9034_EVENT_A 0x01
36#define DA9034_EVENT_B 0x02
37#define DA9034_EVENT_C 0x03
38#define DA9034_EVENT_D 0x04
39#define DA9034_STATUS_A 0x05
40#define DA9034_STATUS_B 0x06
41#define DA9034_IRQ_MASK_A 0x07
42#define DA9034_IRQ_MASK_B 0x08
43#define DA9034_IRQ_MASK_C 0x09
44#define DA9034_IRQ_MASK_D 0x0a
45#define DA9034_SYS_CTRL_A 0x0b
46#define DA9034_SYS_CTRL_B 0x0c
47#define DA9034_FAULT_LOG 0x0d
48
49struct da903x_chip;
50
51struct da903x_chip_ops {
52 int (*init_chip)(struct da903x_chip *);
53 int (*unmask_events)(struct da903x_chip *, unsigned int events);
54 int (*mask_events)(struct da903x_chip *, unsigned int events);
55 int (*read_events)(struct da903x_chip *, unsigned int *events);
56 int (*read_status)(struct da903x_chip *, unsigned int *status);
57};
58
59struct da903x_chip {
60 struct i2c_client *client;
61 struct device *dev;
62 struct da903x_chip_ops *ops;
63
64 int type;
65 uint32_t events_mask;
66
67 struct mutex lock;
68 struct work_struct irq_work;
69
70 struct blocking_notifier_head notifier_list;
71};
72
73static inline int __da903x_read(struct i2c_client *client,
74 int reg, uint8_t *val)
75{
76 int ret;
77
78 ret = i2c_smbus_read_byte_data(client, reg);
79 if (ret < 0) {
80 dev_err(&client->dev, "failed reading at 0x%02x\n", reg);
81 return ret;
82 }
83
84 *val = (uint8_t)ret;
85 return 0;
86}
87
88static inline int __da903x_reads(struct i2c_client *client, int reg,
89 int len, uint8_t *val)
90{
91 int ret;
92
93 ret = i2c_smbus_read_i2c_block_data(client, reg, len, val);
94 if (ret < 0) {
95 dev_err(&client->dev, "failed reading from 0x%02x\n", reg);
96 return ret;
97 }
98 return 0;
99}
100
101static inline int __da903x_write(struct i2c_client *client,
102 int reg, uint8_t val)
103{
104 int ret;
105
106 ret = i2c_smbus_write_byte_data(client, reg, val);
107 if (ret < 0) {
108 dev_err(&client->dev, "failed writing 0x%02x to 0x%02x\n",
109 val, reg);
110 return ret;
111 }
112 return 0;
113}
114
115static inline int __da903x_writes(struct i2c_client *client, int reg,
116 int len, uint8_t *val)
117{
118 int ret;
119
120 ret = i2c_smbus_write_i2c_block_data(client, reg, len, val);
121 if (ret < 0) {
122 dev_err(&client->dev, "failed writings to 0x%02x\n", reg);
123 return ret;
124 }
125 return 0;
126}
127
128int da903x_register_notifier(struct device *dev, struct notifier_block *nb,
129 unsigned int events)
130{
131 struct da903x_chip *chip = dev_get_drvdata(dev);
132
133 chip->ops->unmask_events(chip, events);
134 return blocking_notifier_chain_register(&chip->notifier_list, nb);
135}
136EXPORT_SYMBOL_GPL(da903x_register_notifier);
137
138int da903x_unregister_notifier(struct device *dev, struct notifier_block *nb,
139 unsigned int events)
140{
141 struct da903x_chip *chip = dev_get_drvdata(dev);
142
143 chip->ops->mask_events(chip, events);
144 return blocking_notifier_chain_unregister(&chip->notifier_list, nb);
145}
146EXPORT_SYMBOL_GPL(da903x_unregister_notifier);
147
148int da903x_write(struct device *dev, int reg, uint8_t val)
149{
150 return __da903x_write(to_i2c_client(dev), reg, val);
151}
152EXPORT_SYMBOL_GPL(da903x_write);
153
154int da903x_read(struct device *dev, int reg, uint8_t *val)
155{
156 return __da903x_read(to_i2c_client(dev), reg, val);
157}
158EXPORT_SYMBOL_GPL(da903x_read);
159
160int da903x_set_bits(struct device *dev, int reg, uint8_t bit_mask)
161{
162 struct da903x_chip *chip = dev_get_drvdata(dev);
163 uint8_t reg_val;
164 int ret = 0;
165
166 mutex_lock(&chip->lock);
167
168 ret = __da903x_read(chip->client, reg, &reg_val);
169 if (ret)
170 goto out;
171
172 if ((reg_val & bit_mask) == 0) {
173 reg_val |= bit_mask;
174 ret = __da903x_write(chip->client, reg, reg_val);
175 }
176out:
177 mutex_unlock(&chip->lock);
178 return ret;
179}
180EXPORT_SYMBOL_GPL(da903x_set_bits);
181
182int da903x_clr_bits(struct device *dev, int reg, uint8_t bit_mask)
183{
184 struct da903x_chip *chip = dev_get_drvdata(dev);
185 uint8_t reg_val;
186 int ret = 0;
187
188 mutex_lock(&chip->lock);
189
190 ret = __da903x_read(chip->client, reg, &reg_val);
191 if (ret)
192 goto out;
193
194 if (reg_val & bit_mask) {
195 reg_val &= ~bit_mask;
196 ret = __da903x_write(chip->client, reg, reg_val);
197 }
198out:
199 mutex_unlock(&chip->lock);
200 return ret;
201}
202EXPORT_SYMBOL_GPL(da903x_clr_bits);
203
204int da903x_update(struct device *dev, int reg, uint8_t val, uint8_t mask)
205{
206 struct da903x_chip *chip = dev_get_drvdata(dev);
207 uint8_t reg_val;
208 int ret = 0;
209
210 mutex_lock(&chip->lock);
211
212 ret = __da903x_read(chip->client, reg, &reg_val);
213 if (ret)
214 goto out;
215
216 if ((reg_val & mask) != val) {
217 reg_val = (reg_val & ~mask) | val;
218 ret = __da903x_write(chip->client, reg, reg_val);
219 }
220out:
221 mutex_unlock(&chip->lock);
222 return ret;
223}
224EXPORT_SYMBOL_GPL(da903x_update);
225
226int da903x_query_status(struct device *dev, unsigned int sbits)
227{
228 struct da903x_chip *chip = dev_get_drvdata(dev);
229 unsigned int status = 0;
230
231 chip->ops->read_status(chip, &status);
232 return ((status & sbits) == sbits);
233}
234EXPORT_SYMBOL(da903x_query_status);
235
236static int __devinit da9030_init_chip(struct da903x_chip *chip)
237{
238 uint8_t chip_id;
239 int err;
240
241 err = __da903x_read(chip->client, DA9030_CHIP_ID, &chip_id);
242 if (err)
243 return err;
244
245 err = __da903x_write(chip->client, DA9030_SYS_CTRL_A, 0xE8);
246 if (err)
247 return err;
248
249 dev_info(chip->dev, "DA9030 (CHIP ID: 0x%02x) detected\n", chip_id);
250 return 0;
251}
252
253static int da9030_unmask_events(struct da903x_chip *chip, unsigned int events)
254{
255 uint8_t v[3];
256
257 chip->events_mask &= ~events;
258
259 v[0] = (chip->events_mask & 0xff);
260 v[1] = (chip->events_mask >> 8) & 0xff;
261 v[2] = (chip->events_mask >> 16) & 0xff;
262
263 return __da903x_writes(chip->client, DA9030_IRQ_MASK_A, 3, v);
264}
265
266static int da9030_mask_events(struct da903x_chip *chip, unsigned int events)
267{
268 uint8_t v[3];
269
270 chip->events_mask &= ~events;
271
272 v[0] = (chip->events_mask & 0xff);
273 v[1] = (chip->events_mask >> 8) & 0xff;
274 v[2] = (chip->events_mask >> 16) & 0xff;
275
276 return __da903x_writes(chip->client, DA9030_IRQ_MASK_A, 3, v);
277}
278
279static int da9030_read_events(struct da903x_chip *chip, unsigned int *events)
280{
281 uint8_t v[3] = {0, 0, 0};
282 int ret;
283
284 ret = __da903x_reads(chip->client, DA9030_EVENT_A, 3, v);
285 if (ret < 0)
286 return ret;
287
288 *events = (v[2] << 16) | (v[1] << 8) | v[0];
289 return 0;
290}
291
292static int da9030_read_status(struct da903x_chip *chip, unsigned int *status)
293{
294 return __da903x_read(chip->client, DA9030_STATUS, (uint8_t *)status);
295}
296
297static int da9034_init_chip(struct da903x_chip *chip)
298{
299 uint8_t chip_id;
300 int err;
301
302 err = __da903x_read(chip->client, DA9034_CHIP_ID, &chip_id);
303 if (err)
304 return err;
305
306 err = __da903x_write(chip->client, DA9034_SYS_CTRL_A, 0xE8);
307 if (err)
308 return err;
309
310 /* avoid SRAM power off during sleep*/
311 __da903x_write(chip->client, 0x10, 0x07);
312 __da903x_write(chip->client, 0x11, 0xff);
313 __da903x_write(chip->client, 0x12, 0xff);
314
315 /* Enable the ONKEY power down functionality */
316 __da903x_write(chip->client, DA9034_SYS_CTRL_B, 0x20);
317 __da903x_write(chip->client, DA9034_SYS_CTRL_A, 0x60);
318
319 /* workaround to make LEDs work */
320 __da903x_write(chip->client, 0x90, 0x01);
321 __da903x_write(chip->client, 0xB0, 0x08);
322
323 /* make ADTV1 and SDTV1 effective */
324 __da903x_write(chip->client, 0x20, 0x00);
325
326 dev_info(chip->dev, "DA9034 (CHIP ID: 0x%02x) detected\n", chip_id);
327 return 0;
328}
329
330static int da9034_unmask_events(struct da903x_chip *chip, unsigned int events)
331{
332 uint8_t v[4];
333
334 chip->events_mask &= ~events;
335
336 v[0] = (chip->events_mask & 0xff);
337 v[1] = (chip->events_mask >> 8) & 0xff;
338 v[2] = (chip->events_mask >> 16) & 0xff;
339 v[3] = (chip->events_mask >> 24) & 0xff;
340
341 return __da903x_writes(chip->client, DA9034_IRQ_MASK_A, 4, v);
342}
343
344static int da9034_mask_events(struct da903x_chip *chip, unsigned int events)
345{
346 uint8_t v[4];
347
348 chip->events_mask |= events;
349
350 v[0] = (chip->events_mask & 0xff);
351 v[1] = (chip->events_mask >> 8) & 0xff;
352 v[2] = (chip->events_mask >> 16) & 0xff;
353 v[3] = (chip->events_mask >> 24) & 0xff;
354
355 return __da903x_writes(chip->client, DA9034_IRQ_MASK_A, 4, v);
356}
357
358static int da9034_read_events(struct da903x_chip *chip, unsigned int *events)
359{
360 uint8_t v[4] = {0, 0, 0, 0};
361 int ret;
362
363 ret = __da903x_reads(chip->client, DA9034_EVENT_A, 4, v);
364 if (ret < 0)
365 return ret;
366
367 *events = (v[3] << 24) | (v[2] << 16) | (v[1] << 8) | v[0];
368 return 0;
369}
370
371static int da9034_read_status(struct da903x_chip *chip, unsigned int *status)
372{
373 uint8_t v[2] = {0, 0};
374 int ret = 0;
375
376 ret = __da903x_reads(chip->client, DA9034_STATUS_A, 2, v);
377 if (ret)
378 return ret;
379
380 *status = (v[1] << 8) | v[0];
381 return 0;
382}
383
384static void da903x_irq_work(struct work_struct *work)
385{
386 struct da903x_chip *chip =
387 container_of(work, struct da903x_chip, irq_work);
388 unsigned int events = 0;
389
390 while (1) {
391 if (chip->ops->read_events(chip, &events))
392 break;
393
394 events &= ~chip->events_mask;
395 if (events == 0)
396 break;
397
398 blocking_notifier_call_chain(
399 &chip->notifier_list, events, NULL);
400 }
401 enable_irq(chip->client->irq);
402}
403
404static int da903x_irq_handler(int irq, void *data)
405{
406 struct da903x_chip *chip = data;
407
408 disable_irq_nosync(irq);
409 (void)schedule_work(&chip->irq_work);
410
411 return IRQ_HANDLED;
412}
413
414static struct da903x_chip_ops da903x_ops[] = {
415 [0] = {
416 .init_chip = da9030_init_chip,
417 .unmask_events = da9030_unmask_events,
418 .mask_events = da9030_mask_events,
419 .read_events = da9030_read_events,
420 .read_status = da9030_read_status,
421 },
422 [1] = {
423 .init_chip = da9034_init_chip,
424 .unmask_events = da9034_unmask_events,
425 .mask_events = da9034_mask_events,
426 .read_events = da9034_read_events,
427 .read_status = da9034_read_status,
428 }
429};
430
431static const struct i2c_device_id da903x_id_table[] = {
432 { "da9030", 0 },
433 { "da9034", 1 },
434 { },
435};
436MODULE_DEVICE_TABLE(i2c, da903x_id_table);
437
438static int __devexit __remove_subdev(struct device *dev, void *unused)
439{
440 platform_device_unregister(to_platform_device(dev));
441 return 0;
442}
443
444static int __devexit da903x_remove_subdevs(struct da903x_chip *chip)
445{
446 return device_for_each_child(chip->dev, NULL, __remove_subdev);
447}
448
449static int __devinit da903x_add_subdevs(struct da903x_chip *chip,
450 struct da903x_platform_data *pdata)
451{
452 struct da903x_subdev_info *subdev;
453 struct platform_device *pdev;
454 int i, ret = 0;
455
456 for (i = 0; i < pdata->num_subdevs; i++) {
457 subdev = &pdata->subdevs[i];
458
459 pdev = platform_device_alloc(subdev->name, subdev->id);
460
461 pdev->dev.parent = chip->dev;
462 pdev->dev.platform_data = subdev->platform_data;
463
464 ret = platform_device_add(pdev);
465 if (ret)
466 goto failed;
467 }
468 return 0;
469
470failed:
471 da903x_remove_subdevs(chip);
472 return ret;
473}
474
475static int __devinit da903x_probe(struct i2c_client *client,
476 const struct i2c_device_id *id)
477{
478 struct da903x_platform_data *pdata = client->dev.platform_data;
479 struct da903x_chip *chip;
480 unsigned int tmp;
481 int ret;
482
483 chip = kzalloc(sizeof(struct da903x_chip), GFP_KERNEL);
484 if (chip == NULL)
485 return -ENOMEM;
486
487 chip->client = client;
488 chip->dev = &client->dev;
489 chip->ops = &da903x_ops[id->driver_data];
490
491 mutex_init(&chip->lock);
492 INIT_WORK(&chip->irq_work, da903x_irq_work);
493 BLOCKING_INIT_NOTIFIER_HEAD(&chip->notifier_list);
494
495 i2c_set_clientdata(client, chip);
496
497 ret = chip->ops->init_chip(chip);
498 if (ret)
499 goto out_free_chip;
500
501 /* mask and clear all IRQs */
502 chip->events_mask = 0xffffffff;
503 chip->ops->mask_events(chip, chip->events_mask);
504 chip->ops->read_events(chip, &tmp);
505
506 ret = request_irq(client->irq, da903x_irq_handler,
507 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
508 "da903x", chip);
509 if (ret) {
510 dev_err(&client->dev, "failed to request irq %d\n",
511 client->irq);
512 goto out_free_chip;
513 }
514
515 ret = da903x_add_subdevs(chip, pdata);
516 if (ret)
517 goto out_free_irq;
518
519 return 0;
520
521out_free_irq:
522 free_irq(client->irq, chip);
523out_free_chip:
524 i2c_set_clientdata(client, NULL);
525 kfree(chip);
526 return ret;
527}
528
529static int __devexit da903x_remove(struct i2c_client *client)
530{
531 struct da903x_chip *chip = i2c_get_clientdata(client);
532
533 da903x_remove_subdevs(chip);
534 kfree(chip);
535 return 0;
536}
537
538static struct i2c_driver da903x_driver = {
539 .driver = {
540 .name = "da903x",
541 .owner = THIS_MODULE,
542 },
543 .probe = da903x_probe,
544 .remove = __devexit_p(da903x_remove),
545 .id_table = da903x_id_table,
546};
547
548static int __init da903x_init(void)
549{
550 return i2c_add_driver(&da903x_driver);
551}
552module_init(da903x_init);
553
554static void __exit da903x_exit(void)
555{
556 i2c_del_driver(&da903x_driver);
557}
558module_exit(da903x_exit);
559
560MODULE_DESCRIPTION("PMIC Driver for Dialog Semiconductor DA9034");
561MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"
562 "Mike Rapoport <mike@compulab.co.il>");
563MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/htc-egpio.c b/drivers/mfd/htc-egpio.c
index ad3379fcd194..1a4d04664d6d 100644
--- a/drivers/mfd/htc-egpio.c
+++ b/drivers/mfd/htc-egpio.c
@@ -289,7 +289,7 @@ static int __init egpio_probe(struct platform_device *pdev)
289 ei->base_addr = ioremap_nocache(res->start, res->end - res->start); 289 ei->base_addr = ioremap_nocache(res->start, res->end - res->start);
290 if (!ei->base_addr) 290 if (!ei->base_addr)
291 goto fail; 291 goto fail;
292 pr_debug("EGPIO phys=%08x virt=%p\n", res->start, ei->base_addr); 292 pr_debug("EGPIO phys=%08x virt=%p\n", (u32)res->start, ei->base_addr);
293 293
294 if ((pdata->bus_width != 16) && (pdata->bus_width != 32)) 294 if ((pdata->bus_width != 16) && (pdata->bus_width != 32))
295 goto fail; 295 goto fail;
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 9c9c126ed334..6c0d1bec4b76 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -20,7 +20,7 @@ static int mfd_add_device(struct device *parent, int id,
20 struct resource *mem_base, 20 struct resource *mem_base,
21 int irq_base) 21 int irq_base)
22{ 22{
23 struct resource res[cell->num_resources]; 23 struct resource *res;
24 struct platform_device *pdev; 24 struct platform_device *pdev;
25 int ret = -ENOMEM; 25 int ret = -ENOMEM;
26 int r; 26 int r;
@@ -29,14 +29,17 @@ static int mfd_add_device(struct device *parent, int id,
29 if (!pdev) 29 if (!pdev)
30 goto fail_alloc; 30 goto fail_alloc;
31 31
32 res = kzalloc(sizeof(*res) * cell->num_resources, GFP_KERNEL);
33 if (!res)
34 goto fail_device;
35
32 pdev->dev.parent = parent; 36 pdev->dev.parent = parent;
33 37
34 ret = platform_device_add_data(pdev, 38 ret = platform_device_add_data(pdev,
35 cell->platform_data, cell->data_size); 39 cell->platform_data, cell->data_size);
36 if (ret) 40 if (ret)
37 goto fail_device; 41 goto fail_res;
38 42
39 memset(res, 0, sizeof(res));
40 for (r = 0; r < cell->num_resources; r++) { 43 for (r = 0; r < cell->num_resources; r++) {
41 res[r].name = cell->resources[r].name; 44 res[r].name = cell->resources[r].name;
42 res[r].flags = cell->resources[r].flags; 45 res[r].flags = cell->resources[r].flags;
@@ -64,11 +67,15 @@ static int mfd_add_device(struct device *parent, int id,
64 67
65 ret = platform_device_add(pdev); 68 ret = platform_device_add(pdev);
66 if (ret) 69 if (ret)
67 goto fail_device; 70 goto fail_res;
71
72 kfree(res);
68 73
69 return 0; 74 return 0;
70 75
71/* platform_device_del(pdev); */ 76/* platform_device_del(pdev); */
77fail_res:
78 kfree(res);
72fail_device: 79fail_device:
73 platform_device_put(pdev); 80 platform_device_put(pdev);
74fail_alloc: 81fail_alloc:
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 7aebad4c06ff..220e4371266b 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -623,8 +623,8 @@ unsigned long sm501_set_clock(struct device *dev,
623 623
624 sm501_sync_regs(sm); 624 sm501_sync_regs(sm);
625 625
626 dev_info(sm->dev, "gate %08lx, clock %08lx, mode %08lx\n", 626 dev_dbg(sm->dev, "gate %08lx, clock %08lx, mode %08lx\n",
627 gate, clock, mode); 627 gate, clock, mode);
628 628
629 sm501_mdelay(sm, 16); 629 sm501_mdelay(sm, 16);
630 mutex_unlock(&sm->clock_lock); 630 mutex_unlock(&sm->clock_lock);
@@ -742,7 +742,7 @@ static int sm501_register_device(struct sm501_devdata *sm,
742 int ret; 742 int ret;
743 743
744 for (ptr = 0; ptr < pdev->num_resources; ptr++) { 744 for (ptr = 0; ptr < pdev->num_resources; ptr++) {
745 printk("%s[%d] flags %08lx: %08llx..%08llx\n", 745 printk(KERN_DEBUG "%s[%d] flags %08lx: %08llx..%08llx\n",
746 pdev->name, ptr, 746 pdev->name, ptr,
747 pdev->resource[ptr].flags, 747 pdev->resource[ptr].flags,
748 (unsigned long long)pdev->resource[ptr].start, 748 (unsigned long long)pdev->resource[ptr].start,
diff --git a/drivers/mfd/t7l66xb.c b/drivers/mfd/t7l66xb.c
index 49a0fffc02af..9f7024c0f8ec 100644
--- a/drivers/mfd/t7l66xb.c
+++ b/drivers/mfd/t7l66xb.c
@@ -24,8 +24,10 @@
24 24
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/err.h>
27#include <linux/io.h> 28#include <linux/io.h>
28#include <linux/irq.h> 29#include <linux/irq.h>
30#include <linux/clk.h>
29#include <linux/platform_device.h> 31#include <linux/platform_device.h>
30#include <linux/mfd/core.h> 32#include <linux/mfd/core.h>
31#include <linux/mfd/tmio.h> 33#include <linux/mfd/tmio.h>
@@ -56,6 +58,8 @@ struct t7l66xb {
56 spinlock_t lock; 58 spinlock_t lock;
57 59
58 struct resource rscr; 60 struct resource rscr;
61 struct clk *clk48m;
62 struct clk *clk32k;
59 int irq; 63 int irq;
60 int irq_base; 64 int irq_base;
61}; 65};
@@ -65,13 +69,11 @@ struct t7l66xb {
65static int t7l66xb_mmc_enable(struct platform_device *mmc) 69static int t7l66xb_mmc_enable(struct platform_device *mmc)
66{ 70{
67 struct platform_device *dev = to_platform_device(mmc->dev.parent); 71 struct platform_device *dev = to_platform_device(mmc->dev.parent);
68 struct t7l66xb_platform_data *pdata = dev->dev.platform_data;
69 struct t7l66xb *t7l66xb = platform_get_drvdata(dev); 72 struct t7l66xb *t7l66xb = platform_get_drvdata(dev);
70 unsigned long flags; 73 unsigned long flags;
71 u8 dev_ctl; 74 u8 dev_ctl;
72 75
73 if (pdata->enable_clk32k) 76 clk_enable(t7l66xb->clk32k);
74 pdata->enable_clk32k(dev);
75 77
76 spin_lock_irqsave(&t7l66xb->lock, flags); 78 spin_lock_irqsave(&t7l66xb->lock, flags);
77 79
@@ -87,7 +89,6 @@ static int t7l66xb_mmc_enable(struct platform_device *mmc)
87static int t7l66xb_mmc_disable(struct platform_device *mmc) 89static int t7l66xb_mmc_disable(struct platform_device *mmc)
88{ 90{
89 struct platform_device *dev = to_platform_device(mmc->dev.parent); 91 struct platform_device *dev = to_platform_device(mmc->dev.parent);
90 struct t7l66xb_platform_data *pdata = dev->dev.platform_data;
91 struct t7l66xb *t7l66xb = platform_get_drvdata(dev); 92 struct t7l66xb *t7l66xb = platform_get_drvdata(dev);
92 unsigned long flags; 93 unsigned long flags;
93 u8 dev_ctl; 94 u8 dev_ctl;
@@ -100,8 +101,7 @@ static int t7l66xb_mmc_disable(struct platform_device *mmc)
100 101
101 spin_unlock_irqrestore(&t7l66xb->lock, flags); 102 spin_unlock_irqrestore(&t7l66xb->lock, flags);
102 103
103 if (pdata->disable_clk32k) 104 clk_disable(t7l66xb->clk32k);
104 pdata->disable_clk32k(dev);
105 105
106 return 0; 106 return 0;
107} 107}
@@ -258,18 +258,22 @@ static void t7l66xb_detach_irq(struct platform_device *dev)
258#ifdef CONFIG_PM 258#ifdef CONFIG_PM
259static int t7l66xb_suspend(struct platform_device *dev, pm_message_t state) 259static int t7l66xb_suspend(struct platform_device *dev, pm_message_t state)
260{ 260{
261 struct t7l66xb *t7l66xb = platform_get_drvdata(dev);
261 struct t7l66xb_platform_data *pdata = dev->dev.platform_data; 262 struct t7l66xb_platform_data *pdata = dev->dev.platform_data;
262 263
263 if (pdata && pdata->suspend) 264 if (pdata && pdata->suspend)
264 pdata->suspend(dev); 265 pdata->suspend(dev);
266 clk_disable(t7l66xb->clk48m);
265 267
266 return 0; 268 return 0;
267} 269}
268 270
269static int t7l66xb_resume(struct platform_device *dev) 271static int t7l66xb_resume(struct platform_device *dev)
270{ 272{
273 struct t7l66xb *t7l66xb = platform_get_drvdata(dev);
271 struct t7l66xb_platform_data *pdata = dev->dev.platform_data; 274 struct t7l66xb_platform_data *pdata = dev->dev.platform_data;
272 275
276 clk_enable(t7l66xb->clk48m);
273 if (pdata && pdata->resume) 277 if (pdata && pdata->resume)
274 pdata->resume(dev); 278 pdata->resume(dev);
275 279
@@ -309,6 +313,19 @@ static int t7l66xb_probe(struct platform_device *dev)
309 313
310 t7l66xb->irq_base = pdata->irq_base; 314 t7l66xb->irq_base = pdata->irq_base;
311 315
316 t7l66xb->clk32k = clk_get(&dev->dev, "CLK_CK32K");
317 if (IS_ERR(t7l66xb->clk32k)) {
318 ret = PTR_ERR(t7l66xb->clk32k);
319 goto err_clk32k_get;
320 }
321
322 t7l66xb->clk48m = clk_get(&dev->dev, "CLK_CK48M");
323 if (IS_ERR(t7l66xb->clk48m)) {
324 ret = PTR_ERR(t7l66xb->clk48m);
325 clk_put(t7l66xb->clk32k);
326 goto err_clk48m_get;
327 }
328
312 rscr = &t7l66xb->rscr; 329 rscr = &t7l66xb->rscr;
313 rscr->name = "t7l66xb-core"; 330 rscr->name = "t7l66xb-core";
314 rscr->start = iomem->start; 331 rscr->start = iomem->start;
@@ -325,6 +342,8 @@ static int t7l66xb_probe(struct platform_device *dev)
325 goto err_ioremap; 342 goto err_ioremap;
326 } 343 }
327 344
345 clk_enable(t7l66xb->clk48m);
346
328 if (pdata && pdata->enable) 347 if (pdata && pdata->enable)
329 pdata->enable(dev); 348 pdata->enable(dev);
330 349
@@ -359,9 +378,13 @@ static int t7l66xb_probe(struct platform_device *dev)
359 iounmap(t7l66xb->scr); 378 iounmap(t7l66xb->scr);
360err_ioremap: 379err_ioremap:
361 release_resource(&t7l66xb->rscr); 380 release_resource(&t7l66xb->rscr);
362err_noirq:
363err_request_scr: 381err_request_scr:
364 kfree(t7l66xb); 382 kfree(t7l66xb);
383 clk_put(t7l66xb->clk48m);
384err_clk48m_get:
385 clk_put(t7l66xb->clk32k);
386err_clk32k_get:
387err_noirq:
365 return ret; 388 return ret;
366} 389}
367 390
@@ -372,7 +395,8 @@ static int t7l66xb_remove(struct platform_device *dev)
372 int ret; 395 int ret;
373 396
374 ret = pdata->disable(dev); 397 ret = pdata->disable(dev);
375 398 clk_disable(t7l66xb->clk48m);
399 clk_put(t7l66xb->clk48m);
376 t7l66xb_detach_irq(dev); 400 t7l66xb_detach_irq(dev);
377 iounmap(t7l66xb->scr); 401 iounmap(t7l66xb->scr);
378 release_resource(&t7l66xb->rscr); 402 release_resource(&t7l66xb->rscr);
diff --git a/drivers/mfd/tc6387xb.c b/drivers/mfd/tc6387xb.c
index a22b21ac6cf8..43222c12fec1 100644
--- a/drivers/mfd/tc6387xb.c
+++ b/drivers/mfd/tc6387xb.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/clk.h>
15#include <linux/err.h> 16#include <linux/err.h>
16#include <linux/mfd/core.h> 17#include <linux/mfd/core.h>
17#include <linux/mfd/tmio.h> 18#include <linux/mfd/tmio.h>
@@ -24,18 +25,22 @@ enum {
24#ifdef CONFIG_PM 25#ifdef CONFIG_PM
25static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state) 26static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state)
26{ 27{
27 struct tc6387xb_platform_data *pdata = platform_get_drvdata(dev); 28 struct clk *clk32k = platform_get_drvdata(dev);
29 struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
28 30
29 if (pdata && pdata->suspend) 31 if (pdata && pdata->suspend)
30 pdata->suspend(dev); 32 pdata->suspend(dev);
33 clk_disable(clk32k);
31 34
32 return 0; 35 return 0;
33} 36}
34 37
35static int tc6387xb_resume(struct platform_device *dev) 38static int tc6387xb_resume(struct platform_device *dev)
36{ 39{
37 struct tc6387xb_platform_data *pdata = platform_get_drvdata(dev); 40 struct clk *clk32k = platform_get_drvdata(dev);
41 struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
38 42
43 clk_enable(clk32k);
39 if (pdata && pdata->resume) 44 if (pdata && pdata->resume)
40 pdata->resume(dev); 45 pdata->resume(dev);
41 46
@@ -51,10 +56,9 @@ static int tc6387xb_resume(struct platform_device *dev)
51static int tc6387xb_mmc_enable(struct platform_device *mmc) 56static int tc6387xb_mmc_enable(struct platform_device *mmc)
52{ 57{
53 struct platform_device *dev = to_platform_device(mmc->dev.parent); 58 struct platform_device *dev = to_platform_device(mmc->dev.parent);
54 struct tc6387xb_platform_data *tc6387xb = dev->dev.platform_data; 59 struct clk *clk32k = platform_get_drvdata(dev);
55 60
56 if (tc6387xb->enable_clk32k) 61 clk_enable(clk32k);
57 tc6387xb->enable_clk32k(dev);
58 62
59 return 0; 63 return 0;
60} 64}
@@ -62,10 +66,9 @@ static int tc6387xb_mmc_enable(struct platform_device *mmc)
62static int tc6387xb_mmc_disable(struct platform_device *mmc) 66static int tc6387xb_mmc_disable(struct platform_device *mmc)
63{ 67{
64 struct platform_device *dev = to_platform_device(mmc->dev.parent); 68 struct platform_device *dev = to_platform_device(mmc->dev.parent);
65 struct tc6387xb_platform_data *tc6387xb = dev->dev.platform_data; 69 struct clk *clk32k = platform_get_drvdata(dev);
66 70
67 if (tc6387xb->disable_clk32k) 71 clk_disable(clk32k);
68 tc6387xb->disable_clk32k(dev);
69 72
70 return 0; 73 return 0;
71} 74}
@@ -102,14 +105,14 @@ static struct mfd_cell tc6387xb_cells[] = {
102 105
103static int tc6387xb_probe(struct platform_device *dev) 106static int tc6387xb_probe(struct platform_device *dev)
104{ 107{
105 struct tc6387xb_platform_data *data = platform_get_drvdata(dev); 108 struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
106 struct resource *iomem; 109 struct resource *iomem;
110 struct clk *clk32k;
107 int irq, ret; 111 int irq, ret;
108 112
109 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0); 113 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
110 if (!iomem) { 114 if (!iomem) {
111 ret = -EINVAL; 115 return -EINVAL;
112 goto err_resource;
113 } 116 }
114 117
115 ret = platform_get_irq(dev, 0); 118 ret = platform_get_irq(dev, 0);
@@ -118,8 +121,15 @@ static int tc6387xb_probe(struct platform_device *dev)
118 else 121 else
119 goto err_resource; 122 goto err_resource;
120 123
121 if (data && data->enable) 124 clk32k = clk_get(&dev->dev, "CLK_CK32K");
122 data->enable(dev); 125 if (IS_ERR(clk32k)) {
126 ret = PTR_ERR(clk32k);
127 goto err_resource;
128 }
129 platform_set_drvdata(dev, clk32k);
130
131 if (pdata && pdata->enable)
132 pdata->enable(dev);
123 133
124 printk(KERN_INFO "Toshiba tc6387xb initialised\n"); 134 printk(KERN_INFO "Toshiba tc6387xb initialised\n");
125 135
@@ -134,18 +144,19 @@ static int tc6387xb_probe(struct platform_device *dev)
134 if (!ret) 144 if (!ret)
135 return 0; 145 return 0;
136 146
147 clk_put(clk32k);
137err_resource: 148err_resource:
138 return ret; 149 return ret;
139} 150}
140 151
141static int tc6387xb_remove(struct platform_device *dev) 152static int tc6387xb_remove(struct platform_device *dev)
142{ 153{
143 struct tc6387xb_platform_data *data = platform_get_drvdata(dev); 154 struct clk *clk32k = platform_get_drvdata(dev);
144
145 if (data && data->disable)
146 data->disable(dev);
147 155
148 /* FIXME - free the resources! */ 156 mfd_remove_devices(&dev->dev);
157 clk_disable(clk32k);
158 clk_put(clk32k);
159 platform_set_drvdata(dev, NULL);
149 160
150 return 0; 161 return 0;
151} 162}
diff --git a/drivers/mfd/tc6393xb.c b/drivers/mfd/tc6393xb.c
index e4c1c788b5f8..f856e9463a9f 100644
--- a/drivers/mfd/tc6393xb.c
+++ b/drivers/mfd/tc6393xb.c
@@ -113,6 +113,8 @@ struct tc6393xb {
113enum { 113enum {
114 TC6393XB_CELL_NAND, 114 TC6393XB_CELL_NAND,
115 TC6393XB_CELL_MMC, 115 TC6393XB_CELL_MMC,
116 TC6393XB_CELL_OHCI,
117 TC6393XB_CELL_FB,
116}; 118};
117 119
118/*--------------------------------------------------------------------------*/ 120/*--------------------------------------------------------------------------*/
@@ -170,6 +172,176 @@ static struct resource __devinitdata tc6393xb_mmc_resources[] = {
170 }, 172 },
171}; 173};
172 174
175const static struct resource tc6393xb_ohci_resources[] = {
176 {
177 .start = 0x3000,
178 .end = 0x31ff,
179 .flags = IORESOURCE_MEM,
180 },
181 {
182 .start = 0x0300,
183 .end = 0x03ff,
184 .flags = IORESOURCE_MEM,
185 },
186 {
187 .start = 0x010000,
188 .end = 0x017fff,
189 .flags = IORESOURCE_MEM,
190 },
191 {
192 .start = 0x018000,
193 .end = 0x01ffff,
194 .flags = IORESOURCE_MEM,
195 },
196 {
197 .start = IRQ_TC6393_OHCI,
198 .end = IRQ_TC6393_OHCI,
199 .flags = IORESOURCE_IRQ,
200 },
201};
202
203static struct resource __devinitdata tc6393xb_fb_resources[] = {
204 {
205 .start = 0x5000,
206 .end = 0x51ff,
207 .flags = IORESOURCE_MEM,
208 },
209 {
210 .start = 0x0500,
211 .end = 0x05ff,
212 .flags = IORESOURCE_MEM,
213 },
214 {
215 .start = 0x100000,
216 .end = 0x1fffff,
217 .flags = IORESOURCE_MEM,
218 },
219 {
220 .start = IRQ_TC6393_FB,
221 .end = IRQ_TC6393_FB,
222 .flags = IORESOURCE_IRQ,
223 },
224};
225
226static int tc6393xb_ohci_enable(struct platform_device *dev)
227{
228 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
229 unsigned long flags;
230 u16 ccr;
231 u8 fer;
232
233 spin_lock_irqsave(&tc6393xb->lock, flags);
234
235 ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
236 ccr |= SCR_CCR_USBCK;
237 tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
238
239 fer = tmio_ioread8(tc6393xb->scr + SCR_FER);
240 fer |= SCR_FER_USBEN;
241 tmio_iowrite8(fer, tc6393xb->scr + SCR_FER);
242
243 spin_unlock_irqrestore(&tc6393xb->lock, flags);
244
245 return 0;
246}
247
248static int tc6393xb_ohci_disable(struct platform_device *dev)
249{
250 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
251 unsigned long flags;
252 u16 ccr;
253 u8 fer;
254
255 spin_lock_irqsave(&tc6393xb->lock, flags);
256
257 fer = tmio_ioread8(tc6393xb->scr + SCR_FER);
258 fer &= ~SCR_FER_USBEN;
259 tmio_iowrite8(fer, tc6393xb->scr + SCR_FER);
260
261 ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
262 ccr &= ~SCR_CCR_USBCK;
263 tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
264
265 spin_unlock_irqrestore(&tc6393xb->lock, flags);
266
267 return 0;
268}
269
270static int tc6393xb_fb_enable(struct platform_device *dev)
271{
272 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
273 unsigned long flags;
274 u16 ccr;
275
276 spin_lock_irqsave(&tc6393xb->lock, flags);
277
278 ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
279 ccr &= ~SCR_CCR_MCLK_MASK;
280 ccr |= SCR_CCR_MCLK_48;
281 tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
282
283 spin_unlock_irqrestore(&tc6393xb->lock, flags);
284
285 return 0;
286}
287
288static int tc6393xb_fb_disable(struct platform_device *dev)
289{
290 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
291 unsigned long flags;
292 u16 ccr;
293
294 spin_lock_irqsave(&tc6393xb->lock, flags);
295
296 ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
297 ccr &= ~SCR_CCR_MCLK_MASK;
298 ccr |= SCR_CCR_MCLK_OFF;
299 tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
300
301 spin_unlock_irqrestore(&tc6393xb->lock, flags);
302
303 return 0;
304}
305
306int tc6393xb_lcd_set_power(struct platform_device *fb, bool on)
307{
308 struct platform_device *dev = to_platform_device(fb->dev.parent);
309 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
310 u8 fer;
311 unsigned long flags;
312
313 spin_lock_irqsave(&tc6393xb->lock, flags);
314
315 fer = ioread8(tc6393xb->scr + SCR_FER);
316 if (on)
317 fer |= SCR_FER_SLCDEN;
318 else
319 fer &= ~SCR_FER_SLCDEN;
320 iowrite8(fer, tc6393xb->scr + SCR_FER);
321
322 spin_unlock_irqrestore(&tc6393xb->lock, flags);
323
324 return 0;
325}
326EXPORT_SYMBOL(tc6393xb_lcd_set_power);
327
328int tc6393xb_lcd_mode(struct platform_device *fb,
329 const struct fb_videomode *mode) {
330 struct platform_device *dev = to_platform_device(fb->dev.parent);
331 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
332 unsigned long flags;
333
334 spin_lock_irqsave(&tc6393xb->lock, flags);
335
336 iowrite16(mode->pixclock, tc6393xb->scr + SCR_PLL1CR + 0);
337 iowrite16(mode->pixclock >> 16, tc6393xb->scr + SCR_PLL1CR + 2);
338
339 spin_unlock_irqrestore(&tc6393xb->lock, flags);
340
341 return 0;
342}
343EXPORT_SYMBOL(tc6393xb_lcd_mode);
344
173static struct mfd_cell __devinitdata tc6393xb_cells[] = { 345static struct mfd_cell __devinitdata tc6393xb_cells[] = {
174 [TC6393XB_CELL_NAND] = { 346 [TC6393XB_CELL_NAND] = {
175 .name = "tmio-nand", 347 .name = "tmio-nand",
@@ -182,6 +354,24 @@ static struct mfd_cell __devinitdata tc6393xb_cells[] = {
182 .num_resources = ARRAY_SIZE(tc6393xb_mmc_resources), 354 .num_resources = ARRAY_SIZE(tc6393xb_mmc_resources),
183 .resources = tc6393xb_mmc_resources, 355 .resources = tc6393xb_mmc_resources,
184 }, 356 },
357 [TC6393XB_CELL_OHCI] = {
358 .name = "tmio-ohci",
359 .num_resources = ARRAY_SIZE(tc6393xb_ohci_resources),
360 .resources = tc6393xb_ohci_resources,
361 .enable = tc6393xb_ohci_enable,
362 .suspend = tc6393xb_ohci_disable,
363 .resume = tc6393xb_ohci_enable,
364 .disable = tc6393xb_ohci_disable,
365 },
366 [TC6393XB_CELL_FB] = {
367 .name = "tmio-fb",
368 .num_resources = ARRAY_SIZE(tc6393xb_fb_resources),
369 .resources = tc6393xb_fb_resources,
370 .enable = tc6393xb_fb_enable,
371 .suspend = tc6393xb_fb_disable,
372 .resume = tc6393xb_fb_enable,
373 .disable = tc6393xb_fb_disable,
374 },
185}; 375};
186 376
187/*--------------------------------------------------------------------------*/ 377/*--------------------------------------------------------------------------*/
@@ -369,41 +559,12 @@ static void tc6393xb_detach_irq(struct platform_device *dev)
369 559
370/*--------------------------------------------------------------------------*/ 560/*--------------------------------------------------------------------------*/
371 561
372static int tc6393xb_hw_init(struct platform_device *dev)
373{
374 struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
375 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
376 int i;
377
378 iowrite8(tc6393xb->suspend_state.fer, tc6393xb->scr + SCR_FER);
379 iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
380 iowrite16(tc6393xb->suspend_state.ccr, tc6393xb->scr + SCR_CCR);
381 iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
382 SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
383 BIT(15), tc6393xb->scr + SCR_MCR);
384 iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
385 iowrite8(0, tc6393xb->scr + SCR_IRR);
386 iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
387
388 for (i = 0; i < 3; i++) {
389 iowrite8(tc6393xb->suspend_state.gpo_dsr[i],
390 tc6393xb->scr + SCR_GPO_DSR(i));
391 iowrite8(tc6393xb->suspend_state.gpo_doecr[i],
392 tc6393xb->scr + SCR_GPO_DOECR(i));
393 iowrite8(tc6393xb->suspend_state.gpi_bcr[i],
394 tc6393xb->scr + SCR_GPI_BCR(i));
395 }
396
397 return 0;
398}
399
400static int __devinit tc6393xb_probe(struct platform_device *dev) 562static int __devinit tc6393xb_probe(struct platform_device *dev)
401{ 563{
402 struct tc6393xb_platform_data *tcpd = dev->dev.platform_data; 564 struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
403 struct tc6393xb *tc6393xb; 565 struct tc6393xb *tc6393xb;
404 struct resource *iomem, *rscr; 566 struct resource *iomem, *rscr;
405 int ret, temp; 567 int ret, temp;
406 int i;
407 568
408 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0); 569 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
409 if (!iomem) 570 if (!iomem)
@@ -458,21 +619,16 @@ static int __devinit tc6393xb_probe(struct platform_device *dev)
458 if (ret) 619 if (ret)
459 goto err_enable; 620 goto err_enable;
460 621
461 tc6393xb->suspend_state.fer = 0; 622 iowrite8(0, tc6393xb->scr + SCR_FER);
462 623 iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
463 for (i = 0; i < 3; i++) { 624 iowrite16(SCR_CCR_UNK1 | SCR_CCR_HCLK_48,
464 tc6393xb->suspend_state.gpo_dsr[i] = 625 tc6393xb->scr + SCR_CCR);
465 (tcpd->scr_gpo_dsr >> (8 * i)) & 0xff; 626 iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
466 tc6393xb->suspend_state.gpo_doecr[i] = 627 SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
467 (tcpd->scr_gpo_doecr >> (8 * i)) & 0xff; 628 BIT(15), tc6393xb->scr + SCR_MCR);
468 } 629 iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
469 630 iowrite8(0, tc6393xb->scr + SCR_IRR);
470 tc6393xb->suspend_state.ccr = SCR_CCR_UNK1 | 631 iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
471 SCR_CCR_HCLK_48;
472
473 ret = tc6393xb_hw_init(dev);
474 if (ret)
475 goto err_hw_init;
476 632
477 printk(KERN_INFO "Toshiba tc6393xb revision %d at 0x%08lx, irq %d\n", 633 printk(KERN_INFO "Toshiba tc6393xb revision %d at 0x%08lx, irq %d\n",
478 tmio_ioread8(tc6393xb->scr + SCR_REVID), 634 tmio_ioread8(tc6393xb->scr + SCR_REVID),
@@ -488,16 +644,33 @@ static int __devinit tc6393xb_probe(struct platform_device *dev)
488 644
489 tc6393xb_attach_irq(dev); 645 tc6393xb_attach_irq(dev);
490 646
647 if (tcpd->setup) {
648 ret = tcpd->setup(dev);
649 if (ret)
650 goto err_setup;
651 }
652
491 tc6393xb_cells[TC6393XB_CELL_NAND].driver_data = tcpd->nand_data; 653 tc6393xb_cells[TC6393XB_CELL_NAND].driver_data = tcpd->nand_data;
492 tc6393xb_cells[TC6393XB_CELL_NAND].platform_data = 654 tc6393xb_cells[TC6393XB_CELL_NAND].platform_data =
493 &tc6393xb_cells[TC6393XB_CELL_NAND]; 655 &tc6393xb_cells[TC6393XB_CELL_NAND];
494 tc6393xb_cells[TC6393XB_CELL_NAND].data_size = 656 tc6393xb_cells[TC6393XB_CELL_NAND].data_size =
495 sizeof(tc6393xb_cells[TC6393XB_CELL_NAND]); 657 sizeof(tc6393xb_cells[TC6393XB_CELL_NAND]);
658
496 tc6393xb_cells[TC6393XB_CELL_MMC].platform_data = 659 tc6393xb_cells[TC6393XB_CELL_MMC].platform_data =
497 &tc6393xb_cells[TC6393XB_CELL_MMC]; 660 &tc6393xb_cells[TC6393XB_CELL_MMC];
498 tc6393xb_cells[TC6393XB_CELL_MMC].data_size = 661 tc6393xb_cells[TC6393XB_CELL_MMC].data_size =
499 sizeof(tc6393xb_cells[TC6393XB_CELL_MMC]); 662 sizeof(tc6393xb_cells[TC6393XB_CELL_MMC]);
500 663
664 tc6393xb_cells[TC6393XB_CELL_OHCI].platform_data =
665 &tc6393xb_cells[TC6393XB_CELL_OHCI];
666 tc6393xb_cells[TC6393XB_CELL_OHCI].data_size =
667 sizeof(tc6393xb_cells[TC6393XB_CELL_OHCI]);
668
669 tc6393xb_cells[TC6393XB_CELL_FB].driver_data = tcpd->fb_data;
670 tc6393xb_cells[TC6393XB_CELL_FB].platform_data =
671 &tc6393xb_cells[TC6393XB_CELL_FB];
672 tc6393xb_cells[TC6393XB_CELL_FB].data_size =
673 sizeof(tc6393xb_cells[TC6393XB_CELL_FB]);
501 674
502 ret = mfd_add_devices(&dev->dev, dev->id, 675 ret = mfd_add_devices(&dev->dev, dev->id,
503 tc6393xb_cells, ARRAY_SIZE(tc6393xb_cells), 676 tc6393xb_cells, ARRAY_SIZE(tc6393xb_cells),
@@ -506,12 +679,15 @@ static int __devinit tc6393xb_probe(struct platform_device *dev)
506 if (!ret) 679 if (!ret)
507 return 0; 680 return 0;
508 681
682 if (tcpd->teardown)
683 tcpd->teardown(dev);
684
685err_setup:
509 tc6393xb_detach_irq(dev); 686 tc6393xb_detach_irq(dev);
510 687
511err_gpio_add: 688err_gpio_add:
512 if (tc6393xb->gpio.base != -1) 689 if (tc6393xb->gpio.base != -1)
513 temp = gpiochip_remove(&tc6393xb->gpio); 690 temp = gpiochip_remove(&tc6393xb->gpio);
514err_hw_init:
515 tcpd->disable(dev); 691 tcpd->disable(dev);
516err_clk_enable: 692err_clk_enable:
517 clk_disable(tc6393xb->clk); 693 clk_disable(tc6393xb->clk);
@@ -535,6 +711,10 @@ static int __devexit tc6393xb_remove(struct platform_device *dev)
535 int ret; 711 int ret;
536 712
537 mfd_remove_devices(&dev->dev); 713 mfd_remove_devices(&dev->dev);
714
715 if (tcpd->teardown)
716 tcpd->teardown(dev);
717
538 tc6393xb_detach_irq(dev); 718 tc6393xb_detach_irq(dev);
539 719
540 if (tc6393xb->gpio.base != -1) { 720 if (tc6393xb->gpio.base != -1) {
@@ -585,15 +765,37 @@ static int tc6393xb_resume(struct platform_device *dev)
585 struct tc6393xb_platform_data *tcpd = dev->dev.platform_data; 765 struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
586 struct tc6393xb *tc6393xb = platform_get_drvdata(dev); 766 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
587 int ret; 767 int ret;
768 int i;
588 769
589 clk_enable(tc6393xb->clk); 770 clk_enable(tc6393xb->clk);
590 771
591 ret = tcpd->resume(dev); 772 ret = tcpd->resume(dev);
592
593 if (ret) 773 if (ret)
594 return ret; 774 return ret;
595 775
596 return tc6393xb_hw_init(dev); 776 if (!tcpd->resume_restore)
777 return 0;
778
779 iowrite8(tc6393xb->suspend_state.fer, tc6393xb->scr + SCR_FER);
780 iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
781 iowrite16(tc6393xb->suspend_state.ccr, tc6393xb->scr + SCR_CCR);
782 iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
783 SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
784 BIT(15), tc6393xb->scr + SCR_MCR);
785 iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
786 iowrite8(0, tc6393xb->scr + SCR_IRR);
787 iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
788
789 for (i = 0; i < 3; i++) {
790 iowrite8(tc6393xb->suspend_state.gpo_dsr[i],
791 tc6393xb->scr + SCR_GPO_DSR(i));
792 iowrite8(tc6393xb->suspend_state.gpo_doecr[i],
793 tc6393xb->scr + SCR_GPO_DOECR(i));
794 iowrite8(tc6393xb->suspend_state.gpi_bcr[i],
795 tc6393xb->scr + SCR_GPI_BCR(i));
796 }
797
798 return 0;
597} 799}
598#else 800#else
599#define tc6393xb_suspend NULL 801#define tc6393xb_suspend NULL
diff --git a/drivers/mfd/twl4030-core.c b/drivers/mfd/twl4030-core.c
new file mode 100644
index 000000000000..fd9a0160202c
--- /dev/null
+++ b/drivers/mfd/twl4030-core.c
@@ -0,0 +1,1193 @@
1/*
2 * twl4030_core.c - driver for TWL4030/TPS659x0 PM and audio CODEC devices
3 *
4 * Copyright (C) 2005-2006 Texas Instruments, Inc.
5 *
6 * Modifications to defer interrupt handling to a kernel thread:
7 * Copyright (C) 2006 MontaVista Software, Inc.
8 *
9 * Based on tlv320aic23.c:
10 * Copyright (c) by Kai Svahn <kai.svahn@nokia.com>
11 *
12 * Code cleanup and modifications to IRQ handler.
13 * by syed khasim <x0khasim@ti.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 */
29
30#include <linux/kernel_stat.h>
31#include <linux/init.h>
32#include <linux/mutex.h>
33#include <linux/interrupt.h>
34#include <linux/irq.h>
35#include <linux/random.h>
36#include <linux/kthread.h>
37#include <linux/platform_device.h>
38#include <linux/clk.h>
39
40#include <linux/i2c.h>
41#include <linux/i2c/twl4030.h>
42
43
44/*
45 * The TWL4030 "Triton 2" is one of a family of a multi-function "Power
46 * Management and System Companion Device" chips originally designed for
47 * use in OMAP2 and OMAP 3 based systems. Its control interfaces use I2C,
48 * often at around 3 Mbit/sec, including for interrupt handling.
49 *
50 * This driver core provides genirq support for the interrupts emitted,
51 * by the various modules, and exports register access primitives.
52 *
53 * FIXME this driver currently requires use of the first interrupt line
54 * (and associated registers).
55 */
56
57#define DRIVER_NAME "twl4030"
58
59#if defined(CONFIG_TWL4030_BCI_BATTERY) || \
60 defined(CONFIG_TWL4030_BCI_BATTERY_MODULE)
61#define twl_has_bci() true
62#else
63#define twl_has_bci() false
64#endif
65
66#if defined(CONFIG_KEYBOARD_TWL4030) || defined(CONFIG_KEYBOARD_TWL4030_MODULE)
67#define twl_has_keypad() true
68#else
69#define twl_has_keypad() false
70#endif
71
72#if defined(CONFIG_GPIO_TWL4030) || defined(CONFIG_GPIO_TWL4030_MODULE)
73#define twl_has_gpio() true
74#else
75#define twl_has_gpio() false
76#endif
77
78#if defined(CONFIG_TWL4030_MADC) || defined(CONFIG_TWL4030_MADC_MODULE)
79#define twl_has_madc() true
80#else
81#define twl_has_madc() false
82#endif
83
84#if defined(CONFIG_RTC_DRV_TWL4030) || defined(CONFIG_RTC_DRV_TWL4030_MODULE)
85#define twl_has_rtc() true
86#else
87#define twl_has_rtc() false
88#endif
89
90#if defined(CONFIG_TWL4030_USB) || defined(CONFIG_TWL4030_USB_MODULE)
91#define twl_has_usb() true
92#else
93#define twl_has_usb() false
94#endif
95
96static inline void activate_irq(int irq)
97{
98#ifdef CONFIG_ARM
99 /* ARM requires an extra step to clear IRQ_NOREQUEST, which it
100 * sets on behalf of every irq_chip. Also sets IRQ_NOPROBE.
101 */
102 set_irq_flags(irq, IRQF_VALID);
103#else
104 /* same effect on other architectures */
105 set_irq_noprobe(irq);
106#endif
107}
108
109/* Primary Interrupt Handler on TWL4030 Registers */
110
111/* Register Definitions */
112
113#define REG_PIH_ISR_P1 (0x1)
114#define REG_PIH_ISR_P2 (0x2)
115#define REG_PIH_SIR (0x3)
116
117/* Triton Core internal information (BEGIN) */
118
119/* Last - for index max*/
120#define TWL4030_MODULE_LAST TWL4030_MODULE_SECURED_REG
121
122#define TWL4030_NUM_SLAVES 4
123
124
125/* Base Address defns for twl4030_map[] */
126
127/* subchip/slave 0 - USB ID */
128#define TWL4030_BASEADD_USB 0x0000
129
130/* subchip/slave 1 - AUD ID */
131#define TWL4030_BASEADD_AUDIO_VOICE 0x0000
132#define TWL4030_BASEADD_GPIO 0x0098
133#define TWL4030_BASEADD_INTBR 0x0085
134#define TWL4030_BASEADD_PIH 0x0080
135#define TWL4030_BASEADD_TEST 0x004C
136
137/* subchip/slave 2 - AUX ID */
138#define TWL4030_BASEADD_INTERRUPTS 0x00B9
139#define TWL4030_BASEADD_LED 0x00EE
140#define TWL4030_BASEADD_MADC 0x0000
141#define TWL4030_BASEADD_MAIN_CHARGE 0x0074
142#define TWL4030_BASEADD_PRECHARGE 0x00AA
143#define TWL4030_BASEADD_PWM0 0x00F8
144#define TWL4030_BASEADD_PWM1 0x00FB
145#define TWL4030_BASEADD_PWMA 0x00EF
146#define TWL4030_BASEADD_PWMB 0x00F1
147#define TWL4030_BASEADD_KEYPAD 0x00D2
148
149/* subchip/slave 3 - POWER ID */
150#define TWL4030_BASEADD_BACKUP 0x0014
151#define TWL4030_BASEADD_INT 0x002E
152#define TWL4030_BASEADD_PM_MASTER 0x0036
153#define TWL4030_BASEADD_PM_RECEIVER 0x005B
154#define TWL4030_BASEADD_RTC 0x001C
155#define TWL4030_BASEADD_SECURED_REG 0x0000
156
157/* Triton Core internal information (END) */
158
159
160/* Few power values */
161#define R_CFG_BOOT 0x05
162#define R_PROTECT_KEY 0x0E
163
164/* access control values for R_PROTECT_KEY */
165#define KEY_UNLOCK1 0xce
166#define KEY_UNLOCK2 0xec
167#define KEY_LOCK 0x00
168
169/* some fields in R_CFG_BOOT */
170#define HFCLK_FREQ_19p2_MHZ (1 << 0)
171#define HFCLK_FREQ_26_MHZ (2 << 0)
172#define HFCLK_FREQ_38p4_MHZ (3 << 0)
173#define HIGH_PERF_SQ (1 << 3)
174
175
176/*----------------------------------------------------------------------*/
177
178/**
179 * struct twl4030_mod_iregs - TWL module IMR/ISR regs to mask/clear at init
180 * @mod_no: TWL4030 module number (e.g., TWL4030_MODULE_GPIO)
181 * @sih_ctrl: address of module SIH_CTRL register
182 * @reg_cnt: number of IMR/ISR regs
183 * @imrs: pointer to array of TWL module interrupt mask register indices
184 * @isrs: pointer to array of TWL module interrupt status register indices
185 *
186 * Ties together TWL4030 modules and lists of IMR/ISR registers to mask/clear
187 * during twl_init_irq().
188 */
189struct twl4030_mod_iregs {
190 const u8 mod_no;
191 const u8 sih_ctrl;
192 const u8 reg_cnt;
193 const u8 *imrs;
194 const u8 *isrs;
195};
196
197/* TWL4030 INT module interrupt mask registers */
198static const u8 __initconst twl4030_int_imr_regs[] = {
199 TWL4030_INT_PWR_IMR1,
200 TWL4030_INT_PWR_IMR2,
201};
202
203/* TWL4030 INT module interrupt status registers */
204static const u8 __initconst twl4030_int_isr_regs[] = {
205 TWL4030_INT_PWR_ISR1,
206 TWL4030_INT_PWR_ISR2,
207};
208
209/* TWL4030 INTERRUPTS module interrupt mask registers */
210static const u8 __initconst twl4030_interrupts_imr_regs[] = {
211 TWL4030_INTERRUPTS_BCIIMR1A,
212 TWL4030_INTERRUPTS_BCIIMR1B,
213 TWL4030_INTERRUPTS_BCIIMR2A,
214 TWL4030_INTERRUPTS_BCIIMR2B,
215};
216
217/* TWL4030 INTERRUPTS module interrupt status registers */
218static const u8 __initconst twl4030_interrupts_isr_regs[] = {
219 TWL4030_INTERRUPTS_BCIISR1A,
220 TWL4030_INTERRUPTS_BCIISR1B,
221 TWL4030_INTERRUPTS_BCIISR2A,
222 TWL4030_INTERRUPTS_BCIISR2B,
223};
224
225/* TWL4030 MADC module interrupt mask registers */
226static const u8 __initconst twl4030_madc_imr_regs[] = {
227 TWL4030_MADC_IMR1,
228 TWL4030_MADC_IMR2,
229};
230
231/* TWL4030 MADC module interrupt status registers */
232static const u8 __initconst twl4030_madc_isr_regs[] = {
233 TWL4030_MADC_ISR1,
234 TWL4030_MADC_ISR2,
235};
236
237/* TWL4030 keypad module interrupt mask registers */
238static const u8 __initconst twl4030_keypad_imr_regs[] = {
239 TWL4030_KEYPAD_KEYP_IMR1,
240 TWL4030_KEYPAD_KEYP_IMR2,
241};
242
243/* TWL4030 keypad module interrupt status registers */
244static const u8 __initconst twl4030_keypad_isr_regs[] = {
245 TWL4030_KEYPAD_KEYP_ISR1,
246 TWL4030_KEYPAD_KEYP_ISR2,
247};
248
249/* TWL4030 GPIO module interrupt mask registers */
250static const u8 __initconst twl4030_gpio_imr_regs[] = {
251 REG_GPIO_IMR1A,
252 REG_GPIO_IMR1B,
253 REG_GPIO_IMR2A,
254 REG_GPIO_IMR2B,
255 REG_GPIO_IMR3A,
256 REG_GPIO_IMR3B,
257};
258
259/* TWL4030 GPIO module interrupt status registers */
260static const u8 __initconst twl4030_gpio_isr_regs[] = {
261 REG_GPIO_ISR1A,
262 REG_GPIO_ISR1B,
263 REG_GPIO_ISR2A,
264 REG_GPIO_ISR2B,
265 REG_GPIO_ISR3A,
266 REG_GPIO_ISR3B,
267};
268
269/* TWL4030 modules that have IMR/ISR registers that must be masked/cleared */
270static const struct twl4030_mod_iregs __initconst twl4030_mod_regs[] = {
271 {
272 .mod_no = TWL4030_MODULE_INT,
273 .sih_ctrl = TWL4030_INT_PWR_SIH_CTRL,
274 .reg_cnt = ARRAY_SIZE(twl4030_int_imr_regs),
275 .imrs = twl4030_int_imr_regs,
276 .isrs = twl4030_int_isr_regs,
277 },
278 {
279 .mod_no = TWL4030_MODULE_INTERRUPTS,
280 .sih_ctrl = TWL4030_INTERRUPTS_BCISIHCTRL,
281 .reg_cnt = ARRAY_SIZE(twl4030_interrupts_imr_regs),
282 .imrs = twl4030_interrupts_imr_regs,
283 .isrs = twl4030_interrupts_isr_regs,
284 },
285 {
286 .mod_no = TWL4030_MODULE_MADC,
287 .sih_ctrl = TWL4030_MADC_SIH_CTRL,
288 .reg_cnt = ARRAY_SIZE(twl4030_madc_imr_regs),
289 .imrs = twl4030_madc_imr_regs,
290 .isrs = twl4030_madc_isr_regs,
291 },
292 {
293 .mod_no = TWL4030_MODULE_KEYPAD,
294 .sih_ctrl = TWL4030_KEYPAD_KEYP_SIH_CTRL,
295 .reg_cnt = ARRAY_SIZE(twl4030_keypad_imr_regs),
296 .imrs = twl4030_keypad_imr_regs,
297 .isrs = twl4030_keypad_isr_regs,
298 },
299 {
300 .mod_no = TWL4030_MODULE_GPIO,
301 .sih_ctrl = REG_GPIO_SIH_CTRL,
302 .reg_cnt = ARRAY_SIZE(twl4030_gpio_imr_regs),
303 .imrs = twl4030_gpio_imr_regs,
304 .isrs = twl4030_gpio_isr_regs,
305 },
306};
307
308/*----------------------------------------------------------------*/
309
310/* is driver active, bound to a chip? */
311static bool inuse;
312
313/* Structure for each TWL4030 Slave */
314struct twl4030_client {
315 struct i2c_client *client;
316 u8 address;
317
318 /* max numb of i2c_msg required is for read =2 */
319 struct i2c_msg xfer_msg[2];
320
321 /* To lock access to xfer_msg */
322 struct mutex xfer_lock;
323};
324
325static struct twl4030_client twl4030_modules[TWL4030_NUM_SLAVES];
326
327
328/* mapping the module id to slave id and base address */
329struct twl4030mapping {
330 unsigned char sid; /* Slave ID */
331 unsigned char base; /* base address */
332};
333
334static struct twl4030mapping twl4030_map[TWL4030_MODULE_LAST + 1] = {
335 /*
336 * NOTE: don't change this table without updating the
337 * <linux/i2c/twl4030.h> defines for TWL4030_MODULE_*
338 * so they continue to match the order in this table.
339 */
340
341 { 0, TWL4030_BASEADD_USB },
342
343 { 1, TWL4030_BASEADD_AUDIO_VOICE },
344 { 1, TWL4030_BASEADD_GPIO },
345 { 1, TWL4030_BASEADD_INTBR },
346 { 1, TWL4030_BASEADD_PIH },
347 { 1, TWL4030_BASEADD_TEST },
348
349 { 2, TWL4030_BASEADD_KEYPAD },
350 { 2, TWL4030_BASEADD_MADC },
351 { 2, TWL4030_BASEADD_INTERRUPTS },
352 { 2, TWL4030_BASEADD_LED },
353 { 2, TWL4030_BASEADD_MAIN_CHARGE },
354 { 2, TWL4030_BASEADD_PRECHARGE },
355 { 2, TWL4030_BASEADD_PWM0 },
356 { 2, TWL4030_BASEADD_PWM1 },
357 { 2, TWL4030_BASEADD_PWMA },
358 { 2, TWL4030_BASEADD_PWMB },
359
360 { 3, TWL4030_BASEADD_BACKUP },
361 { 3, TWL4030_BASEADD_INT },
362 { 3, TWL4030_BASEADD_PM_MASTER },
363 { 3, TWL4030_BASEADD_PM_RECEIVER },
364 { 3, TWL4030_BASEADD_RTC },
365 { 3, TWL4030_BASEADD_SECURED_REG },
366};
367
368/*----------------------------------------------------------------------*/
369
370/*
371 * TWL4030 doesn't have PIH mask, hence dummy function for mask
372 * and unmask of the (eight) interrupts reported at that level ...
373 * masking is only available from SIH (secondary) modules.
374 */
375
376static void twl4030_i2c_ackirq(unsigned int irq)
377{
378}
379
380static void twl4030_i2c_disableint(unsigned int irq)
381{
382}
383
384static void twl4030_i2c_enableint(unsigned int irq)
385{
386}
387
388static struct irq_chip twl4030_irq_chip = {
389 .name = "twl4030",
390 .ack = twl4030_i2c_ackirq,
391 .mask = twl4030_i2c_disableint,
392 .unmask = twl4030_i2c_enableint,
393};
394
395/*----------------------------------------------------------------------*/
396
397/* Exported Functions */
398
399/**
400 * twl4030_i2c_write - Writes a n bit register in TWL4030
401 * @mod_no: module number
402 * @value: an array of num_bytes+1 containing data to write
403 * @reg: register address (just offset will do)
404 * @num_bytes: number of bytes to transfer
405 *
406 * IMPORTANT: for 'value' parameter: Allocate value num_bytes+1 and
407 * valid data starts at Offset 1.
408 *
409 * Returns the result of operation - 0 is success
410 */
411int twl4030_i2c_write(u8 mod_no, u8 *value, u8 reg, u8 num_bytes)
412{
413 int ret;
414 int sid;
415 struct twl4030_client *twl;
416 struct i2c_msg *msg;
417
418 if (unlikely(mod_no > TWL4030_MODULE_LAST)) {
419 pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
420 return -EPERM;
421 }
422 sid = twl4030_map[mod_no].sid;
423 twl = &twl4030_modules[sid];
424
425 if (unlikely(!inuse)) {
426 pr_err("%s: client %d is not initialized\n", DRIVER_NAME, sid);
427 return -EPERM;
428 }
429 mutex_lock(&twl->xfer_lock);
430 /*
431 * [MSG1]: fill the register address data
432 * fill the data Tx buffer
433 */
434 msg = &twl->xfer_msg[0];
435 msg->addr = twl->address;
436 msg->len = num_bytes + 1;
437 msg->flags = 0;
438 msg->buf = value;
439 /* over write the first byte of buffer with the register address */
440 *value = twl4030_map[mod_no].base + reg;
441 ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 1);
442 mutex_unlock(&twl->xfer_lock);
443
444 /* i2cTransfer returns num messages.translate it pls.. */
445 if (ret >= 0)
446 ret = 0;
447 return ret;
448}
449EXPORT_SYMBOL(twl4030_i2c_write);
450
451/**
452 * twl4030_i2c_read - Reads a n bit register in TWL4030
453 * @mod_no: module number
454 * @value: an array of num_bytes containing data to be read
455 * @reg: register address (just offset will do)
456 * @num_bytes: number of bytes to transfer
457 *
458 * Returns result of operation - num_bytes is success else failure.
459 */
460int twl4030_i2c_read(u8 mod_no, u8 *value, u8 reg, u8 num_bytes)
461{
462 int ret;
463 u8 val;
464 int sid;
465 struct twl4030_client *twl;
466 struct i2c_msg *msg;
467
468 if (unlikely(mod_no > TWL4030_MODULE_LAST)) {
469 pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
470 return -EPERM;
471 }
472 sid = twl4030_map[mod_no].sid;
473 twl = &twl4030_modules[sid];
474
475 if (unlikely(!inuse)) {
476 pr_err("%s: client %d is not initialized\n", DRIVER_NAME, sid);
477 return -EPERM;
478 }
479 mutex_lock(&twl->xfer_lock);
480 /* [MSG1] fill the register address data */
481 msg = &twl->xfer_msg[0];
482 msg->addr = twl->address;
483 msg->len = 1;
484 msg->flags = 0; /* Read the register value */
485 val = twl4030_map[mod_no].base + reg;
486 msg->buf = &val;
487 /* [MSG2] fill the data rx buffer */
488 msg = &twl->xfer_msg[1];
489 msg->addr = twl->address;
490 msg->flags = I2C_M_RD; /* Read the register value */
491 msg->len = num_bytes; /* only n bytes */
492 msg->buf = value;
493 ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 2);
494 mutex_unlock(&twl->xfer_lock);
495
496 /* i2cTransfer returns num messages.translate it pls.. */
497 if (ret >= 0)
498 ret = 0;
499 return ret;
500}
501EXPORT_SYMBOL(twl4030_i2c_read);
502
503/**
504 * twl4030_i2c_write_u8 - Writes a 8 bit register in TWL4030
505 * @mod_no: module number
506 * @value: the value to be written 8 bit
507 * @reg: register address (just offset will do)
508 *
509 * Returns result of operation - 0 is success
510 */
511int twl4030_i2c_write_u8(u8 mod_no, u8 value, u8 reg)
512{
513
514 /* 2 bytes offset 1 contains the data offset 0 is used by i2c_write */
515 u8 temp_buffer[2] = { 0 };
516 /* offset 1 contains the data */
517 temp_buffer[1] = value;
518 return twl4030_i2c_write(mod_no, temp_buffer, reg, 1);
519}
520EXPORT_SYMBOL(twl4030_i2c_write_u8);
521
522/**
523 * twl4030_i2c_read_u8 - Reads a 8 bit register from TWL4030
524 * @mod_no: module number
525 * @value: the value read 8 bit
526 * @reg: register address (just offset will do)
527 *
528 * Returns result of operation - 0 is success
529 */
530int twl4030_i2c_read_u8(u8 mod_no, u8 *value, u8 reg)
531{
532 return twl4030_i2c_read(mod_no, value, reg, 1);
533}
534EXPORT_SYMBOL(twl4030_i2c_read_u8);
535
536/*----------------------------------------------------------------------*/
537
538static unsigned twl4030_irq_base;
539
540static struct completion irq_event;
541
542/*
543 * This thread processes interrupts reported by the Primary Interrupt Handler.
544 */
545static int twl4030_irq_thread(void *data)
546{
547 long irq = (long)data;
548 irq_desc_t *desc = irq_desc + irq;
549 static unsigned i2c_errors;
550 const static unsigned max_i2c_errors = 100;
551
552 current->flags |= PF_NOFREEZE;
553
554 while (!kthread_should_stop()) {
555 int ret;
556 int module_irq;
557 u8 pih_isr;
558
559 /* Wait for IRQ, then read PIH irq status (also blocking) */
560 wait_for_completion_interruptible(&irq_event);
561
562 ret = twl4030_i2c_read_u8(TWL4030_MODULE_PIH, &pih_isr,
563 REG_PIH_ISR_P1);
564 if (ret) {
565 pr_warning("%s: I2C error %d reading PIH ISR\n",
566 DRIVER_NAME, ret);
567 if (++i2c_errors >= max_i2c_errors) {
568 printk(KERN_ERR "Maximum I2C error count"
569 " exceeded. Terminating %s.\n",
570 __func__);
571 break;
572 }
573 complete(&irq_event);
574 continue;
575 }
576
577 /* these handlers deal with the relevant SIH irq status */
578 local_irq_disable();
579 for (module_irq = twl4030_irq_base;
580 pih_isr;
581 pih_isr >>= 1, module_irq++) {
582 if (pih_isr & 0x1) {
583 irq_desc_t *d = irq_desc + module_irq;
584
585 d->handle_irq(module_irq, d);
586 }
587 }
588 local_irq_enable();
589
590 desc->chip->unmask(irq);
591 }
592
593 return 0;
594}
595
596/*
597 * do_twl4030_irq() is the desc->handle method for the twl4030 interrupt.
598 * This is a chained interrupt, so there is no desc->action method for it.
599 * Now we need to query the interrupt controller in the twl4030 to determine
600 * which module is generating the interrupt request. However, we can't do i2c
601 * transactions in interrupt context, so we must defer that work to a kernel
602 * thread. All we do here is acknowledge and mask the interrupt and wakeup
603 * the kernel thread.
604 */
605static void do_twl4030_irq(unsigned int irq, irq_desc_t *desc)
606{
607 const unsigned int cpu = smp_processor_id();
608
609 /*
610 * Earlier this was desc->triggered = 1;
611 */
612 desc->status |= IRQ_LEVEL;
613
614 /*
615 * Acknowledge, clear _AND_ disable the interrupt.
616 */
617 desc->chip->ack(irq);
618
619 if (!desc->depth) {
620 kstat_cpu(cpu).irqs[irq]++;
621
622 complete(&irq_event);
623 }
624}
625
626static struct task_struct * __init start_twl4030_irq_thread(long irq)
627{
628 struct task_struct *thread;
629
630 init_completion(&irq_event);
631 thread = kthread_run(twl4030_irq_thread, (void *)irq, "twl4030-irq");
632 if (!thread)
633 pr_err("%s: could not create twl4030 irq %ld thread!\n",
634 DRIVER_NAME, irq);
635
636 return thread;
637}
638
639/*----------------------------------------------------------------------*/
640
641static int add_children(struct twl4030_platform_data *pdata)
642{
643 struct platform_device *pdev = NULL;
644 struct twl4030_client *twl = NULL;
645 int status = 0;
646
647 if (twl_has_bci() && pdata->bci) {
648 twl = &twl4030_modules[3];
649
650 pdev = platform_device_alloc("twl4030_bci", -1);
651 if (!pdev) {
652 pr_debug("%s: can't alloc bci dev\n", DRIVER_NAME);
653 status = -ENOMEM;
654 goto err;
655 }
656
657 if (status == 0) {
658 pdev->dev.parent = &twl->client->dev;
659 status = platform_device_add_data(pdev, pdata->bci,
660 sizeof(*pdata->bci));
661 if (status < 0) {
662 dev_dbg(&twl->client->dev,
663 "can't add bci data, %d\n",
664 status);
665 goto err;
666 }
667 }
668
669 if (status == 0) {
670 struct resource r = {
671 .start = TWL4030_PWRIRQ_CHG_PRES,
672 .flags = IORESOURCE_IRQ,
673 };
674
675 status = platform_device_add_resources(pdev, &r, 1);
676 }
677
678 if (status == 0)
679 status = platform_device_add(pdev);
680
681 if (status < 0) {
682 platform_device_put(pdev);
683 dev_dbg(&twl->client->dev,
684 "can't create bci dev, %d\n",
685 status);
686 goto err;
687 }
688 }
689
690 if (twl_has_gpio() && pdata->gpio) {
691 twl = &twl4030_modules[1];
692
693 pdev = platform_device_alloc("twl4030_gpio", -1);
694 if (!pdev) {
695 pr_debug("%s: can't alloc gpio dev\n", DRIVER_NAME);
696 status = -ENOMEM;
697 goto err;
698 }
699
700 /* more driver model init */
701 if (status == 0) {
702 pdev->dev.parent = &twl->client->dev;
703 /* device_init_wakeup(&pdev->dev, 1); */
704
705 status = platform_device_add_data(pdev, pdata->gpio,
706 sizeof(*pdata->gpio));
707 if (status < 0) {
708 dev_dbg(&twl->client->dev,
709 "can't add gpio data, %d\n",
710 status);
711 goto err;
712 }
713 }
714
715 /* GPIO module IRQ */
716 if (status == 0) {
717 struct resource r = {
718 .start = pdata->irq_base + 0,
719 .flags = IORESOURCE_IRQ,
720 };
721
722 status = platform_device_add_resources(pdev, &r, 1);
723 }
724
725 if (status == 0)
726 status = platform_device_add(pdev);
727
728 if (status < 0) {
729 platform_device_put(pdev);
730 dev_dbg(&twl->client->dev,
731 "can't create gpio dev, %d\n",
732 status);
733 goto err;
734 }
735 }
736
737 if (twl_has_keypad() && pdata->keypad) {
738 pdev = platform_device_alloc("twl4030_keypad", -1);
739 if (pdev) {
740 twl = &twl4030_modules[2];
741 pdev->dev.parent = &twl->client->dev;
742 device_init_wakeup(&pdev->dev, 1);
743 status = platform_device_add_data(pdev, pdata->keypad,
744 sizeof(*pdata->keypad));
745 if (status < 0) {
746 dev_dbg(&twl->client->dev,
747 "can't add keypad data, %d\n",
748 status);
749 platform_device_put(pdev);
750 goto err;
751 }
752 status = platform_device_add(pdev);
753 if (status < 0) {
754 platform_device_put(pdev);
755 dev_dbg(&twl->client->dev,
756 "can't create keypad dev, %d\n",
757 status);
758 goto err;
759 }
760 } else {
761 pr_debug("%s: can't alloc keypad dev\n", DRIVER_NAME);
762 status = -ENOMEM;
763 goto err;
764 }
765 }
766
767 if (twl_has_madc() && pdata->madc) {
768 pdev = platform_device_alloc("twl4030_madc", -1);
769 if (pdev) {
770 twl = &twl4030_modules[2];
771 pdev->dev.parent = &twl->client->dev;
772 device_init_wakeup(&pdev->dev, 1);
773 status = platform_device_add_data(pdev, pdata->madc,
774 sizeof(*pdata->madc));
775 if (status < 0) {
776 platform_device_put(pdev);
777 dev_dbg(&twl->client->dev,
778 "can't add madc data, %d\n",
779 status);
780 goto err;
781 }
782 status = platform_device_add(pdev);
783 if (status < 0) {
784 platform_device_put(pdev);
785 dev_dbg(&twl->client->dev,
786 "can't create madc dev, %d\n",
787 status);
788 goto err;
789 }
790 } else {
791 pr_debug("%s: can't alloc madc dev\n", DRIVER_NAME);
792 status = -ENOMEM;
793 goto err;
794 }
795 }
796
797 if (twl_has_rtc()) {
798 twl = &twl4030_modules[3];
799
800 pdev = platform_device_alloc("twl4030_rtc", -1);
801 if (!pdev) {
802 pr_debug("%s: can't alloc rtc dev\n", DRIVER_NAME);
803 status = -ENOMEM;
804 } else {
805 pdev->dev.parent = &twl->client->dev;
806 device_init_wakeup(&pdev->dev, 1);
807 }
808
809 /*
810 * REVISIT platform_data here currently might use of
811 * "msecure" line ... but for now we just expect board
812 * setup to tell the chip "we are secure" at all times.
813 * Eventually, Linux might become more aware of such
814 * HW security concerns, and "least privilege".
815 */
816
817 /* RTC module IRQ */
818 if (status == 0) {
819 struct resource r = {
820 /* REVISIT don't hard-wire this stuff */
821 .start = TWL4030_PWRIRQ_RTC,
822 .flags = IORESOURCE_IRQ,
823 };
824
825 status = platform_device_add_resources(pdev, &r, 1);
826 }
827
828 if (status == 0)
829 status = platform_device_add(pdev);
830
831 if (status < 0) {
832 platform_device_put(pdev);
833 dev_dbg(&twl->client->dev,
834 "can't create rtc dev, %d\n",
835 status);
836 goto err;
837 }
838 }
839
840 if (twl_has_usb() && pdata->usb) {
841 twl = &twl4030_modules[0];
842
843 pdev = platform_device_alloc("twl4030_usb", -1);
844 if (!pdev) {
845 pr_debug("%s: can't alloc usb dev\n", DRIVER_NAME);
846 status = -ENOMEM;
847 goto err;
848 }
849
850 if (status == 0) {
851 pdev->dev.parent = &twl->client->dev;
852 device_init_wakeup(&pdev->dev, 1);
853 status = platform_device_add_data(pdev, pdata->usb,
854 sizeof(*pdata->usb));
855 if (status < 0) {
856 platform_device_put(pdev);
857 dev_dbg(&twl->client->dev,
858 "can't add usb data, %d\n",
859 status);
860 goto err;
861 }
862 }
863
864 if (status == 0) {
865 struct resource r = {
866 .start = TWL4030_PWRIRQ_USB_PRES,
867 .flags = IORESOURCE_IRQ,
868 };
869
870 status = platform_device_add_resources(pdev, &r, 1);
871 }
872
873 if (status == 0)
874 status = platform_device_add(pdev);
875
876 if (status < 0) {
877 platform_device_put(pdev);
878 dev_dbg(&twl->client->dev,
879 "can't create usb dev, %d\n",
880 status);
881 }
882 }
883
884err:
885 if (status)
886 pr_err("failed to add twl4030's children (status %d)\n", status);
887 return status;
888}
889
890/*----------------------------------------------------------------------*/
891
892/*
893 * These three functions initialize the on-chip clock framework,
894 * letting it generate the right frequencies for USB, MADC, and
895 * other purposes.
896 */
897static inline int __init protect_pm_master(void)
898{
899 int e = 0;
900
901 e = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_LOCK,
902 R_PROTECT_KEY);
903 return e;
904}
905
906static inline int __init unprotect_pm_master(void)
907{
908 int e = 0;
909
910 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_UNLOCK1,
911 R_PROTECT_KEY);
912 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_UNLOCK2,
913 R_PROTECT_KEY);
914 return e;
915}
916
917static void __init clocks_init(void)
918{
919 int e = 0;
920 struct clk *osc;
921 u32 rate;
922 u8 ctrl = HFCLK_FREQ_26_MHZ;
923
924#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
925 if (cpu_is_omap2430())
926 osc = clk_get(NULL, "osc_ck");
927 else
928 osc = clk_get(NULL, "osc_sys_ck");
929#else
930 /* REVISIT for non-OMAP systems, pass the clock rate from
931 * board init code, using platform_data.
932 */
933 osc = ERR_PTR(-EIO);
934#endif
935 if (IS_ERR(osc)) {
936 printk(KERN_WARNING "Skipping twl4030 internal clock init and "
937 "using bootloader value (unknown osc rate)\n");
938 return;
939 }
940
941 rate = clk_get_rate(osc);
942 clk_put(osc);
943
944 switch (rate) {
945 case 19200000:
946 ctrl = HFCLK_FREQ_19p2_MHZ;
947 break;
948 case 26000000:
949 ctrl = HFCLK_FREQ_26_MHZ;
950 break;
951 case 38400000:
952 ctrl = HFCLK_FREQ_38p4_MHZ;
953 break;
954 }
955
956 ctrl |= HIGH_PERF_SQ;
957 e |= unprotect_pm_master();
958 /* effect->MADC+USB ck en */
959 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, ctrl, R_CFG_BOOT);
960 e |= protect_pm_master();
961
962 if (e < 0)
963 pr_err("%s: clock init err [%d]\n", DRIVER_NAME, e);
964}
965
966/*----------------------------------------------------------------------*/
967
968/**
969 * twl4030_i2c_clear_isr - clear TWL4030 SIH ISR regs via read + write
970 * @mod_no: TWL4030 module number
971 * @reg: register index to clear
972 * @cor: value of the <module>_SIH_CTRL.COR bit (1 or 0)
973 *
974 * Either reads (cor == 1) or writes (cor == 0) to a TWL4030 interrupt
975 * status register to ensure that any prior interrupts are cleared.
976 * Returns the status from the I2C read operation.
977 */
978static int __init twl4030_i2c_clear_isr(u8 mod_no, u8 reg, u8 cor)
979{
980 u8 tmp;
981
982 return (cor) ? twl4030_i2c_read_u8(mod_no, &tmp, reg) :
983 twl4030_i2c_write_u8(mod_no, 0xff, reg);
984}
985
986/**
987 * twl4030_read_cor_bit - are TWL module ISRs cleared by reads or writes?
988 * @mod_no: TWL4030 module number
989 * @reg: register index to clear
990 *
991 * Returns 1 if the TWL4030 SIH interrupt status registers (ISRs) for
992 * the specified TWL module are cleared by reads, or 0 if cleared by
993 * writes.
994 */
995static int twl4030_read_cor_bit(u8 mod_no, u8 reg)
996{
997 u8 tmp = 0;
998
999 WARN_ON(twl4030_i2c_read_u8(mod_no, &tmp, reg) < 0);
1000
1001 tmp &= TWL4030_SIH_CTRL_COR_MASK;
1002 tmp >>= __ffs(TWL4030_SIH_CTRL_COR_MASK);
1003
1004 return tmp;
1005}
1006
1007/**
1008 * twl4030_mask_clear_intrs - mask and clear all TWL4030 interrupts
1009 * @t: pointer to twl4030_mod_iregs array
1010 * @t_sz: ARRAY_SIZE(t) (starting at 1)
1011 *
1012 * Mask all TWL4030 interrupt mask registers (IMRs) and clear all
1013 * interrupt status registers (ISRs). No return value, but will WARN if
1014 * any I2C operations fail.
1015 */
1016static void __init twl4030_mask_clear_intrs(const struct twl4030_mod_iregs *t,
1017 const u8 t_sz)
1018{
1019 int i, j;
1020
1021 /*
1022 * N.B. - further efficiency is possible here. Eight I2C
1023 * operations on BCI and GPIO modules are avoidable if I2C
1024 * burst read/write transactions were implemented. Would
1025 * probably save about 1ms of boot time and a small amount of
1026 * power.
1027 */
1028 for (i = 0; i < t_sz; i++) {
1029 const struct twl4030_mod_iregs tmr = t[i];
1030 int cor;
1031
1032 /* Are ISRs cleared by reads or writes? */
1033 cor = twl4030_read_cor_bit(tmr.mod_no, tmr.sih_ctrl);
1034
1035 for (j = 0; j < tmr.reg_cnt; j++) {
1036
1037 /* Mask interrupts at the TWL4030 */
1038 WARN_ON(twl4030_i2c_write_u8(tmr.mod_no, 0xff,
1039 tmr.imrs[j]) < 0);
1040
1041 /* Clear TWL4030 ISRs */
1042 WARN_ON(twl4030_i2c_clear_isr(tmr.mod_no,
1043 tmr.isrs[j], cor) < 0);
1044 }
1045 }
1046}
1047
1048
1049static void twl_init_irq(int irq_num, unsigned irq_base, unsigned irq_end)
1050{
1051 int i;
1052
1053 /*
1054 * Mask and clear all TWL4030 interrupts since initially we do
1055 * not have any TWL4030 module interrupt handlers present
1056 */
1057 twl4030_mask_clear_intrs(twl4030_mod_regs,
1058 ARRAY_SIZE(twl4030_mod_regs));
1059
1060 twl4030_irq_base = irq_base;
1061
1062 /* install an irq handler for each of the PIH modules */
1063 for (i = irq_base; i < irq_end; i++) {
1064 set_irq_chip_and_handler(i, &twl4030_irq_chip,
1065 handle_simple_irq);
1066 activate_irq(i);
1067 }
1068
1069 /* install an irq handler to demultiplex the TWL4030 interrupt */
1070 set_irq_data(irq_num, start_twl4030_irq_thread(irq_num));
1071 set_irq_chained_handler(irq_num, do_twl4030_irq);
1072}
1073
1074/*----------------------------------------------------------------------*/
1075
1076static int twl4030_remove(struct i2c_client *client)
1077{
1078 unsigned i;
1079
1080 /* FIXME undo twl_init_irq() */
1081 if (twl4030_irq_base) {
1082 dev_err(&client->dev, "can't yet clean up IRQs?\n");
1083 return -ENOSYS;
1084 }
1085
1086 for (i = 0; i < TWL4030_NUM_SLAVES; i++) {
1087 struct twl4030_client *twl = &twl4030_modules[i];
1088
1089 if (twl->client && twl->client != client)
1090 i2c_unregister_device(twl->client);
1091 twl4030_modules[i].client = NULL;
1092 }
1093 inuse = false;
1094 return 0;
1095}
1096
1097/* NOTE: this driver only handles a single twl4030/tps659x0 chip */
1098static int
1099twl4030_probe(struct i2c_client *client, const struct i2c_device_id *id)
1100{
1101 int status;
1102 unsigned i;
1103 struct twl4030_platform_data *pdata = client->dev.platform_data;
1104
1105 if (!pdata) {
1106 dev_dbg(&client->dev, "no platform data?\n");
1107 return -EINVAL;
1108 }
1109
1110 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
1111 dev_dbg(&client->dev, "can't talk I2C?\n");
1112 return -EIO;
1113 }
1114
1115 if (inuse || twl4030_irq_base) {
1116 dev_dbg(&client->dev, "driver is already in use\n");
1117 return -EBUSY;
1118 }
1119
1120 for (i = 0; i < TWL4030_NUM_SLAVES; i++) {
1121 struct twl4030_client *twl = &twl4030_modules[i];
1122
1123 twl->address = client->addr + i;
1124 if (i == 0)
1125 twl->client = client;
1126 else {
1127 twl->client = i2c_new_dummy(client->adapter,
1128 twl->address);
1129 if (!twl->client) {
1130 dev_err(&twl->client->dev,
1131 "can't attach client %d\n", i);
1132 status = -ENOMEM;
1133 goto fail;
1134 }
1135 strlcpy(twl->client->name, id->name,
1136 sizeof(twl->client->name));
1137 }
1138 mutex_init(&twl->xfer_lock);
1139 }
1140 inuse = true;
1141
1142 /* setup clock framework */
1143 clocks_init();
1144
1145 /* Maybe init the T2 Interrupt subsystem */
1146 if (client->irq
1147 && pdata->irq_base
1148 && pdata->irq_end > pdata->irq_base) {
1149 twl_init_irq(client->irq, pdata->irq_base, pdata->irq_end);
1150 dev_info(&client->dev, "IRQ %d chains IRQs %d..%d\n",
1151 client->irq, pdata->irq_base, pdata->irq_end - 1);
1152 }
1153
1154 status = add_children(pdata);
1155fail:
1156 if (status < 0)
1157 twl4030_remove(client);
1158 return status;
1159}
1160
1161static const struct i2c_device_id twl4030_ids[] = {
1162 { "twl4030", 0 }, /* "Triton 2" */
1163 { "tps65950", 0 }, /* catalog version of twl4030 */
1164 { "tps65930", 0 }, /* fewer LDOs and DACs; no charger */
1165 { "tps65920", 0 }, /* fewer LDOs; no codec or charger */
1166 { "twl5030", 0 }, /* T2 updated */
1167 { /* end of list */ },
1168};
1169MODULE_DEVICE_TABLE(i2c, twl4030_ids);
1170
1171/* One Client Driver , 4 Clients */
1172static struct i2c_driver twl4030_driver = {
1173 .driver.name = DRIVER_NAME,
1174 .id_table = twl4030_ids,
1175 .probe = twl4030_probe,
1176 .remove = twl4030_remove,
1177};
1178
1179static int __init twl4030_init(void)
1180{
1181 return i2c_add_driver(&twl4030_driver);
1182}
1183subsys_initcall(twl4030_init);
1184
1185static void __exit twl4030_exit(void)
1186{
1187 i2c_del_driver(&twl4030_driver);
1188}
1189module_exit(twl4030_exit);
1190
1191MODULE_AUTHOR("Texas Instruments, Inc.");
1192MODULE_DESCRIPTION("I2C Core interface for TWL4030");
1193MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c
index 25a7a5d08bce..bf87f675e7fa 100644
--- a/drivers/mfd/wm8350-core.c
+++ b/drivers/mfd/wm8350-core.c
@@ -1217,7 +1217,7 @@ int wm8350_device_init(struct wm8350 *wm8350, int irq,
1217 1217
1218 mutex_init(&wm8350->irq_mutex); 1218 mutex_init(&wm8350->irq_mutex);
1219 INIT_WORK(&wm8350->irq_work, wm8350_irq_worker); 1219 INIT_WORK(&wm8350->irq_work, wm8350_irq_worker);
1220 if (irq != NO_IRQ) { 1220 if (irq) {
1221 ret = request_irq(irq, wm8350_irq, 0, 1221 ret = request_irq(irq, wm8350_irq, 0,
1222 "wm8350", wm8350); 1222 "wm8350", wm8350);
1223 if (ret != 0) { 1223 if (ret != 0) {