mx31ads.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. #include "devices.h"
  36. /*!
  37. * @file mx31ads.c
  38. *
  39. * @brief This file contains the board-specific initialization routines.
  40. *
  41. * @ingroup System
  42. */
  43. #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
  44. /*!
  45. * The serial port definition structure.
  46. */
  47. static struct plat_serial8250_port serial_platform_data[] = {
  48. {
  49. .membase = (void *)(PBC_BASE_ADDRESS + PBC_SC16C652_UARTA),
  50. .mapbase = (unsigned long)(CS4_BASE_ADDR + PBC_SC16C652_UARTA),
  51. .irq = EXPIO_INT_XUART_INTA,
  52. .uartclk = 14745600,
  53. .regshift = 0,
  54. .iotype = UPIO_MEM,
  55. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_AUTO_IRQ,
  56. }, {
  57. .membase = (void *)(PBC_BASE_ADDRESS + PBC_SC16C652_UARTB),
  58. .mapbase = (unsigned long)(CS4_BASE_ADDR + PBC_SC16C652_UARTB),
  59. .irq = EXPIO_INT_XUART_INTB,
  60. .uartclk = 14745600,
  61. .regshift = 0,
  62. .iotype = UPIO_MEM,
  63. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_AUTO_IRQ,
  64. },
  65. {},
  66. };
  67. static struct platform_device serial_device = {
  68. .name = "serial8250",
  69. .id = 0,
  70. .dev = {
  71. .platform_data = serial_platform_data,
  72. },
  73. };
  74. static int __init mxc_init_extuart(void)
  75. {
  76. return platform_device_register(&serial_device);
  77. }
  78. #else
  79. static inline int mxc_init_extuart(void)
  80. {
  81. return 0;
  82. }
  83. #endif
  84. #if defined(CONFIG_SERIAL_IMX) || defined(CONFIG_SERIAL_IMX_MODULE)
  85. static struct imxuart_platform_data uart_pdata = {
  86. .flags = IMXUART_HAVE_RTSCTS,
  87. };
  88. static inline void mxc_init_imx_uart(void)
  89. {
  90. mxc_iomux_mode(MX31_PIN_CTS1__CTS1);
  91. mxc_iomux_mode(MX31_PIN_RTS1__RTS1);
  92. mxc_iomux_mode(MX31_PIN_TXD1__TXD1);
  93. mxc_iomux_mode(MX31_PIN_RXD1__RXD1);
  94. mxc_register_device(&mxc_uart_device0, &uart_pdata);
  95. }
  96. #else /* !SERIAL_IMX */
  97. static inline void mxc_init_imx_uart(void)
  98. {
  99. }
  100. #endif /* !SERIAL_IMX */
  101. static void mx31ads_expio_irq_handler(u32 irq, struct irq_desc *desc)
  102. {
  103. u32 imr_val;
  104. u32 int_valid;
  105. u32 expio_irq;
  106. imr_val = __raw_readw(PBC_INTMASK_SET_REG);
  107. int_valid = __raw_readw(PBC_INTSTATUS_REG) & imr_val;
  108. expio_irq = MXC_EXP_IO_BASE;
  109. for (; int_valid != 0; int_valid >>= 1, expio_irq++) {
  110. if ((int_valid & 1) == 0)
  111. continue;
  112. generic_handle_irq(expio_irq);
  113. }
  114. }
  115. /*
  116. * Disable an expio pin's interrupt by setting the bit in the imr.
  117. * @param irq an expio virtual irq number
  118. */
  119. static void expio_mask_irq(u32 irq)
  120. {
  121. u32 expio = MXC_IRQ_TO_EXPIO(irq);
  122. /* mask the interrupt */
  123. __raw_writew(1 << expio, PBC_INTMASK_CLEAR_REG);
  124. __raw_readw(PBC_INTMASK_CLEAR_REG);
  125. }
  126. /*
  127. * Acknowledge an expanded io pin's interrupt by clearing the bit in the isr.
  128. * @param irq an expanded io virtual irq number
  129. */
  130. static void expio_ack_irq(u32 irq)
  131. {
  132. u32 expio = MXC_IRQ_TO_EXPIO(irq);
  133. /* clear the interrupt status */
  134. __raw_writew(1 << expio, PBC_INTSTATUS_REG);
  135. }
  136. /*
  137. * Enable a expio pin's interrupt by clearing the bit in the imr.
  138. * @param irq a expio virtual irq number
  139. */
  140. static void expio_unmask_irq(u32 irq)
  141. {
  142. u32 expio = MXC_IRQ_TO_EXPIO(irq);
  143. /* unmask the interrupt */
  144. __raw_writew(1 << expio, PBC_INTMASK_SET_REG);
  145. }
  146. static struct irq_chip expio_irq_chip = {
  147. .ack = expio_ack_irq,
  148. .mask = expio_mask_irq,
  149. .unmask = expio_unmask_irq,
  150. };
  151. static void __init mx31ads_init_expio(void)
  152. {
  153. int i;
  154. printk(KERN_INFO "MX31ADS EXPIO(CPLD) hardware\n");
  155. /*
  156. * Configure INT line as GPIO input
  157. */
  158. mxc_iomux_mode(IOMUX_MODE(MX31_PIN_GPIO1_4, IOMUX_CONFIG_GPIO));
  159. /* disable the interrupt and clear the status */
  160. __raw_writew(0xFFFF, PBC_INTMASK_CLEAR_REG);
  161. __raw_writew(0xFFFF, PBC_INTSTATUS_REG);
  162. for (i = MXC_EXP_IO_BASE; i < (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES);
  163. i++) {
  164. set_irq_chip(i, &expio_irq_chip);
  165. set_irq_handler(i, handle_level_irq);
  166. set_irq_flags(i, IRQF_VALID);
  167. }
  168. set_irq_type(EXPIO_PARENT_INT, IRQ_TYPE_LEVEL_HIGH);
  169. set_irq_chained_handler(EXPIO_PARENT_INT, mx31ads_expio_irq_handler);
  170. }
  171. /*!
  172. * This structure defines static mappings for the i.MX31ADS board.
  173. */
  174. static struct map_desc mx31ads_io_desc[] __initdata = {
  175. {
  176. .virtual = AIPS1_BASE_ADDR_VIRT,
  177. .pfn = __phys_to_pfn(AIPS1_BASE_ADDR),
  178. .length = AIPS1_SIZE,
  179. .type = MT_DEVICE_NONSHARED
  180. }, {
  181. .virtual = SPBA0_BASE_ADDR_VIRT,
  182. .pfn = __phys_to_pfn(SPBA0_BASE_ADDR),
  183. .length = SPBA0_SIZE,
  184. .type = MT_DEVICE_NONSHARED
  185. }, {
  186. .virtual = AIPS2_BASE_ADDR_VIRT,
  187. .pfn = __phys_to_pfn(AIPS2_BASE_ADDR),
  188. .length = AIPS2_SIZE,
  189. .type = MT_DEVICE_NONSHARED
  190. }, {
  191. .virtual = CS4_BASE_ADDR_VIRT,
  192. .pfn = __phys_to_pfn(CS4_BASE_ADDR),
  193. .length = CS4_SIZE / 2,
  194. .type = MT_DEVICE
  195. },
  196. };
  197. /*!
  198. * Set up static virtual mappings.
  199. */
  200. void __init mx31ads_map_io(void)
  201. {
  202. mxc_map_io();
  203. iotable_init(mx31ads_io_desc, ARRAY_SIZE(mx31ads_io_desc));
  204. }
  205. void __init mx31ads_init_irq(void)
  206. {
  207. mxc_init_irq();
  208. mx31ads_init_expio();
  209. }
  210. /*!
  211. * Board specific initialization.
  212. */
  213. static void __init mxc_board_init(void)
  214. {
  215. mxc_init_extuart();
  216. mxc_init_imx_uart();
  217. }
  218. static void __init mx31ads_timer_init(void)
  219. {
  220. mxc_clocks_init(26000000);
  221. mxc_timer_init("ipg_clk.0");
  222. }
  223. struct sys_timer mx31ads_timer = {
  224. .init = mx31ads_timer_init,
  225. };
  226. /*
  227. * The following uses standard kernel macros defined in arch.h in order to
  228. * initialize __mach_desc_MX31ADS data structure.
  229. */
  230. MACHINE_START(MX31ADS, "Freescale MX31ADS")
  231. /* Maintainer: Freescale Semiconductor, Inc. */
  232. .phys_io = AIPS1_BASE_ADDR,
  233. .io_pg_offst = ((AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
  234. .boot_params = PHYS_OFFSET + 0x100,
  235. .map_io = mx31ads_map_io,
  236. .init_irq = mx31ads_init_irq,
  237. .init_machine = mxc_board_init,
  238. .timer = &mx31ads_timer,
  239. MACHINE_END