mach-mx31_3ds.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/types.h>
  16. #include <linux/init.h>
  17. #include <linux/clk.h>
  18. #include <linux/irq.h>
  19. #include <linux/gpio.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/mfd/mc13783.h>
  22. #include <linux/spi/spi.h>
  23. #include <linux/regulator/machine.h>
  24. #include <linux/fsl_devices.h>
  25. #include <linux/input/matrix_keypad.h>
  26. #include <mach/hardware.h>
  27. #include <asm/mach-types.h>
  28. #include <asm/mach/arch.h>
  29. #include <asm/mach/time.h>
  30. #include <asm/memory.h>
  31. #include <asm/mach/map.h>
  32. #include <mach/common.h>
  33. #include <mach/iomux-mx3.h>
  34. #include <mach/3ds_debugboard.h>
  35. #include "devices-imx31.h"
  36. #include "devices.h"
  37. /* Definitions for components on the Debug board */
  38. /* Base address of CPLD controller on the Debug board */
  39. #define DEBUG_BASE_ADDRESS CS5_IO_ADDRESS(MX3x_CS5_BASE_ADDR)
  40. /* LAN9217 ethernet base address */
  41. #define LAN9217_BASE_ADDR MX3x_CS5_BASE_ADDR
  42. /* CPLD config and interrupt base address */
  43. #define CPLD_ADDR (DEBUG_BASE_ADDRESS + 0x20000)
  44. /* status, interrupt */
  45. #define CPLD_INT_STATUS_REG (CPLD_ADDR + 0x10)
  46. #define CPLD_INT_MASK_REG (CPLD_ADDR + 0x38)
  47. #define CPLD_INT_RESET_REG (CPLD_ADDR + 0x20)
  48. /* magic word for debug CPLD */
  49. #define CPLD_MAGIC_NUMBER1_REG (CPLD_ADDR + 0x40)
  50. #define CPLD_MAGIC_NUMBER2_REG (CPLD_ADDR + 0x48)
  51. /* CPLD code version */
  52. #define CPLD_CODE_VER_REG (CPLD_ADDR + 0x50)
  53. /* magic word for debug CPLD */
  54. #define CPLD_MAGIC_NUMBER3_REG (CPLD_ADDR + 0x58)
  55. /* CPLD IRQ line for external uart, external ethernet etc */
  56. #define EXPIO_PARENT_INT IOMUX_TO_IRQ(MX31_PIN_GPIO1_1)
  57. #define MXC_EXP_IO_BASE (MXC_BOARD_IRQ_START)
  58. #define MXC_IRQ_TO_EXPIO(irq) ((irq) - MXC_EXP_IO_BASE)
  59. #define EXPIO_INT_ENET (MXC_EXP_IO_BASE + 0)
  60. #define MXC_MAX_EXP_IO_LINES 16
  61. /*
  62. * This file contains the board-specific initialization routines.
  63. */
  64. static int mx31_3ds_pins[] = {
  65. /* UART1 */
  66. MX31_PIN_CTS1__CTS1,
  67. MX31_PIN_RTS1__RTS1,
  68. MX31_PIN_TXD1__TXD1,
  69. MX31_PIN_RXD1__RXD1,
  70. IOMUX_MODE(MX31_PIN_GPIO1_1, IOMUX_CONFIG_GPIO),
  71. /* SPI 1 */
  72. MX31_PIN_CSPI2_SCLK__SCLK,
  73. MX31_PIN_CSPI2_MOSI__MOSI,
  74. MX31_PIN_CSPI2_MISO__MISO,
  75. MX31_PIN_CSPI2_SPI_RDY__SPI_RDY,
  76. MX31_PIN_CSPI2_SS0__SS0,
  77. MX31_PIN_CSPI2_SS2__SS2, /*CS for MC13783 */
  78. /* MC13783 IRQ */
  79. IOMUX_MODE(MX31_PIN_GPIO1_3, IOMUX_CONFIG_GPIO),
  80. /* USB OTG reset */
  81. IOMUX_MODE(MX31_PIN_USB_PWR, IOMUX_CONFIG_GPIO),
  82. /* USB OTG */
  83. MX31_PIN_USBOTG_DATA0__USBOTG_DATA0,
  84. MX31_PIN_USBOTG_DATA1__USBOTG_DATA1,
  85. MX31_PIN_USBOTG_DATA2__USBOTG_DATA2,
  86. MX31_PIN_USBOTG_DATA3__USBOTG_DATA3,
  87. MX31_PIN_USBOTG_DATA4__USBOTG_DATA4,
  88. MX31_PIN_USBOTG_DATA5__USBOTG_DATA5,
  89. MX31_PIN_USBOTG_DATA6__USBOTG_DATA6,
  90. MX31_PIN_USBOTG_DATA7__USBOTG_DATA7,
  91. MX31_PIN_USBOTG_CLK__USBOTG_CLK,
  92. MX31_PIN_USBOTG_DIR__USBOTG_DIR,
  93. MX31_PIN_USBOTG_NXT__USBOTG_NXT,
  94. MX31_PIN_USBOTG_STP__USBOTG_STP,
  95. /*Keyboard*/
  96. MX31_PIN_KEY_ROW0_KEY_ROW0,
  97. MX31_PIN_KEY_ROW1_KEY_ROW1,
  98. MX31_PIN_KEY_ROW2_KEY_ROW2,
  99. MX31_PIN_KEY_COL0_KEY_COL0,
  100. MX31_PIN_KEY_COL1_KEY_COL1,
  101. MX31_PIN_KEY_COL2_KEY_COL2,
  102. MX31_PIN_KEY_COL3_KEY_COL3,
  103. };
  104. /*
  105. * Matrix keyboard
  106. */
  107. static const uint32_t mx31_3ds_keymap[] = {
  108. KEY(0, 0, KEY_UP),
  109. KEY(0, 1, KEY_DOWN),
  110. KEY(1, 0, KEY_RIGHT),
  111. KEY(1, 1, KEY_LEFT),
  112. KEY(1, 2, KEY_ENTER),
  113. KEY(2, 0, KEY_F6),
  114. KEY(2, 1, KEY_F8),
  115. KEY(2, 2, KEY_F9),
  116. KEY(2, 3, KEY_F10),
  117. };
  118. static struct matrix_keymap_data mx31_3ds_keymap_data = {
  119. .keymap = mx31_3ds_keymap,
  120. .keymap_size = ARRAY_SIZE(mx31_3ds_keymap),
  121. };
  122. /* Regulators */
  123. static struct regulator_init_data pwgtx_init = {
  124. .constraints = {
  125. .boot_on = 1,
  126. .always_on = 1,
  127. },
  128. };
  129. static struct mc13783_regulator_init_data mx31_3ds_regulators[] = {
  130. {
  131. .id = MC13783_REGU_PWGT1SPI, /* Power Gate for ARM core. */
  132. .init_data = &pwgtx_init,
  133. }, {
  134. .id = MC13783_REGU_PWGT2SPI, /* Power Gate for L2 Cache. */
  135. .init_data = &pwgtx_init,
  136. },
  137. };
  138. /* MC13783 */
  139. static struct mc13783_platform_data mc13783_pdata __initdata = {
  140. .regulators = mx31_3ds_regulators,
  141. .num_regulators = ARRAY_SIZE(mx31_3ds_regulators),
  142. .flags = MC13783_USE_REGULATOR,
  143. };
  144. /* SPI */
  145. static int spi1_internal_chipselect[] = {
  146. MXC_SPI_CS(0),
  147. MXC_SPI_CS(2),
  148. };
  149. static const struct spi_imx_master spi1_pdata __initconst = {
  150. .chipselect = spi1_internal_chipselect,
  151. .num_chipselect = ARRAY_SIZE(spi1_internal_chipselect),
  152. };
  153. static struct spi_board_info mx31_3ds_spi_devs[] __initdata = {
  154. {
  155. .modalias = "mc13783",
  156. .max_speed_hz = 1000000,
  157. .bus_num = 1,
  158. .chip_select = 1, /* SS2 */
  159. .platform_data = &mc13783_pdata,
  160. .irq = IOMUX_TO_IRQ(MX31_PIN_GPIO1_3),
  161. .mode = SPI_CS_HIGH,
  162. },
  163. };
  164. /*
  165. * NAND Flash
  166. */
  167. static const struct mxc_nand_platform_data
  168. mx31_3ds_nand_board_info __initconst = {
  169. .width = 1,
  170. .hw_ecc = 1,
  171. #ifdef MACH_MX31_3DS_MXC_NAND_USE_BBT
  172. .flash_bbt = 1,
  173. #endif
  174. };
  175. /*
  176. * USB OTG
  177. */
  178. #define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
  179. PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
  180. #define USBOTG_RST_B IOMUX_TO_GPIO(MX31_PIN_USB_PWR)
  181. static int mx31_3ds_usbotg_init(void)
  182. {
  183. int err;
  184. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA0, USB_PAD_CFG);
  185. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA1, USB_PAD_CFG);
  186. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA2, USB_PAD_CFG);
  187. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA3, USB_PAD_CFG);
  188. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA4, USB_PAD_CFG);
  189. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA5, USB_PAD_CFG);
  190. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA6, USB_PAD_CFG);
  191. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA7, USB_PAD_CFG);
  192. mxc_iomux_set_pad(MX31_PIN_USBOTG_CLK, USB_PAD_CFG);
  193. mxc_iomux_set_pad(MX31_PIN_USBOTG_DIR, USB_PAD_CFG);
  194. mxc_iomux_set_pad(MX31_PIN_USBOTG_NXT, USB_PAD_CFG);
  195. mxc_iomux_set_pad(MX31_PIN_USBOTG_STP, USB_PAD_CFG);
  196. err = gpio_request(USBOTG_RST_B, "otgusb-reset");
  197. if (err) {
  198. pr_err("Failed to request the USB OTG reset gpio\n");
  199. return err;
  200. }
  201. err = gpio_direction_output(USBOTG_RST_B, 0);
  202. if (err) {
  203. pr_err("Failed to drive the USB OTG reset gpio\n");
  204. goto usbotg_free_reset;
  205. }
  206. mdelay(1);
  207. gpio_set_value(USBOTG_RST_B, 1);
  208. return 0;
  209. usbotg_free_reset:
  210. gpio_free(USBOTG_RST_B);
  211. return err;
  212. }
  213. static struct fsl_usb2_platform_data usbotg_pdata = {
  214. .operating_mode = FSL_USB2_DR_DEVICE,
  215. .phy_mode = FSL_USB2_PHY_ULPI,
  216. };
  217. static const struct imxuart_platform_data uart_pdata __initconst = {
  218. .flags = IMXUART_HAVE_RTSCTS,
  219. };
  220. /*
  221. * Set up static virtual mappings.
  222. */
  223. static void __init mx31_3ds_map_io(void)
  224. {
  225. mx31_map_io();
  226. }
  227. /*!
  228. * Board specific initialization.
  229. */
  230. static void __init mxc_board_init(void)
  231. {
  232. mxc_iomux_setup_multiple_pins(mx31_3ds_pins, ARRAY_SIZE(mx31_3ds_pins),
  233. "mx31_3ds");
  234. imx31_add_imx_uart0(&uart_pdata);
  235. imx31_add_mxc_nand(&mx31_3ds_nand_board_info);
  236. imx31_add_spi_imx0(&spi1_pdata);
  237. spi_register_board_info(mx31_3ds_spi_devs,
  238. ARRAY_SIZE(mx31_3ds_spi_devs));
  239. mxc_register_device(&imx_kpp_device, &mx31_3ds_keymap_data);
  240. mx31_3ds_usbotg_init();
  241. mxc_register_device(&mxc_otg_udc_device, &usbotg_pdata);
  242. if (!mxc_expio_init(CS5_BASE_ADDR, EXPIO_PARENT_INT))
  243. printk(KERN_WARNING "Init of the debugboard failed, all "
  244. "devices on the board are unusable.\n");
  245. }
  246. static void __init mx31_3ds_timer_init(void)
  247. {
  248. mx31_clocks_init(26000000);
  249. }
  250. static struct sys_timer mx31_3ds_timer = {
  251. .init = mx31_3ds_timer_init,
  252. };
  253. /*
  254. * The following uses standard kernel macros defined in arch.h in order to
  255. * initialize __mach_desc_MX31_3DS data structure.
  256. */
  257. MACHINE_START(MX31_3DS, "Freescale MX31PDK (3DS)")
  258. /* Maintainer: Freescale Semiconductor, Inc. */
  259. .phys_io = MX31_AIPS1_BASE_ADDR,
  260. .io_pg_offst = (MX31_AIPS1_BASE_ADDR_VIRT >> 18) & 0xfffc,
  261. .boot_params = MX3x_PHYS_OFFSET + 0x100,
  262. .map_io = mx31_3ds_map_io,
  263. .init_irq = mx31_init_irq,
  264. .init_machine = mxc_board_init,
  265. .timer = &mx31_3ds_timer,
  266. MACHINE_END