aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrice Chotard <patrice.chotard@st.com>2016-05-24 07:57:43 -0400
committerLinus Walleij <linus.walleij@linaro.org>2016-05-31 04:06:12 -0400
commit4fac724fd76623c65ad00b412f5c7d0a816b98ff (patch)
treef7adefadd8bd3a109732a2b0bc79b8d1465f8471
parenta0ee2ac039c012062d91fbb324c3068c089a9380 (diff)
pinctrl: stm32: factorize stm32_pconf_input/output_get()
As these 2 functions code are 95% similar, factorize them. Signed-off-by: Patrice Chotard <patrice.chotard@st.com> Acked-by: Maxime Coquelin <maxime.coquelin@st.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--drivers/pinctrl/stm32/pinctrl-stm32.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
index ae9fab82a1b9..4ae596bf19b5 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
@@ -638,8 +638,8 @@ static u32 stm32_pconf_get_bias(struct stm32_gpio_bank *bank,
638 return (val >> (offset * 2)); 638 return (val >> (offset * 2));
639} 639}
640 640
641static bool stm32_pconf_input_get(struct stm32_gpio_bank *bank, 641static bool stm32_pconf_get(struct stm32_gpio_bank *bank,
642 unsigned int offset) 642 unsigned int offset, bool dir)
643{ 643{
644 unsigned long flags; 644 unsigned long flags;
645 u32 val; 645 u32 val;
@@ -647,23 +647,12 @@ static bool stm32_pconf_input_get(struct stm32_gpio_bank *bank,
647 clk_enable(bank->clk); 647 clk_enable(bank->clk);
648 spin_lock_irqsave(&bank->lock, flags); 648 spin_lock_irqsave(&bank->lock, flags);
649 649
650 val = !!(readl_relaxed(bank->base + STM32_GPIO_IDR) & BIT(offset)); 650 if (dir)
651 651 val = !!(readl_relaxed(bank->base + STM32_GPIO_IDR) &
652 spin_unlock_irqrestore(&bank->lock, flags); 652 BIT(offset));
653 clk_disable(bank->clk); 653 else
654 654 val = !!(readl_relaxed(bank->base + STM32_GPIO_ODR) &
655 return val; 655 BIT(offset));
656}
657
658static bool stm32_pconf_output_get(struct stm32_gpio_bank *bank,
659 unsigned int offset)
660{
661 unsigned long flags;
662 u32 val;
663
664 clk_enable(bank->clk);
665 spin_lock_irqsave(&bank->lock, flags);
666 val = !!(readl_relaxed(bank->base + STM32_GPIO_ODR) & BIT(offset));
667 656
668 spin_unlock_irqrestore(&bank->lock, flags); 657 spin_unlock_irqrestore(&bank->lock, flags);
669 clk_disable(bank->clk); 658 clk_disable(bank->clk);
@@ -772,7 +761,7 @@ static void stm32_pconf_dbg_show(struct pinctrl_dev *pctldev,
772 switch (mode) { 761 switch (mode) {
773 /* input */ 762 /* input */
774 case 0: 763 case 0:
775 val = stm32_pconf_input_get(bank, offset); 764 val = stm32_pconf_get(bank, offset, true);
776 seq_printf(s, "- %s - %s", 765 seq_printf(s, "- %s - %s",
777 val ? "high" : "low", 766 val ? "high" : "low",
778 biasing[bias]); 767 biasing[bias]);
@@ -782,7 +771,7 @@ static void stm32_pconf_dbg_show(struct pinctrl_dev *pctldev,
782 case 1: 771 case 1:
783 drive = stm32_pconf_get_driving(bank, offset); 772 drive = stm32_pconf_get_driving(bank, offset);
784 speed = stm32_pconf_get_speed(bank, offset); 773 speed = stm32_pconf_get_speed(bank, offset);
785 val = stm32_pconf_output_get(bank, offset); 774 val = stm32_pconf_get(bank, offset, false);
786 seq_printf(s, "- %s - %s - %s - %s %s", 775 seq_printf(s, "- %s - %s - %s - %s %s",
787 val ? "high" : "low", 776 val ? "high" : "low",
788 drive ? "open drain" : "push pull", 777 drive ? "open drain" : "push pull",