Commit cc4dac3f authored by Linus Walleij's avatar Linus Walleij

Merge tag 'intel-pinctrl-v5.17-2' of...

Merge tag 'intel-pinctrl-v5.17-2' of gitolite.kernel.org:pub/scm/linux/kernel/git/pinctrl/intel into devel

intel-pinctrl for v5.17-2

* Introduce new generic kasprintf_strarray() API
* Clean up and convert existing drivers to use the above

The API will be needed in the future for new comers, including Intel ones.

The following is an automated git shortlog grouped by driver:

armada-37xx:
 -  Switch to use devm_kasprintf_strarray()
 -  Convert to use dev_err_probe()
 -  Make use of the devm_platform_ioremap_resource()
 -  Use temporary variable for struct device
 -  Fix function name in the kernel doc

gpio:
 -  mockup: Switch to use kasprintf_strarray()

lib/string_helpers:
 -  Introduce managed variant of kasprintf_strarray()
 -  Introduce kasprintf_strarray()

pinctrl/rockchip:
 -  Switch to use devm_kasprintf_strarray()
 -  Convert to use dev_err_probe()
 -  Make use of the devm_platform_get_and_ioremap_resource()
 -  Use temporary variable for struct device
 -  Drop wrong kernel doc annotation

st:
 -  Switch to use devm_kasprintf_strarray()
 -  Convert to use dev_err_probe()
 -  Make use of the devm_platform_ioremap_resource_byname()
 -  Use temporary variable for struct device
 -  Drop wrong kernel doc annotations

zynqmp:
 -  Unify pin naming
parents fa55b7dc f7c151d8
...@@ -491,27 +491,6 @@ static void gpio_mockup_unregister_pdevs(void) ...@@ -491,27 +491,6 @@ static void gpio_mockup_unregister_pdevs(void)
} }
} }
static __init char **gpio_mockup_make_line_names(const char *label,
unsigned int num_lines)
{
unsigned int i;
char **names;
names = kcalloc(num_lines + 1, sizeof(char *), GFP_KERNEL);
if (!names)
return NULL;
for (i = 0; i < num_lines; i++) {
names[i] = kasprintf(GFP_KERNEL, "%s-%u", label, i);
if (!names[i]) {
kfree_strarray(names, i);
return NULL;
}
}
return names;
}
static int __init gpio_mockup_register_chip(int idx) static int __init gpio_mockup_register_chip(int idx)
{ {
struct property_entry properties[GPIO_MOCKUP_MAX_PROP]; struct property_entry properties[GPIO_MOCKUP_MAX_PROP];
...@@ -538,7 +517,7 @@ static int __init gpio_mockup_register_chip(int idx) ...@@ -538,7 +517,7 @@ static int __init gpio_mockup_register_chip(int idx)
properties[prop++] = PROPERTY_ENTRY_U16("nr-gpios", ngpio); properties[prop++] = PROPERTY_ENTRY_U16("nr-gpios", ngpio);
if (gpio_mockup_named_lines) { if (gpio_mockup_named_lines) {
line_names = gpio_mockup_make_line_names(chip_label, ngpio); line_names = kasprintf_strarray(GFP_KERNEL, chip_label, ngpio);
if (!line_names) if (!line_names)
return -ENOMEM; return -ENOMEM;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string_helpers.h>
#include "../pinctrl-utils.h" #include "../pinctrl-utils.h"
...@@ -341,12 +342,12 @@ static int armada_37xx_pmx_set_by_name(struct pinctrl_dev *pctldev, ...@@ -341,12 +342,12 @@ static int armada_37xx_pmx_set_by_name(struct pinctrl_dev *pctldev,
struct armada_37xx_pin_group *grp) struct armada_37xx_pin_group *grp)
{ {
struct armada_37xx_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); struct armada_37xx_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
struct device *dev = info->dev;
unsigned int reg = SELECTION; unsigned int reg = SELECTION;
unsigned int mask = grp->reg_mask; unsigned int mask = grp->reg_mask;
int func, val; int func, val;
dev_dbg(info->dev, "enable function %s group %s\n", dev_dbg(dev, "enable function %s group %s\n", name, grp->name);
name, grp->name);
func = match_string(grp->funcs, NB_FUNCS, name); func = match_string(grp->funcs, NB_FUNCS, name);
if (func < 0) if (func < 0)
...@@ -722,25 +723,22 @@ static unsigned int armada_37xx_irq_startup(struct irq_data *d) ...@@ -722,25 +723,22 @@ static unsigned int armada_37xx_irq_startup(struct irq_data *d)
static int armada_37xx_irqchip_register(struct platform_device *pdev, static int armada_37xx_irqchip_register(struct platform_device *pdev,
struct armada_37xx_pinctrl *info) struct armada_37xx_pinctrl *info)
{ {
struct device_node *np = info->dev->of_node;
struct gpio_chip *gc = &info->gpio_chip; struct gpio_chip *gc = &info->gpio_chip;
struct irq_chip *irqchip = &info->irq_chip; struct irq_chip *irqchip = &info->irq_chip;
struct gpio_irq_chip *girq = &gc->irq; struct gpio_irq_chip *girq = &gc->irq;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct resource res; struct device_node *np;
int ret = -ENODEV, i, nr_irq_parent; int ret = -ENODEV, i, nr_irq_parent;
/* Check if we have at least one gpio-controller child node */ /* Check if we have at least one gpio-controller child node */
for_each_child_of_node(info->dev->of_node, np) { for_each_child_of_node(dev->of_node, np) {
if (of_property_read_bool(np, "gpio-controller")) { if (of_property_read_bool(np, "gpio-controller")) {
ret = 0; ret = 0;
break; break;
} }
} }
if (ret) { if (ret)
dev_err(dev, "no gpio-controller child node\n"); return dev_err_probe(dev, ret, "no gpio-controller child node\n");
return ret;
}
nr_irq_parent = of_irq_count(np); nr_irq_parent = of_irq_count(np);
spin_lock_init(&info->irq_lock); spin_lock_init(&info->irq_lock);
...@@ -750,12 +748,7 @@ static int armada_37xx_irqchip_register(struct platform_device *pdev, ...@@ -750,12 +748,7 @@ static int armada_37xx_irqchip_register(struct platform_device *pdev,
return 0; return 0;
} }
if (of_address_to_resource(info->dev->of_node, 1, &res)) { info->base = devm_platform_ioremap_resource(pdev, 1);
dev_err(dev, "cannot find IO resource\n");
return -ENOENT;
}
info->base = devm_ioremap_resource(info->dev, &res);
if (IS_ERR(info->base)) if (IS_ERR(info->base))
return PTR_ERR(info->base); return PTR_ERR(info->base);
...@@ -774,8 +767,7 @@ static int armada_37xx_irqchip_register(struct platform_device *pdev, ...@@ -774,8 +767,7 @@ static int armada_37xx_irqchip_register(struct platform_device *pdev,
* the chained irq with all of them. * the chained irq with all of them.
*/ */
girq->num_parents = nr_irq_parent; girq->num_parents = nr_irq_parent;
girq->parents = devm_kcalloc(&pdev->dev, nr_irq_parent, girq->parents = devm_kcalloc(dev, nr_irq_parent, sizeof(*girq->parents), GFP_KERNEL);
sizeof(*girq->parents), GFP_KERNEL);
if (!girq->parents) if (!girq->parents)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < nr_irq_parent; i++) { for (i = 0; i < nr_irq_parent; i++) {
...@@ -794,11 +786,12 @@ static int armada_37xx_irqchip_register(struct platform_device *pdev, ...@@ -794,11 +786,12 @@ static int armada_37xx_irqchip_register(struct platform_device *pdev,
static int armada_37xx_gpiochip_register(struct platform_device *pdev, static int armada_37xx_gpiochip_register(struct platform_device *pdev,
struct armada_37xx_pinctrl *info) struct armada_37xx_pinctrl *info)
{ {
struct device *dev = &pdev->dev;
struct device_node *np; struct device_node *np;
struct gpio_chip *gc; struct gpio_chip *gc;
int ret = -ENODEV; int ret = -ENODEV;
for_each_child_of_node(info->dev->of_node, np) { for_each_child_of_node(dev->of_node, np) {
if (of_find_property(np, "gpio-controller", NULL)) { if (of_find_property(np, "gpio-controller", NULL)) {
ret = 0; ret = 0;
break; break;
...@@ -811,19 +804,16 @@ static int armada_37xx_gpiochip_register(struct platform_device *pdev, ...@@ -811,19 +804,16 @@ static int armada_37xx_gpiochip_register(struct platform_device *pdev,
gc = &info->gpio_chip; gc = &info->gpio_chip;
gc->ngpio = info->data->nr_pins; gc->ngpio = info->data->nr_pins;
gc->parent = &pdev->dev; gc->parent = dev;
gc->base = -1; gc->base = -1;
gc->of_node = np; gc->of_node = np;
gc->label = info->data->name; gc->label = info->data->name;
ret = armada_37xx_irqchip_register(pdev, info); ret = armada_37xx_irqchip_register(pdev, info);
if (ret)
return ret;
ret = devm_gpiochip_add_data(&pdev->dev, gc, info);
if (ret) if (ret)
return ret; return ret;
return 0; return devm_gpiochip_add_data(dev, gc, info);
} }
/** /**
...@@ -874,13 +864,13 @@ static int armada_37xx_add_function(struct armada_37xx_pmx_func *funcs, ...@@ -874,13 +864,13 @@ static int armada_37xx_add_function(struct armada_37xx_pmx_func *funcs,
static int armada_37xx_fill_group(struct armada_37xx_pinctrl *info) static int armada_37xx_fill_group(struct armada_37xx_pinctrl *info)
{ {
int n, num = 0, funcsize = info->data->nr_pins; int n, num = 0, funcsize = info->data->nr_pins;
struct device *dev = info->dev;
for (n = 0; n < info->ngroups; n++) { for (n = 0; n < info->ngroups; n++) {
struct armada_37xx_pin_group *grp = &info->groups[n]; struct armada_37xx_pin_group *grp = &info->groups[n];
int i, j, f; int i, j, f;
grp->pins = devm_kcalloc(info->dev, grp->pins = devm_kcalloc(dev, grp->npins + grp->extra_npins,
grp->npins + grp->extra_npins,
sizeof(*grp->pins), sizeof(*grp->pins),
GFP_KERNEL); GFP_KERNEL);
if (!grp->pins) if (!grp->pins)
...@@ -898,8 +888,7 @@ static int armada_37xx_fill_group(struct armada_37xx_pinctrl *info) ...@@ -898,8 +888,7 @@ static int armada_37xx_fill_group(struct armada_37xx_pinctrl *info)
ret = armada_37xx_add_function(info->funcs, &funcsize, ret = armada_37xx_add_function(info->funcs, &funcsize,
grp->funcs[f]); grp->funcs[f]);
if (ret == -EOVERFLOW) if (ret == -EOVERFLOW)
dev_err(info->dev, dev_err(dev, "More functions than pins(%d)\n",
"More functions than pins(%d)\n",
info->data->nr_pins); info->data->nr_pins);
if (ret < 0) if (ret < 0)
continue; continue;
...@@ -913,7 +902,7 @@ static int armada_37xx_fill_group(struct armada_37xx_pinctrl *info) ...@@ -913,7 +902,7 @@ static int armada_37xx_fill_group(struct armada_37xx_pinctrl *info)
} }
/** /**
* armada_37xx_fill_funcs() - complete the funcs array * armada_37xx_fill_func() - complete the funcs array
* @info: info driver instance * @info: info driver instance
* *
* Based on the data available from the armada_37xx_pin_group array * Based on the data available from the armada_37xx_pin_group array
...@@ -925,6 +914,7 @@ static int armada_37xx_fill_group(struct armada_37xx_pinctrl *info) ...@@ -925,6 +914,7 @@ static int armada_37xx_fill_group(struct armada_37xx_pinctrl *info)
static int armada_37xx_fill_func(struct armada_37xx_pinctrl *info) static int armada_37xx_fill_func(struct armada_37xx_pinctrl *info)
{ {
struct armada_37xx_pmx_func *funcs = info->funcs; struct armada_37xx_pmx_func *funcs = info->funcs;
struct device *dev = info->dev;
int n; int n;
for (n = 0; n < info->nfuncs; n++) { for (n = 0; n < info->nfuncs; n++) {
...@@ -932,8 +922,7 @@ static int armada_37xx_fill_func(struct armada_37xx_pinctrl *info) ...@@ -932,8 +922,7 @@ static int armada_37xx_fill_func(struct armada_37xx_pinctrl *info)
const char **groups; const char **groups;
int g; int g;
funcs[n].groups = devm_kcalloc(info->dev, funcs[n].groups = devm_kcalloc(dev, funcs[n].ngroups,
funcs[n].ngroups,
sizeof(*(funcs[n].groups)), sizeof(*(funcs[n].groups)),
GFP_KERNEL); GFP_KERNEL);
if (!funcs[n].groups) if (!funcs[n].groups)
...@@ -962,6 +951,8 @@ static int armada_37xx_pinctrl_register(struct platform_device *pdev, ...@@ -962,6 +951,8 @@ static int armada_37xx_pinctrl_register(struct platform_device *pdev,
const struct armada_37xx_pin_data *pin_data = info->data; const struct armada_37xx_pin_data *pin_data = info->data;
struct pinctrl_desc *ctrldesc = &info->pctl; struct pinctrl_desc *ctrldesc = &info->pctl;
struct pinctrl_pin_desc *pindesc, *pdesc; struct pinctrl_pin_desc *pindesc, *pdesc;
struct device *dev = &pdev->dev;
char **pin_names;
int pin, ret; int pin, ret;
info->groups = pin_data->groups; info->groups = pin_data->groups;
...@@ -973,20 +964,21 @@ static int armada_37xx_pinctrl_register(struct platform_device *pdev, ...@@ -973,20 +964,21 @@ static int armada_37xx_pinctrl_register(struct platform_device *pdev,
ctrldesc->pmxops = &armada_37xx_pmx_ops; ctrldesc->pmxops = &armada_37xx_pmx_ops;
ctrldesc->confops = &armada_37xx_pinconf_ops; ctrldesc->confops = &armada_37xx_pinconf_ops;
pindesc = devm_kcalloc(&pdev->dev, pindesc = devm_kcalloc(dev, pin_data->nr_pins, sizeof(*pindesc), GFP_KERNEL);
pin_data->nr_pins, sizeof(*pindesc),
GFP_KERNEL);
if (!pindesc) if (!pindesc)
return -ENOMEM; return -ENOMEM;
ctrldesc->pins = pindesc; ctrldesc->pins = pindesc;
ctrldesc->npins = pin_data->nr_pins; ctrldesc->npins = pin_data->nr_pins;
pin_names = devm_kasprintf_strarray(dev, pin_data->name, pin_data->nr_pins);
if (IS_ERR(pin_names))
return PTR_ERR(pin_names);
pdesc = pindesc; pdesc = pindesc;
for (pin = 0; pin < pin_data->nr_pins; pin++) { for (pin = 0; pin < pin_data->nr_pins; pin++) {
pdesc->number = pin; pdesc->number = pin;
pdesc->name = kasprintf(GFP_KERNEL, "%s-%d", pdesc->name = pin_names[pin];
pin_data->name, pin);
pdesc++; pdesc++;
} }
...@@ -994,14 +986,10 @@ static int armada_37xx_pinctrl_register(struct platform_device *pdev, ...@@ -994,14 +986,10 @@ static int armada_37xx_pinctrl_register(struct platform_device *pdev,
* we allocate functions for number of pins and hope there are * we allocate functions for number of pins and hope there are
* fewer unique functions than pins available * fewer unique functions than pins available
*/ */
info->funcs = devm_kcalloc(&pdev->dev, info->funcs = devm_kcalloc(dev, pin_data->nr_pins, sizeof(*info->funcs), GFP_KERNEL);
pin_data->nr_pins,
sizeof(struct armada_37xx_pmx_func),
GFP_KERNEL);
if (!info->funcs) if (!info->funcs)
return -ENOMEM; return -ENOMEM;
ret = armada_37xx_fill_group(info); ret = armada_37xx_fill_group(info);
if (ret) if (ret)
return ret; return ret;
...@@ -1010,11 +998,9 @@ static int armada_37xx_pinctrl_register(struct platform_device *pdev, ...@@ -1010,11 +998,9 @@ static int armada_37xx_pinctrl_register(struct platform_device *pdev,
if (ret) if (ret)
return ret; return ret;
info->pctl_dev = devm_pinctrl_register(&pdev->dev, ctrldesc, info); info->pctl_dev = devm_pinctrl_register(dev, ctrldesc, info);
if (IS_ERR(info->pctl_dev)) { if (IS_ERR(info->pctl_dev))
dev_err(&pdev->dev, "could not register pinctrl driver\n"); return dev_err_probe(dev, PTR_ERR(info->pctl_dev), "could not register pinctrl driver\n");
return PTR_ERR(info->pctl_dev);
}
return 0; return 0;
} }
...@@ -1143,18 +1129,15 @@ static int __init armada_37xx_pinctrl_probe(struct platform_device *pdev) ...@@ -1143,18 +1129,15 @@ static int __init armada_37xx_pinctrl_probe(struct platform_device *pdev)
struct regmap *regmap; struct regmap *regmap;
int ret; int ret;
info = devm_kzalloc(dev, sizeof(struct armada_37xx_pinctrl), info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
GFP_KERNEL);
if (!info) if (!info)
return -ENOMEM; return -ENOMEM;
info->dev = dev; info->dev = dev;
regmap = syscon_node_to_regmap(np); regmap = syscon_node_to_regmap(np);
if (IS_ERR(regmap)) { if (IS_ERR(regmap))
dev_err(&pdev->dev, "cannot get regmap\n"); return dev_err_probe(dev, PTR_ERR(regmap), "cannot get regmap\n");
return PTR_ERR(regmap);
}
info->regmap = regmap; info->regmap = regmap;
info->data = of_device_get_match_data(dev); info->data = of_device_get_match_data(dev);
......
...@@ -33,13 +33,15 @@ ...@@ -33,13 +33,15 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/mfd/syscon.h> #include <linux/mfd/syscon.h>
#include <linux/string_helpers.h>
#include <dt-bindings/pinctrl/rockchip.h> #include <dt-bindings/pinctrl/rockchip.h>
#include "core.h" #include "core.h"
#include "pinconf.h" #include "pinconf.h"
#include "pinctrl-rockchip.h" #include "pinctrl-rockchip.h"
/** /*
* Generate a bitmask for setting a value (v) with a write mask bit in hiword * Generate a bitmask for setting a value (v) with a write mask bit in hiword
* register 31:16 area. * register 31:16 area.
*/ */
...@@ -285,6 +287,7 @@ static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev, ...@@ -285,6 +287,7 @@ static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev,
{ {
struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
const struct rockchip_pin_group *grp; const struct rockchip_pin_group *grp;
struct device *dev = info->dev;
struct pinctrl_map *new_map; struct pinctrl_map *new_map;
struct device_node *parent; struct device_node *parent;
int map_num = 1; int map_num = 1;
...@@ -296,8 +299,7 @@ static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev, ...@@ -296,8 +299,7 @@ static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev,
*/ */
grp = pinctrl_name_to_group(info, np->name); grp = pinctrl_name_to_group(info, np->name);
if (!grp) { if (!grp) {
dev_err(info->dev, "unable to find group for node %pOFn\n", dev_err(dev, "unable to find group for node %pOFn\n", np);
np);
return -EINVAL; return -EINVAL;
} }
...@@ -331,7 +333,7 @@ static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev, ...@@ -331,7 +333,7 @@ static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev,
new_map[i].data.configs.num_configs = grp->data[i].nconfigs; new_map[i].data.configs.num_configs = grp->data[i].nconfigs;
} }
dev_dbg(pctldev->dev, "maps: function %s group %s num %d\n", dev_dbg(dev, "maps: function %s group %s num %d\n",
(*map)->data.mux.function, (*map)->data.mux.group, map_num); (*map)->data.mux.function, (*map)->data.mux.group, map_num);
return 0; return 0;
...@@ -872,20 +874,20 @@ static int rockchip_verify_mux(struct rockchip_pin_bank *bank, ...@@ -872,20 +874,20 @@ static int rockchip_verify_mux(struct rockchip_pin_bank *bank,
int pin, int mux) int pin, int mux)
{ {
struct rockchip_pinctrl *info = bank->drvdata; struct rockchip_pinctrl *info = bank->drvdata;
struct device *dev = info->dev;
int iomux_num = (pin / 8); int iomux_num = (pin / 8);
if (iomux_num > 3) if (iomux_num > 3)
return -EINVAL; return -EINVAL;
if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) { if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
dev_err(info->dev, "pin %d is unrouted\n", pin); dev_err(dev, "pin %d is unrouted\n", pin);
return -EINVAL; return -EINVAL;
} }
if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) { if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) {
if (mux != RK_FUNC_GPIO) { if (mux != RK_FUNC_GPIO) {
dev_err(info->dev, dev_err(dev, "pin %d only supports a gpio mux\n", pin);
"pin %d only supports a gpio mux\n", pin);
return -ENOTSUPP; return -ENOTSUPP;
} }
} }
...@@ -909,6 +911,7 @@ static int rockchip_verify_mux(struct rockchip_pin_bank *bank, ...@@ -909,6 +911,7 @@ static int rockchip_verify_mux(struct rockchip_pin_bank *bank,
static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux) static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
{ {
struct rockchip_pinctrl *info = bank->drvdata; struct rockchip_pinctrl *info = bank->drvdata;
struct device *dev = info->dev;
int iomux_num = (pin / 8); int iomux_num = (pin / 8);
struct regmap *regmap; struct regmap *regmap;
int reg, ret, mask, mux_type; int reg, ret, mask, mux_type;
...@@ -922,8 +925,7 @@ static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux) ...@@ -922,8 +925,7 @@ static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
return 0; return 0;
dev_dbg(info->dev, "setting mux of GPIO%d-%d to %d\n", dev_dbg(dev, "setting mux of GPIO%d-%d to %d\n", bank->bank_num, pin, mux);
bank->bank_num, pin, mux);
regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU) regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
? info->regmap_pmu : info->regmap_base; ? info->regmap_pmu : info->regmap_base;
...@@ -1575,6 +1577,7 @@ static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank, ...@@ -1575,6 +1577,7 @@ static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank,
{ {
struct rockchip_pinctrl *info = bank->drvdata; struct rockchip_pinctrl *info = bank->drvdata;
struct rockchip_pin_ctrl *ctrl = info->ctrl; struct rockchip_pin_ctrl *ctrl = info->ctrl;
struct device *dev = info->dev;
struct regmap *regmap; struct regmap *regmap;
int reg, ret; int reg, ret;
u32 data, temp, rmask_bits; u32 data, temp, rmask_bits;
...@@ -1620,7 +1623,7 @@ static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank, ...@@ -1620,7 +1623,7 @@ static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank,
bit -= 16; bit -= 16;
break; break;
default: default:
dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n", dev_err(dev, "unsupported bit: %d for pinctrl drive type: %d\n",
bit, drv_type); bit, drv_type);
return -EINVAL; return -EINVAL;
} }
...@@ -1632,8 +1635,7 @@ static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank, ...@@ -1632,8 +1635,7 @@ static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank,
rmask_bits = RK3288_DRV_BITS_PER_PIN; rmask_bits = RK3288_DRV_BITS_PER_PIN;
break; break;
default: default:
dev_err(info->dev, "unsupported pinctrl drive type: %d\n", dev_err(dev, "unsupported pinctrl drive type: %d\n", drv_type);
drv_type);
return -EINVAL; return -EINVAL;
} }
...@@ -1652,13 +1654,14 @@ static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank, ...@@ -1652,13 +1654,14 @@ static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
{ {
struct rockchip_pinctrl *info = bank->drvdata; struct rockchip_pinctrl *info = bank->drvdata;
struct rockchip_pin_ctrl *ctrl = info->ctrl; struct rockchip_pin_ctrl *ctrl = info->ctrl;
struct device *dev = info->dev;
struct regmap *regmap; struct regmap *regmap;
int reg, ret, i; int reg, ret, i;
u32 data, rmask, rmask_bits, temp; u32 data, rmask, rmask_bits, temp;
u8 bit; u8 bit;
int drv_type = bank->drv[pin_num / 8].drv_type; int drv_type = bank->drv[pin_num / 8].drv_type;
dev_dbg(info->dev, "setting drive of GPIO%d-%d to %d\n", dev_dbg(dev, "setting drive of GPIO%d-%d to %d\n",
bank->bank_num, pin_num, strength); bank->bank_num, pin_num, strength);
ctrl->drv_calc_reg(bank, pin_num, &regmap, &reg, &bit); ctrl->drv_calc_reg(bank, pin_num, &regmap, &reg, &bit);
...@@ -1680,8 +1683,7 @@ static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank, ...@@ -1680,8 +1683,7 @@ static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
} }
if (ret < 0) { if (ret < 0) {
dev_err(info->dev, "unsupported driver strength %d\n", dev_err(dev, "unsupported driver strength %d\n", strength);
strength);
return ret; return ret;
} }
...@@ -1720,7 +1722,7 @@ static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank, ...@@ -1720,7 +1722,7 @@ static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
bit -= 16; bit -= 16;
break; break;
default: default:
dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n", dev_err(dev, "unsupported bit: %d for pinctrl drive type: %d\n",
bit, drv_type); bit, drv_type);
return -EINVAL; return -EINVAL;
} }
...@@ -1731,8 +1733,7 @@ static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank, ...@@ -1731,8 +1733,7 @@ static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
rmask_bits = RK3288_DRV_BITS_PER_PIN; rmask_bits = RK3288_DRV_BITS_PER_PIN;
break; break;
default: default:
dev_err(info->dev, "unsupported pinctrl drive type: %d\n", dev_err(dev, "unsupported pinctrl drive type: %d\n", drv_type);
drv_type);
return -EINVAL; return -EINVAL;
} }
...@@ -1766,6 +1767,7 @@ static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num) ...@@ -1766,6 +1767,7 @@ static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)
{ {
struct rockchip_pinctrl *info = bank->drvdata; struct rockchip_pinctrl *info = bank->drvdata;
struct rockchip_pin_ctrl *ctrl = info->ctrl; struct rockchip_pin_ctrl *ctrl = info->ctrl;
struct device *dev = info->dev;
struct regmap *regmap; struct regmap *regmap;
int reg, ret, pull_type; int reg, ret, pull_type;
u8 bit; u8 bit;
...@@ -1800,7 +1802,7 @@ static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num) ...@@ -1800,7 +1802,7 @@ static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)
return rockchip_pull_list[pull_type][data]; return rockchip_pull_list[pull_type][data];
default: default:
dev_err(info->dev, "unsupported pinctrl type\n"); dev_err(dev, "unsupported pinctrl type\n");
return -EINVAL; return -EINVAL;
}; };
} }
...@@ -1810,13 +1812,13 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank, ...@@ -1810,13 +1812,13 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank,
{ {
struct rockchip_pinctrl *info = bank->drvdata; struct rockchip_pinctrl *info = bank->drvdata;
struct rockchip_pin_ctrl *ctrl = info->ctrl; struct rockchip_pin_ctrl *ctrl = info->ctrl;
struct device *dev = info->dev;
struct regmap *regmap; struct regmap *regmap;
int reg, ret, i, pull_type; int reg, ret, i, pull_type;
u8 bit; u8 bit;
u32 data, rmask; u32 data, rmask;
dev_dbg(info->dev, "setting pull of GPIO%d-%d to %d\n", dev_dbg(dev, "setting pull of GPIO%d-%d to %d\n", bank->bank_num, pin_num, pull);
bank->bank_num, pin_num, pull);
/* rk3066b does support any pulls */ /* rk3066b does support any pulls */
if (ctrl->type == RK3066B) if (ctrl->type == RK3066B)
...@@ -1859,8 +1861,7 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank, ...@@ -1859,8 +1861,7 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank,
} }
if (ret < 0) { if (ret < 0) {
dev_err(info->dev, "unsupported pull setting %d\n", dev_err(dev, "unsupported pull setting %d\n", pull);
pull);
return ret; return ret;
} }
...@@ -1872,7 +1873,7 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank, ...@@ -1872,7 +1873,7 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank,
ret = regmap_update_bits(regmap, reg, rmask, data); ret = regmap_update_bits(regmap, reg, rmask, data);
break; break;
default: default:
dev_err(info->dev, "unsupported pinctrl type\n"); dev_err(dev, "unsupported pinctrl type\n");
return -EINVAL; return -EINVAL;
} }
...@@ -1963,12 +1964,13 @@ static int rockchip_set_schmitt(struct rockchip_pin_bank *bank, ...@@ -1963,12 +1964,13 @@ static int rockchip_set_schmitt(struct rockchip_pin_bank *bank,
{ {
struct rockchip_pinctrl *info = bank->drvdata; struct rockchip_pinctrl *info = bank->drvdata;
struct rockchip_pin_ctrl *ctrl = info->ctrl; struct rockchip_pin_ctrl *ctrl = info->ctrl;
struct device *dev = info->dev;
struct regmap *regmap; struct regmap *regmap;
int reg, ret; int reg, ret;
u8 bit; u8 bit;
u32 data, rmask; u32 data, rmask;
dev_dbg(info->dev, "setting input schmitt of GPIO%d-%d to %d\n", dev_dbg(dev, "setting input schmitt of GPIO%d-%d to %d\n",
bank->bank_num, pin_num, enable); bank->bank_num, pin_num, enable);
ret = ctrl->schmitt_calc_reg(bank, pin_num, &regmap, &reg, &bit); ret = ctrl->schmitt_calc_reg(bank, pin_num, &regmap, &reg, &bit);
...@@ -2028,10 +2030,11 @@ static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector, ...@@ -2028,10 +2030,11 @@ static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
const unsigned int *pins = info->groups[group].pins; const unsigned int *pins = info->groups[group].pins;
const struct rockchip_pin_config *data = info->groups[group].data; const struct rockchip_pin_config *data = info->groups[group].data;
struct device *dev = info->dev;
struct rockchip_pin_bank *bank; struct rockchip_pin_bank *bank;
int cnt, ret = 0; int cnt, ret = 0;
dev_dbg(info->dev, "enable function %s group %s\n", dev_dbg(dev, "enable function %s group %s\n",
info->functions[selector].name, info->groups[group].name); info->functions[selector].name, info->groups[group].name);
/* /*
...@@ -2310,6 +2313,7 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np, ...@@ -2310,6 +2313,7 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np,
struct rockchip_pinctrl *info, struct rockchip_pinctrl *info,
u32 index) u32 index)
{ {
struct device *dev = info->dev;
struct rockchip_pin_bank *bank; struct rockchip_pin_bank *bank;
int size; int size;
const __be32 *list; const __be32 *list;
...@@ -2317,7 +2321,7 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np, ...@@ -2317,7 +2321,7 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np,
int i, j; int i, j;
int ret; int ret;
dev_dbg(info->dev, "group(%d): %pOFn\n", index, np); dev_dbg(dev, "group(%d): %pOFn\n", index, np);
/* Initialise group */ /* Initialise group */
grp->name = np->name; grp->name = np->name;
...@@ -2329,19 +2333,13 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np, ...@@ -2329,19 +2333,13 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np,
list = of_get_property(np, "rockchip,pins", &size); list = of_get_property(np, "rockchip,pins", &size);
/* we do not check return since it's safe node passed down */ /* we do not check return since it's safe node passed down */
size /= sizeof(*list); size /= sizeof(*list);
if (!size || size % 4) { if (!size || size % 4)
dev_err(info->dev, "wrong pins number or pins and configs should be by 4\n"); return dev_err_probe(dev, -EINVAL, "wrong pins number or pins and configs should be by 4\n");
return -EINVAL;
}
grp->npins = size / 4; grp->npins = size / 4;
grp->pins = devm_kcalloc(info->dev, grp->npins, sizeof(unsigned int), grp->pins = devm_kcalloc(dev, grp->npins, sizeof(*grp->pins), GFP_KERNEL);
GFP_KERNEL); grp->data = devm_kcalloc(dev, grp->npins, sizeof(*grp->data), GFP_KERNEL);
grp->data = devm_kcalloc(info->dev,
grp->npins,
sizeof(struct rockchip_pin_config),
GFP_KERNEL);
if (!grp->pins || !grp->data) if (!grp->pins || !grp->data)
return -ENOMEM; return -ENOMEM;
...@@ -2375,6 +2373,7 @@ static int rockchip_pinctrl_parse_functions(struct device_node *np, ...@@ -2375,6 +2373,7 @@ static int rockchip_pinctrl_parse_functions(struct device_node *np,
struct rockchip_pinctrl *info, struct rockchip_pinctrl *info,
u32 index) u32 index)
{ {
struct device *dev = info->dev;
struct device_node *child; struct device_node *child;
struct rockchip_pmx_func *func; struct rockchip_pmx_func *func;
struct rockchip_pin_group *grp; struct rockchip_pin_group *grp;
...@@ -2382,7 +2381,7 @@ static int rockchip_pinctrl_parse_functions(struct device_node *np, ...@@ -2382,7 +2381,7 @@ static int rockchip_pinctrl_parse_functions(struct device_node *np,
static u32 grp_index; static u32 grp_index;
u32 i = 0; u32 i = 0;
dev_dbg(info->dev, "parse function(%d): %pOFn\n", index, np); dev_dbg(dev, "parse function(%d): %pOFn\n", index, np);
func = &info->functions[index]; func = &info->functions[index];
...@@ -2392,8 +2391,7 @@ static int rockchip_pinctrl_parse_functions(struct device_node *np, ...@@ -2392,8 +2391,7 @@ static int rockchip_pinctrl_parse_functions(struct device_node *np,
if (func->ngroups <= 0) if (func->ngroups <= 0)
return 0; return 0;
func->groups = devm_kcalloc(info->dev, func->groups = devm_kcalloc(dev, func->ngroups, sizeof(*func->groups), GFP_KERNEL);
func->ngroups, sizeof(char *), GFP_KERNEL);
if (!func->groups) if (!func->groups)
return -ENOMEM; return -ENOMEM;
...@@ -2421,20 +2419,14 @@ static int rockchip_pinctrl_parse_dt(struct platform_device *pdev, ...@@ -2421,20 +2419,14 @@ static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
rockchip_pinctrl_child_count(info, np); rockchip_pinctrl_child_count(info, np);
dev_dbg(&pdev->dev, "nfunctions = %d\n", info->nfunctions); dev_dbg(dev, "nfunctions = %d\n", info->nfunctions);
dev_dbg(&pdev->dev, "ngroups = %d\n", info->ngroups); dev_dbg(dev, "ngroups = %d\n", info->ngroups);
info->functions = devm_kcalloc(dev, info->functions = devm_kcalloc(dev, info->nfunctions, sizeof(*info->functions), GFP_KERNEL);
info->nfunctions,
sizeof(struct rockchip_pmx_func),
GFP_KERNEL);
if (!info->functions) if (!info->functions)
return -ENOMEM; return -ENOMEM;
info->groups = devm_kcalloc(dev, info->groups = devm_kcalloc(dev, info->ngroups, sizeof(*info->groups), GFP_KERNEL);
info->ngroups,
sizeof(struct rockchip_pin_group),
GFP_KERNEL);
if (!info->groups) if (!info->groups)
return -ENOMEM; return -ENOMEM;
...@@ -2446,7 +2438,7 @@ static int rockchip_pinctrl_parse_dt(struct platform_device *pdev, ...@@ -2446,7 +2438,7 @@ static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
ret = rockchip_pinctrl_parse_functions(child, info, i++); ret = rockchip_pinctrl_parse_functions(child, info, i++);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to parse function\n"); dev_err(dev, "failed to parse function\n");
of_node_put(child); of_node_put(child);
return ret; return ret;
} }
...@@ -2461,6 +2453,8 @@ static int rockchip_pinctrl_register(struct platform_device *pdev, ...@@ -2461,6 +2453,8 @@ static int rockchip_pinctrl_register(struct platform_device *pdev,
struct pinctrl_desc *ctrldesc = &info->pctl; struct pinctrl_desc *ctrldesc = &info->pctl;
struct pinctrl_pin_desc *pindesc, *pdesc; struct pinctrl_pin_desc *pindesc, *pdesc;
struct rockchip_pin_bank *pin_bank; struct rockchip_pin_bank *pin_bank;
struct device *dev = &pdev->dev;
char **pin_names;
int pin, bank, ret; int pin, bank, ret;
int k; int k;
...@@ -2470,9 +2464,7 @@ static int rockchip_pinctrl_register(struct platform_device *pdev, ...@@ -2470,9 +2464,7 @@ static int rockchip_pinctrl_register(struct platform_device *pdev,
ctrldesc->pmxops = &rockchip_pmx_ops; ctrldesc->pmxops = &rockchip_pmx_ops;
ctrldesc->confops = &rockchip_pinconf_ops; ctrldesc->confops = &rockchip_pinconf_ops;
pindesc = devm_kcalloc(&pdev->dev, pindesc = devm_kcalloc(dev, info->ctrl->nr_pins, sizeof(*pindesc), GFP_KERNEL);
info->ctrl->nr_pins, sizeof(*pindesc),
GFP_KERNEL);
if (!pindesc) if (!pindesc)
return -ENOMEM; return -ENOMEM;
...@@ -2482,10 +2474,14 @@ static int rockchip_pinctrl_register(struct platform_device *pdev, ...@@ -2482,10 +2474,14 @@ static int rockchip_pinctrl_register(struct platform_device *pdev,
pdesc = pindesc; pdesc = pindesc;
for (bank = 0, k = 0; bank < info->ctrl->nr_banks; bank++) { for (bank = 0, k = 0; bank < info->ctrl->nr_banks; bank++) {
pin_bank = &info->ctrl->pin_banks[bank]; pin_bank = &info->ctrl->pin_banks[bank];
pin_names = devm_kasprintf_strarray(dev, pin_bank->name, pin_bank->nr_pins);
if (IS_ERR(pin_names))
return PTR_ERR(pin_names);
for (pin = 0; pin < pin_bank->nr_pins; pin++, k++) { for (pin = 0; pin < pin_bank->nr_pins; pin++, k++) {
pdesc->number = k; pdesc->number = k;
pdesc->name = kasprintf(GFP_KERNEL, "%s-%d", pdesc->name = pin_names[pin];
pin_bank->name, pin);
pdesc++; pdesc++;
} }
...@@ -2497,11 +2493,9 @@ static int rockchip_pinctrl_register(struct platform_device *pdev, ...@@ -2497,11 +2493,9 @@ static int rockchip_pinctrl_register(struct platform_device *pdev,
if (ret) if (ret)
return ret; return ret;
info->pctl_dev = devm_pinctrl_register(&pdev->dev, ctrldesc, info); info->pctl_dev = devm_pinctrl_register(dev, ctrldesc, info);
if (IS_ERR(info->pctl_dev)) { if (IS_ERR(info->pctl_dev))
dev_err(&pdev->dev, "could not register pinctrl driver\n"); return dev_err_probe(dev, PTR_ERR(info->pctl_dev), "could not register pinctrl driver\n");
return PTR_ERR(info->pctl_dev);
}
return 0; return 0;
} }
...@@ -2513,8 +2507,9 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data( ...@@ -2513,8 +2507,9 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
struct rockchip_pinctrl *d, struct rockchip_pinctrl *d,
struct platform_device *pdev) struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
struct device_node *node = dev->of_node;
const struct of_device_id *match; const struct of_device_id *match;
struct device_node *node = pdev->dev.of_node;
struct rockchip_pin_ctrl *ctrl; struct rockchip_pin_ctrl *ctrl;
struct rockchip_pin_bank *bank; struct rockchip_pin_bank *bank;
int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j; int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
...@@ -2566,7 +2561,7 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data( ...@@ -2566,7 +2561,7 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
drv_pmu_offs : drv_grf_offs; drv_pmu_offs : drv_grf_offs;
} }
dev_dbg(d->dev, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n", dev_dbg(dev, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
i, j, iom->offset, drv->offset); i, j, iom->offset, drv->offset);
/* /*
...@@ -2675,16 +2670,14 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev) ...@@ -2675,16 +2670,14 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev)
{ {
struct rockchip_pinctrl *info; struct rockchip_pinctrl *info;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node, *node;
struct rockchip_pin_ctrl *ctrl; struct rockchip_pin_ctrl *ctrl;
struct device_node *np = pdev->dev.of_node, *node;
struct resource *res; struct resource *res;
void __iomem *base; void __iomem *base;
int ret; int ret;
if (!dev->of_node) { if (!dev->of_node)
dev_err(dev, "device tree node not found\n"); return dev_err_probe(dev, -ENODEV, "device tree node not found\n");
return -ENODEV;
}
info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
if (!info) if (!info)
...@@ -2693,10 +2686,8 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev) ...@@ -2693,10 +2686,8 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev)
info->dev = dev; info->dev = dev;
ctrl = rockchip_pinctrl_get_soc_data(info, pdev); ctrl = rockchip_pinctrl_get_soc_data(info, pdev);
if (!ctrl) { if (!ctrl)
dev_err(dev, "driver data not available\n"); return dev_err_probe(dev, -EINVAL, "driver data not available\n");
return -EINVAL;
}
info->ctrl = ctrl; info->ctrl = ctrl;
node = of_parse_phandle(np, "rockchip,grf", 0); node = of_parse_phandle(np, "rockchip,grf", 0);
...@@ -2705,32 +2696,28 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev) ...@@ -2705,32 +2696,28 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev)
if (IS_ERR(info->regmap_base)) if (IS_ERR(info->regmap_base))
return PTR_ERR(info->regmap_base); return PTR_ERR(info->regmap_base);
} else { } else {
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(base)) if (IS_ERR(base))
return PTR_ERR(base); return PTR_ERR(base);
rockchip_regmap_config.max_register = resource_size(res) - 4; rockchip_regmap_config.max_register = resource_size(res) - 4;
rockchip_regmap_config.name = "rockchip,pinctrl"; rockchip_regmap_config.name = "rockchip,pinctrl";
info->regmap_base = devm_regmap_init_mmio(&pdev->dev, base, info->regmap_base =
&rockchip_regmap_config); devm_regmap_init_mmio(dev, base, &rockchip_regmap_config);
/* to check for the old dt-bindings */ /* to check for the old dt-bindings */
info->reg_size = resource_size(res); info->reg_size = resource_size(res);
/* Honor the old binding, with pull registers as 2nd resource */ /* Honor the old binding, with pull registers as 2nd resource */
if (ctrl->type == RK3188 && info->reg_size < 0x200) { if (ctrl->type == RK3188 && info->reg_size < 0x200) {
res = platform_get_resource(pdev, IORESOURCE_MEM, 1); base = devm_platform_get_and_ioremap_resource(pdev, 1, &res);
base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(base)) if (IS_ERR(base))
return PTR_ERR(base); return PTR_ERR(base);
rockchip_regmap_config.max_register = rockchip_regmap_config.max_register = resource_size(res) - 4;
resource_size(res) - 4;
rockchip_regmap_config.name = "rockchip,pinctrl-pull"; rockchip_regmap_config.name = "rockchip,pinctrl-pull";
info->regmap_pull = devm_regmap_init_mmio(&pdev->dev, info->regmap_pull =
base, devm_regmap_init_mmio(dev, base, &rockchip_regmap_config);
&rockchip_regmap_config);
} }
} }
...@@ -2749,10 +2736,8 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev) ...@@ -2749,10 +2736,8 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, info); platform_set_drvdata(pdev, info);
ret = of_platform_populate(np, rockchip_bank_match, NULL, NULL); ret = of_platform_populate(np, rockchip_bank_match, NULL, NULL);
if (ret) { if (ret)
dev_err(&pdev->dev, "failed to register gpio device\n"); return dev_err_probe(dev, ret, "failed to register gpio device\n");
return ret;
}
return 0; return 0;
} }
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
#define ST_GPIO_DIRECTION_OUT 0x2 #define ST_GPIO_DIRECTION_OUT 0x2
#define ST_GPIO_DIRECTION_IN 0x4 #define ST_GPIO_DIRECTION_IN 0x4
/** /*
* Packed style retime configuration. * Packed style retime configuration.
* There are two registers cfg0 and cfg1 in this style for each bank. * There are two registers cfg0 and cfg1 in this style for each bank.
* Each field in this register is 8 bit corresponding to 8 pins in the bank. * Each field in this register is 8 bit corresponding to 8 pins in the bank.
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
#define RT_P_CFG1_CLKNOTDATA_FIELD(reg) REG_FIELD(reg, 16, 23) #define RT_P_CFG1_CLKNOTDATA_FIELD(reg) REG_FIELD(reg, 16, 23)
#define RT_P_CFG1_DOUBLE_EDGE_FIELD(reg) REG_FIELD(reg, 24, 31) #define RT_P_CFG1_DOUBLE_EDGE_FIELD(reg) REG_FIELD(reg, 24, 31)
/** /*
* Dedicated style retime Configuration register * Dedicated style retime Configuration register
* each register is dedicated per pin. * each register is dedicated per pin.
*/ */
...@@ -814,26 +814,25 @@ static int st_pctl_dt_node_to_map(struct pinctrl_dev *pctldev, ...@@ -814,26 +814,25 @@ static int st_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
{ {
struct st_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); struct st_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
const struct st_pctl_group *grp; const struct st_pctl_group *grp;
struct device *dev = info->dev;
struct pinctrl_map *new_map; struct pinctrl_map *new_map;
struct device_node *parent; struct device_node *parent;
int map_num, i; int map_num, i;
grp = st_pctl_find_group_by_name(info, np->name); grp = st_pctl_find_group_by_name(info, np->name);
if (!grp) { if (!grp) {
dev_err(info->dev, "unable to find group for node %pOFn\n", dev_err(dev, "unable to find group for node %pOFn\n", np);
np);
return -EINVAL; return -EINVAL;
} }
map_num = grp->npins + 1; map_num = grp->npins + 1;
new_map = devm_kcalloc(pctldev->dev, new_map = devm_kcalloc(dev, map_num, sizeof(*new_map), GFP_KERNEL);
map_num, sizeof(*new_map), GFP_KERNEL);
if (!new_map) if (!new_map)
return -ENOMEM; return -ENOMEM;
parent = of_get_parent(np); parent = of_get_parent(np);
if (!parent) { if (!parent) {
devm_kfree(pctldev->dev, new_map); devm_kfree(dev, new_map);
return -EINVAL; return -EINVAL;
} }
...@@ -853,7 +852,7 @@ static int st_pctl_dt_node_to_map(struct pinctrl_dev *pctldev, ...@@ -853,7 +852,7 @@ static int st_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
new_map[i].data.configs.configs = &grp->pin_conf[i].config; new_map[i].data.configs.configs = &grp->pin_conf[i].config;
new_map[i].data.configs.num_configs = 1; new_map[i].data.configs.num_configs = 1;
} }
dev_info(pctldev->dev, "maps: function %s group %s num %d\n", dev_info(dev, "maps: function %s group %s num %d\n",
(*map)->data.mux.function, grp->name, map_num); (*map)->data.mux.function, grp->name, map_num);
return 0; return 0;
...@@ -1173,6 +1172,7 @@ static int st_pctl_dt_parse_groups(struct device_node *np, ...@@ -1173,6 +1172,7 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
/* bank pad direction val altfunction */ /* bank pad direction val altfunction */
const __be32 *list; const __be32 *list;
struct property *pp; struct property *pp;
struct device *dev = info->dev;
struct st_pinconf *conf; struct st_pinconf *conf;
struct device_node *pins; struct device_node *pins;
int i = 0, npins = 0, nr_props, ret = 0; int i = 0, npins = 0, nr_props, ret = 0;
...@@ -1197,9 +1197,8 @@ static int st_pctl_dt_parse_groups(struct device_node *np, ...@@ -1197,9 +1197,8 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
grp->npins = npins; grp->npins = npins;
grp->name = np->name; grp->name = np->name;
grp->pins = devm_kcalloc(info->dev, npins, sizeof(u32), GFP_KERNEL); grp->pins = devm_kcalloc(dev, npins, sizeof(*grp->pins), GFP_KERNEL);
grp->pin_conf = devm_kcalloc(info->dev, grp->pin_conf = devm_kcalloc(dev, npins, sizeof(*grp->pin_conf), GFP_KERNEL);
npins, sizeof(*conf), GFP_KERNEL);
if (!grp->pins || !grp->pin_conf) { if (!grp->pins || !grp->pin_conf) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -1247,6 +1246,7 @@ static int st_pctl_dt_parse_groups(struct device_node *np, ...@@ -1247,6 +1246,7 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
static int st_pctl_parse_functions(struct device_node *np, static int st_pctl_parse_functions(struct device_node *np,
struct st_pinctrl *info, u32 index, int *grp_index) struct st_pinctrl *info, u32 index, int *grp_index)
{ {
struct device *dev = info->dev;
struct device_node *child; struct device_node *child;
struct st_pmx_func *func; struct st_pmx_func *func;
struct st_pctl_group *grp; struct st_pctl_group *grp;
...@@ -1255,12 +1255,9 @@ static int st_pctl_parse_functions(struct device_node *np, ...@@ -1255,12 +1255,9 @@ static int st_pctl_parse_functions(struct device_node *np,
func = &info->functions[index]; func = &info->functions[index];
func->name = np->name; func->name = np->name;
func->ngroups = of_get_child_count(np); func->ngroups = of_get_child_count(np);
if (func->ngroups == 0) { if (func->ngroups == 0)
dev_err(info->dev, "No groups defined\n"); return dev_err_probe(dev, -EINVAL, "No groups defined\n");
return -EINVAL; func->groups = devm_kcalloc(dev, func->ngroups, sizeof(*func->groups), GFP_KERNEL);
}
func->groups = devm_kcalloc(info->dev,
func->ngroups, sizeof(char *), GFP_KERNEL);
if (!func->groups) if (!func->groups)
return -ENOMEM; return -ENOMEM;
...@@ -1275,8 +1272,7 @@ static int st_pctl_parse_functions(struct device_node *np, ...@@ -1275,8 +1272,7 @@ static int st_pctl_parse_functions(struct device_node *np,
return ret; return ret;
} }
} }
dev_info(info->dev, "Function[%d\t name:%s,\tgroups:%d]\n", dev_info(dev, "Function[%d\t name:%s,\tgroups:%d]\n", index, func->name, func->ngroups);
index, func->name, func->ngroups);
return 0; return 0;
} }
...@@ -1557,10 +1553,8 @@ static int st_gpiolib_register_bank(struct st_pinctrl *info, ...@@ -1557,10 +1553,8 @@ static int st_gpiolib_register_bank(struct st_pinctrl *info,
skip_irq: skip_irq:
err = gpiochip_add_data(&bank->gpio_chip, bank); err = gpiochip_add_data(&bank->gpio_chip, bank);
if (err) { if (err)
dev_err(dev, "Failed to add gpiochip(%d)!\n", bank_num); return dev_err_probe(dev, err, "Failed to add gpiochip(%d)!\n", bank_num);
return err;
}
dev_info(dev, "%s bank added.\n", range->name); dev_info(dev, "%s bank added.\n", range->name);
return 0; return 0;
...@@ -1577,63 +1571,50 @@ static const struct of_device_id st_pctl_of_match[] = { ...@@ -1577,63 +1571,50 @@ static const struct of_device_id st_pctl_of_match[] = {
static int st_pctl_probe_dt(struct platform_device *pdev, static int st_pctl_probe_dt(struct platform_device *pdev,
struct pinctrl_desc *pctl_desc, struct st_pinctrl *info) struct pinctrl_desc *pctl_desc, struct st_pinctrl *info)
{ {
struct device *dev = &pdev->dev;
int ret = 0; int ret = 0;
int i = 0, j = 0, k = 0, bank; int i = 0, j = 0, k = 0, bank;
struct pinctrl_pin_desc *pdesc; struct pinctrl_pin_desc *pdesc;
struct device_node *np = pdev->dev.of_node; struct device_node *np = dev->of_node;
struct device_node *child; struct device_node *child;
int grp_index = 0; int grp_index = 0;
int irq = 0; int irq = 0;
struct resource *res;
st_pctl_dt_child_count(info, np); st_pctl_dt_child_count(info, np);
if (!info->nbanks) { if (!info->nbanks)
dev_err(&pdev->dev, "you need at least one gpio bank\n"); return dev_err_probe(dev, -EINVAL, "you need at least one gpio bank\n");
return -EINVAL;
}
dev_info(&pdev->dev, "nbanks = %d\n", info->nbanks); dev_info(dev, "nbanks = %d\n", info->nbanks);
dev_info(&pdev->dev, "nfunctions = %d\n", info->nfunctions); dev_info(dev, "nfunctions = %d\n", info->nfunctions);
dev_info(&pdev->dev, "ngroups = %d\n", info->ngroups); dev_info(dev, "ngroups = %d\n", info->ngroups);
info->functions = devm_kcalloc(&pdev->dev, info->functions = devm_kcalloc(dev, info->nfunctions, sizeof(*info->functions), GFP_KERNEL);
info->nfunctions, sizeof(*info->functions), GFP_KERNEL);
info->groups = devm_kcalloc(&pdev->dev, info->groups = devm_kcalloc(dev, info->ngroups, sizeof(*info->groups), GFP_KERNEL);
info->ngroups, sizeof(*info->groups),
GFP_KERNEL);
info->banks = devm_kcalloc(&pdev->dev, info->banks = devm_kcalloc(dev, info->nbanks, sizeof(*info->banks), GFP_KERNEL);
info->nbanks, sizeof(*info->banks), GFP_KERNEL);
if (!info->functions || !info->groups || !info->banks) if (!info->functions || !info->groups || !info->banks)
return -ENOMEM; return -ENOMEM;
info->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg"); info->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
if (IS_ERR(info->regmap)) { if (IS_ERR(info->regmap))
dev_err(info->dev, "No syscfg phandle specified\n"); return dev_err_probe(dev, PTR_ERR(info->regmap), "No syscfg phandle specified\n");
return PTR_ERR(info->regmap);
}
info->data = of_match_node(st_pctl_of_match, np)->data; info->data = of_match_node(st_pctl_of_match, np)->data;
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq > 0) { if (irq > 0) {
res = platform_get_resource_byname(pdev, info->irqmux_base = devm_platform_ioremap_resource_byname(pdev, "irqmux");
IORESOURCE_MEM, "irqmux");
info->irqmux_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(info->irqmux_base)) if (IS_ERR(info->irqmux_base))
return PTR_ERR(info->irqmux_base); return PTR_ERR(info->irqmux_base);
irq_set_chained_handler_and_data(irq, st_gpio_irqmux_handler, irq_set_chained_handler_and_data(irq, st_gpio_irqmux_handler,
info); info);
} }
pctl_desc->npins = info->nbanks * ST_GPIO_PINS_PER_BANK; pctl_desc->npins = info->nbanks * ST_GPIO_PINS_PER_BANK;
pdesc = devm_kcalloc(&pdev->dev, pdesc = devm_kcalloc(dev, pctl_desc->npins, sizeof(*pdesc), GFP_KERNEL);
pctl_desc->npins, sizeof(*pdesc), GFP_KERNEL);
if (!pdesc) if (!pdesc)
return -ENOMEM; return -ENOMEM;
...@@ -1643,6 +1624,8 @@ static int st_pctl_probe_dt(struct platform_device *pdev, ...@@ -1643,6 +1624,8 @@ static int st_pctl_probe_dt(struct platform_device *pdev,
for_each_child_of_node(np, child) { for_each_child_of_node(np, child) {
if (of_property_read_bool(child, "gpio-controller")) { if (of_property_read_bool(child, "gpio-controller")) {
const char *bank_name = NULL; const char *bank_name = NULL;
char **pin_names;
ret = st_gpiolib_register_bank(info, bank, child); ret = st_gpiolib_register_bank(info, bank, child);
if (ret) { if (ret) {
of_node_put(child); of_node_put(child);
...@@ -1651,10 +1634,16 @@ static int st_pctl_probe_dt(struct platform_device *pdev, ...@@ -1651,10 +1634,16 @@ static int st_pctl_probe_dt(struct platform_device *pdev,
k = info->banks[bank].range.pin_base; k = info->banks[bank].range.pin_base;
bank_name = info->banks[bank].range.name; bank_name = info->banks[bank].range.name;
pin_names = devm_kasprintf_strarray(dev, bank_name, ST_GPIO_PINS_PER_BANK);
if (IS_ERR(pin_names)) {
of_node_put(child);
return PTR_ERR(pin_names);
}
for (j = 0; j < ST_GPIO_PINS_PER_BANK; j++, k++) { for (j = 0; j < ST_GPIO_PINS_PER_BANK; j++, k++) {
pdesc->number = k; pdesc->number = k;
pdesc->name = kasprintf(GFP_KERNEL, "%s[%d]", pdesc->name = pin_names[j];
bank_name, j);
pdesc++; pdesc++;
} }
st_parse_syscfgs(info, bank, child); st_parse_syscfgs(info, bank, child);
...@@ -1663,7 +1652,7 @@ static int st_pctl_probe_dt(struct platform_device *pdev, ...@@ -1663,7 +1652,7 @@ static int st_pctl_probe_dt(struct platform_device *pdev,
ret = st_pctl_parse_functions(child, info, ret = st_pctl_parse_functions(child, info,
i++, &grp_index); i++, &grp_index);
if (ret) { if (ret) {
dev_err(&pdev->dev, "No functions found.\n"); dev_err(dev, "No functions found.\n");
of_node_put(child); of_node_put(child);
return ret; return ret;
} }
...@@ -1675,24 +1664,25 @@ static int st_pctl_probe_dt(struct platform_device *pdev, ...@@ -1675,24 +1664,25 @@ static int st_pctl_probe_dt(struct platform_device *pdev,
static int st_pctl_probe(struct platform_device *pdev) static int st_pctl_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
struct st_pinctrl *info; struct st_pinctrl *info;
struct pinctrl_desc *pctl_desc; struct pinctrl_desc *pctl_desc;
int ret, i; int ret, i;
if (!pdev->dev.of_node) { if (!dev->of_node) {
dev_err(&pdev->dev, "device node not found.\n"); dev_err(dev, "device node not found.\n");
return -EINVAL; return -EINVAL;
} }
pctl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctl_desc), GFP_KERNEL); pctl_desc = devm_kzalloc(dev, sizeof(*pctl_desc), GFP_KERNEL);
if (!pctl_desc) if (!pctl_desc)
return -ENOMEM; return -ENOMEM;
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
if (!info) if (!info)
return -ENOMEM; return -ENOMEM;
info->dev = &pdev->dev; info->dev = dev;
platform_set_drvdata(pdev, info); platform_set_drvdata(pdev, info);
ret = st_pctl_probe_dt(pdev, pctl_desc, info); ret = st_pctl_probe_dt(pdev, pctl_desc, info);
if (ret) if (ret)
...@@ -1702,13 +1692,11 @@ static int st_pctl_probe(struct platform_device *pdev) ...@@ -1702,13 +1692,11 @@ static int st_pctl_probe(struct platform_device *pdev)
pctl_desc->pctlops = &st_pctlops; pctl_desc->pctlops = &st_pctlops;
pctl_desc->pmxops = &st_pmxops; pctl_desc->pmxops = &st_pmxops;
pctl_desc->confops = &st_confops; pctl_desc->confops = &st_confops;
pctl_desc->name = dev_name(&pdev->dev); pctl_desc->name = dev_name(dev);
info->pctl = devm_pinctrl_register(&pdev->dev, pctl_desc, info); info->pctl = devm_pinctrl_register(dev, pctl_desc, info);
if (IS_ERR(info->pctl)) { if (IS_ERR(info->pctl))
dev_err(&pdev->dev, "Failed pinctrl registration\n"); return dev_err_probe(dev, PTR_ERR(info->pctl), "Failed pinctrl registration\n");
return PTR_ERR(info->pctl);
}
for (i = 0; i < info->nbanks; i++) for (i = 0; i < info->nbanks; i++)
pinctrl_add_gpio_range(info->pctl, &info->banks[i].range); pinctrl_add_gpio_range(info->pctl, &info->banks[i].range);
......
...@@ -809,6 +809,7 @@ static int zynqmp_pinctrl_prepare_pin_desc(struct device *dev, ...@@ -809,6 +809,7 @@ static int zynqmp_pinctrl_prepare_pin_desc(struct device *dev,
unsigned int *npins) unsigned int *npins)
{ {
struct pinctrl_pin_desc *pins, *pin; struct pinctrl_pin_desc *pins, *pin;
char **pin_names;
int ret; int ret;
int i; int i;
...@@ -820,13 +821,14 @@ static int zynqmp_pinctrl_prepare_pin_desc(struct device *dev, ...@@ -820,13 +821,14 @@ static int zynqmp_pinctrl_prepare_pin_desc(struct device *dev,
if (!pins) if (!pins)
return -ENOMEM; return -ENOMEM;
pin_names = devm_kasprintf_strarray(dev, ZYNQMP_PIN_PREFIX, *npins);
if (IS_ERR(pin_names))
return PTR_ERR(pin_names);
for (i = 0; i < *npins; i++) { for (i = 0; i < *npins; i++) {
pin = &pins[i]; pin = &pins[i];
pin->number = i; pin->number = i;
pin->name = devm_kasprintf(dev, GFP_KERNEL, "%s%d", pin->name = pin_names[i];
ZYNQMP_PIN_PREFIX, i);
if (!pin->name)
return -ENOMEM;
} }
*zynqmp_pins = pins; *zynqmp_pins = pins;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <linux/string.h> #include <linux/string.h>
#include <linux/types.h> #include <linux/types.h>
struct device;
struct file; struct file;
struct task_struct; struct task_struct;
...@@ -100,6 +101,9 @@ char *kstrdup_quotable(const char *src, gfp_t gfp); ...@@ -100,6 +101,9 @@ char *kstrdup_quotable(const char *src, gfp_t gfp);
char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp); char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp);
char *kstrdup_quotable_file(struct file *file, gfp_t gfp); char *kstrdup_quotable_file(struct file *file, gfp_t gfp);
char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n);
void kfree_strarray(char **array, size_t n); void kfree_strarray(char **array, size_t n);
char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n);
#endif #endif
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/math64.h> #include <linux/math64.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/device.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/limits.h> #include <linux/limits.h>
...@@ -674,6 +675,39 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp) ...@@ -674,6 +675,39 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp)
} }
EXPORT_SYMBOL_GPL(kstrdup_quotable_file); EXPORT_SYMBOL_GPL(kstrdup_quotable_file);
/**
* kasprintf_strarray - allocate and fill array of sequential strings
* @gfp: flags for the slab allocator
* @prefix: prefix to be used
* @n: amount of lines to be allocated and filled
*
* Allocates and fills @n strings using pattern "%s-%zu", where prefix
* is provided by caller. The caller is responsible to free them with
* kfree_strarray() after use.
*
* Returns array of strings or NULL when memory can't be allocated.
*/
char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n)
{
char **names;
size_t i;
names = kcalloc(n + 1, sizeof(char *), gfp);
if (!names)
return NULL;
for (i = 0; i < n; i++) {
names[i] = kasprintf(gfp, "%s-%zu", prefix, i);
if (!names[i]) {
kfree_strarray(names, i);
return NULL;
}
}
return names;
}
EXPORT_SYMBOL_GPL(kasprintf_strarray);
/** /**
* kfree_strarray - free a number of dynamically allocated strings contained * kfree_strarray - free a number of dynamically allocated strings contained
* in an array and the array itself * in an array and the array itself
...@@ -697,6 +731,36 @@ void kfree_strarray(char **array, size_t n) ...@@ -697,6 +731,36 @@ void kfree_strarray(char **array, size_t n)
} }
EXPORT_SYMBOL_GPL(kfree_strarray); EXPORT_SYMBOL_GPL(kfree_strarray);
struct strarray {
char **array;
size_t n;
};
static void devm_kfree_strarray(struct device *dev, void *res)
{
struct strarray *array = res;
kfree_strarray(array->array, array->n);
}
char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n)
{
struct strarray *ptr;
ptr = devres_alloc(devm_kfree_strarray, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);
ptr->array = kasprintf_strarray(GFP_KERNEL, prefix, n);
if (!ptr->array) {
devres_free(ptr);
return ERR_PTR(-ENOMEM);
}
return ptr->array;
}
EXPORT_SYMBOL_GPL(devm_kasprintf_strarray);
/** /**
* strscpy_pad() - Copy a C-string into a sized buffer * strscpy_pad() - Copy a C-string into a sized buffer
* @dest: Where to copy the string to * @dest: Where to copy the string to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment