board-cpuimx51.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 <mach/eukrea-baseboards.h>
  26. #include <mach/common.h>
  27. #include <mach/hardware.h>
  28. #include <mach/iomux-mx51.h>
  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. #include "devices-imx51.h"
  35. #include "devices.h"
  36. #define CPUIMX51_USBH1_STP IMX_GPIO_NR(1, 27)
  37. #define CPUIMX51_QUARTA_GPIO IMX_GPIO_NR(3, 28)
  38. #define CPUIMX51_QUARTB_GPIO IMX_GPIO_NR(3, 25)
  39. #define CPUIMX51_QUARTC_GPIO IMX_GPIO_NR(3, 26)
  40. #define CPUIMX51_QUARTD_GPIO IMX_GPIO_NR(3, 27)
  41. #define CPUIMX51_QUARTA_IRQ (MXC_INTERNAL_IRQS + CPUIMX51_QUARTA_GPIO)
  42. #define CPUIMX51_QUARTB_IRQ (MXC_INTERNAL_IRQS + CPUIMX51_QUARTB_GPIO)
  43. #define CPUIMX51_QUARTC_IRQ (MXC_INTERNAL_IRQS + CPUIMX51_QUARTC_GPIO)
  44. #define CPUIMX51_QUARTD_IRQ (MXC_INTERNAL_IRQS + CPUIMX51_QUARTD_GPIO)
  45. #define CPUIMX51_QUART_XTAL 14745600
  46. #define CPUIMX51_QUART_REGSHIFT 17
  47. /* USB_CTRL_1 */
  48. #define MX51_USB_CTRL_1_OFFSET 0x10
  49. #define MX51_USB_CTRL_UH1_EXT_CLK_EN (1 << 25)
  50. #define MX51_USB_PLLDIV_12_MHZ 0x00
  51. #define MX51_USB_PLL_DIV_19_2_MHZ 0x01
  52. #define MX51_USB_PLL_DIV_24_MHZ 0x02
  53. static struct plat_serial8250_port serial_platform_data[] = {
  54. {
  55. .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x400000),
  56. .irq = CPUIMX51_QUARTA_IRQ,
  57. .irqflags = IRQF_TRIGGER_HIGH,
  58. .uartclk = CPUIMX51_QUART_XTAL,
  59. .regshift = CPUIMX51_QUART_REGSHIFT,
  60. .iotype = UPIO_MEM,
  61. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
  62. }, {
  63. .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x800000),
  64. .irq = CPUIMX51_QUARTB_IRQ,
  65. .irqflags = IRQF_TRIGGER_HIGH,
  66. .uartclk = CPUIMX51_QUART_XTAL,
  67. .regshift = CPUIMX51_QUART_REGSHIFT,
  68. .iotype = UPIO_MEM,
  69. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
  70. }, {
  71. .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x1000000),
  72. .irq = CPUIMX51_QUARTC_IRQ,
  73. .irqflags = IRQF_TRIGGER_HIGH,
  74. .uartclk = CPUIMX51_QUART_XTAL,
  75. .regshift = CPUIMX51_QUART_REGSHIFT,
  76. .iotype = UPIO_MEM,
  77. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
  78. }, {
  79. .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x2000000),
  80. .irq = CPUIMX51_QUARTD_IRQ,
  81. .irqflags = IRQF_TRIGGER_HIGH,
  82. .uartclk = CPUIMX51_QUART_XTAL,
  83. .regshift = CPUIMX51_QUART_REGSHIFT,
  84. .iotype = UPIO_MEM,
  85. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
  86. }, {
  87. }
  88. };
  89. static struct platform_device serial_device = {
  90. .name = "serial8250",
  91. .id = 0,
  92. .dev = {
  93. .platform_data = serial_platform_data,
  94. },
  95. };
  96. static struct platform_device *devices[] __initdata = {
  97. &serial_device,
  98. };
  99. static iomux_v3_cfg_t eukrea_cpuimx51_pads[] = {
  100. /* UART1 */
  101. MX51_PAD_UART1_RXD__UART1_RXD,
  102. MX51_PAD_UART1_TXD__UART1_TXD,
  103. MX51_PAD_UART1_RTS__UART1_RTS,
  104. MX51_PAD_UART1_CTS__UART1_CTS,
  105. /* I2C2 */
  106. MX51_PAD_GPIO1_2__I2C2_SCL,
  107. MX51_PAD_GPIO1_3__I2C2_SDA,
  108. MX51_PAD_NANDF_D10__GPIO3_30,
  109. /* QUART IRQ */
  110. MX51_PAD_NANDF_D15__GPIO3_25,
  111. MX51_PAD_NANDF_D14__GPIO3_26,
  112. MX51_PAD_NANDF_D13__GPIO3_27,
  113. MX51_PAD_NANDF_D12__GPIO3_28,
  114. /* USB HOST1 */
  115. MX51_PAD_USBH1_CLK__USBH1_CLK,
  116. MX51_PAD_USBH1_DIR__USBH1_DIR,
  117. MX51_PAD_USBH1_NXT__USBH1_NXT,
  118. MX51_PAD_USBH1_DATA0__USBH1_DATA0,
  119. MX51_PAD_USBH1_DATA1__USBH1_DATA1,
  120. MX51_PAD_USBH1_DATA2__USBH1_DATA2,
  121. MX51_PAD_USBH1_DATA3__USBH1_DATA3,
  122. MX51_PAD_USBH1_DATA4__USBH1_DATA4,
  123. MX51_PAD_USBH1_DATA5__USBH1_DATA5,
  124. MX51_PAD_USBH1_DATA6__USBH1_DATA6,
  125. MX51_PAD_USBH1_DATA7__USBH1_DATA7,
  126. MX51_PAD_USBH1_STP__USBH1_STP,
  127. };
  128. static const struct mxc_nand_platform_data
  129. eukrea_cpuimx51_nand_board_info __initconst = {
  130. .width = 1,
  131. .hw_ecc = 1,
  132. .flash_bbt = 1,
  133. };
  134. static const struct imxuart_platform_data uart_pdata __initconst = {
  135. .flags = IMXUART_HAVE_RTSCTS,
  136. };
  137. static const
  138. struct imxi2c_platform_data eukrea_cpuimx51_i2c_data __initconst = {
  139. .bitrate = 100000,
  140. };
  141. static struct i2c_board_info eukrea_cpuimx51_i2c_devices[] = {
  142. {
  143. I2C_BOARD_INFO("pcf8563", 0x51),
  144. },
  145. };
  146. /* This function is board specific as the bit mask for the plldiv will also
  147. be different for other Freescale SoCs, thus a common bitmask is not
  148. possible and cannot get place in /plat-mxc/ehci.c.*/
  149. static int initialize_otg_port(struct platform_device *pdev)
  150. {
  151. u32 v;
  152. void __iomem *usb_base;
  153. void __iomem *usbother_base;
  154. usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
  155. if (!usb_base)
  156. return -ENOMEM;
  157. usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
  158. /* Set the PHY clock to 19.2MHz */
  159. v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
  160. v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK;
  161. v |= MX51_USB_PLL_DIV_19_2_MHZ;
  162. __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
  163. iounmap(usb_base);
  164. mdelay(10);
  165. return mx51_initialize_usb_hw(0, MXC_EHCI_INTERNAL_PHY);
  166. }
  167. static int initialize_usbh1_port(struct platform_device *pdev)
  168. {
  169. u32 v;
  170. void __iomem *usb_base;
  171. void __iomem *usbother_base;
  172. usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
  173. if (!usb_base)
  174. return -ENOMEM;
  175. usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
  176. /* The clock for the USBH1 ULPI port will come externally from the PHY. */
  177. v = __raw_readl(usbother_base + MX51_USB_CTRL_1_OFFSET);
  178. __raw_writel(v | MX51_USB_CTRL_UH1_EXT_CLK_EN, usbother_base + MX51_USB_CTRL_1_OFFSET);
  179. iounmap(usb_base);
  180. mdelay(10);
  181. return mx51_initialize_usb_hw(1, MXC_EHCI_POWER_PINS_ENABLED |
  182. MXC_EHCI_ITC_NO_THRESHOLD);
  183. }
  184. static struct mxc_usbh_platform_data dr_utmi_config = {
  185. .init = initialize_otg_port,
  186. .portsc = MXC_EHCI_UTMI_16BIT,
  187. };
  188. static struct fsl_usb2_platform_data usb_pdata = {
  189. .operating_mode = FSL_USB2_DR_DEVICE,
  190. .phy_mode = FSL_USB2_PHY_UTMI_WIDE,
  191. };
  192. static struct mxc_usbh_platform_data usbh1_config = {
  193. .init = initialize_usbh1_port,
  194. .portsc = MXC_EHCI_MODE_ULPI,
  195. };
  196. static int otg_mode_host;
  197. static int __init eukrea_cpuimx51_otg_mode(char *options)
  198. {
  199. if (!strcmp(options, "host"))
  200. otg_mode_host = 1;
  201. else if (!strcmp(options, "device"))
  202. otg_mode_host = 0;
  203. else
  204. pr_info("otg_mode neither \"host\" nor \"device\". "
  205. "Defaulting to device\n");
  206. return 0;
  207. }
  208. __setup("otg_mode=", eukrea_cpuimx51_otg_mode);
  209. /*
  210. * Board specific initialization.
  211. */
  212. static void __init eukrea_cpuimx51_init(void)
  213. {
  214. mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx51_pads,
  215. ARRAY_SIZE(eukrea_cpuimx51_pads));
  216. imx51_add_imx_uart(0, &uart_pdata);
  217. imx51_add_mxc_nand(&eukrea_cpuimx51_nand_board_info);
  218. gpio_request(CPUIMX51_QUARTA_GPIO, "quarta_irq");
  219. gpio_direction_input(CPUIMX51_QUARTA_GPIO);
  220. gpio_free(CPUIMX51_QUARTA_GPIO);
  221. gpio_request(CPUIMX51_QUARTB_GPIO, "quartb_irq");
  222. gpio_direction_input(CPUIMX51_QUARTB_GPIO);
  223. gpio_free(CPUIMX51_QUARTB_GPIO);
  224. gpio_request(CPUIMX51_QUARTC_GPIO, "quartc_irq");
  225. gpio_direction_input(CPUIMX51_QUARTC_GPIO);
  226. gpio_free(CPUIMX51_QUARTC_GPIO);
  227. gpio_request(CPUIMX51_QUARTD_GPIO, "quartd_irq");
  228. gpio_direction_input(CPUIMX51_QUARTD_GPIO);
  229. gpio_free(CPUIMX51_QUARTD_GPIO);
  230. imx51_add_fec(NULL);
  231. platform_add_devices(devices, ARRAY_SIZE(devices));
  232. imx51_add_imx_i2c(1, &eukrea_cpuimx51_i2c_data);
  233. i2c_register_board_info(1, eukrea_cpuimx51_i2c_devices,
  234. ARRAY_SIZE(eukrea_cpuimx51_i2c_devices));
  235. if (otg_mode_host)
  236. mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config);
  237. else {
  238. initialize_otg_port(NULL);
  239. mxc_register_device(&mxc_usbdr_udc_device, &usb_pdata);
  240. }
  241. mxc_register_device(&mxc_usbh1_device, &usbh1_config);
  242. #ifdef CONFIG_MACH_EUKREA_MBIMX51_BASEBOARD
  243. eukrea_mbimx51_baseboard_init();
  244. #endif
  245. }
  246. static void __init eukrea_cpuimx51_timer_init(void)
  247. {
  248. mx51_clocks_init(32768, 24000000, 22579200, 0);
  249. }
  250. static struct sys_timer mxc_timer = {
  251. .init = eukrea_cpuimx51_timer_init,
  252. };
  253. MACHINE_START(EUKREA_CPUIMX51, "Eukrea CPUIMX51 Module")
  254. /* Maintainer: Eric Bénard <eric@eukrea.com> */
  255. .boot_params = MX51_PHYS_OFFSET + 0x100,
  256. .map_io = mx51_map_io,
  257. .init_early = imx51_init_early,
  258. .init_irq = mx51_init_irq,
  259. .timer = &mxc_timer,
  260. .init_machine = eukrea_cpuimx51_init,
  261. MACHINE_END