1/*
2 *  LILLY-1131 module support
3 *
4 *    Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
5 *
6 *  based on code for other MX31 boards,
7 *
8 *    Copyright 2005-2007 Freescale Semiconductor
9 *    Copyright (c) 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
10 *    Copyright (C) 2009 Valentin Longchamp, EPFL Mobots group
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 * GNU General Public License for more details.
21 */
22
23#include <linux/types.h>
24#include <linux/init.h>
25#include <linux/clk.h>
26#include <linux/gpio.h>
27#include <linux/delay.h>
28#include <linux/platform_device.h>
29#include <linux/interrupt.h>
30#include <linux/moduleparam.h>
31#include <linux/smsc911x.h>
32#include <linux/mtd/physmap.h>
33#include <linux/spi/spi.h>
34#include <linux/mfd/mc13783.h>
35#include <linux/usb/otg.h>
36#include <linux/usb/ulpi.h>
37#include <linux/regulator/machine.h>
38#include <linux/regulator/fixed.h>
39
40#include <asm/mach-types.h>
41#include <asm/mach/arch.h>
42#include <asm/mach/time.h>
43#include <asm/mach/map.h>
44
45#include <mach/hardware.h>
46#include <mach/common.h>
47#include <mach/iomux-mx3.h>
48#include <mach/board-mx31lilly.h>
49#include <mach/ulpi.h>
50
51#include "devices-imx31.h"
52
53/*
54 * This file contains module-specific initialization routines for LILLY-1131.
55 * Initialization of peripherals found on the baseboard is implemented in the
56 * appropriate baseboard support code.
57 */
58
59/* SMSC ethernet support */
60
61static struct resource smsc91x_resources[] = {
62	{
63		.start	= MX31_CS4_BASE_ADDR,
64		.end	= MX31_CS4_BASE_ADDR + 0xffff,
65		.flags	= IORESOURCE_MEM,
66	},
67	{
68		.start	= IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
69		.end	= IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
70		.flags	= IORESOURCE_IRQ | IRQF_TRIGGER_FALLING,
71	}
72};
73
74static struct smsc911x_platform_config smsc911x_config = {
75	.phy_interface	= PHY_INTERFACE_MODE_MII,
76	.irq_polarity	= SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
77	.irq_type	= SMSC911X_IRQ_TYPE_OPEN_DRAIN,
78	.flags		= SMSC911X_USE_32BIT |
79			  SMSC911X_SAVE_MAC_ADDRESS |
80			  SMSC911X_FORCE_INTERNAL_PHY,
81};
82
83static struct platform_device smsc91x_device = {
84	.name		= "smsc911x",
85	.id		= -1,
86	.num_resources	= ARRAY_SIZE(smsc91x_resources),
87	.resource	= smsc91x_resources,
88	.dev		= {
89		.platform_data = &smsc911x_config,
90	}
91};
92
93/* NOR flash */
94static struct physmap_flash_data nor_flash_data = {
95	.width  = 2,
96};
97
98static struct resource nor_flash_resource = {
99	.start	= 0xa0000000,
100	.end	= 0xa1ffffff,
101	.flags	= IORESOURCE_MEM,
102};
103
104static struct platform_device physmap_flash_device = {
105	.name	= "physmap-flash",
106	.id	= 0,
107	.dev	= {
108		.platform_data  = &nor_flash_data,
109	},
110	.resource = &nor_flash_resource,
111	.num_resources = 1,
112};
113
114/* USB */
115
116#define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
117			PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
118
119static int usbh1_init(struct platform_device *pdev)
120{
121	int pins[] = {
122		MX31_PIN_CSPI1_MOSI__USBH1_RXDM,
123		MX31_PIN_CSPI1_MISO__USBH1_RXDP,
124		MX31_PIN_CSPI1_SS0__USBH1_TXDM,
125		MX31_PIN_CSPI1_SS1__USBH1_TXDP,
126		MX31_PIN_CSPI1_SS2__USBH1_RCV,
127		MX31_PIN_CSPI1_SCLK__USBH1_OEB,
128		MX31_PIN_CSPI1_SPI_RDY__USBH1_FS,
129	};
130
131	mxc_iomux_setup_multiple_pins(pins, ARRAY_SIZE(pins), "USB H1");
132
133	mxc_iomux_set_pad(MX31_PIN_CSPI1_MOSI, USB_PAD_CFG);
134	mxc_iomux_set_pad(MX31_PIN_CSPI1_MISO, USB_PAD_CFG);
135	mxc_iomux_set_pad(MX31_PIN_CSPI1_SS0, USB_PAD_CFG);
136	mxc_iomux_set_pad(MX31_PIN_CSPI1_SS1, USB_PAD_CFG);
137	mxc_iomux_set_pad(MX31_PIN_CSPI1_SS2, USB_PAD_CFG);
138	mxc_iomux_set_pad(MX31_PIN_CSPI1_SCLK, USB_PAD_CFG);
139	mxc_iomux_set_pad(MX31_PIN_CSPI1_SPI_RDY, USB_PAD_CFG);
140
141	mxc_iomux_set_gpr(MUX_PGP_USB_SUSPEND, true);
142
143	mdelay(10);
144
145	return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED |
146			MXC_EHCI_INTERFACE_SINGLE_UNI);
147}
148
149static int usbh2_init(struct platform_device *pdev)
150{
151	int pins[] = {
152		MX31_PIN_USBH2_DATA0__USBH2_DATA0,
153		MX31_PIN_USBH2_DATA1__USBH2_DATA1,
154		MX31_PIN_USBH2_CLK__USBH2_CLK,
155		MX31_PIN_USBH2_DIR__USBH2_DIR,
156		MX31_PIN_USBH2_NXT__USBH2_NXT,
157		MX31_PIN_USBH2_STP__USBH2_STP,
158	};
159
160	mxc_iomux_setup_multiple_pins(pins, ARRAY_SIZE(pins), "USB H2");
161
162	mxc_iomux_set_pad(MX31_PIN_USBH2_CLK, USB_PAD_CFG);
163	mxc_iomux_set_pad(MX31_PIN_USBH2_DIR, USB_PAD_CFG);
164	mxc_iomux_set_pad(MX31_PIN_USBH2_NXT, USB_PAD_CFG);
165	mxc_iomux_set_pad(MX31_PIN_USBH2_STP, USB_PAD_CFG);
166	mxc_iomux_set_pad(MX31_PIN_USBH2_DATA0, USB_PAD_CFG);
167	mxc_iomux_set_pad(MX31_PIN_USBH2_DATA1, USB_PAD_CFG);
168	mxc_iomux_set_pad(MX31_PIN_SRXD6, USB_PAD_CFG);
169	mxc_iomux_set_pad(MX31_PIN_STXD6, USB_PAD_CFG);
170	mxc_iomux_set_pad(MX31_PIN_SFS3, USB_PAD_CFG);
171	mxc_iomux_set_pad(MX31_PIN_SCK3, USB_PAD_CFG);
172	mxc_iomux_set_pad(MX31_PIN_SRXD3, USB_PAD_CFG);
173	mxc_iomux_set_pad(MX31_PIN_STXD3, USB_PAD_CFG);
174
175	mxc_iomux_set_gpr(MUX_PGP_UH2, true);
176
177	/* chip select */
178	mxc_iomux_alloc_pin(IOMUX_MODE(MX31_PIN_DTR_DCE1, IOMUX_CONFIG_GPIO),
179				"USBH2_CS");
180	gpio_request(IOMUX_TO_GPIO(MX31_PIN_DTR_DCE1), "USBH2 CS");
181	gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_DTR_DCE1), 0);
182
183	mdelay(10);
184
185	return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED);
186}
187
188static const struct mxc_usbh_platform_data usbh1_pdata __initconst = {
189	.init	= usbh1_init,
190	.portsc	= MXC_EHCI_MODE_UTMI | MXC_EHCI_SERIAL,
191};
192
193static struct mxc_usbh_platform_data usbh2_pdata __initdata = {
194	.init	= usbh2_init,
195	.portsc	= MXC_EHCI_MODE_ULPI | MXC_EHCI_UTMI_8BIT,
196};
197
198static void __init lilly1131_usb_init(void)
199{
200	imx31_add_mxc_ehci_hs(1, &usbh1_pdata);
201
202	usbh2_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
203			ULPI_OTG_DRVVBUS_EXT);
204	if (usbh2_pdata.otg)
205		imx31_add_mxc_ehci_hs(2, &usbh2_pdata);
206}
207
208/* SPI */
209
210static int spi_internal_chipselect[] = {
211	MXC_SPI_CS(0),
212	MXC_SPI_CS(1),
213	MXC_SPI_CS(2),
214};
215
216static const struct spi_imx_master spi0_pdata __initconst = {
217	.chipselect = spi_internal_chipselect,
218	.num_chipselect = ARRAY_SIZE(spi_internal_chipselect),
219};
220
221static const struct spi_imx_master spi1_pdata __initconst = {
222	.chipselect = spi_internal_chipselect,
223	.num_chipselect = ARRAY_SIZE(spi_internal_chipselect),
224};
225
226static struct mc13xxx_platform_data mc13783_pdata __initdata = {
227	.flags = MC13XXX_USE_RTC | MC13XXX_USE_TOUCHSCREEN,
228};
229
230static struct spi_board_info mc13783_dev __initdata = {
231	.modalias	= "mc13783",
232	.max_speed_hz	= 1000000,
233	.bus_num	= 1,
234	.chip_select	= 0,
235	.platform_data	= &mc13783_pdata,
236	.irq		= IOMUX_TO_IRQ(MX31_PIN_GPIO1_3),
237};
238
239static struct platform_device *devices[] __initdata = {
240	&smsc91x_device,
241	&physmap_flash_device,
242};
243
244static int mx31lilly_baseboard;
245core_param(mx31lilly_baseboard, mx31lilly_baseboard, int, 0444);
246
247static struct regulator_consumer_supply dummy_supplies[] = {
248	REGULATOR_SUPPLY("vdd33a", "smsc911x"),
249	REGULATOR_SUPPLY("vddvario", "smsc911x"),
250};
251
252static void __init mx31lilly_board_init(void)
253{
254	imx31_soc_init();
255
256	switch (mx31lilly_baseboard) {
257	case MX31LILLY_NOBOARD:
258		break;
259	case MX31LILLY_DB:
260		mx31lilly_db_init();
261		break;
262	default:
263		printk(KERN_ERR "Illegal mx31lilly_baseboard type %d\n",
264			mx31lilly_baseboard);
265	}
266
267	mxc_iomux_alloc_pin(MX31_PIN_CS4__CS4, "Ethernet CS");
268
269	/* SPI */
270	mxc_iomux_alloc_pin(MX31_PIN_CSPI1_SCLK__SCLK, "SPI1_CLK");
271	mxc_iomux_alloc_pin(MX31_PIN_CSPI1_MOSI__MOSI, "SPI1_TX");
272	mxc_iomux_alloc_pin(MX31_PIN_CSPI1_MISO__MISO, "SPI1_RX");
273	mxc_iomux_alloc_pin(MX31_PIN_CSPI1_SPI_RDY__SPI_RDY, "SPI1_RDY");
274	mxc_iomux_alloc_pin(MX31_PIN_CSPI1_SS0__SS0, "SPI1_SS0");
275	mxc_iomux_alloc_pin(MX31_PIN_CSPI1_SS1__SS1, "SPI1_SS1");
276	mxc_iomux_alloc_pin(MX31_PIN_CSPI1_SS2__SS2, "SPI1_SS2");
277
278	mxc_iomux_alloc_pin(MX31_PIN_CSPI2_SCLK__SCLK, "SPI2_CLK");
279	mxc_iomux_alloc_pin(MX31_PIN_CSPI2_MOSI__MOSI, "SPI2_TX");
280	mxc_iomux_alloc_pin(MX31_PIN_CSPI2_MISO__MISO, "SPI2_RX");
281	mxc_iomux_alloc_pin(MX31_PIN_CSPI2_SPI_RDY__SPI_RDY, "SPI2_RDY");
282	mxc_iomux_alloc_pin(MX31_PIN_CSPI2_SS0__SS0, "SPI2_SS0");
283	mxc_iomux_alloc_pin(MX31_PIN_CSPI2_SS1__SS1, "SPI2_SS1");
284	mxc_iomux_alloc_pin(MX31_PIN_CSPI2_SS2__SS2, "SPI2_SS2");
285
286	imx31_add_spi_imx0(&spi0_pdata);
287	imx31_add_spi_imx1(&spi1_pdata);
288	spi_register_board_info(&mc13783_dev, 1);
289
290	regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
291
292	platform_add_devices(devices, ARRAY_SIZE(devices));
293
294	/* USB */
295	lilly1131_usb_init();
296}
297
298static void __init mx31lilly_timer_init(void)
299{
300	mx31_clocks_init(26000000);
301}
302
303static struct sys_timer mx31lilly_timer = {
304	.init	= mx31lilly_timer_init,
305};
306
307MACHINE_START(LILLY1131, "INCO startec LILLY-1131")
308	.atag_offset = 0x100,
309	.map_io = mx31_map_io,
310	.init_early = imx31_init_early,
311	.init_irq = mx31_init_irq,
312	.handle_irq = imx31_handle_irq,
313	.timer = &mx31lilly_timer,
314	.init_machine = mx31lilly_board_init,
315	.restart	= mxc_restart,
316MACHINE_END
317