drivers: gpio: mcp23xxx: add support for reset pin

This allows the device to be reset to a known state before initialization.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
This commit is contained in:
Armin Brauns 2023-02-14 10:20:44 +01:00 committed by Carles Cufí
parent 07af23c1c6
commit 01e8b3445e
5 changed files with 27 additions and 0 deletions

View file

@ -93,6 +93,7 @@ static int mcp230xx_bus_is_ready(const struct device *dev)
.i2c = I2C_DT_SPEC_INST_GET(inst), \
}, \
.gpio_int = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \
.gpio_reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
.ngpios = DT_INST_PROP(inst, ngpios), \
.read_fn = mcp230xx_read_port_regs, \
.write_fn = mcp230xx_write_port_regs, \

View file

@ -133,6 +133,7 @@ static int mcp23sxx_bus_is_ready(const struct device *dev)
SPI_MODE_CPHA | SPI_WORD_SET(8), 0) \
}, \
.gpio_int = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \
.gpio_reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
.ngpios = DT_INST_PROP(inst, ngpios), \
.read_fn = mcp23sxx_read_port_regs, \
.write_fn = mcp23sxx_write_port_regs, \

View file

@ -23,6 +23,8 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(gpio_mcp23xxx);
#define MCP23XXX_RESET_TIME_US 1
/**
* @brief Reads given register from mcp23xxx.
*
@ -481,6 +483,23 @@ int gpio_mcp23xxx_init(const struct device *dev)
k_sem_init(&drv_data->lock, 0, 1);
/* If the RESET line is available, pulse it. */
if (config->gpio_reset.port) {
err = gpio_pin_configure_dt(&config->gpio_reset, GPIO_OUTPUT_ACTIVE);
if (err != 0) {
LOG_ERR("Failed to configure RESET line: %d", err);
return -EIO;
}
k_usleep(MCP23XXX_RESET_TIME_US);
err = gpio_pin_set_dt(&config->gpio_reset, 0);
if (err != 0) {
LOG_ERR("Failed to deactivate RESET line: %d", err);
return -EIO;
}
}
/* If the INT line is available, configure the callback for it. */
if (config->gpio_int.port) {
if (config->ngpios == 16) {

View file

@ -58,6 +58,7 @@ struct mcp23xxx_config {
} bus;
struct gpio_dt_spec gpio_int;
struct gpio_dt_spec gpio_reset;
uint8_t ngpios;
mcp23xxx_read_port_regs read_fn;

View file

@ -17,6 +17,11 @@ properties:
description: |
GPIO connected to the controller INT pin. This pin is active-low.
reset-gpios:
type: phandle-array
description: |
GPIO connected to the controller RESET pin. This pin is active-low.
ngpios:
type: int
enum: