12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/i2c.h>
27 static struct mfd_cell bk_devs[] __devinitdata = {
29 .
name =
"max8925-backlight",
31 .resources = &bk_resources[0],
36 static struct resource touch_resources[] = {
38 .name =
"max8925-tsc",
45 static struct mfd_cell touch_devs[] = {
47 .name =
"max8925-touch",
49 .resources = &touch_resources[0],
54 static struct resource power_supply_resources[] = {
56 .name =
"max8925-power",
63 static struct mfd_cell power_devs[] = {
65 .name =
"max8925-power",
67 .resources = &power_supply_resources[0],
72 static struct resource rtc_resources[] = {
74 .name =
"max8925-rtc",
81 static struct mfd_cell rtc_devs[] = {
83 .name =
"max8925-rtc",
85 .resources = &rtc_resources[0],
90 static struct resource onkey_resources[] = {
92 .name =
"max8925-onkey",
97 .name =
"max8925-onkey",
104 static struct mfd_cell onkey_devs[] = {
106 .name =
"max8925-onkey",
108 .resources = &onkey_resources[0],
113 static struct resource sd1_resources[] __devinitdata = {
117 static struct resource sd2_resources[] __devinitdata = {
121 static struct resource sd3_resources[] __devinitdata = {
125 static struct resource ldo1_resources[] __devinitdata = {
129 static struct resource ldo2_resources[] __devinitdata = {
133 static struct resource ldo3_resources[] __devinitdata = {
137 static struct resource ldo4_resources[] __devinitdata = {
141 static struct resource ldo5_resources[] __devinitdata = {
145 static struct resource ldo6_resources[] __devinitdata = {
149 static struct resource ldo7_resources[] __devinitdata = {
153 static struct resource ldo8_resources[] __devinitdata = {
157 static struct resource ldo9_resources[] __devinitdata = {
161 static struct resource ldo10_resources[] __devinitdata = {
165 static struct resource ldo11_resources[] __devinitdata = {
169 static struct resource ldo12_resources[] __devinitdata = {
173 static struct resource ldo13_resources[] __devinitdata = {
177 static struct resource ldo14_resources[] __devinitdata = {
181 static struct resource ldo15_resources[] __devinitdata = {
185 static struct resource ldo16_resources[] __devinitdata = {
189 static struct resource ldo17_resources[] __devinitdata = {
193 static struct resource ldo18_resources[] __devinitdata = {
197 static struct resource ldo19_resources[] __devinitdata = {
201 static struct resource ldo20_resources[] __devinitdata = {
205 static struct mfd_cell reg_devs[] __devinitdata = {
207 .
name =
"max8925-regulator",
210 .resources = sd1_resources,
212 .name =
"max8925-regulator",
215 .resources = sd2_resources,
217 .name =
"max8925-regulator",
220 .resources = sd3_resources,
222 .name =
"max8925-regulator",
225 .resources = ldo1_resources,
227 .name =
"max8925-regulator",
230 .resources = ldo2_resources,
232 .name =
"max8925-regulator",
235 .resources = ldo3_resources,
237 .name =
"max8925-regulator",
240 .resources = ldo4_resources,
242 .name =
"max8925-regulator",
245 .resources = ldo5_resources,
247 .name =
"max8925-regulator",
250 .resources = ldo6_resources,
252 .name =
"max8925-regulator",
255 .resources = ldo7_resources,
257 .name =
"max8925-regulator",
260 .resources = ldo8_resources,
262 .name =
"max8925-regulator",
265 .resources = ldo9_resources,
267 .name =
"max8925-regulator",
270 .resources = ldo10_resources,
272 .name =
"max8925-regulator",
275 .resources = ldo11_resources,
277 .name =
"max8925-regulator",
280 .resources = ldo12_resources,
282 .name =
"max8925-regulator",
285 .resources = ldo13_resources,
287 .name =
"max8925-regulator",
290 .resources = ldo14_resources,
292 .name =
"max8925-regulator",
295 .resources = ldo15_resources,
297 .name =
"max8925-regulator",
300 .resources = ldo16_resources,
302 .name =
"max8925-regulator",
305 .resources = ldo17_resources,
307 .name =
"max8925-regulator",
310 .resources = ldo18_resources,
312 .name =
"max8925-regulator",
315 .resources = ldo19_resources,
317 .name =
"max8925-regulator",
320 .resources = ldo20_resources,
475 return &max8925_irqs[irq - chip->
irq_base];
486 for (i = 0; i <
ARRAY_SIZE(max8925_irqs); i++) {
487 irq_data = &max8925_irqs[
i];
497 if (read_reg != irq_data->
reg) {
498 read_reg = irq_data->
reg;
507 static irqreturn_t max8925_tsc_irq(
int irq,
void *data)
512 int read_reg = -1,
value = 0;
515 for (i = 0; i <
ARRAY_SIZE(max8925_irqs); i++) {
516 irq_data = &max8925_irqs[
i];
526 if (read_reg != irq_data->
reg) {
527 read_reg = irq_data->
reg;
536 static void max8925_irq_lock(
struct irq_data *data)
538 struct max8925_chip *chip = irq_data_get_irq_chip_data(data);
543 static void max8925_irq_sync_unlock(
struct irq_data *data)
545 struct max8925_chip *chip = irq_data_get_irq_chip_data(data);
547 static unsigned char cache_chg[2] = {0xff, 0xff};
548 static unsigned char cache_on[2] = {0xff, 0xff};
549 static unsigned char cache_rtc = 0xff, cache_tsc = 0xff;
550 unsigned char irq_chg[2], irq_on[2];
551 unsigned char irq_rtc, irq_tsc;
555 irq_chg[0] = cache_chg[0];
556 irq_chg[1] = cache_chg[1];
557 irq_on[0] = cache_on[0];
558 irq_on[1] = cache_on[1];
561 for (i = 0; i <
ARRAY_SIZE(max8925_irqs); i++) {
562 irq_data = &max8925_irqs[
i];
566 irq_chg[0] &= ~irq_data->
enable;
569 irq_chg[1] &= ~irq_data->
enable;
572 irq_on[0] &= ~irq_data->
enable;
575 irq_on[1] &= ~irq_data->
enable;
578 irq_rtc &= ~irq_data->
enable;
581 irq_tsc &= ~irq_data->
enable;
589 if (cache_chg[0] != irq_chg[0]) {
590 cache_chg[0] = irq_chg[0];
594 if (cache_chg[1] != irq_chg[1]) {
595 cache_chg[1] = irq_chg[1];
599 if (cache_on[0] != irq_on[0]) {
600 cache_on[0] = irq_on[0];
604 if (cache_on[1] != irq_on[1]) {
605 cache_on[1] = irq_on[1];
609 if (cache_rtc != irq_rtc) {
613 if (cache_tsc != irq_tsc) {
621 static void max8925_irq_enable(
struct irq_data *data)
623 struct max8925_chip *chip = irq_data_get_irq_chip_data(data);
628 static void max8925_irq_disable(
struct irq_data *data)
630 struct max8925_chip *chip = irq_data_get_irq_chip_data(data);
634 static struct irq_chip max8925_irq_chip = {
636 .irq_bus_lock = max8925_irq_lock,
637 .irq_bus_sync_unlock = max8925_irq_sync_unlock,
638 .irq_enable = max8925_irq_enable,
639 .irq_disable = max8925_irq_disable,
642 static int max8925_irq_init(
struct max8925_chip *chip,
int irq,
650 dev_warn(chip->
dev,
"No interrupt support on IRQ base\n");
674 for (i = 0; i <
ARRAY_SIZE(max8925_irqs); i++) {
677 irq_set_chip_and_handler(__irq, &max8925_irq_chip,
679 irq_set_nested_thread(__irq, 1);
683 irq_set_noprobe(__irq);
687 dev_warn(chip->
dev,
"No interrupt support on core IRQ\n");
694 dev_err(chip->
dev,
"Failed to request core IRQ: %d\n", ret);
703 dev_warn(chip->
dev,
"No interrupt support on TSC IRQ\n");
711 dev_err(chip->
dev,
"Failed to request TSC IRQ: %d\n", ret);
725 reg_devs[0].platform_data = pdata->
sd1;
729 reg_devs[1].platform_data = pdata->
sd2;
733 reg_devs[2].platform_data = pdata->
sd3;
737 reg_devs[3].platform_data = pdata->
ldo1;
741 reg_devs[4].platform_data = pdata->
ldo2;
745 reg_devs[5].platform_data = pdata->
ldo3;
749 reg_devs[6].platform_data = pdata->
ldo4;
753 reg_devs[7].platform_data = pdata->
ldo5;
757 reg_devs[8].platform_data = pdata->
ldo6;
761 reg_devs[9].platform_data = pdata->
ldo7;
765 reg_devs[10].platform_data = pdata->
ldo8;
769 reg_devs[11].platform_data = pdata->
ldo9;
773 reg_devs[12].platform_data = pdata->
ldo10;
777 reg_devs[13].platform_data = pdata->
ldo11;
781 reg_devs[14].platform_data = pdata->
ldo12;
785 reg_devs[15].platform_data = pdata->
ldo13;
789 reg_devs[16].platform_data = pdata->
ldo14;
793 reg_devs[17].platform_data = pdata->
ldo15;
797 reg_devs[18].platform_data = pdata->
ldo16;
801 reg_devs[19].platform_data = pdata->
ldo17;
805 reg_devs[20].platform_data = pdata->
ldo18;
809 reg_devs[21].platform_data = pdata->
ldo19;
813 reg_devs[22].platform_data = pdata->
ldo20;
819 dev_err(chip->
dev,
"Failed to add regulator subdev\n");
829 max8925_irq_init(chip, chip->
i2c->irq, pdata);
831 if (pdata && (pdata->
power || pdata->
touch)) {
851 dev_err(chip->
dev,
"Failed to add rtc subdev\n");
857 &onkey_resources[0], 0,
NULL);
859 dev_err(chip->
dev,
"Failed to add onkey subdev\n");
863 init_regulator(chip, pdata);
866 bk_devs[0].platform_data = &pdata->
backlight;
872 dev_err(chip->
dev,
"Failed to add backlight subdev\n");
876 if (pdata && pdata->
power) {
879 &power_supply_resources[0], 0,
NULL);
881 dev_err(chip->
dev,
"Failed to add power supply "
887 if (pdata && pdata->
touch) {
890 &touch_resources[0], 0,
NULL);
892 dev_err(chip->
dev,
"Failed to add touch subdev\n");