2 * Regulator driver for Active-semi act8931 PMIC chip
4 * Copyright (C) 2014 ROCKCHIP, Inc.
6 * Based on act8931.c in kernel 3.0 that is work by xhc<xhc@rock-chips.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/mutex.h>
15 #include <linux/bug.h>
16 #include <linux/err.h>
17 #include <linux/i2c.h>
18 #include <linux/kernel.h>
19 #include <linux/delay.h>
20 #include <linux/slab.h>
21 #include <linux/interrupt.h>
23 #include <linux/of_device.h>
24 #include <linux/of_gpio.h>
25 #include <linux/module.h>
26 #include <linux/regulator/of_regulator.h>
27 #include <linux/regulator/machine.h>
28 #include <linux/regulator/driver.h>
29 #include <asm/system_misc.h>
32 #define DBG(x...) printk(KERN_INFO x)
37 #define ACT8931_NUM_REGULATORS 7
39 struct act8931 *g_act8931;
43 unsigned int pwr_hold_gpio;
46 struct i2c_client *i2c;
48 struct regulator_dev **rdev;
51 struct act8931_board {
55 struct regulator_init_data *act8931_init_data[ACT8931_NUM_REGULATORS];
56 struct device_node *of_node[ACT8931_NUM_REGULATORS];
59 static u8 act8931_reg_read(struct act8931 *act8931, u8 reg);
60 static int act8931_set_bits(struct act8931 *act8931, u8 reg, u16 mask, u16 val);
62 #define ACT8931_DCDC1 0
63 #define ACT8931_DCDC2 1
64 #define ACT8931_DCDC3 2
66 #define ACT8931_LDO1 3
67 #define ACT8931_LDO2 4
68 #define ACT8931_LDO3 5
69 #define ACT8931_LDO4 6
71 #define act8931_BUCK1_SET_VOL_BASE 0x20
72 #define act8931_BUCK2_SET_VOL_BASE 0x30
73 #define act8931_BUCK3_SET_VOL_BASE 0x40
74 #define act8931_LDO1_SET_VOL_BASE 0x50
75 #define act8931_LDO2_SET_VOL_BASE 0x54
76 #define act8931_LDO3_SET_VOL_BASE 0x60
77 #define act8931_LDO4_SET_VOL_BASE 0x64
79 #define act8931_BUCK1_CONTR_BASE 0x22
80 #define act8931_BUCK2_CONTR_BASE 0x32
81 #define act8931_BUCK3_CONTR_BASE 0x42
82 #define act8931_LDO1_CONTR_BASE 0x51
83 #define act8931_LDO2_CONTR_BASE 0x55
84 #define act8931_LDO3_CONTR_BASE 0x61
85 #define act8931_LDO4_CONTR_BASE 0x65
87 #define BUCK_VOL_MASK 0x3f
88 #define LDO_VOL_MASK 0x3f
90 #define VOL_MIN_IDX 0x00
91 #define VOL_MAX_IDX 0x3f
93 #define INSTAT_MASK (1<<5)
94 #define CHGSTAT_MASK (1<<4)
95 #define INDAT_MASK (1<<1)
96 #define CHGDAT_MASK (1<<0)
98 #define INCON_MASK (1<<5)
99 #define CHGEOCIN_MASK (1<<4)
100 #define INDIS_MASK (1<<1)
101 #define CHGEOCOUT_MASK (1<<0)
103 int act8931_charge_det;
104 EXPORT_SYMBOL(act8931_charge_det);
106 int act8931_charge_ok;
107 EXPORT_SYMBOL(act8931_charge_ok);
109 static const int buck_set_vol_base_addr[] = {
110 act8931_BUCK1_SET_VOL_BASE,
111 act8931_BUCK2_SET_VOL_BASE,
112 act8931_BUCK3_SET_VOL_BASE,
114 static const int buck_contr_base_addr[] = {
115 act8931_BUCK1_CONTR_BASE,
116 act8931_BUCK2_CONTR_BASE,
117 act8931_BUCK3_CONTR_BASE,
119 #define act8931_BUCK_SET_VOL_REG(x) (buck_set_vol_base_addr[x])
120 #define act8931_BUCK_CONTR_REG(x) (buck_contr_base_addr[x])
122 static const int ldo_set_vol_base_addr[] = {
123 act8931_LDO1_SET_VOL_BASE,
124 act8931_LDO2_SET_VOL_BASE,
125 act8931_LDO3_SET_VOL_BASE,
126 act8931_LDO4_SET_VOL_BASE,
128 static const int ldo_contr_base_addr[] = {
129 act8931_LDO1_CONTR_BASE,
130 act8931_LDO2_CONTR_BASE,
131 act8931_LDO3_CONTR_BASE,
132 act8931_LDO4_CONTR_BASE,
134 #define act8931_LDO_SET_VOL_REG(x) (ldo_set_vol_base_addr[x])
135 #define act8931_LDO_CONTR_REG(x) (ldo_contr_base_addr[x])
137 static const int buck_voltage_map[] = {
138 600, 625, 650, 675, 700, 725, 750, 775,
139 800, 825, 850, 875, 900, 925, 950, 975,
140 1000, 1025, 1050, 1075, 1100, 1125, 1150,
141 1175, 1200, 1250, 1300, 1350, 1400, 1450,
142 1500, 1550, 1600, 1650, 1700, 1750, 1800,
143 1850, 1900, 1950, 2000, 2050, 2100, 2150,
144 2200, 2250, 2300, 2350, 2400, 2500, 2600,
145 2700, 2800, 2850, 2900, 3000, 3100, 3200,
146 3300, 3400, 3500, 3600, 3700, 3800, 3900,
149 static const int ldo_voltage_map[] = {
150 600, 625, 650, 675, 700, 725, 750, 775,
151 800, 825, 850, 875, 900, 925, 950, 975,
152 1000, 1025, 1050, 1075, 1100, 1125, 1150,
153 1175, 1200, 1250, 1300, 1350, 1400, 1450,
154 1500, 1550, 1600, 1650, 1700, 1750, 1800,
155 1850, 1900, 1950, 2000, 2050, 2100, 2150,
156 2200, 2250, 2300, 2350, 2400, 2500, 2600,
157 2700, 2800, 2850, 2900, 3000, 3100, 3200,
158 3300, 3400, 3500, 3600, 3700, 3800, 3900,
161 static int act8931_ldo_list_voltage(struct regulator_dev *dev, unsigned index)
163 if (index >= ARRAY_SIZE(ldo_voltage_map))
165 return 1000 * ldo_voltage_map[index];
168 static int act8931_ldo_is_enabled(struct regulator_dev *dev)
170 struct act8931 *act8931 = rdev_get_drvdata(dev);
171 int ldo = rdev_get_id(dev) - ACT8931_LDO1;
175 val = act8931_reg_read(act8931, act8931_LDO_CONTR_REG(ldo));
185 static int act8931_ldo_enable(struct regulator_dev *dev)
187 struct act8931 *act8931 = rdev_get_drvdata(dev);
188 int ldo = rdev_get_id(dev) - ACT8931_LDO1;
191 return act8931_set_bits(act8931, act8931_LDO_CONTR_REG(ldo), mask,
195 static int act8931_ldo_disable(struct regulator_dev *dev)
197 struct act8931 *act8931 = rdev_get_drvdata(dev);
198 int ldo = rdev_get_id(dev) - ACT8931_LDO1;
201 return act8931_set_bits(act8931, act8931_LDO_CONTR_REG(ldo), mask, 0);
204 static int act8931_ldo_get_voltage(struct regulator_dev *dev)
206 struct act8931 *act8931 = rdev_get_drvdata(dev);
207 int ldo = rdev_get_id(dev) - ACT8931_LDO1;
211 reg = act8931_reg_read(act8931, act8931_LDO_SET_VOL_REG(ldo));
213 val = 1000 * ldo_voltage_map[reg];
218 static int act8931_ldo_set_voltage(struct regulator_dev *dev,
219 int min_uV, int max_uV, unsigned *selector)
221 struct act8931 *act8931 = rdev_get_drvdata(dev);
222 int ldo = rdev_get_id(dev) - ACT8931_LDO1;
223 int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
224 const int *vol_map = ldo_voltage_map;
228 if (min_vol < vol_map[VOL_MIN_IDX] || min_vol > vol_map[VOL_MAX_IDX])
231 for (val = VOL_MIN_IDX; val <= VOL_MAX_IDX; val++) {
232 if (vol_map[val] >= min_vol)
236 if (vol_map[val] > max_vol)
239 ret = act8931_set_bits(act8931, act8931_LDO_SET_VOL_REG(ldo),
245 static unsigned int act8931_ldo_get_mode(struct regulator_dev *dev)
247 struct act8931 *act8931 = rdev_get_drvdata(dev);
248 int ldo = rdev_get_id(dev) - ACT8931_LDO1;
252 val = act8931_reg_read(act8931, act8931_LDO_CONTR_REG(ldo));
256 return REGULATOR_MODE_NORMAL;
258 return REGULATOR_MODE_STANDBY;
261 static int act8931_ldo_set_mode(struct regulator_dev *dev, unsigned int mode)
263 struct act8931 *act8931 = rdev_get_drvdata(dev);
264 int ldo = rdev_get_id(dev) - ACT8931_LDO1;
268 case REGULATOR_MODE_NORMAL:
269 return act8931_set_bits(act8931, act8931_LDO_CONTR_REG(ldo),
271 case REGULATOR_MODE_STANDBY:
272 return act8931_set_bits(act8931, act8931_LDO_CONTR_REG(ldo),
275 pr_err("pmu_act8931 only lowpower and normal mode\n");
280 static struct regulator_ops act8931_ldo_ops = {
281 .set_voltage = act8931_ldo_set_voltage,
282 .get_voltage = act8931_ldo_get_voltage,
283 .list_voltage = act8931_ldo_list_voltage,
284 .is_enabled = act8931_ldo_is_enabled,
285 .enable = act8931_ldo_enable,
286 .disable = act8931_ldo_disable,
287 .get_mode = act8931_ldo_get_mode,
288 .set_mode = act8931_ldo_set_mode,
291 static int act8931_dcdc_list_voltage(struct regulator_dev *dev, unsigned index)
293 if (index >= ARRAY_SIZE(buck_voltage_map))
296 return 1000 * buck_voltage_map[index];
299 static int act8931_dcdc_is_enabled(struct regulator_dev *dev)
301 struct act8931 *act8931 = rdev_get_drvdata(dev);
302 int buck = rdev_get_id(dev) - ACT8931_DCDC1;
306 val = act8931_reg_read(act8931, act8931_BUCK_CONTR_REG(buck));
316 static int act8931_dcdc_enable(struct regulator_dev *dev)
318 struct act8931 *act8931 = rdev_get_drvdata(dev);
319 int buck = rdev_get_id(dev) - ACT8931_DCDC1;
322 return act8931_set_bits(act8931, act8931_BUCK_CONTR_REG(buck), mask,
326 static int act8931_dcdc_disable(struct regulator_dev *dev)
328 struct act8931 *act8931 = rdev_get_drvdata(dev);
329 int buck = rdev_get_id(dev) - ACT8931_DCDC1;
332 return act8931_set_bits(act8931, act8931_BUCK_CONTR_REG(buck), mask, 0);
335 static int act8931_dcdc_get_voltage(struct regulator_dev *dev)
337 struct act8931 *act8931 = rdev_get_drvdata(dev);
338 int buck = rdev_get_id(dev) - ACT8931_DCDC1;
342 reg = act8931_reg_read(act8931, act8931_BUCK_SET_VOL_REG(buck));
343 reg &= BUCK_VOL_MASK;
345 val = 1000 * buck_voltage_map[reg];
351 static int act8931_dcdc_set_voltage(struct regulator_dev *dev,
352 int min_uV, int max_uV, unsigned *selector)
354 struct act8931 *act8931 = rdev_get_drvdata(dev);
355 int buck = rdev_get_id(dev) - ACT8931_DCDC1;
356 int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
357 const int *vol_map = buck_voltage_map;
361 DBG("%s, min_uV = %d, max_uV = %d!\n", __func__, min_uV, max_uV);
362 if (min_vol < vol_map[VOL_MIN_IDX] ||
363 min_vol > vol_map[VOL_MAX_IDX])
366 for (val = VOL_MIN_IDX; val <= VOL_MAX_IDX; val++) {
367 if (vol_map[val] >= min_vol)
371 if (vol_map[val] > max_vol)
372 pr_warn("this voltage is not support!voltage set is %d mv\n",
375 ret = act8931_set_bits(act8931, act8931_BUCK_SET_VOL_REG(buck),
377 ret = act8931_set_bits(act8931, act8931_BUCK_SET_VOL_REG(buck) + 0x01,
383 static unsigned int act8931_dcdc_get_mode(struct regulator_dev *dev)
385 struct act8931 *act8931 = rdev_get_drvdata(dev);
386 int buck = rdev_get_id(dev) - ACT8931_DCDC1;
390 val = act8931_reg_read(act8931, act8931_BUCK_CONTR_REG(buck));
393 return REGULATOR_MODE_STANDBY;
395 return REGULATOR_MODE_NORMAL;
398 static int act8931_dcdc_set_mode(struct regulator_dev *dev, unsigned int mode)
400 struct act8931 *act8931 = rdev_get_drvdata(dev);
401 int buck = rdev_get_id(dev) - ACT8931_DCDC1;
405 case REGULATOR_MODE_STANDBY:
406 return act8931_set_bits(act8931, act8931_BUCK_CONTR_REG(buck),
408 case REGULATOR_MODE_NORMAL:
409 return act8931_set_bits(act8931, act8931_BUCK_CONTR_REG(buck),
412 pr_err("pmu_act8931 only powersave and pwm mode\n");
417 static struct regulator_ops act8931_dcdc_ops = {
418 .set_voltage = act8931_dcdc_set_voltage,
419 .get_voltage = act8931_dcdc_get_voltage,
420 .list_voltage = act8931_dcdc_list_voltage,
421 .is_enabled = act8931_dcdc_is_enabled,
422 .enable = act8931_dcdc_enable,
423 .disable = act8931_dcdc_disable,
424 .get_mode = act8931_dcdc_get_mode,
425 .set_mode = act8931_dcdc_set_mode,
428 static struct regulator_desc regulators[] = {
432 .ops = &act8931_dcdc_ops,
433 .n_voltages = ARRAY_SIZE(buck_voltage_map),
434 .type = REGULATOR_VOLTAGE,
435 .owner = THIS_MODULE,
440 .ops = &act8931_dcdc_ops,
441 .n_voltages = ARRAY_SIZE(buck_voltage_map),
442 .type = REGULATOR_VOLTAGE,
443 .owner = THIS_MODULE,
448 .ops = &act8931_dcdc_ops,
449 .n_voltages = ARRAY_SIZE(buck_voltage_map),
450 .type = REGULATOR_VOLTAGE,
451 .owner = THIS_MODULE,
456 .ops = &act8931_ldo_ops,
457 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
458 .type = REGULATOR_VOLTAGE,
459 .owner = THIS_MODULE,
464 .ops = &act8931_ldo_ops,
465 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
466 .type = REGULATOR_VOLTAGE,
467 .owner = THIS_MODULE,
472 .ops = &act8931_ldo_ops,
473 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
474 .type = REGULATOR_VOLTAGE,
475 .owner = THIS_MODULE,
480 .ops = &act8931_ldo_ops,
481 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
482 .type = REGULATOR_VOLTAGE,
483 .owner = THIS_MODULE,
488 static int act8931_i2c_read(struct i2c_client *i2c, char reg, int count,
492 struct i2c_adapter *adap;
493 struct i2c_msg msgs[2];
503 msgs[0].addr = i2c->addr;
505 msgs[0].flags = i2c->flags;
507 msgs[0].scl_rate = 200*1000;
509 msgs[1].buf = (u8 *)dest;
510 msgs[1].addr = i2c->addr;
511 msgs[1].flags = i2c->flags | I2C_M_RD;
513 msgs[1].scl_rate = 200*1000;
514 ret = i2c_transfer(adap, msgs, 2);
516 DBG("***run in %s %d msgs[1].buf = %d\n", __func__, __LINE__,
522 static int act8931_i2c_write(struct i2c_client *i2c, char reg, int count,
525 struct i2c_adapter *adap;
539 msg.addr = i2c->addr;
540 msg.buf = &tx_buf[0];
542 msg.flags = i2c->flags;
543 msg.scl_rate = 200*1000;
545 ret = i2c_transfer(adap, &msg, 1);
550 static u8 act8931_reg_read(struct act8931 *act8931, u8 reg)
554 mutex_lock(&act8931->io_lock);
556 act8931_i2c_read(act8931->i2c, reg, 1, &val);
558 DBG("reg read 0x%02x -> 0x%02x\n", (int)reg, (unsigned)val&0xff);
560 mutex_unlock(&act8931->io_lock);
565 static int act8931_set_bits(struct act8931 *act8931, u8 reg, u16 mask, u16 val)
570 mutex_lock(&act8931->io_lock);
572 ret = act8931_i2c_read(act8931->i2c, reg, 1, &tmp);
573 DBG("1 reg read 0x%02x -> 0x%02x\n", (int)reg, (unsigned)tmp&0xff);
574 tmp = (tmp & ~mask) | val;
576 ret = act8931_i2c_write(act8931->i2c, reg, 1, tmp);
577 DBG("reg write 0x%02x -> 0x%02x\n", (int)reg,
580 act8931_i2c_read(act8931->i2c, reg, 1, &tmp);
581 DBG("2 reg read 0x%02x -> 0x%02x\n", (int)reg, (unsigned)tmp&0xff);
582 mutex_unlock(&act8931->io_lock);
587 void act8931_device_shutdown(void)
590 struct act8931 *act8931 = g_act8931;
592 pr_info("%s\n", __func__);
594 ret = act8931_reg_read(act8931, 0x01);
595 ret = act8931_set_bits(act8931, 0x01, (0x1<<5) | (0x3<<0),
596 (0x1<<5) | (0x3<<0));
598 pr_err("act8931 set 0x01 error!\n");
601 arm_pm_restart('h', "charge");
605 static struct of_device_id act8931_of_match[] = {
606 { .compatible = "act,act8931"},
609 MODULE_DEVICE_TABLE(of, act8931_of_match);
613 static struct of_regulator_match act8931_reg_matches[] = {
614 { .name = "act_dcdc1" },
615 { .name = "act_dcdc2" },
616 { .name = "act_dcdc3" },
617 { .name = "act_ldo1" },
618 { .name = "act_ldo2" },
619 { .name = "act_ldo3" },
620 { .name = "act_ldo4" },
623 static struct act8931_board *act8931_parse_dt(struct act8931 *act8931)
625 struct act8931_board *pdata;
626 struct device_node *regs;
627 struct device_node *node;
630 node = of_node_get(act8931->dev->of_node);
632 pr_err("%s: could not find pmic node\n", __func__);
636 regs = of_get_child_by_name(node, "regulators");
640 count = of_regulator_match(act8931->dev, regs, act8931_reg_matches,
641 ACT8931_NUM_REGULATORS);
644 if ((count < 0) || (count > ACT8931_NUM_REGULATORS))
647 pdata = devm_kzalloc(act8931->dev, sizeof(*pdata), GFP_KERNEL);
651 for (i = 0; i < count; i++) {
652 pdata->act8931_init_data[i] = act8931_reg_matches[i].init_data;
653 pdata->of_node[i] = act8931_reg_matches[i].of_node;
656 pdata->irq_gpio = of_get_named_gpio(node, "gpios", 0);
657 if (!gpio_is_valid(pdata->irq_gpio)) {
658 pr_err("%s: invalid gpio: %d\n", __func__, pdata->irq_gpio);
662 pdata->pwr_hold_gpio = of_get_named_gpio(node, "gpios", 1);
663 if (!gpio_is_valid(pdata->pwr_hold_gpio)) {
664 pr_err("%s: invalid gpio: %d\n", __func__,
665 pdata->pwr_hold_gpio);
669 pdata->pm_off = of_property_read_bool(node,
670 "act8931,system-power-controller");
675 static struct act8931_board *act8931_parse_dt(struct act8931 *act8931)
681 static irqreturn_t act8931_irq_thread(int irq, void *dev_id)
683 struct act8931 *act8931 = (struct act8931 *)dev_id;
687 val = act8931_reg_read(act8931, 0x78);
688 act8931_charge_det = (val & INDAT_MASK) ? 1 : 0;
689 act8931_charge_ok = (val & CHGDAT_MASK) ? 1 : 0;
690 DBG(charge_det ? "connect!" : "disconnect!");
691 DBG(charge_ok ? "charge ok!\n" : "charging or discharge!\n");
693 /* reset related regs according to spec */
694 ret = act8931_set_bits(act8931, 0x78, INSTAT_MASK | CHGSTAT_MASK,
695 INSTAT_MASK | CHGSTAT_MASK);
697 pr_err("act8931 set 0x78 error!\n");
702 static int act8931_i2c_probe(struct i2c_client *i2c,
703 const struct i2c_device_id *id)
705 const struct of_device_id *match;
706 struct act8931 *act8931;
707 struct act8931_board *pdata;
708 struct regulator_init_data *reg_data;
709 struct regulator_config config = { };
710 const char *rail_name = NULL;
711 struct regulator_dev *rdev;
715 pr_info("%s,line=%d\n", __func__, __LINE__);
717 if (i2c->dev.of_node) {
718 match = of_match_device(act8931_of_match, &i2c->dev);
720 pr_err("Failed to find matching dt id\n");
725 act8931 = devm_kzalloc(&i2c->dev, sizeof(struct act8931), GFP_KERNEL);
726 if (act8931 == NULL) {
731 act8931->dev = &i2c->dev;
734 mutex_init(&act8931->io_lock);
736 ret = act8931_reg_read(act8931, 0x22);
737 if ((ret < 0) || (ret == 0xff)) {
738 pr_err("The device is not act8931\n");
742 if (act8931->dev->of_node)
743 pdata = act8931_parse_dt(act8931);
745 ret = act8931_reg_read(act8931, 0x01);
748 ret = act8931_set_bits(act8931, 0x01, (0x1<<5) | (0x1<<0), (0x1<<0));
750 pr_err("act8931 set 0x01 error!\n");
754 /* Initialize charge status */
755 val = act8931_reg_read(act8931, 0x78);
756 act8931_charge_det = (val & INDAT_MASK) ? 1 : 0;
757 act8931_charge_ok = (val & CHGDAT_MASK) ? 1 : 0;
758 DBG(charge_det ? "connect!" : "disconnect!");
759 DBG(charge_ok ? "charge ok!\n" : "charging or discharge!\n");
761 ret = act8931_set_bits(act8931, 0x78, INSTAT_MASK | CHGSTAT_MASK,
762 INSTAT_MASK | CHGSTAT_MASK);
764 pr_err("act8931 set 0x78 error!\n");
768 ret = act8931_set_bits(act8931, 0x79, INCON_MASK | CHGEOCIN_MASK
769 | INDIS_MASK | CHGEOCOUT_MASK, INCON_MASK
770 | CHGEOCIN_MASK | INDIS_MASK | CHGEOCOUT_MASK);
772 pr_err("act8931 set 0x79 error!\n");
777 act8931->num_regulators = ACT8931_NUM_REGULATORS;
778 act8931->rdev = kcalloc(ACT8931_NUM_REGULATORS,
779 sizeof(struct regulator_dev *),
784 /* Instantiate the regulators */
785 for (i = 0; i < ACT8931_NUM_REGULATORS; i++) {
786 reg_data = pdata->act8931_init_data[i];
789 if (reg_data->constraints.name)
790 rail_name = reg_data->constraints.name;
792 rail_name = regulators[i].name;
793 reg_data->supply_regulator = rail_name;
795 config.dev = act8931->dev;
796 config.driver_data = act8931;
797 if (act8931->dev->of_node)
798 config.of_node = pdata->of_node[i];
799 config.init_data = reg_data;
801 rdev = regulator_register(®ulators[i], &config);
803 pr_err("failed to register %d regulator\n", i);
806 act8931->rdev[i] = rdev;
810 if (pdata->pm_off && !pm_power_off)
811 pm_power_off = act8931_device_shutdown;
813 act8931->pwr_hold_gpio = pdata->pwr_hold_gpio;
814 if (act8931->pwr_hold_gpio) {
815 ret = gpio_request(act8931->pwr_hold_gpio, "act8931 pmic_hold");
817 pr_err("Failed to request gpio %d with ret %d\n",
818 act8931->pwr_hold_gpio, ret);
821 gpio_direction_output(act8931->pwr_hold_gpio, 1);
822 ret = gpio_get_value(act8931->pwr_hold_gpio);
823 pr_info("%s: act8931_pmic_hold=%x\n", __func__, ret);
826 ret = gpio_request(pdata->irq_gpio, "act8931 irq");
828 pr_err("act8931 irq_gpio request fail\n");
829 gpio_free(pdata->irq_gpio);
832 gpio_direction_input(pdata->irq_gpio);
834 act8931->irq = gpio_to_irq(pdata->irq_gpio);
835 ret = request_threaded_irq(act8931->irq, NULL, act8931_irq_thread,
836 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
837 i2c->dev.driver->name, act8931);
839 pr_err("request act8931 irq fail\n");
842 enable_irq_wake(act8931->irq);
844 i2c_set_clientdata(i2c, act8931);
852 static int act8931_i2c_remove(struct i2c_client *i2c)
854 struct act8931 *act8931 = i2c_get_clientdata(i2c);
857 for (i = 0; i < act8931->num_regulators; i++)
858 if (act8931->rdev[i])
859 regulator_unregister(act8931->rdev[i]);
860 kfree(act8931->rdev);
861 i2c_set_clientdata(i2c, NULL);
867 static const struct i2c_device_id act8931_i2c_id[] = {
871 MODULE_DEVICE_TABLE(i2c, act8931_i2c_id);
873 static struct i2c_driver act8931_i2c_driver = {
876 .owner = THIS_MODULE,
877 .of_match_table = of_match_ptr(act8931_of_match),
879 .probe = act8931_i2c_probe,
880 .remove = act8931_i2c_remove,
881 .id_table = act8931_i2c_id,
884 static int __init act8931_module_init(void)
888 ret = i2c_add_driver(&act8931_i2c_driver);
890 pr_err("Failed to register I2C driver: %d\n", ret);
893 subsys_initcall_sync(act8931_module_init);
895 static void __exit act8931_module_exit(void)
897 i2c_del_driver(&act8931_i2c_driver);
899 module_exit(act8931_module_exit);
901 MODULE_LICENSE("GPL");
902 MODULE_AUTHOR("dkl <dkl@rock-chips.com>");
903 MODULE_DESCRIPTION("act8931 PMIC driver");