2 * Regulator driver for Active-semi act8846 PMIC chip for rk29xx
4 * Copyright (C) 2010, 2011 ROCKCHIP, Inc.
6 * Based on act8846.c that is work by zhangqing<zhangqing@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/bug.h>
15 #include <linux/err.h>
16 #include <linux/i2c.h>
17 #include <linux/kernel.h>
18 #include <linux/regulator/driver.h>
19 #include <linux/regulator/act8846.h>
20 #include <mach/gpio.h>
21 #include <linux/delay.h>
22 #include <mach/iomux.h>
23 #include <linux/slab.h>
24 #ifdef CONFIG_HAS_EARLYSUSPEND
25 #include <linux/earlysuspend.h>
30 #define DBG(x...) printk(KERN_INFO x)
35 #define DBG_INFO(x...) printk(KERN_INFO x)
37 #define DBG_INFO(x...)
44 struct i2c_client *i2c;
46 struct regulator_dev **rdev;
47 struct early_suspend act8846_suspend;
50 struct act8846 *g_act8846;
52 static u8 act8846_reg_read(struct act8846 *act8846, u8 reg);
53 static int act8846_set_bits(struct act8846 *act8846, u8 reg, u16 mask, u16 val);
56 #define act8846_BUCK1_SET_VOL_BASE 0x10
57 #define act8846_BUCK2_SET_VOL_BASE 0x20
58 #define act8846_BUCK3_SET_VOL_BASE 0x30
59 #define act8846_BUCK4_SET_VOL_BASE 0x40
61 #define act8846_BUCK2_SLP_VOL_BASE 0x21
62 #define act8846_BUCK3_SLP_VOL_BASE 0x31
63 #define act8846_BUCK4_SLP_VOL_BASE 0x41
65 #define act8846_LDO1_SET_VOL_BASE 0x50
66 #define act8846_LDO2_SET_VOL_BASE 0x58
67 #define act8846_LDO3_SET_VOL_BASE 0x60
68 #define act8846_LDO4_SET_VOL_BASE 0x68
69 #define act8846_LDO5_SET_VOL_BASE 0x70
70 #define act8846_LDO6_SET_VOL_BASE 0x80
71 #define act8846_LDO7_SET_VOL_BASE 0x90
72 #define act8846_LDO8_SET_VOL_BASE 0xa0
73 //#define act8846_LDO9_SET_VOL_BASE 0xb1
75 #define act8846_BUCK1_CONTR_BASE 0x12
76 #define act8846_BUCK2_CONTR_BASE 0x22
77 #define act8846_BUCK3_CONTR_BASE 0x32
78 #define act8846_BUCK4_CONTR_BASE 0x42
80 #define act8846_LDO1_CONTR_BASE 0x51
81 #define act8846_LDO2_CONTR_BASE 0x59
82 #define act8846_LDO3_CONTR_BASE 0x61
83 #define act8846_LDO4_CONTR_BASE 0x69
84 #define act8846_LDO5_CONTR_BASE 0x71
85 #define act8846_LDO6_CONTR_BASE 0x81
86 #define act8846_LDO7_CONTR_BASE 0x91
87 #define act8846_LDO8_CONTR_BASE 0xa1
88 //#define act8846_LDO9_CONTR_BASE 0xb1
90 #define BUCK_VOL_MASK 0x3f
91 #define LDO_VOL_MASK 0x3f
93 #define VOL_MIN_IDX 0x00
94 #define VOL_MAX_IDX 0x3f
96 const static int buck_set_vol_base_addr[] = {
97 act8846_BUCK1_SET_VOL_BASE,
98 act8846_BUCK2_SET_VOL_BASE,
99 act8846_BUCK3_SET_VOL_BASE,
100 act8846_BUCK4_SET_VOL_BASE,
102 const static int buck_contr_base_addr[] = {
103 act8846_BUCK1_CONTR_BASE,
104 act8846_BUCK2_CONTR_BASE,
105 act8846_BUCK3_CONTR_BASE,
106 act8846_BUCK4_CONTR_BASE,
108 #define act8846_BUCK_SET_VOL_REG(x) (buck_set_vol_base_addr[x])
109 #define act8846_BUCK_CONTR_REG(x) (buck_contr_base_addr[x])
112 const static int ldo_set_vol_base_addr[] = {
113 act8846_LDO1_SET_VOL_BASE,
114 act8846_LDO2_SET_VOL_BASE,
115 act8846_LDO3_SET_VOL_BASE,
116 act8846_LDO4_SET_VOL_BASE,
117 act8846_LDO5_SET_VOL_BASE,
118 act8846_LDO6_SET_VOL_BASE,
119 act8846_LDO7_SET_VOL_BASE,
120 act8846_LDO8_SET_VOL_BASE,
121 // act8846_LDO9_SET_VOL_BASE,
123 const static int ldo_contr_base_addr[] = {
124 act8846_LDO1_CONTR_BASE,
125 act8846_LDO2_CONTR_BASE,
126 act8846_LDO3_CONTR_BASE,
127 act8846_LDO4_CONTR_BASE,
128 act8846_LDO5_CONTR_BASE,
129 act8846_LDO6_CONTR_BASE,
130 act8846_LDO7_CONTR_BASE,
131 act8846_LDO8_CONTR_BASE,
132 // act8846_LDO9_CONTR_BASE,
134 #define act8846_LDO_SET_VOL_REG(x) (ldo_set_vol_base_addr[x])
135 #define act8846_LDO_CONTR_REG(x) (ldo_contr_base_addr[x])
137 const static 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 const static 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 act8846_ldo_list_voltage(struct regulator_dev *dev, unsigned index)
163 if (index >= ARRAY_SIZE(ldo_voltage_map))
165 return 1000 * ldo_voltage_map[index];
167 static int act8846_ldo_is_enabled(struct regulator_dev *dev)
169 struct act8846 *act8846 = rdev_get_drvdata(dev);
170 int ldo = rdev_get_id(dev) - ACT8846_LDO1;
173 val = act8846_reg_read(act8846, act8846_LDO_CONTR_REG(ldo));
182 static int act8846_ldo_enable(struct regulator_dev *dev)
184 struct act8846 *act8846 = rdev_get_drvdata(dev);
185 int ldo= rdev_get_id(dev) - ACT8846_LDO1;
188 return act8846_set_bits(act8846, act8846_LDO_CONTR_REG(ldo), mask, 0x80);
191 static int act8846_ldo_disable(struct regulator_dev *dev)
193 struct act8846 *act8846 = rdev_get_drvdata(dev);
194 int ldo= rdev_get_id(dev) - ACT8846_LDO1;
197 return act8846_set_bits(act8846, act8846_LDO_CONTR_REG(ldo), mask, 0);
200 static int act8846_ldo_get_voltage(struct regulator_dev *dev)
202 struct act8846 *act8846 = rdev_get_drvdata(dev);
203 int ldo= rdev_get_id(dev) - ACT8846_LDO1;
206 reg = act8846_reg_read(act8846,act8846_LDO_SET_VOL_REG(ldo));
208 val = 1000 * ldo_voltage_map[reg];
211 static int act8846_ldo_set_voltage(struct regulator_dev *dev,
212 int min_uV, int max_uV,unsigned *selector)
214 struct act8846 *act8846 = rdev_get_drvdata(dev);
215 int ldo= rdev_get_id(dev) - ACT8846_LDO1;
216 int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
217 const int *vol_map =ldo_voltage_map;
220 if (min_vol < vol_map[VOL_MIN_IDX] ||
221 min_vol > vol_map[VOL_MAX_IDX])
224 for (val = VOL_MIN_IDX; val <= VOL_MAX_IDX; val++){
225 if (vol_map[val] >= min_vol)
229 if (vol_map[val] > max_vol)
232 ret = act8846_set_bits(act8846, act8846_LDO_SET_VOL_REG(ldo),
237 static unsigned int act8846_ldo_get_mode(struct regulator_dev *dev)
239 struct act8846 *act8846 = rdev_get_drvdata(dev);
240 int ldo = rdev_get_id(dev) - ACT8846_LDO1;
243 val = act8846_reg_read(act8846, act8846_LDO_CONTR_REG(ldo));
249 return REGULATOR_MODE_NORMAL;
251 return REGULATOR_MODE_STANDBY;
254 static int act8846_ldo_set_mode(struct regulator_dev *dev, unsigned int mode)
256 struct act8846 *act8846 = rdev_get_drvdata(dev);
257 int ldo = rdev_get_id(dev) - ACT8846_LDO1;
261 case REGULATOR_MODE_NORMAL:
262 return act8846_set_bits(act8846, act8846_LDO_CONTR_REG(ldo), mask, mask);
263 case REGULATOR_MODE_STANDBY:
264 return act8846_set_bits(act8846, act8846_LDO_CONTR_REG(ldo), mask, 0);
266 printk("error:pmu_act8846 only lowpower and nomal mode\n");
272 static struct regulator_ops act8846_ldo_ops = {
273 .set_voltage = act8846_ldo_set_voltage,
274 .get_voltage = act8846_ldo_get_voltage,
275 .list_voltage = act8846_ldo_list_voltage,
276 .is_enabled = act8846_ldo_is_enabled,
277 .enable = act8846_ldo_enable,
278 .disable = act8846_ldo_disable,
279 .get_mode = act8846_ldo_get_mode,
280 .set_mode = act8846_ldo_set_mode,
284 static int act8846_dcdc_list_voltage(struct regulator_dev *dev, unsigned index)
286 if (index >= ARRAY_SIZE(buck_voltage_map))
288 return 1000 * buck_voltage_map[index];
290 static int act8846_dcdc_is_enabled(struct regulator_dev *dev)
292 struct act8846 *act8846 = rdev_get_drvdata(dev);
293 int buck = rdev_get_id(dev) - ACT8846_DCDC1;
296 val = act8846_reg_read(act8846, act8846_BUCK_CONTR_REG(buck));
305 static int act8846_dcdc_enable(struct regulator_dev *dev)
307 struct act8846 *act8846 = rdev_get_drvdata(dev);
308 int buck = rdev_get_id(dev) - ACT8846_DCDC1;
310 return act8846_set_bits(act8846, act8846_BUCK_CONTR_REG(buck), mask, 0x80);
313 static int act8846_dcdc_disable(struct regulator_dev *dev)
315 struct act8846 *act8846 = rdev_get_drvdata(dev);
316 int buck = rdev_get_id(dev) - ACT8846_DCDC1;
318 return act8846_set_bits(act8846, act8846_BUCK_CONTR_REG(buck), mask, 0);
320 static int act8846_dcdc_get_voltage(struct regulator_dev *dev)
322 struct act8846 *act8846 = rdev_get_drvdata(dev);
323 int buck = rdev_get_id(dev) - ACT8846_DCDC1;
326 #ifdef CONFIG_ACT8846_SUPPORT_RESET
327 reg = act8846_reg_read(act8846,(act8846_BUCK_SET_VOL_REG(buck)+0x1));
329 reg = act8846_reg_read(act8846,act8846_BUCK_SET_VOL_REG(buck));
331 reg &= BUCK_VOL_MASK;
333 val = 1000 * buck_voltage_map[reg];
337 static int act8846_dcdc_set_voltage(struct regulator_dev *dev,
338 int min_uV, int max_uV,unsigned *selector)
340 struct act8846 *act8846 = rdev_get_drvdata(dev);
341 int buck = rdev_get_id(dev) - ACT8846_DCDC1;
342 int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
343 const int *vol_map = buck_voltage_map;
347 DBG("%s, min_uV = %d, max_uV = %d!\n", __func__, min_uV, max_uV);
348 if (min_vol < vol_map[VOL_MIN_IDX] ||
349 min_vol > vol_map[VOL_MAX_IDX])
352 for (val = VOL_MIN_IDX; val <= VOL_MAX_IDX; val++){
353 if (vol_map[val] >= min_vol)
357 if (vol_map[val] > max_vol)
358 printk("WARNING:this voltage is not support!voltage set is %d mv\n",vol_map[val]);
360 #ifdef CONFIG_ACT8846_SUPPORT_RESET
361 ret = act8846_set_bits(act8846, (act8846_BUCK_SET_VOL_REG(buck) +0x1),BUCK_VOL_MASK, val);
363 ret = act8846_set_bits(act8846, act8846_BUCK_SET_VOL_REG(buck) ,BUCK_VOL_MASK, val);
368 static int act8846_dcdc_set_sleep_voltage(struct regulator_dev *dev,
371 struct act8846 *act8846 = rdev_get_drvdata(dev);
372 int buck = rdev_get_id(dev) - ACT8846_DCDC1;
373 int min_vol = uV / 1000,max_vol = uV / 1000;
374 const int *vol_map = buck_voltage_map;
378 DBG("%s, min_uV = %d, max_uV = %d!\n", __func__, min_uV, max_uV);
379 if (min_vol < vol_map[VOL_MIN_IDX] ||
380 min_vol > vol_map[VOL_MAX_IDX])
383 for (val = VOL_MIN_IDX; val <= VOL_MAX_IDX; val++){
384 if (vol_map[val] >= min_vol)
388 if (vol_map[val] > max_vol)
389 printk("WARNING:this voltage is not support!voltage set is %d mv\n",vol_map[val]);
390 #ifdef CONFIG_ACT8846_SUPPORT_RESET
391 ret = act8846_set_bits(act8846, (act8846_BUCK_SET_VOL_REG(buck) ),BUCK_VOL_MASK, val);
393 ret = act8846_set_bits(act8846, (act8846_BUCK_SET_VOL_REG(buck) +0x01),BUCK_VOL_MASK, val);
398 static unsigned int act8846_dcdc_get_mode(struct regulator_dev *dev)
400 struct act8846 *act8846 = rdev_get_drvdata(dev);
401 int buck = rdev_get_id(dev) - ACT8846_DCDC1;
404 val = act8846_reg_read(act8846, act8846_BUCK_CONTR_REG(buck));
410 return REGULATOR_MODE_NORMAL;
412 return REGULATOR_MODE_STANDBY;
415 static int act8846_dcdc_set_mode(struct regulator_dev *dev, unsigned int mode)
417 struct act8846 *act8846 = rdev_get_drvdata(dev);
418 int buck = rdev_get_id(dev) - ACT8846_DCDC1;
422 case REGULATOR_MODE_STANDBY:
423 return act8846_set_bits(act8846, act8846_BUCK_CONTR_REG(buck), mask, 0);
424 case REGULATOR_MODE_NORMAL:
425 return act8846_set_bits(act8846, act8846_BUCK_CONTR_REG(buck), mask, mask);
427 printk("error:pmu_act8846 only powersave and pwm mode\n");
433 static int act8846_dcdc_set_voltage_time_sel(struct regulator_dev *dev, unsigned int old_selector,
434 unsigned int new_selector)
436 struct act8846 *act8846 = rdev_get_drvdata(dev);
437 int ret =0,old_volt, new_volt;
439 old_volt = act8846_dcdc_list_voltage(dev, old_selector);
443 new_volt = act8846_dcdc_list_voltage(dev, new_selector);
447 return DIV_ROUND_UP(abs(old_volt - new_volt)*2, 25000);
450 static struct regulator_ops act8846_dcdc_ops = {
451 .set_voltage = act8846_dcdc_set_voltage,
452 .get_voltage = act8846_dcdc_get_voltage,
453 .list_voltage= act8846_dcdc_list_voltage,
454 .is_enabled = act8846_dcdc_is_enabled,
455 .enable = act8846_dcdc_enable,
456 .disable = act8846_dcdc_disable,
457 .get_mode = act8846_dcdc_get_mode,
458 .set_mode = act8846_dcdc_set_mode,
459 .set_suspend_voltage = act8846_dcdc_set_sleep_voltage,
460 .set_voltage_time_sel = act8846_dcdc_set_voltage_time_sel,
462 static struct regulator_desc regulators[] = {
467 .ops = &act8846_dcdc_ops,
468 .n_voltages = ARRAY_SIZE(buck_voltage_map),
469 .type = REGULATOR_VOLTAGE,
470 .owner = THIS_MODULE,
475 .ops = &act8846_dcdc_ops,
476 .n_voltages = ARRAY_SIZE(buck_voltage_map),
477 .type = REGULATOR_VOLTAGE,
478 .owner = THIS_MODULE,
483 .ops = &act8846_dcdc_ops,
484 .n_voltages = ARRAY_SIZE(buck_voltage_map),
485 .type = REGULATOR_VOLTAGE,
486 .owner = THIS_MODULE,
491 .ops = &act8846_dcdc_ops,
492 .n_voltages = ARRAY_SIZE(buck_voltage_map),
493 .type = REGULATOR_VOLTAGE,
494 .owner = THIS_MODULE,
500 .ops = &act8846_ldo_ops,
501 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
502 .type = REGULATOR_VOLTAGE,
503 .owner = THIS_MODULE,
508 .ops = &act8846_ldo_ops,
509 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
510 .type = REGULATOR_VOLTAGE,
511 .owner = THIS_MODULE,
516 .ops = &act8846_ldo_ops,
517 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
518 .type = REGULATOR_VOLTAGE,
519 .owner = THIS_MODULE,
524 .ops = &act8846_ldo_ops,
525 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
526 .type = REGULATOR_VOLTAGE,
527 .owner = THIS_MODULE,
533 .ops = &act8846_ldo_ops,
534 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
535 .type = REGULATOR_VOLTAGE,
536 .owner = THIS_MODULE,
541 .ops = &act8846_ldo_ops,
542 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
543 .type = REGULATOR_VOLTAGE,
544 .owner = THIS_MODULE,
549 .ops = &act8846_ldo_ops,
550 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
551 .type = REGULATOR_VOLTAGE,
552 .owner = THIS_MODULE,
557 .ops = &act8846_ldo_ops,
558 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
559 .type = REGULATOR_VOLTAGE,
560 .owner = THIS_MODULE,
565 .ops = &act8846_ldo_ops,
566 .n_voltages = ARRAY_SIZE(ldo_voltage_map),
567 .type = REGULATOR_VOLTAGE,
568 .owner = THIS_MODULE,
575 static int act8846_i2c_read(struct i2c_client *i2c, char reg, int count, u16 *dest)
578 struct i2c_adapter *adap;
579 struct i2c_msg msgs[2];
589 msgs[0].addr = i2c->addr;
591 msgs[0].flags = i2c->flags;
593 msgs[0].scl_rate = 200*1000;
595 msgs[1].buf = (u8 *)dest;
596 msgs[1].addr = i2c->addr;
597 msgs[1].flags = i2c->flags | I2C_M_RD;
599 msgs[1].scl_rate = 200*1000;
600 ret = i2c_transfer(adap, msgs, 2);
602 DBG("***run in %s %d msgs[1].buf = %d\n",__FUNCTION__,__LINE__,*(msgs[1].buf));
607 static int act8846_i2c_write(struct i2c_client *i2c, char reg, int count, const u16 src)
611 struct i2c_adapter *adap;
624 msg.addr = i2c->addr;
625 msg.buf = &tx_buf[0];
627 msg.flags = i2c->flags;
628 msg.scl_rate = 200*1000;
630 ret = i2c_transfer(adap, &msg, 1);
634 static u8 act8846_reg_read(struct act8846 *act8846, u8 reg)
638 mutex_lock(&act8846->io_lock);
640 act8846_i2c_read(act8846->i2c, reg, 1, &val);
642 DBG("reg read 0x%02x -> 0x%02x\n", (int)reg, (unsigned)val&0xff);
644 mutex_unlock(&act8846->io_lock);
649 static int act8846_set_bits(struct act8846 *act8846, u8 reg, u16 mask, u16 val)
654 mutex_lock(&act8846->io_lock);
656 ret = act8846_i2c_read(act8846->i2c, reg, 1, &tmp);
657 DBG("1 reg read 0x%02x -> 0x%02x\n", (int)reg, (unsigned)tmp&0xff);
658 tmp = (tmp & ~mask) | val;
660 ret = act8846_i2c_write(act8846->i2c, reg, 1, tmp);
661 DBG("reg write 0x%02x -> 0x%02x\n", (int)reg, (unsigned)val&0xff);
663 act8846_i2c_read(act8846->i2c, reg, 1, &tmp);
664 DBG("2 reg read 0x%02x -> 0x%02x\n", (int)reg, (unsigned)tmp&0xff);
665 mutex_unlock(&act8846->io_lock);
669 static int __devinit setup_regulators(struct act8846 *act8846, struct act8846_platform_data *pdata)
673 act8846->num_regulators = pdata->num_regulators;
674 act8846->rdev = kcalloc(pdata->num_regulators,
675 sizeof(struct regulator_dev *), GFP_KERNEL);
676 if (!act8846->rdev) {
679 /* Instantiate the regulators */
680 for (i = 0; i < pdata->num_regulators; i++) {
681 int id = pdata->regulators[i].id;
682 act8846->rdev[i] = regulator_register(®ulators[id],
683 act8846->dev, pdata->regulators[i].initdata, act8846);
685 if (IS_ERR(act8846->rdev[i])) {
686 err = PTR_ERR(act8846->rdev[i]);
687 dev_err(act8846->dev, "regulator init failed: %d\n",
696 regulator_unregister(act8846->rdev[i]);
697 kfree(act8846->rdev);
698 act8846->rdev = NULL;
703 int act8846_device_shutdown(void)
707 struct act8846 *act8846 = g_act8846;
709 printk("%s\n",__func__);
711 ret = act8846_reg_read(act8846,0xc3);
712 ret = act8846_set_bits(act8846, 0xc3,(0x1<<3),(0x1<<3));
713 ret = act8846_set_bits(act8846, 0xc3,(0x1<<4),(0x1<<4));
715 printk("act8846 set 0xc3 error!\n");
720 EXPORT_SYMBOL_GPL(act8846_device_shutdown);
722 __weak void act8846_device_suspend(void) {}
723 __weak void act8846_device_resume(void) {}
725 static int act8846_suspend(struct i2c_client *i2c, pm_message_t mesg)
727 act8846_device_suspend();
731 static int act8846_resume(struct i2c_client *i2c)
733 act8846_device_resume();
737 static int act8846_suspend(struct i2c_client *i2c, pm_message_t mesg)
742 static int act8846_resume(struct i2c_client *i2c)
749 #ifdef CONFIG_HAS_EARLYSUSPEND
750 __weak void act8846_early_suspend(struct early_suspend *h) {}
751 __weak void act8846_late_resume(struct early_suspend *h) {}
754 static int __devinit act8846_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
756 struct act8846 *act8846;
757 struct act8846_platform_data *pdata = i2c->dev.platform_data;
759 act8846 = kzalloc(sizeof(struct act8846), GFP_KERNEL);
760 if (act8846 == NULL) {
765 act8846->dev = &i2c->dev;
766 i2c_set_clientdata(i2c, act8846);
767 mutex_init(&act8846->io_lock);
769 ret = act8846_reg_read(act8846,0x22);
770 if ((ret < 0) || (ret == 0xff)){
771 printk("The device is not act8846 \n");
775 ret = act8846_set_bits(act8846, 0xf4,(0x1<<7),(0x0<<7));
777 printk("act8846 set 0xf4 error!\n");
782 ret = setup_regulators(act8846, pdata);
786 dev_warn(act8846->dev, "No platform init data supplied\n");
789 pdata->set_init(act8846);
791 #ifdef CONFIG_HAS_EARLYSUSPEND
792 act8846->act8846_suspend.suspend = act8846_early_suspend,
793 act8846->act8846_suspend.resume = act8846_late_resume,
794 act8846->act8846_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1,
795 register_early_suspend(&act8846->act8846_suspend);
805 static int __devexit act8846_i2c_remove(struct i2c_client *i2c)
807 struct act8846 *act8846 = i2c_get_clientdata(i2c);
810 for (i = 0; i < act8846->num_regulators; i++)
811 if (act8846->rdev[i])
812 regulator_unregister(act8846->rdev[i]);
813 kfree(act8846->rdev);
814 i2c_set_clientdata(i2c, NULL);
820 static const struct i2c_device_id act8846_i2c_id[] = {
825 MODULE_DEVICE_TABLE(i2c, act8846_i2c_id);
827 static struct i2c_driver act8846_i2c_driver = {
830 .owner = THIS_MODULE,
832 .probe = act8846_i2c_probe,
833 .remove = __devexit_p(act8846_i2c_remove),
834 .id_table = act8846_i2c_id,
836 .suspend = act8846_suspend,
837 .resume = act8846_resume,
841 static int __init act8846_module_init(void)
844 ret = i2c_add_driver(&act8846_i2c_driver);
846 pr_err("Failed to register I2C driver: %d\n", ret);
849 //module_init(act8846_module_init);
850 //subsys_initcall(act8846_module_init);
851 //rootfs_initcall(act8846_module_init);
852 subsys_initcall_sync(act8846_module_init);
854 static void __exit act8846_module_exit(void)
856 i2c_del_driver(&act8846_i2c_driver);
858 module_exit(act8846_module_exit);
860 MODULE_LICENSE("GPL");
861 MODULE_AUTHOR("zhangqing <zhangqing@rock-chips.com>");
862 MODULE_DESCRIPTION("act8846 PMIC driver");