f0f0fc567118261ef25aeb6d19ae4785a09bf86c
[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          ret = rt5025_reg_read(rt5025_chip->i2c, 0x07);
41         ret |= (1<<5);  //
42         rt5025_reg_write(rt5025_chip->i2c, 0x07,ret);
43
44         /************************************************/
45         return 0;
46   }
47 static int rt5025_post_init(void)
48 {
49         struct regulator *dcdc;
50         struct regulator *ldo;
51         int i = 0;
52         printk("%s,line=%d\n", __func__,__LINE__);
53
54         #ifndef CONFIG_RK_CONFIG
55         g_pmic_type = PMIC_TYPE_RT5025;
56         #endif
57         printk("%s:g_pmic_type=%d\n",__func__,g_pmic_type);
58         
59         for(i = 0; i < ARRAY_SIZE(rt5025_dcdc_info); i++)
60         {
61                 if(rt5025_dcdc_info[i].min_uv == 0 && rt5025_dcdc_info[i].max_uv == 0)
62                         continue;
63                 dcdc =regulator_get(NULL, rt5025_dcdc_info[i].name);
64
65                 regulator_set_voltage(dcdc, rt5025_dcdc_info[i].min_uv, rt5025_dcdc_info[i].max_uv);
66
67                 regulator_set_mode(dcdc, REGULATOR_MODE_NORMAL);
68                 regulator_enable(dcdc);
69                 printk("%s  %s =%duV end\n", __func__,rt5025_dcdc_info[i].name, regulator_get_voltage(dcdc));
70                 regulator_put(dcdc);
71                 udelay(100);
72         }
73         
74         for(i = 0; i < ARRAY_SIZE(rt5025_ldo_info); i++)
75         {
76                 if(rt5025_ldo_info[i].min_uv == 0 && rt5025_ldo_info[i].max_uv == 0)
77                         continue;
78                 ldo =regulator_get(NULL, rt5025_ldo_info[i].name);
79                 regulator_set_voltage(ldo, rt5025_ldo_info[i].min_uv, rt5025_ldo_info[i].max_uv);
80                 regulator_enable(ldo);
81                 printk("%s  %s =%duV end\n", __func__,rt5025_ldo_info[i].name, regulator_get_voltage(ldo));
82                 regulator_put(ldo);
83         }
84         
85         printk("%s,line=%d END\n", __func__,__LINE__);
86         
87         return 0;
88 }
89 static struct regulator_consumer_supply rt5025_dcdc1_supply[] = {
90         {
91                 .supply = "rt5025-dcdc1",
92         },
93         {
94                 .supply = "vdd_cpu",
95         },
96         
97 };
98 static struct regulator_consumer_supply rt5025_dcdc2_supply[] = {
99         {
100                 .supply = "rt5025-dcdc2",
101         },
102         {
103                 .supply = "vdd_core",
104         },
105 };
106 static struct regulator_consumer_supply rt5025_dcdc3_supply[] = {
107         {
108                 .supply = "rt5025-dcdc3",
109         },
110 };
111
112 static struct regulator_consumer_supply rt5025_dcdc4_supply[] = {
113         {
114                 .supply = "rt5025-dcdc4",
115         },
116 };
117
118 static struct regulator_consumer_supply rt5025_ldo1_supply[] = {
119         {
120                 .supply = "rt5025-ldo1",
121         },
122 };
123 static struct regulator_consumer_supply rt5025_ldo2_supply[] = {
124         {
125                 .supply = "rt5025-ldo2",
126         },
127 };
128
129 static struct regulator_consumer_supply rt5025_ldo3_supply[] = {
130         {
131                 .supply = "rt5025-ldo3",
132         },
133 };
134 static struct regulator_consumer_supply rt5025_ldo4_supply[] = {
135         {
136                 .supply = "rt5025-ldo4",
137         },
138 };
139 static struct regulator_consumer_supply rt5025_ldo5_supply[] = {
140         {
141                 .supply = "rt5025-ldo5",
142         },
143 };
144 static struct regulator_consumer_supply rt5025_ldo6_supply[] = {
145         {
146                 .supply = "rt5025-ldo6",
147         },
148 };
149
150 static struct regulator_init_data rt5025_dcdc1_info = {
151         .constraints = {
152                 .name           = "RT5025-DCDC1",
153                 .min_uV =  700000,
154                 .max_uV = 2275000,
155                 .valid_modes_mask = REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
156                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS| REGULATOR_CHANGE_MODE,
157         },
158         .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc1_supply),
159         .consumer_supplies =  rt5025_dcdc1_supply,
160 };
161
162 static struct regulator_init_data rt5025_dcdc2_info = {
163         .constraints = {
164                 .name           = "RT5025-DCDC2",
165                 .min_uV =  700000,
166                 .max_uV = 3500000,
167                 .valid_modes_mask =  REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
168                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS  | REGULATOR_CHANGE_MODE,
169         },
170         .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc2_supply),
171         .consumer_supplies =  rt5025_dcdc2_supply,
172 };
173
174 static struct regulator_init_data rt5025_dcdc3_info = {
175         .constraints = {
176                 .name           = "RT5025-DCDC3",
177                 .min_uV =  700000,
178                 .max_uV = 3500000,
179                 .valid_modes_mask =  REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
180                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS  | REGULATOR_CHANGE_MODE,
181         },
182         .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc3_supply),
183         .consumer_supplies =  rt5025_dcdc3_supply,
184 };
185
186 static struct regulator_init_data rt5025_dcdc4_info = {
187         .constraints = {
188                 .name           = "RT5025-DCDC4",
189                 .min_uV = 4500000,
190                 .max_uV = 5500000,
191                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
192                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
193         },
194         .num_consumer_supplies = ARRAY_SIZE(rt5025_dcdc4_supply),
195         .consumer_supplies =  rt5025_dcdc4_supply,
196 };
197
198 static struct regulator_init_data rt5025_ldo1_info = {
199         .constraints = {
200                 .name           = "RT5025-LDO1",
201                 .min_uV =  700000,
202                 .max_uV = 3500000,
203                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
204                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
205         },
206         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo1_supply),
207         .consumer_supplies =  rt5025_ldo1_supply,
208 };
209
210 static struct regulator_init_data rt5025_ldo2_info = {
211         .constraints = {
212                 .name           = "RT5025-LDO2",
213                 .min_uV =  700000,
214                 .max_uV = 3500000,
215                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
216                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
217         },
218         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo2_supply),
219         .consumer_supplies =  rt5025_ldo2_supply,
220 };
221
222 static struct regulator_init_data rt5025_ldo3_info = {
223         .constraints = {
224                 .name           = "RT5025-LDO3",
225                 .min_uV = 1000000,
226                 .max_uV = 3300000,
227                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
228                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
229         },
230         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo3_supply),
231         .consumer_supplies =  rt5025_ldo3_supply,
232 };
233
234 static struct regulator_init_data rt5025_ldo4_info = {
235         .constraints = {
236                 .name           = "RT5025-LDO4",
237                 .min_uV = 1000000,
238                 .max_uV = 3300000,
239                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
240                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
241         },
242         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo4_supply),
243         .consumer_supplies =  rt5025_ldo4_supply,
244 };
245
246 static struct regulator_init_data rt5025_ldo5_info = {
247         .constraints = {
248                 .name           = "RT5025-LDO5",
249                 .min_uV = 1000000,
250                 .max_uV = 3300000,
251                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
252                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
253         },
254         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo5_supply),
255         .consumer_supplies =  rt5025_ldo5_supply,
256 };
257
258 static struct regulator_init_data rt5025_ldo6_info = {
259         .constraints = {
260                 .name           = "RT5025-LDO6",
261                 .min_uV = 1000000,
262                 .max_uV = 3300000,
263                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
264                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_STATUS,
265         },
266         .num_consumer_supplies = ARRAY_SIZE(rt5025_ldo6_supply),
267         .consumer_supplies =  rt5025_ldo6_supply,
268 };
269
270 static struct rt5025_power_data rt5025_power_data = {
271         .CHGControl2 = {
272                 .bitfield = {
273                         .CHGBC_EN = 1,
274                         .TE = 1,
275                         .CCCHG_TIMEOUT = RT5025_CCCHG_TO_6H,
276                         .PRECHG_TIMEOUT = RT5025_PRECHG_TO_30M,
277                 },
278         },
279         .CHGControl3 = {
280                 .bitfield = {
281                         .VOREG = 0x23,
282                 },
283         },
284         .CHGControl4 = {
285                 .bitfield = {
286                         .AICR = RT5025_AICR_500MA,
287                         .ICC = RT5025_ICC_1P8A,
288                 },
289         },
290         .CHGControl5 = {
291                 .bitfield = {
292                         .DPM = RT5025_DPM_DIS,
293                 },
294         },
295         .CHGControl6 = {
296                 .bitfield = {
297                         .IPREC = RT5025_IPREC_10P,
298                         .IEOC = RT5025_IEOC_10P,
299                         .VPREC = RT5025_VPREC_3V,
300                 },
301         },
302         .CHGControl7 = {
303                 .bitfield = {
304                         .CHGC_EN = 1,
305                         .CHG_DCDC_MODE = 1,
306                         .BATD_EN = 0,
307                 },
308         },
309 };
310
311 static struct rt5025_gpio_data rt5025_gpio_data = {
312 //      .gpio_base = RT5025_GPIO_BASE,
313         .irq_base = IRQ_BOARD_BASE,
314 };
315
316 static struct rt5025_misc_data rt5025_misc_data = {
317         .RSTCtrl = {
318                 .bitfield = {
319                         .Action = 2,
320                         .Delayed1 = RT5025_RSTDELAY1_1S,
321                         .Delayed2 = RT5025_RSTDELAY2_1S,
322                 },
323         },
324         .VSYSCtrl = {
325                 .bitfield = {
326                         .VOFF = RT5025_VOFF_3P1V,
327                 },
328         },
329         .PwrOnCfg = {
330                 .bitfield = {
331                         .PG_DLY = RT5025_PGDLY_100MS,
332                         .SHDN_PRESS = RT5025_SHDNPRESS_6S,
333                         .LPRESS_TIME = RT5025_LPRESS_1P5S,
334                         .START_TIME = RT5025_STARTIME_100MS,
335                 },
336         },
337         .SHDNCtrl = {
338                 .bitfield = {
339                         .SHDN_DLYTIME = RT5025_SHDNDLY_1S,
340                         .SHDN_TIMING = 1,
341                         .SHDN_CTRL = 0,
342                 },
343         },
344         .PwrOffCond = {
345                 .bitfield = {
346                         .OT_ENSHDN = 1,
347                         .PWRON_ENSHDN = 1,
348                         .DCDC3LV_ENSHDN = 0,
349                         .DCDC2LV_ENSHDN = 0,
350                         .DCDC1LV_ENSHDN = 0,
351                         .SYSLV_ENSHDN = 0,
352                 },
353         },
354 };
355
356 static struct rt5025_irq_data rt5025_irq_data = {
357         .irq_enable1 = {
358                 .bitfield = {
359                         .BATABS = 1,
360                         .INUSB_PLUGIN = 1,
361                         .INUSBOVP = 1,
362                         .INAC_PLUGIN = 1,
363                         .INACOVP = 1,
364                 },
365         },
366         .irq_enable2 = {
367                 .bitfield = {
368                         .CHTERMI = 1,
369                         .CHBATOVI = 1,
370                         .CHGOODI_INUSB = 0,
371                         .CHBADI_INUSB = 1,
372                         .CHSLPI_INUSB = 1,
373                         .CHGOODI_INAC = 0,
374                         .CHBADI_INAC = 1,
375                         .CHSLPI_INAC = 1,
376                 },
377         },
378         .irq_enable3 = {
379                 .bitfield = {
380                         .TIMEOUT_CC = 1,
381                         .TIMEOUT_PC = 1,
382                         .CHVSREGI = 0,
383                         .CHTREGI = 0,
384                         .CHRCHGI = 0,
385                 },
386         },
387         .irq_enable4 = {
388                 .bitfield = {
389                         .SYSLV = 0,
390                         .DCDC4LVHV = 1,
391                         .PWRONLP = 0,
392                         .PWRONSP = 0,
393                         .DCDC3LV = 1,
394                         .DCDC2LV = 1,
395                         .DCDC1LV = 1,
396                         .OT = 1,
397                 },
398         },
399         .irq_enable5 = {
400                 .bitfield = {
401                         .GPIO0_IE = 0,
402                         .GPIO1_IE = 0,
403                         .GPIO2_IE = 0,
404                         .RESETB = 1,
405                         .PWRONF = 0,
406                         .PWRONR = 0,
407                         .KPSHDN = 1,
408                 },
409         },
410 };
411
412 static void rt5025_charger_event_callback(uint32_t detected)
413 {
414         RTINFO("event detected = 0x%08x\n", detected);
415 }
416
417 static void rt5025_power_event_callback(uint32_t detected)
418 {
419         RTINFO("event detected = 0x%08x\n", detected);
420 }
421
422 static struct rt5025_event_callback rt5025_event_callback = {
423         .charger_event_callback = rt5025_charger_event_callback,
424         .power_event_callkback = rt5025_power_event_callback,
425 };
426
427 static struct rt5025_platform_data rt5025_data = {
428         .pre_init=rt5025_pre_init,
429         .post_init=rt5025_post_init,
430         .regulator = {
431                 &rt5025_dcdc1_info,
432                 &rt5025_dcdc2_info,
433                 &rt5025_dcdc3_info,
434                 &rt5025_dcdc4_info,
435                 &rt5025_ldo1_info,
436                 &rt5025_ldo2_info,
437                 &rt5025_ldo3_info,
438                 &rt5025_ldo4_info,
439                 &rt5025_ldo5_info,
440                 &rt5025_ldo6_info,
441         },
442         .power_data = &rt5025_power_data,
443         .gpio_data = &rt5025_gpio_data,
444         .misc_data = &rt5025_misc_data,
445         .irq_data = &rt5025_irq_data,
446         .cb = &rt5025_event_callback,
447         .intr_pin = 81, //GPIO81
448 };
449
450 void __sramfunc board_pmu_rt5025_suspend(void)
451 {       
452 }
453 void __sramfunc board_pmu_rt5025_resume(void)
454 {
455 }
456
457
458 #endif
459
460
461
462