blob: e2afe0c2a12ed55ae0d1dbd7f99bbd74e7937d84 [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
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010040#define CPUIMX51_USBH1_STP IMX_GPIO_NR(1, 27)
41#define CPUIMX51_QUARTA_GPIO IMX_GPIO_NR(3, 28)
42#define CPUIMX51_QUARTB_GPIO IMX_GPIO_NR(3, 25)
43#define CPUIMX51_QUARTC_GPIO IMX_GPIO_NR(3, 26)
44#define CPUIMX51_QUARTD_GPIO IMX_GPIO_NR(3, 27)
Eric Bénardef93f142010-07-23 16:11:19 +020045#define CPUIMX51_QUART_XTAL 14745600
46#define CPUIMX51_QUART_REGSHIFT 17
47
48/* USB_CTRL_1 */
49#define MX51_USB_CTRL_1_OFFSET 0x10
50#define MX51_USB_CTRL_UH1_EXT_CLK_EN (1 << 25)
51
52#define MX51_USB_PLLDIV_12_MHZ 0x00
53#define MX51_USB_PLL_DIV_19_2_MHZ 0x01
54#define MX51_USB_PLL_DIV_24_MHZ 0x02
55
Eric Bénardef93f142010-07-23 16:11:19 +020056static struct plat_serial8250_port serial_platform_data[] = {
57 {
58 .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x400000),
Sascha Hauer7cf73812011-05-11 11:31:54 +020059 .irq = gpio_to_irq(CPUIMX51_QUARTA_GPIO),
Eric Bénardef93f142010-07-23 16:11:19 +020060 .irqflags = IRQF_TRIGGER_HIGH,
61 .uartclk = CPUIMX51_QUART_XTAL,
62 .regshift = CPUIMX51_QUART_REGSHIFT,
63 .iotype = UPIO_MEM,
64 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
65 }, {
66 .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x800000),
Sascha Hauer7cf73812011-05-11 11:31:54 +020067 .irq = gpio_to_irq(CPUIMX51_QUARTB_GPIO),
Eric Bénardef93f142010-07-23 16:11:19 +020068 .irqflags = IRQF_TRIGGER_HIGH,
69 .uartclk = CPUIMX51_QUART_XTAL,
70 .regshift = CPUIMX51_QUART_REGSHIFT,
71 .iotype = UPIO_MEM,
72 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
73 }, {
74 .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x1000000),
Sascha Hauer7cf73812011-05-11 11:31:54 +020075 .irq = gpio_to_irq(CPUIMX51_QUARTC_GPIO),
Eric Bénardef93f142010-07-23 16:11:19 +020076 .irqflags = IRQF_TRIGGER_HIGH,
77 .uartclk = CPUIMX51_QUART_XTAL,
78 .regshift = CPUIMX51_QUART_REGSHIFT,
79 .iotype = UPIO_MEM,
80 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
81 }, {
82 .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x2000000),
Sascha Hauer7cf73812011-05-11 11:31:54 +020083 .irq = irq_to_gpio(CPUIMX51_QUARTD_GPIO),
Eric Bénardef93f142010-07-23 16:11:19 +020084 .irqflags = IRQF_TRIGGER_HIGH,
85 .uartclk = CPUIMX51_QUART_XTAL,
86 .regshift = CPUIMX51_QUART_REGSHIFT,
87 .iotype = UPIO_MEM,
88 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
89 }, {
90 }
91};
92
93static struct platform_device serial_device = {
94 .name = "serial8250",
95 .id = 0,
96 .dev = {
97 .platform_data = serial_platform_data,
98 },
99};
Eric Bénardef93f142010-07-23 16:11:19 +0200100
101static struct platform_device *devices[] __initdata = {
Eric Bénardef93f142010-07-23 16:11:19 +0200102 &serial_device,
Eric Bénardef93f142010-07-23 16:11:19 +0200103};
104
Lothar Waßmann8f5260c2010-10-26 14:28:31 +0200105static iomux_v3_cfg_t eukrea_cpuimx51_pads[] = {
Eric Bénardef93f142010-07-23 16:11:19 +0200106 /* UART1 */
107 MX51_PAD_UART1_RXD__UART1_RXD,
108 MX51_PAD_UART1_TXD__UART1_TXD,
109 MX51_PAD_UART1_RTS__UART1_RTS,
110 MX51_PAD_UART1_CTS__UART1_CTS,
111
112 /* I2C2 */
Sascha Haueree1ae4d2010-12-15 09:56:35 +0100113 MX51_PAD_GPIO1_2__I2C2_SCL,
114 MX51_PAD_GPIO1_3__I2C2_SDA,
115 MX51_PAD_NANDF_D10__GPIO3_30,
Eric Bénardef93f142010-07-23 16:11:19 +0200116
117 /* QUART IRQ */
Sascha Haueree1ae4d2010-12-15 09:56:35 +0100118 MX51_PAD_NANDF_D15__GPIO3_25,
119 MX51_PAD_NANDF_D14__GPIO3_26,
120 MX51_PAD_NANDF_D13__GPIO3_27,
121 MX51_PAD_NANDF_D12__GPIO3_28,
Eric Bénardef93f142010-07-23 16:11:19 +0200122
123 /* USB HOST1 */
124 MX51_PAD_USBH1_CLK__USBH1_CLK,
125 MX51_PAD_USBH1_DIR__USBH1_DIR,
126 MX51_PAD_USBH1_NXT__USBH1_NXT,
127 MX51_PAD_USBH1_DATA0__USBH1_DATA0,
128 MX51_PAD_USBH1_DATA1__USBH1_DATA1,
129 MX51_PAD_USBH1_DATA2__USBH1_DATA2,
130 MX51_PAD_USBH1_DATA3__USBH1_DATA3,
131 MX51_PAD_USBH1_DATA4__USBH1_DATA4,
132 MX51_PAD_USBH1_DATA5__USBH1_DATA5,
133 MX51_PAD_USBH1_DATA6__USBH1_DATA6,
134 MX51_PAD_USBH1_DATA7__USBH1_DATA7,
135 MX51_PAD_USBH1_STP__USBH1_STP,
136};
137
Eric Bénarda3927412010-10-12 16:29:20 +0200138static const struct mxc_nand_platform_data
139 eukrea_cpuimx51_nand_board_info __initconst = {
140 .width = 1,
141 .hw_ecc = 1,
142 .flash_bbt = 1,
143};
144
Uwe Kleine-König04b73b12010-08-11 22:23:06 +0200145static const struct imxuart_platform_data uart_pdata __initconst = {
Eric Bénardef93f142010-07-23 16:11:19 +0200146 .flags = IMXUART_HAVE_RTSCTS,
147};
148
Uwe Kleine-König44505c02010-09-30 16:44:53 +0200149static const
150struct imxi2c_platform_data eukrea_cpuimx51_i2c_data __initconst = {
Eric Bénardef93f142010-07-23 16:11:19 +0200151 .bitrate = 100000,
152};
153
154static struct i2c_board_info eukrea_cpuimx51_i2c_devices[] = {
155 {
156 I2C_BOARD_INFO("pcf8563", 0x51),
157 },
158};
159
160/* This function is board specific as the bit mask for the plldiv will also
161be different for other Freescale SoCs, thus a common bitmask is not
162possible and cannot get place in /plat-mxc/ehci.c.*/
163static int initialize_otg_port(struct platform_device *pdev)
164{
165 u32 v;
166 void __iomem *usb_base;
167 void __iomem *usbother_base;
168
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200169 usb_base = ioremap(MX51_USB_OTG_BASE_ADDR, SZ_4K);
Fabio Estevam28a4f902010-12-13 10:47:05 -0200170 if (!usb_base)
171 return -ENOMEM;
Eric Bénardef93f142010-07-23 16:11:19 +0200172 usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
173
174 /* Set the PHY clock to 19.2MHz */
175 v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
176 v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK;
177 v |= MX51_USB_PLL_DIV_19_2_MHZ;
178 __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
179 iounmap(usb_base);
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100180
181 mdelay(10);
182
183 return mx51_initialize_usb_hw(0, MXC_EHCI_INTERNAL_PHY);
Eric Bénardef93f142010-07-23 16:11:19 +0200184}
185
186static int initialize_usbh1_port(struct platform_device *pdev)
187{
188 u32 v;
189 void __iomem *usb_base;
190 void __iomem *usbother_base;
191
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200192 usb_base = ioremap(MX51_USB_OTG_BASE_ADDR, SZ_4K);
Fabio Estevam28a4f902010-12-13 10:47:05 -0200193 if (!usb_base)
194 return -ENOMEM;
Eric Bénardef93f142010-07-23 16:11:19 +0200195 usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
196
197 /* The clock for the USBH1 ULPI port will come externally from the PHY. */
198 v = __raw_readl(usbother_base + MX51_USB_CTRL_1_OFFSET);
199 __raw_writel(v | MX51_USB_CTRL_UH1_EXT_CLK_EN, usbother_base + MX51_USB_CTRL_1_OFFSET);
200 iounmap(usb_base);
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100201
202 mdelay(10);
203
204 return mx51_initialize_usb_hw(1, MXC_EHCI_POWER_PINS_ENABLED |
205 MXC_EHCI_ITC_NO_THRESHOLD);
Eric Bénardef93f142010-07-23 16:11:19 +0200206}
207
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200208static const struct mxc_usbh_platform_data dr_utmi_config __initconst = {
Eric Bénardef93f142010-07-23 16:11:19 +0200209 .init = initialize_otg_port,
210 .portsc = MXC_EHCI_UTMI_16BIT,
Eric Bénardef93f142010-07-23 16:11:19 +0200211};
212
Uwe Kleine-König6cafe482011-07-30 23:57:25 +0200213static const struct fsl_usb2_platform_data usb_pdata __initconst = {
Eric Bénardef93f142010-07-23 16:11:19 +0200214 .operating_mode = FSL_USB2_DR_DEVICE,
215 .phy_mode = FSL_USB2_PHY_UTMI_WIDE,
216};
217
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200218static const struct mxc_usbh_platform_data usbh1_config __initconst = {
Eric Bénardef93f142010-07-23 16:11:19 +0200219 .init = initialize_usbh1_port,
220 .portsc = MXC_EHCI_MODE_ULPI,
Eric Bénardef93f142010-07-23 16:11:19 +0200221};
222
223static int otg_mode_host;
224
225static int __init eukrea_cpuimx51_otg_mode(char *options)
226{
227 if (!strcmp(options, "host"))
228 otg_mode_host = 1;
229 else if (!strcmp(options, "device"))
230 otg_mode_host = 0;
231 else
232 pr_info("otg_mode neither \"host\" nor \"device\". "
233 "Defaulting to device\n");
234 return 0;
235}
236__setup("otg_mode=", eukrea_cpuimx51_otg_mode);
237
238/*
239 * Board specific initialization.
240 */
241static void __init eukrea_cpuimx51_init(void)
242{
Shawn Guob78d8e52011-06-06 00:07:55 +0800243 imx51_soc_init();
244
Eric Bénardef93f142010-07-23 16:11:19 +0200245 mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx51_pads,
246 ARRAY_SIZE(eukrea_cpuimx51_pads));
247
Uwe Kleine-König04b73b12010-08-11 22:23:06 +0200248 imx51_add_imx_uart(0, &uart_pdata);
Eric Bénarda3927412010-10-12 16:29:20 +0200249 imx51_add_mxc_nand(&eukrea_cpuimx51_nand_board_info);
250
Eric Bénardef93f142010-07-23 16:11:19 +0200251 gpio_request(CPUIMX51_QUARTA_GPIO, "quarta_irq");
252 gpio_direction_input(CPUIMX51_QUARTA_GPIO);
253 gpio_free(CPUIMX51_QUARTA_GPIO);
254 gpio_request(CPUIMX51_QUARTB_GPIO, "quartb_irq");
255 gpio_direction_input(CPUIMX51_QUARTB_GPIO);
256 gpio_free(CPUIMX51_QUARTB_GPIO);
257 gpio_request(CPUIMX51_QUARTC_GPIO, "quartc_irq");
258 gpio_direction_input(CPUIMX51_QUARTC_GPIO);
259 gpio_free(CPUIMX51_QUARTC_GPIO);
260 gpio_request(CPUIMX51_QUARTD_GPIO, "quartd_irq");
261 gpio_direction_input(CPUIMX51_QUARTD_GPIO);
262 gpio_free(CPUIMX51_QUARTD_GPIO);
263
Uwe Kleine-König6bd96f32010-10-06 12:00:18 +0200264 imx51_add_fec(NULL);
Eric Bénardef93f142010-07-23 16:11:19 +0200265 platform_add_devices(devices, ARRAY_SIZE(devices));
266
Uwe Kleine-König44505c02010-09-30 16:44:53 +0200267 imx51_add_imx_i2c(1, &eukrea_cpuimx51_i2c_data);
Eric Bénardef93f142010-07-23 16:11:19 +0200268 i2c_register_board_info(1, eukrea_cpuimx51_i2c_devices,
269 ARRAY_SIZE(eukrea_cpuimx51_i2c_devices));
270
271 if (otg_mode_host)
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200272 imx51_add_mxc_ehci_otg(&dr_utmi_config);
Eric Bénardef93f142010-07-23 16:11:19 +0200273 else {
274 initialize_otg_port(NULL);
Uwe Kleine-König6cafe482011-07-30 23:57:25 +0200275 imx51_add_fsl_usb2_udc(&usb_pdata);
Eric Bénardef93f142010-07-23 16:11:19 +0200276 }
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200277 imx51_add_mxc_ehci_hs(1, &usbh1_config);
Eric Bénardef93f142010-07-23 16:11:19 +0200278
279#ifdef CONFIG_MACH_EUKREA_MBIMX51_BASEBOARD
280 eukrea_mbimx51_baseboard_init();
281#endif
282}
283
284static void __init eukrea_cpuimx51_timer_init(void)
285{
286 mx51_clocks_init(32768, 24000000, 22579200, 0);
287}
288
289static struct sys_timer mxc_timer = {
290 .init = eukrea_cpuimx51_timer_init,
291};
292
293MACHINE_START(EUKREA_CPUIMX51, "Eukrea CPUIMX51 Module")
294 /* Maintainer: Eric Bénard <eric@eukrea.com> */
Sascha Hauer7608d7d2010-11-04 21:20:43 +0100295 .boot_params = MX51_PHYS_OFFSET + 0x100,
Eric Bénardef93f142010-07-23 16:11:19 +0200296 .map_io = mx51_map_io,
Uwe Kleine-Königab130422011-02-07 16:35:21 +0100297 .init_early = imx51_init_early,
Eric Bénardef93f142010-07-23 16:11:19 +0200298 .init_irq = mx51_init_irq,
Eric Bénardef93f142010-07-23 16:11:19 +0200299 .timer = &mxc_timer,
Uwe Kleine-Königab130422011-02-07 16:35:21 +0100300 .init_machine = eukrea_cpuimx51_init,
Eric Bénardef93f142010-07-23 16:11:19 +0200301MACHINE_END