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__);
86 int rt5025_set_otg_enable(int enable)
89 rt5025_ext_set_charging_buck(0);
91 rt5025_ext_set_charging_buck(1);
95 static struct regulator_consumer_supply rt5025_dcdc1_supply[] = {
97 .supply = "rt5025-dcdc1",
104 static struct regulator_consumer_supply rt5025_dcdc2_supply[] = {
106 .supply = "rt5025-dcdc2",
109 .supply = "vdd_core",
112 static struct regulator_consumer_supply rt5025_dcdc3_supply[] = {
114 .supply = "rt5025-dcdc3",
118 static struct regulator_consumer_supply rt5025_dcdc4_supply[] = {
120 .supply = "rt5025-dcdc4",
124 static struct regulator_consumer_supply rt5025_ldo1_supply[] = {
126 .supply = "rt5025-ldo1",
129 static struct regulator_consumer_supply rt5025_ldo2_supply[] = {
131 .supply = "rt5025-ldo2",
135 static struct regulator_consumer_supply rt5025_ldo3_supply[] = {
137 .supply = "rt5025-ldo3",
140 static struct regulator_consumer_supply rt5025_ldo4_supply[] = {
142 .supply = "rt5025-ldo4",
145 static struct regulator_consumer_supply rt5025_ldo5_supply[] = {
147 .supply = "rt5025-ldo5",
150 static struct regulator_consumer_supply rt5025_ldo6_supply[] = {
152 .supply = "rt5025-ldo6",
156 static struct regulator_init_data rt5025_dcdc1_info = {
158 .name = "RT5025-DCDC1",
161 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
162 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS| REGULATOR_CHANGE_MODE,
164 .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc1_supply),
165 .consumer_supplies = rt5025_dcdc1_supply,
168 static struct regulator_init_data rt5025_dcdc2_info = {
170 .name = "RT5025-DCDC2",
173 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
174 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_MODE,
176 .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc2_supply),
177 .consumer_supplies = rt5025_dcdc2_supply,
180 static struct regulator_init_data rt5025_dcdc3_info = {
182 .name = "RT5025-DCDC3",
185 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
186 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_MODE,
188 .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc3_supply),
189 .consumer_supplies = rt5025_dcdc3_supply,
192 static struct regulator_init_data rt5025_dcdc4_info = {
194 .name = "RT5025-DCDC4",
197 .valid_modes_mask = REGULATOR_MODE_NORMAL,
198 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
200 .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc4_supply),
201 .consumer_supplies = rt5025_dcdc4_supply,
204 static struct regulator_init_data rt5025_ldo1_info = {
206 .name = "RT5025-LDO1",
209 .valid_modes_mask = REGULATOR_MODE_NORMAL,
210 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
212 .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo1_supply),
213 .consumer_supplies = rt5025_ldo1_supply,
216 static struct regulator_init_data rt5025_ldo2_info = {
218 .name = "RT5025-LDO2",
221 .valid_modes_mask = REGULATOR_MODE_NORMAL,
222 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
224 .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo2_supply),
225 .consumer_supplies = rt5025_ldo2_supply,
228 static struct regulator_init_data rt5025_ldo3_info = {
230 .name = "RT5025-LDO3",
233 .valid_modes_mask = REGULATOR_MODE_NORMAL,
234 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
236 .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo3_supply),
237 .consumer_supplies = rt5025_ldo3_supply,
240 static struct regulator_init_data rt5025_ldo4_info = {
242 .name = "RT5025-LDO4",
245 .valid_modes_mask = REGULATOR_MODE_NORMAL,
246 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
248 .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo4_supply),
249 .consumer_supplies = rt5025_ldo4_supply,
252 static struct regulator_init_data rt5025_ldo5_info = {
254 .name = "RT5025-LDO5",
257 .valid_modes_mask = REGULATOR_MODE_NORMAL,
258 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
260 .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo5_supply),
261 .consumer_supplies = rt5025_ldo5_supply,
264 static struct regulator_init_data rt5025_ldo6_info = {
266 .name = "RT5025-LDO6",
269 .valid_modes_mask = REGULATOR_MODE_NORMAL,
270 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
272 .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo6_supply),
273 .consumer_supplies = rt5025_ldo6_supply,
276 static struct rt5025_power_data rt5025_power_data = {
281 .CCCHG_TIMEOUT = RT5025_CCCHG_TO_10H,
282 .PRECHG_TIMEOUT = RT5025_PRECHG_TO_60M,
293 .AICR = RT5025_AICR_1A,
294 .ICC = RT5025_ICC_1A,
299 .DPM = RT5025_DPM_4P5V,
304 .IPREC = RT5025_IPREC_20P,
305 .IEOC = RT5025_IEOC_10P,
306 .VPREC = RT5025_VPREC_3V,
316 // .fcc = 6200, //6200 mAh
319 static struct rt5025_gpio_data rt5025_gpio_data = {
320 // .gpio_base = RT5025_GPIO_BASE,
321 .irq_base = IRQ_BOARD_BASE,
324 static struct rt5025_misc_data rt5025_misc_data = {
328 .Delayed1 = RT5025_RSTDELAY1_1S,
329 .Delayed2 = RT5025_RSTDELAY2_1S,
334 .VOFF = RT5025_VOFF_3P0V,
339 .PG_DLY = RT5025_PGDLY_100MS,
340 .SHDN_PRESS = RT5025_SHDNPRESS_6S,
341 .LPRESS_TIME = RT5025_LPRESS_1P5S,
342 .START_TIME = RT5025_STARTIME_100MS,
347 .SHDN_DLYTIME = RT5025_SHDNDLY_1S,
364 static struct rt5025_irq_data rt5025_irq_data = {
420 //temp unit: 'c*10 degree
421 static int jeita_temp[4] = { 0, 150, 500, 600};
422 //-5', 5', 15', 20', 45' 55' 55', 65'
423 static u8 jeita_scalar[8] = { 0x30, 0x2B, 0x25, 0x20, 0x15, 0x10, 0x10, 0x0D };
425 static int jeita_temp_cc[][5] = {{ 500, 500, 500, 500, 500}, // not plugin
426 { 0 , 500, 500, 500, 0}, // normal USB
427 { 0, 500, 1000, 500, 0}, // USB charger
428 { 0, 500, 1000, 500, 0}}; // AC Adapter
430 static int jeita_temp_cv[][5] = {{ 4200, 4200, 4200, 4200, 4200}, // not plugin
431 { 4200, 4200, 4200, 4200, 4200}, // normal USB
432 { 4200, 4200, 4200, 4200, 4200}, // USB charger
433 { 4200, 4200, 4200, 4200, 4200}}; // AC Adapter
435 static struct rt5025_jeita_data rt5025_jeita_data = {
437 .temp_scalar = jeita_scalar,
438 .temp_cc = jeita_temp_cc,
439 .temp_cv = jeita_temp_cv,
442 static void rt5025_charger_event_callback(uint32_t detected)
444 RTINFO("charger event detected = 0x%08x\n", detected);
445 if (detected & CHG_EVENT_CHTERMI)
447 pr_info("charger termination OK\n");
451 static void rt5025_power_event_callback(uint32_t detected)
453 RTINFO("power event detected = 0x%08x\n", detected);
456 static struct rt5025_event_callback rt5025_event_callback = {
457 .charger_event_callback = rt5025_charger_event_callback,
458 .power_event_callkback = rt5025_power_event_callback,
461 static struct rt5025_platform_data rt5025_data = {
462 .pre_init=rt5025_pre_init,
463 .post_init=rt5025_post_init,
476 .power_data = &rt5025_power_data,
477 .gpio_data = &rt5025_gpio_data,
478 .misc_data = &rt5025_misc_data,
479 .irq_data = &rt5025_irq_data,
480 .jeita_data = &rt5025_jeita_data,
481 .cb = &rt5025_event_callback,
482 .intr_pin = 81, //GPIO81
485 void __sramfunc board_pmu_rt5025_suspend(void)
488 void __sramfunc board_pmu_rt5025_resume(void)