]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
pinctrl: at91: add support for OUTPUT config
authorBoris BREZILLON <b.brezillon@overkiz.com>
Fri, 28 Oct 2016 07:54:10 +0000 (15:54 +0800)
committerLinus Walleij <linus.walleij@linaro.org>
Mon, 31 Oct 2016 08:16:46 +0000 (09:16 +0100)
Add support for pin output control through the pinctrl config:
 - support enabling/disabling output on a given pin
 - support output level setting (high or low)

Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Documentation/devicetree/bindings/pinctrl/atmel,at91-pinctrl.txt
drivers/pinctrl/pinctrl-at91.c
include/dt-bindings/pinctrl/at91.h

index b7a93e80a3026e75727fe5a1a17fc2611a72cc26..9a8a45d9d8abc284c3108adb4ef6d1355208c415 100644 (file)
@@ -98,6 +98,8 @@ DRIVE_STRENGTH (3 << 5): indicate the drive strength of the pin using the
                                01 - Low
                                10 - Medium
                                11 - High
+OUTPUT         (1 << 7): indicate this pin need to be configured as an output.
+OUTPUT_VAL     (1 << 8): output val (1 = high, 0 = low)
 DEBOUNCE       (1 << 16): indicate this pin needs debounce.
 DEBOUNCE_VAL   (0x3fff << 17): debounce value.
 
index 9f09041859099134220b54c7aee691f8810ee09d..569bc28cb90972943bb0929127688b2a1e59ff91 100644 (file)
@@ -56,6 +56,9 @@ static int gpio_banks;
 #define DRIVE_STRENGTH_SHIFT   5
 #define DRIVE_STRENGTH_MASK            0x3
 #define DRIVE_STRENGTH   (DRIVE_STRENGTH_MASK << DRIVE_STRENGTH_SHIFT)
+#define OUTPUT         (1 << 7)
+#define OUTPUT_VAL_SHIFT       8
+#define OUTPUT_VAL     (0x1 << OUTPUT_VAL_SHIFT)
 #define DEBOUNCE       (1 << 16)
 #define DEBOUNCE_VAL_SHIFT     17
 #define DEBOUNCE_VAL   (0x3fff << DEBOUNCE_VAL_SHIFT)
@@ -375,6 +378,19 @@ static void at91_mux_set_pullup(void __iomem *pio, unsigned mask, bool on)
        writel_relaxed(mask, pio + (on ? PIO_PUER : PIO_PUDR));
 }
 
+static bool at91_mux_get_output(void __iomem *pio, unsigned int pin, bool *val)
+{
+       *val = (readl_relaxed(pio + PIO_ODSR) >> pin) & 0x1;
+       return (readl_relaxed(pio + PIO_OSR) >> pin) & 0x1;
+}
+
+static void at91_mux_set_output(void __iomem *pio, unsigned int mask,
+                               bool is_on, bool val)
+{
+       writel_relaxed(mask, pio + (val ? PIO_SODR : PIO_CODR));
+       writel_relaxed(mask, pio + (is_on ? PIO_OER : PIO_ODR));
+}
+
 static unsigned at91_mux_get_multidrive(void __iomem *pio, unsigned pin)
 {
        return (readl_relaxed(pio + PIO_MDSR) >> pin) & 0x1;
@@ -848,6 +864,7 @@ static int at91_pinconf_get(struct pinctrl_dev *pctldev,
        void __iomem *pio;
        unsigned pin;
        int div;
+       bool out;
 
        *config = 0;
        dev_dbg(info->dev, "%s:%d, pin_id=%d", __func__, __LINE__, pin_id);
@@ -875,6 +892,8 @@ static int at91_pinconf_get(struct pinctrl_dev *pctldev,
        if (info->ops->get_drivestrength)
                *config |= (info->ops->get_drivestrength(pio, pin)
                                << DRIVE_STRENGTH_SHIFT);
+       if (at91_mux_get_output(pio, pin, &out))
+               *config |= OUTPUT | (out << OUTPUT_VAL_SHIFT);
 
        return 0;
 }
@@ -907,6 +926,8 @@ static int at91_pinconf_set(struct pinctrl_dev *pctldev,
                if (config & PULL_UP && config & PULL_DOWN)
                        return -EINVAL;
 
+               at91_mux_set_output(pio, mask, config & OUTPUT,
+                                   (config & OUTPUT_VAL) >> OUTPUT_VAL_SHIFT);
                at91_mux_set_pullup(pio, mask, config & PULL_UP);
                at91_mux_set_multidrive(pio, mask, config & MULTI_DRIVE);
                if (info->ops->set_deglitch)
index bbca3d038900730a1f203eea2e15cb0ddcb19155..2732d6c0fb39ebd28ef4ec81d415fc0d0677c8e7 100644 (file)
@@ -15,6 +15,8 @@
 #define AT91_PINCTRL_DEGLITCH          (1 << 2)
 #define AT91_PINCTRL_PULL_DOWN         (1 << 3)
 #define AT91_PINCTRL_DIS_SCHMIT                (1 << 4)
+#define AT91_PINCTRL_OUTPUT            (1 << 7)
+#define AT91_PINCTRL_OUTPUT_VAL(x)     ((x & 0x1) << 8)
 #define AT91_PINCTRL_DEBOUNCE          (1 << 16)
 #define AT91_PINCTRL_DEBOUNCE_VAL(x)   (x << 17)