1 #include <linux/regulator/machine.h>
2 #include <linux/mfd/rk808.h>
4 #include <linux/platform_device.h>
7 #include <mach/iomux.h>
8 #include <mach/board.h>
10 #ifdef CONFIG_MFD_RK808
12 static int rk808_pre_init(struct rk808 *rk808)
15 printk("%s,line=%d\n", __func__,__LINE__);
16 /***********set ILIM ************/
17 val = rk808_reg_read(rk808,RK808_BUCK3_CONFIG_REG);
20 ret = rk808_reg_write(rk808,RK808_BUCK3_CONFIG_REG,val);
22 printk(KERN_ERR "Unable to write RK808_BUCK3_CONFIG_REG reg\n");
26 val = rk808_reg_read(rk808,RK808_BUCK4_CONFIG_REG);
29 ret = rk808_reg_write(rk808,RK808_BUCK4_CONFIG_REG,val);
31 printk(KERN_ERR "Unable to write RK808_BUCK4_CONFIG_REG reg\n");
35 val = rk808_reg_read(rk808,RK808_BOOST_CONFIG_REG);
38 ret = rk808_reg_write(rk808,RK808_BOOST_CONFIG_REG,val);
40 printk(KERN_ERR "Unable to write RK808_BOOST_CONFIG_REG reg\n");
43 /*****************************************/
44 /***********set buck OTP function************/
45 ret = rk808_reg_write(rk808,0x6f,0x5a);
47 printk(KERN_ERR "Unable to write 0x6f reg\n");
51 ret = rk808_reg_write(rk808,0x91,0x80);
53 printk(KERN_ERR "Unable to write 0x91 reg\n");
57 ret = rk808_reg_write(rk808,0x92,0x55);
59 printk(KERN_ERR "Unable to write 0x92 reg\n");
62 /*****************************************/
63 /***********set buck 12.5mv/us ************/
64 val = rk808_reg_read(rk808,RK808_BUCK1_CONFIG_REG);
67 ret = rk808_reg_write(rk808,RK808_BUCK1_CONFIG_REG,val);
69 printk(KERN_ERR "Unable to write RK808_BUCK1_CONFIG_REG reg\n");
73 val = rk808_reg_read(rk808,RK808_BUCK2_CONFIG_REG);
76 ret = rk808_reg_write(rk808,RK808_BUCK2_CONFIG_REG,val);
78 printk(KERN_ERR "Unable to write RK808_BUCK2_CONFIG_REG reg\n");
81 /*****************************************/
83 /*******enable switch and boost***********/
84 val = rk808_reg_read(rk808,RK808_DCDC_EN_REG);
85 val |= (0x3 << 5); //enable switch1/2
86 // val |= (0x1 << 4); //enable boost
87 ret = rk808_reg_write(rk808,RK808_DCDC_EN_REG,val);
89 printk(KERN_ERR "Unable to write RK808_DCDC_EN_REG reg\n");
92 /****************************************/
93 /***********set dc1\2 dvs voltge*********/
94 val = rk808_reg_read(rk808,RK808_BUCK1_DVS_REG);
95 val |= 0x34; //set dc1 dvs 1.35v
96 ret = rk808_reg_write(rk808,RK808_BUCK1_DVS_REG,val);
98 printk(KERN_ERR "Unable to write RK808_BUCK1_DVS_REG reg\n");
102 val = rk808_reg_read(rk808,RK808_BUCK2_DVS_REG);
103 val |= 0x34; //set dc2 dvs 1.35v
104 ret = rk808_reg_write(rk808,RK808_BUCK2_DVS_REG,val);
106 printk(KERN_ERR "Unable to write RK808_BUCK2_DVS_REG reg\n");
109 /***********************************/
111 /****************set vbat low **********/
112 val = rk808_reg_read(rk808,RK808_VB_MON_REG);
113 val &= (~(0x7<<0)); //set vbat < 3.5v irq
117 ret = rk808_reg_write(rk808,RK808_VB_MON_REG,val);
119 printk(KERN_ERR "Unable to write RK808_VB_MON_REG reg\n");
122 /**************************************/
123 /********set dcdc/ldo/switch off when in sleep******/
124 val = rk808_reg_read(rk808,RK808_SLEEP_SET_OFF_REG1);
126 ret = rk808_reg_write(rk808,RK808_SLEEP_SET_OFF_REG1,val);
128 printk(KERN_ERR "Unable to write RK808_SLEEP_SET_OFF_REG1 reg\n");
131 val = rk808_reg_read(rk808,RK808_SLEEP_SET_OFF_REG2);
133 ret = rk808_reg_write(rk808,RK808_SLEEP_SET_OFF_REG2,val);
135 printk(KERN_ERR "Unable to write RK808_SLEEP_SET_OFF_REG2 reg\n");
138 /**************************************************/
139 /**********mask int****************/
140 val = rk808_reg_read(rk808,RK808_INT_STS_MSK_REG1);
141 val |= (0x1<<0); //mask vout_lo_int
142 ret = rk808_reg_write(rk808,RK808_INT_STS_MSK_REG1,val);
144 printk(KERN_ERR "Unable to write RK808_INT_STS_MSK_REG1 reg\n");
147 /**********************************/
148 printk("%s,line=%d\n", __func__,__LINE__);
150 static int rk808_set_init(struct rk808 *rk808)
152 struct regulator *dcdc;
153 struct regulator *ldo;
155 printk("%s,line=%d\n", __func__,__LINE__);
157 #ifndef CONFIG_RK_CONFIG
158 g_pmic_type = PMIC_TYPE_RK808;
160 printk("%s:g_pmic_type=%d\n",__func__,g_pmic_type);
162 for(i = 0; i < ARRAY_SIZE(rk808_dcdc_info); i++)
165 if(rk808_dcdc_info[i].min_uv == 0 && rk808_dcdc_info[i].max_uv == 0)
167 dcdc =regulator_get(NULL, rk808_dcdc_info[i].name);
168 regulator_set_voltage(dcdc, rk808_dcdc_info[i].min_uv, rk808_dcdc_info[i].max_uv);
169 regulator_set_suspend_voltage(dcdc, rk808_dcdc_info[i].suspend_vol);
170 regulator_enable(dcdc);
171 printk("%s %s =%duV end\n", __func__,rk808_dcdc_info[i].name, regulator_get_voltage(dcdc));
176 for(i = 0; i < ARRAY_SIZE(rk808_ldo_info); i++)
178 if(rk808_ldo_info[i].min_uv == 0 && rk808_ldo_info[i].max_uv == 0)
180 ldo =regulator_get(NULL, rk808_ldo_info[i].name);
182 regulator_set_voltage(ldo, rk808_ldo_info[i].min_uv, rk808_ldo_info[i].max_uv);
183 regulator_set_suspend_voltage(ldo, rk808_ldo_info[i].suspend_vol);
184 regulator_enable(ldo);
185 printk("%s %s =%duV end\n", __func__,rk808_ldo_info[i].name, regulator_get_voltage(ldo));
189 #ifdef CONFIG_RK_CONFIG
190 if(sram_gpio_init(get_port_config(pmic_slp).gpio, &pmic_sleep) < 0){
191 printk(KERN_ERR "sram_gpio_init failed\n");
194 if(port_output_init(pmic_slp, 0, "pmic_slp") < 0){
195 printk(KERN_ERR "port_output_init failed\n");
199 if(sram_gpio_init(PMU_POWER_SLEEP, &pmic_sleep) < 0){
200 printk(KERN_ERR "sram_gpio_init failed\n");
203 gpio_request(PMU_POWER_SLEEP, "NULL");
204 gpio_direction_output(PMU_POWER_SLEEP, GPIO_LOW);
208 printk("%s,line=%d END\n", __func__,__LINE__);
214 static struct regulator_consumer_supply rk808_buck1_supply[] = {
216 .supply = "rk_dcdc1",
224 static struct regulator_consumer_supply rk808_buck2_supply[] = {
226 .supply = "rk_dcdc2",
230 .supply = "vdd_core",
234 static struct regulator_consumer_supply rk808_buck3_supply[] = {
236 .supply = "rk_dcdc3",
240 static struct regulator_consumer_supply rk808_buck4_supply[] = {
242 .supply = "rk_dcdc4",
247 static struct regulator_consumer_supply rk808_ldo1_supply[] = {
252 static struct regulator_consumer_supply rk808_ldo2_supply[] = {
258 static struct regulator_consumer_supply rk808_ldo3_supply[] = {
263 static struct regulator_consumer_supply rk808_ldo4_supply[] = {
268 static struct regulator_consumer_supply rk808_ldo5_supply[] = {
273 static struct regulator_consumer_supply rk808_ldo6_supply[] = {
279 static struct regulator_consumer_supply rk808_ldo7_supply[] = {
284 static struct regulator_consumer_supply rk808_ldo8_supply[] = {
290 static struct regulator_init_data rk808_buck1 = {
297 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
298 .valid_modes_mask = REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL,
301 .num_consumer_supplies = ARRAY_SIZE(rk808_buck1_supply),
302 .consumer_supplies = rk808_buck1_supply,
306 static struct regulator_init_data rk808_buck2 = {
313 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
314 .valid_modes_mask = REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL,
317 .num_consumer_supplies = ARRAY_SIZE(rk808_buck2_supply),
318 .consumer_supplies = rk808_buck2_supply,
322 static struct regulator_init_data rk808_buck3 = {
329 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
330 .valid_modes_mask = REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL,
333 .num_consumer_supplies = ARRAY_SIZE(rk808_buck3_supply),
334 .consumer_supplies = rk808_buck3_supply,
337 static struct regulator_init_data rk808_buck4 = {
344 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
345 .valid_modes_mask = REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL,
348 .num_consumer_supplies = ARRAY_SIZE(rk808_buck4_supply),
349 .consumer_supplies = rk808_buck4_supply,
352 static struct regulator_init_data rk808_ldo1 = {
359 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
360 .valid_modes_mask = REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL,
363 .num_consumer_supplies = ARRAY_SIZE(rk808_ldo1_supply),
364 .consumer_supplies = rk808_ldo1_supply,
368 static struct regulator_init_data rk808_ldo2 = {
375 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
376 .valid_modes_mask = REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL,
379 .num_consumer_supplies = ARRAY_SIZE(rk808_ldo2_supply),
380 .consumer_supplies = rk808_ldo2_supply,
384 static struct regulator_init_data rk808_ldo3 = {
391 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
392 .valid_modes_mask = REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL,
395 .num_consumer_supplies = ARRAY_SIZE(rk808_ldo3_supply),
396 .consumer_supplies = rk808_ldo3_supply,
400 static struct regulator_init_data rk808_ldo4 = {
407 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
408 .valid_modes_mask = REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL,
411 .num_consumer_supplies = ARRAY_SIZE(rk808_ldo4_supply),
412 .consumer_supplies = rk808_ldo4_supply,
415 static struct regulator_init_data rk808_ldo5 = {
422 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
423 .valid_modes_mask = REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL,
426 .num_consumer_supplies = ARRAY_SIZE(rk808_ldo5_supply),
427 .consumer_supplies = rk808_ldo5_supply,
430 static struct regulator_init_data rk808_ldo6 = {
437 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
438 .valid_modes_mask = REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL,
441 .num_consumer_supplies = ARRAY_SIZE(rk808_ldo6_supply),
442 .consumer_supplies = rk808_ldo6_supply,
445 static struct regulator_init_data rk808_ldo7 = {
452 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
453 .valid_modes_mask = REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL,
456 .num_consumer_supplies = ARRAY_SIZE(rk808_ldo7_supply),
457 .consumer_supplies = rk808_ldo7_supply,
460 static struct regulator_init_data rk808_ldo8 = {
467 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
468 .valid_modes_mask = REGULATOR_MODE_FAST | REGULATOR_MODE_NORMAL,
471 .num_consumer_supplies = ARRAY_SIZE(rk808_ldo8_supply),
472 .consumer_supplies = rk808_ldo8_supply,
475 struct rk808_regulator_subdev rk808_regulator_subdev_id[] = {
478 .initdata=&rk808_buck1,
483 .initdata=&rk808_buck2,
487 .initdata=&rk808_buck3,
491 .initdata=&rk808_buck4,
496 .initdata=&rk808_ldo1,
501 .initdata=&rk808_ldo2,
506 .initdata=&rk808_ldo3,
511 .initdata=&rk808_ldo4,
516 .initdata=&rk808_ldo5,
521 .initdata=&rk808_ldo6,
526 .initdata=&rk808_ldo7,
531 .initdata=&rk808_ldo8,
535 struct rk808_platform_data rk808_data={
536 .pre_init=rk808_pre_init,
537 .set_init=rk808_set_init,
539 .regulators=rk808_regulator_subdev_id,
540 .irq = (unsigned)RK808_HOST_IRQ,
541 .irq_base = IRQ_BOARD_BASE,
544 #ifdef CONFIG_HAS_EARLYSUSPEND
545 void rk808_early_suspend(struct early_suspend *h)
549 void rk808_late_resume(struct early_suspend *h)
555 void rk808_device_suspend(void)
558 void rk808_device_resume(void)
563 void __sramfunc board_pmu_rk808_suspend(void)
565 #ifdef CONFIG_CLK_SWITCH_TO_32K
566 sram_gpio_set_value(pmic_sleep, GPIO_HIGH);
569 void __sramfunc board_pmu_rk808_resume(void)
571 #ifdef CONFIG_CLK_SWITCH_TO_32K
572 sram_gpio_set_value(pmic_sleep, GPIO_LOW);
573 sram_32k_udelay(1000);