diff options
author | Patrice Chotard <patrice.chotard@st.com> | 2013-05-24 08:06:31 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2013-06-16 05:56:51 -0400 |
commit | d2752ae54d4ac36a5c05450cfce470bff9dc6faa (patch) | |
tree | c81950b5bb17a2b0b3a1eca1ce698817c1e7e5f8 | |
parent | 9ed3cd3338fcb6e5129be2b3091439e32be545b8 (diff) |
pinctrl: abx500: fix abx500_gpio_dbg_show_one() to show pull up/down
- rework abx500_gpio_dbg_show_one() to take in account pull up/down
feature available on AB8540 only.
- add abx500_get_pull_updown() needed by abx500_gpio_dbg_show_one()
- rename abx500_config_pull_updown() to abx500_set_pull_updown()
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r-- | drivers/pinctrl/pinctrl-abx500.c | 86 |
1 files changed, 70 insertions, 16 deletions
diff --git a/drivers/pinctrl/pinctrl-abx500.c b/drivers/pinctrl/pinctrl-abx500.c index 363712bad7ef..378ed3b850e7 100644 --- a/drivers/pinctrl/pinctrl-abx500.c +++ b/drivers/pinctrl/pinctrl-abx500.c | |||
@@ -181,10 +181,11 @@ static void abx500_gpio_set(struct gpio_chip *chip, unsigned offset, int val) | |||
181 | dev_err(pct->dev, "%s write failed\n", __func__); | 181 | dev_err(pct->dev, "%s write failed\n", __func__); |
182 | } | 182 | } |
183 | 183 | ||
184 | static int abx500_config_pull_updown(struct abx500_pinctrl *pct, | 184 | static int abx500_get_pull_updown(struct abx500_pinctrl *pct, int offset, |
185 | int offset, enum abx500_gpio_pull_updown val) | 185 | enum abx500_gpio_pull_updown *pull_updown) |
186 | { | 186 | { |
187 | u8 pos; | 187 | u8 pos; |
188 | u8 val; | ||
188 | int ret; | 189 | int ret; |
189 | struct pullud *pullud; | 190 | struct pullud *pullud; |
190 | 191 | ||
@@ -203,6 +204,40 @@ static int abx500_config_pull_updown(struct abx500_pinctrl *pct, | |||
203 | goto out; | 204 | goto out; |
204 | } | 205 | } |
205 | 206 | ||
207 | ret = abx500_get_register_interruptible(pct->dev, | ||
208 | AB8500_MISC, AB8540_GPIO_PULL_UPDOWN_REG, &val); | ||
209 | |||
210 | pos = (offset - pullud->first_pin) << 1; | ||
211 | *pull_updown = (val >> pos) & AB8540_GPIO_PULL_UPDOWN_MASK; | ||
212 | |||
213 | out: | ||
214 | if (ret < 0) | ||
215 | dev_err(pct->dev, "%s failed (%d)\n", __func__, ret); | ||
216 | |||
217 | return ret; | ||
218 | } | ||
219 | |||
220 | static int abx500_set_pull_updown(struct abx500_pinctrl *pct, | ||
221 | int offset, enum abx500_gpio_pull_updown val) | ||
222 | { | ||
223 | u8 pos; | ||
224 | int ret; | ||
225 | struct pullud *pullud; | ||
226 | |||
227 | if (!pct->soc->pullud) { | ||
228 | dev_err(pct->dev, "%s AB chip doesn't support pull up/down feature", | ||
229 | __func__); | ||
230 | ret = -EPERM; | ||
231 | goto out; | ||
232 | } | ||
233 | |||
234 | pullud = pct->soc->pullud; | ||
235 | |||
236 | if ((offset < pullud->first_pin) | ||
237 | || (offset > pullud->last_pin)) { | ||
238 | ret = -EINVAL; | ||
239 | goto out; | ||
240 | } | ||
206 | pos = (offset - pullud->first_pin) << 1; | 241 | pos = (offset - pullud->first_pin) << 1; |
207 | 242 | ||
208 | ret = abx500_mask_and_set_register_interruptible(pct->dev, | 243 | ret = abx500_mask_and_set_register_interruptible(pct->dev, |
@@ -238,7 +273,7 @@ static int abx500_gpio_direction_output(struct gpio_chip *chip, | |||
238 | /* if supported, disable both pull down and pull up */ | 273 | /* if supported, disable both pull down and pull up */ |
239 | gpio = offset + 1; | 274 | gpio = offset + 1; |
240 | if (pullud && gpio >= pullud->first_pin && gpio <= pullud->last_pin) { | 275 | if (pullud && gpio >= pullud->first_pin && gpio <= pullud->last_pin) { |
241 | ret = abx500_config_pull_updown(pct, | 276 | ret = abx500_set_pull_updown(pct, |
242 | gpio, | 277 | gpio, |
243 | ABX500_GPIO_PULL_NONE); | 278 | ABX500_GPIO_PULL_NONE); |
244 | if (ret < 0) | 279 | if (ret < 0) |
@@ -462,11 +497,14 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s, | |||
462 | struct gpio_chip *chip, | 497 | struct gpio_chip *chip, |
463 | unsigned offset, unsigned gpio) | 498 | unsigned offset, unsigned gpio) |
464 | { | 499 | { |
500 | struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); | ||
501 | struct pullud *pullud = pct->soc->pullud; | ||
465 | const char *label = gpiochip_is_requested(chip, offset - 1); | 502 | const char *label = gpiochip_is_requested(chip, offset - 1); |
466 | u8 gpio_offset = offset - 1; | 503 | u8 gpio_offset = offset - 1; |
467 | int mode = -1; | 504 | int mode = -1; |
468 | bool is_out; | 505 | bool is_out; |
469 | bool pull; | 506 | bool pd; |
507 | enum abx500_gpio_pull_updown pud; | ||
470 | 508 | ||
471 | const char *modes[] = { | 509 | const char *modes[] = { |
472 | [ABX500_DEFAULT] = "default", | 510 | [ABX500_DEFAULT] = "default", |
@@ -475,21 +513,37 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s, | |||
475 | [ABX500_ALT_C] = "altC", | 513 | [ABX500_ALT_C] = "altC", |
476 | }; | 514 | }; |
477 | 515 | ||
516 | const char *pull_up_down[] = { | ||
517 | [ABX500_GPIO_PULL_DOWN] = "pull down", | ||
518 | [ABX500_GPIO_PULL_NONE] = "pull none", | ||
519 | [ABX500_GPIO_PULL_NONE + 1] = "pull none", | ||
520 | [ABX500_GPIO_PULL_UP] = "pull up", | ||
521 | }; | ||
522 | |||
478 | abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG, gpio_offset, &is_out); | 523 | abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG, gpio_offset, &is_out); |
479 | abx500_gpio_get_bit(chip, AB8500_GPIO_PUD1_REG, gpio_offset, &pull); | 524 | |
525 | seq_printf(s, " gpio-%-3d (%-20.20s) %-3s", | ||
526 | gpio, label ?: "(none)", | ||
527 | is_out ? "out" : "in "); | ||
528 | |||
529 | if (!is_out) { | ||
530 | if (pullud && | ||
531 | (offset >= pullud->first_pin) && | ||
532 | (offset <= pullud->last_pin)) { | ||
533 | abx500_get_pull_updown(pct, offset, &pud); | ||
534 | seq_printf(s, " %-9s", pull_up_down[pud]); | ||
535 | } else { | ||
536 | abx500_gpio_get_bit(chip, AB8500_GPIO_PUD1_REG, | ||
537 | gpio_offset, &pd); | ||
538 | seq_printf(s, " %-9s", pull_up_down[pd]); | ||
539 | } | ||
540 | } else | ||
541 | seq_printf(s, " %-9s", chip->get(chip, offset) ? "hi" : "lo"); | ||
480 | 542 | ||
481 | if (pctldev) | 543 | if (pctldev) |
482 | mode = abx500_get_mode(pctldev, chip, offset); | 544 | mode = abx500_get_mode(pctldev, chip, offset); |
483 | 545 | ||
484 | seq_printf(s, " gpio-%-3d (%-20.20s) %-3s %-9s %s", | 546 | seq_printf(s, " %s", (mode < 0) ? "unknown" : modes[mode]); |
485 | gpio, label ?: "(none)", | ||
486 | is_out ? "out" : "in ", | ||
487 | is_out ? | ||
488 | (chip->get | ||
489 | ? (chip->get(chip, offset) ? "hi" : "lo") | ||
490 | : "? ") | ||
491 | : (pull ? "pull up" : "pull down"), | ||
492 | (mode < 0) ? "unknown" : modes[mode]); | ||
493 | } | 547 | } |
494 | 548 | ||
495 | static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) | 549 | static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) |
@@ -754,7 +808,7 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, | |||
754 | if (pullud && | 808 | if (pullud && |
755 | pin >= pullud->first_pin && | 809 | pin >= pullud->first_pin && |
756 | pin <= pullud->last_pin) | 810 | pin <= pullud->last_pin) |
757 | ret = abx500_config_pull_updown(pct, | 811 | ret = abx500_set_pull_updown(pct, |
758 | pin, | 812 | pin, |
759 | argument ? ABX500_GPIO_PULL_DOWN : ABX500_GPIO_PULL_NONE); | 813 | argument ? ABX500_GPIO_PULL_DOWN : ABX500_GPIO_PULL_NONE); |
760 | else | 814 | else |
@@ -779,7 +833,7 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, | |||
779 | if (pullud && | 833 | if (pullud && |
780 | pin >= pullud->first_pin && | 834 | pin >= pullud->first_pin && |
781 | pin <= pullud->last_pin) { | 835 | pin <= pullud->last_pin) { |
782 | ret = abx500_config_pull_updown(pct, | 836 | ret = abx500_set_pull_updown(pct, |
783 | pin, | 837 | pin, |
784 | argument ? ABX500_GPIO_PULL_UP : ABX500_GPIO_PULL_NONE); | 838 | argument ? ABX500_GPIO_PULL_UP : ABX500_GPIO_PULL_NONE); |
785 | } | 839 | } |