From patchwork Tue Mar 30 14:38:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12172723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33FCFC433DB for ; Tue, 30 Mar 2021 14:38:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA39461878 for ; Tue, 30 Mar 2021 14:38:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232082AbhC3OiP (ORCPT ); Tue, 30 Mar 2021 10:38:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:50562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232046AbhC3OiG (ORCPT ); Tue, 30 Mar 2021 10:38:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E1431619C8; Tue, 30 Mar 2021 14:38:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617115086; bh=+6W/Yl//h0yVqmxmy3+UJygrHKmPkBC8VX4z4yi1Wl0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bRfESmEcCc7LtpOzIpOWSNP/JolMBZ/QgPUeZnKc7FLJYJ+qQUzEplQjYc89FNDaw rQyJsAB+3SlhiXawCdvwgKbheu0ac/hj95UCnKEEd2ndjfLKY0OnQsdiaSGeeWpnhZ mkL4kZ4rOT7A3pzl3ksKwCcRvw9+fo9hYKoL4QrLEshZn+dwmazz23Z7TvGeCoLSxD OhFqLwHxOxFQ8TRW5jdhXyKWH/FExBSofJTTMC+VFhCdZtuMkCXbVUxElqYpnPbrua VioJwEhNBRmMTdsawUurWRmR/DaV7jPfohl1iA5ADFEFNpwDo7SwlgYMoQFC5Du7Ap 91Z3aD9AGn2vQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lRFVj-0002Nt-LB; Tue, 30 Mar 2021 16:38:27 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] USB: serial: xr: claim both interfaces Date: Tue, 30 Mar 2021 16:38:20 +0200 Message-Id: <20210330143820.9103-5-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210330143820.9103-1-johan@kernel.org> References: <20210330143820.9103-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use the new multi-interface support in USB serial core to properly claim also the control interface during probe. This prevents having another driver claim the control interface and makes core allocate resources also for the interrupt endpoint (currently unused). Switch to probing only Communication Class interfaces and use the Union functional descriptor to determine the corresponding data interface. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index c59c8b47a120..88c73f88cb26 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -16,6 +16,7 @@ #include #include #include +#include #include struct xr_txrx_clk_mask { @@ -550,15 +551,34 @@ static void xr_close(struct usb_serial_port *port) static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) { - /* Don't bind to control interface */ - if (serial->interface->cur_altsetting->desc.bInterfaceNumber == 0) + struct usb_interface *control = serial->interface; + struct usb_host_interface *alt = control->cur_altsetting; + struct usb_cdc_parsed_header hdrs; + struct usb_cdc_union_desc *desc; + struct usb_interface *data; + int ret; + + ret = cdc_parse_cdc_header(&hdrs, control, alt->extra, alt->extralen); + if (ret < 0) return -ENODEV; + desc = hdrs.usb_cdc_union_desc; + if (!desc) + return -ENODEV; + + data = usb_ifnum_to_if(serial->dev, desc->bSlaveInterface0); + if (!data) + return -ENODEV; + + ret = usb_serial_claim_interface(serial, data); + if (ret) + return ret; + return 0; } static const struct usb_device_id id_table[] = { - { USB_DEVICE(0x04e2, 0x1410) }, /* XR21V141X */ + { USB_DEVICE_INTERFACE_CLASS(0x04e2, 0x1410, USB_CLASS_COMM) }, /* XR21V141X */ { } }; MODULE_DEVICE_TABLE(usb, id_table);