Signed-off-by: Tomaz Solc <tomaz.solc@xxxxxxxxxx> --- drivers/pinctrl/pinctrl-mcp23s08.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c index bccebe43dd6a..764c93dfd277 100644 --- a/drivers/pinctrl/pinctrl-mcp23s08.c +++ b/drivers/pinctrl/pinctrl-mcp23s08.c @@ -339,6 +339,29 @@ mcp23s08_direction_output(struct gpio_chip *chip, unsigned offset, int value) return status; } +static int +mcp23s08_get_direction(struct gpio_chip *chip, unsigned offset) +{ + struct mcp23s08 *mcp = gpiochip_get_data(chip); + unsigned mask = BIT(offset); + int status, ret; + + mutex_lock(&mcp->lock); + + ret = mcp_read(mcp, MCP_IODIR, &status); + if (ret == 0) { + if(status & mask) { + ret = GPIO_LINE_DIRECTION_IN; + } else { + ret = GPIO_LINE_DIRECTION_OUT; + } + } + + mutex_unlock(&mcp->lock); + + return ret; +} + /*----------------------------------------------------------------------*/ static irqreturn_t mcp23s08_irq(int irq, void *data) { @@ -545,6 +568,7 @@ int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, mcp->irq_chip.irq_bus_lock = mcp23s08_irq_bus_lock; mcp->irq_chip.irq_bus_sync_unlock = mcp23s08_irq_bus_unlock; + mcp->chip.get_direction = mcp23s08_get_direction; mcp->chip.direction_input = mcp23s08_direction_input; mcp->chip.get = mcp23s08_get; mcp->chip.direction_output = mcp23s08_direction_output; -- 2.20.1