Skip to content

Commit ad6e110

Browse files
John Crispinlinusw
authored andcommitted
pinctrl: enhance reporting of errors when loading from DT
There are a few places in the api where the code simply returns -EINVAL when it finds an error. An example is pinmux_map_to_setting() which now reports an error if we try to match a group with a function that it does not support. The reporting of errors in pinconf_check_ops and pinmux_check_ops now has the same style and is located inside the according functions and not the calling code. When the map is found in the DT but the default state can not be selected we get an error to know that the code at least tried. The patch also removes a stray word from one comment and a "->" from another for the sake of consistency. Finally we replace a few pr_err/debug() calls with dev_err/dbg(). Thanks go to Stephen Warren for reviewing the patch and enhancing the reporting inside pinmux_map_to_setting(). Signed-off-by: John Crispin <blogic@openwrt.org> Acked-by: Stephen Warren <swarren@wwwdotorg.org> Cc: linux-kernel@vger.kernel.org Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 02ae6da commit ad6e110

File tree

3 files changed

+49
-27
lines changed

3 files changed

+49
-27
lines changed

drivers/pinctrl/core.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,37 +1391,29 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
13911391
/* check core ops for sanity */
13921392
ret = pinctrl_check_ops(pctldev);
13931393
if (ret) {
1394-
pr_err("%s pinctrl ops lacks necessary functions\n",
1395-
pctldesc->name);
1394+
dev_err(dev, "pinctrl ops lacks necessary functions\n");
13961395
goto out_err;
13971396
}
13981397

13991398
/* If we're implementing pinmuxing, check the ops for sanity */
14001399
if (pctldesc->pmxops) {
14011400
ret = pinmux_check_ops(pctldev);
1402-
if (ret) {
1403-
pr_err("%s pinmux ops lacks necessary functions\n",
1404-
pctldesc->name);
1401+
if (ret)
14051402
goto out_err;
1406-
}
14071403
}
14081404

14091405
/* If we're implementing pinconfig, check the ops for sanity */
14101406
if (pctldesc->confops) {
14111407
ret = pinconf_check_ops(pctldev);
1412-
if (ret) {
1413-
pr_err("%s pin config ops lacks necessary functions\n",
1414-
pctldesc->name);
1408+
if (ret)
14151409
goto out_err;
1416-
}
14171410
}
14181411

14191412
/* Register all the pins */
1420-
pr_debug("try to register %d pins on %s...\n",
1421-
pctldesc->npins, pctldesc->name);
1413+
dev_dbg(dev, "try to register %d pins ...\n", pctldesc->npins);
14221414
ret = pinctrl_register_pins(pctldev, pctldesc->pins, pctldesc->npins);
14231415
if (ret) {
1424-
pr_err("error during pin registration\n");
1416+
dev_err(dev, "error during pin registration\n");
14251417
pinctrl_free_pindescs(pctldev, pctldesc->pins,
14261418
pctldesc->npins);
14271419
goto out_err;
@@ -1436,8 +1428,15 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
14361428
struct pinctrl_state *s =
14371429
pinctrl_lookup_state_locked(pctldev->p,
14381430
PINCTRL_STATE_DEFAULT);
1439-
if (!IS_ERR(s))
1440-
pinctrl_select_state_locked(pctldev->p, s);
1431+
if (IS_ERR(s)) {
1432+
dev_dbg(dev, "failed to lookup the default state\n");
1433+
} else {
1434+
ret = pinctrl_select_state_locked(pctldev->p, s);
1435+
if (ret) {
1436+
dev_err(dev,
1437+
"failed to select default state\n");
1438+
}
1439+
}
14411440
}
14421441

14431442
mutex_unlock(&pinctrl_mutex);

drivers/pinctrl/pinconf.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ int pinconf_check_ops(struct pinctrl_dev *pctldev)
2828
const struct pinconf_ops *ops = pctldev->desc->confops;
2929

3030
/* We must be able to read out pin status */
31-
if (!ops->pin_config_get && !ops->pin_config_group_get)
31+
if (!ops->pin_config_get && !ops->pin_config_group_get) {
32+
dev_err(pctldev->dev,
33+
"pinconf must be able to read out pin status\n");
3234
return -EINVAL;
35+
}
3336
/* We have to be able to config the pins in SOME way */
34-
if (!ops->pin_config_set && !ops->pin_config_group_set)
37+
if (!ops->pin_config_set && !ops->pin_config_group_set) {
38+
dev_err(pctldev->dev,
39+
"pinconf has to be able to set a pins config\n");
3540
return -EINVAL;
41+
}
3642
return 0;
3743
}
3844

drivers/pinctrl/pinmux.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ int pinmux_check_ops(struct pinctrl_dev *pctldev)
4242
!ops->get_function_name ||
4343
!ops->get_function_groups ||
4444
!ops->enable ||
45-
!ops->disable)
45+
!ops->disable) {
46+
dev_err(pctldev->dev, "pinmux ops lacks necessary functions\n");
4647
return -EINVAL;
47-
48+
}
4849
/* Check that all functions registered have names */
4950
nfuncs = ops->get_functions_count(pctldev);
5051
while (selector < nfuncs) {
@@ -143,7 +144,7 @@ static int pin_request(struct pinctrl_dev *pctldev,
143144
status = 0;
144145

145146
if (status) {
146-
dev_err(pctldev->dev, "->request on device %s failed for pin %d\n",
147+
dev_err(pctldev->dev, "request on device %s failed for pin %d\n",
147148
pctldev->desc->name, pin);
148149
module_put(pctldev->owner);
149150
}
@@ -330,17 +331,26 @@ int pinmux_map_to_setting(struct pinctrl_map const *map,
330331
}
331332

332333
ret = pinmux_func_name_to_selector(pctldev, map->data.mux.function);
333-
if (ret < 0)
334+
if (ret < 0) {
335+
dev_err(pctldev->dev, "invalid function %s in map table\n",
336+
map->data.mux.function);
334337
return ret;
338+
}
335339
setting->data.mux.func = ret;
336340

337341
ret = pmxops->get_function_groups(pctldev, setting->data.mux.func,
338342
&groups, &num_groups);
339-
if (ret < 0)
343+
if (ret < 0) {
344+
dev_err(pctldev->dev, "can't query groups for function %s\n",
345+
map->data.mux.function);
340346
return ret;
341-
if (!num_groups)
347+
}
348+
if (!num_groups) {
349+
dev_err(pctldev->dev,
350+
"function %s can't be selected on any group\n",
351+
map->data.mux.function);
342352
return -EINVAL;
343-
353+
}
344354
if (map->data.mux.group) {
345355
bool found = false;
346356
group = map->data.mux.group;
@@ -350,15 +360,22 @@ int pinmux_map_to_setting(struct pinctrl_map const *map,
350360
break;
351361
}
352362
}
353-
if (!found)
363+
if (!found) {
364+
dev_err(pctldev->dev,
365+
"invalid group \"%s\" for function \"%s\"\n",
366+
group, map->data.mux.function);
354367
return -EINVAL;
368+
}
355369
} else {
356370
group = groups[0];
357371
}
358372

359373
ret = pinctrl_get_group_selector(pctldev, group);
360-
if (ret < 0)
374+
if (ret < 0) {
375+
dev_err(pctldev->dev, "invalid group %s in map table\n",
376+
map->data.mux.group);
361377
return ret;
378+
}
362379
setting->data.mux.group = ret;
363380

364381
ret = pctlops->get_group_pins(pctldev, setting->data.mux.group, &pins,
@@ -375,7 +392,7 @@ int pinmux_map_to_setting(struct pinctrl_map const *map,
375392
ret = pin_request(pctldev, pins[i], map->dev_name, NULL);
376393
if (ret) {
377394
dev_err(pctldev->dev,
378-
"could not get request pin %d on device %s\n",
395+
"could not request pin %d on device %s\n",
379396
pins[i], pinctrl_dev_get_name(pctldev));
380397
/* On error release all taken pins */
381398
i--; /* this pin just failed */

0 commit comments

Comments
 (0)