Skip to content

Commit 9c5a40f

Browse files
ConchuODlinusw
authored andcommitted
pinctrl: generic: move function to amlogic-am4 driver
pinconf_generic_dt_node_to_map_pinmux() is not actually a generic function, and really belongs in the amlogic-am4 driver. There are three reasons why. First, and least, of the reasons is that this function behaves differently to the other dt_node_to_map functions in a way that is not obvious from a first glance. This difference stems for the devicetree properties that the function is intended for use with, and how they are typically used. The other generic dt_node_to_map functions support platforms where the pins, groups and functions are described statically in the driver and require a function that will produce a mapping from dt nodes to these pre-established descriptions. No other code in the driver is require to be executed at runtime. pinconf_generic_dt_node_to_map_pinmux() on the other hand is intended for use with the pinmux property, where groups and functions are determined entirely from the devicetree. As a result, there are no statically defined groups and functions in the driver for this function to perform a mapping to. Other drivers that use the pinmux property (e.g. the k1) their dt_node_to_map function creates the groups and functions as the devicetree is parsed. Instead of that, pinconf_generic_dt_node_to_map_pinmux() requires that the devicetree is parsed twice, once by it and once at probe, so that the driver dynamically creates the groups and functions before the dt_node_to_map callback is executed. I don't believe this double parsing requirement is how developers would expect this to work and is not necessary given there are drivers that do not have this behaviour. Secondly and thirdly, the function bakes in some assumptions that only really match the amlogic platform about how the devicetree is constructed. These, to me, are problematic for something that claims to be generic. The other dt_node_to_map implementations accept a being called for either a node containing pin configuration properties or a node containing child nodes that each contain the configuration properties. IOW, they support the following two devicetree configurations: | cfg { | label: group { | pinmux = <asjhdasjhlajskd>; | config-item1; | }; | }; | label: cfg { | group1 { | pinmux = <dsjhlfka>; | config-item2; | }; | group2 { | pinmux = <lsdjhaf>; | config-item1; | }; | }; pinconf_generic_dt_node_to_map_pinmux() only supports the latter. The other assumption about devicetree configuration that the function makes is that the labeled node's parent is a "function node". The amlogic driver uses these "function nodes" to create the functions at probe time, and pinconf_generic_dt_node_to_map_pinmux() finds the parent of the node it is operating on's name as part of the mapping. IOW, it requires that the devicetree look like: | pinctrl@bla { | | func-foo { | label: group-default { | pinmuxes = <lskdf>; | }; | }; | }; and couldn't be used if the nodes containing the pinmux and configuration properties are children of the pinctrl node itself: | pinctrl@bla { | | label: group-default { | pinmuxes = <lskdf>; | }; | }; These final two reasons are mainly why I believe this is not suitable as a generic function, and should be moved into the driver that is the sole user and originator of the "generic" function. Signed-off-by: Conor Dooley <conor.dooley@microchip.com> Acked-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Linus Walleij <linusw@kernel.org>
1 parent 6e544d8 commit 9c5a40f

3 files changed

Lines changed: 70 additions & 75 deletions

File tree

drivers/pinctrl/meson/pinctrl-amlogic-a4.c

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <dt-bindings/pinctrl/amlogic,pinctrl.h>
2525

2626
#include "../core.h"
27+
#include "../pinctrl-utils.h"
2728
#include "../pinconf.h"
2829

2930
#define gpio_chip_to_bank(chip) \
@@ -672,11 +673,79 @@ static void aml_pin_dbg_show(struct pinctrl_dev *pcdev, struct seq_file *s,
672673
seq_printf(s, " %s", dev_name(pcdev->dev));
673674
}
674675

676+
static int aml_dt_node_to_map_pinmux(struct pinctrl_dev *pctldev,
677+
struct device_node *np,
678+
struct pinctrl_map **map,
679+
unsigned int *num_maps)
680+
{
681+
struct device *dev = pctldev->dev;
682+
struct device_node *pnode;
683+
unsigned long *configs = NULL;
684+
unsigned int num_configs = 0;
685+
struct property *prop;
686+
unsigned int reserved_maps;
687+
int reserve;
688+
int ret;
689+
690+
prop = of_find_property(np, "pinmux", NULL);
691+
if (!prop) {
692+
dev_info(dev, "Missing pinmux property\n");
693+
return -ENOENT;
694+
}
695+
696+
pnode = of_get_parent(np);
697+
if (!pnode) {
698+
dev_info(dev, "Missing function node\n");
699+
return -EINVAL;
700+
}
701+
702+
reserved_maps = 0;
703+
*map = NULL;
704+
*num_maps = 0;
705+
706+
ret = pinconf_generic_parse_dt_config(np, pctldev, &configs,
707+
&num_configs);
708+
if (ret < 0) {
709+
dev_err(dev, "%pOF: could not parse node property\n", np);
710+
return ret;
711+
}
712+
713+
reserve = 1;
714+
if (num_configs)
715+
reserve++;
716+
717+
ret = pinctrl_utils_reserve_map(pctldev, map, &reserved_maps,
718+
num_maps, reserve);
719+
if (ret < 0)
720+
goto exit;
721+
722+
ret = pinctrl_utils_add_map_mux(pctldev, map,
723+
&reserved_maps, num_maps, np->name,
724+
pnode->name);
725+
if (ret < 0)
726+
goto exit;
727+
728+
if (num_configs) {
729+
ret = pinctrl_utils_add_map_configs(pctldev, map, &reserved_maps,
730+
num_maps, np->name, configs,
731+
num_configs, PIN_MAP_TYPE_CONFIGS_GROUP);
732+
if (ret < 0)
733+
goto exit;
734+
}
735+
736+
exit:
737+
kfree(configs);
738+
if (ret)
739+
pinctrl_utils_free_map(pctldev, *map, *num_maps);
740+
741+
return ret;
742+
}
743+
675744
static const struct pinctrl_ops aml_pctrl_ops = {
676745
.get_groups_count = aml_get_groups_count,
677746
.get_group_name = aml_get_group_name,
678747
.get_group_pins = aml_get_group_pins,
679-
.dt_node_to_map = pinconf_generic_dt_node_to_map_pinmux,
748+
.dt_node_to_map = aml_dt_node_to_map_pinmux,
680749
.dt_free_map = pinconf_generic_dt_free_map,
681750
.pin_dbg_show = aml_pin_dbg_show,
682751
};

drivers/pinctrl/pinconf-generic.c

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -385,75 +385,6 @@ int pinconf_generic_parse_dt_config(struct device_node *np,
385385
}
386386
EXPORT_SYMBOL_GPL(pinconf_generic_parse_dt_config);
387387

388-
int pinconf_generic_dt_node_to_map_pinmux(struct pinctrl_dev *pctldev,
389-
struct device_node *np,
390-
struct pinctrl_map **map,
391-
unsigned int *num_maps)
392-
{
393-
struct device *dev = pctldev->dev;
394-
struct device_node *pnode;
395-
unsigned long *configs = NULL;
396-
unsigned int num_configs = 0;
397-
struct property *prop;
398-
unsigned int reserved_maps;
399-
int reserve;
400-
int ret;
401-
402-
prop = of_find_property(np, "pinmux", NULL);
403-
if (!prop) {
404-
dev_info(dev, "Missing pinmux property\n");
405-
return -ENOENT;
406-
}
407-
408-
pnode = of_get_parent(np);
409-
if (!pnode) {
410-
dev_info(dev, "Missing function node\n");
411-
return -EINVAL;
412-
}
413-
414-
reserved_maps = 0;
415-
*map = NULL;
416-
*num_maps = 0;
417-
418-
ret = pinconf_generic_parse_dt_config(np, pctldev, &configs,
419-
&num_configs);
420-
if (ret < 0) {
421-
dev_err(dev, "%pOF: could not parse node property\n", np);
422-
return ret;
423-
}
424-
425-
reserve = 1;
426-
if (num_configs)
427-
reserve++;
428-
429-
ret = pinctrl_utils_reserve_map(pctldev, map, &reserved_maps,
430-
num_maps, reserve);
431-
if (ret < 0)
432-
goto exit;
433-
434-
ret = pinctrl_utils_add_map_mux(pctldev, map,
435-
&reserved_maps, num_maps, np->name,
436-
pnode->name);
437-
if (ret < 0)
438-
goto exit;
439-
440-
if (num_configs) {
441-
ret = pinctrl_utils_add_map_configs(pctldev, map, &reserved_maps,
442-
num_maps, np->name, configs,
443-
num_configs, PIN_MAP_TYPE_CONFIGS_GROUP);
444-
if (ret < 0)
445-
goto exit;
446-
}
447-
448-
exit:
449-
kfree(configs);
450-
if (ret)
451-
pinctrl_utils_free_map(pctldev, *map, *num_maps);
452-
453-
return ret;
454-
}
455-
EXPORT_SYMBOL_GPL(pinconf_generic_dt_node_to_map_pinmux);
456-
457388
int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev,
458389
struct device_node *np, struct pinctrl_map **map,
459390
unsigned int *reserved_maps, unsigned int *num_maps,

include/linux/pinctrl/pinconf-generic.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,4 @@ static inline int pinconf_generic_dt_node_to_map_all(struct pinctrl_dev *pctldev
250250
return pinconf_generic_dt_node_to_map(pctldev, np_config, map, num_maps,
251251
PIN_MAP_TYPE_INVALID);
252252
}
253-
254-
int pinconf_generic_dt_node_to_map_pinmux(struct pinctrl_dev *pctldev,
255-
struct device_node *np,
256-
struct pinctrl_map **map,
257-
unsigned int *num_maps);
258253
#endif /* __LINUX_PINCTRL_PINCONF_GENERIC_H */

0 commit comments

Comments
 (0)