ARM64: DTS: Add rk3399-firefly uart4 device, node as /dev/ttyS1
[firefly-linux-kernel-4.4.55.git] / board-rk30-sdk-twl80032.c
1 #include <linux/regulator/machine.h>
2 #include <linux/i2c/twl.h>
3
4 #include <mach/sram.h>
5
6 #define TWL60xx_IRQ_BASE        IRQ_BOARD_BASE
7 #ifdef CONFIG_TWL4030_CORE
8 #define TWL60xx_BASE_NR_IRQS    24
9 #else
10 #define TWL60xx_BASE_NR_IRQS    0
11 #endif
12 #define TWL60xx_IRQ_END         (TWL60xx_IRQ_BASE + TWL60xx_BASE_NR_IRQS)
13
14
15 #ifdef CONFIG_TWL4030_CORE
16 #define VREG_VOLTAGE            3
17 #define VREG_VOLTAGE_DVS_SMPS 3 
18 static inline int twl_reg_read(unsigned base, unsigned slave_subgp, unsigned offset)
19 {
20         u8 value;
21         int status;
22         status = twl_i2c_read_u8(slave_subgp,&value, base + offset);
23         return (status < 0) ? status : value;
24 }
25
26
27 static inline int twl_reg_write(unsigned base, unsigned slave_subgp, unsigned offset,
28                                                  u8 value)
29 {
30         return twl_i2c_write_u8(slave_subgp,value, base + offset);
31 }
32
33 int tps80032_pre_init(void){
34         int ret;
35         u8 value;
36         printk("%s\n", __func__);
37
38         return 0;
39
40 }
41 int tps80032_set_init(void)
42 {
43         struct regulator *dcdc;
44         struct regulator *ldo;
45         printk("%s\n", __func__);
46         
47         ldo = regulator_get(NULL, "ldo1");      //vcca_33
48         regulator_set_voltage(ldo, 3300000, 3300000);
49         regulator_enable(ldo);
50 //      printk("%s set ldo1 vcca_33=%dmV end\n", __func__, regulator_get_voltage(ldo));
51         regulator_put(ldo);
52         udelay(100);
53         
54         ldo = regulator_get(NULL, "ldo4");      // vdd_11
55         regulator_set_voltage(ldo, 1100000, 1100000);
56         regulator_enable(ldo);
57 //      printk("%s set ldo4 vdd_11=%dmV end\n", __func__, regulator_get_voltage(ldo));
58         regulator_put(ldo);
59         udelay(100);
60
61         dcdc = regulator_get(NULL, "smps4");
62         regulator_set_voltage(dcdc,3000000,3000000);
63         regulator_enable(dcdc); 
64 //      printk("%s set dcdc4 vcc_io=%dmV end\n", __func__, regulator_get_voltage(dcdc));
65         regulator_put(dcdc);
66         udelay(100);
67
68         ldo = regulator_get(NULL, "ldo2");      // vdd_usb11
69         regulator_set_voltage(ldo, 1100000, 1100000);
70         regulator_enable(ldo);
71 //      printk("%s set ldo2 vdd_usb11=%dmV end\n", __func__, regulator_get_voltage(ldo));
72         regulator_put(ldo);
73         udelay(100);
74
75         ldo = regulator_get(NULL, "ldo5");      // vcc_25
76         regulator_set_voltage(ldo, 2500000, 2500000);
77         regulator_enable(ldo);
78 //      printk("%s set ldo5 vcc_25=%dmV end\n", __func__, regulator_get_voltage(ldo));
79         regulator_put(ldo);
80         udelay(100);
81
82         ldo = regulator_get(NULL, "ldousb");    // vcc_usb33
83         regulator_set_voltage(ldo, 3300000, 3300000);
84         regulator_enable(ldo);
85 //      printk("%s set ldousb vcc_usb33=%dmV end\n", __func__, regulator_get_voltage(ldo));
86         regulator_put(ldo);
87         udelay(100);
88
89         dcdc = regulator_get(NULL, "vdd_cpu"); // vdd_arm
90         regulator_set_voltage(dcdc,1100000,1100000);
91         regulator_enable(dcdc); 
92         printk("%s set dcdc1 vdd_cpu=%dmV end\n", __func__, regulator_get_voltage(dcdc));
93         regulator_put(dcdc);
94         udelay(100);
95
96         dcdc = regulator_get(NULL, "vdd_core");  //vdd_log
97         regulator_set_voltage(dcdc,1100000,1100000);
98         regulator_enable(dcdc); 
99         printk("%s set dcdc2 vdd_core=%dmV end\n", __func__, regulator_get_voltage(dcdc));
100         regulator_put(dcdc);
101         udelay(100);
102
103         dcdc = regulator_get(NULL, "smps3");  //vcc_ddr
104         regulator_set_voltage(dcdc,1800000,1800000);
105         regulator_enable(dcdc); 
106 //      printk("%s set dcdc3 vcc_lpddr2_1v8=%dmV end\n", __func__, regulator_get_voltage(dcdc));
107         regulator_put(dcdc);
108         udelay(100);
109
110         dcdc = regulator_get(NULL, "smps5");
111         regulator_set_voltage(dcdc,1200000,1200000);
112         regulator_enable(dcdc); 
113 //      printk("%s set dcdc5 vcc_lpddr2_1v2=%dmV end\n", __func__, regulator_get_voltage(dcdc));
114         regulator_put(dcdc);
115         udelay(100);
116
117         
118         ldo = regulator_get(NULL, "ldo3");      //vcc_nandflash
119         regulator_set_voltage(ldo, 3300000, 3300000);
120         regulator_enable(ldo);
121 //      printk("%s set ldo3 vcc_nandflash=%dmV end\n", __func__, regulator_get_voltage(ldo));
122         regulator_put(ldo);
123         udelay(100);
124         
125         ldo = regulator_get(NULL, "ldo6");      //codecvdd_1v8
126         regulator_set_voltage(ldo, 1800000, 1800000);
127         regulator_enable(ldo);
128 //      printk("%s set ldo6 codecvdd_1v8=%dmV end\n", __func__, regulator_get_voltage(ldo));
129         regulator_put(ldo);
130         udelay(100);
131
132         ldo = regulator_get(NULL, "ldo7");      //vcc_lcd
133         regulator_set_voltage(ldo, 3000000, 3000000);
134         regulator_enable(ldo);
135 //      printk("%s set ldo7 vcc_lcd=%dmV end\n", __func__, regulator_get_voltage(ldo));
136         regulator_put(ldo);
137         udelay(100);
138
139         ldo = regulator_get(NULL, "ldoln");       //vcccodec_io
140         regulator_set_voltage(ldo, 3300000, 3300000);
141         regulator_enable(ldo);
142 //      printk("%s set ldoln vcccodec_io=%dmV end\n", __func__, regulator_get_voltage(ldo));
143         regulator_put(ldo);
144         udelay(100);
145 /*
146         ldo = regulator_get(NULL, "vana");      //vana_out
147         regulator_set_voltage(ldo, 2500000, 2500000);
148 //      regulator_set_suspend_voltage(ldo, 2500000);
149         regulator_enable(ldo);
150         printk("%s set vana vana_out=%dmV end\n", __func__, regulator_get_voltage(ldo));
151         regulator_put(ldo);
152         udelay(100);
153 */
154
155         printk("tps80032_set_init end.\n");
156         return 0;
157 }
158
159
160 static struct regulator_consumer_supply tps80032_smps1_supply[] = {
161         {
162                 .supply = "vdd_cpu",
163         },
164 };
165 static struct regulator_consumer_supply tps80032_smps2_supply[] = {
166         {
167                 .supply = "vdd_core",
168         },
169 };
170 static struct regulator_consumer_supply tps80032_smps3_supply[] = {
171         {
172                 .supply = "smps3",
173         },
174 };
175 static struct regulator_consumer_supply tps80032_smps4_supply[] = {
176         {
177                 .supply = "smps4",
178         },
179 };
180 static struct regulator_consumer_supply tps80032_smps5_supply[] = {
181         {
182                 .supply = "smps5",
183         },
184 };
185 static struct regulator_consumer_supply tps80032_ldo1_supply[] = {
186         {
187                 .supply = "ldo1",
188         },
189 };
190 static struct regulator_consumer_supply tps80032_ldo2_supply[] = {
191         {
192                 .supply = "ldo2",
193         },
194 };
195
196 static struct regulator_consumer_supply tps80032_ldo3_supply[] = {
197         {
198                 .supply = "ldo3",
199         },
200 };
201 static struct regulator_consumer_supply tps80032_ldo4_supply[] = {
202         {
203                 .supply = "ldo4",
204         },
205 };
206 static struct regulator_consumer_supply tps80032_ldo5_supply[] = {
207         {
208                 .supply = "ldo5",
209         },
210 };
211 static struct regulator_consumer_supply tps80032_ldo6_supply[] = {
212         {
213                 .supply = "ldo6",
214         },
215 };
216 static struct regulator_consumer_supply tps80032_ldo7_supply[] = {
217         {
218                 .supply = "ldo7",
219         },
220 };
221
222 static struct regulator_consumer_supply tps80032_ldoln_supply[] = {
223         {
224                 .supply = "ldoln",
225         },
226 };
227 static struct regulator_consumer_supply tps80032_ldousb_supply[] = {
228         {
229                 .supply = "ldousb",
230         },
231 };
232 static struct regulator_consumer_supply tps80032_ldovana_supply[] = {
233         {
234                 .supply = "vana",
235         },
236 };
237 /* */
238 static struct regulator_init_data tps80032_smps1 = {
239         .constraints = {
240                 .name           = "SMPS1",
241                 .min_uV                 = 600000,
242                 .max_uV                 = 2100000,
243                 .apply_uV               = 1,
244                 
245                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
246                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
247
248         },
249         .num_consumer_supplies = ARRAY_SIZE(tps80032_smps1_supply),
250         .consumer_supplies =  tps80032_smps1_supply,
251 };
252
253 /* */
254 static struct regulator_init_data tps80032_smps2 = {
255         .constraints = {
256                 .name           = "SMPS2",
257                 .min_uV                 = 600000,
258                 .max_uV                 = 2100000,
259                 .apply_uV               = 1,
260                 
261                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
262                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
263
264         },
265         .num_consumer_supplies = ARRAY_SIZE(tps80032_smps2_supply),
266         .consumer_supplies =  tps80032_smps2_supply,
267 };
268
269
270
271 /* */
272 static struct regulator_init_data tps80032_smps3 = {
273         .constraints = {
274                 .name           = "SMPS3",
275                 .min_uV                 = 600000,
276                 .max_uV                 = 2100000,
277                 .apply_uV               = 1,
278                 
279                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
280                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
281
282         },
283         .num_consumer_supplies = ARRAY_SIZE(tps80032_smps3_supply),
284         .consumer_supplies =  tps80032_smps3_supply,
285 };
286
287
288 /* */
289 static struct regulator_init_data tps80032_smps4 = {
290         .constraints = {
291                 .name           = "SMPS4",
292                 .min_uV                 = 600000,
293                 .max_uV                 = 2100000,
294                 .apply_uV               = 1,
295                 
296                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
297                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
298
299         },
300         .num_consumer_supplies = ARRAY_SIZE(tps80032_smps4_supply),
301         .consumer_supplies =  tps80032_smps4_supply,
302 };
303 /* */
304 static struct regulator_init_data tps80032_smps5 = {
305         .constraints = {
306                 .name           = "SMPS5",
307                 .min_uV                 = 600000,
308                 .max_uV                 = 2100000,
309                 .apply_uV               = 1,
310                 
311                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
312                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
313
314         },
315         .num_consumer_supplies = ARRAY_SIZE(tps80032_smps5_supply),
316         .consumer_supplies =  tps80032_smps5_supply,
317 };
318 static struct regulator_init_data tps80032_ldo1 = {
319         .constraints = {
320                 .name           = "LDO1",
321                 .min_uV                 = 1200000,
322                 .max_uV                 = 3000000,
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_ldo1_supply),
330         .consumer_supplies =  tps80032_ldo1_supply,
331 };
332
333 /* */
334 static struct regulator_init_data tps80032_ldo2 = {
335         .constraints = {
336                 .name           = "LDO2",
337                 .min_uV                 = 1200000,
338                 .max_uV                 = 3000000,
339                 .apply_uV               = 1,
340                 
341                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
342                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
343
344         },
345         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldo2_supply),
346         .consumer_supplies =  tps80032_ldo2_supply,
347 };
348
349 /* */
350 static struct regulator_init_data tps80032_ldo3 = {
351         .constraints = {
352                 .name           = "LDO3",
353                 .min_uV                 = 1200000,
354                 .max_uV                 = 3000000,
355                 .apply_uV               = 1,
356                 
357                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
358                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
359
360         },
361         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldo3_supply),
362         .consumer_supplies =  tps80032_ldo3_supply,
363 };
364
365 /* */
366 static struct regulator_init_data tps80032_ldo4 = {
367         .constraints = {
368                 .name           = "LDO4",
369                 .min_uV                 = 1200000,
370                 .max_uV                 = 3000000,
371                 .apply_uV               = 1,
372                 
373                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
374                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
375
376         },
377         .num_consumer_supplies = ARRAY_SIZE(tps80032_ldo4_supply),
378         .consumer_supplies =  tps80032_ldo4_supply,
379 };
380
381 /* */
382 static struct regulator_init_data tps80032_ldo5 = {
383         .constraints = {
384                 .name           = "LDO5",
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_ldo5_supply),
394         .consumer_supplies =  tps80032_ldo5_supply,
395 };
396
397 /* */
398 static struct regulator_init_data tps80032_ldo6 = {
399         .constraints = {
400                 .name           = "LDO6",
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_ldo6_supply),
410         .consumer_supplies =  tps80032_ldo6_supply,
411 };
412
413 /* */
414 static struct regulator_init_data tps80032_ldo7 = {
415         .constraints = {
416                 .name           = "LDO7",
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_ldo7_supply),
426         .consumer_supplies =  tps80032_ldo7_supply,
427 };
428
429 /* */
430 static struct regulator_init_data tps80032_ldoln = {
431         .constraints = {
432                 .name           = "LDOLN",
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_ldoln_supply),
442         .consumer_supplies =  tps80032_ldoln_supply,
443 };
444
445 /* */
446 static struct regulator_init_data tps80032_ldousb = {
447         .constraints = {
448                 .name           = "LDOUSB",
449                 .min_uV                 = 3300000,
450                 .max_uV                 = 3300000,
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_ldousb_supply),
458         .consumer_supplies =  tps80032_ldousb_supply,
459 };
460
461 /* */
462 static struct regulator_init_data tps80032_ldovana = {
463         .constraints = {
464                 .name           = "LDOVANA",
465                 .min_uV                 = 600000,
466                 .max_uV                 = 2500000,
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_ldovana_supply),
474         .consumer_supplies =  tps80032_ldovana_supply,
475 };
476
477
478 static struct twl4030_platform_data tps80032_data = {
479         .irq_base       = TWL60xx_IRQ_BASE,
480         .irq_end        = TWL60xx_IRQ_END,
481         //.irq            = RK29_PIN0_PA1,
482         .pre_init = tps80032_pre_init,
483         .set_init = tps80032_set_init,
484
485         /* Regulators */
486         .ldo1           = &tps80032_ldo1,
487         .ldo2           = &tps80032_ldo2,
488         .ldo3           = &tps80032_ldo3,
489         .ldo4           = &tps80032_ldo4,
490         .ldo5           = &tps80032_ldo5,
491         .ldo6           = &tps80032_ldo6,
492         .ldo7           = &tps80032_ldo7,
493         .ldoln             = &tps80032_ldoln,
494         .ldousb           =&tps80032_ldousb,
495         .vana              = &tps80032_ldovana,
496         
497         .smps1 = &tps80032_smps1,
498         .smps2= &tps80032_smps2,
499         .smps3          = &tps80032_smps3,
500         .smps4          = &tps80032_smps4,
501         .smps5   = &tps80032_smps5,
502  
503 };
504
505 #endif