mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 10:09:10 +02:00
pinctrl: extract pinctrl_generic_to_map() from pinctrl_generic_pins_function_dt_node_to_map()
Refactor pinctrl_generic_pins_function_dt_subnode_to_map() by separating DT parsing logic from map creation. Introduce a new helper pinctrl_generic_to_map() to handle mapping to kernel data structures, while keeping DT property parsing in the subnode function. Improve code structure and enables easier reuse for platforms using different DT properties (e.g. pinmux) without modifying the dt_node_to_map-style callback API. Avoid unnecessary coupling to pinctrl_generic_pins_function_dt_node_to_map(), which provides functionality not needed when the phandle target is unambiguous. Maximize code reuse and provide a cleaner extension point for future pinctrl drivers. Suggested-by: Conor Dooley <conor.dooley@microchip.com> Acked-by: Conor Dooley <conor.dooley@microchip.com> Signed-off-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Linus Walleij <linusw@kernel.org>
This commit is contained in:
parent
9e5e1de61d
commit
aaaf31be04
|
|
@ -172,6 +172,13 @@ int pinctrl_generic_pins_function_dt_node_to_map(struct pinctrl_dev *pctldev,
|
||||||
struct device_node *np,
|
struct device_node *np,
|
||||||
struct pinctrl_map **maps,
|
struct pinctrl_map **maps,
|
||||||
unsigned int *num_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,
|
||||||
|
const char **group_name, unsigned int ngroups,
|
||||||
|
const char **functions, unsigned int *pins,
|
||||||
|
unsigned int npins);
|
||||||
#else
|
#else
|
||||||
static inline int
|
static inline int
|
||||||
pinctrl_generic_pins_function_dt_node_to_map(struct pinctrl_dev *pctldev,
|
pinctrl_generic_pins_function_dt_node_to_map(struct pinctrl_dev *pctldev,
|
||||||
|
|
@ -181,4 +188,15 @@ pinctrl_generic_pins_function_dt_node_to_map(struct pinctrl_dev *pctldev,
|
||||||
{
|
{
|
||||||
return -ENOTSUPP;
|
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,
|
||||||
|
unsigned int *num_maps, unsigned int *num_reserved_maps,
|
||||||
|
const char **group_name, unsigned int ngroups,
|
||||||
|
const char **functions, unsigned int *pins,
|
||||||
|
void *function_data)
|
||||||
|
{
|
||||||
|
return -ENOTSUPP;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -17,29 +17,18 @@
|
||||||
#include "pinctrl-utils.h"
|
#include "pinctrl-utils.h"
|
||||||
#include "pinmux.h"
|
#include "pinmux.h"
|
||||||
|
|
||||||
static int pinctrl_generic_pins_function_dt_subnode_to_map(struct pinctrl_dev *pctldev,
|
int pinctrl_generic_to_map(struct pinctrl_dev *pctldev, struct device_node *parent,
|
||||||
struct device_node *parent,
|
struct device_node *np, struct pinctrl_map **maps,
|
||||||
struct device_node *np,
|
unsigned int *num_maps, unsigned int *num_reserved_maps,
|
||||||
struct pinctrl_map **maps,
|
const char **group_names, unsigned int ngroups,
|
||||||
unsigned int *num_maps,
|
const char **functions, unsigned int *pins,
|
||||||
unsigned int *num_reserved_maps,
|
unsigned int npins)
|
||||||
const char **group_names,
|
|
||||||
unsigned int ngroups)
|
|
||||||
{
|
{
|
||||||
struct device *dev = pctldev->dev;
|
struct device *dev = pctldev->dev;
|
||||||
const char **functions;
|
unsigned int num_configs;
|
||||||
const char *group_name;
|
const char *group_name;
|
||||||
unsigned long *configs;
|
unsigned long *configs;
|
||||||
unsigned int num_configs, pin, *pins;
|
int ret, reserve = 1;
|
||||||
int npins, ret, reserve = 1;
|
|
||||||
|
|
||||||
npins = 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 = devm_kasprintf(dev, GFP_KERNEL, "%pOFn.%pOFn", parent, np);
|
group_name = devm_kasprintf(dev, GFP_KERNEL, "%pOFn.%pOFn", parent, np);
|
||||||
if (!group_name)
|
if (!group_name)
|
||||||
|
|
@ -47,26 +36,6 @@ static int pinctrl_generic_pins_function_dt_subnode_to_map(struct pinctrl_dev *p
|
||||||
|
|
||||||
group_names[ngroups] = group_name;
|
group_names[ngroups] = group_name;
|
||||||
|
|
||||||
pins = devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL);
|
|
||||||
if (!pins)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
functions = devm_kcalloc(dev, npins, sizeof(*functions), GFP_KERNEL);
|
|
||||||
if (!functions)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
for (int i = 0; i < npins; i++) {
|
|
||||||
ret = of_property_read_u32_index(np, "pins", i, &pin);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
pins[i] = pin;
|
|
||||||
|
|
||||||
ret = of_property_read_string(np, "function", &functions[i]);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = pinctrl_utils_reserve_map(pctldev, maps, num_reserved_maps, num_maps, reserve);
|
ret = pinctrl_utils_reserve_map(pctldev, maps, num_reserved_maps, num_maps, reserve);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -102,6 +71,54 @@ static int pinctrl_generic_pins_function_dt_subnode_to_map(struct pinctrl_dev *p
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
EXPORT_SYMBOL_GPL(pinctrl_generic_to_map);
|
||||||
|
|
||||||
|
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 = pctldev->dev;
|
||||||
|
unsigned int pin, *pins;
|
||||||
|
const char **functions;
|
||||||
|
int npins, ret;
|
||||||
|
|
||||||
|
npins = 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 = devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL);
|
||||||
|
if (!pins)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
functions = devm_kcalloc(dev, npins, sizeof(*functions), GFP_KERNEL);
|
||||||
|
if (!functions)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
for (int i = 0; i < npins; i++) {
|
||||||
|
ret = of_property_read_u32_index(np, "pins", i, &pin);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
pins[i] = pin;
|
||||||
|
|
||||||
|
ret = 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, npins);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For platforms that do not define groups or functions in the driver, but
|
* For platforms that do not define groups or functions in the driver, but
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user