camera rk30:two cif controls use different ipp mem size.
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk30 / board-rk30-sdk.c
1 /* arch/arm/mach-rk30/board-rk30-sdk.c
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
28 #include <asm/setup.h>
29 #include <asm/mach-types.h>
30 #include <asm/mach/arch.h>
31 #include <asm/mach/map.h>
32 #include <asm/mach/flash.h>
33 #include <asm/hardware/gic.h>
34
35 #include <mach/board.h>
36 #include <mach/hardware.h>
37 #include <mach/io.h>
38 #include <mach/gpio.h>
39 #include <mach/iomux.h>
40 /*set touchscreen different type header*/
41 #if defined(CONFIG_TOUCHSCREEN_XPT2046_NORMAL_SPI)
42 #include "../../../drivers/input/touchscreen/xpt2046_ts.h"
43 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_TSLIB_SPI)
44 #include "../../../drivers/input/touchscreen/xpt2046_tslib_ts.h"
45 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
46 #include "../../../drivers/input/touchscreen/xpt2046_cbn_ts.h"
47 #endif
48 #if defined(CONFIG_SPIM_RK29)
49 #include "../../../drivers/spi/rk29_spim.h"
50 #endif
51 #if defined(CONFIG_ANDROID_TIMED_GPIO)
52 #include "../../../drivers/staging/android/timed_gpio.h"
53 #endif
54
55 #define RK30_FB0_MEM_SIZE 8*SZ_1M
56
57 #ifdef CONFIG_VIDEO_RK29
58 /*---------------- Camera Sensor Macro Define Begin  ------------------------*/
59 /*---------------- Camera Sensor Configuration Macro Begin ------------------------*/
60 #define CONFIG_SENSOR_0 RK29_CAM_SENSOR_OV5642                                          /* back camera sensor */
61 #define CONFIG_SENSOR_IIC_ADDR_0                0x78
62 #define CONFIG_SENSOR_IIC_ADAPTER_ID_0    1
63 #define CONFIG_SENSOR_CIF_INDEX_0                    0
64 #define CONFIG_SENSOR_ORIENTATION_0       90
65 #define CONFIG_SENSOR_POWER_PIN_0                 INVALID_GPIO
66 #define CONFIG_SENSOR_RESET_PIN_0                 INVALID_GPIO
67 #define CONFIG_SENSOR_POWERDN_PIN_0       INVALID_GPIO
68 #define CONFIG_SENSOR_FALSH_PIN_0                 INVALID_GPIO
69 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_0 RK29_CAM_POWERACTIVE_L
70 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_0 RK29_CAM_RESETACTIVE_L
71 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_0 RK29_CAM_POWERDNACTIVE_H
72 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_0 RK29_CAM_FLASHACTIVE_L
73
74 #define CONFIG_SENSOR_QCIF_FPS_FIXED_0          15000
75 #define CONFIG_SENSOR_QVGA_FPS_FIXED_0          15000
76 #define CONFIG_SENSOR_CIF_FPS_FIXED_0           15000
77 #define CONFIG_SENSOR_VGA_FPS_FIXED_0           15000
78 #define CONFIG_SENSOR_480P_FPS_FIXED_0          15000
79 #define CONFIG_SENSOR_SVGA_FPS_FIXED_0          15000
80 #define CONFIG_SENSOR_720P_FPS_FIXED_0          30000
81
82 #define CONFIG_SENSOR_1 RK29_CAM_SENSOR_OV2659                                          /* front camera sensor */
83 #define CONFIG_SENSOR_IIC_ADDR_1                0x60
84 #define CONFIG_SENSOR_IIC_ADAPTER_ID_1    1
85 #define CONFIG_SENSOR_CIF_INDEX_1                                 1
86 #define CONFIG_SENSOR_ORIENTATION_1       270
87 #define CONFIG_SENSOR_POWER_PIN_1                 INVALID_GPIO
88 #define CONFIG_SENSOR_RESET_PIN_1                 INVALID_GPIO
89 #define CONFIG_SENSOR_POWERDN_PIN_1       INVALID_GPIO
90 #define CONFIG_SENSOR_FALSH_PIN_1                 INVALID_GPIO
91 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_1 RK29_CAM_POWERACTIVE_L
92 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_1 RK29_CAM_RESETACTIVE_L
93 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_1 RK29_CAM_POWERDNACTIVE_H
94 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_1 RK29_CAM_FLASHACTIVE_L
95
96 #define CONFIG_SENSOR_QCIF_FPS_FIXED_1          15000
97 #define CONFIG_SENSOR_QVGA_FPS_FIXED_1          15000
98 #define CONFIG_SENSOR_CIF_FPS_FIXED_1           15000
99 #define CONFIG_SENSOR_VGA_FPS_FIXED_1           15000
100 #define CONFIG_SENSOR_480P_FPS_FIXED_1          15000
101 #define CONFIG_SENSOR_SVGA_FPS_FIXED_1          15000
102 #define CONFIG_SENSOR_720P_FPS_FIXED_1          30000
103
104 #define CONFIG_USE_CIF_0        1
105 #define CONFIG_USE_CIF_1      1
106 #endif  //#ifdef CONFIG_VIDEO_RK29
107 /*---------------- Camera Sensor Configuration Macro End------------------------*/
108 #include "../../../drivers/media/video/rk30_camera.c"
109 /*---------------- Camera Sensor Macro Define End  ---------*/
110
111 //RK30,use  ion to allocate mem , set it as 0
112 #define PMEM_CAM_SIZE           0//PMEM_CAM_NECESSARY
113 #ifdef CONFIG_VIDEO_RK29_WORK_IPP
114 #define MEM_CAMIPP_SIZE_CIF_0   PMEM_CAMIPP_NECESSARY_CIF_0
115 #define MEM_CAMIPP_SIZE_CIF_1   PMEM_CAMIPP_NECESSARY_CIF_0
116 #else
117 #define MEM_CAMIPP_SIZE_CIF_0   0
118 #define MEM_CAMIPP_SIZE_CIF_1   0
119
120 #endif
121 /*****************************************************************************************
122  * camera  devices
123  * author: ddl@rock-chips.com
124  *****************************************************************************************/
125 #ifdef CONFIG_VIDEO_RK29
126 #define CONFIG_SENSOR_POWER_IOCTL_USR      0
127 #define CONFIG_SENSOR_RESET_IOCTL_USR      0
128 #define CONFIG_SENSOR_POWERDOWN_IOCTL_USR          0
129 #define CONFIG_SENSOR_FLASH_IOCTL_USR      0
130
131 #if CONFIG_SENSOR_POWER_IOCTL_USR
132 static int sensor_power_usr_cb (struct rk29camera_gpio_res *res,int on)
133 {
134         #error "CONFIG_SENSOR_POWER_IOCTL_USR is 1, sensor_power_usr_cb function must be writed!!";
135 }
136 #endif
137
138 #if CONFIG_SENSOR_RESET_IOCTL_USR
139 static int sensor_reset_usr_cb (struct rk29camera_gpio_res *res,int on)
140 {
141         #error "CONFIG_SENSOR_RESET_IOCTL_USR is 1, sensor_reset_usr_cb function must be writed!!";
142 }
143 #endif
144
145 #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
146 static int sensor_powerdown_usr_cb (struct rk29camera_gpio_res *res,int on)
147 {
148         #error "CONFIG_SENSOR_POWERDOWN_IOCTL_USR is 1, sensor_powerdown_usr_cb function must be writed!!";
149 }
150 #endif
151
152 #if CONFIG_SENSOR_FLASH_IOCTL_USR
153 static int sensor_flash_usr_cb (struct rk29camera_gpio_res *res,int on)
154 {
155         #error "CONFIG_SENSOR_FLASH_IOCTL_USR is 1, sensor_flash_usr_cb function must be writed!!";
156 }
157 #endif
158
159 static struct rk29camera_platform_ioctl_cb      sensor_ioctl_cb = {
160         #if CONFIG_SENSOR_POWER_IOCTL_USR
161         .sensor_power_cb = sensor_power_usr_cb,
162         #else
163         .sensor_power_cb = NULL,
164         #endif
165
166         #if CONFIG_SENSOR_RESET_IOCTL_USR
167         .sensor_reset_cb = sensor_reset_usr_cb,
168         #else
169         .sensor_reset_cb = NULL,
170         #endif
171
172         #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
173         .sensor_powerdown_cb = sensor_powerdown_usr_cb,
174         #else
175         .sensor_powerdown_cb = NULL,
176         #endif
177
178         #if CONFIG_SENSOR_FLASH_IOCTL_USR
179         .sensor_flash_cb = sensor_flash_usr_cb,
180         #else
181         .sensor_flash_cb = NULL,
182         #endif
183 };
184 static struct reginfo_t rk_init_data_sensor_reg_0[] =
185 {
186                 {0x0000, 0x00,0,0}
187         };
188 static struct reginfo_t rk_init_data_sensor_winseqreg_0[] ={
189         {0x0000, 0x00,0,0}
190         };
191 static rk_sensor_user_init_data_s rk_init_data_sensor_0 = 
192 {       
193         .rk_sensor_init_width = INVALID_VALUE,
194         .rk_sensor_init_height = INVALID_VALUE,
195         .rk_sensor_init_bus_param = INVALID_VALUE,
196         .rk_sensor_init_pixelcode = INVALID_VALUE,
197         .rk_sensor_init_data = rk_init_data_sensor_reg_0,
198         .rk_sensor_init_winseq = NULL,//rk_init_data_sensor_winseqreg_0,
199         .rk_sensor_winseq_size = sizeof(rk_init_data_sensor_winseqreg_0) / sizeof(struct reginfo_t),
200         
201 };
202 static rk_sensor_user_init_data_s* rk_init_data_sensor_0_p = NULL;
203 static rk_sensor_user_init_data_s* rk_init_data_sensor_1_p = NULL;
204 #include "../../../drivers/media/video/rk30_camera.c"
205
206 #endif
207
208 #if defined(CONFIG_TOUCHSCREEN_GT8XX)
209 #define TOUCH_RESET_PIN  RK30_PIN4_PD0
210 #define TOUCH_PWR_PIN    INVALID_GPIO
211 int goodix_init_platform_hw(void)
212 {
213         int ret;
214         printk("goodix_init_platform_hw\n");
215         if(TOUCH_PWR_PIN != INVALID_GPIO)
216         {
217                 ret = gpio_request(TOUCH_PWR_PIN, "goodix power pin");
218                 if(ret != 0){
219                         gpio_free(TOUCH_PWR_PIN);
220                         printk("goodix power error\n");
221                         return -EIO;
222                 }
223                 gpio_direction_output(TOUCH_PWR_PIN, 0);
224                 gpio_set_value(TOUCH_PWR_PIN,GPIO_LOW);
225                 msleep(100);
226         }
227         
228         if(TOUCH_RESET_PIN != INVALID_GPIO)
229         {
230                 ret = gpio_request(TOUCH_RESET_PIN, "goodix reset pin");
231                 if(ret != 0){
232                         gpio_free(TOUCH_RESET_PIN);
233                         printk("goodix gpio_request error\n");
234                         return -EIO;
235                 }
236                 gpio_direction_output(TOUCH_RESET_PIN, 0);
237                 gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
238                 msleep(10);
239                 gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
240                 msleep(500);
241         }
242         return 0;
243 }
244
245 struct goodix_platform_data goodix_info = {
246           .model= 8105,
247           .irq_pin = RK30_PIN4_PC2,
248           .rest_pin  = TOUCH_RESET_PIN,
249           .init_platform_hw = goodix_init_platform_hw,
250 };
251 #endif
252
253
254 /*****************************************************************************************
255  * xpt2046 touch panel
256  * author: hhb@rock-chips.com
257  *****************************************************************************************/
258 #if defined(CONFIG_TOUCHSCREEN_XPT2046_NORMAL_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_TSLIB_SPI)
259 #define XPT2046_GPIO_INT        RK30_PIN4_PC2 
260 #define DEBOUNCE_REPTIME        3
261
262
263 static struct xpt2046_platform_data xpt2046_info = {
264         .model                  = 2046,
265         .keep_vref_on           = 1,
266         .swap_xy                = 0,
267         .debounce_max           = 7,
268         .debounce_rep           = DEBOUNCE_REPTIME,
269         .debounce_tol           = 20,
270         .gpio_pendown           = XPT2046_GPIO_INT,
271         .pendown_iomux_name = GPIO4C2_SMCDATA2_TRACEDATA2_NAME, 
272         .pendown_iomux_mode = GPIO4C_GPIO4C2,   
273         .touch_virtualkey_length = 60,
274         .penirq_recheck_delay_usecs = 1,
275 #if defined(CONFIG_TOUCHSCREEN_480X800)
276         .x_min                  = 0,
277         .x_max                  = 480,
278         .y_min                  = 0,
279         .y_max                  = 800,
280         .touch_ad_top = 3940,
281         .touch_ad_bottom = 310,
282         .touch_ad_left = 3772,
283         .touch_ad_right = 340,
284 #elif defined(CONFIG_TOUCHSCREEN_800X480)
285         .x_min                  = 0,
286         .x_max                  = 800,
287         .y_min                  = 0,
288         .y_max                  = 480,
289         .touch_ad_top = 2447,
290         .touch_ad_bottom = 207,
291         .touch_ad_left = 5938,
292         .touch_ad_right = 153,
293 #elif defined(CONFIG_TOUCHSCREEN_320X480)
294         .x_min                  = 0,
295         .x_max                  = 320,
296         .y_min                  = 0,
297         .y_max                  = 480,
298         .touch_ad_top = 3166,
299         .touch_ad_bottom = 256,
300         .touch_ad_left = 3658,
301         .touch_ad_right = 380,
302 #endif  
303 };
304 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
305 static struct xpt2046_platform_data xpt2046_info = {
306         .model                  = 2046,
307         .keep_vref_on   = 1,
308         .swap_xy                = 0,
309         .debounce_max           = 7,
310         .debounce_rep           = DEBOUNCE_REPTIME,
311         .debounce_tol           = 20,
312         .gpio_pendown           = XPT2046_GPIO_INT,
313         .pendown_iomux_name = GPIO4C2_SMCDATA2_TRACEDATA2_NAME, 
314         .pendown_iomux_mode = GPIO4C_GPIO4C2,   
315         .touch_virtualkey_length = 60,
316         .penirq_recheck_delay_usecs = 1,
317         
318 #if defined(CONFIG_TOUCHSCREEN_480X800)
319         .x_min                  = 0,
320         .x_max                  = 480,
321         .y_min                  = 0,
322         .y_max                  = 800,
323         .screen_x = { 70,  410, 70, 410, 240},
324         .screen_y = { 50, 50,  740, 740, 400},
325         .uncali_x_default = {  3267,  831, 3139, 715, 1845 },
326         .uncali_y_default = { 3638,  3664, 564,  591, 2087 },
327 #elif defined(CONFIG_TOUCHSCREEN_800X480)
328         .x_min                  = 0,
329         .x_max                  = 800,
330         .y_min                  = 0,
331         .y_max                  = 480,
332         .screen_x[5] = { 50, 750,  50, 750, 400};
333         .screen_y[5] = { 40,  40, 440, 440, 240};
334         .uncali_x_default[5] = { 438,  565, 3507,  3631, 2105 };
335         .uncali_y_default[5] = {  3756,  489, 3792, 534, 2159 };
336 #elif defined(CONFIG_TOUCHSCREEN_320X480)
337         .x_min                  = 0,
338         .x_max                  = 320,
339         .y_min                  = 0,
340         .y_max                  = 480,
341         .screen_x[5] = { 50, 270,  50, 270, 160}; 
342         .screen_y[5] = { 40,  40, 440, 440, 240}; 
343         .uncali_x_default[5] = { 812,  3341, 851,  3371, 2183 };
344         .uncali_y_default[5] = {  442,  435, 3193, 3195, 2004 };
345 #endif  
346 };
347 #endif
348 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
349 static struct rk29xx_spi_chip xpt2046_chip = {
350         //.poll_mode = 1,
351         .enable_dma = 1,
352 };
353 #endif
354 static struct spi_board_info board_spi_devices[] = {
355 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
356         {
357                 .modalias       = "xpt2046_ts",
358                 .chip_select    = 1,// 2,
359                 .max_speed_hz   = 1 * 1000 * 800,/* (max sample rate @ 3V) * (cmd + data + overhead) */
360                 .bus_num        = 0,
361                 .irq            = XPT2046_GPIO_INT,
362                 .platform_data = &xpt2046_info,
363                 .controller_data = &xpt2046_chip,
364         },
365 #endif
366
367 };
368
369
370 /***********************************************************
371 *       rk30  backlight
372 ************************************************************/
373 #ifdef CONFIG_BACKLIGHT_RK29_BL
374 #define PWM_ID            0
375 #define PWM_MUX_NAME      GPIO0A3_PWM0_NAME
376 #define PWM_MUX_MODE      GPIO0A_PWM0
377 #define PWM_MUX_MODE_GPIO GPIO0A_GPIO0A3
378 #define PWM_GPIO          RK30_PIN0_PA3
379 #define PWM_EFFECT_VALUE  1
380
381 #define LCD_DISP_ON_PIN
382
383 #ifdef  LCD_DISP_ON_PIN
384 //#define BL_EN_MUX_NAME    GPIOF34_UART3_SEL_NAME
385 //#define BL_EN_MUX_MODE    IOMUXB_GPIO1_B34
386
387 #define BL_EN_PIN         RK30_PIN6_PB3
388 #define BL_EN_VALUE       GPIO_HIGH
389 #endif
390 static int rk29_backlight_io_init(void)
391 {
392         int ret = 0;
393         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
394 #ifdef  LCD_DISP_ON_PIN
395         // rk30_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
396
397         ret = gpio_request(BL_EN_PIN, NULL);
398         if(ret != 0)
399         {
400                 gpio_free(BL_EN_PIN);
401         }
402
403         gpio_direction_output(BL_EN_PIN, 0);
404         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
405 #endif
406     return ret;
407 }
408
409 static int rk29_backlight_io_deinit(void)
410 {
411         int ret = 0;
412 #ifdef  LCD_DISP_ON_PIN
413         gpio_free(BL_EN_PIN);
414 #endif
415         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);   
416     return ret;
417 }
418
419 static int rk29_backlight_pwm_suspend(void)
420 {
421         int ret = 0;
422         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
423         if (gpio_request(PWM_GPIO, NULL)) {
424                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
425                 return -1;
426         }
427         gpio_direction_output(PWM_GPIO, GPIO_LOW);
428 #ifdef  LCD_DISP_ON_PIN
429         gpio_direction_output(BL_EN_PIN, 0);
430         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
431 #endif
432         return ret;
433 }
434
435 static int rk29_backlight_pwm_resume(void)
436 {
437         gpio_free(PWM_GPIO);
438         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
439 #ifdef  LCD_DISP_ON_PIN
440         msleep(30);
441         gpio_direction_output(BL_EN_PIN, 1);
442         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
443 #endif
444         return 0;
445 }
446
447 static struct rk29_bl_info rk29_bl_info = {
448     .pwm_id   = PWM_ID,
449     .bl_ref   = PWM_EFFECT_VALUE,
450     .io_init   = rk29_backlight_io_init,
451     .io_deinit = rk29_backlight_io_deinit,
452     .pwm_suspend = rk29_backlight_pwm_suspend,
453     .pwm_resume = rk29_backlight_pwm_resume,
454 };
455
456
457 static struct platform_device rk29_device_backlight = {
458         .name   = "rk29_backlight",
459         .id     = -1,
460         .dev    = {
461            .platform_data  = &rk29_bl_info,
462         }
463 };
464
465 #endif
466
467 /*MMA8452 gsensor*/
468 #if defined (CONFIG_GS_MMA8452)
469 #define MMA8452_INT_PIN   RK30_PIN4_PC0
470
471 static int mma8452_init_platform_hw(void)
472 {
473         rk30_mux_api_set(GPIO4C0_SMCDATA0_TRACEDATA0_NAME, GPIO4C_GPIO4C0);
474
475         if(gpio_request(MMA8452_INT_PIN,NULL) != 0){
476                 gpio_free(MMA8452_INT_PIN);
477                 printk("mma8452_init_platform_hw gpio_request error\n");
478                 return -EIO;
479         }
480         gpio_pull_updown(MMA8452_INT_PIN, 1);
481         return 0;
482 }
483
484
485 static struct mma8452_platform_data mma8452_info = {
486         .model= 8452,
487         .swap_xy = 0,
488         .swap_xyz = 1,
489         .init_platform_hw= mma8452_init_platform_hw,
490         .orientation = { -1, 0, 0, 0, 0, 1, 0, -1, 0},
491 };
492 #endif
493 #if defined (CONFIG_COMPASS_AK8975)
494 static struct akm8975_platform_data akm8975_info =
495 {
496         .m_layout = 
497         {
498                 {
499                         {1, 0, 0 },
500                         {0, -1, 0 },
501                         {0,     0, -1 },
502                 },
503
504                 {
505                         {1, 0, 0 },
506                         {0, 1, 0 },
507                         {0,     0, 1 },
508                 },
509
510                 {
511                         {1, 0, 0 },
512                         {0, 1, 0 },
513                         {0,     0, 1 },
514                 },
515
516                 {
517                         {1, 0, 0 },
518                         {0, 1, 0 },
519                         {0,     0, 1 },
520                 },
521         }
522
523 };
524
525 #endif
526
527 #if defined(CONFIG_GYRO_L3G4200D)
528
529 #include <linux/l3g4200d.h>
530 #define L3G4200D_INT_PIN  RK30_PIN4_PC3
531
532 static int l3g4200d_init_platform_hw(void)
533 {
534         if (gpio_request(L3G4200D_INT_PIN, NULL) != 0) {
535                 gpio_free(L3G4200D_INT_PIN);
536                 printk("%s: request l3g4200d int pin error\n", __func__);
537                 return -EIO;
538         }
539         gpio_pull_updown(L3G4200D_INT_PIN, 1);
540         return 0;
541 }
542
543 static struct l3g4200d_platform_data l3g4200d_info = {
544         .fs_range = 1,
545
546         .axis_map_x = 0,
547         .axis_map_y = 1,
548         .axis_map_z = 2,
549
550         .negate_x = 1,
551         .negate_y = 1,
552         .negate_z = 0,
553
554         .init = l3g4200d_init_platform_hw,
555 };
556
557 #endif
558
559 #ifdef CONFIG_LS_CM3217
560
561 #define CM3217_POWER_PIN        INVALID_GPIO
562 #define CM3217_IRQ_PIN          INVALID_GPIO
563 static int cm3217_init_hw(void)
564 {
565 #if 0
566         if (gpio_request(CM3217_POWER_PIN, NULL) != 0) {
567         gpio_free(CM3217_POWER_PIN);
568         printk("%s: request cm3217 power pin error\n", __func__);
569         return -EIO;
570         }
571         gpio_pull_updown(CM3217_POWER_PIN, PullDisable);
572
573         if (gpio_request(CM3217_IRQ_PIN, NULL) != 0) {
574         gpio_free(CM3217_IRQ_PIN);
575         printk("%s: request cm3217 int pin error\n", __func__);
576         return -EIO;
577         }
578         gpio_pull_updown(CM3217_IRQ_PIN, PullDisable);
579 #endif
580         return 0;
581 }
582
583 static void cm3217_exit_hw(void)
584 {
585 #if 0
586         gpio_free(CM3217_POWER_PIN);
587         gpio_free(CM3217_IRQ_PIN);
588 #endif
589         return;
590 }
591
592 struct cm3217_platform_data cm3217_info = {
593         .irq_pin = CM3217_IRQ_PIN,
594         .power_pin = CM3217_POWER_PIN,
595         .init_platform_hw = cm3217_init_hw,
596         .exit_platform_hw = cm3217_exit_hw,
597 };
598 #endif
599
600
601
602 #ifdef CONFIG_FB_ROCKCHIP
603 static struct resource resource_fb[] = {
604         [0] = {
605                 .name  = "fb0 buf",
606                 .start = 0,
607                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
608                 .flags = IORESOURCE_MEM,
609         },
610         [1] = {
611                 .name  = "ipp buf",  //for rotate
612                 .start = 0,
613                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
614                 .flags = IORESOURCE_MEM,
615         },
616         [2] = {
617                 .name  = "fb2 buf",
618                 .start = 0,
619                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
620                 .flags = IORESOURCE_MEM,
621         },
622 };
623
624 static struct platform_device device_fb = {
625         .name             = "rk-fb",
626         .id               = -1,
627         .num_resources    = ARRAY_SIZE(resource_fb),
628         .resource         = resource_fb,
629 };
630 #endif
631
632 #ifdef CONFIG_ANDROID_TIMED_GPIO
633 static struct timed_gpio timed_gpios[] = {
634         {
635                 .name = "vibrator",
636                 .gpio = RK30_PIN0_PA4,
637                 .max_timeout = 1000,
638                 .active_low = 0,
639                 .adjust_time =20,      //adjust for diff product
640         },
641 };
642
643 struct timed_gpio_platform_data rk29_vibrator_info = {
644         .num_gpios = 1,
645         .gpios = timed_gpios,
646 };
647
648 struct platform_device rk29_device_vibrator ={
649         .name = "timed-gpio",
650         .id = -1,
651         .dev = {
652                 .platform_data = &rk29_vibrator_info,
653                 },
654
655 };
656 #endif 
657
658 #ifdef CONFIG_LEDS_GPIO_PLATFORM
659 struct gpio_led rk29_leds[] = {
660                 {
661                         .name = "button-backlight",
662                         .gpio = RK30_PIN4_PD7,
663                         .default_trigger = "timer",
664                         .active_low = 0,
665                         .retain_state_suspended = 0,
666                         .default_state = LEDS_GPIO_DEFSTATE_OFF,
667                 },
668 };
669
670 struct gpio_led_platform_data rk29_leds_pdata = {
671         .leds = &rk29_leds,
672         .num_leds       = ARRAY_SIZE(rk29_leds),
673 };
674
675 struct platform_device rk29_device_gpio_leds = {
676         .name   = "leds-gpio",
677         .id     = -1,
678         .dev    = {
679            .platform_data  = &rk29_leds_pdata,
680         },
681 };
682 #endif
683
684 #ifdef CONFIG_RK_IRDA
685 #define IRDA_IRQ_PIN           RK30_PIN6_PA1
686
687 int irda_iomux_init(void)
688 {
689         int ret = 0;
690
691         //irda irq pin
692         ret = gpio_request(IRDA_IRQ_PIN, NULL);
693         if(ret != 0)
694         {
695         gpio_free(IRDA_IRQ_PIN);
696         printk(">>>>>> IRDA_IRQ_PIN gpio_request err \n ");
697         }
698         gpio_pull_updown(IRDA_IRQ_PIN, PullDisable);
699         gpio_direction_input(IRDA_IRQ_PIN);
700
701         return 0;
702 }
703
704 int irda_iomux_deinit(void)
705 {
706         gpio_free(IRDA_IRQ_PIN);
707         return 0;
708 }
709
710 static struct irda_info rk29_irda_info = {
711         .intr_pin = IRDA_IRQ_PIN,
712         .iomux_init = irda_iomux_init,
713         .iomux_deinit = irda_iomux_deinit,
714         //.irda_pwr_ctl = bu92747guw_power_ctl,
715 };
716
717 static struct platform_device irda_device = {
718 #ifdef CONFIG_RK_IRDA_NET
719                         .name   = "rk_irda",
720 #else
721                         .name = "bu92747_irda",
722 #endif
723     .id           = -1,
724         .dev            = {
725                 .platform_data  = &rk29_irda_info,
726         }
727 };
728 #endif
729
730 #ifdef CONFIG_ION
731 #define ION_RESERVE_SIZE        (80 * SZ_1M)
732 static struct ion_platform_data rk30_ion_pdata = {
733         .nr = 1,
734         .heaps = {
735                 {
736                         .type = ION_HEAP_TYPE_CARVEOUT,
737                         .id = ION_NOR_HEAP_ID,
738                         .name = "norheap",
739                         .size = ION_RESERVE_SIZE,
740                 }
741         },
742 };
743
744 static struct platform_device device_ion = {
745         .name = "ion-rockchip",
746         .id = 0,
747         .dev = {
748                 .platform_data = &rk30_ion_pdata,
749         },
750 };
751 #endif
752
753 static struct platform_device *devices[] __initdata = {
754 #ifdef CONFIG_BACKLIGHT_RK29_BL
755         &rk29_device_backlight,
756 #endif  
757 #ifdef CONFIG_FB_ROCKCHIP
758         &device_fb,
759 #endif
760 #ifdef CONFIG_ION
761         &device_ion,
762 #endif
763 #ifdef CONFIG_ANDROID_TIMED_GPIO
764         &rk29_device_vibrator,
765 #endif
766 #ifdef CONFIG_LEDS_GPIO_PLATFORM
767         &rk29_device_gpio_leds,
768 #endif
769 #ifdef CONFIG_RK_IRDA
770         &irda_device,
771 #endif
772 };
773
774 // i2c
775 #ifdef CONFIG_I2C0_RK30
776 static struct i2c_board_info __initdata i2c0_info[] = {
777 #if defined (CONFIG_GS_MMA8452)
778             {
779               .type           = "gs_mma8452",
780               .addr           = 0x1c,
781               .flags          = 0,
782               .irq            = MMA8452_INT_PIN,
783               .platform_data  = &mma8452_info,
784             },
785 #endif
786 #if defined (CONFIG_COMPASS_AK8975)
787         {
788                 .type           = "ak8975",
789                 .addr           = 0x0d,
790                 .flags          = 0,
791                 .irq            = RK30_PIN4_PC1,
792                 .platform_data  = &akm8975_info,
793         },
794 #endif
795 #if defined (CONFIG_GYRO_L3G4200D)
796         {
797                 .type           = "l3g4200d_gryo",
798                 .addr           = 0x69,
799                 .flags          = 0,
800                 .irq            = L3G4200D_INT_PIN,
801                 .platform_data  = &l3g4200d_info,
802         },
803 #endif
804
805 #if defined (CONFIG_SND_SOC_RK1000)
806         {
807                 .type                   = "rk1000_i2c_codec",
808                 .addr           = 0x60,
809                 .flags                  = 0,
810         },
811         {
812                 .type                   = "rk1000_control",
813                 .addr                   = 0x40,
814                 .flags                  = 0,
815         },      
816 #endif
817 };
818 #endif
819
820 #ifdef CONFIG_I2C1_RK30
821 #include "board-rk30-sdk-wm8326.c"
822
823 static struct i2c_board_info __initdata i2c1_info[] = {
824 #if defined (CONFIG_MFD_WM831X_I2C)
825         {
826                 .type           = "wm8326",
827                 .addr           = 0x36,    //0x34    ,is Decided by cs
828                 .flags          = 0,
829                 .irq            = RK30_PIN6_PA4,
830                 .platform_data  = &wm831x_platdata,
831         },
832 #endif
833 };
834 #endif
835
836 #ifdef CONFIG_I2C2_RK30
837 static struct i2c_board_info __initdata i2c2_info[] = {
838 #if defined (CONFIG_TOUCHSCREEN_GT8XX)
839                     {
840                                 .type   = "Goodix-TS",
841                                 .addr   = 0x55,
842                                 .flags      =0,
843                                 .irq            =RK30_PIN4_PC2,
844                                 .platform_data = &goodix_info,
845                     },
846 #endif
847 #if defined (CONFIG_LS_CM3217)
848         {
849                 .type           = "lightsensor",
850                 .addr           = 0x20,
851                 .flags          = 0,
852                 .irq            = CM3217_IRQ_PIN,
853                 .platform_data  = &cm3217_info,
854         },
855 #endif
856
857 };
858 #endif
859
860 #ifdef CONFIG_I2C3_RK30
861 static struct i2c_board_info __initdata i2c3_info[] = {
862 };
863 #endif
864
865 #ifdef CONFIG_I2C4_RK30
866 static struct i2c_board_info __initdata i2c4_info[] = {
867 };
868 #endif
869
870 static void __init rk30_i2c_register_board_info(void)
871 {
872 #ifdef CONFIG_I2C0_RK30
873         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
874 #endif
875 #ifdef CONFIG_I2C1_RK30
876         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
877 #endif
878 #ifdef CONFIG_I2C2_RK30
879         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
880 #endif
881 #ifdef CONFIG_I2C3_RK30
882         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
883 #endif
884 #ifdef CONFIG_I2C4_RK30
885         i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info));
886 #endif
887 }
888 //end of i2c
889
890
891 /**************************************************************************************************
892  * SDMMC devices,  include the module of SD,MMC,and sdio.noted by xbw at 2012-03-05
893 **************************************************************************************************/
894 #ifdef CONFIG_SDMMC_RK29
895 #include "board-rk30-sdk-sdmmc.c"
896
897 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
898 #define SDMMC0_WRITE_PROTECT_PIN                RK30_PIN3_PB7 //According to your own project to set the value of write-protect-pin.
899 #endif
900
901 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
902 #define SDMMC1_WRITE_PROTECT_PIN                RK30_PIN3_PC7 //According to your own project to set the value of write-protect-pin.
903 #endif
904
905 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK30_PIN6_PB2
906
907 #endif //endif ---#ifdef CONFIG_SDMMC_RK29
908
909
910 #ifdef CONFIG_SDMMC0_RK29
911 static int rk29_sdmmc0_cfg_gpio(void)
912 {
913 #ifdef CONFIG_SDMMC_RK29_OLD    
914     rk30_mux_api_set(GPIO3B1_SDMMC0CMD_NAME, GPIO3B_SDMMC0_CMD);
915     rk30_mux_api_set(GPIO3B0_SDMMC0CLKOUT_NAME, GPIO3B_SDMMC0_CLKOUT);
916     rk30_mux_api_set(GPIO3B2_SDMMC0DATA0_NAME, GPIO3B_SDMMC0_DATA0);
917     rk30_mux_api_set(GPIO3B3_SDMMC0DATA1_NAME, GPIO3B_SDMMC0_DATA1);
918     rk30_mux_api_set(GPIO3B4_SDMMC0DATA2_NAME, GPIO3B_SDMMC0_DATA2);
919     rk30_mux_api_set(GPIO3B5_SDMMC0DATA3_NAME, GPIO3B_SDMMC0_DATA3);
920         
921         rk30_mux_api_set(GPIO3B6_SDMMC0DETECTN_NAME, GPIO3B_GPIO3B6);
922
923     rk30_mux_api_set(GPIO3A7_SDMMC0PWREN_NAME, GPIO3A_GPIO3A7);
924         gpio_request(RK30_PIN3_PA7,"sdmmc-power");
925         gpio_direction_output(RK30_PIN3_PA7,GPIO_LOW);
926         
927 #else
928     rk29_sdmmc_set_iomux(0, 0xFFFF);
929     
930         rk30_mux_api_set(GPIO3B6_SDMMC0DETECTN_NAME, GPIO3B_SDMMC0_DETECT_N);
931
932         #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
933     gpio_request(SDMMC0_WRITE_PROTECT_PIN,"sdmmc-wp");
934     gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);         
935     #endif
936
937 #endif
938
939         return 0;
940 }
941
942 #define CONFIG_SDMMC0_USE_DMA
943 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
944         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
945                                            MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33|
946                                            MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
947         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
948         .io_init = rk29_sdmmc0_cfg_gpio,
949         
950 #if !defined(CONFIG_SDMMC_RK29_OLD)             
951         .set_iomux = rk29_sdmmc_set_iomux,
952 #endif
953
954         .dma_name = "sd_mmc",
955 #ifdef CONFIG_SDMMC0_USE_DMA
956         .use_dma  = 1,
957 #else
958         .use_dma = 0,
959 #endif
960         .detect_irq = RK30_PIN3_PB6, // INVALID_GPIO
961         .enable_sd_wakeup = 0,
962
963 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
964     .write_prt = SDMMC0_WRITE_PROTECT_PIN,
965 #else
966     .write_prt = INVALID_GPIO,
967 #endif
968 };
969 #endif//endif--#ifdef CONFIG_SDMMC0_RK29
970
971 #ifdef CONFIG_SDMMC1_RK29
972 #define CONFIG_SDMMC1_USE_DMA
973 static int rk29_sdmmc1_cfg_gpio(void)
974 {
975 #if defined(CONFIG_SDMMC_RK29_OLD)
976         rk30_mux_api_set(GPIO3C0_SMMC1CMD_NAME, GPIO3C_SMMC1_CMD);
977     rk30_mux_api_set(GPIO3C5_SDMMC1CLKOUT_NAME, GPIO3C_SDMMC1_CLKOUT);
978     rk30_mux_api_set(GPIO3C1_SDMMC1DATA0_NAME, GPIO3C_SDMMC1_DATA0);
979     rk30_mux_api_set(GPIO3C2_SDMMC1DATA1_NAME, GPIO3C_SDMMC1_DATA1);
980     rk30_mux_api_set(GPIO3C3_SDMMC1DATA2_NAME, GPIO3C_SDMMC1_DATA2);
981     rk30_mux_api_set(GPIO3C4_SDMMC1DATA3_NAME, GPIO3C_SDMMC1_DATA3);
982         //rk30_mux_api_set(GPIO3C6_SDMMC1DETECTN_NAME, GPIO3C_SDMMC1_DETECT_N);
983
984 #else
985
986 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
987     gpio_request(SDMMC1_WRITE_PROTECT_PIN,"sdio-wp");
988     gpio_direction_input(SDMMC1_WRITE_PROTECT_PIN);         
989 #endif
990
991 #endif
992
993         return 0;
994 }
995
996
997 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
998         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
999                                            MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
1000                                            MMC_VDD_32_33|MMC_VDD_33_34),
1001                                            
1002 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)                                     
1003         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
1004                                    MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
1005 #else
1006     .host_caps  = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
1007 #endif
1008
1009         .io_init = rk29_sdmmc1_cfg_gpio,
1010         
1011 #if !defined(CONFIG_SDMMC_RK29_OLD)             
1012         .set_iomux = rk29_sdmmc_set_iomux,
1013 #endif  
1014
1015         .dma_name = "sdio",
1016 #ifdef CONFIG_SDMMC1_USE_DMA
1017         .use_dma  = 1,
1018 #else
1019         .use_dma = 0,
1020 #endif
1021
1022 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
1023 #ifdef CONFIG_WIFI_CONTROL_FUNC
1024         .status = rk29sdk_wifi_status,
1025         .register_status_notify = rk29sdk_wifi_status_register,
1026 #endif
1027 #if 0
1028         .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
1029 #endif
1030
1031 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
1032     .write_prt = SDMMC1_WRITE_PROTECT_PIN,
1033 #else
1034     .write_prt = INVALID_GPIO, 
1035 #endif  
1036
1037 #else
1038     .detect_irq = INVALID_GPIO,
1039     .enable_sd_wakeup = 0,
1040 #endif
1041
1042 };
1043 #endif //endif--#ifdef CONFIG_SDMMC1_RK29
1044 /**************************************************************************************************
1045  * the end of setting for SDMMC devices
1046 **************************************************************************************************/
1047
1048 static void __init machine_rk30_board_init(void)
1049 {
1050         rk30_i2c_register_board_info();
1051         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1052         platform_add_devices(devices, ARRAY_SIZE(devices));
1053 }
1054
1055 static void __init rk30_reserve(void)
1056 {
1057 #ifdef CONFIG_ION
1058         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion",ION_RESERVE_SIZE);
1059 #endif
1060 #ifdef CONFIG_FB_ROCKCHIP
1061         resource_fb[0].start = board_mem_reserve_add("fb0",RK30_FB0_MEM_SIZE);
1062         resource_fb[0].end = resource_fb[0].start + RK30_FB0_MEM_SIZE - 1;
1063         resource_fb[1].start = board_mem_reserve_add("ipp buf",RK30_FB0_MEM_SIZE);
1064         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
1065         resource_fb[2].start = board_mem_reserve_add("fb2",RK30_FB0_MEM_SIZE);
1066         resource_fb[2].end = resource_fb[2].start + RK30_FB0_MEM_SIZE - 1;      
1067 #endif
1068 #ifdef CONFIG_VIDEO_RK29
1069         rk30_camera_request_reserve_mem();
1070 #endif
1071         board_mem_reserved();
1072 }
1073
1074 MACHINE_START(RK30, "RK30board")
1075         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
1076         .fixup          = rk30_fixup,
1077         .reserve        = &rk30_reserve,
1078         .map_io         = rk30_map_io,
1079         .init_irq       = rk30_init_irq,
1080         .timer          = &rk30_timer,
1081         .init_machine   = machine_rk30_board_init,
1082 MACHINE_END