How to enable USB gadget function?

I want to enable the USB gadget function, My config is : CONFIG_USB_GADGET=y CONFIG_USB_SUNXI_UDC0=y CONFIG_USB_GADGET_DUALSPEED=y CONFIG_USB_G_ANDROID=y CONFIG_USB_SUNXI_USB=y CONFIG_USB_SUNXI_USB_MANAGER=y CONFIG_USB_SUNXI_USB0_OTG=y CONFIG_USB_SUNXI_USB_DEBUG=y

in sys_config.fex [usbc0] usb_used = 1 usb_port_type = 2 usb_detect_type = 1 usb_id_gpio = port:PH11<0><1> usb_det_vbus_gpio = “axp_ctrl” usb_drv_vbus_gpio = port:power4<1><0><0> usb_restrict_gpio = usb_host_init_state = 0 usb_restric_flag = 0 usb_restric_voltage = 3550000 usb_restric_capacity= 5 usb_regulator_io = “vcc-usb0-33” usb_regulator_vol = 3300000 usb_not_suspend = 0

After build and pack, flash into emmc and reboot, I can see log on console: … [ 3.030147] ------print_msc_config-----
[ 3.034404] vendor_id = 0x18d1
[ 3.038948] mass_storage_id = 0x1
[ 3.043223] adb_id = 0x2
[ 3.047478] usb_manufacturer_name = USB Developer
[ 3.052719] usb_product_name = Android
[ 3.057360] usb_serial_number = 20080411
[ 3.062117] msc_vendor_name = USB 2.0
[ 3.066758] msc_product_name = USB Flash Driver
[ 3.072287] msc_release = 100
[ 3.076542] serial_unique = 1
[ 3.080620] luns = 3
[ 3.084682] ---------------------------
[ 3.089125] udc sunxi_usb_udc: registering UDC driver [android_usb]
[ 3.096282] file system registered
[ 3.101049] gserial_setup: registered 4 ttyGS* devices
[ 3.107735] android_usb gadget: Mass Storage Function, version: 2009/09/11
[ 3.115399] android_usb gadget: Number of LUNs=3
[ 3.120542] lun0: LUN: removable file: (no medium)
[ 3.125956] lun1: LUN: removable file: (no medium)
[ 3.131390] lun2: LUN: removable file: (no medium)
[ 3.136805] android_usb gadget: I/O thread pid: 95
[ 3.142145] lun name: lun
[ 3.145061] lun name: lun1
[ 3.148068] lun name: lun2
[ 3.151441] android_bind, serial_unique = 1
[ 3.156085] get usb_serial_number success from boot command line
[ 3.162601] android_usb gadget: android_usb ready

But I can’t see anything on host PC with lsusb,

What else I missing ?

something useful here : http://igor2.repo.hu/tmp/opi_usb_gadget.txt

Thanks to Orange PI community http://www.orangepi.org/orangepibbsen/forum.php?mod=viewthread&tid=848

If someone want enable g_hid function, here are some experience sharing :slight_smile:

  1. create a platform_device in arch/arm/mach-sunxi/sun8i.c #include "<"linux/usb/g_hid.h>

static struct platform_device hidg_plat = { .name = “hidg”, .id = 0, .num_resources = 0, .resource = 0, .dev = { .platform_data = &touch_data, }, }; static struct hidg_func_descriptor touch_data = { .subclass = 0, .protocol = 0, .report_length = 64, //assume interrupt transfer .report_desc_length = xxx, .report_desc = { … here put you hid descriptor }

static struct platform_device *sunxi_dev[] __initdata = { #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE) &serial_dev, #endif #if defined(CONFIG_CPU_HAS_PMU) &sunxi_pmu_dev, #endif &hidg_plat, //add hid }; #endif

  1. Enable configuration CONFIG_USB_G_HID=y

That’s all, have fun.