mach-mx31_3ds.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <linux/delay.h>
  19. #include <linux/types.h>
  20. #include <linux/init.h>
  21. #include <linux/clk.h>
  22. #include <linux/irq.h>
  23. #include <linux/gpio.h>
  24. #include <linux/smsc911x.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/mfd/mc13783.h>
  27. #include <linux/spi/spi.h>
  28. #include <linux/regulator/machine.h>
  29. #include <linux/fsl_devices.h>
  30. #include <linux/input/matrix_keypad.h>
  31. #include <mach/hardware.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/time.h>
  35. #include <asm/memory.h>
  36. #include <asm/mach/map.h>
  37. #include <mach/common.h>
  38. #include <mach/board-mx31_3ds.h>
  39. #include <mach/imx-uart.h>
  40. #include <mach/iomux-mx3.h>
  41. #include <mach/mxc_nand.h>
  42. #include <mach/spi.h>
  43. #include "devices.h"
  44. /*!
  45. * @file mx31_3ds.c
  46. *
  47. * @brief This file contains the board-specific initialization routines.
  48. *
  49. * @ingroup System
  50. */
  51. static int mx31_3ds_pins[] = {
  52. /* UART1 */
  53. MX31_PIN_CTS1__CTS1,
  54. MX31_PIN_RTS1__RTS1,
  55. MX31_PIN_TXD1__TXD1,
  56. MX31_PIN_RXD1__RXD1,
  57. IOMUX_MODE(MX31_PIN_GPIO1_1, IOMUX_CONFIG_GPIO),
  58. /* SPI 1 */
  59. MX31_PIN_CSPI2_SCLK__SCLK,
  60. MX31_PIN_CSPI2_MOSI__MOSI,
  61. MX31_PIN_CSPI2_MISO__MISO,
  62. MX31_PIN_CSPI2_SPI_RDY__SPI_RDY,
  63. MX31_PIN_CSPI2_SS0__SS0,
  64. MX31_PIN_CSPI2_SS2__SS2, /*CS for MC13783 */
  65. /* MC13783 IRQ */
  66. IOMUX_MODE(MX31_PIN_GPIO1_3, IOMUX_CONFIG_GPIO),
  67. /* USB OTG reset */
  68. IOMUX_MODE(MX31_PIN_USB_PWR, IOMUX_CONFIG_GPIO),
  69. /* USB OTG */
  70. MX31_PIN_USBOTG_DATA0__USBOTG_DATA0,
  71. MX31_PIN_USBOTG_DATA1__USBOTG_DATA1,
  72. MX31_PIN_USBOTG_DATA2__USBOTG_DATA2,
  73. MX31_PIN_USBOTG_DATA3__USBOTG_DATA3,
  74. MX31_PIN_USBOTG_DATA4__USBOTG_DATA4,
  75. MX31_PIN_USBOTG_DATA5__USBOTG_DATA5,
  76. MX31_PIN_USBOTG_DATA6__USBOTG_DATA6,
  77. MX31_PIN_USBOTG_DATA7__USBOTG_DATA7,
  78. MX31_PIN_USBOTG_CLK__USBOTG_CLK,
  79. MX31_PIN_USBOTG_DIR__USBOTG_DIR,
  80. MX31_PIN_USBOTG_NXT__USBOTG_NXT,
  81. MX31_PIN_USBOTG_STP__USBOTG_STP,
  82. /*Keyboard*/
  83. MX31_PIN_KEY_ROW0_KEY_ROW0,
  84. MX31_PIN_KEY_ROW1_KEY_ROW1,
  85. MX31_PIN_KEY_ROW2_KEY_ROW2,
  86. MX31_PIN_KEY_COL0_KEY_COL0,
  87. MX31_PIN_KEY_COL1_KEY_COL1,
  88. MX31_PIN_KEY_COL2_KEY_COL2,
  89. MX31_PIN_KEY_COL3_KEY_COL3,
  90. };
  91. /*
  92. * Matrix keyboard
  93. */
  94. static const uint32_t mx31_3ds_keymap[] = {
  95. KEY(0, 0, KEY_UP),
  96. KEY(0, 1, KEY_DOWN),
  97. KEY(1, 0, KEY_RIGHT),
  98. KEY(1, 1, KEY_LEFT),
  99. KEY(1, 2, KEY_ENTER),
  100. KEY(2, 0, KEY_F6),
  101. KEY(2, 1, KEY_F8),
  102. KEY(2, 2, KEY_F9),
  103. KEY(2, 3, KEY_F10),
  104. };
  105. static struct matrix_keymap_data mx31_3ds_keymap_data = {
  106. .keymap = mx31_3ds_keymap,
  107. .keymap_size = ARRAY_SIZE(mx31_3ds_keymap),
  108. };
  109. /* Regulators */
  110. static struct regulator_init_data pwgtx_init = {
  111. .constraints = {
  112. .boot_on = 1,
  113. .always_on = 1,
  114. },
  115. };
  116. static struct mc13783_regulator_init_data mx31_3ds_regulators[] = {
  117. {
  118. .id = MC13783_REGU_PWGT1SPI, /* Power Gate for ARM core. */
  119. .init_data = &pwgtx_init,
  120. }, {
  121. .id = MC13783_REGU_PWGT2SPI, /* Power Gate for L2 Cache. */
  122. .init_data = &pwgtx_init,
  123. },
  124. };
  125. /* MC13783 */
  126. static struct mc13783_platform_data mc13783_pdata __initdata = {
  127. .regulators = mx31_3ds_regulators,
  128. .num_regulators = ARRAY_SIZE(mx31_3ds_regulators),
  129. .flags = MC13783_USE_REGULATOR,
  130. };
  131. /* SPI */
  132. static int spi1_internal_chipselect[] = {
  133. MXC_SPI_CS(0),
  134. MXC_SPI_CS(2),
  135. };
  136. static struct spi_imx_master spi1_pdata = {
  137. .chipselect = spi1_internal_chipselect,
  138. .num_chipselect = ARRAY_SIZE(spi1_internal_chipselect),
  139. };
  140. static struct spi_board_info mx31_3ds_spi_devs[] __initdata = {
  141. {
  142. .modalias = "mc13783",
  143. .max_speed_hz = 1000000,
  144. .bus_num = 1,
  145. .chip_select = 1, /* SS2 */
  146. .platform_data = &mc13783_pdata,
  147. .irq = IOMUX_TO_IRQ(MX31_PIN_GPIO1_3),
  148. .mode = SPI_CS_HIGH,
  149. },
  150. };
  151. /*
  152. * NAND Flash
  153. */
  154. static struct mxc_nand_platform_data imx31_3ds_nand_flash_pdata = {
  155. .width = 1,
  156. .hw_ecc = 1,
  157. #ifdef MACH_MX31_3DS_MXC_NAND_USE_BBT
  158. .flash_bbt = 1,
  159. #endif
  160. };
  161. /*
  162. * USB OTG
  163. */
  164. #define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
  165. PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
  166. #define USBOTG_RST_B IOMUX_TO_GPIO(MX31_PIN_USB_PWR)
  167. static void mx31_3ds_usbotg_init(void)
  168. {
  169. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA0, USB_PAD_CFG);
  170. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA1, USB_PAD_CFG);
  171. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA2, USB_PAD_CFG);
  172. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA3, USB_PAD_CFG);
  173. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA4, USB_PAD_CFG);
  174. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA5, USB_PAD_CFG);
  175. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA6, USB_PAD_CFG);
  176. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA7, USB_PAD_CFG);
  177. mxc_iomux_set_pad(MX31_PIN_USBOTG_CLK, USB_PAD_CFG);
  178. mxc_iomux_set_pad(MX31_PIN_USBOTG_DIR, USB_PAD_CFG);
  179. mxc_iomux_set_pad(MX31_PIN_USBOTG_NXT, USB_PAD_CFG);
  180. mxc_iomux_set_pad(MX31_PIN_USBOTG_STP, USB_PAD_CFG);
  181. gpio_request(USBOTG_RST_B, "otgusb-reset");
  182. gpio_direction_output(USBOTG_RST_B, 0);
  183. mdelay(1);
  184. gpio_set_value(USBOTG_RST_B, 1);
  185. }
  186. static struct fsl_usb2_platform_data usbotg_pdata = {
  187. .operating_mode = FSL_USB2_DR_DEVICE,
  188. .phy_mode = FSL_USB2_PHY_ULPI,
  189. };
  190. static struct imxuart_platform_data uart_pdata = {
  191. .flags = IMXUART_HAVE_RTSCTS,
  192. };
  193. /*
  194. * Support for the SMSC9217 on the Debug board.
  195. */
  196. static struct smsc911x_platform_config smsc911x_config = {
  197. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  198. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  199. .flags = SMSC911X_USE_16BIT | SMSC911X_FORCE_INTERNAL_PHY,
  200. .phy_interface = PHY_INTERFACE_MODE_MII,
  201. };
  202. static struct resource smsc911x_resources[] = {
  203. {
  204. .start = LAN9217_BASE_ADDR,
  205. .end = LAN9217_BASE_ADDR + 0xff,
  206. .flags = IORESOURCE_MEM,
  207. }, {
  208. .start = EXPIO_INT_ENET,
  209. .end = EXPIO_INT_ENET,
  210. .flags = IORESOURCE_IRQ,
  211. },
  212. };
  213. static struct platform_device smsc911x_device = {
  214. .name = "smsc911x",
  215. .id = -1,
  216. .num_resources = ARRAY_SIZE(smsc911x_resources),
  217. .resource = smsc911x_resources,
  218. .dev = {
  219. .platform_data = &smsc911x_config,
  220. },
  221. };
  222. /*
  223. * Routines for the CPLD on the debug board. It contains a CPLD handling
  224. * LEDs, switches, interrupts for Ethernet.
  225. */
  226. static void mx31_3ds_expio_irq_handler(uint32_t irq, struct irq_desc *desc)
  227. {
  228. uint32_t imr_val;
  229. uint32_t int_valid;
  230. uint32_t expio_irq;
  231. imr_val = __raw_readw(CPLD_INT_MASK_REG);
  232. int_valid = __raw_readw(CPLD_INT_STATUS_REG) & ~imr_val;
  233. expio_irq = MXC_EXP_IO_BASE;
  234. for (; int_valid != 0; int_valid >>= 1, expio_irq++) {
  235. if ((int_valid & 1) == 0)
  236. continue;
  237. generic_handle_irq(expio_irq);
  238. }
  239. }
  240. /*
  241. * Disable an expio pin's interrupt by setting the bit in the imr.
  242. * @param irq an expio virtual irq number
  243. */
  244. static void expio_mask_irq(uint32_t irq)
  245. {
  246. uint16_t reg;
  247. uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
  248. /* mask the interrupt */
  249. reg = __raw_readw(CPLD_INT_MASK_REG);
  250. reg |= 1 << expio;
  251. __raw_writew(reg, CPLD_INT_MASK_REG);
  252. }
  253. /*
  254. * Acknowledge an expanded io pin's interrupt by clearing the bit in the isr.
  255. * @param irq an expanded io virtual irq number
  256. */
  257. static void expio_ack_irq(uint32_t irq)
  258. {
  259. uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
  260. /* clear the interrupt status */
  261. __raw_writew(1 << expio, CPLD_INT_RESET_REG);
  262. __raw_writew(0, CPLD_INT_RESET_REG);
  263. /* mask the interrupt */
  264. expio_mask_irq(irq);
  265. }
  266. /*
  267. * Enable a expio pin's interrupt by clearing the bit in the imr.
  268. * @param irq a expio virtual irq number
  269. */
  270. static void expio_unmask_irq(uint32_t irq)
  271. {
  272. uint16_t reg;
  273. uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
  274. /* unmask the interrupt */
  275. reg = __raw_readw(CPLD_INT_MASK_REG);
  276. reg &= ~(1 << expio);
  277. __raw_writew(reg, CPLD_INT_MASK_REG);
  278. }
  279. static struct irq_chip expio_irq_chip = {
  280. .ack = expio_ack_irq,
  281. .mask = expio_mask_irq,
  282. .unmask = expio_unmask_irq,
  283. };
  284. static int __init mx31_3ds_init_expio(void)
  285. {
  286. int i;
  287. int ret;
  288. /* Check if there's a debug board connected */
  289. if ((__raw_readw(CPLD_MAGIC_NUMBER1_REG) != 0xAAAA) ||
  290. (__raw_readw(CPLD_MAGIC_NUMBER2_REG) != 0x5555) ||
  291. (__raw_readw(CPLD_MAGIC_NUMBER3_REG) != 0xCAFE)) {
  292. /* No Debug board found */
  293. return -ENODEV;
  294. }
  295. pr_info("i.MX31 3DS Debug board detected, rev = 0x%04X\n",
  296. __raw_readw(CPLD_CODE_VER_REG));
  297. /*
  298. * Configure INT line as GPIO input
  299. */
  300. ret = gpio_request(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1), "sms9217-irq");
  301. if (ret)
  302. pr_warning("could not get LAN irq gpio\n");
  303. else
  304. gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1));
  305. /* Disable the interrupts and clear the status */
  306. __raw_writew(0, CPLD_INT_MASK_REG);
  307. __raw_writew(0xFFFF, CPLD_INT_RESET_REG);
  308. __raw_writew(0, CPLD_INT_RESET_REG);
  309. __raw_writew(0x1F, CPLD_INT_MASK_REG);
  310. for (i = MXC_EXP_IO_BASE;
  311. i < (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES);
  312. i++) {
  313. set_irq_chip(i, &expio_irq_chip);
  314. set_irq_handler(i, handle_level_irq);
  315. set_irq_flags(i, IRQF_VALID);
  316. }
  317. set_irq_type(EXPIO_PARENT_INT, IRQ_TYPE_LEVEL_LOW);
  318. set_irq_chained_handler(EXPIO_PARENT_INT, mx31_3ds_expio_irq_handler);
  319. return 0;
  320. }
  321. /*
  322. * This structure defines the MX31 memory map.
  323. */
  324. static struct map_desc mx31_3ds_io_desc[] __initdata = {
  325. {
  326. .virtual = MX31_CS5_BASE_ADDR_VIRT,
  327. .pfn = __phys_to_pfn(MX31_CS5_BASE_ADDR),
  328. .length = MX31_CS5_SIZE,
  329. .type = MT_DEVICE,
  330. },
  331. };
  332. /*
  333. * Set up static virtual mappings.
  334. */
  335. static void __init mx31_3ds_map_io(void)
  336. {
  337. mx31_map_io();
  338. iotable_init(mx31_3ds_io_desc, ARRAY_SIZE(mx31_3ds_io_desc));
  339. }
  340. /*!
  341. * Board specific initialization.
  342. */
  343. static void __init mxc_board_init(void)
  344. {
  345. mxc_iomux_setup_multiple_pins(mx31_3ds_pins, ARRAY_SIZE(mx31_3ds_pins),
  346. "mx31_3ds");
  347. mxc_register_device(&mxc_uart_device0, &uart_pdata);
  348. mxc_register_device(&mxc_nand_device, &imx31_3ds_nand_flash_pdata);
  349. mxc_register_device(&mxc_spi_device1, &spi1_pdata);
  350. spi_register_board_info(mx31_3ds_spi_devs,
  351. ARRAY_SIZE(mx31_3ds_spi_devs));
  352. mxc_register_device(&imx_kpp_device, &mx31_3ds_keymap_data);
  353. mx31_3ds_usbotg_init();
  354. mxc_register_device(&mxc_otg_udc_device, &usbotg_pdata);
  355. if (!mx31_3ds_init_expio())
  356. platform_device_register(&smsc911x_device);
  357. }
  358. static void __init mx31_3ds_timer_init(void)
  359. {
  360. mx31_clocks_init(26000000);
  361. }
  362. static struct sys_timer mx31_3ds_timer = {
  363. .init = mx31_3ds_timer_init,
  364. };
  365. /*
  366. * The following uses standard kernel macros defined in arch.h in order to
  367. * initialize __mach_desc_MX31_3DS data structure.
  368. */
  369. MACHINE_START(MX31_3DS, "Freescale MX31PDK (3DS)")
  370. /* Maintainer: Freescale Semiconductor, Inc. */
  371. .phys_io = MX31_AIPS1_BASE_ADDR,
  372. .io_pg_offst = (MX31_AIPS1_BASE_ADDR_VIRT >> 18) & 0xfffc,
  373. .boot_params = MX3x_PHYS_OFFSET + 0x100,
  374. .map_io = mx31_3ds_map_io,
  375. .init_irq = mx31_init_irq,
  376. .init_machine = mxc_board_init,
  377. .timer = &mx31_3ds_timer,
  378. MACHINE_END