generic.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 <linux/io.h>
  25. #include <linux/irqchip/arm-vic.h>
  26. #include <linux/reboot.h>
  27. #include <mach/hardware.h>
  28. #include <asm/mach/map.h>
  29. #include <mach/netx-regs.h>
  30. #include <asm/mach/irq.h>
  31. static struct map_desc netx_io_desc[] __initdata = {
  32. {
  33. .virtual = NETX_IO_VIRT,
  34. .pfn = __phys_to_pfn(NETX_IO_PHYS),
  35. .length = NETX_IO_SIZE,
  36. .type = MT_DEVICE
  37. }
  38. };
  39. void __init netx_map_io(void)
  40. {
  41. iotable_init(netx_io_desc, ARRAY_SIZE(netx_io_desc));
  42. }
  43. static struct resource netx_rtc_resources[] = {
  44. [0] = {
  45. .start = 0x00101200,
  46. .end = 0x00101220,
  47. .flags = IORESOURCE_MEM,
  48. },
  49. };
  50. static struct platform_device netx_rtc_device = {
  51. .name = "netx-rtc",
  52. .id = 0,
  53. .num_resources = ARRAY_SIZE(netx_rtc_resources),
  54. .resource = netx_rtc_resources,
  55. };
  56. static struct platform_device *devices[] __initdata = {
  57. &netx_rtc_device,
  58. };
  59. #if 0
  60. #define DEBUG_IRQ(fmt...) printk(fmt)
  61. #else
  62. #define DEBUG_IRQ(fmt...) while (0) {}
  63. #endif
  64. static void netx_hif_demux_handler(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. while (stat) {
  71. if (stat & 1) {
  72. DEBUG_IRQ("handling irq %d\n", irq);
  73. generic_handle_irq(irq);
  74. }
  75. irq++;
  76. stat >>= 1;
  77. }
  78. }
  79. static int
  80. netx_hif_irq_type(struct irq_data *d, unsigned int type)
  81. {
  82. unsigned int val, irq;
  83. val = readl(NETX_DPMAS_IF_CONF1);
  84. irq = d->irq - NETX_IRQ_HIF_CHAINED(0);
  85. if (type & IRQ_TYPE_EDGE_RISING) {
  86. DEBUG_IRQ("rising edges\n");
  87. val |= (1 << 26) << irq;
  88. }
  89. if (type & IRQ_TYPE_EDGE_FALLING) {
  90. DEBUG_IRQ("falling edges\n");
  91. val &= ~((1 << 26) << irq);
  92. }
  93. if (type & IRQ_TYPE_LEVEL_LOW) {
  94. DEBUG_IRQ("low level\n");
  95. val &= ~((1 << 26) << irq);
  96. }
  97. if (type & IRQ_TYPE_LEVEL_HIGH) {
  98. DEBUG_IRQ("high level\n");
  99. val |= (1 << 26) << irq;
  100. }
  101. writel(val, NETX_DPMAS_IF_CONF1);
  102. return 0;
  103. }
  104. static void
  105. netx_hif_ack_irq(struct irq_data *d)
  106. {
  107. unsigned int val, irq;
  108. irq = d->irq - NETX_IRQ_HIF_CHAINED(0);
  109. writel((1 << 24) << irq, NETX_DPMAS_INT_STAT);
  110. val = readl(NETX_DPMAS_INT_EN);
  111. val &= ~((1 << 24) << irq);
  112. writel(val, NETX_DPMAS_INT_EN);
  113. DEBUG_IRQ("%s: irq %d\n", __func__, d->irq);
  114. }
  115. static void
  116. netx_hif_mask_irq(struct irq_data *d)
  117. {
  118. unsigned int val, irq;
  119. irq = d->irq - NETX_IRQ_HIF_CHAINED(0);
  120. val = readl(NETX_DPMAS_INT_EN);
  121. val &= ~((1 << 24) << irq);
  122. writel(val, NETX_DPMAS_INT_EN);
  123. DEBUG_IRQ("%s: irq %d\n", __func__, d->irq);
  124. }
  125. static void
  126. netx_hif_unmask_irq(struct irq_data *d)
  127. {
  128. unsigned int val, irq;
  129. irq = d->irq - NETX_IRQ_HIF_CHAINED(0);
  130. val = readl(NETX_DPMAS_INT_EN);
  131. val |= (1 << 24) << irq;
  132. writel(val, NETX_DPMAS_INT_EN);
  133. DEBUG_IRQ("%s: irq %d\n", __func__, d->irq);
  134. }
  135. static struct irq_chip netx_hif_chip = {
  136. .irq_ack = netx_hif_ack_irq,
  137. .irq_mask = netx_hif_mask_irq,
  138. .irq_unmask = netx_hif_unmask_irq,
  139. .irq_set_type = netx_hif_irq_type,
  140. };
  141. void __init netx_init_irq(void)
  142. {
  143. int irq;
  144. vic_init(io_p2v(NETX_PA_VIC), NETX_IRQ_VIC_START, ~0, 0);
  145. for (irq = NETX_IRQ_HIF_CHAINED(0); irq <= NETX_IRQ_HIF_LAST; irq++) {
  146. irq_set_chip_and_handler(irq, &netx_hif_chip,
  147. handle_level_irq);
  148. irq_clear_status_flags(irq, IRQ_NOREQUEST);
  149. }
  150. writel(NETX_DPMAS_INT_EN_GLB_EN, NETX_DPMAS_INT_EN);
  151. irq_set_chained_handler(NETX_IRQ_HIF, netx_hif_demux_handler);
  152. }
  153. static int __init netx_init(void)
  154. {
  155. return platform_add_devices(devices, ARRAY_SIZE(devices));
  156. }
  157. subsys_initcall(netx_init);
  158. void netx_restart(enum reboot_mode mode, const char *cmd)
  159. {
  160. writel(NETX_SYSTEM_RES_CR_FIRMW_RES_EN | NETX_SYSTEM_RES_CR_FIRMW_RES,
  161. NETX_SYSTEM_RES_CR);
  162. }