board-mx51_babbage.c 7.6 KB

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