USB/Linux USB Layers/Configfs Composite Gadget/Usage eq. to g zero.ko

From Tizen Wiki
Jump to: navigation, search

Owner

  • Andrzej Pietrasiewicz <andrzej.p (at) samsung.com> (KERNEL)

Code change log

v1..v2:

- fixes after Michal's review, thank you, Michal! - simplified redirecting the setup request

Rebased onto Felipe's master.


Guide

This series aims at integrating configfs into gadget zero, the way it has been done for acm, ncm, ecm, eem, ecm subset, rndis, obex, phonet,

mass_storage and FunctionFS. It contains everything that is required to provide the equivalent of g_zero.ko with configfs.


BACKWARD COMPATIBILITY

Please note that the old g_zero.ko is still available and works.

USING THE NEW "GADGET"

Please refer to this post:

http://www.spinics.net/lists/linux-usb/msg76388.html

for general information from Sebastian on how to use configfs-based gadgets (*).

With configfs the procedure is as follows, compared to the information mentioned above (*):

instead of

mkdir functions/acm.ttyS1 

do

mkdir functions/Loopback.0
mkdir functions/SourceSink.0

In the Loopback.0 directory there will be two attributes:

qlen - depth of loopback queue

bulk_buflen - buffer length

In the SourceSink.0 directory there will be six attributes:

pattern - 0 (all zeros), 1 (mod63), 2 (none)

isoc_interval - 1..16

isoc_maxpacket - 0 - 1023 (fs), 0 - 1024 (hs/ss)

isoc_mult - 0..2 (hs/ss only)

isoc_maxburst - 0..15 (ss only)

bulk_buflen - buffer length


An example gadget with Loopback and SourceSink functions:

$ modprobe libcomposite

$ mount none cfg -t configfs

$ mkdir cfg/usb_gadget/g1
$ cd cfg/usb_gadget/g1
 
$ mkdir configs/c.1
$ mkdir configs/c.2
$ mkdir functions/Loopback.0
$ mkdir functions/SourceSink.0

$ mkdir strings/0x409
$ mkdir configs/c.1/strings/0x409
$ mkdir configs/c.2/strings/0x409

$ echo 0x2d01 > idProduct
$ echo 0x04e8 > idVendor

$ echo my-serial-num > strings/0x409/serialnumber
$ echo my-manufacturer > strings/0x409/manufacturer
$ echo "Test gadget" > strings/0x409/product

$ echo "Conf 1" > configs/c.1/strings/0x409/configuration
$ echo "Conf 2" > configs/c.2/strings/0x409/configuration
$ echo 120 > configs/c.1/MaxPower
$ ln -s functions/Loopback.0 configs/c.1
$ ln -s functions/SourceSink.0 configs/c.2

$ echo s3c-hsotg > cfg/usb_gadget/g1/UDC

After unbinding the gadget with

echo "" > UDC

the symbolic links in the configuration directory can be removed, the strings/* subdirectories in the configuration directory can

be removed, the strings/* subdirectories at the gadget level can be removed and the configs/* subdirectories can be removed.

The functions/* subdirectories can be removed. After that the gadget directory can be removed.

Daemons need to be closed and then the respective modules can be unloaded.


TESTING THE FUNCTIONS

loopback, souresink)

device: run the gadget

host: test-usb

http://www.linux-usb.org/usbtest/testusb.c

The results should be the same as with the g_zero.ko.