1 #include <linux/regulator/machine.h>
2 #include <linux/i2c/twl.h>
3 #include <linux/mfd/tps65910.h>
5 #include <linux/platform_device.h>
8 #include <mach/iomux.h>
9 #define PMU_POWER_SLEEP RK2928_PIN1_PA1
10 #ifdef CONFIG_MFD_TPS65910
12 extern int platform_device_register(struct platform_device *pdev);
14 int tps65910_pre_init(struct tps65910 *tps65910){
20 printk("%s,line=%d\n", __func__,__LINE__);
21 #ifdef CONFIG_RK_CONFIG
22 if(sram_gpio_init(get_port_config(pmic_slp).gpio, &pmic_sleep) < 0){
23 printk(KERN_ERR "sram_gpio_init failed\n");
26 if(port_output_init(pmic_slp, 0, "pmic_slp") < 0){
27 printk(KERN_ERR "port_output_init failed\n");
31 if(sram_gpio_init(PMU_POWER_SLEEP, &pmic_sleep) < 0){
32 printk(KERN_ERR "sram_gpio_init failed\n");
35 // GPIO1A1_I2S_SCLK_NAME
36 rk30_mux_api_set(GPIO1A1_I2S_SCLK_NAME, 0);
38 gpio_request(PMU_POWER_SLEEP, "NULL");
39 gpio_direction_output(PMU_POWER_SLEEP, GPIO_LOW);
42 val = tps65910_reg_read(tps65910, TPS65910_DEVCTRL2);
44 printk(KERN_ERR "Unable to read TPS65910_DEVCTRL2 reg\n");
47 /* Set sleep state active high and allow device turn-off after PWRON long press */
48 val |= (DEVCTRL2_SLEEPSIG_POL_MASK | DEVCTRL2_PWON_LP_OFF_MASK);
50 err = tps65910_reg_write(tps65910, TPS65910_DEVCTRL2, val);
52 printk(KERN_ERR "Unable to write TPS65910_DEVCTRL2 reg\n");
57 val = tps65910_reg_read(tps65910, TPS65910_DCDCCTRL);
59 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
63 val &= ~DEVCTRL_DEV_OFF_MASK;
64 val &= ~DEVCTRL_DEV_SLP_MASK;
65 err = tps65910_reg_write(tps65910, TPS65910_DCDCCTRL, val);
67 printk(KERN_ERR "Unable to write TPS65910_DCDCCTRL reg\n");
71 /* Set the maxinum load current */
73 val = tps65910_reg_read(tps65910, TPS65910_VDD1);
75 printk(KERN_ERR "Unable to read TPS65910_VDD1 reg\n");
79 val |= (1<<5); //when 1: 1.5 A
80 val |= (0x07<<2); //TSTEP[2:0] = 111 : 2.5 mV/|¨¬s(sampling 3 Mhz/5)
81 err = tps65910_reg_write(tps65910, TPS65910_VDD1, val);
83 printk(KERN_ERR "Unable to write TPS65910_VDD1 reg\n");
88 val = tps65910_reg_read(tps65910, TPS65910_VDD2);
90 printk(KERN_ERR "Unable to read TPS65910_VDD2 reg\n");
94 val |= (1<<5); //when 1: 1.5 A
95 err = tps65910_reg_write(tps65910, TPS65910_VDD2, val);
97 printk(KERN_ERR "Unable to write TPS65910_VDD2 reg\n");
102 val = tps65910_reg_read(tps65910, TPS65910_VIO);
104 printk(KERN_ERR "Unable to read TPS65910_VIO reg\n");
108 val |= (1<<6); //when 01: 1.0 A
109 err = tps65910_reg_write(tps65910, TPS65910_VIO, val);
111 printk(KERN_ERR "Unable to write TPS65910_VIO reg\n");
115 /* Mask ALL interrupts */
116 err = tps65910_reg_write(tps65910,TPS65910_INT_MSK, 0xFF);
118 printk(KERN_ERR "Unable to write TPS65910_INT_MSK reg\n");
122 err = tps65910_reg_write(tps65910, TPS65910_INT_MSK2, 0x03);
124 printk(KERN_ERR "Unable to write TPS65910_INT_MSK2 reg\n");
128 /* Set RTC Power, disable Smart Reflex in DEVCTRL_REG */
131 val |= (DEVCTRL_SR_CTL_I2C_SEL_MASK);
132 err = tps65910_reg_write(tps65910, TPS65910_DEVCTRL, val);
134 printk(KERN_ERR "Unable to write TPS65910_DEVCTRL reg\n");
137 printk(KERN_INFO "TPS65910 Set default voltage.\n");
140 //read sleep control register for debug
143 err = tps65910_reg_read(tps65910, &val, TPS65910_DEVCTRL+i);
145 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
149 printk("%s.......is 0x%04x\n",__FUNCTION__,val);
154 //sleep control register
155 /*set func when in sleep mode */
156 val = tps65910_reg_read(tps65910, TPS65910_DEVCTRL);
158 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
163 err = tps65910_reg_write(tps65910, TPS65910_DEVCTRL, val);
165 printk(KERN_ERR "Unable to read TPS65910 Reg at offset 0x%x= \
166 \n", TPS65910_VDIG1);
170 /* open ldo when in sleep mode */
171 val = tps65910_reg_read(tps65910, TPS65910_SLEEP_KEEP_LDO_ON);
173 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
178 err = tps65910_reg_write(tps65910, TPS65910_SLEEP_KEEP_LDO_ON, val);
180 printk(KERN_ERR "Unable to read TPS65910 Reg at offset 0x%x= \
181 \n", TPS65910_VDIG1);
185 /*set dc mode when in sleep mode */
186 val = tps65910_reg_read(tps65910, TPS65910_SLEEP_KEEP_RES_ON);
188 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
193 err = tps65910_reg_write(tps65910, TPS65910_SLEEP_KEEP_RES_ON, val);
195 printk(KERN_ERR "Unable to read TPS65910 Reg at offset 0x%x= \
196 \n", TPS65910_VDIG1);
200 /*close ldo when in sleep mode */
201 val = tps65910_reg_read(tps65910, TPS65910_SLEEP_SET_LDO_OFF);
203 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
209 err = tps65910_reg_write(tps65910, TPS65910_SLEEP_SET_LDO_OFF, val);
211 printk(KERN_ERR "Unable to read TPS65910 Reg at offset 0x%x= \
212 \n", TPS65910_VDIG1);
218 //read sleep control register for debug
221 err = tps65910_reg_read(tps65910, &val, TPS65910_DEVCTRL+i);
223 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
227 printk("%s.......is 0x%4x\n",__FUNCTION__,val);
232 printk("%s,line=%d\n", __func__,__LINE__);
238 int tps65910_post_init(struct tps65910 *tps65910)
240 struct regulator *dcdc;
241 struct regulator *ldo;
243 printk("%s,line=%d\n", __func__,__LINE__);
245 #ifndef CONFIG_RK_CONFIG
246 g_pmic_type = PMIC_TYPE_TPS65910;
248 printk("%s:g_pmic_type=%d\n",__func__,g_pmic_type);
250 #ifdef CONFIG_RK30_PWM_REGULATOR
251 platform_device_register(&pwm_regulator_device[0]);
254 dcdc = regulator_get(NULL, "vio"); //vcc_io
255 regulator_set_voltage(dcdc, 3300000, 3300000);
256 regulator_enable(dcdc);
257 printk("%s set vio vcc_io=%dmV end\n", __func__, regulator_get_voltage(dcdc));
260 #if defined(CONFIG_MACH_RK2928_TB) || defined(CONFIG_MACH_RK2926_TB) || defined(CONFIG_MACH_RK2926_V86)
261 ldo = regulator_get(NULL, "vpll"); // vcc25
262 regulator_set_voltage(ldo, 2500000, 2500000);
263 regulator_enable(ldo);
264 printk("%s set vpll vcc25=%dmV end\n", __func__, regulator_get_voltage(ldo));
268 ldo = regulator_get(NULL, "vdig2"); // vdd12
269 regulator_set_voltage(ldo, 1200000, 1200000);
270 regulator_enable(ldo);
271 printk("%s set vdig2 vdd12=%dmV end\n", __func__, regulator_get_voltage(ldo));
275 ldo = regulator_get(NULL, "vaux33"); //vcc_tp
276 regulator_set_voltage(ldo, 3300000, 3300000);
277 regulator_enable(ldo);
278 printk("%s set vaux33 vcc_tp=%dmV end\n", __func__, regulator_get_voltage(ldo));
282 dcdc = regulator_get(NULL, "vdd_cpu"); //vdd_cpu
283 regulator_set_voltage(dcdc, 1200000, 1200000);
284 regulator_enable(dcdc);
285 printk("%s set vdd1 vdd_cpu=%dmV end\n", __func__, regulator_get_voltage(dcdc));
289 dcdc = regulator_get(NULL, "vdd2"); //vcc_ddr
290 regulator_set_voltage(dcdc, 1200000, 1200000); // 1.5*4/5 = 1.2 and Vout=1.5v
291 regulator_enable(dcdc);
292 printk("%s set vdd2 vcc_ddr=%dmV end\n", __func__, regulator_get_voltage(dcdc));
296 ldo = regulator_get(NULL, "vdig1"); //vcc18_cif
297 regulator_set_voltage(ldo, 1800000, 1800000);
298 regulator_enable(ldo);
299 printk("%s set vdig1 vcc18_cif=%dmV end\n", __func__, regulator_get_voltage(ldo));
303 dcdc = regulator_get(NULL, "vaux1"); //vcc28_cif
304 regulator_set_voltage(dcdc,2800000,2800000);
305 regulator_enable(dcdc);
306 printk("%s set vaux1 vcc28_cif=%dmV end\n", __func__, regulator_get_voltage(dcdc));
310 ldo = regulator_get(NULL, "vaux2"); //vcca33
311 regulator_set_voltage(ldo, 3300000, 3300000);
312 regulator_enable(ldo);
313 printk("%s set vaux2 vcca33=%dmV end\n", __func__, regulator_get_voltage(ldo));
316 #if defined(CONFIG_MACH_RK2928_TB) || defined(CONFIG_MACH_RK2926_TB)
317 ldo = regulator_get(NULL, "vdac"); // vccio_wl
318 regulator_set_voltage(ldo,1800000,1800000);
319 regulator_enable(ldo);
320 printk("%s set vdac vccio_wl=%dmV end\n", __func__, regulator_get_voltage(ldo));
324 ldo = regulator_get(NULL, "vmmc"); //vccio_wl
325 regulator_set_voltage(ldo,3300000,3300000);
326 regulator_enable(ldo);
327 printk("%s set vmmc vccio_wl=%dmV end\n", __func__, regulator_get_voltage(ldo));
328 #if defined(CONFIG_MACH_RK2928_TB) || defined(CONFIG_MACH_RK2926_TB) || defined(CONFIG_MACH_RK2926_V86) || defined(CONFIG_MACH_RK2928_PHONEPAD_760)
329 //do not disable vccio wl
331 regulator_disable(ldo); //for i30 sdcard used vcc_io so must close
336 printk("%s,line=%d END\n", __func__,__LINE__);
340 static struct regulator_consumer_supply tps65910_smps1_supply[] = {
348 static struct regulator_consumer_supply tps65910_smps2_supply[] = {
353 .supply = "vdd_core",
357 static struct regulator_consumer_supply tps65910_smps3_supply[] = {
362 static struct regulator_consumer_supply tps65910_smps4_supply[] = {
367 static struct regulator_consumer_supply tps65910_ldo1_supply[] = {
372 static struct regulator_consumer_supply tps65910_ldo2_supply[] = {
378 static struct regulator_consumer_supply tps65910_ldo3_supply[] = {
383 static struct regulator_consumer_supply tps65910_ldo4_supply[] = {
388 static struct regulator_consumer_supply tps65910_ldo5_supply[] = {
393 static struct regulator_consumer_supply tps65910_ldo6_supply[] = {
398 static struct regulator_consumer_supply tps65910_ldo7_supply[] = {
404 static struct regulator_consumer_supply tps65910_ldo8_supply[] = {
410 static struct regulator_init_data tps65910_smps1 = {
417 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
418 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
421 .num_consumer_supplies = ARRAY_SIZE(tps65910_smps1_supply),
422 .consumer_supplies = tps65910_smps1_supply,
426 static struct regulator_init_data tps65910_smps2 = {
433 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
434 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
437 .num_consumer_supplies = ARRAY_SIZE(tps65910_smps2_supply),
438 .consumer_supplies = tps65910_smps2_supply,
442 static struct regulator_init_data tps65910_smps3 = {
449 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
450 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
453 .num_consumer_supplies = ARRAY_SIZE(tps65910_smps3_supply),
454 .consumer_supplies = tps65910_smps3_supply,
457 static struct regulator_init_data tps65910_smps4 = {
464 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
465 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
468 .num_consumer_supplies = ARRAY_SIZE(tps65910_smps4_supply),
469 .consumer_supplies = tps65910_smps4_supply,
471 static struct regulator_init_data tps65910_ldo1 = {
478 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
479 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
482 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo1_supply),
483 .consumer_supplies = tps65910_ldo1_supply,
487 static struct regulator_init_data tps65910_ldo2 = {
494 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
495 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
498 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo2_supply),
499 .consumer_supplies = tps65910_ldo2_supply,
503 static struct regulator_init_data tps65910_ldo3 = {
510 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
511 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
514 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo3_supply),
515 .consumer_supplies = tps65910_ldo3_supply,
519 static struct regulator_init_data tps65910_ldo4 = {
526 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
527 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
530 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo4_supply),
531 .consumer_supplies = tps65910_ldo4_supply,
535 static struct regulator_init_data tps65910_ldo5 = {
542 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
543 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
546 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo5_supply),
547 .consumer_supplies = tps65910_ldo5_supply,
551 static struct regulator_init_data tps65910_ldo6 = {
558 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
559 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
562 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo6_supply),
563 .consumer_supplies = tps65910_ldo6_supply,
567 static struct regulator_init_data tps65910_ldo7 = {
574 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
575 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
578 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo7_supply),
579 .consumer_supplies = tps65910_ldo7_supply,
583 static struct regulator_init_data tps65910_ldo8 = {
589 #if defined(CONFIG_MACH_RK2926_V86)
593 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
594 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
597 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo8_supply),
598 .consumer_supplies = tps65910_ldo8_supply,
600 void __sramfunc board_pmu_tps65910_suspend(void)
603 sram_gpio_set_value(pmic_sleep, GPIO_HIGH);
605 void __sramfunc board_pmu_tps65910_resume(void)
607 sram_gpio_set_value(pmic_sleep, GPIO_LOW);
610 static struct tps65910_board tps65910_data = {
611 .irq = (unsigned)TPS65910_HOST_IRQ,
612 .irq_base = IRQ_BOARD_BASE,
613 .gpio_base = TPS65910_GPIO_EXPANDER_BASE,
615 .pre_init = tps65910_pre_init,
616 .post_init = tps65910_post_init,
618 //TPS65910_NUM_REGS = 13
620 .tps65910_pmic_init_data[TPS65910_REG_VRTC] = NULL,
621 .tps65910_pmic_init_data[TPS65910_REG_VIO] = &tps65910_smps4,
622 .tps65910_pmic_init_data[TPS65910_REG_VDD1] = &tps65910_smps1,
623 .tps65910_pmic_init_data[TPS65910_REG_VDD2] = &tps65910_smps2,
624 .tps65910_pmic_init_data[TPS65910_REG_VDD3] = &tps65910_smps3,
625 .tps65910_pmic_init_data[TPS65910_REG_VDIG1] = &tps65910_ldo1,
626 .tps65910_pmic_init_data[TPS65910_REG_VDIG2] = &tps65910_ldo2,
627 .tps65910_pmic_init_data[TPS65910_REG_VPLL] = &tps65910_ldo8,
628 .tps65910_pmic_init_data[TPS65910_REG_VDAC] = &tps65910_ldo7,
629 .tps65910_pmic_init_data[TPS65910_REG_VAUX1] = &tps65910_ldo3,
630 .tps65910_pmic_init_data[TPS65910_REG_VAUX2] = &tps65910_ldo4,
631 .tps65910_pmic_init_data[TPS65910_REG_VAUX33] = &tps65910_ldo5,
632 .tps65910_pmic_init_data[TPS65910_REG_VMMC] = &tps65910_ldo6,