]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/mfd/88pm860x-core.c
Merge branch 'slab/for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/penber...
[karo-tx-linux.git] / drivers / mfd / 88pm860x-core.c
1 /*
2  * Base driver for Marvell 88PM8607
3  *
4  * Copyright (C) 2009 Marvell International Ltd.
5  *      Haojian Zhuang <haojian.zhuang@marvell.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/err.h>
15 #include <linux/i2c.h>
16 #include <linux/irq.h>
17 #include <linux/interrupt.h>
18 #include <linux/irqdomain.h>
19 #include <linux/of.h>
20 #include <linux/of_platform.h>
21 #include <linux/platform_device.h>
22 #include <linux/regmap.h>
23 #include <linux/slab.h>
24 #include <linux/mfd/core.h>
25 #include <linux/mfd/88pm860x.h>
26 #include <linux/regulator/machine.h>
27
28 #define INT_STATUS_NUM                  3
29
30 static struct resource bk0_resources[] __devinitdata = {
31         {2, 2, "duty cycle", IORESOURCE_REG, },
32         {3, 3, "always on",  IORESOURCE_REG, },
33         {3, 3, "current",    IORESOURCE_REG, },
34 };
35 static struct resource bk1_resources[] __devinitdata = {
36         {4, 4, "duty cycle", IORESOURCE_REG, },
37         {5, 5, "always on",  IORESOURCE_REG, },
38         {5, 5, "current",    IORESOURCE_REG, },
39 };
40 static struct resource bk2_resources[] __devinitdata = {
41         {6, 6, "duty cycle", IORESOURCE_REG, },
42         {7, 7, "always on",  IORESOURCE_REG, },
43         {5, 5, "current",    IORESOURCE_REG, },
44 };
45
46 static struct resource led0_resources[] __devinitdata = {
47         /* RGB1 Red LED */
48         {0xd, 0xd, "control", IORESOURCE_REG, },
49         {0xc, 0xc, "blink",   IORESOURCE_REG, },
50 };
51 static struct resource led1_resources[] __devinitdata = {
52         /* RGB1 Green LED */
53         {0xe, 0xe, "control", IORESOURCE_REG, },
54         {0xc, 0xc, "blink",   IORESOURCE_REG, },
55 };
56 static struct resource led2_resources[] __devinitdata = {
57         /* RGB1 Blue LED */
58         {0xf, 0xf, "control", IORESOURCE_REG, },
59         {0xc, 0xc, "blink",   IORESOURCE_REG, },
60 };
61 static struct resource led3_resources[] __devinitdata = {
62         /* RGB2 Red LED */
63         {0x9, 0x9, "control", IORESOURCE_REG, },
64         {0x8, 0x8, "blink",   IORESOURCE_REG, },
65 };
66 static struct resource led4_resources[] __devinitdata = {
67         /* RGB2 Green LED */
68         {0xa, 0xa, "control", IORESOURCE_REG, },
69         {0x8, 0x8, "blink",   IORESOURCE_REG, },
70 };
71 static struct resource led5_resources[] __devinitdata = {
72         /* RGB2 Blue LED */
73         {0xb, 0xb, "control", IORESOURCE_REG, },
74         {0x8, 0x8, "blink",   IORESOURCE_REG, },
75 };
76
77 static struct resource buck1_resources[] __devinitdata = {
78         {0x24, 0x24, "buck set", IORESOURCE_REG, },
79 };
80 static struct resource buck2_resources[] __devinitdata = {
81         {0x25, 0x25, "buck set", IORESOURCE_REG, },
82 };
83 static struct resource buck3_resources[] __devinitdata = {
84         {0x26, 0x26, "buck set", IORESOURCE_REG, },
85 };
86 static struct resource ldo1_resources[] __devinitdata = {
87         {0x10, 0x10, "ldo set", IORESOURCE_REG, },
88 };
89 static struct resource ldo2_resources[] __devinitdata = {
90         {0x11, 0x11, "ldo set", IORESOURCE_REG, },
91 };
92 static struct resource ldo3_resources[] __devinitdata = {
93         {0x12, 0x12, "ldo set", IORESOURCE_REG, },
94 };
95 static struct resource ldo4_resources[] __devinitdata = {
96         {0x13, 0x13, "ldo set", IORESOURCE_REG, },
97 };
98 static struct resource ldo5_resources[] __devinitdata = {
99         {0x14, 0x14, "ldo set", IORESOURCE_REG, },
100 };
101 static struct resource ldo6_resources[] __devinitdata = {
102         {0x15, 0x15, "ldo set", IORESOURCE_REG, },
103 };
104 static struct resource ldo7_resources[] __devinitdata = {
105         {0x16, 0x16, "ldo set", IORESOURCE_REG, },
106 };
107 static struct resource ldo8_resources[] __devinitdata = {
108         {0x17, 0x17, "ldo set", IORESOURCE_REG, },
109 };
110 static struct resource ldo9_resources[] __devinitdata = {
111         {0x18, 0x18, "ldo set", IORESOURCE_REG, },
112 };
113 static struct resource ldo10_resources[] __devinitdata = {
114         {0x19, 0x19, "ldo set", IORESOURCE_REG, },
115 };
116 static struct resource ldo12_resources[] __devinitdata = {
117         {0x1a, 0x1a, "ldo set", IORESOURCE_REG, },
118 };
119 static struct resource ldo_vibrator_resources[] __devinitdata = {
120         {0x28, 0x28, "ldo set", IORESOURCE_REG, },
121 };
122 static struct resource ldo14_resources[] __devinitdata = {
123         {0x1b, 0x1b, "ldo set", IORESOURCE_REG, },
124 };
125
126 static struct resource touch_resources[] __devinitdata = {
127         {PM8607_IRQ_PEN, PM8607_IRQ_PEN, "touch", IORESOURCE_IRQ,},
128 };
129
130 static struct resource onkey_resources[] __devinitdata = {
131         {PM8607_IRQ_ONKEY, PM8607_IRQ_ONKEY, "onkey", IORESOURCE_IRQ,},
132 };
133
134 static struct resource codec_resources[] __devinitdata = {
135         /* Headset microphone insertion or removal */
136         {PM8607_IRQ_MICIN,   PM8607_IRQ_MICIN,   "micin",   IORESOURCE_IRQ,},
137         /* Hook-switch press or release */
138         {PM8607_IRQ_HOOK,    PM8607_IRQ_HOOK,    "hook",    IORESOURCE_IRQ,},
139         /* Headset insertion or removal */
140         {PM8607_IRQ_HEADSET, PM8607_IRQ_HEADSET, "headset", IORESOURCE_IRQ,},
141         /* Audio short */
142         {PM8607_IRQ_AUDIO_SHORT, PM8607_IRQ_AUDIO_SHORT, "audio-short", IORESOURCE_IRQ,},
143 };
144
145 static struct resource battery_resources[] __devinitdata = {
146         {PM8607_IRQ_CC,  PM8607_IRQ_CC,  "columb counter", IORESOURCE_IRQ,},
147         {PM8607_IRQ_BAT, PM8607_IRQ_BAT, "battery",        IORESOURCE_IRQ,},
148 };
149
150 static struct resource charger_resources[] __devinitdata = {
151         {PM8607_IRQ_CHG,  PM8607_IRQ_CHG,  "charger detect",  IORESOURCE_IRQ,},
152         {PM8607_IRQ_CHG_DONE,  PM8607_IRQ_CHG_DONE,  "charging done",       IORESOURCE_IRQ,},
153         {PM8607_IRQ_CHG_FAULT, PM8607_IRQ_CHG_FAULT, "charging timeout",    IORESOURCE_IRQ,},
154         {PM8607_IRQ_GPADC1,    PM8607_IRQ_GPADC1,    "battery temperature", IORESOURCE_IRQ,},
155         {PM8607_IRQ_VBAT, PM8607_IRQ_VBAT, "battery voltage", IORESOURCE_IRQ,},
156         {PM8607_IRQ_VCHG, PM8607_IRQ_VCHG, "vchg voltage",    IORESOURCE_IRQ,},
157 };
158
159 static struct resource rtc_resources[] __devinitdata = {
160         {PM8607_IRQ_RTC, PM8607_IRQ_RTC, "rtc", IORESOURCE_IRQ,},
161 };
162
163 static struct mfd_cell bk_devs[] __devinitdata = {
164         {
165                 .name = "88pm860x-backlight",
166                 .id = 0,
167                 .num_resources = ARRAY_SIZE(bk0_resources),
168                 .resources = bk0_resources,
169         }, {
170                 .name = "88pm860x-backlight",
171                 .id = 1,
172                 .num_resources = ARRAY_SIZE(bk1_resources),
173                 .resources = bk1_resources,
174         }, {
175                 .name = "88pm860x-backlight",
176                 .id = 2,
177                 .num_resources = ARRAY_SIZE(bk2_resources),
178                 .resources = bk2_resources,
179         },
180 };
181
182 static struct mfd_cell led_devs[] __devinitdata = {
183         {
184                 .name = "88pm860x-led",
185                 .id = 0,
186                 .num_resources = ARRAY_SIZE(led0_resources),
187                 .resources = led0_resources,
188         }, {
189                 .name = "88pm860x-led",
190                 .id = 1,
191                 .num_resources = ARRAY_SIZE(led1_resources),
192                 .resources = led1_resources,
193         }, {
194                 .name = "88pm860x-led",
195                 .id = 2,
196                 .num_resources = ARRAY_SIZE(led2_resources),
197                 .resources = led2_resources,
198         }, {
199                 .name = "88pm860x-led",
200                 .id = 3,
201                 .num_resources = ARRAY_SIZE(led3_resources),
202                 .resources = led3_resources,
203         }, {
204                 .name = "88pm860x-led",
205                 .id = 4,
206                 .num_resources = ARRAY_SIZE(led4_resources),
207                 .resources = led4_resources,
208         }, {
209                 .name = "88pm860x-led",
210                 .id = 5,
211                 .num_resources = ARRAY_SIZE(led5_resources),
212                 .resources = led5_resources,
213         },
214 };
215
216 static struct mfd_cell reg_devs[] __devinitdata = {
217         {
218                 .name = "88pm860x-regulator",
219                 .id = 0,
220                 .num_resources = ARRAY_SIZE(buck1_resources),
221                 .resources = buck1_resources,
222         }, {
223                 .name = "88pm860x-regulator",
224                 .id = 1,
225                 .num_resources = ARRAY_SIZE(buck2_resources),
226                 .resources = buck2_resources,
227         }, {
228                 .name = "88pm860x-regulator",
229                 .id = 2,
230                 .num_resources = ARRAY_SIZE(buck3_resources),
231                 .resources = buck3_resources,
232         }, {
233                 .name = "88pm860x-regulator",
234                 .id = 3,
235                 .num_resources = ARRAY_SIZE(ldo1_resources),
236                 .resources = ldo1_resources,
237         }, {
238                 .name = "88pm860x-regulator",
239                 .id = 4,
240                 .num_resources = ARRAY_SIZE(ldo2_resources),
241                 .resources = ldo2_resources,
242         }, {
243                 .name = "88pm860x-regulator",
244                 .id = 5,
245                 .num_resources = ARRAY_SIZE(ldo3_resources),
246                 .resources = ldo3_resources,
247         }, {
248                 .name = "88pm860x-regulator",
249                 .id = 6,
250                 .num_resources = ARRAY_SIZE(ldo4_resources),
251                 .resources = ldo4_resources,
252         }, {
253                 .name = "88pm860x-regulator",
254                 .id = 7,
255                 .num_resources = ARRAY_SIZE(ldo5_resources),
256                 .resources = ldo5_resources,
257         }, {
258                 .name = "88pm860x-regulator",
259                 .id = 8,
260                 .num_resources = ARRAY_SIZE(ldo6_resources),
261                 .resources = ldo6_resources,
262         }, {
263                 .name = "88pm860x-regulator",
264                 .id = 9,
265                 .num_resources = ARRAY_SIZE(ldo7_resources),
266                 .resources = ldo7_resources,
267         }, {
268                 .name = "88pm860x-regulator",
269                 .id = 10,
270                 .num_resources = ARRAY_SIZE(ldo8_resources),
271                 .resources = ldo8_resources,
272         }, {
273                 .name = "88pm860x-regulator",
274                 .id = 11,
275                 .num_resources = ARRAY_SIZE(ldo9_resources),
276                 .resources = ldo9_resources,
277         }, {
278                 .name = "88pm860x-regulator",
279                 .id = 12,
280                 .num_resources = ARRAY_SIZE(ldo10_resources),
281                 .resources = ldo10_resources,
282         }, {
283                 .name = "88pm860x-regulator",
284                 .id = 13,
285                 .num_resources = ARRAY_SIZE(ldo12_resources),
286                 .resources = ldo12_resources,
287         }, {
288                 .name = "88pm860x-regulator",
289                 .id = 14,
290                 .num_resources = ARRAY_SIZE(ldo_vibrator_resources),
291                 .resources = ldo_vibrator_resources,
292         }, {
293                 .name = "88pm860x-regulator",
294                 .id = 15,
295                 .num_resources = ARRAY_SIZE(ldo14_resources),
296                 .resources = ldo14_resources,
297         },
298 };
299
300 static struct mfd_cell touch_devs[] = {
301         {"88pm860x-touch", -1,},
302 };
303
304 static struct mfd_cell onkey_devs[] = {
305         {"88pm860x-onkey", -1,},
306 };
307
308 static struct mfd_cell codec_devs[] = {
309         {"88pm860x-codec", -1,},
310 };
311
312 static struct regulator_consumer_supply preg_supply[] = {
313         REGULATOR_SUPPLY("preg", "charger-manager"),
314 };
315
316 static struct regulator_init_data preg_init_data = {
317         .num_consumer_supplies  = ARRAY_SIZE(preg_supply),
318         .consumer_supplies      = &preg_supply[0],
319 };
320
321 static struct mfd_cell power_devs[] = {
322         {"88pm860x-battery", -1,},
323         {"88pm860x-charger", -1,},
324         {"88pm860x-preg",    -1,},
325 };
326
327 static struct mfd_cell rtc_devs[] = {
328         {"88pm860x-rtc", -1,},
329 };
330
331
332 struct pm860x_irq_data {
333         int     reg;
334         int     mask_reg;
335         int     enable;         /* enable or not */
336         int     offs;           /* bit offset in mask register */
337 };
338
339 static struct pm860x_irq_data pm860x_irqs[] = {
340         [PM8607_IRQ_ONKEY] = {
341                 .reg            = PM8607_INT_STATUS1,
342                 .mask_reg       = PM8607_INT_MASK_1,
343                 .offs           = 1 << 0,
344         },
345         [PM8607_IRQ_EXTON] = {
346                 .reg            = PM8607_INT_STATUS1,
347                 .mask_reg       = PM8607_INT_MASK_1,
348                 .offs           = 1 << 1,
349         },
350         [PM8607_IRQ_CHG] = {
351                 .reg            = PM8607_INT_STATUS1,
352                 .mask_reg       = PM8607_INT_MASK_1,
353                 .offs           = 1 << 2,
354         },
355         [PM8607_IRQ_BAT] = {
356                 .reg            = PM8607_INT_STATUS1,
357                 .mask_reg       = PM8607_INT_MASK_1,
358                 .offs           = 1 << 3,
359         },
360         [PM8607_IRQ_RTC] = {
361                 .reg            = PM8607_INT_STATUS1,
362                 .mask_reg       = PM8607_INT_MASK_1,
363                 .offs           = 1 << 4,
364         },
365         [PM8607_IRQ_CC] = {
366                 .reg            = PM8607_INT_STATUS1,
367                 .mask_reg       = PM8607_INT_MASK_1,
368                 .offs           = 1 << 5,
369         },
370         [PM8607_IRQ_VBAT] = {
371                 .reg            = PM8607_INT_STATUS2,
372                 .mask_reg       = PM8607_INT_MASK_2,
373                 .offs           = 1 << 0,
374         },
375         [PM8607_IRQ_VCHG] = {
376                 .reg            = PM8607_INT_STATUS2,
377                 .mask_reg       = PM8607_INT_MASK_2,
378                 .offs           = 1 << 1,
379         },
380         [PM8607_IRQ_VSYS] = {
381                 .reg            = PM8607_INT_STATUS2,
382                 .mask_reg       = PM8607_INT_MASK_2,
383                 .offs           = 1 << 2,
384         },
385         [PM8607_IRQ_TINT] = {
386                 .reg            = PM8607_INT_STATUS2,
387                 .mask_reg       = PM8607_INT_MASK_2,
388                 .offs           = 1 << 3,
389         },
390         [PM8607_IRQ_GPADC0] = {
391                 .reg            = PM8607_INT_STATUS2,
392                 .mask_reg       = PM8607_INT_MASK_2,
393                 .offs           = 1 << 4,
394         },
395         [PM8607_IRQ_GPADC1] = {
396                 .reg            = PM8607_INT_STATUS2,
397                 .mask_reg       = PM8607_INT_MASK_2,
398                 .offs           = 1 << 5,
399         },
400         [PM8607_IRQ_GPADC2] = {
401                 .reg            = PM8607_INT_STATUS2,
402                 .mask_reg       = PM8607_INT_MASK_2,
403                 .offs           = 1 << 6,
404         },
405         [PM8607_IRQ_GPADC3] = {
406                 .reg            = PM8607_INT_STATUS2,
407                 .mask_reg       = PM8607_INT_MASK_2,
408                 .offs           = 1 << 7,
409         },
410         [PM8607_IRQ_AUDIO_SHORT] = {
411                 .reg            = PM8607_INT_STATUS3,
412                 .mask_reg       = PM8607_INT_MASK_3,
413                 .offs           = 1 << 0,
414         },
415         [PM8607_IRQ_PEN] = {
416                 .reg            = PM8607_INT_STATUS3,
417                 .mask_reg       = PM8607_INT_MASK_3,
418                 .offs           = 1 << 1,
419         },
420         [PM8607_IRQ_HEADSET] = {
421                 .reg            = PM8607_INT_STATUS3,
422                 .mask_reg       = PM8607_INT_MASK_3,
423                 .offs           = 1 << 2,
424         },
425         [PM8607_IRQ_HOOK] = {
426                 .reg            = PM8607_INT_STATUS3,
427                 .mask_reg       = PM8607_INT_MASK_3,
428                 .offs           = 1 << 3,
429         },
430         [PM8607_IRQ_MICIN] = {
431                 .reg            = PM8607_INT_STATUS3,
432                 .mask_reg       = PM8607_INT_MASK_3,
433                 .offs           = 1 << 4,
434         },
435         [PM8607_IRQ_CHG_FAIL] = {
436                 .reg            = PM8607_INT_STATUS3,
437                 .mask_reg       = PM8607_INT_MASK_3,
438                 .offs           = 1 << 5,
439         },
440         [PM8607_IRQ_CHG_DONE] = {
441                 .reg            = PM8607_INT_STATUS3,
442                 .mask_reg       = PM8607_INT_MASK_3,
443                 .offs           = 1 << 6,
444         },
445         [PM8607_IRQ_CHG_FAULT] = {
446                 .reg            = PM8607_INT_STATUS3,
447                 .mask_reg       = PM8607_INT_MASK_3,
448                 .offs           = 1 << 7,
449         },
450 };
451
452 static irqreturn_t pm860x_irq(int irq, void *data)
453 {
454         struct pm860x_chip *chip = data;
455         struct pm860x_irq_data *irq_data;
456         struct i2c_client *i2c;
457         int read_reg = -1, value = 0;
458         int i;
459
460         i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
461         for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
462                 irq_data = &pm860x_irqs[i];
463                 if (read_reg != irq_data->reg) {
464                         read_reg = irq_data->reg;
465                         value = pm860x_reg_read(i2c, irq_data->reg);
466                 }
467                 if (value & irq_data->enable)
468                         handle_nested_irq(chip->irq_base + i);
469         }
470         return IRQ_HANDLED;
471 }
472
473 static void pm860x_irq_lock(struct irq_data *data)
474 {
475         struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
476
477         mutex_lock(&chip->irq_lock);
478 }
479
480 static void pm860x_irq_sync_unlock(struct irq_data *data)
481 {
482         struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
483         struct pm860x_irq_data *irq_data;
484         struct i2c_client *i2c;
485         static unsigned char cached[3] = {0x0, 0x0, 0x0};
486         unsigned char mask[3];
487         int i;
488
489         i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
490         /* Load cached value. In initial, all IRQs are masked */
491         for (i = 0; i < 3; i++)
492                 mask[i] = cached[i];
493         for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
494                 irq_data = &pm860x_irqs[i];
495                 switch (irq_data->mask_reg) {
496                 case PM8607_INT_MASK_1:
497                         mask[0] &= ~irq_data->offs;
498                         mask[0] |= irq_data->enable;
499                         break;
500                 case PM8607_INT_MASK_2:
501                         mask[1] &= ~irq_data->offs;
502                         mask[1] |= irq_data->enable;
503                         break;
504                 case PM8607_INT_MASK_3:
505                         mask[2] &= ~irq_data->offs;
506                         mask[2] |= irq_data->enable;
507                         break;
508                 default:
509                         dev_err(chip->dev, "wrong IRQ\n");
510                         break;
511                 }
512         }
513         /* update mask into registers */
514         for (i = 0; i < 3; i++) {
515                 if (mask[i] != cached[i]) {
516                         cached[i] = mask[i];
517                         pm860x_reg_write(i2c, PM8607_INT_MASK_1 + i, mask[i]);
518                 }
519         }
520
521         mutex_unlock(&chip->irq_lock);
522 }
523
524 static void pm860x_irq_enable(struct irq_data *data)
525 {
526         pm860x_irqs[data->hwirq].enable = pm860x_irqs[data->hwirq].offs;
527 }
528
529 static void pm860x_irq_disable(struct irq_data *data)
530 {
531         pm860x_irqs[data->hwirq].enable = 0;
532 }
533
534 static struct irq_chip pm860x_irq_chip = {
535         .name           = "88pm860x",
536         .irq_bus_lock   = pm860x_irq_lock,
537         .irq_bus_sync_unlock = pm860x_irq_sync_unlock,
538         .irq_enable     = pm860x_irq_enable,
539         .irq_disable    = pm860x_irq_disable,
540 };
541
542 static int pm860x_irq_domain_map(struct irq_domain *d, unsigned int virq,
543                                  irq_hw_number_t hw)
544 {
545         irq_set_chip_data(virq, d->host_data);
546         irq_set_chip_and_handler(virq, &pm860x_irq_chip, handle_edge_irq);
547         irq_set_nested_thread(virq, 1);
548 #ifdef CONFIG_ARM
549         set_irq_flags(virq, IRQF_VALID);
550 #else
551         irq_set_noprobe(virq);
552 #endif
553         return 0;
554 }
555
556 static struct irq_domain_ops pm860x_irq_domain_ops = {
557         .map    = pm860x_irq_domain_map,
558         .xlate  = irq_domain_xlate_onetwocell,
559 };
560
561 static int __devinit device_irq_init(struct pm860x_chip *chip,
562                                      struct pm860x_platform_data *pdata)
563 {
564         struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
565                                 : chip->companion;
566         unsigned char status_buf[INT_STATUS_NUM];
567         unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
568         int data, mask, ret = -EINVAL;
569         int nr_irqs, irq_base = -1;
570         struct device_node *node = i2c->dev.of_node;
571
572         mask = PM8607_B0_MISC1_INV_INT | PM8607_B0_MISC1_INT_CLEAR
573                 | PM8607_B0_MISC1_INT_MASK;
574         data = 0;
575         chip->irq_mode = 0;
576         if (pdata && pdata->irq_mode) {
577                 /*
578                  * irq_mode defines the way of clearing interrupt. If it's 1,
579                  * clear IRQ by write. Otherwise, clear it by read.
580                  * This control bit is valid from 88PM8607 B0 steping.
581                  */
582                 data |= PM8607_B0_MISC1_INT_CLEAR;
583                 chip->irq_mode = 1;
584         }
585         ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, mask, data);
586         if (ret < 0)
587                 goto out;
588
589         /* mask all IRQs */
590         memset(status_buf, 0, INT_STATUS_NUM);
591         ret = pm860x_bulk_write(i2c, PM8607_INT_MASK_1,
592                                 INT_STATUS_NUM, status_buf);
593         if (ret < 0)
594                 goto out;
595
596         if (chip->irq_mode) {
597                 /* clear interrupt status by write */
598                 memset(status_buf, 0xFF, INT_STATUS_NUM);
599                 ret = pm860x_bulk_write(i2c, PM8607_INT_STATUS1,
600                                         INT_STATUS_NUM, status_buf);
601         } else {
602                 /* clear interrupt status by read */
603                 ret = pm860x_bulk_read(i2c, PM8607_INT_STATUS1,
604                                         INT_STATUS_NUM, status_buf);
605         }
606         if (ret < 0)
607                 goto out;
608
609         mutex_init(&chip->irq_lock);
610
611         if (pdata && pdata->irq_base)
612                 irq_base = pdata->irq_base;
613         nr_irqs = ARRAY_SIZE(pm860x_irqs);
614         chip->irq_base = irq_alloc_descs(irq_base, 0, nr_irqs, 0);
615         if (chip->irq_base < 0) {
616                 dev_err(&i2c->dev, "Failed to allocate interrupts, ret:%d\n",
617                         chip->irq_base);
618                 ret = -EBUSY;
619                 goto out;
620         }
621         irq_domain_add_legacy(node, nr_irqs, chip->irq_base, 0,
622                               &pm860x_irq_domain_ops, chip);
623         chip->core_irq = i2c->irq;
624         if (!chip->core_irq)
625                 goto out;
626
627         ret = request_threaded_irq(chip->core_irq, NULL, pm860x_irq, flags | IRQF_ONESHOT,
628                                    "88pm860x", chip);
629         if (ret) {
630                 dev_err(chip->dev, "Failed to request IRQ: %d\n", ret);
631                 chip->core_irq = 0;
632         }
633
634         return 0;
635 out:
636         chip->core_irq = 0;
637         return ret;
638 }
639
640 static void device_irq_exit(struct pm860x_chip *chip)
641 {
642         if (chip->core_irq)
643                 free_irq(chip->core_irq, chip);
644 }
645
646 int pm8606_osc_enable(struct pm860x_chip *chip, unsigned short client)
647 {
648         int ret = -EIO;
649         struct i2c_client *i2c = (chip->id == CHIP_PM8606) ?
650                 chip->client : chip->companion;
651
652         dev_dbg(chip->dev, "%s(B): client=0x%x\n", __func__, client);
653         dev_dbg(chip->dev, "%s(B): vote=0x%x status=%d\n",
654                         __func__, chip->osc_vote,
655                         chip->osc_status);
656
657         mutex_lock(&chip->osc_lock);
658         /* Update voting status */
659         chip->osc_vote |= client;
660         /* If reference group is off - turn on*/
661         if (chip->osc_status != PM8606_REF_GP_OSC_ON) {
662                 chip->osc_status = PM8606_REF_GP_OSC_UNKNOWN;
663                 /* Enable Reference group Vsys */
664                 if (pm860x_set_bits(i2c, PM8606_VSYS,
665                                 PM8606_VSYS_EN, PM8606_VSYS_EN))
666                         goto out;
667
668                 /*Enable Internal Oscillator */
669                 if (pm860x_set_bits(i2c, PM8606_MISC,
670                                 PM8606_MISC_OSC_EN, PM8606_MISC_OSC_EN))
671                         goto out;
672                 /* Update status (only if writes succeed) */
673                 chip->osc_status = PM8606_REF_GP_OSC_ON;
674         }
675         mutex_unlock(&chip->osc_lock);
676
677         dev_dbg(chip->dev, "%s(A): vote=0x%x status=%d ret=%d\n",
678                         __func__, chip->osc_vote,
679                         chip->osc_status, ret);
680         return 0;
681 out:
682         mutex_unlock(&chip->osc_lock);
683         return ret;
684 }
685 EXPORT_SYMBOL(pm8606_osc_enable);
686
687 int pm8606_osc_disable(struct pm860x_chip *chip, unsigned short client)
688 {
689         int ret = -EIO;
690         struct i2c_client *i2c = (chip->id == CHIP_PM8606) ?
691                 chip->client : chip->companion;
692
693         dev_dbg(chip->dev, "%s(B): client=0x%x\n", __func__, client);
694         dev_dbg(chip->dev, "%s(B): vote=0x%x status=%d\n",
695                         __func__, chip->osc_vote,
696                         chip->osc_status);
697
698         mutex_lock(&chip->osc_lock);
699         /*Update voting status */
700         chip->osc_vote &= ~(client);
701         /* If reference group is off and this is the last client to release
702          * - turn off */
703         if ((chip->osc_status != PM8606_REF_GP_OSC_OFF) &&
704                         (chip->osc_vote == REF_GP_NO_CLIENTS)) {
705                 chip->osc_status = PM8606_REF_GP_OSC_UNKNOWN;
706                 /* Disable Reference group Vsys */
707                 if (pm860x_set_bits(i2c, PM8606_VSYS, PM8606_VSYS_EN, 0))
708                         goto out;
709                 /* Disable Internal Oscillator */
710                 if (pm860x_set_bits(i2c, PM8606_MISC, PM8606_MISC_OSC_EN, 0))
711                         goto out;
712                 chip->osc_status = PM8606_REF_GP_OSC_OFF;
713         }
714         mutex_unlock(&chip->osc_lock);
715
716         dev_dbg(chip->dev, "%s(A): vote=0x%x status=%d ret=%d\n",
717                         __func__, chip->osc_vote,
718                         chip->osc_status, ret);
719         return 0;
720 out:
721         mutex_unlock(&chip->osc_lock);
722         return ret;
723 }
724 EXPORT_SYMBOL(pm8606_osc_disable);
725
726 static void __devinit device_osc_init(struct i2c_client *i2c)
727 {
728         struct pm860x_chip *chip = i2c_get_clientdata(i2c);
729
730         mutex_init(&chip->osc_lock);
731         /* init portofino reference group voting and status */
732         /* Disable Reference group Vsys */
733         pm860x_set_bits(i2c, PM8606_VSYS, PM8606_VSYS_EN, 0);
734         /* Disable Internal Oscillator */
735         pm860x_set_bits(i2c, PM8606_MISC, PM8606_MISC_OSC_EN, 0);
736
737         chip->osc_vote = REF_GP_NO_CLIENTS;
738         chip->osc_status = PM8606_REF_GP_OSC_OFF;
739 }
740
741 static void __devinit device_bk_init(struct pm860x_chip *chip,
742                                      struct pm860x_platform_data *pdata)
743 {
744         int ret, i;
745
746         if (pdata && pdata->backlight) {
747                 if (pdata->num_backlights > ARRAY_SIZE(bk_devs))
748                         pdata->num_backlights = ARRAY_SIZE(bk_devs);
749                 for (i = 0; i < pdata->num_backlights; i++) {
750                         bk_devs[i].platform_data = &pdata->backlight[i];
751                         bk_devs[i].pdata_size =
752                                 sizeof(struct pm860x_backlight_pdata);
753                 }
754         }
755         ret = mfd_add_devices(chip->dev, 0, bk_devs,
756                               ARRAY_SIZE(bk_devs), NULL, 0, NULL);
757         if (ret < 0)
758                 dev_err(chip->dev, "Failed to add backlight subdev\n");
759 }
760
761 static void __devinit device_led_init(struct pm860x_chip *chip,
762                                       struct pm860x_platform_data *pdata)
763 {
764         int ret, i;
765
766         if (pdata && pdata->led) {
767                 if (pdata->num_leds > ARRAY_SIZE(led_devs))
768                         pdata->num_leds = ARRAY_SIZE(led_devs);
769                 for (i = 0; i < pdata->num_leds; i++) {
770                         led_devs[i].platform_data = &pdata->led[i];
771                         led_devs[i].pdata_size =
772                                 sizeof(struct pm860x_led_pdata);
773                 }
774         }
775         ret = mfd_add_devices(chip->dev, 0, led_devs,
776                               ARRAY_SIZE(led_devs), NULL, 0, NULL);
777         if (ret < 0) {
778                 dev_err(chip->dev, "Failed to add led subdev\n");
779                 return;
780         }
781 }
782
783 static void __devinit device_regulator_init(struct pm860x_chip *chip,
784                                             struct pm860x_platform_data *pdata)
785 {
786         int ret;
787
788         if (pdata == NULL)
789                 return;
790         if (pdata->buck1) {
791                 reg_devs[0].platform_data = pdata->buck1;
792                 reg_devs[0].pdata_size = sizeof(struct regulator_init_data);
793         }
794         if (pdata->buck2) {
795                 reg_devs[1].platform_data = pdata->buck2;
796                 reg_devs[1].pdata_size = sizeof(struct regulator_init_data);
797         }
798         if (pdata->buck3) {
799                 reg_devs[2].platform_data = pdata->buck3;
800                 reg_devs[2].pdata_size = sizeof(struct regulator_init_data);
801         }
802         if (pdata->ldo1) {
803                 reg_devs[3].platform_data = pdata->ldo1;
804                 reg_devs[3].pdata_size = sizeof(struct regulator_init_data);
805         }
806         if (pdata->ldo2) {
807                 reg_devs[4].platform_data = pdata->ldo2;
808                 reg_devs[4].pdata_size = sizeof(struct regulator_init_data);
809         }
810         if (pdata->ldo3) {
811                 reg_devs[5].platform_data = pdata->ldo3;
812                 reg_devs[5].pdata_size = sizeof(struct regulator_init_data);
813         }
814         if (pdata->ldo4) {
815                 reg_devs[6].platform_data = pdata->ldo4;
816                 reg_devs[6].pdata_size = sizeof(struct regulator_init_data);
817         }
818         if (pdata->ldo5) {
819                 reg_devs[7].platform_data = pdata->ldo5;
820                 reg_devs[7].pdata_size = sizeof(struct regulator_init_data);
821         }
822         if (pdata->ldo6) {
823                 reg_devs[8].platform_data = pdata->ldo6;
824                 reg_devs[8].pdata_size = sizeof(struct regulator_init_data);
825         }
826         if (pdata->ldo7) {
827                 reg_devs[9].platform_data = pdata->ldo7;
828                 reg_devs[9].pdata_size = sizeof(struct regulator_init_data);
829         }
830         if (pdata->ldo8) {
831                 reg_devs[10].platform_data = pdata->ldo8;
832                 reg_devs[10].pdata_size = sizeof(struct regulator_init_data);
833         }
834         if (pdata->ldo9) {
835                 reg_devs[11].platform_data = pdata->ldo9;
836                 reg_devs[11].pdata_size = sizeof(struct regulator_init_data);
837         }
838         if (pdata->ldo10) {
839                 reg_devs[12].platform_data = pdata->ldo10;
840                 reg_devs[12].pdata_size = sizeof(struct regulator_init_data);
841         }
842         if (pdata->ldo12) {
843                 reg_devs[13].platform_data = pdata->ldo12;
844                 reg_devs[13].pdata_size = sizeof(struct regulator_init_data);
845         }
846         if (pdata->ldo_vibrator) {
847                 reg_devs[14].platform_data = pdata->ldo_vibrator;
848                 reg_devs[14].pdata_size = sizeof(struct regulator_init_data);
849         }
850         if (pdata->ldo14) {
851                 reg_devs[15].platform_data = pdata->ldo14;
852                 reg_devs[15].pdata_size = sizeof(struct regulator_init_data);
853         }
854         ret = mfd_add_devices(chip->dev, 0, reg_devs,
855                               ARRAY_SIZE(reg_devs), NULL, 0, NULL);
856         if (ret < 0) {
857                 dev_err(chip->dev, "Failed to add regulator subdev\n");
858                 return;
859         }
860 }
861
862 static void __devinit device_rtc_init(struct pm860x_chip *chip,
863                                       struct pm860x_platform_data *pdata)
864 {
865         int ret;
866
867         if ((pdata == NULL))
868                 return;
869
870         rtc_devs[0].platform_data = pdata->rtc;
871         rtc_devs[0].pdata_size = sizeof(struct pm860x_rtc_pdata);
872         rtc_devs[0].num_resources = ARRAY_SIZE(rtc_resources);
873         rtc_devs[0].resources = &rtc_resources[0];
874         ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0],
875                               ARRAY_SIZE(rtc_devs), &rtc_resources[0],
876                               chip->irq_base, NULL);
877         if (ret < 0)
878                 dev_err(chip->dev, "Failed to add rtc subdev\n");
879 }
880
881 static void __devinit device_touch_init(struct pm860x_chip *chip,
882                                         struct pm860x_platform_data *pdata)
883 {
884         int ret;
885
886         if (pdata == NULL)
887                 return;
888
889         touch_devs[0].platform_data = pdata->touch;
890         touch_devs[0].pdata_size = sizeof(struct pm860x_touch_pdata);
891         touch_devs[0].num_resources = ARRAY_SIZE(touch_resources);
892         touch_devs[0].resources = &touch_resources[0];
893         ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
894                               ARRAY_SIZE(touch_devs), &touch_resources[0],
895                               chip->irq_base, NULL);
896         if (ret < 0)
897                 dev_err(chip->dev, "Failed to add touch subdev\n");
898 }
899
900 static void __devinit device_power_init(struct pm860x_chip *chip,
901                                         struct pm860x_platform_data *pdata)
902 {
903         int ret;
904
905         if (pdata == NULL)
906                 return;
907
908         power_devs[0].platform_data = pdata->power;
909         power_devs[0].pdata_size = sizeof(struct pm860x_power_pdata);
910         power_devs[0].num_resources = ARRAY_SIZE(battery_resources);
911         power_devs[0].resources = &battery_resources[0],
912         ret = mfd_add_devices(chip->dev, 0, &power_devs[0], 1,
913                               &battery_resources[0], chip->irq_base, NULL);
914         if (ret < 0)
915                 dev_err(chip->dev, "Failed to add battery subdev\n");
916
917         power_devs[1].platform_data = pdata->power;
918         power_devs[1].pdata_size = sizeof(struct pm860x_power_pdata);
919         power_devs[1].num_resources = ARRAY_SIZE(charger_resources);
920         power_devs[1].resources = &charger_resources[0],
921         ret = mfd_add_devices(chip->dev, 0, &power_devs[1], 1,
922                               &charger_resources[0], chip->irq_base, NULL);
923         if (ret < 0)
924                 dev_err(chip->dev, "Failed to add charger subdev\n");
925
926         power_devs[2].platform_data = &preg_init_data;
927         power_devs[2].pdata_size = sizeof(struct regulator_init_data);
928         ret = mfd_add_devices(chip->dev, 0, &power_devs[2], 1,
929                               NULL, chip->irq_base, NULL);
930         if (ret < 0)
931                 dev_err(chip->dev, "Failed to add preg subdev\n");
932 }
933
934 static void __devinit device_onkey_init(struct pm860x_chip *chip,
935                                         struct pm860x_platform_data *pdata)
936 {
937         int ret;
938
939         onkey_devs[0].num_resources = ARRAY_SIZE(onkey_resources);
940         onkey_devs[0].resources = &onkey_resources[0],
941         ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
942                               ARRAY_SIZE(onkey_devs), &onkey_resources[0],
943                               chip->irq_base, NULL);
944         if (ret < 0)
945                 dev_err(chip->dev, "Failed to add onkey subdev\n");
946 }
947
948 static void __devinit device_codec_init(struct pm860x_chip *chip,
949                                         struct pm860x_platform_data *pdata)
950 {
951         int ret;
952
953         codec_devs[0].num_resources = ARRAY_SIZE(codec_resources);
954         codec_devs[0].resources = &codec_resources[0],
955         ret = mfd_add_devices(chip->dev, 0, &codec_devs[0],
956                               ARRAY_SIZE(codec_devs), &codec_resources[0], 0,
957                               NULL);
958         if (ret < 0)
959                 dev_err(chip->dev, "Failed to add codec subdev\n");
960 }
961
962 static void __devinit device_8607_init(struct pm860x_chip *chip,
963                                        struct i2c_client *i2c,
964                                        struct pm860x_platform_data *pdata)
965 {
966         int data, ret;
967
968         ret = pm860x_reg_read(i2c, PM8607_CHIP_ID);
969         if (ret < 0) {
970                 dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret);
971                 goto out;
972         }
973         switch (ret & PM8607_VERSION_MASK) {
974         case 0x40:
975         case 0x50:
976                 dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n",
977                          ret);
978                 break;
979         default:
980                 dev_err(chip->dev, "Failed to detect Marvell 88PM8607. "
981                         "Chip ID: %02x\n", ret);
982                 goto out;
983         }
984
985         ret = pm860x_reg_read(i2c, PM8607_BUCK3);
986         if (ret < 0) {
987                 dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret);
988                 goto out;
989         }
990         if (ret & PM8607_BUCK3_DOUBLE)
991                 chip->buck3_double = 1;
992
993         ret = pm860x_reg_read(i2c, PM8607_B0_MISC1);
994         if (ret < 0) {
995                 dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret);
996                 goto out;
997         }
998
999         if (pdata && (pdata->i2c_port == PI2C_PORT))
1000                 data = PM8607_B0_MISC1_PI2C;
1001         else
1002                 data = 0;
1003         ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, PM8607_B0_MISC1_PI2C, data);
1004         if (ret < 0) {
1005                 dev_err(chip->dev, "Failed to access MISC1:%d\n", ret);
1006                 goto out;
1007         }
1008
1009         ret = device_irq_init(chip, pdata);
1010         if (ret < 0)
1011                 goto out;
1012
1013         device_regulator_init(chip, pdata);
1014         device_rtc_init(chip, pdata);
1015         device_onkey_init(chip, pdata);
1016         device_touch_init(chip, pdata);
1017         device_power_init(chip, pdata);
1018         device_codec_init(chip, pdata);
1019 out:
1020         return;
1021 }
1022
1023 static void __devinit device_8606_init(struct pm860x_chip *chip,
1024                                        struct i2c_client *i2c,
1025                                        struct pm860x_platform_data *pdata)
1026 {
1027         device_osc_init(i2c);
1028         device_bk_init(chip, pdata);
1029         device_led_init(chip, pdata);
1030 }
1031
1032 static int __devinit pm860x_device_init(struct pm860x_chip *chip,
1033                                         struct pm860x_platform_data *pdata)
1034 {
1035         chip->core_irq = 0;
1036
1037         switch (chip->id) {
1038         case CHIP_PM8606:
1039                 device_8606_init(chip, chip->client, pdata);
1040                 break;
1041         case CHIP_PM8607:
1042                 device_8607_init(chip, chip->client, pdata);
1043                 break;
1044         }
1045
1046         if (chip->companion) {
1047                 switch (chip->id) {
1048                 case CHIP_PM8607:
1049                         device_8606_init(chip, chip->companion, pdata);
1050                         break;
1051                 case CHIP_PM8606:
1052                         device_8607_init(chip, chip->companion, pdata);
1053                         break;
1054                 }
1055         }
1056
1057         return 0;
1058 }
1059
1060 static void __devexit pm860x_device_exit(struct pm860x_chip *chip)
1061 {
1062         device_irq_exit(chip);
1063         mfd_remove_devices(chip->dev);
1064 }
1065
1066 static int verify_addr(struct i2c_client *i2c)
1067 {
1068         unsigned short addr_8607[] = {0x30, 0x34};
1069         unsigned short addr_8606[] = {0x10, 0x11};
1070         int size, i;
1071
1072         if (i2c == NULL)
1073                 return 0;
1074         size = ARRAY_SIZE(addr_8606);
1075         for (i = 0; i < size; i++) {
1076                 if (i2c->addr == *(addr_8606 + i))
1077                         return CHIP_PM8606;
1078         }
1079         size = ARRAY_SIZE(addr_8607);
1080         for (i = 0; i < size; i++) {
1081                 if (i2c->addr == *(addr_8607 + i))
1082                         return CHIP_PM8607;
1083         }
1084         return 0;
1085 }
1086
1087 static struct regmap_config pm860x_regmap_config = {
1088         .reg_bits = 8,
1089         .val_bits = 8,
1090 };
1091
1092 static int __devinit pm860x_dt_init(struct device_node *np,
1093                                     struct device *dev,
1094                                     struct pm860x_platform_data *pdata)
1095 {
1096         int ret;
1097
1098         if (of_get_property(np, "marvell,88pm860x-irq-read-clr", NULL))
1099                 pdata->irq_mode = 1;
1100         ret = of_property_read_u32(np, "marvell,88pm860x-slave-addr",
1101                                    &pdata->companion_addr);
1102         if (ret) {
1103                 dev_err(dev, "Not found \"marvell,88pm860x-slave-addr\" "
1104                         "property\n");
1105                 pdata->companion_addr = 0;
1106         }
1107         return 0;
1108 }
1109
1110 static int __devinit pm860x_probe(struct i2c_client *client,
1111                                   const struct i2c_device_id *id)
1112 {
1113         struct pm860x_platform_data *pdata = client->dev.platform_data;
1114         struct device_node *node = client->dev.of_node;
1115         struct pm860x_chip *chip;
1116         int ret;
1117
1118         if (node && !pdata) {
1119                 /* parse DT to get platform data */
1120                 pdata = devm_kzalloc(&client->dev,
1121                                      sizeof(struct pm860x_platform_data),
1122                                      GFP_KERNEL);
1123                 if (!pdata)
1124                         return -ENOMEM;
1125                 ret = pm860x_dt_init(node, &client->dev, pdata);
1126                 if (ret)
1127                         goto err;
1128         } else if (!pdata) {
1129                 pr_info("No platform data in %s!\n", __func__);
1130                 return -EINVAL;
1131         }
1132
1133         chip = kzalloc(sizeof(struct pm860x_chip), GFP_KERNEL);
1134         if (chip == NULL) {
1135                 ret = -ENOMEM;
1136                 goto err;
1137         }
1138
1139         chip->id = verify_addr(client);
1140         chip->regmap = regmap_init_i2c(client, &pm860x_regmap_config);
1141         if (IS_ERR(chip->regmap)) {
1142                 ret = PTR_ERR(chip->regmap);
1143                 dev_err(&client->dev, "Failed to allocate register map: %d\n",
1144                                 ret);
1145                 kfree(chip);
1146                 return ret;
1147         }
1148         chip->client = client;
1149         i2c_set_clientdata(client, chip);
1150         chip->dev = &client->dev;
1151         dev_set_drvdata(chip->dev, chip);
1152
1153         /*
1154          * Both client and companion client shares same platform driver.
1155          * Driver distinguishes them by pdata->companion_addr.
1156          * pdata->companion_addr is only assigned if companion chip exists.
1157          * At the same time, the companion_addr shouldn't equal to client
1158          * address.
1159          */
1160         if (pdata->companion_addr && (pdata->companion_addr != client->addr)) {
1161                 chip->companion_addr = pdata->companion_addr;
1162                 chip->companion = i2c_new_dummy(chip->client->adapter,
1163                                                 chip->companion_addr);
1164                 chip->regmap_companion = regmap_init_i2c(chip->companion,
1165                                                         &pm860x_regmap_config);
1166                 if (IS_ERR(chip->regmap_companion)) {
1167                         ret = PTR_ERR(chip->regmap_companion);
1168                         dev_err(&chip->companion->dev,
1169                                 "Failed to allocate register map: %d\n", ret);
1170                         return ret;
1171                 }
1172                 i2c_set_clientdata(chip->companion, chip);
1173         }
1174
1175         pm860x_device_init(chip, pdata);
1176         return 0;
1177 err:
1178         if (node)
1179                 devm_kfree(&client->dev, pdata);
1180         return ret;
1181 }
1182
1183 static int __devexit pm860x_remove(struct i2c_client *client)
1184 {
1185         struct pm860x_chip *chip = i2c_get_clientdata(client);
1186
1187         pm860x_device_exit(chip);
1188         if (chip->companion) {
1189                 regmap_exit(chip->regmap_companion);
1190                 i2c_unregister_device(chip->companion);
1191         }
1192         regmap_exit(chip->regmap);
1193         kfree(chip);
1194         return 0;
1195 }
1196
1197 #ifdef CONFIG_PM_SLEEP
1198 static int pm860x_suspend(struct device *dev)
1199 {
1200         struct i2c_client *client = container_of(dev, struct i2c_client, dev);
1201         struct pm860x_chip *chip = i2c_get_clientdata(client);
1202
1203         if (device_may_wakeup(dev) && chip->wakeup_flag)
1204                 enable_irq_wake(chip->core_irq);
1205         return 0;
1206 }
1207
1208 static int pm860x_resume(struct device *dev)
1209 {
1210         struct i2c_client *client = container_of(dev, struct i2c_client, dev);
1211         struct pm860x_chip *chip = i2c_get_clientdata(client);
1212
1213         if (device_may_wakeup(dev) && chip->wakeup_flag)
1214                 disable_irq_wake(chip->core_irq);
1215         return 0;
1216 }
1217 #endif
1218
1219 static SIMPLE_DEV_PM_OPS(pm860x_pm_ops, pm860x_suspend, pm860x_resume);
1220
1221 static const struct i2c_device_id pm860x_id_table[] = {
1222         { "88PM860x", 0 },
1223         {}
1224 };
1225 MODULE_DEVICE_TABLE(i2c, pm860x_id_table);
1226
1227 static const struct of_device_id pm860x_dt_ids[] = {
1228         { .compatible = "marvell,88pm860x", },
1229         {},
1230 };
1231 MODULE_DEVICE_TABLE(of, pm860x_dt_ids);
1232
1233 static struct i2c_driver pm860x_driver = {
1234         .driver = {
1235                 .name   = "88PM860x",
1236                 .owner  = THIS_MODULE,
1237                 .pm     = &pm860x_pm_ops,
1238                 .of_match_table = of_match_ptr(pm860x_dt_ids),
1239         },
1240         .probe          = pm860x_probe,
1241         .remove         = __devexit_p(pm860x_remove),
1242         .id_table       = pm860x_id_table,
1243 };
1244
1245 static int __init pm860x_i2c_init(void)
1246 {
1247         int ret;
1248         ret = i2c_add_driver(&pm860x_driver);
1249         if (ret != 0)
1250                 pr_err("Failed to register 88PM860x I2C driver: %d\n", ret);
1251         return ret;
1252 }
1253 subsys_initcall(pm860x_i2c_init);
1254
1255 static void __exit pm860x_i2c_exit(void)
1256 {
1257         i2c_del_driver(&pm860x_driver);
1258 }
1259 module_exit(pm860x_i2c_exit);
1260
1261 MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x");
1262 MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
1263 MODULE_LICENSE("GPL");