ARM64: DTS: Add rk3399-firefly uart4 device, node as /dev/ttyS1
[firefly-linux-kernel-4.4.55.git] / board-rk30-ds1001b-wm8326.c
1 #include <linux/regulator/machine.h>
2 #include <linux/mfd/wm831x/pdata.h>
3 #include <linux/mfd/wm831x/core.h>
4 #include <linux/mfd/wm831x/gpio.h>
5 #include <linux/mfd/wm831x/pmu.h>
6
7 #include <mach/sram.h>
8
9 #define cru_readl(offset)       readl_relaxed(RK30_CRU_BASE + offset)
10 #define cru_writel(v, offset)   do { writel_relaxed(v, RK30_CRU_BASE + offset); dsb(); } while (0)
11
12 #define grf_readl(offset)       readl_relaxed(RK30_GRF_BASE + offset)
13 #define grf_writel(v, offset)   do { writel_relaxed(v, RK30_GRF_BASE + offset); dsb(); } while (0)
14
15 #define CRU_CLKGATE5_CON_ADDR 0x00e4
16 #define GRF_GPIO6L_DIR_ADDR 0x0030
17 #define GRF_GPIO6L_DO_ADDR 0x0068
18 #define GRF_GPIO6L_EN_ADDR 0x00a0
19 #define CRU_CLKGATE5_GRFCLK_ON 0x00100000
20 #define CRU_CLKGATE5_GRFCLK_OFF 0x00100010
21 #define GPIO6_PB1_DIR_OUT  0x02000200
22 #define GPIO6_PB1_DO_LOW  0x02000000
23 #define GPIO6_PB1_DO_HIGH  0x02000200
24 #define GPIO6_PB1_EN_MASK  0x02000200
25 #define GPIO6_PB1_UNEN_MASK  0x02000000
26
27 /* wm8326 pmu*/
28 #if defined(CONFIG_GPIO_WM831X)
29 static struct rk29_gpio_expander_info wm831x_gpio_settinginfo[] = {
30         {
31                 .gpio_num = WM831X_P01, // tp3
32                 .pin_type = GPIO_OUT,
33                 .pin_value = GPIO_LOW,
34         },
35         {
36                 .gpio_num = WM831X_P02, //tp4
37                 .pin_type = GPIO_IN,
38         },
39         {
40                 .gpio_num = WM831X_P03, //tp2
41                 .pin_type = GPIO_OUT,
42                 .pin_value = GPIO_HIGH,
43         },
44         {
45                 .gpio_num = WM831X_P04, //tp1
46                 .pin_type = GPIO_IN,
47         },
48         {
49                 .gpio_num = WM831X_P05, //tp1
50                 .pin_type = GPIO_IN,
51         },
52         {
53                 .gpio_num = WM831X_P06, //tp1
54                 .pin_type = GPIO_OUT,
55                 .pin_value = GPIO_HIGH,
56         },
57         {
58                 .gpio_num = WM831X_P07, //tp1
59                 .pin_type = GPIO_IN,
60         },
61         {
62                 .gpio_num = WM831X_P08, //tp1
63                 .pin_type = GPIO_OUT,
64                 .pin_value = GPIO_HIGH,
65         },
66         {
67                 .gpio_num = WM831X_P09, //tp1
68                 .pin_type = GPIO_OUT,
69                 .pin_value = GPIO_HIGH,
70         },
71         {
72                 .gpio_num = WM831X_P10, //tp1
73                 .pin_type = GPIO_IN,
74         },
75         {
76                 .gpio_num = WM831X_P11, //tp1
77                 .pin_type = GPIO_OUT,
78                 .pin_value = GPIO_HIGH,
79         },
80         {
81                 .gpio_num = WM831X_P12,
82                 .pin_type = GPIO_OUT,
83                 .pin_value = GPIO_HIGH,
84         },
85 };
86 #endif
87
88 #if defined(CONFIG_MFD_WM831X)
89
90 #define UNLOCK_SECURITY_KEY     ~(0x1<<5)
91 #define LOCK_SECURITY_KEY       0x00
92 #define PMU_POWER_SLEEP RK30_PIN6_PB1
93 static struct wm831x *Wm831x;
94
95 static int wm831x_pre_init(struct wm831x *parm)
96 {
97         int ret;
98         Wm831x = parm;
99 //      printk("%s\n", __func__);
100         gpio_request(PMU_POWER_SLEEP, "NULL");
101         gpio_direction_output(PMU_POWER_SLEEP, GPIO_LOW);
102
103         #ifdef CONFIG_WM8326_VBAT_LOW_DETECTION
104         #ifdef CONFIG_BATTERY_RK30_VOL3V8
105         wm831x_set_bits(parm,WM831X_SYSVDD_CONTROL ,0xc077,0xc035);       //pvdd power on dect vbat voltage
106         printk("+++The vbat is too low+++\n");  
107         #endif
108         #endif
109         
110         ret = wm831x_reg_read(parm, WM831X_POWER_STATE) & 0xffff;
111         wm831x_reg_write(parm, WM831X_POWER_STATE, (ret & 0xfff8) | 0x04);
112
113         wm831x_set_bits(parm, WM831X_RTC_CONTROL, WM831X_RTC_ALAM_ENA_MASK, 0x0400);//enable rtc alam
114         //BATT_FET_ENA = 1
115         wm831x_reg_write(parm, WM831X_SECURITY_KEY, 0x9716);    // unlock security key
116         wm831x_set_bits(parm, WM831X_RESET_CONTROL, 0x1003, 0x1001);
117         ret = wm831x_reg_read(parm, WM831X_RESET_CONTROL) & 0xffff & UNLOCK_SECURITY_KEY;       // enternal reset active in sleep
118 //      printk("%s:WM831X_RESET_CONTROL=0x%x\n", __func__, ret);
119         wm831x_reg_write(parm, WM831X_RESET_CONTROL, ret);
120
121         wm831x_set_bits(parm,WM831X_DC1_ON_CONFIG ,0x0300,0x0000); //set dcdc mode is FCCM
122         wm831x_set_bits(parm,WM831X_DC2_ON_CONFIG ,0x0300,0x0000);
123         wm831x_set_bits(parm,WM831X_DC3_ON_CONFIG ,0x0300,0x0000);
124         wm831x_set_bits(parm,0x4066,0x0300,0x0000);
125
126 #ifndef CONFIG_MACH_RK3066_SDK
127         wm831x_set_bits(parm,WM831X_LDO10_CONTROL ,0x0040,0x0040);// set ldo10 in switch mode
128 #endif
129         wm831x_set_bits(parm,WM831X_STATUS_LED_1 ,0xc300,0xc100);// set led1 on(in manual mode)
130         wm831x_set_bits(parm,WM831X_STATUS_LED_2 ,0xc300,0xc000);//set led2 off(in manual mode)
131
132         wm831x_set_bits(parm,WM831X_LDO5_SLEEP_CONTROL ,0xe000,0x2000);// set ldo5 is disable in sleep mode 
133         wm831x_set_bits(parm,WM831X_LDO1_SLEEP_CONTROL ,0xe000,0x2000);// set ldo1 is disable in sleep mode 
134         
135         wm831x_reg_write(parm, WM831X_SECURITY_KEY, LOCK_SECURITY_KEY); // lock security key
136
137         return 0;
138 }
139 static int wm831x_mask_interrupt(struct wm831x *Wm831x)
140 {
141         /**************************clear interrupt********************/
142         wm831x_reg_write(Wm831x,WM831X_INTERRUPT_STATUS_1,0xffff);
143         wm831x_reg_write(Wm831x,WM831X_INTERRUPT_STATUS_2,0xffff);
144         wm831x_reg_write(Wm831x,WM831X_INTERRUPT_STATUS_3,0xffff);
145         wm831x_reg_write(Wm831x,WM831X_INTERRUPT_STATUS_4,0xffff);
146         wm831x_reg_write(Wm831x,WM831X_INTERRUPT_STATUS_5,0xffff);
147         
148         wm831x_reg_write(Wm831x,WM831X_SYSTEM_INTERRUPTS_MASK,0xbedc); //mask interrupt which not used
149         return 0;
150         /*****************************************************************/
151 }
152
153 #ifdef CONFIG_WM8326_VBAT_LOW_DETECTION
154 static int wm831x_low_power_detection(struct wm831x *wm831x)
155 {
156         #ifdef CONFIG_BATTERY_RK30_VOL3V8
157         wm831x_reg_write(wm831x,WM831X_SYSTEM_INTERRUPTS_MASK,0xbe5c);  
158         wm831x_set_bits(wm831x,WM831X_INTERRUPT_STATUS_1_MASK,0x8000,0x0000);   
159         wm831x_set_bits(wm831x,WM831X_SYSVDD_CONTROL ,0xc077,0x0035);           //set pvdd low voltage is 3.1v hi voltage is 3.3v 
160         #else
161         wm831x_reg_write(wm831x,WM831X_AUXADC_CONTROL,0x803f);     //open adc 
162         wm831x_reg_write(wm831x,WM831X_AUXADC_CONTROL,0xd03f);
163         wm831x_reg_write(wm831x,WM831X_AUXADC_SOURCE,0x0001);
164         
165         wm831x_reg_write(wm831x,WM831X_COMPARATOR_CONTROL,0x0001);
166         wm831x_reg_write(wm831x,WM831X_COMPARATOR_1,0x2844);   //set the low power is 3.1v
167         
168         wm831x_reg_write(wm831x,WM831X_INTERRUPT_STATUS_1_MASK,0x99ee);
169         wm831x_set_bits(wm831x,WM831X_SYSTEM_INTERRUPTS_MASK,0x0100,0x0000);
170         if (wm831x_reg_read(wm831x,WM831X_AUXADC_DATA)< 0x1844){
171                 printk("The vbat is too low.\n");
172                 wm831x_device_shutdown(wm831x);
173         }
174         #endif
175         return 0;       
176 }
177 #endif
178
179 #define AVS_BASE 172
180 int wm831x_post_init(struct wm831x *Wm831x)
181 {
182         struct regulator *dcdc;
183         struct regulator *ldo;
184
185
186         ldo = regulator_get(NULL, "ldo6");      //vcc_33
187         regulator_set_voltage(ldo, 3300000, 3300000);
188         regulator_set_suspend_voltage(ldo, 3300000);
189         regulator_enable(ldo);
190 //      printk("%s set ldo6 vcc_33=%dmV end\n", __func__, regulator_get_voltage(ldo));
191         regulator_put(ldo);
192         udelay(100);
193         
194         ldo = regulator_get(NULL, "ldo4");      // vdd_11
195         regulator_set_voltage(ldo, 1100000, 1100000);
196         regulator_set_suspend_voltage(ldo, 1000000);
197         regulator_enable(ldo);
198 //      printk("%s set ldo4 vdd_11=%dmV end\n", __func__, regulator_get_voltage(ldo));
199         regulator_put(ldo);
200         udelay(100);
201
202         ldo = regulator_get(NULL, "ldo5");      //vcc_25
203         regulator_set_voltage(ldo, 2500000, 2500000);
204         regulator_set_suspend_voltage(ldo, 2500000);
205         regulator_enable(ldo);
206 //      printk("%s set ldo5 vcc_25=%dmV end\n", __func__, regulator_get_voltage(ldo));
207         regulator_put(ldo);
208
209         dcdc = regulator_get(NULL, "dcdc4");    // vcc_io
210 #ifdef CONFIG_MACH_RK3066_SDK
211         regulator_set_voltage(dcdc, 3300000, 3300000);
212         regulator_set_suspend_voltage(dcdc, 3100000);
213 #else
214         regulator_set_voltage(dcdc, 3000000, 3000000);
215         regulator_set_suspend_voltage(dcdc, 2800000);
216 #endif
217         regulator_enable(dcdc);
218 //      printk("%s set dcdc4 vcc_io=%dmV end\n", __func__, regulator_get_voltage(dcdc));
219         regulator_put(dcdc);
220         udelay(100);
221
222         dcdc = regulator_get(NULL, "vdd_cpu");  // vdd_arm
223         regulator_set_voltage(dcdc, 1100000, 1100000);
224         regulator_set_suspend_voltage(dcdc, 1000000);
225         regulator_enable(dcdc);
226         printk("%s set dcdc2 vdd_cpu(vdd_arm)=%dmV end\n", __func__, regulator_get_voltage(dcdc));
227         regulator_put(dcdc);
228         udelay(100);
229
230         dcdc = regulator_get(NULL, "vdd_core"); // vdd_log
231         
232         /* Read avs value under logic 1.1V*/
233         regulator_set_voltage(dcdc, 1100000, 1100000);
234         avs_init_val_get(1,1100000,"wm8326 init");
235         udelay(600);
236         avs_set_scal_val(AVS_BASE);
237
238         regulator_set_voltage(dcdc, 1150000, 1150000);
239         regulator_set_suspend_voltage(dcdc, 1000000);
240         regulator_enable(dcdc);
241         printk("%s set dcdc1 vdd_core(vdd_log)=%dmV end\n", __func__, regulator_get_voltage(dcdc));
242         regulator_put(dcdc);
243         udelay(100);
244
245         dcdc = regulator_get(NULL, "dcdc3");    // vcc_ddr
246         regulator_set_voltage(dcdc, 1150000, 1150000);
247         regulator_set_suspend_voltage(dcdc, 1150000);
248         regulator_enable(dcdc);
249 //      printk("%s set dcdc3 vcc_ddr=%dmV end\n", __func__, regulator_get_voltage(dcdc));
250         regulator_put(dcdc);
251         udelay(100);
252
253         ldo = regulator_get(NULL, "ldo7");      // vcc28_cif
254         regulator_set_voltage(ldo, 2800000, 2800000);
255         regulator_set_suspend_voltage(ldo, 2800000);
256         regulator_enable(ldo);
257 //      printk("%s set ldo7 vcc28_cif=%dmV end\n", __func__, regulator_get_voltage(ldo));
258         regulator_put(ldo);
259         udelay(100);
260
261         ldo = regulator_get(NULL, "ldo1");      // vcc18_cif
262         regulator_set_voltage(ldo, 1800000, 1800000);
263         regulator_set_suspend_voltage(ldo, 1800000);
264         regulator_enable(ldo);
265 //      printk("%s set ldo1 vcc18_cif=%dmV end\n", __func__, regulator_get_voltage(ldo));
266         regulator_put(ldo);
267         udelay(100);
268
269         ldo = regulator_get(NULL, "ldo8");      // vcca_33
270         regulator_set_voltage(ldo, 3300000, 3300000);
271         regulator_set_suspend_voltage(ldo, 3300000);
272         regulator_enable(ldo);
273 //      printk("%s set ldo8 vcca_33=%dmV end\n", __func__, regulator_get_voltage(ldo));
274         regulator_put(ldo);
275         udelay(100);
276
277         ldo = regulator_get(NULL, "ldo2");      //vccio_wl
278         regulator_set_voltage(ldo, 1800000, 1800000);
279         regulator_set_suspend_voltage(ldo, 1800000);
280         regulator_enable(ldo);
281 //      printk("%s set ldo2 vccio_wl=%dmV end\n", __func__, regulator_get_voltage(ldo));
282         regulator_put(ldo);
283         udelay(100);
284
285         ldo = regulator_get(NULL, "ldo10");     //flash io
286         regulator_set_voltage(ldo, 1800000, 1800000);
287         regulator_set_suspend_voltage(ldo, 1800000);
288         regulator_enable(ldo);
289 //      printk("%s set ldo10 vcca_wl=%dmV end\n", __func__, regulator_get_voltage(ldo));
290         regulator_put(ldo);
291         udelay(100);
292
293 #ifdef CONFIG_MACH_RK3066_SDK
294         ldo = regulator_get(NULL, "ldo3");      //vdd11_hdmi
295         regulator_set_voltage(ldo, 1100000, 1100000);
296         regulator_set_suspend_voltage(ldo, 1100000);
297 #else
298         ldo = regulator_get(NULL, "ldo3");      //vdd_12
299         regulator_set_voltage(ldo, 1200000, 1200000);
300         regulator_set_suspend_voltage(ldo, 1200000);
301 #endif
302         regulator_enable(ldo);
303 //      printk("%s set ldo3 vdd_12=%dmV end\n", __func__, regulator_get_voltage(ldo));
304         regulator_put(ldo);
305         udelay(100);
306
307         ldo = regulator_get(NULL, "ldo9");      //vcc_tp
308         regulator_set_voltage(ldo, 3300000, 3300000);
309         regulator_set_suspend_voltage(ldo, 3300000);
310         regulator_enable(ldo);
311 //      printk("%s set ldo9 vcc_tp=%dmV end\n", __func__, regulator_get_voltage(ldo));
312         regulator_put(ldo);
313         udelay(100);
314
315         wm831x_mask_interrupt(Wm831x);
316
317         #ifdef CONFIG_WM8326_VBAT_LOW_DETECTION
318         wm831x_low_power_detection(Wm831x);
319         #endif
320         
321         printk("wm831x_post_init end");
322         return 0;
323 }
324
325 static int wm831x_last_deinit(struct wm831x *Wm831x)
326 {
327         struct regulator *ldo;
328
329         printk("%s\n", __func__);
330         ldo = regulator_get(NULL, "ldo1");
331         regulator_disable(ldo);
332         regulator_put(ldo);
333
334         ldo = regulator_get(NULL, "ldo2");
335         regulator_disable(ldo);
336         regulator_put(ldo);
337
338         ldo = regulator_get(NULL, "ldo3");
339         regulator_disable(ldo);
340         regulator_put(ldo);
341
342         ldo = regulator_get(NULL, "ldo4");
343         //regulator_disable(ldo);
344         regulator_put(ldo);
345
346         ldo = regulator_get(NULL, "ldo5");
347 //      regulator_disable(ldo);
348         regulator_put(ldo);
349
350         ldo = regulator_get(NULL, "ldo6");
351 //      regulator_disable(ldo);
352         regulator_put(ldo);
353
354         ldo = regulator_get(NULL, "ldo7");
355         regulator_disable(ldo);
356         regulator_put(ldo);
357
358         ldo = regulator_get(NULL, "ldo8");
359         regulator_disable(ldo);
360         regulator_put(ldo);
361
362         ldo = regulator_get(NULL, "ldo9");
363         regulator_disable(ldo);
364         regulator_put(ldo);
365
366         ldo = regulator_get(NULL, "ldo10");
367         regulator_disable(ldo);
368         regulator_put(ldo);
369
370         return 0;
371 }
372
373 struct wm831x_status_pdata wm831x_status_platdata[WM831X_MAX_STATUS] = {
374         {
375                 .default_src = WM831X_STATUS_OTP,
376                 .name = "wm831x_status0",
377                 .default_trigger = "wm831x_otp",
378         },
379         {
380                 .default_src = WM831X_STATUS_POWER,
381                 .name = "wm831x_status1",
382                 .default_trigger = "wm831x_power",
383         },
384 };
385
386 static struct regulator_consumer_supply dcdc1_consumers[] = {
387         {
388                 .supply = "vdd_core",
389         }
390 };
391
392 static struct regulator_consumer_supply dcdc2_consumers[] = {
393         {
394                 .supply = "vdd_cpu",
395         }
396         
397 };
398
399 static struct regulator_consumer_supply dcdc3_consumers[] = {
400         {
401                 .supply = "dcdc3",
402         }
403 };
404
405 static struct regulator_consumer_supply dcdc4_consumers[] = {
406         {
407                 .supply = "dcdc4",
408         }
409 };
410
411 #if 0
412 static struct regulator_consumer_supply epe1_consumers[] = {
413         {
414                 .supply = "epe1",
415         }
416 };
417
418 static struct regulator_consumer_supply epe2_consumers[] = {
419         {
420                 .supply = "epe2",
421         }
422 };
423 #endif
424
425 static struct regulator_consumer_supply ldo1_consumers[] = {
426         {
427                 .supply = "ldo1",
428         }
429 };
430
431 static struct regulator_consumer_supply ldo2_consumers[] = {
432         {
433                 .supply = "ldo2",
434         }
435 };
436
437 static struct regulator_consumer_supply ldo3_consumers[] = {
438         {
439                 .supply = "ldo3",
440         }
441 };
442
443 static struct regulator_consumer_supply ldo4_consumers[] = {
444         {
445                 .supply = "ldo4",
446         }
447 };
448
449 static struct regulator_consumer_supply ldo5_consumers[] = {
450         {
451                 .supply = "ldo5",
452         }
453 };
454
455 static struct regulator_consumer_supply ldo6_consumers[] = {
456         {
457                 .supply = "ldo6",
458         }
459 };
460
461 static struct regulator_consumer_supply ldo7_consumers[] = {
462         {
463                 .supply = "ldo7",
464         }
465 };
466
467 static struct regulator_consumer_supply ldo8_consumers[] = {
468         {
469                 .supply = "ldo8",
470         }
471 };
472
473 static struct regulator_consumer_supply ldo9_consumers[] = {
474         {
475                 .supply = "ldo9",
476         }
477 };
478
479 static struct regulator_consumer_supply ldo10_consumers[] = {
480         {
481                 .supply = "ldo10",
482         }
483 };
484
485 static struct regulator_consumer_supply ldo11_consumers[] = {
486         {
487                 .supply = "ldo11",
488         }
489 };
490
491 struct regulator_init_data wm831x_regulator_init_dcdc[WM831X_MAX_DCDC] = {
492         {
493                 .constraints = {
494                         .name = "DCDC1",
495                         .min_uV = 600000,
496                         .max_uV = 1800000,      //0.6-1.8V
497                         .apply_uV = true,
498                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
499                 },
500                 .num_consumer_supplies = ARRAY_SIZE(dcdc1_consumers),
501                 .consumer_supplies = dcdc1_consumers,
502         },
503         {
504                 .constraints = {
505                         .name = "DCDC2",
506                         .min_uV = 600000,
507                         .max_uV = 1800000,      //0.6-1.8V
508                         .apply_uV = true,
509                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
510                 },
511                 .num_consumer_supplies = ARRAY_SIZE(dcdc2_consumers),
512                 .consumer_supplies = dcdc2_consumers,
513         },
514         {
515                 .constraints = {
516                         .name = "DCDC3",
517                         .min_uV = 850000,
518                         .max_uV = 3400000,      //0.85-3.4V
519                         .apply_uV = true,
520                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
521                 },
522                 .num_consumer_supplies = ARRAY_SIZE(dcdc3_consumers),
523                 .consumer_supplies = dcdc3_consumers,
524         },
525         {
526                 .constraints = {
527                         .name = "DCDC4",
528                         .min_uV = 850000,
529                         .max_uV = 3400000,      //0.85-3.4V
530                         .apply_uV = true,
531                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
532                 },
533                 .num_consumer_supplies = ARRAY_SIZE(dcdc4_consumers),
534                 .consumer_supplies = dcdc4_consumers,
535         },
536 };
537
538 #if 0
539 struct regulator_init_data wm831x_regulator_init_epe[WM831X_MAX_EPE] = {
540         {
541                 .constraints = {
542                         .name = "EPE1",
543                         .min_uV = 1200000,
544                         .max_uV = 3000000,
545                         .apply_uV = true,
546                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
547                 },
548                 .num_consumer_supplies = ARRAY_SIZE(epe1_consumers),
549                 .consumer_supplies = epe1_consumers,
550         },
551         {
552                 .constraints = {
553                         .name = "EPE2",
554                         .min_uV = 1200000,
555                         .max_uV = 3000000,
556                         .apply_uV = true,
557                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
558                 },
559                 .num_consumer_supplies = ARRAY_SIZE(epe2_consumers),
560                 .consumer_supplies = epe2_consumers,
561         },
562 };
563 #endif
564
565 struct regulator_init_data wm831x_regulator_init_ldo[WM831X_MAX_LDO] = {
566         {
567                 .constraints = {
568                         .name = "LDO1",
569                         .min_uV = 900000,
570                         .max_uV = 3300000,
571                         .apply_uV = true,
572                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
573                 },
574                 .num_consumer_supplies = ARRAY_SIZE(ldo1_consumers),
575                 .consumer_supplies = ldo1_consumers,
576         },
577         {
578                 .constraints = {
579                         .name = "LDO2",
580                         .min_uV = 900000,
581                         .max_uV = 3300000,
582                         .apply_uV = true,
583                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
584                 },
585                 .num_consumer_supplies = ARRAY_SIZE(ldo2_consumers),
586                 .consumer_supplies = ldo2_consumers,
587         },
588         {
589                 .constraints = {
590                         .name = "LDO3",
591                         .min_uV = 900000,
592                         .max_uV = 3300000,
593                         .apply_uV = true,
594                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
595                 },
596                 .num_consumer_supplies = ARRAY_SIZE(ldo3_consumers),
597                 .consumer_supplies = ldo3_consumers,
598         },
599         {
600                 .constraints = {
601                         .name = "LDO4",
602                         .min_uV = 900000,
603                         .max_uV = 3300000,
604                         .apply_uV = true,
605                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
606                 },
607                 .num_consumer_supplies = ARRAY_SIZE(ldo4_consumers),
608                 .consumer_supplies = ldo4_consumers,
609         },
610         {
611                 .constraints = {
612                         .name = "LDO5",
613                         .min_uV = 900000,
614                         .max_uV = 3300000,
615                         .apply_uV = true,
616                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
617                 },
618                 .num_consumer_supplies = ARRAY_SIZE(ldo5_consumers),
619                 .consumer_supplies = ldo5_consumers,
620         },
621         {
622                 .constraints = {
623                         .name = "LDO6",
624                         .min_uV = 900000,
625                         .max_uV = 3300000,
626                         .apply_uV = true,
627                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
628                 },
629                 .num_consumer_supplies = ARRAY_SIZE(ldo6_consumers),
630                 .consumer_supplies = ldo6_consumers,
631         },
632         {
633                 .constraints = {
634                         .name = "LDO7",
635                         .min_uV = 1000000,
636                         .max_uV = 3500000,
637                         .apply_uV = true,
638                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
639                 },
640                 .num_consumer_supplies = ARRAY_SIZE(ldo7_consumers),
641                 .consumer_supplies = ldo7_consumers,
642         },
643         {
644                 .constraints = {
645                         .name = "LDO8",
646                         .min_uV = 1000000,
647                         .max_uV = 3500000,
648                         .apply_uV = true,
649                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
650                 },
651                 .num_consumer_supplies = ARRAY_SIZE(ldo8_consumers),
652                 .consumer_supplies = ldo8_consumers,
653         },
654         {
655                 .constraints = {
656                         .name = "LDO9",
657                         .min_uV = 1000000,
658                         .max_uV = 3500000,
659                         .apply_uV = true,
660                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
661                 },
662                 .num_consumer_supplies = ARRAY_SIZE(ldo9_consumers),
663                 .consumer_supplies = ldo9_consumers,
664         },
665         {
666                 .constraints = {
667                         .name = "LDO10",
668                         .min_uV = 1000000,
669                         .max_uV = 3500000,
670                         .apply_uV = true,
671                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
672                 },
673                 .num_consumer_supplies = ARRAY_SIZE(ldo10_consumers),
674                 .consumer_supplies = ldo10_consumers,
675         },
676         {
677                 .constraints = {
678                         .name = "LDO11",
679                         .min_uV = 800000,
680                         .max_uV = 1550000,
681                         .apply_uV = true,
682                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
683                 },
684                 .num_consumer_supplies = ARRAY_SIZE(ldo11_consumers),
685                 .consumer_supplies = ldo11_consumers,
686         },
687 };
688
689 static int wm831x_init_pin_type(struct wm831x *wm831x)
690 {
691         struct wm831x_pdata *pdata;
692         struct rk29_gpio_expander_info *wm831x_gpio_settinginfo;
693         uint16_t wm831x_settingpin_num;
694         int i;
695
696         if (!wm831x || !wm831x->dev)
697                 goto out;
698
699         pdata = wm831x->dev->platform_data;
700         if (!pdata)
701                 goto out;
702
703         wm831x_gpio_settinginfo = pdata->settinginfo;
704         if (!wm831x_gpio_settinginfo)
705                 goto out;
706
707         wm831x_settingpin_num = pdata->settinginfolen;
708         for (i = 0; i < wm831x_settingpin_num; i++) {
709                 if (wm831x_gpio_settinginfo[i].pin_type == GPIO_IN) {
710                         wm831x_set_bits(wm831x,
711                                         WM831X_GPIO1_CONTROL + i,
712                                         WM831X_GPN_DIR_MASK | WM831X_GPN_TRI_MASK,
713                                         1 << WM831X_GPN_DIR_SHIFT | 1 << WM831X_GPN_TRI_SHIFT);
714                 if (i == 1) {
715                                 wm831x_set_bits(wm831x,
716                                                 WM831X_GPIO1_CONTROL + i,
717                                                 WM831X_GPN_POL_MASK,
718                                                 0x0400);
719                                 wm831x_set_bits(wm831x,
720                                                 WM831X_GPIO1_CONTROL + i,
721                                                 WM831X_GPN_FN_MASK,
722                                                 0x0003);                                
723                         }       // set gpio2 sleep/wakeup
724                         
725                 if (i == 9) {
726                                 wm831x_set_bits(wm831x,
727                                                 WM831X_GPIO1_CONTROL + i,
728                                                 WM831X_GPN_PULL_MASK,
729                                                 0x0000);      //disable pullup/down
730                                 wm831x_set_bits(wm831x,
731                                                 WM831X_GPIO1_CONTROL + i,
732                                                 WM831X_GPN_PWR_DOM_MASK,
733                                                 0x0800); 
734                                 wm831x_set_bits(wm831x,
735                                                 WM831X_GPIO1_CONTROL + i,
736                                                 WM831X_GPN_ENA_MASK,
737                                                 0x0000); 
738                         }  //set gpio10 as adc input
739                                         
740                 } else {
741                         wm831x_set_bits(wm831x,
742                                         WM831X_GPIO1_CONTROL + i,
743                                         WM831X_GPN_DIR_MASK | WM831X_GPN_TRI_MASK,
744                                         1 << WM831X_GPN_TRI_SHIFT);
745                         if (wm831x_gpio_settinginfo[i].pin_value == GPIO_HIGH) {
746                                 wm831x_set_bits(wm831x, WM831X_GPIO_LEVEL, 1 << i, 1 << i);
747                         } else {
748                                 wm831x_set_bits(wm831x, WM831X_GPIO_LEVEL, 1 << i, 0 << i);
749                         }
750                         if (i == 2) {
751                                 wm831x_set_bits(wm831x,
752                                                 WM831X_GPIO1_CONTROL + i,
753                                                 WM831X_GPN_PWR_DOM_MASK | WM831X_GPN_POL_MASK |WM831X_GPN_FN_MASK,
754                                                 1 << WM831X_GPN_POL_SHIFT | 1 << WM831X_GPN_PWR_DOM_SHIFT | 1 << 0);
755
756                         }       // set gpio3 as clkout output 32.768K
757                         
758                 }
759         }
760
761 #if 0
762         for (i = 0; i < pdata->gpio_pin_num; i++) {
763                 wm831x_set_bits(wm831x,
764                                 WM831X_GPIO1_CONTROL + i,
765                                 WM831X_GPN_PULL_MASK | WM831X_GPN_POL_MASK | WM831X_GPN_OD_MASK | WM831X_GPN_TRI_MASK,
766                                 1 << WM831X_GPN_POL_SHIFT | 1 << WM831X_GPN_TRI_SHIFT);
767
768                 ret = wm831x_reg_read(wm831x, WM831X_GPIO1_CONTROL + i);
769                 printk("Gpio%d Pin Configuration = %x\n", i, ret);
770         }
771 #endif
772
773 out:
774         return 0;
775 }
776
777 void __sramfunc board_pmu_suspend(void)
778 {       
779         cru_writel(CRU_CLKGATE5_GRFCLK_ON,CRU_CLKGATE5_CON_ADDR); //open grf clk
780         grf_writel(GPIO6_PB1_DIR_OUT, GRF_GPIO6L_DIR_ADDR);
781         grf_writel(GPIO6_PB1_DO_HIGH, GRF_GPIO6L_DO_ADDR);  //set gpio6_b1 output low
782         grf_writel(GPIO6_PB1_EN_MASK, GRF_GPIO6L_EN_ADDR);
783 }
784 void __sramfunc board_pmu_resume(void)
785 {
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 high
788         grf_writel(GPIO6_PB1_EN_MASK, GRF_GPIO6L_EN_ADDR);
789 #ifdef CONFIG_CLK_SWITCH_TO_32K
790         sram_32k_udelay(10000);
791 #else
792         sram_udelay(10000);
793 #endif
794 }
795 static struct wm831x_pdata wm831x_platdata = {
796
797         /** Called before subdevices are set up */
798         .pre_init = wm831x_pre_init,
799         /** Called after subdevices are set up */
800         .post_init = wm831x_post_init,
801         /** Called before subdevices are power down */
802         .last_deinit = wm831x_last_deinit,
803
804 #if defined(CONFIG_GPIO_WM831X)
805         .gpio_base = WM831X_GPIO_EXPANDER_BASE,
806         .gpio_pin_num = WM831X_TOTOL_GPIO_NUM,
807         .settinginfo = wm831x_gpio_settinginfo,
808         .settinginfolen = ARRAY_SIZE(wm831x_gpio_settinginfo),
809         .pin_type_init = wm831x_init_pin_type,
810         .irq_base = IRQ_BOARD_BASE,
811 #endif
812
813         /** LED1 = 0 and so on */
814         .status = { &wm831x_status_platdata[0], &wm831x_status_platdata[1] },
815
816         /** DCDC1 = 0 and so on */
817         .dcdc = {
818                 &wm831x_regulator_init_dcdc[0],
819                 &wm831x_regulator_init_dcdc[1],
820                 &wm831x_regulator_init_dcdc[2],
821                 &wm831x_regulator_init_dcdc[3],
822         },
823
824         /** EPE1 = 0 and so on */
825         //.epe = { &wm831x_regulator_init_epe[0], &wm831x_regulator_init_epe[1] },
826
827         /** LDO1 = 0 and so on */
828         .ldo = {
829                 &wm831x_regulator_init_ldo[0],
830                 &wm831x_regulator_init_ldo[1],
831                 &wm831x_regulator_init_ldo[2],
832                 &wm831x_regulator_init_ldo[3],
833                 &wm831x_regulator_init_ldo[4],
834                 &wm831x_regulator_init_ldo[5],
835                 &wm831x_regulator_init_ldo[6],
836                 &wm831x_regulator_init_ldo[7],
837                 &wm831x_regulator_init_ldo[8],
838                 &wm831x_regulator_init_ldo[9],
839                 &wm831x_regulator_init_ldo[10],
840         },
841 };
842 #endif