generic pinmux dt_node_to_map implementation/spacemit driver converted to use it
Subsystems (4)
v2 cover generic pinmux dt_node_to_map implementation/spacemit driver converted to use it
From: Conor Dooley <[email protected]>
Hey folks,
Here's a real version of my generic pinmux dt_node_to_map implementation. I tested this on my bpif3 but the dts in mainline is very limited in terms of pinctrl use so I would really appreciate any testing that could be done with a more complete setup.
If you try to apply this, it's on top of Frank's mux series. It's also here if any of the spacemit-ters want to look at what I did to their driver:
https://git.kernel.org/pub/scm/linux/kernel/git/conor/linux.git/log/?h=spacemit-pinctrl
Cheers,
Conor.
Conor Dooley (4):
pinctrl: generic: change signature of pinctrl_generic_to_map() to pass
void data
pinctrl: add new generic groups/function creation function for pinmux
pinctrl: spacemit: delete spacemit_pctrl_check_power()
pinctrl: spacemit: move over to generic pinmux dt_node_to_map
implementation
drivers/pinctrl/pinconf.h | 20 ++- drivers/pinctrl/pinctrl-generic.c | 124 ++++++++++++++---- drivers/pinctrl/spacemit/Kconfig | 4 +- drivers/pinctrl/spacemit/pinctrl-k1.c | 177 ++------------------------ 4 files changed, 128 insertions(+), 197 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/4 pinctrl: generic: change signature of pinctrl_generic_to_map() to pass void data
From: Conor Dooley <[email protected]>
In order to make pinctrl_generic_to_map() usable for controllers that use pinmux, change the functions char array pointer that it passes to pinctrl_generic_add_group() to a void pointer. In the pinmux case this property will contain the mux setting as a number rather than as strings in the pins + functions case.
--- drivers/pinctrl/pinconf.h | 6 ++---- drivers/pinctrl/pinctrl-generic.c | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-)
drivers/pinctrl/pinconf.h +2 -4
@@ -177,8 +177,7 @@ int pinctrl_generic_to_map(struct pinctrl_dev *pctldev, struct device_node *pare struct device_node *np, struct pinctrl_map **maps, unsigned int *num_maps, unsigned int *num_reserved_maps, const char **group_name, unsigned int ngroups, - const char **functions, unsigned int *pins, - unsigned int npins); + void *data, unsigned int *pins, unsigned int npins);#else static inline int pinctrl_generic_pins_function_dt_node_to_map(struct pinctrl_dev *pctldev,
@@ -194,8 +193,7 @@ 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_name, unsigned int ngroups, - const char **functions, unsigned int *pins, - unsigned int npins) + void *data, unsigned int *pins, unsigned int npins) { return -ENOTSUPP; }
drivers/pinctrl/pinctrl-generic.c +2 -3
@@ -21,8 +21,7 @@ int pinctrl_generic_to_map(struct pinctrl_dev *pctldev, struct device_node *pare 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, - unsigned int npins) + void *data, unsigned int *pins, unsigned int npins) { struct device *dev = pctldev->dev;unsigned int num_configs;
@@ -45,7 +44,7 @@ int pinctrl_generic_to_map(struct pinctrl_dev *pctldev, struct device_node *pareif (ret <0 )return ret; - ret =pinctrl_generic_add_group (pctldev, group_name, pins, npins, functions); + ret =pinctrl_generic_add_group (pctldev, group_name, pins, npins, data);if (ret <0 )return dev_err_probe (dev, ret,"failed to add group %s: %d\n" , group_name, ret);
Signature · 1 line
2.53.0
PATCH v2 2/4 pinctrl: add new generic groups/function creation function for pinmux
In reply to Conor DooleyFrom: Conor Dooley <[email protected]>
Akin to my recently added pinctrl_generic_pins_functions_dt_node_to_map(), create an analogue that performs the same role of dynamically creating groups at runtime for controllers using the pinmux property. The pinmux property is freeform, so this function mandates that the upper 16 bits contain the pin and the lower 16 bits contains the mux setting. The group's data pointer is populated with an array of the mux settings for each pin it contains.
Since the node parsing and subsequent pinctrl core function calls are practically identical to the pins + functions case, other than which properties are examined, it makes sense to extract the common code from pinctrl_generic_pins_function_dt_node_to_map() into a generic function that takes the case-specific devicetree parsing function as an argument.
--- drivers/pinctrl/pinconf.h | 14 ++++ drivers/pinctrl/pinctrl-generic.c | 119 ++++++++++++++++++++++++------ 2 files changed, 112 insertions(+), 21 deletions(-)
drivers/pinctrl/pinconf.h +14 -0
@@ -173,6 +173,11 @@ int pinctrl_generic_pins_function_dt_node_to_map(struct pinctrl_dev *pctldev,struct pinctrl_map **maps, unsigned int *num_maps); +int pinctrl_generic_pinmux_dt_node_to_map (struct pinctrl_dev *pctldev, +struct device_node *np, +struct pinctrl_map **maps, +unsigned int *num_maps); + 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,
@@ -188,6 +193,15 @@ pinctrl_generic_pins_function_dt_node_to_map(struct pinctrl_dev *pctldev,return -ENOTSUPP ; } +static inline int +pinctrl_generic_pinmux_dt_node_to_map (struct pinctrl_dev *pctldev, +struct device_node *np, +struct pinctrl_map **maps, +unsigned int *num_maps) +{ +return -ENOTSUPP ; +} + static inline int pinctrl_generic_to_map(struct pinctrl_dev *pctldev, struct device_node *parent, struct device_node *np, struct pinctrl_map **maps,
drivers/pinctrl/pinctrl-generic.c +98 -21
141 lines not on this page · raw message
Signature · 1 line
2.53.0
Troy Mitchell
reviewerRe: [PATCH v2 2/4] pinctrl: add new generic groups/function creation function for pinmux
Quoted 1 line · Conor Dooley
From: Conor Dooley <[email protected]>
[...]
drivers/pinctrl/pinctrl-generic.c int pinctrl_generic_pins_function_dt_node_to_map(struct pinctrl_dev *pctldev, · line 281
Quoted 8 lines
drivers/pinctrl/pinctrl-generic.c +8
-0+int pinctrl_generic_pinmux_dt_node_to_map (struct pinctrl_dev *pctldev, +struct device_node *np, +struct pinctrl_map **maps, +unsigned int *num_maps) +{ +return pinctrl_generic_dt_node_to_map (pctldev, np, maps, num_maps, + &pinctrl_generic_pinmux_dt_subnode_to_map); +};
Nit: stray semicolon after the closing brace of the function definition.
- Troy
Quoted 1 line
+EXPORT_SYMBOL_GPL(pinctrl_generic_pinmux_dt_node_to_map);
PATCH v2 3/4 pinctrl: spacemit: delete spacemit_pctrl_check_power()
In reply to Conor DooleyFrom: Conor Dooley <[email protected]>
As far as I can tell spacemit_pctrl_check_power(), called during the custom implementation of dt_node_to_map, is redundant because the driver's implementation generate_config performs the check too. Removing this would allow the driver to use the newly added common function pinctrl_generic_pinmux_dt_node_to_map().
--- drivers/pinctrl/spacemit/pinctrl-k1.c | 37 --------------------------- 1 file changed, 37 deletions(-)
drivers/pinctrl/spacemit/pinctrl-k1.c +0 -37
@@ -409,38 +409,6 @@ static inline u32 spacemit_get_drive_strength_mA(enum spacemit_pin_io_type type, } } -static int spacemit_pctrl_check_power (struct pinctrl_dev *pctldev, -struct device_node *dn, -struct spacemit_pin_mux_config *pinmuxs, -int num_pins,const char *grpname) -{ -struct spacemit_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); -struct device *dev = pctrl->dev; -enum spacemit_pin_io_type type; -u32 power =0 , i; - -of_property_read_u32 (dn,"power-source" , &power); - -for (i =0 ; i < num_pins; i++) { - type =spacemit_to_pin_io_type (pinmuxs[i].pin); - -if (type !=IO_TYPE_EXTERNAL ) -continue ; - -switch (power) { -case PIN_POWER_STATE_1V8 : -case PIN_POWER_STATE_3V3 : -break ; -default : -dev_err (dev,"group %s has unsupported power\n" , - grpname); -return -ENOTSUPP ; - } - } - -return 0 ; -} -static void spacemit_set_io_pwr_domain (struct spacemit_pinctrl *pctrl,const struct spacemit_pin *spin,const enum spacemit_pin_io_type type)
@@ -548,11 +516,6 @@ static int spacemit_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,return dev_err_probe (dev, -ENODEV ,"failed to get pin %d\n" , pins[i]); } - ret =spacemit_pctrl_check_power (pctldev, child, pinmuxs, - npins, grpname); -if (ret <0 ) -return ret; - map[nmaps].type =PIN_MAP_TYPE_MUX_GROUP ; map[nmaps].data.mux.function = np->name; map[nmaps].data.mux.group = grpname;
Signature · 1 line
2.53.0
PATCH v2 4/4 pinctrl: spacemit: move over to generic pinmux dt_node_to_map implementation
In reply to Conor DooleyFrom: Conor Dooley <[email protected]>
Replace the custom implementation of dt_node_to_map with pinctrl_generic_dt_node_to_map() to demonstrate its use. spacemit_pin_mux_config didn't provide much value in the first place, because the group contains the information required to look up the spacemit_pin struct corresponding to a pin, so there's no loss in functionality as a result of the generic function carrying only the mux data in the group's data pointer rather than having an array of spacemit_pin_mux_config structs.
--- drivers/pinctrl/spacemit/Kconfig | 4 +- drivers/pinctrl/spacemit/pinctrl-k1.c | 140 ++------------------------ 2 files changed, 12 insertions(+), 132 deletions(-)
drivers/pinctrl/spacemit/Kconfig +1 -3
@@ -8,9 +8,7 @@ config PINCTRL_SPACEMIT_K1 depends on ARCH_SPACEMIT || COMPILE_TEST depends on OF default ARCH_SPACEMIT - select GENERIC_PINCTRL_GROUPS - select GENERIC_PINMUX_FUNCTIONS - select GENERIC_PINCONF + select GENERIC_PINCTRL help Say Y to select the pinctrl driver for K1/K3 SoC. This pin controller allows selecting the mux function for
drivers/pinctrl/spacemit/pinctrl-k1.c +11 -129
178 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v2 4/4] pinctrl: spacemit: move over to generic pinmux dt_node_to_map implementation
Quoted 11 lines · Conor Dooley
From: Conor Dooley <[email protected]>
Replace the custom implementation of
dt_node_to_mapwithpinctrl_generic_dt_node_to_map()to demonstrate its use.spacemit_pin_mux_configdidn't provide much value in the first place, because the group contains the information required to look up thespacemit_pinstruct corresponding to a pin, so there's no loss in functionality as a result of the generic function carrying only the mux data in the group's data pointer rather than having an array ofspacemit_pin_mux_configstructs.
Quoted 1 line
Signed-off-by Conor Dooley <[email protected]>
Linus Walleij
maintainerQuoted 9 lines · Conor Dooley
Here's a real version of my generic pinmux
dt_node_to_mapimplementation. I tested this on my bpif3 but the dts in mainline is very limited in terms of pinctrl use so I would really appreciate any testing that could be done with a more complete setup.If you try to apply this, it's on top of Frank's mux series. It's also here if any of the spacemit-ters want to look at what I did to their driver:
https://git.kernel.org/pub/scm/linux/kernel/git/conor/linux.git/log/?h=spacemit-pinctrl
I just applied it and it seems to work, at least it compiles!
No point in waiting for more review comments, let's ship it and see what happens.
Yours,
Linus Walleij