rk3026: rk3028a_tb: wifi support
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk3026 / board-rk3028a-tb.c
1 /*
2  * Copyright (C) 2013 ROCKCHIP, Inc.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/input.h>
19 #include <linux/io.h>
20 #include <linux/delay.h>
21 #include <linux/i2c.h>
22 #include <linux/skbuff.h>
23 #include <linux/spi/spi.h>
24 #include <linux/mmc/host.h>
25 #include <linux/ion.h>
26 #include <linux/cpufreq.h>
27 #include <linux/clk.h>
28 #include <linux/rk_fb.h>
29 #include <linux/regulator/machine.h>
30 #include <linux/rfkill-rk.h>
31 #include <linux/sensor-dev.h>
32 #include <linux/mfd/tps65910.h>
33 #include <linux/regulator/act8846.h>
34 #include <linux/regulator/rk29-pwm-regulator.h>
35
36 #include <asm/setup.h>
37 #include <asm/mach-types.h>
38 #include <asm/mach/arch.h>
39 #include <asm/mach/map.h>
40 #include <asm/mach/flash.h>
41 #include <asm/hardware/gic.h>
42
43 #include <mach/dvfs.h>
44 #include <mach/board.h>
45 #include <mach/hardware.h>
46 #include <mach/io.h>
47 #include <mach/gpio.h>
48 #include <mach/iomux.h>
49
50 #if defined(CONFIG_SPIM_RK29)
51 #include "../../../drivers/spi/rk29_spim.h"
52 #endif
53
54 #ifdef CONFIG_SND_SOC_RK3028
55 #include "../../../sound/soc/codecs/rk3028_codec.h"
56 #endif
57
58 #if defined(CONFIG_RK_HDMI)
59         #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
60 #endif
61
62 #include "board-rk3026-tb-camera.c"
63
64 /***********************************************************
65 *       board config
66 ************************************************************/
67 //system power on
68 #define POWER_ON_PIN            RK30_PIN1_PA1  //PWR_HOLD
69
70 //touchscreen
71 #define TOUCH_RST_PIN           RK30_PIN3_PC3
72 #define TOUCH_RST_VALUE         GPIO_HIGH
73 #define TOUCH_PWR_PIN           RK30_PIN2_PD0
74 #define TOUCH_PWR_VALUE         GPIO_LOW
75 #define TOUCH_INT_PIN           RK30_PIN3_PC7
76
77 //backlight
78 #define LCD_DISP_ON_PIN
79 #define BL_PWM                  0  // (0 ~ 2)
80 #define PWM_EFFECT_VALUE        1
81 #define BL_EN_PIN               RK30_PIN3_PC5
82 #define BL_EN_VALUE             GPIO_HIGH
83
84 //fb
85 #define LCD_EN_PIN              RK30_PIN3_PD2
86 #define LCD_EN_VALUE            GPIO_HIGH
87 #define LCD_CS_PIN              INVALID_GPIO
88 #define LCD_CS_VALUE            GPIO_HIGH
89
90 //gsensor
91 #define GS_INT_PIN              RK30_PIN3_PD1
92
93 //sdmmc
94 //Reference to board-rk3028a-tb-sdmmc-config.c
95
96 //keyboard
97 //#define RK31XX_MAINBOARD_V1      //if mainboard is RK31XX_MAINBOARD_V1.0
98 #define PLAY_ON_PIN             RK30_PIN0_PD1   //wakeup key            
99
100 //pwm regulator
101 #define REG_PWM                 1  // (0 ~ 2)
102
103 //pmic
104 #define PMU_INT_PIN             RK30_PIN3_PC6
105 #define PMU_SLEEP_PIN           RK30_PIN0_PD0
106
107 //ion reserve memory
108 #define ION_RESERVE_SIZE        (80 * SZ_1M)
109
110 static int pwm_mode[] = {PWM0, PWM1, PWM2};
111 static inline int rk_gpio_request(int gpio, int direction, int value, const char *label)
112 {
113         int ret = 0;
114         unsigned long flags = 0;
115
116         if(!gpio_is_valid(gpio))
117                 return 0;
118
119         if(direction == GPIOF_DIR_IN)
120                 flags = GPIOF_IN;
121         else if(value == GPIO_LOW)
122                 flags = GPIOF_OUT_INIT_LOW;
123         else
124                 flags = GPIOF_OUT_INIT_HIGH;
125
126         ret = gpio_request_one(gpio, flags, label);
127         if(ret < 0)
128                 pr_err("Failed to request '%s'\n", label);
129
130         return ret;
131 }
132
133 static struct spi_board_info board_spi_devices[] = {
134 };
135
136 /***********************************************************
137 *       touchscreen
138 ************************************************************/
139 #if defined(CONFIG_TOUCHSCREEN_GT8XX)
140 static int goodix_init_platform_hw(void)
141 {
142         int ret  = 0;
143
144         ret = rk_gpio_request(TOUCH_PWR_PIN, GPIOF_DIR_OUT, TOUCH_PWR_VALUE, "touch_pwr");
145         if(ret < 0)
146                 return ret; 
147         msleep(100);
148
149         ret = rk_gpio_request(TOUCH_RST_PIN, GPIOF_DIR_OUT, TOUCH_RST_VALUE, "touch_rst");
150         if(ret < 0)
151                 return ret; 
152         msleep(100);
153
154         return 0;
155 }
156
157 struct goodix_platform_data goodix_info = {
158         .model = 8105,
159         .irq_pin = TOUCH_INT_PIN,
160         .rest_pin = TOUCH_RST_PIN,
161         .init_platform_hw = goodix_init_platform_hw,
162 };
163 #endif
164
165 /***********************************************************
166 *       rk30  backlight
167 ************************************************************/
168 #ifdef CONFIG_BACKLIGHT_RK29_BL
169 static int rk29_backlight_io_init(void)
170 {
171         int ret = 0;
172
173         iomux_set(pwm_mode[BL_PWM]);
174 #ifdef  LCD_DISP_ON_PIN
175         ret = rk_gpio_request(BL_EN_PIN, GPIOF_DIR_OUT, BL_EN_VALUE, "bl_en");
176         if(ret < 0)
177                 return ret;
178 #endif
179         return 0;
180 }
181
182 static int rk29_backlight_io_deinit(void)
183 {
184         int pwm_gpio;
185 #ifdef  LCD_DISP_ON_PIN
186         gpio_free(BL_EN_PIN);
187 #endif
188         pwm_gpio = iomux_mode_to_gpio(pwm_mode[BL_PWM]);
189         return rk_gpio_request(BL_EN_PIN, GPIOF_DIR_OUT, GPIO_LOW, "BL_PWM");
190 }
191
192 static int rk29_backlight_pwm_suspend(void)
193 {
194         int ret, pwm_gpio = iomux_mode_to_gpio(pwm_mode[BL_PWM]);
195
196         ret = rk_gpio_request(pwm_gpio, GPIOF_DIR_OUT, GPIO_LOW, "BL_PWM");
197         if(ret < 0)
198                 return ret;
199 #ifdef  LCD_DISP_ON_PIN
200         gpio_direction_output(BL_EN_PIN, !BL_EN_VALUE);
201 #endif
202         return ret;
203 }
204
205 static int rk29_backlight_pwm_resume(void)
206 {
207         int pwm_gpio = iomux_mode_to_gpio(pwm_mode[BL_PWM]);
208
209         gpio_free(pwm_gpio);
210         iomux_set(pwm_mode[BL_PWM]);
211 #ifdef  LCD_DISP_ON_PIN
212         msleep(30);
213         gpio_direction_output(BL_EN_PIN, BL_EN_VALUE);
214 #endif
215         return 0;
216 }
217
218 static struct rk29_bl_info rk29_bl_info = {
219         .pwm_id = BL_PWM,
220         .min_brightness=200,
221         .max_brightness=255,
222         .brightness_mode = BRIGHTNESS_MODE_CONIC,
223         .bl_ref = PWM_EFFECT_VALUE,
224         .io_init = rk29_backlight_io_init,
225         .io_deinit = rk29_backlight_io_deinit,
226         .pwm_suspend = rk29_backlight_pwm_suspend,
227         .pwm_resume = rk29_backlight_pwm_resume,
228 };
229
230 static struct platform_device rk29_device_backlight = {
231         .name   = "rk29_backlight",
232         .id     = -1,
233         .dev    = {
234                 .platform_data  = &rk29_bl_info,
235         }
236 };
237 #endif
238
239 /***********************************************************
240 *       fb
241 ************************************************************/
242 #ifdef CONFIG_FB_ROCKCHIP
243 static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
244 {
245         int ret = 0;
246
247         ret = rk_gpio_request(LCD_CS_PIN, GPIOF_DIR_OUT, LCD_CS_VALUE, "lcd_cs");
248         if(ret < 0)
249                 return ret;
250
251         return rk_gpio_request(LCD_EN_PIN, GPIOF_DIR_OUT, LCD_EN_VALUE, "lcd_en");
252 }
253
254 static int rk_fb_io_disable(void)
255 {
256         gpio_set_value(LCD_CS_PIN, !LCD_CS_VALUE);
257         gpio_set_value(LCD_EN_PIN, !LCD_EN_VALUE);
258
259         return 0;
260 }
261
262 static int rk_fb_io_enable(void)
263 {
264         gpio_set_value(LCD_CS_PIN, LCD_CS_VALUE);
265         gpio_set_value(LCD_EN_PIN, LCD_EN_VALUE);
266
267         return 0;
268 }
269
270 #if defined(CONFIG_LCDC0_RK3066B) || defined(CONFIG_LCDC0_RK3188)
271 struct rk29fb_info lcdc0_screen_info = {
272 #if defined(CONFIG_RK_HDMI) && defined(CONFIG_HDMI_SOURCE_LCDC0) && defined(CONFIG_DUAL_LCDC_DUAL_DISP_IN_KERNEL)
273         .prop      = EXTEND,    //extend display device
274         .io_init    = NULL,
275         .io_disable = NULL,
276         .io_enable = NULL,
277         .set_screen_info = hdmi_init_lcdc,
278 #else
279         .prop      = PRMRY,             //primary display device
280         .io_init   = rk_fb_io_init,
281         .io_disable = rk_fb_io_disable,
282         .io_enable = rk_fb_io_enable,
283         .set_screen_info = set_lcd_info,
284 #endif
285 };
286 #endif
287
288 #if defined(CONFIG_LCDC1_RK3066B) || defined(CONFIG_LCDC1_RK3188)
289 struct rk29fb_info lcdc1_screen_info = {
290 #if defined(CONFIG_RK_HDMI) && defined(CONFIG_HDMI_SOURCE_LCDC1) && defined(CONFIG_DUAL_LCDC_DUAL_DISP_IN_KERNEL)
291         .prop      = EXTEND,    //extend display device
292         .io_init    = NULL,
293         .io_disable = NULL,
294         .io_enable = NULL,
295         .set_screen_info = hdmi_init_lcdc,
296 #else
297         .prop      = PRMRY,             //primary display device
298         .io_init   = rk_fb_io_init,
299         .io_disable = rk_fb_io_disable,
300         .io_enable = rk_fb_io_enable,
301         .set_screen_info = set_lcd_info,
302 #endif
303 };
304 #endif
305
306 static struct resource resource_fb[] = {
307         [0] = {
308                 .name  = "fb0 buf",
309                 .start = 0,
310                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
311                 .flags = IORESOURCE_MEM,
312         },
313         [1] = {
314                 .name  = "ipp buf",  //for rotate
315                 .start = 0,
316                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
317                 .flags = IORESOURCE_MEM,
318         },
319         [2] = {
320                 .name  = "fb2 buf",
321                 .start = 0,
322                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
323                 .flags = IORESOURCE_MEM,
324         },
325 };
326
327 static struct platform_device device_fb = {
328         .name           = "rk-fb",
329         .id             = -1,
330         .num_resources  = ARRAY_SIZE(resource_fb),
331         .resource       = resource_fb,
332 };
333 #endif
334
335 #if defined(CONFIG_LCDC0_RK3066B) || defined(CONFIG_LCDC0_RK3188)
336 static struct resource resource_lcdc0[] = {
337         [0] = {
338                 .name  = "lcdc0 reg",
339                 .start = RK3026_LCDC0_PHYS,
340                 .end   = RK3026_LCDC0_PHYS + RK3026_LCDC0_SIZE - 1,
341                 .flags = IORESOURCE_MEM,
342         },
343         
344         [1] = {
345                 .name  = "lcdc0 irq",
346                 .start = IRQ_LCDC,
347                 .end   = IRQ_LCDC,
348                 .flags = IORESOURCE_IRQ,
349         },
350 };
351
352 static struct platform_device device_lcdc0 = {
353         .name             = "rk30-lcdc",
354         .id               = 0,
355         .num_resources    = ARRAY_SIZE(resource_lcdc0),
356         .resource         = resource_lcdc0,
357         .dev            = {
358                 .platform_data = &lcdc0_screen_info,
359         },
360 };
361 #endif
362
363 #if defined(CONFIG_LCDC1_RK3066B) || defined(CONFIG_LCDC1_RK3188)
364 static struct resource resource_lcdc1[] = {
365         [0] = {
366                 .name  = "lcdc1 reg",
367                 .start = RK3026_LCDC1_PHYS,
368                 .end   = RK3026_LCDC1_PHYS + RK3026_LCDC1_SIZE - 1,
369                 .flags = IORESOURCE_MEM,
370         },
371         [1] = {
372                 .name  = "lcdc1 irq",
373                 .start = IRQ_LCDC1,
374                 .end   = IRQ_LCDC1,
375                 .flags = IORESOURCE_IRQ,
376         },
377 };
378
379 static struct platform_device device_lcdc1 = {
380         .name             = "rk30-lcdc",
381         .id               = 1,
382         .num_resources    = ARRAY_SIZE(resource_lcdc1),
383         .resource         = resource_lcdc1,
384         .dev            = {
385                 .platform_data = &lcdc1_screen_info,
386         },
387 };
388 #endif
389
390 static int rk_platform_add_display_devices(void)
391 {
392         struct platform_device *fb = NULL;  //fb
393         struct platform_device *lcdc0 = NULL; //lcdc0
394         struct platform_device *lcdc1 = NULL; //lcdc1
395         struct platform_device *bl = NULL; //backlight
396 #ifdef CONFIG_FB_ROCKCHIP
397         fb = &device_fb;
398 #endif
399
400 #if defined(CONFIG_LCDC0_RK3066B) || defined(CONFIG_LCDC0_RK3188)
401         lcdc0 = &device_lcdc0,
402 #endif
403
404 #if defined(CONFIG_LCDC1_RK3066B) || defined(CONFIG_LCDC1_RK3188)
405         lcdc1 = &device_lcdc1,
406 #endif
407
408 #ifdef CONFIG_BACKLIGHT_RK29_BL
409         bl = &rk29_device_backlight,
410 #endif
411         __rk_platform_add_display_devices(fb,lcdc0,lcdc1,bl);
412
413         return 0;
414 }
415
416
417 /***********************************************************
418 *       gsensor
419 ************************************************************/
420 #if defined (CONFIG_GS_MMA8452)
421 static int mma8452_init_platform_hw(void)
422 {
423         return 0;
424 }
425
426 static struct sensor_platform_data mma8452_info = {
427         .type = SENSOR_TYPE_ACCEL,
428         .irq_enable = 1,
429         .poll_delay_ms = 30,
430         .init_platform_hw = mma8452_init_platform_hw,
431         .orientation = {-1, 0, 0, 0, -1, 0, 0, 0, 1},
432 };
433 #endif
434
435 /***********************************************************
436 *       keyboard
437 ************************************************************/
438 #include <plat/key.h>
439
440 static struct rk29_keys_button key_button[] = {
441         {
442                 .desc   = "play",
443                 .code   = KEY_POWER,
444                 .gpio   = PLAY_ON_PIN,
445                 .active_low = PRESS_LEV_LOW,
446                 .wakeup = 1,
447         },
448 /* disable adc keyboard,
449  * because rk280a adc reference voltage is 3.3V, but
450  * rk30xx mainbord key's supply voltage is 2.5V and
451  * rk31xx mainbord key's supply voltage is 1.8V.
452  */
453 #if 0 
454 #ifdef RK31XX_MAINBOARD_V1
455         {
456                 .desc   = "vol-",
457                 .code   = KEY_VOLUMEDOWN,
458                 .adc_value      = 744,
459                 .gpio   = INVALID_GPIO,
460                 .active_low = PRESS_LEV_LOW,
461         },
462         {
463                 .desc   = "play",
464                 .code   = KEY_POWER,
465                 .gpio   = PLAY_ON_PIN,
466                 .active_low = PRESS_LEV_LOW,
467                 .wakeup = 1,
468         },
469         {
470                 .desc   = "vol+",
471                 .code   = KEY_VOLUMEUP,
472                 .adc_value      = 558,
473                 .gpio = INVALID_GPIO,
474                 .active_low = PRESS_LEV_LOW,
475         },
476         {
477                 .desc   = "menu",
478                 .code   = EV_MENU,
479                 .adc_value      = 1,
480                 .gpio = INVALID_GPIO,
481                 .active_low = PRESS_LEV_LOW,
482         },
483         {
484                 .desc   = "home",
485                 .code   = KEY_HOME,
486                 .adc_value      = 354,
487                 .gpio = INVALID_GPIO,
488                 .active_low = PRESS_LEV_LOW,
489         },
490         {
491                 .desc   = "esc",
492                 .code   = KEY_BACK,
493                 .adc_value      = 169,
494                 .gpio = INVALID_GPIO,
495                 .active_low = PRESS_LEV_LOW,
496         },
497 #else
498         {
499                 .desc   = "vol-",
500                 .code   = KEY_VOLUMEDOWN,
501                 .adc_value      = 900,
502                 .gpio   = INVALID_GPIO,
503                 .active_low = PRESS_LEV_LOW,
504         },
505         {
506                 .desc   = "play",
507                 .code   = KEY_POWER,
508                 .gpio   = PLAY_ON_PIN,
509                 .active_low = PRESS_LEV_LOW,
510                 .wakeup = 1,
511         },
512         {
513                 .desc   = "vol+",
514                 .code   = KEY_VOLUMEUP,
515                 .adc_value      = 1,
516                 .gpio = INVALID_GPIO,
517                 .active_low = PRESS_LEV_LOW,
518         },
519         {
520                 .desc   = "menu",
521                 .code   = EV_MENU,
522                 .adc_value      = 133,
523                 .gpio = INVALID_GPIO,
524                 .active_low = PRESS_LEV_LOW,
525         },
526         {
527                 .desc   = "home",
528                 .code   = KEY_HOME,
529                 .adc_value      = 550,
530                 .gpio = INVALID_GPIO,
531                 .active_low = PRESS_LEV_LOW,
532         },
533         {
534                 .desc   = "esc",
535                 .code   = KEY_BACK,
536                 .adc_value      = 333,
537                 .gpio = INVALID_GPIO,
538                 .active_low = PRESS_LEV_LOW,
539         },
540         {
541                 .desc   = "camera",
542                 .code   = KEY_CAMERA,
543                 .adc_value      = 742,
544                 .gpio = INVALID_GPIO,
545                 .active_low = PRESS_LEV_LOW,
546         },
547 #endif
548 #endif
549 };
550
551 struct rk29_keys_platform_data rk29_keys_pdata = {
552         .buttons        = key_button,
553         .nbuttons       = ARRAY_SIZE(key_button),
554         .chn    = 1,  //chn: 0-7, if do not use ADC,set 'chn' -1
555 };
556
557 /***********************************************************
558 *       sdmmc
559 ************************************************************/
560 #ifdef CONFIG_SDMMC_RK29
561 #include "board-rk3028a-tb-sdmmc-config.c"
562 #include "../plat-rk/rk-sdmmc-ops.c"
563 #include "../plat-rk/rk-sdmmc-wifi.c"
564 #endif //endif ---#ifdef CONFIG_SDMMC_RK29
565
566 #ifdef CONFIG_SDMMC0_RK29
567 #define CONFIG_SDMMC0_USE_DMA
568 static int rk29_sdmmc0_cfg_gpio(void)
569 {
570         rk29_sdmmc_set_iomux(0, 0xFFFF);
571         #if defined(CONFIG_SDMMC0_RK29_SDCARD_DET_FROM_GPIO)
572         iomux_set_gpio_mode(iomux_gpio_to_mode(RK29SDK_SD_CARD_DETECT_N));
573         #else
574         iomux_set(MMC0_DETN);
575         #endif  
576
577         #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
578         gpio_request(SDMMC0_WRITE_PROTECT_PIN, "sdmmc-wp");
579         gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);
580         #endif
581         return 0;
582 }
583
584 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
585         .host_ocr_avail =
586             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
587              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
588              MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36),
589         .host_caps =
590             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
591         .io_init = rk29_sdmmc0_cfg_gpio,
592
593         .set_iomux = rk29_sdmmc_set_iomux,
594
595         .dma_name = "sd_mmc",
596 #ifdef CONFIG_SDMMC0_USE_DMA
597         .use_dma = 1,
598 #else
599         .use_dma = 0,
600 #endif
601
602 #if defined(CONFIG_WIFI_COMBO_MODULE_CONTROL_FUNC) && defined(CONFIG_USE_SDMMC0_FOR_WIFI_DEVELOP_BOARD)
603         .status = rk29sdk_wifi_mmc0_status,
604         .register_status_notify = rk29sdk_wifi_mmc0_status_register,
605 #endif
606
607 #if defined(RK29SDK_SD_CARD_PWR_EN) || (INVALID_GPIO != RK29SDK_SD_CARD_PWR_EN)
608         .power_en = RK29SDK_SD_CARD_PWR_EN,
609         .power_en_level = RK29SDK_SD_CARD_PWR_EN_LEVEL,
610 #else
611         .power_en = INVALID_GPIO,
612         .power_en_level = GPIO_LOW,
613 #endif    
614         .enable_sd_wakeup = 0,
615
616 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
617         .write_prt = SDMMC0_WRITE_PROTECT_PIN,
618         .write_prt_enalbe_level = SDMMC0_WRITE_PROTECT_ENABLE_VALUE;
619 #else
620         .write_prt = INVALID_GPIO,
621 #endif
622
623         .det_pin_info = {    
624                 #if defined(RK29SDK_SD_CARD_DETECT_N) || (INVALID_GPIO != RK29SDK_SD_CARD_DETECT_N)  
625                 .io             = RK29SDK_SD_CARD_DETECT_N, //INVALID_GPIO,
626                 .enable         = RK29SDK_SD_CARD_INSERT_LEVEL,
627                 #else
628                 .io             = INVALID_GPIO,
629                 .enable         = GPIO_LOW,
630                 #endif    
631         }, 
632
633 };
634 #endif // CONFIG_SDMMC0_RK29
635
636 #ifdef CONFIG_SDMMC1_RK29
637 #define CONFIG_SDMMC1_USE_DMA
638 static int rk29_sdmmc1_cfg_gpio(void)
639 {
640 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
641         gpio_request(SDMMC1_WRITE_PROTECT_PIN, "sdio-wp");
642         gpio_direction_input(SDMMC1_WRITE_PROTECT_PIN);
643 #endif
644         return 0;
645 }
646
647 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
648         .host_ocr_avail =
649             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
650              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
651              MMC_VDD_33_34),
652
653 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
654         .host_caps = (MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ |
655                       MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
656 #else
657         .host_caps =
658             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
659 #endif
660
661         .io_init = rk29_sdmmc1_cfg_gpio,
662
663         .set_iomux = rk29_sdmmc_set_iomux,
664
665         .dma_name = "sdio",
666 #ifdef CONFIG_SDMMC1_USE_DMA
667         .use_dma = 1,
668 #else
669         .use_dma = 0,
670 #endif
671
672 #if defined(CONFIG_WIFI_CONTROL_FUNC) || defined(CONFIG_WIFI_COMBO_MODULE_CONTROL_FUNC)
673         .status = rk29sdk_wifi_status,
674         .register_status_notify = rk29sdk_wifi_status_register,
675 #endif
676
677 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
678         .write_prt = SDMMC1_WRITE_PROTECT_PIN,
679         .write_prt_enalbe_level = SDMMC1_WRITE_PROTECT_ENABLE_VALUE;
680 #else
681         .write_prt = INVALID_GPIO,
682 #endif
683
684     #if defined(CONFIG_RK29_SDIO_IRQ_FROM_GPIO)
685         .sdio_INT_gpio = RK29SDK_WIFI_SDIO_CARD_INT,
686     #endif
687
688         .det_pin_info = {    
689         #if defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
690                 #if defined(RK29SDK_SD_CARD_DETECT_N) || (INVALID_GPIO != RK29SDK_SD_CARD_DETECT_N)  
691                 .io             = RK29SDK_SD_CARD_DETECT_N,
692                 #else
693                 .io             = INVALID_GPIO,
694                 #endif   
695
696                 .enable         = RK29SDK_SD_CARD_INSERT_LEVEL,
697         #else
698                 .io             = INVALID_GPIO,
699                 .enable         = GPIO_LOW,
700         #endif
701         },
702         .enable_sd_wakeup = 0,
703 };
704 #endif //endif--#ifdef CONFIG_SDMMC1_RK29
705
706 /***********************************************************
707 *       rfkill
708 ************************************************************/
709 #ifdef CONFIG_RFKILL_RK
710 // bluetooth rfkill device, its driver in net/rfkill/rfkill-rk.c
711 static struct rfkill_rk_platform_data rfkill_rk_platdata = {
712         .type               = RFKILL_TYPE_BLUETOOTH,
713
714         .poweron_gpio       = { // BT_REG_ON
715                 .io             = INVALID_GPIO, //RK30_PIN3_PC7,
716                 .enable         = GPIO_HIGH,
717                 .iomux          = {
718                         .name       = "bt_poweron",
719                         //.fgpio      = GPIO3_C7,
720                 },
721         },
722
723         .reset_gpio         = { // BT_RST
724                 .io             = RK30_PIN3_PD5, // set io to INVALID_GPIO for disable it
725                 .enable         = GPIO_LOW,
726                 .iomux          = {
727                         .name       = "bt_reset",
728                         //.fgpio      = GPIO3_D5,
729                 },
730         }, 
731
732         .wake_gpio          = { // BT_WAKE, use to control bt's sleep and wakeup
733                 .io             = RK30_PIN0_PC6, // set io to INVALID_GPIO for disable it
734                 .enable         = GPIO_HIGH,
735                 .iomux          = {
736                         .name       = "bt_wake",
737                         //.fgpio      = GPIO0_C6,
738                 },
739         },
740
741         .wake_host_irq      = { // BT_HOST_WAKE, for bt wakeup host when it is in deep sleep
742                 .gpio           = {
743                         .io         = RK30_PIN0_PC5, // set io to INVALID_GPIO for disable it
744                         .enable     = GPIO_LOW,      // set GPIO_LOW for falling, set 0 for rising
745                         .iomux      = {
746                                 .name   = "bt_wake_host",
747                                 //.fgpio  = GPIO0_C5,  
748                         },
749                 },
750         },
751
752         .rts_gpio           = { // UART_RTS, enable or disable BT's data coming
753                 .io             = RK30_PIN0_PC3, // set io to INVALID_GPIO for disable it
754                 .enable         = GPIO_LOW,
755                 .iomux          = {
756                         .name       = "bt_rts",
757                         .fgpio      = GPIO0_C3,
758                         .fmux       = UART0_RTSN,
759                 },
760         }
761 };
762
763 static struct platform_device device_rfkill_rk = {
764     .name   = "rfkill_rk",
765     .id     = -1,
766     .dev    = {
767         .platform_data = &rfkill_rk_platdata,
768     },
769 };
770 #endif
771
772 /***********************************************************
773 *       ion
774 ************************************************************/
775 #ifdef CONFIG_ION
776 static struct ion_platform_data rk30_ion_pdata = {
777         .nr = 1,
778         .heaps = {
779                 {
780                         .type = ION_HEAP_TYPE_CARVEOUT,
781                         .id = ION_NOR_HEAP_ID,
782                         .name = "norheap",
783                         .size = ION_RESERVE_SIZE,
784                 }
785         },
786 };
787
788 static struct platform_device device_ion = {
789         .name = "ion-rockchip",
790         .id = 0,
791         .dev = {
792                 .platform_data = &rk30_ion_pdata,
793         },
794 };
795 #endif
796
797 #ifdef CONFIG_SND_SOC_RK3028
798 struct rk3028_codec_pdata rk3028_codec_pdata_info={
799             .spk_ctl_gpio = INVALID_GPIO,
800             .hp_ctl_gpio = RK2928_PIN3_PD4,
801         };
802
803 static struct resource resources_acodec[] = {
804         {
805                 .start  = RK2928_ACODEC_PHYS,
806                 .end    = RK2928_ACODEC_PHYS + RK2928_ACODEC_SIZE - 1,
807                 .flags  = IORESOURCE_MEM,
808         },
809 };
810
811 static struct platform_device rk3028_codec = {
812         .name   = "rk3028-codec",
813         .id     = -1,
814         .resource = resources_acodec,
815         .dev = {
816                .platform_data = &rk3028_codec_pdata_info,
817                     }
818         };
819 #endif
820
821 /***********************************************************
822 *       pwm regulator
823 ************************************************************/
824 #ifdef CONFIG_RK30_PWM_REGULATOR
825 static int pwm_voltage_map[] = {
826         800000,  825000,  850000,  875000,  900000,  925000 ,
827         950000,  975000,  1000000, 1025000, 1050000, 1075000, 
828         1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 
829         1250000, 1275000, 1300000, 1325000, 1350000, 1375000
830 };
831
832 static struct regulator_consumer_supply pwm_dcdc1_consumers[] = {
833         {
834                 .supply = "vdd_core",
835         }
836 };
837
838 struct regulator_init_data pwm_regulator_init_dcdc[1] = {
839         {
840                 .constraints = {
841                         .name = "PWM_DCDC1",
842                         .min_uV = 600000,
843                         .max_uV = 1800000,      //0.6-1.8V
844                         .apply_uV = true,
845                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
846                 },
847                 .num_consumer_supplies = ARRAY_SIZE(pwm_dcdc1_consumers),
848                 .consumer_supplies = pwm_dcdc1_consumers,
849         },
850 };
851
852 static struct pwm_platform_data pwm_regulator_info[1] = {
853         {
854                 .pwm_id = REG_PWM,
855                 .pwm_voltage = 1200000,
856                 .suspend_voltage = 1050000,
857                 .min_uV = 950000,
858                 .max_uV = 1400000,
859                 .coefficient = 504,     //50.4%
860                 .pwm_voltage_map = pwm_voltage_map,
861                 .init_data      = &pwm_regulator_init_dcdc[0],
862         },
863 };
864 struct platform_device pwm_regulator_device[1] = {
865         {
866                 .name = "pwm-voltage-regulator",
867                 .id = 0,
868                 .dev            = {
869                         .platform_data = &pwm_regulator_info[0],
870                 }
871         },
872 };
873
874 static void pwm_regulator_init(void)
875 {
876         pwm_regulator_info[0].pwm_gpio = iomux_mode_to_gpio(pwm_mode[REG_PWM]);
877         pwm_regulator_info[0].pwm_iomux_pwm = pwm_mode[REG_PWM];
878         pwm_regulator_info[0].pwm_iomux_gpio = iomux_switch_gpio_mode(pwm_mode[REG_PWM]);
879 }
880 #endif
881
882 int __sramdata pwm_iomux, pwm_do, pwm_dir, pwm_en;
883 #define grf_readl(offset)       readl_relaxed(RK30_GRF_BASE + offset)
884 #define grf_writel(v, offset)   do { writel_relaxed(v, RK30_GRF_BASE + offset); dsb(); } while (0)
885
886 #define GPIO0_D2_OFFSET         10
887 void __sramfunc rk30_pwm_logic_suspend_voltage(void)
888 {
889 #ifdef CONFIG_RK30_PWM_REGULATOR
890         #if 0
891         /* pwm0: GPIO0_D2, pwm1: GPIO0_D3, pwm2: GPIO0_D4 */
892         int off = GPIO0_D2_OFFSET + REG_PWM;
893
894         sram_udelay(10000);
895         pwm_iomux = grf_readl(GRF_GPIO0D_IOMUX);
896         pwm_dir = grf_readl(GRF_GPIO0H_DIR);
897         pwm_do = grf_readl(GRF_GPIO0H_DO);
898         pwm__en = grf_readl(GRF_GPIO0H_EN);
899
900         grf_writel((1<<(2 * off), GRF_GPIO0D_IOMUX);
901         grf_writel((1<<(16 + off))|(1<<off), GRF_GPIO0H_DIR);
902         grf_writel((1<<(16 + off))|(1<<off), GRF_GPIO0H_DO);
903         #endif
904 #endif
905 }
906
907 void __sramfunc rk30_pwm_logic_resume_voltage(void)
908 {
909 #ifdef CONFIG_RK30_PWM_REGULATOR
910         #if 0
911         /* pwm0: GPIO0_D2, pwm1: GPIO0_D3, pwm2: GPIO0_D4 */
912         int off = GPIO0_D2_OFFSET + REG_PWM;
913
914         grf_writel((1<<(2 * off))|pwm_iomux, GRF_GPIO0D_IOMUX);
915         grf_writel(((1<<(16 + off))|pwm_dir), GRF_GPIO0L_DIR);
916         grf_writel(((1<<(16 + off))|pwm_do), GRF_GPIO0L_DO);
917         grf_writel(((1<<(16 + off))|pwm_en), GRF_GPIO0L_EN);
918         sram_udelay(10000);
919         #endif
920 #endif
921 }
922 extern void pwm_suspend_voltage(void);
923 extern void pwm_resume_voltage(void);
924
925 void  rk30_pwm_suspend_voltage_set(void)
926 {
927 #ifdef CONFIG_RK30_PWM_REGULATOR
928         pwm_suspend_voltage();
929 #endif
930 }
931
932 void  rk30_pwm_resume_voltage_set(void)
933 {
934 #ifdef CONFIG_RK30_PWM_REGULATOR
935         pwm_resume_voltage();
936 #endif
937 }
938
939 /***********************************************************
940 *       pmic
941 ************************************************************/
942 int __sramdata g_pmic_type =  0;
943
944 #ifdef CONFIG_MFD_TPS65910
945 #define TPS65910_HOST_IRQ       PMU_INT_PIN
946 #define PMU_POWER_SLEEP         PMU_SLEEP_PIN
947 static struct pmu_info  tps65910_dcdc_info[] = {
948         {
949                 .name = "vdd_cpu",
950                 .min_uv = 1200000,
951                 .max_uv = 1200000,
952         },
953         {
954                 .name = "vdd2",
955                 .min_uv = 1200000,
956                 .max_uv = 1200000,
957         },
958         {
959                 .name = "vio",
960                 .min_uv = 3300000,
961                 .max_uv = 3300000,
962         },
963 };
964
965 static struct pmu_info tps65910_ldo_info[] = {
966         {
967                 .name          = "vpll",   //vcc25
968                 .min_uv          = 2500000,
969                 .max_uv         = 2500000,
970         },
971         {
972                 .name          = "vdig1",    //vcc18_cif
973                 .min_uv          = 1800000,
974                 .max_uv         = 1800000,
975         },
976
977         {
978                 .name          = "vdig2",   //vdd11
979                 .min_uv          = 1100000,
980                 .max_uv         = 1100000,
981         },
982         {
983                 .name          = "vaux1",   //vcc28_cif
984                 .min_uv          = 2800000,
985                 .max_uv         = 2800000,
986         },
987         {
988                 .name          = "vaux2",   //vcca33
989                 .min_uv          = 3300000,
990                 .max_uv         = 3300000,
991         },
992         {
993                 .name          = "vaux33",   //vcc_tp
994                 .min_uv          = 3300000,
995                 .max_uv         = 3300000,
996         },
997         {
998                 .name          = "vmmc",   //vccio_wl
999                 .min_uv          = 1800000,
1000                 .max_uv         = 1800000,
1001         },
1002         {
1003                 .name          = "vdac",   //
1004                 .min_uv          = 1800000,
1005                 .max_uv         = 1800000,
1006         },
1007 };
1008 #include "../mach-rk30/board-pmu-tps65910.c"
1009 #endif
1010
1011 void __sramfunc board_pmu_suspend(void)
1012 {
1013         #if defined (CONFIG_MFD_TPS65910)
1014         if(pmic_is_tps65910())
1015                 board_pmu_tps65910_suspend();
1016         #endif
1017 }
1018
1019 void __sramfunc board_pmu_resume(void)
1020 {
1021         #if defined (CONFIG_MFD_TPS65910)
1022         if(pmic_is_tps65910())
1023                 board_pmu_tps65910_resume();
1024         #endif
1025 }
1026
1027 /***********************************************************
1028 *       i2c
1029 ************************************************************/
1030 #ifdef CONFIG_I2C0_RK30
1031 static struct i2c_board_info __initdata i2c0_info[] = {
1032 #if defined (CONFIG_GS_MMA8452)
1033         {
1034                 .type           = "gs_mma8452",
1035                 .addr           = 0x1d,
1036                 .flags          = 0,
1037                 .irq            = GS_INT_PIN,
1038                 .platform_data = &mma8452_info,
1039         },
1040 #endif
1041 };
1042 #endif
1043
1044 #ifdef CONFIG_I2C1_RK30
1045 static struct i2c_board_info __initdata i2c1_info[] = {
1046 #if defined (CONFIG_MFD_TPS65910)
1047         {
1048                 .type           = "tps65910",
1049                 .addr           = TPS65910_I2C_ID0,
1050                 .flags          = 0,
1051                 .irq            = TPS65910_HOST_IRQ,
1052                 .platform_data = &tps65910_data,
1053         },
1054 #endif
1055 };
1056 #endif
1057
1058 #ifdef CONFIG_I2C2_RK30
1059 static struct i2c_board_info __initdata i2c2_info[] = {
1060 #if defined (CONFIG_TOUCHSCREEN_GT8XX)
1061         {
1062                 .type          = "Goodix-TS",
1063                 .addr          = 0x55,
1064                 .flags         = 0,
1065                 .irq           = TOUCH_INT_PIN,
1066                 .platform_data = &goodix_info,
1067         },
1068 #endif
1069 };
1070 #endif
1071
1072 #ifdef CONFIG_I2C3_RK30
1073 static struct i2c_board_info __initdata i2c3_info[] = {
1074 };
1075 #endif
1076
1077 #ifdef CONFIG_I2C_GPIO_RK30
1078 #define I2C_SDA_PIN     INVALID_GPIO// RK30_PIN2_PD6   //set sda_pin here
1079 #define I2C_SCL_PIN     INVALID_GPIO//RK30_PIN2_PD7   //set scl_pin here
1080 static int rk30_i2c_io_init(void)
1081 {
1082         return 0;
1083 }
1084
1085 struct i2c_gpio_platform_data default_i2c_gpio_data = {
1086        .sda_pin = I2C_SDA_PIN,
1087        .scl_pin = I2C_SCL_PIN,
1088        .udelay = 5, // clk = 500/udelay = 100Khz
1089        .timeout = 100,//msecs_to_jiffies(100),
1090        .bus_num    = 5,
1091        .io_init = rk30_i2c_io_init,
1092 };
1093
1094 static struct i2c_board_info __initdata i2c_gpio_info[] = {
1095 };
1096 #endif
1097
1098 static void __init rk30_i2c_register_board_info(void)
1099 {
1100 #ifdef CONFIG_I2C0_RK30
1101         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
1102 #endif
1103 #ifdef CONFIG_I2C1_RK30
1104         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
1105 #endif
1106 #ifdef CONFIG_I2C2_RK30
1107         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
1108 #endif
1109 #ifdef CONFIG_I2C3_RK30
1110         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
1111 #endif
1112 #ifdef CONFIG_I2C_GPIO_RK30
1113         i2c_register_board_info(4, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info));
1114 #endif
1115 }
1116
1117 /***********************************************************
1118 *       board init
1119 ************************************************************/
1120 static struct platform_device *devices[] __initdata = {
1121 #ifdef CONFIG_ION
1122         &device_ion,
1123 #endif
1124 #ifdef CONFIG_WIFI_CONTROL_FUNC
1125         &rk29sdk_wifi_device,
1126 #endif
1127 #ifdef CONFIG_RFKILL_RK
1128         &device_rfkill_rk,
1129 #endif
1130 #ifdef CONFIG_SND_SOC_RK3028
1131         &rk3028_codec,
1132 #endif
1133 };
1134
1135 static void rk30_pm_power_off(void)
1136 {
1137 #if defined(CONFIG_MFD_TPS65910)
1138         tps65910_device_shutdown();//tps65910 shutdown
1139 #endif
1140         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
1141         while(1);
1142 }
1143
1144 static void __init machine_rk30_board_init(void)
1145 {
1146 #ifdef CONFIG_RK30_PWM_REGULATOR
1147         pwm_regulator_init();
1148 #endif
1149         avs_init();
1150         pm_power_off = rk30_pm_power_off;
1151         rk_gpio_request(POWER_ON_PIN, GPIOF_DIR_OUT, GPIO_HIGH, "system power on");
1152         rk30_i2c_register_board_info();
1153         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1154         platform_add_devices(devices, ARRAY_SIZE(devices));
1155         rk_platform_add_display_devices();      
1156 #if defined(CONFIG_WIFI_CONTROL_FUNC)
1157         rk29sdk_wifi_bt_gpio_control_init();
1158 #elif defined(CONFIG_WIFI_COMBO_MODULE_CONTROL_FUNC)
1159     rk29sdk_wifi_combo_module_gpio_init();
1160 #endif
1161 }
1162
1163 static void __init rk30_reserve(void)
1164 {
1165         //fb reserve
1166 #ifdef CONFIG_FB_ROCKCHIP
1167         resource_fb[0].start = board_mem_reserve_add("fb0 buf", get_fb_size());
1168         resource_fb[0].end = resource_fb[0].start + get_fb_size()- 1;
1169         #if 0
1170         resource_fb[1].start = board_mem_reserve_add("ipp buf", RK30_FB0_MEM_SIZE);
1171         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
1172         #endif
1173
1174         #if defined(CONFIG_FB_ROTATE) || !defined(CONFIG_THREE_FB_BUFFER)
1175         resource_fb[2].start = board_mem_reserve_add("fb2 buf",get_fb_size());
1176         resource_fb[2].end = resource_fb[2].start + get_fb_size() - 1;
1177         #endif
1178 #endif
1179         //ion reserve
1180 #ifdef CONFIG_ION
1181         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion", ION_RESERVE_SIZE);
1182 #endif
1183         board_mem_reserved();
1184 }
1185
1186 /***********************************************************
1187 *       clock
1188 ************************************************************/
1189 static struct cpufreq_frequency_table dvfs_arm_table[] = {
1190         {.frequency = 312 * 1000,       .index = 1200 * 1000},
1191         {.frequency = 504 * 1000,       .index = 1200 * 1000},
1192         {.frequency = 816 * 1000,       .index = 1200 * 1000},
1193         //{.frequency = 1008 * 1000,      .index = 1200 * 1000},
1194         //{.frequency = 1200 * 1000,      .index = 1200 * 1000},
1195         //{.frequency = 1416 * 1000,      .index = 1200 * 1000},
1196         //{.frequency = 1608 * 1000,      .index = 1200 * 1000},
1197         {.frequency = CPUFREQ_TABLE_END},
1198 };
1199
1200 static struct cpufreq_frequency_table dvfs_gpu_table[] = {
1201         {.frequency = 100 * 1000,       .index = 1200 * 1000},
1202         {.frequency = 200 * 1000,       .index = 1200 * 1000},
1203         {.frequency = 266 * 1000,       .index = 1200 * 1000},
1204         {.frequency = 300 * 1000,       .index = 1200 * 1000},
1205         {.frequency = 400 * 1000,       .index = 1200 * 1000},
1206         {.frequency = CPUFREQ_TABLE_END},
1207 };
1208
1209 static struct cpufreq_frequency_table dvfs_ddr_table[] = {
1210         {.frequency = 200 * 1000 + DDR_FREQ_SUSPEND,    .index = 1200 * 1000},
1211         {.frequency = 300 * 1000 + DDR_FREQ_VIDEO,      .index = 1200 * 1000},
1212         {.frequency = 400 * 1000 + DDR_FREQ_NORMAL,     .index = 1200 * 1000},
1213         {.frequency = CPUFREQ_TABLE_END},
1214 };
1215
1216 void __init board_clock_init(void)
1217 {
1218         rk2928_clock_data_init(periph_pll_default, codec_pll_default, RK30_CLOCKS_DEFAULT_FLAGS);
1219         //dvfs_set_arm_logic_volt(dvfs_cpu_logic_table, cpu_dvfs_table, dep_cpu2core_table);    
1220         dvfs_set_freq_volt_table(clk_get(NULL, "cpu"), dvfs_arm_table);
1221         dvfs_set_freq_volt_table(clk_get(NULL, "gpu"), dvfs_gpu_table);
1222         dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
1223 }
1224
1225 /************************ end *****************************/
1226 MACHINE_START(RK30, "RK30board")
1227         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
1228         .fixup          = rk2928_fixup,
1229         .reserve        = &rk30_reserve,
1230         .map_io         = rk2928_map_io,
1231         .init_irq       = rk2928_init_irq,
1232         .timer          = &rk2928_timer,
1233         .init_machine   = machine_rk30_board_init,
1234 MACHINE_END