x86: Set up edge triggering on interrupt 9
authorSimon Glass <sjg@chromium.org>
Sat, 15 Nov 2014 01:18:31 +0000 (18:18 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 25 Nov 2014 13:34:00 +0000 (06:34 -0700)
Add this additional init in case it is needed by the OS.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
arch/x86/include/asm/interrupt.h
arch/x86/lib/pcat_interrupts.c

index 3f46e0920a8646bea0b044ac2509a3b2346b3277..25abde7be6ebf1c3027b181a6e2025d8b0d70701 100644 (file)
@@ -27,4 +27,15 @@ void specific_eoi(int irq);
 
 extern char exception_stack[];
 
+/**
+ * configure_irq_trigger() - Configure IRQ triggering
+ *
+ * Switch the given interrupt to be level / edge triggered
+ *
+ * @param int_num legacy interrupt number (3-7, 9-15)
+ * @param is_level_triggered true for level triggered interrupt, false for
+ *     edge triggered interrupt
+ */
+void configure_irq_trigger(int int_num, bool is_level_triggered);
+
 #endif
index 4c86f7fc6a85ae2910c8b6d1e8f3b047fb42fbe5..2dc2fbd55b626166bfd8ca31f377b9e3c1d3fac6 100644 (file)
@@ -62,6 +62,9 @@ int interrupt_init(void)
         */
        unmask_irq(2);
 
+       /* Interrupt 9 should be level triggered (SCI). The OS might do this */
+       configure_irq_trigger(9, true);
+
        enable_interrupts();
 
        return 0;
@@ -114,3 +117,38 @@ void specific_eoi(int irq)
 
        outb(OCW2_SEOI | irq, MASTER_PIC + OCW2);
 }
+
+#define ELCR1                  0x4d0
+#define ELCR2                  0x4d1
+
+void configure_irq_trigger(int int_num, bool is_level_triggered)
+{
+       u16 int_bits = inb(ELCR1) | (((u16)inb(ELCR2)) << 8);
+
+       debug("%s: current interrupts are 0x%x\n", __func__, int_bits);
+       if (is_level_triggered)
+               int_bits |= (1 << int_num);
+       else
+               int_bits &= ~(1 << int_num);
+
+       /* Write new values */
+       debug("%s: try to set interrupts 0x%x\n", __func__, int_bits);
+       outb((u8)(int_bits & 0xff), ELCR1);
+       outb((u8)(int_bits >> 8), ELCR2);
+
+#ifdef PARANOID_IRQ_TRIGGERS
+       /*
+        * Try reading back the new values. This seems like an error but is
+        * not
+        */
+       if (inb(ELCR1) != (int_bits & 0xff)) {
+               printf("%s: lower order bits are wrong: want 0x%x, got 0x%x\n",
+                      __func__, (int_bits & 0xff), inb(ELCR1));
+       }
+
+       if (inb(ELCR2) != (int_bits >> 8)) {
+               printf("%s: higher order bits are wrong: want 0x%x, got 0x%x\n",
+                      __func__, (int_bits>>8), inb(ELCR2));
+       }
+#endif
+}