Merge branch 'develop-3.0' of ssh://10.10.10.29/rk/kernel into develop-3.0
[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 static struct regulator_consumer_supply rt5025_dcdc1_supply[] = {
86         {
87                 .supply = "rt5025-dcdc1",
88         },
89         {
90                 .supply = "vdd_cpu",
91         },
92         
93 };
94 static struct regulator_consumer_supply rt5025_dcdc2_supply[] = {
95         {
96                 .supply = "rt5025-dcdc2",
97         },
98         {
99                 .supply = "vdd_core",
100         },
101 };
102 static struct regulator_consumer_supply rt5025_dcdc3_supply[] = {
103         {
104                 .supply = "rt5025-dcdc3",
105         },
106 };
107
108 static struct regulator_consumer_supply rt5025_dcdc4_supply[] = {
109         {
110                 .supply = "rt5025-dcdc4",
111         },
112 };
113
114 static struct regulator_consumer_supply rt5025_ldo1_supply[] = {
115         {
116                 .supply = "rt5025-ldo1",
117         },
118 };
119 static struct regulator_consumer_supply rt5025_ldo2_supply[] = {
120         {
121                 .supply = "rt5025-ldo2",
122         },
123 };
124
125 static struct regulator_consumer_supply rt5025_ldo3_supply[] = {
126         {
127                 .supply = "rt5025-ldo3",
128         },
129 };
130 static struct regulator_consumer_supply rt5025_ldo4_supply[] = {
131         {
132                 .supply = "rt5025-ldo4",
133         },
134 };
135 static struct regulator_consumer_supply rt5025_ldo5_supply[] = {
136         {
137                 .supply = "rt5025-ldo5",
138         },
139 };
140 static struct regulator_consumer_supply rt5025_ldo6_supply[] = {
141         {
142                 .supply = "rt5025-ldo6",
143         },
144 };
145
146 static struct regulator_init_data rt5025_dcdc1_info = {
147         .constraints = {
148                 .name           = "RT5025-DCDC1",
149                 .min_uV =  700000,
150                 .max_uV = 2275000,
151                 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
152                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS| REGULATOR_CHANGE_MODE,
153         },
154         .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc1_supply),
155         .consumer_supplies =  rt5025_dcdc1_supply,
156 };
157
158 static struct regulator_init_data rt5025_dcdc2_info = {
159         .constraints = {
160                 .name           = "RT5025-DCDC2",
161                 .min_uV =  700000,
162                 .max_uV = 3500000,
163                 .valid_modes_mask =  REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
164                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS  | REGULATOR_CHANGE_MODE,
165         },
166         .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc2_supply),
167         .consumer_supplies =  rt5025_dcdc2_supply,
168 };
169
170 static struct regulator_init_data rt5025_dcdc3_info = {
171         .constraints = {
172                 .name           = "RT5025-DCDC3",
173                 .min_uV =  700000,
174                 .max_uV = 3500000,
175                 .valid_modes_mask =  REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
176                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS  | REGULATOR_CHANGE_MODE,
177         },
178         .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc3_supply),
179         .consumer_supplies =  rt5025_dcdc3_supply,
180 };
181
182 static struct regulator_init_data rt5025_dcdc4_info = {
183         .constraints = {
184                 .name           = "RT5025-DCDC4",
185                 .min_uV = 4500000,
186                 .max_uV = 5500000,
187                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
188                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
189         },
190         .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc4_supply),
191         .consumer_supplies =  rt5025_dcdc4_supply,
192 };
193
194 static struct regulator_init_data rt5025_ldo1_info = {
195         .constraints = {
196                 .name           = "RT5025-LDO1",
197                 .min_uV =  700000,
198                 .max_uV = 3500000,
199                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
200                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
201         },
202         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo1_supply),
203         .consumer_supplies =  rt5025_ldo1_supply,
204 };
205
206 static struct regulator_init_data rt5025_ldo2_info = {
207         .constraints = {
208                 .name           = "RT5025-LDO2",
209                 .min_uV =  700000,
210                 .max_uV = 3500000,
211                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
212                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
213         },
214         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo2_supply),
215         .consumer_supplies =  rt5025_ldo2_supply,
216 };
217
218 static struct regulator_init_data rt5025_ldo3_info = {
219         .constraints = {
220                 .name           = "RT5025-LDO3",
221                 .min_uV = 1000000,
222                 .max_uV = 3300000,
223                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
224                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
225         },
226         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo3_supply),
227         .consumer_supplies =  rt5025_ldo3_supply,
228 };
229
230 static struct regulator_init_data rt5025_ldo4_info = {
231         .constraints = {
232                 .name           = "RT5025-LDO4",
233                 .min_uV = 1000000,
234                 .max_uV = 3300000,
235                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
236                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
237         },
238         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo4_supply),
239         .consumer_supplies =  rt5025_ldo4_supply,
240 };
241
242 static struct regulator_init_data rt5025_ldo5_info = {
243         .constraints = {
244                 .name           = "RT5025-LDO5",
245                 .min_uV = 1000000,
246                 .max_uV = 3300000,
247                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
248                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
249         },
250         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo5_supply),
251         .consumer_supplies =  rt5025_ldo5_supply,
252 };
253
254 static struct regulator_init_data rt5025_ldo6_info = {
255         .constraints = {
256                 .name           = "RT5025-LDO6",
257                 .min_uV = 1000000,
258                 .max_uV = 3300000,
259                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
260                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
261         },
262         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo6_supply),
263         .consumer_supplies =  rt5025_ldo6_supply,
264 };
265
266 static struct rt5025_power_data rt5025_power_data = {
267         .CHGControl2 = {
268                 .bitfield = {
269                         .CHGBC_EN = 1,
270                         .TE = 1,
271                         .CCCHG_TIMEOUT = RT5025_CCCHG_TO_10H,
272                         .PRECHG_TIMEOUT = RT5025_PRECHG_TO_60M,
273                 },
274         },
275         .CHGControl3 = {
276                 .bitfield = {
277                         .VOREG = 0x23,
278                 },
279         },
280         .CHGControl4 = {
281                 .bitfield = {
282                         .AICR_CON = 1,
283                         .AICR = RT5025_AICR_1A,
284                         .ICC = RT5025_ICC_1A,
285                 },
286         },
287         .CHGControl5 = {
288                 .bitfield = {
289                         .DPM = RT5025_DPM_4P5V,
290                 },
291         },
292         .CHGControl6 = {
293                 .bitfield = {
294                         .IPREC = RT5025_IPREC_20P,
295                         .IEOC = RT5025_IEOC_10P,
296                         .VPREC = RT5025_VPREC_3V,
297                 },
298         },
299         .CHGControl7 = {
300                 .bitfield = {
301                         .CHGC_EN = 1,
302                         .CHG_DCDC_MODE = 0,
303                         .BATD_EN = 0,
304                 },
305         },
306 //      .fcc = 6200, //6200 mAh
307 };
308
309 static struct rt5025_gpio_data rt5025_gpio_data = {
310 //      .gpio_base = RT5025_GPIO_BASE,
311         .irq_base = IRQ_BOARD_BASE,
312 };
313
314 static struct rt5025_misc_data rt5025_misc_data = {
315         .RSTCtrl = {
316                 .bitfield = {
317                         .Action = 2,
318                         .Delayed1 = RT5025_RSTDELAY1_1S,
319                         .Delayed2 = RT5025_RSTDELAY2_1S,
320                 },
321         },
322         .VSYSCtrl = {
323                 .bitfield = {
324                         .VOFF = RT5025_VOFF_3P0V,
325                 },
326         },
327         .PwrOnCfg = {
328                 .bitfield = {
329                         .PG_DLY = RT5025_PGDLY_100MS,
330                         .SHDN_PRESS = RT5025_SHDNPRESS_6S,
331                         .LPRESS_TIME = RT5025_LPRESS_1P5S,
332                         .START_TIME = RT5025_STARTIME_100MS,
333                 },
334         },
335         .SHDNCtrl = {
336                 .bitfield = {
337                         .SHDN_DLYTIME = RT5025_SHDNDLY_1S,
338                         .SHDN_TIMING = 1,
339                         .SHDN_CTRL = 0,
340                 },
341         },
342         .PwrOffCond = {
343                 .bitfield = {
344                         .OT_ENSHDN = 1,
345                         .PWRON_ENSHDN = 1,
346                         .DCDC3LV_ENSHDN = 0,
347                         .DCDC2LV_ENSHDN = 0,
348                         .DCDC1LV_ENSHDN = 0,
349                         .SYSLV_ENSHDN = 1,
350                 },
351         },
352 };
353
354 static struct rt5025_irq_data rt5025_irq_data = {
355         .irq_enable1 = {
356                 .bitfield = {
357                         .BATABS = 0,
358                         .INUSB_PLUGIN = 1,
359                         .INUSBOVP = 1,
360                         .INAC_PLUGIN = 1,
361                         .INACOVP = 1,
362                 },
363         },
364         .irq_enable2 = {
365                 .bitfield = {
366                         .CHTERMI = 1,
367                         .CHBATOVI = 1,
368                         .CHGOODI_INUSB = 0,
369                         .CHBADI_INUSB = 0,
370                         .CHSLPI_INUSB = 1,
371                         .CHGOODI_INAC = 0,
372                         .CHBADI_INAC = 0,
373                         .CHSLPI_INAC = 1,
374                 },
375         },
376         .irq_enable3 = {
377                 .bitfield = {
378                         .TIMEOUT_CC = 0,
379                         .TIMEOUT_PC = 0,
380                         .CHVSREGI = 0,
381                         .CHTREGI = 0,
382                         .CHRCHGI = 1,
383                 },
384         },
385         .irq_enable4 = {
386                 .bitfield = {
387                         .SYSLV = 0,
388                         .DCDC4LVHV = 0,
389                         .PWRONLP = 0,
390                         .PWRONSP = 0,
391                         .DCDC3LV = 0,
392                         .DCDC2LV = 0,
393                         .DCDC1LV = 0,
394                         .OT = 1,
395                 },
396         },
397         .irq_enable5 = {
398                 .bitfield = {
399                         .GPIO0_IE = 0,
400                         .GPIO1_IE = 0,
401                         .GPIO2_IE = 0,
402                         .RESETB = 1,
403                         .PWRONF = 0,
404                         .PWRONR = 0,
405                         .KPSHDN = 1,
406                 },
407         },
408 };
409
410 //temp unit: 'c*10 degree
411 static int jeita_temp[4] = { 0, 150, 500, 600};
412                              //-5',  5',   15', 20',   45'   55'   55',  65'
413 static u8 jeita_scalar[8] = { 0x30, 0x2B, 0x25, 0x20, 0x15, 0x10, 0x10, 0x0D };
414 //cc unit: xxx mA
415 static int jeita_temp_cc[][5] = {{ 500,  500,  500,  500, 500},    // not plugin
416                                  {   0 , 500,  500,  500,   0},    // normal USB
417                                  {   0,  500, 1000,  500,   0},    // USB charger
418                                  {   0,  500, 1000,  500,   0}};   // AC Adapter
419 //cv unit: xxx mV
420 static int jeita_temp_cv[][5] = {{ 4200, 4200, 4200, 4200, 4200},  // not plugin
421                                  { 4200, 4200, 4200, 4200, 4200},  // normal USB
422                                  { 4200, 4200, 4200, 4200, 4200},  // USB charger
423                                  { 4200, 4200, 4200, 4200, 4200}}; // AC Adapter
424
425 static struct rt5025_jeita_data rt5025_jeita_data = {
426         .temp = jeita_temp,
427         .temp_scalar = jeita_scalar,
428         .temp_cc = jeita_temp_cc,
429         .temp_cv = jeita_temp_cv,
430 };
431
432 static void rt5025_charger_event_callback(uint32_t detected)
433 {
434         RTINFO("charger event detected = 0x%08x\n", detected);
435         if (detected & CHG_EVENT_CHTERMI)
436         {
437                 pr_info("charger termination OK\n");
438         }
439 }
440
441 static void rt5025_power_event_callback(uint32_t detected)
442 {
443         RTINFO("power event detected = 0x%08x\n", detected);
444 }
445
446 static struct rt5025_event_callback rt5025_event_callback = {
447         .charger_event_callback = rt5025_charger_event_callback,
448         .power_event_callkback = rt5025_power_event_callback,
449 };
450
451 static struct rt5025_platform_data rt5025_data = {
452         .pre_init=rt5025_pre_init,
453         .post_init=rt5025_post_init,
454         .regulator = {
455                 &rt5025_dcdc1_info,
456                 &rt5025_dcdc2_info,
457                 &rt5025_dcdc3_info,
458                 &rt5025_dcdc4_info,
459                 &rt5025_ldo1_info,
460                 &rt5025_ldo2_info,
461                 &rt5025_ldo3_info,
462                 &rt5025_ldo4_info,
463                 &rt5025_ldo5_info,
464                 &rt5025_ldo6_info,
465         },
466         .power_data = &rt5025_power_data,
467         .gpio_data = &rt5025_gpio_data,
468         .misc_data = &rt5025_misc_data,
469         .irq_data = &rt5025_irq_data,
470         .jeita_data = &rt5025_jeita_data,
471         .cb = &rt5025_event_callback,
472         .intr_pin = 81, //GPIO81
473 };
474
475 void __sramfunc board_pmu_rt5025_suspend(void)
476 {       
477 }
478 void __sramfunc board_pmu_rt5025_resume(void)
479 {
480 }
481
482
483 #endif
484
485
486
487