Eddie James | b9c253d | 2018-12-11 13:25:50 -0600 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | new_directory="/sys/kernel/config/usb_gadget/obmc_hid" |
| 4 | |
| 5 | if [ -e "${new_directory}" ]; then |
| 6 | exit 0 |
| 7 | fi |
| 8 | |
| 9 | # create gadget |
| 10 | original_directory="$(pwd)" |
| 11 | mkdir "${new_directory}" |
| 12 | cd "${new_directory}" |
| 13 | |
| 14 | # add basic information |
| 15 | echo 0x0100 > bcdDevice |
| 16 | echo 0x0200 > bcdUSB |
Eddie James | b9c253d | 2018-12-11 13:25:50 -0600 | [diff] [blame] | 17 | echo 0x0104 > idProduct # Multifunction Composite Gadget |
| 18 | echo 0x1d6b > idVendor # Linux Foundation |
| 19 | |
| 20 | # create English locale |
| 21 | mkdir strings/0x409 |
| 22 | |
| 23 | echo "OpenBMC" > strings/0x409/manufacturer |
| 24 | echo "virtual_input" > strings/0x409/product |
| 25 | echo "OBMC0001" > strings/0x409/serialnumber |
| 26 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 27 | # Create HID keyboard function |
| 28 | mkdir functions/hid.0 |
Eddie James | b9c253d | 2018-12-11 13:25:50 -0600 | [diff] [blame] | 29 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 30 | echo 1 > functions/hid.0/protocol # 1: keyboard |
| 31 | echo 8 > functions/hid.0/report_length |
| 32 | echo 1 > functions/hid.0/subclass |
Eddie James | b9c253d | 2018-12-11 13:25:50 -0600 | [diff] [blame] | 33 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 34 | # 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 |
| 67 | echo -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 |
| 70 | mkdir functions/hid.1 |
| 71 | |
| 72 | echo 2 > functions/hid.1/protocol # 2: mouse |
| 73 | echo 5 > functions/hid.1/report_length |
| 74 | echo 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 |
| 107 | echo -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 James | b9c253d | 2018-12-11 13:25:50 -0600 | [diff] [blame] | 109 | # Create configuration |
| 110 | mkdir configs/c.1 |
| 111 | mkdir configs/c.1/strings/0x409 |
| 112 | |
| 113 | echo 0x80 > configs/c.1/bmAttributes |
| 114 | echo 200 > configs/c.1/MaxPower |
| 115 | echo "" > configs/c.1/strings/0x409/configuration |
| 116 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 117 | # Link HID functions to configuration |
| 118 | ln -s functions/hid.0 configs/c.1 |
| 119 | ln -s functions/hid.1 configs/c.1 |
Eddie James | b9c253d | 2018-12-11 13:25:50 -0600 | [diff] [blame] | 120 | |
| 121 | # Enable gadget |
| 122 | dev_name="1e6a0000.usb-vhub" |
| 123 | i=0 |
| 124 | num_ports=5 |
| 125 | base_usb_dir="/sys/bus/platform/devices/${dev_name}/${dev_name}:p" |
| 126 | while [ $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 |
| 132 | done |
| 133 | echo "${dev_name}:p${port}" > UDC |
| 134 | |
| 135 | cd "${original_directory}" |