Consummate bcm wifi oob on all platform(Wake gpio define).
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk30 / board-pmu-rt5025.c
1 #include <linux/regulator/machine.h>
2 #include <mach/sram.h>
3 #include <linux/platform_device.h>
4
5 #include <mach/gpio.h>
6 #include <mach/iomux.h>
7 #include <mach/board.h>
8
9 #include <linux/mfd/rt5025.h>
10
11 #ifdef CONFIG_MFD_RT5025
12
13 static int rt5025_pre_init(struct rt5025_chip *rt5025_chip){
14
15         
16         printk("%s,line=%d\n", __func__,__LINE__);      
17         int ret;
18         /**********set voltage speed***********************/
19         ret = rt5025_reg_read(rt5025_chip->i2c, 0x08);
20         ret &= (~(3<<0));  //dcdc1 25mv/10us
21         rt5025_reg_write(rt5025_chip->i2c, 0x08,ret);
22         
23         ret = rt5025_reg_read(rt5025_chip->i2c, 0x09);
24         ret &= (~(3<<0));//dcdc2 100mv/10us
25         rt5025_reg_write(rt5025_chip->i2c, 0x09,ret);
26         
27         ret = rt5025_reg_read(rt5025_chip->i2c, 0x0a);
28         ret &= (~(3<<0));//dcdc3 50mv/12us
29         rt5025_reg_write(rt5025_chip->i2c, 0x0a,ret);
30         /************************************************/
31         /***************set power off voltage***************/
32         ret = rt5025_reg_read(rt5025_chip->i2c, 0x17);
33         ret &= (~(7<<5));  //power off 2.8v
34         rt5025_reg_write(rt5025_chip->i2c, 0x17,ret);
35
36         ret = rt5025_reg_read(rt5025_chip->i2c, 0x17);
37         ret |= (1<<3);  //enable DC4 boost
38         rt5025_reg_write(rt5025_chip->i2c, 0x17,ret);
39         /***********************************************/
40         /************************************************/
41         return 0;
42   }
43 static int rt5025_post_init(void)
44 {
45         struct regulator *dcdc;
46         struct regulator *ldo;
47         int i = 0;
48         printk("%s,line=%d\n", __func__,__LINE__);
49
50         #ifndef CONFIG_RK_CONFIG
51         g_pmic_type = PMIC_TYPE_RT5025;
52         #endif
53         printk("%s:g_pmic_type=%d\n",__func__,g_pmic_type);
54         
55         for(i = 0; i < ARRAY_SIZE(rt5025_dcdc_info); i++)
56         {
57                 if(rt5025_dcdc_info[i].min_uv == 0 && rt5025_dcdc_info[i].max_uv == 0)
58                         continue;
59                 dcdc =regulator_get(NULL, rt5025_dcdc_info[i].name);
60
61                 regulator_set_voltage(dcdc, rt5025_dcdc_info[i].min_uv, rt5025_dcdc_info[i].max_uv);
62
63                 regulator_set_mode(dcdc, REGULATOR_MODE_NORMAL);
64                 regulator_enable(dcdc);
65                 printk("%s  %s =%duV end\n", __func__,rt5025_dcdc_info[i].name, regulator_get_voltage(dcdc));
66                 regulator_put(dcdc);
67                 udelay(100);
68         }
69         
70         for(i = 0; i < ARRAY_SIZE(rt5025_ldo_info); i++)
71         {
72                 if(rt5025_ldo_info[i].min_uv == 0 && rt5025_ldo_info[i].max_uv == 0)
73                         continue;
74                 ldo =regulator_get(NULL, rt5025_ldo_info[i].name);
75                 regulator_set_voltage(ldo, rt5025_ldo_info[i].min_uv, rt5025_ldo_info[i].max_uv);
76                 regulator_enable(ldo);
77                 printk("%s  %s =%duV end\n", __func__,rt5025_ldo_info[i].name, regulator_get_voltage(ldo));
78                 regulator_put(ldo);
79         }
80         
81         printk("%s,line=%d END\n", __func__,__LINE__);
82         
83         return 0;
84 }
85
86  int rt5025_set_otg_enable(int enable)
87 {
88         if (enable)
89                 rt5025_ext_set_charging_buck(0);
90         else
91                 rt5025_ext_set_charging_buck(1);
92         return 0;
93 }
94
95 static struct regulator_consumer_supply rt5025_dcdc1_supply[] = {
96         {
97                 .supply = "rt5025-dcdc1",
98         },
99         {
100                 .supply = "vdd_cpu",
101         },
102         
103 };
104 static struct regulator_consumer_supply rt5025_dcdc2_supply[] = {
105         {
106                 .supply = "rt5025-dcdc2",
107         },
108         {
109                 .supply = "vdd_core",
110         },
111 };
112 static struct regulator_consumer_supply rt5025_dcdc3_supply[] = {
113         {
114                 .supply = "rt5025-dcdc3",
115         },
116 };
117
118 static struct regulator_consumer_supply rt5025_dcdc4_supply[] = {
119         {
120                 .supply = "rt5025-dcdc4",
121         },
122 };
123
124 static struct regulator_consumer_supply rt5025_ldo1_supply[] = {
125         {
126                 .supply = "rt5025-ldo1",
127         },
128 };
129 static struct regulator_consumer_supply rt5025_ldo2_supply[] = {
130         {
131                 .supply = "rt5025-ldo2",
132         },
133 };
134
135 static struct regulator_consumer_supply rt5025_ldo3_supply[] = {
136         {
137                 .supply = "rt5025-ldo3",
138         },
139 };
140 static struct regulator_consumer_supply rt5025_ldo4_supply[] = {
141         {
142                 .supply = "rt5025-ldo4",
143         },
144 };
145 static struct regulator_consumer_supply rt5025_ldo5_supply[] = {
146         {
147                 .supply = "rt5025-ldo5",
148         },
149 };
150 static struct regulator_consumer_supply rt5025_ldo6_supply[] = {
151         {
152                 .supply = "rt5025-ldo6",
153         },
154 };
155
156 static struct regulator_init_data rt5025_dcdc1_info = {
157         .constraints = {
158                 .name           = "RT5025-DCDC1",
159                 .min_uV =  700000,
160                 .max_uV = 2275000,
161                 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
162                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS| REGULATOR_CHANGE_MODE,
163         },
164         .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc1_supply),
165         .consumer_supplies =  rt5025_dcdc1_supply,
166 };
167
168 static struct regulator_init_data rt5025_dcdc2_info = {
169         .constraints = {
170                 .name           = "RT5025-DCDC2",
171                 .min_uV =  700000,
172                 .max_uV = 3500000,
173                 .valid_modes_mask =  REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
174                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS  | REGULATOR_CHANGE_MODE,
175         },
176         .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc2_supply),
177         .consumer_supplies =  rt5025_dcdc2_supply,
178 };
179
180 static struct regulator_init_data rt5025_dcdc3_info = {
181         .constraints = {
182                 .name           = "RT5025-DCDC3",
183                 .min_uV =  700000,
184                 .max_uV = 3500000,
185                 .valid_modes_mask =  REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
186                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS  | REGULATOR_CHANGE_MODE,
187         },
188         .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc3_supply),
189         .consumer_supplies =  rt5025_dcdc3_supply,
190 };
191
192 static struct regulator_init_data rt5025_dcdc4_info = {
193         .constraints = {
194                 .name           = "RT5025-DCDC4",
195                 .min_uV = 4500000,
196                 .max_uV = 5500000,
197                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
198                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
199         },
200         .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc4_supply),
201         .consumer_supplies =  rt5025_dcdc4_supply,
202 };
203
204 static struct regulator_init_data rt5025_ldo1_info = {
205         .constraints = {
206                 .name           = "RT5025-LDO1",
207                 .min_uV =  700000,
208                 .max_uV = 3500000,
209                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
210                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
211         },
212         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo1_supply),
213         .consumer_supplies =  rt5025_ldo1_supply,
214 };
215
216 static struct regulator_init_data rt5025_ldo2_info = {
217         .constraints = {
218                 .name           = "RT5025-LDO2",
219                 .min_uV =  700000,
220                 .max_uV = 3500000,
221                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
222                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
223         },
224         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo2_supply),
225         .consumer_supplies =  rt5025_ldo2_supply,
226 };
227
228 static struct regulator_init_data rt5025_ldo3_info = {
229         .constraints = {
230                 .name           = "RT5025-LDO3",
231                 .min_uV = 1000000,
232                 .max_uV = 3300000,
233                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
234                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
235         },
236         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo3_supply),
237         .consumer_supplies =  rt5025_ldo3_supply,
238 };
239
240 static struct regulator_init_data rt5025_ldo4_info = {
241         .constraints = {
242                 .name           = "RT5025-LDO4",
243                 .min_uV = 1000000,
244                 .max_uV = 3300000,
245                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
246                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
247         },
248         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo4_supply),
249         .consumer_supplies =  rt5025_ldo4_supply,
250 };
251
252 static struct regulator_init_data rt5025_ldo5_info = {
253         .constraints = {
254                 .name           = "RT5025-LDO5",
255                 .min_uV = 1000000,
256                 .max_uV = 3300000,
257                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
258                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
259         },
260         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo5_supply),
261         .consumer_supplies =  rt5025_ldo5_supply,
262 };
263
264 static struct regulator_init_data rt5025_ldo6_info = {
265         .constraints = {
266                 .name           = "RT5025-LDO6",
267                 .min_uV = 1000000,
268                 .max_uV = 3300000,
269                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
270                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
271         },
272         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo6_supply),
273         .consumer_supplies =  rt5025_ldo6_supply,
274 };
275
276 static struct rt5025_power_data rt5025_power_data = {
277         .CHGControl2 = {
278                 .bitfield = {
279                         .CHGBC_EN = 1,
280                         .TE = 1,
281                         .CCCHG_TIMEOUT = RT5025_CCCHG_TO_10H,
282                         .PRECHG_TIMEOUT = RT5025_PRECHG_TO_60M,
283                 },
284         },
285         .CHGControl3 = {
286                 .bitfield = {
287                         .VOREG = 0x23,
288                 },
289         },
290         .CHGControl4 = {
291                 .bitfield = {
292                         .AICR_CON = 1,
293                         .AICR = RT5025_AICR_1A,
294                         .ICC = RT5025_ICC_1A,
295                 },
296         },
297         .CHGControl5 = {
298                 .bitfield = {
299                         .DPM = RT5025_DPM_4P5V,
300                 },
301         },
302         .CHGControl6 = {
303                 .bitfield = {
304                         .IPREC = RT5025_IPREC_20P,
305                         .IEOC = RT5025_IEOC_10P,
306                         .VPREC = RT5025_VPREC_3V,
307                 },
308         },
309         .CHGControl7 = {
310                 .bitfield = {
311                         .CHGC_EN = 1,
312                         .CHG_DCDC_MODE = 0,
313                         .BATD_EN = 0,
314                 },
315         },
316 //      .fcc = 6200, //6200 mAh
317 };
318
319 static struct rt5025_gpio_data rt5025_gpio_data = {
320 //      .gpio_base = RT5025_GPIO_BASE,
321         .irq_base = IRQ_BOARD_BASE,
322 };
323
324 static struct rt5025_misc_data rt5025_misc_data = {
325         .RSTCtrl = {
326                 .bitfield = {
327                         .Action = 2,
328                         .Delayed1 = RT5025_RSTDELAY1_1S,
329                         .Delayed2 = RT5025_RSTDELAY2_1S,
330                 },
331         },
332         .VSYSCtrl = {
333                 .bitfield = {
334                         .VOFF = RT5025_VOFF_3P0V,
335                 },
336         },
337         .PwrOnCfg = {
338                 .bitfield = {
339                         .PG_DLY = RT5025_PGDLY_100MS,
340                         .SHDN_PRESS = RT5025_SHDNPRESS_6S,
341                         .LPRESS_TIME = RT5025_LPRESS_1P5S,
342                         .START_TIME = RT5025_STARTIME_100MS,
343                 },
344         },
345         .SHDNCtrl = {
346                 .bitfield = {
347                         .SHDN_DLYTIME = RT5025_SHDNDLY_1S,
348                         .SHDN_TIMING = 1,
349                         .SHDN_CTRL = 0,
350                 },
351         },
352         .PwrOffCond = {
353                 .bitfield = {
354                         .OT_ENSHDN = 1,
355                         .PWRON_ENSHDN = 1,
356                         .DCDC3LV_ENSHDN = 0,
357                         .DCDC2LV_ENSHDN = 0,
358                         .DCDC1LV_ENSHDN = 0,
359                         .SYSLV_ENSHDN = 1,
360                 },
361         },
362 };
363
364 static struct rt5025_irq_data rt5025_irq_data = {
365         .irq_enable1 = {
366                 .bitfield = {
367                         .BATABS = 0,
368                         .INUSB_PLUGIN = 1,
369                         .INUSBOVP = 1,
370                         .INAC_PLUGIN = 1,
371                         .INACOVP = 1,
372                 },
373         },
374         .irq_enable2 = {
375                 .bitfield = {
376                         .CHTERMI = 1,
377                         .CHBATOVI = 1,
378                         .CHGOODI_INUSB = 0,
379                         .CHBADI_INUSB = 0,
380                         .CHSLPI_INUSB = 1,
381                         .CHGOODI_INAC = 0,
382                         .CHBADI_INAC = 0,
383                         .CHSLPI_INAC = 1,
384                 },
385         },
386         .irq_enable3 = {
387                 .bitfield = {
388                         .TIMEOUT_CC = 0,
389                         .TIMEOUT_PC = 0,
390                         .CHVSREGI = 0,
391                         .CHTREGI = 0,
392                         .CHRCHGI = 1,
393                 },
394         },
395         .irq_enable4 = {
396                 .bitfield = {
397                         .SYSLV = 0,
398                         .DCDC4LVHV = 0,
399                         .PWRONLP = 0,
400                         .PWRONSP = 0,
401                         .DCDC3LV = 0,
402                         .DCDC2LV = 0,
403                         .DCDC1LV = 0,
404                         .OT = 1,
405                 },
406         },
407         .irq_enable5 = {
408                 .bitfield = {
409                         .GPIO0_IE = 0,
410                         .GPIO1_IE = 0,
411                         .GPIO2_IE = 0,
412                         .RESETB = 1,
413                         .PWRONF = 0,
414                         .PWRONR = 0,
415                         .KPSHDN = 1,
416                 },
417         },
418 };
419
420 //temp unit: 'c*10 degree
421 static int jeita_temp[4] = { 0, 150, 500, 600};
422                              //-5',  5',   15', 20',   45'   55'   55',  65'
423 static u8 jeita_scalar[8] = { 0x30, 0x2B, 0x25, 0x20, 0x15, 0x10, 0x10, 0x0D };
424 //cc unit: xxx mA
425 static int jeita_temp_cc[][5] = {{ 500,  500,  500,  500, 500},    // not plugin
426                                  {   0 , 500,  500,  500,   0},    // normal USB
427                                  {   0,  500, 1000,  500,   0},    // USB charger
428                                  {   0,  500, 1000,  500,   0}};   // AC Adapter
429 //cv unit: xxx mV
430 static int jeita_temp_cv[][5] = {{ 4200, 4200, 4200, 4200, 4200},  // not plugin
431                                  { 4200, 4200, 4200, 4200, 4200},  // normal USB
432                                  { 4200, 4200, 4200, 4200, 4200},  // USB charger
433                                  { 4200, 4200, 4200, 4200, 4200}}; // AC Adapter
434
435 static struct rt5025_jeita_data rt5025_jeita_data = {
436         .temp = jeita_temp,
437         .temp_scalar = jeita_scalar,
438         .temp_cc = jeita_temp_cc,
439         .temp_cv = jeita_temp_cv,
440 };
441
442 static void rt5025_charger_event_callback(uint32_t detected)
443 {
444         RTINFO("charger event detected = 0x%08x\n", detected);
445         if (detected & CHG_EVENT_CHTERMI)
446         {
447                 pr_info("charger termination OK\n");
448         }
449 }
450
451 static void rt5025_power_event_callback(uint32_t detected)
452 {
453         RTINFO("power event detected = 0x%08x\n", detected);
454 }
455
456 static struct rt5025_event_callback rt5025_event_callback = {
457         .charger_event_callback = rt5025_charger_event_callback,
458         .power_event_callkback = rt5025_power_event_callback,
459 };
460
461 static struct rt5025_platform_data rt5025_data = {
462         .pre_init=rt5025_pre_init,
463         .post_init=rt5025_post_init,
464         .regulator = {
465                 &rt5025_dcdc1_info,
466                 &rt5025_dcdc2_info,
467                 &rt5025_dcdc3_info,
468                 &rt5025_dcdc4_info,
469                 &rt5025_ldo1_info,
470                 &rt5025_ldo2_info,
471                 &rt5025_ldo3_info,
472                 &rt5025_ldo4_info,
473                 &rt5025_ldo5_info,
474                 &rt5025_ldo6_info,
475         },
476         .power_data = &rt5025_power_data,
477         .gpio_data = &rt5025_gpio_data,
478         .misc_data = &rt5025_misc_data,
479         .irq_data = &rt5025_irq_data,
480         .jeita_data = &rt5025_jeita_data,
481         .cb = &rt5025_event_callback,
482         .intr_pin = 81, //GPIO81
483 };
484
485 void __sramfunc board_pmu_rt5025_suspend(void)
486 {       
487 }
488 void __sramfunc board_pmu_rt5025_resume(void)
489 {
490 }
491
492
493 #endif
494
495
496
497