blob: d0296a94c475dda0448ade48b192a790e6047c34 [file] [log] [blame]
Eric Bénardef93f142010-07-23 16:11:19 +02001/*
2 *
3 * Copyright (C) 2010 Eric Bénard <eric@eukrea.com>
4 *
5 * based on board-mx51_babbage.c which is
6 * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
7 * Copyright (C) 2009-2010 Amit Kucheria <amit.kucheria@canonical.com>
8 *
9 * The code contained herein is licensed under the GNU General Public
10 * License. You may obtain a copy of the GNU General Public License
11 * Version 2 or later at the following locations:
12 *
13 * http://www.opensource.org/licenses/gpl-license.html
14 * http://www.gnu.org/copyleft/gpl.html
15 */
16
17#include <linux/init.h>
18#include <linux/platform_device.h>
19#include <linux/serial_8250.h>
20#include <linux/i2c.h>
21#include <linux/gpio.h>
22#include <linux/delay.h>
23#include <linux/io.h>
24#include <linux/interrupt.h>
25#include <linux/irq.h>
26#include <linux/fsl_devices.h>
27
28#include <mach/eukrea-baseboards.h>
29#include <mach/common.h>
30#include <mach/hardware.h>
Eric Bénardef93f142010-07-23 16:11:19 +020031#include <mach/iomux-mx51.h>
Eric Bénardef93f142010-07-23 16:11:19 +020032#include <mach/mxc_ehci.h>
33
34#include <asm/irq.h>
35#include <asm/setup.h>
36#include <asm/mach-types.h>
37#include <asm/mach/arch.h>
38#include <asm/mach/time.h>
39
Uwe Kleine-König04b73b12010-08-11 22:23:06 +020040#include "devices-imx51.h"
Eric Bénardef93f142010-07-23 16:11:19 +020041#include "devices.h"
42
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010043#define CPUIMX51_USBH1_STP IMX_GPIO_NR(1, 27)
44#define CPUIMX51_QUARTA_GPIO IMX_GPIO_NR(3, 28)
45#define CPUIMX51_QUARTB_GPIO IMX_GPIO_NR(3, 25)
46#define CPUIMX51_QUARTC_GPIO IMX_GPIO_NR(3, 26)
47#define CPUIMX51_QUARTD_GPIO IMX_GPIO_NR(3, 27)
Eric Bénardef93f142010-07-23 16:11:19 +020048#define CPUIMX51_QUARTA_IRQ (MXC_INTERNAL_IRQS + CPUIMX51_QUARTA_GPIO)
49#define CPUIMX51_QUARTB_IRQ (MXC_INTERNAL_IRQS + CPUIMX51_QUARTB_GPIO)
50#define CPUIMX51_QUARTC_IRQ (MXC_INTERNAL_IRQS + CPUIMX51_QUARTC_GPIO)
51#define CPUIMX51_QUARTD_IRQ (MXC_INTERNAL_IRQS + CPUIMX51_QUARTD_GPIO)
52#define CPUIMX51_QUART_XTAL 14745600
53#define CPUIMX51_QUART_REGSHIFT 17
54
55/* USB_CTRL_1 */
56#define MX51_USB_CTRL_1_OFFSET 0x10
57#define MX51_USB_CTRL_UH1_EXT_CLK_EN (1 << 25)
58
59#define MX51_USB_PLLDIV_12_MHZ 0x00
60#define MX51_USB_PLL_DIV_19_2_MHZ 0x01
61#define MX51_USB_PLL_DIV_24_MHZ 0x02
62
Eric Bénardef93f142010-07-23 16:11:19 +020063static struct plat_serial8250_port serial_platform_data[] = {
64 {
65 .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x400000),
66 .irq = CPUIMX51_QUARTA_IRQ,
67 .irqflags = IRQF_TRIGGER_HIGH,
68 .uartclk = CPUIMX51_QUART_XTAL,
69 .regshift = CPUIMX51_QUART_REGSHIFT,
70 .iotype = UPIO_MEM,
71 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
72 }, {
73 .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x800000),
74 .irq = CPUIMX51_QUARTB_IRQ,
75 .irqflags = IRQF_TRIGGER_HIGH,
76 .uartclk = CPUIMX51_QUART_XTAL,
77 .regshift = CPUIMX51_QUART_REGSHIFT,
78 .iotype = UPIO_MEM,
79 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
80 }, {
81 .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x1000000),
82 .irq = CPUIMX51_QUARTC_IRQ,
83 .irqflags = IRQF_TRIGGER_HIGH,
84 .uartclk = CPUIMX51_QUART_XTAL,
85 .regshift = CPUIMX51_QUART_REGSHIFT,
86 .iotype = UPIO_MEM,
87 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
88 }, {
89 .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x2000000),
90 .irq = CPUIMX51_QUARTD_IRQ,
91 .irqflags = IRQF_TRIGGER_HIGH,
92 .uartclk = CPUIMX51_QUART_XTAL,
93 .regshift = CPUIMX51_QUART_REGSHIFT,
94 .iotype = UPIO_MEM,
95 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
96 }, {
97 }
98};
99
100static struct platform_device serial_device = {
101 .name = "serial8250",
102 .id = 0,
103 .dev = {
104 .platform_data = serial_platform_data,
105 },
106};
Eric Bénardef93f142010-07-23 16:11:19 +0200107
108static struct platform_device *devices[] __initdata = {
Eric Bénardef93f142010-07-23 16:11:19 +0200109 &serial_device,
Eric Bénardef93f142010-07-23 16:11:19 +0200110};
111
Lothar Waßmann8f5260c2010-10-26 14:28:31 +0200112static iomux_v3_cfg_t eukrea_cpuimx51_pads[] = {
Eric Bénardef93f142010-07-23 16:11:19 +0200113 /* UART1 */
114 MX51_PAD_UART1_RXD__UART1_RXD,
115 MX51_PAD_UART1_TXD__UART1_TXD,
116 MX51_PAD_UART1_RTS__UART1_RTS,
117 MX51_PAD_UART1_CTS__UART1_CTS,
118
119 /* I2C2 */
Sascha Haueree1ae4d2010-12-15 09:56:35 +0100120 MX51_PAD_GPIO1_2__I2C2_SCL,
121 MX51_PAD_GPIO1_3__I2C2_SDA,
122 MX51_PAD_NANDF_D10__GPIO3_30,
Eric Bénardef93f142010-07-23 16:11:19 +0200123
124 /* QUART IRQ */
Sascha Haueree1ae4d2010-12-15 09:56:35 +0100125 MX51_PAD_NANDF_D15__GPIO3_25,
126 MX51_PAD_NANDF_D14__GPIO3_26,
127 MX51_PAD_NANDF_D13__GPIO3_27,
128 MX51_PAD_NANDF_D12__GPIO3_28,
Eric Bénardef93f142010-07-23 16:11:19 +0200129
130 /* USB HOST1 */
131 MX51_PAD_USBH1_CLK__USBH1_CLK,
132 MX51_PAD_USBH1_DIR__USBH1_DIR,
133 MX51_PAD_USBH1_NXT__USBH1_NXT,
134 MX51_PAD_USBH1_DATA0__USBH1_DATA0,
135 MX51_PAD_USBH1_DATA1__USBH1_DATA1,
136 MX51_PAD_USBH1_DATA2__USBH1_DATA2,
137 MX51_PAD_USBH1_DATA3__USBH1_DATA3,
138 MX51_PAD_USBH1_DATA4__USBH1_DATA4,
139 MX51_PAD_USBH1_DATA5__USBH1_DATA5,
140 MX51_PAD_USBH1_DATA6__USBH1_DATA6,
141 MX51_PAD_USBH1_DATA7__USBH1_DATA7,
142 MX51_PAD_USBH1_STP__USBH1_STP,
143};
144
Eric Bénarda3927412010-10-12 16:29:20 +0200145static const struct mxc_nand_platform_data
146 eukrea_cpuimx51_nand_board_info __initconst = {
147 .width = 1,
148 .hw_ecc = 1,
149 .flash_bbt = 1,
150};
151
Uwe Kleine-König04b73b12010-08-11 22:23:06 +0200152static const struct imxuart_platform_data uart_pdata __initconst = {
Eric Bénardef93f142010-07-23 16:11:19 +0200153 .flags = IMXUART_HAVE_RTSCTS,
154};
155
Uwe Kleine-König44505c02010-09-30 16:44:53 +0200156static const
157struct imxi2c_platform_data eukrea_cpuimx51_i2c_data __initconst = {
Eric Bénardef93f142010-07-23 16:11:19 +0200158 .bitrate = 100000,
159};
160
161static struct i2c_board_info eukrea_cpuimx51_i2c_devices[] = {
162 {
163 I2C_BOARD_INFO("pcf8563", 0x51),
164 },
165};
166
167/* This function is board specific as the bit mask for the plldiv will also
168be different for other Freescale SoCs, thus a common bitmask is not
169possible and cannot get place in /plat-mxc/ehci.c.*/
170static int initialize_otg_port(struct platform_device *pdev)
171{
172 u32 v;
173 void __iomem *usb_base;
174 void __iomem *usbother_base;
175
176 usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
Fabio Estevam28a4f902010-12-13 10:47:05 -0200177 if (!usb_base)
178 return -ENOMEM;
Eric Bénardef93f142010-07-23 16:11:19 +0200179 usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
180
181 /* Set the PHY clock to 19.2MHz */
182 v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
183 v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK;
184 v |= MX51_USB_PLL_DIV_19_2_MHZ;
185 __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
186 iounmap(usb_base);
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100187
188 mdelay(10);
189
190 return mx51_initialize_usb_hw(0, MXC_EHCI_INTERNAL_PHY);
Eric Bénardef93f142010-07-23 16:11:19 +0200191}
192
193static int initialize_usbh1_port(struct platform_device *pdev)
194{
195 u32 v;
196 void __iomem *usb_base;
197 void __iomem *usbother_base;
198
199 usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
Fabio Estevam28a4f902010-12-13 10:47:05 -0200200 if (!usb_base)
201 return -ENOMEM;
Eric Bénardef93f142010-07-23 16:11:19 +0200202 usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
203
204 /* The clock for the USBH1 ULPI port will come externally from the PHY. */
205 v = __raw_readl(usbother_base + MX51_USB_CTRL_1_OFFSET);
206 __raw_writel(v | MX51_USB_CTRL_UH1_EXT_CLK_EN, usbother_base + MX51_USB_CTRL_1_OFFSET);
207 iounmap(usb_base);
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100208
209 mdelay(10);
210
211 return mx51_initialize_usb_hw(1, MXC_EHCI_POWER_PINS_ENABLED |
212 MXC_EHCI_ITC_NO_THRESHOLD);
Eric Bénardef93f142010-07-23 16:11:19 +0200213}
214
215static struct mxc_usbh_platform_data dr_utmi_config = {
216 .init = initialize_otg_port,
217 .portsc = MXC_EHCI_UTMI_16BIT,
Eric Bénardef93f142010-07-23 16:11:19 +0200218};
219
220static struct fsl_usb2_platform_data usb_pdata = {
221 .operating_mode = FSL_USB2_DR_DEVICE,
222 .phy_mode = FSL_USB2_PHY_UTMI_WIDE,
223};
224
225static struct mxc_usbh_platform_data usbh1_config = {
226 .init = initialize_usbh1_port,
227 .portsc = MXC_EHCI_MODE_ULPI,
Eric Bénardef93f142010-07-23 16:11:19 +0200228};
229
230static int otg_mode_host;
231
232static int __init eukrea_cpuimx51_otg_mode(char *options)
233{
234 if (!strcmp(options, "host"))
235 otg_mode_host = 1;
236 else if (!strcmp(options, "device"))
237 otg_mode_host = 0;
238 else
239 pr_info("otg_mode neither \"host\" nor \"device\". "
240 "Defaulting to device\n");
241 return 0;
242}
243__setup("otg_mode=", eukrea_cpuimx51_otg_mode);
244
245/*
246 * Board specific initialization.
247 */
248static void __init eukrea_cpuimx51_init(void)
249{
250 mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx51_pads,
251 ARRAY_SIZE(eukrea_cpuimx51_pads));
252
Uwe Kleine-König04b73b12010-08-11 22:23:06 +0200253 imx51_add_imx_uart(0, &uart_pdata);
Eric Bénarda3927412010-10-12 16:29:20 +0200254 imx51_add_mxc_nand(&eukrea_cpuimx51_nand_board_info);
255
Eric Bénardef93f142010-07-23 16:11:19 +0200256 gpio_request(CPUIMX51_QUARTA_GPIO, "quarta_irq");
257 gpio_direction_input(CPUIMX51_QUARTA_GPIO);
258 gpio_free(CPUIMX51_QUARTA_GPIO);
259 gpio_request(CPUIMX51_QUARTB_GPIO, "quartb_irq");
260 gpio_direction_input(CPUIMX51_QUARTB_GPIO);
261 gpio_free(CPUIMX51_QUARTB_GPIO);
262 gpio_request(CPUIMX51_QUARTC_GPIO, "quartc_irq");
263 gpio_direction_input(CPUIMX51_QUARTC_GPIO);
264 gpio_free(CPUIMX51_QUARTC_GPIO);
265 gpio_request(CPUIMX51_QUARTD_GPIO, "quartd_irq");
266 gpio_direction_input(CPUIMX51_QUARTD_GPIO);
267 gpio_free(CPUIMX51_QUARTD_GPIO);
268
Uwe Kleine-König6bd96f32010-10-06 12:00:18 +0200269 imx51_add_fec(NULL);
Eric Bénardef93f142010-07-23 16:11:19 +0200270 platform_add_devices(devices, ARRAY_SIZE(devices));
271
Uwe Kleine-König44505c02010-09-30 16:44:53 +0200272 imx51_add_imx_i2c(1, &eukrea_cpuimx51_i2c_data);
Eric Bénardef93f142010-07-23 16:11:19 +0200273 i2c_register_board_info(1, eukrea_cpuimx51_i2c_devices,
274 ARRAY_SIZE(eukrea_cpuimx51_i2c_devices));
275
276 if (otg_mode_host)
277 mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config);
278 else {
279 initialize_otg_port(NULL);
280 mxc_register_device(&mxc_usbdr_udc_device, &usb_pdata);
281 }
282 mxc_register_device(&mxc_usbh1_device, &usbh1_config);
283
284#ifdef CONFIG_MACH_EUKREA_MBIMX51_BASEBOARD
285 eukrea_mbimx51_baseboard_init();
286#endif
287}
288
289static void __init eukrea_cpuimx51_timer_init(void)
290{
291 mx51_clocks_init(32768, 24000000, 22579200, 0);
292}
293
294static struct sys_timer mxc_timer = {
295 .init = eukrea_cpuimx51_timer_init,
296};
297
298MACHINE_START(EUKREA_CPUIMX51, "Eukrea CPUIMX51 Module")
299 /* Maintainer: Eric Bénard <eric@eukrea.com> */
Sascha Hauer7608d7d2010-11-04 21:20:43 +0100300 .boot_params = MX51_PHYS_OFFSET + 0x100,
Eric Bénardef93f142010-07-23 16:11:19 +0200301 .map_io = mx51_map_io,
Uwe Kleine-Königab130422011-02-07 16:35:21 +0100302 .init_early = imx51_init_early,
Eric Bénardef93f142010-07-23 16:11:19 +0200303 .init_irq = mx51_init_irq,
Eric Bénardef93f142010-07-23 16:11:19 +0200304 .timer = &mxc_timer,
Uwe Kleine-Königab130422011-02-07 16:35:21 +0100305 .init_machine = eukrea_cpuimx51_init,
Eric Bénardef93f142010-07-23 16:11:19 +0200306MACHINE_END