ARM64: DTS: Add rk3399-firefly uart4 device, node as /dev/ttyS1
[firefly-linux-kernel-4.4.55.git] / board-rk30-phone-twl60xx.c
1 #include <linux/regulator/machine.h>
2 #include <linux/i2c/twl.h>
3
4 #include <mach/sram.h>
5
6 #define grf_readl(offset)       readl_relaxed(RK30_GRF_BASE + offset)
7 #define grf_writel(v, offset)   do { writel_relaxed(v, RK30_GRF_BASE + offset); dsb(); } while (0)
8
9 #define CRU_CLKGATE5_CON_ADDR 0x00e4
10 #define GRF_GPIO6L_DIR_ADDR 0x0030
11 #define GRF_GPIO6L_DO_ADDR 0x0068
12 #define GRF_GPIO6L_EN_ADDR 0x00a0
13 #define GPIO6_PB3_DIR_OUT  0x08000800
14 #define GPIO6_PB3_DO_LOW  0x08000000
15 #define GPIO6_PB3_DO_HIGH  0x08000800
16 #define GPIO6_PB3_EN_MASK  0x08000800
17 #define GPIO6_PB3_UNEN_MASK  0x08000000
18 #define GPIO6_PB1_DIR_OUT  0x02000200
19 #define GPIO6_PB1_DO_LOW  0x02000000
20 #define GPIO6_PB1_DO_HIGH  0x02000200
21 #define GPIO6_PB1_EN_MASK  0x02000200
22 #define GPIO6_PB1_UNEN_MASK  0x02000000
23
24 #define TWL60xx_IRQ_BASE        IRQ_BOARD_BASE
25 #ifdef CONFIG_TWL4030_CORE
26 #define TWL60xx_BASE_NR_IRQS    24
27 #else
28 #define TWL60xx_BASE_NR_IRQS    0
29 #endif
30 #define TWL60xx_IRQ_END         (TWL60xx_IRQ_BASE + TWL60xx_BASE_NR_IRQS)
31
32 #ifdef CONFIG_TWL4030_CORE
33
34 static inline int twl_reg_read(unsigned base, unsigned slave_subgp)
35 {
36         u8 value;
37         int status;
38         status = twl_i2c_read_u8(slave_subgp,&value, base);
39         return (status < 0) ? status : value;
40 }
41
42
43 static inline int twl_reg_write(unsigned base, unsigned slave_subgp,
44                                                  u8 value)
45 {
46         return twl_i2c_write_u8(slave_subgp,value, base);
47 }
48
49 #define PMU_POWER_SLEEP RK30_PIN6_PB3   
50 #define PMU_CHRG_DET_N RK30_PIN0_PC7
51 int tps80032_pre_init(void){
52         
53         printk("%s\n", __func__);       
54
55         gpio_request(PMU_POWER_SLEEP, "NULL");
56         gpio_direction_output(PMU_POWER_SLEEP, GPIO_LOW);
57         
58         gpio_request(PMU_CHRG_DET_N, "NULL");
59         gpio_direction_output(PMU_CHRG_DET_N, GPIO_HIGH);
60
61         twl_reg_write(0x0e,TWL_MODULE_PM_MASTER,0x5f);
62         twl_reg_write(PREQ1_RES_ASS_A,TWL_MODULE_PM_SLAVE_RES,0x2b);
63         twl_reg_write(PREQ1_RES_ASS_B,TWL_MODULE_PM_SLAVE_RES,0x50);
64         twl_reg_write(PREQ1_RES_ASS_C,TWL_MODULE_PM_SLAVE_RES,0x27);
65         twl_reg_write(PHOENIX_MSK_TRANSITION,TWL_MODULE_PM_MASTER,0x00);
66         twl_reg_write(PHOENIX_SENS_TRANSITION,TWL_MODULE_PM_MASTER,0xc0);   //set pmu enter sleep on a preq1 rising edge
67         
68         twl_reg_write(SMPS1_CFG_STATE,TWL_MODULE_PM_RECEIVER,0x01);   //set state
69         twl_reg_write(SMPS2_CFG_STATE,TWL_MODULE_PM_RECEIVER,0x01);
70         twl_reg_write(LDO7_CFG_STATE,TWL_MODULE_PM_RECEIVER,0x01);
71
72         twl_reg_write(CLK32KG_CFG_STATE,TWL_MODULE_PM_SLAVE_RES,0x01);  //set clk32kg on when we use
73         twl_reg_write(CLK32KAUDIO_CFG_STATE,TWL_MODULE_PM_SLAVE_RES,0x01);  //set clk32kaudio on when we use
74
75         twl_reg_write(CHARGERUSB_CTRLLIMIT2,TWL6030_MODULE_CHARGER, 0x0f);
76         twl_reg_write(CHARGERUSB_CTRLLIMIT2,TWL6030_MODULE_CHARGER, 0x1f);
77
78         twl_reg_write(0x05,TWL_MODULE_PM_MASTER,0x1d);   //set vlow wakeup voltage 3.45v
79         
80         twl_reg_write(LDO5_CFG_TRANS,TWL_MODULE_PM_RECEIVER,0x03);   //set ldo5 is disabled when in sleep mode 
81         twl_reg_write(LDO7_CFG_TRANS,TWL_MODULE_PM_RECEIVER,0x03);   //set ldo7 is disabled when in sleep mode
82         twl_reg_write(LDOUSB_CFG_TRANS,TWL_MODULE_PM_RECEIVER,0x03); 
83         return 0;
84
85 }
86 int tps80032_set_init(void)
87 {
88         struct regulator *dcdc;
89         struct regulator *ldo;
90         printk("%s\n", __func__);
91         
92         ldo = regulator_get(NULL, "ldo1");      //vcca_33
93         regulator_set_voltage(ldo, 3300000, 3300000);
94         regulator_enable(ldo);
95 //      printk("%s set ldo1 vcca_33=%dmV end\n", __func__, regulator_get_voltage(ldo));
96         regulator_put(ldo);
97         udelay(100);
98         
99         ldo = regulator_get(NULL, "ldo4");      // vdd_11
100         regulator_set_voltage(ldo, 1100000, 1100000);
101         regulator_enable(ldo);
102 //      printk("%s set ldo4 vdd_11=%dmV end\n", __func__, regulator_get_voltage(ldo));
103         regulator_put(ldo);
104         udelay(100);
105
106         dcdc = regulator_get(NULL, "vcc_io");
107         regulator_set_voltage(dcdc,3000000,3000000);
108         regulator_enable(dcdc); 
109 //      printk("%s set dcdc4 vcc_io=%dmV end\n", __func__, regulator_get_voltage(dcdc));
110         regulator_put(dcdc);
111         udelay(100);
112
113         ldo = regulator_get(NULL, "ldo2");      // vdd_usb11
114         regulator_set_voltage(ldo, 1100000, 1100000);
115         regulator_enable(ldo);
116 //      printk("%s set ldo2 vdd_usb11=%dmV end\n", __func__, regulator_get_voltage(ldo));
117         regulator_put(ldo);
118         udelay(100);
119
120         ldo = regulator_get(NULL, "ldo5");      // vcc_25
121         regulator_set_voltage(ldo, 2500000, 2500000);
122         regulator_enable(ldo);
123 //      printk("%s set ldo5 vcc_25=%dmV end\n", __func__, regulator_get_voltage(ldo));
124         regulator_put(ldo);
125         udelay(100);
126
127         ldo = regulator_get(NULL, "ldousb");    // vcc_usb33
128         regulator_set_voltage(ldo, 3300000, 3300000);
129         regulator_enable(ldo);
130 //      printk("%s set ldousb vcc_usb33=%dmV end\n", __func__, regulator_get_voltage(ldo));
131         regulator_put(ldo);
132         udelay(100);
133
134         dcdc = regulator_get(NULL, "vdd_cpu"); // vdd_arm
135         regulator_set_voltage(dcdc,1100000,1100000);
136         regulator_enable(dcdc); 
137         printk("%s set dcdc1 vdd_cpu=%dmV end\n", __func__, regulator_get_voltage(dcdc));
138         regulator_put(dcdc);
139         udelay(100);
140
141         dcdc = regulator_get(NULL, "vdd_core");  //vdd_log
142         regulator_set_voltage(dcdc,1100000,1100000);
143         regulator_enable(dcdc); 
144         printk("%s set dcdc2 vdd_core=%dmV end\n", __func__, regulator_get_voltage(dcdc));
145         regulator_put(dcdc);
146         udelay(100);
147
148         dcdc = regulator_get(NULL, "vcc_lpddr2_1v8");  //vcc_lpddr2_1v8
149         regulator_set_voltage(dcdc,DC3_VCC_DDR_VOL,DC3_VCC_DDR_VOL);
150         regulator_enable(dcdc); 
151 //      printk("%s set dcdc3 vcc_lpddr2_1v8=%dmV end\n", __func__, regulator_get_voltage(dcdc));
152         regulator_put(dcdc);
153         udelay(100);
154
155         dcdc = regulator_get(NULL, "vcc_lpddr2_1v2");   //vcc_lpddr2_1v2
156         regulator_set_voltage(dcdc,DC5_VCC_DDR_VOL,DC5_VCC_DDR_VOL);
157         regulator_enable(dcdc); 
158 //      printk("%s set dcdc5 vcc_lpddr2_1v2=%dmV end\n", __func__, regulator_get_voltage(dcdc));
159         regulator_put(dcdc);
160         udelay(100);
161         
162         ldo = regulator_get(NULL, "ldo3");      //vcc_nandflash
163         regulator_set_voltage(ldo, 3300000, 3300000);
164         regulator_enable(ldo);
165 //      printk("%s set ldo3 vcc_nandflash=%dmV end\n", __func__, regulator_get_voltage(ldo));
166         regulator_put(ldo);
167         udelay(100);
168         
169         ldo = regulator_get(NULL, "ldo6");      //codecvdd_1v8
170         regulator_set_voltage(ldo, 1800000, 1800000);
171         regulator_enable(ldo);
172 //      printk("%s set ldo6 codecvdd_1v8=%dmV end\n", __func__, regulator_get_voltage(ldo));
173         regulator_put(ldo);
174         udelay(100);
175
176         ldo = regulator_get(NULL, "ldo7");      //vcc_lcd
177         regulator_set_voltage(ldo, 3000000, 3000000);
178         regulator_enable(ldo);
179 //      printk("%s set ldo7 vcc_lcd=%dmV end\n", __func__, regulator_get_voltage(ldo));
180         regulator_put(ldo);
181         udelay(100);
182
183
184         ldo = regulator_get(NULL, "ldoln");       //vcccodec_io
185         regulator_set_voltage(ldo, 3300000, 3300000);
186         regulator_enable(ldo);
187 //      printk("%s set ldoln vcccodec_io=%dmV end\n", __func__, regulator_get_voltage(ldo));
188         regulator_put(ldo);
189         udelay(100);
190         
191 /*
192         ldo = regulator_get(NULL, "vana");      //vana_out
193         regulator_set_voltage(ldo, 2500000, 2500000);
194 //      regulator_set_suspend_voltage(ldo, 2500000);
195         regulator_enable(ldo);
196         printk("%s set vana vana_out=%dmV end\n", __func__, regulator_get_voltage(ldo));
197         regulator_put(ldo);
198         udelay(100);
199 */
200         
201         printk("tps80032_set_init end.\n");
202         return 0;
203 }
204
205
206 static struct regulator_consumer_supply tps80032_smps1_supply[] = {
207         {
208                 .supply = "smps1",
209         },
210         {
211                 .supply = "vdd_cpu",
212         },
213 };
214 static struct regulator_consumer_supply tps80032_smps2_supply[] = {
215         {
216                 .supply = "smps2",
217         },
218         {
219                 .supply = "vdd_core",
220         },
221 };
222 static struct regulator_consumer_supply tps80032_smps3_supply[] = {
223         {
224                 .supply = "smps3",
225         },
226         {
227                 .supply = "vcc_lpddr2_1v8",
228         },
229         {
230                 .supply = "vcc_ddr3",
231         },
232 };
233 static struct regulator_consumer_supply tps80032_smps4_supply[] = {
234         {
235                 .supply = "smps4",
236         },
237         {
238                 .supply = "vcc_io",
239         },
240 };
241 static struct regulator_consumer_supply tps80032_smps5_supply[] = {
242         {
243                 .supply = "smps5",
244         },
245         {
246                 .supply = "vcc_lpddr2_1v2",
247         },
248 };
249 static struct regulator_consumer_supply tps80032_ldo1_supply[] = {
250         {
251                 .supply = "ldo1",
252         },
253 };
254 static struct regulator_consumer_supply tps80032_ldo2_supply[] = {
255         {
256                 .supply = "ldo2",
257         },
258 };
259
260 static struct regulator_consumer_supply tps80032_ldo3_supply[] = {
261         {
262                 .supply = "ldo3",
263         },
264 };
265 static struct regulator_consumer_supply tps80032_ldo4_supply[] = {
266         {
267                 .supply = "ldo4",
268         },
269 };
270 static struct regulator_consumer_supply tps80032_ldo5_supply[] = {
271         {
272                 .supply = "ldo5",
273         },
274 };
275 static struct regulator_consumer_supply tps80032_ldo6_supply[] = {
276         {
277                 .supply = "ldo6",
278         },
279 };
280 static struct regulator_consumer_supply tps80032_ldo7_supply[] = {
281         {
282                 .supply = "ldo7",
283         },
284 };
285
286 static struct regulator_consumer_supply tps80032_ldoln_supply[] = {
287         {
288                 .supply = "ldoln",
289         },
290 };
291 static struct regulator_consumer_supply tps80032_ldousb_supply[] = {
292         {
293                 .supply = "ldousb",
294         },
295 };
296 static struct regulator_consumer_supply tps80032_ldovana_supply[] = {
297         {
298                 .supply = "vana",
299         },
300 };
301 /* */
302 static struct regulator_init_data tps80032_smps1 = {
303         .constraints = {
304                 .name           = "SMPS1",
305                 .min_uV                 = 600000,
306                 .max_uV                 = 2100000,
307                 .apply_uV               = 1,
308                 
309                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
310                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
311
312         },
313         .num_consumer_supplies = ARRAY_SIZE(tps80032_smps1_supply),
314         .consumer_supplies =  tps80032_smps1_supply,
315 };
316
317 /* */
318 static struct regulator_init_data tps80032_smps2 = {
319         .constraints = {
320                 .name           = "SMPS2",
321                 .min_uV                 = 600000,
322                 .max_uV                 = 2100000,
323                 .apply_uV               = 1,
324                 
325                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
326                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
327
328         },
329         .num_consumer_supplies = ARRAY_SIZE(tps80032_smps2_supply),
330         .consumer_supplies =  tps80032_smps2_supply,
331 };
332
333
334
335 /* */
336 static struct regulator_init_data tps80032_smps3 = {
337         .constraints = {
338                 .name           = "SMPS3",
339                 .min_uV                 = 600000,
340                 .max_uV                 = 2100000,
341                 .apply_uV               = 1,
342                 
343                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
344                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
345
346         },
347         .num_consumer_supplies = ARRAY_SIZE(tps80032_smps3_supply),
348         .consumer_supplies =  tps80032_smps3_supply,
349 };
350
351
352 /* */
353 static struct regulator_init_data tps80032_smps4 = {
354         .constraints = {
355                 .name           = "SMPS4",
356                 .min_uV                 = 600000,
357                 .max_uV                 = 2100000,
358                 .apply_uV               = 1,
359                 
360                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
361                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
362
363         },
364         .num_consumer_supplies = ARRAY_SIZE(tps80032_smps4_supply),
365         .consumer_supplies =  tps80032_smps4_supply,
366 };
367 /* */
368 static struct regulator_init_data tps80032_smps5 = {
369         .constraints = {
370                 .name           = "SMPS5",
371                 .min_uV                 = 600000,
372                 .max_uV                 = 2100000,
373                 .apply_uV               = 1,
374                 
375                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
376                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
377
378         },
379         .num_consumer_supplies = ARRAY_SIZE(tps80032_smps5_supply),
380         .consumer_supplies =  tps80032_smps5_supply,
381 };
382 static struct regulator_init_data tps80032_ldo1 = {
383         .constraints = {
384                 .name           = "LDO1",
385                 .min_uV                 = 1200000,
386                 .max_uV                 = 3000000,
387                 .apply_uV               = 1,
388                 
389                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
390                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
391
392         },
393         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldo1_supply),
394         .consumer_supplies =  tps80032_ldo1_supply,
395 };
396
397 /* */
398 static struct regulator_init_data tps80032_ldo2 = {
399         .constraints = {
400                 .name           = "LDO2",
401                 .min_uV                 = 1200000,
402                 .max_uV                 = 3000000,
403                 .apply_uV               = 1,
404                 
405                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
406                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
407
408         },
409         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldo2_supply),
410         .consumer_supplies =  tps80032_ldo2_supply,
411 };
412
413 /* */
414 static struct regulator_init_data tps80032_ldo3 = {
415         .constraints = {
416                 .name           = "LDO3",
417                 .min_uV                 = 1200000,
418                 .max_uV                 = 3000000,
419                 .apply_uV               = 1,
420                 
421                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
422                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
423
424         },
425         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldo3_supply),
426         .consumer_supplies =  tps80032_ldo3_supply,
427 };
428
429 /* */
430 static struct regulator_init_data tps80032_ldo4 = {
431         .constraints = {
432                 .name           = "LDO4",
433                 .min_uV                 = 1200000,
434                 .max_uV                 = 3000000,
435                 .apply_uV               = 1,
436                 
437                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
438                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
439
440         },
441         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldo4_supply),
442         .consumer_supplies =  tps80032_ldo4_supply,
443 };
444
445 /* */
446 static struct regulator_init_data tps80032_ldo5 = {
447         .constraints = {
448                 .name           = "LDO5",
449                 .min_uV                 = 1200000,
450                 .max_uV                 = 3000000,
451                 .apply_uV               = 1,
452                 
453                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
454                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
455
456         },
457         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldo5_supply),
458         .consumer_supplies =  tps80032_ldo5_supply,
459 };
460
461 /* */
462 static struct regulator_init_data tps80032_ldo6 = {
463         .constraints = {
464                 .name           = "LDO6",
465                 .min_uV                 = 1200000,
466                 .max_uV                 = 3000000,
467                 .apply_uV               = 1,
468                 
469                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
470                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
471
472         },
473         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldo6_supply),
474         .consumer_supplies =  tps80032_ldo6_supply,
475 };
476
477 /* */
478 static struct regulator_init_data tps80032_ldo7 = {
479         .constraints = {
480                 .name           = "LDO7",
481                 .min_uV                 = 1200000,
482                 .max_uV                 = 3000000,
483                 .apply_uV               = 1,
484                 
485                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
486                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
487
488         },
489         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldo7_supply),
490         .consumer_supplies =  tps80032_ldo7_supply,
491 };
492
493 /* */
494 static struct regulator_init_data tps80032_ldoln = {
495         .constraints = {
496                 .name           = "LDOLN",
497                 .min_uV                 = 1200000,
498                 .max_uV                 = 3000000,
499                 .apply_uV               = 1,
500                 
501                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
502                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
503
504         },
505         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldoln_supply),
506         .consumer_supplies =  tps80032_ldoln_supply,
507 };
508
509 /* */
510 static struct regulator_init_data tps80032_ldousb = {
511         .constraints = {
512                 .name           = "LDOUSB",
513                 .min_uV                 = 3300000,
514                 .max_uV                 = 3300000,
515                 .apply_uV               = 1,
516                 
517                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
518                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
519
520         },
521         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldousb_supply),
522         .consumer_supplies =  tps80032_ldousb_supply,
523 };
524
525 /* */
526 static struct regulator_init_data tps80032_ldovana = {
527         .constraints = {
528                 .name           = "LDOVANA",
529                 .min_uV                 = 600000,
530                 .max_uV                 = 2500000,
531                 .apply_uV               = 1,
532                 
533                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
534                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
535
536         },
537         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldovana_supply),
538         .consumer_supplies =  tps80032_ldovana_supply,
539 };
540
541 static struct twl4030_madc_platform_data tps80032_madc_data = {
542         .irq_line       = 1,
543 };
544 static int tps_batt_table[] = {
545 /* 0 C*/
546         3400,3420,3440,3475,3505,3525,
547         3540,3557,3570,3580,3610,
548         3630,3640,3652,3662,3672,
549         3680,3687,3693,3699,3705,
550         3710,3714,3718,3722,3726,
551         3730,3734,3738,3742,3746,
552         3750,3756,3764,3774,3786,
553         3800,3808,3817,3827,3845,
554         3950,3964,3982,4002,4026,
555         4030,4034,4055,4070,4085,4120
556 };
557 static struct twl4030_bci_platform_data tps80032_bci_data = {
558         .battery_tmp_tbl        = tps_batt_table,
559         .tblsize                = ARRAY_SIZE(tps_batt_table),
560 };
561
562 static int rk30_phy_init(struct device *dev){
563         return 0;
564         }
565 static int rk30_phy_exit(struct device *dev){
566         return 0;
567         }
568 static int rk30_phy_power(struct device *dev, int ID, int on){
569         return 0;
570         }
571 static int rk30_phy_set_clk(struct device *dev, int on){
572         return 0;
573         }
574 static int rk30_phy_suspend(struct device *dev, int suspend){
575         return 0;
576         }
577 static struct twl4030_usb_data tps80032_usbphy_data = {
578         .phy_init       = rk30_phy_init,
579         .phy_exit       = rk30_phy_exit,
580         .phy_power      = rk30_phy_power,
581         .phy_set_clock  = rk30_phy_set_clk,
582         .phy_suspend    = rk30_phy_suspend,
583
584 };
585 static struct twl4030_ins sleep_on_seq[] __initdata = {
586 /*
587  * Turn off everything
588  */
589         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_ALL, 1, 0, RES_STATE_SLEEP), 2},
590 };
591
592 static struct twl4030_script sleep_on_script __initdata = {
593         .script = sleep_on_seq,
594         .size   = ARRAY_SIZE(sleep_on_seq),
595         .flags  = TWL4030_SLEEP_SCRIPT,
596 };
597
598 static struct twl4030_ins wakeup_seq[] __initdata = {
599 /*
600  * Reenable everything
601  */
602         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_ALL, 1, 0, RES_STATE_ACTIVE), 2},
603 };
604
605 static struct twl4030_script wakeup_script __initdata = {
606         .script = wakeup_seq,
607         .size   = ARRAY_SIZE(wakeup_seq),
608         .flags  = TWL4030_WAKEUP12_SCRIPT,
609 };
610
611 static struct twl4030_ins wakeup_p3_seq[] __initdata = {
612 /*
613  * Reenable everything
614  */
615         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_ALL, 1, 0, RES_STATE_ACTIVE), 2},
616 };
617
618 static struct twl4030_script wakeup_p3_script __initdata = {
619         .script = wakeup_p3_seq,
620         .size   = ARRAY_SIZE(wakeup_p3_seq),
621         .flags  = TWL4030_WAKEUP3_SCRIPT,
622 };
623 static struct twl4030_ins wrst_seq[] __initdata = {
624 /*
625  * Reset twl4030.
626  * Reset VDD1 regulator.
627  * Reset VDD2 regulator.
628  * Reset VPLL1 regulator.
629  * Enable sysclk output.
630  * Reenable twl4030.
631  */
632         {MSG_SINGULAR(DEV_GRP_NULL, RES_RESET, RES_STATE_OFF), 2},
633         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_ALL, 0, 1, RES_STATE_ACTIVE),
634                 0x13},
635         {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_PP, 0, 3, RES_STATE_OFF), 0x13},
636         {MSG_SINGULAR(DEV_GRP_NULL, RES_VDD1, RES_STATE_WRST), 0x13},
637         {MSG_SINGULAR(DEV_GRP_NULL, RES_VDD2, RES_STATE_WRST), 0x13},
638         {MSG_SINGULAR(DEV_GRP_NULL, RES_VPLL1, RES_STATE_WRST), 0x35},
639         {MSG_SINGULAR(DEV_GRP_P3, RES_HFCLKOUT, RES_STATE_ACTIVE), 2},
640         {MSG_SINGULAR(DEV_GRP_NULL, RES_RESET, RES_STATE_ACTIVE), 2},
641 };
642 static struct twl4030_script wrst_script __initdata = {
643         .script = wrst_seq,
644         .size   = ARRAY_SIZE(wrst_seq),
645         .flags  = TWL4030_WRST_SCRIPT,
646 };
647
648 static struct twl4030_script *twl4030_scripts[] __initdata = {
649         /* wakeup12 script should be loaded before sleep script, otherwise a
650            board might hit retention before loading of wakeup script is
651            completed. This can cause boot failures depending on timing issues.
652         */
653         &wakeup_script,
654         &sleep_on_script,
655         &wakeup_p3_script,
656         &wrst_script,
657 };
658 static struct twl4030_resconfig twl4030_rconfig[] __initdata = {
659         { .resource = RES_VDD1, .devgroup = -1,
660           .type = 1, .type2 = -1, .remap_off = RES_STATE_OFF,
661           .remap_sleep = RES_STATE_OFF
662         },
663         { .resource = RES_VDD2, .devgroup = -1,
664           .type = 1, .type2 = -1, .remap_off = RES_STATE_OFF,
665           .remap_sleep = RES_STATE_OFF
666         },
667         { .resource = RES_VPLL1, .devgroup = -1,
668           .type = 1, .type2 = -1, .remap_off = RES_STATE_OFF,
669           .remap_sleep = RES_STATE_OFF
670         },
671         { .resource = RES_VPLL2, .devgroup = -1,
672           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
673         },
674         { .resource = RES_VAUX1, .devgroup = -1,
675           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
676         },
677         { .resource = RES_VAUX2, .devgroup = -1,
678           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
679         },
680         { .resource = RES_VAUX3, .devgroup = -1,
681           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
682         },
683         { .resource = RES_VAUX4, .devgroup = -1,
684           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
685         },
686                 { .resource = RES_VMMC1, .devgroup = -1,
687           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
688         },
689         { .resource = RES_VMMC2, .devgroup = -1,
690           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
691         },
692         { .resource = RES_VDAC, .devgroup = -1,
693           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
694         },
695         { .resource = RES_VSIM, .devgroup = -1,
696           .type = -1, .type2 = 3, .remap_off = -1, .remap_sleep = -1
697         },
698         { .resource = RES_VINTANA1, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
699           .type = -1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
700         },
701         { .resource = RES_VINTANA2, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
702           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
703         },
704         { .resource = RES_VINTDIG, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
705           .type = -1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
706         },
707         { .resource = RES_VIO, .devgroup = DEV_GRP_P3,
708           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
709         },
710         { .resource = RES_CLKEN, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
711           .type = 1, .type2 = -1 , .remap_off = -1, .remap_sleep = -1
712         },
713         { .resource = RES_REGEN, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
714           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
715         },
716         { .resource = RES_NRES_PWRON, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
717           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
718         },
719         { .resource = RES_SYSEN, .devgroup = DEV_GRP_P1 | DEV_GRP_P3,
720           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
721         },
722         { .resource = RES_HFCLKOUT, .devgroup = DEV_GRP_P3,
723           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
724         },
725         { .resource = RES_32KCLKOUT, .devgroup = -1,
726           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
727         },
728         { .resource = RES_RESET, .devgroup = -1,
729           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
730         },
731         { .resource = RES_MAIN_REF, .devgroup = -1,
732           .type = 1, .type2 = -1, .remap_off = -1, .remap_sleep = -1
733         },
734         { 0, 0},
735 };
736 static struct twl4030_power_data tps80032_scripts_data __initdata = {
737         .scripts        = twl4030_scripts,
738         .num = ARRAY_SIZE(twl4030_scripts),
739         .resource_config = twl4030_rconfig,
740 };
741
742 #ifdef CONFIG_HAS_EARLYSUSPEND
743 void twl60xx_pmu_early_suspend(struct regulator_dev *rdev)
744 {
745         printk("%s\n", __func__);
746         int ret;
747         ret = twl_reg_read(REG_INT_MSK_STS_A,TWL_MODULE_PIH);
748         twl_reg_write(REG_INT_MSK_STS_A,TWL_MODULE_PIH, ret & (~(1 << 2))); //open vlow interrupt
749 }
750 void twl60xx_pmu_early_resume(struct regulator_dev *rdev)
751 {
752         printk("%s\n", __func__);
753         int ret;
754         ret = twl_reg_read(REG_INT_MSK_STS_A,TWL_MODULE_PIH);
755         twl_reg_write(REG_INT_MSK_STS_A,TWL_MODULE_PIH, ret |(1 << 2)); //close vlow interrupt
756 }
757 #else
758 void twl60xx_pmu_early_suspend(struct regulator_dev *rdev)
759 {
760 }
761 void twl60xx_pmu_early_resume(struct regulator_dev *rdev)
762 {
763 }
764 #endif
765
766 void __sramfunc board_pmu_suspend(void)
767 {       
768         #ifdef CONFIG_CLK_SWITCH_TO_32K                 //switch clk to 32k
769         grf_writel(GPIO6_PB1_DIR_OUT, GRF_GPIO6L_DIR_ADDR);
770         grf_writel(GPIO6_PB1_DO_HIGH, GRF_GPIO6L_DO_ADDR);  //set gpio6_b1 output low
771         grf_writel(GPIO6_PB1_EN_MASK, GRF_GPIO6L_EN_ADDR);
772         #endif
773         
774         grf_writel(GPIO6_PB3_DIR_OUT, GRF_GPIO6L_DIR_ADDR);
775         grf_writel(GPIO6_PB3_DO_HIGH, GRF_GPIO6L_DO_ADDR);  //set gpio6_b3 output low
776         grf_writel(GPIO6_PB3_EN_MASK, GRF_GPIO6L_EN_ADDR);
777         
778 }
779 void __sramfunc board_pmu_resume(void)
780 {
781         grf_writel(GPIO6_PB3_DIR_OUT, GRF_GPIO6L_DIR_ADDR);
782         grf_writel(GPIO6_PB3_DO_LOW, GRF_GPIO6L_DO_ADDR);     //set gpio6_b3 output high
783         grf_writel(GPIO6_PB3_EN_MASK, GRF_GPIO6L_EN_ADDR);
784         
785         #ifdef CONFIG_CLK_SWITCH_TO_32K                 //switch clk to 24M
786         grf_writel(GPIO6_PB1_DIR_OUT, GRF_GPIO6L_DIR_ADDR);
787         grf_writel(GPIO6_PB1_DO_LOW, GRF_GPIO6L_DO_ADDR);  //set gpio6_b1 output low
788         grf_writel(GPIO6_PB1_EN_MASK, GRF_GPIO6L_EN_ADDR);
789         sram_32k_udelay(10000);
790         #else
791         sram_udelay(2000);
792         #endif
793 }
794
795 static struct twl4030_platform_data tps80032_data = {
796         .irq_base       = TWL60xx_IRQ_BASE,
797         .irq_end        = TWL60xx_IRQ_END,
798         //.irq            = RK29_PIN0_PA1,
799         .pre_init = tps80032_pre_init,
800         .set_init = tps80032_set_init,
801         
802         .madc           = &tps80032_madc_data,
803         .bci            = &tps80032_bci_data,
804         .usb            = &tps80032_usbphy_data,
805 //      .power                  = &tps80032_scripts_data,
806         /* Regulators */
807         .ldo1           = &tps80032_ldo1,
808         .ldo2           = &tps80032_ldo2,
809         .ldo3           = &tps80032_ldo3,
810         .ldo4           = &tps80032_ldo4,
811         .ldo5           = &tps80032_ldo5,
812         .ldo6           = &tps80032_ldo6,
813         .ldo7           = &tps80032_ldo7,
814         .ldoln             = &tps80032_ldoln,
815         .ldousb           =&tps80032_ldousb,
816         .vana              = &tps80032_ldovana,
817         
818         .smps1 = &tps80032_smps1,
819         .smps2= &tps80032_smps2,
820         .smps3          = &tps80032_smps3,
821         .smps4          = &tps80032_smps4,
822         .smps5   = &tps80032_smps5,
823  
824 };
825
826 #endif