generic.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * arch/arm/mach-netx/generic.c
  3. *
  4. * Copyright (C) 2005 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
  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 version 2
  8. * as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/device.h>
  20. #include <linux/init.h>
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/platform_device.h>
  24. #include <asm/hardware.h>
  25. #include <asm/mach/map.h>
  26. #include <asm/hardware/vic.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/netx-regs.h>
  29. #include <asm/mach/irq.h>
  30. static struct map_desc netx_io_desc[] __initdata = {
  31. {
  32. .virtual = NETX_IO_VIRT,
  33. .pfn = __phys_to_pfn(NETX_IO_PHYS),
  34. .length = NETX_IO_SIZE,
  35. .type = MT_DEVICE
  36. }
  37. };
  38. void __init netx_map_io(void)
  39. {
  40. iotable_init(netx_io_desc, ARRAY_SIZE(netx_io_desc));
  41. }
  42. static struct resource netx_rtc_resources[] = {
  43. [0] = {
  44. .start = 0x00101200,
  45. .end = 0x00101220,
  46. .flags = IORESOURCE_MEM,
  47. },
  48. };
  49. static struct platform_device netx_rtc_device = {
  50. .name = "netx-rtc",
  51. .id = 0,
  52. .num_resources = ARRAY_SIZE(netx_rtc_resources),
  53. .resource = netx_rtc_resources,
  54. };
  55. static struct platform_device *devices[] __initdata = {
  56. &netx_rtc_device,
  57. };
  58. #if 0
  59. #define DEBUG_IRQ(fmt...) printk(fmt)
  60. #else
  61. #define DEBUG_IRQ(fmt...) while (0) {}
  62. #endif
  63. static void
  64. netx_hif_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  65. {
  66. unsigned int irq = NETX_IRQ_HIF_CHAINED(0);
  67. unsigned int stat;
  68. stat = ((readl(NETX_DPMAS_INT_EN) &
  69. readl(NETX_DPMAS_INT_STAT)) >> 24) & 0x1f;
  70. desc = irq_desc + NETX_IRQ_HIF_CHAINED(0);
  71. while (stat) {
  72. if (stat & 1) {
  73. DEBUG_IRQ("handling irq %d\n", irq);
  74. desc_handle_irq(irq, desc);
  75. }
  76. irq++;
  77. desc++;
  78. stat >>= 1;
  79. }
  80. }
  81. static int
  82. netx_hif_irq_type(unsigned int _irq, unsigned int type)
  83. {
  84. unsigned int val, irq;
  85. val = readl(NETX_DPMAS_IF_CONF1);
  86. irq = _irq - NETX_IRQ_HIF_CHAINED(0);
  87. if (type & __IRQT_RISEDGE) {
  88. DEBUG_IRQ("rising edges\n");
  89. val |= (1 << 26) << irq;
  90. }
  91. if (type & __IRQT_FALEDGE) {
  92. DEBUG_IRQ("falling edges\n");
  93. val &= ~((1 << 26) << irq);
  94. }
  95. if (type & __IRQT_LOWLVL) {
  96. DEBUG_IRQ("low level\n");
  97. val &= ~((1 << 26) << irq);
  98. }
  99. if (type & __IRQT_HIGHLVL) {
  100. DEBUG_IRQ("high level\n");
  101. val |= (1 << 26) << irq;
  102. }
  103. writel(val, NETX_DPMAS_IF_CONF1);
  104. return 0;
  105. }
  106. static void
  107. netx_hif_ack_irq(unsigned int _irq)
  108. {
  109. unsigned int val, irq;
  110. irq = _irq - NETX_IRQ_HIF_CHAINED(0);
  111. writel((1 << 24) << irq, NETX_DPMAS_INT_STAT);
  112. val = readl(NETX_DPMAS_INT_EN);
  113. val &= ~((1 << 24) << irq);
  114. writel(val, NETX_DPMAS_INT_EN);
  115. DEBUG_IRQ("%s: irq %d\n", __FUNCTION__, _irq);
  116. }
  117. static void
  118. netx_hif_mask_irq(unsigned int _irq)
  119. {
  120. unsigned int val, irq;
  121. irq = _irq - NETX_IRQ_HIF_CHAINED(0);
  122. val = readl(NETX_DPMAS_INT_EN);
  123. val &= ~((1 << 24) << irq);
  124. writel(val, NETX_DPMAS_INT_EN);
  125. DEBUG_IRQ("%s: irq %d\n", __FUNCTION__, _irq);
  126. }
  127. static void
  128. netx_hif_unmask_irq(unsigned int _irq)
  129. {
  130. unsigned int val, irq;
  131. irq = _irq - NETX_IRQ_HIF_CHAINED(0);
  132. val = readl(NETX_DPMAS_INT_EN);
  133. val |= (1 << 24) << irq;
  134. writel(val, NETX_DPMAS_INT_EN);
  135. DEBUG_IRQ("%s: irq %d\n", __FUNCTION__, _irq);
  136. }
  137. static struct irq_chip netx_hif_chip = {
  138. .ack = netx_hif_ack_irq,
  139. .mask = netx_hif_mask_irq,
  140. .unmask = netx_hif_unmask_irq,
  141. .set_type = netx_hif_irq_type,
  142. };
  143. void __init netx_init_irq(void)
  144. {
  145. int irq;
  146. vic_init(__io(io_p2v(NETX_PA_VIC)), 0, ~0);
  147. for (irq = NETX_IRQ_HIF_CHAINED(0); irq <= NETX_IRQ_HIF_LAST; irq++) {
  148. set_irq_chip(irq, &netx_hif_chip);
  149. set_irq_handler(irq, handle_level_irq);
  150. set_irq_flags(irq, IRQF_VALID);
  151. }
  152. writel(NETX_DPMAS_INT_EN_GLB_EN, NETX_DPMAS_INT_EN);
  153. set_irq_chained_handler(NETX_IRQ_HIF, netx_hif_demux_handler);
  154. }
  155. static int __init netx_init(void)
  156. {
  157. return platform_add_devices(devices, ARRAY_SIZE(devices));
  158. }
  159. subsys_initcall(netx_init);