common.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. }
  117. ixp4xx_config_irq(irq, irq_type);
  118. if (line >= 8) { /* pins 8-15 */
  119. line -= 8;
  120. int_reg = IXP4XX_GPIO_GPIT2R;
  121. } else { /* pins 0-7 */
  122. int_reg = IXP4XX_GPIO_GPIT1R;
  123. }
  124. /* Clear the style for the appropriate pin */
  125. *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
  126. (line * IXP4XX_GPIO_STYLE_SIZE));
  127. /* Set the new style */
  128. *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
  129. }
  130. static void ixp4xx_irq_mask(unsigned int irq)
  131. {
  132. if (cpu_is_ixp46x() && irq >= 32)
  133. *IXP4XX_ICMR2 &= ~(1 << (irq - 32));
  134. else
  135. *IXP4XX_ICMR &= ~(1 << irq);
  136. }
  137. static void ixp4xx_irq_unmask(unsigned int irq)
  138. {
  139. if (cpu_is_ixp46x() && irq >= 32)
  140. *IXP4XX_ICMR2 |= (1 << (irq - 32));
  141. else
  142. *IXP4XX_ICMR |= (1 << irq);
  143. }
  144. static void ixp4xx_irq_ack(unsigned int irq)
  145. {
  146. int line = (irq < 32) ? irq2gpio[irq] : -1;
  147. if (line >= 0)
  148. gpio_line_isr_clear(line);
  149. }
  150. /*
  151. * Level triggered interrupts on GPIO lines can only be cleared when the
  152. * interrupt condition disappears.
  153. */
  154. static void ixp4xx_irq_level_unmask(unsigned int irq)
  155. {
  156. ixp4xx_irq_ack(irq);
  157. ixp4xx_irq_unmask(irq);
  158. }
  159. static struct irqchip ixp4xx_irq_level_chip = {
  160. .ack = ixp4xx_irq_mask,
  161. .mask = ixp4xx_irq_mask,
  162. .unmask = ixp4xx_irq_level_unmask,
  163. .set_type = ixp4xx_set_irq_type,
  164. };
  165. static struct irqchip ixp4xx_irq_edge_chip = {
  166. .ack = ixp4xx_irq_ack,
  167. .mask = ixp4xx_irq_mask,
  168. .unmask = ixp4xx_irq_unmask,
  169. .set_type = ixp4xx_set_irq_type,
  170. };
  171. static void ixp4xx_config_irq(unsigned irq, enum ixp4xx_irq_type type)
  172. {
  173. switch (type) {
  174. case IXP4XX_IRQ_LEVEL:
  175. set_irq_chip(irq, &ixp4xx_irq_level_chip);
  176. set_irq_handler(irq, do_level_IRQ);
  177. break;
  178. case IXP4XX_IRQ_EDGE:
  179. set_irq_chip(irq, &ixp4xx_irq_edge_chip);
  180. set_irq_handler(irq, do_edge_IRQ);
  181. break;
  182. }
  183. set_irq_flags(irq, IRQF_VALID);
  184. }
  185. void __init ixp4xx_init_irq(void)
  186. {
  187. int i = 0;
  188. /* Route all sources to IRQ instead of FIQ */
  189. *IXP4XX_ICLR = 0x0;
  190. /* Disable all interrupt */
  191. *IXP4XX_ICMR = 0x0;
  192. if (cpu_is_ixp46x()) {
  193. /* Route upper 32 sources to IRQ instead of FIQ */
  194. *IXP4XX_ICLR2 = 0x00;
  195. /* Disable upper 32 interrupts */
  196. *IXP4XX_ICMR2 = 0x00;
  197. }
  198. /* Default to all level triggered */
  199. for(i = 0; i < NR_IRQS; i++)
  200. ixp4xx_config_irq(i, IXP4XX_IRQ_LEVEL);
  201. }
  202. /*************************************************************************
  203. * IXP4xx timer tick
  204. * We use OS timer1 on the CPU for the timer tick and the timestamp
  205. * counter as a source of real clock ticks to account for missed jiffies.
  206. *************************************************************************/
  207. static unsigned volatile last_jiffy_time;
  208. #define CLOCK_TICKS_PER_USEC ((CLOCK_TICK_RATE + USEC_PER_SEC/2) / USEC_PER_SEC)
  209. /* IRQs are disabled before entering here from do_gettimeofday() */
  210. static unsigned long ixp4xx_gettimeoffset(void)
  211. {
  212. u32 elapsed;
  213. elapsed = *IXP4XX_OSTS - last_jiffy_time;
  214. return elapsed / CLOCK_TICKS_PER_USEC;
  215. }
  216. static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  217. {
  218. write_seqlock(&xtime_lock);
  219. /* Clear Pending Interrupt by writing '1' to it */
  220. *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
  221. /*
  222. * Catch up with the real idea of time
  223. */
  224. while ((*IXP4XX_OSTS - last_jiffy_time) > LATCH) {
  225. timer_tick(regs);
  226. last_jiffy_time += LATCH;
  227. }
  228. write_sequnlock(&xtime_lock);
  229. return IRQ_HANDLED;
  230. }
  231. static struct irqaction ixp4xx_timer_irq = {
  232. .name = "IXP4xx Timer Tick",
  233. .flags = SA_INTERRUPT | SA_TIMER,
  234. .handler = ixp4xx_timer_interrupt,
  235. };
  236. static void __init ixp4xx_timer_init(void)
  237. {
  238. /* Clear Pending Interrupt by writing '1' to it */
  239. *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
  240. /* Setup the Timer counter value */
  241. *IXP4XX_OSRT1 = (LATCH & ~IXP4XX_OST_RELOAD_MASK) | IXP4XX_OST_ENABLE;
  242. /* Reset time-stamp counter */
  243. *IXP4XX_OSTS = 0;
  244. last_jiffy_time = 0;
  245. /* Connect the interrupt handler and enable the interrupt */
  246. setup_irq(IRQ_IXP4XX_TIMER1, &ixp4xx_timer_irq);
  247. }
  248. struct sys_timer ixp4xx_timer = {
  249. .init = ixp4xx_timer_init,
  250. .offset = ixp4xx_gettimeoffset,
  251. };
  252. static struct resource ixp46x_i2c_resources[] = {
  253. [0] = {
  254. .start = 0xc8011000,
  255. .end = 0xc801101c,
  256. .flags = IORESOURCE_MEM,
  257. },
  258. [1] = {
  259. .start = IRQ_IXP4XX_I2C,
  260. .end = IRQ_IXP4XX_I2C,
  261. .flags = IORESOURCE_IRQ
  262. }
  263. };
  264. /*
  265. * I2C controller. The IXP46x uses the same block as the IOP3xx, so
  266. * we just use the same device name.
  267. */
  268. static struct platform_device ixp46x_i2c_controller = {
  269. .name = "IOP3xx-I2C",
  270. .id = 0,
  271. .num_resources = 2,
  272. .resource = ixp46x_i2c_resources
  273. };
  274. static struct platform_device *ixp46x_devices[] __initdata = {
  275. &ixp46x_i2c_controller
  276. };
  277. void __init ixp4xx_sys_init(void)
  278. {
  279. if (cpu_is_ixp46x()) {
  280. platform_add_devices(ixp46x_devices,
  281. ARRAY_SIZE(ixp46x_devices));
  282. }
  283. }