mcp23s08: add get_direction and PIN_CONFIG_OUTPUT support.
Subsystems (3)
cover mcp23s08: add get_direction and PIN_CONFIG_OUTPUT support.
Motivation for these two patches is setting mcp23s08 outputs on boot from the device tree.
gpio-hog was already functional with mcp23s08, however libgpio incorrectly showed pins with output-high or output-low hogs as inputs since the driver did not implement gpio_chip->get_direction().
Many other drivers also support setting pins to output-high or output-low via pinmux. In contrast to gpio-hog, using pinmux to set the pin state on boot allows the state to be changed later from user space. mcp23s08 did not support this since PIN_CONFIG_OUTPUT was not implemented in pinconf_ops->pin_config_set().
One issue with the second patch is that pins set to output-high or output-low via pinmux still show up as inputs in libgpio after boot. This is because the pin direction gets cached in gpio_desc.flags in devm_gpiochip_add_data(). However output-high/-low in pimux only gets applied after that. I am not sure what would be the best approach to fix this.
Tomaz Solc (2):
pinctrl: mcp23s08: implement get_direction()
pinctrl: mcp23s08: support for PIN_CONFIG_OUTPUT.
.../bindings/pinctrl/pinctrl-mcp23s08.txt | 12 ++-- drivers/pinctrl/pinctrl-mcp23s08.c | 72 ++++++++++++++++--- 2 files changed, 68 insertions(+), 16 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/2 pinctrl: mcp23s08: implement get_direction()
--- drivers/pinctrl/pinctrl-mcp23s08.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/pinctrl/pinctrl-mcp23s08.c +24 -0
@@ -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;
Signature · 1 line
2.20.1
PATCH 2/2 pinctrl: mcp23s08: support for PIN_CONFIG_OUTPUT.
In reply to Tomaz SolcAdds support for setting mcp23s08 pins to output-high or output-low via pinmux in the device tree.
--- .../bindings/pinctrl/pinctrl-mcp23s08.txt | 12 ++-- drivers/pinctrl/pinctrl-mcp23s08.c | 58 ++++++++++++++----- 2 files changed, 49 insertions(+), 21 deletions(-)
Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt +7 -5
@@ -88,11 +88,11 @@ gpiom1: gpio@0 { spi-max-frequency = <1000000>; }; -Pull-up configuration -===================== +Pin configuration +================= -If pins are used as output, they can also be configured with pull-ups. This is -done with pinctrl. +If pins are used as inputs, they can also be configured with pull-ups. Pins +used as outputs can have their default states set. This is done with pinctrl. Please refer file <devicetree/bindings/pinctrl/pinctrl-bindings.txt> for details of the common pinctrl bindings used by client devices,
@@ -121,8 +121,10 @@ The following optional property is defined in the pinmux DT binding document <pinctrl-bindings.txt>. Absence of this property will leave the configuration in its default state. bias-pull-up + output-high + output-low -Example with pinctrl to pull-up output pins: +Example with pinctrl to pull-up input pins: gpio21: gpio@21 { compatible = "microchip,mcp23017"; gpio-controller;
drivers/pinctrl/pinctrl-mcp23s08.c +42 -16
99 lines not on this page · raw message
Signature · 1 line
2.20.1