Skip to content

Commit 693c9ec

Browse files
andy-shevlinusw
authored andcommitted
pinctrl: nuvoton: Reduce use of OF-specific APIs
Some drivers are using device property APIs along with OF-specific ones. At the same time few of the latter can be converted to device property calls. Reduce use of OF-specific APIs in order to bring a bit more consistency into the drivers. Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/20250318105932.2090926-6-andriy.shevchenko@linux.intel.com Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent d52ecc6 commit 693c9ec

File tree

4 files changed

+21
-34
lines changed

4 files changed

+21
-34
lines changed

drivers/pinctrl/nuvoton/pinctrl-ma35.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ static int ma35_gpiolib_register(struct platform_device *pdev, struct ma35_pinct
519519
bank->irqtype = 0;
520520
bank->irqinten = 0;
521521
bank->chip.label = bank->name;
522-
bank->chip.of_gpio_n_cells = 2;
523522
bank->chip.parent = &pdev->dev;
524523
bank->chip.request = ma35_gpio_core_to_request;
525524
bank->chip.direction_input = ma35_gpio_core_direction_in;
@@ -976,9 +975,10 @@ static const struct pinconf_ops ma35_pinconf_ops = {
976975
.is_generic = true,
977976
};
978977

979-
static int ma35_pinctrl_parse_groups(struct device_node *np, struct group_desc *grp,
978+
static int ma35_pinctrl_parse_groups(struct fwnode_handle *fwnode, struct group_desc *grp,
980979
struct ma35_pinctrl *npctl, u32 index)
981980
{
981+
struct device_node *np = to_of_node(fwnode);
982982
struct ma35_pin_setting *pin;
983983
unsigned long *configs;
984984
unsigned int nconfigs;
@@ -990,7 +990,7 @@ static int ma35_pinctrl_parse_groups(struct device_node *np, struct group_desc *
990990
if (ret)
991991
return ret;
992992

993-
count = of_property_count_elems_of_size(np, "nuvoton,pins", sizeof(u32));
993+
count = fwnode_property_count_u32(fwnode, "nuvoton,pins");
994994
if (!count || count % 3)
995995
return -EINVAL;
996996

@@ -1000,7 +1000,7 @@ static int ma35_pinctrl_parse_groups(struct device_node *np, struct group_desc *
10001000

10011001
grp->grp.name = np->name;
10021002

1003-
ret = of_property_read_u32_array(np, "nuvoton,pins", elems, count);
1003+
ret = fwnode_property_read_u32_array(fwnode, "nuvoton,pins", elems, count);
10041004
if (ret)
10051005
return -EINVAL;
10061006
grp->grp.npins = count / 3;
@@ -1027,10 +1027,11 @@ static int ma35_pinctrl_parse_groups(struct device_node *np, struct group_desc *
10271027
return 0;
10281028
}
10291029

1030-
static int ma35_pinctrl_parse_functions(struct device_node *np, struct ma35_pinctrl *npctl,
1030+
static int ma35_pinctrl_parse_functions(struct fwnode_handle *fwnode, struct ma35_pinctrl *npctl,
10311031
u32 index)
10321032
{
1033-
struct device_node *child;
1033+
struct device_node *np = to_of_node(fwnode);
1034+
struct fwnode_handle *child;
10341035
struct pinfunction *func;
10351036
struct group_desc *grp;
10361037
static u32 grp_index;
@@ -1050,12 +1051,14 @@ static int ma35_pinctrl_parse_functions(struct device_node *np, struct ma35_pinc
10501051
if (!groups)
10511052
return -ENOMEM;
10521053

1053-
for_each_child_of_node(np, child) {
1054-
groups[i] = child->name;
1054+
fwnode_for_each_child_node(fwnode, child) {
1055+
struct device_node *node = to_of_node(child);
1056+
1057+
groups[i] = node->name;
10551058
grp = &npctl->groups[grp_index++];
10561059
ret = ma35_pinctrl_parse_groups(child, grp, npctl, i++);
10571060
if (ret) {
1058-
of_node_put(child);
1061+
fwnode_handle_put(child);
10591062
return ret;
10601063
}
10611064
}
@@ -1066,13 +1069,12 @@ static int ma35_pinctrl_parse_functions(struct device_node *np, struct ma35_pinc
10661069

10671070
static int ma35_pinctrl_probe_dt(struct platform_device *pdev, struct ma35_pinctrl *npctl)
10681071
{
1072+
struct device *dev = &pdev->dev;
10691073
struct fwnode_handle *child;
10701074
u32 idx = 0;
10711075
int ret;
10721076

1073-
device_for_each_child_node(&pdev->dev, child) {
1074-
if (fwnode_property_present(child, "gpio-controller"))
1075-
continue;
1077+
for_each_gpiochip_node(dev, child) {
10761078
npctl->nfunctions++;
10771079
npctl->ngroups += of_get_child_count(to_of_node(child));
10781080
}
@@ -1090,11 +1092,8 @@ static int ma35_pinctrl_probe_dt(struct platform_device *pdev, struct ma35_pinct
10901092
if (!npctl->groups)
10911093
return -ENOMEM;
10921094

1093-
device_for_each_child_node(&pdev->dev, child) {
1094-
if (fwnode_property_present(child, "gpio-controller"))
1095-
continue;
1096-
1097-
ret = ma35_pinctrl_parse_functions(to_of_node(child), npctl, idx++);
1095+
for_each_gpiochip_node(dev, child) {
1096+
ret = ma35_pinctrl_parse_functions(child, npctl, idx++);
10981097
if (ret) {
10991098
fwnode_handle_put(child);
11001099
dev_err(&pdev->dev, "failed to parse function\n");
@@ -1139,7 +1138,7 @@ int ma35_pinctrl_probe(struct platform_device *pdev, const struct ma35_pinctrl_s
11391138
npctl->info = info;
11401139
npctl->dev = &pdev->dev;
11411140

1142-
npctl->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "nuvoton,sys");
1141+
npctl->regmap = syscon_regmap_lookup_by_phandle(dev_of_node(dev), "nuvoton,sys");
11431142
if (IS_ERR(npctl->regmap))
11441143
return dev_err_probe(&pdev->dev, PTR_ERR(npctl->regmap),
11451144
"No syscfg phandle specified\n");

drivers/pinctrl/nuvoton/pinctrl-ma35d1.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <linux/io.h>
1010
#include <linux/mod_devicetable.h>
1111
#include <linux/module.h>
12-
#include <linux/of.h>
1312
#include <linux/platform_device.h>
1413
#include <linux/pm.h>
1514

drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
#include <linux/interrupt.h>
88
#include <linux/irq.h>
99
#include <linux/mfd/syscon.h>
10+
#include <linux/mod_devicetable.h>
1011
#include <linux/module.h>
11-
#include <linux/of.h>
12-
#include <linux/of_address.h>
13-
#include <linux/of_irq.h>
1412
#include <linux/platform_device.h>
1513
#include <linux/property.h>
1614
#include <linux/regmap.h>
@@ -1832,22 +1830,13 @@ static struct pinctrl_desc npcm7xx_pinctrl_desc = {
18321830
static int npcm7xx_gpio_of(struct npcm7xx_pinctrl *pctrl)
18331831
{
18341832
int ret = -ENXIO;
1835-
struct resource res;
18361833
struct device *dev = pctrl->dev;
18371834
struct fwnode_reference_args args;
18381835
struct fwnode_handle *child;
18391836
int id = 0;
18401837

18411838
for_each_gpiochip_node(dev, child) {
1842-
struct device_node *np = to_of_node(child);
1843-
1844-
ret = of_address_to_resource(np, 0, &res);
1845-
if (ret < 0) {
1846-
dev_err(dev, "Resource fail for GPIO bank %u\n", id);
1847-
return ret;
1848-
}
1849-
1850-
pctrl->gpio_bank[id].base = ioremap(res.start, resource_size(&res));
1839+
pctrl->gpio_bank[id].base = fwnode_iomap(child, 0);
18511840
if (!pctrl->gpio_bank[id].base)
18521841
return -EINVAL;
18531842

@@ -1869,7 +1858,7 @@ static int npcm7xx_gpio_of(struct npcm7xx_pinctrl *pctrl)
18691858
return ret;
18701859
}
18711860

1872-
ret = irq_of_parse_and_map(np, 0);
1861+
ret = fwnode_irq_get(child, 0);
18731862
if (!ret) {
18741863
dev_err(dev, "No IRQ for GPIO bank %u\n", id);
18751864
return -EINVAL;

drivers/pinctrl/nuvoton/pinctrl-npcm8xx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2421,7 +2421,7 @@ static int npcm8xx_pinctrl_probe(struct platform_device *pdev)
24212421
platform_set_drvdata(pdev, pctrl);
24222422

24232423
pctrl->gcr_regmap =
2424-
syscon_regmap_lookup_by_phandle(dev->of_node, "nuvoton,sysgcr");
2424+
syscon_regmap_lookup_by_phandle(dev_of_node(dev), "nuvoton,sysgcr");
24252425
if (IS_ERR(pctrl->gcr_regmap))
24262426
return dev_err_probe(dev, PTR_ERR(pctrl->gcr_regmap),
24272427
"Failed to find nuvoton,sysgcr property\n");

0 commit comments

Comments
 (0)