sbc82xx.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * arch/ppc/platforms/sbc82xx.c
  3. *
  4. * SBC82XX platform support
  5. *
  6. * Author: Guy Streeter <streeter@redhat.com>
  7. *
  8. * Derived from: est8260_setup.c by Allen Curtis, ONZ
  9. *
  10. * Copyright 2004 Red Hat, Inc.
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. */
  17. #include <linux/config.h>
  18. #include <linux/stddef.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/irq.h>
  21. #include <linux/init.h>
  22. #include <linux/pci.h>
  23. #include <asm/mpc8260.h>
  24. #include <asm/machdep.h>
  25. #include <asm/io.h>
  26. #include <asm/todc.h>
  27. #include <asm/immap_cpm2.h>
  28. #include <asm/pci.h>
  29. static void (*callback_init_IRQ)(void);
  30. extern unsigned char __res[sizeof(bd_t)];
  31. extern void (*late_time_init)(void);
  32. #ifdef CONFIG_GEN_RTC
  33. TODC_ALLOC();
  34. /*
  35. * Timer init happens before mem_init but after paging init, so we cannot
  36. * directly use ioremap() at that time.
  37. * late_time_init() is call after paging init.
  38. */
  39. static void sbc82xx_time_init(void)
  40. {
  41. volatile memctl_cpm2_t *mc = &cpm2_immr->im_memctl;
  42. /* Set up CS11 for RTC chip */
  43. mc->memc_br11=0;
  44. mc->memc_or11=0xffff0836;
  45. mc->memc_br11=SBC82xx_TODC_NVRAM_ADDR | 0x0801;
  46. TODC_INIT(TODC_TYPE_MK48T59, 0, 0, SBC82xx_TODC_NVRAM_ADDR, 0);
  47. todc_info->nvram_data =
  48. (unsigned int)ioremap(todc_info->nvram_data, 0x2000);
  49. BUG_ON(!todc_info->nvram_data);
  50. ppc_md.get_rtc_time = todc_get_rtc_time;
  51. ppc_md.set_rtc_time = todc_set_rtc_time;
  52. ppc_md.nvram_read_val = todc_direct_read_val;
  53. ppc_md.nvram_write_val = todc_direct_write_val;
  54. todc_time_init();
  55. }
  56. #endif /* CONFIG_GEN_RTC */
  57. static volatile char *sbc82xx_i8259_map;
  58. static char sbc82xx_i8259_mask = 0xff;
  59. static DEFINE_SPINLOCK(sbc82xx_i8259_lock);
  60. static void sbc82xx_i8259_mask_and_ack_irq(unsigned int irq_nr)
  61. {
  62. unsigned long flags;
  63. irq_nr -= NR_SIU_INTS;
  64. spin_lock_irqsave(&sbc82xx_i8259_lock, flags);
  65. sbc82xx_i8259_mask |= 1 << irq_nr;
  66. (void) sbc82xx_i8259_map[1]; /* Dummy read */
  67. sbc82xx_i8259_map[1] = sbc82xx_i8259_mask;
  68. sbc82xx_i8259_map[0] = 0x20; /* OCW2: Non-specific EOI */
  69. spin_unlock_irqrestore(&sbc82xx_i8259_lock, flags);
  70. }
  71. static void sbc82xx_i8259_mask_irq(unsigned int irq_nr)
  72. {
  73. unsigned long flags;
  74. irq_nr -= NR_SIU_INTS;
  75. spin_lock_irqsave(&sbc82xx_i8259_lock, flags);
  76. sbc82xx_i8259_mask |= 1 << irq_nr;
  77. sbc82xx_i8259_map[1] = sbc82xx_i8259_mask;
  78. spin_unlock_irqrestore(&sbc82xx_i8259_lock, flags);
  79. }
  80. static void sbc82xx_i8259_unmask_irq(unsigned int irq_nr)
  81. {
  82. unsigned long flags;
  83. irq_nr -= NR_SIU_INTS;
  84. spin_lock_irqsave(&sbc82xx_i8259_lock, flags);
  85. sbc82xx_i8259_mask &= ~(1 << irq_nr);
  86. sbc82xx_i8259_map[1] = sbc82xx_i8259_mask;
  87. spin_unlock_irqrestore(&sbc82xx_i8259_lock, flags);
  88. }
  89. static void sbc82xx_i8259_end_irq(unsigned int irq)
  90. {
  91. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS))
  92. && irq_desc[irq].action)
  93. sbc82xx_i8259_unmask_irq(irq);
  94. }
  95. struct hw_interrupt_type sbc82xx_i8259_ic = {
  96. .typename = " i8259 ",
  97. .enable = sbc82xx_i8259_unmask_irq,
  98. .disable = sbc82xx_i8259_mask_irq,
  99. .ack = sbc82xx_i8259_mask_and_ack_irq,
  100. .end = sbc82xx_i8259_end_irq,
  101. };
  102. static irqreturn_t sbc82xx_i8259_demux(int irq, void *dev_id, struct pt_regs *regs)
  103. {
  104. spin_lock(&sbc82xx_i8259_lock);
  105. sbc82xx_i8259_map[0] = 0x0c; /* OCW3: Read IR register on RD# pulse */
  106. irq = sbc82xx_i8259_map[0] & 7; /* Read IRR */
  107. if (irq == 7) {
  108. /* Possible spurious interrupt */
  109. int isr;
  110. sbc82xx_i8259_map[0] = 0x0b; /* OCW3: Read IS register on RD# pulse */
  111. isr = sbc82xx_i8259_map[0]; /* Read ISR */
  112. if (!(isr & 0x80)) {
  113. printk(KERN_INFO "Spurious i8259 interrupt\n");
  114. return IRQ_HANDLED;
  115. }
  116. }
  117. __do_IRQ(NR_SIU_INTS + irq, regs);
  118. return IRQ_HANDLED;
  119. }
  120. static struct irqaction sbc82xx_i8259_irqaction = {
  121. .handler = sbc82xx_i8259_demux,
  122. .flags = SA_INTERRUPT,
  123. .mask = CPU_MASK_NONE,
  124. .name = "i8259 demux",
  125. };
  126. void __init sbc82xx_init_IRQ(void)
  127. {
  128. volatile memctl_cpm2_t *mc = &cpm2_immr->im_memctl;
  129. volatile intctl_cpm2_t *ic = &cpm2_immr->im_intctl;
  130. int i;
  131. callback_init_IRQ();
  132. /* u-boot doesn't always set the board up correctly */
  133. mc->memc_br5 = 0;
  134. mc->memc_or5 = 0xfff00856;
  135. mc->memc_br5 = 0x22000801;
  136. sbc82xx_i8259_map = ioremap(0x22008000, 2);
  137. if (!sbc82xx_i8259_map) {
  138. printk(KERN_CRIT "Mapping i8259 interrupt controller failed\n");
  139. return;
  140. }
  141. /* Set up the interrupt handlers for the i8259 IRQs */
  142. for (i = NR_SIU_INTS; i < NR_SIU_INTS + 8; i++) {
  143. irq_desc[i].handler = &sbc82xx_i8259_ic;
  144. irq_desc[i].status |= IRQ_LEVEL;
  145. }
  146. /* make IRQ6 level sensitive */
  147. ic->ic_siexr &= ~(1 << (14 - (SIU_INT_IRQ6 - SIU_INT_IRQ1)));
  148. irq_desc[SIU_INT_IRQ6].status |= IRQ_LEVEL;
  149. /* Initialise the i8259 */
  150. sbc82xx_i8259_map[0] = 0x1b; /* ICW1: Level, no cascade, ICW4 */
  151. sbc82xx_i8259_map[1] = 0x00; /* ICW2: vector base */
  152. /* No ICW3 (no cascade) */
  153. sbc82xx_i8259_map[1] = 0x01; /* ICW4: 8086 mode, normal EOI */
  154. sbc82xx_i8259_map[0] = 0x0b; /* OCW3: Read IS register on RD# pulse */
  155. sbc82xx_i8259_map[1] = sbc82xx_i8259_mask; /* Set interrupt mask */
  156. /* Request cascade IRQ */
  157. if (setup_irq(SIU_INT_IRQ6, &sbc82xx_i8259_irqaction)) {
  158. printk("Installation of i8259 IRQ demultiplexer failed.\n");
  159. }
  160. }
  161. static int sbc82xx_pci_map_irq(struct pci_dev *dev, unsigned char idsel,
  162. unsigned char pin)
  163. {
  164. static char pci_irq_table[][4] = {
  165. /*
  166. * PCI IDSEL/INTPIN->INTLINE
  167. * A B C D
  168. */
  169. { SBC82xx_PIRQA, SBC82xx_PIRQB, SBC82xx_PIRQC, SBC82xx_PIRQD }, /* IDSEL 16 - PMC slot */
  170. { SBC82xx_PC_IRQA, SBC82xx_PC_IRQB, -1, -1 }, /* IDSEL 17 - CardBus */
  171. { SBC82xx_PIRQA, SBC82xx_PIRQB, SBC82xx_PIRQC, SBC82xx_PIRQD }, /* IDSEL 18 - PCI-X bridge */
  172. };
  173. const long min_idsel = 16, max_idsel = 18, irqs_per_slot = 4;
  174. return PCI_IRQ_TABLE_LOOKUP;
  175. }
  176. static void __devinit quirk_sbc8260_cardbus(struct pci_dev *pdev)
  177. {
  178. uint32_t ctrl;
  179. if (pdev->bus->number != 0 || pdev->devfn != PCI_DEVFN(17, 0))
  180. return;
  181. printk(KERN_INFO "Setting up CardBus controller\n");
  182. /* Set P2CCLK bit in System Control Register */
  183. pci_read_config_dword(pdev, 0x80, &ctrl);
  184. ctrl |= (1<<27);
  185. pci_write_config_dword(pdev, 0x80, ctrl);
  186. /* Set MFUNC up for PCI IRQ routing via INTA and INTB, and LEDs. */
  187. pci_write_config_dword(pdev, 0x8c, 0x00c01d22);
  188. }
  189. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1420, quirk_sbc8260_cardbus);
  190. void __init
  191. m82xx_board_init(void)
  192. {
  193. /* u-boot may be using one of the FCC Ethernet devices.
  194. Use the MAC address to the SCC. */
  195. __res[offsetof(bd_t, bi_enetaddr[5])] &= ~3;
  196. /* Anything special for this platform */
  197. callback_init_IRQ = ppc_md.init_IRQ;
  198. ppc_md.init_IRQ = sbc82xx_init_IRQ;
  199. ppc_md.pci_map_irq = sbc82xx_pci_map_irq;
  200. #ifdef CONFIG_GEN_RTC
  201. ppc_md.time_init = NULL;
  202. ppc_md.get_rtc_time = NULL;
  203. ppc_md.set_rtc_time = NULL;
  204. ppc_md.nvram_read_val = NULL;
  205. ppc_md.nvram_write_val = NULL;
  206. late_time_init = sbc82xx_time_init;
  207. #endif /* CONFIG_GEN_RTC */
  208. }