45595bddc92c8d620cdd7561ab0aa075b6c62bba
[openwrt/staging/chunkeey.git] /
1 From a49d784d5a8272d0f63c448fe8dc69e589db006e Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Tue, 18 Dec 2018 16:58:08 +0100
4 Subject: [PATCH] pinctrl: bcm: ns: support updated DT binding as syscon
5 subnode
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 Documentation has been recently updated specifying that pinctrl should
11 be subnode of the CRU "syscon". Support that by using parent node for
12 regmap and reading "offset" property from the DT.
13
14 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
15 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
16 ---
17 drivers/pinctrl/bcm/pinctrl-ns.c | 29 +++++++++++++++++++----------
18 1 file changed, 19 insertions(+), 10 deletions(-)
19
20 --- a/drivers/pinctrl/bcm/pinctrl-ns.c
21 +++ b/drivers/pinctrl/bcm/pinctrl-ns.c
22 @@ -5,6 +5,7 @@
23
24 #include <linux/err.h>
25 #include <linux/io.h>
26 +#include <linux/mfd/syscon.h>
27 #include <linux/module.h>
28 #include <linux/of.h>
29 #include <linux/of_device.h>
30 @@ -12,6 +13,7 @@
31 #include <linux/pinctrl/pinctrl.h>
32 #include <linux/pinctrl/pinmux.h>
33 #include <linux/platform_device.h>
34 +#include <linux/regmap.h>
35 #include <linux/slab.h>
36
37 #define FLAG_BCM4708 BIT(1)
38 @@ -22,7 +24,8 @@ struct ns_pinctrl {
39 struct device *dev;
40 unsigned int chipset_flag;
41 struct pinctrl_dev *pctldev;
42 - void __iomem *base;
43 + struct regmap *regmap;
44 + u32 offset;
45
46 struct pinctrl_desc pctldesc;
47 struct ns_pinctrl_group *groups;
48 @@ -229,9 +232,9 @@ static int ns_pinctrl_set_mux(struct pin
49 unset |= BIT(pin_number);
50 }
51
52 - tmp = readl(ns_pinctrl->base);
53 + regmap_read(ns_pinctrl->regmap, ns_pinctrl->offset, &tmp);
54 tmp &= ~unset;
55 - writel(tmp, ns_pinctrl->base);
56 + regmap_write(ns_pinctrl->regmap, ns_pinctrl->offset, tmp);
57
58 return 0;
59 }
60 @@ -263,13 +266,13 @@ static const struct of_device_id ns_pinc
61 static int ns_pinctrl_probe(struct platform_device *pdev)
62 {
63 struct device *dev = &pdev->dev;
64 + struct device_node *np = dev->of_node;
65 const struct of_device_id *of_id;
66 struct ns_pinctrl *ns_pinctrl;
67 struct pinctrl_desc *pctldesc;
68 struct pinctrl_pin_desc *pin;
69 struct ns_pinctrl_group *group;
70 struct ns_pinctrl_function *function;
71 - struct resource *res;
72 int i;
73
74 ns_pinctrl = devm_kzalloc(dev, sizeof(*ns_pinctrl), GFP_KERNEL);
75 @@ -287,12 +290,18 @@ static int ns_pinctrl_probe(struct platf
76 return -EINVAL;
77 ns_pinctrl->chipset_flag = (uintptr_t)of_id->data;
78
79 - res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
80 - "cru_gpio_control");
81 - ns_pinctrl->base = devm_ioremap_resource(dev, res);
82 - if (IS_ERR(ns_pinctrl->base)) {
83 - dev_err(dev, "Failed to map pinctrl regs\n");
84 - return PTR_ERR(ns_pinctrl->base);
85 + ns_pinctrl->regmap = syscon_node_to_regmap(of_get_parent(np));
86 + if (IS_ERR(ns_pinctrl->regmap)) {
87 + int err = PTR_ERR(ns_pinctrl->regmap);
88 +
89 + dev_err(dev, "Failed to map pinctrl regs: %d\n", err);
90 +
91 + return err;
92 + }
93 +
94 + if (of_property_read_u32(np, "offset", &ns_pinctrl->offset)) {
95 + dev_err(dev, "Failed to get register offset\n");
96 + return -ENOENT;
97 }
98
99 memcpy(pctldesc, &ns_pinctrl_desc, sizeof(*pctldesc));