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