board-mx51_babbage.c 7.0 KB

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