hd64461.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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(struct irq_data *data)
  18. {
  19. unsigned int irq = data->irq;
  20. unsigned short nimr;
  21. unsigned short mask = 1 << (irq - HD64461_IRQBASE);
  22. nimr = __raw_readw(HD64461_NIMR);
  23. nimr |= mask;
  24. __raw_writew(nimr, HD64461_NIMR);
  25. }
  26. static void hd64461_unmask_irq(struct irq_data *data)
  27. {
  28. unsigned int irq = data->irq;
  29. unsigned short nimr;
  30. unsigned short mask = 1 << (irq - HD64461_IRQBASE);
  31. nimr = __raw_readw(HD64461_NIMR);
  32. nimr &= ~mask;
  33. __raw_writew(nimr, HD64461_NIMR);
  34. }
  35. static void hd64461_mask_and_ack_irq(struct irq_data *data)
  36. {
  37. hd64461_mask_irq(data);
  38. #ifdef CONFIG_HD64461_ENABLER
  39. if (data->irq == HD64461_IRQBASE + 13)
  40. __raw_writeb(0x00, HD64461_PCC1CSCR);
  41. #endif
  42. }
  43. static struct irq_chip hd64461_irq_chip = {
  44. .name = "HD64461-IRQ",
  45. .irq_mask = hd64461_mask_irq,
  46. .irq_mask_ack = hd64461_mask_and_ack_irq,
  47. .irq_unmask = hd64461_unmask_irq,
  48. };
  49. static void hd64461_irq_demux(struct irq_desc *desc)
  50. {
  51. unsigned short intv = __raw_readw(HD64461_NIRR);
  52. unsigned int ext_irq = HD64461_IRQBASE;
  53. intv &= (1 << HD64461_IRQ_NUM) - 1;
  54. for (; intv; intv >>= 1, ext_irq++) {
  55. if (!(intv & 1))
  56. continue;
  57. generic_handle_irq(ext_irq);
  58. }
  59. }
  60. int __init setup_hd64461(void)
  61. {
  62. int irq_base, i;
  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_base = irq_alloc_descs(HD64461_IRQBASE, HD64461_IRQBASE, 16, -1);
  73. if (IS_ERR_VALUE(irq_base)) {
  74. pr_err("%s: failed hooking irqs for HD64461\n", __func__);
  75. return irq_base;
  76. }
  77. for (i = 0; i < 16; i++)
  78. irq_set_chip_and_handler(irq_base + i, &hd64461_irq_chip,
  79. handle_level_irq);
  80. irq_set_chained_handler(CONFIG_HD64461_IRQ, hd64461_irq_demux);
  81. irq_set_irq_type(CONFIG_HD64461_IRQ, IRQ_TYPE_LEVEL_LOW);
  82. #ifdef CONFIG_HD64461_ENABLER
  83. printk(KERN_INFO "HD64461: enabling PCMCIA devices\n");
  84. __raw_writeb(0x4c, HD64461_PCC1CSCIER);
  85. __raw_writeb(0x00, HD64461_PCC1CSCR);
  86. #endif
  87. return 0;
  88. }
  89. module_init(setup_hd64461);