From: Ley Foon Tan Date: Thu, 16 Aug 2018 13:46:30 +0800 Subject: [U-Boot] [PATCH v2] gpio: dwapb_gpio: Enable get_function support In-Reply-To: <1534398390-5249-1-git-send-email-ley.foon.tan@intel.com> References: <1534398390-5249-1-git-send-email-ley.foon.tan@intel.com> Message-ID: <1534398390-5249-2-git-send-email-ley.foon.tan@intel.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Enabled get_function support for dwapb where the function will return the state of GPIO port. Signed-off-by: Chin Liang See Signed-off-by: Ley Foon Tan --- v2: Change to use "if (gpio & BIT(offset))" bit masking. --- drivers/gpio/dwapb_gpio.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index 680b11a..7cf2d47 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -78,11 +78,25 @@ static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val) return 0; } +static int dwapb_gpio_get_function(struct udevice *dev, unsigned offset) +{ + struct gpio_dwapb_platdata *plat = dev_get_platdata(dev); + u32 gpio; + + gpio = readl(plat->base + GPIO_SWPORT_DDR(plat->bank)); + + if (gpio & BIT(offset)) + return GPIOF_OUTPUT; + else + return GPIOF_INPUT; +} + static const struct dm_gpio_ops gpio_dwapb_ops = { .direction_input = dwapb_gpio_direction_input, .direction_output = dwapb_gpio_direction_output, .get_value = dwapb_gpio_get_value, .set_value = dwapb_gpio_set_value, + .get_function = dwapb_gpio_get_function, }; static int gpio_dwapb_probe(struct udevice *dev) -- 2.2.2