Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved. |
| 3 | * Copyright (C) 2009-2010 Amit Kucheria <amit.kucheria@canonical.com> |
| 4 | * |
| 5 | * The code contained herein is licensed under the GNU General Public |
| 6 | * License. You may obtain a copy of the GNU General Public License |
| 7 | * Version 2 or later at the following locations: |
| 8 | * |
| 9 | * http://www.opensource.org/licenses/gpl-license.html |
| 10 | * http://www.gnu.org/copyleft/gpl.html |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/platform_device.h> |
Dinh Nguyen | f00b771 | 2010-05-27 10:45:05 -0500 | [diff] [blame] | 15 | #include <linux/i2c.h> |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 16 | #include <linux/gpio.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/io.h> |
Dinh Nguyen | 2ba5a2c | 2010-05-10 13:45:59 -0500 | [diff] [blame] | 19 | #include <linux/fsl_devices.h> |
Fabio Estevam | 3efee47 | 2010-08-23 07:32:09 -0700 | [diff] [blame] | 20 | #include <linux/fec.h> |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 21 | |
| 22 | #include <mach/common.h> |
| 23 | #include <mach/hardware.h> |
| 24 | #include <mach/imx-uart.h> |
| 25 | #include <mach/iomux-mx51.h> |
Dinh Nguyen | f00b771 | 2010-05-27 10:45:05 -0500 | [diff] [blame] | 26 | #include <mach/i2c.h> |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 27 | #include <mach/mxc_ehci.h> |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 28 | |
| 29 | #include <asm/irq.h> |
| 30 | #include <asm/setup.h> |
| 31 | #include <asm/mach-types.h> |
| 32 | #include <asm/mach/arch.h> |
| 33 | #include <asm/mach/time.h> |
| 34 | |
| 35 | #include "devices.h" |
| 36 | |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 37 | #define BABBAGE_USB_HUB_RESET (0*32 + 7) /* GPIO_1_7 */ |
| 38 | #define BABBAGE_USBH1_STP (0*32 + 27) /* GPIO_1_27 */ |
Fabio Estevam | 3efee47 | 2010-08-23 07:32:09 -0700 | [diff] [blame] | 39 | #define BABBAGE_PHY_RESET (1*32 + 5) /* GPIO_2_5 */ |
| 40 | #define BABBAGE_FEC_PHY_RESET (1*32 + 14) /* GPIO_2_14 */ |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 41 | |
| 42 | /* USB_CTRL_1 */ |
| 43 | #define MX51_USB_CTRL_1_OFFSET 0x10 |
| 44 | #define MX51_USB_CTRL_UH1_EXT_CLK_EN (1 << 25) |
| 45 | |
| 46 | #define MX51_USB_PLLDIV_12_MHZ 0x00 |
| 47 | #define MX51_USB_PLL_DIV_19_2_MHZ 0x01 |
| 48 | #define MX51_USB_PLL_DIV_24_MHZ 0x02 |
| 49 | |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 50 | static struct platform_device *devices[] __initdata = { |
| 51 | &mxc_fec_device, |
| 52 | }; |
| 53 | |
| 54 | static struct pad_desc mx51babbage_pads[] = { |
| 55 | /* UART1 */ |
| 56 | MX51_PAD_UART1_RXD__UART1_RXD, |
| 57 | MX51_PAD_UART1_TXD__UART1_TXD, |
| 58 | MX51_PAD_UART1_RTS__UART1_RTS, |
| 59 | MX51_PAD_UART1_CTS__UART1_CTS, |
| 60 | |
| 61 | /* UART2 */ |
| 62 | MX51_PAD_UART2_RXD__UART2_RXD, |
| 63 | MX51_PAD_UART2_TXD__UART2_TXD, |
| 64 | |
| 65 | /* UART3 */ |
| 66 | MX51_PAD_EIM_D25__UART3_RXD, |
| 67 | MX51_PAD_EIM_D26__UART3_TXD, |
| 68 | MX51_PAD_EIM_D27__UART3_RTS, |
| 69 | MX51_PAD_EIM_D24__UART3_CTS, |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 70 | |
Dinh Nguyen | f00b771 | 2010-05-27 10:45:05 -0500 | [diff] [blame] | 71 | /* I2C1 */ |
| 72 | MX51_PAD_EIM_D16__I2C1_SDA, |
| 73 | MX51_PAD_EIM_D19__I2C1_SCL, |
| 74 | |
| 75 | /* I2C2 */ |
| 76 | MX51_PAD_KEY_COL4__I2C2_SCL, |
| 77 | MX51_PAD_KEY_COL5__I2C2_SDA, |
| 78 | |
| 79 | /* HSI2C */ |
| 80 | MX51_PAD_I2C1_CLK__HSI2C_CLK, |
| 81 | MX51_PAD_I2C1_DAT__HSI2C_DAT, |
| 82 | |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 83 | /* USB HOST1 */ |
| 84 | MX51_PAD_USBH1_CLK__USBH1_CLK, |
| 85 | MX51_PAD_USBH1_DIR__USBH1_DIR, |
| 86 | MX51_PAD_USBH1_NXT__USBH1_NXT, |
| 87 | MX51_PAD_USBH1_DATA0__USBH1_DATA0, |
| 88 | MX51_PAD_USBH1_DATA1__USBH1_DATA1, |
| 89 | MX51_PAD_USBH1_DATA2__USBH1_DATA2, |
| 90 | MX51_PAD_USBH1_DATA3__USBH1_DATA3, |
| 91 | MX51_PAD_USBH1_DATA4__USBH1_DATA4, |
| 92 | MX51_PAD_USBH1_DATA5__USBH1_DATA5, |
| 93 | MX51_PAD_USBH1_DATA6__USBH1_DATA6, |
| 94 | MX51_PAD_USBH1_DATA7__USBH1_DATA7, |
| 95 | |
| 96 | /* USB HUB reset line*/ |
Amit Kucheria | 68d03da | 2010-06-16 14:00:15 +0300 | [diff] [blame] | 97 | MX51_PAD_GPIO_1_7__GPIO_1_7, |
Fabio Estevam | 3efee47 | 2010-08-23 07:32:09 -0700 | [diff] [blame] | 98 | |
| 99 | /* FEC */ |
| 100 | MX51_PAD_EIM_EB2__FEC_MDIO, |
| 101 | MX51_PAD_EIM_EB3__FEC_RDAT1, |
| 102 | MX51_PAD_EIM_CS2__FEC_RDAT2, |
| 103 | MX51_PAD_EIM_CS3__FEC_RDAT3, |
| 104 | MX51_PAD_EIM_CS4__FEC_RX_ER, |
| 105 | MX51_PAD_EIM_CS5__FEC_CRS, |
| 106 | MX51_PAD_NANDF_RB2__FEC_COL, |
| 107 | MX51_PAD_NANDF_RB3__FEC_RXCLK, |
| 108 | MX51_PAD_NANDF_RB6__FEC_RDAT0, |
| 109 | MX51_PAD_NANDF_RB7__FEC_TDAT0, |
| 110 | MX51_PAD_NANDF_CS2__FEC_TX_ER, |
| 111 | MX51_PAD_NANDF_CS3__FEC_MDC, |
| 112 | MX51_PAD_NANDF_CS4__FEC_TDAT1, |
| 113 | MX51_PAD_NANDF_CS5__FEC_TDAT2, |
| 114 | MX51_PAD_NANDF_CS6__FEC_TDAT3, |
| 115 | MX51_PAD_NANDF_CS7__FEC_TX_EN, |
| 116 | MX51_PAD_NANDF_RDY_INT__FEC_TX_CLK, |
| 117 | |
| 118 | /* FEC PHY reset line */ |
| 119 | MX51_PAD_EIM_A20__GPIO_2_14, |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | /* Serial ports */ |
| 123 | #if defined(CONFIG_SERIAL_IMX) || defined(CONFIG_SERIAL_IMX_MODULE) |
| 124 | static struct imxuart_platform_data uart_pdata = { |
| 125 | .flags = IMXUART_HAVE_RTSCTS, |
| 126 | }; |
| 127 | |
| 128 | static inline void mxc_init_imx_uart(void) |
| 129 | { |
| 130 | mxc_register_device(&mxc_uart_device0, &uart_pdata); |
| 131 | mxc_register_device(&mxc_uart_device1, &uart_pdata); |
| 132 | mxc_register_device(&mxc_uart_device2, &uart_pdata); |
| 133 | } |
| 134 | #else /* !SERIAL_IMX */ |
| 135 | static inline void mxc_init_imx_uart(void) |
| 136 | { |
| 137 | } |
| 138 | #endif /* SERIAL_IMX */ |
| 139 | |
Dinh Nguyen | f00b771 | 2010-05-27 10:45:05 -0500 | [diff] [blame] | 140 | static struct imxi2c_platform_data babbage_i2c_data = { |
| 141 | .bitrate = 100000, |
| 142 | }; |
| 143 | |
| 144 | static struct imxi2c_platform_data babbage_hsi2c_data = { |
| 145 | .bitrate = 400000, |
| 146 | }; |
| 147 | |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 148 | static int gpio_usbh1_active(void) |
| 149 | { |
| 150 | struct pad_desc usbh1stp_gpio = MX51_PAD_USBH1_STP__GPIO_1_27; |
Dinh Nguyen | d6b273b | 2010-05-17 10:46:01 -0500 | [diff] [blame] | 151 | struct pad_desc phyreset_gpio = MX51_PAD_EIM_D21__GPIO_2_5; |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 152 | int ret; |
| 153 | |
| 154 | /* Set USBH1_STP to GPIO and toggle it */ |
| 155 | mxc_iomux_v3_setup_pad(&usbh1stp_gpio); |
| 156 | ret = gpio_request(BABBAGE_USBH1_STP, "usbh1_stp"); |
| 157 | |
| 158 | if (ret) { |
| 159 | pr_debug("failed to get MX51_PAD_USBH1_STP__GPIO_1_27: %d\n", ret); |
| 160 | return ret; |
| 161 | } |
| 162 | gpio_direction_output(BABBAGE_USBH1_STP, 0); |
| 163 | gpio_set_value(BABBAGE_USBH1_STP, 1); |
| 164 | msleep(100); |
| 165 | gpio_free(BABBAGE_USBH1_STP); |
Dinh Nguyen | d6b273b | 2010-05-17 10:46:01 -0500 | [diff] [blame] | 166 | |
| 167 | /* De-assert USB PHY RESETB */ |
| 168 | mxc_iomux_v3_setup_pad(&phyreset_gpio); |
| 169 | ret = gpio_request(BABBAGE_PHY_RESET, "phy_reset"); |
| 170 | |
| 171 | if (ret) { |
| 172 | pr_debug("failed to get MX51_PAD_EIM_D21__GPIO_2_5: %d\n", ret); |
| 173 | return ret; |
| 174 | } |
| 175 | gpio_direction_output(BABBAGE_PHY_RESET, 1); |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | static inline void babbage_usbhub_reset(void) |
| 180 | { |
| 181 | int ret; |
| 182 | |
| 183 | /* Bring USB hub out of reset */ |
| 184 | ret = gpio_request(BABBAGE_USB_HUB_RESET, "GPIO1_7"); |
| 185 | if (ret) { |
| 186 | printk(KERN_ERR"failed to get GPIO_USB_HUB_RESET: %d\n", ret); |
| 187 | return; |
| 188 | } |
| 189 | gpio_direction_output(BABBAGE_USB_HUB_RESET, 0); |
| 190 | |
| 191 | /* USB HUB RESET - De-assert USB HUB RESET_N */ |
| 192 | msleep(1); |
| 193 | gpio_set_value(BABBAGE_USB_HUB_RESET, 0); |
| 194 | msleep(1); |
| 195 | gpio_set_value(BABBAGE_USB_HUB_RESET, 1); |
| 196 | } |
| 197 | |
Fabio Estevam | 3efee47 | 2010-08-23 07:32:09 -0700 | [diff] [blame] | 198 | static inline void babbage_fec_reset(void) |
| 199 | { |
| 200 | int ret; |
| 201 | |
| 202 | /* reset FEC PHY */ |
| 203 | ret = gpio_request(BABBAGE_FEC_PHY_RESET, "fec-phy-reset"); |
| 204 | if (ret) { |
| 205 | printk(KERN_ERR"failed to get GPIO_FEC_PHY_RESET: %d\n", ret); |
| 206 | return; |
| 207 | } |
| 208 | gpio_direction_output(BABBAGE_FEC_PHY_RESET, 0); |
| 209 | gpio_set_value(BABBAGE_FEC_PHY_RESET, 0); |
| 210 | msleep(1); |
| 211 | gpio_set_value(BABBAGE_FEC_PHY_RESET, 1); |
| 212 | } |
| 213 | |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 214 | /* This function is board specific as the bit mask for the plldiv will also |
| 215 | be different for other Freescale SoCs, thus a common bitmask is not |
| 216 | possible and cannot get place in /plat-mxc/ehci.c.*/ |
| 217 | static int initialize_otg_port(struct platform_device *pdev) |
| 218 | { |
| 219 | u32 v; |
| 220 | void __iomem *usb_base; |
Sascha Hauer | e7a895b | 2010-08-19 11:37:31 +0200 | [diff] [blame] | 221 | void __iomem *usbother_base; |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 222 | |
| 223 | usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K); |
| 224 | usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET; |
| 225 | |
| 226 | /* Set the PHY clock to 19.2MHz */ |
| 227 | v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET); |
| 228 | v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK; |
| 229 | v |= MX51_USB_PLL_DIV_19_2_MHZ; |
| 230 | __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET); |
| 231 | iounmap(usb_base); |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static int initialize_usbh1_port(struct platform_device *pdev) |
| 236 | { |
| 237 | u32 v; |
| 238 | void __iomem *usb_base; |
Sascha Hauer | e7a895b | 2010-08-19 11:37:31 +0200 | [diff] [blame] | 239 | void __iomem *usbother_base; |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 240 | |
| 241 | usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K); |
| 242 | usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET; |
| 243 | |
| 244 | /* The clock for the USBH1 ULPI port will come externally from the PHY. */ |
| 245 | v = __raw_readl(usbother_base + MX51_USB_CTRL_1_OFFSET); |
| 246 | __raw_writel(v | MX51_USB_CTRL_UH1_EXT_CLK_EN, usbother_base + MX51_USB_CTRL_1_OFFSET); |
| 247 | iounmap(usb_base); |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | static struct mxc_usbh_platform_data dr_utmi_config = { |
| 252 | .init = initialize_otg_port, |
| 253 | .portsc = MXC_EHCI_UTMI_16BIT, |
| 254 | .flags = MXC_EHCI_INTERNAL_PHY, |
| 255 | }; |
| 256 | |
Dinh Nguyen | 2ba5a2c | 2010-05-10 13:45:59 -0500 | [diff] [blame] | 257 | static struct fsl_usb2_platform_data usb_pdata = { |
| 258 | .operating_mode = FSL_USB2_DR_DEVICE, |
| 259 | .phy_mode = FSL_USB2_PHY_UTMI_WIDE, |
| 260 | }; |
| 261 | |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 262 | static struct mxc_usbh_platform_data usbh1_config = { |
| 263 | .init = initialize_usbh1_port, |
| 264 | .portsc = MXC_EHCI_MODE_ULPI, |
| 265 | .flags = (MXC_EHCI_POWER_PINS_ENABLED | MXC_EHCI_ITC_NO_THRESHOLD), |
| 266 | }; |
| 267 | |
Dinh Nguyen | 2ba5a2c | 2010-05-10 13:45:59 -0500 | [diff] [blame] | 268 | static int otg_mode_host; |
| 269 | |
| 270 | static int __init babbage_otg_mode(char *options) |
| 271 | { |
| 272 | if (!strcmp(options, "host")) |
| 273 | otg_mode_host = 1; |
| 274 | else if (!strcmp(options, "device")) |
| 275 | otg_mode_host = 0; |
| 276 | else |
| 277 | pr_info("otg_mode neither \"host\" nor \"device\". " |
| 278 | "Defaulting to device\n"); |
| 279 | return 0; |
| 280 | } |
| 281 | __setup("otg_mode=", babbage_otg_mode); |
| 282 | |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 283 | /* |
| 284 | * Board specific initialization. |
| 285 | */ |
| 286 | static void __init mxc_board_init(void) |
| 287 | { |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 288 | struct pad_desc usbh1stp = MX51_PAD_USBH1_STP__USBH1_STP; |
| 289 | |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 290 | mxc_iomux_v3_setup_multiple_pads(mx51babbage_pads, |
| 291 | ARRAY_SIZE(mx51babbage_pads)); |
| 292 | mxc_init_imx_uart(); |
Fabio Estevam | 3efee47 | 2010-08-23 07:32:09 -0700 | [diff] [blame] | 293 | babbage_fec_reset(); |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 294 | platform_add_devices(devices, ARRAY_SIZE(devices)); |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 295 | |
Dinh Nguyen | f00b771 | 2010-05-27 10:45:05 -0500 | [diff] [blame] | 296 | mxc_register_device(&mxc_i2c_device0, &babbage_i2c_data); |
| 297 | mxc_register_device(&mxc_i2c_device1, &babbage_i2c_data); |
| 298 | mxc_register_device(&mxc_hsi2c_device, &babbage_hsi2c_data); |
| 299 | |
Dinh Nguyen | 2ba5a2c | 2010-05-10 13:45:59 -0500 | [diff] [blame] | 300 | if (otg_mode_host) |
| 301 | mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config); |
| 302 | else { |
| 303 | initialize_otg_port(NULL); |
| 304 | mxc_register_device(&mxc_usbdr_udc_device, &usb_pdata); |
| 305 | } |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 306 | |
| 307 | gpio_usbh1_active(); |
| 308 | mxc_register_device(&mxc_usbh1_device, &usbh1_config); |
| 309 | /* setback USBH1_STP to be function */ |
| 310 | mxc_iomux_v3_setup_pad(&usbh1stp); |
| 311 | babbage_usbhub_reset(); |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static void __init mx51_babbage_timer_init(void) |
| 315 | { |
Fabio Estevam | 82d52a1 | 2010-02-17 12:02:56 -0800 | [diff] [blame] | 316 | mx51_clocks_init(32768, 24000000, 22579200, 0); |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static struct sys_timer mxc_timer = { |
| 320 | .init = mx51_babbage_timer_init, |
| 321 | }; |
| 322 | |
| 323 | MACHINE_START(MX51_BABBAGE, "Freescale MX51 Babbage Board") |
| 324 | /* Maintainer: Amit Kucheria <amit.kucheria@canonical.com> */ |
| 325 | .phys_io = MX51_AIPS1_BASE_ADDR, |
| 326 | .io_pg_offst = ((MX51_AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc, |
Uwe Kleine-König | e16ddb3 | 2010-08-24 12:33:23 +0200 | [diff] [blame^] | 327 | .boot_params = MX51_PHYS_OFFSET + 0x100, |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 328 | .map_io = mx51_map_io, |
| 329 | .init_irq = mx51_init_irq, |
| 330 | .init_machine = mxc_board_init, |
| 331 | .timer = &mxc_timer, |
| 332 | MACHINE_END |