Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 1 | /* |
| 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énard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 26 | |
| 27 | #include <mach/eukrea-baseboards.h> |
| 28 | #include <mach/common.h> |
| 29 | #include <mach/hardware.h> |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 30 | #include <mach/iomux-mx51.h> |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 31 | |
| 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önig | 04b73b1 | 2010-08-11 22:23:06 +0200 | [diff] [blame] | 38 | #include "devices-imx51.h" |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 39 | #include "devices.h" |
| 40 | |
Arnaud Patard (Rtp) | 96886c4 | 2010-11-26 15:20:52 +0100 | [diff] [blame] | 41 | #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énard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 46 | #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énard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 57 | static struct plat_serial8250_port serial_platform_data[] = { |
| 58 | { |
| 59 | .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x400000), |
Sascha Hauer | 7cf7381 | 2011-05-11 11:31:54 +0200 | [diff] [blame] | 60 | .irq = gpio_to_irq(CPUIMX51_QUARTA_GPIO), |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 61 | .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 Hauer | 7cf7381 | 2011-05-11 11:31:54 +0200 | [diff] [blame] | 68 | .irq = gpio_to_irq(CPUIMX51_QUARTB_GPIO), |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 69 | .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 Hauer | 7cf7381 | 2011-05-11 11:31:54 +0200 | [diff] [blame] | 76 | .irq = gpio_to_irq(CPUIMX51_QUARTC_GPIO), |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 77 | .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 Hauer | 7cf7381 | 2011-05-11 11:31:54 +0200 | [diff] [blame] | 84 | .irq = irq_to_gpio(CPUIMX51_QUARTD_GPIO), |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 85 | .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 | |
| 94 | static struct platform_device serial_device = { |
| 95 | .name = "serial8250", |
| 96 | .id = 0, |
| 97 | .dev = { |
| 98 | .platform_data = serial_platform_data, |
| 99 | }, |
| 100 | }; |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 101 | |
| 102 | static struct platform_device *devices[] __initdata = { |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 103 | &serial_device, |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 104 | }; |
| 105 | |
Lothar Waßmann | 8f5260c | 2010-10-26 14:28:31 +0200 | [diff] [blame] | 106 | static iomux_v3_cfg_t eukrea_cpuimx51_pads[] = { |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 107 | /* 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 Hauer | ee1ae4d | 2010-12-15 09:56:35 +0100 | [diff] [blame] | 114 | MX51_PAD_GPIO1_2__I2C2_SCL, |
| 115 | MX51_PAD_GPIO1_3__I2C2_SDA, |
| 116 | MX51_PAD_NANDF_D10__GPIO3_30, |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 117 | |
| 118 | /* QUART IRQ */ |
Sascha Hauer | ee1ae4d | 2010-12-15 09:56:35 +0100 | [diff] [blame] | 119 | 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énard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 123 | |
| 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énard | a392741 | 2010-10-12 16:29:20 +0200 | [diff] [blame] | 139 | static 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önig | 04b73b1 | 2010-08-11 22:23:06 +0200 | [diff] [blame] | 146 | static const struct imxuart_platform_data uart_pdata __initconst = { |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 147 | .flags = IMXUART_HAVE_RTSCTS, |
| 148 | }; |
| 149 | |
Uwe Kleine-König | 44505c0 | 2010-09-30 16:44:53 +0200 | [diff] [blame] | 150 | static const |
| 151 | struct imxi2c_platform_data eukrea_cpuimx51_i2c_data __initconst = { |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 152 | .bitrate = 100000, |
| 153 | }; |
| 154 | |
| 155 | static 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 |
| 162 | be different for other Freescale SoCs, thus a common bitmask is not |
| 163 | possible and cannot get place in /plat-mxc/ehci.c.*/ |
| 164 | static int initialize_otg_port(struct platform_device *pdev) |
| 165 | { |
| 166 | u32 v; |
| 167 | void __iomem *usb_base; |
| 168 | void __iomem *usbother_base; |
| 169 | |
| 170 | usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K); |
Fabio Estevam | 28a4f90 | 2010-12-13 10:47:05 -0200 | [diff] [blame] | 171 | if (!usb_base) |
| 172 | return -ENOMEM; |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 173 | 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 Hauer | 4bd597b | 2011-01-03 11:30:28 +0100 | [diff] [blame] | 181 | |
| 182 | mdelay(10); |
| 183 | |
| 184 | return mx51_initialize_usb_hw(0, MXC_EHCI_INTERNAL_PHY); |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | static int initialize_usbh1_port(struct platform_device *pdev) |
| 188 | { |
| 189 | u32 v; |
| 190 | void __iomem *usb_base; |
| 191 | void __iomem *usbother_base; |
| 192 | |
| 193 | usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K); |
Fabio Estevam | 28a4f90 | 2010-12-13 10:47:05 -0200 | [diff] [blame] | 194 | if (!usb_base) |
| 195 | return -ENOMEM; |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 196 | 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 Hauer | 4bd597b | 2011-01-03 11:30:28 +0100 | [diff] [blame] | 202 | |
| 203 | mdelay(10); |
| 204 | |
| 205 | return mx51_initialize_usb_hw(1, MXC_EHCI_POWER_PINS_ENABLED | |
| 206 | MXC_EHCI_ITC_NO_THRESHOLD); |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static struct mxc_usbh_platform_data dr_utmi_config = { |
| 210 | .init = initialize_otg_port, |
| 211 | .portsc = MXC_EHCI_UTMI_16BIT, |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | static struct fsl_usb2_platform_data usb_pdata = { |
| 215 | .operating_mode = FSL_USB2_DR_DEVICE, |
| 216 | .phy_mode = FSL_USB2_PHY_UTMI_WIDE, |
| 217 | }; |
| 218 | |
| 219 | static struct mxc_usbh_platform_data usbh1_config = { |
| 220 | .init = initialize_usbh1_port, |
| 221 | .portsc = MXC_EHCI_MODE_ULPI, |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | static int otg_mode_host; |
| 225 | |
| 226 | static 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 | */ |
| 242 | static void __init eukrea_cpuimx51_init(void) |
| 243 | { |
Shawn Guo | b78d8e5 | 2011-06-06 00:07:55 +0800 | [diff] [blame] | 244 | imx51_soc_init(); |
| 245 | |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 246 | mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx51_pads, |
| 247 | ARRAY_SIZE(eukrea_cpuimx51_pads)); |
| 248 | |
Uwe Kleine-König | 04b73b1 | 2010-08-11 22:23:06 +0200 | [diff] [blame] | 249 | imx51_add_imx_uart(0, &uart_pdata); |
Eric Bénard | a392741 | 2010-10-12 16:29:20 +0200 | [diff] [blame] | 250 | imx51_add_mxc_nand(&eukrea_cpuimx51_nand_board_info); |
| 251 | |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 252 | 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önig | 6bd96f3 | 2010-10-06 12:00:18 +0200 | [diff] [blame] | 265 | imx51_add_fec(NULL); |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 266 | platform_add_devices(devices, ARRAY_SIZE(devices)); |
| 267 | |
Uwe Kleine-König | 44505c0 | 2010-09-30 16:44:53 +0200 | [diff] [blame] | 268 | imx51_add_imx_i2c(1, &eukrea_cpuimx51_i2c_data); |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 269 | i2c_register_board_info(1, eukrea_cpuimx51_i2c_devices, |
| 270 | ARRAY_SIZE(eukrea_cpuimx51_i2c_devices)); |
| 271 | |
| 272 | if (otg_mode_host) |
| 273 | mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config); |
| 274 | else { |
| 275 | initialize_otg_port(NULL); |
| 276 | mxc_register_device(&mxc_usbdr_udc_device, &usb_pdata); |
| 277 | } |
| 278 | mxc_register_device(&mxc_usbh1_device, &usbh1_config); |
| 279 | |
| 280 | #ifdef CONFIG_MACH_EUKREA_MBIMX51_BASEBOARD |
| 281 | eukrea_mbimx51_baseboard_init(); |
| 282 | #endif |
| 283 | } |
| 284 | |
| 285 | static void __init eukrea_cpuimx51_timer_init(void) |
| 286 | { |
| 287 | mx51_clocks_init(32768, 24000000, 22579200, 0); |
| 288 | } |
| 289 | |
| 290 | static struct sys_timer mxc_timer = { |
| 291 | .init = eukrea_cpuimx51_timer_init, |
| 292 | }; |
| 293 | |
| 294 | MACHINE_START(EUKREA_CPUIMX51, "Eukrea CPUIMX51 Module") |
| 295 | /* Maintainer: Eric Bénard <eric@eukrea.com> */ |
Sascha Hauer | 7608d7d | 2010-11-04 21:20:43 +0100 | [diff] [blame] | 296 | .boot_params = MX51_PHYS_OFFSET + 0x100, |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 297 | .map_io = mx51_map_io, |
Uwe Kleine-König | ab13042 | 2011-02-07 16:35:21 +0100 | [diff] [blame] | 298 | .init_early = imx51_init_early, |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 299 | .init_irq = mx51_init_irq, |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 300 | .timer = &mxc_timer, |
Uwe Kleine-König | ab13042 | 2011-02-07 16:35:21 +0100 | [diff] [blame] | 301 | .init_machine = eukrea_cpuimx51_init, |
Eric Bénard | ef93f14 | 2010-07-23 16:11:19 +0200 | [diff] [blame] | 302 | MACHINE_END |