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 | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 15 | #include <linux/gpio.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/io.h> |
Dinh Nguyen | 2ba5a2c | 2010-05-10 13:45:59 -0500 | [diff] [blame] | 18 | #include <linux/fsl_devices.h> |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 19 | |
| 20 | #include <mach/common.h> |
| 21 | #include <mach/hardware.h> |
| 22 | #include <mach/imx-uart.h> |
| 23 | #include <mach/iomux-mx51.h> |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 24 | #include <mach/mxc_ehci.h> |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 25 | |
| 26 | #include <asm/irq.h> |
| 27 | #include <asm/setup.h> |
| 28 | #include <asm/mach-types.h> |
| 29 | #include <asm/mach/arch.h> |
| 30 | #include <asm/mach/time.h> |
| 31 | |
| 32 | #include "devices.h" |
| 33 | |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 34 | #define BABBAGE_USB_HUB_RESET (0*32 + 7) /* GPIO_1_7 */ |
| 35 | #define BABBAGE_USBH1_STP (0*32 + 27) /* GPIO_1_27 */ |
Dinh Nguyen | d6b273b | 2010-05-17 10:46:01 -0500 | [diff] [blame^] | 36 | #define BABBAGE_PHY_RESET (1*32 +5) /* GPIO_2_5 */ |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 37 | |
| 38 | /* USB_CTRL_1 */ |
| 39 | #define MX51_USB_CTRL_1_OFFSET 0x10 |
| 40 | #define MX51_USB_CTRL_UH1_EXT_CLK_EN (1 << 25) |
| 41 | |
| 42 | #define MX51_USB_PLLDIV_12_MHZ 0x00 |
| 43 | #define MX51_USB_PLL_DIV_19_2_MHZ 0x01 |
| 44 | #define MX51_USB_PLL_DIV_24_MHZ 0x02 |
| 45 | |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 46 | static struct platform_device *devices[] __initdata = { |
| 47 | &mxc_fec_device, |
| 48 | }; |
| 49 | |
| 50 | static struct pad_desc mx51babbage_pads[] = { |
| 51 | /* UART1 */ |
| 52 | MX51_PAD_UART1_RXD__UART1_RXD, |
| 53 | MX51_PAD_UART1_TXD__UART1_TXD, |
| 54 | MX51_PAD_UART1_RTS__UART1_RTS, |
| 55 | MX51_PAD_UART1_CTS__UART1_CTS, |
| 56 | |
| 57 | /* UART2 */ |
| 58 | MX51_PAD_UART2_RXD__UART2_RXD, |
| 59 | MX51_PAD_UART2_TXD__UART2_TXD, |
| 60 | |
| 61 | /* UART3 */ |
| 62 | MX51_PAD_EIM_D25__UART3_RXD, |
| 63 | MX51_PAD_EIM_D26__UART3_TXD, |
| 64 | MX51_PAD_EIM_D27__UART3_RTS, |
| 65 | MX51_PAD_EIM_D24__UART3_CTS, |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 66 | |
| 67 | /* USB HOST1 */ |
| 68 | MX51_PAD_USBH1_CLK__USBH1_CLK, |
| 69 | MX51_PAD_USBH1_DIR__USBH1_DIR, |
| 70 | MX51_PAD_USBH1_NXT__USBH1_NXT, |
| 71 | MX51_PAD_USBH1_DATA0__USBH1_DATA0, |
| 72 | MX51_PAD_USBH1_DATA1__USBH1_DATA1, |
| 73 | MX51_PAD_USBH1_DATA2__USBH1_DATA2, |
| 74 | MX51_PAD_USBH1_DATA3__USBH1_DATA3, |
| 75 | MX51_PAD_USBH1_DATA4__USBH1_DATA4, |
| 76 | MX51_PAD_USBH1_DATA5__USBH1_DATA5, |
| 77 | MX51_PAD_USBH1_DATA6__USBH1_DATA6, |
| 78 | MX51_PAD_USBH1_DATA7__USBH1_DATA7, |
| 79 | |
| 80 | /* USB HUB reset line*/ |
| 81 | MX51_PAD_GPIO_1_7__GPIO1_7, |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | /* Serial ports */ |
| 85 | #if defined(CONFIG_SERIAL_IMX) || defined(CONFIG_SERIAL_IMX_MODULE) |
| 86 | static struct imxuart_platform_data uart_pdata = { |
| 87 | .flags = IMXUART_HAVE_RTSCTS, |
| 88 | }; |
| 89 | |
| 90 | static inline void mxc_init_imx_uart(void) |
| 91 | { |
| 92 | mxc_register_device(&mxc_uart_device0, &uart_pdata); |
| 93 | mxc_register_device(&mxc_uart_device1, &uart_pdata); |
| 94 | mxc_register_device(&mxc_uart_device2, &uart_pdata); |
| 95 | } |
| 96 | #else /* !SERIAL_IMX */ |
| 97 | static inline void mxc_init_imx_uart(void) |
| 98 | { |
| 99 | } |
| 100 | #endif /* SERIAL_IMX */ |
| 101 | |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 102 | static int gpio_usbh1_active(void) |
| 103 | { |
| 104 | struct pad_desc usbh1stp_gpio = MX51_PAD_USBH1_STP__GPIO_1_27; |
Dinh Nguyen | d6b273b | 2010-05-17 10:46:01 -0500 | [diff] [blame^] | 105 | struct pad_desc phyreset_gpio = MX51_PAD_EIM_D21__GPIO_2_5; |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 106 | int ret; |
| 107 | |
| 108 | /* Set USBH1_STP to GPIO and toggle it */ |
| 109 | mxc_iomux_v3_setup_pad(&usbh1stp_gpio); |
| 110 | ret = gpio_request(BABBAGE_USBH1_STP, "usbh1_stp"); |
| 111 | |
| 112 | if (ret) { |
| 113 | pr_debug("failed to get MX51_PAD_USBH1_STP__GPIO_1_27: %d\n", ret); |
| 114 | return ret; |
| 115 | } |
| 116 | gpio_direction_output(BABBAGE_USBH1_STP, 0); |
| 117 | gpio_set_value(BABBAGE_USBH1_STP, 1); |
| 118 | msleep(100); |
| 119 | gpio_free(BABBAGE_USBH1_STP); |
Dinh Nguyen | d6b273b | 2010-05-17 10:46:01 -0500 | [diff] [blame^] | 120 | |
| 121 | /* De-assert USB PHY RESETB */ |
| 122 | mxc_iomux_v3_setup_pad(&phyreset_gpio); |
| 123 | ret = gpio_request(BABBAGE_PHY_RESET, "phy_reset"); |
| 124 | |
| 125 | if (ret) { |
| 126 | pr_debug("failed to get MX51_PAD_EIM_D21__GPIO_2_5: %d\n", ret); |
| 127 | return ret; |
| 128 | } |
| 129 | gpio_direction_output(BABBAGE_PHY_RESET, 1); |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | static inline void babbage_usbhub_reset(void) |
| 134 | { |
| 135 | int ret; |
| 136 | |
| 137 | /* Bring USB hub out of reset */ |
| 138 | ret = gpio_request(BABBAGE_USB_HUB_RESET, "GPIO1_7"); |
| 139 | if (ret) { |
| 140 | printk(KERN_ERR"failed to get GPIO_USB_HUB_RESET: %d\n", ret); |
| 141 | return; |
| 142 | } |
| 143 | gpio_direction_output(BABBAGE_USB_HUB_RESET, 0); |
| 144 | |
| 145 | /* USB HUB RESET - De-assert USB HUB RESET_N */ |
| 146 | msleep(1); |
| 147 | gpio_set_value(BABBAGE_USB_HUB_RESET, 0); |
| 148 | msleep(1); |
| 149 | gpio_set_value(BABBAGE_USB_HUB_RESET, 1); |
| 150 | } |
| 151 | |
| 152 | /* This function is board specific as the bit mask for the plldiv will also |
| 153 | be different for other Freescale SoCs, thus a common bitmask is not |
| 154 | possible and cannot get place in /plat-mxc/ehci.c.*/ |
| 155 | static int initialize_otg_port(struct platform_device *pdev) |
| 156 | { |
| 157 | u32 v; |
| 158 | void __iomem *usb_base; |
| 159 | u32 usbother_base; |
| 160 | |
| 161 | usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K); |
| 162 | usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET; |
| 163 | |
| 164 | /* Set the PHY clock to 19.2MHz */ |
| 165 | v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET); |
| 166 | v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK; |
| 167 | v |= MX51_USB_PLL_DIV_19_2_MHZ; |
| 168 | __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET); |
| 169 | iounmap(usb_base); |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static int initialize_usbh1_port(struct platform_device *pdev) |
| 174 | { |
| 175 | u32 v; |
| 176 | void __iomem *usb_base; |
| 177 | u32 usbother_base; |
| 178 | |
| 179 | usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K); |
| 180 | usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET; |
| 181 | |
| 182 | /* The clock for the USBH1 ULPI port will come externally from the PHY. */ |
| 183 | v = __raw_readl(usbother_base + MX51_USB_CTRL_1_OFFSET); |
| 184 | __raw_writel(v | MX51_USB_CTRL_UH1_EXT_CLK_EN, usbother_base + MX51_USB_CTRL_1_OFFSET); |
| 185 | iounmap(usb_base); |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | static struct mxc_usbh_platform_data dr_utmi_config = { |
| 190 | .init = initialize_otg_port, |
| 191 | .portsc = MXC_EHCI_UTMI_16BIT, |
| 192 | .flags = MXC_EHCI_INTERNAL_PHY, |
| 193 | }; |
| 194 | |
Dinh Nguyen | 2ba5a2c | 2010-05-10 13:45:59 -0500 | [diff] [blame] | 195 | static struct fsl_usb2_platform_data usb_pdata = { |
| 196 | .operating_mode = FSL_USB2_DR_DEVICE, |
| 197 | .phy_mode = FSL_USB2_PHY_UTMI_WIDE, |
| 198 | }; |
| 199 | |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 200 | static struct mxc_usbh_platform_data usbh1_config = { |
| 201 | .init = initialize_usbh1_port, |
| 202 | .portsc = MXC_EHCI_MODE_ULPI, |
| 203 | .flags = (MXC_EHCI_POWER_PINS_ENABLED | MXC_EHCI_ITC_NO_THRESHOLD), |
| 204 | }; |
| 205 | |
Dinh Nguyen | 2ba5a2c | 2010-05-10 13:45:59 -0500 | [diff] [blame] | 206 | static int otg_mode_host; |
| 207 | |
| 208 | static int __init babbage_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=", babbage_otg_mode); |
| 220 | |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 221 | /* |
| 222 | * Board specific initialization. |
| 223 | */ |
| 224 | static void __init mxc_board_init(void) |
| 225 | { |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 226 | struct pad_desc usbh1stp = MX51_PAD_USBH1_STP__USBH1_STP; |
| 227 | |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 228 | mxc_iomux_v3_setup_multiple_pads(mx51babbage_pads, |
| 229 | ARRAY_SIZE(mx51babbage_pads)); |
| 230 | mxc_init_imx_uart(); |
| 231 | platform_add_devices(devices, ARRAY_SIZE(devices)); |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 232 | |
Dinh Nguyen | 2ba5a2c | 2010-05-10 13:45:59 -0500 | [diff] [blame] | 233 | if (otg_mode_host) |
| 234 | mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config); |
| 235 | else { |
| 236 | initialize_otg_port(NULL); |
| 237 | mxc_register_device(&mxc_usbdr_udc_device, &usb_pdata); |
| 238 | } |
Dinh Nguyen | 231637f | 2010-04-30 15:48:25 -0500 | [diff] [blame] | 239 | |
| 240 | gpio_usbh1_active(); |
| 241 | mxc_register_device(&mxc_usbh1_device, &usbh1_config); |
| 242 | /* setback USBH1_STP to be function */ |
| 243 | mxc_iomux_v3_setup_pad(&usbh1stp); |
| 244 | babbage_usbhub_reset(); |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | static void __init mx51_babbage_timer_init(void) |
| 248 | { |
Fabio Estevam | 82d52a1 | 2010-02-17 12:02:56 -0800 | [diff] [blame] | 249 | mx51_clocks_init(32768, 24000000, 22579200, 0); |
Amit Kucheria | b996b58 | 2010-02-02 11:57:53 -0800 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | static struct sys_timer mxc_timer = { |
| 253 | .init = mx51_babbage_timer_init, |
| 254 | }; |
| 255 | |
| 256 | MACHINE_START(MX51_BABBAGE, "Freescale MX51 Babbage Board") |
| 257 | /* Maintainer: Amit Kucheria <amit.kucheria@canonical.com> */ |
| 258 | .phys_io = MX51_AIPS1_BASE_ADDR, |
| 259 | .io_pg_offst = ((MX51_AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc, |
| 260 | .boot_params = PHYS_OFFSET + 0x100, |
| 261 | .map_io = mx51_map_io, |
| 262 | .init_irq = mx51_init_irq, |
| 263 | .init_machine = mxc_board_init, |
| 264 | .timer = &mxc_timer, |
| 265 | MACHINE_END |