Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[sfrench/cifs-2.6.git] / 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
20 #include <asm/gpio.h>
21 #include <asm/arch/mfp-pxa300.h>
22 #include <asm/arch/zylonite.h>
23
24 #include "generic.h"
25
26 /* PXA300/PXA310 common configurations */
27 static mfp_cfg_t common_mfp_cfg[] __initdata = {
28         /* LCD */
29         GPIO54_LCD_LDD_0,
30         GPIO55_LCD_LDD_1,
31         GPIO56_LCD_LDD_2,
32         GPIO57_LCD_LDD_3,
33         GPIO58_LCD_LDD_4,
34         GPIO59_LCD_LDD_5,
35         GPIO60_LCD_LDD_6,
36         GPIO61_LCD_LDD_7,
37         GPIO62_LCD_LDD_8,
38         GPIO63_LCD_LDD_9,
39         GPIO64_LCD_LDD_10,
40         GPIO65_LCD_LDD_11,
41         GPIO66_LCD_LDD_12,
42         GPIO67_LCD_LDD_13,
43         GPIO68_LCD_LDD_14,
44         GPIO69_LCD_LDD_15,
45         GPIO70_LCD_LDD_16,
46         GPIO71_LCD_LDD_17,
47         GPIO72_LCD_FCLK,
48         GPIO73_LCD_LCLK,
49         GPIO74_LCD_PCLK,
50         GPIO75_LCD_BIAS,
51         GPIO76_LCD_VSYNC,
52         GPIO127_LCD_CS_N,
53
54         /* BTUART */
55         GPIO111_UART2_RTS,
56         GPIO112_UART2_RXD | MFP_LPM_EDGE_FALL,
57         GPIO113_UART2_TXD,
58         GPIO114_UART2_CTS | MFP_LPM_EDGE_BOTH,
59
60         /* STUART */
61         GPIO109_UART3_TXD,
62         GPIO110_UART3_RXD | MFP_LPM_EDGE_FALL,
63
64         /* AC97 */
65         GPIO23_AC97_nACRESET,
66         GPIO24_AC97_SYSCLK,
67         GPIO29_AC97_BITCLK,
68         GPIO25_AC97_SDATA_IN_0,
69         GPIO27_AC97_SDATA_OUT,
70         GPIO28_AC97_SYNC,
71
72         /* WM9713 IRQ */
73         GPIO26_GPIO,
74
75         /* Keypad */
76         GPIO107_KP_DKIN_0 | MFP_LPM_EDGE_BOTH,
77         GPIO108_KP_DKIN_1 | MFP_LPM_EDGE_BOTH,
78         GPIO115_KP_MKIN_0 | MFP_LPM_EDGE_BOTH,
79         GPIO116_KP_MKIN_1 | MFP_LPM_EDGE_BOTH,
80         GPIO117_KP_MKIN_2 | MFP_LPM_EDGE_BOTH,
81         GPIO118_KP_MKIN_3 | MFP_LPM_EDGE_BOTH,
82         GPIO119_KP_MKIN_4 | MFP_LPM_EDGE_BOTH,
83         GPIO120_KP_MKIN_5 | MFP_LPM_EDGE_BOTH,
84         GPIO2_2_KP_MKIN_6 | MFP_LPM_EDGE_BOTH,
85         GPIO3_2_KP_MKIN_7 | MFP_LPM_EDGE_BOTH,
86         GPIO121_KP_MKOUT_0,
87         GPIO122_KP_MKOUT_1,
88         GPIO123_KP_MKOUT_2,
89         GPIO124_KP_MKOUT_3,
90         GPIO125_KP_MKOUT_4,
91         GPIO4_2_KP_MKOUT_5,
92         GPIO5_2_KP_MKOUT_6,
93         GPIO6_2_KP_MKOUT_7,
94
95         /* MMC1 */
96         GPIO3_MMC1_DAT0,
97         GPIO4_MMC1_DAT1 | MFP_LPM_EDGE_BOTH,
98         GPIO5_MMC1_DAT2,
99         GPIO6_MMC1_DAT3,
100         GPIO7_MMC1_CLK,
101         GPIO8_MMC1_CMD, /* CMD0 for slot 0 */
102         GPIO15_GPIO,    /* CMD1 default as GPIO for slot 0 */
103
104         /* MMC2 */
105         GPIO9_MMC2_DAT0,
106         GPIO10_MMC2_DAT1 | MFP_LPM_EDGE_BOTH,
107         GPIO11_MMC2_DAT2,
108         GPIO12_MMC2_DAT3,
109         GPIO13_MMC2_CLK,
110         GPIO14_MMC2_CMD,
111 };
112
113 static mfp_cfg_t pxa300_mfp_cfg[] __initdata = {
114         /* FFUART */
115         GPIO30_UART1_RXD | MFP_LPM_EDGE_FALL,
116         GPIO31_UART1_TXD,
117         GPIO32_UART1_CTS,
118         GPIO37_UART1_RTS,
119         GPIO33_UART1_DCD,
120         GPIO34_UART1_DSR | MFP_LPM_EDGE_FALL,
121         GPIO35_UART1_RI,
122         GPIO36_UART1_DTR,
123
124         /* Ethernet */
125         GPIO2_nCS3,
126         GPIO99_GPIO,
127 };
128
129 static mfp_cfg_t pxa310_mfp_cfg[] __initdata = {
130         /* FFUART */
131         GPIO99_UART1_RXD | MFP_LPM_EDGE_FALL,
132         GPIO100_UART1_TXD,
133         GPIO101_UART1_CTS,
134         GPIO106_UART1_RTS,
135
136         /* Ethernet */
137         GPIO2_nCS3,
138         GPIO102_GPIO,
139
140         /* MMC3 */
141         GPIO7_2_MMC3_DAT0,
142         GPIO8_2_MMC3_DAT1 | MFP_LPM_EDGE_BOTH,
143         GPIO9_2_MMC3_DAT2,
144         GPIO10_2_MMC3_DAT3,
145         GPIO103_MMC3_CLK,
146         GPIO105_MMC3_CMD,
147 };
148
149 #define NUM_LCD_DETECT_PINS     7
150
151 static int lcd_detect_pins[] __initdata = {
152         MFP_PIN_GPIO71, /* LCD_LDD_17 - ORIENT */
153         MFP_PIN_GPIO70, /* LCD_LDD_16 - LCDID[5] */
154         MFP_PIN_GPIO75, /* LCD_BIAS   - LCDID[4] */
155         MFP_PIN_GPIO73, /* LCD_LCLK   - LCDID[3] */
156         MFP_PIN_GPIO72, /* LCD_FCLK   - LCDID[2] */
157         MFP_PIN_GPIO127,/* LCD_CS_N   - LCDID[1] */
158         MFP_PIN_GPIO76, /* LCD_VSYNC  - LCDID[0] */
159 };
160
161 static void __init zylonite_detect_lcd_panel(void)
162 {
163         unsigned long mfpr_save[NUM_LCD_DETECT_PINS];
164         int i, gpio, id = 0;
165
166         /* save the original MFP settings of these pins and configure
167          * them as GPIO Input, DS01X, Pull Neither, Edge Clear
168          */
169         for (i = 0; i < NUM_LCD_DETECT_PINS; i++) {
170                 mfpr_save[i] = pxa3xx_mfp_read(lcd_detect_pins[i]);
171                 pxa3xx_mfp_write(lcd_detect_pins[i], 0x8440);
172         }
173
174         for (i = 0; i < NUM_LCD_DETECT_PINS; i++) {
175                 id = id << 1;
176                 gpio = mfp_to_gpio(lcd_detect_pins[i]);
177                 gpio_direction_input(gpio);
178
179                 if (gpio_get_value(gpio))
180                         id = id | 0x1;
181         }
182
183         /* lcd id, flush out bit 1 */
184         lcd_id = id & 0x3d;
185
186         /* lcd orientation, portrait or landscape */
187         lcd_orientation = (id >> 6) & 0x1;
188
189         /* restore the original MFP settings */
190         for (i = 0; i < NUM_LCD_DETECT_PINS; i++)
191                 pxa3xx_mfp_write(lcd_detect_pins[i], mfpr_save[i]);
192 }
193
194 void __init zylonite_pxa300_init(void)
195 {
196         if (cpu_is_pxa300() || cpu_is_pxa310()) {
197                 /* initialize MFP */
198                 pxa3xx_mfp_config(ARRAY_AND_SIZE(common_mfp_cfg));
199
200                 /* detect LCD panel */
201                 zylonite_detect_lcd_panel();
202
203                 /* GPIO pin assignment */
204                 gpio_backlight = mfp_to_gpio(MFP_PIN_GPIO20);
205
206                 /* MMC card detect & write protect for controller 0 */
207                 zylonite_mmc_slot[0].gpio_cd  = EXT_GPIO(0);
208                 zylonite_mmc_slot[0].gpio_wp  = EXT_GPIO(2);
209
210                 /* WM9713 IRQ */
211                 wm9713_irq = mfp_to_gpio(MFP_PIN_GPIO26);
212         }
213
214         if (cpu_is_pxa300()) {
215                 pxa3xx_mfp_config(ARRAY_AND_SIZE(pxa300_mfp_cfg));
216                 gpio_eth_irq = mfp_to_gpio(MFP_PIN_GPIO99);
217         }
218
219         if (cpu_is_pxa310()) {
220                 pxa3xx_mfp_config(ARRAY_AND_SIZE(pxa310_mfp_cfg));
221                 gpio_eth_irq = mfp_to_gpio(MFP_PIN_GPIO102);
222
223                 /* MMC card detect & write protect for controller 2 */
224                 zylonite_mmc_slot[2].gpio_cd = EXT_GPIO(30);
225                 zylonite_mmc_slot[2].gpio_wp = EXT_GPIO(31);
226         }
227 }