From patchwork Fri Nov 24 16:44:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hardik Gajjar X-Patchwork-Id: 169517 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp1359432vqx; Fri, 24 Nov 2023 08:45:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHoPgChCnKXoGKrfwXUjvzcrSdbr3x60GGAdCp0Mn2FnwnBcZ5d3Bfx8nr/jcamA2ybXiLz X-Received: by 2002:a05:6a20:1483:b0:186:e53:b64b with SMTP id o3-20020a056a20148300b001860e53b64bmr2832715pzi.47.1700844320761; Fri, 24 Nov 2023 08:45:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700844320; cv=none; d=google.com; s=arc-20160816; b=Syr/vlaBOIeAdhOxgovdQLTrG7bFHnXfkDNIVvrHlbiAv0ZITFvZ2Xr+e+dg/anW3d LnJVNGrGaTHiDJUuHehlZh66X+0DaAeaXJe1n0269YixQZieEDir6sdwO+WOGlkf1mI/ D8rrgMIBgjebuZBKCVSFt56zMTxX8WX6HyMBcoLfduJnnR2js84rYOSK5VuSxcw+oOZ5 z4Yk1Qvmi9TOsXUqmn/IJu6c2vCCjrZS5fTm8vOqQtQC8si1LKRoj5bI1vgQe7N+EGVy xbakGywyIa4t/6h+ePCIlWpCdkwiG0rv8IUUc4iGSEvwc1hf0CsjXTGt9MOxpsNnQX2a Nrsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=I47y07EvLQUECHcJVKeWbHn0ll9lJU93OUNQpB1hjz4=; fh=ImEDAHDwwefdVYaKIShhm52Wlrykm8gk+Y4GIZ7+YdU=; b=FWg8zv7g6+qqlLp6QrZsTK1q6YWNipIl8SgbPukOxlRkf8b81q3BbiogGS/mvuQh6h Op2aKzrt4HQHOl2A8qH9uMIpAH9Pi7EiHAVpd7QPldAORqxeqHMDc6xg8nbxLZ6bYY+C VXVu8WSgzZ8iV3DLxOT/GbMLLvRzhnCerzupcOn1StByqmtLNKV8miztdSe0YVMc4yKC +ApUeHqA7PkZxBVPu7TAJiX713jHE2jkMvmJuzTapjMZU1sAdLFtRDqq6rxlgJaRAqEu AGu07qxFr7g9bJXZMhlYjUuIv52+IOfXM5VoZ2CiucFso0sq9zsUnZBr4uF9+4cvfCBA 9BPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id y129-20020a636487000000b005c201af09fdsi3841845pgb.575.2023.11.24.08.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 08:45:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 14245809AFF3; Fri, 24 Nov 2023 08:45:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231462AbjKXQoo (ORCPT + 99 others); Fri, 24 Nov 2023 11:44:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231379AbjKXQol (ORCPT ); Fri, 24 Nov 2023 11:44:41 -0500 Received: from hi1smtp01.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E45D3173D; Fri, 24 Nov 2023 08:44:45 -0800 (PST) Received: from hi2exch02.adit-jv.com (hi2exch02.adit-jv.com [10.72.92.28]) by hi1smtp01.de.adit-jv.com (Postfix) with ESMTP id 7E15A5201D5; Fri, 24 Nov 2023 17:44:44 +0100 (CET) Received: from vmlxhi-118.adit-jv.com (10.72.93.77) by hi2exch02.adit-jv.com (10.72.92.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Fri, 24 Nov 2023 17:44:44 +0100 From: Hardik Gajjar To: , , CC: , , , , , Subject: [PATCH] usb: gadget: f_fs: Add the missing get_alt callback Date: Fri, 24 Nov 2023 17:44:35 +0100 Message-ID: <20231124164435.74727-1-hgajjar@de.adit-jv.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.72.93.77] X-ClientProxiedBy: hi2exch02.adit-jv.com (10.72.92.28) To hi2exch02.adit-jv.com (10.72.92.28) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 24 Nov 2023 08:45:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783464533989401267 X-GMAIL-MSGID: 1783464533989401267 Some USB OTG hubs have multiple alternate configurations to offer, such as one for Carplay and another for Carlife. This patch implements and sets the get_alt callback to retrieve the currently used alternate setting. The new function allows dynamic retrieval of the current alternate setting for a specific interface. The current alternate setting values are stored in the 'cur_alt' array within the 'ffs_function' structure. Signed-off-by: Hardik Gajjar --- drivers/usb/gadget/function/f_fs.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index efe3e3b85769..37c47c11f57a 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -75,6 +75,7 @@ struct ffs_function { short *interfaces_nums; struct usb_function function; + int cur_alt[MAX_CONFIG_INTERFACES]; }; @@ -98,6 +99,7 @@ static int __must_check ffs_func_eps_enable(struct ffs_function *func); static int ffs_func_bind(struct usb_configuration *, struct usb_function *); static int ffs_func_set_alt(struct usb_function *, unsigned, unsigned); +static int ffs_func_get_alt(struct usb_function *f, unsigned int intf); static void ffs_func_disable(struct usb_function *); static int ffs_func_setup(struct usb_function *, const struct usb_ctrlrequest *); @@ -3232,6 +3234,15 @@ static void ffs_reset_work(struct work_struct *work) ffs_data_reset(ffs); } +static int ffs_func_get_alt(struct usb_function *f, + unsigned int interface) +{ + struct ffs_function *func = ffs_func_from_usb(f); + int intf = ffs_func_revmap_intf(func, interface); + + return (intf < 0) ? intf : func->cur_alt[interface]; +} + static int ffs_func_set_alt(struct usb_function *f, unsigned interface, unsigned alt) { @@ -3266,8 +3277,10 @@ static int ffs_func_set_alt(struct usb_function *f, ffs->func = func; ret = ffs_func_eps_enable(func); - if (ret >= 0) + if (ret >= 0) { ffs_event_add(ffs, FUNCTIONFS_ENABLE); + func->cur_alt[interface] = alt; + } return ret; } @@ -3574,6 +3587,7 @@ static struct usb_function *ffs_alloc(struct usb_function_instance *fi) func->function.bind = ffs_func_bind; func->function.unbind = ffs_func_unbind; func->function.set_alt = ffs_func_set_alt; + func->function.get_alt = ffs_func_get_alt; func->function.disable = ffs_func_disable; func->function.setup = ffs_func_setup; func->function.req_match = ffs_func_req_match;