common.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*
  2. * arch/arm/mach-ixp4xx/common.c
  3. *
  4. * Generic code shared across all IXP4XX platforms
  5. *
  6. * Maintainer: Deepak Saxena <dsaxena@plexity.net>
  7. *
  8. * Copyright 2002 (c) Intel Corporation
  9. * Copyright 2003-2004 (c) MontaVista, Software, Inc.
  10. *
  11. * This file is licensed under the terms of the GNU General Public
  12. * License version 2. This program is licensed "as is" without any
  13. * warranty of any kind, whether express or implied.
  14. */
  15. #include <linux/config.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mm.h>
  18. #include <linux/init.h>
  19. #include <linux/serial.h>
  20. #include <linux/sched.h>
  21. #include <linux/tty.h>
  22. #include <linux/serial_core.h>
  23. #include <linux/bootmem.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/bitops.h>
  26. #include <linux/time.h>
  27. #include <linux/timex.h>
  28. #include <asm/hardware.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/io.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/page.h>
  33. #include <asm/irq.h>
  34. #include <asm/mach/map.h>
  35. #include <asm/mach/irq.h>
  36. #include <asm/mach/time.h>
  37. /*************************************************************************
  38. * IXP4xx chipset I/O mapping
  39. *************************************************************************/
  40. static struct map_desc ixp4xx_io_desc[] __initdata = {
  41. { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
  42. .virtual = IXP4XX_PERIPHERAL_BASE_VIRT,
  43. .physical = IXP4XX_PERIPHERAL_BASE_PHYS,
  44. .length = IXP4XX_PERIPHERAL_REGION_SIZE,
  45. .type = MT_DEVICE
  46. }, { /* Expansion Bus Config Registers */
  47. .virtual = IXP4XX_EXP_CFG_BASE_VIRT,
  48. .physical = IXP4XX_EXP_CFG_BASE_PHYS,
  49. .length = IXP4XX_EXP_CFG_REGION_SIZE,
  50. .type = MT_DEVICE
  51. }, { /* PCI Registers */
  52. .virtual = IXP4XX_PCI_CFG_BASE_VIRT,
  53. .physical = IXP4XX_PCI_CFG_BASE_PHYS,
  54. .length = IXP4XX_PCI_CFG_REGION_SIZE,
  55. .type = MT_DEVICE
  56. },
  57. #ifdef CONFIG_DEBUG_LL
  58. { /* Debug UART mapping */
  59. .virtual = IXP4XX_DEBUG_UART_BASE_VIRT,
  60. .physical = IXP4XX_DEBUG_UART_BASE_PHYS,
  61. .length = IXP4XX_DEBUG_UART_REGION_SIZE,
  62. .type = MT_DEVICE
  63. }
  64. #endif
  65. };
  66. void __init ixp4xx_map_io(void)
  67. {
  68. iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
  69. }
  70. /*************************************************************************
  71. * IXP4xx chipset IRQ handling
  72. *
  73. * TODO: GPIO IRQs should be marked invalid until the user of the IRQ
  74. * (be it PCI or something else) configures that GPIO line
  75. * as an IRQ.
  76. **************************************************************************/
  77. enum ixp4xx_irq_type {
  78. IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
  79. };
  80. static void ixp4xx_config_irq(unsigned irq, enum ixp4xx_irq_type type);
  81. /*
  82. * IRQ -> GPIO mapping table
  83. */
  84. static int irq2gpio[32] = {
  85. -1, -1, -1, -1, -1, -1, 0, 1,
  86. -1, -1, -1, -1, -1, -1, -1, -1,
  87. -1, -1, -1, 2, 3, 4, 5, 6,
  88. 7, 8, 9, 10, 11, 12, -1, -1,
  89. };
  90. static int ixp4xx_set_irq_type(unsigned int irq, unsigned int type)
  91. {
  92. int line = irq2gpio[irq];
  93. u32 int_style;
  94. enum ixp4xx_irq_type irq_type;
  95. volatile u32 *int_reg;
  96. /*
  97. * Only for GPIO IRQs
  98. */
  99. if (line < 0)
  100. return -EINVAL;
  101. if (type & IRQT_BOTHEDGE) {
  102. int_style = IXP4XX_GPIO_STYLE_TRANSITIONAL;
  103. irq_type = IXP4XX_IRQ_EDGE;
  104. } else if (type & IRQT_RISING) {
  105. int_style = IXP4XX_GPIO_STYLE_RISING_EDGE;
  106. irq_type = IXP4XX_IRQ_EDGE;
  107. } else if (type & IRQT_FALLING) {
  108. int_style = IXP4XX_GPIO_STYLE_FALLING_EDGE;
  109. irq_type = IXP4XX_IRQ_EDGE;
  110. } else if (type & IRQT_HIGH) {
  111. int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
  112. irq_type = IXP4XX_IRQ_LEVEL;
  113. } else if (type & IRQT_LOW) {
  114. int_style = IXP4XX_GPIO_STYLE_ACTIVE_LOW;
  115. irq_type = IXP4XX_IRQ_LEVEL;
  116. } else
  117. return -EINVAL;
  118. ixp4xx_config_irq(irq, irq_type);
  119. if (line >= 8) { /* pins 8-15 */
  120. line -= 8;
  121. int_reg = IXP4XX_GPIO_GPIT2R;
  122. } else { /* pins 0-7 */
  123. int_reg = IXP4XX_GPIO_GPIT1R;
  124. }
  125. /* Clear the style for the appropriate pin */
  126. *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
  127. (line * IXP4XX_GPIO_STYLE_SIZE));
  128. /* Set the new style */
  129. *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
  130. return 0;
  131. }
  132. static void ixp4xx_irq_mask(unsigned int irq)
  133. {
  134. if (cpu_is_ixp46x() && irq >= 32)
  135. *IXP4XX_ICMR2 &= ~(1 << (irq - 32));
  136. else
  137. *IXP4XX_ICMR &= ~(1 << irq);
  138. }
  139. static void ixp4xx_irq_unmask(unsigned int irq)
  140. {
  141. if (cpu_is_ixp46x() && irq >= 32)
  142. *IXP4XX_ICMR2 |= (1 << (irq - 32));
  143. else
  144. *IXP4XX_ICMR |= (1 << irq);
  145. }
  146. static void ixp4xx_irq_ack(unsigned int irq)
  147. {
  148. int line = (irq < 32) ? irq2gpio[irq] : -1;
  149. if (line >= 0)
  150. gpio_line_isr_clear(line);
  151. }
  152. /*
  153. * Level triggered interrupts on GPIO lines can only be cleared when the
  154. * interrupt condition disappears.
  155. */
  156. static void ixp4xx_irq_level_unmask(unsigned int irq)
  157. {
  158. ixp4xx_irq_ack(irq);
  159. ixp4xx_irq_unmask(irq);
  160. }
  161. static struct irqchip ixp4xx_irq_level_chip = {
  162. .ack = ixp4xx_irq_mask,
  163. .mask = ixp4xx_irq_mask,
  164. .unmask = ixp4xx_irq_level_unmask,
  165. .set_type = ixp4xx_set_irq_type,
  166. };
  167. static struct irqchip ixp4xx_irq_edge_chip = {
  168. .ack = ixp4xx_irq_ack,
  169. .mask = ixp4xx_irq_mask,
  170. .unmask = ixp4xx_irq_unmask,
  171. .set_type = ixp4xx_set_irq_type,
  172. };
  173. static void ixp4xx_config_irq(unsigned irq, enum ixp4xx_irq_type type)
  174. {
  175. switch (type) {
  176. case IXP4XX_IRQ_LEVEL:
  177. set_irq_chip(irq, &ixp4xx_irq_level_chip);
  178. set_irq_handler(irq, do_level_IRQ);
  179. break;
  180. case IXP4XX_IRQ_EDGE:
  181. set_irq_chip(irq, &ixp4xx_irq_edge_chip);
  182. set_irq_handler(irq, do_edge_IRQ);
  183. break;
  184. }
  185. set_irq_flags(irq, IRQF_VALID);
  186. }
  187. void __init ixp4xx_init_irq(void)
  188. {
  189. int i = 0;
  190. /* Route all sources to IRQ instead of FIQ */
  191. *IXP4XX_ICLR = 0x0;
  192. /* Disable all interrupt */
  193. *IXP4XX_ICMR = 0x0;
  194. if (cpu_is_ixp46x()) {
  195. /* Route upper 32 sources to IRQ instead of FIQ */
  196. *IXP4XX_ICLR2 = 0x00;
  197. /* Disable upper 32 interrupts */
  198. *IXP4XX_ICMR2 = 0x00;
  199. }
  200. /* Default to all level triggered */
  201. for(i = 0; i < NR_IRQS; i++)
  202. ixp4xx_config_irq(i, IXP4XX_IRQ_LEVEL);
  203. }
  204. /*************************************************************************
  205. * IXP4xx timer tick
  206. * We use OS timer1 on the CPU for the timer tick and the timestamp
  207. * counter as a source of real clock ticks to account for missed jiffies.
  208. *************************************************************************/
  209. static unsigned volatile last_jiffy_time;
  210. #define CLOCK_TICKS_PER_USEC ((CLOCK_TICK_RATE + USEC_PER_SEC/2) / USEC_PER_SEC)
  211. /* IRQs are disabled before entering here from do_gettimeofday() */
  212. static unsigned long ixp4xx_gettimeoffset(void)
  213. {
  214. u32 elapsed;
  215. elapsed = *IXP4XX_OSTS - last_jiffy_time;
  216. return elapsed / CLOCK_TICKS_PER_USEC;
  217. }
  218. static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  219. {
  220. write_seqlock(&xtime_lock);
  221. /* Clear Pending Interrupt by writing '1' to it */
  222. *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
  223. /*
  224. * Catch up with the real idea of time
  225. */
  226. while ((*IXP4XX_OSTS - last_jiffy_time) > LATCH) {
  227. timer_tick(regs);
  228. last_jiffy_time += LATCH;
  229. }
  230. write_sequnlock(&xtime_lock);
  231. return IRQ_HANDLED;
  232. }
  233. static struct irqaction ixp4xx_timer_irq = {
  234. .name = "IXP4xx Timer Tick",
  235. .flags = SA_INTERRUPT | SA_TIMER,
  236. .handler = ixp4xx_timer_interrupt,
  237. };
  238. static void __init ixp4xx_timer_init(void)
  239. {
  240. /* Clear Pending Interrupt by writing '1' to it */
  241. *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
  242. /* Setup the Timer counter value */
  243. *IXP4XX_OSRT1 = (LATCH & ~IXP4XX_OST_RELOAD_MASK) | IXP4XX_OST_ENABLE;
  244. /* Reset time-stamp counter */
  245. *IXP4XX_OSTS = 0;
  246. last_jiffy_time = 0;
  247. /* Connect the interrupt handler and enable the interrupt */
  248. setup_irq(IRQ_IXP4XX_TIMER1, &ixp4xx_timer_irq);
  249. }
  250. struct sys_timer ixp4xx_timer = {
  251. .init = ixp4xx_timer_init,
  252. .offset = ixp4xx_gettimeoffset,
  253. };
  254. static struct resource ixp46x_i2c_resources[] = {
  255. [0] = {
  256. .start = 0xc8011000,
  257. .end = 0xc801101c,
  258. .flags = IORESOURCE_MEM,
  259. },
  260. [1] = {
  261. .start = IRQ_IXP4XX_I2C,
  262. .end = IRQ_IXP4XX_I2C,
  263. .flags = IORESOURCE_IRQ
  264. }
  265. };
  266. /*
  267. * I2C controller. The IXP46x uses the same block as the IOP3xx, so
  268. * we just use the same device name.
  269. */
  270. static struct platform_device ixp46x_i2c_controller = {
  271. .name = "IOP3xx-I2C",
  272. .id = 0,
  273. .num_resources = 2,
  274. .resource = ixp46x_i2c_resources
  275. };
  276. static struct platform_device *ixp46x_devices[] __initdata = {
  277. &ixp46x_i2c_controller
  278. };
  279. void __init ixp4xx_sys_init(void)
  280. {
  281. if (cpu_is_ixp46x()) {
  282. platform_add_devices(ixp46x_devices,
  283. ARRAY_SIZE(ixp46x_devices));
  284. }
  285. }