Skip to content

Commit 03b054e

Browse files
shermanyinLinus Walleij
authored andcommitted
pinctrl: Pass all configs to driver on pin_config_set()
When setting pin configuration in the pinctrl framework, pin_config_set() or pin_config_group_set() is called in a loop to set one configuration at a time for the specified pin or group. This patch 1) removes the loop and 2) changes the API to pass the whole pin config array to the driver. It is now up to the driver to loop through the configs. This allows the driver to potentially combine configs and reduce the number of writes to pin config registers. All c files changed have been build-tested to verify the change compiles and that the corresponding .o is successfully generated. Signed-off-by: Sherman Yin <syin@broadcom.com> Reviewed-by: Christian Daudt <csd@broadcom.com> Reviewed-by: Matt Porter <matt.porter@linaro.org> Tested-by: Stephen Warren <swarren@nvidia.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent f5ba9c5 commit 03b054e

24 files changed

Lines changed: 952 additions & 726 deletions

‎drivers/pinctrl/mvebu/pinctrl-mvebu.c‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,27 @@ static int mvebu_pinconf_group_get(struct pinctrl_dev *pctldev,
191191
}
192192

193193
static int mvebu_pinconf_group_set(struct pinctrl_dev *pctldev,
194-
unsigned gid, unsigned long config)
194+
unsigned gid, unsigned long *configs,
195+
unsigned num_configs)
195196
{
196197
struct mvebu_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
197198
struct mvebu_pinctrl_group *grp = &pctl->groups[gid];
199+
int i, ret;
198200

199201
if (!grp->ctrl)
200202
return -EINVAL;
201203

202-
if (grp->ctrl->mpp_set)
203-
return grp->ctrl->mpp_set(grp->ctrl, config);
204+
for (i = 0; i < num_configs; i++) {
205+
if (grp->ctrl->mpp_set)
206+
ret = grp->ctrl->mpp_set(grp->ctrl, configs[i]);
207+
else
208+
ret = mvebu_common_mpp_set(pctl, grp, configs[i]);
204209

205-
return mvebu_common_mpp_set(pctl, grp, config);
210+
if (ret)
211+
return ret;
212+
} /* for each config */
213+
214+
return 0;
206215
}
207216

208217
static void mvebu_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
@@ -303,6 +312,7 @@ static int mvebu_pinmux_enable(struct pinctrl_dev *pctldev, unsigned fid,
303312
struct mvebu_pinctrl_group *grp = &pctl->groups[gid];
304313
struct mvebu_mpp_ctrl_setting *setting;
305314
int ret;
315+
unsigned long config;
306316

307317
setting = mvebu_pinctrl_find_setting_by_name(pctl, grp,
308318
func->name);
@@ -313,7 +323,8 @@ static int mvebu_pinmux_enable(struct pinctrl_dev *pctldev, unsigned fid,
313323
return -EINVAL;
314324
}
315325

316-
ret = mvebu_pinconf_group_set(pctldev, grp->gid, setting->val);
326+
config = setting->val;
327+
ret = mvebu_pinconf_group_set(pctldev, grp->gid, &config, 1);
317328
if (ret) {
318329
dev_err(pctl->dev, "cannot set group %s to %s\n",
319330
func->groups[gid], func->name);
@@ -329,6 +340,7 @@ static int mvebu_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev,
329340
struct mvebu_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
330341
struct mvebu_pinctrl_group *grp;
331342
struct mvebu_mpp_ctrl_setting *setting;
343+
unsigned long config;
332344

333345
grp = mvebu_pinctrl_find_group_by_pid(pctl, offset);
334346
if (!grp)
@@ -341,7 +353,9 @@ static int mvebu_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev,
341353
if (!setting)
342354
return -ENOTSUPP;
343355

344-
return mvebu_pinconf_group_set(pctldev, grp->gid, setting->val);
356+
config = setting->val;
357+
358+
return mvebu_pinconf_group_set(pctldev, grp->gid, &config, 1);
345359
}
346360

347361
static int mvebu_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,

‎drivers/pinctrl/pinconf.c‎

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ int pinconf_apply_setting(struct pinctrl_setting const *setting)
158158
{
159159
struct pinctrl_dev *pctldev = setting->pctldev;
160160
const struct pinconf_ops *ops = pctldev->desc->confops;
161-
int i, ret;
161+
int ret;
162162

163163
if (!ops) {
164164
dev_err(pctldev->dev, "missing confops\n");
@@ -171,17 +171,15 @@ int pinconf_apply_setting(struct pinctrl_setting const *setting)
171171
dev_err(pctldev->dev, "missing pin_config_set op\n");
172172
return -EINVAL;
173173
}
174-
for (i = 0; i < setting->data.configs.num_configs; i++) {
175-
ret = ops->pin_config_set(pctldev,
176-
setting->data.configs.group_or_pin,
177-
setting->data.configs.configs[i]);
178-
if (ret < 0) {
179-
dev_err(pctldev->dev,
180-
"pin_config_set op failed for pin %d config %08lx\n",
181-
setting->data.configs.group_or_pin,
182-
setting->data.configs.configs[i]);
183-
return ret;
184-
}
174+
ret = ops->pin_config_set(pctldev,
175+
setting->data.configs.group_or_pin,
176+
setting->data.configs.configs,
177+
setting->data.configs.num_configs);
178+
if (ret < 0) {
179+
dev_err(pctldev->dev,
180+
"pin_config_set op failed for pin %d\n",
181+
setting->data.configs.group_or_pin);
182+
return ret;
185183
}
186184
break;
187185
case PIN_MAP_TYPE_CONFIGS_GROUP:
@@ -190,17 +188,15 @@ int pinconf_apply_setting(struct pinctrl_setting const *setting)
190188
"missing pin_config_group_set op\n");
191189
return -EINVAL;
192190
}
193-
for (i = 0; i < setting->data.configs.num_configs; i++) {
194-
ret = ops->pin_config_group_set(pctldev,
195-
setting->data.configs.group_or_pin,
196-
setting->data.configs.configs[i]);
197-
if (ret < 0) {
198-
dev_err(pctldev->dev,
199-
"pin_config_group_set op failed for group %d config %08lx\n",
200-
setting->data.configs.group_or_pin,
201-
setting->data.configs.configs[i]);
202-
return ret;
203-
}
191+
ret = ops->pin_config_group_set(pctldev,
192+
setting->data.configs.group_or_pin,
193+
setting->data.configs.configs,
194+
setting->data.configs.num_configs);
195+
if (ret < 0) {
196+
dev_err(pctldev->dev,
197+
"pin_config_group_set op failed for group %d\n",
198+
setting->data.configs.group_or_pin);
199+
return ret;
204200
}
205201
break;
206202
default:

‎drivers/pinctrl/pinctrl-abx500.c‎

Lines changed: 102 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,98 +1041,115 @@ static int abx500_pin_config_get(struct pinctrl_dev *pctldev,
10411041

10421042
static int abx500_pin_config_set(struct pinctrl_dev *pctldev,
10431043
unsigned pin,
1044-
unsigned long config)
1044+
unsigned long *configs,
1045+
unsigned num_configs)
10451046
{
10461047
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
10471048
struct gpio_chip *chip = &pct->chip;
10481049
unsigned offset;
10491050
int ret = -EINVAL;
1050-
enum pin_config_param param = pinconf_to_config_param(config);
1051-
enum pin_config_param argument = pinconf_to_config_argument(config);
1052-
1053-
dev_dbg(chip->dev, "pin %d [%#lx]: %s %s\n",
1054-
pin, config, (param == PIN_CONFIG_OUTPUT) ? "output " : "input",
1055-
(param == PIN_CONFIG_OUTPUT) ? (argument ? "high" : "low") :
1056-
(argument ? "pull up" : "pull down"));
1057-
1058-
/* on ABx500, there is no GPIO0, so adjust the offset */
1059-
offset = pin - 1;
1060-
1061-
switch (param) {
1062-
case PIN_CONFIG_BIAS_DISABLE:
1063-
ret = abx500_gpio_direction_input(chip, offset);
1064-
if (ret < 0)
1065-
goto out;
1066-
/*
1067-
* Some chips only support pull down, while some actually
1068-
* support both pull up and pull down. Such chips have
1069-
* a "pullud" range specified for the pins that support
1070-
* both features. If the pin is not within that range, we
1071-
* fall back to the old bit set that only support pull down.
1072-
*/
1073-
if (abx500_pullud_supported(chip, pin))
1074-
ret = abx500_set_pull_updown(pct,
1075-
pin,
1076-
ABX500_GPIO_PULL_NONE);
1077-
else
1078-
/* Chip only supports pull down */
1079-
ret = abx500_gpio_set_bits(chip, AB8500_GPIO_PUD1_REG,
1080-
offset, ABX500_GPIO_PULL_NONE);
1081-
break;
1082-
1083-
case PIN_CONFIG_BIAS_PULL_DOWN:
1084-
ret = abx500_gpio_direction_input(chip, offset);
1085-
if (ret < 0)
1086-
goto out;
1087-
/*
1088-
* if argument = 1 set the pull down
1089-
* else clear the pull down
1090-
* Some chips only support pull down, while some actually
1091-
* support both pull up and pull down. Such chips have
1092-
* a "pullud" range specified for the pins that support
1093-
* both features. If the pin is not within that range, we
1094-
* fall back to the old bit set that only support pull down.
1095-
*/
1096-
if (abx500_pullud_supported(chip, pin))
1097-
ret = abx500_set_pull_updown(pct,
1098-
pin,
1099-
argument ? ABX500_GPIO_PULL_DOWN : ABX500_GPIO_PULL_NONE);
1100-
else
1101-
/* Chip only supports pull down */
1102-
ret = abx500_gpio_set_bits(chip, AB8500_GPIO_PUD1_REG,
1103-
offset,
1104-
argument ? ABX500_GPIO_PULL_DOWN : ABX500_GPIO_PULL_NONE);
1105-
break;
1106-
1107-
case PIN_CONFIG_BIAS_PULL_UP:
1108-
ret = abx500_gpio_direction_input(chip, offset);
1109-
if (ret < 0)
1110-
goto out;
1111-
/*
1112-
* if argument = 1 set the pull up
1113-
* else clear the pull up
1114-
*/
1115-
ret = abx500_gpio_direction_input(chip, offset);
1116-
/*
1117-
* Some chips only support pull down, while some actually
1118-
* support both pull up and pull down. Such chips have
1119-
* a "pullud" range specified for the pins that support
1120-
* both features. If the pin is not within that range, do
1121-
* nothing
1122-
*/
1123-
if (abx500_pullud_supported(chip, pin))
1124-
ret = abx500_set_pull_updown(pct,
1125-
pin,
1126-
argument ? ABX500_GPIO_PULL_UP : ABX500_GPIO_PULL_NONE);
1127-
break;
1051+
int i;
1052+
enum pin_config_param param;
1053+
enum pin_config_param argument;
1054+
1055+
for (i = 0; i < num_configs; i++) {
1056+
param = pinconf_to_config_param(configs[i]);
1057+
argument = pinconf_to_config_argument(configs[i]);
1058+
1059+
dev_dbg(chip->dev, "pin %d [%#lx]: %s %s\n",
1060+
pin, configs[i],
1061+
(param == PIN_CONFIG_OUTPUT) ? "output " : "input",
1062+
(param == PIN_CONFIG_OUTPUT) ?
1063+
(argument ? "high" : "low") :
1064+
(argument ? "pull up" : "pull down"));
1065+
1066+
/* on ABx500, there is no GPIO0, so adjust the offset */
1067+
offset = pin - 1;
1068+
1069+
switch (param) {
1070+
case PIN_CONFIG_BIAS_DISABLE:
1071+
ret = abx500_gpio_direction_input(chip, offset);
1072+
if (ret < 0)
1073+
goto out;
1074+
/*
1075+
* Some chips only support pull down, while some
1076+
* actually support both pull up and pull down. Such
1077+
* chips have a "pullud" range specified for the pins
1078+
* that support both features. If the pin is not
1079+
* within that range, we fall back to the old bit set
1080+
* that only support pull down.
1081+
*/
1082+
if (abx500_pullud_supported(chip, pin))
1083+
ret = abx500_set_pull_updown(pct,
1084+
pin,
1085+
ABX500_GPIO_PULL_NONE);
1086+
else
1087+
/* Chip only supports pull down */
1088+
ret = abx500_gpio_set_bits(chip,
1089+
AB8500_GPIO_PUD1_REG, offset,
1090+
ABX500_GPIO_PULL_NONE);
1091+
break;
11281092

1129-
case PIN_CONFIG_OUTPUT:
1130-
ret = abx500_gpio_direction_output(chip, offset, argument);
1131-
break;
1093+
case PIN_CONFIG_BIAS_PULL_DOWN:
1094+
ret = abx500_gpio_direction_input(chip, offset);
1095+
if (ret < 0)
1096+
goto out;
1097+
/*
1098+
* if argument = 1 set the pull down
1099+
* else clear the pull down
1100+
* Some chips only support pull down, while some
1101+
* actually support both pull up and pull down. Such
1102+
* chips have a "pullud" range specified for the pins
1103+
* that support both features. If the pin is not
1104+
* within that range, we fall back to the old bit set
1105+
* that only support pull down.
1106+
*/
1107+
if (abx500_pullud_supported(chip, pin))
1108+
ret = abx500_set_pull_updown(pct,
1109+
pin,
1110+
argument ? ABX500_GPIO_PULL_DOWN :
1111+
ABX500_GPIO_PULL_NONE);
1112+
else
1113+
/* Chip only supports pull down */
1114+
ret = abx500_gpio_set_bits(chip,
1115+
AB8500_GPIO_PUD1_REG,
1116+
offset,
1117+
argument ? ABX500_GPIO_PULL_DOWN :
1118+
ABX500_GPIO_PULL_NONE);
1119+
break;
11321120

1133-
default:
1134-
dev_err(chip->dev, "illegal configuration requested\n");
1135-
}
1121+
case PIN_CONFIG_BIAS_PULL_UP:
1122+
ret = abx500_gpio_direction_input(chip, offset);
1123+
if (ret < 0)
1124+
goto out;
1125+
/*
1126+
* if argument = 1 set the pull up
1127+
* else clear the pull up
1128+
*/
1129+
ret = abx500_gpio_direction_input(chip, offset);
1130+
/*
1131+
* Some chips only support pull down, while some
1132+
* actually support both pull up and pull down. Such
1133+
* chips have a "pullud" range specified for the pins
1134+
* that support both features. If the pin is not
1135+
* within that range, do nothing
1136+
*/
1137+
if (abx500_pullud_supported(chip, pin))
1138+
ret = abx500_set_pull_updown(pct,
1139+
pin,
1140+
argument ? ABX500_GPIO_PULL_UP :
1141+
ABX500_GPIO_PULL_NONE);
1142+
break;
1143+
1144+
case PIN_CONFIG_OUTPUT:
1145+
ret = abx500_gpio_direction_output(chip, offset,
1146+
argument);
1147+
break;
1148+
1149+
default:
1150+
dev_err(chip->dev, "illegal configuration requested\n");
1151+
}
1152+
} /* for each config */
11361153
out:
11371154
if (ret < 0)
11381155
dev_err(pct->dev, "%s failed (%d)\n", __func__, ret);

‎drivers/pinctrl/pinctrl-at91.c‎

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -736,30 +736,40 @@ static int at91_pinconf_get(struct pinctrl_dev *pctldev,
736736
}
737737

738738
static int at91_pinconf_set(struct pinctrl_dev *pctldev,
739-
unsigned pin_id, unsigned long config)
739+
unsigned pin_id, unsigned long *configs,
740+
unsigned num_configs)
740741
{
741742
struct at91_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
742743
unsigned mask;
743744
void __iomem *pio;
744-
745-
dev_dbg(info->dev, "%s:%d, pin_id=%d, config=0x%lx", __func__, __LINE__, pin_id, config);
746-
pio = pin_to_controller(info, pin_to_bank(pin_id));
747-
mask = pin_to_mask(pin_id % MAX_NB_GPIO_PER_BANK);
748-
749-
if (config & PULL_UP && config & PULL_DOWN)
750-
return -EINVAL;
751-
752-
at91_mux_set_pullup(pio, mask, config & PULL_UP);
753-
at91_mux_set_multidrive(pio, mask, config & MULTI_DRIVE);
754-
if (info->ops->set_deglitch)
755-
info->ops->set_deglitch(pio, mask, config & DEGLITCH);
756-
if (info->ops->set_debounce)
757-
info->ops->set_debounce(pio, mask, config & DEBOUNCE,
745+
int i;
746+
unsigned long config;
747+
748+
for (i = 0; i < num_configs; i++) {
749+
config = configs[i];
750+
751+
dev_dbg(info->dev,
752+
"%s:%d, pin_id=%d, config=0x%lx",
753+
__func__, __LINE__, pin_id, config);
754+
pio = pin_to_controller(info, pin_to_bank(pin_id));
755+
mask = pin_to_mask(pin_id % MAX_NB_GPIO_PER_BANK);
756+
757+
if (config & PULL_UP && config & PULL_DOWN)
758+
return -EINVAL;
759+
760+
at91_mux_set_pullup(pio, mask, config & PULL_UP);
761+
at91_mux_set_multidrive(pio, mask, config & MULTI_DRIVE);
762+
if (info->ops->set_deglitch)
763+
info->ops->set_deglitch(pio, mask, config & DEGLITCH);
764+
if (info->ops->set_debounce)
765+
info->ops->set_debounce(pio, mask, config & DEBOUNCE,
758766
(config & DEBOUNCE_VAL) >> DEBOUNCE_VAL_SHIFT);
759-
if (info->ops->set_pulldown)
760-
info->ops->set_pulldown(pio, mask, config & PULL_DOWN);
761-
if (info->ops->disable_schmitt_trig && config & DIS_SCHMIT)
762-
info->ops->disable_schmitt_trig(pio, mask);
767+
if (info->ops->set_pulldown)
768+
info->ops->set_pulldown(pio, mask, config & PULL_DOWN);
769+
if (info->ops->disable_schmitt_trig && config & DIS_SCHMIT)
770+
info->ops->disable_schmitt_trig(pio, mask);
771+
772+
} /* for each config */
763773

764774
return 0;
765775
}

0 commit comments

Comments
 (0)