board-cpuimx51.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. #include <linux/init.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/serial_8250.h>
  19. #include <linux/i2c.h>
  20. #include <linux/gpio.h>
  21. #include <linux/delay.h>
  22. #include <linux/io.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/fsl_devices.h>
  26. #include <mach/eukrea-baseboards.h>
  27. #include <mach/common.h>
  28. #include <mach/hardware.h>
  29. #include <mach/imx-uart.h>
  30. #include <mach/iomux-mx51.h>
  31. #include <mach/i2c.h>
  32. #include <mach/mxc_ehci.h>
  33. #include <asm/irq.h>
  34. #include <asm/setup.h>
  35. #include <asm/mach-types.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/mach/time.h>
  38. #include "devices.h"
  39. #define CPUIMX51_USBH1_STP (0*32 + 27)
  40. #define CPUIMX51_QUARTA_GPIO (2*32 + 28)
  41. #define CPUIMX51_QUARTB_GPIO (2*32 + 25)
  42. #define CPUIMX51_QUARTC_GPIO (2*32 + 26)
  43. #define CPUIMX51_QUARTD_GPIO (2*32 + 27)
  44. #define CPUIMX51_QUARTA_IRQ (MXC_INTERNAL_IRQS + CPUIMX51_QUARTA_GPIO)
  45. #define CPUIMX51_QUARTB_IRQ (MXC_INTERNAL_IRQS + CPUIMX51_QUARTB_GPIO)
  46. #define CPUIMX51_QUARTC_IRQ (MXC_INTERNAL_IRQS + CPUIMX51_QUARTC_GPIO)
  47. #define CPUIMX51_QUARTD_IRQ (MXC_INTERNAL_IRQS + CPUIMX51_QUARTD_GPIO)
  48. #define CPUIMX51_QUART_XTAL 14745600
  49. #define CPUIMX51_QUART_REGSHIFT 17
  50. /* USB_CTRL_1 */
  51. #define MX51_USB_CTRL_1_OFFSET 0x10
  52. #define MX51_USB_CTRL_UH1_EXT_CLK_EN (1 << 25)
  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. #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
  57. static struct plat_serial8250_port serial_platform_data[] = {
  58. {
  59. .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x400000),
  60. .irq = CPUIMX51_QUARTA_IRQ,
  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),
  68. .irq = CPUIMX51_QUARTB_IRQ,
  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),
  76. .irq = CPUIMX51_QUARTC_IRQ,
  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),
  84. .irq = CPUIMX51_QUARTD_IRQ,
  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. static struct platform_device serial_device = {
  94. .name = "serial8250",
  95. .id = 0,
  96. .dev = {
  97. .platform_data = serial_platform_data,
  98. },
  99. };
  100. #endif
  101. static struct platform_device *devices[] __initdata = {
  102. &mxc_fec_device,
  103. #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
  104. &serial_device,
  105. #endif
  106. };
  107. static struct pad_desc eukrea_cpuimx51_pads[] = {
  108. /* UART1 */
  109. MX51_PAD_UART1_RXD__UART1_RXD,
  110. MX51_PAD_UART1_TXD__UART1_TXD,
  111. MX51_PAD_UART1_RTS__UART1_RTS,
  112. MX51_PAD_UART1_CTS__UART1_CTS,
  113. /* I2C2 */
  114. MX51_PAD_GPIO_1_2__I2C2_SCL,
  115. MX51_PAD_GPIO_1_3__I2C2_SDA,
  116. MX51_PAD_NANDF_D10__GPIO_3_30,
  117. /* QUART IRQ */
  118. MX51_PAD_NANDF_D15__GPIO_3_25,
  119. MX51_PAD_NANDF_D14__GPIO_3_26,
  120. MX51_PAD_NANDF_D13__GPIO_3_27,
  121. MX51_PAD_NANDF_D12__GPIO_3_28,
  122. /* USB HOST1 */
  123. MX51_PAD_USBH1_CLK__USBH1_CLK,
  124. MX51_PAD_USBH1_DIR__USBH1_DIR,
  125. MX51_PAD_USBH1_NXT__USBH1_NXT,
  126. MX51_PAD_USBH1_DATA0__USBH1_DATA0,
  127. MX51_PAD_USBH1_DATA1__USBH1_DATA1,
  128. MX51_PAD_USBH1_DATA2__USBH1_DATA2,
  129. MX51_PAD_USBH1_DATA3__USBH1_DATA3,
  130. MX51_PAD_USBH1_DATA4__USBH1_DATA4,
  131. MX51_PAD_USBH1_DATA5__USBH1_DATA5,
  132. MX51_PAD_USBH1_DATA6__USBH1_DATA6,
  133. MX51_PAD_USBH1_DATA7__USBH1_DATA7,
  134. MX51_PAD_USBH1_STP__USBH1_STP,
  135. };
  136. static struct imxuart_platform_data uart_pdata = {
  137. .flags = IMXUART_HAVE_RTSCTS,
  138. };
  139. static struct imxi2c_platform_data eukrea_cpuimx51_i2c_data = {
  140. .bitrate = 100000,
  141. };
  142. static struct i2c_board_info eukrea_cpuimx51_i2c_devices[] = {
  143. {
  144. I2C_BOARD_INFO("pcf8563", 0x51),
  145. },
  146. };
  147. /* This function is board specific as the bit mask for the plldiv will also
  148. be different for other Freescale SoCs, thus a common bitmask is not
  149. possible and cannot get place in /plat-mxc/ehci.c.*/
  150. static int initialize_otg_port(struct platform_device *pdev)
  151. {
  152. u32 v;
  153. void __iomem *usb_base;
  154. void __iomem *usbother_base;
  155. usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
  156. usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
  157. /* Set the PHY clock to 19.2MHz */
  158. v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
  159. v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK;
  160. v |= MX51_USB_PLL_DIV_19_2_MHZ;
  161. __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
  162. iounmap(usb_base);
  163. return 0;
  164. }
  165. static int initialize_usbh1_port(struct platform_device *pdev)
  166. {
  167. u32 v;
  168. void __iomem *usb_base;
  169. void __iomem *usbother_base;
  170. usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
  171. usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
  172. /* The clock for the USBH1 ULPI port will come externally from the PHY. */
  173. v = __raw_readl(usbother_base + MX51_USB_CTRL_1_OFFSET);
  174. __raw_writel(v | MX51_USB_CTRL_UH1_EXT_CLK_EN, usbother_base + MX51_USB_CTRL_1_OFFSET);
  175. iounmap(usb_base);
  176. return 0;
  177. }
  178. static struct mxc_usbh_platform_data dr_utmi_config = {
  179. .init = initialize_otg_port,
  180. .portsc = MXC_EHCI_UTMI_16BIT,
  181. .flags = MXC_EHCI_INTERNAL_PHY,
  182. };
  183. static struct fsl_usb2_platform_data usb_pdata = {
  184. .operating_mode = FSL_USB2_DR_DEVICE,
  185. .phy_mode = FSL_USB2_PHY_UTMI_WIDE,
  186. };
  187. static struct mxc_usbh_platform_data usbh1_config = {
  188. .init = initialize_usbh1_port,
  189. .portsc = MXC_EHCI_MODE_ULPI,
  190. .flags = (MXC_EHCI_POWER_PINS_ENABLED | MXC_EHCI_ITC_NO_THRESHOLD),
  191. };
  192. static int otg_mode_host;
  193. static int __init eukrea_cpuimx51_otg_mode(char *options)
  194. {
  195. if (!strcmp(options, "host"))
  196. otg_mode_host = 1;
  197. else if (!strcmp(options, "device"))
  198. otg_mode_host = 0;
  199. else
  200. pr_info("otg_mode neither \"host\" nor \"device\". "
  201. "Defaulting to device\n");
  202. return 0;
  203. }
  204. __setup("otg_mode=", eukrea_cpuimx51_otg_mode);
  205. /*
  206. * Board specific initialization.
  207. */
  208. static void __init eukrea_cpuimx51_init(void)
  209. {
  210. mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx51_pads,
  211. ARRAY_SIZE(eukrea_cpuimx51_pads));
  212. mxc_register_device(&mxc_uart_device0, &uart_pdata);
  213. gpio_request(CPUIMX51_QUARTA_GPIO, "quarta_irq");
  214. gpio_direction_input(CPUIMX51_QUARTA_GPIO);
  215. gpio_free(CPUIMX51_QUARTA_GPIO);
  216. gpio_request(CPUIMX51_QUARTB_GPIO, "quartb_irq");
  217. gpio_direction_input(CPUIMX51_QUARTB_GPIO);
  218. gpio_free(CPUIMX51_QUARTB_GPIO);
  219. gpio_request(CPUIMX51_QUARTC_GPIO, "quartc_irq");
  220. gpio_direction_input(CPUIMX51_QUARTC_GPIO);
  221. gpio_free(CPUIMX51_QUARTC_GPIO);
  222. gpio_request(CPUIMX51_QUARTD_GPIO, "quartd_irq");
  223. gpio_direction_input(CPUIMX51_QUARTD_GPIO);
  224. gpio_free(CPUIMX51_QUARTD_GPIO);
  225. platform_add_devices(devices, ARRAY_SIZE(devices));
  226. mxc_register_device(&mxc_i2c_device1, &eukrea_cpuimx51_i2c_data);
  227. i2c_register_board_info(1, eukrea_cpuimx51_i2c_devices,
  228. ARRAY_SIZE(eukrea_cpuimx51_i2c_devices));
  229. if (otg_mode_host)
  230. mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config);
  231. else {
  232. initialize_otg_port(NULL);
  233. mxc_register_device(&mxc_usbdr_udc_device, &usb_pdata);
  234. }
  235. mxc_register_device(&mxc_usbh1_device, &usbh1_config);
  236. #ifdef CONFIG_MACH_EUKREA_MBIMX51_BASEBOARD
  237. eukrea_mbimx51_baseboard_init();
  238. #endif
  239. }
  240. static void __init eukrea_cpuimx51_timer_init(void)
  241. {
  242. mx51_clocks_init(32768, 24000000, 22579200, 0);
  243. }
  244. static struct sys_timer mxc_timer = {
  245. .init = eukrea_cpuimx51_timer_init,
  246. };
  247. MACHINE_START(EUKREA_CPUIMX51, "Eukrea CPUIMX51 Module")
  248. /* Maintainer: Eric Bénard <eric@eukrea.com> */
  249. .phys_io = MX51_AIPS1_BASE_ADDR,
  250. .io_pg_offst = ((MX51_AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
  251. .boot_params = PHYS_OFFSET + 0x100,
  252. .map_io = mx51_map_io,
  253. .init_irq = mx51_init_irq,
  254. .init_machine = eukrea_cpuimx51_init,
  255. .timer = &mxc_timer,
  256. MACHINE_END