rk3066b lcdc: adjust fb lcdc backlight driver load and remove order as rk30 rk2928
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk30 / board-rk3066b-sdk.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/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/rk29-pwm-regulator.h>
49 #if defined(CONFIG_HDMI_RK30)
50         #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
51 #endif
52
53 #if defined(CONFIG_SPIM_RK29)
54 #include "../../../drivers/spi/rk29_spim.h"
55 #endif
56 #if defined(CONFIG_MU509)
57 #include <linux/mu509.h>
58 #endif
59 #if defined(CONFIG_MW100)
60 #include <linux/mw100.h>
61 #endif
62 #if defined(CONFIG_MT6229)
63 #include <linux/mt6229.h>
64 #endif
65 #if defined(CONFIG_ANDROID_TIMED_GPIO)
66 #include "../../../drivers/staging/android/timed_gpio.h"
67 #endif
68
69 #ifdef  CONFIG_THREE_FB_BUFFER
70 #define RK30_FB0_MEM_SIZE 12*SZ_1M
71 #else
72 #define RK30_FB0_MEM_SIZE 8*SZ_1M
73 #endif
74
75 #include "board-rk3066b-sdk-camera.c"
76 #include "board-rk3066b-sdk-key.c"
77
78 #if defined(CONFIG_TOUCHSCREEN_GT8XX)
79 #define TOUCH_RESET_PIN  RK30_PIN2_PC0
80 #define TOUCH_PWR_PIN    INVALID_GPIO
81 static int goodix_init_platform_hw(void)
82 {
83         int ret;
84         
85         rk30_mux_api_set(GPIO2C0_LCDC1DATA16_SMCADDR0_TRACECLK_NAME, GPIO2C_GPIO2C0);
86         rk30_mux_api_set(GPIO0D4_SPI1RXD_NAME, GPIO0D_GPIO0D4);
87         printk("%s:0x%x,0x%x\n",__func__,rk30_mux_api_get(GPIO2C0_LCDC1DATA16_SMCADDR0_TRACECLK_NAME),rk30_mux_api_get(GPIO0D4_SPI1RXD_NAME));
88
89         if (TOUCH_PWR_PIN != INVALID_GPIO) {
90                 ret = gpio_request(TOUCH_PWR_PIN, "goodix power pin");
91                 if (ret != 0) {
92                         gpio_free(TOUCH_PWR_PIN);
93                         printk("goodix power error\n");
94                         return -EIO;
95                 }
96                 gpio_direction_output(TOUCH_PWR_PIN, 0);
97                 gpio_set_value(TOUCH_PWR_PIN, GPIO_LOW);
98                 msleep(100);
99         }
100
101         if (TOUCH_RESET_PIN != INVALID_GPIO) {
102                 ret = gpio_request(TOUCH_RESET_PIN, "goodix reset pin");
103                 if (ret != 0) {
104                         gpio_free(TOUCH_RESET_PIN);
105                         printk("goodix gpio_request error\n");
106                         return -EIO;
107                 }
108                 gpio_direction_output(TOUCH_RESET_PIN, 1);
109                 msleep(100);
110                 //gpio_set_value(TOUCH_RESET_PIN, GPIO_LOW);
111                 //msleep(100);
112                 //gpio_set_value(TOUCH_RESET_PIN, GPIO_HIGH);
113                 //msleep(500);
114         }
115         return 0;
116 }
117
118 struct goodix_platform_data goodix_info = {
119         .model = 8105,
120         .irq_pin = RK30_PIN0_PD4,
121         .rest_pin = TOUCH_RESET_PIN,
122         .init_platform_hw = goodix_init_platform_hw,
123 };
124 #endif
125
126 static struct spi_board_info board_spi_devices[] = {
127 };
128
129 /***********************************************************
130 *       rk30  backlight
131 ************************************************************/
132 #ifdef CONFIG_BACKLIGHT_RK29_BL
133 #define PWM_ID            0
134 #define PWM_MUX_NAME      GPIO3D3_PWM0_NAME
135 #define PWM_MUX_MODE      GPIO3D_PWM0
136 #define PWM_MUX_MODE_GPIO GPIO3D_GPIO3D4
137 #define PWM_GPIO          RK30_PIN3_PD4
138 #define PWM_EFFECT_VALUE  1
139
140 #define LCD_DISP_ON_PIN
141
142 #ifdef  LCD_DISP_ON_PIN
143 #define BL_EN_PIN         RK30_PIN0_PA1
144 #define BL_EN_VALUE       GPIO_HIGH
145 #endif
146 static int rk29_backlight_io_init(void)
147 {
148         int ret = 0;
149         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
150 #ifdef  LCD_DISP_ON_PIN
151         // rk30_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
152
153         ret = gpio_request(BL_EN_PIN, NULL);
154         if (ret != 0) {
155                 gpio_free(BL_EN_PIN);
156         }
157
158         gpio_direction_output(BL_EN_PIN, 0);
159         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
160 #endif
161         return ret;
162 }
163
164 static int rk29_backlight_io_deinit(void)
165 {
166         int ret = 0;
167 #ifdef  LCD_DISP_ON_PIN
168         gpio_free(BL_EN_PIN);
169 #endif
170         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
171         return ret;
172 }
173
174 static int rk29_backlight_pwm_suspend(void)
175 {
176         int ret = 0;
177         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
178         if (gpio_request(PWM_GPIO, NULL)) {
179                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
180                 return -1;
181         }
182         gpio_direction_output(PWM_GPIO, GPIO_LOW);
183 #ifdef  LCD_DISP_ON_PIN
184         gpio_direction_output(BL_EN_PIN, 0);
185         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
186 #endif
187         return ret;
188 }
189
190 static int rk29_backlight_pwm_resume(void)
191 {
192         gpio_free(PWM_GPIO);
193         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
194 #ifdef  LCD_DISP_ON_PIN
195         msleep(30);
196         gpio_direction_output(BL_EN_PIN, 1);
197         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
198 #endif
199         return 0;
200 }
201
202 static struct rk29_bl_info rk29_bl_info = {
203         .pwm_id = PWM_ID,
204         .bl_ref = PWM_EFFECT_VALUE,
205         .io_init = rk29_backlight_io_init,
206         .io_deinit = rk29_backlight_io_deinit,
207         .pwm_suspend = rk29_backlight_pwm_suspend,
208         .pwm_resume = rk29_backlight_pwm_resume,
209 };
210
211 static struct platform_device rk29_device_backlight = {
212         .name   = "rk29_backlight",
213         .id     = -1,
214         .dev    = {
215                 .platform_data  = &rk29_bl_info,
216         }
217 };
218
219 #endif
220
221 #ifdef CONFIG_RK29_SUPPORT_MODEM
222
223 #define RK30_MODEM_POWER        RK30_PIN2_PB0
224 #define RK30_MODEM_POWER_IOMUX  rk29_mux_api_set(GPIO2B0_LCDC1DATA8_SMCDATA8_TRACEDATA8_NAME, GPIO2B_GPIO2B0)
225
226 static int rk30_modem_io_init(void)
227 {
228     printk("%s\n", __FUNCTION__);
229     RK30_MODEM_POWER_IOMUX;
230
231         return 0;
232 }
233
234 static struct rk29_io_t rk30_modem_io = {
235     .io_addr    = RK30_MODEM_POWER,
236     .enable     = GPIO_HIGH,
237     .disable    = GPIO_LOW,
238     .io_init    = rk30_modem_io_init,
239 };
240
241 static struct platform_device rk30_device_modem = {
242         .name   = "rk30_modem",
243         .id     = -1,
244         .dev    = {
245                 .platform_data  = &rk30_modem_io,
246         }
247 };
248 #endif
249 #if defined(CONFIG_MU509)
250 static int mu509_io_init(void)
251 {
252
253         rk30_mux_api_set(GPIO2B0_LCDC1DATA8_SMCDATA8_TRACEDATA8_NAME, GPIO2B_GPIO2B0);
254        rk30_mux_api_set(GPIO2D1_LCDC1DEN_SMCWEN_NAME, GPIO2D_GPIO2D1);
255         rk30_mux_api_set(GPIO2B7_LCDC1DATA15_SMCADDR19_HSADCDATA7_NAME, GPIO2B_GPIO2B7);
256         rk30_mux_api_set(GPIO2C0_LCDCDATA16_GPSCLK_HSADCCLKOUT_NAME, GPIO2C_GPIO2C0);
257         return 0;
258 }
259
260 static int mu509_io_deinit(void)
261 {
262         
263         return 0;
264 }
265  
266 struct rk29_mu509_data rk29_mu509_info = {
267         .io_init = mu509_io_init,
268         .io_deinit = mu509_io_deinit,
269         .modem_power_en = RK30_PIN2_PB0,
270         .bp_power = RK30_PIN2_PB0,
271         .bp_reset = RK30_PIN2_PD1,
272         .ap_wakeup_bp = RK30_PIN2_PB7,
273         .bp_wakeup_ap = RK30_PIN6_PA0, 
274 };
275 struct platform_device rk29_device_mu509 = {    
276         .name = "mu509",        
277         .id = -1,       
278         .dev            = {
279                 .platform_data = &rk29_mu509_info,
280         }       
281     };
282 #endif
283 #if defined(CONFIG_MW100)
284 static int mw100_io_init(void)
285 {
286          rk30_mux_api_set(GPIO2B0_LCDC1DATA8_SMCDATA8_TRACEDATA8_NAME, GPIO2B_GPIO2B0);
287          rk30_mux_api_set(GPIO2D1_LCDC1DEN_SMCWEN_NAME, GPIO2D_GPIO2D1);
288          rk30_mux_api_set(GPIO2B7_LCDC1DATA15_SMCADDR19_HSADCDATA7_NAME, GPIO2B_GPIO2B7);
289          rk30_mux_api_set(GPIO2C0_LCDCDATA16_GPSCLK_HSADCCLKOUT_NAME, GPIO2C_GPIO2C0);
290         return 0;
291 }
292
293 static int mw100_io_deinit(void)
294 {
295         
296         return 0;
297 }
298  
299 struct rk29_mw100_data rk29_mw100_info = {
300         .io_init = mw100_io_init,
301         .io_deinit = mw100_io_deinit,
302         .modem_power_en = RK30_PIN6_PB0,
303         .bp_power = RK30_PIN2_PB0,
304         .bp_reset = RK30_PIN2_PD1,
305         .ap_wakeup_bp = RK30_PIN2_PB7,
306         .bp_wakeup_ap = RK30_PIN6_PA0,
307 };
308 struct platform_device rk29_device_mw100 = {    
309         .name = "mw100",        
310         .id = -1,       
311         .dev            = {
312                 .platform_data = &rk29_mw100_info,
313         }       
314     };
315 #endif
316 #if defined(CONFIG_MT6229)
317 static int mt6229_io_init(void)
318 {
319          rk30_mux_api_set(GPIO2B0_LCDC1DATA8_SMCDATA8_TRACEDATA8_NAME, GPIO2B_GPIO2B0);
320          rk30_mux_api_set(GPIO2D1_LCDC1DEN_SMCWEN_NAME, GPIO2D_GPIO2D1);
321          rk30_mux_api_set(GPIO2B7_LCDC1DATA15_SMCADDR19_HSADCDATA7_NAME, GPIO2B_GPIO2B7);
322          rk30_mux_api_set(GPIO2C0_LCDCDATA16_GPSCLK_HSADCCLKOUT_NAME, GPIO2C_GPIO2C0);
323         return 0;
324 }
325
326 static int mt6229_io_deinit(void)
327 {
328         
329         return 0;
330 }
331  
332 struct rk29_mt6229_data rk29_mt6229_info = {
333         .io_init = mt6229_io_init,
334         .io_deinit = mt6229_io_deinit,
335         .modem_power_en = RK30_PIN2_PB0,
336         .bp_power = RK30_PIN2_PB0,//RK30_PIN2_PB6,
337         .bp_reset = RK30_PIN2_PD1,
338         .ap_wakeup_bp = RK30_PIN2_PC0,
339         .bp_wakeup_ap = RK30_PIN6_PA0,
340 };
341 struct platform_device rk29_device_mt6229 = {   
342         .name = "mt6229",       
343         .id = -1,       
344         .dev            = {
345                 .platform_data = &rk29_mt6229_info,
346         }       
347     };
348 #endif
349
350 /*MMA8452 gsensor*/
351 #if defined (CONFIG_GS_MMA8452)
352 #define MMA8452_INT_PIN   RK30_PIN3_PD7
353
354 static int mma8452_init_platform_hw(void)
355 {
356         return 0;
357 }
358
359 static struct sensor_platform_data mma8452_info = {
360         .type = SENSOR_TYPE_ACCEL,
361         .irq_enable = 1,
362         .poll_delay_ms = 30,
363         .init_platform_hw = mma8452_init_platform_hw,
364         .orientation = {-1, 0, 0, 0, 0, 1, 0, -1, 0},
365 };
366 #endif
367 #if defined (CONFIG_GS_LIS3DH)
368 #define LIS3DH_INT_PIN   RK30_PIN3_PD7
369
370 static int lis3dh_init_platform_hw(void)
371 {
372
373         return 0;
374 }
375
376 static struct sensor_platform_data lis3dh_info = {
377         .type = SENSOR_TYPE_ACCEL,
378         .irq_enable = 1,
379         .poll_delay_ms = 30,
380         .init_platform_hw = lis3dh_init_platform_hw,
381         .orientation = {-1, 0, 0, 0, 0, 1, 0, -1, 0},
382 };
383 #endif
384 #if defined (CONFIG_COMPASS_AK8975)
385 static struct sensor_platform_data akm8975_info =
386 {
387         .type = SENSOR_TYPE_COMPASS,
388         .irq_enable = 1,
389         .poll_delay_ms = 30,
390         .m_layout = 
391         {
392                 {
393                         {1, 0, 0},
394                         {0, 1, 0},
395                         {0, 0, 1},
396                 },
397
398                 {
399                         {1, 0, 0},
400                         {0, 1, 0},
401                         {0, 0, 1},
402                 },
403
404                 {
405                         {1, 0, 0},
406                         {0, 1, 0},
407                         {0, 0, 1},
408                 },
409
410                 {
411                         {1, 0, 0},
412                         {0, 1, 0},
413                         {0, 0, 1},
414                 },
415         }
416 };
417
418 #endif
419
420 #if defined(CONFIG_GYRO_L3G4200D)
421
422 #include <linux/l3g4200d.h>
423 #define L3G4200D_INT_PIN  RK30_PIN0_PB4
424
425 static int l3g4200d_init_platform_hw(void)
426 {
427         return 0;
428 }
429
430 static struct sensor_platform_data l3g4200d_info = {
431         .type = SENSOR_TYPE_GYROSCOPE,
432         .irq_enable = 1,
433         .poll_delay_ms = 30,
434         .orientation = {0, 1, 0, -1, 0, 0, 0, 0, 1},
435         .init_platform_hw = l3g4200d_init_platform_hw,
436         .x_min = 40,//x_min,y_min,z_min = (0-100) according to hardware
437         .y_min = 40,
438         .z_min = 20,
439 };
440
441 #endif
442
443 #ifdef CONFIG_LS_CM3217
444 static struct sensor_platform_data cm3217_info = {
445         .type = SENSOR_TYPE_LIGHT,
446         .irq_enable = 0,
447         .poll_delay_ms = 500,
448 };
449
450 #endif
451
452 #ifdef CONFIG_FB_ROCKCHIP
453
454 #define LCD_CS_PIN         RK30_PIN0_PB0
455 #define LCD_CS_VALUE       GPIO_HIGH
456
457 #define LCD_EN_PIN         RK30_PIN0_PB0
458 #define LCD_EN_VALUE       GPIO_LOW
459
460 static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
461 {
462         int ret = 0;
463         ret = gpio_request(LCD_CS_PIN, NULL);
464         if (ret != 0)
465         {
466                 gpio_free(LCD_CS_PIN);
467                 printk(KERN_ERR "request lcd cs pin fail!\n");
468                 return -1;
469         }
470         else
471         {
472                 gpio_direction_output(LCD_CS_PIN, LCD_CS_VALUE);
473         }
474         ret = gpio_request(LCD_EN_PIN, NULL);
475         if (ret != 0)
476         {
477                 gpio_free(LCD_EN_PIN);
478                 printk(KERN_ERR "request lcd en pin fail!\n");
479                 return -1;
480         }
481         else
482         {
483                 gpio_direction_output(LCD_EN_PIN, LCD_EN_VALUE);
484         }
485         return 0;
486 }
487 static int rk_fb_io_disable(void)
488 {
489         gpio_set_value(LCD_CS_PIN, LCD_CS_VALUE? 0:1);
490         gpio_set_value(LCD_EN_PIN, LCD_EN_VALUE? 0:1);
491         return 0;
492 }
493 static int rk_fb_io_enable(void)
494 {
495         gpio_set_value(LCD_CS_PIN, LCD_CS_VALUE);
496         gpio_set_value(LCD_EN_PIN, LCD_EN_VALUE);
497         return 0;
498 }
499
500 #if defined(CONFIG_LCDC0_RK31)
501 struct rk29fb_info lcdc0_screen_info = {
502         .prop      = PRMRY,             //primary display device
503         .io_init   = rk_fb_io_init,
504         .io_disable = rk_fb_io_disable,
505         .io_enable = rk_fb_io_enable,
506         .set_screen_info = set_lcd_info,
507 };
508 #endif
509
510 #if defined(CONFIG_LCDC1_RK31)
511 struct rk29fb_info lcdc1_screen_info = {
512         #if defined(CONFIG_HDMI_RK30)
513         .prop           = EXTEND,       //extend display device
514         .lcd_info  = NULL,
515         .set_screen_info = hdmi_init_lcdc,
516         #endif
517 };
518 #endif
519
520 static struct resource resource_fb[] = {
521         [0] = {
522                 .name  = "fb0 buf",
523                 .start = 0,
524                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
525                 .flags = IORESOURCE_MEM,
526         },
527         [1] = {
528                 .name  = "ipp buf",  //for rotate
529                 .start = 0,
530                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
531                 .flags = IORESOURCE_MEM,
532         },
533         [2] = {
534                 .name  = "fb2 buf",
535                 .start = 0,
536                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
537                 .flags = IORESOURCE_MEM,
538         },
539 };
540
541 static struct platform_device device_fb = {
542         .name           = "rk-fb",
543         .id             = -1,
544         .num_resources  = ARRAY_SIZE(resource_fb),
545         .resource       = resource_fb,
546 };
547 #endif
548
549 #if defined(CONFIG_LCDC0_RK31)
550 static struct resource resource_lcdc0[] = {
551         [0] = {
552                 .name  = "lcdc0 reg",
553                 .start = RK30_LCDC0_PHYS,
554                 .end   = RK30_LCDC0_PHYS + RK30_LCDC0_SIZE - 1,
555                 .flags = IORESOURCE_MEM,
556         },
557         
558         [1] = {
559                 .name  = "lcdc0 irq",
560                 .start = IRQ_LCDC0,
561                 .end   = IRQ_LCDC0,
562                 .flags = IORESOURCE_IRQ,
563         },
564 };
565
566 static struct platform_device device_lcdc0 = {
567         .name             = "rk30-lcdc",
568         .id               = 0,
569         .num_resources    = ARRAY_SIZE(resource_lcdc0),
570         .resource         = resource_lcdc0,
571         .dev            = {
572                 .platform_data = &lcdc0_screen_info,
573         },
574 };
575 #endif
576 #if defined(CONFIG_LCDC1_RK31) 
577 static struct resource resource_lcdc1[] = {
578         [0] = {
579                 .name  = "lcdc1 reg",
580                 .start = RK30_LCDC1_PHYS,
581                 .end   = RK30_LCDC1_PHYS + RK30_LCDC1_SIZE - 1,
582                 .flags = IORESOURCE_MEM,
583         },
584         [1] = {
585                 .name  = "lcdc1 irq",
586                 .start = IRQ_LCDC1,
587                 .end   = IRQ_LCDC1,
588                 .flags = IORESOURCE_IRQ,
589         },
590 };
591
592 static struct platform_device device_lcdc1 = {
593         .name             = "rk30-lcdc",
594         .id               = 1,
595         .num_resources    = ARRAY_SIZE(resource_lcdc1),
596         .resource         = resource_lcdc1,
597         .dev            = {
598                 .platform_data = &lcdc1_screen_info,
599         },
600 };
601 #endif
602
603 #ifdef CONFIG_ANDROID_TIMED_GPIO
604 static struct timed_gpio timed_gpios[] = {
605         {
606                 .name = "vibrator",
607                 .gpio = RK30_PIN0_PA4,
608                 .max_timeout = 1000,
609                 .active_low = 0,
610                 .adjust_time =20,      //adjust for diff product
611         },
612 };
613
614 static struct timed_gpio_platform_data rk29_vibrator_info = {
615         .num_gpios = 1,
616         .gpios = timed_gpios,
617 };
618
619 static struct platform_device rk29_device_vibrator = {
620         .name = "timed-gpio",
621         .id = -1,
622         .dev = {
623                 .platform_data = &rk29_vibrator_info,
624         },
625
626 };
627 #endif
628
629 #ifdef CONFIG_LEDS_GPIO_PLATFORM
630 static struct gpio_led rk29_leds[] = {
631         {
632                 .name = "button-backlight",
633                 .gpio = RK30_PIN2_PB3,
634                 .default_trigger = "timer",
635                 .active_low = 0,
636                 .retain_state_suspended = 0,
637                 .default_state = LEDS_GPIO_DEFSTATE_OFF,
638         },
639 };
640
641 static struct gpio_led_platform_data rk29_leds_pdata = {
642         .leds = rk29_leds,
643         .num_leds = ARRAY_SIZE(rk29_leds),
644 };
645
646 static struct platform_device rk29_device_gpio_leds = {
647         .name   = "leds-gpio",
648         .id     = -1,
649         .dev    = {
650                 .platform_data  = &rk29_leds_pdata,
651         },
652 };
653 #endif
654
655 #ifdef CONFIG_RK_IRDA
656 #define IRDA_IRQ_PIN           RK30_PIN0_PA3
657
658 static int irda_iomux_init(void)
659 {
660         int ret = 0;
661
662         //irda irq pin
663         ret = gpio_request(IRDA_IRQ_PIN, NULL);
664         if (ret != 0) {
665                 gpio_free(IRDA_IRQ_PIN);
666                 printk(">>>>>> IRDA_IRQ_PIN gpio_request err \n ");
667         }
668         gpio_pull_updown(IRDA_IRQ_PIN, PullDisable);
669         gpio_direction_input(IRDA_IRQ_PIN);
670
671         return 0;
672 }
673
674 static int irda_iomux_deinit(void)
675 {
676         gpio_free(IRDA_IRQ_PIN);
677         return 0;
678 }
679
680 static struct irda_info rk29_irda_info = {
681         .intr_pin = IRDA_IRQ_PIN,
682         .iomux_init = irda_iomux_init,
683         .iomux_deinit = irda_iomux_deinit,
684         //.irda_pwr_ctl = bu92747guw_power_ctl,
685 };
686
687 static struct platform_device irda_device = {
688 #ifdef CONFIG_RK_IRDA_NET
689         .name = "rk_irda",
690 #else
691         .name = "bu92747_irda",
692 #endif
693         .id = -1,
694         .dev = {
695                 .platform_data = &rk29_irda_info,
696         }
697 };
698 #endif
699
700 #ifdef CONFIG_ION
701 #define ION_RESERVE_SIZE        (80 * SZ_1M)
702 static struct ion_platform_data rk30_ion_pdata = {
703         .nr = 1,
704         .heaps = {
705                 {
706                         .type = ION_HEAP_TYPE_CARVEOUT,
707                         .id = ION_NOR_HEAP_ID,
708                         .name = "norheap",
709                         .size = ION_RESERVE_SIZE,
710                 }
711         },
712 };
713
714 static struct platform_device device_ion = {
715         .name = "ion-rockchip",
716         .id = 0,
717         .dev = {
718                 .platform_data = &rk30_ion_pdata,
719         },
720 };
721 #endif
722
723 /**************************************************************************************************
724  * SDMMC devices,  include the module of SD,MMC,and sdio.noted by xbw at 2012-03-05
725 **************************************************************************************************/
726 #ifdef CONFIG_SDMMC_RK29
727 #include "board-rk3066b-sdk-sdmmc.c"
728
729 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
730 #define SDMMC0_WRITE_PROTECT_PIN        RK30_PIN3_PB7   //According to your own project to set the value of write-protect-pin.
731 #endif
732
733 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
734 #define SDMMC1_WRITE_PROTECT_PIN        RK30_PIN3_PC7   //According to your own project to set the value of write-protect-pin.
735 #endif
736
737 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK30_PIN6_PB2
738
739 #endif //endif ---#ifdef CONFIG_SDMMC_RK29
740
741 #ifdef CONFIG_SDMMC0_RK29
742 static int rk29_sdmmc0_cfg_gpio(void)
743 {
744 #ifdef CONFIG_SDMMC_RK29_OLD
745         rk30_mux_api_set(GPIO3B1_SDMMC0CMD_NAME, GPIO3B_SDMMC0_CMD);
746         rk30_mux_api_set(GPIO3B0_SDMMC0CLKOUT_NAME, GPIO3B_SDMMC0_CLKOUT);
747         rk30_mux_api_set(GPIO3B2_SDMMC0DATA0_NAME, GPIO3B_SDMMC0_DATA0);
748         rk30_mux_api_set(GPIO3B3_SDMMC0DATA1_NAME, GPIO3B_SDMMC0_DATA1);
749         rk30_mux_api_set(GPIO3B4_SDMMC0DATA2_NAME, GPIO3B_SDMMC0_DATA2);
750         rk30_mux_api_set(GPIO3B5_SDMMC0DATA3_NAME, GPIO3B_SDMMC0_DATA3);
751
752         rk30_mux_api_set(GPIO3B6_SDMMC0DETECTN_NAME, GPIO3B_GPIO3B6);
753
754         rk30_mux_api_set(GPIO3A7_SDMMC0PWREN_NAME, GPIO3A_GPIO3A7);
755         gpio_request(RK30_PIN3_PA7, "sdmmc-power");
756         gpio_direction_output(RK30_PIN3_PA7, GPIO_LOW);
757
758 #else
759         rk29_sdmmc_set_iomux(0, 0xFFFF);
760
761         rk30_mux_api_set(GPIO3B0_SDMMC0DETECTN_NAME, GPIO3B_SDMMC0DETECTN);
762
763 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
764         gpio_request(SDMMC0_WRITE_PROTECT_PIN, "sdmmc-wp");
765         gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);
766 #endif
767
768 #endif
769
770         return 0;
771 }
772
773 #define CONFIG_SDMMC0_USE_DMA
774 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
775         .host_ocr_avail =
776             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
777              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
778              MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36),
779         .host_caps =
780             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
781         .io_init = rk29_sdmmc0_cfg_gpio,
782
783 #if !defined(CONFIG_SDMMC_RK29_OLD)
784         .set_iomux = rk29_sdmmc_set_iomux,
785 #endif
786
787         .dma_name = "sd_mmc",
788 #ifdef CONFIG_SDMMC0_USE_DMA
789         .use_dma = 1,
790 #else
791         .use_dma = 0,
792 #endif
793         .detect_irq = RK30_PIN3_PB6,    // INVALID_GPIO
794         .enable_sd_wakeup = 0,
795
796 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
797         .write_prt = SDMMC0_WRITE_PROTECT_PIN,
798 #else
799         .write_prt = INVALID_GPIO,
800 #endif
801 };
802 #endif // CONFIG_SDMMC0_RK29
803
804 #ifdef CONFIG_SDMMC1_RK29
805 #define CONFIG_SDMMC1_USE_DMA
806 static int rk29_sdmmc1_cfg_gpio(void)
807 {
808 #if defined(CONFIG_SDMMC_RK29_OLD)
809         rk30_mux_api_set(GPIO3C0_SMMC1CMD_NAME, GPIO3C_SMMC1_CMD);
810         rk30_mux_api_set(GPIO3C5_SDMMC1CLKOUT_NAME, GPIO3C_SDMMC1_CLKOUT);
811         rk30_mux_api_set(GPIO3C1_SDMMC1DATA0_NAME, GPIO3C_SDMMC1_DATA0);
812         rk30_mux_api_set(GPIO3C2_SDMMC1DATA1_NAME, GPIO3C_SDMMC1_DATA1);
813         rk30_mux_api_set(GPIO3C3_SDMMC1DATA2_NAME, GPIO3C_SDMMC1_DATA2);
814         rk30_mux_api_set(GPIO3C4_SDMMC1DATA3_NAME, GPIO3C_SDMMC1_DATA3);
815         //rk30_mux_api_set(GPIO3C6_SDMMC1DETECTN_NAME, GPIO3C_SDMMC1_DETECT_N);
816
817 #else
818
819 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
820         gpio_request(SDMMC1_WRITE_PROTECT_PIN, "sdio-wp");
821         gpio_direction_input(SDMMC1_WRITE_PROTECT_PIN);
822 #endif
823
824 #endif
825
826         return 0;
827 }
828
829 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
830         .host_ocr_avail =
831             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
832              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
833              MMC_VDD_33_34),
834
835 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
836         .host_caps = (MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ |
837                       MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
838 #else
839         .host_caps =
840             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
841 #endif
842
843         .io_init = rk29_sdmmc1_cfg_gpio,
844
845 #if !defined(CONFIG_SDMMC_RK29_OLD)
846         .set_iomux = rk29_sdmmc_set_iomux,
847 #endif
848
849         .dma_name = "sdio",
850 #ifdef CONFIG_SDMMC1_USE_DMA
851         .use_dma = 1,
852 #else
853         .use_dma = 0,
854 #endif
855
856 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
857 #ifdef CONFIG_WIFI_CONTROL_FUNC
858         .status = rk29sdk_wifi_status,
859         .register_status_notify = rk29sdk_wifi_status_register,
860 #endif
861 #if 0
862         .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
863 #endif
864
865 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
866         .write_prt = SDMMC1_WRITE_PROTECT_PIN,
867 #else
868         .write_prt = INVALID_GPIO,
869 #endif
870
871 #else
872         .detect_irq = INVALID_GPIO,
873         .enable_sd_wakeup = 0,
874 #endif
875
876 };
877 #endif //endif--#ifdef CONFIG_SDMMC1_RK29
878
879 /**************************************************************************************************
880  * the end of setting for SDMMC devices
881 **************************************************************************************************/
882
883 #ifdef CONFIG_BATTERY_RK30_ADC
884 static struct rk30_adc_battery_platform_data rk30_adc_battery_platdata = {
885         .dc_det_pin      = RK30_PIN0_PB2,
886         .batt_low_pin    = RK30_PIN0_PB1, 
887         .charge_set_pin  = INVALID_GPIO,
888         .charge_ok_pin   = RK30_PIN0_PA6,
889         .dc_det_level    = GPIO_LOW,
890         .charge_ok_level = GPIO_HIGH,
891 };
892
893 static struct platform_device rk30_device_adc_battery = {
894         .name   = "rk30-battery",
895         .id     = -1,
896         .dev = {
897                 .platform_data = &rk30_adc_battery_platdata,
898         },
899 };
900 #endif
901 #ifdef CONFIG_RK30_PWM_REGULATOR
902 const static int pwm_voltage_map[] = {
903         1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000, 1400000
904 };
905
906 static struct regulator_consumer_supply pwm_dcdc1_consumers[] = {
907         {
908                 .supply = "vdd_core",
909         }
910 };
911
912 struct regulator_init_data pwm_regulator_init_dcdc[1] =
913 {
914         {
915                 .constraints = {
916                         .name = "PWM_DCDC1",
917                         .min_uV = 600000,
918                         .max_uV = 1800000,      //0.6-1.8V
919                         .apply_uV = true,
920                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
921                 },
922                 .num_consumer_supplies = ARRAY_SIZE(pwm_dcdc1_consumers),
923                 .consumer_supplies = pwm_dcdc1_consumers,
924         },
925 };
926
927 static struct pwm_platform_data pwm_regulator_info[1] = {
928         {
929                 .pwm_id = 3,
930                 .pwm_gpio = RK30_PIN3_PD6,
931                 .pwm_iomux_name = GPIO3D6_PWM3_JTAGTMS_HOSTDRVVBUS_NAME,
932                 .pwm_iomux_pwm = GPIO3D_PWM3,
933                 .pwm_iomux_gpio = GPIO3D_GPIO3D6,
934                 .pwm_voltage = 1100000,
935                 .suspend_voltage = 1050000,
936                 .min_uV = 1000000,
937                 .max_uV = 1400000,
938                 .coefficient = 455,     //45.5%
939                 .pwm_voltage_map = pwm_voltage_map,
940                 .init_data      = &pwm_regulator_init_dcdc[0],
941         },
942 };
943
944 struct platform_device pwm_regulator_device[1] = {
945         {
946                 .name = "pwm-voltage-regulator",
947                 .id = 0,
948                 .dev            = {
949                         .platform_data = &pwm_regulator_info[0],
950                 }
951         },
952 };
953 #endif
954
955 #ifdef CONFIG_RK29_VMAC
956 #define PHY_PWR_EN_GPIO RK30_PIN1_PD6
957 #include "board-rk30-sdk-vmac.c"
958 #endif
959
960 #ifdef CONFIG_RFKILL_RK
961 // bluetooth rfkill device, its driver in net/rfkill/rfkill-rk.c
962 static struct rfkill_rk_platform_data rfkill_rk_platdata = {
963     .type               = RFKILL_TYPE_BLUETOOTH,
964
965     .poweron_gpio       = { // BT_REG_ON
966         .io             = RK30_PIN3_PC6, 
967         .enable         = GPIO_HIGH,
968         .iomux          = {
969             .name       = GPIO3C6_SDMMC1DETECTN_RMIIRXERR_NAME,
970             .fgpio      = GPIO3C_GPIO3C6,
971         },
972     },
973
974     .reset_gpio         = { // BT_RST
975         .io             = RK30_PIN3_PD0, // set io to INVALID_GPIO for disable it
976         .enable         = GPIO_LOW,
977         .iomux          = {
978             .name       = GPIO3D0_SDMMC1PWREN_MIIMD_NAME,
979             .fgpio      = GPIO3D_GPIO3D0,
980         },
981     },
982
983     .wake_gpio          = { // BT_WAKE, use to control bt's sleep and wakeup
984         .io             = RK30_PIN3_PC5, // set io to INVALID_GPIO for disable it
985         .enable         = GPIO_HIGH,
986         .iomux          = {
987             .name       = GPIO3C5_SDMMC1CLKOUT_RMIICLKOUT_RMIICLKIN_NAME,
988             .fgpio      = GPIO3C_GPIO3C5,
989         },
990     },
991
992     .wake_host_irq      = { // BT_HOST_WAKE, for bt wakeup host when it is in deep sleep
993         .gpio           = {
994             .io         = RK30_PIN0_PA5, // set io to INVALID_GPIO for disable it
995             .enable     = GPIO_LOW,      // set GPIO_LOW for falling, set 0 for rising
996             .iomux      = {
997                 .name   = NULL,
998             },
999         },
1000     },
1001
1002     .rts_gpio           = { // UART_RTS, enable or disable BT's data coming
1003         .io             = RK30_PIN1_PA3, // set io to INVALID_GPIO for disable it
1004         .enable         = GPIO_LOW,
1005         .iomux          = {
1006             .name       = GPIO1A3_UART0RTSN_NAME,
1007             .fgpio      = GPIO1A_GPIO1A3,
1008             .fmux       = GPIO1A_UART0RTSN,
1009         },
1010     },
1011 };
1012
1013 static struct platform_device device_rfkill_rk = {
1014     .name   = "rfkill_rk",
1015     .id     = -1,
1016     .dev    = {
1017         .platform_data = &rfkill_rk_platdata,
1018     },
1019 };
1020 #endif
1021
1022 static struct platform_device *devices[] __initdata = {
1023 #ifdef CONFIG_FB_ROCKCHIP
1024         &device_fb,
1025 #endif
1026 #if defined(CONFIG_LCDC0_RK31)
1027         &device_lcdc0,
1028 #endif
1029 #if defined(CONFIG_LCDC1_RK31)
1030         &device_lcdc1,
1031 #endif
1032                 
1033 #ifdef CONFIG_BACKLIGHT_RK29_BL
1034         &rk29_device_backlight,
1035 #endif
1036
1037 #ifdef CONFIG_ION
1038         &device_ion,
1039 #endif
1040 #ifdef CONFIG_ANDROID_TIMED_GPIO
1041         &rk29_device_vibrator,
1042 #endif
1043 #ifdef CONFIG_LEDS_GPIO_PLATFORM
1044         &rk29_device_gpio_leds,
1045 #endif
1046 #ifdef CONFIG_RK_IRDA
1047         &irda_device,
1048 #endif
1049 #ifdef CONFIG_WIFI_CONTROL_FUNC
1050         &rk29sdk_wifi_device,
1051 #endif
1052 #ifdef CONFIG_RK29_SUPPORT_MODEM
1053         &rk30_device_modem,
1054 #endif
1055 #if defined(CONFIG_MU509)
1056         &rk29_device_mu509,
1057 #endif
1058 #if defined(CONFIG_MW100)
1059         &rk29_device_mw100,
1060 #endif
1061 #if defined(CONFIG_MT6229)
1062         &rk29_device_mt6229,
1063 #endif
1064 #ifdef CONFIG_BATTERY_RK30_ADC
1065         &rk30_device_adc_battery,
1066 #endif
1067 #ifdef CONFIG_RFKILL_RK
1068         &device_rfkill_rk,
1069 #endif
1070 };
1071
1072 // i2c
1073 #ifdef CONFIG_I2C0_RK30
1074 static struct i2c_board_info __initdata i2c0_info[] = {
1075 #if defined (CONFIG_GS_MMA8452)
1076         {
1077                 .type           = "gs_mma8452",
1078                 .addr           = 0x1d,
1079                 .flags          = 0,
1080                 .irq            = MMA8452_INT_PIN,
1081                 .platform_data = &mma8452_info,
1082         },
1083 #endif
1084 #if defined (CONFIG_GS_LIS3DH)
1085         {
1086                 .type           = "gs_lis3dh",
1087                 .addr           = 0x19,   //0x19(SA0-->VCC), 0x18(SA0-->GND)
1088                 .flags          = 0,
1089                 .irq            = LIS3DH_INT_PIN,
1090                 .platform_data = &lis3dh_info,
1091         },
1092 #endif
1093 #if defined (CONFIG_COMPASS_AK8975)
1094         {
1095                 .type          = "ak8975",
1096                 .addr          = 0x0d,
1097                 .flags         = 0,
1098                 .irq           = RK30_PIN0_PD5,
1099                 .platform_data = &akm8975_info,
1100         },
1101 #endif
1102 #if defined (CONFIG_GYRO_L3G4200D)
1103         {
1104                 .type          = "l3g4200d_gryo",
1105                 .addr          = 0x69,
1106                 .flags         = 0,
1107                 .irq           = L3G4200D_INT_PIN,
1108                 .platform_data = &l3g4200d_info,
1109         },
1110 #endif
1111 #if defined (CONFIG_SND_SOC_RK1000)
1112         {
1113                 .type          = "rk1000_i2c_codec",
1114                 .addr          = 0x60,
1115                 .flags         = 0,
1116         },
1117         {
1118                 .type          = "rk1000_control",
1119                 .addr          = 0x40,
1120                 .flags         = 0,
1121         },
1122 #endif
1123 #if defined (CONFIG_SND_SOC_RT5631)
1124         {
1125                 .type                   = "rt5631",
1126                 .addr                   = 0x1a,
1127                 .flags                  = 0,
1128         },
1129 #endif
1130
1131 #ifdef CONFIG_MFD_RK610
1132                 {
1133                         .type                   = "rk610_ctl",
1134                         .addr                   = 0x40,
1135                         .flags                  = 0,
1136                 },
1137 #ifdef CONFIG_RK610_TVOUT
1138                 {
1139                         .type                   = "rk610_tvout",
1140                         .addr                   = 0x42,
1141                         .flags                  = 0,
1142                 },
1143 #endif
1144 #ifdef CONFIG_RK610_HDMI
1145                 {
1146                         .type                   = "rk610_hdmi",
1147                         .addr                   = 0x46,
1148                         .flags                  = 0,
1149                         .irq                    = RK29_PIN5_PA2,
1150                 },
1151 #endif
1152 #ifdef CONFIG_SND_SOC_RK610
1153                 {//RK610_CODEC addr  from 0x60 to 0x80 (0x60~0x80)
1154                         .type                   = "rk610_i2c_codec",
1155                         .addr                   = 0x60,
1156                         .flags                  = 0,
1157                 },
1158 #endif
1159 #endif
1160
1161 };
1162 #endif
1163
1164 #define PMIC_TYPE_WM8326        1
1165 #define PMIC_TYPE_TPS65910      2
1166 int __sramdata g_pmic_type =  0;
1167 #ifdef CONFIG_I2C1_RK30
1168 #ifdef CONFIG_MFD_WM831X_I2C
1169 #include "board-rk3066b-sdk-wm8326.c"
1170 #endif
1171 #ifdef CONFIG_MFD_TPS65910
1172 #define TPS65910_HOST_IRQ        RK30_PIN6_PA4
1173 #include "board-rk3066b-sdk-tps65910.c"
1174 #endif
1175
1176 static struct i2c_board_info __initdata i2c1_info[] = {
1177 #if defined (CONFIG_MFD_WM831X_I2C)
1178         {
1179                 .type          = "wm8326",
1180                 .addr          = 0x34,
1181                 .flags         = 0,
1182                 .irq           = RK30_PIN0_PB3,
1183                 .platform_data = &wm831x_platdata,
1184         },
1185 #endif
1186 #if defined (CONFIG_MFD_TPS65910)
1187         {
1188         .type           = "tps65910",
1189         .addr           = TPS65910_I2C_ID0,
1190         .flags          = 0,
1191         .irq            = TPS65910_HOST_IRQ,
1192         .platform_data = &tps65910_data,
1193         },
1194 #endif
1195 };
1196 #endif
1197
1198 void __sramfunc board_pmu_suspend(void)
1199 {      
1200         #if defined (CONFIG_MFD_WM831X_I2C)
1201        if(g_pmic_type == PMIC_TYPE_WM8326)
1202        board_pmu_wm8326_suspend();
1203         #endif
1204         #if defined (CONFIG_MFD_TPS65910)
1205        if(g_pmic_type == PMIC_TYPE_TPS65910)
1206        board_pmu_tps65910_suspend(); 
1207     #endif   
1208 }
1209
1210 void __sramfunc board_pmu_resume(void)
1211 {      
1212         #if defined (CONFIG_MFD_WM831X_I2C)
1213        if(g_pmic_type == PMIC_TYPE_WM8326)
1214        board_pmu_wm8326_resume();
1215         #endif
1216         #if defined (CONFIG_MFD_TPS65910)
1217        if(g_pmic_type == PMIC_TYPE_TPS65910)
1218        board_pmu_tps65910_resume(); 
1219         #endif
1220 }
1221
1222  int __sramdata gpio0d7_iomux,gpio0d7_do,gpio0d7_dir,gpio0d7_en;
1223
1224 void __sramfunc rk30_pwm_logic_suspend_voltage(void)
1225 {
1226 #ifdef CONFIG_RK30_PWM_REGULATOR
1227
1228 //      int gpio0d7_iomux,gpio0d7_do,gpio0d7_dir,gpio0d7_en;
1229         sram_udelay(10000);
1230         gpio0d7_iomux = readl_relaxed(GRF_GPIO0D_IOMUX);
1231         gpio0d7_do = grf_readl(GRF_GPIO0H_DO);
1232         gpio0d7_dir = grf_readl(GRF_GPIO0H_DIR);
1233         gpio0d7_en = grf_readl(GRF_GPIO0H_EN);
1234
1235         writel_relaxed((1<<30), GRF_GPIO0D_IOMUX);
1236         grf_writel((1<<31)|(1<<15), GRF_GPIO0H_DIR);
1237         grf_writel((1<<31)|(1<<15), GRF_GPIO0H_DO);
1238         grf_writel((1<<31)|(1<<15), GRF_GPIO0H_EN);
1239 #endif 
1240 }
1241 void __sramfunc rk30_pwm_logic_resume_voltage(void)
1242 {
1243 #ifdef CONFIG_RK30_PWM_REGULATOR
1244         writel_relaxed((1<<30)|gpio0d7_iomux, GRF_GPIO0D_IOMUX);
1245         grf_writel((1<<31)|gpio0d7_en, GRF_GPIO0H_EN);
1246         grf_writel((1<<31)|gpio0d7_dir, GRF_GPIO0H_DIR);
1247         grf_writel((1<<31)|gpio0d7_do, GRF_GPIO0H_DO);
1248         sram_udelay(10000);
1249
1250 #endif
1251
1252 }
1253 extern void pwm_suspend_voltage(void);
1254 extern void pwm_resume_voltage(void);
1255 void  rk30_pwm_suspend_voltage_set(void)
1256 {
1257 #ifdef CONFIG_RK30_PWM_REGULATOR
1258         pwm_suspend_voltage();
1259 #endif
1260 }
1261 void  rk30_pwm_resume_voltage_set(void)
1262 {
1263 #ifdef CONFIG_RK30_PWM_REGULATOR
1264         pwm_resume_voltage();
1265 #endif
1266 }
1267
1268
1269 #ifdef CONFIG_I2C2_RK30
1270 static struct i2c_board_info __initdata i2c2_info[] = {
1271 #if defined (CONFIG_TOUCHSCREEN_GT8XX)
1272         {
1273                 .type          = "Goodix-TS",
1274                 .addr          = 0x55,
1275                 .flags         = 0,
1276                 .irq           = RK30_PIN0_PD4,
1277                 .platform_data = &goodix_info,
1278         },
1279 #endif
1280 #if defined (CONFIG_LS_CM3217)
1281         {
1282                 .type          = "lightsensor",
1283                 .addr          = 0x10,
1284                 .flags         = 0,
1285                 .platform_data = &cm3217_info,
1286         },
1287 #endif
1288 };
1289 #endif
1290
1291 #ifdef CONFIG_I2C3_RK30
1292 static struct i2c_board_info __initdata i2c3_info[] = {
1293 };
1294 #endif
1295
1296 #ifdef CONFIG_I2C4_RK30
1297 static struct i2c_board_info __initdata i2c4_info[] = {
1298 };
1299 #endif
1300
1301 #ifdef CONFIG_I2C_GPIO_RK30
1302 #define I2C_SDA_PIN     INVALID_GPIO// RK30_PIN2_PD6   //set sda_pin here
1303 #define I2C_SCL_PIN     INVALID_GPIO//RK30_PIN2_PD7   //set scl_pin here
1304 static int rk30_i2c_io_init(void)
1305 {
1306         //set iomux (gpio) here
1307         //rk30_mux_api_set(GPIO2D7_I2C1SCL_NAME, GPIO2D_GPIO2D7);
1308         //rk30_mux_api_set(GPIO2D6_I2C1SDA_NAME, GPIO2D_GPIO2D6);
1309
1310         return 0;
1311 }
1312 struct i2c_gpio_platform_data default_i2c_gpio_data = {
1313        .sda_pin = I2C_SDA_PIN,
1314        .scl_pin = I2C_SCL_PIN,
1315        .udelay = 5, // clk = 500/udelay = 100Khz
1316        .timeout = 100,//msecs_to_jiffies(100),
1317        .bus_num    = 5,
1318        .io_init = rk30_i2c_io_init,
1319 };
1320 static struct i2c_board_info __initdata i2c_gpio_info[] = {
1321 };
1322 #endif
1323
1324 static void __init rk30_i2c_register_board_info(void)
1325 {
1326 #ifdef CONFIG_I2C0_RK30
1327         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
1328 #endif
1329 #ifdef CONFIG_I2C1_RK30
1330         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
1331 #endif
1332 #ifdef CONFIG_I2C2_RK30
1333         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
1334 #endif
1335 #ifdef CONFIG_I2C3_RK30
1336         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
1337 #endif
1338 #ifdef CONFIG_I2C4_RK30
1339         i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info));
1340 #endif
1341 #ifdef CONFIG_I2C_GPIO_RK30
1342         i2c_register_board_info(5, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info));
1343 #endif
1344 }
1345 //end of i2c
1346
1347 #define POWER_ON_PIN RK30_PIN0_PA0   //power_hold
1348 static void rk30_pm_power_off(void)
1349 {
1350         printk(KERN_ERR "rk30_pm_power_off start...\n");
1351         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
1352 #if defined(CONFIG_MFD_WM831X)
1353         wm831x_set_bits(Wm831x,WM831X_GPIO_LEVEL,0x0001,0x0000);  //set sys_pwr 0
1354         wm831x_device_shutdown(Wm831x);//wm8326 shutdown
1355 #endif
1356         while (1);
1357 }
1358
1359 static void __init machine_rk30_board_init(void)
1360 {
1361         avs_init();
1362         gpio_request(POWER_ON_PIN, "poweronpin");
1363         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
1364         
1365         pm_power_off = rk30_pm_power_off;
1366         
1367         rk30_i2c_register_board_info();
1368         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1369         platform_add_devices(devices, ARRAY_SIZE(devices));
1370         board_usb_detect_init(RK30_PIN0_PA7);
1371
1372 #ifdef CONFIG_WIFI_CONTROL_FUNC
1373         rk29sdk_wifi_bt_gpio_control_init();
1374 #endif
1375 }
1376
1377 static void __init rk30_reserve(void)
1378 {
1379 #ifdef CONFIG_ION
1380         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion", ION_RESERVE_SIZE);
1381 #endif
1382 #ifdef CONFIG_FB_ROCKCHIP
1383         resource_fb[0].start = board_mem_reserve_add("fb0", RK30_FB0_MEM_SIZE);
1384         resource_fb[0].end = resource_fb[0].start + RK30_FB0_MEM_SIZE - 1;
1385         resource_fb[1].start = board_mem_reserve_add("ipp buf", RK30_FB0_MEM_SIZE);
1386         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
1387         resource_fb[2].start = board_mem_reserve_add("fb2", RK30_FB0_MEM_SIZE);
1388         resource_fb[2].end = resource_fb[2].start + RK30_FB0_MEM_SIZE - 1;
1389 #endif
1390 #ifdef CONFIG_VIDEO_RK29
1391         rk30_camera_request_reserve_mem();
1392 #endif
1393         board_mem_reserved();
1394 }
1395
1396 /**
1397  * dvfs_cpu_logic_table: table for arm and logic dvfs 
1398  * @frequency   : arm frequency
1399  * @cpu_volt    : arm voltage depend on frequency
1400  * @logic_volt  : logic voltage arm requests depend on frequency
1401  * comments     : min arm/logic voltage
1402  */
1403 static struct dvfs_arm_table dvfs_cpu_logic_table[] = {
1404         {.frequency = 252 * 1000,       .cpu_volt = 1075 * 1000,        .logic_volt = 1125 * 1000},//0.975V/1.000V
1405         {.frequency = 504 * 1000,       .cpu_volt = 1100 * 1000,        .logic_volt = 1125 * 1000},//0.975V/1.000V
1406         {.frequency = 816 * 1000,       .cpu_volt = 1125 * 1000,        .logic_volt = 1150 * 1000},//1.000V/1.025V
1407         {.frequency = 1008 * 1000,      .cpu_volt = 1125 * 1000,        .logic_volt = 1150 * 1000},//1.025V/1.050V
1408         {.frequency = 1200 * 1000,      .cpu_volt = 1175 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
1409         {.frequency = 1272 * 1000,      .cpu_volt = 1225 * 1000,        .logic_volt = 1200 * 1000},//1.150V/1.100V
1410         {.frequency = 1416 * 1000,      .cpu_volt = 1300 * 1000,        .logic_volt = 1200 * 1000},//1.225V/1.100V
1411         {.frequency = 1512 * 1000,      .cpu_volt = 1350 * 1000,        .logic_volt = 1250 * 1000},//1.300V/1.150V
1412         {.frequency = 1608 * 1000,      .cpu_volt = 1425 * 1000,        .logic_volt = 1300 * 1000},//1.325V/1.175V
1413         {.frequency = CPUFREQ_TABLE_END},
1414 };
1415
1416 static struct cpufreq_frequency_table dvfs_gpu_table[] = {
1417         {.frequency = 266 * 1000,       .index = 1050 * 1000},
1418         {.frequency = 400 * 1000,       .index = 1275 * 1000},
1419         {.frequency = CPUFREQ_TABLE_END},
1420 };
1421
1422 static struct cpufreq_frequency_table dvfs_ddr_table[] = {
1423         {.frequency = 300 * 1000,       .index = 1050 * 1000},
1424         {.frequency = 400 * 1000,       .index = 1125 * 1000},
1425         {.frequency = CPUFREQ_TABLE_END},
1426 };
1427
1428 #define DVFS_CPU_TABLE_SIZE     (ARRAY_SIZE(dvfs_cpu_logic_table))
1429 static struct cpufreq_frequency_table cpu_dvfs_table[DVFS_CPU_TABLE_SIZE];
1430 static struct cpufreq_frequency_table dep_cpu2core_table[DVFS_CPU_TABLE_SIZE];
1431
1432 void __init board_clock_init(void)
1433 {
1434         rk30_clock_data_init(periph_pll_default, codec_pll_default, RK30_CLOCKS_DEFAULT_FLAGS);
1435         dvfs_set_arm_logic_volt(dvfs_cpu_logic_table, cpu_dvfs_table, dep_cpu2core_table);
1436         dvfs_set_freq_volt_table(clk_get(NULL, "gpu"), dvfs_gpu_table);
1437         dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
1438 }
1439
1440 MACHINE_START(RK30, "RK30board")
1441         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
1442         .fixup          = rk30_fixup,
1443         .reserve        = &rk30_reserve,
1444         .map_io         = rk30_map_io,
1445         .init_irq       = rk30_init_irq,
1446         .timer          = &rk30_timer,
1447         .init_machine   = machine_rk30_board_init,
1448 MACHINE_END