summaryrefslogtreecommitdiff
path: root/net-wireless/irda-utils/files/irda-setup.sh
blob: a7c781989c5748fefabdde6cccafacd9c5a66190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
#
# irda-setup
#
# Initialize IrDA devices. Based on a Ubuntu init-script,
# but adapted to be called directly from udev.
#
# params: sir/fir <module> <options>

MODE="${1}"
shift

SYSFS="/sys"
RESOURCES="${SYSFS}${DEVPATH}/resources"

# Work out resource ranges, so we know which serial port to work with
PORTS=$(/bin/sed -n 's/io \(.*\)-.*/\1/p' "${RESOURCES}")
for PORT in ${PORTS}; do
	case "${PORT}" in
		0x3f8)
			PORT="/dev/ttyS0"
			break;;
		0x2f8)
			PORT="/dev/ttyS1"
			break;;
		0x3e8)
			PORT="/dev/ttyS2"
			break;;
		0x2e8)
			PORT="/dev/ttyS3"
			break;;
		default)
			PORT="UNKNOWN";;
	esac
done

# Handle FIR dongles
if [ "${MODE}" = "fir" ]; then
	# The BIOS doesn't always activate the device. Prod it
	echo disable > "${RESOURCES}"
	echo activate > "${RESOURCES}"

	UART="unknown";
	if [ "${PORT}" != "UNKNOWN" ]; then
		# We should attempt to disable the UART. However, we need to store
		# it - there's a chance that things could still go horribly wrong
		UART=$(/bin/setserial ${PORT} | /bin/sed 's/.*UART: \(.*\), Port.*/\1/')
		/bin/setserial ${PORT} uart none
	fi

	# Load FIR module
	/sbin/modprobe -sq "${@}" && exit 0  # OK

	# Try to recover
	[ "${UART}" != "undefined" ] && /bin/setserial ${PORT} uart ${UART}
fi

# We'll only have got here if we have SIR or the FIR module has failed
if [ "${PORT}" != "UNKNOWN" ]; then
	# The BIOS doesn't always activate the device. Prod it
	echo disable > "${RESOURCES}"
	echo activate > "${RESOURCES}"

	# The IRQ is not always set correctly, so try to deal with that
	/bin/setserial ${PORT} $(/bin/grep -h '^irq ' "${RESOURCES}")
fi

exit 0  # never fail