mach-mx31_3ds.c 12 KB

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