rk31xx:RT5025:support pmic rt5025
[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_6H,
272                         .PRECHG_TIMEOUT = RT5025_PRECHG_TO_30M,
273                 },
274         },
275         .CHGControl3 = {
276                 .bitfield = {
277                         .VOREG = 0x23,
278                 },
279         },
280         .CHGControl4 = {
281                 .bitfield = {
282                         .AICR = RT5025_AICR_500MA,
283                         .ICC = RT5025_ICC_1P8A,
284                 },
285         },
286         .CHGControl5 = {
287                 .bitfield = {
288                         .DPM = RT5025_DPM_DIS,
289                 },
290         },
291         .CHGControl6 = {
292                 .bitfield = {
293                         .IPREC = RT5025_IPREC_10P,
294                         .IEOC = RT5025_IEOC_10P,
295                         .VPREC = RT5025_VPREC_3V,
296                 },
297         },
298         .CHGControl7 = {
299                 .bitfield = {
300                         .CHGC_EN = 1,
301                         .CHG_DCDC_MODE = 0,
302                         .BATD_EN = 0,
303                 },
304         },
305 };
306
307 static struct rt5025_gpio_data rt5025_gpio_data = {
308 //      .gpio_base = RT5025_GPIO_BASE,
309         .irq_base = IRQ_BOARD_BASE,
310 };
311
312 static struct rt5025_misc_data rt5025_misc_data = {
313         .RSTCtrl = {
314                 .bitfield = {
315                         .Action = 2,
316                         .Delayed1 = RT5025_RSTDELAY1_1S,
317                         .Delayed2 = RT5025_RSTDELAY2_1S,
318                 },
319         },
320         .VSYSCtrl = {
321                 .bitfield = {
322                         .VOFF = RT5025_VOFF_3P1V,
323                 },
324         },
325         .PwrOnCfg = {
326                 .bitfield = {
327                         .PG_DLY = RT5025_PGDLY_100MS,
328                         .SHDN_PRESS = RT5025_SHDNPRESS_6S,
329                         .LPRESS_TIME = RT5025_LPRESS_1P5S,
330                         .START_TIME = RT5025_STARTIME_100MS,
331                 },
332         },
333         .SHDNCtrl = {
334                 .bitfield = {
335                         .SHDN_DLYTIME = RT5025_SHDNDLY_1S,
336                         .SHDN_TIMING = 1,
337                         .SHDN_CTRL = 0,
338                 },
339         },
340         .PwrOffCond = {
341                 .bitfield = {
342                         .OT_ENSHDN = 1,
343                         .PWRON_ENSHDN = 1,
344                         .DCDC3LV_ENSHDN = 0,
345                         .DCDC2LV_ENSHDN = 0,
346                         .DCDC1LV_ENSHDN = 0,
347                         .SYSLV_ENSHDN = 0,
348                 },
349         },
350 };
351
352 static struct rt5025_irq_data rt5025_irq_data = {
353         .irq_enable1 = {
354                 .bitfield = {
355                         .BATABS = 1,
356                         .INUSB_PLUGIN = 1,
357                         .INUSBOVP = 1,
358                         .INAC_PLUGIN = 1,
359                         .INACOVP = 1,
360                 },
361         },
362         .irq_enable2 = {
363                 .bitfield = {
364                         .CHTERMI = 1,
365                         .CHBATOVI = 1,
366                         .CHGOODI_INUSB = 0,
367                         .CHBADI_INUSB = 1,
368                         .CHSLPI_INUSB = 1,
369                         .CHGOODI_INAC = 0,
370                         .CHBADI_INAC = 1,
371                         .CHSLPI_INAC = 1,
372                 },
373         },
374         .irq_enable3 = {
375                 .bitfield = {
376                         .TIMEOUT_CC = 1,
377                         .TIMEOUT_PC = 1,
378                         .CHVSREGI = 0,
379                         .CHTREGI = 0,
380                         .CHRCHGI = 0,
381                 },
382         },
383         .irq_enable4 = {
384                 .bitfield = {
385                         .SYSLV = 0,
386                         .DCDC4LVHV = 1,
387                         .PWRONLP = 0,
388                         .PWRONSP = 0,
389                         .DCDC3LV = 1,
390                         .DCDC2LV = 1,
391                         .DCDC1LV = 1,
392                         .OT = 1,
393                 },
394         },
395         .irq_enable5 = {
396                 .bitfield = {
397                         .GPIO0_IE = 0,
398                         .GPIO1_IE = 0,
399                         .GPIO2_IE = 0,
400                         .RESETB = 1,
401                         .PWRONF = 0,
402                         .PWRONR = 0,
403                         .KPSHDN = 1,
404                 },
405         },
406 };
407
408 static void rt5025_charger_event_callback(uint32_t detected)
409 {
410         RTINFO("event detected = 0x%08x\n", detected);
411 }
412
413 static void rt5025_power_event_callback(uint32_t detected)
414 {
415         RTINFO("event detected = 0x%08x\n", detected);
416 }
417
418 static struct rt5025_event_callback rt5025_event_callback = {
419         .charger_event_callback = rt5025_charger_event_callback,
420         .power_event_callkback = rt5025_power_event_callback,
421 };
422
423 static struct rt5025_platform_data rt5025_data = {
424         .pre_init=rt5025_pre_init,
425         .post_init=rt5025_post_init,
426         .regulator = {
427                 &rt5025_dcdc1_info,
428                 &rt5025_dcdc2_info,
429                 &rt5025_dcdc3_info,
430                 &rt5025_dcdc4_info,
431                 &rt5025_ldo1_info,
432                 &rt5025_ldo2_info,
433                 &rt5025_ldo3_info,
434                 &rt5025_ldo4_info,
435                 &rt5025_ldo5_info,
436                 &rt5025_ldo6_info,
437         },
438         .power_data = &rt5025_power_data,
439         .gpio_data = &rt5025_gpio_data,
440         .misc_data = &rt5025_misc_data,
441         .irq_data = &rt5025_irq_data,
442         .cb = &rt5025_event_callback,
443         .intr_pin = 81, //GPIO81
444 };
445
446 void __sramfunc board_pmu_rt5025_suspend(void)
447 {       
448 }
449 void __sramfunc board_pmu_rt5025_resume(void)
450 {
451 }
452
453
454 #endif
455
456
457
458