23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/i2c.h>
28 #include <linux/slab.h>
30 #define PM800_CHIP_ID (0x00)
33 #define PM800_INT_STATUS1 (0x05)
34 #define PM800_ONKEY_INT_STS1 (1 << 0)
35 #define PM800_EXTON_INT_STS1 (1 << 1)
36 #define PM800_CHG_INT_STS1 (1 << 2)
37 #define PM800_BAT_INT_STS1 (1 << 3)
38 #define PM800_RTC_INT_STS1 (1 << 4)
39 #define PM800_CLASSD_OC_INT_STS1 (1 << 5)
41 #define PM800_INT_STATUS2 (0x06)
42 #define PM800_VBAT_INT_STS2 (1 << 0)
43 #define PM800_VSYS_INT_STS2 (1 << 1)
44 #define PM800_VCHG_INT_STS2 (1 << 2)
45 #define PM800_TINT_INT_STS2 (1 << 3)
46 #define PM800_GPADC0_INT_STS2 (1 << 4)
47 #define PM800_TBAT_INT_STS2 (1 << 5)
48 #define PM800_GPADC2_INT_STS2 (1 << 6)
49 #define PM800_GPADC3_INT_STS2 (1 << 7)
51 #define PM800_INT_STATUS3 (0x07)
53 #define PM800_INT_STATUS4 (0x08)
54 #define PM800_GPIO0_INT_STS4 (1 << 0)
55 #define PM800_GPIO1_INT_STS4 (1 << 1)
56 #define PM800_GPIO2_INT_STS4 (1 << 2)
57 #define PM800_GPIO3_INT_STS4 (1 << 3)
58 #define PM800_GPIO4_INT_STS4 (1 << 4)
60 #define PM800_INT_ENA_1 (0x09)
61 #define PM800_ONKEY_INT_ENA1 (1 << 0)
62 #define PM800_EXTON_INT_ENA1 (1 << 1)
63 #define PM800_CHG_INT_ENA1 (1 << 2)
64 #define PM800_BAT_INT_ENA1 (1 << 3)
65 #define PM800_RTC_INT_ENA1 (1 << 4)
66 #define PM800_CLASSD_OC_INT_ENA1 (1 << 5)
68 #define PM800_INT_ENA_2 (0x0A)
69 #define PM800_VBAT_INT_ENA2 (1 << 0)
70 #define PM800_VSYS_INT_ENA2 (1 << 1)
71 #define PM800_VCHG_INT_ENA2 (1 << 2)
72 #define PM800_TINT_INT_ENA2 (1 << 3)
74 #define PM800_INT_ENA_3 (0x0B)
75 #define PM800_GPADC0_INT_ENA3 (1 << 0)
76 #define PM800_GPADC1_INT_ENA3 (1 << 1)
77 #define PM800_GPADC2_INT_ENA3 (1 << 2)
78 #define PM800_GPADC3_INT_ENA3 (1 << 3)
79 #define PM800_GPADC4_INT_ENA3 (1 << 4)
81 #define PM800_INT_ENA_4 (0x0C)
82 #define PM800_GPIO0_INT_ENA4 (1 << 0)
83 #define PM800_GPIO1_INT_ENA4 (1 << 1)
84 #define PM800_GPIO2_INT_ENA4 (1 << 2)
85 #define PM800_GPIO3_INT_ENA4 (1 << 3)
86 #define PM800_GPIO4_INT_ENA4 (1 << 4)
89 #define PM800_INT_REG_NUM (4)
134 static struct resource rtc_resources[] = {
136 .name =
"88pm80x-rtc",
143 static struct mfd_cell rtc_devs[] = {
145 .name =
"88pm80x-rtc",
147 .resources = &rtc_resources[0],
152 static struct resource onkey_resources[] = {
154 .name =
"88pm80x-onkey",
161 static struct mfd_cell onkey_devs[] = {
163 .name =
"88pm80x-onkey",
165 .resources = &onkey_resources[0],
170 static const struct regmap_irq pm800_irqs[] = {
260 "Warning: gpadc regmap is not available!\n");
299 if (pdata && (pdata->
batt_det == 0))
310 dev_info(chip->
dev,
"pm800 device_gpadc_init: Done\n");
314 dev_info(chip->
dev,
"pm800 device_gpadc_init: Failed!\n");
324 if (!map || !chip->
irq) {
351 static void device_irq_exit_800(
struct pm80x_chip *chip)
356 static struct regmap_irq_chip pm800_irq_chip = {
367 static int pm800_pages_init(
struct pm80x_chip *chip)
380 i2c_set_clientdata(subchip->
power_page, chip);
383 "PM800 block power 0x31: No power_page_addr\n");
392 i2c_set_clientdata(subchip->
gpadc_page, chip);
395 "PM800 block GPADC 0x32: No gpadc_page_addr\n");
400 static void pm800_pages_exit(
struct pm80x_chip *chip)
426 dev_err(chip->
dev,
"Failed to read CHIP ID: %d\n", ret);
435 "88PM80x:Marvell 88PM800 (ID:0x%x) detected\n", val);
438 "Failed to detect Marvell 88PM800:ChipID[0x%x]\n", val);
449 dev_err(chip->
dev,
"Failed to read RTC register: %d\n", ret);
453 if (pdata && pdata->
rtc)
454 pdata->
rtc->rtc_wakeup = 1;
457 ret = device_gpadc_init(chip, pdata);
459 dev_err(chip->
dev,
"[%s]Failed to init gpadc\n", __func__);
465 ret = device_irq_init_800(chip);
467 dev_err(chip->
dev,
"[%s]Failed to init pm800 irq\n", __func__);
473 ARRAY_SIZE(onkey_devs), &onkey_resources[0], 0,
476 dev_err(chip->
dev,
"Failed to add onkey subdev\n");
479 dev_info(chip->
dev,
"[%s]:Added mfd onkey_devs\n", __func__);
481 if (pdata && pdata->
rtc) {
487 dev_err(chip->
dev,
"Failed to add rtc subdev\n");
491 "[%s]:Added mfd rtc_devs\n", __func__);
497 device_irq_exit_800(chip);
516 chip = i2c_get_clientdata(client);
524 goto err_subchip_alloc;
531 ret = device_800_init(chip, pdata);
533 dev_err(chip->
dev,
"%s id 0x%x failed!\n", __func__, chip->
id);
537 ret = pm800_pages_init(chip);
539 dev_err(&client->
dev,
"pm800_pages_init failed!\n");
548 device_irq_exit_800(chip);
559 struct pm80x_chip *chip = i2c_get_clientdata(client);
562 device_irq_exit_800(chip);
564 pm800_pages_exit(chip);
578 .probe = pm800_probe,
580 .id_table = pm80x_id_table,
583 static int __init pm800_i2c_init(
void)
585 return i2c_add_driver(&pm800_driver);
589 static void __exit pm800_i2c_exit(
void)