[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8ad18de5-53cd-49ba-8e84-1e8c7e5bd627@baylibre.com>
Date: Mon, 15 Dec 2025 10:36:08 -0600
From: David Lechner <dlechner@...libre.com>
To: Ajith Anandhan <ajithanandhan0406@...il.com>, jic23@...nel.org
Cc: nuno.sa@...log.com, andy@...nel.org, robh@...nel.org, krzk+dt@...nel.org,
conor+dt@...nel.org, linux-iio@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 2/2] iio: adc: Add support for TI ADS1120
On 12/15/25 10:13 AM, Ajith Anandhan wrote:
> On 11/18/25 7:34 PM, David Lechner wrote:
>> On 11/9/25 8:11 AM, Ajith Anandhan wrote:
>>> Add driver for the Texas Instruments ADS1120, a precision 16-bit
>>> analog-to-digital converter with an SPI interface.
>>>
>> ...
>>
>>> +#define ADS1120_CFG0_GAIN_MASK GENMASK(3, 1)
>>> +#define ADS1120_CFG0_GAIN_1 0
>>> +#define ADS1120_CFG0_GAIN_2 1
>>> +#define ADS1120_CFG0_GAIN_4 2
>>> +#define ADS1120_CFG0_GAIN_8 3
>>> +#define ADS1120_CFG0_GAIN_16 4
>>> +#define ADS1120_CFG0_GAIN_32 5
>>> +#define ADS1120_CFG0_GAIN_64 6
>>> +#define ADS1120_CFG0_GAIN_128 7
>> We could avoid these macros by just doing ilog2(gain).
>
>
> I understand your concern about unused macros. I've kept them for documentation purposes as they map directly to the datasheet register definitions, which makes it easier to verify correctness against hardware specs also I'd prefer to keep it like this since it give more readability Shall i keep this as it is for this initial version?
I would argue that if they aren't being used then omitting them would
save us the time of having to verify the correctness in the first place.
>>> +static int ads1120_set_gain(struct ads1120_state *st, int gain_val)
>>> +{
>>> + int i;
>>> +
>>> + for (i = 0; i < ARRAY_SIZE(ads1120_gain_values); i++) {
>>> + if (ads1120_gain_values[i] == gain_val)
>>> + break;
>>> + }
>>> +
>>> + if (i == ARRAY_SIZE(ads1120_gain_values))
>>> + return -EINVAL;
>> Since there is only one gain register, we should store this in a
>> per-channel variable, then set the gain in the register in
>> ads1120_set_mux() instead (and it would make sense to rename
>> that function as well to something like ads1120_configure_channel()).
>
>
> I've implemented a global gain that applies to all channels for simplicity. I planed to add
>
> per-channel gain storage in the later patches.
>
OK. Just mention this in the commit message.
>>> +/* Regmap write function for ADS1120 */
>>> +static int ads1120_regmap_write(void *context, const void *data, size_t count)
>>> +{
>>> + struct ads1120_state *st = context;
>>> + const u8 *buf = data;
>>> +
>>> + if (count != 2)
>>> + return -EINVAL;
>>> +
>>> + /* WREG command: 0100rr00 where rr is register address */
>>> + st->data[0] = ADS1120_CMD_WREG | (buf[0] << 2);
>>> + st->data[1] = buf[1];
>>> +
>>> + return spi_write(st->spi, st->data, 2);
>>> +}
>> I don't see anyting unusal about these read/write functions. We should
>> be able to use the existing spi_regmap with the proper configuration
>> instead of making a custom regmap_bus.
>
>
> The ADS1120 needs register address shifted by 2 bits
> in command byte (reg << 2). I couldn't find a way to do this with standard
> SPI regmap. If there's a configuration I'm missing, please point me to it and I'll gladly simplify.
>
>
I think you are looking for reg_shift in struct regmap_config.
Powered by blists - more mailing lists