AndroidComputer: wifi,bt,ethernet board config
[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-ac-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_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_RK29_VMAC
1100 #define PHY_PWR_EN_GPIO RK30_PIN0_PC0
1101 #define PHY_PWR_EN_VALUE   GPIO_HIGH
1102 #include "../mach-rk30/board-rk31-sdk-vmac.c"
1103 #endif
1104
1105 #ifdef CONFIG_RFKILL_RK
1106 // bluetooth rfkill device, its driver in net/rfkill/rfkill-rk.c
1107 static struct rfkill_rk_platform_data rfkill_rk_platdata = {
1108     .type               = RFKILL_TYPE_BLUETOOTH,
1109
1110     .poweron_gpio       = { // BT_REG_ON
1111         .io             = INVALID_GPIO, //RK30_PIN3_PC7,
1112         .enable         = GPIO_HIGH,
1113         .iomux          = {
1114             .name       = "bt_poweron",
1115             .fgpio      = GPIO3_C7,
1116         },
1117     },
1118
1119     .reset_gpio         = { // BT_RST
1120         .io             = RK30_PIN3_PA0, // set io to INVALID_GPIO for disable it
1121         .enable         = GPIO_LOW,
1122         .iomux          = {
1123             .name       = "bt_reset",
1124             .fgpio      = GPIO3_A0,
1125        },
1126    }, 
1127
1128     .wake_gpio          = { // BT_WAKE, use to control bt's sleep and wakeup
1129         .io             = RK30_PIN3_PB0, // set io to INVALID_GPIO for disable it
1130         .enable         = GPIO_HIGH,
1131         .iomux          = {
1132             .name       = "bt_wake",
1133             .fgpio      = GPIO3_B0,
1134         },
1135     },
1136
1137     .wake_host_irq      = { // BT_HOST_WAKE, for bt wakeup host when it is in deep sleep
1138         .gpio           = {
1139             .io         = RK30_PIN3_PB1, // set io to INVALID_GPIO for disable it
1140             .enable     = GPIO_LOW,      // set GPIO_LOW for falling, set 0 for rising
1141             .iomux      = {
1142                 .name   = NULL,
1143             },
1144         },
1145     },
1146
1147     .rts_gpio           = { // UART_RTS, enable or disable BT's data coming
1148         .io             = RK30_PIN1_PA3, // set io to INVALID_GPIO for disable it
1149         .enable         = GPIO_LOW,
1150         .iomux          = {
1151             .name       = "bt_rts",
1152             .fgpio      = GPIO1_A3,
1153             .fmux       = UART0_RTSN,
1154         },
1155     },
1156 };
1157
1158 static struct platform_device device_rfkill_rk = {
1159     .name   = "rfkill_rk",
1160     .id     = -1,
1161     .dev    = {
1162         .platform_data = &rfkill_rk_platdata,
1163     },
1164 };
1165 #endif
1166
1167 #if defined(CONFIG_GPS_RK)
1168 int rk_gps_io_init(void)
1169 {
1170         printk("%s \n", __FUNCTION__);
1171         
1172         rk30_mux_api_set(GPIO1B5_UART3RTSN_NAME, GPIO1B_GPIO1B5);//VCC_EN
1173         gpio_request(RK30_PIN1_PB5, NULL);
1174         gpio_direction_output(RK30_PIN1_PB5, GPIO_LOW);
1175
1176         rk30_mux_api_set(GPIO1B4_UART3CTSN_GPSRFCLK_NAME, GPIO1B_GPSRFCLK);//GPS_CLK
1177         rk30_mux_api_set(GPIO1B2_UART3SIN_GPSMAG_NAME, GPIO1B_GPSMAG);//GPS_MAG
1178         rk30_mux_api_set(GPIO1B3_UART3SOUT_GPSSIG_NAME, GPIO1B_GPSSIG);//GPS_SIGN
1179
1180         rk30_mux_api_set(GPIO1A6_UART1CTSN_SPI0CLK_NAME, GPIO1A_GPIO1A6);//SPI_CLK
1181         gpio_request(RK30_PIN1_PA6, NULL);
1182         gpio_direction_output(RK30_PIN1_PA6, GPIO_LOW);
1183
1184         rk30_mux_api_set(GPIO1A5_UART1SOUT_SPI0TXD_NAME, GPIO1A_GPIO1A5);//SPI_MOSI
1185         gpio_request(RK30_PIN1_PA5, NULL);
1186         gpio_direction_output(RK30_PIN1_PA5, GPIO_LOW); 
1187
1188         rk30_mux_api_set(GPIO1A7_UART1RTSN_SPI0CSN0_NAME, GPIO1A_GPIO1A7);//SPI_CS
1189         gpio_request(RK30_PIN1_PA7, NULL);
1190         gpio_direction_output(RK30_PIN1_PA7, GPIO_LOW);         
1191         return 0;
1192 }
1193 int rk_gps_power_up(void)
1194 {
1195         printk("%s \n", __FUNCTION__);
1196
1197         return 0;
1198 }
1199
1200 int rk_gps_power_down(void)
1201 {
1202         printk("%s \n", __FUNCTION__);
1203
1204         return 0;
1205 }
1206
1207 int rk_gps_reset_set(int level)
1208 {
1209         return 0;
1210 }
1211 int rk_enable_hclk_gps(void)
1212 {
1213         printk("%s \n", __FUNCTION__);
1214         clk_enable(clk_get(NULL, "hclk_gps"));
1215         return 0;
1216 }
1217 int rk_disable_hclk_gps(void)
1218 {
1219         printk("%s \n", __FUNCTION__);
1220         clk_disable(clk_get(NULL, "hclk_gps"));
1221         return 0;
1222 }
1223 struct rk_gps_data rk_gps_info = {
1224         .io_init = rk_gps_io_init,
1225         .power_up = rk_gps_power_up,
1226         .power_down = rk_gps_power_down,
1227         .reset = rk_gps_reset_set,
1228         .enable_hclk_gps = rk_enable_hclk_gps,
1229         .disable_hclk_gps = rk_disable_hclk_gps,
1230         .GpsSign = RK30_PIN1_PB3,
1231         .GpsMag = RK30_PIN1_PB2,        //GPIO index
1232         .GpsClk = RK30_PIN1_PB4,        //GPIO index
1233         .GpsVCCEn = RK30_PIN1_PB5,     //GPIO index
1234         .GpsSpi_CSO = RK30_PIN1_PA4,    //GPIO index
1235         .GpsSpiClk = RK30_PIN1_PA5,     //GPIO index
1236         .GpsSpiMOSI = RK30_PIN1_PA7,      //GPIO index
1237         .GpsIrq = IRQ_GPS,
1238         .GpsSpiEn = 0,
1239         .GpsAdcCh = 2,
1240         .u32GpsPhyAddr = RK30_GPS_PHYS,
1241         .u32GpsPhySize = RK30_GPS_SIZE,
1242 };
1243
1244 struct platform_device rk_device_gps = {
1245         .name = "gps_hv5820b",
1246         .id = -1,
1247         .dev            = {
1248         .platform_data = &rk_gps_info,
1249                 }
1250         };
1251 #endif
1252
1253 #if defined(CONFIG_MT5931_MT6622)
1254 static struct mt6622_platform_data mt6622_platdata = {
1255                     .power_gpio         = { // BT_REG_ON
1256                       #if DS1006H_V1_2_SUPPORT
1257                     .io             = RK30_PIN3_PC7, // set io to INVALID_GPIO for disable it
1258                       #else
1259                         .io             = RK30_PIN3_PD5, // set io to INVALID_GPIO for disable it
1260                         #endif
1261                             .enable         = GPIO_HIGH,
1262                             .iomux          = {
1263                                     .name       = NULL,
1264                                 },
1265                     },
1266
1267                     .reset_gpio         = { // BT_RST
1268                         #if DS1006H_V1_2_SUPPORT
1269                     .io             = RK30_PIN3_PD1,
1270                         #else
1271                         .io             = RK30_PIN0_PD7,
1272                         #endif
1273                         .enable         = GPIO_HIGH,
1274                         .iomux          = {
1275                             .name       = NULL,
1276                         },
1277                     },
1278
1279                     .irq_gpio           = {
1280                           #if DS1006H_V1_2_SUPPORT
1281                        .io             = RK30_PIN0_PA5,
1282                           #else
1283                             .io             = RK30_PIN3_PD2,
1284                             #endif
1285                             .enable         = GPIO_HIGH,
1286                             .iomux          = {
1287                                     .name       = NULL,
1288                                 },
1289                     }
1290 };
1291
1292 static struct platform_device device_mt6622 = {
1293                     .name   = "mt6622",
1294                         .id     = -1,
1295                         .dev    = {
1296                                .platform_data = &mt6622_platdata,
1297                         },
1298 };      
1299 #endif
1300
1301 #if defined CONFIG_TCC_BT_DEV
1302 static struct tcc_bt_platform_data tcc_bt_platdata = {
1303
1304     .power_gpio   = { // ldoon
1305         .io             =  RK2928_PIN3_PC0,
1306         .enable         = GPIO_HIGH,
1307         .iomux          = {
1308             .name       = NULL,
1309             },
1310         },
1311
1312     .wake_host_gpio  = { // BT_HOST_WAKE, for bt wakeup host when it is in deep sleep
1313         .io         = RK2928_PIN0_PC5, // set io to INVALID_GPIO for disable it
1314         .enable     = IRQF_TRIGGER_RISING,// set IRQF_TRIGGER_FALLING for falling, set IRQF_TRIGGER_RISING for rising
1315         .iomux      = {
1316             .name       = NULL,
1317         },
1318     },
1319 };
1320
1321 static struct platform_device device_tcc_bt = {
1322     .name   = "tcc_bt_dev",
1323     .id     = -1,
1324     .dev    = {
1325         .platform_data = &tcc_bt_platdata,
1326         },
1327 };
1328 #endif
1329
1330
1331 static struct platform_device *devices[] __initdata = {
1332
1333 #ifdef CONFIG_ION
1334         &device_ion,
1335 #endif
1336 #ifdef CONFIG_WIFI_CONTROL_FUNC
1337         &rk29sdk_wifi_device,
1338 #endif
1339
1340 #if defined(CONFIG_MT6620)
1341             &mt3326_device_gps,
1342 #endif
1343
1344 #ifdef CONFIG_BATTERY_RK30_ADC_FAC
1345         &rk30_device_adc_battery,
1346 #endif
1347 #ifdef CONFIG_RFKILL_RK
1348         &device_rfkill_rk,
1349 #endif
1350 #ifdef CONFIG_GPS_RK
1351         &rk_device_gps,
1352 #endif
1353 #ifdef CONFIG_MT5931_MT6622
1354         &device_mt6622,
1355 #endif
1356 #if defined(CONFIG_MT6229)
1357         &rk29_device_mt6229,
1358 #endif
1359 #if defined(CONFIG_ARCH_RK3188)
1360         &device_mali,
1361 #endif
1362
1363 #ifdef CONFIG_TCC_BT_DEV
1364         &device_tcc_bt,
1365 #endif
1366 };
1367
1368
1369 static int rk_platform_add_display_devices(void)
1370 {
1371         struct platform_device *fb = NULL;  //fb
1372         struct platform_device *lcdc0 = NULL; //lcdc0
1373         struct platform_device *lcdc1 = NULL; //lcdc1
1374         struct platform_device *bl = NULL; //backlight
1375 #ifdef CONFIG_FB_ROCKCHIP
1376         fb = &device_fb;
1377 #endif
1378
1379 #if defined(CONFIG_LCDC0_RK3188)
1380         lcdc0 = &device_lcdc0,
1381 #endif
1382
1383 #if defined(CONFIG_LCDC1_RK3188)
1384         lcdc1 = &device_lcdc1,
1385 #endif
1386
1387 #ifdef CONFIG_BACKLIGHT_RK29_BL
1388         bl = &rk29_device_backlight,
1389 #endif
1390         __rk_platform_add_display_devices(fb,lcdc0,lcdc1,bl);
1391
1392         return 0;
1393         
1394 }
1395
1396 // i2c
1397 #ifdef CONFIG_I2C0_RK30
1398 static struct i2c_board_info __initdata i2c0_info[] = {
1399 #if defined (CONFIG_GS_MMA8452)
1400         {
1401                 .type           = "gs_mma8452",
1402                 .addr           = 0x1d,
1403                 .flags          = 0,
1404                 .irq            = MMA8452_INT_PIN,
1405                 .platform_data = &mma8452_info,
1406         },
1407 #endif
1408
1409 #if defined (CONFIG_GS_LIS3DH)
1410         {
1411                 .type           = "gs_lis3dh",
1412                 .addr           = 0x19,   //0x19(SA0-->VCC), 0x18(SA0-->GND)
1413                 .flags          = 0,
1414                 .irq            = LIS3DH_INT_PIN,
1415                 .platform_data = &lis3dh_info,
1416         },
1417 #endif
1418 #if defined (CONFIG_COMPASS_AK8963)
1419         {
1420                 .type          = "ak8963",
1421                 .addr          = 0x0d,
1422                 .flags         = 0,
1423                 .irq           = RK30_PIN3_PD7, 
1424                 .platform_data = &akm8963_info,
1425         },
1426 #endif
1427
1428 #if defined (CONFIG_LS_PHOTORESISTOR)
1429         {
1430                 .type           = "ls_photoresistor",
1431                 .addr           = 0x5e,            
1432                 .flags          = 0,
1433                 .irq            = INVALID_GPIO, 
1434                 .platform_data = &light_photoresistor_info,
1435         },
1436 #endif
1437
1438 #if defined (CONFIG_COMPASS_AK8975)
1439         {
1440                 .type          = "ak8975",
1441                 .addr          = 0x0d,
1442                 .flags         = 0,
1443                 .irq           = RK30_PIN3_PD7, 
1444                 .platform_data = &akm8975_info,
1445                 .irq           = RK30_PIN3_PD7, 
1446                 .platform_data = &akm8975_info,
1447         },
1448 #endif
1449 #if defined (CONFIG_GYRO_L3G4200D)
1450         {
1451                 .type          = "l3g4200d_gryo",
1452                 .addr          = 0x69,
1453                 .flags         = 0,
1454                 .irq           = L3G4200D_INT_PIN,
1455                 .platform_data = &l3g4200d_info,
1456         },
1457 #endif
1458 #if defined (CONFIG_SND_SOC_RK1000)
1459         {
1460                 .type          = "rk1000_i2c_codec",
1461                 .addr          = 0x60,
1462                 .flags         = 0,
1463         },
1464         {
1465                 .type          = "rk1000_control",
1466                 .addr          = 0x40,
1467                 .flags         = 0,
1468         },
1469 #endif
1470 #if defined (CONFIG_SND_SOC_CX2070X)
1471         {
1472                 .type                   = "cx2070x",
1473                 .addr                   = 0x14,
1474                 .flags                  = 0,
1475         },
1476 #endif
1477 };
1478 #endif
1479
1480 int __sramdata g_pmic_type =  0;
1481 #ifdef CONFIG_I2C1_RK30
1482 #ifdef CONFIG_REGULATOR_ACT8846
1483 #define PMU_POWER_SLEEP RK30_PIN0_PA1
1484 #define PMU_VSEL RK30_PIN3_PD3
1485 #define ACT8846_HOST_IRQ                RK30_PIN0_PB3
1486
1487 static struct pmu_info  act8846_dcdc_info[] = {
1488         {
1489                 .name          = "act_dcdc1",   //ddr
1490                 .min_uv          = 1200000,
1491                 .max_uv         = 1200000,
1492                 .suspend_vol  =   1200000,
1493         },
1494         {
1495                 .name          = "vdd_core",    //logic
1496                 .min_uv          = 1000000,
1497                 .max_uv         = 1000000,
1498                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1499                 .suspend_vol  =  1200000,
1500                 #else
1501                 .suspend_vol  =  900000,
1502                 #endif
1503         },
1504         {
1505                 .name          = "vdd_cpu",   //arm
1506                 .min_uv          = 1000000,
1507                 .max_uv         = 1000000,
1508                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1509                 .suspend_vol  =  1200000,
1510                 #else
1511                 .suspend_vol  =  900000,
1512                 #endif
1513         },
1514         {
1515                 .name          = "act_dcdc4",   //vccio
1516                 .min_uv          = 3000000,
1517                 .max_uv         = 3000000,
1518                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1519                 .suspend_vol  =  3000000,
1520                 #else
1521                 .suspend_vol  =  2800000,
1522                 #endif
1523         },
1524         
1525 };
1526 static  struct pmu_info  act8846_ldo_info[] = {
1527         {
1528                 .name          = "act_ldo1",   //vdd10
1529                 .min_uv          = 1000000,
1530                 .max_uv         = 1000000,
1531         },
1532         {
1533                 .name          = "act_ldo2",    //vdd12
1534                 .min_uv          = 1200000,
1535                 .max_uv         = 1200000,
1536         },
1537         {
1538                 .name          = "act_ldo3",   //vcc18_cif
1539                 .min_uv          = 1800000,
1540                 .max_uv         = 1800000,
1541         },
1542         {
1543                 .name          = "act_ldo4",   //vcca33
1544                 .min_uv          = 3300000,
1545                 .max_uv         = 3300000,
1546         },
1547         {
1548                 .name          = "act_ldo5",   //vcctp
1549                 .min_uv          = 3300000,
1550                 .max_uv         = 3300000,
1551         },
1552         {
1553                 .name          = "act_ldo6",   //vcc_jetta
1554                 .min_uv          = 3300000,
1555                 .max_uv         = 3300000,
1556         },
1557         {
1558                 .name          = "act_ldo7",   //vcc18
1559                 .min_uv          = 1800000,
1560                 .max_uv         = 1800000,
1561         },
1562         {
1563                 .name          = "act_ldo8",   //vcc28_cif
1564                 .min_uv          = 2800000,
1565                 .max_uv         = 2800000,
1566         },
1567  };
1568
1569 #include "../mach-rk30/board-pmu-act8846.c"
1570 #endif
1571
1572 #ifdef CONFIG_MFD_WM831X_I2C
1573 #define PMU_POWER_SLEEP                 RK30_PIN0_PA1 
1574
1575 static struct pmu_info  wm8326_dcdc_info[] = {
1576         {
1577                 .name          = "vdd_core",   //logic
1578                 .min_uv          = 1000000,
1579                 .max_uv         = 1000000,
1580                 .suspend_vol  =  950000,
1581         },
1582         {
1583                 .name          = "vdd_cpu",    //arm
1584                 .min_uv          = 1000000,
1585                 .max_uv         = 1000000,
1586                 .suspend_vol  =  950000,
1587         },
1588         {
1589                 .name          = "dcdc3",   //ddr
1590                 .min_uv          = 1150000,
1591                 .max_uv         = 1150000,
1592                 .suspend_vol  =  1150000,
1593         },
1594         #ifdef CONFIG_MACH_RK3066_SDK
1595         {
1596                 .name          = "dcdc4",   //vcc_io
1597                 .min_uv          = 3300000,
1598                 .max_uv         = 3300000,
1599                 .suspend_vol  =  3000000,
1600         },
1601         #else
1602         {
1603                 .name          = "dcdc4",   //vcc_io
1604                 .min_uv          = 3000000,
1605                 .max_uv         = 3000000,
1606                 .suspend_vol  =  2800000,
1607         },
1608         #endif
1609 };
1610
1611 static struct pmu_info  wm8326_ldo_info[] = {
1612         {
1613                 .name          = "ldo1",   //vcc18_cif
1614                 .min_uv          = 1800000,
1615                 .max_uv         = 1800000,
1616                 .suspend_vol  =  1800000,
1617         },
1618         {
1619                 .name          = "ldo2",    //vccio_wl
1620                 .min_uv          = 1800000,
1621                 .max_uv         = 1800000,
1622                 .suspend_vol  =  1800000,
1623         },
1624         {
1625                 .name          = "ldo3",   //
1626                 .min_uv          = 1100000,
1627                 .max_uv         = 1100000,
1628                 .suspend_vol  =  1100000,
1629         },
1630         {
1631                 .name          = "ldo4",   //vdd11
1632                 .min_uv          = 1000000,
1633                 .max_uv         = 1000000,
1634                 .suspend_vol  =  1000000,
1635         },
1636         {
1637                 .name          = "ldo5",   //vcc25
1638                 .min_uv          = 1800000,
1639                 .max_uv         = 1800000,
1640                 .suspend_vol  =  1800000,
1641         },
1642         {
1643                 .name          = "ldo6",   //vcc33
1644                 .min_uv          = 3300000,
1645                 .max_uv         = 3300000,
1646                 .suspend_vol  =  3300000,
1647         },
1648         {
1649                 .name          = "ldo7",   //vcc28_cif
1650                 .min_uv          = 2800000,
1651                 .max_uv         = 2800000,
1652                 .suspend_vol  =  2800000,
1653         },
1654         {
1655                 .name          = "ldo8",   //vcca33
1656                 .min_uv          = 3300000,
1657                 .max_uv         = 3300000,
1658                 .suspend_vol  =  3300000,
1659         },
1660         {
1661                 .name          = "ldo9",   //vcc_tp
1662                 .min_uv          = 3300000,
1663                 .max_uv         = 3300000,
1664                 .suspend_vol  =  3300000,
1665         },
1666         {
1667                 .name          = "ldo10",   //flash_io
1668                 .min_uv          = 1800000,
1669                 .max_uv         = 1800000,
1670                 .suspend_vol  =  1800000,
1671         },
1672 };
1673
1674 #include "../mach-rk30/board-pmu-wm8326.c"
1675 #endif
1676
1677 #ifdef CONFIG_MFD_TPS65910
1678 #ifdef CONFIG_ARCH_RK3188
1679 #define TPS65910_HOST_IRQ        RK30_PIN0_PB3
1680 #else
1681 #define TPS65910_HOST_IRQ        RK30_PIN6_PA4
1682 #endif
1683
1684 #define PMU_POWER_SLEEP RK30_PIN0_PA1
1685
1686 static struct pmu_info  tps65910_dcdc_info[] = {
1687         {
1688                 .name          = "vdd_core",   //logic
1689                 .min_uv          = 1100000,
1690                 .max_uv         = 1100000,
1691         },
1692         {
1693                 .name          = "vdd2",    //ddr
1694                 .min_uv          = 1200000,
1695                 .max_uv         = 1200000,
1696         },
1697         {
1698                 .name          = "vio",   //vcc_io
1699                 .min_uv          = 2500000,
1700                 .max_uv         = 2500000,
1701         },
1702         
1703 };
1704 static  struct pmu_info  tps65910_ldo_info[] = {
1705         {
1706                 .name          = "vpll",   //vdd10
1707                 .min_uv          = 1000000,
1708                 .max_uv         = 1000000,
1709         },
1710         {
1711                 .name          = "vdig1",    //vcc18_cif
1712                 .min_uv          = 1800000,
1713                 .max_uv         = 1800000,
1714         },
1715         {
1716                 .name          = "vdig2",   //vdd_jetta
1717                 .min_uv          = 1200000,
1718                 .max_uv         = 1200000,
1719         },
1720         {
1721                 .name          = "vaux1",   //vcc28_cif
1722                 .min_uv          = 2800000,
1723                 .max_uv         = 2800000,
1724         },
1725         {
1726                 .name          = "vaux2",   //vcca33
1727                 .min_uv          = 3300000,
1728                 .max_uv         = 3300000,
1729         },
1730         {
1731                 .name          = "vaux33",   //vcc_tp
1732                 .min_uv          = 3300000,
1733                 .max_uv         = 3300000,
1734         },
1735         {
1736                 .name          = "vmmc",   //vcc30
1737                 .min_uv          = 3000000,
1738                 .max_uv         = 3000000,
1739         },
1740         {
1741                 .name          = "vdac",   //vcc18
1742                 .min_uv          = 1800000,
1743                 .max_uv         = 1800000,
1744         },
1745  };
1746
1747 #include "../mach-rk30/board-pmu-tps65910.c"
1748 #endif
1749
1750 static struct i2c_board_info __initdata i2c1_info[] = {
1751 #if defined (CONFIG_REGULATOR_ACT8846)
1752         {
1753                 .type                   = "act8846",
1754                 .addr           = 0x5a, 
1755                 .flags                  = 0,
1756                 .irq            = ACT8846_HOST_IRQ,
1757                 .platform_data=&act8846_data,
1758         },
1759 #endif
1760 #if defined (CONFIG_RTC_HYM8563)
1761         {
1762                 .type                   = "rtc_hym8563",
1763                 .addr           = 0x51,
1764                 .flags                  = 0,
1765                 .irq            = RK30_PIN0_PB5,
1766         },
1767 #endif
1768 #if defined (CONFIG_MFD_WM831X_I2C)
1769         {
1770                 .type          = "wm8326",
1771                 .addr          = 0x34,
1772                 .flags         = 0,
1773                 .irq           = RK30_PIN0_PB3,
1774                 .platform_data = &wm831x_platdata,
1775         },
1776 #endif
1777 #if defined (CONFIG_MFD_TPS65910)
1778         {
1779         .type           = "tps65910",
1780         .addr           = TPS65910_I2C_ID0,
1781         .flags          = 0,
1782         .irq            = TPS65910_HOST_IRQ,
1783         .platform_data = &tps65910_data,
1784         },
1785 #endif
1786 };
1787 #endif
1788
1789 void __sramfunc board_pmu_suspend(void)
1790 {      
1791         #if defined (CONFIG_REGULATOR_ACT8846)
1792        if(pmic_is_act8846())
1793        board_pmu_act8846_suspend(); 
1794        #endif
1795         #if defined (CONFIG_MFD_WM831X_I2C)
1796        if(pmic_is_wm8326())
1797        board_pmu_wm8326_suspend();
1798         #endif
1799         #if defined (CONFIG_MFD_TPS65910)
1800        if(pmic_is_tps65910())
1801        board_pmu_tps65910_suspend(); 
1802     #endif   
1803 }
1804
1805 void __sramfunc board_pmu_resume(void)
1806 {      
1807         #if defined (CONFIG_REGULATOR_ACT8846)
1808        if(pmic_is_act8846())
1809        board_pmu_act8846_resume(); 
1810        #endif
1811         #if defined (CONFIG_MFD_WM831X_I2C)
1812        if(pmic_is_wm8326())
1813        board_pmu_wm8326_resume();
1814         #endif
1815         #if defined (CONFIG_MFD_TPS65910)
1816        if(pmic_is_tps65910())
1817        board_pmu_tps65910_resume(); 
1818         #endif
1819 }
1820
1821  int __sramdata gpio3d6_iomux,gpio3d6_do,gpio3d6_dir,gpio3d6_en;
1822
1823 #define grf_readl(offset)       readl_relaxed(RK30_GRF_BASE + offset)
1824 #define grf_writel(v, offset)   do { writel_relaxed(v, RK30_GRF_BASE + offset); dsb(); } while (0)
1825  
1826 void __sramfunc rk30_pwm_logic_suspend_voltage(void)
1827 {
1828 #ifdef CONFIG_RK30_PWM_REGULATOR
1829
1830 //      int gpio0d7_iomux,gpio0d7_do,gpio0d7_dir,gpio0d7_en;
1831         sram_udelay(10000);
1832         gpio3d6_iomux = grf_readl(GRF_GPIO3D_IOMUX);
1833         gpio3d6_do = grf_readl(GRF_GPIO3H_DO);
1834         gpio3d6_dir = grf_readl(GRF_GPIO3H_DIR);
1835         gpio3d6_en = grf_readl(GRF_GPIO3H_EN);
1836
1837         grf_writel((1<<28), GRF_GPIO3D_IOMUX);
1838         grf_writel((1<<30)|(1<<14), GRF_GPIO3H_DIR);
1839         grf_writel((1<<30)|(1<<14), GRF_GPIO3H_DO);
1840         grf_writel((1<<30)|(1<<14), GRF_GPIO3H_EN);
1841 #endif 
1842 }
1843 void __sramfunc rk30_pwm_logic_resume_voltage(void)
1844 {
1845 #ifdef CONFIG_RK30_PWM_REGULATOR
1846         grf_writel((1<<28)|gpio3d6_iomux, GRF_GPIO3D_IOMUX);
1847         grf_writel((1<<30)|gpio3d6_en, GRF_GPIO3H_EN);
1848         grf_writel((1<<30)|gpio3d6_dir, GRF_GPIO3H_DIR);
1849         grf_writel((1<<30)|gpio3d6_do, GRF_GPIO3H_DO);
1850         sram_udelay(10000);
1851
1852 #endif
1853
1854 }
1855 extern void pwm_suspend_voltage(void);
1856 extern void pwm_resume_voltage(void);
1857 void  rk30_pwm_suspend_voltage_set(void)
1858 {
1859 #ifdef CONFIG_RK30_PWM_REGULATOR
1860         pwm_suspend_voltage();
1861 #endif
1862 }
1863 void  rk30_pwm_resume_voltage_set(void)
1864 {
1865 #ifdef CONFIG_RK30_PWM_REGULATOR
1866         pwm_resume_voltage();
1867 #endif
1868 }
1869
1870
1871 #ifdef CONFIG_I2C2_RK30
1872 static struct i2c_board_info __initdata i2c2_info[] = {
1873 #if defined (CONFIG_CT36X_TS)
1874         {
1875                 .type          = CT36X_NAME,
1876                 .addr          = 0x01,
1877                 .flags         = 0,
1878                 .platform_data = &ct36x_info,
1879         },
1880 #endif
1881 #if defined (CONFIG_LS_CM3217)
1882         {
1883                 .type          = "lightsensor",
1884                 .addr          = 0x10,
1885                 .flags         = 0,
1886                 .platform_data = &cm3217_info,
1887         },
1888 #endif
1889 #if defined (CONFIG_LS_US5151)
1890         {    
1891                 .type           = "us5151",
1892                 .addr           = 0x10,
1893                 .flags          = 0, 
1894         },   
1895 #endif
1896
1897 #if defined(CONFIG_HDMI_CAT66121)
1898         {
1899                 .type           = "cat66121_hdmi",
1900                 .addr           = 0x4c,
1901                 .flags          = 0,
1902                 .irq            = RK30_PIN2_PD6,
1903                 .platform_data  = &rk_hdmi_pdata,
1904         },
1905 #endif
1906 };
1907 #endif
1908
1909 #ifdef CONFIG_I2C3_RK30
1910 static struct i2c_board_info __initdata i2c3_info[] = {
1911 };
1912 #endif
1913
1914 #ifdef CONFIG_I2C4_RK30
1915 static struct i2c_board_info __initdata i2c4_info[] = {
1916 #ifdef CONFIG_MFD_RK610
1917                 {
1918                         .type                   = "rk610_ctl",
1919                         .addr                   = 0x40,
1920                         .flags                  = 0,
1921                         .platform_data          = &rk610_ctl_pdata,
1922                 },
1923 #ifdef CONFIG_RK610_TVOUT
1924                 {
1925                         .type                   = "rk610_tvout",
1926                         .addr                   = 0x42,
1927                         .flags                  = 0,
1928                 },
1929 #endif
1930 #ifdef CONFIG_HDMI_RK610
1931                 {
1932                         .type                   = "rk610_hdmi",
1933                         .addr                   = 0x46,
1934                         .flags                  = 0,
1935                         .irq                    = INVALID_GPIO,
1936                 },
1937 #endif
1938 #ifdef CONFIG_SND_SOC_RK610
1939                 {//RK610_CODEC addr  from 0x60 to 0x80 (0x60~0x80)
1940                         .type                   = "rk610_i2c_codec",
1941                         .addr                   = 0x60,
1942                         .flags                  = 0,
1943                         .platform_data          = &rk610_codec_pdata,                   
1944                 },
1945 #endif
1946 #endif
1947
1948 #if defined (CONFIG_SND_SOC_RT5631)
1949         {
1950                 .type                   = "rt5631",
1951                 .addr                   = 0x1a,
1952                 .flags                  = 0,
1953         },
1954 #endif
1955
1956 };
1957 #endif
1958
1959 #ifdef CONFIG_I2C_GPIO_RK30
1960 #define I2C_SDA_PIN     INVALID_GPIO// RK30_PIN2_PD6   //set sda_pin here
1961 #define I2C_SCL_PIN     INVALID_GPIO//RK30_PIN2_PD7   //set scl_pin here
1962 static int rk30_i2c_io_init(void)
1963 {
1964         //set iomux (gpio) here
1965         //rk30_mux_api_set(GPIO2D7_I2C1SCL_NAME, GPIO2D_GPIO2D7);
1966         //rk30_mux_api_set(GPIO2D6_I2C1SDA_NAME, GPIO2D_GPIO2D6);
1967
1968         return 0;
1969 }
1970 struct i2c_gpio_platform_data default_i2c_gpio_data = {
1971        .sda_pin = I2C_SDA_PIN,
1972        .scl_pin = I2C_SCL_PIN,
1973        .udelay = 5, // clk = 500/udelay = 100Khz
1974        .timeout = 100,//msecs_to_jiffies(100),
1975        .bus_num    = 5,
1976        .io_init = rk30_i2c_io_init,
1977 };
1978 static struct i2c_board_info __initdata i2c_gpio_info[] = {
1979 };
1980 #endif
1981
1982 static void __init rk30_i2c_register_board_info(void)
1983 {
1984 #ifdef CONFIG_I2C0_RK30
1985         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
1986 #endif
1987 #ifdef CONFIG_I2C1_RK30
1988         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
1989 #endif
1990 #ifdef CONFIG_I2C2_RK30
1991         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
1992 #endif
1993 #ifdef CONFIG_I2C3_RK30
1994         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
1995 #endif
1996 #ifdef CONFIG_I2C4_RK30
1997         i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info));
1998 #endif
1999 #ifdef CONFIG_I2C_GPIO_RK30
2000         i2c_register_board_info(5, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info));
2001 #endif
2002 }
2003 //end of i2c
2004
2005 #define POWER_ON_PIN RK30_PIN0_PA0   //power_hold
2006 static void rk30_pm_power_off(void)
2007 {
2008         printk(KERN_ERR "rk30_pm_power_off start...\n");
2009 #if defined(CONFIG_MFD_WM831X)
2010         wm831x_set_bits(Wm831x,WM831X_GPIO_LEVEL,0x0001,0x0000);  //set sys_pwr 0
2011         wm831x_device_shutdown(Wm831x);//wm8326 shutdown
2012 #endif
2013 #if defined(CONFIG_REGULATOR_ACT8846)
2014        if (pmic_is_act8846()) {
2015                printk("enter dcdet===========\n");
2016                if(gpio_get_value (RK30_PIN0_PB2) == GPIO_LOW)
2017                {
2018                        printk("enter restart===========\n");
2019                        arm_pm_restart(0, "charge");
2020                }
2021                 /** code here may cause tablet cannot boot when shutdown without charger pluged in
2022                   * and then plug in charger. -- Cody Xie
2023                else
2024                 {
2025                         act8846_device_shutdown();
2026                 }
2027                   */
2028        }
2029 #endif
2030         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
2031         while (1);
2032 }
2033
2034 static void __init machine_rk30_board_init(void)
2035 {
2036         //avs_init();
2037         gpio_request(POWER_ON_PIN, "poweronpin");
2038         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
2039         
2040         pm_power_off = rk30_pm_power_off;
2041         
2042         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
2043
2044
2045         rk30_i2c_register_board_info();
2046         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
2047         platform_add_devices(devices, ARRAY_SIZE(devices));
2048         rk_platform_add_display_devices();
2049         //board_usb_detect_init(RK30_PIN0_PA7);
2050
2051 #ifdef CONFIG_WIFI_CONTROL_FUNC
2052         rk29sdk_wifi_bt_gpio_control_init();
2053 #endif
2054
2055 #if defined(CONFIG_MT6620)
2056             clk_set_rate(clk_get_sys("rk_serial.1", "uart"), 48*1000000);
2057 #endif
2058
2059 #if defined(CONFIG_MT5931_MT6622)
2060                 clk_set_rate(clk_get_sys("rk_serial.0", "uart"), 24*1000000);
2061 #endif          
2062 }
2063
2064 #define HD_SCREEN_SIZE 1920UL*1200UL*4*3
2065 static void __init rk30_reserve(void)
2066 {
2067 #if defined(CONFIG_ARCH_RK3188)
2068         /*if lcd resolution great than or equal to 1920*1200,reserve the ump memory */
2069         if(!(get_fb_size() < ALIGN(HD_SCREEN_SIZE,SZ_1M)))
2070         {
2071                 int ump_mem_phy_size=512UL*1024UL*1024UL; 
2072                 resource_mali[0].start = board_mem_reserve_add("ump buf", ump_mem_phy_size); 
2073                 resource_mali[0].end = resource_mali[0].start + ump_mem_phy_size -1;
2074         }
2075 #endif
2076 #ifdef CONFIG_ION
2077         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion", ION_RESERVE_SIZE);
2078 #endif
2079
2080 #ifdef CONFIG_FB_ROCKCHIP
2081         resource_fb[0].start = board_mem_reserve_add("fb0 buf", get_fb_size());
2082         resource_fb[0].end = resource_fb[0].start + get_fb_size()- 1;
2083 #if 0
2084         resource_fb[1].start = board_mem_reserve_add("ipp buf", RK30_FB0_MEM_SIZE);
2085         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
2086 #endif
2087
2088 #if defined(CONFIG_FB_ROTATE) || !defined(CONFIG_THREE_FB_BUFFER)
2089         resource_fb[2].start = board_mem_reserve_add("fb2 buf",get_fb_size());
2090         resource_fb[2].end = resource_fb[2].start + get_fb_size() - 1;
2091 #endif
2092 #endif
2093
2094
2095 #ifdef CONFIG_VIDEO_RK29
2096         rk30_camera_request_reserve_mem();
2097 #endif
2098         
2099 #ifdef CONFIG_GPS_RK
2100         //it must be more than 8MB
2101         rk_gps_info.u32MemoryPhyAddr = board_mem_reserve_add("gps", SZ_8M);
2102 #endif
2103         board_mem_reserved();
2104 }
2105 /******************************** arm dvfs frequency volt table **********************************/
2106 /**
2107  * dvfs_cpu_logic_table: table for arm and logic dvfs 
2108  * @frequency   : arm frequency
2109  * @cpu_volt    : arm voltage depend on frequency
2110  */
2111
2112 //sdk
2113 static struct cpufreq_frequency_table dvfs_arm_table_volt_level0[] = {
2114         {.frequency = 312 * 1000,       .index = 850 * 1000},
2115         {.frequency = 504 * 1000,       .index = 900 * 1000},
2116         {.frequency = 816 * 1000,       .index = 950 * 1000},
2117         {.frequency = 1008 * 1000,      .index = 1025 * 1000},
2118         {.frequency = 1200 * 1000,      .index = 1100 * 1000},
2119         {.frequency = 1416 * 1000,      .index = 1200 * 1000},
2120         {.frequency = 1608 * 1000,      .index = 1300 * 1000},
2121         {.frequency = CPUFREQ_TABLE_END},
2122 };
2123 //default
2124 static struct cpufreq_frequency_table dvfs_arm_table_volt_level1[] = {
2125         {.frequency = 312 * 1000,       .index = 875 * 1000},
2126         {.frequency = 504 * 1000,       .index = 925 * 1000},
2127         {.frequency = 816 * 1000,       .index = 975 * 1000},
2128         {.frequency = 1008 * 1000,      .index = 1075 * 1000},
2129         {.frequency = 1200 * 1000,      .index = 1150 * 1000},
2130         {.frequency = 1416 * 1000,      .index = 1250 * 1000},
2131         {.frequency = 1608 * 1000,      .index = 1350 * 1000},
2132         {.frequency = CPUFREQ_TABLE_END},
2133 };
2134 // ds1006h 10'
2135 static struct cpufreq_frequency_table dvfs_arm_table_volt_level2[] = {
2136         {.frequency = 312 * 1000,       .index = 900 * 1000},
2137         {.frequency = 504 * 1000,       .index = 925 * 1000},
2138         {.frequency = 816 * 1000,       .index = 1000 * 1000},
2139         {.frequency = 1008 * 1000,      .index = 1075 * 1000},
2140         {.frequency = 1200 * 1000,      .index = 1200 * 1000},
2141         {.frequency = 1416 * 1000,      .index = 1250 * 1000},
2142         {.frequency = 1608 * 1000,      .index = 1350 * 1000},
2143         {.frequency = CPUFREQ_TABLE_END},
2144 };
2145 //if you board is good for volt quality,select dvfs_arm_table_volt_level0
2146 #define dvfs_arm_table dvfs_arm_table_volt_level2
2147
2148 /******************************** gpu dvfs frequency volt table **********************************/
2149 //sdk
2150 static struct cpufreq_frequency_table dvfs_gpu_table_volt_level0[] = {  
2151         {.frequency = 133 * 1000,       .index = 975 * 1000},//the mininum rate is limited 133M for rk3188
2152         {.frequency = 200 * 1000,       .index = 975 * 1000},
2153         {.frequency = 266 * 1000,       .index = 1000 * 1000},
2154         {.frequency = 300 * 1000,       .index = 1050 * 1000},
2155         {.frequency = 400 * 1000,       .index = 1100 * 1000},
2156         {.frequency = 600 * 1000,       .index = 1200 * 1000},
2157         {.frequency = CPUFREQ_TABLE_END},
2158 };
2159 //ds1006h 10'
2160 static struct cpufreq_frequency_table dvfs_gpu_table_volt_level1[] = {  
2161        {.frequency = 133 * 1000,       .index = 975 * 1000},
2162         {.frequency = 200 * 1000,       .index = 1000 * 1000},
2163         {.frequency = 266 * 1000,       .index = 1025 * 1000},
2164         {.frequency = 300 * 1000,       .index = 1050 * 1000},
2165         {.frequency = 400 * 1000,       .index = 1100 * 1000},
2166         {.frequency = 600 * 1000,       .index = 1250 * 1000},
2167         {.frequency = CPUFREQ_TABLE_END},
2168 };
2169
2170 #define dvfs_gpu_table dvfs_gpu_table_volt_level1
2171
2172 /******************************** ddr dvfs frequency volt table **********************************/
2173 static struct cpufreq_frequency_table dvfs_ddr_table_volt_level0[] = {
2174         {.frequency = 200 * 1000 + DDR_FREQ_SUSPEND,    .index = 950 * 1000},
2175         {.frequency = 300 * 1000 + DDR_FREQ_VIDEO,      .index = 1000 * 1000},
2176         {.frequency = 396 * 1000 + DDR_FREQ_NORMAL,     .index = 1100 * 1000},
2177         {.frequency = 460 * 1000 + DDR_FREQ_DUALVIEW,     .index = 1150 * 1000},
2178         //{.frequency = 528 * 1000 + DDR_FREQ_NORMAL,     .index = 1200 * 1000},
2179         {.frequency = CPUFREQ_TABLE_END},
2180 };
2181
2182 static struct cpufreq_frequency_table dvfs_ddr_table_t[] = {
2183         {.frequency = 200 * 1000 + DDR_FREQ_SUSPEND,    .index = 950 * 1000},
2184         {.frequency = 460 * 1000 + DDR_FREQ_NORMAL,     .index = 1150 * 1000},
2185         {.frequency = CPUFREQ_TABLE_END},
2186 };
2187 #define dvfs_ddr_table dvfs_ddr_table_volt_level0
2188
2189 /******************************** arm dvfs frequency volt table end **********************************/
2190
2191
2192
2193 //#define DVFS_CPU_TABLE_SIZE   (ARRAY_SIZE(dvfs_cpu_logic_table))
2194 //static struct cpufreq_frequency_table cpu_dvfs_table[DVFS_CPU_TABLE_SIZE];
2195 //static struct cpufreq_frequency_table dep_cpu2core_table[DVFS_CPU_TABLE_SIZE];
2196 int get_max_freq(struct cpufreq_frequency_table *table)
2197 {
2198         int i,temp=0;
2199         
2200         for(i=0;table[i].frequency!= CPUFREQ_TABLE_END;i++)
2201         {
2202                 if(temp<table[i].frequency)
2203                         temp=table[i].frequency;
2204         }       
2205         printk("get_max_freq=%d\n",temp);
2206         return temp;
2207 }
2208
2209 void __init board_clock_init(void)
2210 {
2211         u32 flags=RK30_CLOCKS_DEFAULT_FLAGS;
2212 #if !defined(CONFIG_ARCH_RK3188)
2213         if(get_max_freq(dvfs_gpu_table)<=(400*1000))
2214         {       
2215                 flags=RK30_CLOCKS_DEFAULT_FLAGS|CLK_GPU_GPLL;
2216         }
2217         else
2218                 flags=RK30_CLOCKS_DEFAULT_FLAGS|CLK_GPU_CPLL;
2219 #endif  
2220         rk30_clock_data_init(periph_pll_default, codec_pll_default, flags);
2221         //dvfs_set_arm_logic_volt(dvfs_cpu_logic_table, cpu_dvfs_table, dep_cpu2core_table);    
2222         dvfs_set_freq_volt_table(clk_get(NULL, "cpu"), dvfs_arm_table);
2223         dvfs_set_freq_volt_table(clk_get(NULL, "gpu"), dvfs_gpu_table);
2224 #if defined(CONFIG_ARCH_RK3188)
2225         if (rk_pll_flag() == 0)
2226                 dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
2227         else
2228                 dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table_t);
2229 #else
2230         dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
2231 #endif
2232 }
2233
2234 MACHINE_START(RK30, "RK30board")
2235         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
2236         .fixup          = rk30_fixup,
2237         .reserve        = &rk30_reserve,
2238         .map_io         = rk30_map_io,
2239         .init_irq       = rk30_init_irq,
2240         .timer          = &rk30_timer,
2241         .init_machine   = machine_rk30_board_init,
2242 MACHINE_END