mx31ads.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Copyright (C) 2000 Deep Blue Solutions Ltd
  3. * Copyright (C) 2002 Shane Nay (shane@minirl.com)
  4. * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/types.h>
  21. #include <linux/init.h>
  22. #include <linux/clk.h>
  23. #include <linux/serial_8250.h>
  24. #include <linux/irq.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-mx31ads.h>
  33. #include <mach/imx-uart.h>
  34. #include <mach/iomux-mx3.h>
  35. /*!
  36. * @file mx31ads.c
  37. *
  38. * @brief This file contains the board-specific initialization routines.
  39. *
  40. * @ingroup System
  41. */
  42. #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
  43. /*!
  44. * The serial port definition structure.
  45. */
  46. static struct plat_serial8250_port serial_platform_data[] = {
  47. {
  48. .membase = (void *)(PBC_BASE_ADDRESS + PBC_SC16C652_UARTA),
  49. .mapbase = (unsigned long)(CS4_BASE_ADDR + PBC_SC16C652_UARTA),
  50. .irq = EXPIO_INT_XUART_INTA,
  51. .uartclk = 14745600,
  52. .regshift = 0,
  53. .iotype = UPIO_MEM,
  54. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_AUTO_IRQ,
  55. }, {
  56. .membase = (void *)(PBC_BASE_ADDRESS + PBC_SC16C652_UARTB),
  57. .mapbase = (unsigned long)(CS4_BASE_ADDR + PBC_SC16C652_UARTB),
  58. .irq = EXPIO_INT_XUART_INTB,
  59. .uartclk = 14745600,
  60. .regshift = 0,
  61. .iotype = UPIO_MEM,
  62. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_AUTO_IRQ,
  63. },
  64. {},
  65. };
  66. static struct platform_device serial_device = {
  67. .name = "serial8250",
  68. .id = 0,
  69. .dev = {
  70. .platform_data = serial_platform_data,
  71. },
  72. };
  73. static int __init mxc_init_extuart(void)
  74. {
  75. return platform_device_register(&serial_device);
  76. }
  77. #else
  78. static inline int mxc_init_extuart(void)
  79. {
  80. return 0;
  81. }
  82. #endif
  83. #if defined(CONFIG_SERIAL_IMX) || defined(CONFIG_SERIAL_IMX_MODULE)
  84. static struct imxuart_platform_data uart_pdata = {
  85. .flags = IMXUART_HAVE_RTSCTS,
  86. };
  87. static inline void mxc_init_imx_uart(void)
  88. {
  89. mxc_iomux_mode(MX31_PIN_CTS1__CTS1);
  90. mxc_iomux_mode(MX31_PIN_RTS1__RTS1);
  91. mxc_iomux_mode(MX31_PIN_TXD1__TXD1);
  92. mxc_iomux_mode(MX31_PIN_RXD1__RXD1);
  93. mxc_register_device(&mxc_uart_device0, &uart_pdata);
  94. }
  95. #else /* !SERIAL_IMX */
  96. static inline void mxc_init_imx_uart(void)
  97. {
  98. }
  99. #endif /* !SERIAL_IMX */
  100. static void mx31ads_expio_irq_handler(u32 irq, struct irq_desc *desc)
  101. {
  102. u32 imr_val;
  103. u32 int_valid;
  104. u32 expio_irq;
  105. imr_val = __raw_readw(PBC_INTMASK_SET_REG);
  106. int_valid = __raw_readw(PBC_INTSTATUS_REG) & imr_val;
  107. expio_irq = MXC_EXP_IO_BASE;
  108. for (; int_valid != 0; int_valid >>= 1, expio_irq++) {
  109. if ((int_valid & 1) == 0)
  110. continue;
  111. generic_handle_irq(expio_irq);
  112. }
  113. }
  114. /*
  115. * Disable an expio pin's interrupt by setting the bit in the imr.
  116. * @param irq an expio virtual irq number
  117. */
  118. static void expio_mask_irq(u32 irq)
  119. {
  120. u32 expio = MXC_IRQ_TO_EXPIO(irq);
  121. /* mask the interrupt */
  122. __raw_writew(1 << expio, PBC_INTMASK_CLEAR_REG);
  123. __raw_readw(PBC_INTMASK_CLEAR_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(u32 irq)
  130. {
  131. u32 expio = MXC_IRQ_TO_EXPIO(irq);
  132. /* clear the interrupt status */
  133. __raw_writew(1 << expio, PBC_INTSTATUS_REG);
  134. }
  135. /*
  136. * Enable a expio pin's interrupt by clearing the bit in the imr.
  137. * @param irq a expio virtual irq number
  138. */
  139. static void expio_unmask_irq(u32 irq)
  140. {
  141. u32 expio = MXC_IRQ_TO_EXPIO(irq);
  142. /* unmask the interrupt */
  143. __raw_writew(1 << expio, PBC_INTMASK_SET_REG);
  144. }
  145. static struct irq_chip expio_irq_chip = {
  146. .ack = expio_ack_irq,
  147. .mask = expio_mask_irq,
  148. .unmask = expio_unmask_irq,
  149. };
  150. static void __init mx31ads_init_expio(void)
  151. {
  152. int i;
  153. printk(KERN_INFO "MX31ADS EXPIO(CPLD) hardware\n");
  154. /*
  155. * Configure INT line as GPIO input
  156. */
  157. mxc_iomux_mode(IOMUX_MODE(MX31_PIN_GPIO1_4, IOMUX_CONFIG_GPIO));
  158. /* disable the interrupt and clear the status */
  159. __raw_writew(0xFFFF, PBC_INTMASK_CLEAR_REG);
  160. __raw_writew(0xFFFF, PBC_INTSTATUS_REG);
  161. for (i = MXC_EXP_IO_BASE; i < (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES);
  162. i++) {
  163. set_irq_chip(i, &expio_irq_chip);
  164. set_irq_handler(i, handle_level_irq);
  165. set_irq_flags(i, IRQF_VALID);
  166. }
  167. set_irq_type(EXPIO_PARENT_INT, IRQ_TYPE_LEVEL_HIGH);
  168. set_irq_chained_handler(EXPIO_PARENT_INT, mx31ads_expio_irq_handler);
  169. }
  170. /*!
  171. * This structure defines static mappings for the i.MX31ADS board.
  172. */
  173. static struct map_desc mx31ads_io_desc[] __initdata = {
  174. {
  175. .virtual = AIPS1_BASE_ADDR_VIRT,
  176. .pfn = __phys_to_pfn(AIPS1_BASE_ADDR),
  177. .length = AIPS1_SIZE,
  178. .type = MT_DEVICE_NONSHARED
  179. }, {
  180. .virtual = SPBA0_BASE_ADDR_VIRT,
  181. .pfn = __phys_to_pfn(SPBA0_BASE_ADDR),
  182. .length = SPBA0_SIZE,
  183. .type = MT_DEVICE_NONSHARED
  184. }, {
  185. .virtual = AIPS2_BASE_ADDR_VIRT,
  186. .pfn = __phys_to_pfn(AIPS2_BASE_ADDR),
  187. .length = AIPS2_SIZE,
  188. .type = MT_DEVICE_NONSHARED
  189. }, {
  190. .virtual = CS4_BASE_ADDR_VIRT,
  191. .pfn = __phys_to_pfn(CS4_BASE_ADDR),
  192. .length = CS4_SIZE / 2,
  193. .type = MT_DEVICE
  194. },
  195. };
  196. /*!
  197. * Set up static virtual mappings.
  198. */
  199. void __init mx31ads_map_io(void)
  200. {
  201. mxc_map_io();
  202. iotable_init(mx31ads_io_desc, ARRAY_SIZE(mx31ads_io_desc));
  203. }
  204. void __init mx31ads_init_irq(void)
  205. {
  206. mxc_init_irq();
  207. mx31ads_init_expio();
  208. }
  209. /*!
  210. * Board specific initialization.
  211. */
  212. static void __init mxc_board_init(void)
  213. {
  214. mxc_init_extuart();
  215. mxc_init_imx_uart();
  216. }
  217. static void __init mx31ads_timer_init(void)
  218. {
  219. mxc_clocks_init(26000000);
  220. mxc_timer_init("ipg_clk.0");
  221. }
  222. struct sys_timer mx31ads_timer = {
  223. .init = mx31ads_timer_init,
  224. };
  225. /*
  226. * The following uses standard kernel macros defined in arch.h in order to
  227. * initialize __mach_desc_MX31ADS data structure.
  228. */
  229. MACHINE_START(MX31ADS, "Freescale MX31ADS")
  230. /* Maintainer: Freescale Semiconductor, Inc. */
  231. .phys_io = AIPS1_BASE_ADDR,
  232. .io_pg_offst = ((AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
  233. .boot_params = PHYS_OFFSET + 0x100,
  234. .map_io = mx31ads_map_io,
  235. .init_irq = mx31ads_init_irq,
  236. .init_machine = mxc_board_init,
  237. .timer = &mx31ads_timer,
  238. MACHINE_END