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