ac:add charge current set
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk3188 / board-rk3188-ac.c
1 /*
2  *
3  * Copyright (C) 2012 ROCKCHIP, Inc.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/input.h>
20 #include <linux/io.h>
21 #include <linux/delay.h>
22 #include <linux/i2c.h>
23 #include <linux/skbuff.h>
24 #include <linux/spi/spi.h>
25 #include <linux/mmc/host.h>
26 #include <linux/ion.h>
27 #include <linux/cpufreq.h>
28 #include <linux/clk.h>
29 #include <mach/dvfs.h>
30
31 #include <asm/setup.h>
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35 #include <asm/mach/flash.h>
36 #include <asm/hardware/gic.h>
37
38 #include <mach/board.h>
39 #include <mach/hardware.h>
40 #include <mach/io.h>
41 #include <mach/gpio.h>
42 #include <mach/iomux.h>
43 #include <linux/rk_fb.h>
44 #include <linux/regulator/machine.h>
45 #include <linux/rfkill-rk.h>
46 #include <linux/sensor-dev.h>
47 #include <linux/mfd/tps65910.h>
48 #include <linux/regulator/act8846.h>
49 #include <plat/efuse.h>
50 #include <linux/regulator/rk29-pwm-regulator.h>
51 #if defined(CONFIG_CT36X_TS)
52 #include <linux/ct36x.h>
53 #endif
54 #if defined(CONFIG_MFD_RK610)
55 #include <linux/mfd/rk610_core.h>
56 #endif
57
58 #if defined(CONFIG_RK_HDMI)
59         #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
60 #endif
61
62 #if defined(CONFIG_SPIM_RK29)
63 #include "../../../drivers/spi/rk29_spim.h"
64 #endif
65 #if defined(CONFIG_MT6229)
66 #include <linux/mt6229.h>
67 #endif
68 #if defined(CONFIG_GPS_RK)
69 #include "../../../drivers/misc/gps/rk_gps/rk_gps.h"
70 #endif
71
72 #if defined(CONFIG_MT6620)
73 #include <linux/gps.h>
74 #endif
75
76 #include "../mach-rk30/board-rk3168-ds1006h-camera.c"
77 #include <plat/key.h>
78
79 static struct rk29_keys_button key_button[] = {
80         {
81                 .desc   = "play",
82                 .code   = KEY_POWER,
83                 .gpio   = RK30_PIN0_PA4, 
84                 .active_low = PRESS_LEV_LOW,
85                 .wakeup = 1,
86         },
87         {
88                 .desc   = "esc",
89                 .code   = KEY_BACK,
90                 .adc_value      = 1,
91                 .gpio = INVALID_GPIO,
92                 .active_low = PRESS_LEV_LOW,
93         },
94 };
95 struct rk29_keys_platform_data rk29_keys_pdata = {
96         .buttons        = key_button,
97         .nbuttons       = ARRAY_SIZE(key_button),
98         .chn    = 1,  //chn: 0-7, if do not use ADC,set 'chn' -1
99 };
100
101 /*
102      v1.0 :     ignore
103      v1.1 :      rk610 lvds + rk610 codec + MT5931_MT6622 + light photoresistor + adc/cw2015
104      v1.2 :      lvds       + rt5631      + M500          + us5151              + adc
105 */
106 #define DS1006H_V1_2_SUPPORT  1
107 int get_harware_version()
108 {
109     #if DS1006H_V1_2_SUPPORT
110         return 2;
111     #else
112         return 1;
113     #endif
114 }
115 EXPORT_SYMBOL_GPL(get_harware_version);
116
117 #if defined(CONFIG_CT36X_TS)
118
119 #define TOUCH_MODEL             363
120 #define TOUCH_MAX_X             1280
121 #define TOUCH_MAX_y             800
122 #define TOUCH_RESET_PIN         RK30_PIN0_PB6
123 #define TOUCH_INT_PIN           RK30_PIN1_PB7
124
125 static struct ct36x_platform_data ct36x_info = {
126         .model   = TOUCH_MODEL,
127         .x_max   = TOUCH_MAX_X,
128         .y_max   = TOUCH_MAX_y,
129
130         .rst_io = {
131                 .gpio = TOUCH_RESET_PIN,
132                 .active_low = 1,
133         },
134         .irq_io = {
135                 .gpio = TOUCH_INT_PIN,
136                 .active_low = 1,
137         },
138         .orientation = {1, 0, 0, 1},
139 };
140 #endif
141 static struct spi_board_info board_spi_devices[] = {
142 };
143
144 /***********************************************************
145 *       rk30  backlight
146 ************************************************************/
147 #ifdef CONFIG_BACKLIGHT_RK29_BL
148 #define PWM_ID            3
149 #define PWM_MODE          PWM3
150 #define PWM_EFFECT_VALUE  1
151
152 #define LCD_DISP_ON_PIN
153
154 #ifdef  LCD_DISP_ON_PIN
155 #define BL_EN_PIN         RK30_PIN0_PA2
156 #define BL_EN_VALUE       GPIO_HIGH
157 #endif
158 static int rk29_backlight_io_init(void)
159 {
160         int ret = 0;
161
162         iomux_set(PWM_MODE);
163 #ifdef  LCD_DISP_ON_PIN
164         ret = gpio_request(BL_EN_PIN, NULL);
165         if (ret != 0) {
166                 gpio_free(BL_EN_PIN);
167         }
168
169         gpio_direction_output(BL_EN_PIN, 0);
170         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
171 #endif
172
173         return ret;
174 }
175
176 static int rk29_backlight_io_deinit(void)
177 {
178         int ret = 0, pwm_gpio;
179
180 #ifdef  LCD_DISP_ON_PIN
181         gpio_free(BL_EN_PIN);
182 #endif
183
184         pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
185         gpio_request(pwm_gpio, NULL);
186         gpio_direction_output(pwm_gpio, GPIO_LOW);
187         return ret;
188 }
189
190 static int rk29_backlight_pwm_suspend(void)
191 {
192         int ret = 0, pwm_gpio;
193
194         pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
195         if (gpio_request(pwm_gpio, NULL)) {
196                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
197                 return -1;
198         }
199         gpio_direction_output(pwm_gpio, GPIO_LOW);
200 #ifdef  LCD_DISP_ON_PIN
201         gpio_direction_output(BL_EN_PIN, 0);
202         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
203 #endif
204         return ret;
205 }
206
207 static int rk29_backlight_pwm_resume(void)
208 {
209         int pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
210
211         gpio_free(pwm_gpio);
212         iomux_set(PWM_MODE);
213 #ifdef  LCD_DISP_ON_PIN
214         msleep(30);
215         gpio_direction_output(BL_EN_PIN, 1);
216         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
217 #endif
218         return 0;
219 }
220
221 static struct rk29_bl_info rk29_bl_info = {
222         .min_brightness = 65,
223         .max_brightness = 150,
224         .brightness_mode =BRIGHTNESS_MODE_CONIC,
225         .pre_div = 30 * 1000,  // pwm output clk: 30k;
226         .pwm_id = PWM_ID,
227         .bl_ref = PWM_EFFECT_VALUE,
228         .io_init = rk29_backlight_io_init,
229         .io_deinit = rk29_backlight_io_deinit,
230         .pwm_suspend = rk29_backlight_pwm_suspend,
231         .pwm_resume = rk29_backlight_pwm_resume,
232 };
233
234 static struct platform_device rk29_device_backlight = {
235         .name   = "rk29_backlight",
236         .id     = -1,
237         .dev    = {
238                 .platform_data  = &rk29_bl_info,
239         }
240 };
241
242 #endif
243
244 /*MMA8452 gsensor*/
245 #if defined (CONFIG_GS_MMA8452)
246 #define MMA8452_INT_PIN   RK30_PIN0_PB7
247
248 static int mma8452_init_platform_hw(void)
249 {
250         return 0;
251 }
252
253 static struct sensor_platform_data mma8452_info = {
254         .type = SENSOR_TYPE_ACCEL,
255         .irq_enable = 1,
256         .poll_delay_ms = 30,
257         .init_platform_hw = mma8452_init_platform_hw,
258         .orientation = {-1, 0, 0, 0, 0, -1, 0, 1, 0},
259 };
260 #endif
261 #if defined (CONFIG_GS_LIS3DH)
262 #define LIS3DH_INT_PIN   RK30_PIN0_PB7
263
264 static int lis3dh_init_platform_hw(void)
265 {
266
267         return 0;
268 }
269
270 static struct sensor_platform_data lis3dh_info = {
271         .type = SENSOR_TYPE_ACCEL,
272         .irq_enable = 1,
273         .poll_delay_ms = 30,
274         .init_platform_hw = lis3dh_init_platform_hw,
275         .orientation = {-1, 0, 0, 0, 1, 0, 0, 0, -1},
276 };
277 #endif
278
279 #if defined (CONFIG_COMPASS_AK8963)
280 static struct sensor_platform_data akm8963_info =
281 {
282        .type = SENSOR_TYPE_COMPASS,
283        .irq_enable = 1,
284        .poll_delay_ms = 30,
285        .m_layout = 
286        {
287                {
288                        {0, 1, 0},
289                        {1, 0, 0},
290                        {0, 0, -1},
291                },
292
293                {
294                        {1, 0, 0},
295                        {0, 1, 0},
296                        {0, 0, 1},
297                },
298
299                {
300                        {0, -1, 0},
301                        {-1, 0, 0},
302                        {0, 0, -1},
303                },
304
305                {
306                        {1, 0, 0},
307                        {0, 1, 0},
308                        {0, 0, 1},
309                },
310        }
311 };
312
313 #endif
314
315 #if defined(CONFIG_LS_PHOTORESISTOR)
316 static struct sensor_platform_data light_photoresistor_info = {
317         .type = SENSOR_TYPE_LIGHT,
318         .irq_enable = 0,
319         .address = 2   ,
320         .poll_delay_ms = 200,
321 };
322 #endif
323
324 #if defined (CONFIG_COMPASS_AK8975)
325 static struct sensor_platform_data akm8975_info =
326 {
327         .type = SENSOR_TYPE_COMPASS,
328         .irq_enable = 1,
329         .poll_delay_ms = 30,
330         .m_layout = 
331         {
332                 {
333                         {1, 0, 0},
334                         {0, 1, 0},
335                         {0, 0, 1},
336                 },
337
338                 {
339                         {1, 0, 0},
340                         {0, 1, 0},
341                         {0, 0, 1},
342                 },
343
344                 {
345                         {1, 0, 0},
346                         {0, 1, 0},
347                         {0, 0, 1},
348                 },
349
350                 {
351                         {1, 0, 0},
352                         {0, 1, 0},
353                         {0, 0, 1},
354                 },
355         }
356 };
357
358 #endif
359
360 #if defined(CONFIG_MT6229)
361 static int mt6229_io_init(void)
362 {
363       #if 0
364         rk30_mux_api_set(GPIO2B6_LCDC1DATA14_SMCADDR18_TSSYNC_NAME, GPIO2B_GPIO2B6);
365       k30_mux_api_set(GPIO4D2_SMCDATA10_TRACEDATA10_NAME, GPIO4D_GPIO4D2);
366         rk30_mux_api_set(GPIO2B7_LCDC1DATA15_SMCADDR19_HSADCDATA7_NAME, GPIO2B_GPIO2B7);
367         rk30_mux_api_set(GPIO2C0_LCDCDATA16_GPSCLK_HSADCCLKOUT_NAME, GPIO2C_GPIO2C0);
368         rk30_mux_api_set(GPIO2C1_LCDC1DATA17_SMCBLSN0_HSADCDATA6_NAME, GPIO2C_GPIO2C1);
369         rk30_mux_api_set(GPIO2C1_LCDC1DATA17_SMCBLSN0_HSADCDATA6_NAME, GPIO2C_GPIO2C1);
370       #endif
371          return 0;
372 }
373
374 static int mt6229_io_deinit(void)
375 {
376         
377         return 0;
378 }
379  
380 struct rk29_mt6229_data rk29_mt6229_info = {
381         .io_init = mt6229_io_init,
382         .io_deinit = mt6229_io_deinit,
383         .modem_power_en = RK30_PIN0_PC6,
384         .bp_power = RK30_PIN2_PD5,
385         .modem_usb_en = RK30_PIN0_PC7,
386         .modem_uart_en = RK30_PIN2_PD4,
387         .bp_wakeup_ap = RK30_PIN0_PC5,
388         .ap_ready = RK30_PIN0_PC4,
389
390 };
391 struct platform_device rk29_device_mt6229 = {   
392         .name = "mt6229",       
393         .id = -1,       
394         .dev            = {
395                 .platform_data = &rk29_mt6229_info,
396         }       
397     };
398 #endif
399
400 #if defined(CONFIG_GYRO_L3G4200D)
401
402 #include <linux/l3g4200d.h>
403 #define L3G4200D_INT_PIN  RK30_PIN0_PB4
404
405 static int l3g4200d_init_platform_hw(void)
406 {
407         return 0;
408 }
409
410 static struct sensor_platform_data l3g4200d_info = {
411         .type = SENSOR_TYPE_GYROSCOPE,
412         .irq_enable = 1,
413         .poll_delay_ms = 0,
414         .orientation = {1, 0, 0 , 0 , -1, 0, 0, 0, -1},
415         .init_platform_hw = l3g4200d_init_platform_hw,
416         .x_min = 40,//x_min,y_min,z_min = (0-100) according to hardware
417         .y_min = 40,
418         .z_min = 20,
419 };
420
421 #endif
422
423 #ifdef CONFIG_LS_CM3217
424 static struct sensor_platform_data cm3217_info = {
425         .type = SENSOR_TYPE_LIGHT,
426         .irq_enable = 0,
427         .poll_delay_ms = 500,
428 };
429
430 #endif
431
432 #ifdef CONFIG_FB_ROCKCHIP
433
434 #if DS1006H_V1_2_SUPPORT
435 #define LCD_CS_PIN         RK30_PIN0_PB0
436 #else
437 #define LCD_CS_PIN         INVALID_GPIO
438 #endif
439 #define LCD_CS_VALUE       GPIO_HIGH
440
441 #if DS1006H_V1_2_SUPPORT
442 #define LCD_EN_PIN         RK30_PIN0_PB1
443 #else
444 #define LCD_EN_PIN         RK30_PIN0_PB0
445 #endif
446 #define LCD_EN_VALUE       GPIO_LOW
447
448 static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
449 {
450         int ret = 0;
451
452         if(LCD_CS_PIN !=INVALID_GPIO)
453         {
454                 ret = gpio_request(LCD_CS_PIN, NULL);
455                 if (ret != 0)
456                 {
457                         gpio_free(LCD_CS_PIN);
458                         printk(KERN_ERR "request lcd cs pin fail!\n");
459                         return -1;
460                 }
461                 else
462                 {
463                         gpio_direction_output(LCD_CS_PIN, LCD_CS_VALUE);
464                 }
465         }
466
467         if(LCD_EN_PIN !=INVALID_GPIO)
468         {
469                 ret = gpio_request(LCD_EN_PIN, NULL);
470                 if (ret != 0)
471                 {
472                         gpio_free(LCD_EN_PIN);
473                         printk(KERN_ERR "request lcd en pin fail!\n");
474                         return -1;
475                 }
476                 else
477                 {
478                         gpio_direction_output(LCD_EN_PIN, LCD_EN_VALUE);
479                 }
480         }
481         return 0;
482 }
483 static int rk_fb_io_disable(void)
484 {
485         if(LCD_CS_PIN !=INVALID_GPIO)
486         {
487                 gpio_set_value(LCD_CS_PIN, !LCD_CS_VALUE);
488         }
489         if(LCD_EN_PIN !=INVALID_GPIO)
490         {
491                 gpio_set_value(LCD_EN_PIN, !LCD_EN_VALUE);
492         }
493         return 0;
494 }
495 static int rk_fb_io_enable(void)
496 {
497         if(LCD_CS_PIN !=INVALID_GPIO)
498         {
499                 gpio_set_value(LCD_CS_PIN, LCD_CS_VALUE);
500         }
501         if(LCD_EN_PIN !=INVALID_GPIO)
502         {
503                 gpio_set_value(LCD_EN_PIN, LCD_EN_VALUE);
504         }
505         return 0;
506 }
507
508 #if defined(CONFIG_LCDC0_RK3188)
509 struct rk29fb_info lcdc0_screen_info = {
510         .prop           = EXTEND,       //extend display device
511        .lcd_info  = NULL,
512        .set_screen_info = hdmi_init_lcdc,
513
514 };
515 #endif
516
517 #if defined(CONFIG_LCDC1_RK3188)
518 struct rk29fb_info lcdc1_screen_info = {
519         .prop      = PRMRY,             //primary display device
520         .io_init   = rk_fb_io_init,
521         .io_disable = rk_fb_io_disable,
522         .io_enable = rk_fb_io_enable,
523         .set_screen_info = set_lcd_info,
524         
525 };
526 #endif
527
528 static struct resource resource_fb[] = {
529         [0] = {
530                 .name  = "fb0 buf",
531                 .start = 0,
532                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
533                 .flags = IORESOURCE_MEM,
534         },
535         [1] = {
536                 .name  = "ipp buf",  //for rotate
537                 .start = 0,
538                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
539                 .flags = IORESOURCE_MEM,
540         },
541         [2] = {
542                 .name  = "fb2 buf",
543                 .start = 0,
544                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
545                 .flags = IORESOURCE_MEM,
546         },
547 };
548
549 static struct platform_device device_fb = {
550         .name           = "rk-fb",
551         .id             = -1,
552         .num_resources  = ARRAY_SIZE(resource_fb),
553         .resource       = resource_fb,
554 };
555 #endif
556
557 #if defined(CONFIG_ARCH_RK3188)
558 static struct resource resource_mali[] = {
559         [0] = {
560         .name  = "ump buf",
561         .start = 0,
562         .end   = 0,
563         .flags = IORESOURCE_MEM,
564         },
565
566 };
567
568 static struct platform_device device_mali= {
569         .name           = "mali400_ump",
570         .id             = -1,
571         .num_resources  = ARRAY_SIZE(resource_mali),
572         .resource       = resource_mali,
573 };
574 #endif
575
576 #if defined(CONFIG_LCDC0_RK3188)
577 static struct resource resource_lcdc0[] = {
578         [0] = {
579                 .name  = "lcdc0 reg",
580                 .start = RK30_LCDC0_PHYS,
581                 .end   = RK30_LCDC0_PHYS + RK30_LCDC0_SIZE - 1,
582                 .flags = IORESOURCE_MEM,
583         },
584         
585         [1] = {
586                 .name  = "lcdc0 irq",
587                 .start = IRQ_LCDC0,
588                 .end   = IRQ_LCDC0,
589                 .flags = IORESOURCE_IRQ,
590         },
591 };
592
593 static struct platform_device device_lcdc0 = {
594         .name             = "rk30-lcdc",
595         .id               = 0,
596         .num_resources    = ARRAY_SIZE(resource_lcdc0),
597         .resource         = resource_lcdc0,
598         .dev            = {
599                 .platform_data = &lcdc0_screen_info,
600         },
601 };
602 #endif
603 #if defined(CONFIG_LCDC1_RK3188) 
604 static struct resource resource_lcdc1[] = {
605         [0] = {
606                 .name  = "lcdc1 reg",
607                 .start = RK30_LCDC1_PHYS,
608                 .end   = RK30_LCDC1_PHYS + RK30_LCDC1_SIZE - 1,
609                 .flags = IORESOURCE_MEM,
610         },
611         [1] = {
612                 .name  = "lcdc1 irq",
613                 .start = IRQ_LCDC1,
614                 .end   = IRQ_LCDC1,
615                 .flags = IORESOURCE_IRQ,
616         },
617 };
618
619 static struct platform_device device_lcdc1 = {
620         .name             = "rk30-lcdc",
621         .id               = 1,
622         .num_resources    = ARRAY_SIZE(resource_lcdc1),
623         .resource         = resource_lcdc1,
624         .dev            = {
625                 .platform_data = &lcdc1_screen_info,
626         },
627 };
628 #endif
629
630 #if defined(CONFIG_MFD_RK610)
631 #define RK610_RST_PIN                   RK30_PIN3_PB2
632 static int rk610_power_on_init(void)
633 {
634         int ret;
635         if(RK610_RST_PIN != INVALID_GPIO)
636         {
637                 ret = gpio_request(RK610_RST_PIN, "rk610 reset");
638                 if (ret)
639                 {
640                         printk(KERN_ERR "rk610_control_probe request gpio fail\n");
641                 }
642                 else 
643                 {
644                         gpio_direction_output(RK610_RST_PIN, GPIO_HIGH);
645                         msleep(100);
646                         gpio_direction_output(RK610_RST_PIN, GPIO_LOW);
647                         msleep(100);
648                         gpio_set_value(RK610_RST_PIN, GPIO_HIGH);
649                 }
650         }
651
652         return 0;
653         
654 }
655
656
657 static struct rk610_ctl_platform_data rk610_ctl_pdata = {
658         .rk610_power_on_init = rk610_power_on_init,
659 };
660 #endif
661
662 #ifdef CONFIG_SND_SOC_RK610
663 static int rk610_codec_io_init(void)
664 {
665 //if need iomux.
666 //Must not gpio_request
667         return 0;
668 }
669
670 static struct rk610_codec_platform_data rk610_codec_pdata = {
671         .spk_ctl_io = RK30_PIN2_PD7,
672         .io_init = rk610_codec_io_init,
673         .boot_depop = 1,
674 };
675 #endif
676
677 #ifdef CONFIG_RK_HDMI
678 #define RK_HDMI_RST_PIN                         RK30_PIN3_PB2
679 static int rk_hdmi_power_init(void)
680 {
681         int ret;
682
683         if(RK_HDMI_RST_PIN != INVALID_GPIO)
684         {
685                 if (gpio_request(RK_HDMI_RST_PIN, NULL)) {
686                         printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
687                         return -1;
688                 }
689                 gpio_direction_output(RK_HDMI_RST_PIN, GPIO_LOW);
690                 gpio_set_value(RK_HDMI_RST_PIN, GPIO_LOW);
691                 msleep(100);
692                 gpio_set_value(RK_HDMI_RST_PIN, GPIO_HIGH);
693                 msleep(50);
694         }
695         return 0;
696 }
697 static struct rk_hdmi_platform_data rk_hdmi_pdata = {
698         //.io_init = rk_hdmi_power_init,
699 };
700 #endif
701 #ifdef CONFIG_ION
702 #define ION_RESERVE_SIZE        (80 * SZ_1M)
703 static struct ion_platform_data rk30_ion_pdata = {
704         .nr = 1,
705         .heaps = {
706                 {
707                         .type = ION_HEAP_TYPE_CARVEOUT,
708                         .id = ION_NOR_HEAP_ID,
709                         .name = "norheap",
710                         .size = ION_RESERVE_SIZE,
711                 }
712         },
713 };
714
715 static struct platform_device device_ion = {
716         .name = "ion-rockchip",
717         .id = 0,
718         .dev = {
719                 .platform_data = &rk30_ion_pdata,
720         },
721 };
722 #endif
723
724 /**************************************************************************************************
725  * SDMMC devices,  include the module of SD,MMC,and sdio.noted by xbw at 2012-03-05
726 **************************************************************************************************/
727 #ifdef CONFIG_SDMMC_RK29
728 #include "board-rk3188-ds1006h-sdmmc-config.c"
729 #include "../plat-rk/rk-sdmmc-ops.c"
730 #include "../plat-rk/rk-sdmmc-wifi.c"
731 #endif //endif ---#ifdef CONFIG_SDMMC_RK29
732
733 #ifdef CONFIG_SDMMC0_RK29
734 static int rk29_sdmmc0_cfg_gpio(void)
735 {
736 #ifdef CONFIG_SDMMC_RK29_OLD
737         iomux_set(MMC0_CMD);
738         iomux_set(MMC0_CLKOUT);
739         iomux_set(MMC0_D0);
740         iomux_set(MMC0_D1);
741         iomux_set(MMC0_D2);
742         iomux_set(MMC0_D3);
743
744         iomux_set_gpio_mode(iomux_mode_to_gpio(MMC0_DETN));
745
746         gpio_request(RK30_PIN3_PA7, "sdmmc-power");
747         gpio_direction_output(RK30_PIN3_PA7, GPIO_LOW);
748
749 #else
750         rk29_sdmmc_set_iomux(0, 0xFFFF);
751
752     #if defined(CONFIG_SDMMC0_RK29_SDCARD_DET_FROM_GPIO)
753         #if SDMMC_USE_NEW_IOMUX_API
754         iomux_set_gpio_mode(iomux_gpio_to_mode(RK29SDK_SD_CARD_DETECT_N));
755         #else
756         rk30_mux_api_set(RK29SDK_SD_CARD_DETECT_PIN_NAME, RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO);
757         #endif
758     #else
759         #if SDMMC_USE_NEW_IOMUX_API       
760         iomux_set(MMC0_DETN);
761         #else
762         rk30_mux_api_set(RK29SDK_SD_CARD_DETECT_PIN_NAME, RK29SDK_SD_CARD_DETECT_IOMUX_FMUX);
763         #endif
764     #endif      
765
766 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
767         gpio_request(SDMMC0_WRITE_PROTECT_PIN, "sdmmc-wp");
768         gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);
769 #endif
770
771 #endif
772
773         return 0;
774 }
775
776 #define CONFIG_SDMMC0_USE_DMA
777 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
778         .host_ocr_avail =
779             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
780              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
781              MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36),
782         .host_caps =
783             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
784         .io_init = rk29_sdmmc0_cfg_gpio,
785
786 #if !defined(CONFIG_SDMMC_RK29_OLD)
787         .set_iomux = rk29_sdmmc_set_iomux,
788 #endif
789
790         .dma_name = "sd_mmc",
791 #ifdef CONFIG_SDMMC0_USE_DMA
792         .use_dma = 1,
793 #else
794         .use_dma = 0,
795 #endif
796
797 #if defined(CONFIG_WIFI_COMBO_MODULE_CONTROL_FUNC) && defined(CONFIG_USE_SDMMC0_FOR_WIFI_DEVELOP_BOARD)
798     .status = rk29sdk_wifi_mmc0_status,
799     .register_status_notify = rk29sdk_wifi_mmc0_status_register,
800 #endif
801
802 #if defined(RK29SDK_SD_CARD_PWR_EN) || (INVALID_GPIO != RK29SDK_SD_CARD_PWR_EN)
803     .power_en = RK29SDK_SD_CARD_PWR_EN,
804     .power_en_level = RK29SDK_SD_CARD_PWR_EN_LEVEL,
805 #else
806     .power_en = INVALID_GPIO,
807     .power_en_level = GPIO_LOW,
808 #endif    
809         .enable_sd_wakeup = 0,
810
811 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
812         .write_prt = SDMMC0_WRITE_PROTECT_PIN,
813         .write_prt_enalbe_level = SDMMC0_WRITE_PROTECT_ENABLE_VALUE;
814 #else
815         .write_prt = INVALID_GPIO,
816 #endif
817
818     .det_pin_info = {    
819     #if defined(RK29SDK_SD_CARD_DETECT_N) || (INVALID_GPIO != RK29SDK_SD_CARD_DETECT_N)  
820         .io             = RK29SDK_SD_CARD_DETECT_N, //INVALID_GPIO,
821         .enable         = RK29SDK_SD_CARD_INSERT_LEVEL,
822         #ifdef RK29SDK_SD_CARD_DETECT_PIN_NAME
823         .iomux          = {
824             .name       = RK29SDK_SD_CARD_DETECT_PIN_NAME,
825             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO
826             .fgpio      = RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO,
827             #endif
828             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FMUX
829             .fmux       = RK29SDK_SD_CARD_DETECT_IOMUX_FMUX,
830             #endif
831         },
832         #endif
833     #else
834         .io             = INVALID_GPIO,
835         .enable         = GPIO_LOW,
836     #endif    
837     }, 
838
839 };
840 #endif // CONFIG_SDMMC0_RK29
841
842 #ifdef CONFIG_SDMMC1_RK29
843 #define CONFIG_SDMMC1_USE_DMA
844 static int rk29_sdmmc1_cfg_gpio(void)
845 {
846 #if defined(CONFIG_SDMMC_RK29_OLD)
847         iomux_set(MMC1_CMD);
848         iomux_set(MMC1_CLKOUT);
849         iomux_set(MMC1_D0);
850         iomux_set(MMC1_D1);
851         iomux_set(MMC1_D2);
852         iomux_set(MMC1_D3);
853 #else
854
855 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
856         gpio_request(SDMMC1_WRITE_PROTECT_PIN, "sdio-wp");
857         gpio_direction_input(SDMMC1_WRITE_PROTECT_PIN);
858 #endif
859
860 #endif
861
862         return 0;
863 }
864
865 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
866         .host_ocr_avail =
867             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
868              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
869              MMC_VDD_33_34),
870
871 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
872         .host_caps = (MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ |
873                       MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
874 #else
875         .host_caps =
876             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
877 #endif
878
879         .io_init = rk29_sdmmc1_cfg_gpio,
880
881 #if !defined(CONFIG_SDMMC_RK29_OLD)
882         .set_iomux = rk29_sdmmc_set_iomux,
883 #endif
884
885         .dma_name = "sdio",
886 #ifdef CONFIG_SDMMC1_USE_DMA
887         .use_dma = 1,
888 #else
889         .use_dma = 0,
890 #endif
891
892 #if defined(CONFIG_WIFI_CONTROL_FUNC) || defined(CONFIG_WIFI_COMBO_MODULE_CONTROL_FUNC)
893     .status = rk29sdk_wifi_status,
894     .register_status_notify = rk29sdk_wifi_status_register,
895 #endif
896
897 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
898         .write_prt = SDMMC1_WRITE_PROTECT_PIN,
899             .write_prt_enalbe_level = SDMMC1_WRITE_PROTECT_ENABLE_VALUE;
900 #else
901         .write_prt = INVALID_GPIO,
902 #endif
903
904     #if defined(CONFIG_RK29_SDIO_IRQ_FROM_GPIO)
905         .sdio_INT_gpio = RK29SDK_WIFI_SDIO_CARD_INT,
906     #endif
907
908     .det_pin_info = {    
909 #if defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
910      #if defined(RK29SDK_SD_CARD_DETECT_N) || (INVALID_GPIO != RK29SDK_SD_CARD_DETECT_N)  
911         .io             = RK29SDK_SD_CARD_DETECT_N,
912      #else
913          .io             = INVALID_GPIO,
914      #endif   
915
916         .enable         = RK29SDK_SD_CARD_INSERT_LEVEL,
917         #ifdef RK29SDK_SD_CARD_DETECT_PIN_NAME
918         .iomux          = {
919             .name       = RK29SDK_SD_CARD_DETECT_PIN_NAME,
920             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO
921             .fgpio      = RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO,
922             #endif
923             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FMUX
924             .fmux       = RK29SDK_SD_CARD_DETECT_IOMUX_FMUX,
925             #endif
926         },
927         #endif
928  #else
929         .io             = INVALID_GPIO,
930         .enable         = GPIO_LOW,
931 #endif
932     },
933    
934         .enable_sd_wakeup = 0,
935 };
936 #endif //endif--#ifdef CONFIG_SDMMC1_RK29
937
938 /**************************************************************************************************
939  * the end of setting for SDMMC devices
940 **************************************************************************************************/
941
942 #ifdef CONFIG_BATTERY_RK30_ADC_FAC
943 static int ac_current = -1;
944 #define CHARING_CURRENT_500MA 0
945 #define CHARING_CURRENT_1000MA 1
946
947 #define   DC_CUR_SET_PIN RK30_PIN0_PB0
948 #define   CHARGE_OK_PIN  RK30_PIN0_PA6
949 #define   DC_DET_PIN     RK30_PIN0_PB2
950 static int rk30_battery_adc_io_init(void)
951 {
952         int ret = 0;
953         printk("charging:  set charging current 500ma \n");
954         ac_current = CHARING_CURRENT_500MA;
955         //dc charge detect pin
956         ret = gpio_request(DC_DET_PIN, NULL);
957         if (ret) {
958              printk("failed to request dc_det gpio\n");
959              return ret ;
960         }
961
962         gpio_pull_updown(DC_DET_PIN, 1);//important
963         ret = gpio_direction_input(DC_DET_PIN);
964         if (ret) {
965                 printk("failed to set gpio dc_det input\n");
966                 return ret ;
967         }
968
969         //charge ok pin
970         ret = gpio_request(CHARGE_OK_PIN, NULL);
971         if (ret) {
972                 printk("failed to request charge_ok gpio\n");
973                 return ret ;
974         }
975
976         gpio_pull_updown(CHARGE_OK_PIN, 1);//important
977         ret = gpio_direction_input(CHARGE_OK_PIN);
978         if (ret) {
979                 printk("failed to set gpio charge_ok input\n");
980                 return ret ;
981         }
982         //charge current set pin
983         ret = gpio_request(DC_CUR_SET_PIN, NULL);
984         if (ret) {
985                 printk("failed to request DC_CUR_SET_PIN gpio\n");
986                 return ret ;
987         }
988
989         ret = gpio_direction_output(DC_CUR_SET_PIN, GPIO_LOW);//500ma
990         if (ret) {
991                 printk("failed to set gpio DC_CUR_SET_PIN output\n");
992                 return ret ;
993         }
994
995         return 0;
996
997 }
998
999 static int set_usb_charging_current(int mode)
1000 {
1001 #if 0
1002     if ( (ac_current==CHARING_CURRENT_1000MA) && (mode == PC_MODE) ) {
1003                 gpio_set_value(DC_CUR_SET_PIN, GPIO_LOW);
1004                 ac_current = CHARING_CURRENT_500MA;
1005      }
1006      else if ((mode == ADAPT_MODE) && (ac_current==CHARING_CURRENT_500MA))
1007      {
1008                 gpio_set_value(DC_CUR_SET_PIN, GPIO_HIGH);
1009                ac_current = CHARING_CURRENT_1000MA;
1010
1011       }
1012 #endif
1013        gpio_set_value(DC_CUR_SET_PIN, GPIO_LOW);
1014        ac_current = CHARING_CURRENT_500MA;
1015 }
1016
1017
1018 static struct rk30_adc_battery_platform_data rk30_adc_battery_platdata = {
1019         .dc_det_pin      = RK30_PIN0_PB2,
1020         .batt_low_pin    = INVALID_GPIO, 
1021         .charge_set_pin  = INVALID_GPIO,
1022         .charge_ok_pin   = RK30_PIN0_PA6,
1023          .usb_det_pin = INVALID_GPIO,
1024         .dc_det_level    = GPIO_LOW,
1025         .charge_ok_level = GPIO_HIGH,
1026
1027         .reference_voltage = 1800, // the rK2928 is 3300;RK3066 and rk29 are 2500;rk3066B is 1800;
1028        .pull_up_res = 200,     //divider resistance ,  pull-up resistor
1029        .pull_down_res = 120, //divider resistance , pull-down resistor
1030
1031         .is_reboot_charging = 1,
1032         .save_capacity   = 1 ,
1033         .low_voltage_protection = 3600,   
1034         .io_init = rk30_battery_adc_io_init,
1035         .control_usb_charging= set_usb_charging_current, 
1036 };
1037
1038 static struct platform_device rk30_device_adc_battery = {
1039         .name   = "rk30-battery",
1040         .id     = -1,
1041         .dev = {
1042                 .platform_data = &rk30_adc_battery_platdata,
1043         },
1044 };
1045 #endif
1046 #ifdef CONFIG_RK30_PWM_REGULATOR
1047 static int pwm_voltage_map[] = {
1048         800000,825000,850000, 875000,900000, 925000 ,950000, 975000,1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000,1375000
1049 };
1050
1051 static struct regulator_consumer_supply pwm_dcdc1_consumers[] = {
1052         {
1053                 .supply = "vdd_cpu",
1054         }
1055 };
1056
1057 struct regulator_init_data pwm_regulator_init_dcdc[1] =
1058 {
1059         {
1060                 .constraints = {
1061                         .name = "PWM_DCDC1",
1062                         .min_uV = 600000,
1063                         .max_uV = 1800000,      //0.6-1.8V
1064                         .apply_uV = true,
1065                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
1066                 },
1067                 .num_consumer_supplies = ARRAY_SIZE(pwm_dcdc1_consumers),
1068                 .consumer_supplies = pwm_dcdc1_consumers,
1069         },
1070 };
1071
1072 static struct pwm_platform_data pwm_regulator_info[1] = {
1073         {
1074                 .pwm_id = 1,
1075                 .pwm_gpio = RK30_PIN3_PD4,
1076                 .pwm_iomux_pwm = PWM1,
1077                 .pwm_iomux_gpio = GPIO3_D4,
1078                 .pwm_voltage = 1100000,
1079                 .suspend_voltage = 1000000,
1080                 .min_uV = 800000,
1081                 .max_uV = 1375000,
1082                 .coefficient = 575,     //57.5%
1083                 .pwm_voltage_map = pwm_voltage_map,
1084                 .init_data      = &pwm_regulator_init_dcdc[0],
1085         },
1086 };
1087
1088 struct platform_device pwm_regulator_device[1] = {
1089         {
1090                 .name = "pwm-voltage-regulator",
1091                 .id = 0,
1092                 .dev            = {
1093                         .platform_data = &pwm_regulator_info[0],
1094                 }
1095         },
1096 };
1097 #endif
1098
1099 #ifdef CONFIG_RFKILL_RK
1100 // bluetooth rfkill device, its driver in net/rfkill/rfkill-rk.c
1101 static struct rfkill_rk_platform_data rfkill_rk_platdata = {
1102     .type               = RFKILL_TYPE_BLUETOOTH,
1103
1104     .poweron_gpio       = { // BT_REG_ON
1105         .io             = INVALID_GPIO, //RK30_PIN3_PC7,
1106         .enable         = GPIO_HIGH,
1107         .iomux          = {
1108             .name       = "bt_poweron",
1109             .fgpio      = GPIO3_C7,
1110         },
1111     },
1112
1113     .reset_gpio         = { // BT_RST
1114         .io             = RK30_PIN3_PD1, // set io to INVALID_GPIO for disable it
1115         .enable         = GPIO_LOW,
1116         .iomux          = {
1117             .name       = "bt_reset",
1118             .fgpio      = GPIO3_D1,
1119        },
1120    }, 
1121
1122     .wake_gpio          = { // BT_WAKE, use to control bt's sleep and wakeup
1123         .io             = RK30_PIN3_PC6, // set io to INVALID_GPIO for disable it
1124         .enable         = GPIO_HIGH,
1125         .iomux          = {
1126             .name       = "bt_wake",
1127             .fgpio      = GPIO3_C6,
1128         },
1129     },
1130
1131     .wake_host_irq      = { // BT_HOST_WAKE, for bt wakeup host when it is in deep sleep
1132         .gpio           = {
1133             .io         = RK30_PIN0_PA5, // set io to INVALID_GPIO for disable it
1134             .enable     = GPIO_LOW,      // set GPIO_LOW for falling, set 0 for rising
1135             .iomux      = {
1136                 .name   = NULL,
1137             },
1138         },
1139     },
1140
1141     .rts_gpio           = { // UART_RTS, enable or disable BT's data coming
1142         .io             = RK30_PIN1_PA3, // set io to INVALID_GPIO for disable it
1143         .enable         = GPIO_LOW,
1144         .iomux          = {
1145             .name       = "bt_rts",
1146             .fgpio      = GPIO1_A3,
1147             .fmux       = UART0_RTSN,
1148         },
1149     },
1150 };
1151
1152 static struct platform_device device_rfkill_rk = {
1153     .name   = "rfkill_rk",
1154     .id     = -1,
1155     .dev    = {
1156         .platform_data = &rfkill_rk_platdata,
1157     },
1158 };
1159 #endif
1160
1161 #if defined(CONFIG_GPS_RK)
1162 int rk_gps_io_init(void)
1163 {
1164         printk("%s \n", __FUNCTION__);
1165         
1166         rk30_mux_api_set(GPIO1B5_UART3RTSN_NAME, GPIO1B_GPIO1B5);//VCC_EN
1167         gpio_request(RK30_PIN1_PB5, NULL);
1168         gpio_direction_output(RK30_PIN1_PB5, GPIO_LOW);
1169
1170         rk30_mux_api_set(GPIO1B4_UART3CTSN_GPSRFCLK_NAME, GPIO1B_GPSRFCLK);//GPS_CLK
1171         rk30_mux_api_set(GPIO1B2_UART3SIN_GPSMAG_NAME, GPIO1B_GPSMAG);//GPS_MAG
1172         rk30_mux_api_set(GPIO1B3_UART3SOUT_GPSSIG_NAME, GPIO1B_GPSSIG);//GPS_SIGN
1173
1174         rk30_mux_api_set(GPIO1A6_UART1CTSN_SPI0CLK_NAME, GPIO1A_GPIO1A6);//SPI_CLK
1175         gpio_request(RK30_PIN1_PA6, NULL);
1176         gpio_direction_output(RK30_PIN1_PA6, GPIO_LOW);
1177
1178         rk30_mux_api_set(GPIO1A5_UART1SOUT_SPI0TXD_NAME, GPIO1A_GPIO1A5);//SPI_MOSI
1179         gpio_request(RK30_PIN1_PA5, NULL);
1180         gpio_direction_output(RK30_PIN1_PA5, GPIO_LOW); 
1181
1182         rk30_mux_api_set(GPIO1A7_UART1RTSN_SPI0CSN0_NAME, GPIO1A_GPIO1A7);//SPI_CS
1183         gpio_request(RK30_PIN1_PA7, NULL);
1184         gpio_direction_output(RK30_PIN1_PA7, GPIO_LOW);         
1185         return 0;
1186 }
1187 int rk_gps_power_up(void)
1188 {
1189         printk("%s \n", __FUNCTION__);
1190
1191         return 0;
1192 }
1193
1194 int rk_gps_power_down(void)
1195 {
1196         printk("%s \n", __FUNCTION__);
1197
1198         return 0;
1199 }
1200
1201 int rk_gps_reset_set(int level)
1202 {
1203         return 0;
1204 }
1205 int rk_enable_hclk_gps(void)
1206 {
1207         printk("%s \n", __FUNCTION__);
1208         clk_enable(clk_get(NULL, "hclk_gps"));
1209         return 0;
1210 }
1211 int rk_disable_hclk_gps(void)
1212 {
1213         printk("%s \n", __FUNCTION__);
1214         clk_disable(clk_get(NULL, "hclk_gps"));
1215         return 0;
1216 }
1217 struct rk_gps_data rk_gps_info = {
1218         .io_init = rk_gps_io_init,
1219         .power_up = rk_gps_power_up,
1220         .power_down = rk_gps_power_down,
1221         .reset = rk_gps_reset_set,
1222         .enable_hclk_gps = rk_enable_hclk_gps,
1223         .disable_hclk_gps = rk_disable_hclk_gps,
1224         .GpsSign = RK30_PIN1_PB3,
1225         .GpsMag = RK30_PIN1_PB2,        //GPIO index
1226         .GpsClk = RK30_PIN1_PB4,        //GPIO index
1227         .GpsVCCEn = RK30_PIN1_PB5,     //GPIO index
1228         .GpsSpi_CSO = RK30_PIN1_PA4,    //GPIO index
1229         .GpsSpiClk = RK30_PIN1_PA5,     //GPIO index
1230         .GpsSpiMOSI = RK30_PIN1_PA7,      //GPIO index
1231         .GpsIrq = IRQ_GPS,
1232         .GpsSpiEn = 0,
1233         .GpsAdcCh = 2,
1234         .u32GpsPhyAddr = RK30_GPS_PHYS,
1235         .u32GpsPhySize = RK30_GPS_SIZE,
1236 };
1237
1238 struct platform_device rk_device_gps = {
1239         .name = "gps_hv5820b",
1240         .id = -1,
1241         .dev            = {
1242         .platform_data = &rk_gps_info,
1243                 }
1244         };
1245 #endif
1246
1247 #if defined(CONFIG_MT5931_MT6622)
1248 static struct mt6622_platform_data mt6622_platdata = {
1249                     .power_gpio         = { // BT_REG_ON
1250                       #if DS1006H_V1_2_SUPPORT
1251                     .io             = RK30_PIN3_PC7, // set io to INVALID_GPIO for disable it
1252                       #else
1253                         .io             = RK30_PIN3_PD5, // set io to INVALID_GPIO for disable it
1254                         #endif
1255                             .enable         = GPIO_HIGH,
1256                             .iomux          = {
1257                                     .name       = NULL,
1258                                 },
1259                     },
1260
1261                     .reset_gpio         = { // BT_RST
1262                         #if DS1006H_V1_2_SUPPORT
1263                     .io             = RK30_PIN3_PD1,
1264                         #else
1265                         .io             = RK30_PIN0_PD7,
1266                         #endif
1267                         .enable         = GPIO_HIGH,
1268                         .iomux          = {
1269                             .name       = NULL,
1270                         },
1271                     },
1272
1273                     .irq_gpio           = {
1274                           #if DS1006H_V1_2_SUPPORT
1275                        .io             = RK30_PIN0_PA5,
1276                           #else
1277                             .io             = RK30_PIN3_PD2,
1278                             #endif
1279                             .enable         = GPIO_HIGH,
1280                             .iomux          = {
1281                                     .name       = NULL,
1282                                 },
1283                     }
1284 };
1285
1286 static struct platform_device device_mt6622 = {
1287                     .name   = "mt6622",
1288                         .id     = -1,
1289                         .dev    = {
1290                                .platform_data = &mt6622_platdata,
1291                         },
1292 };      
1293 #endif
1294
1295 #if defined CONFIG_TCC_BT_DEV
1296 static struct tcc_bt_platform_data tcc_bt_platdata = {
1297
1298     .power_gpio   = { // ldoon
1299         .io             =  RK2928_PIN3_PC0,
1300         .enable         = GPIO_HIGH,
1301         .iomux          = {
1302             .name       = NULL,
1303             },
1304         },
1305
1306     .wake_host_gpio  = { // BT_HOST_WAKE, for bt wakeup host when it is in deep sleep
1307         .io         = RK2928_PIN0_PC5, // set io to INVALID_GPIO for disable it
1308         .enable     = IRQF_TRIGGER_RISING,// set IRQF_TRIGGER_FALLING for falling, set IRQF_TRIGGER_RISING for rising
1309         .iomux      = {
1310             .name       = NULL,
1311         },
1312     },
1313 };
1314
1315 static struct platform_device device_tcc_bt = {
1316     .name   = "tcc_bt_dev",
1317     .id     = -1,
1318     .dev    = {
1319         .platform_data = &tcc_bt_platdata,
1320         },
1321 };
1322 #endif
1323
1324
1325 static struct platform_device *devices[] __initdata = {
1326
1327 #ifdef CONFIG_ION
1328         &device_ion,
1329 #endif
1330 #ifdef CONFIG_WIFI_CONTROL_FUNC
1331         &rk29sdk_wifi_device,
1332 #endif
1333
1334 #if defined(CONFIG_MT6620)
1335             &mt3326_device_gps,
1336 #endif
1337
1338 #ifdef CONFIG_BATTERY_RK30_ADC_FAC
1339         &rk30_device_adc_battery,
1340 #endif
1341 #ifdef CONFIG_RFKILL_RK
1342         &device_rfkill_rk,
1343 #endif
1344 #ifdef CONFIG_GPS_RK
1345         &rk_device_gps,
1346 #endif
1347 #ifdef CONFIG_MT5931_MT6622
1348         &device_mt6622,
1349 #endif
1350 #if defined(CONFIG_MT6229)
1351         &rk29_device_mt6229,
1352 #endif
1353 #if defined(CONFIG_ARCH_RK3188)
1354         &device_mali,
1355 #endif
1356
1357 #ifdef CONFIG_TCC_BT_DEV
1358         &device_tcc_bt,
1359 #endif
1360 };
1361
1362
1363 static int rk_platform_add_display_devices(void)
1364 {
1365         struct platform_device *fb = NULL;  //fb
1366         struct platform_device *lcdc0 = NULL; //lcdc0
1367         struct platform_device *lcdc1 = NULL; //lcdc1
1368         struct platform_device *bl = NULL; //backlight
1369 #ifdef CONFIG_FB_ROCKCHIP
1370         fb = &device_fb;
1371 #endif
1372
1373 #if defined(CONFIG_LCDC0_RK3188)
1374         lcdc0 = &device_lcdc0,
1375 #endif
1376
1377 #if defined(CONFIG_LCDC1_RK3188)
1378         lcdc1 = &device_lcdc1,
1379 #endif
1380
1381 #ifdef CONFIG_BACKLIGHT_RK29_BL
1382         bl = &rk29_device_backlight,
1383 #endif
1384         __rk_platform_add_display_devices(fb,lcdc0,lcdc1,bl);
1385
1386         return 0;
1387         
1388 }
1389
1390 // i2c
1391 #ifdef CONFIG_I2C0_RK30
1392 static struct i2c_board_info __initdata i2c0_info[] = {
1393 #if defined (CONFIG_GS_MMA8452)
1394         {
1395                 .type           = "gs_mma8452",
1396                 .addr           = 0x1d,
1397                 .flags          = 0,
1398                 .irq            = MMA8452_INT_PIN,
1399                 .platform_data = &mma8452_info,
1400         },
1401 #endif
1402
1403 #if defined (CONFIG_GS_LIS3DH)
1404         {
1405                 .type           = "gs_lis3dh",
1406                 .addr           = 0x19,   //0x19(SA0-->VCC), 0x18(SA0-->GND)
1407                 .flags          = 0,
1408                 .irq            = LIS3DH_INT_PIN,
1409                 .platform_data = &lis3dh_info,
1410         },
1411 #endif
1412 #if defined (CONFIG_COMPASS_AK8963)
1413         {
1414                 .type          = "ak8963",
1415                 .addr          = 0x0d,
1416                 .flags         = 0,
1417                 .irq           = RK30_PIN3_PD7, 
1418                 .platform_data = &akm8963_info,
1419         },
1420 #endif
1421
1422 #if defined (CONFIG_LS_PHOTORESISTOR)
1423         {
1424                 .type           = "ls_photoresistor",
1425                 .addr           = 0x5e,            
1426                 .flags          = 0,
1427                 .irq            = INVALID_GPIO, 
1428                 .platform_data = &light_photoresistor_info,
1429         },
1430 #endif
1431
1432 #if defined (CONFIG_COMPASS_AK8975)
1433         {
1434                 .type          = "ak8975",
1435                 .addr          = 0x0d,
1436                 .flags         = 0,
1437                 .irq           = RK30_PIN3_PD7, 
1438                 .platform_data = &akm8975_info,
1439                 .irq           = RK30_PIN3_PD7, 
1440                 .platform_data = &akm8975_info,
1441         },
1442 #endif
1443 #if defined (CONFIG_GYRO_L3G4200D)
1444         {
1445                 .type          = "l3g4200d_gryo",
1446                 .addr          = 0x69,
1447                 .flags         = 0,
1448                 .irq           = L3G4200D_INT_PIN,
1449                 .platform_data = &l3g4200d_info,
1450         },
1451 #endif
1452 #if defined (CONFIG_SND_SOC_RK1000)
1453         {
1454                 .type          = "rk1000_i2c_codec",
1455                 .addr          = 0x60,
1456                 .flags         = 0,
1457         },
1458         {
1459                 .type          = "rk1000_control",
1460                 .addr          = 0x40,
1461                 .flags         = 0,
1462         },
1463 #endif
1464 #if defined (CONFIG_SND_SOC_CX2070X)
1465         {
1466                 .type                   = "cx2070x",
1467                 .addr                   = 0x14,
1468                 .flags                  = 0,
1469         },
1470 #endif
1471 };
1472 #endif
1473
1474 int __sramdata g_pmic_type =  0;
1475 #ifdef CONFIG_I2C1_RK30
1476 #ifdef CONFIG_REGULATOR_ACT8846
1477 #define PMU_POWER_SLEEP RK30_PIN0_PA1
1478 #define PMU_VSEL RK30_PIN3_PD3
1479 #define ACT8846_HOST_IRQ                RK30_PIN0_PB3
1480
1481 static struct pmu_info  act8846_dcdc_info[] = {
1482         {
1483                 .name          = "act_dcdc1",   //ddr
1484                 .min_uv          = 1200000,
1485                 .max_uv         = 1200000,
1486                 .suspend_vol  =   1200000,
1487         },
1488         {
1489                 .name          = "vdd_core",    //logic
1490                 .min_uv          = 1000000,
1491                 .max_uv         = 1000000,
1492                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1493                 .suspend_vol  =  1200000,
1494                 #else
1495                 .suspend_vol  =  900000,
1496                 #endif
1497         },
1498         {
1499                 .name          = "vdd_cpu",   //arm
1500                 .min_uv          = 1000000,
1501                 .max_uv         = 1000000,
1502                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1503                 .suspend_vol  =  1200000,
1504                 #else
1505                 .suspend_vol  =  900000,
1506                 #endif
1507         },
1508         {
1509                 .name          = "act_dcdc4",   //vccio
1510                 .min_uv          = 3000000,
1511                 .max_uv         = 3000000,
1512                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1513                 .suspend_vol  =  3000000,
1514                 #else
1515                 .suspend_vol  =  2800000,
1516                 #endif
1517         },
1518         
1519 };
1520 static  struct pmu_info  act8846_ldo_info[] = {
1521         {
1522                 .name          = "act_ldo1",   //vdd10
1523                 .min_uv          = 1000000,
1524                 .max_uv         = 1000000,
1525         },
1526         {
1527                 .name          = "act_ldo2",    //vdd12
1528                 .min_uv          = 1200000,
1529                 .max_uv         = 1200000,
1530         },
1531         {
1532                 .name          = "act_ldo3",   //vcc18_cif
1533                 .min_uv          = 1800000,
1534                 .max_uv         = 1800000,
1535         },
1536         {
1537                 .name          = "act_ldo4",   //vcca33
1538                 .min_uv          = 3300000,
1539                 .max_uv         = 3300000,
1540         },
1541         {
1542                 .name          = "act_ldo5",   //vcctp
1543                 .min_uv          = 3300000,
1544                 .max_uv         = 3300000,
1545         },
1546         {
1547                 .name          = "act_ldo6",   //vcc_jetta
1548                 .min_uv          = 3300000,
1549                 .max_uv         = 3300000,
1550         },
1551         {
1552                 .name          = "act_ldo7",   //vcc18
1553                 .min_uv          = 1800000,
1554                 .max_uv         = 1800000,
1555         },
1556         {
1557                 .name          = "act_ldo8",   //vcc28_cif
1558                 .min_uv          = 2800000,
1559                 .max_uv         = 2800000,
1560         },
1561  };
1562
1563 #include "../mach-rk30/board-pmu-act8846.c"
1564 #endif
1565
1566 #ifdef CONFIG_MFD_WM831X_I2C
1567 #define PMU_POWER_SLEEP                 RK30_PIN0_PA1 
1568
1569 static struct pmu_info  wm8326_dcdc_info[] = {
1570         {
1571                 .name          = "vdd_core",   //logic
1572                 .min_uv          = 1000000,
1573                 .max_uv         = 1000000,
1574                 .suspend_vol  =  950000,
1575         },
1576         {
1577                 .name          = "vdd_cpu",    //arm
1578                 .min_uv          = 1000000,
1579                 .max_uv         = 1000000,
1580                 .suspend_vol  =  950000,
1581         },
1582         {
1583                 .name          = "dcdc3",   //ddr
1584                 .min_uv          = 1150000,
1585                 .max_uv         = 1150000,
1586                 .suspend_vol  =  1150000,
1587         },
1588         #ifdef CONFIG_MACH_RK3066_SDK
1589         {
1590                 .name          = "dcdc4",   //vcc_io
1591                 .min_uv          = 3300000,
1592                 .max_uv         = 3300000,
1593                 .suspend_vol  =  3000000,
1594         },
1595         #else
1596         {
1597                 .name          = "dcdc4",   //vcc_io
1598                 .min_uv          = 3000000,
1599                 .max_uv         = 3000000,
1600                 .suspend_vol  =  2800000,
1601         },
1602         #endif
1603 };
1604
1605 static struct pmu_info  wm8326_ldo_info[] = {
1606         {
1607                 .name          = "ldo1",   //vcc18_cif
1608                 .min_uv          = 1800000,
1609                 .max_uv         = 1800000,
1610                 .suspend_vol  =  1800000,
1611         },
1612         {
1613                 .name          = "ldo2",    //vccio_wl
1614                 .min_uv          = 1800000,
1615                 .max_uv         = 1800000,
1616                 .suspend_vol  =  1800000,
1617         },
1618         {
1619                 .name          = "ldo3",   //
1620                 .min_uv          = 1100000,
1621                 .max_uv         = 1100000,
1622                 .suspend_vol  =  1100000,
1623         },
1624         {
1625                 .name          = "ldo4",   //vdd11
1626                 .min_uv          = 1000000,
1627                 .max_uv         = 1000000,
1628                 .suspend_vol  =  1000000,
1629         },
1630         {
1631                 .name          = "ldo5",   //vcc25
1632                 .min_uv          = 1800000,
1633                 .max_uv         = 1800000,
1634                 .suspend_vol  =  1800000,
1635         },
1636         {
1637                 .name          = "ldo6",   //vcc33
1638                 .min_uv          = 3300000,
1639                 .max_uv         = 3300000,
1640                 .suspend_vol  =  3300000,
1641         },
1642         {
1643                 .name          = "ldo7",   //vcc28_cif
1644                 .min_uv          = 2800000,
1645                 .max_uv         = 2800000,
1646                 .suspend_vol  =  2800000,
1647         },
1648         {
1649                 .name          = "ldo8",   //vcca33
1650                 .min_uv          = 3300000,
1651                 .max_uv         = 3300000,
1652                 .suspend_vol  =  3300000,
1653         },
1654         {
1655                 .name          = "ldo9",   //vcc_tp
1656                 .min_uv          = 3300000,
1657                 .max_uv         = 3300000,
1658                 .suspend_vol  =  3300000,
1659         },
1660         {
1661                 .name          = "ldo10",   //flash_io
1662                 .min_uv          = 1800000,
1663                 .max_uv         = 1800000,
1664                 .suspend_vol  =  1800000,
1665         },
1666 };
1667
1668 #include "../mach-rk30/board-pmu-wm8326.c"
1669 #endif
1670
1671 #ifdef CONFIG_MFD_TPS65910
1672 #ifdef CONFIG_ARCH_RK3188
1673 #define TPS65910_HOST_IRQ        RK30_PIN0_PB3
1674 #else
1675 #define TPS65910_HOST_IRQ        RK30_PIN6_PA4
1676 #endif
1677
1678 #define PMU_POWER_SLEEP RK30_PIN0_PA1
1679
1680 static struct pmu_info  tps65910_dcdc_info[] = {
1681         {
1682                 .name          = "vdd_core",   //logic
1683                 .min_uv          = 1100000,
1684                 .max_uv         = 1100000,
1685         },
1686         {
1687                 .name          = "vdd2",    //ddr
1688                 .min_uv          = 1200000,
1689                 .max_uv         = 1200000,
1690         },
1691         {
1692                 .name          = "vio",   //vcc_io
1693                 .min_uv          = 2500000,
1694                 .max_uv         = 2500000,
1695         },
1696         
1697 };
1698 static  struct pmu_info  tps65910_ldo_info[] = {
1699         {
1700                 .name          = "vpll",   //vdd10
1701                 .min_uv          = 1000000,
1702                 .max_uv         = 1000000,
1703         },
1704         {
1705                 .name          = "vdig1",    //vcc18_cif
1706                 .min_uv          = 1800000,
1707                 .max_uv         = 1800000,
1708         },
1709         {
1710                 .name          = "vdig2",   //vdd_jetta
1711                 .min_uv          = 1200000,
1712                 .max_uv         = 1200000,
1713         },
1714         {
1715                 .name          = "vaux1",   //vcc28_cif
1716                 .min_uv          = 2800000,
1717                 .max_uv         = 2800000,
1718         },
1719         {
1720                 .name          = "vaux2",   //vcca33
1721                 .min_uv          = 3300000,
1722                 .max_uv         = 3300000,
1723         },
1724         {
1725                 .name          = "vaux33",   //vcc_tp
1726                 .min_uv          = 3300000,
1727                 .max_uv         = 3300000,
1728         },
1729         {
1730                 .name          = "vmmc",   //vcc30
1731                 .min_uv          = 3000000,
1732                 .max_uv         = 3000000,
1733         },
1734         {
1735                 .name          = "vdac",   //vcc18
1736                 .min_uv          = 1800000,
1737                 .max_uv         = 1800000,
1738         },
1739  };
1740
1741 #include "../mach-rk30/board-pmu-tps65910.c"
1742 #endif
1743
1744 static struct i2c_board_info __initdata i2c1_info[] = {
1745 #if defined (CONFIG_REGULATOR_ACT8846)
1746         {
1747                 .type                   = "act8846",
1748                 .addr           = 0x5a, 
1749                 .flags                  = 0,
1750                 .irq            = ACT8846_HOST_IRQ,
1751                 .platform_data=&act8846_data,
1752         },
1753 #endif
1754 #if defined (CONFIG_RTC_HYM8563)
1755         {
1756                 .type                   = "rtc_hym8563",
1757                 .addr           = 0x51,
1758                 .flags                  = 0,
1759                 .irq            = RK30_PIN0_PB5,
1760         },
1761 #endif
1762 #if defined (CONFIG_MFD_WM831X_I2C)
1763         {
1764                 .type          = "wm8326",
1765                 .addr          = 0x34,
1766                 .flags         = 0,
1767                 .irq           = RK30_PIN0_PB3,
1768                 .platform_data = &wm831x_platdata,
1769         },
1770 #endif
1771 #if defined (CONFIG_MFD_TPS65910)
1772         {
1773         .type           = "tps65910",
1774         .addr           = TPS65910_I2C_ID0,
1775         .flags          = 0,
1776         .irq            = TPS65910_HOST_IRQ,
1777         .platform_data = &tps65910_data,
1778         },
1779 #endif
1780 };
1781 #endif
1782
1783 void __sramfunc board_pmu_suspend(void)
1784 {      
1785         #if defined (CONFIG_REGULATOR_ACT8846)
1786        if(pmic_is_act8846())
1787        board_pmu_act8846_suspend(); 
1788        #endif
1789         #if defined (CONFIG_MFD_WM831X_I2C)
1790        if(pmic_is_wm8326())
1791        board_pmu_wm8326_suspend();
1792         #endif
1793         #if defined (CONFIG_MFD_TPS65910)
1794        if(pmic_is_tps65910())
1795        board_pmu_tps65910_suspend(); 
1796     #endif   
1797 }
1798
1799 void __sramfunc board_pmu_resume(void)
1800 {      
1801         #if defined (CONFIG_REGULATOR_ACT8846)
1802        if(pmic_is_act8846())
1803        board_pmu_act8846_resume(); 
1804        #endif
1805         #if defined (CONFIG_MFD_WM831X_I2C)
1806        if(pmic_is_wm8326())
1807        board_pmu_wm8326_resume();
1808         #endif
1809         #if defined (CONFIG_MFD_TPS65910)
1810        if(pmic_is_tps65910())
1811        board_pmu_tps65910_resume(); 
1812         #endif
1813 }
1814
1815  int __sramdata gpio3d6_iomux,gpio3d6_do,gpio3d6_dir,gpio3d6_en;
1816
1817 #define grf_readl(offset)       readl_relaxed(RK30_GRF_BASE + offset)
1818 #define grf_writel(v, offset)   do { writel_relaxed(v, RK30_GRF_BASE + offset); dsb(); } while (0)
1819  
1820 void __sramfunc rk30_pwm_logic_suspend_voltage(void)
1821 {
1822 #ifdef CONFIG_RK30_PWM_REGULATOR
1823
1824 //      int gpio0d7_iomux,gpio0d7_do,gpio0d7_dir,gpio0d7_en;
1825         sram_udelay(10000);
1826         gpio3d6_iomux = grf_readl(GRF_GPIO3D_IOMUX);
1827         gpio3d6_do = grf_readl(GRF_GPIO3H_DO);
1828         gpio3d6_dir = grf_readl(GRF_GPIO3H_DIR);
1829         gpio3d6_en = grf_readl(GRF_GPIO3H_EN);
1830
1831         grf_writel((1<<28), GRF_GPIO3D_IOMUX);
1832         grf_writel((1<<30)|(1<<14), GRF_GPIO3H_DIR);
1833         grf_writel((1<<30)|(1<<14), GRF_GPIO3H_DO);
1834         grf_writel((1<<30)|(1<<14), GRF_GPIO3H_EN);
1835 #endif 
1836 }
1837 void __sramfunc rk30_pwm_logic_resume_voltage(void)
1838 {
1839 #ifdef CONFIG_RK30_PWM_REGULATOR
1840         grf_writel((1<<28)|gpio3d6_iomux, GRF_GPIO3D_IOMUX);
1841         grf_writel((1<<30)|gpio3d6_en, GRF_GPIO3H_EN);
1842         grf_writel((1<<30)|gpio3d6_dir, GRF_GPIO3H_DIR);
1843         grf_writel((1<<30)|gpio3d6_do, GRF_GPIO3H_DO);
1844         sram_udelay(10000);
1845
1846 #endif
1847
1848 }
1849 extern void pwm_suspend_voltage(void);
1850 extern void pwm_resume_voltage(void);
1851 void  rk30_pwm_suspend_voltage_set(void)
1852 {
1853 #ifdef CONFIG_RK30_PWM_REGULATOR
1854         pwm_suspend_voltage();
1855 #endif
1856 }
1857 void  rk30_pwm_resume_voltage_set(void)
1858 {
1859 #ifdef CONFIG_RK30_PWM_REGULATOR
1860         pwm_resume_voltage();
1861 #endif
1862 }
1863
1864
1865 #ifdef CONFIG_I2C2_RK30
1866 static struct i2c_board_info __initdata i2c2_info[] = {
1867 #if defined (CONFIG_CT36X_TS)
1868         {
1869                 .type          = CT36X_NAME,
1870                 .addr          = 0x01,
1871                 .flags         = 0,
1872                 .platform_data = &ct36x_info,
1873         },
1874 #endif
1875 #if defined (CONFIG_LS_CM3217)
1876         {
1877                 .type          = "lightsensor",
1878                 .addr          = 0x10,
1879                 .flags         = 0,
1880                 .platform_data = &cm3217_info,
1881         },
1882 #endif
1883 #if defined (CONFIG_LS_US5151)
1884         {    
1885                 .type           = "us5151",
1886                 .addr           = 0x10,
1887                 .flags          = 0, 
1888         },   
1889 #endif
1890
1891 #if defined(CONFIG_HDMI_CAT66121)
1892         {
1893                 .type           = "cat66121_hdmi",
1894                 .addr           = 0x4c,
1895                 .flags          = 0,
1896                 .irq            = RK30_PIN2_PD6,
1897                 .platform_data  = &rk_hdmi_pdata,
1898         },
1899 #endif
1900 };
1901 #endif
1902
1903 #ifdef CONFIG_I2C3_RK30
1904 static struct i2c_board_info __initdata i2c3_info[] = {
1905 };
1906 #endif
1907
1908 #ifdef CONFIG_I2C4_RK30
1909 static struct i2c_board_info __initdata i2c4_info[] = {
1910 #ifdef CONFIG_MFD_RK610
1911                 {
1912                         .type                   = "rk610_ctl",
1913                         .addr                   = 0x40,
1914                         .flags                  = 0,
1915                         .platform_data          = &rk610_ctl_pdata,
1916                 },
1917 #ifdef CONFIG_RK610_TVOUT
1918                 {
1919                         .type                   = "rk610_tvout",
1920                         .addr                   = 0x42,
1921                         .flags                  = 0,
1922                 },
1923 #endif
1924 #ifdef CONFIG_HDMI_RK610
1925                 {
1926                         .type                   = "rk610_hdmi",
1927                         .addr                   = 0x46,
1928                         .flags                  = 0,
1929                         .irq                    = INVALID_GPIO,
1930                 },
1931 #endif
1932 #ifdef CONFIG_SND_SOC_RK610
1933                 {//RK610_CODEC addr  from 0x60 to 0x80 (0x60~0x80)
1934                         .type                   = "rk610_i2c_codec",
1935                         .addr                   = 0x60,
1936                         .flags                  = 0,
1937                         .platform_data          = &rk610_codec_pdata,                   
1938                 },
1939 #endif
1940 #endif
1941
1942 #if defined (CONFIG_SND_SOC_RT5631)
1943         {
1944                 .type                   = "rt5631",
1945                 .addr                   = 0x1a,
1946                 .flags                  = 0,
1947         },
1948 #endif
1949
1950 };
1951 #endif
1952
1953 #ifdef CONFIG_I2C_GPIO_RK30
1954 #define I2C_SDA_PIN     INVALID_GPIO// RK30_PIN2_PD6   //set sda_pin here
1955 #define I2C_SCL_PIN     INVALID_GPIO//RK30_PIN2_PD7   //set scl_pin here
1956 static int rk30_i2c_io_init(void)
1957 {
1958         //set iomux (gpio) here
1959         //rk30_mux_api_set(GPIO2D7_I2C1SCL_NAME, GPIO2D_GPIO2D7);
1960         //rk30_mux_api_set(GPIO2D6_I2C1SDA_NAME, GPIO2D_GPIO2D6);
1961
1962         return 0;
1963 }
1964 struct i2c_gpio_platform_data default_i2c_gpio_data = {
1965        .sda_pin = I2C_SDA_PIN,
1966        .scl_pin = I2C_SCL_PIN,
1967        .udelay = 5, // clk = 500/udelay = 100Khz
1968        .timeout = 100,//msecs_to_jiffies(100),
1969        .bus_num    = 5,
1970        .io_init = rk30_i2c_io_init,
1971 };
1972 static struct i2c_board_info __initdata i2c_gpio_info[] = {
1973 };
1974 #endif
1975
1976 static void __init rk30_i2c_register_board_info(void)
1977 {
1978 #ifdef CONFIG_I2C0_RK30
1979         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
1980 #endif
1981 #ifdef CONFIG_I2C1_RK30
1982         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
1983 #endif
1984 #ifdef CONFIG_I2C2_RK30
1985         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
1986 #endif
1987 #ifdef CONFIG_I2C3_RK30
1988         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
1989 #endif
1990 #ifdef CONFIG_I2C4_RK30
1991         i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info));
1992 #endif
1993 #ifdef CONFIG_I2C_GPIO_RK30
1994         i2c_register_board_info(5, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info));
1995 #endif
1996 }
1997 //end of i2c
1998
1999 #define POWER_ON_PIN RK30_PIN0_PA0   //power_hold
2000 static void rk30_pm_power_off(void)
2001 {
2002         printk(KERN_ERR "rk30_pm_power_off start...\n");
2003 #if defined(CONFIG_MFD_WM831X)
2004         wm831x_set_bits(Wm831x,WM831X_GPIO_LEVEL,0x0001,0x0000);  //set sys_pwr 0
2005         wm831x_device_shutdown(Wm831x);//wm8326 shutdown
2006 #endif
2007 #if defined(CONFIG_REGULATOR_ACT8846)
2008        if (pmic_is_act8846()) {
2009                printk("enter dcdet===========\n");
2010                if(gpio_get_value (RK30_PIN0_PB2) == GPIO_LOW)
2011                {
2012                        printk("enter restart===========\n");
2013                        arm_pm_restart(0, "charge");
2014                }
2015                 /** code here may cause tablet cannot boot when shutdown without charger pluged in
2016                   * and then plug in charger. -- Cody Xie
2017                else
2018                 {
2019                         act8846_device_shutdown();
2020                 }
2021                   */
2022        }
2023 #endif
2024         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
2025         while (1);
2026 }
2027
2028 static void __init machine_rk30_board_init(void)
2029 {
2030         //avs_init();
2031         gpio_request(POWER_ON_PIN, "poweronpin");
2032         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
2033         
2034         pm_power_off = rk30_pm_power_off;
2035         
2036         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
2037
2038
2039         rk30_i2c_register_board_info();
2040         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
2041         platform_add_devices(devices, ARRAY_SIZE(devices));
2042         rk_platform_add_display_devices();
2043         //board_usb_detect_init(RK30_PIN0_PA7);
2044
2045 #ifdef CONFIG_WIFI_CONTROL_FUNC
2046         rk29sdk_wifi_bt_gpio_control_init();
2047 #endif
2048
2049 #if defined(CONFIG_MT6620)
2050             clk_set_rate(clk_get_sys("rk_serial.1", "uart"), 48*1000000);
2051 #endif
2052
2053 #if defined(CONFIG_MT5931_MT6622)
2054                 clk_set_rate(clk_get_sys("rk_serial.0", "uart"), 24*1000000);
2055 #endif          
2056 }
2057
2058 #define HD_SCREEN_SIZE 1920UL*1200UL*4*3
2059 static void __init rk30_reserve(void)
2060 {
2061 #if defined(CONFIG_ARCH_RK3188)
2062         /*if lcd resolution great than or equal to 1920*1200,reserve the ump memory */
2063         if(!(get_fb_size() < ALIGN(HD_SCREEN_SIZE,SZ_1M)))
2064         {
2065                 int ump_mem_phy_size=512UL*1024UL*1024UL; 
2066                 resource_mali[0].start = board_mem_reserve_add("ump buf", ump_mem_phy_size); 
2067                 resource_mali[0].end = resource_mali[0].start + ump_mem_phy_size -1;
2068         }
2069 #endif
2070 #ifdef CONFIG_ION
2071         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion", ION_RESERVE_SIZE);
2072 #endif
2073
2074 #ifdef CONFIG_FB_ROCKCHIP
2075         resource_fb[0].start = board_mem_reserve_add("fb0 buf", get_fb_size());
2076         resource_fb[0].end = resource_fb[0].start + get_fb_size()- 1;
2077 #if 0
2078         resource_fb[1].start = board_mem_reserve_add("ipp buf", RK30_FB0_MEM_SIZE);
2079         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
2080 #endif
2081
2082 #if defined(CONFIG_FB_ROTATE) || !defined(CONFIG_THREE_FB_BUFFER)
2083         resource_fb[2].start = board_mem_reserve_add("fb2 buf",get_fb_size());
2084         resource_fb[2].end = resource_fb[2].start + get_fb_size() - 1;
2085 #endif
2086 #endif
2087
2088
2089 #ifdef CONFIG_VIDEO_RK29
2090         rk30_camera_request_reserve_mem();
2091 #endif
2092         
2093 #ifdef CONFIG_GPS_RK
2094         //it must be more than 8MB
2095         rk_gps_info.u32MemoryPhyAddr = board_mem_reserve_add("gps", SZ_8M);
2096 #endif
2097         board_mem_reserved();
2098 }
2099 /******************************** arm dvfs frequency volt table **********************************/
2100 /**
2101  * dvfs_cpu_logic_table: table for arm and logic dvfs 
2102  * @frequency   : arm frequency
2103  * @cpu_volt    : arm voltage depend on frequency
2104  */
2105
2106 //sdk
2107 static struct cpufreq_frequency_table dvfs_arm_table_volt_level0[] = {
2108         {.frequency = 312 * 1000,       .index = 850 * 1000},
2109         {.frequency = 504 * 1000,       .index = 900 * 1000},
2110         {.frequency = 816 * 1000,       .index = 950 * 1000},
2111         {.frequency = 1008 * 1000,      .index = 1025 * 1000},
2112         {.frequency = 1200 * 1000,      .index = 1100 * 1000},
2113         {.frequency = 1416 * 1000,      .index = 1200 * 1000},
2114         {.frequency = 1608 * 1000,      .index = 1300 * 1000},
2115         {.frequency = CPUFREQ_TABLE_END},
2116 };
2117 //default
2118 static struct cpufreq_frequency_table dvfs_arm_table_volt_level1[] = {
2119         {.frequency = 312 * 1000,       .index = 875 * 1000},
2120         {.frequency = 504 * 1000,       .index = 925 * 1000},
2121         {.frequency = 816 * 1000,       .index = 975 * 1000},
2122         {.frequency = 1008 * 1000,      .index = 1075 * 1000},
2123         {.frequency = 1200 * 1000,      .index = 1150 * 1000},
2124         {.frequency = 1416 * 1000,      .index = 1250 * 1000},
2125         {.frequency = 1608 * 1000,      .index = 1350 * 1000},
2126         {.frequency = CPUFREQ_TABLE_END},
2127 };
2128 // ds1006h 10'
2129 static struct cpufreq_frequency_table dvfs_arm_table_volt_level2[] = {
2130         {.frequency = 312 * 1000,       .index = 900 * 1000},
2131         {.frequency = 504 * 1000,       .index = 925 * 1000},
2132         {.frequency = 816 * 1000,       .index = 1000 * 1000},
2133         {.frequency = 1008 * 1000,      .index = 1075 * 1000},
2134         {.frequency = 1200 * 1000,      .index = 1200 * 1000},
2135         {.frequency = 1416 * 1000,      .index = 1250 * 1000},
2136         {.frequency = 1608 * 1000,      .index = 1350 * 1000},
2137         {.frequency = CPUFREQ_TABLE_END},
2138 };
2139 //if you board is good for volt quality,select dvfs_arm_table_volt_level0
2140 #define dvfs_arm_table dvfs_arm_table_volt_level2
2141
2142 /******************************** gpu dvfs frequency volt table **********************************/
2143 //sdk
2144 static struct cpufreq_frequency_table dvfs_gpu_table_volt_level0[] = {  
2145         {.frequency = 133 * 1000,       .index = 975 * 1000},//the mininum rate is limited 133M for rk3188
2146         {.frequency = 200 * 1000,       .index = 975 * 1000},
2147         {.frequency = 266 * 1000,       .index = 1000 * 1000},
2148         {.frequency = 300 * 1000,       .index = 1050 * 1000},
2149         {.frequency = 400 * 1000,       .index = 1100 * 1000},
2150         {.frequency = 600 * 1000,       .index = 1200 * 1000},
2151         {.frequency = CPUFREQ_TABLE_END},
2152 };
2153 //ds1006h 10'
2154 static struct cpufreq_frequency_table dvfs_gpu_table_volt_level1[] = {  
2155        {.frequency = 133 * 1000,       .index = 975 * 1000},
2156         {.frequency = 200 * 1000,       .index = 1000 * 1000},
2157         {.frequency = 266 * 1000,       .index = 1025 * 1000},
2158         {.frequency = 300 * 1000,       .index = 1050 * 1000},
2159         {.frequency = 400 * 1000,       .index = 1100 * 1000},
2160         {.frequency = 600 * 1000,       .index = 1250 * 1000},
2161         {.frequency = CPUFREQ_TABLE_END},
2162 };
2163
2164 #define dvfs_gpu_table dvfs_gpu_table_volt_level1
2165
2166 /******************************** ddr dvfs frequency volt table **********************************/
2167 static struct cpufreq_frequency_table dvfs_ddr_table_volt_level0[] = {
2168         {.frequency = 200 * 1000 + DDR_FREQ_SUSPEND,    .index = 950 * 1000},
2169         {.frequency = 300 * 1000 + DDR_FREQ_VIDEO,      .index = 1000 * 1000},
2170         {.frequency = 396 * 1000 + DDR_FREQ_NORMAL,     .index = 1100 * 1000},
2171         {.frequency = 460 * 1000 + DDR_FREQ_DUALVIEW,     .index = 1150 * 1000},
2172         //{.frequency = 528 * 1000 + DDR_FREQ_NORMAL,     .index = 1200 * 1000},
2173         {.frequency = CPUFREQ_TABLE_END},
2174 };
2175
2176 static struct cpufreq_frequency_table dvfs_ddr_table_t[] = {
2177         {.frequency = 200 * 1000 + DDR_FREQ_SUSPEND,    .index = 950 * 1000},
2178         {.frequency = 460 * 1000 + DDR_FREQ_NORMAL,     .index = 1150 * 1000},
2179         {.frequency = CPUFREQ_TABLE_END},
2180 };
2181 #define dvfs_ddr_table dvfs_ddr_table_volt_level0
2182
2183 /******************************** arm dvfs frequency volt table end **********************************/
2184
2185
2186
2187 //#define DVFS_CPU_TABLE_SIZE   (ARRAY_SIZE(dvfs_cpu_logic_table))
2188 //static struct cpufreq_frequency_table cpu_dvfs_table[DVFS_CPU_TABLE_SIZE];
2189 //static struct cpufreq_frequency_table dep_cpu2core_table[DVFS_CPU_TABLE_SIZE];
2190 int get_max_freq(struct cpufreq_frequency_table *table)
2191 {
2192         int i,temp=0;
2193         
2194         for(i=0;table[i].frequency!= CPUFREQ_TABLE_END;i++)
2195         {
2196                 if(temp<table[i].frequency)
2197                         temp=table[i].frequency;
2198         }       
2199         printk("get_max_freq=%d\n",temp);
2200         return temp;
2201 }
2202
2203 void __init board_clock_init(void)
2204 {
2205         u32 flags=RK30_CLOCKS_DEFAULT_FLAGS;
2206 #if !defined(CONFIG_ARCH_RK3188)
2207         if(get_max_freq(dvfs_gpu_table)<=(400*1000))
2208         {       
2209                 flags=RK30_CLOCKS_DEFAULT_FLAGS|CLK_GPU_GPLL;
2210         }
2211         else
2212                 flags=RK30_CLOCKS_DEFAULT_FLAGS|CLK_GPU_CPLL;
2213 #endif  
2214         rk30_clock_data_init(periph_pll_default, codec_pll_default, flags);
2215         //dvfs_set_arm_logic_volt(dvfs_cpu_logic_table, cpu_dvfs_table, dep_cpu2core_table);    
2216         dvfs_set_freq_volt_table(clk_get(NULL, "cpu"), dvfs_arm_table);
2217         dvfs_set_freq_volt_table(clk_get(NULL, "gpu"), dvfs_gpu_table);
2218 #if defined(CONFIG_ARCH_RK3188)
2219         if (rk_pll_flag() == 0)
2220                 dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
2221         else
2222                 dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table_t);
2223 #else
2224         dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
2225 #endif
2226 }
2227
2228 MACHINE_START(RK30, "RK30board")
2229         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
2230         .fixup          = rk30_fixup,
2231         .reserve        = &rk30_reserve,
2232         .map_io         = rk30_map_io,
2233         .init_irq       = rk30_init_irq,
2234         .timer          = &rk30_timer,
2235         .init_machine   = machine_rk30_board_init,
2236 MACHINE_END