blob: 656299102d7fbf0fb554190d64f67a1fdec46db6 [file] [log] [blame]
Eddie Jamesb9c253d2018-12-11 13:25:50 -06001#!/bin/sh
2
3new_directory="/sys/kernel/config/usb_gadget/obmc_hid"
4
5if [ -e "${new_directory}" ]; then
6 exit 0
7fi
8
9# create gadget
10original_directory="$(pwd)"
11mkdir "${new_directory}"
12cd "${new_directory}"
13
14# add basic information
15echo 0x0100 > bcdDevice
16echo 0x0200 > bcdUSB
Eddie Jamesb9c253d2018-12-11 13:25:50 -060017echo 0x0104 > idProduct # Multifunction Composite Gadget
18echo 0x1d6b > idVendor # Linux Foundation
19
20# create English locale
21mkdir strings/0x409
22
23echo "OpenBMC" > strings/0x409/manufacturer
24echo "virtual_input" > strings/0x409/product
25echo "OBMC0001" > strings/0x409/serialnumber
26
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080027# Create HID keyboard function
28mkdir functions/hid.0
Eddie Jamesb9c253d2018-12-11 13:25:50 -060029
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080030echo 1 > functions/hid.0/protocol # 1: keyboard
31echo 8 > functions/hid.0/report_length
32echo 1 > functions/hid.0/subclass
Eddie Jamesb9c253d2018-12-11 13:25:50 -060033
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080034# Binary HID keyboard descriptor
35# 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
36# 0x09, 0x06, // USAGE (Keyboard)
37# 0xa1, 0x01, // COLLECTION (Application)
38# 0x05, 0x07, // USAGE_PAGE (Keyboard)
39# 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
40# 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
41# 0x15, 0x00, // LOGICAL_MINIMUM (0)
42# 0x25, 0x01, // LOGICAL_MAXIMUM (1)
43# 0x75, 0x01, // REPORT_SIZE (1)
44# 0x95, 0x08, // REPORT_COUNT (8)
45# 0x81, 0x02, // INPUT (Data,Var,Abs)
46# 0x95, 0x01, // REPORT_COUNT (1)
47# 0x75, 0x08, // REPORT_SIZE (8)
48# 0x81, 0x03, // INPUT (Data,Var,Abs)
49# 0x95, 0x05, // REPORT_COUNT (5)
50# 0x75, 0x01, // REPORT_SIZE (1)
51# 0x05, 0x08, // USAGE_PAGE (LEDs)
52# 0x19, 0x01, // USAGE_MINIMUM (Num Lock)
53# 0x29, 0x05, // USAGE_MAXIMUM (Kana)
54# 0x91, 0x02, // OUTPUT (Data,Var,Abs)
55# 0x95, 0x01, // REPORT_COUNT (1)
56# 0x75, 0x03, // REPORT_SIZE (3)
57# 0x91, 0x03, // OUTPUT (Cnst,Var,Abs)
58# 0x95, 0x06, // REPORT_COUNT (6)
59# 0x75, 0x08, // REPORT_SIZE (8)
60# 0x15, 0x00, // LOGICAL_MINIMUM (0)
61# 0x25, 0x65, // LOGICAL_MAXIMUM (101)
62# 0x05, 0x07, // USAGE_PAGE (Keyboard)
63# 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
64# 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
65# 0x81, 0x00, // INPUT (Data,Ary,Abs)
66# 0xc0 // END_COLLECTION
67echo -ne '\x05\x01\x09\x06\xa1\x01\x05\x07\x19\xe0\x29\xe7\x15\x00\x25\x01\x75\x01\x95\x08\x81\x02\x95\x01\x75\x08\x81\x03\x95\x05\x75\x01\x05\x08\x19\x01\x29\x05\x91\x02\x95\x01\x75\x03\x91\x03\x95\x06\x75\x08\x15\x00\x25\x65\x05\x07\x19\x00\x29\x65\x81\x00\xc0' > functions/hid.0/report_desc
68
69# Create HID mouse function
70mkdir functions/hid.1
71
72echo 2 > functions/hid.1/protocol # 2: mouse
73echo 5 > functions/hid.1/report_length
74echo 1 > functions/hid.1/subclass
75
76# Binary HID mouse descriptor (absolute coordinate)
77# 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
78# 0x09, 0x02, // USAGE (Mouse)
79# 0xa1, 0x01, // COLLECTION (Application)
80# 0x09, 0x01, // USAGE (Pointer)
81# 0xa1, 0x00, // COLLECTION (Physical)
82# 0x05, 0x09, // USAGE_PAGE (Button)
83# 0x19, 0x01, // USAGE_MINIMUM (Button 1)
84# 0x29, 0x03, // USAGE_MAXIMUM (Button 3)
85# 0x15, 0x00, // LOGICAL_MINIMUM (0)
86# 0x25, 0x01, // LOGICAL_MAXIMUM (1)
87# 0x95, 0x03, // REPORT_COUNT (3)
88# 0x75, 0x01, // REPORT_SIZE (1)
89# 0x81, 0x02, // INPUT (Data,Var,Abs)
90# 0x95, 0x01, // REPORT_COUNT (1)
91# 0x75, 0x05, // REPORT_SIZE (5)
92# 0x81, 0x03, // INPUT (Cnst,Var,Abs)
93# 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
94# 0x09, 0x30, // USAGE (X)
95# 0x09, 0x31, // USAGE (Y)
96# 0x35, 0x00, // PHYSICAL_MINIMUM (0)
97# 0x46, 0xff, 0x7f, // PHYSICAL_MAXIMUM (32767)
98# 0x15, 0x00, // LOGICAL_MINIMUM (0)
99# 0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767)
100# 0x65, 0x11, // UNIT (SI Lin:Distance)
101# 0x55, 0x00, // UNIT_EXPONENT (0)
102# 0x75, 0x10, // REPORT_SIZE (16)
103# 0x95, 0x02, // REPORT_COUNT (2)
104# 0x81, 0x02, // INPUT (Data,Var,Abs)
105# 0xc0, // END_COLLECTION
106# 0xc0 // END_COLLECTION
107echo -ne '\x05\x01\x09\x02\xa1\x01\x09\x01\xa1\x00\x05\x09\x19\x01\x29\x03\x15\x00\x25\x01\x95\x03\x75\x01\x81\x02\x95\x01\x75\x05\x81\x03\x05\x01\x09\x30\x09\x31\x35\x00\x46\xff\x7f\x15\x00\x26\xff\x7f\x65\x11\x55\x00\x75\x10\x95\x02\x81\x02\xc0\xc0' > functions/hid.1/report_desc
108
Eddie Jamesb9c253d2018-12-11 13:25:50 -0600109# Create configuration
110mkdir configs/c.1
111mkdir configs/c.1/strings/0x409
112
113echo 0x80 > configs/c.1/bmAttributes
114echo 200 > configs/c.1/MaxPower
115echo "" > configs/c.1/strings/0x409/configuration
116
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -0800117# Link HID functions to configuration
118ln -s functions/hid.0 configs/c.1
119ln -s functions/hid.1 configs/c.1
Eddie Jamesb9c253d2018-12-11 13:25:50 -0600120
121# Enable gadget
122dev_name="1e6a0000.usb-vhub"
123i=0
124num_ports=5
125base_usb_dir="/sys/bus/platform/devices/${dev_name}/${dev_name}:p"
126while [ $i -lt $num_ports ]; do
127 port=$(($i + 1))
128 i=$port
129 if [ ! -e "${base_usb_dir}${port}/gadget/suspended" ]; then
130 break
131 fi
132done
133echo "${dev_name}:p${port}" > UDC
134
135cd "${original_directory}"