From: Jonathan Cameron <jic23@kernel.org>
To: Claudiu <claudiu.beznea@tuxon.dev>
Cc: prabhakar.mahadev-lad.rj@bp.renesas.com, lars@metafoo.de,
robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
geert+renesas@glider.be, magnus.damm@gmail.com,
mturquette@baylibre.com, sboyd@kernel.org,
p.zabel@pengutronix.de, linux-iio@vger.kernel.org,
linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org,
Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Subject: Re: [PATCH 09/14] iio: adc: rzg2l_adc: Add support for channel 8
Date: Tue, 3 Dec 2024 20:18:57 +0000 [thread overview]
Message-ID: <20241203201857.7ccdcf99@jic23-huawei> (raw)
In-Reply-To: <20241203111314.2420473-10-claudiu.beznea.uj@bp.renesas.com>
On Tue, 3 Dec 2024 13:13:09 +0200
Claudiu <claudiu.beznea@tuxon.dev> wrote:
> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
>
> The ADC on the Renesas RZ/G3S SoC includes an additional channel (channel
> 8) dedicated to reading temperature values from the Thermal Sensor Unit
> (TSU). There is a direct in-SoC connection between the ADC and TSU IPs.
>
> To read the temperature reported by the TSU, a different sampling rate
> (compared to channels 0-7) must be configured in the ADM3 register.
>
> The rzg2l_adc driver has been updated to support reading the TSU
> temperature.
>
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> static unsigned int rzg2l_adc_readl(struct rzg2l_adc *adc, u32 reg)
> @@ -161,7 +173,7 @@ static void rzg2l_set_trigger(struct rzg2l_adc *adc)
> rzg2l_adc_writel(adc, RZG2L_ADM(1), reg);
> }
>
> -static int rzg2l_adc_conversion_setup(struct rzg2l_adc *adc, u8 ch)
> +static int rzg2l_adc_conversion_setup(struct rzg2l_adc *adc, u8 ch, enum iio_chan_type type)
> {
> const struct rzg2l_adc_hw_params *hw_params = adc->hw_params;
> u32 reg;
> @@ -177,6 +189,15 @@ static int rzg2l_adc_conversion_setup(struct rzg2l_adc *adc, u8 ch)
> reg |= BIT(ch);
> rzg2l_adc_writel(adc, RZG2L_ADM(2), reg);
>
> + reg = rzg2l_adc_readl(adc, RZG2L_ADM(3));
> + reg &= ~hw_params->adsmp_mask;
> + /*
> + * type could be IIO_VOLTAGE = 0 or IIO_TEMP = 9. Divide to 8 to get
> + * index 0 or 1 depending on the channel type.
That is not particularly nice and potentially a little fragile if we get other device
support in future. Better to match on the type in rzg2l_adc_channels[] possibly wrapped
up in a little utility function bool rzg2l_adc_channels_is_temp(); Then use a
? 1 : 0 to get the offset in default_adsmp[]
> + */
> + reg |= hw_params->default_adsmp[type / 8];
> + rzg2l_adc_writel(adc, RZG2L_ADM(3), reg);
> +
> /*
> * Setup ADINT
> * INTS[31] - Select pulse signal
> @@ -192,7 +213,8 @@ static int rzg2l_adc_conversion_setup(struct rzg2l_adc *adc, u8 ch)
> return 0;
> }
>
>
> + case IIO_CHAN_INFO_PROCESSED:
> + if (chan->type != IIO_TEMP)
> + return -EINVAL;
> +
> + mutex_lock(&adc->lock);
> + ret = rzg2l_adc_conversion(indio_dev, chan->type, adc, ch);
> + if (!ret) {
> + /* Convert it to mili Celsius. */
> + *val = adc->last_val[ch] * 1000;
Prefer you provide a scale of 1000 and report this raw.
> + }
Also strong preference for error conditions out of line.
As in that other case, guard() makes that easier as yo ucan do
{
guard(mutex)(&adc->lock);
ret = rz....
if (ret)
return ret;
*val = ...
return IIO_VAL_INT;
}
> + mutex_unlock(&adc->lock);
> +
> + return ret ? ret : IIO_VAL_INT;
> +
> default:
> return -EINVAL;
> }
> static const struct iio_info rzg2l_adc_iio_info = {
> @@ -332,11 +368,14 @@ static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l
> if (channel >= hw_params->num_channels)
> return -EINVAL;
>
> - chan_array[i].type = IIO_VOLTAGE;
> + chan_array[i].type = rzg2l_adc_channels[channel].type;
> chan_array[i].indexed = 1;
> chan_array[i].channel = channel;
> - chan_array[i].info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
> - chan_array[i].datasheet_name = rzg2l_adc_channel_name[channel];
> + if (rzg2l_adc_channels[channel].type == IIO_VOLTAGE)
> + chan_array[i].info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
> + else
> + chan_array[i].info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED);
Make it raw, but I'm curious we have no _SCALE on this device. Do we really have no idea
of the calibration of these channels?
> + chan_array[i].datasheet_name = rzg2l_adc_channels[channel].name;
> i++;
> }
>
> @@ -386,7 +425,7 @@ static int rzg2l_adc_hw_init(struct device *dev, struct rzg2l_adc *adc)
> reg &= ~RZG2L_ADM3_ADCMP_MASK;
> reg &= ~hw_params->adsmp_mask;
> reg |= FIELD_PREP(RZG2L_ADM3_ADCMP_MASK, hw_params->default_adcmp) |
> - hw_params->default_adsmp;
> + hw_params->default_adsmp[0];
>
> rzg2l_adc_writel(adc, RZG2L_ADM(3), reg);
>
> @@ -479,7 +518,7 @@ static int rzg2l_adc_probe(struct platform_device *pdev)
> static const struct rzg2l_adc_hw_params rzg2l_hw_params = {
> .num_channels = 8,
> .default_adcmp = 0xe,
> - .default_adsmp = 0x578,
> + .default_adsmp = { 0x578 },
> .adsmp_mask = GENMASK(15, 0),
> .adint_inten_mask = GENMASK(7, 0),
> .adivc = true
next prev parent reply other threads:[~2024-12-03 20:19 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-03 11:13 [PATCH 00/14] iio: adc: rzg2l_adc: Add support for RZ/G3S Claudiu
2024-12-03 11:13 ` [PATCH 01/14] clk: renesas: r9a08g045: Add clocks, resets and power domain support for the ADC IP Claudiu
2024-12-03 11:13 ` [PATCH 02/14] iio: adc: rzg2l_adc: Use devres helpers to request pre-deasserted reset controls Claudiu
2024-12-03 19:51 ` Jonathan Cameron
2024-12-03 11:13 ` [PATCH 03/14] iio: adc: rzg2l_adc: Simplify the runtime PM code Claudiu
2024-12-03 12:53 ` Paul Barker
2024-12-03 13:40 ` Claudiu Beznea
2024-12-03 14:20 ` Paul Barker
2024-12-03 11:13 ` [PATCH 04/14] iio: adc: rzg2l_adc: Switch to RUNTIME_PM_OPS() and pm_ptr() Claudiu
2024-12-03 11:13 ` [PATCH 05/14] iio: adc: rzg2l_adc: Use read_poll_timeout() Claudiu
2024-12-03 11:13 ` [PATCH 06/14] iio: adc: rzg2l_adc: Simplify the locking scheme in rzg2l_adc_read_raw() Claudiu
2024-12-03 13:03 ` Paul Barker
2024-12-03 18:07 ` Jonathan Cameron
2024-12-03 11:13 ` [PATCH 07/14] iio: adc: rzg2l_adc: Enable runtime PM autosuspend support Claudiu
2024-12-03 20:00 ` Jonathan Cameron
2024-12-04 8:31 ` Claudiu Beznea
2024-12-04 9:09 ` Biju Das
2024-12-03 11:13 ` [PATCH 08/14] iio: adc: rzg2l_adc: Prepare for the addition of RZ/G3S support Claudiu
2024-12-03 20:09 ` Jonathan Cameron
2024-12-04 9:40 ` Geert Uytterhoeven
2024-12-07 17:37 ` Jonathan Cameron
2024-12-03 11:13 ` [PATCH 09/14] iio: adc: rzg2l_adc: Add support for channel 8 Claudiu
2024-12-03 20:18 ` Jonathan Cameron [this message]
2024-12-04 8:50 ` Claudiu Beznea
2024-12-07 17:42 ` Jonathan Cameron
2024-12-03 11:13 ` [PATCH 10/14] iio: adc: rzg2l_adc: Add suspend/resume support Claudiu
2024-12-03 11:13 ` [PATCH 11/14] dt-bindings: iio: adc: renesas,rzg2l-adc: Document RZ/G3S SoC Claudiu
2024-12-03 16:04 ` Conor Dooley
2024-12-03 11:13 ` [PATCH 12/14] iio: adc: rzg2l_adc: Add support for Renesas RZ/G3S Claudiu
2024-12-03 22:08 ` Jonathan Cameron
2024-12-03 11:13 ` [PATCH 13/14] arm64: dts: renesas: r9a08g045: Add ADC node Claudiu
2024-12-03 11:13 ` [PATCH 14/14] arm64: dts: renesas: rzg3s-smarc-som: Enable ADC Claudiu
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=20241203201857.7ccdcf99@jic23-huawei \
--to=jic23@kernel.org \
--cc=claudiu.beznea.uj@bp.renesas.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=geert+renesas@glider.be \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-clk@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=mturquette@baylibre.com \
--cc=p.zabel@pengutronix.de \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=robh@kernel.org \
--cc=sboyd@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