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

Wolfram Sang posted 5 patches 2 years, 8 months ago
There is a newer version of this series
[RFC PATCH 4/5] gnss: ubx: add support for the reset gpio
Posted by Wolfram Sang 2 years, 8 months ago
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
Re: [RFC PATCH 4/5] gnss: ubx: add support for the reset gpio
Posted by Johan Hovold 2 years, 7 months ago
On Tue, May 23, 2023 at 08:43:09AM +0200, Wolfram Sang wrote:
> Tested with a Renesas KingFisher board. The chip correctly disappears
> from the I2C bus when the 'gnss0' device is not opened.

What do you mean by "disappears from the I2C bus"?

Does this device support both I2C and UART?

Johan
Re: [RFC PATCH 4/5] gnss: ubx: add support for the reset gpio
Posted by Wolfram Sang 2 years, 7 months ago
> > Tested with a Renesas KingFisher board. The chip correctly disappears
> > from the I2C bus when the 'gnss0' device is not opened.
> 
> What do you mean by "disappears from the I2C bus"?
> 
> Does this device support both I2C and UART?

Yes, and on my board, both are wired.

Re: [RFC PATCH 4/5] gnss: ubx: add support for the reset gpio
Posted by Johan Hovold 2 years, 7 months ago
On Tue, Jun 20, 2023 at 11:06:33AM +0200, Wolfram Sang wrote:
> 
> > > Tested with a Renesas KingFisher board. The chip correctly disappears
> > > from the I2C bus when the 'gnss0' device is not opened.
> > 
> > What do you mean by "disappears from the I2C bus"?
> > 
> > Does this device support both I2C and UART?
> 
> Yes, and on my board, both are wired.

Ah, yes, it was ublox device.

But can you elaborate on the "disappearing" bit? How exactly does it
"disappear" when the gnss0 device is *not* opened?

Johan
Re: [RFC PATCH 4/5] gnss: ubx: add support for the reset gpio
Posted by Wolfram Sang 2 years, 7 months ago
> But can you elaborate on the "disappearing" bit? How exactly does it
> "disappear" when the gnss0 device is *not* opened?

When you send an I2C message with the address of the device, it usually
ACKs it to say "Hi, I am here". When the ublox device is in reset state,
it does not ACK its address. So, tools like "i2cdetect" will not report
the device as "someone is listening there".

Here is the i2cdetect output with the GNSS device open:

# i2cdetect -y -r 15
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: 10 -- -- -- -- -- -- -- -- -- -- -- -- 1d -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- 42 -- -- -- -- -- -- -- -- -- -- -- -- UU 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- 6b -- -- -- -- 
70: -- UU -- -- UU UU -- --                         

And with the device closed. Note address 0x42 disappearing:

# i2cdetect -y -r 15
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: 10 -- -- -- -- -- -- -- -- -- -- -- -- 1d -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- UU 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- 6b -- -- -- -- 
70: -- UU -- -- UU UU -- --                         

Re: [RFC PATCH 4/5] gnss: ubx: add support for the reset gpio
Posted by Johan Hovold 2 years, 7 months ago
On Tue, Jun 20, 2023 at 11:41:39AM +0200, Wolfram Sang wrote:
> 
> > But can you elaborate on the "disappearing" bit? How exactly does it
> > "disappear" when the gnss0 device is *not* opened?
> 
> When you send an I2C message with the address of the device, it usually
> ACKs it to say "Hi, I am here". When the ublox device is in reset state,
> it does not ACK its address. So, tools like "i2cdetect" will not report
> the device as "someone is listening there".

Ah, ok, so you used it to verify that reset is working as intended.

Rereading the commit message now it makes more sense, I guess I was
thrown off by the reference to I2C. Perhaps adding a sentence or two
about the alternate interface and using it as a means of verification
would make things a bit more clear.

Johan
Re: [RFC PATCH 4/5] gnss: ubx: add support for the reset gpio
Posted by Wolfram Sang 2 years, 7 months ago
> Rereading the commit message now it makes more sense, I guess I was
> thrown off by the reference to I2C. Perhaps adding a sentence or two
> about the alternate interface and using it as a means of verification
> would make things a bit more clear.

Will do!