camera driver v0.2.1 for RK30
[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_RK
58 /*---------------- Camera Sensor Macro Define Begin  ------------------------*/
59 /*---------------- Camera Sensor Configuration Macro Begin ------------------------*/
60 #define CONFIG_SENSOR_0 RK_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 RK_CAM_POWERACTIVE_L
70 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_0 RK_CAM_RESETACTIVE_L
71 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_0 RK_CAM_POWERDNACTIVE_H
72 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_0 RK_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 RK_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 RK_CAM_POWERACTIVE_L
92 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_1 RK_CAM_RESETACTIVE_L
93 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_1 RK_CAM_POWERDNACTIVE_H
94 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_1 RK_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/rk_camera.c"
109 /*---------------- Camera Sensor Macro Define End  ---------*/
110
111 #define PMEM_CAM_SIZE           PMEM_CAM_NECESSARY
112 #ifdef CONFIG_VIDEO_RK_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_RK
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 rkcamera_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 rkcamera_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 rkcamera_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 rkcamera_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 rkcamera_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                 {0x3000, 0x0f,0,0},
183                 {0x3001, 0xff,0,0},
184                 {0x3002, 0xff,0,0},
185                 //{0x0100, 0x01},       //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array
186                 {0x3633, 0x3d,0,0},
187                 {0x3620, 0x02,0,0},
188                 {0x3631, 0x11,0,0},
189                 {0x3612, 0x04,0,0},
190                 {0x3630, 0x20,0,0},
191                 {0x4702, 0x02,0,0},
192                 {0x370c, 0x34,0,0},
193                 {0x3004, 0x10,0,0},
194                 {0x3005, 0x18,0,0},
195                 {0x3800, 0x00,0,0},
196                 {0x3801, 0x00,0,0},
197                 {0x3802, 0x00,0,0},
198                 {0x3803, 0x00,0,0},
199                 {0x3804, 0x06,0,0},
200                 {0x3805, 0x5f,0,0},
201                 {0x3806, 0x04,0,0},
202                 {0x3807, 0xb7,0,0},
203                 {0x3808, 0x03,0,0},
204                 {0x3809, 0x20,0,0},
205                 {0x380a, 0x02,0,0},
206                 {0x380b, 0x58,0,0},
207                 {0x380c, 0x05,0,0},
208                 {0x380d, 0x14,0,0},
209                 {0x380e, 0x02,0,0},
210                 {0x380f, 0x68,0,0},
211                 {0x3811, 0x08,0,0},
212                 {0x3813, 0x02,0,0},
213                 {0x3814, 0x31,0,0},
214                 {0x3815, 0x31,0,0},
215                 {0x3a02, 0x02,0,0},
216                 {0x3a03, 0x68,0,0},
217                 {0x3a08, 0x00,0,0},
218                 {0x3a09, 0x5c,0,0},
219                 {0x3a0a, 0x00,0,0},
220                 {0x3a0b, 0x4d,0,0},
221                 {0x3a0d, 0x08,0,0},
222                 {0x3a0e, 0x06,0,0},
223                 {0x3a14, 0x02,0,0},
224                 {0x3a15, 0x28,0,0},
225                         {0x4708, 0x01,0,0},
226                 {0x3623, 0x00,0,0},
227                 {0x3634, 0x76,0,0},
228                 {0x3701, 0x44,0,0},
229                 {0x3702, 0x18,0,0},
230                 {0x3703, 0x24,0,0},
231                 {0x3704, 0x24,0,0},
232                 {0x3705, 0x0c,0,0},
233                 {0x3820, 0x81,0,0},
234                 {0x3821, 0x01,0,0},
235                 {0x370a, 0x52,0,0},
236                 {0x4608, 0x00,0,0},
237                 {0x4609, 0x80,0,0},
238                 {0x4300, 0x32,0,0},
239                 {0x5086, 0x02,0,0},
240                 {0x5000, 0xfb,0,0},
241                 {0x5001, 0x1f,0,0},
242                 {0x5002, 0x00,0,0},
243                 {0x5025, 0x0e,0,0},
244                 {0x5026, 0x18,0,0},
245                 {0x5027, 0x34,0,0},
246                 {0x5028, 0x4c,0,0},
247                 {0x5029, 0x62,0,0},
248                 {0x502a, 0x74,0,0},
249                 {0x502b, 0x85,0,0},
250                 {0x502c, 0x92,0,0},
251                 {0x502d, 0x9e,0,0},
252                 {0x502e, 0xb2,0,0},
253                 {0x502f, 0xc0,0,0},
254                 {0x5030, 0xcc,0,0},
255                 {0x5031, 0xe0,0,0},
256                 {0x5032, 0xee,0,0},
257                 {0x5033, 0xf6,0,0},
258                 {0x5034, 0x11,0,0},
259                 {0x5070, 0x1c,0,0},
260                 {0x5071, 0x5b,0,0},
261                 {0x5072, 0x05,0,0},
262                 {0x5073, 0x20,0,0},
263                 {0x5074, 0x94,0,0},
264                 {0x5075, 0xb4,0,0},
265                 {0x5076, 0xb4,0,0},
266                 {0x5077, 0xaf,0,0},
267                 {0x5078, 0x05,0,0},
268                 {0x5079, 0x98,0,0},
269                 {0x507a, 0x21,0,0},
270                 {0x5035, 0x6a,0,0},
271                 {0x5036, 0x11,0,0},
272                 {0x5037, 0x92,0,0},
273                 {0x5038, 0x21,0,0},
274         
275                 {0x5039, 0xe1,0,0},
276                 {0x503a, 0x01,0,0},
277                 {0x503c, 0x05,0,0},
278                 {0x503d, 0x08,0,0},
279                 {0x503e, 0x08,0,0},
280                 {0x503f, 0x64,0,0},
281                 {0x5040, 0x58,0,0},
282                 {0x5041, 0x2a,0,0},
283                 {0x5042, 0xc5,0,0},
284                 {0x5043, 0x2e,0,0},
285                 {0x5044, 0x3a,0,0},
286                 {0x5045, 0x3c,0,0},
287                 {0x5046, 0x44,0,0},
288                 {0x5047, 0xf8,0,0},
289                 {0x5048, 0x08,0,0},
290                 {0x5049, 0x70,0,0},
291                 {0x504a, 0xf0,0,0},
292                 {0x504b, 0xf0,0,0},
293                 {0x500c, 0x03,0,0},
294                 {0x500d, 0x20,0,0},
295                 {0x500e, 0x02,0,0},
296                 {0x500f, 0x5c,0,0},
297                 {0x5010, 0x48,0,0},
298                 {0x5011, 0x00,0,0},
299                 {0x5012, 0x66,0,0},
300                 {0x5013, 0x03,0,0},
301                 {0x5014, 0x30,0,0},
302                 {0x5015, 0x02,0,0},
303                 {0x5016, 0x7c,0,0},
304                 {0x5017, 0x40,0,0},
305                 {0x5018, 0x00,0,0},
306                 {0x5019, 0x66,0,0},
307                 {0x501a, 0x03,0,0},
308                 {0x501b, 0x10,0,0},
309                 {0x501c, 0x02,0,0},
310                 {0x501d, 0x7c,0,0},
311                 {0x501e, 0x3a,0,0},
312                 {0x501f, 0x00,0,0},
313                 {0x5020, 0x66,0,0},
314                 {0x506e, 0x44,0,0},
315                 {0x5064, 0x08,0,0},
316                 {0x5065, 0x10,0,0},
317                 {0x5066, 0x12,0,0},
318                 {0x5067, 0x02,0,0},
319                 {0x506c, 0x08,0,0},
320                 {0x506d, 0x10,0,0},
321                 {0x506f, 0xa6,0,0},
322                 {0x5068, 0x08,0,0},
323         
324         
325                 {0x5069, 0x10,0,0},
326                 {0x506a, 0x04,0,0},
327                 {0x506b, 0x12,0,0},
328                 {0x507e, 0x40,0,0},
329                 {0x507f, 0x20,0,0},
330                 {0x507b, 0x02,0,0},
331                 {0x507a, 0x01,0,0},
332                 {0x5084, 0x0c,0,0},
333                 {0x5085, 0x3e,0,0},
334                 {0x5005, 0x80,0,0},
335                 {0x3a0f, 0x30,0,0},
336                 {0x3a10, 0x28,0,0},
337                 {0x3a1b, 0x32,0,0},
338                 {0x3a1e, 0x26,0,0},
339                 {0x3a11, 0x60,0,0},
340                 {0x3a1f, 0x14,0,0},
341                 {0x5060, 0x69,0,0},
342                 {0x5061, 0x7d,0,0},
343                 {0x5062, 0x7d,0,0},
344                 {0x5063, 0x69,0,0},
345                 {0x3004, 0x20,0,0},
346                         {0x0100, 0x01,0,0},
347                 {0x0000, 0x00,0,0}
348         };
349 static struct reginfo_t rk_init_data_sensor_winseqreg_0[] ={
350         {0x0000, 0x00,0,0}
351         };
352 static rk_sensor_user_init_data_s rk_init_data_sensor_0 = 
353 {       
354         .rk_sensor_init_width = INVALID_VALUE,
355         .rk_sensor_init_height = INVALID_VALUE,
356         .rk_sensor_init_bus_param = INVALID_VALUE,
357         .rk_sensor_init_pixelcode = INVALID_VALUE,
358         .rk_sensor_init_data = rk_init_data_sensor_reg_0,
359         .rk_sensor_init_winseq = NULL,//rk_init_data_sensor_winseqreg_0,
360         .rk_sensor_winseq_size = sizeof(rk_init_data_sensor_winseqreg_0) / sizeof(struct reginfo_t),
361         
362 };
363 static rk_sensor_user_init_data_s* rk_init_data_sensor_0_p = &rk_init_data_sensor_0;
364 static rk_sensor_user_init_data_s* rk_init_data_sensor_1_p = NULL;
365 #include "../../../drivers/media/video/rk_camera.c"
366
367 #endif
368
369 #if defined(CONFIG_TOUCHSCREEN_GT8XX)
370 #define TOUCH_RESET_PIN  RK30_PIN4_PD0
371 #define TOUCH_PWR_PIN    INVALID_GPIO
372 int goodix_init_platform_hw(void)
373 {
374         int ret;
375         printk("goodix_init_platform_hw\n");
376         if(TOUCH_PWR_PIN != INVALID_GPIO)
377         {
378                 ret = gpio_request(TOUCH_PWR_PIN, "goodix power pin");
379                 if(ret != 0){
380                         gpio_free(TOUCH_PWR_PIN);
381                         printk("goodix power error\n");
382                         return -EIO;
383                 }
384                 gpio_direction_output(TOUCH_PWR_PIN, 0);
385                 gpio_set_value(TOUCH_PWR_PIN,GPIO_LOW);
386                 msleep(100);
387         }
388         
389         if(TOUCH_RESET_PIN != INVALID_GPIO)
390         {
391                 ret = gpio_request(TOUCH_RESET_PIN, "goodix reset pin");
392                 if(ret != 0){
393                         gpio_free(TOUCH_RESET_PIN);
394                         printk("goodix gpio_request error\n");
395                         return -EIO;
396                 }
397                 gpio_direction_output(TOUCH_RESET_PIN, 0);
398                 gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
399                 msleep(10);
400                 gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
401                 msleep(500);
402         }
403         return 0;
404 }
405
406 struct goodix_platform_data goodix_info = {
407           .model= 8105,
408           .irq_pin = RK30_PIN4_PC2,
409           .rest_pin  = TOUCH_RESET_PIN,
410           .init_platform_hw = goodix_init_platform_hw,
411 };
412 #endif
413
414
415 /*****************************************************************************************
416  * xpt2046 touch panel
417  * author: hhb@rock-chips.com
418  *****************************************************************************************/
419 #if defined(CONFIG_TOUCHSCREEN_XPT2046_NORMAL_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_TSLIB_SPI)
420 #define XPT2046_GPIO_INT        RK30_PIN4_PC2 
421 #define DEBOUNCE_REPTIME        3
422
423
424 static struct xpt2046_platform_data xpt2046_info = {
425         .model                  = 2046,
426         .keep_vref_on           = 1,
427         .swap_xy                = 0,
428         .debounce_max           = 7,
429         .debounce_rep           = DEBOUNCE_REPTIME,
430         .debounce_tol           = 20,
431         .gpio_pendown           = XPT2046_GPIO_INT,
432         .pendown_iomux_name = GPIO4C2_SMCDATA2_TRACEDATA2_NAME, 
433         .pendown_iomux_mode = GPIO4C_GPIO4C2,   
434         .touch_virtualkey_length = 60,
435         .penirq_recheck_delay_usecs = 1,
436 #if defined(CONFIG_TOUCHSCREEN_480X800)
437         .x_min                  = 0,
438         .x_max                  = 480,
439         .y_min                  = 0,
440         .y_max                  = 800,
441         .touch_ad_top = 3940,
442         .touch_ad_bottom = 310,
443         .touch_ad_left = 3772,
444         .touch_ad_right = 340,
445 #elif defined(CONFIG_TOUCHSCREEN_800X480)
446         .x_min                  = 0,
447         .x_max                  = 800,
448         .y_min                  = 0,
449         .y_max                  = 480,
450         .touch_ad_top = 2447,
451         .touch_ad_bottom = 207,
452         .touch_ad_left = 5938,
453         .touch_ad_right = 153,
454 #elif defined(CONFIG_TOUCHSCREEN_320X480)
455         .x_min                  = 0,
456         .x_max                  = 320,
457         .y_min                  = 0,
458         .y_max                  = 480,
459         .touch_ad_top = 3166,
460         .touch_ad_bottom = 256,
461         .touch_ad_left = 3658,
462         .touch_ad_right = 380,
463 #endif  
464 };
465 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
466 static struct xpt2046_platform_data xpt2046_info = {
467         .model                  = 2046,
468         .keep_vref_on   = 1,
469         .swap_xy                = 0,
470         .debounce_max           = 7,
471         .debounce_rep           = DEBOUNCE_REPTIME,
472         .debounce_tol           = 20,
473         .gpio_pendown           = XPT2046_GPIO_INT,
474         .pendown_iomux_name = GPIO4C2_SMCDATA2_TRACEDATA2_NAME, 
475         .pendown_iomux_mode = GPIO4C_GPIO4C2,   
476         .touch_virtualkey_length = 60,
477         .penirq_recheck_delay_usecs = 1,
478         
479 #if defined(CONFIG_TOUCHSCREEN_480X800)
480         .x_min                  = 0,
481         .x_max                  = 480,
482         .y_min                  = 0,
483         .y_max                  = 800,
484         .screen_x = { 70,  410, 70, 410, 240},
485         .screen_y = { 50, 50,  740, 740, 400},
486         .uncali_x_default = {  3267,  831, 3139, 715, 1845 },
487         .uncali_y_default = { 3638,  3664, 564,  591, 2087 },
488 #elif defined(CONFIG_TOUCHSCREEN_800X480)
489         .x_min                  = 0,
490         .x_max                  = 800,
491         .y_min                  = 0,
492         .y_max                  = 480,
493         .screen_x[5] = { 50, 750,  50, 750, 400};
494         .screen_y[5] = { 40,  40, 440, 440, 240};
495         .uncali_x_default[5] = { 438,  565, 3507,  3631, 2105 };
496         .uncali_y_default[5] = {  3756,  489, 3792, 534, 2159 };
497 #elif defined(CONFIG_TOUCHSCREEN_320X480)
498         .x_min                  = 0,
499         .x_max                  = 320,
500         .y_min                  = 0,
501         .y_max                  = 480,
502         .screen_x[5] = { 50, 270,  50, 270, 160}; 
503         .screen_y[5] = { 40,  40, 440, 440, 240}; 
504         .uncali_x_default[5] = { 812,  3341, 851,  3371, 2183 };
505         .uncali_y_default[5] = {  442,  435, 3193, 3195, 2004 };
506 #endif  
507 };
508 #endif
509 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
510 static struct rk29xx_spi_chip xpt2046_chip = {
511         //.poll_mode = 1,
512         .enable_dma = 1,
513 };
514 #endif
515 static struct spi_board_info board_spi_devices[] = {
516 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
517         {
518                 .modalias       = "xpt2046_ts",
519                 .chip_select    = 1,// 2,
520                 .max_speed_hz   = 1 * 1000 * 800,/* (max sample rate @ 3V) * (cmd + data + overhead) */
521                 .bus_num        = 0,
522                 .irq            = XPT2046_GPIO_INT,
523                 .platform_data = &xpt2046_info,
524                 .controller_data = &xpt2046_chip,
525         },
526 #endif
527
528 };
529
530
531 /***********************************************************
532 *       rk30  backlight
533 ************************************************************/
534 #ifdef CONFIG_BACKLIGHT_RK29_BL
535 #define PWM_ID            0
536 #define PWM_MUX_NAME      GPIO0A3_PWM0_NAME
537 #define PWM_MUX_MODE      GPIO0A_PWM0
538 #define PWM_MUX_MODE_GPIO GPIO0A_GPIO0A3
539 #define PWM_GPIO          RK30_PIN0_PA3
540 #define PWM_EFFECT_VALUE  1
541
542 #define LCD_DISP_ON_PIN
543
544 #ifdef  LCD_DISP_ON_PIN
545 //#define BL_EN_MUX_NAME    GPIOF34_UART3_SEL_NAME
546 //#define BL_EN_MUX_MODE    IOMUXB_GPIO1_B34
547
548 #define BL_EN_PIN         RK30_PIN6_PB3
549 #define BL_EN_VALUE       GPIO_HIGH
550 #endif
551 static int rk29_backlight_io_init(void)
552 {
553         int ret = 0;
554         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
555 #ifdef  LCD_DISP_ON_PIN
556         // rk30_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
557
558         ret = gpio_request(BL_EN_PIN, NULL);
559         if(ret != 0)
560         {
561                 gpio_free(BL_EN_PIN);
562         }
563
564         gpio_direction_output(BL_EN_PIN, 0);
565         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
566 #endif
567     return ret;
568 }
569
570 static int rk29_backlight_io_deinit(void)
571 {
572         int ret = 0;
573 #ifdef  LCD_DISP_ON_PIN
574         gpio_free(BL_EN_PIN);
575 #endif
576         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);   
577     return ret;
578 }
579
580 static int rk29_backlight_pwm_suspend(void)
581 {
582         int ret = 0;
583         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
584         if (gpio_request(PWM_GPIO, NULL)) {
585                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
586                 return -1;
587         }
588         gpio_direction_output(PWM_GPIO, GPIO_LOW);
589 #ifdef  LCD_DISP_ON_PIN
590         gpio_direction_output(BL_EN_PIN, 0);
591         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
592 #endif
593         return ret;
594 }
595
596 static int rk29_backlight_pwm_resume(void)
597 {
598         gpio_free(PWM_GPIO);
599         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
600 #ifdef  LCD_DISP_ON_PIN
601         msleep(30);
602         gpio_direction_output(BL_EN_PIN, 1);
603         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
604 #endif
605         return 0;
606 }
607
608 static struct rk29_bl_info rk29_bl_info = {
609     .pwm_id   = PWM_ID,
610     .bl_ref   = PWM_EFFECT_VALUE,
611     .io_init   = rk29_backlight_io_init,
612     .io_deinit = rk29_backlight_io_deinit,
613     .pwm_suspend = rk29_backlight_pwm_suspend,
614     .pwm_resume = rk29_backlight_pwm_resume,
615 };
616
617
618 static struct platform_device rk29_device_backlight = {
619         .name   = "rk29_backlight",
620         .id     = -1,
621         .dev    = {
622            .platform_data  = &rk29_bl_info,
623         }
624 };
625
626 #endif
627
628 /*MMA8452 gsensor*/
629 #if defined (CONFIG_GS_MMA8452)
630 #define MMA8452_INT_PIN   RK30_PIN4_PC0
631
632 static int mma8452_init_platform_hw(void)
633 {
634         rk30_mux_api_set(GPIO4C0_SMCDATA0_TRACEDATA0_NAME, GPIO4C_GPIO4C0);
635
636         if(gpio_request(MMA8452_INT_PIN,NULL) != 0){
637                 gpio_free(MMA8452_INT_PIN);
638                 printk("mma8452_init_platform_hw gpio_request error\n");
639                 return -EIO;
640         }
641         gpio_pull_updown(MMA8452_INT_PIN, 1);
642         return 0;
643 }
644
645
646 static struct mma8452_platform_data mma8452_info = {
647         .model= 8452,
648         .swap_xy = 0,
649         .swap_xyz = 1,
650         .init_platform_hw= mma8452_init_platform_hw,
651         .orientation = { -1, 0, 0, 0, 0, 1, 0, -1, 0},
652 };
653 #endif
654 #if defined (CONFIG_COMPASS_AK8975)
655 static struct akm8975_platform_data akm8975_info =
656 {
657         .m_layout = 
658         {
659                 {
660                         {1, 0, 0 },
661                         {0, -1, 0 },
662                         {0,     0, -1 },
663                 },
664
665                 {
666                         {1, 0, 0 },
667                         {0, 1, 0 },
668                         {0,     0, 1 },
669                 },
670
671                 {
672                         {1, 0, 0 },
673                         {0, 1, 0 },
674                         {0,     0, 1 },
675                 },
676
677                 {
678                         {1, 0, 0 },
679                         {0, 1, 0 },
680                         {0,     0, 1 },
681                 },
682         }
683
684 };
685
686 #endif
687
688 #if defined(CONFIG_GYRO_L3G4200D)
689
690 #include <linux/l3g4200d.h>
691 #define L3G4200D_INT_PIN  RK30_PIN4_PC3
692
693 static int l3g4200d_init_platform_hw(void)
694 {
695         if (gpio_request(L3G4200D_INT_PIN, NULL) != 0) {
696                 gpio_free(L3G4200D_INT_PIN);
697                 printk("%s: request l3g4200d int pin error\n", __func__);
698                 return -EIO;
699         }
700         gpio_pull_updown(L3G4200D_INT_PIN, 1);
701         return 0;
702 }
703
704 static struct l3g4200d_platform_data l3g4200d_info = {
705         .fs_range = 1,
706
707         .axis_map_x = 0,
708         .axis_map_y = 1,
709         .axis_map_z = 2,
710
711         .negate_x = 1,
712         .negate_y = 1,
713         .negate_z = 0,
714
715         .init = l3g4200d_init_platform_hw,
716 };
717
718 #endif
719
720 #ifdef CONFIG_LS_CM3217
721
722 #define CM3217_POWER_PIN        INVALID_GPIO
723 #define CM3217_IRQ_PIN          INVALID_GPIO
724 static int cm3217_init_hw(void)
725 {
726 #if 0
727         if (gpio_request(CM3217_POWER_PIN, NULL) != 0) {
728         gpio_free(CM3217_POWER_PIN);
729         printk("%s: request cm3217 power pin error\n", __func__);
730         return -EIO;
731         }
732         gpio_pull_updown(CM3217_POWER_PIN, PullDisable);
733
734         if (gpio_request(CM3217_IRQ_PIN, NULL) != 0) {
735         gpio_free(CM3217_IRQ_PIN);
736         printk("%s: request cm3217 int pin error\n", __func__);
737         return -EIO;
738         }
739         gpio_pull_updown(CM3217_IRQ_PIN, PullDisable);
740 #endif
741         return 0;
742 }
743
744 static void cm3217_exit_hw(void)
745 {
746 #if 0
747         gpio_free(CM3217_POWER_PIN);
748         gpio_free(CM3217_IRQ_PIN);
749 #endif
750         return;
751 }
752
753 struct cm3217_platform_data cm3217_info = {
754         .irq_pin = CM3217_IRQ_PIN,
755         .power_pin = CM3217_POWER_PIN,
756         .init_platform_hw = cm3217_init_hw,
757         .exit_platform_hw = cm3217_exit_hw,
758 };
759 #endif
760
761
762
763 #ifdef CONFIG_FB_ROCKCHIP
764 static struct resource resource_fb[] = {
765         [0] = {
766                 .name  = "fb0 buf",
767                 .start = 0,
768                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
769                 .flags = IORESOURCE_MEM,
770         },
771         [1] = {
772                 .name  = "ipp buf",  //for rotate
773                 .start = 0,
774                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
775                 .flags = IORESOURCE_MEM,
776         },
777         [2] = {
778                 .name  = "fb2 buf",
779                 .start = 0,
780                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
781                 .flags = IORESOURCE_MEM,
782         },
783 };
784
785 static struct platform_device device_fb = {
786         .name             = "rk-fb",
787         .id               = -1,
788         .num_resources    = ARRAY_SIZE(resource_fb),
789         .resource         = resource_fb,
790 };
791 #endif
792
793 #ifdef CONFIG_ANDROID_TIMED_GPIO
794 static struct timed_gpio timed_gpios[] = {
795         {
796                 .name = "vibrator",
797                 .gpio = RK30_PIN0_PA4,
798                 .max_timeout = 1000,
799                 .active_low = 0,
800                 .adjust_time =20,      //adjust for diff product
801         },
802 };
803
804 struct timed_gpio_platform_data rk29_vibrator_info = {
805         .num_gpios = 1,
806         .gpios = timed_gpios,
807 };
808
809 struct platform_device rk29_device_vibrator ={
810         .name = "timed-gpio",
811         .id = -1,
812         .dev = {
813                 .platform_data = &rk29_vibrator_info,
814                 },
815
816 };
817 #endif 
818
819 #ifdef CONFIG_LEDS_GPIO_PLATFORM
820 struct gpio_led rk29_leds[] = {
821                 {
822                         .name = "button-backlight",
823                         .gpio = RK30_PIN4_PD7,
824                         .default_trigger = "timer",
825                         .active_low = 0,
826                         .retain_state_suspended = 0,
827                         .default_state = LEDS_GPIO_DEFSTATE_OFF,
828                 },
829 };
830
831 struct gpio_led_platform_data rk29_leds_pdata = {
832         .leds = &rk29_leds,
833         .num_leds       = ARRAY_SIZE(rk29_leds),
834 };
835
836 struct platform_device rk29_device_gpio_leds = {
837         .name   = "leds-gpio",
838         .id     = -1,
839         .dev    = {
840            .platform_data  = &rk29_leds_pdata,
841         },
842 };
843 #endif
844
845 #ifdef CONFIG_RK_IRDA
846 #define IRDA_IRQ_PIN           RK30_PIN6_PA1
847
848 int irda_iomux_init(void)
849 {
850         int ret = 0;
851
852         //irda irq pin
853         ret = gpio_request(IRDA_IRQ_PIN, NULL);
854         if(ret != 0)
855         {
856         gpio_free(IRDA_IRQ_PIN);
857         printk(">>>>>> IRDA_IRQ_PIN gpio_request err \n ");
858         }
859         gpio_pull_updown(IRDA_IRQ_PIN, PullDisable);
860         gpio_direction_input(IRDA_IRQ_PIN);
861
862         return 0;
863 }
864
865 int irda_iomux_deinit(void)
866 {
867         gpio_free(IRDA_IRQ_PIN);
868         return 0;
869 }
870
871 static struct irda_info rk29_irda_info = {
872         .intr_pin = IRDA_IRQ_PIN,
873         .iomux_init = irda_iomux_init,
874         .iomux_deinit = irda_iomux_deinit,
875         //.irda_pwr_ctl = bu92747guw_power_ctl,
876 };
877
878 static struct platform_device irda_device = {
879 #ifdef CONFIG_RK_IRDA_NET
880                         .name   = "rk_irda",
881 #else
882                         .name = "bu92747_irda",
883 #endif
884     .id           = -1,
885         .dev            = {
886                 .platform_data  = &rk29_irda_info,
887         }
888 };
889 #endif
890
891
892
893
894 static struct platform_device *devices[] __initdata = {
895 #ifdef CONFIG_BACKLIGHT_RK29_BL
896         &rk29_device_backlight,
897 #endif  
898 #ifdef CONFIG_FB_ROCKCHIP
899         &device_fb,
900 #endif
901 #ifdef CONFIG_ANDROID_TIMED_GPIO
902         &rk29_device_vibrator,
903 #endif
904 #ifdef CONFIG_LEDS_GPIO_PLATFORM
905         &rk29_device_gpio_leds,
906 #endif
907 #ifdef CONFIG_RK_IRDA
908         &irda_device,
909 #endif
910
911
912 };
913
914 // i2c
915 #ifdef CONFIG_I2C0_RK30
916 static struct i2c_board_info __initdata i2c0_info[] = {
917 #if defined (CONFIG_GS_MMA8452)
918             {
919               .type           = "gs_mma8452",
920               .addr           = 0x1c,
921               .flags          = 0,
922               .irq            = MMA8452_INT_PIN,
923               .platform_data  = &mma8452_info,
924             },
925 #endif
926 #if defined (CONFIG_COMPASS_AK8975)
927         {
928                 .type           = "ak8975",
929                 .addr           = 0x0d,
930                 .flags          = 0,
931                 .irq            = RK30_PIN4_PC1,
932                 .platform_data  = &akm8975_info,
933         },
934 #endif
935 #if defined (CONFIG_GYRO_L3G4200D)
936         {
937                 .type           = "l3g4200d_gryo",
938                 .addr           = 0x69,
939                 .flags          = 0,
940                 .irq            = L3G4200D_INT_PIN,
941                 .platform_data  = &l3g4200d_info,
942         },
943 #endif
944
945 #if defined (CONFIG_SND_SOC_RK1000)
946         {
947                 .type                   = "rk1000_i2c_codec",
948                 .addr           = 0x60,
949                 .flags                  = 0,
950         },
951         {
952                 .type                   = "rk1000_control",
953                 .addr                   = 0x40,
954                 .flags                  = 0,
955         },      
956 #endif
957 };
958 #endif
959
960 #ifdef CONFIG_I2C1_RK30
961 static struct i2c_board_info __initdata i2c1_info[] = {
962 };
963 #endif
964
965 #ifdef CONFIG_I2C2_RK30
966 static struct i2c_board_info __initdata i2c2_info[] = {
967 #if defined (CONFIG_TOUCHSCREEN_GT8XX)
968                     {
969                                 .type   = "Goodix-TS",
970                                 .addr   = 0x55,
971                                 .flags      =0,
972                                 .irq            =RK30_PIN4_PC2,
973                                 .platform_data = &goodix_info,
974                     },
975 #endif
976 #if defined (CONFIG_LS_CM3217)
977         {
978                 .type           = "lightsensor",
979                 .addr           = 0x20,
980                 .flags          = 0,
981                 .irq            = CM3217_IRQ_PIN,
982                 .platform_data  = &cm3217_info,
983         },
984 #endif
985
986 };
987 #endif
988
989 #ifdef CONFIG_I2C3_RK30
990 static struct i2c_board_info __initdata i2c3_info[] = {
991 };
992 #endif
993
994 #ifdef CONFIG_I2C4_RK30
995 static struct i2c_board_info __initdata i2c4_info[] = {
996 };
997 #endif
998
999 static void __init rk30_i2c_register_board_info(void)
1000 {
1001 #ifdef CONFIG_I2C0_RK30
1002         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
1003 #endif
1004 #ifdef CONFIG_I2C1_RK30
1005         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
1006 #endif
1007 #ifdef CONFIG_I2C2_RK30
1008         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
1009 #endif
1010 #ifdef CONFIG_I2C3_RK30
1011         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
1012 #endif
1013 #ifdef CONFIG_I2C4_RK30
1014         i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info));
1015 #endif
1016 }
1017 //end of i2c
1018
1019 static void __init machine_rk30_board_init(void)
1020 {
1021         rk30_i2c_register_board_info();
1022         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1023         platform_add_devices(devices, ARRAY_SIZE(devices));
1024 }
1025
1026 static void __init rk30_reserve(void)
1027 {
1028 #ifdef CONFIG_FB_ROCKCHIP
1029         resource_fb[0].start = board_mem_reserve_add("fb0",RK30_FB0_MEM_SIZE);
1030         resource_fb[0].end = resource_fb[0].start + RK30_FB0_MEM_SIZE - 1;
1031         resource_fb[1].start = board_mem_reserve_add("ipp buf",RK30_FB0_MEM_SIZE);
1032         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
1033         resource_fb[2].start = board_mem_reserve_add("fb2",RK30_FB0_MEM_SIZE);
1034         resource_fb[2].end = resource_fb[2].start + RK30_FB0_MEM_SIZE - 1;      
1035 #endif
1036
1037 #if (MEM_CAMIPP_SIZE != 0)
1038         #if CONFIG_USE_CIF_0
1039         rk_camera_platform_data_host_0.meminfo.name = "camera_ipp_mem_0";
1040         rk_camera_platform_data_host_0.meminfo.start = board_mem_reserve_add("camera_ipp_mem_0",MEM_CAMIPP_SIZE);
1041         rk_camera_platform_data_host_0.meminfo.size= MEM_CAMIPP_SIZE;
1042         #endif
1043         #if CONFIG_USE_CIF_1
1044         rk_camera_platform_data_host_1.meminfo.name = "camera_ipp_mem_1";
1045         rk_camera_platform_data_host_1.meminfo.start =board_mem_reserve_add("camera_ipp_mem_1",MEM_CAMIPP_SIZE);
1046         rk_camera_platform_data_host_1.meminfo.size= MEM_CAMIPP_SIZE;
1047         #endif
1048 #endif
1049
1050 #if (PMEM_CAM_SIZE != 0)
1051         android_pmem_cam_pdata.start = board_mem_reserve_add("camera_pmem",PMEM_CAM_SIZE);
1052         android_pmem_cam_pdata.size = PMEM_CAM_SIZE;
1053 #endif
1054
1055         board_mem_reserved();
1056 }
1057
1058 MACHINE_START(RK30, "RK30board")
1059         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
1060         .fixup          = rk30_fixup,
1061         .reserve        = &rk30_reserve,
1062         .map_io         = rk30_map_io,
1063         .init_irq       = rk30_init_irq,
1064         .timer          = &rk30_timer,
1065         .init_machine   = machine_rk30_board_init,
1066 MACHINE_END