[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0b97adc3-4d77-480f-ace9-a53403c62216@gmail.com>
Date: Tue, 16 Sep 2025 07:48:03 +0300
From: Matti Vaittinen <mazziesaccount@...il.com>
To: Andy Shevchenko <andriy.shevchenko@...el.com>
Cc: Jonathan Cameron <jic23@...nel.org>, David Lechner
<dlechner@...libre.com>, Nuno Sá <nuno.sa@...log.com>,
Andy Shevchenko <andy@...nel.org>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley
<conor+dt@...nel.org>, Linus Walleij <linus.walleij@...aro.org>,
Bartosz Golaszewski <brgl@...ev.pl>, linux-iio@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-gpio@...r.kernel.org
Subject: Re: [PATCH v5 2/3] iio: adc: Support ROHM BD79112 ADC/GPIO
On 15/09/2025 17:12, Andy Shevchenko 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 can see you think so :) For me it doesn't look good. This is in-kernel
C-code not physics textbook. For the kernel C it has been convention to
_not_ use capital letters (or CamelCase) for variables. This convention
is strong enough reason for me to avoid mV in a variable name because
the capital letter instantly requires my attention and makes me need to
consider if this is "just a variable". What comes to the vref_mv, there
really are no true downside. It is clear what the _mv suffix denotes and
"there is no 'mv' in physics" is really an artificial problem.
>> + 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 am not really sure under what conditions this would fail. Without
taking a further look at that - then we just use unoptimized SPI
transfers(?). Could warrant a warning print though.
Thanks for taking a look at this again :)
Yours,
-- Matti
Powered by blists - more mailing lists