From nobody Wed Dec 17 15:35:15 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA1A9C61D97 for ; Fri, 24 Nov 2023 16:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231356AbjKXQoq (ORCPT ); Fri, 24 Nov 2023 11:44:46 -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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/functi= on/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; =20 struct usb_function function; + int cur_alt[MAX_CONFIG_INTERFACES]; }; =20 =20 @@ -98,6 +99,7 @@ static int __must_check ffs_func_eps_enable(struct ffs_fu= nction *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); } =20 +static int ffs_func_get_alt(struct usb_function *f, + unsigned int interface) +{ + struct ffs_function *func =3D ffs_func_from_usb(f); + int intf =3D 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, =20 ffs->func =3D func; ret =3D ffs_func_eps_enable(func); - if (ret >=3D 0) + if (ret >=3D 0) { ffs_event_add(ffs, FUNCTIONFS_ENABLE); + func->cur_alt[interface] =3D alt; + } return ret; } =20 @@ -3574,6 +3587,7 @@ static struct usb_function *ffs_alloc(struct usb_func= tion_instance *fi) func->function.bind =3D ffs_func_bind; func->function.unbind =3D ffs_func_unbind; func->function.set_alt =3D ffs_func_set_alt; + func->function.get_alt =3D ffs_func_get_alt; func->function.disable =3D ffs_func_disable; func->function.setup =3D ffs_func_setup; func->function.req_match =3D ffs_func_req_match; --=20 2.17.1