mach-mx31_3ds.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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/smsc911x.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/mfd/mc13783.h>
  23. #include <linux/spi/spi.h>
  24. #include <linux/regulator/machine.h>
  25. #include <linux/fsl_devices.h>
  26. #include <linux/input/matrix_keypad.h>
  27. #include <mach/hardware.h>
  28. #include <asm/mach-types.h>
  29. #include <asm/mach/arch.h>
  30. #include <asm/mach/time.h>
  31. #include <asm/memory.h>
  32. #include <asm/mach/map.h>
  33. #include <mach/common.h>
  34. #include <mach/iomux-mx3.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. * Support for the SMSC9217 on the Debug board.
  222. */
  223. static struct smsc911x_platform_config smsc911x_config = {
  224. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  225. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  226. .flags = SMSC911X_USE_16BIT | SMSC911X_FORCE_INTERNAL_PHY,
  227. .phy_interface = PHY_INTERFACE_MODE_MII,
  228. };
  229. static struct resource smsc911x_resources[] = {
  230. {
  231. .start = LAN9217_BASE_ADDR,
  232. .end = LAN9217_BASE_ADDR + 0xff,
  233. .flags = IORESOURCE_MEM,
  234. }, {
  235. .start = EXPIO_INT_ENET,
  236. .end = EXPIO_INT_ENET,
  237. .flags = IORESOURCE_IRQ,
  238. },
  239. };
  240. static struct platform_device smsc911x_device = {
  241. .name = "smsc911x",
  242. .id = -1,
  243. .num_resources = ARRAY_SIZE(smsc911x_resources),
  244. .resource = smsc911x_resources,
  245. .dev = {
  246. .platform_data = &smsc911x_config,
  247. },
  248. };
  249. /*
  250. * Routines for the CPLD on the debug board. It contains a CPLD handling
  251. * LEDs, switches, interrupts for Ethernet.
  252. */
  253. static void mx31_3ds_expio_irq_handler(uint32_t irq, struct irq_desc *desc)
  254. {
  255. uint32_t imr_val;
  256. uint32_t int_valid;
  257. uint32_t expio_irq;
  258. imr_val = __raw_readw(CPLD_INT_MASK_REG);
  259. int_valid = __raw_readw(CPLD_INT_STATUS_REG) & ~imr_val;
  260. expio_irq = MXC_EXP_IO_BASE;
  261. for (; int_valid != 0; int_valid >>= 1, expio_irq++) {
  262. if ((int_valid & 1) == 0)
  263. continue;
  264. generic_handle_irq(expio_irq);
  265. }
  266. }
  267. /*
  268. * Disable an expio pin's interrupt by setting the bit in the imr.
  269. * @param irq an expio virtual irq number
  270. */
  271. static void expio_mask_irq(uint32_t irq)
  272. {
  273. uint16_t reg;
  274. uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
  275. /* mask the interrupt */
  276. reg = __raw_readw(CPLD_INT_MASK_REG);
  277. reg |= 1 << expio;
  278. __raw_writew(reg, CPLD_INT_MASK_REG);
  279. }
  280. /*
  281. * Acknowledge an expanded io pin's interrupt by clearing the bit in the isr.
  282. * @param irq an expanded io virtual irq number
  283. */
  284. static void expio_ack_irq(uint32_t irq)
  285. {
  286. uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
  287. /* clear the interrupt status */
  288. __raw_writew(1 << expio, CPLD_INT_RESET_REG);
  289. __raw_writew(0, CPLD_INT_RESET_REG);
  290. /* mask the interrupt */
  291. expio_mask_irq(irq);
  292. }
  293. /*
  294. * Enable a expio pin's interrupt by clearing the bit in the imr.
  295. * @param irq a expio virtual irq number
  296. */
  297. static void expio_unmask_irq(uint32_t irq)
  298. {
  299. uint16_t reg;
  300. uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
  301. /* unmask the interrupt */
  302. reg = __raw_readw(CPLD_INT_MASK_REG);
  303. reg &= ~(1 << expio);
  304. __raw_writew(reg, CPLD_INT_MASK_REG);
  305. }
  306. static struct irq_chip expio_irq_chip = {
  307. .ack = expio_ack_irq,
  308. .mask = expio_mask_irq,
  309. .unmask = expio_unmask_irq,
  310. };
  311. static int __init mx31_3ds_init_expio(void)
  312. {
  313. int i;
  314. int ret;
  315. /* Check if there's a debug board connected */
  316. if ((__raw_readw(CPLD_MAGIC_NUMBER1_REG) != 0xAAAA) ||
  317. (__raw_readw(CPLD_MAGIC_NUMBER2_REG) != 0x5555) ||
  318. (__raw_readw(CPLD_MAGIC_NUMBER3_REG) != 0xCAFE)) {
  319. /* No Debug board found */
  320. return -ENODEV;
  321. }
  322. pr_info("i.MX31 3DS Debug board detected, rev = 0x%04X\n",
  323. __raw_readw(CPLD_CODE_VER_REG));
  324. /*
  325. * Configure INT line as GPIO input
  326. */
  327. ret = gpio_request(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1), "sms9217-irq");
  328. if (ret)
  329. pr_warning("could not get LAN irq gpio\n");
  330. else
  331. gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1));
  332. /* Disable the interrupts and clear the status */
  333. __raw_writew(0, CPLD_INT_MASK_REG);
  334. __raw_writew(0xFFFF, CPLD_INT_RESET_REG);
  335. __raw_writew(0, CPLD_INT_RESET_REG);
  336. __raw_writew(0x1F, CPLD_INT_MASK_REG);
  337. for (i = MXC_EXP_IO_BASE;
  338. i < (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES);
  339. i++) {
  340. set_irq_chip(i, &expio_irq_chip);
  341. set_irq_handler(i, handle_level_irq);
  342. set_irq_flags(i, IRQF_VALID);
  343. }
  344. set_irq_type(EXPIO_PARENT_INT, IRQ_TYPE_LEVEL_LOW);
  345. set_irq_chained_handler(EXPIO_PARENT_INT, mx31_3ds_expio_irq_handler);
  346. return 0;
  347. }
  348. /*
  349. * This structure defines the MX31 memory map.
  350. */
  351. static struct map_desc mx31_3ds_io_desc[] __initdata = {
  352. {
  353. .virtual = MX31_CS5_BASE_ADDR_VIRT,
  354. .pfn = __phys_to_pfn(MX31_CS5_BASE_ADDR),
  355. .length = MX31_CS5_SIZE,
  356. .type = MT_DEVICE,
  357. },
  358. };
  359. /*
  360. * Set up static virtual mappings.
  361. */
  362. static void __init mx31_3ds_map_io(void)
  363. {
  364. mx31_map_io();
  365. iotable_init(mx31_3ds_io_desc, ARRAY_SIZE(mx31_3ds_io_desc));
  366. }
  367. /*!
  368. * Board specific initialization.
  369. */
  370. static void __init mxc_board_init(void)
  371. {
  372. mxc_iomux_setup_multiple_pins(mx31_3ds_pins, ARRAY_SIZE(mx31_3ds_pins),
  373. "mx31_3ds");
  374. imx31_add_imx_uart0(&uart_pdata);
  375. imx31_add_mxc_nand(&mx31_3ds_nand_board_info);
  376. imx31_add_spi_imx0(&spi1_pdata);
  377. spi_register_board_info(mx31_3ds_spi_devs,
  378. ARRAY_SIZE(mx31_3ds_spi_devs));
  379. mxc_register_device(&imx_kpp_device, &mx31_3ds_keymap_data);
  380. mx31_3ds_usbotg_init();
  381. mxc_register_device(&mxc_otg_udc_device, &usbotg_pdata);
  382. if (!mx31_3ds_init_expio())
  383. platform_device_register(&smsc911x_device);
  384. }
  385. static void __init mx31_3ds_timer_init(void)
  386. {
  387. mx31_clocks_init(26000000);
  388. }
  389. static struct sys_timer mx31_3ds_timer = {
  390. .init = mx31_3ds_timer_init,
  391. };
  392. /*
  393. * The following uses standard kernel macros defined in arch.h in order to
  394. * initialize __mach_desc_MX31_3DS data structure.
  395. */
  396. MACHINE_START(MX31_3DS, "Freescale MX31PDK (3DS)")
  397. /* Maintainer: Freescale Semiconductor, Inc. */
  398. .phys_io = MX31_AIPS1_BASE_ADDR,
  399. .io_pg_offst = (MX31_AIPS1_BASE_ADDR_VIRT >> 18) & 0xfffc,
  400. .boot_params = MX3x_PHYS_OFFSET + 0x100,
  401. .map_io = mx31_3ds_map_io,
  402. .init_irq = mx31_init_irq,
  403. .init_machine = mxc_board_init,
  404. .timer = &mx31_3ds_timer,
  405. MACHINE_END