[RFC PATCH 4/5] gnss: ubx: add support for the reset gpio

Wolfram Sang
2023-05-23T06:43:46Z

Tested with a Renesas KingFisher board. The chip correctly disappears
from the I2C bus when the 'gnss0' device is not opened.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/gnss/ubx.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/drivers/gnss/ubx.c b/drivers/gnss/ubx.c
index d5281bfae9cb..be393b123d9a 100644
--- a/drivers/gnss/ubx.c
+++ b/drivers/gnss/ubx.c
@@ -7,6 +7,7 @@

#include <linux/errno.h>
#include <linux/gnss.h>
+#include <linux/gpio/consumer.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
@@ -18,6 +19,7 @@

struct ubx_data {
struct regulator *vcc;
+ struct gpio_desc *reset_gpio;
};

static int ubx_set_active(struct gnss_serial *gserial)
@@ -31,6 +33,8 @@ static int ubx_set_active(struct gnss_serial *gserial)
return ret;
}

+ gpiod_set_value_cansleep(data->reset_gpio, 0);
+
return 0;
}

@@ -45,6 +49,8 @@ static int ubx_set_standby(struct gnss_serial *gserial)
return ret;
}

+ gpiod_set_value_cansleep(data->reset_gpio, 1);
+
return 0;
}

@@ -116,6 +122,11 @@ static int ubx_probe(struct serdev_device *serdev)
if (ret < 0 && ret != -ENODEV)
goto err_free_gserial;

+ /* Start with reset asserted (GPIO must be active low!) */
+ data->reset_gpio = devm_gpiod_get_optional(&serdev->dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(data->reset_gpio))
+ return PTR_ERR(data->reset_gpio);
+
ret = gnss_serial_register(gserial);
if (ret)
goto err_free_gserial;
--
2.35.1