Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1289477
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v3 13/36] usb: gadget: composite: enable eps before calling set_alt() callback |
| Date | 2015-12-11 12:40 +0100 |
| Message-ID | <qEudk-3DB-27@gated-at.bofh.it> (permalink) |
| References | <qEu3E-3z9-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Change set_alt() behavior for functions using new API. Before we call
set_alt() callback, we disable endpoints of previously selected altsetting,
and enable endpoints of currently selected altsetting, which reduces
amount of boilerplate code in USB functions.
We also calculate index of interface in function and pass it to set_alt()
callback instead of passing index of interface in configuration which has
to be obtained from interface descriptor. This simplifies altsetting
changes handling in code of USB functions.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/composite.c | 80 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 78 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 3695b75..34721ef 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -654,6 +654,26 @@ static void usb_function_free_vendor_descs(struct usb_function *f)
}
/**
+ * usb_interface_id_to_index - if interface with a specified id belongs
+ * to given USB function, return its index within descriptors array
+ * of this function
+ * @f: USB function
+ * @id: id number of interface
+ *
+ * Returns interface index on success, else negative errno.
+ */
+static int usb_interface_id_to_index(struct usb_function *f, u8 id)
+{
+ int i;
+
+ for (i = 0; i < f->descs->intfs_num; ++i)
+ if (f->descs->intfs[i]->id == id)
+ return i;
+
+ return -EINVAL;
+}
+
+/**
* usb_interface_id() - allocate an unused interface ID
* @config: configuration associated with the interface
* @function: function handling the interface
@@ -999,6 +1019,62 @@ static void reset_config(struct usb_composite_dev *cdev)
cdev->delayed_status = 0;
}
+/**
+ * set_alt() - select specified altsetting in given interface
+ * @f: USB function
+ * @i: interface id number
+ * @a: altsetting number
+ *
+ * This function has different behavior depending on which API is used by
+ * given USB function. For functions using old API behavior stays unchanged,
+ * while for functions using new API index of interface in function is
+ * calculated and endpoints are configured and enabled before calling
+ * set_alt() callback.
+ */
+static int set_alt(struct usb_function *f, unsigned i, unsigned a)
+{
+ struct usb_composite_dev *cdev = f->config->cdev;
+ struct usb_composite_altset *alt;
+ struct usb_composite_ep *ep;
+ int e, ret = -EINVAL;
+
+ /* To be removed after switch to new API */
+ if (!usb_function_is_new_api(f))
+ return f->set_alt(f, i, a);
+
+ i = usb_interface_id_to_index(f, i);
+ if (i < 0)
+ return i;
+
+ disable_interface(f, i);
+
+ if (a >= f->descs->intfs[i]->altsets_num)
+ return -EINVAL;
+
+ alt = f->descs->intfs[i]->altsets[a];
+ for (e = 0; e < alt->eps_num; ++e) {
+ ep = alt->eps[e];
+ ret = config_ep_by_speed(cdev->gadget, f, ep->ep);
+ if (ret)
+ goto err;
+ ret = usb_ep_enable(ep->ep);
+ if (ret)
+ goto err;
+ }
+
+ f->descs->intfs[i]->cur_altset = a;
+ ret = f->set_alt(f, i, a);
+ if (ret)
+ goto err;
+
+ return 0;
+err:
+ for (e = 0; e < alt->eps_num; ++e)
+ usb_ep_disable(alt->eps[e]->ep);
+ f->descs->intfs[i]->cur_altset = -1;
+ return ret;
+}
+
static int set_config(struct usb_composite_dev *cdev,
const struct usb_ctrlrequest *ctrl, unsigned number)
{
@@ -1078,7 +1154,7 @@ static int set_config(struct usb_composite_dev *cdev,
set_bit(addr, f->endpoints);
}
- result = f->set_alt(f, tmp, 0);
+ result = set_alt(f, tmp, 0);
if (result < 0) {
DBG(cdev, "interface %d (%s/%p) alt 0 --> %d\n",
tmp, f->name, f, result);
@@ -1979,7 +2055,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
break;
if (w_value && !f->set_alt)
break;
- value = f->set_alt(f, w_index, w_value);
+ value = set_alt(f, w_index, w_value);
if (value == USB_GADGET_DELAYED_STATUS) {
DBG(cdev,
"%s: interface %d (%s) requested delayed status\n",
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v3 00/36] usb: gadget: composite: introduce new function API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 06/36] usb: gadget: composite: introduce new descriptors format Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 23/36] usb: gadget: f_rndis: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 26/36] usb: gadget: f_acm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 34/36] usb: gadget: f_uac1: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 18/36] usb: gadget: composite: enable adding USB functions using new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 04/36] usb: gadget: f_loopback: free requests in loopback_disable() Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 25/36] usb: gadget: f_hid: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 07/36] usb: gadget: composite: add functions for descriptors handling Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 35/36] usb: gadget: f_uac2: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 01/36] Documentation: usb: update usb-tools repository address Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
Re: [PATCH v3 01/36] Documentation: usb: update usb-tools repository address Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2015-12-11 13:40 +0100
[PATCH v3 33/36] usb: gadget: f_subset: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 21/36] usb: gadget: f_sourcesink: convert to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 19/36] usb: gadget: configfs: add new composite API support Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 10/36] usb: gadget: composite: handle vendor descs Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 14/36] usb: gadget: composite: introduce clear_alt() operation Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 32/36] usb: gadget: f_phonet: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 28/36] usb: gadget: f_ncm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 36/36] usb: gadget: f_mass_storage: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 20/36] usb: gadget: f_loopback: convert to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 09/36] usb: gadget: composite: handle function bind Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 22/36] usb: gadget: f_ecm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 24/36] usb: gadget: f_hid: handle requests lifetime properly Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 30/36] usb: gadget: f_serial: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 15/36] usb: gadget: composite: handle get_alt() automatically Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 17/36] usb: gadget: composite: add usb_get_interface_id() function Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 13/36] usb: gadget: composite: enable eps before calling set_alt() callback Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 27/36] usb: gadget: f_eem: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 11/36] usb: gadget: composite: generate old descs for compatibility Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 12/36] usb: gadget: composite: disable eps before calling disable() callback Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 31/36] usb: gadget: f_obex: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 29/36] usb: gadget: f_printer: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 05/36] usb: gadget: configfs: fix error path Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 08/36] usb: gadget: composite: introduce new USB function ops Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 03/36] usb: gadget: f_sourcesink: free requests in sourcesink_disable() Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:50 +0100
csiph-web