diff options
author | Patrice Chotard <patrice.chotard@st.com> | 2013-06-24 08:41:46 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2013-06-24 09:20:32 -0400 |
commit | 9be580afe4a746818223844b3c2cc97ed7c5c11d (patch) | |
tree | 077e7d48d582636bb22065f4804c2e9751883b98 /drivers/pinctrl/pinctrl-abx500.c | |
parent | acd260b0aa5b8a4503252450afbf575b08009c85 (diff) |
pinctrl: abx500: rework error path
At several places, return value was not tested
and error output was missing.
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/pinctrl-abx500.c')
-rw-r--r-- | drivers/pinctrl/pinctrl-abx500.c | 114 |
1 files changed, 87 insertions, 27 deletions
diff --git a/drivers/pinctrl/pinctrl-abx500.c b/drivers/pinctrl/pinctrl-abx500.c index f0e3f28022a5..1d3f988c2c8b 100644 --- a/drivers/pinctrl/pinctrl-abx500.c +++ b/drivers/pinctrl/pinctrl-abx500.c | |||
@@ -134,8 +134,8 @@ static int abx500_gpio_get_bit(struct gpio_chip *chip, u8 reg, | |||
134 | 134 | ||
135 | if (ret < 0) | 135 | if (ret < 0) |
136 | dev_err(pct->dev, | 136 | dev_err(pct->dev, |
137 | "%s read reg =%x, offset=%x failed\n", | 137 | "%s read reg =%x, offset=%x failed (%d)\n", |
138 | __func__, reg, offset); | 138 | __func__, reg, offset, ret); |
139 | 139 | ||
140 | return ret; | 140 | return ret; |
141 | } | 141 | } |
@@ -151,7 +151,8 @@ static int abx500_gpio_set_bits(struct gpio_chip *chip, u8 reg, | |||
151 | ret = abx500_mask_and_set_register_interruptible(pct->dev, | 151 | ret = abx500_mask_and_set_register_interruptible(pct->dev, |
152 | AB8500_MISC, reg, BIT(pos), val << pos); | 152 | AB8500_MISC, reg, BIT(pos), val << pos); |
153 | if (ret < 0) | 153 | if (ret < 0) |
154 | dev_err(pct->dev, "%s write failed\n", __func__); | 154 | dev_err(pct->dev, "%s write reg, %x offset %x failed (%d)\n", |
155 | __func__, reg, offset, ret); | ||
155 | 156 | ||
156 | return ret; | 157 | return ret; |
157 | } | 158 | } |
@@ -171,10 +172,8 @@ static int abx500_gpio_get(struct gpio_chip *chip, unsigned offset) | |||
171 | 172 | ||
172 | ret = abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG, | 173 | ret = abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG, |
173 | gpio_offset, &is_out); | 174 | gpio_offset, &is_out); |
174 | if (ret < 0) { | 175 | if (ret < 0) |
175 | dev_err(pct->dev, "%s failed\n", __func__); | 176 | goto out; |
176 | return ret; | ||
177 | } | ||
178 | 177 | ||
179 | if (is_out) | 178 | if (is_out) |
180 | ret = abx500_gpio_get_bit(chip, AB8500_GPIO_OUT1_REG, | 179 | ret = abx500_gpio_get_bit(chip, AB8500_GPIO_OUT1_REG, |
@@ -182,8 +181,9 @@ static int abx500_gpio_get(struct gpio_chip *chip, unsigned offset) | |||
182 | else | 181 | else |
183 | ret = abx500_gpio_get_bit(chip, AB8500_GPIO_IN1_REG, | 182 | ret = abx500_gpio_get_bit(chip, AB8500_GPIO_IN1_REG, |
184 | gpio_offset, &bit); | 183 | gpio_offset, &bit); |
184 | out: | ||
185 | if (ret < 0) { | 185 | if (ret < 0) { |
186 | dev_err(pct->dev, "%s failed\n", __func__); | 186 | dev_err(pct->dev, "%s failed (%d)\n", __func__, ret); |
187 | return ret; | 187 | return ret; |
188 | } | 188 | } |
189 | 189 | ||
@@ -197,7 +197,7 @@ static void abx500_gpio_set(struct gpio_chip *chip, unsigned offset, int val) | |||
197 | 197 | ||
198 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_OUT1_REG, offset, val); | 198 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_OUT1_REG, offset, val); |
199 | if (ret < 0) | 199 | if (ret < 0) |
200 | dev_err(pct->dev, "%s write failed\n", __func__); | 200 | dev_err(pct->dev, "%s write failed (%d)\n", __func__, ret); |
201 | } | 201 | } |
202 | 202 | ||
203 | static int abx500_get_pull_updown(struct abx500_pinctrl *pct, int offset, | 203 | static int abx500_get_pull_updown(struct abx500_pinctrl *pct, int offset, |
@@ -294,7 +294,7 @@ static int abx500_gpio_direction_output(struct gpio_chip *chip, | |||
294 | offset, | 294 | offset, |
295 | ABX500_GPIO_OUTPUT); | 295 | ABX500_GPIO_OUTPUT); |
296 | if (ret < 0) | 296 | if (ret < 0) |
297 | return ret; | 297 | goto out; |
298 | 298 | ||
299 | /* disable pull down */ | 299 | /* disable pull down */ |
300 | ret = abx500_gpio_set_bits(chip, | 300 | ret = abx500_gpio_set_bits(chip, |
@@ -302,7 +302,7 @@ static int abx500_gpio_direction_output(struct gpio_chip *chip, | |||
302 | offset, | 302 | offset, |
303 | ABX500_GPIO_PULL_NONE); | 303 | ABX500_GPIO_PULL_NONE); |
304 | if (ret < 0) | 304 | if (ret < 0) |
305 | return ret; | 305 | goto out; |
306 | 306 | ||
307 | /* if supported, disable both pull down and pull up */ | 307 | /* if supported, disable both pull down and pull up */ |
308 | gpio = offset + 1; | 308 | gpio = offset + 1; |
@@ -310,8 +310,11 @@ static int abx500_gpio_direction_output(struct gpio_chip *chip, | |||
310 | ret = abx500_set_pull_updown(pct, | 310 | ret = abx500_set_pull_updown(pct, |
311 | gpio, | 311 | gpio, |
312 | ABX500_GPIO_PULL_NONE); | 312 | ABX500_GPIO_PULL_NONE); |
313 | if (ret < 0) | 313 | } |
314 | return ret; | 314 | out: |
315 | if (ret < 0) { | ||
316 | dev_err(pct->dev, "%s failed (%d)\n", __func__, ret); | ||
317 | return ret; | ||
315 | } | 318 | } |
316 | 319 | ||
317 | /* set the output as 1 or 0 */ | 320 | /* set the output as 1 or 0 */ |
@@ -409,10 +412,16 @@ static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip, | |||
409 | if (af.alt_bit1 != UNUSED) { | 412 | if (af.alt_bit1 != UNUSED) { |
410 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG, | 413 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG, |
411 | offset, 0); | 414 | offset, 0); |
415 | if (ret < 0) | ||
416 | goto out; | ||
417 | |||
412 | ret = abx500_gpio_set_bits(chip, | 418 | ret = abx500_gpio_set_bits(chip, |
413 | AB8500_GPIO_ALTFUN_REG, | 419 | AB8500_GPIO_ALTFUN_REG, |
414 | af.alt_bit1, | 420 | af.alt_bit1, |
415 | !!(af.alta_val && BIT(0))); | 421 | !!(af.alta_val && BIT(0))); |
422 | if (ret < 0) | ||
423 | goto out; | ||
424 | |||
416 | if (af.alt_bit2 != UNUSED) | 425 | if (af.alt_bit2 != UNUSED) |
417 | ret = abx500_gpio_set_bits(chip, | 426 | ret = abx500_gpio_set_bits(chip, |
418 | AB8500_GPIO_ALTFUN_REG, | 427 | AB8500_GPIO_ALTFUN_REG, |
@@ -426,8 +435,14 @@ static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip, | |||
426 | case ABX500_ALT_B: | 435 | case ABX500_ALT_B: |
427 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG, | 436 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG, |
428 | offset, 0); | 437 | offset, 0); |
438 | if (ret < 0) | ||
439 | goto out; | ||
440 | |||
429 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG, | 441 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG, |
430 | af.alt_bit1, !!(af.altb_val && BIT(0))); | 442 | af.alt_bit1, !!(af.altb_val && BIT(0))); |
443 | if (ret < 0) | ||
444 | goto out; | ||
445 | |||
431 | if (af.alt_bit2 != UNUSED) | 446 | if (af.alt_bit2 != UNUSED) |
432 | ret = abx500_gpio_set_bits(chip, | 447 | ret = abx500_gpio_set_bits(chip, |
433 | AB8500_GPIO_ALTFUN_REG, | 448 | AB8500_GPIO_ALTFUN_REG, |
@@ -438,8 +453,14 @@ static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip, | |||
438 | case ABX500_ALT_C: | 453 | case ABX500_ALT_C: |
439 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG, | 454 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG, |
440 | offset, 0); | 455 | offset, 0); |
456 | if (ret < 0) | ||
457 | goto out; | ||
458 | |||
441 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG, | 459 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG, |
442 | af.alt_bit2, !!(af.altc_val && BIT(0))); | 460 | af.alt_bit2, !!(af.altc_val && BIT(0))); |
461 | if (ret < 0) | ||
462 | goto out; | ||
463 | |||
443 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG, | 464 | ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG, |
444 | af.alt_bit2, !!(af.altc_val && BIT(1))); | 465 | af.alt_bit2, !!(af.altc_val && BIT(1))); |
445 | break; | 466 | break; |
@@ -449,11 +470,14 @@ static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip, | |||
449 | 470 | ||
450 | return -EINVAL; | 471 | return -EINVAL; |
451 | } | 472 | } |
473 | out: | ||
474 | if (ret < 0) | ||
475 | dev_err(pct->dev, "%s failed (%d)\n", __func__, ret); | ||
452 | 476 | ||
453 | return ret; | 477 | return ret; |
454 | } | 478 | } |
455 | 479 | ||
456 | static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip, | 480 | static int abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip, |
457 | unsigned gpio) | 481 | unsigned gpio) |
458 | { | 482 | { |
459 | u8 mode; | 483 | u8 mode; |
@@ -464,6 +488,7 @@ static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip, | |||
464 | struct alternate_functions af = pct->soc->alternate_functions[gpio]; | 488 | struct alternate_functions af = pct->soc->alternate_functions[gpio]; |
465 | /* on ABx5xx, there is no GPIO0, so adjust the offset */ | 489 | /* on ABx5xx, there is no GPIO0, so adjust the offset */ |
466 | unsigned offset = gpio - 1; | 490 | unsigned offset = gpio - 1; |
491 | int ret; | ||
467 | 492 | ||
468 | /* | 493 | /* |
469 | * if gpiosel_bit is set to unused, | 494 | * if gpiosel_bit is set to unused, |
@@ -473,8 +498,11 @@ static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip, | |||
473 | return ABX500_DEFAULT; | 498 | return ABX500_DEFAULT; |
474 | 499 | ||
475 | /* read GpioSelx register */ | 500 | /* read GpioSelx register */ |
476 | abx500_gpio_get_bit(chip, AB8500_GPIO_SEL1_REG + (offset / 8), | 501 | ret = abx500_gpio_get_bit(chip, AB8500_GPIO_SEL1_REG + (offset / 8), |
477 | af.gpiosel_bit, &bit_mode); | 502 | af.gpiosel_bit, &bit_mode); |
503 | if (ret < 0) | ||
504 | goto out; | ||
505 | |||
478 | mode = bit_mode; | 506 | mode = bit_mode; |
479 | 507 | ||
480 | /* sanity check */ | 508 | /* sanity check */ |
@@ -506,14 +534,19 @@ static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip, | |||
506 | * pin use the AlternatFunction register | 534 | * pin use the AlternatFunction register |
507 | * read alt_bit1 value | 535 | * read alt_bit1 value |
508 | */ | 536 | */ |
509 | abx500_gpio_get_bit(chip, AB8500_GPIO_ALTFUN_REG, | 537 | ret = abx500_gpio_get_bit(chip, AB8500_GPIO_ALTFUN_REG, |
510 | af.alt_bit1, &alt_bit1); | 538 | af.alt_bit1, &alt_bit1); |
539 | if (ret < 0) | ||
540 | goto out; | ||
511 | 541 | ||
512 | if (af.alt_bit2 != UNUSED) | 542 | if (af.alt_bit2 != UNUSED) { |
513 | /* read alt_bit2 value */ | 543 | /* read alt_bit2 value */ |
514 | abx500_gpio_get_bit(chip, AB8500_GPIO_ALTFUN_REG, af.alt_bit2, | 544 | ret = abx500_gpio_get_bit(chip, AB8500_GPIO_ALTFUN_REG, |
545 | af.alt_bit2, | ||
515 | &alt_bit2); | 546 | &alt_bit2); |
516 | else | 547 | if (ret < 0) |
548 | goto out; | ||
549 | } else | ||
517 | alt_bit2 = 0; | 550 | alt_bit2 = 0; |
518 | 551 | ||
519 | mode = (alt_bit2 << 1) + alt_bit1; | 552 | mode = (alt_bit2 << 1) + alt_bit1; |
@@ -523,6 +556,10 @@ static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip, | |||
523 | return ABX500_ALT_B; | 556 | return ABX500_ALT_B; |
524 | else | 557 | else |
525 | return ABX500_ALT_C; | 558 | return ABX500_ALT_C; |
559 | |||
560 | out: | ||
561 | dev_err(pct->dev, "%s failed (%d)\n", __func__, ret); | ||
562 | return ret; | ||
526 | } | 563 | } |
527 | 564 | ||
528 | #ifdef CONFIG_DEBUG_FS | 565 | #ifdef CONFIG_DEBUG_FS |
@@ -541,6 +578,7 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s, | |||
541 | bool is_out; | 578 | bool is_out; |
542 | bool pd; | 579 | bool pd; |
543 | enum abx500_gpio_pull_updown pud = 0; | 580 | enum abx500_gpio_pull_updown pud = 0; |
581 | int ret; | ||
544 | 582 | ||
545 | const char *modes[] = { | 583 | const char *modes[] = { |
546 | [ABX500_DEFAULT] = "default", | 584 | [ABX500_DEFAULT] = "default", |
@@ -556,7 +594,10 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s, | |||
556 | [ABX500_GPIO_PULL_UP] = "pull up", | 594 | [ABX500_GPIO_PULL_UP] = "pull up", |
557 | }; | 595 | }; |
558 | 596 | ||
559 | abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG, gpio_offset, &is_out); | 597 | ret = abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG, |
598 | gpio_offset, &is_out); | ||
599 | if (ret < 0) | ||
600 | goto out; | ||
560 | 601 | ||
561 | seq_printf(s, " gpio-%-3d (%-20.20s) %-3s", | 602 | seq_printf(s, " gpio-%-3d (%-20.20s) %-3s", |
562 | gpio, label ?: "(none)", | 603 | gpio, label ?: "(none)", |
@@ -564,11 +605,17 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s, | |||
564 | 605 | ||
565 | if (!is_out) { | 606 | if (!is_out) { |
566 | if (abx500_pullud_supported(chip, offset)) { | 607 | if (abx500_pullud_supported(chip, offset)) { |
567 | abx500_get_pull_updown(pct, offset, &pud); | 608 | ret = abx500_get_pull_updown(pct, offset, &pud); |
609 | if (ret < 0) | ||
610 | goto out; | ||
611 | |||
568 | seq_printf(s, " %-9s", pull_up_down[pud]); | 612 | seq_printf(s, " %-9s", pull_up_down[pud]); |
569 | } else { | 613 | } else { |
570 | abx500_gpio_get_bit(chip, AB8500_GPIO_PUD1_REG, | 614 | ret = abx500_gpio_get_bit(chip, AB8500_GPIO_PUD1_REG, |
571 | gpio_offset, &pd); | 615 | gpio_offset, &pd); |
616 | if (ret < 0) | ||
617 | goto out; | ||
618 | |||
572 | seq_printf(s, " %-9s", pull_up_down[pd]); | 619 | seq_printf(s, " %-9s", pull_up_down[pd]); |
573 | } | 620 | } |
574 | } else | 621 | } else |
@@ -578,6 +625,10 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s, | |||
578 | mode = abx500_get_mode(pctldev, chip, offset); | 625 | mode = abx500_get_mode(pctldev, chip, offset); |
579 | 626 | ||
580 | seq_printf(s, " %s", (mode < 0) ? "unknown" : modes[mode]); | 627 | seq_printf(s, " %s", (mode < 0) ? "unknown" : modes[mode]); |
628 | |||
629 | out: | ||
630 | if (ret < 0) | ||
631 | dev_err(pct->dev, "%s failed (%d)\n", __func__, ret); | ||
581 | } | 632 | } |
582 | 633 | ||
583 | static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) | 634 | static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) |
@@ -681,6 +732,9 @@ static int abx500_pmx_enable(struct pinctrl_dev *pctldev, unsigned function, | |||
681 | ret = abx500_set_mode(pctldev, chip, g->pins[i], g->altsetting); | 732 | ret = abx500_set_mode(pctldev, chip, g->pins[i], g->altsetting); |
682 | } | 733 | } |
683 | 734 | ||
735 | if (ret < 0) | ||
736 | dev_err(pct->dev, "%s failed (%d)\n", __func__, ret); | ||
737 | |||
684 | return ret; | 738 | return ret; |
685 | } | 739 | } |
686 | 740 | ||
@@ -729,10 +783,8 @@ static int abx500_gpio_request_enable(struct pinctrl_dev *pctldev, | |||
729 | 783 | ||
730 | ret = abx500_set_mode(pct->pctldev, &pct->chip, | 784 | ret = abx500_set_mode(pct->pctldev, &pct->chip, |
731 | offset, p->altfunc); | 785 | offset, p->altfunc); |
732 | if (ret < 0) { | 786 | if (ret < 0) |
733 | dev_err(pct->dev, "%s setting altfunc failed\n", __func__); | 787 | dev_err(pct->dev, "%s setting altfunc failed\n", __func__); |
734 | return ret; | ||
735 | } | ||
736 | 788 | ||
737 | return ret; | 789 | return ret; |
738 | } | 790 | } |
@@ -1009,6 +1061,8 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, | |||
1009 | switch (param) { | 1061 | switch (param) { |
1010 | case PIN_CONFIG_BIAS_DISABLE: | 1062 | case PIN_CONFIG_BIAS_DISABLE: |
1011 | ret = abx500_gpio_direction_input(chip, offset); | 1063 | ret = abx500_gpio_direction_input(chip, offset); |
1064 | if (ret < 0) | ||
1065 | goto out; | ||
1012 | /* | 1066 | /* |
1013 | * Some chips only support pull down, while some actually | 1067 | * Some chips only support pull down, while some actually |
1014 | * support both pull up and pull down. Such chips have | 1068 | * support both pull up and pull down. Such chips have |
@@ -1028,6 +1082,8 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, | |||
1028 | 1082 | ||
1029 | case PIN_CONFIG_BIAS_PULL_DOWN: | 1083 | case PIN_CONFIG_BIAS_PULL_DOWN: |
1030 | ret = abx500_gpio_direction_input(chip, offset); | 1084 | ret = abx500_gpio_direction_input(chip, offset); |
1085 | if (ret < 0) | ||
1086 | goto out; | ||
1031 | /* | 1087 | /* |
1032 | * if argument = 1 set the pull down | 1088 | * if argument = 1 set the pull down |
1033 | * else clear the pull down | 1089 | * else clear the pull down |
@@ -1050,6 +1106,8 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, | |||
1050 | 1106 | ||
1051 | case PIN_CONFIG_BIAS_PULL_UP: | 1107 | case PIN_CONFIG_BIAS_PULL_UP: |
1052 | ret = abx500_gpio_direction_input(chip, offset); | 1108 | ret = abx500_gpio_direction_input(chip, offset); |
1109 | if (ret < 0) | ||
1110 | goto out; | ||
1053 | /* | 1111 | /* |
1054 | * if argument = 1 set the pull up | 1112 | * if argument = 1 set the pull up |
1055 | * else clear the pull up | 1113 | * else clear the pull up |
@@ -1070,12 +1128,14 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, | |||
1070 | 1128 | ||
1071 | case PIN_CONFIG_OUTPUT: | 1129 | case PIN_CONFIG_OUTPUT: |
1072 | ret = abx500_gpio_direction_output(chip, offset, argument); | 1130 | ret = abx500_gpio_direction_output(chip, offset, argument); |
1073 | |||
1074 | break; | 1131 | break; |
1075 | 1132 | ||
1076 | default: | 1133 | default: |
1077 | dev_err(chip->dev, "illegal configuration requested\n"); | 1134 | dev_err(chip->dev, "illegal configuration requested\n"); |
1078 | } | 1135 | } |
1136 | out: | ||
1137 | if (ret < 0) | ||
1138 | dev_err(pct->dev, "%s failed (%d)\n", __func__, ret); | ||
1079 | 1139 | ||
1080 | return ret; | 1140 | return ret; |
1081 | } | 1141 | } |