rk30: sdk add wm8326 support
[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_OV2659//RK_CAM_SENSOR_OV5642                                            /* back camera sensor */
61 #define CONFIG_SENSOR_IIC_ADDR_0                0x60//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      0
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 #define PMEM_CAM_SIZE           PMEM_CAM_NECESSARY
112 #ifdef CONFIG_VIDEO_RK29_WORK_IPP
113 #define MEM_CAMIPP_SIZE         PMEM_CAMIPP_NECESSARY
114 #else
115 #define MEM_CAMIPP_SIZE         0
116 #endif
117 /*****************************************************************************************
118  * camera  devices
119  * author: ddl@rock-chips.com
120  *****************************************************************************************/
121 #ifdef CONFIG_VIDEO_RK29
122 #define CONFIG_SENSOR_POWER_IOCTL_USR      0
123 #define CONFIG_SENSOR_RESET_IOCTL_USR      0
124 #define CONFIG_SENSOR_POWERDOWN_IOCTL_USR          0
125 #define CONFIG_SENSOR_FLASH_IOCTL_USR      0
126
127 #if CONFIG_SENSOR_POWER_IOCTL_USR
128 static int sensor_power_usr_cb (struct rk29camera_gpio_res *res,int on)
129 {
130         #error "CONFIG_SENSOR_POWER_IOCTL_USR is 1, sensor_power_usr_cb function must be writed!!";
131 }
132 #endif
133
134 #if CONFIG_SENSOR_RESET_IOCTL_USR
135 static int sensor_reset_usr_cb (struct rk29camera_gpio_res *res,int on)
136 {
137         #error "CONFIG_SENSOR_RESET_IOCTL_USR is 1, sensor_reset_usr_cb function must be writed!!";
138 }
139 #endif
140
141 #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
142 static int sensor_powerdown_usr_cb (struct rk29camera_gpio_res *res,int on)
143 {
144         #error "CONFIG_SENSOR_POWERDOWN_IOCTL_USR is 1, sensor_powerdown_usr_cb function must be writed!!";
145 }
146 #endif
147
148 #if CONFIG_SENSOR_FLASH_IOCTL_USR
149 static int sensor_flash_usr_cb (struct rk29camera_gpio_res *res,int on)
150 {
151         #error "CONFIG_SENSOR_FLASH_IOCTL_USR is 1, sensor_flash_usr_cb function must be writed!!";
152 }
153 #endif
154
155 static struct rk29camera_platform_ioctl_cb      sensor_ioctl_cb = {
156         #if CONFIG_SENSOR_POWER_IOCTL_USR
157         .sensor_power_cb = sensor_power_usr_cb,
158         #else
159         .sensor_power_cb = NULL,
160         #endif
161
162         #if CONFIG_SENSOR_RESET_IOCTL_USR
163         .sensor_reset_cb = sensor_reset_usr_cb,
164         #else
165         .sensor_reset_cb = NULL,
166         #endif
167
168         #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
169         .sensor_powerdown_cb = sensor_powerdown_usr_cb,
170         #else
171         .sensor_powerdown_cb = NULL,
172         #endif
173
174         #if CONFIG_SENSOR_FLASH_IOCTL_USR
175         .sensor_flash_cb = sensor_flash_usr_cb,
176         #else
177         .sensor_flash_cb = NULL,
178         #endif
179 };
180 static struct reginfo_t rk_init_data_sensor_reg_0[] =
181 {
182                 {0x0000, 0x00,0,0}
183         };
184 static struct reginfo_t rk_init_data_sensor_winseqreg_0[] ={
185         {0x0000, 0x00,0,0}
186         };
187 static rk_sensor_user_init_data_s rk_init_data_sensor_0 = 
188 {       
189         .rk_sensor_init_width = INVALID_VALUE,
190         .rk_sensor_init_height = INVALID_VALUE,
191         .rk_sensor_init_bus_param = INVALID_VALUE,
192         .rk_sensor_init_pixelcode = INVALID_VALUE,
193         .rk_sensor_init_data = rk_init_data_sensor_reg_0,
194         .rk_sensor_init_winseq = NULL,//rk_init_data_sensor_winseqreg_0,
195         .rk_sensor_winseq_size = sizeof(rk_init_data_sensor_winseqreg_0) / sizeof(struct reginfo_t),
196         
197 };
198 static rk_sensor_user_init_data_s* rk_init_data_sensor_0_p = &rk_init_data_sensor_0;
199 static rk_sensor_user_init_data_s* rk_init_data_sensor_1_p = NULL;
200 #include "../../../drivers/media/video/rk30_camera.c"
201
202 #endif
203
204 #if defined(CONFIG_TOUCHSCREEN_GT8XX)
205 #define TOUCH_RESET_PIN  RK30_PIN4_PD0
206 #define TOUCH_PWR_PIN    INVALID_GPIO
207 int goodix_init_platform_hw(void)
208 {
209         int ret;
210         printk("goodix_init_platform_hw\n");
211         if(TOUCH_PWR_PIN != INVALID_GPIO)
212         {
213                 ret = gpio_request(TOUCH_PWR_PIN, "goodix power pin");
214                 if(ret != 0){
215                         gpio_free(TOUCH_PWR_PIN);
216                         printk("goodix power error\n");
217                         return -EIO;
218                 }
219                 gpio_direction_output(TOUCH_PWR_PIN, 0);
220                 gpio_set_value(TOUCH_PWR_PIN,GPIO_LOW);
221                 msleep(100);
222         }
223         
224         if(TOUCH_RESET_PIN != INVALID_GPIO)
225         {
226                 ret = gpio_request(TOUCH_RESET_PIN, "goodix reset pin");
227                 if(ret != 0){
228                         gpio_free(TOUCH_RESET_PIN);
229                         printk("goodix gpio_request error\n");
230                         return -EIO;
231                 }
232                 gpio_direction_output(TOUCH_RESET_PIN, 0);
233                 gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
234                 msleep(10);
235                 gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
236                 msleep(500);
237         }
238         return 0;
239 }
240
241 struct goodix_platform_data goodix_info = {
242           .model= 8105,
243           .irq_pin = RK30_PIN4_PC2,
244           .rest_pin  = TOUCH_RESET_PIN,
245           .init_platform_hw = goodix_init_platform_hw,
246 };
247 #endif
248
249
250 /*****************************************************************************************
251  * xpt2046 touch panel
252  * author: hhb@rock-chips.com
253  *****************************************************************************************/
254 #if defined(CONFIG_TOUCHSCREEN_XPT2046_NORMAL_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_TSLIB_SPI)
255 #define XPT2046_GPIO_INT        RK30_PIN4_PC2 
256 #define DEBOUNCE_REPTIME        3
257
258
259 static struct xpt2046_platform_data xpt2046_info = {
260         .model                  = 2046,
261         .keep_vref_on           = 1,
262         .swap_xy                = 0,
263         .debounce_max           = 7,
264         .debounce_rep           = DEBOUNCE_REPTIME,
265         .debounce_tol           = 20,
266         .gpio_pendown           = XPT2046_GPIO_INT,
267         .pendown_iomux_name = GPIO4C2_SMCDATA2_TRACEDATA2_NAME, 
268         .pendown_iomux_mode = GPIO4C_GPIO4C2,   
269         .touch_virtualkey_length = 60,
270         .penirq_recheck_delay_usecs = 1,
271 #if defined(CONFIG_TOUCHSCREEN_480X800)
272         .x_min                  = 0,
273         .x_max                  = 480,
274         .y_min                  = 0,
275         .y_max                  = 800,
276         .touch_ad_top = 3940,
277         .touch_ad_bottom = 310,
278         .touch_ad_left = 3772,
279         .touch_ad_right = 340,
280 #elif defined(CONFIG_TOUCHSCREEN_800X480)
281         .x_min                  = 0,
282         .x_max                  = 800,
283         .y_min                  = 0,
284         .y_max                  = 480,
285         .touch_ad_top = 2447,
286         .touch_ad_bottom = 207,
287         .touch_ad_left = 5938,
288         .touch_ad_right = 153,
289 #elif defined(CONFIG_TOUCHSCREEN_320X480)
290         .x_min                  = 0,
291         .x_max                  = 320,
292         .y_min                  = 0,
293         .y_max                  = 480,
294         .touch_ad_top = 3166,
295         .touch_ad_bottom = 256,
296         .touch_ad_left = 3658,
297         .touch_ad_right = 380,
298 #endif  
299 };
300 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
301 static struct xpt2046_platform_data xpt2046_info = {
302         .model                  = 2046,
303         .keep_vref_on   = 1,
304         .swap_xy                = 0,
305         .debounce_max           = 7,
306         .debounce_rep           = DEBOUNCE_REPTIME,
307         .debounce_tol           = 20,
308         .gpio_pendown           = XPT2046_GPIO_INT,
309         .pendown_iomux_name = GPIO4C2_SMCDATA2_TRACEDATA2_NAME, 
310         .pendown_iomux_mode = GPIO4C_GPIO4C2,   
311         .touch_virtualkey_length = 60,
312         .penirq_recheck_delay_usecs = 1,
313         
314 #if defined(CONFIG_TOUCHSCREEN_480X800)
315         .x_min                  = 0,
316         .x_max                  = 480,
317         .y_min                  = 0,
318         .y_max                  = 800,
319         .screen_x = { 70,  410, 70, 410, 240},
320         .screen_y = { 50, 50,  740, 740, 400},
321         .uncali_x_default = {  3267,  831, 3139, 715, 1845 },
322         .uncali_y_default = { 3638,  3664, 564,  591, 2087 },
323 #elif defined(CONFIG_TOUCHSCREEN_800X480)
324         .x_min                  = 0,
325         .x_max                  = 800,
326         .y_min                  = 0,
327         .y_max                  = 480,
328         .screen_x[5] = { 50, 750,  50, 750, 400};
329         .screen_y[5] = { 40,  40, 440, 440, 240};
330         .uncali_x_default[5] = { 438,  565, 3507,  3631, 2105 };
331         .uncali_y_default[5] = {  3756,  489, 3792, 534, 2159 };
332 #elif defined(CONFIG_TOUCHSCREEN_320X480)
333         .x_min                  = 0,
334         .x_max                  = 320,
335         .y_min                  = 0,
336         .y_max                  = 480,
337         .screen_x[5] = { 50, 270,  50, 270, 160}; 
338         .screen_y[5] = { 40,  40, 440, 440, 240}; 
339         .uncali_x_default[5] = { 812,  3341, 851,  3371, 2183 };
340         .uncali_y_default[5] = {  442,  435, 3193, 3195, 2004 };
341 #endif  
342 };
343 #endif
344 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
345 static struct rk29xx_spi_chip xpt2046_chip = {
346         //.poll_mode = 1,
347         .enable_dma = 1,
348 };
349 #endif
350 static struct spi_board_info board_spi_devices[] = {
351 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
352         {
353                 .modalias       = "xpt2046_ts",
354                 .chip_select    = 1,// 2,
355                 .max_speed_hz   = 1 * 1000 * 800,/* (max sample rate @ 3V) * (cmd + data + overhead) */
356                 .bus_num        = 0,
357                 .irq            = XPT2046_GPIO_INT,
358                 .platform_data = &xpt2046_info,
359                 .controller_data = &xpt2046_chip,
360         },
361 #endif
362
363 };
364
365
366 /***********************************************************
367 *       rk30  backlight
368 ************************************************************/
369 #ifdef CONFIG_BACKLIGHT_RK29_BL
370 #define PWM_ID            0
371 #define PWM_MUX_NAME      GPIO0A3_PWM0_NAME
372 #define PWM_MUX_MODE      GPIO0A_PWM0
373 #define PWM_MUX_MODE_GPIO GPIO0A_GPIO0A3
374 #define PWM_GPIO          RK30_PIN0_PA3
375 #define PWM_EFFECT_VALUE  1
376
377 #define LCD_DISP_ON_PIN
378
379 #ifdef  LCD_DISP_ON_PIN
380 //#define BL_EN_MUX_NAME    GPIOF34_UART3_SEL_NAME
381 //#define BL_EN_MUX_MODE    IOMUXB_GPIO1_B34
382
383 #define BL_EN_PIN         RK30_PIN6_PB3
384 #define BL_EN_VALUE       GPIO_HIGH
385 #endif
386 static int rk29_backlight_io_init(void)
387 {
388         int ret = 0;
389         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
390 #ifdef  LCD_DISP_ON_PIN
391         // rk30_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
392
393         ret = gpio_request(BL_EN_PIN, NULL);
394         if(ret != 0)
395         {
396                 gpio_free(BL_EN_PIN);
397         }
398
399         gpio_direction_output(BL_EN_PIN, 0);
400         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
401 #endif
402     return ret;
403 }
404
405 static int rk29_backlight_io_deinit(void)
406 {
407         int ret = 0;
408 #ifdef  LCD_DISP_ON_PIN
409         gpio_free(BL_EN_PIN);
410 #endif
411         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);   
412     return ret;
413 }
414
415 static int rk29_backlight_pwm_suspend(void)
416 {
417         int ret = 0;
418         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
419         if (gpio_request(PWM_GPIO, NULL)) {
420                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
421                 return -1;
422         }
423         gpio_direction_output(PWM_GPIO, GPIO_LOW);
424 #ifdef  LCD_DISP_ON_PIN
425         gpio_direction_output(BL_EN_PIN, 0);
426         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
427 #endif
428         return ret;
429 }
430
431 static int rk29_backlight_pwm_resume(void)
432 {
433         gpio_free(PWM_GPIO);
434         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
435 #ifdef  LCD_DISP_ON_PIN
436         msleep(30);
437         gpio_direction_output(BL_EN_PIN, 1);
438         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
439 #endif
440         return 0;
441 }
442
443 static struct rk29_bl_info rk29_bl_info = {
444     .pwm_id   = PWM_ID,
445     .bl_ref   = PWM_EFFECT_VALUE,
446     .io_init   = rk29_backlight_io_init,
447     .io_deinit = rk29_backlight_io_deinit,
448     .pwm_suspend = rk29_backlight_pwm_suspend,
449     .pwm_resume = rk29_backlight_pwm_resume,
450 };
451
452
453 static struct platform_device rk29_device_backlight = {
454         .name   = "rk29_backlight",
455         .id     = -1,
456         .dev    = {
457            .platform_data  = &rk29_bl_info,
458         }
459 };
460
461 #endif
462
463 /*MMA8452 gsensor*/
464 #if defined (CONFIG_GS_MMA8452)
465 #define MMA8452_INT_PIN   RK30_PIN4_PC0
466
467 static int mma8452_init_platform_hw(void)
468 {
469         rk30_mux_api_set(GPIO4C0_SMCDATA0_TRACEDATA0_NAME, GPIO4C_GPIO4C0);
470
471         if(gpio_request(MMA8452_INT_PIN,NULL) != 0){
472                 gpio_free(MMA8452_INT_PIN);
473                 printk("mma8452_init_platform_hw gpio_request error\n");
474                 return -EIO;
475         }
476         gpio_pull_updown(MMA8452_INT_PIN, 1);
477         return 0;
478 }
479
480
481 static struct mma8452_platform_data mma8452_info = {
482         .model= 8452,
483         .swap_xy = 0,
484         .swap_xyz = 1,
485         .init_platform_hw= mma8452_init_platform_hw,
486         .orientation = { -1, 0, 0, 0, 0, 1, 0, -1, 0},
487 };
488 #endif
489 #if defined (CONFIG_COMPASS_AK8975)
490 static struct akm8975_platform_data akm8975_info =
491 {
492         .m_layout = 
493         {
494                 {
495                         {1, 0, 0 },
496                         {0, -1, 0 },
497                         {0,     0, -1 },
498                 },
499
500                 {
501                         {1, 0, 0 },
502                         {0, 1, 0 },
503                         {0,     0, 1 },
504                 },
505
506                 {
507                         {1, 0, 0 },
508                         {0, 1, 0 },
509                         {0,     0, 1 },
510                 },
511
512                 {
513                         {1, 0, 0 },
514                         {0, 1, 0 },
515                         {0,     0, 1 },
516                 },
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
597
598 #ifdef CONFIG_FB_ROCKCHIP
599 static struct resource resource_fb[] = {
600         [0] = {
601                 .name  = "fb0 buf",
602                 .start = 0,
603                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
604                 .flags = IORESOURCE_MEM,
605         },
606         [1] = {
607                 .name  = "ipp buf",  //for rotate
608                 .start = 0,
609                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
610                 .flags = IORESOURCE_MEM,
611         },
612         [2] = {
613                 .name  = "fb2 buf",
614                 .start = 0,
615                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
616                 .flags = IORESOURCE_MEM,
617         },
618 };
619
620 static struct platform_device device_fb = {
621         .name             = "rk-fb",
622         .id               = -1,
623         .num_resources    = ARRAY_SIZE(resource_fb),
624         .resource         = resource_fb,
625 };
626 #endif
627
628 #ifdef CONFIG_ANDROID_TIMED_GPIO
629 static struct timed_gpio timed_gpios[] = {
630         {
631                 .name = "vibrator",
632                 .gpio = RK30_PIN0_PA4,
633                 .max_timeout = 1000,
634                 .active_low = 0,
635                 .adjust_time =20,      //adjust for diff product
636         },
637 };
638
639 struct timed_gpio_platform_data rk29_vibrator_info = {
640         .num_gpios = 1,
641         .gpios = timed_gpios,
642 };
643
644 struct platform_device rk29_device_vibrator ={
645         .name = "timed-gpio",
646         .id = -1,
647         .dev = {
648                 .platform_data = &rk29_vibrator_info,
649                 },
650
651 };
652 #endif 
653
654 #ifdef CONFIG_LEDS_GPIO_PLATFORM
655 struct gpio_led rk29_leds[] = {
656                 {
657                         .name = "button-backlight",
658                         .gpio = RK30_PIN4_PD7,
659                         .default_trigger = "timer",
660                         .active_low = 0,
661                         .retain_state_suspended = 0,
662                         .default_state = LEDS_GPIO_DEFSTATE_OFF,
663                 },
664 };
665
666 struct gpio_led_platform_data rk29_leds_pdata = {
667         .leds = &rk29_leds,
668         .num_leds       = ARRAY_SIZE(rk29_leds),
669 };
670
671 struct platform_device rk29_device_gpio_leds = {
672         .name   = "leds-gpio",
673         .id     = -1,
674         .dev    = {
675            .platform_data  = &rk29_leds_pdata,
676         },
677 };
678 #endif
679
680 #ifdef CONFIG_RK_IRDA
681 #define IRDA_IRQ_PIN           RK30_PIN6_PA1
682
683 int irda_iomux_init(void)
684 {
685         int ret = 0;
686
687         //irda irq pin
688         ret = gpio_request(IRDA_IRQ_PIN, NULL);
689         if(ret != 0)
690         {
691         gpio_free(IRDA_IRQ_PIN);
692         printk(">>>>>> IRDA_IRQ_PIN gpio_request err \n ");
693         }
694         gpio_pull_updown(IRDA_IRQ_PIN, PullDisable);
695         gpio_direction_input(IRDA_IRQ_PIN);
696
697         return 0;
698 }
699
700 int irda_iomux_deinit(void)
701 {
702         gpio_free(IRDA_IRQ_PIN);
703         return 0;
704 }
705
706 static struct irda_info rk29_irda_info = {
707         .intr_pin = IRDA_IRQ_PIN,
708         .iomux_init = irda_iomux_init,
709         .iomux_deinit = irda_iomux_deinit,
710         //.irda_pwr_ctl = bu92747guw_power_ctl,
711 };
712
713 static struct platform_device irda_device = {
714 #ifdef CONFIG_RK_IRDA_NET
715                         .name   = "rk_irda",
716 #else
717                         .name = "bu92747_irda",
718 #endif
719     .id           = -1,
720         .dev            = {
721                 .platform_data  = &rk29_irda_info,
722         }
723 };
724 #endif
725
726 #ifdef CONFIG_ION
727 #define ION_RESERVE_SIZE        (80 * SZ_1M)
728 static struct ion_platform_data rk30_ion_pdata = {
729         .nr = 1,
730         .heaps = {
731                 {
732                         .type = ION_HEAP_TYPE_CARVEOUT,
733                         .id = ION_NOR_HEAP_ID,
734                         .name = "norheap",
735                         .size = ION_RESERVE_SIZE,
736                 }
737         },
738 };
739
740 static struct platform_device device_ion = {
741         .name = "ion-rockchip",
742         .id = 0,
743         .dev = {
744                 .platform_data = &rk30_ion_pdata,
745         },
746 };
747 #endif
748
749 static struct platform_device *devices[] __initdata = {
750 #ifdef CONFIG_BACKLIGHT_RK29_BL
751         &rk29_device_backlight,
752 #endif  
753 #ifdef CONFIG_FB_ROCKCHIP
754         &device_fb,
755 #endif
756 #ifdef CONFIG_ION
757         &device_ion,
758 #endif
759 #ifdef CONFIG_ANDROID_TIMED_GPIO
760         &rk29_device_vibrator,
761 #endif
762 #ifdef CONFIG_LEDS_GPIO_PLATFORM
763         &rk29_device_gpio_leds,
764 #endif
765 #ifdef CONFIG_RK_IRDA
766         &irda_device,
767 #endif
768 };
769
770 // i2c
771 #ifdef CONFIG_I2C0_RK30
772 static struct i2c_board_info __initdata i2c0_info[] = {
773 #if defined (CONFIG_GS_MMA8452)
774             {
775               .type           = "gs_mma8452",
776               .addr           = 0x1c,
777               .flags          = 0,
778               .irq            = MMA8452_INT_PIN,
779               .platform_data  = &mma8452_info,
780             },
781 #endif
782 #if defined (CONFIG_COMPASS_AK8975)
783         {
784                 .type           = "ak8975",
785                 .addr           = 0x0d,
786                 .flags          = 0,
787                 .irq            = RK30_PIN4_PC1,
788                 .platform_data  = &akm8975_info,
789         },
790 #endif
791 #if defined (CONFIG_GYRO_L3G4200D)
792         {
793                 .type           = "l3g4200d_gryo",
794                 .addr           = 0x69,
795                 .flags          = 0,
796                 .irq            = L3G4200D_INT_PIN,
797                 .platform_data  = &l3g4200d_info,
798         },
799 #endif
800
801 #if defined (CONFIG_SND_SOC_RK1000)
802         {
803                 .type                   = "rk1000_i2c_codec",
804                 .addr           = 0x60,
805                 .flags                  = 0,
806         },
807         {
808                 .type                   = "rk1000_control",
809                 .addr                   = 0x40,
810                 .flags                  = 0,
811         },      
812 #endif
813 };
814 #endif
815
816 #ifdef CONFIG_I2C1_RK30
817 #include "board-rk30-sdk-wm8326.c"
818
819 static struct i2c_board_info __initdata i2c1_info[] = {
820 #if defined (CONFIG_MFD_WM831X_I2C)
821         {
822                 .type           = "wm8326",
823                 .addr           = 0x36,    //0x34    ,is Decided by cs
824                 .flags          = 0,
825                 .irq            = RK30_PIN6_PA4,
826                 .platform_data  = &wm831x_platdata,
827         },
828 #endif
829 };
830 #endif
831
832 #ifdef CONFIG_I2C2_RK30
833 static struct i2c_board_info __initdata i2c2_info[] = {
834 #if defined (CONFIG_TOUCHSCREEN_GT8XX)
835                     {
836                                 .type   = "Goodix-TS",
837                                 .addr   = 0x55,
838                                 .flags      =0,
839                                 .irq            =RK30_PIN4_PC2,
840                                 .platform_data = &goodix_info,
841                     },
842 #endif
843 #if defined (CONFIG_LS_CM3217)
844         {
845                 .type           = "lightsensor",
846                 .addr           = 0x20,
847                 .flags          = 0,
848                 .irq            = CM3217_IRQ_PIN,
849                 .platform_data  = &cm3217_info,
850         },
851 #endif
852
853 };
854 #endif
855
856 #ifdef CONFIG_I2C3_RK30
857 static struct i2c_board_info __initdata i2c3_info[] = {
858 };
859 #endif
860
861 #ifdef CONFIG_I2C4_RK30
862 static struct i2c_board_info __initdata i2c4_info[] = {
863 };
864 #endif
865
866 static void __init rk30_i2c_register_board_info(void)
867 {
868 #ifdef CONFIG_I2C0_RK30
869         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
870 #endif
871 #ifdef CONFIG_I2C1_RK30
872         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
873 #endif
874 #ifdef CONFIG_I2C2_RK30
875         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
876 #endif
877 #ifdef CONFIG_I2C3_RK30
878         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
879 #endif
880 #ifdef CONFIG_I2C4_RK30
881         i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info));
882 #endif
883 }
884 //end of i2c
885
886
887 /**************************************************************************************************
888  * SDMMC devices,  include the module of SD,MMC,sdio,and some BT.noted by xbw at 2012-03-05
889 **************************************************************************************************/
890 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
891 #define SDMMC0_WRITE_PROTECT_PIN                RK30_PIN3_PB7 //According to your own project to set the value of write-protect-pin.
892 #endif
893
894
895 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
896 #define SDMMC1_WRITE_PROTECT_PIN                RK30_PIN3_PC7 //According to your own project to set the value of write-protect-pin.
897 #endif
898
899 #if !defined(CONFIG_SDMMC_RK29_OLD)     
900 static void rk29_sdmmc_gpio_open(int device_id, int on)
901 {
902     switch(device_id)
903     {
904         case 0://mmc0
905         {
906             #ifdef CONFIG_SDMMC0_RK29
907             if(on)
908             {
909                 gpio_direction_output(GPIO3B_GPIO3B0,GPIO_HIGH);//set mmc0-clk to high
910                 gpio_direction_output(GPIO3B_GPIO3B1,GPIO_HIGH);// set mmc0-cmd to high.
911                 gpio_direction_output(GPIO3B_GPIO3B2,GPIO_HIGH);//set mmc0-data0 to high.
912                 gpio_direction_output(GPIO3B_GPIO3B3,GPIO_HIGH);//set mmc0-data1 to high.
913                 gpio_direction_output(GPIO3B_GPIO3B4,GPIO_HIGH);//set mmc0-data2 to high.
914                 gpio_direction_output(GPIO3B_GPIO3B5,GPIO_HIGH);//set mmc0-data3 to high.
915
916                 mdelay(30);
917             }
918             else
919             {
920                 rk30_mux_api_set(GPIO3B0_SDMMC0CLKOUT_NAME, GPIO3B_GPIO3B0);
921                 gpio_request(RK30_PIN3_PB0, "mmc0-clk");
922                 gpio_direction_output(RK30_PIN3_PB0,GPIO_LOW);//set mmc0-clk to low.
923
924                 rk30_mux_api_set(GPIO3B1_SDMMC0CMD_NAME, GPIO3B_GPIO3B1);
925                 gpio_request(RK30_PIN3_PB1, "mmc0-cmd");
926                 gpio_direction_output(RK30_PIN3_PB1,GPIO_LOW);//set mmc0-cmd to low.
927
928                 rk30_mux_api_set(GPIO3B2_SDMMC0DATA0_NAME, GPIO3B_GPIO3B2);
929                 gpio_request(RK30_PIN3_PB2, "mmc0-data0");
930                 gpio_direction_output(RK30_PIN3_PB2,GPIO_LOW);//set mmc0-data0 to low.
931
932                 rk30_mux_api_set(GPIO3B3_SDMMC0DATA1_NAME, GPIO3B_GPIO3B3);
933                 gpio_request(RK30_PIN3_PB3, "mmc0-data1");
934                 gpio_direction_output(RK30_PIN3_PB3,GPIO_LOW);//set mmc0-data1 to low.
935
936                 rk30_mux_api_set(GPIO3B4_SDMMC0DATA2_NAME, GPIO3B_GPIO3B4);
937                 gpio_request(RK30_PIN3_PB4, "mmc0-data2");
938                 gpio_direction_output(RK30_PIN3_PB4,GPIO_LOW);//set mmc0-data2 to low.
939
940                 rk30_mux_api_set(GPIO3B5_SDMMC0DATA3_NAME, GPIO3B_GPIO3B5);
941                 gpio_request(RK30_PIN3_PB5, "mmc0-data3");
942                 gpio_direction_output(RK30_PIN3_PB5,GPIO_LOW);//set mmc0-data3 to low.
943
944                 mdelay(30);
945             }
946             #endif
947         }
948         break;
949         
950         case 1://mmc1
951         {
952             #ifdef CONFIG_SDMMC1_RK29
953             if(on)
954             {
955                 gpio_direction_output(RK30_PIN3_PC5,GPIO_HIGH);//set mmc1-clk to high
956                 gpio_direction_output(RK30_PIN3_PC0,GPIO_HIGH);//set mmc1-cmd to high.
957                 gpio_direction_output(RK30_PIN3_PC1,GPIO_HIGH);//set mmc1-data0 to high.
958                 gpio_direction_output(RK30_PIN3_PC2,GPIO_HIGH);//set mmc1-data1 to high.
959                 gpio_direction_output(RK30_PIN3_PC3,GPIO_HIGH);//set mmc1-data2 to high.
960                 gpio_direction_output(RK30_PIN3_PC5,GPIO_HIGH);//set mmc1-data3 to high.
961                 mdelay(100);
962             }
963             else
964             {
965                 rk30_mux_api_set(GPIO3C5_SDMMC1CLKOUT_NAME, GPIO3C_GPIO3C5);
966                 gpio_request(RK30_PIN3_PC5, "mmc1-clk");
967                 gpio_direction_output(RK30_PIN3_PC5,GPIO_LOW);//set mmc1-clk to low.
968
969                 rk30_mux_api_set(GPIO3C0_SMMC1CMD_NAME, GPIO3C_GPIO3C0);
970                 gpio_request(RK30_PIN3_PC0, "mmc1-cmd");
971                 gpio_direction_output(RK30_PIN3_PC0,GPIO_LOW);//set mmc1-cmd to low.
972
973                 rk30_mux_api_set(GPIO3C1_SDMMC1DATA0_NAME, GPIO3C_GPIO3C1);
974                 gpio_request(RK30_PIN3_PC1, "mmc1-data0");
975                 gpio_direction_output(RK30_PIN3_PC1,GPIO_LOW);//set mmc1-data0 to low.
976
977                 mdelay(100);
978             }
979             #endif
980         }
981         break; 
982         
983         case 2: //mmc2
984         break;
985         
986         default:
987         break;
988     }
989 }
990
991 static void rk29_sdmmc_set_iomux_mmc0(unsigned int bus_width)
992 {
993     switch (bus_width)
994     {
995         
996         case 1://SDMMC_CTYPE_4BIT:
997         {
998                 rk30_mux_api_set(GPIO3B3_SDMMC0DATA1_NAME, GPIO3B_SDMMC0_DATA1);
999                 rk30_mux_api_set(GPIO3B4_SDMMC0DATA2_NAME, GPIO3B_SDMMC0_DATA2);
1000                 rk30_mux_api_set(GPIO3B5_SDMMC0DATA3_NAME, GPIO3B_SDMMC0_DATA3);
1001         }
1002         break;
1003
1004         case 0x10000://SDMMC_CTYPE_8BIT:
1005             break;
1006         case 0xFFFF: //gpio_reset
1007         {
1008             rk30_mux_api_set(GPIO3A7_SDMMC0PWREN_NAME, GPIO3A_GPIO3A7);
1009             gpio_request(RK30_PIN3_PA7,"sdmmc-power");
1010             gpio_direction_output(RK30_PIN3_PA7,GPIO_HIGH); //power-off
1011
1012             rk29_sdmmc_gpio_open(0, 0);
1013
1014             gpio_direction_output(RK30_PIN3_PA7,GPIO_LOW); //power-on
1015
1016             rk29_sdmmc_gpio_open(0, 1);
1017         }
1018         break;
1019
1020         default: //case 0://SDMMC_CTYPE_1BIT:
1021         {
1022                 rk30_mux_api_set(GPIO3B1_SDMMC0CMD_NAME, GPIO3B_SDMMC0_CMD);
1023                 rk30_mux_api_set(GPIO3B0_SDMMC0CLKOUT_NAME, GPIO3B_SDMMC0_CLKOUT);
1024                 rk30_mux_api_set(GPIO3B2_SDMMC0DATA0_NAME, GPIO3B_SDMMC0_DATA0);
1025
1026             rk30_mux_api_set(GPIO3B3_SDMMC0DATA1_NAME, GPIO3B_GPIO3B3);
1027             gpio_request(RK30_PIN3_PB3, "mmc0-data1");
1028             gpio_direction_output(RK30_PIN3_PB3,GPIO_HIGH);//set mmc0-data1 to high.
1029
1030             rk30_mux_api_set(GPIO3B4_SDMMC0DATA2_NAME, GPIO3B_GPIO3B4);
1031             gpio_request(RK30_PIN3_PB4, "mmc0-data2");
1032             gpio_direction_output(RK30_PIN3_PB4,GPIO_HIGH);//set mmc0-data2 to high.
1033
1034             rk30_mux_api_set(GPIO3B5_SDMMC0DATA3_NAME, GPIO3B_GPIO3B5);
1035             gpio_request(RK30_PIN3_PB5, "mmc0-data3");
1036             gpio_direction_output(RK30_PIN3_PB5,GPIO_HIGH);//set mmc0-data3 to high.
1037         }
1038         break;
1039         }
1040 }
1041
1042 static void rk29_sdmmc_set_iomux_mmc1(unsigned int bus_width)
1043 {
1044     rk30_mux_api_set(GPIO3C0_SMMC1CMD_NAME, GPIO3C_SMMC1_CMD);
1045     rk30_mux_api_set(GPIO3C5_SDMMC1CLKOUT_NAME, GPIO3C_SDMMC1_CLKOUT);
1046     rk30_mux_api_set(GPIO3C1_SDMMC1DATA0_NAME, GPIO3C_SDMMC1_DATA0);
1047     rk30_mux_api_set(GPIO3C2_SDMMC1DATA1_NAME, GPIO3C_SDMMC1_DATA1);
1048     rk30_mux_api_set(GPIO3C3_SDMMC1DATA2_NAME, GPIO3C_SDMMC1_DATA2);
1049     rk30_mux_api_set(GPIO3C4_SDMMC1DATA3_NAME, GPIO3C_SDMMC1_DATA3);
1050 }
1051
1052 static void rk29_sdmmc_set_iomux_mmc2(unsigned int bus_width)
1053 {
1054     ;//
1055 }
1056
1057 static void rk29_sdmmc_set_iomux(int device_id, unsigned int bus_width)
1058 {
1059     switch(device_id)
1060     {
1061         case 0:
1062             #ifdef CONFIG_SDMMC0_RK29
1063             rk29_sdmmc_set_iomux_mmc0(bus_width);
1064             #endif
1065             break;
1066         case 1:
1067             #ifdef CONFIG_SDMMC1_RK29
1068             rk29_sdmmc_set_iomux_mmc1(bus_width);
1069             #endif
1070             break;
1071         case 2:
1072             rk29_sdmmc_set_iomux_mmc2(bus_width);
1073             break;
1074         default:
1075             break;
1076     }    
1077 }
1078
1079 #endif
1080
1081
1082 #ifdef CONFIG_SDMMC0_RK29
1083 static int rk29_sdmmc0_cfg_gpio(void)
1084 {
1085 #ifdef CONFIG_SDMMC_RK29_OLD    
1086     rk30_mux_api_set(GPIO3B1_SDMMC0CMD_NAME, GPIO3B_SDMMC0_CMD);
1087     rk30_mux_api_set(GPIO3B0_SDMMC0CLKOUT_NAME, GPIO3B_SDMMC0_CLKOUT);
1088     rk30_mux_api_set(GPIO3B2_SDMMC0DATA0_NAME, GPIO3B_SDMMC0_DATA0);
1089     rk30_mux_api_set(GPIO3B3_SDMMC0DATA1_NAME, GPIO3B_SDMMC0_DATA1);
1090     rk30_mux_api_set(GPIO3B4_SDMMC0DATA2_NAME, GPIO3B_SDMMC0_DATA2);
1091     rk30_mux_api_set(GPIO3B5_SDMMC0DATA3_NAME, GPIO3B_SDMMC0_DATA3);
1092         
1093         rk30_mux_api_set(GPIO3B6_SDMMC0DETECTN_NAME, GPIO3B_GPIO3B6);
1094
1095     rk30_mux_api_set(GPIO3A7_SDMMC0PWREN_NAME, GPIO3A_GPIO3A7);
1096         gpio_request(RK30_PIN3_PA7,"sdmmc-power");
1097         gpio_direction_output(RK30_PIN3_PA7,GPIO_LOW);
1098         
1099 #else
1100     rk29_sdmmc_set_iomux(0, 0xFFFF);
1101     
1102         rk30_mux_api_set(GPIO3B6_SDMMC0DETECTN_NAME, GPIO3B_SDMMC0_DETECT_N);
1103
1104         #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
1105     gpio_request(SDMMC0_WRITE_PROTECT_PIN,"sdmmc-wp");
1106     gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);         
1107     #endif
1108
1109 #endif
1110
1111         return 0;
1112 }
1113
1114 #define CONFIG_SDMMC0_USE_DMA
1115 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
1116         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
1117                                            MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33|
1118                                            MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
1119         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
1120         .io_init = rk29_sdmmc0_cfg_gpio,
1121         
1122 #if !defined(CONFIG_SDMMC_RK29_OLD)             
1123         .set_iomux = rk29_sdmmc_set_iomux,
1124 #endif
1125
1126         .dma_name = "sd_mmc",
1127 #ifdef CONFIG_SDMMC0_USE_DMA
1128         .use_dma  = 1,
1129 #else
1130         .use_dma = 0,
1131 #endif
1132         .detect_irq = RK30_PIN3_PB6, // INVALID_GPIO
1133         .enable_sd_wakeup = 0,
1134
1135 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
1136     .write_prt = SDMMC0_WRITE_PROTECT_PIN,
1137 #else
1138     .write_prt = INVALID_GPIO,
1139 #endif
1140 };
1141 #endif//endif--#ifdef CONFIG_SDMMC0_RK29
1142
1143 #ifdef CONFIG_SDMMC1_RK29
1144 #define CONFIG_SDMMC1_USE_DMA
1145 static int rk29_sdmmc1_cfg_gpio(void)
1146 {
1147 #if defined(CONFIG_SDMMC_RK29_OLD)
1148         rk30_mux_api_set(GPIO3C0_SMMC1CMD_NAME, GPIO3C_SMMC1_CMD);
1149     rk30_mux_api_set(GPIO3C5_SDMMC1CLKOUT_NAME, GPIO3C_SDMMC1_CLKOUT);
1150     rk30_mux_api_set(GPIO3C1_SDMMC1DATA0_NAME, GPIO3C_SDMMC1_DATA0);
1151     rk30_mux_api_set(GPIO3C2_SDMMC1DATA1_NAME, GPIO3C_SDMMC1_DATA1);
1152     rk30_mux_api_set(GPIO3C3_SDMMC1DATA2_NAME, GPIO3C_SDMMC1_DATA2);
1153     rk30_mux_api_set(GPIO3C4_SDMMC1DATA3_NAME, GPIO3C_SDMMC1_DATA3);
1154         //rk30_mux_api_set(GPIO3C6_SDMMC1DETECTN_NAME, GPIO3C_SDMMC1_DETECT_N);
1155
1156 #else
1157
1158 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
1159     gpio_request(SDMMC1_WRITE_PROTECT_PIN,"sdio-wp");
1160     gpio_direction_input(SDMMC1_WRITE_PROTECT_PIN);         
1161 #endif
1162
1163 #endif
1164
1165         return 0;
1166 }
1167
1168
1169
1170 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK30_PIN6_PB2
1171
1172 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
1173         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
1174                                            MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
1175                                            MMC_VDD_32_33|MMC_VDD_33_34),
1176                                            
1177 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)                                     
1178         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
1179                                    MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
1180 #else
1181     .host_caps  = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
1182 #endif
1183
1184         .io_init = rk29_sdmmc1_cfg_gpio,
1185         
1186 #if !defined(CONFIG_SDMMC_RK29_OLD)             
1187         .set_iomux = rk29_sdmmc_set_iomux,
1188 #endif  
1189
1190         .dma_name = "sdio",
1191 #ifdef CONFIG_SDMMC1_USE_DMA
1192         .use_dma  = 1,
1193 #else
1194         .use_dma = 0,
1195 #endif
1196
1197 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
1198 #ifdef CONFIG_WIFI_CONTROL_FUNC
1199         .status = rk29sdk_wifi_status,
1200         .register_status_notify = rk29sdk_wifi_status_register,
1201 #endif
1202 #if 0
1203         .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
1204 #endif
1205
1206 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
1207     .write_prt = SDMMC1_WRITE_PROTECT_PIN,
1208 #else
1209     .write_prt = INVALID_GPIO, 
1210 #endif  
1211
1212 #else
1213     .detect_irq = INVALID_GPIO,
1214     .enable_sd_wakeup = 0,
1215 #endif
1216
1217 };
1218 #endif //endif--#ifdef CONFIG_SDMMC1_RK29
1219
1220 int rk29sdk_wifi_power_state = 0;
1221 int rk29sdk_bt_power_state = 0;
1222
1223 #ifdef CONFIG_WIFI_CONTROL_FUNC
1224 #define RK29SDK_WIFI_BT_GPIO_POWER_N       RK30_PIN3_PD0
1225 #define RK29SDK_WIFI_GPIO_RESET_N          RK30_PIN3_PD2
1226 #define RK29SDK_BT_GPIO_RESET_N            RK30_PIN3_PD1
1227
1228 static int rk29sdk_wifi_cd = 0;   /* wifi virtual 'card detect' status */
1229 static void (*wifi_status_cb)(int card_present, void *dev_id);
1230 static void *wifi_status_cb_devid;
1231
1232 static int rk29sdk_wifi_status(struct device *dev)
1233 {
1234         return rk29sdk_wifi_cd;
1235 }
1236
1237 static int rk29sdk_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
1238 {
1239         if(wifi_status_cb)
1240                 return -EAGAIN;
1241         wifi_status_cb = callback;
1242         wifi_status_cb_devid = dev_id;
1243         return 0;
1244 }
1245
1246 static int rk29sdk_wifi_bt_gpio_control_init(void)
1247 {
1248     if (gpio_request(RK29SDK_WIFI_BT_GPIO_POWER_N, "wifi_bt_power")) {
1249            pr_info("%s: request wifi_bt power gpio failed\n", __func__);
1250            return -1;
1251     }
1252
1253     if (gpio_request(RK29SDK_WIFI_GPIO_RESET_N, "wifi reset")) {
1254            pr_info("%s: request wifi reset gpio failed\n", __func__);
1255            gpio_free(RK29SDK_WIFI_BT_GPIO_POWER_N);
1256            return -1;
1257     }
1258
1259     if (gpio_request(RK29SDK_BT_GPIO_RESET_N, "bt reset")) {
1260           pr_info("%s: request bt reset gpio failed\n", __func__);
1261           gpio_free(RK29SDK_WIFI_GPIO_RESET_N);
1262           return -1;
1263     }
1264
1265     gpio_direction_output(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
1266     gpio_direction_output(RK29SDK_WIFI_GPIO_RESET_N,    GPIO_LOW);
1267     gpio_direction_output(RK29SDK_BT_GPIO_RESET_N,      GPIO_LOW);
1268
1269     #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
1270     
1271     rk29_mux_api_set(GPIO3C2_SDMMC1DATA1_NAME, GPIO3C_GPIO3C2);
1272     gpio_request(RK30_PIN3_PC2, "mmc1-data1");
1273     gpio_direction_output(RK30_PIN3_PC2,GPIO_LOW);//set mmc1-data1 to low.
1274
1275     rk29_mux_api_set(GPIO3C3_SDMMC1DATA2_NAME, GPIO3C_GPIO3C3);
1276     gpio_request(RK30_PIN3_PC3, "mmc1-data2");
1277     gpio_direction_output(RK30_PIN3_PC3,GPIO_LOW);//set mmc1-data2 to low.
1278
1279     rk29_mux_api_set(GPIO3C4_SDMMC1DATA3_NAME, GPIO3C_GPIO3C4);
1280     gpio_request(RK30_PIN3_PC4, "mmc1-data3");
1281     gpio_direction_output(RK30_PIN3_PC4,GPIO_LOW);//set mmc1-data3 to low.
1282     
1283     rk29_sdmmc_gpio_open(1, 0); //added by xbw at 2011-10-13
1284     #endif    
1285     pr_info("%s: init finished\n",__func__);
1286
1287     return 0;
1288 }
1289
1290 static int rk29sdk_wifi_power(int on)
1291 {
1292         pr_info("%s: %d\n", __func__, on);
1293         if (on){
1294                 gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_HIGH);
1295
1296                 #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)      
1297                 rk29_sdmmc_gpio_open(1, 1); //added by xbw at 2011-10-13
1298                 #endif
1299
1300                 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_HIGH);
1301                 mdelay(100);
1302                 pr_info("wifi turn on power\n");
1303         }else{
1304                 if (!rk29sdk_bt_power_state){
1305                         gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
1306
1307                         #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)      
1308                         rk29_sdmmc_gpio_open(1, 0); //added by xbw at 2011-10-13
1309                         #endif
1310                         
1311                         mdelay(100);
1312                         pr_info("wifi shut off power\n");
1313                 }else
1314                 {
1315                         pr_info("wifi shouldn't shut off power, bt is using it!\n");
1316                 }
1317                 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
1318
1319         }
1320
1321         rk29sdk_wifi_power_state = on;
1322         return 0;
1323 }
1324
1325 static int rk29sdk_wifi_reset_state;
1326 static int rk29sdk_wifi_reset(int on)
1327 {
1328         pr_info("%s: %d\n", __func__, on);
1329         gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, on);
1330         mdelay(100);
1331         rk29sdk_wifi_reset_state = on;
1332         return 0;
1333 }
1334
1335 int rk29sdk_wifi_set_carddetect(int val)
1336 {
1337         pr_info("%s:%d\n", __func__, val);
1338         rk29sdk_wifi_cd = val;
1339         if (wifi_status_cb){
1340                 wifi_status_cb(val, wifi_status_cb_devid);
1341         }else {
1342                 pr_warning("%s, nobody to notify\n", __func__);
1343         }
1344         return 0;
1345 }
1346 EXPORT_SYMBOL(rk29sdk_wifi_set_carddetect);
1347
1348 static struct wifi_mem_prealloc wifi_mem_array[PREALLOC_WLAN_SEC_NUM] = {
1349         {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
1350         {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
1351         {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
1352         {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)}
1353 };
1354
1355 static void *rk29sdk_mem_prealloc(int section, unsigned long size)
1356 {
1357         if (section == PREALLOC_WLAN_SEC_NUM)
1358                 return wlan_static_skb;
1359
1360         if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM))
1361                 return NULL;
1362
1363         if (wifi_mem_array[section].size < size)
1364                 return NULL;
1365
1366         return wifi_mem_array[section].mem_ptr;
1367 }
1368
1369 int __init rk29sdk_init_wifi_mem(void)
1370 {
1371         int i;
1372         int j;
1373
1374         for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
1375                 wlan_static_skb[i] = dev_alloc_skb(
1376                                 ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
1377
1378                 if (!wlan_static_skb[i])
1379                         goto err_skb_alloc;
1380         }
1381
1382         for (i = 0 ; i < PREALLOC_WLAN_SEC_NUM ; i++) {
1383                 wifi_mem_array[i].mem_ptr =
1384                                 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
1385
1386                 if (!wifi_mem_array[i].mem_ptr)
1387                         goto err_mem_alloc;
1388         }
1389         return 0;
1390
1391 err_mem_alloc:
1392         pr_err("Failed to mem_alloc for WLAN\n");
1393         for (j = 0 ; j < i ; j++)
1394                kfree(wifi_mem_array[j].mem_ptr);
1395
1396         i = WLAN_SKB_BUF_NUM;
1397
1398 err_skb_alloc:
1399         pr_err("Failed to skb_alloc for WLAN\n");
1400         for (j = 0 ; j < i ; j++)
1401                 dev_kfree_skb(wlan_static_skb[j]);
1402
1403         return -ENOMEM;
1404 }
1405
1406 static struct wifi_platform_data rk29sdk_wifi_control = {
1407         .set_power = rk29sdk_wifi_power,
1408         .set_reset = rk29sdk_wifi_reset,
1409         .set_carddetect = rk29sdk_wifi_set_carddetect,
1410         .mem_prealloc   = rk29sdk_mem_prealloc,
1411 };
1412 static struct platform_device rk29sdk_wifi_device = {
1413         .name = "bcm4329_wlan",
1414         .id = 1,
1415         .dev = {
1416                 .platform_data = &rk29sdk_wifi_control,
1417          },
1418 };
1419 #endif
1420
1421
1422 /* bluetooth rfkill device */
1423 static struct platform_device rk29sdk_rfkill = {
1424         .name = "rk29sdk_rfkill",
1425         .id = -1,
1426 };
1427
1428 /**************************************************************************************************
1429  * the end of setting for SDMMC devices
1430 **************************************************************************************************/
1431
1432 static void __init machine_rk30_board_init(void)
1433 {
1434         rk30_i2c_register_board_info();
1435         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1436         platform_add_devices(devices, ARRAY_SIZE(devices));
1437 }
1438
1439 static void __init rk30_reserve(void)
1440 {
1441 #ifdef CONFIG_ION
1442         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion",ION_RESERVE_SIZE);
1443 #endif
1444 #ifdef CONFIG_FB_ROCKCHIP
1445         resource_fb[0].start = board_mem_reserve_add("fb0",RK30_FB0_MEM_SIZE);
1446         resource_fb[0].end = resource_fb[0].start + RK30_FB0_MEM_SIZE - 1;
1447         resource_fb[1].start = board_mem_reserve_add("ipp buf",RK30_FB0_MEM_SIZE);
1448         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
1449         resource_fb[2].start = board_mem_reserve_add("fb2",RK30_FB0_MEM_SIZE);
1450         resource_fb[2].end = resource_fb[2].start + RK30_FB0_MEM_SIZE - 1;      
1451 #endif
1452
1453 #if (MEM_CAMIPP_SIZE != 0)
1454         #if CONFIG_USE_CIF_0
1455         rk_camera_platform_data.meminfo.name = "camera_ipp_mem_0";
1456         rk_camera_platform_data.meminfo.start = board_mem_reserve_add("camera_ipp_mem_0",MEM_CAMIPP_SIZE);
1457         rk_camera_platform_data.meminfo.size= MEM_CAMIPP_SIZE;
1458         #endif
1459         #if CONFIG_USE_CIF_1
1460         rk_camera_platform_data.meminfo_cif1.name = "camera_ipp_mem_1";
1461         rk_camera_platform_data.meminfo_cif1.start =board_mem_reserve_add("camera_ipp_mem_1",MEM_CAMIPP_SIZE);
1462         rk_camera_platform_data.meminfo_cif1.size= MEM_CAMIPP_SIZE;
1463         #endif
1464 #endif
1465
1466 #if (PMEM_CAM_SIZE != 0)
1467         android_pmem_cam_pdata.start = board_mem_reserve_add("camera_pmem",PMEM_CAM_SIZE);
1468         android_pmem_cam_pdata.size = PMEM_CAM_SIZE;
1469 #endif
1470
1471         board_mem_reserved();
1472 }
1473
1474 MACHINE_START(RK30, "RK30board")
1475         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
1476         .fixup          = rk30_fixup,
1477         .reserve        = &rk30_reserve,
1478         .map_io         = rk30_map_io,
1479         .init_irq       = rk30_init_irq,
1480         .timer          = &rk30_timer,
1481         .init_machine   = machine_rk30_board_init,
1482 MACHINE_END