[RFC PATCH 3/5] gnss: ubx: 'vcc' can be optional

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

There are devices where 'vcc' is always on. The reset pin is used for
silencing the chip. Make the 'vcc' regulator optional.

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

diff --git a/drivers/gnss/ubx.c b/drivers/gnss/ubx.c
index c8d027973b85..d5281bfae9cb 100644
--- a/drivers/gnss/ubx.c
+++ b/drivers/gnss/ubx.c
@@ -25,9 +25,11 @@ static int ubx_set_active(struct gnss_serial *gserial)
struct ubx_data *data = gnss_serial_get_drvdata(gserial);
int ret;

- ret = regulator_enable(data->vcc);
- if (ret)
- return ret;
+ if (data->vcc) {
+ ret = regulator_enable(data->vcc);
+ if (ret)
+ return ret;
+ }

return 0;
}
@@ -37,9 +39,11 @@ static int ubx_set_standby(struct gnss_serial *gserial)
struct ubx_data *data = gnss_serial_get_drvdata(gserial);
int ret;

- ret = regulator_disable(data->vcc);
- if (ret)
- return ret;
+ if (data->vcc) {
+ ret = regulator_disable(data->vcc);
+ if (ret)
+ return ret;
+ }

return 0;
}
@@ -99,10 +103,13 @@ static int ubx_probe(struct serdev_device *serdev)

data = gnss_serial_get_drvdata(gserial);

- data->vcc = devm_regulator_get(&serdev->dev, "vcc");
+ data->vcc = devm_regulator_get_optional(&serdev->dev, "vcc");
if (IS_ERR(data->vcc)) {
ret = PTR_ERR(data->vcc);
- goto err_free_gserial;
+ if (ret == -ENODEV)
+ data->vcc = NULL;
+ else
+ goto err_free_gserial;
}

ret = devm_regulator_get_enable_optional(&serdev->dev, info->v_bckp_name);
--
2.35.1