1 #include <linux/regulator/machine.h>
3 #include <linux/platform_device.h>
6 #include <mach/iomux.h>
7 #include <mach/board.h>
9 #include <linux/mfd/rt5025.h>
11 #ifdef CONFIG_MFD_RT5025
13 static int rt5025_pre_init(struct rt5025_chip *rt5025_chip){
16 printk("%s,line=%d\n", __func__,__LINE__);
18 /**********set voltage speed***********************/
19 ret = rt5025_reg_read(rt5025_chip->i2c, 0x08);
20 ret &= (~(3<<0)); //dcdc1 25mv/10us
21 rt5025_reg_write(rt5025_chip->i2c, 0x08,ret);
23 ret = rt5025_reg_read(rt5025_chip->i2c, 0x09);
24 ret &= (~(3<<0));//dcdc2 100mv/10us
25 rt5025_reg_write(rt5025_chip->i2c, 0x09,ret);
27 ret = rt5025_reg_read(rt5025_chip->i2c, 0x0a);
28 ret &= (~(3<<0));//dcdc3 50mv/12us
29 rt5025_reg_write(rt5025_chip->i2c, 0x0a,ret);
30 /************************************************/
31 /***************set power off voltage***************/
32 ret = rt5025_reg_read(rt5025_chip->i2c, 0x17);
33 ret &= (~(7<<5)); //power off 2.8v
34 rt5025_reg_write(rt5025_chip->i2c, 0x17,ret);
36 ret = rt5025_reg_read(rt5025_chip->i2c, 0x17);
37 ret |= (1<<3); //enable DC4 boost
38 rt5025_reg_write(rt5025_chip->i2c, 0x17,ret);
39 /***********************************************/
40 /************************************************/
43 static int rt5025_post_init(void)
45 struct regulator *dcdc;
46 struct regulator *ldo;
48 printk("%s,line=%d\n", __func__,__LINE__);
50 #ifndef CONFIG_RK_CONFIG
51 g_pmic_type = PMIC_TYPE_RT5025;
53 printk("%s:g_pmic_type=%d\n",__func__,g_pmic_type);
55 for(i = 0; i < ARRAY_SIZE(rt5025_dcdc_info); i++)
57 if(rt5025_dcdc_info[i].min_uv == 0 && rt5025_dcdc_info[i].max_uv == 0)
59 dcdc =regulator_get(NULL, rt5025_dcdc_info[i].name);
61 regulator_set_voltage(dcdc, rt5025_dcdc_info[i].min_uv, rt5025_dcdc_info[i].max_uv);
63 regulator_set_mode(dcdc, REGULATOR_MODE_NORMAL);
64 regulator_enable(dcdc);
65 printk("%s %s =%duV end\n", __func__,rt5025_dcdc_info[i].name, regulator_get_voltage(dcdc));
70 for(i = 0; i < ARRAY_SIZE(rt5025_ldo_info); i++)
72 if(rt5025_ldo_info[i].min_uv == 0 && rt5025_ldo_info[i].max_uv == 0)
74 ldo =regulator_get(NULL, rt5025_ldo_info[i].name);
75 regulator_set_voltage(ldo, rt5025_ldo_info[i].min_uv, rt5025_ldo_info[i].max_uv);
76 regulator_enable(ldo);
77 printk("%s %s =%duV end\n", __func__,rt5025_ldo_info[i].name, regulator_get_voltage(ldo));
81 printk("%s,line=%d END\n", __func__,__LINE__);
85 static struct regulator_consumer_supply rt5025_dcdc1_supply[] = {
87 .supply = "rt5025-dcdc1",
94 static struct regulator_consumer_supply rt5025_dcdc2_supply[] = {
96 .supply = "rt5025-dcdc2",
102 static struct regulator_consumer_supply rt5025_dcdc3_supply[] = {
104 .supply = "rt5025-dcdc3",
108 static struct regulator_consumer_supply rt5025_dcdc4_supply[] = {
110 .supply = "rt5025-dcdc4",
114 static struct regulator_consumer_supply rt5025_ldo1_supply[] = {
116 .supply = "rt5025-ldo1",
119 static struct regulator_consumer_supply rt5025_ldo2_supply[] = {
121 .supply = "rt5025-ldo2",
125 static struct regulator_consumer_supply rt5025_ldo3_supply[] = {
127 .supply = "rt5025-ldo3",
130 static struct regulator_consumer_supply rt5025_ldo4_supply[] = {
132 .supply = "rt5025-ldo4",
135 static struct regulator_consumer_supply rt5025_ldo5_supply[] = {
137 .supply = "rt5025-ldo5",
140 static struct regulator_consumer_supply rt5025_ldo6_supply[] = {
142 .supply = "rt5025-ldo6",
146 static struct regulator_init_data rt5025_dcdc1_info = {
148 .name = "RT5025-DCDC1",
151 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
152 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS| REGULATOR_CHANGE_MODE,
154 .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc1_supply),
155 .consumer_supplies = rt5025_dcdc1_supply,
158 static struct regulator_init_data rt5025_dcdc2_info = {
160 .name = "RT5025-DCDC2",
163 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
164 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_MODE,
166 .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc2_supply),
167 .consumer_supplies = rt5025_dcdc2_supply,
170 static struct regulator_init_data rt5025_dcdc3_info = {
172 .name = "RT5025-DCDC3",
175 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
176 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_MODE,
178 .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc3_supply),
179 .consumer_supplies = rt5025_dcdc3_supply,
182 static struct regulator_init_data rt5025_dcdc4_info = {
184 .name = "RT5025-DCDC4",
187 .valid_modes_mask = REGULATOR_MODE_NORMAL,
188 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
190 .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc4_supply),
191 .consumer_supplies = rt5025_dcdc4_supply,
194 static struct regulator_init_data rt5025_ldo1_info = {
196 .name = "RT5025-LDO1",
199 .valid_modes_mask = REGULATOR_MODE_NORMAL,
200 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
202 .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo1_supply),
203 .consumer_supplies = rt5025_ldo1_supply,
206 static struct regulator_init_data rt5025_ldo2_info = {
208 .name = "RT5025-LDO2",
211 .valid_modes_mask = REGULATOR_MODE_NORMAL,
212 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
214 .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo2_supply),
215 .consumer_supplies = rt5025_ldo2_supply,
218 static struct regulator_init_data rt5025_ldo3_info = {
220 .name = "RT5025-LDO3",
223 .valid_modes_mask = REGULATOR_MODE_NORMAL,
224 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
226 .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo3_supply),
227 .consumer_supplies = rt5025_ldo3_supply,
230 static struct regulator_init_data rt5025_ldo4_info = {
232 .name = "RT5025-LDO4",
235 .valid_modes_mask = REGULATOR_MODE_NORMAL,
236 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
238 .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo4_supply),
239 .consumer_supplies = rt5025_ldo4_supply,
242 static struct regulator_init_data rt5025_ldo5_info = {
244 .name = "RT5025-LDO5",
247 .valid_modes_mask = REGULATOR_MODE_NORMAL,
248 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
250 .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo5_supply),
251 .consumer_supplies = rt5025_ldo5_supply,
254 static struct regulator_init_data rt5025_ldo6_info = {
256 .name = "RT5025-LDO6",
259 .valid_modes_mask = REGULATOR_MODE_NORMAL,
260 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
262 .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo6_supply),
263 .consumer_supplies = rt5025_ldo6_supply,
266 static struct rt5025_power_data rt5025_power_data = {
271 .CCCHG_TIMEOUT = RT5025_CCCHG_TO_6H,
272 .PRECHG_TIMEOUT = RT5025_PRECHG_TO_30M,
283 .AICR = RT5025_AICR_500MA,
284 .ICC = RT5025_ICC_0P5A,
289 .DPM = RT5025_DPM_4P5V,
294 .IPREC = RT5025_IPREC_10P,
295 .IEOC = RT5025_IEOC_10P,
296 .VPREC = RT5025_VPREC_3V,
306 .fcc = 6200, //6200 mAh
309 static struct rt5025_gpio_data rt5025_gpio_data = {
310 // .gpio_base = RT5025_GPIO_BASE,
311 .irq_base = IRQ_BOARD_BASE,
314 static struct rt5025_misc_data rt5025_misc_data = {
318 .Delayed1 = RT5025_RSTDELAY1_1S,
319 .Delayed2 = RT5025_RSTDELAY2_1S,
324 .VOFF = RT5025_VOFF_3P4V,
329 .PG_DLY = RT5025_PGDLY_100MS,
330 .SHDN_PRESS = RT5025_SHDNPRESS_6S,
331 .LPRESS_TIME = RT5025_LPRESS_1P5S,
332 .START_TIME = RT5025_STARTIME_100MS,
337 .SHDN_DLYTIME = RT5025_SHDNDLY_1S,
354 static struct rt5025_irq_data rt5025_irq_data = {
410 static void rt5025_charger_event_callback(uint32_t detected)
412 RTINFO("event detected = 0x%08x\n", detected);
413 if (detected & CHG_EVENT_CHTERMI)
415 pr_info("charger termination OK\n");
419 static void rt5025_power_event_callback(uint32_t detected)
421 RTINFO("event detected = 0x%08x\n", detected);
422 if (detected & PWR_EVENT_SYSLV)
424 pr_info("sys voltage low\n");
428 static struct rt5025_event_callback rt5025_event_callback = {
429 .charger_event_callback = rt5025_charger_event_callback,
430 .power_event_callkback = rt5025_power_event_callback,
433 static struct rt5025_platform_data rt5025_data = {
434 .pre_init=rt5025_pre_init,
435 .post_init=rt5025_post_init,
448 .power_data = &rt5025_power_data,
449 .gpio_data = &rt5025_gpio_data,
450 .misc_data = &rt5025_misc_data,
451 .irq_data = &rt5025_irq_data,
452 .cb = &rt5025_event_callback,
453 .intr_pin = 81, //GPIO81
456 void __sramfunc board_pmu_rt5025_suspend(void)
459 void __sramfunc board_pmu_rt5025_resume(void)