Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
[linux-2.6] / arch / arm / mach-pxa / zylonite_pxa300.c
1 /*
2  * linux/arch/arm/mach-pxa/zylonite_pxa300.c
3  *
4  * PXA300/PXA310 specific support code for the
5  * PXA3xx Development Platform (aka Zylonite)
6  *
7  * Copyright (C) 2007 Marvell Internation Ltd.
8  * 2007-08-21: eric miao <eric.miao@marvell.com>
9  *             initial version
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2 as
13  * published by the Free Software Foundation.
14  */
15
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/i2c.h>
20 #include <linux/i2c/pca953x.h>
21
22 #include <asm/gpio.h>
23 #include <mach/mfp-pxa300.h>
24 #include <mach/i2c.h>
25 #include <mach/zylonite.h>
26
27 #include "generic.h"
28
29 /* PXA300/PXA310 common configurations */
30 static mfp_cfg_t common_mfp_cfg[] __initdata = {
31         /* LCD */
32         GPIO54_LCD_LDD_0,
33         GPIO55_LCD_LDD_1,
34         GPIO56_LCD_LDD_2,
35         GPIO57_LCD_LDD_3,
36         GPIO58_LCD_LDD_4,
37         GPIO59_LCD_LDD_5,
38         GPIO60_LCD_LDD_6,
39         GPIO61_LCD_LDD_7,
40         GPIO62_LCD_LDD_8,
41         GPIO63_LCD_LDD_9,
42         GPIO64_LCD_LDD_10,
43         GPIO65_LCD_LDD_11,
44         GPIO66_LCD_LDD_12,
45         GPIO67_LCD_LDD_13,
46         GPIO68_LCD_LDD_14,
47         GPIO69_LCD_LDD_15,
48         GPIO70_LCD_LDD_16,
49         GPIO71_LCD_LDD_17,
50         GPIO72_LCD_FCLK,
51         GPIO73_LCD_LCLK,
52         GPIO74_LCD_PCLK,
53         GPIO75_LCD_BIAS,
54         GPIO76_LCD_VSYNC,
55         GPIO127_LCD_CS_N,
56         GPIO20_PWM3_OUT,        /* backlight */
57
58         /* BTUART */
59         GPIO111_UART2_RTS,
60         GPIO112_UART2_RXD | MFP_LPM_EDGE_FALL,
61         GPIO113_UART2_TXD,
62         GPIO114_UART2_CTS | MFP_LPM_EDGE_BOTH,
63
64         /* STUART */
65         GPIO109_UART3_TXD,
66         GPIO110_UART3_RXD | MFP_LPM_EDGE_FALL,
67
68         /* AC97 */
69         GPIO23_AC97_nACRESET,
70         GPIO24_AC97_SYSCLK,
71         GPIO29_AC97_BITCLK,
72         GPIO25_AC97_SDATA_IN_0,
73         GPIO27_AC97_SDATA_OUT,
74         GPIO28_AC97_SYNC,
75
76         /* WM9713 IRQ */
77         GPIO26_GPIO,
78
79         /* Keypad */
80         GPIO107_KP_DKIN_0 | MFP_LPM_EDGE_BOTH,
81         GPIO108_KP_DKIN_1 | MFP_LPM_EDGE_BOTH,
82         GPIO115_KP_MKIN_0 | MFP_LPM_EDGE_BOTH,
83         GPIO116_KP_MKIN_1 | MFP_LPM_EDGE_BOTH,
84         GPIO117_KP_MKIN_2 | MFP_LPM_EDGE_BOTH,
85         GPIO118_KP_MKIN_3 | MFP_LPM_EDGE_BOTH,
86         GPIO119_KP_MKIN_4 | MFP_LPM_EDGE_BOTH,
87         GPIO120_KP_MKIN_5 | MFP_LPM_EDGE_BOTH,
88         GPIO2_2_KP_MKIN_6 | MFP_LPM_EDGE_BOTH,
89         GPIO3_2_KP_MKIN_7 | MFP_LPM_EDGE_BOTH,
90         GPIO121_KP_MKOUT_0,
91         GPIO122_KP_MKOUT_1,
92         GPIO123_KP_MKOUT_2,
93         GPIO124_KP_MKOUT_3,
94         GPIO125_KP_MKOUT_4,
95         GPIO4_2_KP_MKOUT_5,
96         GPIO5_2_KP_MKOUT_6,
97         GPIO6_2_KP_MKOUT_7,
98
99         /* MMC1 */
100         GPIO3_MMC1_DAT0,
101         GPIO4_MMC1_DAT1 | MFP_LPM_EDGE_BOTH,
102         GPIO5_MMC1_DAT2,
103         GPIO6_MMC1_DAT3,
104         GPIO7_MMC1_CLK,
105         GPIO8_MMC1_CMD, /* CMD0 for slot 0 */
106         GPIO15_GPIO,    /* CMD1 default as GPIO for slot 0 */
107
108         /* MMC2 */
109         GPIO9_MMC2_DAT0,
110         GPIO10_MMC2_DAT1 | MFP_LPM_EDGE_BOTH,
111         GPIO11_MMC2_DAT2,
112         GPIO12_MMC2_DAT3,
113         GPIO13_MMC2_CLK,
114         GPIO14_MMC2_CMD,
115
116         /* Standard I2C */
117         GPIO21_I2C_SCL,
118         GPIO22_I2C_SDA,
119 };
120
121 static mfp_cfg_t pxa300_mfp_cfg[] __initdata = {
122         /* FFUART */
123         GPIO30_UART1_RXD | MFP_LPM_EDGE_FALL,
124         GPIO31_UART1_TXD,
125         GPIO32_UART1_CTS,
126         GPIO37_UART1_RTS,
127         GPIO33_UART1_DCD,
128         GPIO34_UART1_DSR | MFP_LPM_EDGE_FALL,
129         GPIO35_UART1_RI,
130         GPIO36_UART1_DTR,
131
132         /* Ethernet */
133         GPIO2_nCS3,
134         GPIO99_GPIO,
135 };
136
137 static mfp_cfg_t pxa310_mfp_cfg[] __initdata = {
138         /* FFUART */
139         GPIO99_UART1_RXD | MFP_LPM_EDGE_FALL,
140         GPIO100_UART1_TXD,
141         GPIO101_UART1_CTS,
142         GPIO106_UART1_RTS,
143
144         /* Ethernet */
145         GPIO2_nCS3,
146         GPIO102_GPIO,
147
148         /* MMC3 */
149         GPIO7_2_MMC3_DAT0,
150         GPIO8_2_MMC3_DAT1 | MFP_LPM_EDGE_BOTH,
151         GPIO9_2_MMC3_DAT2,
152         GPIO10_2_MMC3_DAT3,
153         GPIO103_MMC3_CLK,
154         GPIO105_MMC3_CMD,
155 };
156
157 #define NUM_LCD_DETECT_PINS     7
158
159 static int lcd_detect_pins[] __initdata = {
160         MFP_PIN_GPIO71, /* LCD_LDD_17 - ORIENT */
161         MFP_PIN_GPIO70, /* LCD_LDD_16 - LCDID[5] */
162         MFP_PIN_GPIO75, /* LCD_BIAS   - LCDID[4] */
163         MFP_PIN_GPIO73, /* LCD_LCLK   - LCDID[3] */
164         MFP_PIN_GPIO72, /* LCD_FCLK   - LCDID[2] */
165         MFP_PIN_GPIO127,/* LCD_CS_N   - LCDID[1] */
166         MFP_PIN_GPIO76, /* LCD_VSYNC  - LCDID[0] */
167 };
168
169 static void __init zylonite_detect_lcd_panel(void)
170 {
171         unsigned long mfpr_save[NUM_LCD_DETECT_PINS];
172         int i, gpio, id = 0;
173
174         /* save the original MFP settings of these pins and configure
175          * them as GPIO Input, DS01X, Pull Neither, Edge Clear
176          */
177         for (i = 0; i < NUM_LCD_DETECT_PINS; i++) {
178                 mfpr_save[i] = pxa3xx_mfp_read(lcd_detect_pins[i]);
179                 pxa3xx_mfp_write(lcd_detect_pins[i], 0x8440);
180         }
181
182         for (i = 0; i < NUM_LCD_DETECT_PINS; i++) {
183                 id = id << 1;
184                 gpio = mfp_to_gpio(lcd_detect_pins[i]);
185                 gpio_direction_input(gpio);
186
187                 if (gpio_get_value(gpio))
188                         id = id | 0x1;
189         }
190
191         /* lcd id, flush out bit 1 */
192         lcd_id = id & 0x3d;
193
194         /* lcd orientation, portrait or landscape */
195         lcd_orientation = (id >> 6) & 0x1;
196
197         /* restore the original MFP settings */
198         for (i = 0; i < NUM_LCD_DETECT_PINS; i++)
199                 pxa3xx_mfp_write(lcd_detect_pins[i], mfpr_save[i]);
200 }
201
202 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
203 static struct pca953x_platform_data gpio_exp[] = {
204         [0] = {
205                 .gpio_base      = 128,
206         },
207         [1] = {
208                 .gpio_base      = 144,
209         },
210 };
211
212 struct i2c_board_info zylonite_i2c_board_info[] = {
213         {
214                 .type           = "pca9539",
215                 .addr           = 0x74,
216                 .platform_data  = &gpio_exp[0],
217                 .irq            = IRQ_GPIO(18),
218         }, {
219                 .type           = "pca9539",
220                 .addr           = 0x75,
221                 .platform_data  = &gpio_exp[1],
222                 .irq            = IRQ_GPIO(19),
223         },
224 };
225
226 static void __init zylonite_init_i2c(void)
227 {
228         pxa_set_i2c_info(NULL);
229         i2c_register_board_info(0, ARRAY_AND_SIZE(zylonite_i2c_board_info));
230 }
231 #else
232 static inline void zylonite_init_i2c(void) {}
233 #endif
234
235 void __init zylonite_pxa300_init(void)
236 {
237         if (cpu_is_pxa300() || cpu_is_pxa310()) {
238                 /* initialize MFP */
239                 pxa3xx_mfp_config(ARRAY_AND_SIZE(common_mfp_cfg));
240
241                 /* detect LCD panel */
242                 zylonite_detect_lcd_panel();
243
244                 /* MMC card detect & write protect for controller 0 */
245                 zylonite_mmc_slot[0].gpio_cd  = EXT_GPIO(0);
246                 zylonite_mmc_slot[0].gpio_wp  = EXT_GPIO(2);
247
248                 /* WM9713 IRQ */
249                 wm9713_irq = mfp_to_gpio(MFP_PIN_GPIO26);
250
251                 zylonite_init_i2c();
252         }
253
254         if (cpu_is_pxa300()) {
255                 pxa3xx_mfp_config(ARRAY_AND_SIZE(pxa300_mfp_cfg));
256                 gpio_eth_irq = mfp_to_gpio(MFP_PIN_GPIO99);
257         }
258
259         if (cpu_is_pxa310()) {
260                 pxa3xx_mfp_config(ARRAY_AND_SIZE(pxa310_mfp_cfg));
261                 gpio_eth_irq = mfp_to_gpio(MFP_PIN_GPIO102);
262
263                 /* MMC card detect & write protect for controller 2 */
264                 zylonite_mmc_slot[2].gpio_cd = EXT_GPIO(30);
265                 zylonite_mmc_slot[2].gpio_wp = EXT_GPIO(31);
266         }
267
268         /* GPIOs for Debug LEDs */
269         gpio_debug_led1 = EXT_GPIO(25);
270         gpio_debug_led2 = EXT_GPIO(26);
271 }