blob: 71a5832d0929c6d86c8e0127747e540a5b99d022 [file] [log] [blame]
Eric Bénard70b17262010-10-12 16:12:36 +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/i2c.h>
20#include <linux/i2c/tsc2007.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énard70b17262010-10-12 16:12:36 +020026#include <linux/i2c-gpio.h>
27#include <linux/spi/spi.h>
28#include <linux/can/platform/mcp251x.h>
29
30#include <mach/eukrea-baseboards.h>
31#include <mach/common.h>
32#include <mach/hardware.h>
33#include <mach/iomux-mx51.h>
Eric Bénard70b17262010-10-12 16:12:36 +020034
35#include <asm/irq.h>
36#include <asm/setup.h>
37#include <asm/mach-types.h>
38#include <asm/mach/arch.h>
39#include <asm/mach/time.h>
40
41#include "devices-imx51.h"
Eric Bénardb13721462011-02-25 14:38:27 +010042#include "cpu_op-mx51.h"
Eric Bénard70b17262010-10-12 16:12:36 +020043
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +010044#define USBH1_RST IMX_GPIO_NR(2, 28)
45#define ETH_RST IMX_GPIO_NR(2, 31)
46#define TSC2007_IRQGPIO IMX_GPIO_NR(3, 12)
47#define CAN_IRQGPIO IMX_GPIO_NR(1, 1)
48#define CAN_RST IMX_GPIO_NR(4, 15)
49#define CAN_NCS IMX_GPIO_NR(4, 24)
50#define CAN_RXOBF IMX_GPIO_NR(1, 4)
51#define CAN_RX1BF IMX_GPIO_NR(1, 6)
52#define CAN_TXORTS IMX_GPIO_NR(1, 7)
53#define CAN_TX1RTS IMX_GPIO_NR(1, 8)
54#define CAN_TX2RTS IMX_GPIO_NR(1, 9)
55#define I2C_SCL IMX_GPIO_NR(4, 16)
56#define I2C_SDA IMX_GPIO_NR(4, 17)
Eric Bénard70b17262010-10-12 16:12:36 +020057
58/* USB_CTRL_1 */
59#define MX51_USB_CTRL_1_OFFSET 0x10
60#define MX51_USB_CTRL_UH1_EXT_CLK_EN (1 << 25)
61
62#define MX51_USB_PLLDIV_12_MHZ 0x00
63#define MX51_USB_PLL_DIV_19_2_MHZ 0x01
64#define MX51_USB_PLL_DIV_24_MHZ 0x02
65
Lothar Waßmann8f5260c2010-10-26 14:28:31 +020066static iomux_v3_cfg_t eukrea_cpuimx51sd_pads[] = {
Eric Bénard70b17262010-10-12 16:12:36 +020067 /* UART1 */
68 MX51_PAD_UART1_RXD__UART1_RXD,
69 MX51_PAD_UART1_TXD__UART1_TXD,
70 MX51_PAD_UART1_RTS__UART1_RTS,
71 MX51_PAD_UART1_CTS__UART1_CTS,
72
73 /* USB HOST1 */
74 MX51_PAD_USBH1_CLK__USBH1_CLK,
75 MX51_PAD_USBH1_DIR__USBH1_DIR,
76 MX51_PAD_USBH1_NXT__USBH1_NXT,
77 MX51_PAD_USBH1_DATA0__USBH1_DATA0,
78 MX51_PAD_USBH1_DATA1__USBH1_DATA1,
79 MX51_PAD_USBH1_DATA2__USBH1_DATA2,
80 MX51_PAD_USBH1_DATA3__USBH1_DATA3,
81 MX51_PAD_USBH1_DATA4__USBH1_DATA4,
82 MX51_PAD_USBH1_DATA5__USBH1_DATA5,
83 MX51_PAD_USBH1_DATA6__USBH1_DATA6,
84 MX51_PAD_USBH1_DATA7__USBH1_DATA7,
85 MX51_PAD_USBH1_STP__USBH1_STP,
Sascha Haueree1ae4d2010-12-15 09:56:35 +010086 MX51_PAD_EIM_CS3__GPIO2_28, /* PHY nRESET */
Eric Bénard70b17262010-10-12 16:12:36 +020087
88 /* FEC */
Sascha Haueree1ae4d2010-12-15 09:56:35 +010089 MX51_PAD_EIM_DTACK__GPIO2_31, /* PHY nRESET */
Eric Bénard70b17262010-10-12 16:12:36 +020090
91 /* HSI2C */
Sascha Haueree1ae4d2010-12-15 09:56:35 +010092 MX51_PAD_I2C1_CLK__GPIO4_16,
93 MX51_PAD_I2C1_DAT__GPIO4_17,
Eric Bénard70b17262010-10-12 16:12:36 +020094
95 /* CAN */
96 MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI,
97 MX51_PAD_CSPI1_MISO__ECSPI1_MISO,
98 MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK,
Sascha Haueree1ae4d2010-12-15 09:56:35 +010099 MX51_PAD_CSPI1_SS0__GPIO4_24, /* nCS */
100 MX51_PAD_CSI2_PIXCLK__GPIO4_15, /* nReset */
101 MX51_PAD_GPIO1_1__GPIO1_1, /* IRQ */
102 MX51_PAD_GPIO1_4__GPIO1_4, /* Control signals */
103 MX51_PAD_GPIO1_6__GPIO1_6,
104 MX51_PAD_GPIO1_7__GPIO1_7,
105 MX51_PAD_GPIO1_8__GPIO1_8,
106 MX51_PAD_GPIO1_9__GPIO1_9,
Eric Bénard70b17262010-10-12 16:12:36 +0200107
108 /* Touchscreen */
Sascha Haueree1ae4d2010-12-15 09:56:35 +0100109 /* IRQ */
Eric Bénard33d34872011-02-25 15:04:14 +0100110 _MX51_PAD_GPIO_NAND__GPIO_NAND | MUX_PAD_CTRL(PAD_CTL_PUS_22K_UP |
Sascha Haueree1ae4d2010-12-15 09:56:35 +0100111 PAD_CTL_PKE | PAD_CTL_SRE_FAST |
112 PAD_CTL_DSE_HIGH | PAD_CTL_PUE | PAD_CTL_HYS),
Eric Bénard70b17262010-10-12 16:12:36 +0200113};
114
115static const struct imxuart_platform_data uart_pdata __initconst = {
116 .flags = IMXUART_HAVE_RTSCTS,
117};
118
Eric Bénard70b17262010-10-12 16:12:36 +0200119static struct tsc2007_platform_data tsc2007_info = {
120 .model = 2007,
121 .x_plate_ohms = 180,
Eric Bénard70b17262010-10-12 16:12:36 +0200122};
123
124static struct i2c_board_info eukrea_cpuimx51sd_i2c_devices[] = {
125 {
126 I2C_BOARD_INFO("pcf8563", 0x51),
127 }, {
128 I2C_BOARD_INFO("tsc2007", 0x49),
129 .type = "tsc2007",
130 .platform_data = &tsc2007_info,
131 .irq = gpio_to_irq(TSC2007_IRQGPIO),
132 },
133};
134
135static const struct mxc_nand_platform_data
136 eukrea_cpuimx51sd_nand_board_info __initconst = {
137 .width = 1,
138 .hw_ecc = 1,
139 .flash_bbt = 1,
140};
141
142/* This function is board specific as the bit mask for the plldiv will also
143be different for other Freescale SoCs, thus a common bitmask is not
144possible and cannot get place in /plat-mxc/ehci.c.*/
145static int initialize_otg_port(struct platform_device *pdev)
146{
147 u32 v;
148 void __iomem *usb_base;
149 void __iomem *usbother_base;
150
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200151 usb_base = ioremap(MX51_USB_OTG_BASE_ADDR, SZ_4K);
Fabio Estevam28a4f902010-12-13 10:47:05 -0200152 if (!usb_base)
153 return -ENOMEM;
Eric Bénard70b17262010-10-12 16:12:36 +0200154 usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
155
156 /* Set the PHY clock to 19.2MHz */
157 v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
158 v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK;
159 v |= MX51_USB_PLL_DIV_19_2_MHZ;
160 __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
161 iounmap(usb_base);
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100162
163 mdelay(10);
164
165 return mx51_initialize_usb_hw(0, MXC_EHCI_INTERNAL_PHY);
Eric Bénard70b17262010-10-12 16:12:36 +0200166}
167
168static int initialize_usbh1_port(struct platform_device *pdev)
169{
170 u32 v;
171 void __iomem *usb_base;
172 void __iomem *usbother_base;
173
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200174 usb_base = ioremap(MX51_USB_OTG_BASE_ADDR, SZ_4K);
Fabio Estevam28a4f902010-12-13 10:47:05 -0200175 if (!usb_base)
176 return -ENOMEM;
Eric Bénard70b17262010-10-12 16:12:36 +0200177 usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
178
179 /* The clock for the USBH1 ULPI port will come from the PHY. */
180 v = __raw_readl(usbother_base + MX51_USB_CTRL_1_OFFSET);
181 __raw_writel(v | MX51_USB_CTRL_UH1_EXT_CLK_EN,
182 usbother_base + MX51_USB_CTRL_1_OFFSET);
183 iounmap(usb_base);
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100184
185 mdelay(10);
186
187 return mx51_initialize_usb_hw(1, MXC_EHCI_POWER_PINS_ENABLED |
188 MXC_EHCI_ITC_NO_THRESHOLD);
Eric Bénard70b17262010-10-12 16:12:36 +0200189}
190
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200191static const struct mxc_usbh_platform_data dr_utmi_config __initconst = {
Eric Bénard70b17262010-10-12 16:12:36 +0200192 .init = initialize_otg_port,
193 .portsc = MXC_EHCI_UTMI_16BIT,
Eric Bénard70b17262010-10-12 16:12:36 +0200194};
195
Uwe Kleine-König6cafe482011-07-30 23:57:25 +0200196static const struct fsl_usb2_platform_data usb_pdata __initconst = {
Eric Bénard70b17262010-10-12 16:12:36 +0200197 .operating_mode = FSL_USB2_DR_DEVICE,
198 .phy_mode = FSL_USB2_PHY_UTMI_WIDE,
199};
200
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200201static const struct mxc_usbh_platform_data usbh1_config __initconst = {
Eric Bénard70b17262010-10-12 16:12:36 +0200202 .init = initialize_usbh1_port,
203 .portsc = MXC_EHCI_MODE_ULPI,
Eric Bénard70b17262010-10-12 16:12:36 +0200204};
205
206static int otg_mode_host;
207
208static int __init eukrea_cpuimx51sd_otg_mode(char *options)
209{
210 if (!strcmp(options, "host"))
211 otg_mode_host = 1;
212 else if (!strcmp(options, "device"))
213 otg_mode_host = 0;
214 else
215 pr_info("otg_mode neither \"host\" nor \"device\". "
216 "Defaulting to device\n");
217 return 0;
218}
219__setup("otg_mode=", eukrea_cpuimx51sd_otg_mode);
220
221static struct i2c_gpio_platform_data pdata = {
222 .sda_pin = I2C_SDA,
223 .sda_is_open_drain = 0,
224 .scl_pin = I2C_SCL,
225 .scl_is_open_drain = 0,
226 .udelay = 2,
227};
228
229static struct platform_device hsi2c_gpio_device = {
230 .name = "i2c-gpio",
231 .id = 0,
232 .dev.platform_data = &pdata,
233};
234
235static struct mcp251x_platform_data mcp251x_info = {
236 .oscillator_frequency = 24E6,
237};
238
239static struct spi_board_info cpuimx51sd_spi_device[] = {
240 {
241 .modalias = "mcp2515",
Eric Bénard8c3f2d72011-02-25 14:38:29 +0100242 .max_speed_hz = 10000000,
Eric Bénard70b17262010-10-12 16:12:36 +0200243 .bus_num = 0,
244 .mode = SPI_MODE_0,
245 .chip_select = 0,
246 .platform_data = &mcp251x_info,
Arnaud Patard (Rtp)96886c42010-11-26 15:20:52 +0100247 .irq = gpio_to_irq(CAN_IRQGPIO)
Eric Bénard70b17262010-10-12 16:12:36 +0200248 },
249};
250
251static int cpuimx51sd_spi1_cs[] = {
252 CAN_NCS,
253};
254
255static const struct spi_imx_master cpuimx51sd_ecspi1_pdata __initconst = {
256 .chipselect = cpuimx51sd_spi1_cs,
257 .num_chipselect = ARRAY_SIZE(cpuimx51sd_spi1_cs),
258};
259
260static struct platform_device *platform_devices[] __initdata = {
261 &hsi2c_gpio_device,
262};
263
264static void __init eukrea_cpuimx51sd_init(void)
265{
Shawn Guob78d8e52011-06-06 00:07:55 +0800266 imx51_soc_init();
267
Eric Bénard70b17262010-10-12 16:12:36 +0200268 mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx51sd_pads,
269 ARRAY_SIZE(eukrea_cpuimx51sd_pads));
270
Eric Bénardb13721462011-02-25 14:38:27 +0100271#if defined(CONFIG_CPU_FREQ_IMX)
272 get_cpu_op = mx51_get_cpu_op;
273#endif
274
Eric Bénard70b17262010-10-12 16:12:36 +0200275 imx51_add_imx_uart(0, &uart_pdata);
276 imx51_add_mxc_nand(&eukrea_cpuimx51sd_nand_board_info);
277
278 gpio_request(ETH_RST, "eth_rst");
279 gpio_set_value(ETH_RST, 1);
280 imx51_add_fec(NULL);
281
282 gpio_request(CAN_IRQGPIO, "can_irq");
283 gpio_direction_input(CAN_IRQGPIO);
284 gpio_free(CAN_IRQGPIO);
285 gpio_request(CAN_NCS, "can_ncs");
286 gpio_direction_output(CAN_NCS, 1);
287 gpio_free(CAN_NCS);
288 gpio_request(CAN_RST, "can_rst");
289 gpio_direction_output(CAN_RST, 0);
290 msleep(20);
291 gpio_set_value(CAN_RST, 1);
292 imx51_add_ecspi(0, &cpuimx51sd_ecspi1_pdata);
293 spi_register_board_info(cpuimx51sd_spi_device,
294 ARRAY_SIZE(cpuimx51sd_spi_device));
295
296 gpio_request(TSC2007_IRQGPIO, "tsc2007_irq");
297 gpio_direction_input(TSC2007_IRQGPIO);
298 gpio_free(TSC2007_IRQGPIO);
299
300 i2c_register_board_info(0, eukrea_cpuimx51sd_i2c_devices,
301 ARRAY_SIZE(eukrea_cpuimx51sd_i2c_devices));
302 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
303
304 if (otg_mode_host)
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200305 imx51_add_mxc_ehci_otg(&dr_utmi_config);
Eric Bénard70b17262010-10-12 16:12:36 +0200306 else {
307 initialize_otg_port(NULL);
Uwe Kleine-König6cafe482011-07-30 23:57:25 +0200308 imx51_add_fsl_usb2_udc(&usb_pdata);
Eric Bénard70b17262010-10-12 16:12:36 +0200309 }
310
311 gpio_request(USBH1_RST, "usb_rst");
312 gpio_direction_output(USBH1_RST, 0);
313 msleep(20);
314 gpio_set_value(USBH1_RST, 1);
Uwe Kleine-König7d92e8e2011-07-30 23:41:49 +0200315 imx51_add_mxc_ehci_hs(1, &usbh1_config);
Eric Bénard70b17262010-10-12 16:12:36 +0200316
317#ifdef CONFIG_MACH_EUKREA_MBIMXSD51_BASEBOARD
318 eukrea_mbimxsd51_baseboard_init();
319#endif
320}
321
322static void __init eukrea_cpuimx51sd_timer_init(void)
323{
324 mx51_clocks_init(32768, 24000000, 22579200, 0);
325}
326
327static struct sys_timer mxc_timer = {
328 .init = eukrea_cpuimx51sd_timer_init,
329};
330
331MACHINE_START(EUKREA_CPUIMX51SD, "Eukrea CPUIMX51SD")
332 /* Maintainer: Eric Bénard <eric@eukrea.com> */
Sascha Hauer7608d7d2010-11-04 21:20:43 +0100333 .boot_params = MX51_PHYS_OFFSET + 0x100,
Eric Bénard70b17262010-10-12 16:12:36 +0200334 .map_io = mx51_map_io,
Uwe Kleine-Königab1304212011-02-07 16:35:21 +0100335 .init_early = imx51_init_early,
Eric Bénard70b17262010-10-12 16:12:36 +0200336 .init_irq = mx51_init_irq,
Eric Bénard70b17262010-10-12 16:12:36 +0200337 .timer = &mxc_timer,
Uwe Kleine-Königab1304212011-02-07 16:35:21 +0100338 .init_machine = eukrea_cpuimx51sd_init,
Eric Bénard70b17262010-10-12 16:12:36 +0200339MACHINE_END