Linux IIO development
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: Ajith Anandhan <ajithanandhan0406@gmail.com>, jic23@kernel.org
Cc: nuno.sa@analog.com, andy@kernel.org, robh@kernel.org,
	krzk+dt@kernel.org, conor+dt@kernel.org,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] iio: adc: Add support for TI ADS1120
Date: Mon, 15 Dec 2025 10:36:08 -0600	[thread overview]
Message-ID: <8ad18de5-53cd-49ba-8e84-1e8c7e5bd627@baylibre.com> (raw)
In-Reply-To: <8e2c73ca-3746-4b2a-9d85-c12b51a69059@gmail.com>

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.


  reply	other threads:[~2025-12-15 16:36 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-09 14:11 [PATCH v2 0/2] iio: adc: ti-ads1120: Add driver and dt-binding Ajith Anandhan
2025-11-09 14:11 ` [PATCH v2 1/2] dt-bindings: iio: adc: Add TI ADS1120 binding Ajith Anandhan
2025-11-10  7:59   ` Krzysztof Kozlowski
2025-11-15 18:31   ` Jonathan Cameron
2025-11-18  0:19     ` David Lechner
2025-12-15 14:49       ` Ajith Anandhan
2025-12-15 15:58         ` David Lechner
2025-11-09 14:11 ` [PATCH v2 2/2] iio: adc: Add support for TI ADS1120 Ajith Anandhan
2025-11-09 17:03   ` Andy Shevchenko
2025-11-09 17:05     ` Andy Shevchenko
2025-11-10 10:17   ` kernel test robot
2025-11-15 18:45   ` Jonathan Cameron
2025-11-18 14:04   ` David Lechner
2025-12-15 16:13     ` Ajith Anandhan
2025-12-15 16:36       ` David Lechner [this message]
2025-12-15 16:49         ` Ajith Anandhan
2025-12-15 17:00           ` Andy Shevchenko
2025-12-15 17:38             ` Ajith Anandhan
2025-12-15 17:42           ` David Lechner
2025-12-15 17:50             ` Ajith Anandhan
2025-12-21 18:57             ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ad18de5-53cd-49ba-8e84-1e8c7e5bd627@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=ajithanandhan0406@gmail.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox