~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/irda-setup

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
 
3
 
. /etc/default/irda-utils
4
 
 
5
 
test "$AUTOMATIC" = "true" || exit 0
6
 
 
7
 
test -d /sys/bus/pnp/devices || exit 0
8
 
 
9
 
cd /sys/bus/pnp/devices
10
 
 
11
 
IRDA=0;
12
 
STATEFILE=/var/run/irdadev;
13
 
 
14
 
case $1 in
15
 
    start|restart|reload|force-reload)
16
 
    for x in *; do
17
 
        FIR="false";
18
 
        SIR="false";
19
 
        FALLBACK=true;
20
 
        OPTIONS=""
21
 
        for y in `cat $x/id`; do
22
 
            case "$y" in
23
 
                PNP0510|PNP0511)
24
 
                SIR="true";
25
 
                ;;
26
 
                NSC*)
27
 
                FIR="nsc-ircc";
28
 
                ;;
29
 
                IBM0071)
30
 
                FIR="nsc-ircc";
31
 
                OPTIONS="dongle_id=0x09";
32
 
                ;;
33
 
                SMC*)
34
 
                FIR="smsc-ircc2";
35
 
                ;;          
36
 
                ALI5123)
37
 
                FIR="ali-ircc";
38
 
                ;;
39
 
                VIA3076)
40
 
                FIR="via-ircc"
41
 
            esac
42
 
        done
43
 
 
44
 
        if [ $FIR = "false" -a $SIR = "false" ]; then
45
 
                continue;
46
 
        fi
47
 
        
48
 
    # Work out resource ranges, so we know which serial port to work with
49
 
        PORTS=`grep io $x/resources | sed -e 's/io \(.*\)-.*/\1/'`
50
 
        for PORT in $PORTS; do
51
 
                case $PORT in
52
 
                0x3f8)
53
 
                PORT="/dev/ttyS0"
54
 
                break;
55
 
                ;;
56
 
                0x2f8)
57
 
                PORT="/dev/ttyS1"
58
 
                break;
59
 
                ;;
60
 
                0x3e8)
61
 
                PORT="/dev/ttyS2"
62
 
                break;
63
 
                ;;
64
 
                0x2e8)
65
 
                PORT="/dev/ttyS3"
66
 
                break;
67
 
                ;;
68
 
                default)
69
 
                PORT="UNKNOWN"
70
 
                ;;
71
 
                esac;
72
 
        done
73
 
 
74
 
        if [ "$FIR" != "false" ]; then
75
 
            # The BIOS doesn't always activate the device. Prod it
76
 
            echo disable >$x/resources;
77
 
            echo activate >$x/resources;
78
 
 
79
 
            UART="unknown";
80
 
            if [ "$PORT" != "UNKNOWN" ]; then
81
 
            # We should attempt to disable the UART. However, we need to store
82
 
            # it - there's a chance that things could still go horribly wrong
83
 
                UART=`setserial $PORT | sed 's/.*UART: \(.*\), Port.*/\1/'`
84
 
                setserial $PORT uart none
85
 
            fi
86
 
            modprobe $FIR $OPTIONS;
87
 
            if [ "$?" = "0" ]; then
88
 
                echo "irda$IRDA fir" >$STATEFILE;
89
 
                let "IRDA=$IRDA+1";
90
 
                continue;
91
 
            else
92
 
            # Try to recover
93
 
                if [ "$UART" != "undefined" ]; then
94
 
                        setserial $PORT uart $UART;
95
 
                fi
96
 
            fi
97
 
        fi
98
 
        
99
 
        if [ "$SIR" = "true" -o "$FIR" != "false" ]; then
100
 
            # We'll only have got here if the FIR module has failed
101
 
 
102
 
            if [ "$PORT" != "UNKNOWN" ]; then
103
 
            # The BIOS doesn't always activate the device. Prod it
104
 
                echo disable >$x/resources;
105
 
                echo activate >$x/resources;
106
 
 
107
 
            # The IRQ is not always set correctly, so try to deal with that
108
 
                IRQ=`grep irq $x/resources | sed -e 's/irq \(.*\)/\1/'`
109
 
                setserial $PORT irq $IRQ;
110
 
                echo "$PORT sir" >$STATEFILE;
111
 
            fi
112
 
        fi
113
 
    done
114
 
    ;;
115
 
    stop)
116
 
    exit 0
117
 
    ;;
118
 
esac