common.c 8.2 KB

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