#!/usr/bin/perl -w
use strict;

open( IN, "/proc/interrupts" ) || die;
while (<IN>) {
    /^\s*(\d+):.*?(XT-PIC|IO-APIC-(?:level|edge))\s+(.+?)\s*$/ || next;
    my ( $irq, $hw ) = ( $1, $3 );
    my @hw = split( ', ', $hw );

	# All USB devices can share one IRQ
	s/^[ue]hci_hcd:(usb\d+)$/$1/   foreach @hw;
	# All Sangoma devices can share one IRQ
	s/^wanpipe\d+$/wanpipe/ foreach @hw;

    my @usb = ();
    my @hw2 = ();
    foreach (@hw) {
        if ( $_ =~ /^usb(\d+)$/ ) {
            push @usb, $1;
        }
        else {
            push @hw2, $_;
        }
    }

    # Delete dupes
    my %hw2;
    $hw2{$_} = 1 foreach @hw2;
    @hw2 = ();
    push @hw2, $_ foreach sort keys %hw2;
    push @hw2, "usb[" . join( ',', @usb ) . "]" if @usb > 0;
    print " * conflict IRQ # $irq: @hw2\n" if @hw2 > 1;
}
close(IN);

