sunxi: Backport patches needed for A64
[openwrt/staging/lynxis.git] / target / linux / sunxi / patches-4.9 / 0034-pinctrl-sunxi-Deal-with-configless-pins.patch
1 From e11dee2e98f8abc99ad5336796576a827853ccfa Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime.ripard@free-electrons.com>
3 Date: Thu, 20 Oct 2016 15:49:02 +0200
4 Subject: pinctrl: sunxi: Deal with configless pins
5
6 Even though the our binding had the assumption that the allwinner,pull and
7 allwinner,drive properties were optional, the code never took that into
8 account.
9
10 Fix that.
11
12 Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
13 Acked-by: Chen-Yu Tsai <wens@csie.org>
14 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
15 ---
16 drivers/pinctrl/sunxi/pinctrl-sunxi.c | 51 +++++++++++++++++++++++++----------
17 1 file changed, 37 insertions(+), 14 deletions(-)
18
19 --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
20 +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
21 @@ -261,20 +261,29 @@ static unsigned long *sunxi_pctrl_build_
22 {
23 unsigned long *pinconfig;
24 unsigned int configlen = 0, idx = 0;
25 + int ret;
26
27 if (sunxi_pctrl_has_drive_prop(node))
28 configlen++;
29 if (sunxi_pctrl_has_bias_prop(node))
30 configlen++;
31
32 + /*
33 + * If we don't have any configuration, bail out
34 + */
35 + if (!configlen)
36 + return NULL;
37 +
38 pinconfig = kzalloc(configlen * sizeof(*pinconfig), GFP_KERNEL);
39 if (!pinconfig)
40 - return NULL;
41 + return ERR_PTR(-ENOMEM);
42
43 if (sunxi_pctrl_has_drive_prop(node)) {
44 int drive = sunxi_pctrl_parse_drive_prop(node);
45 - if (drive < 0)
46 + if (drive < 0) {
47 + ret = drive;
48 goto err_free;
49 + }
50
51 pinconfig[idx++] = pinconf_to_config_packed(PIN_CONFIG_DRIVE_STRENGTH,
52 drive);
53 @@ -282,8 +291,10 @@ static unsigned long *sunxi_pctrl_build_
54
55 if (sunxi_pctrl_has_bias_prop(node)) {
56 int pull = sunxi_pctrl_parse_bias_prop(node);
57 - if (pull < 0)
58 + if (pull < 0) {
59 + ret = pull;
60 goto err_free;
61 + }
62
63 pinconfig[idx++] = pinconf_to_config_packed(pull, 0);
64 }
65 @@ -294,7 +305,7 @@ static unsigned long *sunxi_pctrl_build_
66
67 err_free:
68 kfree(pinconfig);
69 - return NULL;
70 + return ERR_PTR(ret);
71 }
72
73 static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
74 @@ -328,7 +339,10 @@ static int sunxi_pctrl_dt_node_to_map(st
75
76 /*
77 * We have two maps for each pin: one for the function, one
78 - * for the configuration (bias, strength, etc)
79 + * for the configuration (bias, strength, etc).
80 + *
81 + * We might be slightly overshooting, since we might not have
82 + * any configuration.
83 */
84 nmaps = npins * 2;
85 *map = kmalloc(nmaps * sizeof(struct pinctrl_map), GFP_KERNEL);
86 @@ -336,8 +350,8 @@ static int sunxi_pctrl_dt_node_to_map(st
87 return -ENOMEM;
88
89 pinconfig = sunxi_pctrl_build_pin_config(node, &configlen);
90 - if (!pinconfig) {
91 - ret = -EINVAL;
92 + if (IS_ERR(pinconfig)) {
93 + ret = PTR_ERR(pinconfig);
94 goto err_free_map;
95 }
96
97 @@ -364,15 +378,24 @@ static int sunxi_pctrl_dt_node_to_map(st
98
99 i++;
100
101 - (*map)[i].type = PIN_MAP_TYPE_CONFIGS_GROUP;
102 - (*map)[i].data.configs.group_or_pin = group;
103 - (*map)[i].data.configs.configs = pinconfig;
104 - (*map)[i].data.configs.num_configs = configlen;
105 -
106 - i++;
107 + if (pinconfig) {
108 + (*map)[i].type = PIN_MAP_TYPE_CONFIGS_GROUP;
109 + (*map)[i].data.configs.group_or_pin = group;
110 + (*map)[i].data.configs.configs = pinconfig;
111 + (*map)[i].data.configs.num_configs = configlen;
112 + i++;
113 + }
114 }
115
116 - *num_maps = nmaps;
117 + *num_maps = i;
118 +
119 + /*
120 + * We know have the number of maps we need, we can resize our
121 + * map array
122 + */
123 + *map = krealloc(*map, i * sizeof(struct pinctrl_map), GFP_KERNEL);
124 + if (!map)
125 + return -ENOMEM;
126
127 return 0;
128