Message ID | 20241021-ad7380-fix-supplies-v2-3-2ca551b3352a@baylibre.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | iio: adc: ad7380: fix several supplies issues | expand |
On Mon, 2024-10-21 at 12:00 +0200, Julien Stephan wrote: > vcc and vlogic are required but are not retrieved and enabled in the > probe. Add them. > > In order to prepare support for additional parts requiring different > supplies, add vcc and vlogic to the platform specific structures > > Signed-off-by: Julien Stephan <jstephan@baylibre.com> > --- One small not below... With that, Reviewed-by: Nuno Sa <nuno.sa@analog.com> > drivers/iio/adc/ad7380.c | 43 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 43 insertions(+) > > diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c > index > e033c734191143a25a490b09c730dbf95f796737..e257f78d63edd7910fcb936ec5344922f8e7 > 0b99 100644 > --- a/drivers/iio/adc/ad7380.c > +++ b/drivers/iio/adc/ad7380.c > @@ -75,6 +75,7 @@ > #define T_CONVERT_NS 190 /* conversion time */ > #define T_CONVERT_0_NS 10 /* 1st conversion start time > (oversampling) */ > #define T_CONVERT_X_NS 500 /* xth conversion start time > (oversampling) */ > +#define T_POWERUP_MS 5 /* Power up */ > > struct ad7380_timing_specs { > const unsigned int t_csh_ns; /* CS minimum high time */ > @@ -86,6 +87,8 @@ struct ad7380_chip_info { > unsigned int num_channels; > unsigned int num_simult_channels; > bool has_mux; > + const char * const *supplies; > + unsigned int num_supplies; > const char * const *vcm_supplies; > unsigned int num_vcm_supplies; > const unsigned long *available_scan_masks; > @@ -243,6 +246,10 @@ DEFINE_AD7380_8_CHANNEL(ad7386_4_channels, 16, 0, u); > DEFINE_AD7380_8_CHANNEL(ad7387_4_channels, 14, 0, u); > DEFINE_AD7380_8_CHANNEL(ad7388_4_channels, 12, 0, u); > > +static const char * const ad7380_supplies[] = { > + "vcc", "vlogic", > +}; > + > static const char * const ad7380_2_channel_vcm_supplies[] = { > "aina", "ainb", > }; > @@ -338,6 +345,8 @@ static const struct ad7380_chip_info ad7380_chip_info = { > .channels = ad7380_channels, > .num_channels = ARRAY_SIZE(ad7380_channels), > .num_simult_channels = 2, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .available_scan_masks = ad7380_2_channel_scan_masks, > .timing_specs = &ad7380_timing, > }; > @@ -347,6 +356,8 @@ static const struct ad7380_chip_info ad7381_chip_info = { > .channels = ad7381_channels, > .num_channels = ARRAY_SIZE(ad7381_channels), > .num_simult_channels = 2, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .available_scan_masks = ad7380_2_channel_scan_masks, > .timing_specs = &ad7380_timing, > }; > @@ -356,6 +367,8 @@ static const struct ad7380_chip_info ad7383_chip_info = { > .channels = ad7383_channels, > .num_channels = ARRAY_SIZE(ad7383_channels), > .num_simult_channels = 2, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .vcm_supplies = ad7380_2_channel_vcm_supplies, > .num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies), > .available_scan_masks = ad7380_2_channel_scan_masks, > @@ -367,6 +380,8 @@ static const struct ad7380_chip_info ad7384_chip_info = { > .channels = ad7384_channels, > .num_channels = ARRAY_SIZE(ad7384_channels), > .num_simult_channels = 2, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .vcm_supplies = ad7380_2_channel_vcm_supplies, > .num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies), > .available_scan_masks = ad7380_2_channel_scan_masks, > @@ -378,6 +393,8 @@ static const struct ad7380_chip_info ad7386_chip_info = { > .channels = ad7386_channels, > .num_channels = ARRAY_SIZE(ad7386_channels), > .num_simult_channels = 2, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .has_mux = true, > .available_scan_masks = ad7380_2x2_channel_scan_masks, > .timing_specs = &ad7380_timing, > @@ -388,6 +405,8 @@ static const struct ad7380_chip_info ad7387_chip_info = { > .channels = ad7387_channels, > .num_channels = ARRAY_SIZE(ad7387_channels), > .num_simult_channels = 2, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .has_mux = true, > .available_scan_masks = ad7380_2x2_channel_scan_masks, > .timing_specs = &ad7380_timing, > @@ -398,6 +417,8 @@ static const struct ad7380_chip_info ad7388_chip_info = { > .channels = ad7388_channels, > .num_channels = ARRAY_SIZE(ad7388_channels), > .num_simult_channels = 2, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .has_mux = true, > .available_scan_masks = ad7380_2x2_channel_scan_masks, > .timing_specs = &ad7380_timing, > @@ -408,6 +429,8 @@ static const struct ad7380_chip_info ad7380_4_chip_info = > { > .channels = ad7380_4_channels, > .num_channels = ARRAY_SIZE(ad7380_4_channels), > .num_simult_channels = 4, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .available_scan_masks = ad7380_4_channel_scan_masks, > .timing_specs = &ad7380_4_timing, > }; > @@ -417,6 +440,8 @@ static const struct ad7380_chip_info ad7381_4_chip_info = > { > .channels = ad7381_4_channels, > .num_channels = ARRAY_SIZE(ad7381_4_channels), > .num_simult_channels = 4, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .available_scan_masks = ad7380_4_channel_scan_masks, > .timing_specs = &ad7380_4_timing, > }; > @@ -426,6 +451,8 @@ static const struct ad7380_chip_info ad7383_4_chip_info = > { > .channels = ad7383_4_channels, > .num_channels = ARRAY_SIZE(ad7383_4_channels), > .num_simult_channels = 4, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .vcm_supplies = ad7380_4_channel_vcm_supplies, > .num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies), > .available_scan_masks = ad7380_4_channel_scan_masks, > @@ -437,6 +464,8 @@ static const struct ad7380_chip_info ad7384_4_chip_info = > { > .channels = ad7384_4_channels, > .num_channels = ARRAY_SIZE(ad7384_4_channels), > .num_simult_channels = 4, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .vcm_supplies = ad7380_4_channel_vcm_supplies, > .num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies), > .available_scan_masks = ad7380_4_channel_scan_masks, > @@ -448,6 +477,8 @@ static const struct ad7380_chip_info ad7386_4_chip_info = > { > .channels = ad7386_4_channels, > .num_channels = ARRAY_SIZE(ad7386_4_channels), > .num_simult_channels = 4, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .has_mux = true, > .available_scan_masks = ad7380_2x4_channel_scan_masks, > .timing_specs = &ad7380_4_timing, > @@ -458,6 +489,8 @@ static const struct ad7380_chip_info ad7387_4_chip_info = > { > .channels = ad7387_4_channels, > .num_channels = ARRAY_SIZE(ad7387_4_channels), > .num_simult_channels = 4, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .has_mux = true, > .available_scan_masks = ad7380_2x4_channel_scan_masks, > .timing_specs = &ad7380_4_timing, > @@ -468,6 +501,8 @@ static const struct ad7380_chip_info ad7388_4_chip_info = > { > .channels = ad7388_4_channels, > .num_channels = ARRAY_SIZE(ad7388_4_channels), > .num_simult_channels = 4, > + .supplies = ad7380_supplies, > + .num_supplies = ARRAY_SIZE(ad7380_supplies), > .has_mux = true, > .available_scan_masks = ad7380_2x4_channel_scan_masks, > .timing_specs = &ad7380_4_timing, > @@ -1004,6 +1039,14 @@ static int ad7380_probe(struct spi_device *spi) > if (!st->chip_info) > return dev_err_probe(&spi->dev, -EINVAL, "missing match > data\n"); > > + ret = devm_regulator_bulk_get_enable(&spi->dev, st->chip_info- > >num_supplies, > + st->chip_info->supplies); > + > + if (ret) > + return dev_err_probe(&spi->dev, ret, > + "Failed to enable power supplies\n"); > + msleep(T_POWERUP_MS); T_POWERUP_MS is 5ms so msleep() is not the advised API to use. In order to have not to think about it, use fsleep(). This came up recently and this is one of the reasons why I think (in most common cases at least) using fsleep() is a good practise even if we already know which function we need to call. Also makes reviewers lives easier as we don't have to double check the time being slept. - Nuno Sá
diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c index e033c734191143a25a490b09c730dbf95f796737..e257f78d63edd7910fcb936ec5344922f8e70b99 100644 --- a/drivers/iio/adc/ad7380.c +++ b/drivers/iio/adc/ad7380.c @@ -75,6 +75,7 @@ #define T_CONVERT_NS 190 /* conversion time */ #define T_CONVERT_0_NS 10 /* 1st conversion start time (oversampling) */ #define T_CONVERT_X_NS 500 /* xth conversion start time (oversampling) */ +#define T_POWERUP_MS 5 /* Power up */ struct ad7380_timing_specs { const unsigned int t_csh_ns; /* CS minimum high time */ @@ -86,6 +87,8 @@ struct ad7380_chip_info { unsigned int num_channels; unsigned int num_simult_channels; bool has_mux; + const char * const *supplies; + unsigned int num_supplies; const char * const *vcm_supplies; unsigned int num_vcm_supplies; const unsigned long *available_scan_masks; @@ -243,6 +246,10 @@ DEFINE_AD7380_8_CHANNEL(ad7386_4_channels, 16, 0, u); DEFINE_AD7380_8_CHANNEL(ad7387_4_channels, 14, 0, u); DEFINE_AD7380_8_CHANNEL(ad7388_4_channels, 12, 0, u); +static const char * const ad7380_supplies[] = { + "vcc", "vlogic", +}; + static const char * const ad7380_2_channel_vcm_supplies[] = { "aina", "ainb", }; @@ -338,6 +345,8 @@ static const struct ad7380_chip_info ad7380_chip_info = { .channels = ad7380_channels, .num_channels = ARRAY_SIZE(ad7380_channels), .num_simult_channels = 2, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .available_scan_masks = ad7380_2_channel_scan_masks, .timing_specs = &ad7380_timing, }; @@ -347,6 +356,8 @@ static const struct ad7380_chip_info ad7381_chip_info = { .channels = ad7381_channels, .num_channels = ARRAY_SIZE(ad7381_channels), .num_simult_channels = 2, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .available_scan_masks = ad7380_2_channel_scan_masks, .timing_specs = &ad7380_timing, }; @@ -356,6 +367,8 @@ static const struct ad7380_chip_info ad7383_chip_info = { .channels = ad7383_channels, .num_channels = ARRAY_SIZE(ad7383_channels), .num_simult_channels = 2, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .vcm_supplies = ad7380_2_channel_vcm_supplies, .num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies), .available_scan_masks = ad7380_2_channel_scan_masks, @@ -367,6 +380,8 @@ static const struct ad7380_chip_info ad7384_chip_info = { .channels = ad7384_channels, .num_channels = ARRAY_SIZE(ad7384_channels), .num_simult_channels = 2, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .vcm_supplies = ad7380_2_channel_vcm_supplies, .num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies), .available_scan_masks = ad7380_2_channel_scan_masks, @@ -378,6 +393,8 @@ static const struct ad7380_chip_info ad7386_chip_info = { .channels = ad7386_channels, .num_channels = ARRAY_SIZE(ad7386_channels), .num_simult_channels = 2, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .has_mux = true, .available_scan_masks = ad7380_2x2_channel_scan_masks, .timing_specs = &ad7380_timing, @@ -388,6 +405,8 @@ static const struct ad7380_chip_info ad7387_chip_info = { .channels = ad7387_channels, .num_channels = ARRAY_SIZE(ad7387_channels), .num_simult_channels = 2, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .has_mux = true, .available_scan_masks = ad7380_2x2_channel_scan_masks, .timing_specs = &ad7380_timing, @@ -398,6 +417,8 @@ static const struct ad7380_chip_info ad7388_chip_info = { .channels = ad7388_channels, .num_channels = ARRAY_SIZE(ad7388_channels), .num_simult_channels = 2, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .has_mux = true, .available_scan_masks = ad7380_2x2_channel_scan_masks, .timing_specs = &ad7380_timing, @@ -408,6 +429,8 @@ static const struct ad7380_chip_info ad7380_4_chip_info = { .channels = ad7380_4_channels, .num_channels = ARRAY_SIZE(ad7380_4_channels), .num_simult_channels = 4, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .available_scan_masks = ad7380_4_channel_scan_masks, .timing_specs = &ad7380_4_timing, }; @@ -417,6 +440,8 @@ static const struct ad7380_chip_info ad7381_4_chip_info = { .channels = ad7381_4_channels, .num_channels = ARRAY_SIZE(ad7381_4_channels), .num_simult_channels = 4, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .available_scan_masks = ad7380_4_channel_scan_masks, .timing_specs = &ad7380_4_timing, }; @@ -426,6 +451,8 @@ static const struct ad7380_chip_info ad7383_4_chip_info = { .channels = ad7383_4_channels, .num_channels = ARRAY_SIZE(ad7383_4_channels), .num_simult_channels = 4, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .vcm_supplies = ad7380_4_channel_vcm_supplies, .num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies), .available_scan_masks = ad7380_4_channel_scan_masks, @@ -437,6 +464,8 @@ static const struct ad7380_chip_info ad7384_4_chip_info = { .channels = ad7384_4_channels, .num_channels = ARRAY_SIZE(ad7384_4_channels), .num_simult_channels = 4, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .vcm_supplies = ad7380_4_channel_vcm_supplies, .num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies), .available_scan_masks = ad7380_4_channel_scan_masks, @@ -448,6 +477,8 @@ static const struct ad7380_chip_info ad7386_4_chip_info = { .channels = ad7386_4_channels, .num_channels = ARRAY_SIZE(ad7386_4_channels), .num_simult_channels = 4, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .has_mux = true, .available_scan_masks = ad7380_2x4_channel_scan_masks, .timing_specs = &ad7380_4_timing, @@ -458,6 +489,8 @@ static const struct ad7380_chip_info ad7387_4_chip_info = { .channels = ad7387_4_channels, .num_channels = ARRAY_SIZE(ad7387_4_channels), .num_simult_channels = 4, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .has_mux = true, .available_scan_masks = ad7380_2x4_channel_scan_masks, .timing_specs = &ad7380_4_timing, @@ -468,6 +501,8 @@ static const struct ad7380_chip_info ad7388_4_chip_info = { .channels = ad7388_4_channels, .num_channels = ARRAY_SIZE(ad7388_4_channels), .num_simult_channels = 4, + .supplies = ad7380_supplies, + .num_supplies = ARRAY_SIZE(ad7380_supplies), .has_mux = true, .available_scan_masks = ad7380_2x4_channel_scan_masks, .timing_specs = &ad7380_4_timing, @@ -1004,6 +1039,14 @@ static int ad7380_probe(struct spi_device *spi) if (!st->chip_info) return dev_err_probe(&spi->dev, -EINVAL, "missing match data\n"); + ret = devm_regulator_bulk_get_enable(&spi->dev, st->chip_info->num_supplies, + st->chip_info->supplies); + + if (ret) + return dev_err_probe(&spi->dev, ret, + "Failed to enable power supplies\n"); + msleep(T_POWERUP_MS); + /* * If there is no REFIO supply, then it means that we are using * the internal 2.5V reference, otherwise REFIO is reference voltage.
vcc and vlogic are required but are not retrieved and enabled in the probe. Add them. In order to prepare support for additional parts requiring different supplies, add vcc and vlogic to the platform specific structures Signed-off-by: Julien Stephan <jstephan@baylibre.com> --- drivers/iio/adc/ad7380.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)