ARM64: DTS: Add rk3399-firefly uart4 device, node as /dev/ttyS1
[firefly-linux-kernel-4.4.55.git] / board-pmu-ricoh619.c
1 #include <linux/regulator/machine.h>
2 #include <linux/mfd/ricoh619.h>
3 #include <linux/regulator/ricoh619-regulator.h>
4 #include <linux/power/ricoh619_battery.h>
5 #include <linux/rtc/rtc-ricoh619.h>
6 #include <mach/sram.h>
7 #include <linux/platform_device.h>
8
9 #include <mach/gpio.h>
10 #include <mach/iomux.h>
11 #include <mach/board.h>
12
13 #ifdef CONFIG_MFD_RICOH619
14
15 static struct ricoh619 *Ricoh619;
16 static int ricoh619_pre_init(struct ricoh619 *ricoh619){
17
18         Ricoh619 =      ricoh619;
19         printk("%s,line=%d\n", __func__,__LINE__);      
20         uint8_t cont;
21         int ret;
22
23         ret = ricoh619_clr_bits(ricoh619->dev,RICOH619_PWR_REP_CNT,(1 << 0));  //set restart when power off
24
25         /**********set dcdc mode when in sleep mode **************/
26         
27         /*****************************************************/
28
29         return 0;
30   }
31 static int ricoh619_post_init(struct ricoh619 *ricoh619)
32 {
33         struct regulator *dcdc;
34         struct regulator *ldo;
35         int i = 0,ret=0;
36         printk("%s,line=%d\n", __func__,__LINE__);
37
38         #ifndef CONFIG_RK_CONFIG
39         g_pmic_type = PMIC_TYPE_RICOH619;
40         #endif
41         printk("%s:g_pmic_type=%d\n",__func__,g_pmic_type);
42         
43         for(i = 0; i < ARRAY_SIZE(ricoh619_dcdc_info); i++)
44         {
45
46                 if(ricoh619_dcdc_info[i].min_uv == 0 && ricoh619_dcdc_info[i].max_uv == 0)
47                         continue;
48                 dcdc =regulator_get(NULL, ricoh619_dcdc_info[i].name);
49                 regulator_set_voltage(dcdc, ricoh619_dcdc_info[i].min_uv, ricoh619_dcdc_info[i].max_uv);
50                  regulator_set_suspend_voltage(dcdc, ricoh619_dcdc_info[i].suspend_vol);
51                  regulator_set_mode(dcdc, REGULATOR_MODE_NORMAL);
52                 regulator_enable(dcdc);
53                 printk("%s  %s =%duV end\n", __func__,ricoh619_dcdc_info[i].name, regulator_get_voltage(dcdc));
54                 regulator_put(dcdc);
55                 udelay(100);
56         }
57         
58         for(i = 0; i < ARRAY_SIZE(ricoh619_ldo_info); i++)
59         {
60                 if(ricoh619_ldo_info[i].min_uv == 0 && ricoh619_ldo_info[i].max_uv == 0)
61                         continue;
62                 ldo =regulator_get(NULL, ricoh619_ldo_info[i].name);
63                 regulator_set_voltage(ldo, ricoh619_ldo_info[i].min_uv, ricoh619_ldo_info[i].max_uv);
64                 regulator_enable(ldo);
65                 printk("%s  %s =%duV end\n", __func__,ricoh619_ldo_info[i].name, regulator_get_voltage(ldo));
66                 regulator_put(ldo);
67         }
68
69                 #ifdef CONFIG_RK_CONFIG
70         if(sram_gpio_init(get_port_config(pmic_slp).gpio, &pmic_sleep) < 0){
71                 printk(KERN_ERR "sram_gpio_init failed\n");
72                 return -EINVAL;
73         }
74         if(port_output_init(pmic_slp, 0, "pmic_slp") < 0){
75                 printk(KERN_ERR "port_output_init failed\n");
76                 return -EINVAL;
77         }
78         #else
79         if(sram_gpio_init(PMU_POWER_SLEEP, &pmic_sleep) < 0){
80                 printk(KERN_ERR "sram_gpio_init failed\n");
81                 return -EINVAL;
82         }
83         gpio_request(PMU_POWER_SLEEP, "NULL");
84         gpio_direction_output(PMU_POWER_SLEEP, GPIO_LOW);
85                 
86         #endif
87         
88         ret = ricoh619_clr_bits(ricoh619->dev,0xb1,(7<< 0));  //set vbatdec voltage  3.0v
89         ret = ricoh619_set_bits(ricoh619->dev,0xb1,(3<< 0));  //set vbatdec voltage 3.0v
90         
91         printk("%s,line=%d END\n", __func__,__LINE__);
92         
93         return 0;
94 }
95 static struct regulator_consumer_supply ricoh619_dcdc1_supply[] = {
96         {
97                 .supply = "ricoh_dc1",
98         },
99         {
100                 .supply = "vdd_cpu",
101         },
102         
103 };
104 static struct regulator_consumer_supply ricoh619_dcdc2_supply[] = {
105         {
106                 .supply = "ricoh_dc2",
107         },
108         {
109                 .supply = "vdd_core",
110         },
111         
112 };
113 static struct regulator_consumer_supply ricoh619_dcdc3_supply[] = {
114         {
115                 .supply = "ricoh_dc3",
116         },
117 };
118
119 static struct regulator_consumer_supply ricoh619_dcdc4_supply[] = {
120         {
121                 .supply = "ricoh_dc4",
122         },
123 };
124
125 static struct regulator_consumer_supply ricoh619_dcdc5_supply[] = {
126         {
127                 .supply = "ricoh_dc5",
128         },
129 };
130
131 static struct regulator_consumer_supply ricoh619_ldo1_supply[] = {
132         {
133                 .supply = "ricoh_ldo1",
134         },
135 };
136 static struct regulator_consumer_supply ricoh619_ldo2_supply[] = {
137         {
138                 .supply = "ricoh_ldo2",
139         },
140 };
141
142 static struct regulator_consumer_supply ricoh619_ldo3_supply[] = {
143         {
144                 .supply = "ricoh_ldo3",
145         },
146 };
147 static struct regulator_consumer_supply ricoh619_ldo4_supply[] = {
148         {
149                 .supply = "ricoh_ldo4",
150         },
151 };
152 static struct regulator_consumer_supply ricoh619_ldo5_supply[] = {
153         {
154                 .supply = "ricoh_ldo5",
155         },
156 };
157 static struct regulator_consumer_supply ricoh619_ldo6_supply[] = {
158         {
159                 .supply = "ricoh_ldo6",
160         },
161 };
162 static struct regulator_consumer_supply ricoh619_ldo7_supply[] = {
163         {
164                 .supply = "ricoh_ldo7",
165         },
166 };
167 static struct regulator_consumer_supply ricoh619_ldo8_supply[] = {
168         {
169                 .supply = "ricoh_ldo8",
170         },
171 };
172 static struct regulator_consumer_supply ricoh619_ldo9_supply[] = {
173         {
174                 .supply = "ricoh_ldo9",
175         },
176 };
177 static struct regulator_consumer_supply ricoh619_ldo10_supply[] = {
178         {
179                 .supply = "ricoh_ldo10",
180         },
181 };
182 static struct regulator_consumer_supply ricoh619_ldortc1_supply[] = {
183         {
184                 .supply = "ricoh_ldortc1",
185         },
186 };
187
188 static struct regulator_init_data ricoh619_dcdc1 = {
189         .constraints = {
190                 .name           = "RICOH_DC1",
191                 .min_uV                 = 600000,
192                 .max_uV                 = 3500000,
193                 .apply_uV               = 1,
194                 .always_on = 1,
195                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
196                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
197
198         },
199         .num_consumer_supplies = ARRAY_SIZE(ricoh619_dcdc1_supply),
200         .consumer_supplies =  ricoh619_dcdc1_supply,
201 };
202
203 /* */
204 static struct regulator_init_data ricoh619_dcdc2 = {
205         .constraints = {
206                 .name           = "RICOH_DC2",
207                 .min_uV                 = 600000,
208                 .max_uV                 = 3500000,
209                 .apply_uV               = 1,
210         
211                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
212                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
213
214         },
215         .num_consumer_supplies = ARRAY_SIZE(ricoh619_dcdc2_supply),
216         .consumer_supplies =  ricoh619_dcdc2_supply,
217 };
218
219 /* */
220 static struct regulator_init_data ricoh619_dcdc3 = {
221         .constraints = {
222                 .name           = "RICOH_DC3",
223                 .min_uV                 = 600000,
224                 .max_uV                 = 3500000,
225                 .apply_uV               = 1,
226                 
227                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
228                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
229
230         },
231         .num_consumer_supplies = ARRAY_SIZE(ricoh619_dcdc3_supply),
232         .consumer_supplies =  ricoh619_dcdc3_supply,
233 };
234
235 static struct regulator_init_data ricoh619_dcdc4 = {
236         .constraints = {
237                 .name           = "RICOH_DC4",
238                 .min_uV                 = 600000,
239                 .max_uV                 = 3500000,
240                 .apply_uV               = 1,
241                 
242                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
243                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
244
245         },
246         .num_consumer_supplies = ARRAY_SIZE(ricoh619_dcdc4_supply),
247         .consumer_supplies =  ricoh619_dcdc4_supply,
248 };
249 static struct regulator_init_data ricoh619_dcdc5 = {
250         .constraints = {
251                 .name           = "RICOH_DC5",
252                 .min_uV                 = 600000,
253                 .max_uV                 = 3500000,
254                 .apply_uV               = 1,
255                 
256                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
257                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST,
258
259         },
260         .num_consumer_supplies = ARRAY_SIZE(ricoh619_dcdc5_supply),
261         .consumer_supplies =  ricoh619_dcdc5_supply,
262 };
263
264 static struct regulator_init_data ricoh619_ldo1 = {
265         .constraints = {
266                 .name           = "RICOH_LDO1",
267                 .min_uV                 = 900000,
268                 .max_uV                 = 3500000,
269                 .apply_uV               = 1,
270                 
271                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
272                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
273
274         },
275         .num_consumer_supplies = ARRAY_SIZE(ricoh619_ldo1_supply),
276         .consumer_supplies =  ricoh619_ldo1_supply,
277 };
278
279 /* */
280 static struct regulator_init_data ricoh619_ldo2 = {
281         .constraints = {
282                 .name           = "RICOH_LDO2",
283                 .min_uV                 = 900000,
284                 .max_uV                 = 3500000,
285                 .apply_uV               = 1,
286                 
287                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
288                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
289
290         },
291         .num_consumer_supplies = ARRAY_SIZE(ricoh619_ldo2_supply),
292         .consumer_supplies =  ricoh619_ldo2_supply,
293 };
294
295 /* */
296 static struct regulator_init_data ricoh619_ldo3 = {
297         .constraints = {
298                 .name           = "RICOH_LDO3",
299                 .min_uV                 = 900000,
300                 .max_uV                 = 3500000,
301                 .apply_uV               = 1,
302                 
303                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
304                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
305
306         },
307         .num_consumer_supplies = ARRAY_SIZE(ricoh619_ldo3_supply),
308         .consumer_supplies =  ricoh619_ldo3_supply,
309 };
310
311 /* */
312 static struct regulator_init_data ricoh619_ldo4 = {
313         .constraints = {
314                 .name           = "RICOH_LDO4",
315                 .min_uV                 = 900000,
316                 .max_uV                 = 3500000,
317                 .apply_uV               = 1,
318                 
319                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
320                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
321
322         },
323         .num_consumer_supplies = ARRAY_SIZE(ricoh619_ldo4_supply),
324         .consumer_supplies =  ricoh619_ldo4_supply,
325 };
326
327 /* */
328 static struct regulator_init_data ricoh619_ldo5 = {
329         .constraints = {
330                 .name           = "RICOH_LDO5",
331                 .min_uV                 = 900000,
332                 .max_uV                 = 3500000,
333                 .apply_uV               = 1,
334                 
335                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
336                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
337
338         },
339         .num_consumer_supplies = ARRAY_SIZE(ricoh619_ldo5_supply),
340         .consumer_supplies =  ricoh619_ldo5_supply,
341 };
342
343 static struct regulator_init_data ricoh619_ldo6 = {
344         .constraints = {
345                 .name           = "RICOH_LDO6",
346                 .min_uV                 = 900000,
347                 .max_uV                 = 3500000,
348                 .apply_uV               = 1,
349                 
350                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
351                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
352
353         },
354         .num_consumer_supplies = ARRAY_SIZE(ricoh619_ldo6_supply),
355         .consumer_supplies =  ricoh619_ldo6_supply,
356 };
357
358 static struct regulator_init_data ricoh619_ldo7 = {
359         .constraints = {
360                 .name           = "RICOH_LDO7",
361                 .min_uV                 = 900000,
362                 .max_uV                 = 3500000,
363                 .apply_uV               = 1,
364                 
365                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
366                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
367
368         },
369         .num_consumer_supplies = ARRAY_SIZE(ricoh619_ldo7_supply),
370         .consumer_supplies =  ricoh619_ldo7_supply,
371 };
372
373 static struct regulator_init_data ricoh619_ldo8 = {
374         .constraints = {
375                 .name           = "RICOH_LDO8",
376                 .min_uV                 = 900000,
377                 .max_uV                 = 3500000,
378                 .apply_uV               = 1,
379                 
380                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
381                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
382
383         },
384         .num_consumer_supplies = ARRAY_SIZE(ricoh619_ldo8_supply),
385         .consumer_supplies =  ricoh619_ldo8_supply,
386 };
387
388 static struct regulator_init_data ricoh619_ldo9 = {
389         .constraints = {
390                 .name           = "RICOH_LDO9",
391                 .min_uV                 = 900000,
392                 .max_uV                 = 3500000,
393                 .apply_uV               = 1,
394                 
395                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
396                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
397
398         },
399         .num_consumer_supplies = ARRAY_SIZE(ricoh619_ldo9_supply),
400         .consumer_supplies =  ricoh619_ldo9_supply,
401 };
402
403 static struct regulator_init_data ricoh619_ldo10 = {
404         .constraints = {
405                 .name           = "RICOH_LDO10",
406                 .min_uV                 = 900000,
407                 .max_uV                 = 3500000,
408                 .apply_uV               = 1,
409                 
410                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
411                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
412
413         },
414         .num_consumer_supplies = ARRAY_SIZE(ricoh619_ldo10_supply),
415         .consumer_supplies =  ricoh619_ldo10_supply,
416 };
417
418 /* */
419 static struct regulator_init_data ricoh619_ldortc1 = {
420         .constraints = {
421                 .name           = "RICOH_LDORTC1",
422                 .min_uV                 = 1700000,
423                 .max_uV                 = 3500000,
424                 .apply_uV               = 1,
425   
426                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
427                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
428
429         },
430         .num_consumer_supplies = ARRAY_SIZE(ricoh619_ldortc1_supply),
431         .consumer_supplies =  ricoh619_ldortc1_supply,
432 };
433
434 static struct ricoh619_battery_platform_data ricoh619_power_battery = {
435         .irq = IRQ_BOARD_BASE,
436         .alarm_vol_mv = 3300,
437         .multiple =0,
438         .monitor_time = 1,
439 };
440
441 static struct rtc_time rk_time = {      //      2012.1.1 12:00:00 Saturday
442                         .tm_wday = 6,
443                         .tm_year = 111,
444                         .tm_mon = 0,
445                         .tm_mday = 1,
446                         .tm_hour = 12,
447                         .tm_min = 0,
448                         .tm_sec = 0,
449 };
450
451 static struct ricoh619_rtc_platform_data ricoh619_rtc_data = {
452         .irq = IRQ_BOARD_BASE ,
453         .time = &rk_time,
454 };
455
456 #define RICOH_REG(_id, _data)  \
457 { \
458                 .id = RICOH619_ID_##_id, \
459                 .name = "ricoh619-regulator", \
460                 .platform_data = _data, \
461 } \
462
463 static struct ricoh619_pwrkey_platform_data ricoh619_pwrkey_data= { 
464         .irq = IRQ_BOARD_BASE + RICOH619_IRQ_POWER_ON, 
465         .delay_ms = 20, 
466 }; 
467
468 static struct ricoh619_subdev_info ricoh619_devs[] = {
469         RICOH_REG(DC1, &ricoh619_dcdc1),
470         RICOH_REG(DC2, &ricoh619_dcdc2),
471         RICOH_REG(DC3, &ricoh619_dcdc3),
472         RICOH_REG(DC4, &ricoh619_dcdc4),
473         RICOH_REG(DC5, &ricoh619_dcdc5),
474         
475         RICOH_REG(LDO1, &ricoh619_ldo1),
476         RICOH_REG(LDO2, &ricoh619_ldo2),
477         RICOH_REG(LDO3, &ricoh619_ldo3),
478         RICOH_REG(LDO4, &ricoh619_ldo4),
479         RICOH_REG(LDO5, &ricoh619_ldo5),
480         RICOH_REG(LDO6, &ricoh619_ldo6),
481         RICOH_REG(LDO7, &ricoh619_ldo7),
482         RICOH_REG(LDO8, &ricoh619_ldo8),
483         RICOH_REG(LDO9, &ricoh619_ldo9),
484         RICOH_REG(LDO10, &ricoh619_ldo10),
485         RICOH_REG(LDORTC1, &ricoh619_ldortc1),
486         
487         {                                       
488                 .id = 16,  
489                 .name ="ricoh619-battery",
490                 .platform_data = &ricoh619_power_battery,
491         },
492         
493         {                                       
494                 .id = 17,  
495                 .name ="rtc_ricoh619",
496                 .platform_data = &ricoh619_rtc_data,
497         },
498         
499         {                                       
500                 .id = 18,  
501                 .name ="ricoh619-pwrkey",
502                 .platform_data = &ricoh619_pwrkey_data,
503         },
504         
505 };
506
507 #define RICOH_GPIO_INIT(_init_apply, _output_mode, _output_val, _led_mode, _led_func)  \
508 {  \
509         .output_mode_en = _output_mode,  \
510         .output_val = _output_val,  \
511         .init_apply = _init_apply,   \
512         .led_mode = _led_mode,  \
513         .led_func = _led_func,  \
514 }  \
515
516 struct ricoh619_gpio_init_data ricoh_gpio_data[] = { 
517         RICOH_GPIO_INIT(0, 1, 0, 0, 1), 
518         RICOH_GPIO_INIT(0, 0, 0, 0, 0), 
519         RICOH_GPIO_INIT(0, 0, 0, 0, 0), 
520         RICOH_GPIO_INIT(0, 0, 0, 0, 0), 
521         RICOH_GPIO_INIT(0, 0, 0, 0, 0), 
522 }; 
523
524 static struct ricoh619_platform_data ricoh619_data={
525         .irq_base = IRQ_BOARD_BASE,
526 //      .init_port  = RICOH619_HOST_IRQ,
527         .num_subdevs    = ARRAY_SIZE(ricoh619_devs),
528         .subdevs        = ricoh619_devs,
529         .pre_init = ricoh619_pre_init,
530         .post_init = ricoh619_post_init,
531         //.gpio_base = RICOH619_GPIO_EXPANDER_BASE, 
532         .gpio_init_data = ricoh_gpio_data, 
533         .num_gpioinit_data = ARRAY_SIZE(ricoh_gpio_data),
534         .enable_shutdown_pin = 0, 
535 };
536
537 void __sramfunc board_pmu_ricoh619_suspend(void)
538 {       
539         #ifdef CONFIG_CLK_SWITCH_TO_32K
540          sram_gpio_set_value(pmic_sleep, GPIO_HIGH);  
541         #endif
542 }
543 void __sramfunc board_pmu_ricoh619_resume(void)
544 {
545         #ifdef CONFIG_CLK_SWITCH_TO_32K
546         sram_gpio_set_value(pmic_sleep, GPIO_LOW);  
547         sram_udelay(2000);
548         #endif
549 }
550
551
552 #endif
553
554
555
556