From: Jonathan Cameron <jic23@kernel.org>
To: Guillaume Stols <gstols@baylibre.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Nuno Sa <nuno.sa@analog.com>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, dlechner@baylibre.com,
jstephan@baylibre.com, aardelean@baylibre.com,
adureghello@baylibre.com
Subject: Re: [PATCH v2 4/9] iio: adc: ad7606: Move software functions into common file
Date: Sun, 15 Dec 2024 11:51:08 +0000 [thread overview]
Message-ID: <20241215115108.558bb5a9@jic23-huawei> (raw)
In-Reply-To: <20241210-ad7606_add_iio_backend_software_mode-v2-4-6619c3e50d81@baylibre.com>
On Tue, 10 Dec 2024 10:46:44 +0000
Guillaume Stols <gstols@baylibre.com> wrote:
> Since the register are always the same, whatever bus is used, moving the
> software functions into the main file avoids the code to be duplicated
> in both SPI and parallel version of the driver.
>
> Signed-off-by: Guillaume Stols <gstols@baylibre.com>
Hi Guillaume,
Patch content is fine, but I'd ideally like you to take the opportunity to
tidy up some of the really inconsistent indentation in the code you are moving.
> int ad7616_write_scale_sw(struct iio_dev *indio_dev, int ch, int val)
> {
> struct ad7606_state *st = iio_priv(indio_dev);
> + unsigned int ch_addr, mode, ch_index;
>
> - st->sw_mode_en = st->bops->sw_mode_config &&
> - device_property_present(st->dev, "adi,sw-mode");
> - if (!st->sw_mode_en)
> - return 0;
> + /*
> + * Ad7616 has 16 channels divided in group A and group B.
> + * The range of channels from A are stored in registers with address 4
> + * while channels from B are stored in register with address 6.
> + * The last bit from channels determines if it is from group A or B
> + * because the order of channels in iio is 0A, 0B, 1A, 1B...
> + */
> + ch_index = ch >> 1;
> +
> + ch_addr = AD7616_RANGE_CH_ADDR(ch_index);
> +
> + if ((ch & 0x1) == 0) /* channel A */
> + ch_addr += AD7616_RANGE_CH_A_ADDR_OFF;
> + else /* channel B */
> + ch_addr += AD7616_RANGE_CH_B_ADDR_OFF;
> +
> + /* 0b01 for 2.5v, 0b10 for 5v and 0b11 for 10v */
> + mode = AD7616_RANGE_CH_MODE(ch_index, ((val + 1) & 0b11));
>
> - indio_dev->info = &ad7606_info_sw_mode;
> + return ad7606_write_mask(st, ch_addr, AD7616_RANGE_CH_MSK(ch_index),
> + mode);
Another odd indent to fix.
> +}
> +
> +static int ad7616_write_os_sw(struct iio_dev *indio_dev, int val)
> +{
> + struct ad7606_state *st = iio_priv(indio_dev);
> +
> + return ad7606_write_mask(st, AD7616_CONFIGURATION_REGISTER,
> + AD7616_OS_MASK, val << 2);
Trivial: Odd indentation choice.
> +}
> +
> +static int ad7606_write_scale_sw(struct iio_dev *indio_dev, int ch, int val)
> +{
> + struct ad7606_state *st = iio_priv(indio_dev);
> +
> + return ad7606_write_mask(st,
> + AD7606_RANGE_CH_ADDR(ch),
In general maybe aim for more consistent indentation choice. I'd pull this time up
on the line above.
> + AD7606_RANGE_CH_MSK(ch),
> + AD7606_RANGE_CH_MODE(ch, val));
> +}
> +
> +static int ad7606_write_os_sw(struct iio_dev *indio_dev, int val)
> +{
> + struct ad7606_state *st = iio_priv(indio_dev);
> +
> + return st->bops->reg_write(st, AD7606_OS_MODE, val);
> +}
> +
> +static int ad7616_sw_mode_setup(struct iio_dev *indio_dev)
> +{
> + struct ad7606_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + /*
> + * Scale can be configured individually for each channel
> + * in software mode.
> + */
> +
> + st->write_scale = ad7616_write_scale_sw;
> + st->write_os = &ad7616_write_os_sw;
> +
> + ret = st->bops->sw_mode_config(indio_dev);
> + if (ret)
> + return ret;
> +
> + /* Activate Burst mode and SEQEN MODE */
> + return ad7606_write_mask(st,
> + AD7616_CONFIGURATION_REGISTER,
Whilst moving the code, feel free to tidy up the indent for inconsistent
cases. Align this lot just after the opening bracket etc.
> + AD7616_BURST_MODE | AD7616_SEQEN_MODE,
> + AD7616_BURST_MODE | AD7616_SEQEN_MODE);
> +}
Thanks,
Jonathan
next prev parent reply other threads:[~2024-12-15 11:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 10:46 [PATCH v2 0/9] Add support for Software mode on AD7606's iio backend driver Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 1/9] iio: adc: ad7606: Fix hardcoded offset in the ADC channels Guillaume Stols
2024-12-14 18:26 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 2/9] dt-bindings: iio: dac: adi-axi-adc: Add ad7606 variant Guillaume Stols
2024-12-10 12:31 ` Rob Herring (Arm)
2024-12-11 22:01 ` David Lechner
2024-12-10 10:46 ` [PATCH v2 3/9] iio:adc: ad7606: Move the software mode configuration Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 4/9] iio: adc: ad7606: Move software functions into common file Guillaume Stols
2024-12-15 11:51 ` Jonathan Cameron [this message]
2024-12-10 10:46 ` [PATCH v2 5/9] iio: adc: adi-axi-adc: Add platform children support Guillaume Stols
2024-12-15 11:57 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 6/9] iio: adc: adi-axi-adc: Add support for AD7606 register writing Guillaume Stols
2024-12-15 12:05 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 7/9] iio: adc: ad7606: change r/w_register signature Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 8/9] iio: adc: ad7606: Change channel macros parameters Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 9/9] iio: adc: ad7606: Add support for writing registers when using backend Guillaume Stols
2024-12-15 12:12 ` 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=20241215115108.558bb5a9@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=aardelean@baylibre.com \
--cc=adureghello@baylibre.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=gstols@baylibre.com \
--cc=jstephan@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--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