Skip to content

Commit

Permalink
usb: gadget: accessory: Add Android Accessory function
Browse files Browse the repository at this point in the history
USB accessory mode allows users to connect USB host hardware
specifically designed for Android-powered devices. The accessories
must adhere to the Android accessory protocol outlined in the
http://accessories.android.com documentation. This allows
Android devices that cannot act as a USB host to still interact with
USB hardware. When an Android device is in USB accessory mode, the
attached Android USB accessory acts as the host, provides power
to the USB bus, and enumerates connected devices.

Change-Id: I67964b50d278f3c0471d47efbb7b0973a3502681
Signed-off-by: Mike Lockwood <lockwood@android.com>

usb: gadget: accessory: Fix section mismatch

create_bulk_endpoints should not be __init since it is called when
accessory is enabled

Change-Id: If827a4531f0f6c15af938345163923186368e2a5
Signed-off-by: Benoit Goby <benoit@android.com>

usb: gadget: add ACCESSORY_SET_AUDIO_MODE control request and ioctl

The control request will be used by the host to enable/disable USB audio
and the ioctl will be used by userspace to read the audio mode

Change-Id: I81c38611b588451e80eacdccc417ca6e11c60cab
Signed-off-by: Mike Lockwood <lockwood@google.com>

usb: gadget: f_accessory: add support for HID input devices

Change-Id: I4f1452db32508382df52acdc47c0eb395ae328c7
Signed-off-by: Mike Lockwood <lockwood@google.com>

usb: gadget: accessory: Fix section mismatch (again)

create_bulk_endpoints should not be __init since it is called when
accessory is enabled.

Change-Id: Iac6e9f29d53c93760e926efd8e7603432632acb4
Signed-off-by: Todd Poynor <toddpoynor@google.com>

usb: gadget: android: Fixes and hacks to make android usb gadget compile on 3.8

Change-Id: I332a6802dbd49b4018b9318b8621d26ed94c955d
Signed-off-by: Arve Hjønnevåg <arve@android.com>

usb: gadget: f_accessory: move userspace interface to uapi

Move the entire contents of linux/usb/f_accessory.h header to uapi,
it only contains a userspace interface.

Change-Id: Ieb5547da449588ae554988a201c0e6b4e3afc531
Signed-off-by: Colin Cross <ccross@android.com>

drivers: usb: gadget: 64-bit related type fixes

Change-Id: I2f9b12e1e0cdfe64ffe20db78d319a6221821184
Signed-off-by: Greg Hackmann <ghackmann@google.com>

usb: gadget: f_accessory: Enabled Zero Length Packet (ZLP) for acc_write

Accessory connected to Android Device requires
Zero Length Packet (ZLP) to be written when data
transferred out from the Android device are multiples
of wMaxPacketSize (64bytes (Full-Speed) / 512bytes (High-Speed))
to end the transfer.

Change-Id: Ib2c2c0ab98ef9afa10e74a720142deca5c0ed476
Signed-off-by: Anson Jacob <ansonkuzhumbil@gmail.com>

usb: gadget: check for accessory device before disconnecting HIDs

While disabling ConfigFS Android gadget, android_disconnect() calls
kill_all_hid_devices(), if CONFIG_USB_CONFIGFS_F_ACC is enabled, to free
the registered HIDs without checking whether the USB accessory device
really exist or not. If USB accessory device doesn't exist then we run into
following kernel panic:
----8<----
[  136.724761] Unable to handle kernel NULL pointer dereference at virtual address 00000064
[  136.724809] pgd = c0204000
[  136.731924] [00000064] *pgd=00000000
[  136.737830] Internal error: Oops: 5 [#1] SMP ARM
[  136.738108] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 3.18.0-rc4-00400-gf75300e-dirty torvalds#76
[  136.742788] task: c0fb19d8 ti: c0fa4000 task.ti: c0fa4000
[  136.750890] PC is at _raw_spin_lock_irqsave+0x24/0x60
[  136.756246] LR is at kill_all_hid_devices+0x24/0x114
---->8----

This patch adds a test to check if USB Accessory device exists before freeing HIDs.

Change-Id: Ie229feaf0de3f4f7a151fcaa9a994e34e15ff73b
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>

===> SQ usb: gadget: Accessory:Migrate to USB_FUNCTION API

This patch adds support to use Android accessory
gadget function through the
DECLARE_USB_FUNCTION_INIT interface.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Change-Id: Ib352752d5bc905fa1df9049b53eabf1294930db7

SQ: f_accessory: usb: gadget: cleanup: fix unused variable and function warnings

Remove unused variables and functions to fix following
build warnings:

  CC      drivers/usb/gadget/configfs.o
drivers/usb/gadget/configfs.c: In function ‘gadgets_make’:
drivers/usb/gadget/configfs.c:1710:6: warning: unused variable ‘err’ [-Wunused-variable]
  int err;
      ^
drivers/usb/gadget/configfs.c:1709:27: warning: unused variable ‘attr’ [-Wunused-variable]
  struct device_attribute *attr;
                           ^
drivers/usb/gadget/configfs.c:1708:28: warning: unused variable ‘attrs’ [-Wunused-variable]
  struct device_attribute **attrs;
                            ^
drivers/usb/gadget/configfs.c: In function ‘gadgets_drop’:
drivers/usb/gadget/configfs.c:1774:27: warning: unused variable ‘attr’ [-Wunused-variable]
  struct device_attribute *attr;
                           ^
drivers/usb/gadget/configfs.c:1773:28: warning: unused variable ‘attrs’ [-Wunused-variable]
  struct device_attribute **attrs;
                            ^
<snip>...
  CC      drivers/usb/gadget/function/f_mtp.o
drivers/usb/gadget/function/f_mtp.c:1219:12: warning: ‘mtp_bind_config’ defined but not used [-Wunused-function]
 static int mtp_bind_config(struct usb_configuration *c, bool ptp_config)
            ^
drivers/usb/gadget/function/f_mtp.c:1300:12: warning: ‘mtp_setup’ defined but not used [-Wunused-function]
 static int mtp_setup(void)
            ^
<snip>...
  CC      drivers/usb/gadget/function/f_accessory.o
drivers/usb/gadget/function/f_accessory.c:969:1: warning: ‘acc_function_bind’ defined but not used [-Wunused-function]
 acc_function_bind(struct usb_configuration *c, struct usb_function *f) {
 ^
drivers/usb/gadget/function/f_accessory.c:1172:12: warning: ‘acc_bind_config’ defined but not used [-Wunused-function]
 static int acc_bind_config(struct usb_configuration *c)
            ^

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>

SQ f_accessory: fix false disconnect due to a signal sent to the reading process

- In the current implementation, when a signal is sent to the reading process,
  read is cancelled by calling usb_ep_dequeue, which lead into calling
  acc_complete_out with ECONNRESET, but the current logic treats it as
  disconnection, which makes the device inaccessible until cable is actually
  disconnected.
- The fix calls disconnect only when ESHUTDOWN error is passed.
- If data has already arrived while trying cancelling, the data is marked
  as available, and it will be read out on the next read. This is necessary
  as USB bulk is assumed to guarantee no data loss.

Signed-off-by: keunyoung <keunyoung@google.com>

===> SQ CHROMIUM: usb: gadget: f_accessory: add .raw_request callback

After this upstream commit: 3c86726,
.raw_request is mandatory in hid_ll_driver structure, hence add an empty
raw_request() function.

BUG=chrome-os-partner:49140
TEST=none

Change-Id: Idd0bbe6960aad2c557376e4a24827d7e1df8e023
Signed-off-by: Mark Kuo <mkuo@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/321038
Commit-Ready: Andrew Bresticker <abrestic@chromium.org>
Tested-by: Andrew Bresticker <abrestic@chromium.org>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>

===> SQ usb: gadget: f_accessory: remove duplicate endpoint alloc

usb_ep_autoconfig is called twice for allocating
bulk out endpoint.

Removed the unwanted call.

Fixes Issue: 67180

Change-Id: I03e87a86fbbbc85831ff7f0496adf038d1de2956
Signed-off-by: Anson Jacob <ansonjacob.aj@gmail.com>

===> SQ usb: gadget: Relocate f_accessory

3.18 kernel has reorganized drivers/usb/gadget
directory. Moving accessory gadget driver from
drivers/usb/gadget to drivers/usb/gadget/function

Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
Change-Id: If73c6df0537c4b1f51338ed3b0db817e51f06b4a
  • Loading branch information
benoitgoby authored and metux committed Nov 10, 2016
1 parent 400b7d6 commit 7e763a7
Show file tree
Hide file tree
Showing 5 changed files with 1,507 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/usb/gadget/Kconfig
Expand Up @@ -215,6 +215,9 @@ config USB_F_MTP
config USB_F_PTP
tristate

config USB_F_ACC
tristate

# this first set of drivers all depend on bulk-capable hardware.

config USB_CONFIGFS
Expand Down Expand Up @@ -382,6 +385,13 @@ config USB_CONFIGFS_F_PTP
help
USB gadget PTP support

config USB_CONFIGFS_F_ACC
boolean "Accessory gadget"
depends on USB_CONFIGFS
select USB_F_ACC
help
USB gadget Accessory support

config USB_CONFIGFS_F_UAC1
bool "Audio Class 1.0"
depends on USB_CONFIGFS
Expand Down
2 changes: 2 additions & 0 deletions drivers/usb/gadget/function/Makefile
Expand Up @@ -50,3 +50,5 @@ usb_f_mtp-y := f_mtp.o
obj-$(CONFIG_USB_F_MTP) += usb_f_mtp.o
usb_f_ptp-y := f_ptp.o
obj-$(CONFIG_USB_F_PTP) += usb_f_ptp.o
usb_f_accessory-y := f_accessory.o
obj-$(CONFIG_USB_F_ACC) += usb_f_accessory.o

0 comments on commit 7e763a7

Please sign in to comment.