1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * linux/arch/arm/mach-pxa/cm-x300.c
4  *
5  * Support for the CompuLab CM-X300 modules
6  *
7  * Copyright (C) 2008,2009 CompuLab Ltd.
8  *
9  * Mike Rapoport <mike@compulab.co.il>
10  * Igor Grinberg <grinberg@compulab.co.il>
11  */
12 #define pr_fmt(fmt) "%s: " fmt, __func__
13 
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/interrupt.h>
17 #include <linux/init.h>
18 #include <linux/delay.h>
19 #include <linux/platform_device.h>
20 #include <linux/clk.h>
21 
22 #include <linux/gpio.h>
23 #include <linux/gpio/machine.h>
24 #include <linux/dm9000.h>
25 #include <linux/leds.h>
26 #include <linux/platform_data/rtc-v3020.h>
27 #include <linux/pwm.h>
28 #include <linux/pwm_backlight.h>
29 
30 #include <linux/i2c.h>
31 #include <linux/platform_data/pca953x.h>
32 #include <linux/platform_data/i2c-pxa.h>
33 
34 #include <linux/mfd/da903x.h>
35 #include <linux/regulator/machine.h>
36 #include <linux/power_supply.h>
37 #include <linux/apm-emulation.h>
38 
39 #include <linux/spi/spi.h>
40 #include <linux/spi/spi_gpio.h>
41 #include <linux/spi/tdo24m.h>
42 
43 #include <linux/soc/pxa/cpu.h>
44 
45 #include <asm/mach-types.h>
46 #include <asm/mach/arch.h>
47 #include <asm/setup.h>
48 #include <asm/system_info.h>
49 
50 #include "pxa300.h"
51 #include "pxa27x-udc.h"
52 #include <linux/platform_data/video-pxafb.h>
53 #include <linux/platform_data/mmc-pxamci.h>
54 #include <linux/platform_data/usb-ohci-pxa27x.h>
55 #include <linux/platform_data/mtd-nand-pxa3xx.h>
56 #include <linux/platform_data/asoc-pxa.h>
57 #include <linux/platform_data/usb-pxa3xx-ulpi.h>
58 
59 #include <asm/mach/map.h>
60 
61 #include "generic.h"
62 #include "devices.h"
63 
64 #define CM_X300_ETH_PHYS	0x08000010
65 
66 #define GPIO82_MMC_IRQ		(82)
67 #define GPIO85_MMC_WP		(85)
68 
69 #define	CM_X300_MMC_IRQ		PXA_GPIO_TO_IRQ(GPIO82_MMC_IRQ)
70 
71 #define GPIO95_RTC_CS		(95)
72 #define GPIO96_RTC_WR		(96)
73 #define GPIO97_RTC_RD		(97)
74 #define GPIO98_RTC_IO		(98)
75 
76 #define GPIO_ULPI_PHY_RST	(127)
77 
78 static mfp_cfg_t cm_x3xx_mfp_cfg[] __initdata = {
79 	/* LCD */
80 	GPIO54_LCD_LDD_0,
81 	GPIO55_LCD_LDD_1,
82 	GPIO56_LCD_LDD_2,
83 	GPIO57_LCD_LDD_3,
84 	GPIO58_LCD_LDD_4,
85 	GPIO59_LCD_LDD_5,
86 	GPIO60_LCD_LDD_6,
87 	GPIO61_LCD_LDD_7,
88 	GPIO62_LCD_LDD_8,
89 	GPIO63_LCD_LDD_9,
90 	GPIO64_LCD_LDD_10,
91 	GPIO65_LCD_LDD_11,
92 	GPIO66_LCD_LDD_12,
93 	GPIO67_LCD_LDD_13,
94 	GPIO68_LCD_LDD_14,
95 	GPIO69_LCD_LDD_15,
96 	GPIO72_LCD_FCLK,
97 	GPIO73_LCD_LCLK,
98 	GPIO74_LCD_PCLK,
99 	GPIO75_LCD_BIAS,
100 
101 	/* BTUART */
102 	GPIO111_UART2_RTS,
103 	GPIO112_UART2_RXD | MFP_LPM_EDGE_FALL,
104 	GPIO113_UART2_TXD,
105 	GPIO114_UART2_CTS | MFP_LPM_EDGE_BOTH,
106 
107 	/* STUART */
108 	GPIO109_UART3_TXD,
109 	GPIO110_UART3_RXD | MFP_LPM_EDGE_FALL,
110 
111 	/* AC97 */
112 	GPIO23_AC97_nACRESET,
113 	GPIO24_AC97_SYSCLK,
114 	GPIO29_AC97_BITCLK,
115 	GPIO25_AC97_SDATA_IN_0,
116 	GPIO27_AC97_SDATA_OUT,
117 	GPIO28_AC97_SYNC,
118 
119 	/* Keypad */
120 	GPIO115_KP_MKIN_0 | MFP_LPM_EDGE_BOTH,
121 	GPIO116_KP_MKIN_1 | MFP_LPM_EDGE_BOTH,
122 	GPIO117_KP_MKIN_2 | MFP_LPM_EDGE_BOTH,
123 	GPIO118_KP_MKIN_3 | MFP_LPM_EDGE_BOTH,
124 	GPIO119_KP_MKIN_4 | MFP_LPM_EDGE_BOTH,
125 	GPIO120_KP_MKIN_5 | MFP_LPM_EDGE_BOTH,
126 	GPIO2_2_KP_MKIN_6 | MFP_LPM_EDGE_BOTH,
127 	GPIO3_2_KP_MKIN_7 | MFP_LPM_EDGE_BOTH,
128 	GPIO121_KP_MKOUT_0,
129 	GPIO122_KP_MKOUT_1,
130 	GPIO123_KP_MKOUT_2,
131 	GPIO124_KP_MKOUT_3,
132 	GPIO125_KP_MKOUT_4,
133 	GPIO4_2_KP_MKOUT_5,
134 
135 	/* MMC1 */
136 	GPIO3_MMC1_DAT0,
137 	GPIO4_MMC1_DAT1 | MFP_LPM_EDGE_BOTH,
138 	GPIO5_MMC1_DAT2,
139 	GPIO6_MMC1_DAT3,
140 	GPIO7_MMC1_CLK,
141 	GPIO8_MMC1_CMD,	/* CMD0 for slot 0 */
142 
143 	/* MMC2 */
144 	GPIO9_MMC2_DAT0,
145 	GPIO10_MMC2_DAT1 | MFP_LPM_EDGE_BOTH,
146 	GPIO11_MMC2_DAT2,
147 	GPIO12_MMC2_DAT3,
148 	GPIO13_MMC2_CLK,
149 	GPIO14_MMC2_CMD,
150 
151 	/* FFUART */
152 	GPIO30_UART1_RXD | MFP_LPM_EDGE_FALL,
153 	GPIO31_UART1_TXD,
154 	GPIO32_UART1_CTS,
155 	GPIO37_UART1_RTS,
156 	GPIO33_UART1_DCD,
157 	GPIO34_UART1_DSR | MFP_LPM_EDGE_FALL,
158 	GPIO35_UART1_RI,
159 	GPIO36_UART1_DTR,
160 
161 	/* GPIOs */
162 	GPIO82_GPIO | MFP_PULL_HIGH,	/* MMC CD */
163 	GPIO85_GPIO,			/* MMC WP */
164 	GPIO99_GPIO,			/* Ethernet IRQ */
165 
166 	/* RTC GPIOs */
167 	GPIO95_GPIO | MFP_LPM_DRIVE_HIGH,	/* RTC CS */
168 	GPIO96_GPIO | MFP_LPM_DRIVE_HIGH,	/* RTC WR */
169 	GPIO97_GPIO | MFP_LPM_DRIVE_HIGH,	/* RTC RD */
170 	GPIO98_GPIO,				/* RTC IO */
171 
172 	/* Standard I2C */
173 	GPIO21_I2C_SCL,
174 	GPIO22_I2C_SDA,
175 
176 	/* PWM Backlight */
177 	GPIO19_PWM2_OUT,
178 };
179 
180 static mfp_cfg_t cm_x3xx_rev_lt130_mfp_cfg[] __initdata = {
181 	/* GPIOs */
182 	GPIO79_GPIO,			/* LED */
183 	GPIO77_GPIO,			/* WiFi reset */
184 	GPIO78_GPIO,			/* BT reset */
185 };
186 
187 static mfp_cfg_t cm_x3xx_rev_ge130_mfp_cfg[] __initdata = {
188 	/* GPIOs */
189 	GPIO76_GPIO,			/* LED */
190 	GPIO71_GPIO,			/* WiFi reset */
191 	GPIO70_GPIO,			/* BT reset */
192 };
193 
194 static mfp_cfg_t cm_x310_mfp_cfg[] __initdata = {
195 	/* USB PORT 2 */
196 	ULPI_STP,
197 	ULPI_NXT,
198 	ULPI_DIR,
199 	GPIO30_ULPI_DATA_OUT_0,
200 	GPIO31_ULPI_DATA_OUT_1,
201 	GPIO32_ULPI_DATA_OUT_2,
202 	GPIO33_ULPI_DATA_OUT_3,
203 	GPIO34_ULPI_DATA_OUT_4,
204 	GPIO35_ULPI_DATA_OUT_5,
205 	GPIO36_ULPI_DATA_OUT_6,
206 	GPIO37_ULPI_DATA_OUT_7,
207 	GPIO38_ULPI_CLK,
208 	/* external PHY reset pin */
209 	GPIO127_GPIO,
210 
211 	/* USB PORT 3 */
212 	GPIO77_USB_P3_1,
213 	GPIO78_USB_P3_2,
214 	GPIO79_USB_P3_3,
215 	GPIO80_USB_P3_4,
216 	GPIO81_USB_P3_5,
217 	GPIO82_USB_P3_6,
218 	GPIO0_2_USBH_PEN,
219 };
220 
221 #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
222 static struct resource dm9000_resources[] = {
223 	[0] = {
224 		.start	= CM_X300_ETH_PHYS,
225 		.end	= CM_X300_ETH_PHYS + 0x3,
226 		.flags	= IORESOURCE_MEM,
227 	},
228 	[1] = {
229 		.start	= CM_X300_ETH_PHYS + 0x4,
230 		.end	= CM_X300_ETH_PHYS + 0x4 + 500,
231 		.flags	= IORESOURCE_MEM,
232 	},
233 	[2] = {
234 		.start	= PXA_GPIO_TO_IRQ(mfp_to_gpio(MFP_PIN_GPIO99)),
235 		.end	= PXA_GPIO_TO_IRQ(mfp_to_gpio(MFP_PIN_GPIO99)),
236 		.flags	= IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
237 	}
238 };
239 
240 static struct dm9000_plat_data cm_x300_dm9000_platdata = {
241 	.flags		= DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM,
242 };
243 
244 static struct platform_device dm9000_device = {
245 	.name		= "dm9000",
246 	.id		= 0,
247 	.num_resources	= ARRAY_SIZE(dm9000_resources),
248 	.resource	= dm9000_resources,
249 	.dev		= {
250 		.platform_data = &cm_x300_dm9000_platdata,
251 	}
252 
253 };
254 
cm_x300_init_dm9000(void)255 static void __init cm_x300_init_dm9000(void)
256 {
257 	platform_device_register(&dm9000_device);
258 }
259 #else
cm_x300_init_dm9000(void)260 static inline void cm_x300_init_dm9000(void) {}
261 #endif
262 
263 /* LCD */
264 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
265 static struct pxafb_mode_info cm_x300_lcd_modes[] = {
266 	[0] = {
267 		.pixclock	= 38250,
268 		.bpp		= 16,
269 		.xres		= 480,
270 		.yres		= 640,
271 		.hsync_len	= 8,
272 		.vsync_len	= 2,
273 		.left_margin	= 8,
274 		.upper_margin	= 2,
275 		.right_margin	= 24,
276 		.lower_margin	= 4,
277 		.cmap_greyscale	= 0,
278 	},
279 	[1] = {
280 		.pixclock	= 153800,
281 		.bpp		= 16,
282 		.xres		= 240,
283 		.yres		= 320,
284 		.hsync_len	= 8,
285 		.vsync_len	= 2,
286 		.left_margin	= 8,
287 		.upper_margin	= 2,
288 		.right_margin	= 88,
289 		.lower_margin	= 2,
290 		.cmap_greyscale	= 0,
291 	},
292 };
293 
294 static struct pxafb_mach_info cm_x300_lcd = {
295 	.modes			= cm_x300_lcd_modes,
296 	.num_modes		= ARRAY_SIZE(cm_x300_lcd_modes),
297 	.lcd_conn		= LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
298 };
299 
cm_x300_init_lcd(void)300 static void __init cm_x300_init_lcd(void)
301 {
302 	pxa_set_fb_info(NULL, &cm_x300_lcd);
303 }
304 #else
cm_x300_init_lcd(void)305 static inline void cm_x300_init_lcd(void) {}
306 #endif
307 
308 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
309 static struct pwm_lookup cm_x300_pwm_lookup[] = {
310 	PWM_LOOKUP("pxa27x-pwm.0", 1, "pwm-backlight.0", NULL, 10000,
311 		   PWM_POLARITY_NORMAL),
312 };
313 
314 static struct platform_pwm_backlight_data cm_x300_backlight_data = {
315 	.max_brightness	= 100,
316 	.dft_brightness	= 100,
317 };
318 
319 static struct platform_device cm_x300_backlight_device = {
320 	.name		= "pwm-backlight",
321 	.dev		= {
322 		.parent = &pxa27x_device_pwm0.dev,
323 		.platform_data	= &cm_x300_backlight_data,
324 	},
325 };
326 
cm_x300_init_bl(void)327 static void cm_x300_init_bl(void)
328 {
329 	pwm_add_table(cm_x300_pwm_lookup, ARRAY_SIZE(cm_x300_pwm_lookup));
330 	platform_device_register(&cm_x300_backlight_device);
331 }
332 #else
cm_x300_init_bl(void)333 static inline void cm_x300_init_bl(void) {}
334 #endif
335 
336 #if defined(CONFIG_SPI_GPIO) || defined(CONFIG_SPI_GPIO_MODULE)
337 #define GPIO_LCD_BASE	(144)
338 #define GPIO_LCD_DIN	(GPIO_LCD_BASE + 8)	/* aux_gpio3_0 */
339 #define GPIO_LCD_DOUT	(GPIO_LCD_BASE + 9)	/* aux_gpio3_1 */
340 #define GPIO_LCD_SCL	(GPIO_LCD_BASE + 10)	/* aux_gpio3_2 */
341 #define GPIO_LCD_CS	(GPIO_LCD_BASE + 11)	/* aux_gpio3_3 */
342 #define LCD_SPI_BUS_NUM	(1)
343 
344 static struct spi_gpio_platform_data cm_x300_spi_gpio_pdata = {
345 	.num_chipselect	= 1,
346 };
347 
348 static struct platform_device cm_x300_spi_gpio = {
349 	.name		= "spi_gpio",
350 	.id		= LCD_SPI_BUS_NUM,
351 	.dev		= {
352 		.platform_data	= &cm_x300_spi_gpio_pdata,
353 	},
354 };
355 
356 static struct gpiod_lookup_table cm_x300_spi_gpiod_table = {
357 	.dev_id         = "spi_gpio",
358 	.table          = {
359 		GPIO_LOOKUP("pca9555.1", GPIO_LCD_SCL - GPIO_LCD_BASE,
360 			    "sck", GPIO_ACTIVE_HIGH),
361 		GPIO_LOOKUP("pca9555.1", GPIO_LCD_DIN - GPIO_LCD_BASE,
362 			    "mosi", GPIO_ACTIVE_HIGH),
363 		GPIO_LOOKUP("pca9555.1", GPIO_LCD_DOUT - GPIO_LCD_BASE,
364 			    "miso", GPIO_ACTIVE_HIGH),
365 		GPIO_LOOKUP("pca9555.1", GPIO_LCD_CS - GPIO_LCD_BASE,
366 			    "cs", GPIO_ACTIVE_HIGH),
367 		{ },
368 	},
369 };
370 
371 static struct tdo24m_platform_data cm_x300_tdo24m_pdata = {
372 	.model = TDO35S,
373 };
374 
375 static struct spi_board_info cm_x300_spi_devices[] __initdata = {
376 	{
377 		.modalias		= "tdo24m",
378 		.max_speed_hz		= 1000000,
379 		.bus_num		= LCD_SPI_BUS_NUM,
380 		.chip_select		= 0,
381 		.platform_data		= &cm_x300_tdo24m_pdata,
382 	},
383 };
384 
cm_x300_init_spi(void)385 static void __init cm_x300_init_spi(void)
386 {
387 	spi_register_board_info(cm_x300_spi_devices,
388 				ARRAY_SIZE(cm_x300_spi_devices));
389 	gpiod_add_lookup_table(&cm_x300_spi_gpiod_table);
390 	platform_device_register(&cm_x300_spi_gpio);
391 }
392 #else
cm_x300_init_spi(void)393 static inline void cm_x300_init_spi(void) {}
394 #endif
395 
396 #if defined(CONFIG_SND_PXA2XX_LIB_AC97)
cm_x300_init_ac97(void)397 static void __init cm_x300_init_ac97(void)
398 {
399 	pxa_set_ac97_info(NULL);
400 }
401 #else
cm_x300_init_ac97(void)402 static inline void cm_x300_init_ac97(void) {}
403 #endif
404 
405 #if IS_ENABLED(CONFIG_MTD_NAND_MARVELL)
406 static struct mtd_partition cm_x300_nand_partitions[] = {
407 	[0] = {
408 		.name        = "OBM",
409 		.offset      = 0,
410 		.size        = SZ_256K,
411 		.mask_flags  = MTD_WRITEABLE, /* force read-only */
412 	},
413 	[1] = {
414 		.name        = "U-Boot",
415 		.offset      = MTDPART_OFS_APPEND,
416 		.size        = SZ_256K,
417 		.mask_flags  = MTD_WRITEABLE, /* force read-only */
418 	},
419 	[2] = {
420 		.name        = "Environment",
421 		.offset      = MTDPART_OFS_APPEND,
422 		.size        = SZ_256K,
423 	},
424 	[3] = {
425 		.name        = "reserved",
426 		.offset      = MTDPART_OFS_APPEND,
427 		.size        = SZ_256K + SZ_1M,
428 		.mask_flags  = MTD_WRITEABLE, /* force read-only */
429 	},
430 	[4] = {
431 		.name        = "kernel",
432 		.offset      = MTDPART_OFS_APPEND,
433 		.size        = SZ_4M,
434 	},
435 	[5] = {
436 		.name        = "fs",
437 		.offset      = MTDPART_OFS_APPEND,
438 		.size        = MTDPART_SIZ_FULL,
439 	},
440 };
441 
442 static struct pxa3xx_nand_platform_data cm_x300_nand_info = {
443 	.keep_config	= 1,
444 	.parts		= cm_x300_nand_partitions,
445 	.nr_parts	= ARRAY_SIZE(cm_x300_nand_partitions),
446 };
447 
cm_x300_init_nand(void)448 static void __init cm_x300_init_nand(void)
449 {
450 	pxa3xx_set_nand_info(&cm_x300_nand_info);
451 }
452 #else
cm_x300_init_nand(void)453 static inline void cm_x300_init_nand(void) {}
454 #endif
455 
456 #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
457 static struct pxamci_platform_data cm_x300_mci_platform_data = {
458 	.detect_delay_ms	= 200,
459 	.ocr_mask		= MMC_VDD_32_33|MMC_VDD_33_34,
460 };
461 
462 static struct gpiod_lookup_table cm_x300_mci_gpio_table = {
463 	.dev_id = "pxa2xx-mci.0",
464 	.table = {
465 		/* Card detect on GPIO 82 */
466 		GPIO_LOOKUP("gpio-pxa", GPIO82_MMC_IRQ, "cd", GPIO_ACTIVE_LOW),
467 		/* Write protect on GPIO 85 */
468 		GPIO_LOOKUP("gpio-pxa", GPIO85_MMC_WP, "wp", GPIO_ACTIVE_LOW),
469 		{ },
470 	},
471 };
472 
473 /* The second MMC slot of CM-X300 is hardwired to Libertas card and has
474    no detection/ro pins */
cm_x300_mci2_init(struct device * dev,irq_handler_t cm_x300_detect_int,void * data)475 static int cm_x300_mci2_init(struct device *dev,
476 			     irq_handler_t cm_x300_detect_int,
477 	void *data)
478 {
479 	return 0;
480 }
481 
cm_x300_mci2_exit(struct device * dev,void * data)482 static void cm_x300_mci2_exit(struct device *dev, void *data)
483 {
484 }
485 
486 static struct pxamci_platform_data cm_x300_mci2_platform_data = {
487 	.detect_delay_ms	= 200,
488 	.ocr_mask		= MMC_VDD_32_33|MMC_VDD_33_34,
489 	.init 			= cm_x300_mci2_init,
490 	.exit			= cm_x300_mci2_exit,
491 };
492 
cm_x300_init_mmc(void)493 static void __init cm_x300_init_mmc(void)
494 {
495 	gpiod_add_lookup_table(&cm_x300_mci_gpio_table);
496 	pxa_set_mci_info(&cm_x300_mci_platform_data);
497 	pxa3xx_set_mci2_info(&cm_x300_mci2_platform_data);
498 }
499 #else
cm_x300_init_mmc(void)500 static inline void cm_x300_init_mmc(void) {}
501 #endif
502 
503 #if defined(CONFIG_PXA310_ULPI)
504 static struct clk *pout_clk;
505 
cm_x300_ulpi_phy_reset(void)506 static int cm_x300_ulpi_phy_reset(void)
507 {
508 	int err;
509 
510 	/* reset the PHY */
511 	err = gpio_request_one(GPIO_ULPI_PHY_RST, GPIOF_OUT_INIT_LOW,
512 			       "ulpi reset");
513 	if (err) {
514 		pr_err("failed to request ULPI reset GPIO: %d\n", err);
515 		return err;
516 	}
517 
518 	msleep(10);
519 	gpio_set_value(GPIO_ULPI_PHY_RST, 1);
520 	msleep(10);
521 
522 	gpio_free(GPIO_ULPI_PHY_RST);
523 
524 	return 0;
525 }
526 
cm_x300_u2d_init(struct device * dev)527 static int cm_x300_u2d_init(struct device *dev)
528 {
529 	int err = 0;
530 
531 	if (cpu_is_pxa310()) {
532 		/* CLK_POUT is connected to the ULPI PHY */
533 		pout_clk = clk_get(NULL, "CLK_POUT");
534 		if (IS_ERR(pout_clk)) {
535 			err = PTR_ERR(pout_clk);
536 			pr_err("failed to get CLK_POUT: %d\n", err);
537 			return err;
538 		}
539 		clk_prepare_enable(pout_clk);
540 
541 		err = cm_x300_ulpi_phy_reset();
542 		if (err) {
543 			clk_disable(pout_clk);
544 			clk_put(pout_clk);
545 		}
546 	}
547 
548 	return err;
549 }
550 
cm_x300_u2d_exit(struct device * dev)551 static void cm_x300_u2d_exit(struct device *dev)
552 {
553 	if (cpu_is_pxa310()) {
554 		clk_disable_unprepare(pout_clk);
555 		clk_put(pout_clk);
556 	}
557 }
558 
559 static struct pxa3xx_u2d_platform_data cm_x300_u2d_platform_data = {
560 	.ulpi_mode	= ULPI_SER_6PIN,
561 	.init		= cm_x300_u2d_init,
562 	.exit		= cm_x300_u2d_exit,
563 };
564 
cm_x300_init_u2d(void)565 static void __init cm_x300_init_u2d(void)
566 {
567 	pxa3xx_set_u2d_info(&cm_x300_u2d_platform_data);
568 }
569 #else
cm_x300_init_u2d(void)570 static inline void cm_x300_init_u2d(void) {}
571 #endif
572 
573 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
cm_x300_ohci_init(struct device * dev)574 static int cm_x300_ohci_init(struct device *dev)
575 {
576 	if (cpu_is_pxa300())
577 		UP2OCR = UP2OCR_HXS
578 			| UP2OCR_HXOE | UP2OCR_DMPDE | UP2OCR_DPPDE;
579 
580 	return 0;
581 }
582 
583 static struct pxaohci_platform_data cm_x300_ohci_platform_data = {
584 	.port_mode	= PMM_PERPORT_MODE,
585 	.flags		= ENABLE_PORT_ALL | POWER_CONTROL_LOW,
586 	.init		= cm_x300_ohci_init,
587 };
588 
cm_x300_init_ohci(void)589 static void __init cm_x300_init_ohci(void)
590 {
591 	pxa_set_ohci_info(&cm_x300_ohci_platform_data);
592 }
593 #else
cm_x300_init_ohci(void)594 static inline void cm_x300_init_ohci(void) {}
595 #endif
596 
597 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
598 static struct gpio_led cm_x300_leds[] = {
599 	[0] = {
600 		.name = "cm-x300:green",
601 		.default_trigger = "heartbeat",
602 		.active_low = 1,
603 	},
604 };
605 
606 static struct gpio_led_platform_data cm_x300_gpio_led_pdata = {
607 	.num_leds = ARRAY_SIZE(cm_x300_leds),
608 	.leds = cm_x300_leds,
609 };
610 
611 static struct platform_device cm_x300_led_device = {
612 	.name		= "leds-gpio",
613 	.id		= -1,
614 	.dev		= {
615 		.platform_data = &cm_x300_gpio_led_pdata,
616 	},
617 };
618 
cm_x300_init_leds(void)619 static void __init cm_x300_init_leds(void)
620 {
621 	if (system_rev < 130)
622 		cm_x300_leds[0].gpio = 79;
623 	else
624 		cm_x300_leds[0].gpio = 76;
625 
626 	platform_device_register(&cm_x300_led_device);
627 }
628 #else
cm_x300_init_leds(void)629 static inline void cm_x300_init_leds(void) {}
630 #endif
631 
632 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
633 /* PCA9555 */
634 static struct pca953x_platform_data cm_x300_gpio_ext_pdata_0 = {
635 	.gpio_base = 128,
636 };
637 
638 static struct pca953x_platform_data cm_x300_gpio_ext_pdata_1 = {
639 	.gpio_base = 144,
640 };
641 
642 static struct i2c_board_info cm_x300_gpio_ext_info[] = {
643 	[0] = {
644 		I2C_BOARD_INFO("pca9555", 0x24),
645 		.platform_data = &cm_x300_gpio_ext_pdata_0,
646 	},
647 	[1] = {
648 		I2C_BOARD_INFO("pca9555", 0x25),
649 		.platform_data = &cm_x300_gpio_ext_pdata_1,
650 	},
651 };
652 
cm_x300_init_i2c(void)653 static void __init cm_x300_init_i2c(void)
654 {
655 	pxa_set_i2c_info(NULL);
656 	i2c_register_board_info(0, cm_x300_gpio_ext_info,
657 				ARRAY_SIZE(cm_x300_gpio_ext_info));
658 }
659 #else
cm_x300_init_i2c(void)660 static inline void cm_x300_init_i2c(void) {}
661 #endif
662 
663 #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
664 struct v3020_platform_data cm_x300_v3020_pdata = {
665 	.use_gpio	= 1,
666 	.gpio_cs	= GPIO95_RTC_CS,
667 	.gpio_wr	= GPIO96_RTC_WR,
668 	.gpio_rd	= GPIO97_RTC_RD,
669 	.gpio_io	= GPIO98_RTC_IO,
670 };
671 
672 static struct platform_device cm_x300_rtc_device = {
673 	.name		= "v3020",
674 	.id		= -1,
675 	.dev		= {
676 		.platform_data = &cm_x300_v3020_pdata,
677 	}
678 };
679 
cm_x300_init_rtc(void)680 static void __init cm_x300_init_rtc(void)
681 {
682 	platform_device_register(&cm_x300_rtc_device);
683 }
684 #else
cm_x300_init_rtc(void)685 static inline void cm_x300_init_rtc(void) {}
686 #endif
687 
688 /* Battery */
689 struct power_supply_info cm_x300_psy_info = {
690 	.name = "battery",
691 	.technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
692 	.voltage_max_design = 4200000,
693 	.voltage_min_design = 3000000,
694 	.use_for_apm = 1,
695 };
696 
cm_x300_battery_low(void)697 static void cm_x300_battery_low(void)
698 {
699 #if defined(CONFIG_APM_EMULATION)
700 	apm_queue_event(APM_LOW_BATTERY);
701 #endif
702 }
703 
cm_x300_battery_critical(void)704 static void cm_x300_battery_critical(void)
705 {
706 #if defined(CONFIG_APM_EMULATION)
707 	apm_queue_event(APM_CRITICAL_SUSPEND);
708 #endif
709 }
710 
711 struct da9030_battery_info cm_x300_battery_info = {
712 	.battery_info = &cm_x300_psy_info,
713 
714 	.charge_milliamp = 1000,
715 	.charge_millivolt = 4200,
716 
717 	.vbat_low = 3600,
718 	.vbat_crit = 3400,
719 	.vbat_charge_start = 4100,
720 	.vbat_charge_stop = 4200,
721 	.vbat_charge_restart = 4000,
722 
723 	.vcharge_min = 3200,
724 	.vcharge_max = 5500,
725 
726 	.tbat_low = 197,
727 	.tbat_high = 78,
728 	.tbat_restart = 100,
729 
730 	.batmon_interval = 0,
731 
732 	.battery_low = cm_x300_battery_low,
733 	.battery_critical = cm_x300_battery_critical,
734 };
735 
736 static struct regulator_consumer_supply buck2_consumers[] = {
737 	REGULATOR_SUPPLY("vcc_core", NULL),
738 };
739 
740 static struct regulator_init_data buck2_data = {
741 	.constraints = {
742 		.min_uV = 1375000,
743 		.max_uV = 1375000,
744 		.state_mem = {
745 			.enabled = 0,
746 		},
747 		.valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
748 		.apply_uV = 1,
749 	},
750 	.num_consumer_supplies = ARRAY_SIZE(buck2_consumers),
751 	.consumer_supplies = buck2_consumers,
752 };
753 
754 /* DA9030 */
755 struct da903x_subdev_info cm_x300_da9030_subdevs[] = {
756 	{
757 		.name = "da903x-battery",
758 		.id = DA9030_ID_BAT,
759 		.platform_data = &cm_x300_battery_info,
760 	},
761 	{
762 		.name = "da903x-regulator",
763 		.id = DA9030_ID_BUCK2,
764 		.platform_data = &buck2_data,
765 	},
766 };
767 
768 static struct da903x_platform_data cm_x300_da9030_info = {
769 	.num_subdevs = ARRAY_SIZE(cm_x300_da9030_subdevs),
770 	.subdevs = cm_x300_da9030_subdevs,
771 };
772 
773 static struct i2c_board_info cm_x300_pmic_info = {
774 	I2C_BOARD_INFO("da9030", 0x49),
775 	.irq = IRQ_WAKEUP0,
776 	.platform_data = &cm_x300_da9030_info,
777 };
778 
779 static struct i2c_pxa_platform_data cm_x300_pwr_i2c_info = {
780 	.use_pio = 1,
781 };
782 
cm_x300_init_da9030(void)783 static void __init cm_x300_init_da9030(void)
784 {
785 	pxa3xx_set_i2c_power_info(&cm_x300_pwr_i2c_info);
786 	i2c_register_board_info(1, &cm_x300_pmic_info, 1);
787 	irq_set_irq_wake(IRQ_WAKEUP0, 1);
788 }
789 
790 /* wi2wi gpio setting for system_rev >= 130 */
791 static struct gpio cm_x300_wi2wi_gpios[] __initdata = {
792 	{ 71, GPIOF_OUT_INIT_HIGH, "wlan en" },
793 	{ 70, GPIOF_OUT_INIT_HIGH, "bt reset" },
794 };
795 
cm_x300_init_wi2wi(void)796 static void __init cm_x300_init_wi2wi(void)
797 {
798 	int err;
799 
800 	if (system_rev < 130) {
801 		cm_x300_wi2wi_gpios[0].gpio = 77;	/* wlan en */
802 		cm_x300_wi2wi_gpios[1].gpio = 78;	/* bt reset */
803 	}
804 
805 	/* Libertas and CSR reset */
806 	err = gpio_request_array(ARRAY_AND_SIZE(cm_x300_wi2wi_gpios));
807 	if (err) {
808 		pr_err("failed to request wifi/bt gpios: %d\n", err);
809 		return;
810 	}
811 
812 	udelay(10);
813 	gpio_set_value(cm_x300_wi2wi_gpios[1].gpio, 0);
814 	udelay(10);
815 	gpio_set_value(cm_x300_wi2wi_gpios[1].gpio, 1);
816 
817 	gpio_free_array(ARRAY_AND_SIZE(cm_x300_wi2wi_gpios));
818 }
819 
820 /* MFP */
cm_x300_init_mfp(void)821 static void __init cm_x300_init_mfp(void)
822 {
823 	/* board-processor specific GPIO initialization */
824 	pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_mfp_cfg));
825 
826 	if (system_rev < 130)
827 		pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_rev_lt130_mfp_cfg));
828 	else
829 		pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_rev_ge130_mfp_cfg));
830 
831 	if (cpu_is_pxa310())
832 		pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x310_mfp_cfg));
833 }
834 
cm_x300_init(void)835 static void __init cm_x300_init(void)
836 {
837 	cm_x300_init_mfp();
838 
839 	pxa_set_btuart_info(NULL);
840 	pxa_set_stuart_info(NULL);
841 	if (cpu_is_pxa300())
842 		pxa_set_ffuart_info(NULL);
843 
844 	cm_x300_init_da9030();
845 	cm_x300_init_dm9000();
846 	cm_x300_init_lcd();
847 	cm_x300_init_u2d();
848 	cm_x300_init_ohci();
849 	cm_x300_init_mmc();
850 	cm_x300_init_nand();
851 	cm_x300_init_leds();
852 	cm_x300_init_i2c();
853 	cm_x300_init_spi();
854 	cm_x300_init_rtc();
855 	cm_x300_init_ac97();
856 	cm_x300_init_wi2wi();
857 	cm_x300_init_bl();
858 
859 	regulator_has_full_constraints();
860 }
861 
cm_x300_fixup(struct tag * tags,char ** cmdline)862 static void __init cm_x300_fixup(struct tag *tags, char **cmdline)
863 {
864 	/* Make sure that mi->bank[0].start = PHYS_ADDR */
865 	for (; tags->hdr.size; tags = tag_next(tags))
866 		if (tags->hdr.tag == ATAG_MEM &&
867 			tags->u.mem.start == 0x80000000) {
868 			tags->u.mem.start = 0xa0000000;
869 			break;
870 		}
871 }
872 
873 MACHINE_START(CM_X300, "CM-X300 module")
874 	.atag_offset	= 0x100,
875 	.map_io		= pxa3xx_map_io,
876 	.nr_irqs	= PXA_NR_IRQS,
877 	.init_irq	= pxa3xx_init_irq,
878 	.handle_irq	= pxa3xx_handle_irq,
879 	.init_time	= pxa_timer_init,
880 	.init_machine	= cm_x300_init,
881 	.fixup		= cm_x300_fixup,
882 	.restart	= pxa_restart,
883 MACHINE_END
884