[PATCHv3 00/29] Equivalent of g_printer with configfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This series aims at integrating configfs into printer, the way
it has been done for acm, ncm, ecm, eem, ecm subset, rndis, obex, phonet,
mass_storage, FunctionFS, loopback, sourcesink, uac1, uac2, uvc, midi
and hid.

The printer gadget before the changes has some bugs, and although it
uses the composite framework, it is not ready for splitting into
a reusable f_printer.c and a legacy printer.c. Most of the patches
in the series are preparation for factoring out f_printer.c. Once
f_printer.c is extracted from printer.c, it can be converted to
use the new function interface, and then the usual procedure of
adding configfs support follows.

Rebased onto Felipe's testing/next.

v2..v3:

- merged v1 with v2 version
- fixed the bug with handling of req_match method according to Bin Liu's
suggestion
- removed Felipe's Signed-off-by because the whole v1 + v2 series
was dropped by him

BACKWARD COMPATIBILITY
======================

Please note that the old g_printer.ko is still available and works.
There is just one minor difference, the dev node at the gadget's side
is called /dev/g_printer<number> instead of /dev/g_printer. This makes
sense, because there are more than one instances of this function allowed
after the series is applied. If /dev/g_printer is needed, it can be
easily added as a symlink with udev rules.

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/printer.<instance name>

e.g. mkdir functions/printer.usb0.

In the printer.usb0 directory there will be the following attributes:


	pnp_string	- Data to be passed to the host in pnp string
	q_len		- Number of requests per endpoint.

Below is a script which creates a printer gadget on a board with dwc2:

$ modprobe libcomposite
$ mount none cfg -t configfs
$ mkdir cfg/usb_gadget/g1
$ cd cfg/usb_gadget/g1
$ mkdir configs/c.1
$ mkdir functions/printer.usb0
$ mkdir strings/0x409
$ mkdir configs/c.1/strings/0x409
$ echo 0x0525 > idVendor
$ echo 0xa4a8 > idProduct
$ echo 1 > strings/0x409/serialnumber
$ echo Samsung > strings/0x409/manufacturer
$ echo Printer Gadget > strings/0x409/product
$ echo 10 > functions/printer.usb0/q_len
$ echo "MFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;" > functions/printer.usb0/pnp_string
$ echo "Conf 1" > configs/c.1/strings/0x409/configuration
$ echo 120 > configs/c.1/MaxPower
$ ln -s functions/printer.usb0 configs/c.1
$ echo 12480000.hsotg > UDC

TESTING THE FUNCTION
====================

The most basic testing:

device: run the gadget,

ls -l /devices/virtual/usb_printer_gadget/

should show g_printer<number>.

If udev is active, then /dev/g_printer<number> should appear automatically.

host:

If udev is active, then e.g. /dev/usb/lp0 should appear.

host->device transmission:

device:
# cat /dev/g_printer<number>
host:
# cat > /dev/usb/lp0

device->host transmission:

# cat > /dev/g_printer<number>
host:
# cat /dev/usb/lp0

More advanced testing can be done with the prn_example
described in Documentation/usb/gadget-printer.txt.



Andrzej Pietrasiewicz (29):
  usb: gadget: composite: don't try standard handling for non-standard
    requests
  usb: gadget: printer: enqueue printer's response for setup request
  usb: gadget: printer: remove unused and empty printer_unbind
  usb: gadget: printer: eliminate random pointer dereference
  usb: gadget: printer: revert usb_add_function() effect in error
    recovery
  usb: gadget: printer: add missing error handling
  usb: gadget: printer: eliminate pdev member of struct printer_dev
  usb: gadget: printer: follow the naming convention for usb_add_config
    callback
  usb: gadget: printer: standardize printer_do_config
  usb: gadget: printer: move function-related bind code to function's
    bind
  usb: gadget: printer: call usb_add_function() last
  usb: gadget: printer: move function-related unbind code to function's
    unbind
  usb: gadget: printer: define pnp string buffer length
  usb: gadget: printer: don't access file global pnp_string in
    function's code
  usb: gadget: printer: add setup and cleanup functions
  usb: gadget: printer: call gprinter_setup() from gadget's bind
  usb: gadget: printer: eliminate file global printer_mutex
  usb: gadget: printer: don't access file global usb_printer_gadget in
    function's code
  usb: gadget: printer: add container_of helper for printer_dev
  usb: gadget: composite: add req_match method to usb_function
  usb: gadget: printer: name class specific requests
  usb: gadget: printer: add req_match for printer function
  usb: gadget: printer: allocate printer_dev instances dynamically
  usb: gadget: printer: factor out f_printer
  usb: gadget: f_printer: convert to new function interface with
    backward compatibility
  usb: gadget: printer: convert to new interface of f_printer
  usb: gadget: f_printer: remove compatibility layer
  usb: gadget: printer: use module_usb_composite_driver helper macro
  usb: gadget: printer: add configfs support

 .../ABI/testing/configfs-usb-gadget-printer        |    9 +
 Documentation/usb/gadget-testing.txt               |   47 +
 drivers/usb/gadget/Kconfig                         |   16 +
 drivers/usb/gadget/composite.c                     |   13 +-
 drivers/usb/gadget/function/Makefile               |    2 +
 drivers/usb/gadget/function/f_printer.c            | 1475 ++++++++++++++++++++
 drivers/usb/gadget/function/u_printer.h            |   37 +
 drivers/usb/gadget/legacy/Kconfig                  |    1 +
 drivers/usb/gadget/legacy/printer.c                | 1239 +---------------
 include/linux/usb/composite.h                      |    3 +
 10 files changed, 1650 insertions(+), 1192 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-printer
 create mode 100644 drivers/usb/gadget/function/f_printer.c
 create mode 100644 drivers/usb/gadget/function/u_printer.h

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux