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