Re: [PATCH v5 2/3] iio: adc: Support ROHM BD79112 ADC/GPIO

Jonathan Cameron
2025-09-16T08:02:17Z

On Tue, 16 Sep 2025 07:52:07 +0300
Matti Vaittinen <mazziesaccount@gmail.com> wrote:

> On 15/09/2025 23:13, Jonathan Cameron wrote:
> > On Mon, 15 Sep 2025 17:12:34 +0300
> > Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> >
> >> On Mon, Sep 15, 2025 at 10:12:43AM +0300, Matti Vaittinen wrote:
> >>> The ROHM BD79112 is an ADC/GPIO with 32 channels. The channel inputs can
> >>> be used as ADC or GPIO. Using the GPIOs as IRQ sources isn't supported.
> >>>
> >>> The ADC is 12-bit, supporting input voltages up to 5.7V, and separate I/O
> >>> voltage supply. Maximum SPI clock rate is 20 MHz (10 MHz with
> >>> daisy-chain configuration) and maximum sampling rate is 1MSPS.
> >>>
> >>> The IC does also support CRC but it is not implemented in the driver.
> >>
> >> ...
> >>
> >>> +static int bd79112_probe(struct spi_device *spi)
> >>> +{
> >>> + struct bd79112_data *data;
> >>> + struct iio_dev *iio_dev;
> >>> + struct iio_chan_spec *cs;
> >>> + struct device *dev = &spi->dev;
> >>> + unsigned long gpio_pins, pin;
> >>> + unsigned int i;
> >>> + int ret;
> >>> +
> >>> + iio_dev = devm_iio_device_alloc(dev, sizeof(*data));
> >>> + if (!iio_dev)
> >>> + return -ENOMEM;
> >>> +
> >>> + data = iio_priv(iio_dev);
> >>> + data->spi = spi;
> >>> + data->dev = dev;
> >>> + data->map = devm_regmap_init(dev, NULL, data, &bd79112_regmap);
> >>> + if (IS_ERR(data->map))
> >>> + return dev_err_probe(dev, PTR_ERR(data->map),
> >>> + "Failed to initialize Regmap\n");
> >>> +
> >>> + ret = devm_regulator_get_enable_read_voltage(dev, "vdd");
> >>> + if (ret < 0)
> >>> + return dev_err_probe(dev, ret, "Failed to get the Vdd\n");
> >>
> >>> + data->vref_mv = ret / 1000;
> >>
> >> I still think moving to _mV is the right thing to do.
> >> There is no 'mv' in the physics for Volts.
> >
> > I'm not disagreeing with this review but I'm also not going to hold a
> > driver back for that given timing is pretty much such that I merge it
> > today or it sits a cycle and this one is very near...
> > I'll get fussier on this once we have written up some guidance and may
> > well send a patch to modify existing recent cases like this one!
>
> As I replied to Andy, I am disagreeing with this. I hope we won't start
> renaming variables with capital letters :(
>
> >>
> >>> + ret = devm_regulator_get_enable(dev, "iovdd");
> >>> + if (ret < 0)
> >>> + return dev_err_probe(dev, ret, "Failed to enable I/O voltage\n");
> >>> +
> >>> + data->read_xfer[0].tx_buf = &data->read_tx[0];
> >>> + data->read_xfer[0].len = sizeof(data->read_tx);
> >>> + data->read_xfer[0].cs_change = 1;
> >>> + data->read_xfer[1].rx_buf = &data->read_rx;
> >>> + data->read_xfer[1].len = sizeof(data->read_rx);
> >>> + spi_message_init_with_transfers(&data->read_msg, data->read_xfer, 2);
> >>
> >>> + devm_spi_optimize_message(dev, spi, &data->read_msg);
> >>
> >> And if it fails?..
> > I've added the following and applied the series.
>
> Thanks!
>
> > Note I'm cutting this fine so if we get any build issues or similar
> > it might well get pushed back to next cycle yet!
> >
> > diff --git a/drivers/iio/adc/rohm-bd79112.c b/drivers/iio/adc/rohm-bd79112.c
> > index b406d4ee5411..d15e06c8b94d 100644
> > --- a/drivers/iio/adc/rohm-bd79112.c
> > +++ b/drivers/iio/adc/rohm-bd79112.c
> > @@ -454,12 +454,18 @@ static int bd79112_probe(struct spi_device *spi)
> > data->read_xfer[1].rx_buf = &data->read_rx;
> > data->read_xfer[1].len = sizeof(data->read_rx);
> > spi_message_init_with_transfers(&data->read_msg, data->read_xfer, 2);
> > - devm_spi_optimize_message(dev, spi, &data->read_msg);
> > + ret = devm_spi_optimize_message(dev, spi, &data->read_msg);
> > + if (ret < 0)
> > + return dev_err_probe(dev, ret,
> > + "Failed to optimize SPI read message\n");
> >
>
> I am not really sure under what conditions the
> devm_spi_optimize_message() could fail. It might be enough to print a
> warning and proceed, but I don't think returning is a problem either.

No. Don't proceed on an unexpected failure whatever it is. That's
storing up problems that may surface in a weird way later that is much
harder to debug.

Jonathan

>
> Thanks a lot for going an extra mile and taking care of this!
>
> Yours,
> -- Matti
>