mach-mx31_3ds.c 7.5 KB

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