blob: aa1ff79e5a7437029cff424a87606ae97157acd2 [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>
Eric Bénardef93f142010-07-23 16:11:19 +020026
27#include <mach/eukrea-baseboards.h>
28#include <mach/common.h>
29#include <mach/hardware.h>
Eric Bénardef93f142010-07-23 16:11:19 +020030#include <mach/iomux-mx51.h>
Eric Bénardef93f142010-07-23 16:11:19 +020031
32#include <asm/irq.h>
33#include <asm/setup.h>
34#include <asm/mach-types.h>
35#include <asm/mach/arch.h>
36#include <asm/mach/time.h>
37
Uwe Kleine-König04b73b12010-08-11 22:23:06 +020038#include "devices-imx51.h"
Eric Bénardef93f142010-07-23 16:11:19 +020039#include "devices.h"
40
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010041#define CPUIMX51_USBH1_STP IMX_GPIO_NR(1, 27)
42#define CPUIMX51_QUARTA_GPIO IMX_GPIO_NR(3, 28)
43#define CPUIMX51_QUARTB_GPIO IMX_GPIO_NR(3, 25)
44#define CPUIMX51_QUARTC_GPIO IMX_GPIO_NR(3, 26)
45#define CPUIMX51_QUARTD_GPIO IMX_GPIO_NR(3, 27)
Eric Bénardef93f142010-07-23 16:11:19 +020046#define CPUIMX51_QUART_XTAL 14745600
47#define CPUIMX51_QUART_REGSHIFT 17
48
49/* USB_CTRL_1 */
50#define MX51_USB_CTRL_1_OFFSET 0x10
51#define MX51_USB_CTRL_UH1_EXT_CLK_EN (1 << 25)
52
53#define MX51_USB_PLLDIV_12_MHZ 0x00
54#define MX51_USB_PLL_DIV_19_2_MHZ 0x01
55#define MX51_USB_PLL_DIV_24_MHZ 0x02
56
Eric Bénardef93f142010-07-23 16:11:19 +020057static struct plat_serial8250_port serial_platform_data[] = {
58 {
59 .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x400000),
Sascha Hauer7cf73812011-05-11 11:31:54 +020060 .irq = gpio_to_irq(CPUIMX51_QUARTA_GPIO),
Eric Bénardef93f142010-07-23 16:11:19 +020061 .irqflags = IRQF_TRIGGER_HIGH,
62 .uartclk = CPUIMX51_QUART_XTAL,
63 .regshift = CPUIMX51_QUART_REGSHIFT,
64 .iotype = UPIO_MEM,
65 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
66 }, {
67 .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x800000),
Sascha Hauer7cf73812011-05-11 11:31:54 +020068 .irq = gpio_to_irq(CPUIMX51_QUARTB_GPIO),
Eric Bénardef93f142010-07-23 16:11:19 +020069 .irqflags = IRQF_TRIGGER_HIGH,
70 .uartclk = CPUIMX51_QUART_XTAL,
71 .regshift = CPUIMX51_QUART_REGSHIFT,
72 .iotype = UPIO_MEM,
73 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
74 }, {
75 .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x1000000),
Sascha Hauer7cf73812011-05-11 11:31:54 +020076 .irq = gpio_to_irq(CPUIMX51_QUARTC_GPIO),
Eric Bénardef93f142010-07-23 16:11:19 +020077 .irqflags = IRQF_TRIGGER_HIGH,
78 .uartclk = CPUIMX51_QUART_XTAL,
79 .regshift = CPUIMX51_QUART_REGSHIFT,
80 .iotype = UPIO_MEM,
81 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
82 }, {
83 .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x2000000),
Sascha Hauer7cf73812011-05-11 11:31:54 +020084 .irq = irq_to_gpio(CPUIMX51_QUARTD_GPIO),
Eric Bénardef93f142010-07-23 16:11:19 +020085 .irqflags = IRQF_TRIGGER_HIGH,
86 .uartclk = CPUIMX51_QUART_XTAL,
87 .regshift = CPUIMX51_QUART_REGSHIFT,
88 .iotype = UPIO_MEM,
89 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
90 }, {
91 }
92};
93
94static struct platform_device serial_device = {
95 .name = "serial8250",
96 .id = 0,
97 .dev = {
98 .platform_data = serial_platform_data,
99 },
100};
Eric Bénardef93f142010-07-23 16:11:19 +0200101
102static struct platform_device *devices[] __initdata = {
Eric Bénardef93f142010-07-23 16:11:19 +0200103 &serial_device,
Eric Bénardef93f142010-07-23 16:11:19 +0200104};
105
Lothar Waßmann8f5260c2010-10-26 14:28:31 +0200106static iomux_v3_cfg_t eukrea_cpuimx51_pads[] = {
Eric Bénardef93f142010-07-23 16:11:19 +0200107 /* UART1 */
108 MX51_PAD_UART1_RXD__UART1_RXD,
109 MX51_PAD_UART1_TXD__UART1_TXD,
110 MX51_PAD_UART1_RTS__UART1_RTS,
111 MX51_PAD_UART1_CTS__UART1_CTS,
112
113 /* I2C2 */
Sascha Haueree1ae4d2010-12-15 09:56:35 +0100114 MX51_PAD_GPIO1_2__I2C2_SCL,
115 MX51_PAD_GPIO1_3__I2C2_SDA,
116 MX51_PAD_NANDF_D10__GPIO3_30,
Eric Bénardef93f142010-07-23 16:11:19 +0200117
118 /* QUART IRQ */
Sascha Haueree1ae4d2010-12-15 09:56:35 +0100119 MX51_PAD_NANDF_D15__GPIO3_25,
120 MX51_PAD_NANDF_D14__GPIO3_26,
121 MX51_PAD_NANDF_D13__GPIO3_27,
122 MX51_PAD_NANDF_D12__GPIO3_28,
Eric Bénardef93f142010-07-23 16:11:19 +0200123
124 /* USB HOST1 */
125 MX51_PAD_USBH1_CLK__USBH1_CLK,
126 MX51_PAD_USBH1_DIR__USBH1_DIR,
127 MX51_PAD_USBH1_NXT__USBH1_NXT,
128 MX51_PAD_USBH1_DATA0__USBH1_DATA0,
129 MX51_PAD_USBH1_DATA1__USBH1_DATA1,
130 MX51_PAD_USBH1_DATA2__USBH1_DATA2,
131 MX51_PAD_USBH1_DATA3__USBH1_DATA3,
132 MX51_PAD_USBH1_DATA4__USBH1_DATA4,
133 MX51_PAD_USBH1_DATA5__USBH1_DATA5,
134 MX51_PAD_USBH1_DATA6__USBH1_DATA6,
135 MX51_PAD_USBH1_DATA7__USBH1_DATA7,
136 MX51_PAD_USBH1_STP__USBH1_STP,
137};
138
Eric Bénarda3927412010-10-12 16:29:20 +0200139static const struct mxc_nand_platform_data
140 eukrea_cpuimx51_nand_board_info __initconst = {
141 .width = 1,
142 .hw_ecc = 1,
143 .flash_bbt = 1,
144};
145
Uwe Kleine-König04b73b12010-08-11 22:23:06 +0200146static const struct imxuart_platform_data uart_pdata __initconst = {
Eric Bénardef93f142010-07-23 16:11:19 +0200147 .flags = IMXUART_HAVE_RTSCTS,
148};
149
Uwe Kleine-König44505c02010-09-30 16:44:53 +0200150static const
151struct imxi2c_platform_data eukrea_cpuimx51_i2c_data __initconst = {
Eric Bénardef93f142010-07-23 16:11:19 +0200152 .bitrate = 100000,
153};
154
155static struct i2c_board_info eukrea_cpuimx51_i2c_devices[] = {
156 {
157 I2C_BOARD_INFO("pcf8563", 0x51),
158 },
159};
160
161/* This function is board specific as the bit mask for the plldiv will also
162be different for other Freescale SoCs, thus a common bitmask is not
163possible and cannot get place in /plat-mxc/ehci.c.*/
164static int initialize_otg_port(struct platform_device *pdev)
165{
166 u32 v;
167 void __iomem *usb_base;
168 void __iomem *usbother_base;
169
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200170 usb_base = ioremap(MX51_USB_OTG_BASE_ADDR, SZ_4K);
Fabio Estevam28a4f902010-12-13 10:47:05 -0200171 if (!usb_base)
172 return -ENOMEM;
Eric Bénardef93f142010-07-23 16:11:19 +0200173 usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
174
175 /* Set the PHY clock to 19.2MHz */
176 v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
177 v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK;
178 v |= MX51_USB_PLL_DIV_19_2_MHZ;
179 __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
180 iounmap(usb_base);
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100181
182 mdelay(10);
183
184 return mx51_initialize_usb_hw(0, MXC_EHCI_INTERNAL_PHY);
Eric Bénardef93f142010-07-23 16:11:19 +0200185}
186
187static int initialize_usbh1_port(struct platform_device *pdev)
188{
189 u32 v;
190 void __iomem *usb_base;
191 void __iomem *usbother_base;
192
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200193 usb_base = ioremap(MX51_USB_OTG_BASE_ADDR, SZ_4K);
Fabio Estevam28a4f902010-12-13 10:47:05 -0200194 if (!usb_base)
195 return -ENOMEM;
Eric Bénardef93f142010-07-23 16:11:19 +0200196 usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
197
198 /* The clock for the USBH1 ULPI port will come externally from the PHY. */
199 v = __raw_readl(usbother_base + MX51_USB_CTRL_1_OFFSET);
200 __raw_writel(v | MX51_USB_CTRL_UH1_EXT_CLK_EN, usbother_base + MX51_USB_CTRL_1_OFFSET);
201 iounmap(usb_base);
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100202
203 mdelay(10);
204
205 return mx51_initialize_usb_hw(1, MXC_EHCI_POWER_PINS_ENABLED |
206 MXC_EHCI_ITC_NO_THRESHOLD);
Eric Bénardef93f142010-07-23 16:11:19 +0200207}
208
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200209static const struct mxc_usbh_platform_data dr_utmi_config __initconst = {
Eric Bénardef93f142010-07-23 16:11:19 +0200210 .init = initialize_otg_port,
211 .portsc = MXC_EHCI_UTMI_16BIT,
Eric Bénardef93f142010-07-23 16:11:19 +0200212};
213
214static struct fsl_usb2_platform_data usb_pdata = {
215 .operating_mode = FSL_USB2_DR_DEVICE,
216 .phy_mode = FSL_USB2_PHY_UTMI_WIDE,
217};
218
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200219static const struct mxc_usbh_platform_data usbh1_config __initconst = {
Eric Bénardef93f142010-07-23 16:11:19 +0200220 .init = initialize_usbh1_port,
221 .portsc = MXC_EHCI_MODE_ULPI,
Eric Bénardef93f142010-07-23 16:11:19 +0200222};
223
224static int otg_mode_host;
225
226static int __init eukrea_cpuimx51_otg_mode(char *options)
227{
228 if (!strcmp(options, "host"))
229 otg_mode_host = 1;
230 else if (!strcmp(options, "device"))
231 otg_mode_host = 0;
232 else
233 pr_info("otg_mode neither \"host\" nor \"device\". "
234 "Defaulting to device\n");
235 return 0;
236}
237__setup("otg_mode=", eukrea_cpuimx51_otg_mode);
238
239/*
240 * Board specific initialization.
241 */
242static void __init eukrea_cpuimx51_init(void)
243{
Shawn Guob78d8e52011-06-06 00:07:55 +0800244 imx51_soc_init();
245
Eric Bénardef93f142010-07-23 16:11:19 +0200246 mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx51_pads,
247 ARRAY_SIZE(eukrea_cpuimx51_pads));
248
Uwe Kleine-König04b73b12010-08-11 22:23:06 +0200249 imx51_add_imx_uart(0, &uart_pdata);
Eric Bénarda3927412010-10-12 16:29:20 +0200250 imx51_add_mxc_nand(&eukrea_cpuimx51_nand_board_info);
251
Eric Bénardef93f142010-07-23 16:11:19 +0200252 gpio_request(CPUIMX51_QUARTA_GPIO, "quarta_irq");
253 gpio_direction_input(CPUIMX51_QUARTA_GPIO);
254 gpio_free(CPUIMX51_QUARTA_GPIO);
255 gpio_request(CPUIMX51_QUARTB_GPIO, "quartb_irq");
256 gpio_direction_input(CPUIMX51_QUARTB_GPIO);
257 gpio_free(CPUIMX51_QUARTB_GPIO);
258 gpio_request(CPUIMX51_QUARTC_GPIO, "quartc_irq");
259 gpio_direction_input(CPUIMX51_QUARTC_GPIO);
260 gpio_free(CPUIMX51_QUARTC_GPIO);
261 gpio_request(CPUIMX51_QUARTD_GPIO, "quartd_irq");
262 gpio_direction_input(CPUIMX51_QUARTD_GPIO);
263 gpio_free(CPUIMX51_QUARTD_GPIO);
264
Uwe Kleine-König6bd96f32010-10-06 12:00:18 +0200265 imx51_add_fec(NULL);
Eric Bénardef93f142010-07-23 16:11:19 +0200266 platform_add_devices(devices, ARRAY_SIZE(devices));
267
Uwe Kleine-König44505c02010-09-30 16:44:53 +0200268 imx51_add_imx_i2c(1, &eukrea_cpuimx51_i2c_data);
Eric Bénardef93f142010-07-23 16:11:19 +0200269 i2c_register_board_info(1, eukrea_cpuimx51_i2c_devices,
270 ARRAY_SIZE(eukrea_cpuimx51_i2c_devices));
271
272 if (otg_mode_host)
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200273 imx51_add_mxc_ehci_otg(&dr_utmi_config);
Eric Bénardef93f142010-07-23 16:11:19 +0200274 else {
275 initialize_otg_port(NULL);
276 mxc_register_device(&mxc_usbdr_udc_device, &usb_pdata);
277 }
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200278 imx51_add_mxc_ehci_hs(1, &usbh1_config);
Eric Bénardef93f142010-07-23 16:11:19 +0200279
280#ifdef CONFIG_MACH_EUKREA_MBIMX51_BASEBOARD
281 eukrea_mbimx51_baseboard_init();
282#endif
283}
284
285static void __init eukrea_cpuimx51_timer_init(void)
286{
287 mx51_clocks_init(32768, 24000000, 22579200, 0);
288}
289
290static struct sys_timer mxc_timer = {
291 .init = eukrea_cpuimx51_timer_init,
292};
293
294MACHINE_START(EUKREA_CPUIMX51, "Eukrea CPUIMX51 Module")
295 /* Maintainer: Eric Bénard <eric@eukrea.com> */
Sascha Hauer7608d7d2010-11-04 21:20:43 +0100296 .boot_params = MX51_PHYS_OFFSET + 0x100,
Eric Bénardef93f142010-07-23 16:11:19 +0200297 .map_io = mx51_map_io,
Uwe Kleine-Königab130422011-02-07 16:35:21 +0100298 .init_early = imx51_init_early,
Eric Bénardef93f142010-07-23 16:11:19 +0200299 .init_irq = mx51_init_irq,
Eric Bénardef93f142010-07-23 16:11:19 +0200300 .timer = &mxc_timer,
Uwe Kleine-Königab130422011-02-07 16:35:21 +0100301 .init_machine = eukrea_cpuimx51_init,
Eric Bénardef93f142010-07-23 16:11:19 +0200302MACHINE_END