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>
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__);
22 #ifdef CONFIG_RK_CONFIG
23 if(sram_gpio_init(get_port_config(pmic_slp).gpio, &pmic_sleep) < 0){
24 printk(KERN_ERR "sram_gpio_init failed\n");
27 if(port_output_init(pmic_slp, 0, "pmic_slp") < 0){
28 printk(KERN_ERR "port_output_init failed\n");
32 if(sram_gpio_init(PMU_POWER_SLEEP, &pmic_sleep) < 0){
33 printk(KERN_ERR "sram_gpio_init failed\n");
37 gpio_request(PMU_POWER_SLEEP, "NULL");
38 gpio_direction_output(PMU_POWER_SLEEP, GPIO_LOW);
42 /*************set vdd11 (pll) voltage 1.0v********************/
43 val = tps65910_reg_read(tps65910, TPS65910_VDIG2);
45 printk(KERN_ERR "Unable to read TPS65910_VDIG2 reg\n");
49 err = tps65910_reg_write(tps65910, TPS65910_VDIG2, val);
51 printk(KERN_ERR "Unable to write TPS65910_VDIG2 reg\n");
54 /****************************************/
56 val = tps65910_reg_read(tps65910, TPS65910_DEVCTRL2);
58 printk(KERN_ERR "Unable to read TPS65910_DEVCTRL2 reg\n");
61 /* Set sleep state active high and allow device turn-off after PWRON long press */
62 val |= (DEVCTRL2_SLEEPSIG_POL_MASK | DEVCTRL2_PWON_LP_OFF_MASK);
64 err = tps65910_reg_write(tps65910, TPS65910_DEVCTRL2, val);
66 printk(KERN_ERR "Unable to write TPS65910_DEVCTRL2 reg\n");
72 val = tps65910_reg_read(tps65910, TPS65910_DCDCCTRL);
74 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
78 val &= ~DEVCTRL_DEV_OFF_MASK;
79 val &= ~DEVCTRL_DEV_SLP_MASK;
80 err = tps65910_reg_write(tps65910, TPS65910_DCDCCTRL, val);
82 printk(KERN_ERR "Unable to write TPS65910_DCDCCTRL reg\n");
86 /* Set the maxinum load current */
88 val = tps65910_reg_read(tps65910, TPS65910_VDD1);
90 printk(KERN_ERR "Unable to read TPS65910_VDD1 reg\n");
94 val |= (1<<5); //when 1: 1.5 A
96 val |= (0x01<<2); //TSTEP[3:2] = 01 : 12.5 mV/us(sampling 3 Mhz)
97 err = tps65910_reg_write(tps65910, TPS65910_VDD1, val);
99 printk(KERN_ERR "Unable to write TPS65910_VDD1 reg\n");
104 val = tps65910_reg_read(tps65910, TPS65910_VDD2);
106 printk(KERN_ERR "Unable to read TPS65910_VDD2 reg\n");
110 val |= (1<<5); //when 1: 1.5 A
112 val |= (0x01<<2); //TSTEP[3:2] = 01 : 12.5 mV/us(sampling 3 Mhz)
113 err = tps65910_reg_write(tps65910, TPS65910_VDD2, val);
115 printk(KERN_ERR "Unable to write TPS65910_VDD2 reg\n");
120 val = tps65910_reg_read(tps65910, TPS65910_VIO);
122 printk(KERN_ERR "Unable to read TPS65910_VIO reg\n");
126 val |= (1<<6); //when 01: 1.0 A
127 err = tps65910_reg_write(tps65910, TPS65910_VIO, val);
129 printk(KERN_ERR "Unable to write TPS65910_VIO reg\n");
133 /* Mask ALL interrupts */
134 err = tps65910_reg_write(tps65910,TPS65910_INT_MSK, 0xFF);
136 printk(KERN_ERR "Unable to write TPS65910_INT_MSK reg\n");
140 err = tps65910_reg_write(tps65910, TPS65910_INT_MSK2, 0x03);
142 printk(KERN_ERR "Unable to write TPS65910_INT_MSK2 reg\n");
146 /* Set RTC Power, disable Smart Reflex in DEVCTRL_REG */
149 val |= (DEVCTRL_SR_CTL_I2C_SEL_MASK);
150 err = tps65910_reg_write(tps65910, TPS65910_DEVCTRL, val);
152 printk(KERN_ERR "Unable to write TPS65910_DEVCTRL reg\n");
155 printk(KERN_INFO "TPS65910 Set default voltage.\n");
158 //read sleep control register for debug
161 err = tps65910_reg_read(tps65910, &val, TPS65910_DEVCTRL+i);
163 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
167 printk("%s.......is 0x%04x\n",__FUNCTION__,val);
172 //sleep control register
173 /*set func when in sleep mode */
174 val = tps65910_reg_read(tps65910, TPS65910_DEVCTRL);
176 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
181 err = tps65910_reg_write(tps65910, TPS65910_DEVCTRL, val);
183 printk(KERN_ERR "Unable to read TPS65910 Reg at offset 0x%x= \
184 \n", TPS65910_VDIG1);
188 /* open ldo when in sleep mode */
189 val = tps65910_reg_read(tps65910, TPS65910_SLEEP_KEEP_LDO_ON);
191 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
196 err = tps65910_reg_write(tps65910, TPS65910_SLEEP_KEEP_LDO_ON, val);
198 printk(KERN_ERR "Unable to read TPS65910 Reg at offset 0x%x= \
199 \n", TPS65910_VDIG1);
203 /*set dc mode when in sleep mode */
204 val = tps65910_reg_read(tps65910, TPS65910_SLEEP_KEEP_RES_ON);
206 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
211 val &= ~(0x07); //set vdd1 vdd2 vio in pfm mode when in sleep
212 err = tps65910_reg_write(tps65910, TPS65910_SLEEP_KEEP_RES_ON, val);
214 printk(KERN_ERR "Unable to read TPS65910 Reg at offset 0x%x= \
215 \n", TPS65910_VDIG1);
219 /*close ldo when in sleep mode */
220 val = tps65910_reg_read(tps65910, TPS65910_SLEEP_SET_LDO_OFF);
222 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
227 err = tps65910_reg_write(tps65910, TPS65910_SLEEP_SET_LDO_OFF, val);
229 printk(KERN_ERR "Unable to read TPS65910 Reg at offset 0x%x= \
230 \n", TPS65910_VDIG1);
235 //read sleep control register for debug
238 err = tps65910_reg_read(tps65910, &val, TPS65910_DEVCTRL+i);
240 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
244 printk("%s.......is 0x%4x\n",__FUNCTION__,val);
249 /*****************set arm and logic (dc1&dc2)in pwm ****************/
250 val = tps65910_reg_read(tps65910, TPS65910_DCDCCTRL);
252 printk(KERN_ERR "Unable to read TPS65910_DCDCCTRL reg\n");
257 err = tps65910_reg_write(tps65910, TPS65910_DCDCCTRL, val);
259 printk(KERN_ERR "Unable to read TPS65910 Reg at offset 0x%x= \
260 \n", TPS65910_VDIG1);
263 /************************************************/
265 printk("%s,line=%d\n", __func__,__LINE__);
269 int tps65910_post_init(struct tps65910 *tps65910)
271 struct regulator *dcdc;
272 struct regulator *ldo;
274 printk("%s,line=%d\n", __func__,__LINE__);
276 g_pmic_type = PMIC_TYPE_TPS65910;
277 printk("%s:g_pmic_type=%d\n",__func__,g_pmic_type);
279 #ifdef CONFIG_RK30_PWM_REGULATOR
280 platform_device_register(&pwm_regulator_device[0]);
283 for(i = 0; i < ARRAY_SIZE(tps65910_dcdc_info); i++)
285 dcdc =regulator_get(NULL, tps65910_dcdc_info[i].name);
286 regulator_set_voltage(dcdc, tps65910_dcdc_info[i].min_uv, tps65910_dcdc_info[i].max_uv);
287 regulator_enable(dcdc);
288 printk("%s %s =%dmV end\n", __func__,tps65910_dcdc_info[i].name, regulator_get_voltage(dcdc));
293 for(i = 0; i < ARRAY_SIZE(tps65910_ldo_info); i++)
295 ldo =regulator_get(NULL, tps65910_ldo_info[i].name);
296 regulator_set_voltage(ldo, tps65910_ldo_info[i].min_uv, tps65910_ldo_info[i].max_uv);
297 regulator_enable(ldo);
298 //printk("%s %s =%dmV end\n", __func__,tps65910_dcdc_info[i].name, regulator_get_voltage(ldo));
302 printk("%s,line=%d END\n", __func__,__LINE__);
307 static struct regulator_consumer_supply tps65910_smps1_supply[] = {
311 #if defined(CONFIG_SOC_RK3168) || defined(CONFIG_ARCH_RK3188)
313 .supply = "vdd_core",
321 static struct regulator_consumer_supply tps65910_smps2_supply[] = {
325 #if defined(CONFIG_MACH_RK3168_86V)
331 static struct regulator_consumer_supply tps65910_smps3_supply[] = {
336 static struct regulator_consumer_supply tps65910_smps4_supply[] = {
341 static struct regulator_consumer_supply tps65910_ldo1_supply[] = {
346 static struct regulator_consumer_supply tps65910_ldo2_supply[] = {
352 static struct regulator_consumer_supply tps65910_ldo3_supply[] = {
357 static struct regulator_consumer_supply tps65910_ldo4_supply[] = {
362 static struct regulator_consumer_supply tps65910_ldo5_supply[] = {
367 static struct regulator_consumer_supply tps65910_ldo6_supply[] = {
372 static struct regulator_consumer_supply tps65910_ldo7_supply[] = {
378 static struct regulator_consumer_supply tps65910_ldo8_supply[] = {
384 static struct regulator_init_data tps65910_smps1 = {
391 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
392 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
395 .num_consumer_supplies = ARRAY_SIZE(tps65910_smps1_supply),
396 .consumer_supplies = tps65910_smps1_supply,
400 static struct regulator_init_data tps65910_smps2 = {
407 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
408 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
411 .num_consumer_supplies = ARRAY_SIZE(tps65910_smps2_supply),
412 .consumer_supplies = tps65910_smps2_supply,
416 static struct regulator_init_data tps65910_smps3 = {
423 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
424 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
427 .num_consumer_supplies = ARRAY_SIZE(tps65910_smps3_supply),
428 .consumer_supplies = tps65910_smps3_supply,
431 static struct regulator_init_data tps65910_smps4 = {
438 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
439 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
442 .num_consumer_supplies = ARRAY_SIZE(tps65910_smps4_supply),
443 .consumer_supplies = tps65910_smps4_supply,
445 static struct regulator_init_data tps65910_ldo1 = {
452 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
453 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
456 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo1_supply),
457 .consumer_supplies = tps65910_ldo1_supply,
461 static struct regulator_init_data tps65910_ldo2 = {
468 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
469 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
472 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo2_supply),
473 .consumer_supplies = tps65910_ldo2_supply,
477 static struct regulator_init_data tps65910_ldo3 = {
484 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
485 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
488 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo3_supply),
489 .consumer_supplies = tps65910_ldo3_supply,
493 static struct regulator_init_data tps65910_ldo4 = {
500 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
501 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
504 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo4_supply),
505 .consumer_supplies = tps65910_ldo4_supply,
509 static struct regulator_init_data tps65910_ldo5 = {
516 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
517 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
520 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo5_supply),
521 .consumer_supplies = tps65910_ldo5_supply,
525 static struct regulator_init_data tps65910_ldo6 = {
532 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
533 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
536 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo6_supply),
537 .consumer_supplies = tps65910_ldo6_supply,
541 static struct regulator_init_data tps65910_ldo7 = {
548 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
549 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
552 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo7_supply),
553 .consumer_supplies = tps65910_ldo7_supply,
557 static struct regulator_init_data tps65910_ldo8 = {
564 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
565 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
568 .num_consumer_supplies = ARRAY_SIZE(tps65910_ldo8_supply),
569 .consumer_supplies = tps65910_ldo8_supply,
572 void __sramfunc board_pmu_tps65910_suspend(void)
574 #ifdef CONFIG_CLK_SWITCH_TO_32K
575 sram_gpio_set_value(pmic_sleep, GPIO_HIGH);
578 void __sramfunc board_pmu_tps65910_resume(void)
580 #ifdef CONFIG_CLK_SWITCH_TO_32K
581 sram_gpio_set_value(pmic_sleep, GPIO_LOW);
582 sram_32k_udelay(2000);
585 static struct tps65910_board tps65910_data = {
586 .irq = (unsigned)TPS65910_HOST_IRQ,
587 .irq_base = IRQ_BOARD_BASE,
588 .gpio_base = TPS65910_GPIO_EXPANDER_BASE,
590 .pre_init = tps65910_pre_init,
591 .post_init = tps65910_post_init,
593 //TPS65910_NUM_REGS = 13
595 .tps65910_pmic_init_data[TPS65910_REG_VRTC] = NULL,
596 .tps65910_pmic_init_data[TPS65910_REG_VIO] = &tps65910_smps4,
597 .tps65910_pmic_init_data[TPS65910_REG_VDD1] = &tps65910_smps1,
598 .tps65910_pmic_init_data[TPS65910_REG_VDD2] = &tps65910_smps2,
599 .tps65910_pmic_init_data[TPS65910_REG_VDD3] = &tps65910_smps3,
600 .tps65910_pmic_init_data[TPS65910_REG_VDIG1] = &tps65910_ldo1,
601 .tps65910_pmic_init_data[TPS65910_REG_VDIG2] = &tps65910_ldo2,
602 .tps65910_pmic_init_data[TPS65910_REG_VPLL] = &tps65910_ldo8,
603 .tps65910_pmic_init_data[TPS65910_REG_VDAC] = &tps65910_ldo7,
604 .tps65910_pmic_init_data[TPS65910_REG_VAUX1] = &tps65910_ldo3,
605 .tps65910_pmic_init_data[TPS65910_REG_VAUX2] = &tps65910_ldo4,
606 .tps65910_pmic_init_data[TPS65910_REG_VAUX33] = &tps65910_ldo5,
607 .tps65910_pmic_init_data[TPS65910_REG_VMMC] = &tps65910_ldo6,