common.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * linux/arch/arm/mach-h720x/common.c
  3. *
  4. * Copyright (C) 2003 Thomas Gleixner <tglx@linutronix.de>
  5. * 2003 Robert Schwebel <r.schwebel@pengutronix.de>
  6. * 2004 Sascha Hauer <s.hauer@pengutronix.de>
  7. *
  8. * common stuff for Hynix h720x processors
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. */
  15. #include <linux/sched.h>
  16. #include <linux/mman.h>
  17. #include <linux/init.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/io.h>
  20. #include <asm/page.h>
  21. #include <asm/pgtable.h>
  22. #include <asm/dma.h>
  23. #include <mach/hardware.h>
  24. #include <asm/irq.h>
  25. #include <asm/mach/irq.h>
  26. #include <asm/mach/map.h>
  27. #include <mach/irqs.h>
  28. #include <asm/mach/dma.h>
  29. #if 0
  30. #define IRQDBG(args...) printk(args)
  31. #else
  32. #define IRQDBG(args...) do {} while(0)
  33. #endif
  34. void __init arch_dma_init(dma_t *dma)
  35. {
  36. }
  37. /*
  38. * Return usecs since last timer reload
  39. * (timercount * (usecs perjiffie)) / (ticks per jiffie)
  40. */
  41. unsigned long h720x_gettimeoffset(void)
  42. {
  43. return (CPU_REG (TIMER_VIRT, TM0_COUNT) * tick_usec) / LATCH;
  44. }
  45. /*
  46. * mask Global irq's
  47. */
  48. static void mask_global_irq(struct irq_data *d)
  49. {
  50. CPU_REG (IRQC_VIRT, IRQC_IER) &= ~(1 << d->irq);
  51. }
  52. /*
  53. * unmask Global irq's
  54. */
  55. static void unmask_global_irq(struct irq_data *d)
  56. {
  57. CPU_REG (IRQC_VIRT, IRQC_IER) |= (1 << d->irq);
  58. }
  59. /*
  60. * ack GPIO irq's
  61. * Ack only for edge triggered int's valid
  62. */
  63. static void inline ack_gpio_irq(struct irq_data *d)
  64. {
  65. u32 reg_base = GPIO_VIRT(IRQ_TO_REGNO(d->irq));
  66. u32 bit = IRQ_TO_BIT(d->irq);
  67. if ( (CPU_REG (reg_base, GPIO_EDGE) & bit))
  68. CPU_REG (reg_base, GPIO_CLR) = bit;
  69. }
  70. /*
  71. * mask GPIO irq's
  72. */
  73. static void inline mask_gpio_irq(struct irq_data *d)
  74. {
  75. u32 reg_base = GPIO_VIRT(IRQ_TO_REGNO(d->irq));
  76. u32 bit = IRQ_TO_BIT(d->irq);
  77. CPU_REG (reg_base, GPIO_MASK) &= ~bit;
  78. }
  79. /*
  80. * unmask GPIO irq's
  81. */
  82. static void inline unmask_gpio_irq(struct irq_data *d)
  83. {
  84. u32 reg_base = GPIO_VIRT(IRQ_TO_REGNO(d->irq));
  85. u32 bit = IRQ_TO_BIT(d->irq);
  86. CPU_REG (reg_base, GPIO_MASK) |= bit;
  87. }
  88. static void
  89. h720x_gpio_handler(unsigned int mask, unsigned int irq,
  90. struct irq_desc *desc)
  91. {
  92. IRQDBG("%s irq: %d\n", __func__, irq);
  93. while (mask) {
  94. if (mask & 1) {
  95. IRQDBG("handling irq %d\n", irq);
  96. generic_handle_irq(irq);
  97. }
  98. irq++;
  99. mask >>= 1;
  100. }
  101. }
  102. static void
  103. h720x_gpioa_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  104. {
  105. unsigned int mask, irq;
  106. mask = CPU_REG(GPIO_A_VIRT,GPIO_STAT);
  107. irq = IRQ_CHAINED_GPIOA(0);
  108. IRQDBG("%s mask: 0x%08x irq: %d\n", __func__, mask,irq);
  109. h720x_gpio_handler(mask, irq, desc);
  110. }
  111. static void
  112. h720x_gpiob_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  113. {
  114. unsigned int mask, irq;
  115. mask = CPU_REG(GPIO_B_VIRT,GPIO_STAT);
  116. irq = IRQ_CHAINED_GPIOB(0);
  117. IRQDBG("%s mask: 0x%08x irq: %d\n", __func__, mask,irq);
  118. h720x_gpio_handler(mask, irq, desc);
  119. }
  120. static void
  121. h720x_gpioc_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  122. {
  123. unsigned int mask, irq;
  124. mask = CPU_REG(GPIO_C_VIRT,GPIO_STAT);
  125. irq = IRQ_CHAINED_GPIOC(0);
  126. IRQDBG("%s mask: 0x%08x irq: %d\n", __func__, mask,irq);
  127. h720x_gpio_handler(mask, irq, desc);
  128. }
  129. static void
  130. h720x_gpiod_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  131. {
  132. unsigned int mask, irq;
  133. mask = CPU_REG(GPIO_D_VIRT,GPIO_STAT);
  134. irq = IRQ_CHAINED_GPIOD(0);
  135. IRQDBG("%s mask: 0x%08x irq: %d\n", __func__, mask,irq);
  136. h720x_gpio_handler(mask, irq, desc);
  137. }
  138. #ifdef CONFIG_CPU_H7202
  139. static void
  140. h720x_gpioe_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  141. {
  142. unsigned int mask, irq;
  143. mask = CPU_REG(GPIO_E_VIRT,GPIO_STAT);
  144. irq = IRQ_CHAINED_GPIOE(0);
  145. IRQDBG("%s mask: 0x%08x irq: %d\n", __func__, mask,irq);
  146. h720x_gpio_handler(mask, irq, desc);
  147. }
  148. #endif
  149. static struct irq_chip h720x_global_chip = {
  150. .irq_ack = mask_global_irq,
  151. .irq_mask = mask_global_irq,
  152. .irq_unmask = unmask_global_irq,
  153. };
  154. static struct irq_chip h720x_gpio_chip = {
  155. .irq_ack = ack_gpio_irq,
  156. .irq_mask = mask_gpio_irq,
  157. .irq_unmask = unmask_gpio_irq,
  158. };
  159. /*
  160. * Initialize IRQ's, mask all, enable multiplexed irq's
  161. */
  162. void __init h720x_init_irq (void)
  163. {
  164. int irq;
  165. /* Mask global irq's */
  166. CPU_REG (IRQC_VIRT, IRQC_IER) = 0x0;
  167. /* Mask all multiplexed irq's */
  168. CPU_REG (GPIO_A_VIRT, GPIO_MASK) = 0x0;
  169. CPU_REG (GPIO_B_VIRT, GPIO_MASK) = 0x0;
  170. CPU_REG (GPIO_C_VIRT, GPIO_MASK) = 0x0;
  171. CPU_REG (GPIO_D_VIRT, GPIO_MASK) = 0x0;
  172. /* Initialize global IRQ's, fast path */
  173. for (irq = 0; irq < NR_GLBL_IRQS; irq++) {
  174. irq_set_chip_and_handler(irq, &h720x_global_chip,
  175. handle_level_irq);
  176. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  177. }
  178. /* Initialize multiplexed IRQ's, slow path */
  179. for (irq = IRQ_CHAINED_GPIOA(0) ; irq <= IRQ_CHAINED_GPIOD(31); irq++) {
  180. irq_set_chip_and_handler(irq, &h720x_gpio_chip,
  181. handle_edge_irq);
  182. set_irq_flags(irq, IRQF_VALID );
  183. }
  184. irq_set_chained_handler(IRQ_GPIOA, h720x_gpioa_demux_handler);
  185. irq_set_chained_handler(IRQ_GPIOB, h720x_gpiob_demux_handler);
  186. irq_set_chained_handler(IRQ_GPIOC, h720x_gpioc_demux_handler);
  187. irq_set_chained_handler(IRQ_GPIOD, h720x_gpiod_demux_handler);
  188. #ifdef CONFIG_CPU_H7202
  189. for (irq = IRQ_CHAINED_GPIOE(0) ; irq <= IRQ_CHAINED_GPIOE(31); irq++) {
  190. irq_set_chip_and_handler(irq, &h720x_gpio_chip,
  191. handle_edge_irq);
  192. set_irq_flags(irq, IRQF_VALID );
  193. }
  194. irq_set_chained_handler(IRQ_GPIOE, h720x_gpioe_demux_handler);
  195. #endif
  196. /* Enable multiplexed irq's */
  197. CPU_REG (IRQC_VIRT, IRQC_IER) = IRQ_ENA_MUX;
  198. }
  199. static struct map_desc h720x_io_desc[] __initdata = {
  200. {
  201. .virtual = IO_VIRT,
  202. .pfn = __phys_to_pfn(IO_PHYS),
  203. .length = IO_SIZE,
  204. .type = MT_DEVICE
  205. },
  206. };
  207. /* Initialize io tables */
  208. void __init h720x_map_io(void)
  209. {
  210. iotable_init(h720x_io_desc,ARRAY_SIZE(h720x_io_desc));
  211. }