1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * linux/arch/arm/mach-pxa/mxm8x10.c
4  *
5  * Support for the Embedian MXM-8x10 Computer on Module
6  *
7  * Copyright (C) 2006 Marvell International Ltd.
8  * Copyright (C) 2009 Embedian Inc.
9  * Copyright (C) 2009 TMT Services & Supplies (Pty) Ltd.
10  *
11  * 2007-09-04: eric miao <eric.y.miao@gmail.com>
12  *             rewrite to align with latest kernel
13  *
14  * 2010-01-09: Edwin Peer <epeer@tmtservices.co.za>
15  * 	       Hennie van der Merwe <hvdmerwe@tmtservices.co.za>
16  *             rework for upstream merge
17  */
18 
19 #include <linux/serial_8250.h>
20 #include <linux/dm9000.h>
21 #include <linux/gpio/machine.h>
22 #include <linux/platform_data/i2c-pxa.h>
23 
24 #include <linux/platform_data/mtd-nand-pxa3xx.h>
25 
26 #include <linux/platform_data/video-pxafb.h>
27 #include <linux/platform_data/mmc-pxamci.h>
28 #include <linux/platform_data/usb-ohci-pxa27x.h>
29 #include <linux/platform_data/asoc-pxa.h>
30 #include "pxa320.h"
31 
32 #include "mxm8x10.h"
33 
34 #include "devices.h"
35 #include "generic.h"
36 
37 /* GPIO pin definition
38 
39 External device stuff   - Leave unconfigured for now...
40 ---------------------
41 GPIO0   -   DREQ    (External DMA Request)
42 GPIO3   -   nGCS2   (External Chip Select) Where is nGCS0; nGCS1; nGCS4; nGCS5 ?
43 GPIO4   -   nGCS3
44 GPIO15  -   EXT_GPIO1
45 GPIO16  -   EXT_GPIO2
46 GPIO17  -   EXT_GPIO3
47 GPIO24  -   EXT_GPIO4
48 GPIO25  -   EXT_GPIO5
49 GPIO26  -   EXT_GPIO6
50 GPIO27  -   EXT_GPIO7
51 GPIO28  -   EXT_GPIO8
52 GPIO29  -   EXT_GPIO9
53 GPIO30  -   EXT_GPIO10
54 GPIO31  -   EXT_GPIO11
55 GPIO57  -   EXT_GPIO12
56 GPIO74  -   EXT_IRQ1
57 GPIO75  -   EXT_IRQ2
58 GPIO76  -   EXT_IRQ3
59 GPIO77  -   EXT_IRQ4
60 GPIO78  -   EXT_IRQ5
61 GPIO79  -   EXT_IRQ6
62 GPIO80  -   EXT_IRQ7
63 GPIO81  -   EXT_IRQ8
64 GPIO87  -   VCCIO_PWREN (External Device PWREN)
65 
66 Dallas 1-Wire   - Leave unconfigured for now...
67 -------------
68 GPIO0_2 -   DS - 1Wire
69 
70 Ethernet
71 --------
72 GPIO1   -   DM9000 PWR
73 GPIO9   -   DM9K_nIRQ
74 GPIO36  -   DM9K_RESET
75 
76 Keypad  - Leave unconfigured by for now...
77 ------
78 GPIO1_2 -   KP_DKIN0
79 GPIO5_2 -   KP_MKOUT7
80 GPIO82  -   KP_DKIN1
81 GPIO85  -   KP_DKIN2
82 GPIO86  -   KP_DKIN3
83 GPIO113 -   KP_MKIN0
84 GPIO114 -   KP_MKIN1
85 GPIO115 -   KP_MKIN2
86 GPIO116 -   KP_MKIN3
87 GPIO117 -   KP_MKIN4
88 GPIO118 -   KP_MKIN5
89 GPIO119 -   KP_MKIN6
90 GPIO120 -   KP_MKIN7
91 GPIO121 -   KP_MKOUT0
92 GPIO122 -   KP_MKOUT1
93 GPIO122 -   KP_MKOUT2
94 GPIO123 -   KP_MKOUT3
95 GPIO124 -   KP_MKOUT4
96 GPIO125 -   KP_MKOUT5
97 GPIO127 -   KP_MKOUT6
98 
99 Data Bus    - Leave unconfigured for now...
100 --------
101 GPIO2   -   nWait (Data Bus)
102 
103 USB Device
104 ----------
105 GPIO4_2 -   USBD_PULLUP
106 GPIO10  -   UTM_CLK (USB Device UTM Clk)
107 GPIO49  -   USB 2.0 Device UTM_DATA0
108 GPIO50  -   USB 2.0 Device UTM_DATA1
109 GPIO51  -   USB 2.0 Device UTM_DATA2
110 GPIO52  -   USB 2.0 Device UTM_DATA3
111 GPIO53  -   USB 2.0 Device UTM_DATA4
112 GPIO54  -   USB 2.0 Device UTM_DATA5
113 GPIO55  -   USB 2.0 Device UTM_DATA6
114 GPIO56  -   USB 2.0 Device UTM_DATA7
115 GPIO58  -   UTM_RXVALID (USB 2.0 Device)
116 GPIO59  -   UTM_RXACTIVE (USB 2.0 Device)
117 GPIO60  -   UTM_RXERROR
118 GPIO61  -   UTM_OPMODE0
119 GPIO62  -   UTM_OPMODE1
120 GPIO71  -   USBD_INT    (USB Device?)
121 GPIO73  -   UTM_TXREADY (USB 2.0 Device)
122 GPIO83  -   UTM_TXVALID (USB 2.0 Device)
123 GPIO98  -   UTM_RESET   (USB 2.0 device)
124 GPIO99  -   UTM_XCVR_SELECT
125 GPIO100 -   UTM_TERM_SELECT
126 GPIO101 -   UTM_SUSPENDM_X
127 GPIO102 -   UTM_LINESTATE0
128 GPIO103 -   UTM_LINESTATE1
129 
130 Card-Bus Interface  - Leave unconfigured for now...
131 ------------------
132 GPIO5   -   nPIOR (I/O space output enable)
133 GPIO6   -   nPIOW (I/O space write enable)
134 GPIO7   -   nIOS16 (Input from I/O space telling size of data bus)
135 GPIO8   -   nPWAIT (Input for inserting wait states)
136 
137 LCD
138 ---
139 GPIO6_2     -   LDD0
140 GPIO7_2     -   LDD1
141 GPIO8_2     -   LDD2
142 GPIO9_2     -   LDD3
143 GPIO11_2    -   LDD5
144 GPIO12_2    -   LDD6
145 GPIO13_2    -   LDD7
146 GPIO14_2    -   VSYNC
147 GPIO15_2    -   HSYNC
148 GPIO16_2    -   VCLK
149 GPIO17_2    -   HCLK
150 GPIO18_2    -   VDEN
151 GPIO63      -   LDD8    (CPU LCD)
152 GPIO64      -   LDD9    (CPU LCD)
153 GPIO65      -   LDD10   (CPU LCD)
154 GPIO66      -   LDD11   (CPU LCD)
155 GPIO67      -   LDD12   (CPU LCD)
156 GPIO68      -   LDD13   (CPU LCD)
157 GPIO69      -   LDD14   (CPU LCD)
158 GPIO70      -   LDD15   (CPU LCD)
159 GPIO88      -   VCCLCD_PWREN (LCD Panel PWREN)
160 GPIO97      -   BACKLIGHT_EN
161 GPIO104     -   LCD_PWREN
162 
163 PWM   - Leave unconfigured for now...
164 ---
165 GPIO11  -   PWM0
166 GPIO12  -   PWM1
167 GPIO13  -   PWM2
168 GPIO14  -   PWM3
169 
170 SD-CARD
171 -------
172 GPIO18  -   SDDATA0
173 GPIO19  -   SDDATA1
174 GPIO20  -   SDDATA2
175 GPIO21  -   SDDATA3
176 GPIO22  -   SDCLK
177 GPIO23  -   SDCMD
178 GPIO72  -   SD_WP
179 GPIO84  -   SD_nIRQ_CD  (SD-Card)
180 
181 I2C
182 ---
183 GPIO32  -   I2CSCL
184 GPIO33  -   I2CSDA
185 
186 AC97
187 ----
188 GPIO35  -   AC97_SDATA_IN
189 GPIO37  -   AC97_SDATA_OUT
190 GPIO38  -   AC97_SYNC
191 GPIO39  -   AC97_BITCLK
192 GPIO40  -   AC97_nRESET
193 
194 UART1
195 -----
196 GPIO41  -   UART_RXD1
197 GPIO42  -   UART_TXD1
198 GPIO43  -   UART_CTS1
199 GPIO44  -   UART_DCD1
200 GPIO45  -   UART_DSR1
201 GPIO46  -   UART_nRI1
202 GPIO47  -   UART_DTR1
203 GPIO48  -   UART_RTS1
204 
205 UART2
206 -----
207 GPIO109 -   RTS2
208 GPIO110 -   RXD2
209 GPIO111 -   TXD2
210 GPIO112 -   nCTS2
211 
212 UART3
213 -----
214 GPIO105 -   nCTS3
215 GPIO106 -   nRTS3
216 GPIO107 -   TXD3
217 GPIO108 -   RXD3
218 
219 SSP3    - Leave unconfigured for now...
220 ----
221 GPIO89  -   SSP3_CLK
222 GPIO90  -   SSP3_SFRM
223 GPIO91  -   SSP3_TXD
224 GPIO92  -   SSP3_RXD
225 
226 SSP4
227 GPIO93  -   SSP4_CLK
228 GPIO94  -   SSP4_SFRM
229 GPIO95  -   SSP4_TXD
230 GPIO96  -   SSP4_RXD
231 */
232 
233 static mfp_cfg_t mfp_cfg[] __initdata = {
234 	/* USB */
235 	GPIO10_UTM_CLK,
236 	GPIO49_U2D_PHYDATA_0,
237 	GPIO50_U2D_PHYDATA_1,
238 	GPIO51_U2D_PHYDATA_2,
239 	GPIO52_U2D_PHYDATA_3,
240 	GPIO53_U2D_PHYDATA_4,
241 	GPIO54_U2D_PHYDATA_5,
242 	GPIO55_U2D_PHYDATA_6,
243 	GPIO56_U2D_PHYDATA_7,
244 	GPIO58_UTM_RXVALID,
245 	GPIO59_UTM_RXACTIVE,
246 	GPIO60_U2D_RXERROR,
247 	GPIO61_U2D_OPMODE0,
248 	GPIO62_U2D_OPMODE1,
249 	GPIO71_GPIO, /* USBD_INT */
250 	GPIO73_UTM_TXREADY,
251 	GPIO83_U2D_TXVALID,
252 	GPIO98_U2D_RESET,
253 	GPIO99_U2D_XCVR_SEL,
254 	GPIO100_U2D_TERM_SEL,
255 	GPIO101_U2D_SUSPEND,
256 	GPIO102_UTM_LINESTATE_0,
257 	GPIO103_UTM_LINESTATE_1,
258 	GPIO4_2_GPIO | MFP_PULL_HIGH, /* UTM_PULLUP */
259 
260 	/* DM9000 */
261 	GPIO1_GPIO,
262 	GPIO9_GPIO,
263 	GPIO36_GPIO,
264 
265 	/* AC97 */
266 	GPIO35_AC97_SDATA_IN_0,
267 	GPIO37_AC97_SDATA_OUT,
268 	GPIO38_AC97_SYNC,
269 	GPIO39_AC97_BITCLK,
270 	GPIO40_AC97_nACRESET,
271 
272 	/* UARTS */
273 	GPIO41_UART1_RXD,
274 	GPIO42_UART1_TXD,
275 	GPIO43_UART1_CTS,
276 	GPIO44_UART1_DCD,
277 	GPIO45_UART1_DSR,
278 	GPIO46_UART1_RI,
279 	GPIO47_UART1_DTR,
280 	GPIO48_UART1_RTS,
281 
282 	GPIO109_UART2_RTS,
283 	GPIO110_UART2_RXD,
284 	GPIO111_UART2_TXD,
285 	GPIO112_UART2_CTS,
286 
287 	GPIO105_UART3_CTS,
288 	GPIO106_UART3_RTS,
289 	GPIO107_UART3_TXD,
290 	GPIO108_UART3_RXD,
291 
292 	GPIO78_GPIO,
293 	GPIO79_GPIO,
294 	GPIO80_GPIO,
295 	GPIO81_GPIO,
296 
297 	/* I2C */
298 	GPIO32_I2C_SCL,
299 	GPIO33_I2C_SDA,
300 
301 	/* MMC */
302 	GPIO18_MMC1_DAT0,
303 	GPIO19_MMC1_DAT1,
304 	GPIO20_MMC1_DAT2,
305 	GPIO21_MMC1_DAT3,
306 	GPIO22_MMC1_CLK,
307 	GPIO23_MMC1_CMD,
308 	GPIO72_GPIO | MFP_PULL_HIGH, /* Card Detect */
309 	GPIO84_GPIO | MFP_PULL_LOW, /* Write Protect */
310 
311 	/* IRQ */
312 	GPIO74_GPIO | MFP_LPM_EDGE_RISE, /* EXT_IRQ1 */
313 	GPIO75_GPIO | MFP_LPM_EDGE_RISE, /* EXT_IRQ2 */
314 	GPIO76_GPIO | MFP_LPM_EDGE_RISE, /* EXT_IRQ3 */
315 	GPIO77_GPIO | MFP_LPM_EDGE_RISE, /* EXT_IRQ4 */
316 	GPIO78_GPIO | MFP_LPM_EDGE_RISE, /* EXT_IRQ5 */
317 	GPIO79_GPIO | MFP_LPM_EDGE_RISE, /* EXT_IRQ6 */
318 	GPIO80_GPIO | MFP_LPM_EDGE_RISE, /* EXT_IRQ7 */
319 	GPIO81_GPIO | MFP_LPM_EDGE_RISE  /* EXT_IRQ8 */
320 };
321 
322 /* MMC/MCI Support */
323 #if defined(CONFIG_MMC)
324 static struct pxamci_platform_data mxm_8x10_mci_platform_data = {
325 	.ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
326 	.detect_delay_ms = 10,
327 };
328 
329 static struct gpiod_lookup_table mxm_8x10_mci_gpio_table = {
330 	.dev_id = "pxa2xx-mci.0",
331 	.table = {
332 		/* Card detect on GPIO 72 */
333 		GPIO_LOOKUP("gpio-pxa", MXM_8X10_SD_nCD,
334 			    "cd", GPIO_ACTIVE_LOW),
335 		/* Write protect on GPIO 84 */
336 		GPIO_LOOKUP("gpio-pxa", MXM_8X10_SD_WP,
337 			    "wp", GPIO_ACTIVE_LOW),
338 		{ },
339 	},
340 };
341 
mxm_8x10_mmc_init(void)342 void __init mxm_8x10_mmc_init(void)
343 {
344 	gpiod_add_lookup_table(&mxm_8x10_mci_gpio_table);
345 	pxa_set_mci_info(&mxm_8x10_mci_platform_data);
346 }
347 #endif
348 
349 /* USB Open Host Controller Interface */
350 static struct pxaohci_platform_data mxm_8x10_ohci_platform_data = {
351 	.port_mode = PMM_NPS_MODE,
352 	.flags = ENABLE_PORT_ALL
353 };
354 
mxm_8x10_usb_host_init(void)355 void __init mxm_8x10_usb_host_init(void)
356 {
357 	pxa_set_ohci_info(&mxm_8x10_ohci_platform_data);
358 }
359 
mxm_8x10_ac97_init(void)360 void __init mxm_8x10_ac97_init(void)
361 {
362 	pxa_set_ac97_info(NULL);
363 }
364 
365 /* NAND flash Support */
366 #if IS_ENABLED(CONFIG_MTD_NAND_MARVELL)
367 #define NAND_BLOCK_SIZE SZ_128K
368 #define NB(x)           (NAND_BLOCK_SIZE * (x))
369 static struct mtd_partition mxm_8x10_nand_partitions[] = {
370 	[0] = {
371 	       .name = "boot",
372 	       .size = NB(0x002),
373 	       .offset = NB(0x000),
374 	       .mask_flags = MTD_WRITEABLE
375 	},
376 	[1] = {
377 	       .name = "kernel",
378 	       .size = NB(0x010),
379 	       .offset = NB(0x002),
380 	       .mask_flags = MTD_WRITEABLE
381 	},
382 	[2] = {
383 	       .name = "root",
384 	       .size = NB(0x36c),
385 	       .offset = NB(0x012)
386 	},
387 	[3] = {
388 	       .name = "bbt",
389 	       .size = NB(0x082),
390 	       .offset = NB(0x37e),
391 	       .mask_flags = MTD_WRITEABLE
392 	}
393 };
394 
395 static struct pxa3xx_nand_platform_data mxm_8x10_nand_info = {
396 	.keep_config	= 1,
397 	.parts		= mxm_8x10_nand_partitions,
398 	.nr_parts	= ARRAY_SIZE(mxm_8x10_nand_partitions)
399 };
400 
mxm_8x10_nand_init(void)401 static void __init mxm_8x10_nand_init(void)
402 {
403 	pxa3xx_set_nand_info(&mxm_8x10_nand_info);
404 }
405 #else
mxm_8x10_nand_init(void)406 static inline void mxm_8x10_nand_init(void) {}
407 #endif /* IS_ENABLED(CONFIG_MTD_NAND_MARVELL) */
408 
409 /* Ethernet support: Davicom DM9000 */
410 static struct resource dm9k_resources[] = {
411 	[0] = {
412 	       .start = MXM_8X10_ETH_PHYS + 0x300,
413 	       .end = MXM_8X10_ETH_PHYS + 0x300,
414 	       .flags = IORESOURCE_MEM
415 	},
416 	[1] = {
417 	       .start = MXM_8X10_ETH_PHYS + 0x308,
418 	       .end = MXM_8X10_ETH_PHYS + 0x308,
419 	       .flags = IORESOURCE_MEM
420 	},
421 	[2] = {
422 	       .start = PXA_GPIO_TO_IRQ(mfp_to_gpio(MFP_PIN_GPIO9)),
423 	       .end = PXA_GPIO_TO_IRQ(mfp_to_gpio(MFP_PIN_GPIO9)),
424 	       .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE
425 	}
426 };
427 
428 static struct dm9000_plat_data dm9k_plat_data = {
429 	.flags = DM9000_PLATF_16BITONLY
430 };
431 
432 static struct platform_device dm9k_device = {
433 	.name = "dm9000",
434 	.id = 0,
435 	.num_resources = ARRAY_SIZE(dm9k_resources),
436 	.resource = dm9k_resources,
437 	.dev = {
438 		.platform_data = &dm9k_plat_data
439 	}
440 };
441 
mxm_8x10_ethernet_init(void)442 static void __init mxm_8x10_ethernet_init(void)
443 {
444 	platform_device_register(&dm9k_device);
445 }
446 
447 /* PXA UARTs */
mxm_8x10_uarts_init(void)448 static void __init mxm_8x10_uarts_init(void)
449 {
450 	pxa_set_ffuart_info(NULL);
451 	pxa_set_btuart_info(NULL);
452 	pxa_set_stuart_info(NULL);
453 }
454 
455 /* I2C and Real Time Clock */
456 static struct i2c_board_info __initdata mxm_8x10_i2c_devices[] = {
457 	{
458 		I2C_BOARD_INFO("ds1337", 0x68)
459 	}
460 };
461 
mxm_8x10_i2c_init(void)462 static void __init mxm_8x10_i2c_init(void)
463 {
464 	i2c_register_board_info(0, mxm_8x10_i2c_devices,
465 				ARRAY_SIZE(mxm_8x10_i2c_devices));
466 	pxa_set_i2c_info(NULL);
467 }
468 
mxm_8x10_barebones_init(void)469 void __init mxm_8x10_barebones_init(void)
470 {
471 	pxa3xx_mfp_config(ARRAY_AND_SIZE(mfp_cfg));
472 
473 	mxm_8x10_uarts_init();
474 	mxm_8x10_nand_init();
475 	mxm_8x10_i2c_init();
476 	mxm_8x10_ethernet_init();
477 }
478