From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A8A99109C04E for ; Wed, 25 Mar 2026 17:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NbDB9rxjdnsn1UTb7YlkdQOd4ifKfSbdGdz7bB1BEmA=; b=KirUaEuaRxQHB4AJ73SClRrFQO CVO7AVSgcPgtaN2IO096YGZafBWAiRabaVXTjbobraniCPTwQelBXxhwTItAH6OuxTanLTeTRSLKj SImlmumRjIvKl1QYqAiXnucpmMVXihPOyQd/R1kqOBDDY4zXr2QRFyGhsUpw6JsQxYm31rKjZtDsq YW6JD/a0SpriLY/+U1mJHVdz3paZ9KfJxDXRJTIA8SbvKyXFStusooskbIbu+ARxIh+fpGV7FH/x5 DoF9woTNabqJEFX+wUK3q7gT+ogGhSH1NGguTKoNa1/RPe3Y7pzOzYgLb8RC0Lb2nDw/i4PdOEG9C 5CMOwYkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w5S8H-0000000406S-1bbw; Wed, 25 Mar 2026 17:35:05 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w5S8F-0000000406M-2Lrf for linux-arm-kernel@lists.infradead.org; Wed, 25 Mar 2026 17:35:03 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id D402060123; Wed, 25 Mar 2026 17:35:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F855C4CEF7; Wed, 25 Mar 2026 17:34:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774460102; bh=EbLhVB6iS1vlGuGUCtBUkhmq/icBUn65MiS+x1rEuCk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MKcBY6a791jkx5gHCq4ysr7GBZz7gmQITFvcNlX6dMlMJEdujsVrD10TuUdxKphgK vDjPavA1epu+sqJkkXrUFOIGYXIEvtFFRlwQE5pQPM5+2qGdFov5p+oDx+9k+4tebN +g2j7XcEzN5OuXLATS5W5tdWUTXCzutiSXS84vx5RltHbFqt6YIfMQxWYt0c9rzM0e nCcom3m459y+W5sCUtcKBDGAczJa8r4YawhGq+BqbnSpvrgZU6pGdCBpVmyOVgKfIz j2rTS9SENMw4tS8iRSDB/8DWW3R9tqxi99Jyp7FCCXoGti1XZBPh+N0wOu/o37YesT 9/wPhJVRq5UJg== Date: Wed, 25 Mar 2026 17:34:57 +0000 From: Conor Dooley To: Frank Li Cc: Linus Walleij , Peter Rosin , Rob Herring , Krzysztof Kozlowski , Conor Dooley , =?utf-8?B?UmFmYcWCIE1pxYJlY2tp?= , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Haibo Chen Subject: Re: [PATCH v3 3/7] pinctrl: pinctrl-generic: add __pinctrl_generic_pins_function_dt_node_to_map() Message-ID: <20260325-rectified-filtrate-32a8f7345d37@spud> References: <20260311-pinctrl-mux-v3-0-236b1c17bf9b@nxp.com> <20260311-pinctrl-mux-v3-3-236b1c17bf9b@nxp.com> <20260325-riding-browbeat-293b47f43d82@spud> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="CY/CCDWk7hyJWyAw" Content-Disposition: inline In-Reply-To: X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --CY/CCDWk7hyJWyAw Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Mar 25, 2026 at 11:09:20AM -0400, Frank Li wrote: > On Wed, Mar 25, 2026 at 10:33:05AM +0000, Conor Dooley wrote: > > On Tue, Mar 24, 2026 at 04:16:10PM -0400, Frank Li wrote: > > > On Fri, Mar 20, 2026 at 09:54:45AM -0400, Frank Li wrote: > > > > On Fri, Mar 20, 2026 at 02:27:21PM +0100, Linus Walleij wrote: > > > > > On Thu, Mar 19, 2026 at 12:04=E2=80=AFAM Frank Li wrote: > > > > > > On Mon, Mar 16, 2026 at 10:37:28AM +0100, Linus Walleij wrote: > > > > > > > > > > > > That said: in this case you're just adding a parameter, just = add > > > > > > > the parameter and change all of the in-tree users to pass fal= se > > > > > > > or whatever you need, these is just one (1) in-tree user anyw= ay. > > > > > > > > > > > > pinctrl_generic_pins_function_dt_node_to_map() directly feed to > > > > > > .dt_node_to_map() callback, add parameter will impact too much. > > > > > > > > > > Why do you say that. It already has many parameters, one more > > > > > or less doesn't matter. It's not like this call is performance-cr= itical. > > > > > Just change the users. > > > > > > > > In only user drivers/pinctrl/microchip/pinctrl-mpfs-mssio.c, > > > > .dt_node_to_map =3D pinctrl_generic_pins_function_dt_node_to_map; > > > > > > > > pinctrl_generic_pins_function_dt_node_to_map() need match .dt_node_= to_map()'s > > > > declear. > > > > > > > > So it can't direct add two parameters in pinctrl_generic_pins_funct= ion_dt_node_to_map() > > > > Need simple wrap function, which other in pinctrl-mpfs-mssio.c or in > > > > pinconf.h. > > > > > > > > If add two parameter in .dt_node_to_map(), need change all function= s, which > > > > .dt_node_to_map =3D xxx_to_map(). and OF core part. > > > > > > Linus Walleij: > > > Is my explain clear enough? I am preparing respin it? > > > > > > is okay use wrap function > > > pinctrl_generic_pins_function_dt_node_to_map_ext()? > > > > I don't understand this patch. The function is called > > pinctrl_generic_pins_function_dt_node_to_map(). You have no pins. > > You're adding a parameter to make a function with *pins* in its name not > > use pins. The new function doesn't use pins but has pins in the name. > > At the very least function names should not be misleading. > > > > I was going to suggest pulling out the relevant portions and creating > > some helpers that could be used by multiple different-but-similar > > functions, but I don't actually even think that there's much in common. > > Most damningly I think, you don't actually read either the functions or > > pins properties at all and neither are permitted by your binding. > > So turns out you use neither pins or functions... > > > > You don't actually have any of these properties which runs counter to t= he > > goal of the function, which is parsing. With this in mind, it feels to = me > > like you're trying way too hard to make use of a generic function when = the > > right thing to do is probably just have an entirely custom function. > > Maybe that's a custom implementation in your driver, or a new function > > here, but I think writing that will highlight just how little of the > > code would be shared between the existing function and what your > > use-case needs: no pin configuration stuff, no reading of the devicetree > > other than the node names and no dealing with the label pointing to the > > "wrong" place. > > > > I recently bought a spacemit k1 board to go and write a sister function > > to pinctrl_generic_pins_function_dt_node_to_map() that deals with pins > > and groups (because that's a pretty common pattern). > > I would be calling that pinctrl_generic_pinmux_dt_node_to_map(), > > because it that's the property it deals with. I have honestly got no > > idea what to call one for this situation since you don't have any of the > > properties in pinmux-node.yaml. Maybe that's a sign. >=20 > At v2, I implemented customize dt_node_to_map(), Linus Walleij think it is > too similar with pinctrl_generic_pins_function_dt_node_to_map(), so ask me > to enhanance and reuse pinctrl_generic_pins_function_dt_node_to_map(). Sure, and he's right that there's a lot similar. Everything you want to do, other than looking at the mux state, is something that pinctrl_generic_pins_function_dt_node_to_map() does. But bastardising a function that's explicitly about reading pins and functions properties to do things that have _neither_ is not a good implementation of that review feedback. If you're going to make something generic, the right level to hook in IMO is at the pinctrl_generic_pins_function_dt_subnode_to_map() level, I already know that 95% of the code in that function is identical to what will be used for the spacemit k1 that uses the pinmux property and changing its API is a lot easier than changing the API of something that is written to match the dt_node_to_map callback. You don't even benefit from the extra functionality that pinctrl_generic_pins_function_dt_node_to_map() provides, because you don't have ambiguity about where the phandle you're parsing from points. In your case, it has to be the group node. pinctrl_generic_pins_function_dt_subnode_to_map() could probably be split into two parts, one that does the dt parsing portion and a second portion that does the mapping to kernel data structures. The first portion of that is the for loop. The second portion is everything after the for loop and the bit that names the groups. IOW, do something like what I am pasting here, and you create your own function that wraps pinctrl_generic_to_map() in the way you want. I personally think this is more tasteful than what you've done, and more importantly I am pretty sure that this is what's needed to be able to maximise code reuse for the devices that use pinmux. I didn't compile this or anything, it's just speculative. diff --git a/drivers/pinctrl/pinctrl-generic.c b/drivers/pinctrl/pinctrl-ge= neric.c index efb39c6a67033..7f02af6d9f3e4 100644 --- a/drivers/pinctrl/pinctrl-generic.c +++ b/drivers/pinctrl/pinctrl-generic.c @@ -17,56 +17,30 @@ #include "pinctrl-utils.h" #include "pinmux.h" =20 -static int pinctrl_generic_pins_function_dt_subnode_to_map(struct pinctrl_= dev *pctldev, - struct device_node *parent, - struct device_node *np, - struct pinctrl_map **maps, - unsigned int *num_maps, - unsigned int *num_reserved_maps, - const char **group_names, - unsigned int ngroups) +static int pinctrl_generic_to_map(struct pinctrl_dev *pctldev, + struct device_node *parent, + struct device_node *np, + struct pinctrl_map **maps, + unsigned int *num_maps, + unsigned int *num_reserved_maps, + const char **group_names, + unsigned int ngroups, + const char **functions, + unsigned int *pins, + void *function_data) { struct device *dev =3D pctldev->dev; - const char **functions; const char *group_name; unsigned long *configs; - unsigned int num_configs, pin, *pins; + unsigned int num_configs; int npins, ret, reserve =3D 1; =20 - npins =3D of_property_count_u32_elems(np, "pins"); - - if (npins < 1) { - dev_err(dev, "invalid pinctrl group %pOFn.%pOFn %d\n", - parent, np, npins); - return npins; - } - group_name =3D devm_kasprintf(dev, GFP_KERNEL, "%pOFn.%pOFn", parent, np); if (!group_name) return -ENOMEM; =20 group_names[ngroups] =3D group_name; =20 - pins =3D devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL); - if (!pins) - return -ENOMEM; - - functions =3D devm_kcalloc(dev, npins, sizeof(*functions), GFP_KERNEL); - if (!functions) - return -ENOMEM; - - for (int i =3D 0; i < npins; i++) { - ret =3D of_property_read_u32_index(np, "pins", i, &pin); - if (ret) - return ret; - - pins[i] =3D pin; - - ret =3D of_property_read_string(np, "function", &functions[i]); - if (ret) - return ret; - } - ret =3D pinctrl_utils_reserve_map(pctldev, maps, num_reserved_maps, num_m= aps, reserve); if (ret) return ret; @@ -101,6 +75,52 @@ static int pinctrl_generic_pins_function_dt_subnode_to_= map(struct pinctrl_dev *p return ret; =20 return 0; +} + +static int pinctrl_generic_pins_function_dt_subnode_to_map(struct pinctrl_= dev *pctldev, + struct device_node *parent, + struct device_node *np, + struct pinctrl_map **maps, + unsigned int *num_maps, + unsigned int *num_reserved_maps, + const char **group_names, + unsigned int ngroups) +{ + struct device *dev =3D pctldev->dev; + const char **functions; + unsigned int pin, *pins; + int npins, ret; + + npins =3D of_property_count_u32_elems(np, "pins"); + + if (npins < 1) { + dev_err(dev, "invalid pinctrl group %pOFn.%pOFn %d\n", + parent, np, npins); + return npins; + } + + pins =3D devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL); + if (!pins) + return -ENOMEM; + + functions =3D devm_kcalloc(dev, npins, sizeof(*functions), GFP_KERNEL); + if (!functions) + return -ENOMEM; + + for (int i =3D 0; i < npins; i++) { + ret =3D of_property_read_u32_index(np, "pins", i, &pin); + if (ret) + return ret; + + pins[i] =3D pin; + + ret =3D of_property_read_string(np, "function", &functions[i]); + if (ret) + return ret; + } + return pinctrl_generic_to_map(pctldev, parent, np, maps, num_maps, + num_reserved_maps, group_names, ngroups, + functions, pins, NULL); }; =20 /* --CY/CCDWk7hyJWyAw Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCacQcwAAKCRB4tDGHoIJi 0nufAQC7IzecDMz+IrNzep7T25HQ6q+Wz7UOlRjqLF09T+nBpwD/bdchu60ojsQu Zgpf0gxXCq/NriMhr7Etk/Epp9gobQ0= =T+72 -----END PGP SIGNATURE----- --CY/CCDWk7hyJWyAw--