From 97106bf95e51e2c119e3aec8e35e878b27670778 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Tue, 28 Jan 2020 16:55:38 -0600 Subject: [PATCH] drivers: modem: clean up pin configuration After startup ublox-sara-r4 code sets the MDM_POWER signal to input using a deprecated configuration macro. This was the only use of the modem context API to configure a pin. Refactor the API to not take the flags as an input but instead select between the flags to be used when the pin is active and a disconnected state. Use this API instead of a separate direct configure call when initializing the modem pins. Signed-off-by: Peter Bigot --- drivers/modem/modem_context.h | 6 +++--- drivers/modem/modem_pin.c | 9 ++++----- drivers/modem/ublox-sara-r4.c | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/modem/modem_context.h b/drivers/modem/modem_context.h index 3cf11593c0a..daafd2e83e7 100644 --- a/drivers/modem/modem_context.h +++ b/drivers/modem/modem_context.h @@ -51,8 +51,8 @@ struct modem_cmd_handler { struct modem_pin { struct device *gpio_port_dev; char *dev_name; - u32_t pin; - int init_flags; + gpio_pin_t pin; + gpio_flags_t init_flags; }; struct modem_context { @@ -128,7 +128,7 @@ int modem_context_register(struct modem_context *ctx); /* pin config functions */ int modem_pin_read(struct modem_context *ctx, u32_t pin); int modem_pin_write(struct modem_context *ctx, u32_t pin, u32_t value); -int modem_pin_config(struct modem_context *ctx, u32_t pin, int flags); +int modem_pin_config(struct modem_context *ctx, u32_t pin, bool enable); int modem_pin_init(struct modem_context *ctx); #ifdef __cplusplus diff --git a/drivers/modem/modem_pin.c b/drivers/modem/modem_pin.c index 3f71c093813..7d050d6529f 100644 --- a/drivers/modem/modem_pin.c +++ b/drivers/modem/modem_pin.c @@ -36,14 +36,15 @@ int modem_pin_write(struct modem_context *ctx, u32_t pin, u32_t value) ctx->pins[pin].pin, value); } -int modem_pin_config(struct modem_context *ctx, u32_t pin, int flags) +int modem_pin_config(struct modem_context *ctx, u32_t pin, bool enable) { if (pin < 0 || pin >= ctx->pins_len) { return -ENODEV; } return gpio_pin_configure(ctx->pins[pin].gpio_port_dev, - ctx->pins[pin].pin, flags); + ctx->pins[pin].pin, + enable ? cts->pins[pin].flags : GPIO_INPUT); } int modem_pin_init(struct modem_context *ctx) @@ -58,9 +59,7 @@ int modem_pin_init(struct modem_context *ctx) return -ENODEV; } - ret = gpio_pin_configure(ctx->pins[i].gpio_port_dev, - ctx->pins[i].pin, - ctx->pins[i].init_flags); + ret = modem_pin_config(ctx, i, true); if (ret < 0) { return ret; } diff --git a/drivers/modem/ublox-sara-r4.c b/drivers/modem/ublox-sara-r4.c index f153d79a83b..33ad16a2c08 100644 --- a/drivers/modem/ublox-sara-r4.c +++ b/drivers/modem/ublox-sara-r4.c @@ -679,7 +679,7 @@ static int pin_init(void) k_sleep(K_SECONDS(10)); #endif - modem_pin_config(&mctx, MDM_POWER, GPIO_DIR_IN); + modem_pin_config(&mctx, MDM_POWER, false); LOG_INF("... Done!");