rk30: refactor i2s init code
[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
52 #define RK30_FB0_MEM_SIZE 8*SZ_1M
53
54
55 /*****************************************************************************************
56  * xpt2046 touch panel
57  * author: hhb@rock-chips.com
58  *****************************************************************************************/
59 #if defined(CONFIG_TOUCHSCREEN_XPT2046_NORMAL_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_TSLIB_SPI)
60 #define XPT2046_GPIO_INT        RK30_PIN4_PC2 
61 #define DEBOUNCE_REPTIME        3
62
63
64 static struct xpt2046_platform_data xpt2046_info = {
65         .model                  = 2046,
66         .keep_vref_on           = 1,
67         .swap_xy                = 0,
68         .debounce_max           = 7,
69         .debounce_rep           = DEBOUNCE_REPTIME,
70         .debounce_tol           = 20,
71         .gpio_pendown           = XPT2046_GPIO_INT,
72         .pendown_iomux_name = GPIO4C2_SMCDATA2_TRACEDATA2_NAME, 
73         .pendown_iomux_mode = GPIO4C_GPIO4C2,   
74         .touch_virtualkey_length = 60,
75         .penirq_recheck_delay_usecs = 1,
76 #if defined(CONFIG_TOUCHSCREEN_480X800)
77         .x_min                  = 0,
78         .x_max                  = 480,
79         .y_min                  = 0,
80         .y_max                  = 800,
81         .touch_ad_top = 3940,
82         .touch_ad_bottom = 310,
83         .touch_ad_left = 3772,
84         .touch_ad_right = 340,
85 #elif defined(CONFIG_TOUCHSCREEN_800X480)
86         .x_min                  = 0,
87         .x_max                  = 800,
88         .y_min                  = 0,
89         .y_max                  = 480,
90         .touch_ad_top = 2447,
91         .touch_ad_bottom = 207,
92         .touch_ad_left = 5938,
93         .touch_ad_right = 153,
94 #elif defined(CONFIG_TOUCHSCREEN_320X480)
95         .x_min                  = 0,
96         .x_max                  = 320,
97         .y_min                  = 0,
98         .y_max                  = 480,
99         .touch_ad_top = 3166,
100         .touch_ad_bottom = 256,
101         .touch_ad_left = 3658,
102         .touch_ad_right = 380,
103 #endif  
104 };
105 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
106 static struct xpt2046_platform_data xpt2046_info = {
107         .model                  = 2046,
108         .keep_vref_on   = 1,
109         .swap_xy                = 0,
110         .debounce_max           = 7,
111         .debounce_rep           = DEBOUNCE_REPTIME,
112         .debounce_tol           = 20,
113         .gpio_pendown           = XPT2046_GPIO_INT,
114         .pendown_iomux_name = GPIO4C2_SMCDATA2_TRACEDATA2_NAME, 
115         .pendown_iomux_mode = GPIO4C_GPIO4C2,   
116         .touch_virtualkey_length = 60,
117         .penirq_recheck_delay_usecs = 1,
118         
119 #if defined(CONFIG_TOUCHSCREEN_480X800)
120         .x_min                  = 0,
121         .x_max                  = 480,
122         .y_min                  = 0,
123         .y_max                  = 800,
124         .screen_x = { 70,  410, 70, 410, 240},
125         .screen_y = { 50, 50,  740, 740, 400},
126         .uncali_x_default = {  3267,  831, 3139, 715, 1845 },
127         .uncali_y_default = { 3638,  3664, 564,  591, 2087 },
128 #elif defined(CONFIG_TOUCHSCREEN_800X480)
129         .x_min                  = 0,
130         .x_max                  = 800,
131         .y_min                  = 0,
132         .y_max                  = 480,
133         .screen_x[5] = { 50, 750,  50, 750, 400};
134         .screen_y[5] = { 40,  40, 440, 440, 240};
135         .uncali_x_default[5] = { 438,  565, 3507,  3631, 2105 };
136         .uncali_y_default[5] = {  3756,  489, 3792, 534, 2159 };
137 #elif defined(CONFIG_TOUCHSCREEN_320X480)
138         .x_min                  = 0,
139         .x_max                  = 320,
140         .y_min                  = 0,
141         .y_max                  = 480,
142         .screen_x[5] = { 50, 270,  50, 270, 160}; 
143         .screen_y[5] = { 40,  40, 440, 440, 240}; 
144         .uncali_x_default[5] = { 812,  3341, 851,  3371, 2183 };
145         .uncali_y_default[5] = {  442,  435, 3193, 3195, 2004 };
146 #endif  
147 };
148 #endif
149 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
150 static struct rk29xx_spi_chip xpt2046_chip = {
151         //.poll_mode = 1,
152         .enable_dma = 1,
153 };
154 #endif
155 static struct spi_board_info board_spi_devices[] = {
156 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
157         {
158                 .modalias       = "xpt2046_ts",
159                 .chip_select    = 1,// 2,
160                 .max_speed_hz   = 1 * 1000 * 800,/* (max sample rate @ 3V) * (cmd + data + overhead) */
161                 .bus_num        = 0,
162                 .irq            = XPT2046_GPIO_INT,
163                 .platform_data = &xpt2046_info,
164                 .controller_data = &xpt2046_chip,
165         },
166 #endif
167
168 };
169
170
171 /***********************************************************
172 *       rk30  backlight
173 ************************************************************/
174 #ifdef CONFIG_BACKLIGHT_RK29_BL
175 #define PWM_ID            0
176 #define PWM_MUX_NAME      GPIO0A3_PWM0_NAME
177 #define PWM_MUX_MODE      GPIO0A_PWM0
178 #define PWM_MUX_MODE_GPIO GPIO0A_GPIO0A3
179 #define PWM_GPIO          RK30_PIN0_PA3
180 #define PWM_EFFECT_VALUE  1
181
182 #define LCD_DISP_ON_PIN
183
184 #ifdef  LCD_DISP_ON_PIN
185 //#define BL_EN_MUX_NAME    GPIOF34_UART3_SEL_NAME
186 //#define BL_EN_MUX_MODE    IOMUXB_GPIO1_B34
187
188 #define BL_EN_PIN         INVALID_GPIO //?
189 #define BL_EN_VALUE       GPIO_HIGH
190 #endif
191 static int rk29_backlight_io_init(void)
192 {
193         int ret = 0;
194         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
195 #ifdef  LCD_DISP_ON_PIN
196         // rk30_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
197
198         ret = gpio_request(BL_EN_PIN, NULL);
199         if(ret != 0)
200         {
201                 gpio_free(BL_EN_PIN);
202         }
203
204         gpio_direction_output(BL_EN_PIN, 0);
205         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
206 #endif
207     return ret;
208 }
209
210 static int rk29_backlight_io_deinit(void)
211 {
212         int ret = 0;
213 #ifdef  LCD_DISP_ON_PIN
214         gpio_free(BL_EN_PIN);
215 #endif
216         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);   
217     return ret;
218 }
219
220 static int rk29_backlight_pwm_suspend(void)
221 {
222         int ret = 0;
223         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
224         if (gpio_request(PWM_GPIO, NULL)) {
225                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
226                 return -1;
227         }
228         gpio_direction_output(PWM_GPIO, GPIO_LOW);
229 #ifdef  LCD_DISP_ON_PIN
230         gpio_direction_output(BL_EN_PIN, 0);
231         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
232 #endif
233         return ret;
234 }
235
236 static int rk29_backlight_pwm_resume(void)
237 {
238         gpio_free(PWM_GPIO);
239         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
240 #ifdef  LCD_DISP_ON_PIN
241         msleep(30);
242         gpio_direction_output(BL_EN_PIN, 1);
243         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
244 #endif
245         return 0;
246 }
247
248 static struct rk29_bl_info rk29_bl_info = {
249     .pwm_id   = PWM_ID,
250     .bl_ref   = PWM_EFFECT_VALUE,
251     .io_init   = rk29_backlight_io_init,
252     .io_deinit = rk29_backlight_io_deinit,
253     .pwm_suspend = rk29_backlight_pwm_suspend,
254     .pwm_resume = rk29_backlight_pwm_resume,
255 };
256
257
258 static struct platform_device rk29_device_backlight = {
259         .name   = "rk29_backlight",
260         .id     = -1,
261         .dev    = {
262            .platform_data  = &rk29_bl_info,
263         }
264 };
265
266 #endif
267
268 /*MMA8452 gsensor*/
269 #if defined (CONFIG_GS_MMA8452)
270 #define MMA8452_INT_PIN   RK30_PIN4_PC0
271
272 static int mma8452_init_platform_hw(void)
273 {
274         rk30_mux_api_set(GPIO4C0_SMCDATA0_TRACEDATA0_NAME, GPIO4C_GPIO4C0);
275
276         if(gpio_request(MMA8452_INT_PIN,NULL) != 0){
277                 gpio_free(MMA8452_INT_PIN);
278                 printk("mma8452_init_platform_hw gpio_request error\n");
279                 return -EIO;
280         }
281         gpio_pull_updown(MMA8452_INT_PIN, 1);
282         return 0;
283 }
284
285
286 static struct mma8452_platform_data mma8452_info = {
287         .model= 8452,
288         .swap_xy = 0,
289         .swap_xyz = 1,
290         .init_platform_hw= mma8452_init_platform_hw,
291         .orientation = { -1, 0, 0, 0, 0, 1, 0, -1, 0},
292 };
293 #endif
294
295 #ifdef CONFIG_FB_ROCKCHIP
296 static struct resource resource_fb[] = {
297         [0] = {
298                 .name  = "fb0 buf",
299                 .start = 0,
300                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
301                 .flags = IORESOURCE_MEM,
302         },
303         [1] = {
304                 .name  = "ipp buf",  //for rotate
305                 .start = 0,
306                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
307                 .flags = IORESOURCE_MEM,
308         },
309         [2] = {
310                 .name  = "fb2 buf",
311                 .start = 0,
312                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
313                 .flags = IORESOURCE_MEM,
314         },
315 };
316
317 static struct platform_device device_fb = {
318         .name             = "rk-fb",
319         .id               = -1,
320         .num_resources    = ARRAY_SIZE(resource_fb),
321         .resource         = resource_fb,
322 };
323 #endif
324
325 static struct platform_device *devices[] __initdata = {
326 #ifdef CONFIG_BACKLIGHT_RK29_BL
327         &rk29_device_backlight,
328 #endif  
329 #ifdef CONFIG_FB_ROCKCHIP
330         &device_fb,
331 #endif
332 };
333
334 // i2c
335 #ifdef CONFIG_I2C0_RK30
336 static struct i2c_board_info __initdata i2c0_info[] = {
337 #if defined (CONFIG_GS_MMA8452)
338             {
339               .type           = "gs_mma8452",
340               .addr           = 0x1c,
341               .flags          = 0,
342               .irq            = MMA8452_INT_PIN,
343               .platform_data  = &mma8452_info,
344             },
345 #endif
346 #if defined (CONFIG_SND_SOC_RK1000)
347         {
348                 .type                   = "rk1000_i2c_codec",
349                 .addr           = 0x60,
350                 .flags                  = 0,
351         },
352         {
353                 .type                   = "rk1000_control",
354                 .addr                   = 0x40,
355                 .flags                  = 0,
356         },      
357 #endif
358 };
359 #endif
360
361 #ifdef CONFIG_I2C1_RK30
362 static struct i2c_board_info __initdata i2c1_info[] = {
363 };
364 #endif
365
366 #ifdef CONFIG_I2C2_RK30
367 static struct i2c_board_info __initdata i2c2_info[] = {
368 };
369 #endif
370
371 #ifdef CONFIG_I2C3_RK30
372 static struct i2c_board_info __initdata i2c3_info[] = {
373 };
374 #endif
375
376 #ifdef CONFIG_I2C4_RK30
377 static struct i2c_board_info __initdata i2c4_info[] = {
378 };
379 #endif
380
381 static void __init rk30_i2c_register_board_info(void)
382 {
383 #ifdef CONFIG_I2C0_RK30
384         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
385 #endif
386 #ifdef CONFIG_I2C1_RK30
387         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
388 #endif
389 #ifdef CONFIG_I2C2_RK30
390         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
391 #endif
392 #ifdef CONFIG_I2C3_RK30
393         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
394 #endif
395 #ifdef CONFIG_I2C4_RK30
396         i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info));
397 #endif
398 }
399 //end of i2c
400
401 static void __init machine_rk30_board_init(void)
402 {
403         rk30_i2c_register_board_info();
404         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
405         platform_add_devices(devices, ARRAY_SIZE(devices));
406 }
407
408 static void __init rk30_reserve(void)
409 {
410 #ifdef CONFIG_FB_ROCKCHIP
411         resource_fb[0].start = board_mem_reserve_add("fb0",RK30_FB0_MEM_SIZE);
412         resource_fb[0].end = resource_fb[0].start + RK30_FB0_MEM_SIZE - 1;
413         resource_fb[1].start = board_mem_reserve_add("ipp buf",RK30_FB0_MEM_SIZE);
414         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
415         resource_fb[2].start = board_mem_reserve_add("fb2",RK30_FB0_MEM_SIZE);
416         resource_fb[2].end = resource_fb[2].start + RK30_FB0_MEM_SIZE - 1;      
417 #endif
418         board_mem_reserved();
419 }
420
421 MACHINE_START(RK30, "RK30board")
422         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
423         .fixup          = rk30_fixup,
424         .reserve        = &rk30_reserve,
425         .map_io         = rk30_map_io,
426         .init_irq       = rk30_init_irq,
427         .timer          = &rk30_timer,
428         .init_machine   = machine_rk30_board_init,
429 MACHINE_END