mach-mx31_3ds.c 7.0 KB

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