blob: 0e6b39f845553db4e265cd0dc92026a2faacdb72 (
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
#
# Copyright Matthias Hentges <devel@hentges.net> (c) 2007
# License: GPL (see http://www.gnu.org/licenses/gpl.txt for a copy of the license)
#
# Filename: usb-gadget
# Date: 20070606 (YMD)
#
#################################################################################
#
# 20070606 - v0.0.1 - Initial release
# 20070630 - v0.0.2 - Add forgotten host mode
# 20090529 - add support for all gadgets in 2.6.29 (koen)
CONF_FILE="/etc/default/usb-gadget"
die() {
echo "ERROR: $1"
exit 1
}
go() {
test -e "$CONF_FILE" && . "$CONF_FILE"
case "$USB_MODE" in
networking) setup_usb g_ether "$MODULE_OPTIONS" ;;
zero) setup_usb g_zero "$MODULE_OPTIONS" ;;
midi) setup_usb g_midi "$MODULE_OPTIONS" ;;
printer) setup_usb g_printer "$MODULE_OPTIONS" ;;
gadgetfs) setup_usb gadgetfs "$MODULE_OPTIONS" ;;
composite) setup_usb g_cdc "$MODULE_OPTIONS" ;;
storage) setup_usb g_file_storage "$MODULE_OPTIONS" ;;
hostmode) unload_usb_gadgets
setup_usb ohci_hcd "$MODULE_OPTIONS" ;;
none) unload_usb_gadgets ;;
esac
}
setup_usb() {
if ! ( lsmod | grep -q "$1" )
then
unload_usb_gadgets
echo "Loading [$1]"
modprobe "$1" "$MODULE_OPTIONS"
else
echo "Already loaded: [$1]"
fi
}
unload_usb_gadgets() {
KERNEL_VERSION="`uname -r`"
GADGET_MODULES="`find /lib/modules/$KERNEL_VERSION/kernel/drivers/usb/gadget -name "*g_*"`"
for module in $GADGET_MODULES
do
MODULE_NAME="`basename $module | sed "s/\.ko//"`"
if ( lsmod | grep -q "$MODULE_NAME" )
then
echo "Unloading [$MODULE_NAME]"
rmmod "$module"
fi
done
}
go
|