Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755446AbbLKL1Q (ORCPT ); Fri, 11 Dec 2015 06:27:16 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:49325 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754175AbbLKL1M (ORCPT ); Fri, 11 Dec 2015 06:27:12 -0500 X-AuditID: cbfee61b-f793c6d00000236c-03-566ab30ee0cf 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 34/36] usb: gadget: f_uac1: conversion to new API Date: Fri, 11 Dec 2015 12:25:13 +0100 Message-id: <1449833115-24065-35-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+NgFprOLMWRmVeSWpSXmKPExsVy+t9jQV2+zVlhBkfvKFvMetnOYrFxxnpW i4P36y2aF69ns7i8aw6bxaJlrcwWa4/cZbd4cHgnuwOHx/65a9g9+rasYvQ4fmM7k8fnTXIB LFFcNimpOZllqUX6dglcGYeXf2MsuGRVMenoWfYGxnOGXYycHBICJhIrly1ihrDFJC7cW8/W xcjFISQwi1Hi3o02ZgjnJ6PE6e4fTCBVbAI6Elu+T2AEsUUEBCTWv7jEDlLELHCOUeLhnTaw hLCAi8SajevAbBYBVYnWXzPYQWxeATeJ+Uufs0Gsk5M4eWwyK4jNCRSffPIS2BlCAq4Sb16v Y5zAyLuAkWEVo0RqQXJBcVJ6rlFearlecWJucWleul5yfu4mRnBwPZPewXh4l/shRgEORiUe 3gUcWWFCrIllxZW5hxglOJiVRHh/bQAK8aYkVlalFuXHF5XmpBYfYpTmYFES5913KTJMSCA9 sSQ1OzW1ILUIJsvEwSnVwNh+1OjujWuqx7PeO60JL3CcUSawuDSiaR23zC6exlWT1eO4Xc3u O8eu1/+zTSt2/tX7V1sSPphwzgx9fyJ1hWxTc235dWYZof8CcTNeCN2YLG9VJa6jtC/77z6r jDOBZSwu6hcNne025C+4JLNgub3Opv43N/MeTDcOKvp39P2JCqOjkVm+LEosxRmJhlrMRcWJ AOl293sqAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7531 Lines: 225 Generate descriptors in new format and attach them to USB function in prep_descs(). Implement prep_vendor_descs() to supply class specific descriptors. Change set_alt() implementation and implement clear_alt() operation. Remove boilerplate code. Signed-off-by: Robert Baldyga --- drivers/usb/gadget/function/f_uac1.c | 134 +++++++++++++++-------------------- 1 file changed, 58 insertions(+), 76 deletions(-) diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c index 6a2346b..2faf4e4 100644 --- a/drivers/usb/gadget/function/f_uac1.c +++ b/drivers/usb/gadget/function/f_uac1.c @@ -189,24 +189,17 @@ static struct uac_iso_endpoint_descriptor as_iso_out_desc = { .wLockDelay = __constant_cpu_to_le16(1), }; -static struct usb_descriptor_header *f_audio_desc[] = { - (struct usb_descriptor_header *)&ac_interface_desc, - (struct usb_descriptor_header *)&ac_header_desc, +USB_COMPOSITE_ENDPOINT(ep_out, &as_out_ep_desc, + &as_out_ep_desc, NULL, NULL); - (struct usb_descriptor_header *)&input_terminal_desc, - (struct usb_descriptor_header *)&output_terminal_desc, - (struct usb_descriptor_header *)&feature_unit_desc, +USB_COMPOSITE_ALTSETTING(intf0alt0, &ac_interface_desc); +USB_COMPOSITE_ALTSETTING(intf1alt0, &as_interface_alt_0_desc); +USB_COMPOSITE_ALTSETTING(intf1alt1, &as_interface_alt_1_desc, &ep_out); - (struct usb_descriptor_header *)&as_interface_alt_0_desc, - (struct usb_descriptor_header *)&as_interface_alt_1_desc, - (struct usb_descriptor_header *)&as_header_desc, +USB_COMPOSITE_INTERFACE(intf0, &intf0alt0); +USB_COMPOSITE_INTERFACE(intf1, &intf1alt0, &intf1alt1); - (struct usb_descriptor_header *)&as_type_i_desc, - - (struct usb_descriptor_header *)&as_out_ep_desc, - (struct usb_descriptor_header *)&as_iso_out_desc, - NULL, -}; +USB_COMPOSITE_DESCRIPTORS(uac1_descs, &intf0, &intf1); enum { STR_AC_IF, @@ -573,7 +566,7 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt) { struct f_audio *audio = func_to_audio(f); struct usb_composite_dev *cdev = f->config->cdev; - struct usb_ep *out_ep = audio->out_ep; + struct usb_ep *out_ep; struct usb_request *req; struct f_uac1_opts *opts; int req_buf_size, req_count, audio_buf_size; @@ -588,11 +581,12 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt) if (intf == 1) { if (alt == 1) { - err = config_ep_by_speed(cdev->gadget, f, out_ep); - if (err) - return err; + out_ep = usb_function_get_ep(f, intf, 0); + if (!out_ep) + return -ENODEV; + + audio->out_ep = out_ep; - usb_ep_enable(out_ep); audio->copy_buf = f_audio_buffer_alloc(audio_buf_size); if (IS_ERR(audio->copy_buf)) return -ENOMEM; @@ -636,7 +630,8 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt) return err; } -static void f_audio_disable(struct usb_function *f) +static void f_audio_clear_alt(struct usb_function *f, + unsigned intf, unsigned alt) { return; } @@ -664,25 +659,11 @@ static void f_audio_build_desc(struct f_audio *audio) } /* audio function driver setup/binding */ -static int -f_audio_bind(struct usb_configuration *c, struct usb_function *f) +static int f_audio_prep_descs(struct usb_function *f) { - struct usb_composite_dev *cdev = c->cdev; - struct f_audio *audio = func_to_audio(f); + struct usb_composite_dev *cdev = f->config->cdev; struct usb_string *us; - int status; - struct usb_ep *ep = NULL; - struct f_uac1_opts *audio_opts; - audio_opts = container_of(f->fi, struct f_uac1_opts, func_inst); - audio->card.gadget = c->cdev->gadget; - /* set up ASLA audio devices */ - if (!audio_opts->bound) { - status = gaudio_setup(&audio->card); - if (status < 0) - return status; - audio_opts->bound = true; - } us = usb_gstrings_attach(cdev, uac1_strings, ARRAY_SIZE(strings_uac1)); if (IS_ERR(us)) return PTR_ERR(us); @@ -694,41 +675,47 @@ f_audio_bind(struct usb_configuration *c, struct usb_function *f) as_interface_alt_0_desc.iInterface = us[STR_AS_IF_ALT0].id; as_interface_alt_1_desc.iInterface = us[STR_AS_IF_ALT1].id; + return usb_function_set_descs(f, &uac1_descs); +} + +static int f_audio_prep_vendor_descs(struct usb_function *f) +{ + struct usb_composite_dev *cdev = f->config->cdev; + struct f_audio *audio = func_to_audio(f); + struct f_uac1_opts *audio_opts; + int status; + + audio_opts = container_of(f->fi, struct f_uac1_opts, func_inst); + audio->card.gadget = cdev->gadget; + + /* set up ASLA audio devices */ + if (!audio_opts->bound) { + status = gaudio_setup(&audio->card); + if (status < 0) + return status; + audio_opts->bound = true; + } f_audio_build_desc(audio); - /* allocate instance-specific interface IDs, and patch descriptors */ - status = usb_interface_id(c, f); - if (status < 0) - goto fail; - ac_interface_desc.bInterfaceNumber = status; - - status = usb_interface_id(c, f); - if (status < 0) - goto fail; - as_interface_alt_0_desc.bInterfaceNumber = status; - as_interface_alt_1_desc.bInterfaceNumber = status; - - status = -ENODEV; - - /* allocate instance-specific endpoints */ - ep = usb_ep_autoconfig(cdev->gadget, &as_out_ep_desc); - if (!ep) - goto fail; - audio->out_ep = ep; - audio->out_ep->desc = &as_out_ep_desc; - - status = -ENOMEM; - - /* copy descriptors, and track endpoint copies */ - status = usb_assign_descriptors(f, f_audio_desc, f_audio_desc, NULL); - if (status) - goto fail; - return 0; + usb_altset_add_vendor_desc(f, 0, 0, + (struct usb_descriptor_header *)&ac_header_desc); + usb_altset_add_vendor_desc(f, 0, 0, + (struct usb_descriptor_header *)&input_terminal_desc); + usb_altset_add_vendor_desc(f, 0, 0, + (struct usb_descriptor_header *)&output_terminal_desc); + usb_altset_add_vendor_desc(f, 0, 0, + (struct usb_descriptor_header *)&feature_unit_desc); -fail: - gaudio_cleanup(&audio->card); - return status; + usb_altset_add_vendor_desc(f, 1, 1, + (struct usb_descriptor_header *)&as_header_desc); + usb_altset_add_vendor_desc(f, 1, 1, + (struct usb_descriptor_header *)&as_type_i_desc); + + usb_ep_add_vendor_desc(f, 1, 1, 0, + (struct usb_descriptor_header *)&as_iso_out_desc); + + return 0; } /*-------------------------------------------------------------------------*/ @@ -938,11 +925,6 @@ static void f_audio_free(struct usb_function *f) mutex_unlock(&opts->lock); } -static void f_audio_unbind(struct usb_configuration *c, struct usb_function *f) -{ - usb_free_all_descriptors(f); -} - static struct usb_function *f_audio_alloc(struct usb_function_instance *fi) { struct f_audio *audio; @@ -962,11 +944,11 @@ static struct usb_function *f_audio_alloc(struct usb_function_instance *fi) INIT_LIST_HEAD(&audio->play_queue); spin_lock_init(&audio->lock); - audio->card.func.bind = f_audio_bind; - audio->card.func.unbind = f_audio_unbind; + audio->card.func.prep_descs = f_audio_prep_descs; + audio->card.func.prep_vendor_descs = f_audio_prep_vendor_descs; audio->card.func.set_alt = f_audio_set_alt; + audio->card.func.clear_alt = f_audio_clear_alt; audio->card.func.setup = f_audio_setup; - audio->card.func.disable = f_audio_disable; audio->card.func.free_func = f_audio_free; control_selector_init(audio); -- 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/