/arch/sh/cchips/hd6446x/hd64461.c

https://bitbucket.org/cresqo/cm7-p500-kernel · C · 123 lines · 92 code · 24 blank · 7 comment · 10 complexity · 089f94fae64a7a2b642b09f59db6b8b1 MD5 · raw file

  1. /*
  2. * Copyright (C) 2000 YAEGASHI Takeshi
  3. * Hitachi HD64461 companion chip support
  4. */
  5. #include <linux/sched.h>
  6. #include <linux/module.h>
  7. #include <linux/kernel.h>
  8. #include <linux/param.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/init.h>
  11. #include <linux/irq.h>
  12. #include <linux/io.h>
  13. #include <asm/irq.h>
  14. #include <asm/hd64461.h>
  15. /* This belongs in cpu specific */
  16. #define INTC_ICR1 0xA4140010UL
  17. static void hd64461_mask_irq(unsigned int irq)
  18. {
  19. unsigned short nimr;
  20. unsigned short mask = 1 << (irq - HD64461_IRQBASE);
  21. nimr = __raw_readw(HD64461_NIMR);
  22. nimr |= mask;
  23. __raw_writew(nimr, HD64461_NIMR);
  24. }
  25. static void hd64461_unmask_irq(unsigned int irq)
  26. {
  27. unsigned short nimr;
  28. unsigned short mask = 1 << (irq - HD64461_IRQBASE);
  29. nimr = __raw_readw(HD64461_NIMR);
  30. nimr &= ~mask;
  31. __raw_writew(nimr, HD64461_NIMR);
  32. }
  33. static void hd64461_mask_and_ack_irq(unsigned int irq)
  34. {
  35. hd64461_mask_irq(irq);
  36. #ifdef CONFIG_HD64461_ENABLER
  37. if (irq == HD64461_IRQBASE + 13)
  38. __raw_writeb(0x00, HD64461_PCC1CSCR);
  39. #endif
  40. }
  41. static struct irq_chip hd64461_irq_chip = {
  42. .name = "HD64461-IRQ",
  43. .mask = hd64461_mask_irq,
  44. .mask_ack = hd64461_mask_and_ack_irq,
  45. .unmask = hd64461_unmask_irq,
  46. };
  47. static void hd64461_irq_demux(unsigned int irq, struct irq_desc *desc)
  48. {
  49. unsigned short intv = __raw_readw(HD64461_NIRR);
  50. unsigned int ext_irq = HD64461_IRQBASE;
  51. intv &= (1 << HD64461_IRQ_NUM) - 1;
  52. for (; intv; intv >>= 1, ext_irq++) {
  53. if (!(intv & 1))
  54. continue;
  55. generic_handle_irq(ext_irq);
  56. }
  57. }
  58. int __init setup_hd64461(void)
  59. {
  60. int i, nid = cpu_to_node(boot_cpu_data);
  61. if (!MACH_HD64461)
  62. return 0;
  63. printk(KERN_INFO
  64. "HD64461 configured at 0x%x on irq %d(mapped into %d to %d)\n",
  65. HD64461_IOBASE, CONFIG_HD64461_IRQ, HD64461_IRQBASE,
  66. HD64461_IRQBASE + 15);
  67. /* Should be at processor specific part.. */
  68. #if defined(CONFIG_CPU_SUBTYPE_SH7709)
  69. __raw_writew(0x2240, INTC_ICR1);
  70. #endif
  71. __raw_writew(0xffff, HD64461_NIMR);
  72. /* IRQ 80 -> 95 belongs to HD64461 */
  73. for (i = HD64461_IRQBASE; i < HD64461_IRQBASE + 16; i++) {
  74. unsigned int irq;
  75. irq = create_irq_nr(i, nid);
  76. if (unlikely(irq == 0)) {
  77. pr_err("%s: failed hooking irq %d for HD64461\n",
  78. __func__, i);
  79. return -EBUSY;
  80. }
  81. if (unlikely(irq != i)) {
  82. pr_err("%s: got irq %d but wanted %d, bailing.\n",
  83. __func__, irq, i);
  84. destroy_irq(irq);
  85. return -EINVAL;
  86. }
  87. set_irq_chip_and_handler(i, &hd64461_irq_chip,
  88. handle_level_irq);
  89. }
  90. set_irq_chained_handler(CONFIG_HD64461_IRQ, hd64461_irq_demux);
  91. set_irq_type(CONFIG_HD64461_IRQ, IRQ_TYPE_LEVEL_LOW);
  92. #ifdef CONFIG_HD64461_ENABLER
  93. printk(KERN_INFO "HD64461: enabling PCMCIA devices\n");
  94. __raw_writeb(0x4c, HD64461_PCC1CSCIER);
  95. __raw_writeb(0x00, HD64461_PCC1CSCR);
  96. #endif
  97. return 0;
  98. }
  99. module_init(setup_hd64461);