12 #include <linux/kernel.h>
13 #include <linux/module.h>
15 #include <linux/i2c.h>
23 #include <linux/slab.h>
29 #define INT_STATUS_NUM 3
36 static struct resource bk1_resources[] __devinitdata = {
41 static struct resource bk2_resources[] __devinitdata = {
47 static struct resource led0_resources[] __devinitdata = {
52 static struct resource led1_resources[] __devinitdata = {
57 static struct resource led2_resources[] __devinitdata = {
62 static struct resource led3_resources[] __devinitdata = {
67 static struct resource led4_resources[] __devinitdata = {
72 static struct resource led5_resources[] __devinitdata = {
78 static struct resource buck1_resources[] __devinitdata = {
81 static struct resource buck2_resources[] __devinitdata = {
84 static struct resource buck3_resources[] __devinitdata = {
87 static struct resource ldo1_resources[] __devinitdata = {
90 static struct resource ldo2_resources[] __devinitdata = {
93 static struct resource ldo3_resources[] __devinitdata = {
96 static struct resource ldo4_resources[] __devinitdata = {
99 static struct resource ldo5_resources[] __devinitdata = {
102 static struct resource ldo6_resources[] __devinitdata = {
105 static struct resource ldo7_resources[] __devinitdata = {
108 static struct resource ldo8_resources[] __devinitdata = {
111 static struct resource ldo9_resources[] __devinitdata = {
114 static struct resource ldo10_resources[] __devinitdata = {
117 static struct resource ldo12_resources[] __devinitdata = {
120 static struct resource ldo_vibrator_resources[] __devinitdata = {
123 static struct resource ldo14_resources[] __devinitdata = {
127 static struct resource touch_resources[] __devinitdata = {
131 static struct resource onkey_resources[] __devinitdata = {
135 static struct resource codec_resources[] __devinitdata = {
146 static struct resource battery_resources[] __devinitdata = {
151 static struct resource charger_resources[] __devinitdata = {
161 static struct resource rtc_resources[] __devinitdata = {
165 static struct mfd_cell bk_devs[] __devinitdata = {
167 .
name =
"88pm860x-backlight",
170 .resources = bk0_resources,
172 .name =
"88pm860x-backlight",
175 .resources = bk1_resources,
177 .name =
"88pm860x-backlight",
180 .resources = bk2_resources,
184 static struct mfd_cell led_devs[] __devinitdata = {
186 .
name =
"88pm860x-led",
189 .resources = led0_resources,
191 .name =
"88pm860x-led",
194 .resources = led1_resources,
196 .name =
"88pm860x-led",
199 .resources = led2_resources,
201 .name =
"88pm860x-led",
204 .resources = led3_resources,
206 .name =
"88pm860x-led",
209 .resources = led4_resources,
211 .name =
"88pm860x-led",
214 .resources = led5_resources,
218 static struct mfd_cell reg_devs[] __devinitdata = {
220 .
name =
"88pm860x-regulator",
223 .resources = buck1_resources,
225 .name =
"88pm860x-regulator",
228 .resources = buck2_resources,
230 .name =
"88pm860x-regulator",
233 .resources = buck3_resources,
235 .name =
"88pm860x-regulator",
238 .resources = ldo1_resources,
240 .name =
"88pm860x-regulator",
243 .resources = ldo2_resources,
245 .name =
"88pm860x-regulator",
248 .resources = ldo3_resources,
250 .name =
"88pm860x-regulator",
253 .resources = ldo4_resources,
255 .name =
"88pm860x-regulator",
258 .resources = ldo5_resources,
260 .name =
"88pm860x-regulator",
263 .resources = ldo6_resources,
265 .name =
"88pm860x-regulator",
268 .resources = ldo7_resources,
270 .name =
"88pm860x-regulator",
273 .resources = ldo8_resources,
275 .name =
"88pm860x-regulator",
278 .resources = ldo9_resources,
280 .name =
"88pm860x-regulator",
283 .resources = ldo10_resources,
285 .name =
"88pm860x-regulator",
288 .resources = ldo12_resources,
290 .name =
"88pm860x-regulator",
292 .num_resources =
ARRAY_SIZE(ldo_vibrator_resources),
293 .resources = ldo_vibrator_resources,
295 .name =
"88pm860x-regulator",
298 .resources = ldo14_resources,
302 static struct mfd_cell touch_devs[] = {
303 {
"88pm860x-touch", -1,},
306 static struct mfd_cell onkey_devs[] = {
307 {
"88pm860x-onkey", -1,},
310 static struct mfd_cell codec_devs[] = {
311 {
"88pm860x-codec", -1,},
319 .num_consumer_supplies =
ARRAY_SIZE(preg_supply),
320 .consumer_supplies = &preg_supply[0],
324 { .regulator_name =
"preg", },
327 static struct mfd_cell power_devs[] = {
328 {
"88pm860x-battery", -1,},
329 {
"88pm860x-charger", -1,},
330 {
"88pm860x-preg", -1,},
331 {
"charger-manager", -1,},
334 static struct mfd_cell rtc_devs[] = {
335 {
"88pm860x-rtc", -1,},
469 irq_data = &pm860x_irqs[
i];
470 if (read_reg != irq_data->
reg) {
471 read_reg = irq_data->
reg;
480 static void pm860x_irq_lock(
struct irq_data *data)
482 struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
487 static void pm860x_irq_sync_unlock(
struct irq_data *data)
489 struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
492 static unsigned char cached[3] = {0x0, 0x0, 0x0};
493 unsigned char mask[3];
498 for (i = 0; i < 3; i++)
500 for (i = 0; i <
ARRAY_SIZE(pm860x_irqs); i++) {
501 irq_data = &pm860x_irqs[
i];
504 mask[0] &= ~irq_data->
offs;
505 mask[0] |= irq_data->
enable;
508 mask[1] &= ~irq_data->
offs;
509 mask[1] |= irq_data->
enable;
512 mask[2] &= ~irq_data->
offs;
513 mask[2] |= irq_data->
enable;
521 for (i = 0; i < 3; i++) {
522 if (mask[i] != cached[i]) {
531 static void pm860x_irq_enable(
struct irq_data *data)
536 static void pm860x_irq_disable(
struct irq_data *data)
541 static struct irq_chip pm860x_irq_chip = {
543 .irq_bus_lock = pm860x_irq_lock,
544 .irq_bus_sync_unlock = pm860x_irq_sync_unlock,
545 .irq_enable = pm860x_irq_enable,
546 .irq_disable = pm860x_irq_disable,
549 static int pm860x_irq_domain_map(
struct irq_domain *
d,
unsigned int virq,
554 irq_set_nested_thread(virq, 1);
558 irq_set_noprobe(virq);
564 .map = pm860x_irq_domain_map,
621 chip->
irq_base = irq_alloc_descs(irq_base, 0, nr_irqs, 0);
623 dev_err(&i2c->
dev,
"Failed to allocate interrupts, ret:%d\n",
629 &pm860x_irq_domain_ops, chip);
647 static void device_irq_exit(
struct pm860x_chip *chip)
659 dev_dbg(chip->
dev,
"%s(B): client=0x%x\n", __func__, client);
660 dev_dbg(chip->
dev,
"%s(B): vote=0x%x status=%d\n",
684 dev_dbg(chip->
dev,
"%s(A): vote=0x%x status=%d ret=%d\n",
700 dev_dbg(chip->
dev,
"%s(B): client=0x%x\n", __func__, client);
701 dev_dbg(chip->
dev,
"%s(B): vote=0x%x status=%d\n",
723 dev_dbg(chip->
dev,
"%s(A): vote=0x%x status=%d ret=%d\n",
735 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
758 bk_devs[
i].pdata_size =
765 dev_err(chip->
dev,
"Failed to add backlight subdev\n");
773 if (pdata && pdata->
led) {
776 for (i = 0; i < pdata->
num_leds; i++) {
777 led_devs[
i].platform_data = &pdata->
led[
i];
778 led_devs[
i].pdata_size =
785 dev_err(chip->
dev,
"Failed to add led subdev\n");
798 reg_devs[0].platform_data = pdata->
buck1;
802 reg_devs[1].platform_data = pdata->
buck2;
806 reg_devs[2].platform_data = pdata->
buck3;
810 reg_devs[3].platform_data = pdata->
ldo1;
814 reg_devs[4].platform_data = pdata->
ldo2;
818 reg_devs[5].platform_data = pdata->
ldo3;
822 reg_devs[6].platform_data = pdata->
ldo4;
826 reg_devs[7].platform_data = pdata->
ldo5;
830 reg_devs[8].platform_data = pdata->
ldo6;
834 reg_devs[9].platform_data = pdata->
ldo7;
838 reg_devs[10].platform_data = pdata->
ldo8;
842 reg_devs[11].platform_data = pdata->
ldo9;
846 reg_devs[12].platform_data = pdata->
ldo10;
850 reg_devs[13].platform_data = pdata->
ldo12;
858 reg_devs[15].platform_data = pdata->
ldo14;
864 dev_err(chip->
dev,
"Failed to add regulator subdev\n");
880 rtc_devs[0].
resources = &rtc_resources[0];
885 dev_err(chip->
dev,
"Failed to add rtc subdev\n");
899 touch_devs[0].
resources = &touch_resources[0];
904 dev_err(chip->
dev,
"Failed to add touch subdev\n");
918 power_devs[0].
resources = &battery_resources[0],
922 dev_err(chip->
dev,
"Failed to add battery subdev\n");
927 power_devs[1].
resources = &charger_resources[0],
931 dev_err(chip->
dev,
"Failed to add charger subdev\n");
938 dev_err(chip->
dev,
"Failed to add preg subdev\n");
941 pdata->
chg_desc->charger_regulators =
942 &chg_desc_regulator_data[0];
943 pdata->
chg_desc->num_charger_regulators =
950 dev_err(chip->
dev,
"Failed to add chg-manager subdev\n");
960 onkey_devs[0].
resources = &onkey_resources[0],
965 dev_err(chip->
dev,
"Failed to add onkey subdev\n");
974 codec_devs[0].
resources = &codec_resources[0],
976 ARRAY_SIZE(codec_devs), &codec_resources[0], 0,
979 dev_err(chip->
dev,
"Failed to add codec subdev\n");
990 dev_err(chip->
dev,
"Failed to read CHIP ID: %d\n", ret);
996 dev_info(chip->
dev,
"Marvell 88PM8607 (ID: %02x) detected\n",
1000 dev_err(chip->
dev,
"Failed to detect Marvell 88PM8607. "
1001 "Chip ID: %02x\n", ret);
1007 dev_err(chip->
dev,
"Failed to read BUCK3 register: %d\n", ret);
1015 dev_err(chip->
dev,
"Failed to read MISC1 register: %d\n", ret);
1025 dev_err(chip->
dev,
"Failed to access MISC1:%d\n", ret);
1029 ret = device_irq_init(chip, pdata);
1033 device_regulator_init(chip, pdata);
1034 device_rtc_init(chip, pdata);
1035 device_onkey_init(chip, pdata);
1036 device_touch_init(chip, pdata);
1037 device_power_init(chip, pdata);
1038 device_codec_init(chip, pdata);
1047 device_osc_init(i2c);
1048 device_bk_init(chip, pdata);
1049 device_led_init(chip, pdata);
1059 device_8606_init(chip, chip->
client, pdata);
1062 device_8607_init(chip, chip->
client, pdata);
1069 device_8606_init(chip, chip->
companion, pdata);
1072 device_8607_init(chip, chip->
companion, pdata);
1082 device_irq_exit(chip);
1086 static int verify_addr(
struct i2c_client *i2c)
1088 unsigned short addr_8607[] = {0x30, 0x34};
1089 unsigned short addr_8606[] = {0x10, 0x11};
1095 for (i = 0; i <
size; i++) {
1096 if (i2c->
addr == *(addr_8606 + i))
1100 for (i = 0; i <
size; i++) {
1101 if (i2c->
addr == *(addr_8607 + i))
1107 static struct regmap_config pm860x_regmap_config = {
1120 ret = of_property_read_u32(np,
"marvell,88pm860x-slave-addr",
1123 dev_err(dev,
"Not found \"marvell,88pm860x-slave-addr\" "
1138 if (node && !pdata) {
1145 ret = pm860x_dt_init(node, &client->
dev, pdata);
1148 }
else if (!pdata) {
1149 pr_info(
"No platform data in %s!\n", __func__);
1159 chip->
id = verify_addr(client);
1161 if (IS_ERR(chip->
regmap)) {
1162 ret = PTR_ERR(chip->
regmap);
1163 dev_err(&client->
dev,
"Failed to allocate register map: %d\n",
1169 i2c_set_clientdata(client, chip);
1170 chip->
dev = &client->
dev;
1185 &pm860x_regmap_config);
1189 "Failed to allocate register map: %d\n", ret);
1192 i2c_set_clientdata(chip->
companion, chip);
1195 pm860x_device_init(chip, pdata);
1205 struct pm860x_chip *chip = i2c_get_clientdata(client);
1207 pm860x_device_exit(chip);
1217 #ifdef CONFIG_PM_SLEEP
1218 static int pm860x_suspend(
struct device *dev)
1221 struct pm860x_chip *chip = i2c_get_clientdata(client);
1228 static int pm860x_resume(
struct device *dev)
1231 struct pm860x_chip *chip = i2c_get_clientdata(client);
1248 { .compatible =
"marvell,88pm860x", },
1257 .pm = &pm860x_pm_ops,
1260 .probe = pm860x_probe,
1262 .id_table = pm860x_id_table,
1265 static int __init pm860x_i2c_init(
void)
1268 ret = i2c_add_driver(&pm860x_driver);
1270 pr_err(
"Failed to register 88PM860x I2C driver: %d\n", ret);
1275 static void __exit pm860x_i2c_exit(
void)