Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755395AbbLKL1I (ORCPT ); Fri, 11 Dec 2015 06:27:08 -0500 Received: from mailout3.samsung.com ([203.254.224.33]:46704 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754822AbbLKL1F (ORCPT ); Fri, 11 Dec 2015 06:27:05 -0500 X-AuditID: cbfee61a-f79266d000003652-2b-566ab3024b79 From: Robert Baldyga To: balbi@ti.com Cc: gregkh@linuxfoundation.org, andrzej.p@samsung.com, m.szyprowski@samsung.com, b.zolnierkie@samsung.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Robert Baldyga Subject: [PATCH v3 30/36] usb: gadget: f_serial: conversion to new API Date: Fri, 11 Dec 2015 12:25:09 +0100 Message-id: <1449833115-24065-31-git-send-email-r.baldyga@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1449833115-24065-1-git-send-email-r.baldyga@samsung.com> References: <1449833115-24065-1-git-send-email-r.baldyga@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprKLMWRmVeSWpSXmKPExsVy+t9jQV2mzVlhBl8ajS1mvWxnsdg4Yz2r xcH79RbNi9ezWVzeNYfNYtGyVmaLtUfusls8OLyT3YHDY//cNewefVtWMXocv7GdyePzJrkA ligum5TUnMyy1CJ9uwSujAN3D7MXHDGvmP/TtYHxiV4XIyeHhICJxPQjS9ggbDGJC/fWA9lc HEICsxglHt9czwTh/GSUWP91CStIFZuAjsSW7xMYQWwRAQGJ9S8usYMUMQucY5R4eKcNLCEs 4CbRvHsHkM3BwSKgKvH4ZABImBcovPXRdKhtchInj00Gm8kJFJ988hIziC0k4Crx5vU6xgmM vAsYGVYxSqQWJBcUJ6XnGuallusVJ+YWl+al6yXn525iBAfWM6kdjAd3uR9iFOBgVOLhXcCR FSbEmlhWXJl7iFGCg1lJhPfXBqAQb0piZVVqUX58UWlOavEhRmkOFiVx3tpLkWFCAumJJanZ qakFqUUwWSYOTqkGxu45Tp7uaga9wVwfRA/v0S9L5Q48e+tWZ+ryHTuDZyeeZOdYc2JSWuyM W92RVjsmXEpKnFK+4pJLvbF3Q+bn6vns6ou3PT63JcXihO6iia4NLr3uyhs0Nz7hUv8+U/MU V8Jj5o9/BXrnh791/fpNjfuF1iSvp1+e+231qDTSdbG4lZUwp2GqhhJLcUaioRZzUXEiAALT 2J0oAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7146 Lines: 212 Generate descriptors in new format and attach them to USB function in prep_descs(). Change set_alt() implementation and implement clear_alt() operation. Remove boilerplate code. Signed-off-by: Robert Baldyga --- drivers/usb/gadget/function/f_serial.c | 122 +++++++-------------------------- 1 file changed, 25 insertions(+), 97 deletions(-) diff --git a/drivers/usb/gadget/function/f_serial.c b/drivers/usb/gadget/function/f_serial.c index 6bb44d61..526e664 100644 --- a/drivers/usb/gadget/function/f_serial.c +++ b/drivers/usb/gadget/function/f_serial.c @@ -69,13 +69,6 @@ static struct usb_endpoint_descriptor gser_fs_out_desc = { .bmAttributes = USB_ENDPOINT_XFER_BULK, }; -static struct usb_descriptor_header *gser_fs_function[] = { - (struct usb_descriptor_header *) &gser_interface_desc, - (struct usb_descriptor_header *) &gser_fs_in_desc, - (struct usb_descriptor_header *) &gser_fs_out_desc, - NULL, -}; - /* high speed support: */ static struct usb_endpoint_descriptor gser_hs_in_desc = { @@ -92,13 +85,6 @@ static struct usb_endpoint_descriptor gser_hs_out_desc = { .wMaxPacketSize = cpu_to_le16(512), }; -static struct usb_descriptor_header *gser_hs_function[] = { - (struct usb_descriptor_header *) &gser_interface_desc, - (struct usb_descriptor_header *) &gser_hs_in_desc, - (struct usb_descriptor_header *) &gser_hs_out_desc, - NULL, -}; - static struct usb_endpoint_descriptor gser_ss_in_desc = { .bLength = USB_DT_ENDPOINT_SIZE, .bDescriptorType = USB_DT_ENDPOINT, @@ -118,14 +104,16 @@ static struct usb_ss_ep_comp_descriptor gser_ss_bulk_comp_desc = { .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, }; -static struct usb_descriptor_header *gser_ss_function[] = { - (struct usb_descriptor_header *) &gser_interface_desc, - (struct usb_descriptor_header *) &gser_ss_in_desc, - (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc, - (struct usb_descriptor_header *) &gser_ss_out_desc, - (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc, - NULL, -}; +USB_COMPOSITE_ENDPOINT(ep_in, &gser_fs_in_desc, &gser_hs_in_desc, + &gser_ss_in_desc, &gser_ss_bulk_comp_desc); +USB_COMPOSITE_ENDPOINT(ep_out, &gser_fs_out_desc, &gser_hs_out_desc, + &gser_ss_out_desc, &gser_ss_bulk_comp_desc); + +USB_COMPOSITE_ALTSETTING(intf0alt0, &gser_interface_desc, &ep_in, &ep_out); + +USB_COMPOSITE_INTERFACE(intf0, &intf0alt0); + +USB_COMPOSITE_DESCRIPTORS(serial_descs, &intf0); /* string descriptors: */ @@ -151,28 +139,21 @@ static int gser_set_alt(struct usb_function *f, unsigned intf, unsigned alt) struct f_gser *gser = func_to_gser(f); struct usb_composite_dev *cdev = f->config->cdev; - /* we know alt == 0, so this is an activation or a reset */ - - if (gser->port.in->enabled) { - dev_dbg(&cdev->gadget->dev, - "reset generic ttyGS%d\n", gser->port_num); - gserial_disconnect(&gser->port); - } - if (!gser->port.in->desc || !gser->port.out->desc) { - dev_dbg(&cdev->gadget->dev, + dev_dbg(&cdev->gadget->dev, "activate generic ttyGS%d\n", gser->port_num); - if (config_ep_by_speed(cdev->gadget, f, gser->port.in) || - config_ep_by_speed(cdev->gadget, f, gser->port.out)) { - gser->port.in->desc = NULL; - gser->port.out->desc = NULL; - return -EINVAL; - } - } + + gser->port.in = usb_function_get_ep(f, intf, 0); + if (!gser->port.in) + return -ENODEV; + gser->port.out = usb_function_get_ep(f, intf, 0); + if (!gser->port.out) + return -ENODEV; + gserial_connect(&gser->port, gser->port_num); return 0; } -static void gser_disable(struct usb_function *f) +static void gser_clear_alt(struct usb_function *f, unsigned intf, unsigned alt) { struct f_gser *gser = func_to_gser(f); struct usb_composite_dev *cdev = f->config->cdev; @@ -186,12 +167,9 @@ static void gser_disable(struct usb_function *f) /* serial function driver setup/binding */ -static int gser_bind(struct usb_configuration *c, struct usb_function *f) +static int gser_prep_descs(struct usb_function *f) { - struct usb_composite_dev *cdev = c->cdev; - struct f_gser *gser = func_to_gser(f); int status; - struct usb_ep *ep; /* REVISIT might want instance-specific strings to help * distinguish instances ... @@ -199,57 +177,13 @@ static int gser_bind(struct usb_configuration *c, struct usb_function *f) /* maybe allocate device-global string ID */ if (gser_string_defs[0].id == 0) { - status = usb_string_id(c->cdev); + status = usb_string_id(f->config->cdev); if (status < 0) return status; gser_string_defs[0].id = status; } - /* allocate instance-specific interface IDs */ - status = usb_interface_id(c, f); - if (status < 0) - goto fail; - gser->data_id = status; - gser_interface_desc.bInterfaceNumber = status; - - status = -ENODEV; - - /* allocate instance-specific endpoints */ - ep = usb_ep_autoconfig(cdev->gadget, &gser_fs_in_desc); - if (!ep) - goto fail; - gser->port.in = ep; - - ep = usb_ep_autoconfig(cdev->gadget, &gser_fs_out_desc); - if (!ep) - goto fail; - gser->port.out = ep; - - /* support all relevant hardware speeds... we expect that when - * hardware is dual speed, all bulk-capable endpoints work at - * both speeds - */ - gser_hs_in_desc.bEndpointAddress = gser_fs_in_desc.bEndpointAddress; - gser_hs_out_desc.bEndpointAddress = gser_fs_out_desc.bEndpointAddress; - - gser_ss_in_desc.bEndpointAddress = gser_fs_in_desc.bEndpointAddress; - gser_ss_out_desc.bEndpointAddress = gser_fs_out_desc.bEndpointAddress; - - status = usb_assign_descriptors(f, gser_fs_function, gser_hs_function, - gser_ss_function); - if (status) - goto fail; - dev_dbg(&cdev->gadget->dev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n", - gser->port_num, - gadget_is_superspeed(c->cdev->gadget) ? "super" : - gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", - gser->port.in->name, gser->port.out->name); - return 0; - -fail: - ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); - - return status; + return usb_function_set_descs(f, &serial_descs); } static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item) @@ -325,11 +259,6 @@ static void gser_free(struct usb_function *f) kfree(serial); } -static void gser_unbind(struct usb_configuration *c, struct usb_function *f) -{ - usb_free_all_descriptors(f); -} - static struct usb_function *gser_alloc(struct usb_function_instance *fi) { struct f_gser *gser; @@ -346,10 +275,9 @@ static struct usb_function *gser_alloc(struct usb_function_instance *fi) gser->port.func.name = "gser"; gser->port.func.strings = gser_strings; - gser->port.func.bind = gser_bind; - gser->port.func.unbind = gser_unbind; + gser->port.func.prep_descs = gser_prep_descs; gser->port.func.set_alt = gser_set_alt; - gser->port.func.disable = gser_disable; + gser->port.func.clear_alt = gser_clear_alt; gser->port.func.free_func = gser_free; return &gser->port.func; -- 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/