ARM64: DTS: Add rk3399-firefly uart4 device, node as /dev/ttyS1
[firefly-linux-kernel-4.4.55.git] / board-rk3168-ds1006h.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 <linux/regulator/rk29-pwm-regulator.h>
50 #if defined(CONFIG_CT36X_TS)
51 #include <linux/ct36x.h>
52 #endif
53 #if defined(CONFIG_MFD_RK610)
54 #include <linux/mfd/rk610_core.h>
55 #endif
56
57 #if defined(CONFIG_RK_HDMI)
58         #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
59 #endif
60
61 #if defined(CONFIG_SPIM_RK29)
62 #include "../../../drivers/spi/rk29_spim.h"
63 #endif
64 #if defined(CONFIG_GPS_RK)
65 #include "../../../drivers/misc/gps/rk_gps/rk_gps.h"
66 #endif
67
68 #if defined(CONFIG_MT6620)
69 #include <linux/gps.h>
70 #endif
71
72 #include "board-rk3168-ds1006h-camera.c"
73 #include <plat/key.h>
74
75 static struct rk29_keys_button key_button[] = {
76         {
77                 .desc   = "play",
78                 .code   = KEY_POWER,
79                 .gpio   = RK30_PIN0_PA4, 
80                 .active_low = PRESS_LEV_LOW,
81                 .wakeup = 1,
82         },
83         {
84                 .desc   = "esc",
85                 .code   = KEY_BACK,
86                 .adc_value      = 1,
87                 .gpio = INVALID_GPIO,
88                 .active_low = PRESS_LEV_LOW,
89         },
90 };
91 struct rk29_keys_platform_data rk29_keys_pdata = {
92         .buttons        = key_button,
93         .nbuttons       = ARRAY_SIZE(key_button),
94         .chn    = 1,  //chn: 0-7, if do not use ADC,set 'chn' -1
95 };
96
97 #if defined(CONFIG_CT36X_TS)
98
99 #define TOUCH_MODEL             363
100 #define TOUCH_MAX_X             1280
101 #define TOUCH_MAX_y             800
102 #define TOUCH_RESET_PIN         RK30_PIN0_PB6
103 #define TOUCH_INT_PIN           RK30_PIN1_PB7
104
105 static struct ct36x_platform_data ct36x_info = {
106         .model   = TOUCH_MODEL,
107         .x_max   = TOUCH_MAX_X,
108         .y_max   = TOUCH_MAX_y,
109
110         .rst_io = {
111                 .gpio = TOUCH_RESET_PIN,
112                 .active_low = 1,
113         },
114         .irq_io = {
115                 .gpio = TOUCH_INT_PIN,
116                 .active_low = 1,
117         },
118         .orientation = {1, 0, 1, 0},
119 };
120 #endif
121 static struct spi_board_info board_spi_devices[] = {
122 };
123
124 /***********************************************************
125 *       rk30  backlight
126 ************************************************************/
127 #ifdef CONFIG_BACKLIGHT_RK29_BL
128 #define PWM_ID            3
129 #define PWM_MODE          PWM3
130 #define PWM_EFFECT_VALUE  1
131
132 #define LCD_DISP_ON_PIN
133
134 #ifdef  LCD_DISP_ON_PIN
135 #define BL_EN_PIN         RK30_PIN0_PA2
136 #define BL_EN_VALUE       GPIO_HIGH
137 #endif
138 static int rk29_backlight_io_init(void)
139 {
140         int ret = 0;
141
142         iomux_set(PWM_MODE);
143 #ifdef  LCD_DISP_ON_PIN
144         ret = gpio_request(BL_EN_PIN, NULL);
145         if (ret != 0) {
146                 gpio_free(BL_EN_PIN);
147         }
148
149         gpio_direction_output(BL_EN_PIN, 0);
150         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
151 #endif
152
153         return ret;
154 }
155
156 static int rk29_backlight_io_deinit(void)
157 {
158         int ret = 0, pwm_gpio;
159
160 #ifdef  LCD_DISP_ON_PIN
161         gpio_free(BL_EN_PIN);
162 #endif
163
164         pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
165         gpio_request(pwm_gpio, NULL);
166         gpio_direction_output(pwm_gpio, GPIO_LOW);
167         return ret;
168 }
169
170 static int rk29_backlight_pwm_suspend(void)
171 {
172         int ret = 0, pwm_gpio;
173
174         pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
175         if (gpio_request(pwm_gpio, NULL)) {
176                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
177                 return -1;
178         }
179         gpio_direction_output(pwm_gpio, GPIO_LOW);
180 #ifdef  LCD_DISP_ON_PIN
181         gpio_direction_output(BL_EN_PIN, 0);
182         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
183 #endif
184         return ret;
185 }
186
187 static int rk29_backlight_pwm_resume(void)
188 {
189         int pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
190
191         gpio_free(pwm_gpio);
192         iomux_set(PWM_MODE);
193 #ifdef  LCD_DISP_ON_PIN
194         msleep(30);
195         gpio_direction_output(BL_EN_PIN, 1);
196         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
197 #endif
198         return 0;
199 }
200
201 static struct rk29_bl_info rk29_bl_info = {
202         .min_brightness = 30,
203         .pre_div = 20 * 1000,  // pwm output clk: 20k;
204         .pwm_id = PWM_ID,
205         .bl_ref = PWM_EFFECT_VALUE,
206         .io_init = rk29_backlight_io_init,
207         .io_deinit = rk29_backlight_io_deinit,
208         .pwm_suspend = rk29_backlight_pwm_suspend,
209         .pwm_resume = rk29_backlight_pwm_resume,
210 };
211
212 static struct platform_device rk29_device_backlight = {
213         .name   = "rk29_backlight",
214         .id     = -1,
215         .dev    = {
216                 .platform_data  = &rk29_bl_info,
217         }
218 };
219
220 #endif
221
222 /*MMA8452 gsensor*/
223 #if defined (CONFIG_GS_MMA8452)
224 #define MMA8452_INT_PIN   RK30_PIN0_PB7
225
226 static int mma8452_init_platform_hw(void)
227 {
228         return 0;
229 }
230
231 static struct sensor_platform_data mma8452_info = {
232         .type = SENSOR_TYPE_ACCEL,
233         .irq_enable = 1,
234         .poll_delay_ms = 30,
235         .init_platform_hw = mma8452_init_platform_hw,
236         .orientation = {-1, 0, 0, 0, 0, 1, 0, 1, 0},
237 };
238 #endif
239 #if defined (CONFIG_GS_LIS3DH)
240 #define LIS3DH_INT_PIN   RK30_PIN0_PB7
241
242 static int lis3dh_init_platform_hw(void)
243 {
244
245         return 0;
246 }
247
248 static struct sensor_platform_data lis3dh_info = {
249         .type = SENSOR_TYPE_ACCEL,
250         .irq_enable = 1,
251         .poll_delay_ms = 30,
252         .init_platform_hw = lis3dh_init_platform_hw,
253         .orientation = {-1, 0, 0, 0, 0, 1, 0, -1, 0},
254 };
255 #endif
256 #if defined (CONFIG_COMPASS_AK8975)
257 static struct sensor_platform_data akm8975_info =
258 {
259         .type = SENSOR_TYPE_COMPASS,
260         .irq_enable = 1,
261         .poll_delay_ms = 30,
262         .m_layout = 
263         {
264                 {
265                         {1, 0, 0},
266                         {0, 1, 0},
267                         {0, 0, 1},
268                 },
269
270                 {
271                         {1, 0, 0},
272                         {0, 1, 0},
273                         {0, 0, 1},
274                 },
275
276                 {
277                         {1, 0, 0},
278                         {0, 1, 0},
279                         {0, 0, 1},
280                 },
281
282                 {
283                         {1, 0, 0},
284                         {0, 1, 0},
285                         {0, 0, 1},
286                 },
287         }
288 };
289
290 #endif
291
292 #if defined(CONFIG_GYRO_L3G4200D)
293
294 #include <linux/l3g4200d.h>
295 #define L3G4200D_INT_PIN  RK30_PIN0_PB4
296
297 static int l3g4200d_init_platform_hw(void)
298 {
299         return 0;
300 }
301
302 static struct sensor_platform_data l3g4200d_info = {
303         .type = SENSOR_TYPE_GYROSCOPE,
304         .irq_enable = 1,
305         .poll_delay_ms = 30,
306         .orientation = {0, 1, 0, -1, 0, 0, 0, 0, 1},
307         .init_platform_hw = l3g4200d_init_platform_hw,
308         .x_min = 40,//x_min,y_min,z_min = (0-100) according to hardware
309         .y_min = 40,
310         .z_min = 20,
311 };
312
313 #endif
314
315 #ifdef CONFIG_LS_CM3217
316 static struct sensor_platform_data cm3217_info = {
317         .type = SENSOR_TYPE_LIGHT,
318         .irq_enable = 0,
319         .poll_delay_ms = 500,
320 };
321
322 #endif
323
324 #ifdef CONFIG_FB_ROCKCHIP
325
326 #define LCD_CS_PIN         INVALID_GPIO
327 #define LCD_CS_VALUE       GPIO_HIGH
328
329 #define LCD_EN_PIN         RK30_PIN0_PB0
330 #define LCD_EN_VALUE       GPIO_LOW
331
332 static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
333 {
334         int ret = 0;
335
336         if(LCD_CS_PIN !=INVALID_GPIO)
337         {
338                 ret = gpio_request(LCD_CS_PIN, NULL);
339                 if (ret != 0)
340                 {
341                         gpio_free(LCD_CS_PIN);
342                         printk(KERN_ERR "request lcd cs pin fail!\n");
343                         return -1;
344                 }
345                 else
346                 {
347                         gpio_direction_output(LCD_CS_PIN, LCD_CS_VALUE);
348                 }
349         }
350
351         if(LCD_EN_PIN !=INVALID_GPIO)
352         {
353                 ret = gpio_request(LCD_EN_PIN, NULL);
354                 if (ret != 0)
355                 {
356                         gpio_free(LCD_EN_PIN);
357                         printk(KERN_ERR "request lcd en pin fail!\n");
358                         return -1;
359                 }
360                 else
361                 {
362                         gpio_direction_output(LCD_EN_PIN, LCD_EN_VALUE);
363                 }
364         }
365         return 0;
366 }
367 static int rk_fb_io_disable(void)
368 {
369         if(LCD_CS_PIN !=INVALID_GPIO)
370         {
371                 gpio_set_value(LCD_CS_PIN, !LCD_CS_VALUE);
372         }
373         if(LCD_EN_PIN !=INVALID_GPIO)
374         {
375                 gpio_set_value(LCD_EN_PIN, !LCD_EN_VALUE);
376         }
377         return 0;
378 }
379 static int rk_fb_io_enable(void)
380 {
381         if(LCD_CS_PIN !=INVALID_GPIO)
382         {
383                 gpio_set_value(LCD_CS_PIN, LCD_CS_VALUE);
384         }
385         if(LCD_EN_PIN !=INVALID_GPIO)
386         {
387                 gpio_set_value(LCD_EN_PIN, LCD_EN_VALUE);
388         }
389         return 0;
390 }
391
392 #if defined(CONFIG_LCDC0_RK3066B)
393 struct rk29fb_info lcdc0_screen_info = {
394         .prop      = EXTEND,            //primary display device
395         .io_init   = NULL,
396         .io_disable = NULL,
397         .io_enable = NULL,
398         .set_screen_info = NULL,
399 };
400 #endif
401
402 #if defined(CONFIG_LCDC1_RK3066B)
403 struct rk29fb_info lcdc1_screen_info = {
404         .prop      = PRMRY,             //primary display device
405         .io_init   = rk_fb_io_init,
406         .io_disable = rk_fb_io_disable,
407         .io_enable = rk_fb_io_enable,
408         .set_screen_info = set_lcd_info,
409         
410 };
411 #endif
412
413 static struct resource resource_fb[] = {
414         [0] = {
415                 .name  = "fb0 buf",
416                 .start = 0,
417                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
418                 .flags = IORESOURCE_MEM,
419         },
420         [1] = {
421                 .name  = "ipp buf",  //for rotate
422                 .start = 0,
423                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
424                 .flags = IORESOURCE_MEM,
425         },
426         [2] = {
427                 .name  = "fb2 buf",
428                 .start = 0,
429                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
430                 .flags = IORESOURCE_MEM,
431         },
432 };
433
434 static struct platform_device device_fb = {
435         .name           = "rk-fb",
436         .id             = -1,
437         .num_resources  = ARRAY_SIZE(resource_fb),
438         .resource       = resource_fb,
439 };
440 #endif
441
442 #if defined(CONFIG_LCDC0_RK3066B)
443 static struct resource resource_lcdc0[] = {
444         [0] = {
445                 .name  = "lcdc0 reg",
446                 .start = RK30_LCDC0_PHYS,
447                 .end   = RK30_LCDC0_PHYS + RK30_LCDC0_SIZE - 1,
448                 .flags = IORESOURCE_MEM,
449         },
450         
451         [1] = {
452                 .name  = "lcdc0 irq",
453                 .start = IRQ_LCDC0,
454                 .end   = IRQ_LCDC0,
455                 .flags = IORESOURCE_IRQ,
456         },
457 };
458
459 static struct platform_device device_lcdc0 = {
460         .name             = "rk30-lcdc",
461         .id               = 0,
462         .num_resources    = ARRAY_SIZE(resource_lcdc0),
463         .resource         = resource_lcdc0,
464         .dev            = {
465                 .platform_data = &lcdc0_screen_info,
466         },
467 };
468 #endif
469 #if defined(CONFIG_LCDC1_RK3066B) 
470 static struct resource resource_lcdc1[] = {
471         [0] = {
472                 .name  = "lcdc1 reg",
473                 .start = RK30_LCDC1_PHYS,
474                 .end   = RK30_LCDC1_PHYS + RK30_LCDC1_SIZE - 1,
475                 .flags = IORESOURCE_MEM,
476         },
477         [1] = {
478                 .name  = "lcdc1 irq",
479                 .start = IRQ_LCDC1,
480                 .end   = IRQ_LCDC1,
481                 .flags = IORESOURCE_IRQ,
482         },
483 };
484
485 static struct platform_device device_lcdc1 = {
486         .name             = "rk30-lcdc",
487         .id               = 1,
488         .num_resources    = ARRAY_SIZE(resource_lcdc1),
489         .resource         = resource_lcdc1,
490         .dev            = {
491                 .platform_data = &lcdc1_screen_info,
492         },
493 };
494 #endif
495
496 #if defined(CONFIG_MFD_RK610)
497 #define RK610_RST_PIN                   RK30_PIN3_PB2
498 static int rk610_power_on_init(void)
499 {
500         int ret;
501         if(RK610_RST_PIN != INVALID_GPIO)
502         {
503                 ret = gpio_request(RK610_RST_PIN, "rk610 reset");
504                 if (ret)
505                 {
506                         printk(KERN_ERR "rk610_control_probe request gpio fail\n");
507                 }
508                 else 
509                 {
510                         gpio_direction_output(RK610_RST_PIN, GPIO_HIGH);
511                         msleep(100);
512                         gpio_direction_output(RK610_RST_PIN, GPIO_LOW);
513                         msleep(100);
514                         gpio_set_value(RK610_RST_PIN, GPIO_HIGH);
515                 }
516         }
517
518         return 0;
519         
520 }
521
522
523 static struct rk610_ctl_platform_data rk610_ctl_pdata = {
524         .rk610_power_on_init = rk610_power_on_init,
525 };
526 #endif
527
528 #ifdef CONFIG_SND_SOC_RK610
529 static int rk610_codec_io_init(void)
530 {
531 //if need iomux.
532 //Must not gpio_request
533         return 0;
534 }
535
536 static struct rk610_codec_platform_data rk610_codec_pdata = {
537         .spk_ctl_io = RK30_PIN2_PD7,
538         .io_init = rk610_codec_io_init,
539         .boot_depop = 1,
540 };
541 #endif
542
543 #ifdef CONFIG_ION
544 #define ION_RESERVE_SIZE        (80 * SZ_1M)
545 static struct ion_platform_data rk30_ion_pdata = {
546         .nr = 1,
547         .heaps = {
548                 {
549                         .type = ION_HEAP_TYPE_CARVEOUT,
550                         .id = ION_NOR_HEAP_ID,
551                         .name = "norheap",
552                         .size = ION_RESERVE_SIZE,
553                 }
554         },
555 };
556
557 static struct platform_device device_ion = {
558         .name = "ion-rockchip",
559         .id = 0,
560         .dev = {
561                 .platform_data = &rk30_ion_pdata,
562         },
563 };
564 #endif
565
566 /**************************************************************************************************
567  * SDMMC devices,  include the module of SD,MMC,and sdio.noted by xbw at 2012-03-05
568 **************************************************************************************************/
569 #ifdef CONFIG_SDMMC_RK29
570 #include "board-rk3168-ds1006h-sdmmc-config.c"
571 #include "../plat-rk/rk-sdmmc-ops.c"
572 #include "../plat-rk/rk-sdmmc-wifi.c"
573 #endif //endif ---#ifdef CONFIG_SDMMC_RK29
574
575 #ifdef CONFIG_SDMMC0_RK29
576 static int rk29_sdmmc0_cfg_gpio(void)
577 {
578 #ifdef CONFIG_SDMMC_RK29_OLD
579         iomux_set(MMC0_CMD);
580         iomux_set(MMC0_CLKOUT);
581         iomux_set(MMC0_D0);
582         iomux_set(MMC0_D1);
583         iomux_set(MMC0_D2);
584         iomux_set(MMC0_D3);
585
586         iomux_set_gpio_mode(iomux_mode_to_gpio(MMC0_DETN));
587
588         gpio_request(RK30_PIN3_PA7, "sdmmc-power");
589         gpio_direction_output(RK30_PIN3_PA7, GPIO_LOW);
590
591 #else
592         rk29_sdmmc_set_iomux(0, 0xFFFF);
593
594     #if defined(CONFIG_SDMMC0_RK29_SDCARD_DET_FROM_GPIO)
595         #if SDMMC_USE_NEW_IOMUX_API
596         iomux_set_gpio_mode(iomux_gpio_to_mode(RK29SDK_SD_CARD_DETECT_N));
597         #else
598         rk30_mux_api_set(RK29SDK_SD_CARD_DETECT_PIN_NAME, RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO);
599         #endif
600     #else
601         #if SDMMC_USE_NEW_IOMUX_API       
602         iomux_set(MMC0_DETN);
603         #else
604         rk30_mux_api_set(RK29SDK_SD_CARD_DETECT_PIN_NAME, RK29SDK_SD_CARD_DETECT_IOMUX_FMUX);
605         #endif
606     #endif      
607
608 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
609         gpio_request(SDMMC0_WRITE_PROTECT_PIN, "sdmmc-wp");
610         gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);
611 #endif
612
613 #endif
614
615         return 0;
616 }
617
618 #define CONFIG_SDMMC0_USE_DMA
619 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
620         .host_ocr_avail =
621             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
622              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
623              MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36),
624         .host_caps =
625             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
626         .io_init = rk29_sdmmc0_cfg_gpio,
627
628 #if !defined(CONFIG_SDMMC_RK29_OLD)
629         .set_iomux = rk29_sdmmc_set_iomux,
630 #endif
631
632         .dma_name = "sd_mmc",
633 #ifdef CONFIG_SDMMC0_USE_DMA
634         .use_dma = 1,
635 #else
636         .use_dma = 0,
637 #endif
638
639 #if defined(CONFIG_WIFI_COMBO_MODULE_CONTROL_FUNC) && defined(CONFIG_USE_SDMMC0_FOR_WIFI_DEVELOP_BOARD)
640     .status = rk29sdk_wifi_mmc0_status,
641     .register_status_notify = rk29sdk_wifi_mmc0_status_register,
642 #endif
643
644 #if defined(RK29SDK_SD_CARD_PWR_EN) || (INVALID_GPIO != RK29SDK_SD_CARD_PWR_EN)
645     .power_en = RK29SDK_SD_CARD_PWR_EN,
646     .power_en_level = RK29SDK_SD_CARD_PWR_EN_LEVEL,
647 #else
648     .power_en = INVALID_GPIO,
649     .power_en_level = GPIO_LOW,
650 #endif    
651         .enable_sd_wakeup = 0,
652
653 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
654         .write_prt = SDMMC0_WRITE_PROTECT_PIN,
655         .write_prt_enalbe_level = SDMMC0_WRITE_PROTECT_ENABLE_VALUE;
656 #else
657         .write_prt = INVALID_GPIO,
658 #endif
659
660     .det_pin_info = {    
661     #if defined(RK29SDK_SD_CARD_DETECT_N) || (INVALID_GPIO != RK29SDK_SD_CARD_DETECT_N)  
662         .io             = RK29SDK_SD_CARD_DETECT_N, //INVALID_GPIO,
663         .enable         = RK29SDK_SD_CARD_INSERT_LEVEL,
664         #ifdef RK29SDK_SD_CARD_DETECT_PIN_NAME
665         .iomux          = {
666             .name       = RK29SDK_SD_CARD_DETECT_PIN_NAME,
667             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO
668             .fgpio      = RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO,
669             #endif
670             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FMUX
671             .fmux       = RK29SDK_SD_CARD_DETECT_IOMUX_FMUX,
672             #endif
673         },
674         #endif
675     #else
676         .io             = INVALID_GPIO,
677         .enable         = GPIO_LOW,
678     #endif    
679     }, 
680
681 };
682 #endif // CONFIG_SDMMC0_RK29
683
684 #ifdef CONFIG_SDMMC1_RK29
685 #define CONFIG_SDMMC1_USE_DMA
686 static int rk29_sdmmc1_cfg_gpio(void)
687 {
688 #if defined(CONFIG_SDMMC_RK29_OLD)
689         iomux_set(MMC1_CMD);
690         iomux_set(MMC1_CLKOUT);
691         iomux_set(MMC1_D0);
692         iomux_set(MMC1_D1);
693         iomux_set(MMC1_D2);
694         iomux_set(MMC1_D3);
695 #else
696
697 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
698         gpio_request(SDMMC1_WRITE_PROTECT_PIN, "sdio-wp");
699         gpio_direction_input(SDMMC1_WRITE_PROTECT_PIN);
700 #endif
701
702 #endif
703
704         return 0;
705 }
706
707 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
708         .host_ocr_avail =
709             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
710              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
711              MMC_VDD_33_34),
712
713 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
714         .host_caps = (MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ |
715                       MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
716 #else
717         .host_caps =
718             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
719 #endif
720
721         .io_init = rk29_sdmmc1_cfg_gpio,
722
723 #if !defined(CONFIG_SDMMC_RK29_OLD)
724         .set_iomux = rk29_sdmmc_set_iomux,
725 #endif
726
727         .dma_name = "sdio",
728 #ifdef CONFIG_SDMMC1_USE_DMA
729         .use_dma = 1,
730 #else
731         .use_dma = 0,
732 #endif
733
734 #if defined(CONFIG_WIFI_CONTROL_FUNC) || defined(CONFIG_WIFI_COMBO_MODULE_CONTROL_FUNC)
735     .status = rk29sdk_wifi_status,
736     .register_status_notify = rk29sdk_wifi_status_register,
737 #endif
738
739 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
740         .write_prt = SDMMC1_WRITE_PROTECT_PIN,
741             .write_prt_enalbe_level = SDMMC1_WRITE_PROTECT_ENABLE_VALUE;
742 #else
743         .write_prt = INVALID_GPIO,
744 #endif
745
746     #if defined(CONFIG_RK29_SDIO_IRQ_FROM_GPIO)
747         .sdio_INT_gpio = RK29SDK_WIFI_SDIO_CARD_INT,
748     #endif
749
750     .det_pin_info = {    
751 #if defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
752      #if defined(RK29SDK_SD_CARD_DETECT_N) || (INVALID_GPIO != RK29SDK_SD_CARD_DETECT_N)  
753         .io             = RK29SDK_SD_CARD_DETECT_N,
754      #else
755          .io             = INVALID_GPIO,
756      #endif   
757
758         .enable         = RK29SDK_SD_CARD_INSERT_LEVEL,
759         #ifdef RK29SDK_SD_CARD_DETECT_PIN_NAME
760         .iomux          = {
761             .name       = RK29SDK_SD_CARD_DETECT_PIN_NAME,
762             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO
763             .fgpio      = RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO,
764             #endif
765             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FMUX
766             .fmux       = RK29SDK_SD_CARD_DETECT_IOMUX_FMUX,
767             #endif
768         },
769         #endif
770  #else
771         .io             = INVALID_GPIO,
772         .enable         = GPIO_LOW,
773 #endif
774     },
775    
776         .enable_sd_wakeup = 0,
777 };
778 #endif //endif--#ifdef CONFIG_SDMMC1_RK29
779
780 /**************************************************************************************************
781  * the end of setting for SDMMC devices
782 **************************************************************************************************/
783
784 #ifdef CONFIG_BATTERY_RK30_ADC_FAC
785 static struct rk30_adc_battery_platform_data rk30_adc_battery_platdata = {
786         .dc_det_pin      = RK30_PIN0_PB2,
787         .batt_low_pin    = INVALID_GPIO, 
788         .charge_set_pin  = INVALID_GPIO,
789         .charge_ok_pin   = RK30_PIN0_PA6,
790          .usb_det_pin = INVALID_GPIO,
791         .dc_det_level    = GPIO_LOW,
792         .charge_ok_level = GPIO_HIGH,
793
794         .reference_voltage = 1800, // the rK2928 is 3300;RK3066 and rk29 are 2500;rk3066B is 1800;
795        .pull_up_res = 200,     //divider resistance ,  pull-up resistor
796        .pull_down_res = 120, //divider resistance , pull-down resistor
797
798         .is_reboot_charging = 1,
799         .save_capacity   = 1 ,
800         .low_voltage_protection = 3600,    
801 };
802
803 static struct platform_device rk30_device_adc_battery = {
804         .name   = "rk30-battery",
805         .id     = -1,
806         .dev = {
807                 .platform_data = &rk30_adc_battery_platdata,
808         },
809 };
810 #endif
811 #ifdef CONFIG_RK30_PWM_REGULATOR
812 static int pwm_voltage_map[] = {
813         800000,825000,850000, 875000,900000, 925000 ,950000, 975000,1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000,1375000
814 };
815
816 static struct regulator_consumer_supply pwm_dcdc1_consumers[] = {
817         {
818                 .supply = "vdd_cpu",
819         }
820 };
821
822 struct regulator_init_data pwm_regulator_init_dcdc[1] =
823 {
824         {
825                 .constraints = {
826                         .name = "PWM_DCDC1",
827                         .min_uV = 600000,
828                         .max_uV = 1800000,      //0.6-1.8V
829                         .apply_uV = true,
830                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
831                 },
832                 .num_consumer_supplies = ARRAY_SIZE(pwm_dcdc1_consumers),
833                 .consumer_supplies = pwm_dcdc1_consumers,
834         },
835 };
836
837 static struct pwm_platform_data pwm_regulator_info[1] = {
838         {
839                 .pwm_id = 1,
840                 .pwm_gpio = RK30_PIN3_PD4,
841                 .pwm_iomux_pwm = PWM1,
842                 .pwm_iomux_gpio = GPIO3_D4,
843                 .pwm_voltage = 1100000,
844                 .suspend_voltage = 1000000,
845                 .min_uV = 800000,
846                 .max_uV = 1375000,
847                 .coefficient = 575,     //57.5%
848                 .pwm_voltage_map = pwm_voltage_map,
849                 .init_data      = &pwm_regulator_init_dcdc[0],
850         },
851 };
852
853 struct platform_device pwm_regulator_device[1] = {
854         {
855                 .name = "pwm-voltage-regulator",
856                 .id = 0,
857                 .dev            = {
858                         .platform_data = &pwm_regulator_info[0],
859                 }
860         },
861 };
862 #endif
863
864 #ifdef CONFIG_RFKILL_RK
865 // bluetooth rfkill device, its driver in net/rfkill/rfkill-rk.c
866 static struct rfkill_rk_platform_data rfkill_rk_platdata = {
867     .type               = RFKILL_TYPE_BLUETOOTH,
868
869     .poweron_gpio       = { // BT_REG_ON
870         .io             = INVALID_GPIO, //RK30_PIN3_PC7,
871         .enable         = GPIO_HIGH,
872         .iomux          = {
873             .name       = "bt_poweron",
874             .fgpio      = GPIO3_C7,
875         },
876     },
877
878     .reset_gpio         = { // BT_RST
879         .io             = RK30_PIN3_PD1, // set io to INVALID_GPIO for disable it
880         .enable         = GPIO_LOW,
881         .iomux          = {
882             .name       = "bt_reset",
883             .fgpio      = GPIO3_D1,
884        },
885    }, 
886
887     .wake_gpio          = { // BT_WAKE, use to control bt's sleep and wakeup
888         .io             = RK30_PIN3_PC6, // set io to INVALID_GPIO for disable it
889         .enable         = GPIO_HIGH,
890         .iomux          = {
891             .name       = "bt_wake",
892             .fgpio      = GPIO3_C6,
893         },
894     },
895
896     .wake_host_irq      = { // BT_HOST_WAKE, for bt wakeup host when it is in deep sleep
897         .gpio           = {
898             .io         = RK30_PIN0_PA5, // set io to INVALID_GPIO for disable it
899             .enable     = GPIO_LOW,      // set GPIO_LOW for falling, set 0 for rising
900             .iomux      = {
901                 .name   = NULL,
902             },
903         },
904     },
905
906     .rts_gpio           = { // UART_RTS, enable or disable BT's data coming
907         .io             = RK30_PIN1_PA3, // set io to INVALID_GPIO for disable it
908         .enable         = GPIO_LOW,
909         .iomux          = {
910             .name       = "bt_rts",
911             .fgpio      = GPIO1_A3,
912             .fmux       = UART0_RTSN,
913         },
914     },
915 };
916
917 static struct platform_device device_rfkill_rk = {
918     .name   = "rfkill_rk",
919     .id     = -1,
920     .dev    = {
921         .platform_data = &rfkill_rk_platdata,
922     },
923 };
924 #endif
925
926 #if defined(CONFIG_GPS_RK)
927 int rk_gps_io_init(void)
928 {
929         printk("%s \n", __FUNCTION__);
930         
931         rk30_mux_api_set(GPIO1B5_UART3RTSN_NAME, GPIO1B_GPIO1B5);//VCC_EN
932         gpio_request(RK30_PIN1_PB5, NULL);
933         gpio_direction_output(RK30_PIN1_PB5, GPIO_LOW);
934
935         rk30_mux_api_set(GPIO1B4_UART3CTSN_GPSRFCLK_NAME, GPIO1B_GPSRFCLK);//GPS_CLK
936         rk30_mux_api_set(GPIO1B2_UART3SIN_GPSMAG_NAME, GPIO1B_GPSMAG);//GPS_MAG
937         rk30_mux_api_set(GPIO1B3_UART3SOUT_GPSSIG_NAME, GPIO1B_GPSSIG);//GPS_SIGN
938
939         rk30_mux_api_set(GPIO1A6_UART1CTSN_SPI0CLK_NAME, GPIO1A_GPIO1A6);//SPI_CLK
940         gpio_request(RK30_PIN1_PA6, NULL);
941         gpio_direction_output(RK30_PIN1_PA6, GPIO_LOW);
942
943         rk30_mux_api_set(GPIO1A5_UART1SOUT_SPI0TXD_NAME, GPIO1A_GPIO1A5);//SPI_MOSI
944         gpio_request(RK30_PIN1_PA5, NULL);
945         gpio_direction_output(RK30_PIN1_PA5, GPIO_LOW); 
946
947         rk30_mux_api_set(GPIO1A7_UART1RTSN_SPI0CSN0_NAME, GPIO1A_GPIO1A7);//SPI_CS
948         gpio_request(RK30_PIN1_PA7, NULL);
949         gpio_direction_output(RK30_PIN1_PA7, GPIO_LOW);         
950         return 0;
951 }
952 int rk_gps_power_up(void)
953 {
954         printk("%s \n", __FUNCTION__);
955
956         return 0;
957 }
958
959 int rk_gps_power_down(void)
960 {
961         printk("%s \n", __FUNCTION__);
962
963         return 0;
964 }
965
966 int rk_gps_reset_set(int level)
967 {
968         return 0;
969 }
970 int rk_enable_hclk_gps(void)
971 {
972         printk("%s \n", __FUNCTION__);
973         clk_enable(clk_get(NULL, "hclk_gps"));
974         return 0;
975 }
976 int rk_disable_hclk_gps(void)
977 {
978         printk("%s \n", __FUNCTION__);
979         clk_disable(clk_get(NULL, "hclk_gps"));
980         return 0;
981 }
982 struct rk_gps_data rk_gps_info = {
983         .io_init = rk_gps_io_init,
984         .power_up = rk_gps_power_up,
985         .power_down = rk_gps_power_down,
986         .reset = rk_gps_reset_set,
987         .enable_hclk_gps = rk_enable_hclk_gps,
988         .disable_hclk_gps = rk_disable_hclk_gps,
989         .GpsSign = RK30_PIN1_PB3,
990         .GpsMag = RK30_PIN1_PB2,        //GPIO index
991         .GpsClk = RK30_PIN1_PB4,        //GPIO index
992         .GpsVCCEn = RK30_PIN1_PB5,     //GPIO index
993         .GpsSpi_CSO = RK30_PIN1_PA4,    //GPIO index
994         .GpsSpiClk = RK30_PIN1_PA5,     //GPIO index
995         .GpsSpiMOSI = RK30_PIN1_PA7,      //GPIO index
996         .GpsIrq = IRQ_GPS,
997         .GpsSpiEn = 0,
998         .GpsAdcCh = 2,
999         .u32GpsPhyAddr = RK30_GPS_PHYS,
1000         .u32GpsPhySize = RK30_GPS_SIZE,
1001 };
1002
1003 struct platform_device rk_device_gps = {
1004         .name = "gps_hv5820b",
1005         .id = -1,
1006         .dev            = {
1007         .platform_data = &rk_gps_info,
1008                 }
1009         };
1010 #endif
1011
1012 #if defined(CONFIG_MT5931_MT6622)
1013 static struct mt6622_platform_data mt6622_platdata = {
1014                     .power_gpio         = { // BT_REG_ON
1015                         .io             = RK30_PIN3_PD5, // set io to INVALID_GPIO for disable it
1016                             .enable         = GPIO_HIGH,
1017                             .iomux          = {
1018                                     .name       = NULL,
1019                                 },
1020                     },
1021
1022                     .reset_gpio         = { // BT_RST
1023                         .io             = RK30_PIN0_PD7,
1024                         .enable         = GPIO_HIGH,
1025                         .iomux          = {
1026                             .name       = NULL,
1027                         },
1028                     },
1029
1030                     .irq_gpio           = {
1031                             .io             = RK30_PIN3_PD2,
1032                             .enable         = GPIO_HIGH,
1033                             .iomux          = {
1034                                     .name       = NULL,
1035                                 },
1036                     }
1037 };
1038
1039 static struct platform_device device_mt6622 = {
1040                     .name   = "mt6622",
1041                         .id     = -1,
1042                         .dev    = {
1043                                .platform_data = &mt6622_platdata,
1044                         },
1045 };      
1046 #endif
1047
1048 static struct platform_device *devices[] __initdata = {
1049
1050 #ifdef CONFIG_ION
1051         &device_ion,
1052 #endif
1053 #ifdef CONFIG_WIFI_CONTROL_FUNC
1054         &rk29sdk_wifi_device,
1055 #endif
1056
1057 #if defined(CONFIG_MT6620)
1058             &mt3326_device_gps,
1059 #endif
1060
1061 #ifdef CONFIG_BATTERY_RK30_ADC_FAC
1062         &rk30_device_adc_battery,
1063 #endif
1064 #ifdef CONFIG_RFKILL_RK
1065         &device_rfkill_rk,
1066 #endif
1067 #ifdef CONFIG_GPS_RK
1068         &rk_device_gps,
1069 #endif
1070 #ifdef CONFIG_MT5931_MT6622
1071         &device_mt6622,
1072 #endif
1073 };
1074
1075
1076 static int rk_platform_add_display_devices(void)
1077 {
1078         struct platform_device *fb = NULL;  //fb
1079         struct platform_device *lcdc0 = NULL; //lcdc0
1080         struct platform_device *lcdc1 = NULL; //lcdc1
1081         struct platform_device *bl = NULL; //backlight
1082 #ifdef CONFIG_FB_ROCKCHIP
1083         fb = &device_fb;
1084 #endif
1085
1086 #if defined(CONFIG_LCDC0_RK3066B)
1087         lcdc0 = &device_lcdc0,
1088 #endif
1089
1090 #if defined(CONFIG_LCDC1_RK3066B)
1091         lcdc1 = &device_lcdc1,
1092 #endif
1093
1094 #ifdef CONFIG_BACKLIGHT_RK29_BL
1095         bl = &rk29_device_backlight,
1096 #endif
1097         __rk_platform_add_display_devices(fb,lcdc0,lcdc1,bl);
1098
1099         return 0;
1100         
1101 }
1102
1103 // i2c
1104 #ifdef CONFIG_I2C0_RK30
1105 static struct i2c_board_info __initdata i2c0_info[] = {
1106 #if defined (CONFIG_GS_MMA8452)
1107         {
1108                 .type           = "gs_mma8452",
1109                 .addr           = 0x1d,
1110                 .flags          = 0,
1111                 .irq            = MMA8452_INT_PIN,
1112                 .platform_data = &mma8452_info,
1113         },
1114 #endif
1115 #if defined (CONFIG_GS_LIS3DH)
1116         {
1117                 .type           = "gs_lis3dh",
1118                 .addr           = 0x19,   //0x19(SA0-->VCC), 0x18(SA0-->GND)
1119                 .flags          = 0,
1120                 .irq            = LIS3DH_INT_PIN,
1121                 .platform_data = &lis3dh_info,
1122         },
1123 #endif
1124 #if defined (CONFIG_COMPASS_AK8975)
1125         {
1126                 .type          = "ak8975",
1127                 .addr          = 0x0d,
1128                 .flags         = 0,
1129                 .irq           = RK30_PIN3_PD7, 
1130                 .platform_data = &akm8975_info,
1131                 .irq           = RK30_PIN3_PD7, 
1132                 .platform_data = &akm8975_info,
1133         },
1134 #endif
1135 #if defined (CONFIG_GYRO_L3G4200D)
1136         {
1137                 .type          = "l3g4200d_gryo",
1138                 .addr          = 0x69,
1139                 .flags         = 0,
1140                 .irq           = L3G4200D_INT_PIN,
1141                 .platform_data = &l3g4200d_info,
1142         },
1143 #endif
1144 #if defined (CONFIG_SND_SOC_RK1000)
1145         {
1146                 .type          = "rk1000_i2c_codec",
1147                 .addr          = 0x60,
1148                 .flags         = 0,
1149         },
1150         {
1151                 .type          = "rk1000_control",
1152                 .addr          = 0x40,
1153                 .flags         = 0,
1154         },
1155 #endif
1156 #if defined (CONFIG_SND_SOC_RT5631)
1157         {
1158                 .type                   = "rt5631",
1159                 .addr                   = 0x1a,
1160                 .flags                  = 0,
1161         },
1162 #endif
1163 };
1164 #endif
1165
1166 int __sramdata g_pmic_type =  0;
1167 #ifdef CONFIG_I2C1_RK30
1168 #ifdef CONFIG_REGULATOR_ACT8846
1169 #define PMU_POWER_SLEEP RK30_PIN0_PA1
1170 #define ACT8846_HOST_IRQ                RK30_PIN0_PB3
1171
1172 static struct pmu_info  act8846_dcdc_info[] = {
1173         {
1174                 .name          = "act_dcdc1",   //ddr
1175                 .min_uv          = 1200000,
1176                 .max_uv         = 1200000,
1177                 .suspend_vol  =   1200000,
1178         },
1179         {
1180                 .name          = "vdd_core",    //logic
1181                 .min_uv          = 1000000,
1182                 .max_uv         = 1000000,
1183                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1184                 .suspend_vol  =  1200000,
1185                 #else
1186                 .suspend_vol  =  900000,
1187                 #endif
1188         },
1189         {
1190                 .name          = "vdd_cpu",   //arm
1191                 .min_uv          = 1000000,
1192                 .max_uv         = 1000000,
1193                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1194                 .suspend_vol  =  1200000,
1195                 #else
1196                 .suspend_vol  =  900000,
1197                 #endif
1198         },
1199         {
1200                 .name          = "act_dcdc4",   //vccio
1201                 .min_uv          = 3000000,
1202                 .max_uv         = 3000000,
1203                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1204                 .suspend_vol  =  3000000,
1205                 #else
1206                 .suspend_vol  =  2800000,
1207                 #endif
1208         },
1209         
1210 };
1211 static  struct pmu_info  act8846_ldo_info[] = {
1212         {
1213                 .name          = "act_ldo1",   //vdd10
1214                 .min_uv          = 1000000,
1215                 .max_uv         = 1000000,
1216         },
1217         {
1218                 .name          = "act_ldo2",    //vdd12
1219                 .min_uv          = 1200000,
1220                 .max_uv         = 1200000,
1221         },
1222         {
1223                 .name          = "act_ldo3",   //vcc18_cif
1224                 .min_uv          = 1800000,
1225                 .max_uv         = 1800000,
1226         },
1227         {
1228                 .name          = "act_ldo4",   //vcca33
1229                 .min_uv          = 3300000,
1230                 .max_uv         = 3300000,
1231         },
1232         {
1233                 .name          = "act_ldo5",   //vcctp
1234                 .min_uv          = 3300000,
1235                 .max_uv         = 3300000,
1236         },
1237         {
1238                 .name          = "act_ldo6",   //vcc_jetta
1239                 .min_uv          = 3300000,
1240                 .max_uv         = 3300000,
1241         },
1242         {
1243                 .name          = "act_ldo7",   //vcc18
1244                 .min_uv          = 1800000,
1245                 .max_uv         = 1800000,
1246         },
1247         {
1248                 .name          = "act_ldo8",   //vcc28_cif
1249                 .min_uv          = 2800000,
1250                 .max_uv         = 2800000,
1251         },
1252  };
1253
1254 #include "board-pmu-act8846.c"
1255 #endif
1256
1257 #ifdef CONFIG_MFD_WM831X_I2C
1258 #define PMU_POWER_SLEEP                 RK30_PIN0_PA1 
1259
1260 static struct pmu_info  wm8326_dcdc_info[] = {
1261         {
1262                 .name          = "vdd_core",   //logic
1263                 .min_uv          = 1000000,
1264                 .max_uv         = 1000000,
1265                 .suspend_vol  =  950000,
1266         },
1267         {
1268                 .name          = "vdd_cpu",    //arm
1269                 .min_uv          = 1000000,
1270                 .max_uv         = 1000000,
1271                 .suspend_vol  =  950000,
1272         },
1273         {
1274                 .name          = "dcdc3",   //ddr
1275                 .min_uv          = 1150000,
1276                 .max_uv         = 1150000,
1277                 .suspend_vol  =  1150000,
1278         },
1279         #ifdef CONFIG_MACH_RK3066_SDK
1280         {
1281                 .name          = "dcdc4",   //vcc_io
1282                 .min_uv          = 3300000,
1283                 .max_uv         = 3300000,
1284                 .suspend_vol  =  3000000,
1285         },
1286         #else
1287         {
1288                 .name          = "dcdc4",   //vcc_io
1289                 .min_uv          = 3000000,
1290                 .max_uv         = 3000000,
1291                 .suspend_vol  =  2800000,
1292         },
1293         #endif
1294 };
1295
1296 static struct pmu_info  wm8326_ldo_info[] = {
1297         {
1298                 .name          = "ldo1",   //vcc18_cif
1299                 .min_uv          = 1800000,
1300                 .max_uv         = 1800000,
1301                 .suspend_vol  =  1800000,
1302         },
1303         {
1304                 .name          = "ldo2",    //vccio_wl
1305                 .min_uv          = 1800000,
1306                 .max_uv         = 1800000,
1307                 .suspend_vol  =  1800000,
1308         },
1309         {
1310                 .name          = "ldo3",   //
1311                 .min_uv          = 1100000,
1312                 .max_uv         = 1100000,
1313                 .suspend_vol  =  1100000,
1314         },
1315         {
1316                 .name          = "ldo4",   //vdd11
1317                 .min_uv          = 1000000,
1318                 .max_uv         = 1000000,
1319                 .suspend_vol  =  1000000,
1320         },
1321         {
1322                 .name          = "ldo5",   //vcc25
1323                 .min_uv          = 1800000,
1324                 .max_uv         = 1800000,
1325                 .suspend_vol  =  1800000,
1326         },
1327         {
1328                 .name          = "ldo6",   //vcc33
1329                 .min_uv          = 3300000,
1330                 .max_uv         = 3300000,
1331                 .suspend_vol  =  3300000,
1332         },
1333         {
1334                 .name          = "ldo7",   //vcc28_cif
1335                 .min_uv          = 2800000,
1336                 .max_uv         = 2800000,
1337                 .suspend_vol  =  2800000,
1338         },
1339         {
1340                 .name          = "ldo8",   //vcca33
1341                 .min_uv          = 3300000,
1342                 .max_uv         = 3300000,
1343                 .suspend_vol  =  3300000,
1344         },
1345         {
1346                 .name          = "ldo9",   //vcc_tp
1347                 .min_uv          = 3300000,
1348                 .max_uv         = 3300000,
1349                 .suspend_vol  =  3300000,
1350         },
1351         {
1352                 .name          = "ldo10",   //flash_io
1353                 .min_uv          = 1800000,
1354                 .max_uv         = 1800000,
1355                 .suspend_vol  =  1800000,
1356         },
1357 };
1358
1359 #include "board-pmu-wm8326.c"
1360 #endif
1361
1362 #ifdef CONFIG_MFD_TPS65910
1363 #ifdef CONFIG_ARCH_RK3066B
1364 #define TPS65910_HOST_IRQ        RK30_PIN0_PB3
1365 #else
1366 #define TPS65910_HOST_IRQ        RK30_PIN6_PA4
1367 #endif
1368
1369 #define PMU_POWER_SLEEP RK30_PIN0_PA1
1370
1371 static struct pmu_info  tps65910_dcdc_info[] = {
1372         {
1373                 .name          = "vdd_core",   //logic
1374                 .min_uv          = 1100000,
1375                 .max_uv         = 1100000,
1376         },
1377         {
1378                 .name          = "vdd2",    //ddr
1379                 .min_uv          = 1200000,
1380                 .max_uv         = 1200000,
1381         },
1382         {
1383                 .name          = "vio",   //vcc_io
1384                 .min_uv          = 2500000,
1385                 .max_uv         = 2500000,
1386         },
1387         
1388 };
1389 static  struct pmu_info  tps65910_ldo_info[] = {
1390         {
1391                 .name          = "vpll",   //vdd10
1392                 .min_uv          = 1000000,
1393                 .max_uv         = 1000000,
1394         },
1395         {
1396                 .name          = "vdig1",    //vcc18_cif
1397                 .min_uv          = 1800000,
1398                 .max_uv         = 1800000,
1399         },
1400         {
1401                 .name          = "vdig2",   //vdd_jetta
1402                 .min_uv          = 1200000,
1403                 .max_uv         = 1200000,
1404         },
1405         {
1406                 .name          = "vaux1",   //vcc28_cif
1407                 .min_uv          = 2800000,
1408                 .max_uv         = 2800000,
1409         },
1410         {
1411                 .name          = "vaux2",   //vcca33
1412                 .min_uv          = 3300000,
1413                 .max_uv         = 3300000,
1414         },
1415         {
1416                 .name          = "vaux33",   //vcc_tp
1417                 .min_uv          = 3300000,
1418                 .max_uv         = 3300000,
1419         },
1420         {
1421                 .name          = "vmmc",   //vcc30
1422                 .min_uv          = 3000000,
1423                 .max_uv         = 3000000,
1424         },
1425         {
1426                 .name          = "vdac",   //vcc18
1427                 .min_uv          = 1800000,
1428                 .max_uv         = 1800000,
1429         },
1430  };
1431
1432 #include "board-pmu-tps65910.c"
1433 #endif
1434
1435 static struct i2c_board_info __initdata i2c1_info[] = {
1436 #if defined (CONFIG_REGULATOR_ACT8846)
1437         {
1438                 .type                   = "act8846",
1439                 .addr           = 0x5a, 
1440                 .flags                  = 0,
1441                 .irq            = ACT8846_HOST_IRQ,
1442                 .platform_data=&act8846_data,
1443         },
1444 #endif
1445 #if defined (CONFIG_RTC_HYM8563)
1446         {
1447                 .type                   = "rtc_hym8563",
1448                 .addr           = 0x51,
1449                 .flags                  = 0,
1450                 .irq            = RK30_PIN0_PB5,
1451         },
1452 #endif
1453 #if defined (CONFIG_MFD_WM831X_I2C)
1454         {
1455                 .type          = "wm8326",
1456                 .addr          = 0x34,
1457                 .flags         = 0,
1458                 .irq           = RK30_PIN0_PB3,
1459                 .platform_data = &wm831x_platdata,
1460         },
1461 #endif
1462 #if defined (CONFIG_MFD_TPS65910)
1463         {
1464         .type           = "tps65910",
1465         .addr           = TPS65910_I2C_ID0,
1466         .flags          = 0,
1467         .irq            = TPS65910_HOST_IRQ,
1468         .platform_data = &tps65910_data,
1469         },
1470 #endif
1471 };
1472 #endif
1473
1474 void __sramfunc board_pmu_suspend(void)
1475 {      
1476         #if defined (CONFIG_REGULATOR_ACT8846)
1477        if(pmic_is_act8846())
1478        board_pmu_act8846_suspend(); 
1479        #endif
1480         #if defined (CONFIG_MFD_WM831X_I2C)
1481        if(pmic_is_wm8326())
1482        board_pmu_wm8326_suspend();
1483         #endif
1484         #if defined (CONFIG_MFD_TPS65910)
1485        if(pmic_is_tps65910())
1486        board_pmu_tps65910_suspend(); 
1487     #endif   
1488 }
1489
1490 void __sramfunc board_pmu_resume(void)
1491 {      
1492         #if defined (CONFIG_REGULATOR_ACT8846)
1493        if(pmic_is_act8846())
1494        board_pmu_act8846_resume(); 
1495        #endif
1496         #if defined (CONFIG_MFD_WM831X_I2C)
1497        if(pmic_is_wm8326())
1498        board_pmu_wm8326_resume();
1499         #endif
1500         #if defined (CONFIG_MFD_TPS65910)
1501        if(pmic_is_tps65910())
1502        board_pmu_tps65910_resume(); 
1503         #endif
1504 }
1505
1506  int __sramdata gpio3d6_iomux,gpio3d6_do,gpio3d6_dir,gpio3d6_en;
1507
1508 #define grf_readl(offset)       readl_relaxed(RK30_GRF_BASE + offset)
1509 #define grf_writel(v, offset)   do { writel_relaxed(v, RK30_GRF_BASE + offset); dsb(); } while (0)
1510  
1511 void __sramfunc rk30_pwm_logic_suspend_voltage(void)
1512 {
1513 #ifdef CONFIG_RK30_PWM_REGULATOR
1514
1515 //      int gpio0d7_iomux,gpio0d7_do,gpio0d7_dir,gpio0d7_en;
1516         sram_udelay(10000);
1517         gpio3d6_iomux = grf_readl(GRF_GPIO3D_IOMUX);
1518         gpio3d6_do = grf_readl(GRF_GPIO3H_DO);
1519         gpio3d6_dir = grf_readl(GRF_GPIO3H_DIR);
1520         gpio3d6_en = grf_readl(GRF_GPIO3H_EN);
1521
1522         grf_writel((1<<28), GRF_GPIO3D_IOMUX);
1523         grf_writel((1<<30)|(1<<14), GRF_GPIO3H_DIR);
1524         grf_writel((1<<30)|(1<<14), GRF_GPIO3H_DO);
1525         grf_writel((1<<30)|(1<<14), GRF_GPIO3H_EN);
1526 #endif 
1527 }
1528 void __sramfunc rk30_pwm_logic_resume_voltage(void)
1529 {
1530 #ifdef CONFIG_RK30_PWM_REGULATOR
1531         grf_writel((1<<28)|gpio3d6_iomux, GRF_GPIO3D_IOMUX);
1532         grf_writel((1<<30)|gpio3d6_en, GRF_GPIO3H_EN);
1533         grf_writel((1<<30)|gpio3d6_dir, GRF_GPIO3H_DIR);
1534         grf_writel((1<<30)|gpio3d6_do, GRF_GPIO3H_DO);
1535         sram_udelay(10000);
1536
1537 #endif
1538
1539 }
1540 extern void pwm_suspend_voltage(void);
1541 extern void pwm_resume_voltage(void);
1542 void  rk30_pwm_suspend_voltage_set(void)
1543 {
1544 #ifdef CONFIG_RK30_PWM_REGULATOR
1545         pwm_suspend_voltage();
1546 #endif
1547 }
1548 void  rk30_pwm_resume_voltage_set(void)
1549 {
1550 #ifdef CONFIG_RK30_PWM_REGULATOR
1551         pwm_resume_voltage();
1552 #endif
1553 }
1554
1555
1556 #ifdef CONFIG_I2C2_RK30
1557 static struct i2c_board_info __initdata i2c2_info[] = {
1558 #if defined (CONFIG_CT36X_TS)
1559         {
1560                 .type          = CT36X_NAME,
1561                 .addr          = 0x01,
1562                 .flags         = 0,
1563                 .platform_data = &ct36x_info,
1564         },
1565 #endif
1566 #if defined (CONFIG_LS_CM3217)
1567         {
1568                 .type          = "lightsensor",
1569                 .addr          = 0x10,
1570                 .flags         = 0,
1571                 .platform_data = &cm3217_info,
1572         },
1573 #endif
1574 };
1575 #endif
1576
1577 #ifdef CONFIG_I2C3_RK30
1578 static struct i2c_board_info __initdata i2c3_info[] = {
1579 };
1580 #endif
1581
1582 #ifdef CONFIG_I2C4_RK30
1583 static struct i2c_board_info __initdata i2c4_info[] = {
1584 #ifdef CONFIG_MFD_RK610
1585                 {
1586                         .type                   = "rk610_ctl",
1587                         .addr                   = 0x40,
1588                         .flags                  = 0,
1589                         .platform_data          = &rk610_ctl_pdata,
1590                 },
1591 #ifdef CONFIG_RK610_TVOUT
1592                 {
1593                         .type                   = "rk610_tvout",
1594                         .addr                   = 0x42,
1595                         .flags                  = 0,
1596                 },
1597 #endif
1598 #ifdef CONFIG_HDMI_RK610
1599                 {
1600                         .type                   = "rk610_hdmi",
1601                         .addr                   = 0x46,
1602                         .flags                  = 0,
1603                         .irq                    = INVALID_GPIO,
1604                 },
1605 #endif
1606 #ifdef CONFIG_SND_SOC_RK610
1607                 {//RK610_CODEC addr  from 0x60 to 0x80 (0x60~0x80)
1608                         .type                   = "rk610_i2c_codec",
1609                         .addr                   = 0x60,
1610                         .flags                  = 0,
1611                         .platform_data          = &rk610_codec_pdata,                   
1612                 },
1613 #endif
1614 #endif
1615
1616 };
1617 #endif
1618
1619 #ifdef CONFIG_I2C_GPIO_RK30
1620 #define I2C_SDA_PIN     INVALID_GPIO// RK30_PIN2_PD6   //set sda_pin here
1621 #define I2C_SCL_PIN     INVALID_GPIO//RK30_PIN2_PD7   //set scl_pin here
1622 static int rk30_i2c_io_init(void)
1623 {
1624         //set iomux (gpio) here
1625         //rk30_mux_api_set(GPIO2D7_I2C1SCL_NAME, GPIO2D_GPIO2D7);
1626         //rk30_mux_api_set(GPIO2D6_I2C1SDA_NAME, GPIO2D_GPIO2D6);
1627
1628         return 0;
1629 }
1630 struct i2c_gpio_platform_data default_i2c_gpio_data = {
1631        .sda_pin = I2C_SDA_PIN,
1632        .scl_pin = I2C_SCL_PIN,
1633        .udelay = 5, // clk = 500/udelay = 100Khz
1634        .timeout = 100,//msecs_to_jiffies(100),
1635        .bus_num    = 5,
1636        .io_init = rk30_i2c_io_init,
1637 };
1638 static struct i2c_board_info __initdata i2c_gpio_info[] = {
1639 };
1640 #endif
1641
1642 static void __init rk30_i2c_register_board_info(void)
1643 {
1644 #ifdef CONFIG_I2C0_RK30
1645         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
1646 #endif
1647 #ifdef CONFIG_I2C1_RK30
1648         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
1649 #endif
1650 #ifdef CONFIG_I2C2_RK30
1651         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
1652 #endif
1653 #ifdef CONFIG_I2C3_RK30
1654         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
1655 #endif
1656 #ifdef CONFIG_I2C4_RK30
1657         i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info));
1658 #endif
1659 #ifdef CONFIG_I2C_GPIO_RK30
1660         i2c_register_board_info(5, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info));
1661 #endif
1662 }
1663 //end of i2c
1664
1665 #define POWER_ON_PIN RK30_PIN0_PA0   //power_hold
1666 static void rk30_pm_power_off(void)
1667 {
1668         printk(KERN_ERR "rk30_pm_power_off start...\n");
1669         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
1670 #if defined(CONFIG_MFD_WM831X)
1671         wm831x_set_bits(Wm831x,WM831X_GPIO_LEVEL,0x0001,0x0000);  //set sys_pwr 0
1672         wm831x_device_shutdown(Wm831x);//wm8326 shutdown
1673 #endif
1674 #if defined(CONFIG_REGULATOR_ACT8846)
1675        if (pmic_is_act8846()) {
1676                printk("enter dcdet===========\n");
1677                if(gpio_get_value (RK30_PIN0_PB2) == GPIO_LOW)
1678                {
1679                        printk("enter restart===========\n");
1680                        arm_pm_restart(0, NULL);
1681                }
1682                //act8931_device_shutdown();
1683        }
1684 #endif
1685         while (1);
1686 }
1687
1688 static void __init machine_rk30_board_init(void)
1689 {
1690         //avs_init();
1691         gpio_request(POWER_ON_PIN, "poweronpin");
1692         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
1693         
1694         pm_power_off = rk30_pm_power_off;
1695         
1696         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
1697
1698
1699         rk30_i2c_register_board_info();
1700         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1701         platform_add_devices(devices, ARRAY_SIZE(devices));
1702         rk_platform_add_display_devices();
1703         board_usb_detect_init(RK30_PIN0_PA7);
1704
1705 #ifdef CONFIG_WIFI_CONTROL_FUNC
1706         rk29sdk_wifi_bt_gpio_control_init();
1707 #endif
1708
1709 #if defined(CONFIG_MT6620)
1710             clk_set_rate(clk_get_sys("rk_serial.1", "uart"), 48*1000000);
1711 #endif
1712
1713 #if defined(CONFIG_MT5931_MT6622)
1714                 clk_set_rate(clk_get_sys("rk_serial.0", "uart"), 24*1000000);
1715 #endif          
1716 }
1717
1718 static void __init rk30_reserve(void)
1719 {
1720 #ifdef CONFIG_ION
1721         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion", ION_RESERVE_SIZE);
1722 #endif
1723
1724 #ifdef CONFIG_FB_ROCKCHIP
1725         resource_fb[0].start = board_mem_reserve_add("fb0 buf", get_fb_size());
1726         resource_fb[0].end = resource_fb[0].start + get_fb_size()- 1;
1727 #if 0
1728         resource_fb[1].start = board_mem_reserve_add("ipp buf", RK30_FB0_MEM_SIZE);
1729         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
1730 #endif
1731
1732 #if defined(CONFIG_FB_ROTATE) || !defined(CONFIG_THREE_FB_BUFFER)
1733         resource_fb[2].start = board_mem_reserve_add("fb2 buf",get_fb_size());
1734         resource_fb[2].end = resource_fb[2].start + get_fb_size() - 1;
1735 #endif
1736 #endif
1737
1738
1739 #ifdef CONFIG_VIDEO_RK29
1740         rk30_camera_request_reserve_mem();
1741 #endif
1742         
1743 #ifdef CONFIG_GPS_RK
1744         //it must be more than 8MB
1745         rk_gps_info.u32MemoryPhyAddr = board_mem_reserve_add("gps", SZ_8M);
1746 #endif
1747         board_mem_reserved();
1748 }
1749
1750 /**
1751  * dvfs_cpu_logic_table: table for arm and logic dvfs 
1752  * @frequency   : arm frequency
1753  * @cpu_volt    : arm voltage depend on frequency
1754  * @logic_volt  : logic voltage arm requests depend on frequency
1755  * comments     : min arm/logic voltage
1756  */
1757 static struct cpufreq_frequency_table dvfs_arm_table[] = {
1758         {.frequency = 312 * 1000,       .index = 850 * 1000},
1759         {.frequency = 504 * 1000,       .index = 900 * 1000},
1760         {.frequency = 816 * 1000,       .index = 950 * 1000},
1761         {.frequency = 1008 * 1000,      .index = 1025 * 1000},
1762         {.frequency = 1200 * 1000,      .index = 1100 * 1000},
1763         {.frequency = 1416 * 1000,      .index = 1200 * 1000},
1764         //{.frequency = 1608 * 1000,      .index = 1300 * 1000},
1765         {.frequency = CPUFREQ_TABLE_END},
1766 };
1767
1768 static struct cpufreq_frequency_table dvfs_gpu_table[] = {
1769         {.frequency = 100 * 1000,       .index = 950 * 1000},
1770         {.frequency = 200 * 1000,       .index = 975 * 1000},
1771         {.frequency = 266 * 1000,       .index = 1000 * 1000},
1772         {.frequency = 300 * 1000,       .index = 1050 * 1000},
1773         {.frequency = 400 * 1000,       .index = 1100 * 1000},
1774         //{.frequency = 600 * 1000,     .index = 1200 * 1000},
1775         {.frequency = CPUFREQ_TABLE_END},
1776 };
1777
1778 static struct cpufreq_frequency_table dvfs_ddr_table[] = {
1779         {.frequency = 200 * 1000 + DDR_FREQ_SUSPEND,    .index = 950 * 1000},
1780         {.frequency = 300 * 1000 + DDR_FREQ_VIDEO,      .index = 1000 * 1000},
1781         {.frequency = 400 * 1000 + DDR_FREQ_NORMAL,     .index = 1100 * 1000},
1782         {.frequency = CPUFREQ_TABLE_END},
1783 };
1784
1785 //#define DVFS_CPU_TABLE_SIZE   (ARRAY_SIZE(dvfs_cpu_logic_table))
1786 //static struct cpufreq_frequency_table cpu_dvfs_table[DVFS_CPU_TABLE_SIZE];
1787 //static struct cpufreq_frequency_table dep_cpu2core_table[DVFS_CPU_TABLE_SIZE];
1788
1789 void __init board_clock_init(void)
1790 {
1791         rk30_clock_data_init(periph_pll_default, codec_pll_default, RK30_CLOCKS_DEFAULT_FLAGS);
1792         //dvfs_set_arm_logic_volt(dvfs_cpu_logic_table, cpu_dvfs_table, dep_cpu2core_table);
1793         dvfs_set_freq_volt_table(clk_get(NULL, "cpu"), dvfs_arm_table);
1794         dvfs_set_freq_volt_table(clk_get(NULL, "gpu"), dvfs_gpu_table);
1795         dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
1796 }
1797
1798 MACHINE_START(RK30, "RK30board")
1799         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
1800         .fixup          = rk30_fixup,
1801         .reserve        = &rk30_reserve,
1802         .map_io         = rk30_map_io,
1803         .init_irq       = rk30_init_irq,
1804         .timer          = &rk30_timer,
1805         .init_machine   = machine_rk30_board_init,
1806 MACHINE_END