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 |
| 17 | echo 0x00 > bDeviceClass |
| 18 | echo 0x00 > bDeviceProtocol |
| 19 | echo 0x00 > bDeviceSubClass |
| 20 | echo 0x0b > bMaxPacketSize0 |
| 21 | echo 0x0104 > idProduct # Multifunction Composite Gadget |
| 22 | echo 0x1d6b > idVendor # Linux Foundation |
| 23 | |
| 24 | # create English locale |
| 25 | mkdir strings/0x409 |
| 26 | |
| 27 | echo "OpenBMC" > strings/0x409/manufacturer |
| 28 | echo "virtual_input" > strings/0x409/product |
| 29 | echo "OBMC0001" > strings/0x409/serialnumber |
| 30 | |
| 31 | # Create HID function |
| 32 | mkdir functions/hid.usb0 |
| 33 | |
| 34 | echo 1 > functions/hid.usb0/protocol |
| 35 | echo 11 > functions/hid.usb0/report_length |
| 36 | echo 1 > functions/hid.usb0/subclass |
| 37 | |
| 38 | # Binary HID descriptor |
| 39 | echo -n -e '\x05\x01\x09\x06\xa1\x01\x85\x01\x05\x07\x19\xe0\x29\xe7\x15\x00\x25\x01\x95\x08\x75\x01\x81\x02\x95\x01\x75\x08\x81\x01\x95\x05\x75\x08\x15\x01\x25\x7f\x05\x07\x19\x01\x29\x7f\x81\x00\xc0\x05\x01\x09\x02\xa1\x01\x85\x02\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\x75\x10\x95\x02\x81\x02\xc0\xc0' > functions/hid.usb0/report_desc |
| 40 | # Create configuration |
| 41 | mkdir configs/c.1 |
| 42 | mkdir configs/c.1/strings/0x409 |
| 43 | |
| 44 | echo 0x80 > configs/c.1/bmAttributes |
| 45 | echo 200 > configs/c.1/MaxPower |
| 46 | echo "" > configs/c.1/strings/0x409/configuration |
| 47 | |
| 48 | # Link HID function to configuration |
| 49 | ln -s functions/hid.usb0 configs/c.1 |
| 50 | |
| 51 | # Enable gadget |
| 52 | dev_name="1e6a0000.usb-vhub" |
| 53 | i=0 |
| 54 | num_ports=5 |
| 55 | base_usb_dir="/sys/bus/platform/devices/${dev_name}/${dev_name}:p" |
| 56 | while [ $i -lt $num_ports ]; do |
| 57 | port=$(($i + 1)) |
| 58 | i=$port |
| 59 | if [ ! -e "${base_usb_dir}${port}/gadget/suspended" ]; then |
| 60 | break |
| 61 | fi |
| 62 | done |
| 63 | echo "${dev_name}:p${port}" > UDC |
| 64 | |
| 65 | cd "${original_directory}" |