Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: mediatek: Backward compatible to previous Mediatek's bias-pull usage

Refine mtk_pinconf_set()/mtk_pinconf_get() for backward compatibility to
previous MediaTek's bias-pull usage.
In PINCTRL_MTK that use pinctrl-mtk-common.c, bias-pull setting for pins
with 2 pull resistors can be specified as value for bias-pull-up and
bias-pull-down. For example:
bias-pull-up = <MTK_PUPD_SET_R1R0_00>;
bias-pull-up = <MTK_PUPD_SET_R1R0_01>;
bias-pull-up = <MTK_PUPD_SET_R1R0_10>;
bias-pull-up = <MTK_PUPD_SET_R1R0_11>;
bias-pull-down = <MTK_PUPD_SET_R1R0_00>;
bias-pull-down = <MTK_PUPD_SET_R1R0_01>;
bias-pull-down = <MTK_PUPD_SET_R1R0_10>;
bias-pull-down = <MTK_PUPD_SET_R1R0_11>;

On the other hand, PINCTRL_MTK_PARIS use customized properties
"mediatek,pull-up-adv" and "mediatek,pull-down-adv" to specify bias-pull
setting for pins with 2 pull resistors.
This introduce in-compatibility in device tree and increase porting
effort to MediaTek's customer that had already used PINCTRL_MTK version.
Besides, if customers are not aware of this change and still write devicetree
for PINCTRL_MTK version, they may encounter runtime failure with pinctrl and
spent time to debug.

This patch adds backward compatible to previous MediaTek's bias-pull usage
so that Mediatek's customer need not use a new devicetree property name.
The rationale is that: changing driver implementation had better leave
interface unchanged.

Signed-off-by: Light Hsieh <light.hsieh@mediatek.com>
Link: https://lore.kernel.org/r/1579675994-7001-5-git-send-email-light.hsieh@mediatek.com
Acked-by: Sean Wang <sean.wang@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Light Hsieh and committed by
Linus Walleij
cafe19db 1bea6afb

+265 -28
+2 -4
drivers/pinctrl/mediatek/pinctrl-mt6765.c
··· 1072 1072 .gpio_m = 0, 1073 1073 .base_names = mt6765_pinctrl_register_base_names, 1074 1074 .nbase_names = ARRAY_SIZE(mt6765_pinctrl_register_base_names), 1075 - .bias_disable_set = mtk_pinconf_bias_disable_set, 1076 - .bias_disable_get = mtk_pinconf_bias_disable_get, 1077 - .bias_set = mtk_pinconf_bias_set, 1078 - .bias_get = mtk_pinconf_bias_get, 1075 + .bias_set_combo = mtk_pinconf_bias_set_combo, 1076 + .bias_get_combo = mtk_pinconf_bias_get_combo, 1079 1077 .drive_set = mtk_pinconf_drive_set_raw, 1080 1078 .drive_get = mtk_pinconf_drive_get_raw, 1081 1079 .adv_pull_get = mtk_pinconf_adv_pull_get,
+2 -4
drivers/pinctrl/mediatek/pinctrl-mt8183.c
··· 556 556 .gpio_m = 0, 557 557 .base_names = mt8183_pinctrl_register_base_names, 558 558 .nbase_names = ARRAY_SIZE(mt8183_pinctrl_register_base_names), 559 - .bias_disable_set = mtk_pinconf_bias_disable_set_rev1, 560 - .bias_disable_get = mtk_pinconf_bias_disable_get_rev1, 561 - .bias_set = mtk_pinconf_bias_set_rev1, 562 - .bias_get = mtk_pinconf_bias_get_rev1, 559 + .bias_set_combo = mtk_pinconf_bias_set_combo, 560 + .bias_get_combo = mtk_pinconf_bias_get_combo, 563 561 .drive_set = mtk_pinconf_drive_set_rev1, 564 562 .drive_get = mtk_pinconf_drive_get_rev1, 565 563 .adv_pull_get = mtk_pinconf_adv_pull_get,
+221
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
··· 6 6 * 7 7 */ 8 8 9 + #include <dt-bindings/pinctrl/mt65xx.h> 9 10 #include <linux/device.h> 10 11 #include <linux/err.h> 11 12 #include <linux/gpio/driver.h> ··· 516 515 *res = 1; 517 516 518 517 return 0; 518 + } 519 + 520 + /* Combo for the following pull register type: 521 + * 1. PU + PD 522 + * 2. PULLSEL + PULLEN 523 + * 3. PUPD + R0 + R1 524 + */ 525 + static int mtk_pinconf_bias_set_pu_pd(struct mtk_pinctrl *hw, 526 + const struct mtk_pin_desc *desc, 527 + u32 pullup, u32 arg) 528 + { 529 + int err, pu, pd; 530 + 531 + if (arg == MTK_DISABLE) { 532 + pu = 0; 533 + pd = 0; 534 + } else if ((arg == MTK_ENABLE) && pullup) { 535 + pu = 1; 536 + pd = 0; 537 + } else if ((arg == MTK_ENABLE) && !pullup) { 538 + pu = 0; 539 + pd = 1; 540 + } else { 541 + err = -EINVAL; 542 + goto out; 543 + } 544 + 545 + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, pu); 546 + if (err) 547 + goto out; 548 + 549 + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd); 550 + 551 + out: 552 + return err; 553 + } 554 + 555 + static int mtk_pinconf_bias_set_pullsel_pullen(struct mtk_pinctrl *hw, 556 + const struct mtk_pin_desc *desc, 557 + u32 pullup, u32 arg) 558 + { 559 + int err, enable; 560 + 561 + if (arg == MTK_DISABLE) 562 + enable = 0; 563 + else if (arg == MTK_ENABLE) 564 + enable = 1; 565 + else { 566 + err = -EINVAL; 567 + goto out; 568 + } 569 + 570 + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN, enable); 571 + if (err) 572 + goto out; 573 + 574 + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup); 575 + 576 + out: 577 + return err; 578 + } 579 + 580 + static int mtk_pinconf_bias_set_pupd_r1_r0(struct mtk_pinctrl *hw, 581 + const struct mtk_pin_desc *desc, 582 + u32 pullup, u32 arg) 583 + { 584 + int err, r0, r1; 585 + 586 + if ((arg == MTK_DISABLE) || (arg == MTK_PUPD_SET_R1R0_00)) { 587 + pullup = 0; 588 + r0 = 0; 589 + r1 = 0; 590 + } else if (arg == MTK_PUPD_SET_R1R0_01) { 591 + r0 = 1; 592 + r1 = 0; 593 + } else if (arg == MTK_PUPD_SET_R1R0_10) { 594 + r0 = 0; 595 + r1 = 1; 596 + } else if (arg == MTK_PUPD_SET_R1R0_11) { 597 + r0 = 1; 598 + r1 = 1; 599 + } else { 600 + err = -EINVAL; 601 + goto out; 602 + } 603 + 604 + /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ 605 + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, !pullup); 606 + if (err) 607 + goto out; 608 + 609 + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R0, r0); 610 + if (err) 611 + goto out; 612 + 613 + err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R1, r1); 614 + 615 + out: 616 + return err; 617 + } 618 + 619 + static int mtk_pinconf_bias_get_pu_pd(struct mtk_pinctrl *hw, 620 + const struct mtk_pin_desc *desc, 621 + u32 *pullup, u32 *enable) 622 + { 623 + int err, pu, pd; 624 + 625 + err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &pu); 626 + if (err) 627 + goto out; 628 + 629 + err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd); 630 + if (err) 631 + goto out; 632 + 633 + if (pu == 0 && pd == 0) { 634 + *pullup = 0; 635 + *enable = MTK_DISABLE; 636 + } else if (pu == 1 && pd == 0) { 637 + *pullup = 1; 638 + *enable = MTK_ENABLE; 639 + } else if (pu == 0 && pd == 1) { 640 + *pullup = 0; 641 + *enable = MTK_ENABLE; 642 + } else 643 + err = -EINVAL; 644 + 645 + out: 646 + return err; 647 + } 648 + 649 + static int mtk_pinconf_bias_get_pullsel_pullen(struct mtk_pinctrl *hw, 650 + const struct mtk_pin_desc *desc, 651 + u32 *pullup, u32 *enable) 652 + { 653 + int err; 654 + 655 + err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup); 656 + if (err) 657 + goto out; 658 + 659 + err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, enable); 660 + 661 + out: 662 + return err; 663 + } 664 + 665 + static int mtk_pinconf_bias_get_pupd_r1_r0(struct mtk_pinctrl *hw, 666 + const struct mtk_pin_desc *desc, 667 + u32 *pullup, u32 *enable) 668 + { 669 + int err, r0, r1; 670 + 671 + err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, pullup); 672 + if (err) 673 + goto out; 674 + /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ 675 + *pullup = !(*pullup); 676 + 677 + err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R0, &r0); 678 + if (err) 679 + goto out; 680 + 681 + err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R1, &r1); 682 + if (err) 683 + goto out; 684 + 685 + if ((r1 == 0) && (r0 == 0)) 686 + *enable = MTK_PUPD_SET_R1R0_00; 687 + else if ((r1 == 0) && (r0 == 1)) 688 + *enable = MTK_PUPD_SET_R1R0_01; 689 + else if ((r1 == 1) && (r0 == 0)) 690 + *enable = MTK_PUPD_SET_R1R0_10; 691 + else if ((r1 == 1) && (r0 == 1)) 692 + *enable = MTK_PUPD_SET_R1R0_11; 693 + else 694 + err = -EINVAL; 695 + 696 + out: 697 + return err; 698 + } 699 + 700 + int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw, 701 + const struct mtk_pin_desc *desc, 702 + u32 pullup, u32 arg) 703 + { 704 + int err; 705 + 706 + err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg); 707 + if (!err) 708 + goto out; 709 + 710 + err = mtk_pinconf_bias_set_pullsel_pullen(hw, desc, pullup, arg); 711 + if (!err) 712 + goto out; 713 + 714 + err = mtk_pinconf_bias_set_pupd_r1_r0(hw, desc, pullup, arg); 715 + 716 + out: 717 + return err; 718 + } 719 + 720 + int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw, 721 + const struct mtk_pin_desc *desc, 722 + u32 *pullup, u32 *enable) 723 + { 724 + int err; 725 + 726 + err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable); 727 + if (!err) 728 + goto out; 729 + 730 + err = mtk_pinconf_bias_get_pullsel_pullen(hw, desc, pullup, enable); 731 + if (!err) 732 + goto out; 733 + 734 + err = mtk_pinconf_bias_get_pupd_r1_r0(hw, desc, pullup, enable); 735 + 736 + out: 737 + return err; 519 738 } 520 739 521 740 /* Revision 0 */
+11
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
··· 216 216 int (*bias_get)(struct mtk_pinctrl *hw, 217 217 const struct mtk_pin_desc *desc, bool pullup, int *res); 218 218 219 + int (*bias_set_combo)(struct mtk_pinctrl *hw, 220 + const struct mtk_pin_desc *desc, u32 pullup, u32 arg); 221 + int (*bias_get_combo)(struct mtk_pinctrl *hw, 222 + const struct mtk_pin_desc *desc, u32 *pullup, u32 *arg); 223 + 219 224 int (*drive_set)(struct mtk_pinctrl *hw, 220 225 const struct mtk_pin_desc *desc, u32 arg); 221 226 int (*drive_get)(struct mtk_pinctrl *hw, ··· 282 277 int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw, 283 278 const struct mtk_pin_desc *desc, bool pullup, 284 279 int *res); 280 + int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw, 281 + const struct mtk_pin_desc *desc, 282 + u32 pullup, u32 enable); 283 + int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw, 284 + const struct mtk_pin_desc *desc, 285 + u32 *pullup, u32 *enable); 285 286 286 287 int mtk_pinconf_drive_set(struct mtk_pinctrl *hw, 287 288 const struct mtk_pin_desc *desc, u32 arg);
+29 -20
drivers/pinctrl/mediatek/pinctrl-paris.c
··· 78 78 { 79 79 struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev); 80 80 u32 param = pinconf_to_config_param(*config); 81 - int err, reg, ret = 1; 81 + int pullup, err, reg, ret = 1; 82 82 const struct mtk_pin_desc *desc; 83 83 84 84 if (pin >= hw->soc->npins) { ··· 89 89 90 90 switch (param) { 91 91 case PIN_CONFIG_BIAS_DISABLE: 92 - if (hw->soc->bias_disable_get) 93 - err = hw->soc->bias_disable_get(hw, desc, &ret); 94 - else 95 - err = -ENOTSUPP; 96 - break; 97 92 case PIN_CONFIG_BIAS_PULL_UP: 98 - if (hw->soc->bias_get) 99 - err = hw->soc->bias_get(hw, desc, 1, &ret); 100 - else 101 - err = -ENOTSUPP; 102 - break; 103 93 case PIN_CONFIG_BIAS_PULL_DOWN: 104 - if (hw->soc->bias_get) 105 - err = hw->soc->bias_get(hw, desc, 0, &ret); 106 - else 94 + if (hw->soc->bias_get_combo) { 95 + err = hw->soc->bias_get_combo(hw, desc, &pullup, &ret); 96 + if (err) 97 + goto out; 98 + if (param == PIN_CONFIG_BIAS_DISABLE) { 99 + if (ret == MTK_PUPD_SET_R1R0_00) 100 + ret = MTK_DISABLE; 101 + } else if (param == PIN_CONFIG_BIAS_PULL_UP) { 102 + /* When desire to get pull-up value, return 103 + * error if current setting is pull-down 104 + */ 105 + if (!pullup) 106 + err = -EINVAL; 107 + } else if (param == PIN_CONFIG_BIAS_PULL_DOWN) { 108 + /* When desire to get pull-down value, return 109 + * error if current setting is pull-up 110 + */ 111 + if (pullup) 112 + err = -EINVAL; 113 + } 114 + } else { 107 115 err = -ENOTSUPP; 116 + } 108 117 break; 109 118 case PIN_CONFIG_SLEW_RATE: 110 119 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SR, &ret); ··· 205 196 206 197 switch ((u32)param) { 207 198 case PIN_CONFIG_BIAS_DISABLE: 208 - if (hw->soc->bias_disable_set) 209 - err = hw->soc->bias_disable_set(hw, desc); 199 + if (hw->soc->bias_set_combo) 200 + err = hw->soc->bias_set_combo(hw, desc, 0, MTK_DISABLE); 210 201 else 211 202 err = -ENOTSUPP; 212 203 break; 213 204 case PIN_CONFIG_BIAS_PULL_UP: 214 - if (hw->soc->bias_set) 215 - err = hw->soc->bias_set(hw, desc, 1); 205 + if (hw->soc->bias_set_combo) 206 + err = hw->soc->bias_set_combo(hw, desc, 1, arg); 216 207 else 217 208 err = -ENOTSUPP; 218 209 break; 219 210 case PIN_CONFIG_BIAS_PULL_DOWN: 220 - if (hw->soc->bias_set) 221 - err = hw->soc->bias_set(hw, desc, 0); 211 + if (hw->soc->bias_set_combo) 212 + err = hw->soc->bias_set_combo(hw, desc, 0, arg); 222 213 else 223 214 err = -ENOTSUPP; 224 215 break;