Fix HID issues

Mixed type HID report descriptor in the current trunk doesn't work
well so this patch fixes the HID creation logic to make it use
composite configuration which has separated keyboard and mouse
HID descriptor using a single USB port.

ikvm service also should be changed using below setting after
applying this patch:
ExecStart=/usr/bin/env obmc-ikvm -v /dev/video0 -k /dev/hidg0 -p /dev/hidg1

Change-Id: I9b2975f4fdade2c6030def829951d02b24bea562
Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>
diff --git a/create_usbhid.sh b/create_usbhid.sh
index c4d9d71..6562991 100644
--- a/create_usbhid.sh
+++ b/create_usbhid.sh
@@ -14,10 +14,6 @@
 # add basic information
 echo 0x0100 > bcdDevice
 echo 0x0200 > bcdUSB
-echo 0x00 > bDeviceClass
-echo 0x00 > bDeviceProtocol
-echo 0x00 > bDeviceSubClass
-echo 0x0b > bMaxPacketSize0
 echo 0x0104 > idProduct		# Multifunction Composite Gadget
 echo 0x1d6b > idVendor		# Linux Foundation
 
@@ -28,15 +24,88 @@
 echo "virtual_input" > strings/0x409/product
 echo "OBMC0001" > strings/0x409/serialnumber
 
-# Create HID function
-mkdir functions/hid.usb0
+# Create HID keyboard function
+mkdir functions/hid.0
 
-echo 1 > functions/hid.usb0/protocol
-echo 11 > functions/hid.usb0/report_length
-echo 1 > functions/hid.usb0/subclass
+echo 1 > functions/hid.0/protocol	# 1: keyboard
+echo 8 > functions/hid.0/report_length
+echo 1 > functions/hid.0/subclass
 
-# Binary HID descriptor
-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
+# Binary HID keyboard descriptor
+#  0x05, 0x01, // USAGE_PAGE (Generic Desktop)
+#  0x09, 0x06, // USAGE (Keyboard)
+#  0xa1, 0x01, // COLLECTION (Application)
+#  0x05, 0x07, //   USAGE_PAGE (Keyboard)
+#  0x19, 0xe0, //   USAGE_MINIMUM (Keyboard LeftControl)
+#  0x29, 0xe7, //   USAGE_MAXIMUM (Keyboard Right GUI)
+#  0x15, 0x00, //   LOGICAL_MINIMUM (0)
+#  0x25, 0x01, //   LOGICAL_MAXIMUM (1)
+#  0x75, 0x01, //   REPORT_SIZE (1)
+#  0x95, 0x08, //   REPORT_COUNT (8)
+#  0x81, 0x02, //   INPUT (Data,Var,Abs)
+#  0x95, 0x01, //   REPORT_COUNT (1)
+#  0x75, 0x08, //   REPORT_SIZE (8)
+#  0x81, 0x03, //   INPUT (Data,Var,Abs)
+#  0x95, 0x05, //   REPORT_COUNT (5)
+#  0x75, 0x01, //   REPORT_SIZE (1)
+#  0x05, 0x08, //   USAGE_PAGE (LEDs)
+#  0x19, 0x01, //   USAGE_MINIMUM (Num Lock)
+#  0x29, 0x05, //   USAGE_MAXIMUM (Kana)
+#  0x91, 0x02, //   OUTPUT (Data,Var,Abs)
+#  0x95, 0x01, //   REPORT_COUNT (1)
+#  0x75, 0x03, //   REPORT_SIZE (3)
+#  0x91, 0x03, //   OUTPUT (Cnst,Var,Abs)
+#  0x95, 0x06, //   REPORT_COUNT (6)
+#  0x75, 0x08, //   REPORT_SIZE (8)
+#  0x15, 0x00, //   LOGICAL_MINIMUM (0)
+#  0x25, 0x65, //   LOGICAL_MAXIMUM (101)
+#  0x05, 0x07, //   USAGE_PAGE (Keyboard)
+#  0x19, 0x00, //   USAGE_MINIMUM (Reserved (no event indicated))
+#  0x29, 0x65, //   USAGE_MAXIMUM (Keyboard Application)
+#  0x81, 0x00, //   INPUT (Data,Ary,Abs)
+#  0xc0        // END_COLLECTION
+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
+
+# Create HID mouse function
+mkdir functions/hid.1
+
+echo 2 > functions/hid.1/protocol	# 2: mouse
+echo 5 > functions/hid.1/report_length
+echo 1 > functions/hid.1/subclass
+
+# Binary HID mouse descriptor (absolute coordinate)
+#  0x05, 0x01,       // USAGE_PAGE (Generic Desktop)
+#  0x09, 0x02,       // USAGE (Mouse)
+#  0xa1, 0x01,       // COLLECTION (Application)
+#  0x09, 0x01,       //   USAGE (Pointer)
+#  0xa1, 0x00,       //   COLLECTION (Physical)
+#  0x05, 0x09,       //     USAGE_PAGE (Button)
+#  0x19, 0x01,       //     USAGE_MINIMUM (Button 1)
+#  0x29, 0x03,       //     USAGE_MAXIMUM (Button 3)
+#  0x15, 0x00,       //     LOGICAL_MINIMUM (0)
+#  0x25, 0x01,       //     LOGICAL_MAXIMUM (1)
+#  0x95, 0x03,       //     REPORT_COUNT (3)
+#  0x75, 0x01,       //     REPORT_SIZE (1)
+#  0x81, 0x02,       //     INPUT (Data,Var,Abs)
+#  0x95, 0x01,       //     REPORT_COUNT (1)
+#  0x75, 0x05,       //     REPORT_SIZE (5)
+#  0x81, 0x03,       //     INPUT (Cnst,Var,Abs)
+#  0x05, 0x01,       //     USAGE_PAGE (Generic Desktop)
+#  0x09, 0x30,       //     USAGE (X)
+#  0x09, 0x31,       //     USAGE (Y)
+#  0x35, 0x00,       //     PHYSICAL_MINIMUM (0)
+#  0x46, 0xff, 0x7f, //     PHYSICAL_MAXIMUM (32767)
+#  0x15, 0x00,       //     LOGICAL_MINIMUM (0)
+#  0x26, 0xff, 0x7f, //     LOGICAL_MAXIMUM (32767)
+#  0x65, 0x11,       //     UNIT (SI Lin:Distance)
+#  0x55, 0x00,       //     UNIT_EXPONENT (0)
+#  0x75, 0x10,       //     REPORT_SIZE (16)
+#  0x95, 0x02,       //     REPORT_COUNT (2)
+#  0x81, 0x02,       //     INPUT (Data,Var,Abs)
+#  0xc0,             //   END_COLLECTION
+#  0xc0              // END_COLLECTION
+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
+
 # Create configuration
 mkdir configs/c.1
 mkdir configs/c.1/strings/0x409
@@ -45,8 +114,9 @@
 echo 200 > configs/c.1/MaxPower
 echo "" > configs/c.1/strings/0x409/configuration
 
-# Link HID function to configuration
-ln -s functions/hid.usb0 configs/c.1
+# Link HID functions to configuration
+ln -s functions/hid.0 configs/c.1
+ln -s functions/hid.1 configs/c.1
 
 # Enable gadget
 dev_name="1e6a0000.usb-vhub"