Skip to content

Commit 3459b35

Browse files
committed
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 <[email protected]>
1 parent 625dae5 commit 3459b35

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

drivers/modem/modem_context.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ struct modem_cmd_handler {
5151
struct modem_pin {
5252
struct device *gpio_port_dev;
5353
char *dev_name;
54-
u32_t pin;
55-
int init_flags;
54+
gpio_pin_t pin;
55+
gpio_flags_t init_flags;
5656
};
5757

5858
struct modem_context {
@@ -128,7 +128,7 @@ int modem_context_register(struct modem_context *ctx);
128128
/* pin config functions */
129129
int modem_pin_read(struct modem_context *ctx, u32_t pin);
130130
int modem_pin_write(struct modem_context *ctx, u32_t pin, u32_t value);
131-
int modem_pin_config(struct modem_context *ctx, u32_t pin, int flags);
131+
int modem_pin_config(struct modem_context *ctx, u32_t pin, bool enable);
132132
int modem_pin_init(struct modem_context *ctx);
133133

134134
#ifdef __cplusplus

drivers/modem/modem_pin.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ int modem_pin_write(struct modem_context *ctx, u32_t pin, u32_t value)
3636
ctx->pins[pin].pin, value);
3737
}
3838

39-
int modem_pin_config(struct modem_context *ctx, u32_t pin, int flags)
39+
int modem_pin_config(struct modem_context *ctx, u32_t pin, bool enable)
4040
{
41+
gpio_flags_t flags = GPIO_DISCONNECTED;
42+
4143
if (pin < 0 || pin >= ctx->pins_len) {
4244
return -ENODEV;
4345
}
4446

47+
if (enable) {
48+
flags = ctx->pins[pin].init_flags;
49+
}
50+
4551
return gpio_pin_configure(ctx->pins[pin].gpio_port_dev,
4652
ctx->pins[pin].pin, flags);
4753
}
@@ -58,9 +64,7 @@ int modem_pin_init(struct modem_context *ctx)
5864
return -ENODEV;
5965
}
6066

61-
ret = gpio_pin_configure(ctx->pins[i].gpio_port_dev,
62-
ctx->pins[i].pin,
63-
ctx->pins[i].init_flags);
67+
ret = modem_pin_config(ctx, i, true);
6468
if (ret < 0) {
6569
return ret;
6670
}

drivers/modem/ublox-sara-r4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ static int pin_init(void)
680680
k_sleep(K_SECONDS(10));
681681
#endif
682682

683-
modem_pin_config(&mctx, MDM_POWER, GPIO_DIR_IN);
683+
modem_pin_config(&mctx, MDM_POWER, false);
684684

685685
LOG_INF("... Done!");
686686

0 commit comments

Comments
 (0)