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
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
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>
16 drivers/pinctrl/sunxi/pinctrl-sunxi.c | 51 +++++++++++++++++++++++++----------
17 1 file changed, 37 insertions(+), 14 deletions(-)
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_
23 unsigned long *pinconfig;
24 unsigned int configlen = 0, idx = 0;
27 if (sunxi_pctrl_has_drive_prop(node))
29 if (sunxi_pctrl_has_bias_prop(node))
33 + * If we don't have any configuration, bail out
38 pinconfig = kzalloc(configlen * sizeof(*pinconfig), GFP_KERNEL);
41 + return ERR_PTR(-ENOMEM);
43 if (sunxi_pctrl_has_drive_prop(node)) {
44 int drive = sunxi_pctrl_parse_drive_prop(node);
51 pinconfig[idx++] = pinconf_to_config_packed(PIN_CONFIG_DRIVE_STRENGTH,
53 @@ -282,8 +291,10 @@ static unsigned long *sunxi_pctrl_build_
55 if (sunxi_pctrl_has_bias_prop(node)) {
56 int pull = sunxi_pctrl_parse_bias_prop(node);
63 pinconfig[idx++] = pinconf_to_config_packed(pull, 0);
65 @@ -294,7 +305,7 @@ static unsigned long *sunxi_pctrl_build_
70 + return ERR_PTR(ret);
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
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).
81 + * We might be slightly overshooting, since we might not have
82 + * any configuration.
85 *map = kmalloc(nmaps * sizeof(struct pinctrl_map), GFP_KERNEL);
86 @@ -336,8 +350,8 @@ static int sunxi_pctrl_dt_node_to_map(st
89 pinconfig = sunxi_pctrl_build_pin_config(node, &configlen);
92 + if (IS_ERR(pinconfig)) {
93 + ret = PTR_ERR(pinconfig);
97 @@ -364,15 +378,24 @@ static int sunxi_pctrl_dt_node_to_map(st
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;
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;
120 + * We know have the number of maps we need, we can resize our
123 + *map = krealloc(*map, i * sizeof(struct pinctrl_map), GFP_KERNEL);