ARM64: DTS: Add rk3399-firefly uart4 device, node as /dev/ttyS1
[firefly-linux-kernel-4.4.55.git] / board-rk30-phone-wm831x.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
6 /* wm8326 pmu*/
7 #if defined(CONFIG_GPIO_WM831X)
8 static struct rk29_gpio_expander_info wm831x_gpio_settinginfo[] = {
9         {
10                 .gpio_num = WM831X_P01, // tp3
11                 .pin_type = GPIO_IN,
12         },
13         {
14                 .gpio_num = WM831X_P02, //tp4
15                 .pin_type = GPIO_IN,
16         },
17         {
18                 .gpio_num = WM831X_P03, //tp2
19                 .pin_type = GPIO_OUT,
20                 .pin_value = GPIO_HIGH,
21         },
22         {
23                 .gpio_num = WM831X_P04, //tp1
24                 .pin_type = GPIO_IN,
25         },
26         {
27                 .gpio_num = WM831X_P05, //tp1
28                 .pin_type = GPIO_IN,
29         },
30         {
31                 .gpio_num = WM831X_P06, //tp1
32                 .pin_type = GPIO_OUT,
33                 .pin_value = GPIO_HIGH,
34         },
35         {
36                 .gpio_num = WM831X_P07, //tp1
37                 .pin_type = GPIO_IN,
38         },
39         {
40                 .gpio_num = WM831X_P08, //tp1
41                 .pin_type = GPIO_OUT,
42                 .pin_value = GPIO_HIGH,
43         },
44         {
45                 .gpio_num = WM831X_P09, //tp1
46                 .pin_type = GPIO_OUT,
47                 .pin_value = GPIO_HIGH,
48         },
49         {
50                 .gpio_num = WM831X_P10, //tp1
51                 .pin_type = GPIO_IN,
52         },
53         {
54                 .gpio_num = WM831X_P11, //tp1
55                 .pin_type = GPIO_OUT,
56                 .pin_value = GPIO_HIGH,
57         },
58         {
59                 .gpio_num = WM831X_P12,
60                 .pin_type = GPIO_OUT,
61                 .pin_value = GPIO_HIGH,
62         },
63 };
64 #endif
65
66 #if defined(CONFIG_MFD_WM831X)
67
68 #define UNLOCK_SECURITY_KEY     ~(0x1<<5)
69 #define LOCK_SECURITY_KEY       0x00
70 #define PMU_POWER_SLEEP RK30_PIN6_PB1
71 static struct wm831x *Wm831x;
72
73 static int wm831x_pre_init(struct wm831x *parm)
74 {
75         int ret;
76         Wm831x = parm;
77 //      printk("%s\n", __func__);
78         gpio_request(PMU_POWER_SLEEP, "NULL");
79         gpio_direction_output(PMU_POWER_SLEEP, GPIO_HIGH);
80         
81         ret = wm831x_reg_read(parm, WM831X_POWER_STATE) & 0xffff;
82         wm831x_reg_write(parm, WM831X_POWER_STATE, (ret & 0xfff8) | 0x04);
83
84         //BATT_FET_ENA = 1
85         wm831x_reg_write(parm, WM831X_SECURITY_KEY, 0x9716);    // unlock security key
86         wm831x_set_bits(parm, WM831X_RESET_CONTROL, 0x1000, 0x1000);
87         ret = wm831x_reg_read(parm, WM831X_RESET_CONTROL) & 0xffff & UNLOCK_SECURITY_KEY;       // enternal reset active in sleep
88 //      printk("%s:WM831X_RESET_CONTROL=0x%x\n", __func__, ret);
89         wm831x_reg_write(parm, WM831X_RESET_CONTROL, ret);
90
91         wm831x_set_bits(parm,WM831X_DC1_ON_CONFIG ,0x0300,0x0000); //set dcdc mode is FCCM
92         wm831x_set_bits(parm,WM831X_DC2_ON_CONFIG ,0x0300,0x0000);
93         wm831x_set_bits(parm,WM831X_DC3_ON_CONFIG ,0x0300,0x0000);
94 //      wm831x_set_bits(parm,0x4066,0x0300,0x0000);
95
96 //      wm831x_set_bits(parm,WM831X_LDO10_CONTROL ,0x0040,0x0040);// set ldo10 in switch mode
97
98         wm831x_set_bits(parm,WM831X_STATUS_LED_1 ,0xc300,0xc100);// set led1 on(in manual mode)
99         wm831x_set_bits(parm,WM831X_STATUS_LED_2 ,0xc300,0xc000);//set led2 off(in manual mode)
100
101         wm831x_reg_write(parm, WM831X_SECURITY_KEY, LOCK_SECURITY_KEY); // lock security key
102
103         return 0;
104 }
105
106 int wm831x_post_init(struct wm831x *Wm831x)
107 {
108         struct regulator *dcdc;
109         struct regulator *ldo;
110
111
112         ldo = regulator_get(NULL, "ldo8");      //vcca33
113         regulator_set_voltage(ldo, 3300000, 3300000);
114         regulator_set_suspend_voltage(ldo, 3300000);
115         regulator_enable(ldo);
116 //      printk("%s set ldo8 vcca33=%dmV end\n", __func__, regulator_get_voltage(ldo));
117         regulator_put(ldo);
118         udelay(100);
119         
120         ldo = regulator_get(NULL, "ldo3");      // vdd_11
121         regulator_set_voltage(ldo, 1100000, 1100000);
122         regulator_set_suspend_voltage(ldo, 1100000);
123         regulator_enable(ldo);
124 //      printk("%s set ldo3 vdd_11=%dmV end\n", __func__, regulator_get_voltage(ldo));
125         regulator_put(ldo);
126         udelay(100);
127
128         dcdc = regulator_get(NULL, "dcdc3");    // vcc_io
129         regulator_set_voltage(dcdc, 3000000, 3000000);
130         regulator_set_suspend_voltage(dcdc, 3000000);
131         regulator_enable(dcdc);
132 //      printk("%s set dcdc3 vcc_io=%dmV end\n", __func__, regulator_get_voltage(dcdc));
133         regulator_put(dcdc);
134         udelay(100);
135
136         ldo = regulator_get(NULL, "ldo4");      //vdd_usb11
137         regulator_set_voltage(ldo, 1100000, 1100000);
138         regulator_set_suspend_voltage(ldo, 1100000);
139         regulator_enable(ldo);
140 //      printk("%s set ldo4 vdd_usb11=%dmV end\n", __func__, regulator_get_voltage(ldo));
141         regulator_put(ldo);
142
143         ldo = regulator_get(NULL, "ldo5");      //vcc_25
144         regulator_set_voltage(ldo, 2500000, 2500000);
145         regulator_set_suspend_voltage(ldo, 2500000);
146         regulator_enable(ldo);
147 //      printk("%s set ldo5 vcc_25=%dmV end\n", __func__, regulator_get_voltage(ldo));
148         regulator_put(ldo);
149
150
151         ldo = regulator_get(NULL, "ldo10");     //vcc_usb33
152         regulator_set_voltage(ldo, 3300000, 3300000);
153         regulator_set_suspend_voltage(ldo, 3300000);
154         regulator_enable(ldo);
155 //      printk("%s set ldo10 vcc_usb33=%dmV end\n", __func__, regulator_get_voltage(ldo));
156         regulator_put(ldo);
157
158         dcdc = regulator_get(NULL, "dcdc1");    // vcc_lpddr2_1v8
159         regulator_set_voltage(dcdc, 1800000, 1800000);
160         regulator_set_suspend_voltage(dcdc, 1800000);
161         regulator_enable(dcdc);
162         printk("%s set dcdc1 vcc_lpddr2_1v8=%dmV end\n", __func__, regulator_get_voltage(dcdc));
163         regulator_put(dcdc);
164         udelay(100);
165
166         dcdc = regulator_get(NULL, "dcdc2");    // vcc_lpddr2_1v2
167         regulator_set_voltage(dcdc, 1200000, 1200000);
168         regulator_set_suspend_voltage(dcdc, 1200000);
169         regulator_enable(dcdc);
170         printk("%s set dcdc2 vcc_lpddr2_1v2=%dmV end\n", __func__, regulator_get_voltage(dcdc));
171         regulator_put(dcdc);
172         udelay(100);
173         
174         ldo = regulator_get(NULL, "ldo2");      // vcc_emmc3v3
175         regulator_set_voltage(ldo, 3000000, 3000000);
176         regulator_set_suspend_voltage(ldo, 3000000);
177         regulator_enable(ldo);
178 //      printk("%s set ldo2 vcc_emmc3v3=%dmV end\n", __func__, regulator_get_voltage(ldo));
179         regulator_put(ldo);
180         udelay(100);
181
182         ldo = regulator_get(NULL, "ldo6");      // vcc_codec18
183         regulator_set_voltage(ldo, 1800000, 1800000);
184         regulator_set_suspend_voltage(ldo, 1800000);
185         regulator_enable(ldo);
186 //      printk("%s set ldo6 vcc_codec18=%dmV end\n", __func__, regulator_get_voltage(ldo));
187         regulator_put(ldo);
188         udelay(100);
189
190         ldo = regulator_get(NULL, "ldo1");      // vcc_lcd
191         regulator_set_voltage(ldo, 3000000, 3000000);
192         regulator_set_suspend_voltage(ldo, 3000000);
193         regulator_enable(ldo);
194 //      printk("%s set ldo1 vcc_lcd=%dmV end\n", __func__, regulator_get_voltage(ldo));
195         regulator_put(ldo);
196         udelay(100);
197 #if 0 
198
199         ldo = regulator_get(NULL, "ldo7");      //vdd_mtv_1v2
200         regulator_set_voltage(ldo, 1200000, 1200000);
201         regulator_set_suspend_voltage(ldo, 1200000);
202         regulator_enable(ldo);
203 //      printk("%s set ldo7 vdd_mtv_1v2=%dmV end\n", __func__, regulator_get_voltage(ldo));
204         regulator_put(ldo);
205         udelay(100);
206         
207         ldo = regulator_get(NULL, "ldo9");      //vdd_mtv_3v
208         regulator_set_voltage(ldo, 3000000, 3000000);
209         regulator_set_suspend_voltage(ldo, 3000000);
210         regulator_enable(ldo);
211 //      printk("%s set ldo9 vdd_mtv_3v=%dmV end\n", __func__, regulator_get_voltage(ldo));
212         regulator_put(ldo);
213         udelay(100);
214 #endif
215
216 //discrete dcdc device
217 #ifdef CONFIG_RK30_PWM_REGULATOR
218         dcdc = regulator_get(NULL, "vdd_core"); // vdd_log
219         regulator_set_voltage(dcdc, 1050000, 1050000);
220         regulator_enable(dcdc);
221         printk("%s set vdd_core=%dmV end\n", __func__, regulator_get_voltage(dcdc));
222         regulator_put(dcdc);
223         udelay(100);
224
225         dcdc = regulator_get(NULL, "vdd_cpu");  // vdd_arm
226         regulator_set_voltage(dcdc, 1100000, 1100000);
227         regulator_enable(dcdc);
228         printk("%s set vdd_cpu=%dmV end\n", __func__, regulator_get_voltage(dcdc));
229         regulator_put(dcdc);
230         udelay(100);
231 #endif
232         printk("wm831x_post_init end");
233         return 0;
234 }
235
236 static int wm831x_last_deinit(struct wm831x *Wm831x)
237 {
238         struct regulator *ldo;
239
240         printk("%s\n", __func__);
241         ldo = regulator_get(NULL, "ldo1");
242         regulator_disable(ldo);
243         regulator_put(ldo);
244
245         ldo = regulator_get(NULL, "ldo2");
246         regulator_disable(ldo);
247         regulator_put(ldo);
248
249         ldo = regulator_get(NULL, "ldo3");
250         //regulator_disable(ldo);
251         regulator_put(ldo);
252
253         ldo = regulator_get(NULL, "ldo4");
254         regulator_disable(ldo);
255         regulator_put(ldo);
256
257         ldo = regulator_get(NULL, "ldo5");
258         //regulator_disable(ldo);
259         regulator_put(ldo);
260
261         ldo = regulator_get(NULL, "ldo6");
262         regulator_disable(ldo);
263         regulator_put(ldo);
264
265         ldo = regulator_get(NULL, "ldo7");
266         regulator_disable(ldo);
267         regulator_put(ldo);
268
269         ldo = regulator_get(NULL, "ldo8");
270         //regulator_disable(ldo);
271         regulator_put(ldo);
272
273         ldo = regulator_get(NULL, "ldo9");
274         regulator_disable(ldo);
275         regulator_put(ldo);
276
277         ldo = regulator_get(NULL, "ldo10");
278         regulator_disable(ldo);
279         regulator_put(ldo);
280
281         return 0;
282 }
283
284 struct wm831x_backlight_pdata wm831x_backlight_platdata = {
285         .isink = 1,     /** ISINK to use, 1 or 2 */
286         .max_uA = 19484,    /** Maximum current to allow */
287 };
288
289 struct wm831x_backup_pdata wm831x_backup_platdata = {
290         .charger_enable = 1,
291         .no_constant_voltage = 0,  /** Disable constant voltage charging */
292         .vlim = 3100,   /** Voltage limit in milivolts */
293         .ilim = 300,   /** Current limit in microamps */
294 };
295
296 struct wm831x_battery_pdata wm831x_battery_platdata = {
297         .enable = 1,         /** Enable charging */
298         .fast_enable = 1,    /** Enable fast charging */
299         .off_mask = 1,       /** Mask OFF while charging */
300         .trickle_ilim = 200,   /** Trickle charge current limit, in mA */
301         .vsel = 4200,           /** Target voltage, in mV */
302         .eoc_iterm = 50,      /** End of trickle charge current, in mA */
303         .fast_ilim = 500,      /** Fast charge current limit, in mA */
304         .timeout = 480,        /** Charge cycle timeout, in minutes */
305         .syslo = 3300,    /* syslo threshold, in mV*/
306         .sysok = 3500,    /* sysko threshold, in mV*/
307 };
308
309 struct wm831x_status_pdata wm831x_status_platdata[WM831X_MAX_STATUS] = {
310         {
311                 .default_src = WM831X_STATUS_OTP,
312                 .name = "wm831x_status0",
313                 .default_trigger = "wm831x_otp",
314         },
315         {
316                 .default_src = WM831X_STATUS_POWER,
317                 .name = "wm831x_status1",
318                 .default_trigger = "wm831x_power",
319         },
320 };
321
322 static struct regulator_consumer_supply dcdc1_consumers[] = {
323         {
324                 .supply = "dcdc1",
325         }
326 };
327
328 static struct regulator_consumer_supply dcdc2_consumers[] = {
329         {
330                 .supply = "dcdc2",
331         }
332         
333 };
334
335 static struct regulator_consumer_supply dcdc3_consumers[] = {
336         {
337                 .supply = "dcdc3",
338         }
339 };
340
341 static struct regulator_consumer_supply dcdc4_consumers[] = {
342         {
343                 .supply = "dcdc4",
344         }
345 };
346
347
348 static struct regulator_consumer_supply epe1_consumers[] = {
349         {
350                 .supply = "epe1",
351         }
352 };
353
354 static struct regulator_consumer_supply epe2_consumers[] = {
355         {
356                 .supply = "epe2",
357         }
358 };
359
360
361 static struct regulator_consumer_supply ldo1_consumers[] = {
362         {
363                 .supply = "ldo1",
364         }
365 };
366
367 static struct regulator_consumer_supply ldo2_consumers[] = {
368         {
369                 .supply = "ldo2",
370         }
371 };
372
373 static struct regulator_consumer_supply ldo3_consumers[] = {
374         {
375                 .supply = "ldo3",
376         }
377 };
378
379 static struct regulator_consumer_supply ldo4_consumers[] = {
380         {
381                 .supply = "ldo4",
382         }
383 };
384
385 static struct regulator_consumer_supply ldo5_consumers[] = {
386         {
387                 .supply = "ldo5",
388         }
389 };
390
391 static struct regulator_consumer_supply ldo6_consumers[] = {
392         {
393                 .supply = "ldo6",
394         }
395 };
396
397 static struct regulator_consumer_supply ldo7_consumers[] = {
398         {
399                 .supply = "ldo7",
400         }
401 };
402
403 static struct regulator_consumer_supply ldo8_consumers[] = {
404         {
405                 .supply = "ldo8",
406         }
407 };
408
409 static struct regulator_consumer_supply ldo9_consumers[] = {
410         {
411                 .supply = "ldo9",
412         }
413 };
414
415 static struct regulator_consumer_supply ldo10_consumers[] = {
416         {
417                 .supply = "ldo10",
418         }
419 };
420
421 static struct regulator_consumer_supply ldo11_consumers[] = {
422         {
423                 .supply = "ldo11",
424         }
425 };
426
427 static struct regulator_consumer_supply isink1_consumers[] = {
428         {
429                 .supply = "isink1",
430         }
431 };
432 static struct regulator_consumer_supply isink2_consumers[] = {
433         {
434                 .supply = "isink2",
435         }
436 };
437 struct regulator_init_data wm831x_regulator_init_dcdc[WM831X_MAX_DCDC] = {
438         {
439                 .constraints = {
440                         .name = "DCDC1",
441                         .min_uV = 600000,
442                         .max_uV = 1800000,      //0.6-1.8V
443                         .apply_uV = true,
444                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
445                 },
446                 .num_consumer_supplies = ARRAY_SIZE(dcdc1_consumers),
447                 .consumer_supplies = dcdc1_consumers,
448         },
449         {
450                 .constraints = {
451                         .name = "DCDC2",
452                         .min_uV = 600000,
453                         .max_uV = 1800000,      //0.6-1.8V
454                         .apply_uV = true,
455                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
456                 },
457                 .num_consumer_supplies = ARRAY_SIZE(dcdc2_consumers),
458                 .consumer_supplies = dcdc2_consumers,
459         },
460         {
461                 .constraints = {
462                         .name = "DCDC3",
463                         .min_uV = 850000,
464                         .max_uV = 3400000,      //0.85-3.4V
465                         .apply_uV = true,
466                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
467                 },
468                 .num_consumer_supplies = ARRAY_SIZE(dcdc3_consumers),
469                 .consumer_supplies = dcdc3_consumers,
470         },
471         {
472                 .constraints = {
473                         .name = "DCDC4",
474                         .min_uV = 00000000,
475                         .max_uV = 30000000,//30V/40mA
476                         .apply_uV = true,               
477                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
478                 },
479                 .num_consumer_supplies = ARRAY_SIZE(dcdc4_consumers),
480                 .consumer_supplies = dcdc4_consumers,
481         },
482 };
483
484 struct regulator_init_data wm831x_regulator_init_epe[WM831X_MAX_EPE] = {
485         {
486                 .constraints = {
487                         .name = "EPE1",
488                         .min_uV = 1200000,
489                         .max_uV = 3000000,
490                         .apply_uV = true,
491                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
492                 },
493                 .num_consumer_supplies = ARRAY_SIZE(epe1_consumers),
494                 .consumer_supplies = epe1_consumers,
495         },
496         {
497                 .constraints = {
498                         .name = "EPE2",
499                         .min_uV = 1200000,
500                         .max_uV = 3000000,
501                         .apply_uV = true,
502                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
503                 },
504                 .num_consumer_supplies = ARRAY_SIZE(epe2_consumers),
505                 .consumer_supplies = epe2_consumers,
506         },
507 };
508
509
510 struct regulator_init_data wm831x_regulator_init_ldo[WM831X_MAX_LDO] = {
511         {
512                 .constraints = {
513                         .name = "LDO1",
514                         .min_uV = 900000,
515                         .max_uV = 3300000,
516                         .apply_uV = true,
517                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
518                 },
519                 .num_consumer_supplies = ARRAY_SIZE(ldo1_consumers),
520                 .consumer_supplies = ldo1_consumers,
521         },
522         {
523                 .constraints = {
524                         .name = "LDO2",
525                         .min_uV = 900000,
526                         .max_uV = 3300000,
527                         .apply_uV = true,
528                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
529                 },
530                 .num_consumer_supplies = ARRAY_SIZE(ldo2_consumers),
531                 .consumer_supplies = ldo2_consumers,
532         },
533         {
534                 .constraints = {
535                         .name = "LDO3",
536                         .min_uV = 900000,
537                         .max_uV = 3300000,
538                         .apply_uV = true,
539                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
540                 },
541                 .num_consumer_supplies = ARRAY_SIZE(ldo3_consumers),
542                 .consumer_supplies = ldo3_consumers,
543         },
544         {
545                 .constraints = {
546                         .name = "LDO4",
547                         .min_uV = 900000,
548                         .max_uV = 3300000,
549                         .apply_uV = true,
550                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
551                 },
552                 .num_consumer_supplies = ARRAY_SIZE(ldo4_consumers),
553                 .consumer_supplies = ldo4_consumers,
554         },
555         {
556                 .constraints = {
557                         .name = "LDO5",
558                         .min_uV = 900000,
559                         .max_uV = 3300000,
560                         .apply_uV = true,
561                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
562                 },
563                 .num_consumer_supplies = ARRAY_SIZE(ldo5_consumers),
564                 .consumer_supplies = ldo5_consumers,
565         },
566         {
567                 .constraints = {
568                         .name = "LDO6",
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(ldo6_consumers),
575                 .consumer_supplies = ldo6_consumers,
576         },
577         {
578                 .constraints = {
579                         .name = "LDO7",
580                         .min_uV = 1000000,
581                         .max_uV = 3500000,
582                         .apply_uV = true,
583                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
584                 },
585                 .num_consumer_supplies = ARRAY_SIZE(ldo7_consumers),
586                 .consumer_supplies = ldo7_consumers,
587         },
588         {
589                 .constraints = {
590                         .name = "LDO8",
591                         .min_uV = 1000000,
592                         .max_uV = 3500000,
593                         .apply_uV = true,
594                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
595                 },
596                 .num_consumer_supplies = ARRAY_SIZE(ldo8_consumers),
597                 .consumer_supplies = ldo8_consumers,
598         },
599         {
600                 .constraints = {
601                         .name = "LDO9",
602                         .min_uV = 1000000,
603                         .max_uV = 3500000,
604                         .apply_uV = true,
605                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
606                 },
607                 .num_consumer_supplies = ARRAY_SIZE(ldo9_consumers),
608                 .consumer_supplies = ldo9_consumers,
609         },
610         {
611                 .constraints = {
612                         .name = "LDO10",
613                         .min_uV = 1000000,
614                         .max_uV = 3500000,
615                         .apply_uV = true,
616                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
617                 },
618                 .num_consumer_supplies = ARRAY_SIZE(ldo10_consumers),
619                 .consumer_supplies = ldo10_consumers,
620         },
621         {
622                 .constraints = {
623                         .name = "LDO11",
624                         .min_uV = 800000,
625                         .max_uV = 1550000,
626                         .apply_uV = true,
627                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
628                 },
629                 .num_consumer_supplies = ARRAY_SIZE(ldo11_consumers),
630                 .consumer_supplies = ldo11_consumers,
631         },
632 };
633 struct regulator_init_data wm831x_regulator_init_isink[WM831X_MAX_ISINK] = {
634         {
635                 .constraints = {
636                         .name = "ISINK1",
637                         .min_uA = 00000,
638                         .max_uA = 40000,
639                         .always_on = true,
640                         .apply_uV = true,               
641                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_CURRENT,           
642                 },
643                 .num_consumer_supplies = ARRAY_SIZE(isink1_consumers),
644                 .consumer_supplies = isink1_consumers,
645         },
646         {
647                 .constraints = {
648                         .name = "ISINK2",
649                         .min_uA = 0000000,
650                         .max_uA = 0000000,
651                         .apply_uV = false,              
652                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_CURRENT,           
653                 },
654                 .num_consumer_supplies = ARRAY_SIZE(isink2_consumers),
655                 .consumer_supplies = isink2_consumers,
656         },
657 };
658 static int wm831x_checkrange(int start,int num,int val)
659 {   
660         if((val<(start+num))&&(val>=start))
661                 return 0;
662         else 
663                 return -1;
664 }
665 static int wm831x_init_pin_type(struct wm831x *wm831x)
666 {
667         struct wm831x_pdata *pdata;
668         struct rk29_gpio_expander_info *wm831x_gpio_settinginfo;
669         uint16_t wm831x_settingpin_num;
670         int i;
671
672         if (!wm831x || !wm831x->dev)
673                 goto out;
674
675         pdata = wm831x->dev->platform_data;
676         if (!pdata)
677                 goto out;
678
679         wm831x_gpio_settinginfo = pdata->settinginfo;
680         if (!wm831x_gpio_settinginfo)
681                 goto out;
682
683         wm831x_settingpin_num = pdata->settinginfolen;
684         for (i = 0; i < wm831x_settingpin_num; i++) {
685                 if (wm831x_gpio_settinginfo[i].pin_type == GPIO_IN) {
686                         wm831x_set_bits(wm831x,
687                                         WM831X_GPIO1_CONTROL + i,
688                                         WM831X_GPN_DIR_MASK | WM831X_GPN_TRI_MASK,
689                                         1 << WM831X_GPN_DIR_SHIFT | 1 << WM831X_GPN_TRI_SHIFT);
690
691                         wm831x_set_bits(wm831x,
692                                         WM831X_GPIO1_CONTROL + i,
693                                         WM831X_GPN_PULL_MASK, 1 << WM831X_GPN_PULL_SHIFT);      //pull down
694                         if (i == 0 ) {
695                                 wm831x_set_bits(wm831x,
696                                                 WM831X_GPIO1_CONTROL + i,
697                                                 WM831X_GPN_PWR_DOM_MASK,
698                                                 WM831X_GPN_PWR_DOM);
699                         }       // set gpiox power domain
700                         else {
701                                 wm831x_set_bits(wm831x,
702                                                 WM831X_GPIO1_CONTROL + i,
703                                                 WM831X_GPN_PWR_DOM_MASK,
704                                                 ~WM831X_GPN_PWR_DOM);
705                         }
706                         if (i == 1) {
707                                 wm831x_set_bits(wm831x,
708                                                 WM831X_GPIO1_CONTROL + i,
709                                                 WM831X_GPN_POL_MASK,
710                                                 0x0000);
711                                 wm831x_set_bits(wm831x,
712                                                 WM831X_GPIO1_CONTROL + i,
713                                                 WM831X_GPN_FN_MASK,
714                                                 0x0004);                                
715                         }       // set gpio2 sleep/wakeup
716                                         
717                 } else {
718                         wm831x_set_bits(wm831x,
719                                         WM831X_GPIO1_CONTROL + i,
720                                         WM831X_GPN_DIR_MASK | WM831X_GPN_TRI_MASK,
721                                         1 << WM831X_GPN_TRI_SHIFT);
722                         if (wm831x_gpio_settinginfo[i].pin_value == GPIO_HIGH) {
723                                 wm831x_set_bits(wm831x, WM831X_GPIO_LEVEL, 1 << i, 1 << i);
724                         } else {
725                                 wm831x_set_bits(wm831x, WM831X_GPIO_LEVEL, 1 << i, 0 << i);
726                         }
727                         if (i == 2) {
728                                 wm831x_set_bits(wm831x,
729                                                 WM831X_GPIO1_CONTROL + i,
730                                                 WM831X_GPN_PWR_DOM_MASK | WM831X_GPN_POL_MASK |WM831X_GPN_FN_MASK,
731                                                 1 << WM831X_GPN_POL_SHIFT | 1 << WM831X_GPN_PWR_DOM_SHIFT | 1 << 0);
732
733                         }       // set gpio3 as clkout output 32.768K
734                         else {
735                                 wm831x_set_bits(wm831x,
736                                                 WM831X_GPIO1_CONTROL + i,
737                                                 WM831X_GPN_PWR_DOM_MASK,
738                                                 ~WM831X_GPN_PWR_DOM);
739                         }
740                 }
741         }
742
743 #if 0
744         for (i = 0; i < pdata->gpio_pin_num; i++) {
745                 wm831x_set_bits(wm831x,
746                                 WM831X_GPIO1_CONTROL + i,
747                                 WM831X_GPN_PULL_MASK | WM831X_GPN_POL_MASK | WM831X_GPN_OD_MASK | WM831X_GPN_TRI_MASK,
748                                 1 << WM831X_GPN_POL_SHIFT | 1 << WM831X_GPN_TRI_SHIFT);
749
750                 ret = wm831x_reg_read(wm831x, WM831X_GPIO1_CONTROL + i);
751                 printk("Gpio%d Pin Configuration = %x\n", i, ret);
752         }
753 #endif
754
755 out:
756         return 0;
757 }
758 #if defined(CONFIG_KEYBOARD_WM831X_GPIO)
759 static struct wm831x_gpio_keys_button wm831x_gpio_buttons[] = {
760 {       
761         .code           = KEY_MEDIA,
762         .gpio           = TCA6424_P21,
763         .active_low     = 1,
764         .desc           = "media",
765         .wakeup         = 0,
766         .debounce_interval = 120,
767 },
768 {
769     .code= KEY_VOLUMEUP,
770                 .gpio= WM831X_P05,
771                 .active_low= 1,
772                 .desc= "volume_up",
773                 .wakeup= 0,
774 },
775 {
776                 .code= KEY_CAMERA,
777                 .gpio= WM831X_P06,
778                 .active_low= 1,
779                 .desc= "camera",
780                 .wakeup= 0,
781 },
782 {
783                 .code= KEY_VOLUMEDOWN,
784                 .gpio= WM831X_P07,
785                 .active_low= 1,
786                 .desc= "volume_down",
787                 .wakeup= 0,
788 },
789 {
790                 .code= KEY_END,
791                 .gpio= WM831X_P09,
792                 .active_low= 1,
793                 .desc= "enter",
794                 .wakeup= 0,
795 },
796 {
797                 .code= KEY_MENU,
798                 .gpio= WM831X_P10,
799                 .active_low= 1,
800                 .desc= "menu",
801                 .wakeup= 0,
802 },
803 {
804                 .code= KEY_SEND,
805                 .gpio= WM831X_P11,
806                 .active_low= 1,
807                 .desc= "esc",
808                 .wakeup= 0,
809 },
810 {
811                 .code= KEY_BACK,
812                 .gpio= WM831X_P12,
813                 .active_low= 1,
814                 .desc= "home",
815                 .wakeup= 0,                     
816 },
817 };
818
819 struct wm831x_gpio_keys_pdata wm831x_gpio_keys_platdata = {
820         .buttons        = wm831x_gpio_buttons,
821         .nbuttons       = ARRAY_SIZE(wm831x_gpio_buttons),
822 };
823
824 #endif
825
826 static struct wm831x_pdata wm831x_platdata = {
827
828         /** Called before subdevices are set up */
829         .pre_init = wm831x_pre_init,
830         /** Called after subdevices are set up */
831         .post_init = wm831x_post_init,
832         /** Called before subdevices are power down */
833         .last_deinit = wm831x_last_deinit,
834
835 #if defined(CONFIG_GPIO_WM831X)
836         .gpio_base = WM831X_GPIO_EXPANDER_BASE,
837         .gpio_pin_num = WM831X_TOTOL_GPIO_NUM,
838         .settinginfo = wm831x_gpio_settinginfo,
839         .settinginfolen = ARRAY_SIZE(wm831x_gpio_settinginfo),
840         .pin_type_init = wm831x_init_pin_type,
841         .irq_base = IRQ_BOARD_BASE,
842 #endif
843         .backlight = &wm831x_backlight_platdata,
844
845         .backup = &wm831x_backup_platdata,
846         
847         .battery = &wm831x_battery_platdata,
848         //.wm831x_touch_pdata = NULL,
849         //.watchdog = NULL,
850         
851 #if defined(CONFIG_KEYBOARD_WM831X_GPIO)        
852         .gpio_keys = &wm831x_gpio_keys_platdata,
853 #endif
854         /** LED1 = 0 and so on */
855         .status = { &wm831x_status_platdata[0], &wm831x_status_platdata[1] },
856
857         /** DCDC1 = 0 and so on */
858         .dcdc = {
859                 &wm831x_regulator_init_dcdc[0],
860                 &wm831x_regulator_init_dcdc[1],
861                 &wm831x_regulator_init_dcdc[2],
862                 &wm831x_regulator_init_dcdc[3],
863         },
864
865         /** EPE1 = 0 and so on */
866         .epe = { &wm831x_regulator_init_epe[0], &wm831x_regulator_init_epe[1] },
867
868         /** LDO1 = 0 and so on */
869         .ldo = {
870                 &wm831x_regulator_init_ldo[0],
871                 &wm831x_regulator_init_ldo[1],
872                 &wm831x_regulator_init_ldo[2],
873                 &wm831x_regulator_init_ldo[3],
874                 &wm831x_regulator_init_ldo[4],
875                 &wm831x_regulator_init_ldo[5],
876                 &wm831x_regulator_init_ldo[6],
877                 &wm831x_regulator_init_ldo[7],
878                 &wm831x_regulator_init_ldo[8],
879                 &wm831x_regulator_init_ldo[9],
880                 &wm831x_regulator_init_ldo[10],
881         },
882         /** ISINK1 = 0 and so on*/
883         //.isink = {&wm831x_regulator_init_isink[0], &wm831x_regulator_init_isink[1]},
884 };
885 #endif