mach-mx31_3ds.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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/types.h>
  19. #include <linux/init.h>
  20. #include <linux/clk.h>
  21. #include <linux/irq.h>
  22. #include <linux/gpio.h>
  23. #include <linux/smsc911x.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/mfd/mc13783.h>
  26. #include <linux/spi/spi.h>
  27. #include <linux/regulator/machine.h>
  28. #include <mach/hardware.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/mach/arch.h>
  31. #include <asm/mach/time.h>
  32. #include <asm/memory.h>
  33. #include <asm/mach/map.h>
  34. #include <mach/common.h>
  35. #include <mach/board-mx31_3ds.h>
  36. #include <mach/imx-uart.h>
  37. #include <mach/iomux-mx3.h>
  38. #include <mach/mxc_nand.h>
  39. #include <mach/spi.h>
  40. #include "devices.h"
  41. /*!
  42. * @file mx31_3ds.c
  43. *
  44. * @brief This file contains the board-specific initialization routines.
  45. *
  46. * @ingroup System
  47. */
  48. static int mx31_3ds_pins[] = {
  49. /* UART1 */
  50. MX31_PIN_CTS1__CTS1,
  51. MX31_PIN_RTS1__RTS1,
  52. MX31_PIN_TXD1__TXD1,
  53. MX31_PIN_RXD1__RXD1,
  54. IOMUX_MODE(MX31_PIN_GPIO1_1, IOMUX_CONFIG_GPIO),
  55. /* SPI 1 */
  56. MX31_PIN_CSPI2_SCLK__SCLK,
  57. MX31_PIN_CSPI2_MOSI__MOSI,
  58. MX31_PIN_CSPI2_MISO__MISO,
  59. MX31_PIN_CSPI2_SPI_RDY__SPI_RDY,
  60. MX31_PIN_CSPI2_SS0__SS0,
  61. MX31_PIN_CSPI2_SS2__SS2, /*CS for MC13783 */
  62. /* MC13783 IRQ */
  63. IOMUX_MODE(MX31_PIN_GPIO1_3, IOMUX_CONFIG_GPIO),
  64. };
  65. /* Regulators */
  66. static struct regulator_init_data pwgtx_init = {
  67. .constraints = {
  68. .boot_on = 1,
  69. .always_on = 1,
  70. },
  71. };
  72. static struct mc13783_regulator_init_data mx31_3ds_regulators[] = {
  73. {
  74. .id = MC13783_REGU_PWGT1SPI, /* Power Gate for ARM core. */
  75. .init_data = &pwgtx_init,
  76. }, {
  77. .id = MC13783_REGU_PWGT2SPI, /* Power Gate for L2 Cache. */
  78. .init_data = &pwgtx_init,
  79. },
  80. };
  81. /* MC13783 */
  82. static struct mc13783_platform_data mc13783_pdata __initdata = {
  83. .regulators = mx31_3ds_regulators,
  84. .num_regulators = ARRAY_SIZE(mx31_3ds_regulators),
  85. .flags = MC13783_USE_REGULATOR,
  86. };
  87. /* SPI */
  88. static int spi1_internal_chipselect[] = {
  89. MXC_SPI_CS(0),
  90. MXC_SPI_CS(2),
  91. };
  92. static struct spi_imx_master spi1_pdata = {
  93. .chipselect = spi1_internal_chipselect,
  94. .num_chipselect = ARRAY_SIZE(spi1_internal_chipselect),
  95. };
  96. static struct spi_board_info mx31_3ds_spi_devs[] __initdata = {
  97. {
  98. .modalias = "mc13783",
  99. .max_speed_hz = 1000000,
  100. .bus_num = 1,
  101. .chip_select = 1, /* SS2 */
  102. .platform_data = &mc13783_pdata,
  103. .irq = IOMUX_TO_IRQ(MX31_PIN_GPIO1_3),
  104. .mode = SPI_CS_HIGH,
  105. },
  106. };
  107. /*
  108. * NAND Flash
  109. */
  110. static struct mxc_nand_platform_data imx31_3ds_nand_flash_pdata = {
  111. .width = 1,
  112. .hw_ecc = 1,
  113. #ifdef MACH_MX31_3DS_MXC_NAND_USE_BBT
  114. .flash_bbt = 1,
  115. #endif
  116. };
  117. static struct imxuart_platform_data uart_pdata = {
  118. .flags = IMXUART_HAVE_RTSCTS,
  119. };
  120. /*
  121. * Support for the SMSC9217 on the Debug board.
  122. */
  123. static struct smsc911x_platform_config smsc911x_config = {
  124. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  125. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  126. .flags = SMSC911X_USE_16BIT | SMSC911X_FORCE_INTERNAL_PHY,
  127. .phy_interface = PHY_INTERFACE_MODE_MII,
  128. };
  129. static struct resource smsc911x_resources[] = {
  130. {
  131. .start = LAN9217_BASE_ADDR,
  132. .end = LAN9217_BASE_ADDR + 0xff,
  133. .flags = IORESOURCE_MEM,
  134. }, {
  135. .start = EXPIO_INT_ENET,
  136. .end = EXPIO_INT_ENET,
  137. .flags = IORESOURCE_IRQ,
  138. },
  139. };
  140. static struct platform_device smsc911x_device = {
  141. .name = "smsc911x",
  142. .id = -1,
  143. .num_resources = ARRAY_SIZE(smsc911x_resources),
  144. .resource = smsc911x_resources,
  145. .dev = {
  146. .platform_data = &smsc911x_config,
  147. },
  148. };
  149. /*
  150. * Routines for the CPLD on the debug board. It contains a CPLD handling
  151. * LEDs, switches, interrupts for Ethernet.
  152. */
  153. static void mx31_3ds_expio_irq_handler(uint32_t irq, struct irq_desc *desc)
  154. {
  155. uint32_t imr_val;
  156. uint32_t int_valid;
  157. uint32_t expio_irq;
  158. imr_val = __raw_readw(CPLD_INT_MASK_REG);
  159. int_valid = __raw_readw(CPLD_INT_STATUS_REG) & ~imr_val;
  160. expio_irq = MXC_EXP_IO_BASE;
  161. for (; int_valid != 0; int_valid >>= 1, expio_irq++) {
  162. if ((int_valid & 1) == 0)
  163. continue;
  164. generic_handle_irq(expio_irq);
  165. }
  166. }
  167. /*
  168. * Disable an expio pin's interrupt by setting the bit in the imr.
  169. * @param irq an expio virtual irq number
  170. */
  171. static void expio_mask_irq(uint32_t irq)
  172. {
  173. uint16_t reg;
  174. uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
  175. /* mask the interrupt */
  176. reg = __raw_readw(CPLD_INT_MASK_REG);
  177. reg |= 1 << expio;
  178. __raw_writew(reg, CPLD_INT_MASK_REG);
  179. }
  180. /*
  181. * Acknowledge an expanded io pin's interrupt by clearing the bit in the isr.
  182. * @param irq an expanded io virtual irq number
  183. */
  184. static void expio_ack_irq(uint32_t irq)
  185. {
  186. uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
  187. /* clear the interrupt status */
  188. __raw_writew(1 << expio, CPLD_INT_RESET_REG);
  189. __raw_writew(0, CPLD_INT_RESET_REG);
  190. /* mask the interrupt */
  191. expio_mask_irq(irq);
  192. }
  193. /*
  194. * Enable a expio pin's interrupt by clearing the bit in the imr.
  195. * @param irq a expio virtual irq number
  196. */
  197. static void expio_unmask_irq(uint32_t irq)
  198. {
  199. uint16_t reg;
  200. uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
  201. /* unmask the interrupt */
  202. reg = __raw_readw(CPLD_INT_MASK_REG);
  203. reg &= ~(1 << expio);
  204. __raw_writew(reg, CPLD_INT_MASK_REG);
  205. }
  206. static struct irq_chip expio_irq_chip = {
  207. .ack = expio_ack_irq,
  208. .mask = expio_mask_irq,
  209. .unmask = expio_unmask_irq,
  210. };
  211. static int __init mx31_3ds_init_expio(void)
  212. {
  213. int i;
  214. int ret;
  215. /* Check if there's a debug board connected */
  216. if ((__raw_readw(CPLD_MAGIC_NUMBER1_REG) != 0xAAAA) ||
  217. (__raw_readw(CPLD_MAGIC_NUMBER2_REG) != 0x5555) ||
  218. (__raw_readw(CPLD_MAGIC_NUMBER3_REG) != 0xCAFE)) {
  219. /* No Debug board found */
  220. return -ENODEV;
  221. }
  222. pr_info("i.MX31 3DS Debug board detected, rev = 0x%04X\n",
  223. __raw_readw(CPLD_CODE_VER_REG));
  224. /*
  225. * Configure INT line as GPIO input
  226. */
  227. ret = gpio_request(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1), "sms9217-irq");
  228. if (ret)
  229. pr_warning("could not get LAN irq gpio\n");
  230. else
  231. gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1));
  232. /* Disable the interrupts and clear the status */
  233. __raw_writew(0, CPLD_INT_MASK_REG);
  234. __raw_writew(0xFFFF, CPLD_INT_RESET_REG);
  235. __raw_writew(0, CPLD_INT_RESET_REG);
  236. __raw_writew(0x1F, CPLD_INT_MASK_REG);
  237. for (i = MXC_EXP_IO_BASE;
  238. i < (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES);
  239. i++) {
  240. set_irq_chip(i, &expio_irq_chip);
  241. set_irq_handler(i, handle_level_irq);
  242. set_irq_flags(i, IRQF_VALID);
  243. }
  244. set_irq_type(EXPIO_PARENT_INT, IRQ_TYPE_LEVEL_LOW);
  245. set_irq_chained_handler(EXPIO_PARENT_INT, mx31_3ds_expio_irq_handler);
  246. return 0;
  247. }
  248. /*
  249. * This structure defines the MX31 memory map.
  250. */
  251. static struct map_desc mx31_3ds_io_desc[] __initdata = {
  252. {
  253. .virtual = MX31_CS5_BASE_ADDR_VIRT,
  254. .pfn = __phys_to_pfn(MX31_CS5_BASE_ADDR),
  255. .length = MX31_CS5_SIZE,
  256. .type = MT_DEVICE,
  257. },
  258. };
  259. /*
  260. * Set up static virtual mappings.
  261. */
  262. static void __init mx31_3ds_map_io(void)
  263. {
  264. mx31_map_io();
  265. iotable_init(mx31_3ds_io_desc, ARRAY_SIZE(mx31_3ds_io_desc));
  266. }
  267. /*!
  268. * Board specific initialization.
  269. */
  270. static void __init mxc_board_init(void)
  271. {
  272. mxc_iomux_setup_multiple_pins(mx31_3ds_pins, ARRAY_SIZE(mx31_3ds_pins),
  273. "mx31_3ds");
  274. mxc_register_device(&mxc_uart_device0, &uart_pdata);
  275. mxc_register_device(&mxc_nand_device, &imx31_3ds_nand_flash_pdata);
  276. mxc_register_device(&mxc_spi_device1, &spi1_pdata);
  277. spi_register_board_info(mx31_3ds_spi_devs,
  278. ARRAY_SIZE(mx31_3ds_spi_devs));
  279. if (!mx31_3ds_init_expio())
  280. platform_device_register(&smsc911x_device);
  281. }
  282. static void __init mx31_3ds_timer_init(void)
  283. {
  284. mx31_clocks_init(26000000);
  285. }
  286. static struct sys_timer mx31_3ds_timer = {
  287. .init = mx31_3ds_timer_init,
  288. };
  289. /*
  290. * The following uses standard kernel macros defined in arch.h in order to
  291. * initialize __mach_desc_MX31_3DS data structure.
  292. */
  293. MACHINE_START(MX31_3DS, "Freescale MX31PDK (3DS)")
  294. /* Maintainer: Freescale Semiconductor, Inc. */
  295. .phys_io = MX31_AIPS1_BASE_ADDR,
  296. .io_pg_offst = (MX31_AIPS1_BASE_ADDR_VIRT >> 18) & 0xfffc,
  297. .boot_params = MX3x_PHYS_OFFSET + 0x100,
  298. .map_io = mx31_3ds_map_io,
  299. .init_irq = mx31_init_irq,
  300. .init_machine = mxc_board_init,
  301. .timer = &mx31_3ds_timer,
  302. MACHINE_END