From: Jonathan Cameron <jic23@kernel.org>
To: Shrikant Raskar <raskar.shree97@gmail.com>
Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
matt@ranostay.sg, skhan@linuxfoundation.org,
david.hunter.linux@gmail.com, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH 2/2] iio: health: max30100: Add pulse-width configuration via DT
Date: Sat, 4 Oct 2025 14:16:44 +0100 [thread overview]
Message-ID: <20251004141644.7fcb9106@jic23-huawei> (raw)
In-Reply-To: <20251004015623.7019-3-raskar.shree97@gmail.com>
On Sat, 4 Oct 2025 07:26:23 +0530
Shrikant Raskar <raskar.shree97@gmail.com> wrote:
> The MAX30100 driver previously hardcoded the SPO2 pulse width to
> 1600us. This patch adds support for reading the pulse width from
> device tree (`maxim,pulse-width`) and programming it into the SPO2
> configuration register.
>
> If no property is provided, the driver falls back to 1600us to
> preserve existing behavior.
>
> Testing:
> Hardware: Raspberry Pi 3B + MAX30100 breakout
> Verified DT property read in probe()
> Confirmed SPO2_CONFIG register written correctly using regmap_read()
A few minor comments inline.
Thanks,
Jonathan
>
> Signed-off-by: Shrikant Raskar <raskar.shree97@gmail.com>
> ---
> drivers/iio/health/max30100.c | 39 +++++++++++++++++++++++++++++++++--
> 1 file changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/health/max30100.c b/drivers/iio/health/max30100.c
> index 814f521e47ae..2b3348c75beb 100644
> --- a/drivers/iio/health/max30100.c
> +++ b/drivers/iio/health/max30100.c
> @@ -5,7 +5,6 @@
> * Copyright (C) 2015, 2018
> * Author: Matt Ranostay <matt.ranostay@konsulko.com>
> *
> - * TODO: enable pulse length controls via device tree properties
> */
>
> #include <linux/module.h>
> @@ -54,6 +53,9 @@
> #define MAX30100_REG_SPO2_CONFIG 0x07
> #define MAX30100_REG_SPO2_CONFIG_100HZ BIT(2)
> #define MAX30100_REG_SPO2_CONFIG_HI_RES_EN BIT(6)
> +#define MAX30100_REG_SPO2_CONFIG_200US 0x0
> +#define MAX30100_REG_SPO2_CONFIG_400US 0x1
> +#define MAX30100_REG_SPO2_CONFIG_800US 0x2
> #define MAX30100_REG_SPO2_CONFIG_1600US 0x3
>
> #define MAX30100_REG_LED_CONFIG 0x09
> @@ -306,19 +308,52 @@ static int max30100_led_init(struct max30100_data *data)
> MAX30100_REG_LED_CONFIG_LED_MASK, reg);
> }
>
> +static int max30100_get_pulse_width(unsigned int pwidth_us)
> +{
> + switch (pwidth_us) {
> + case 200:
> + return MAX30100_REG_SPO2_CONFIG_200US;
> + case 400:
> + return MAX30100_REG_SPO2_CONFIG_400US;
> + case 800:
> + return MAX30100_REG_SPO2_CONFIG_800US;
> + case 1600:
> + return MAX30100_REG_SPO2_CONFIG_1600US;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> static int max30100_chip_init(struct max30100_data *data)
> {
> int ret;
> + unsigned int pulse_us;
> + unsigned int pulse_width;
> + struct device *dev = &data->client->dev;
>
> /* setup LED current settings */
> ret = max30100_led_init(data);
> if (ret)
> return ret;
>
> + /* Get pulse width from DT, default = 1600us */
> + ret = device_property_read_u32(dev, "maxim,pulse-width", &pulse_us);
> + if (ret) {
> + dev_warn(dev, "no pulse-width defined, defaulting to 1600us\n");
> + pulse_width = MAX30100_REG_SPO2_CONFIG_1600US;
Usual trick for these is to set pulse_us to 1600 before calling the
device_property_read_u32(). If that fails then the default value will remain
in the variable and we can just call the code below without needing
to explicitly handle two cases.
> + } else {
> + pulse_width = max30100_get_pulse_width(pulse_us);
> + if (pulse_width < 0) {
> + dev_err(dev, "invalid pulse-width %u\n", pulse_us);
Only happens in probe() so prefer use of return dev_err_probe()
for compactness in this case.
> + return pulse_width;
> + }
> + }
> +
> /* enable hi-res SPO2 readings at 100Hz */
> ret = regmap_write(data->regmap, MAX30100_REG_SPO2_CONFIG,
> MAX30100_REG_SPO2_CONFIG_HI_RES_EN |
> - MAX30100_REG_SPO2_CONFIG_100HZ);
> + MAX30100_REG_SPO2_CONFIG_100HZ |
> + pulse_width);
Even though it's the lowest field in this register. I'd prefer
a mask being defined and FIELD_PREP() used to set it.
That way we don't need to know it is the lowest field when looking at this
code.
> if (ret)
> return ret;
>
next prev parent reply other threads:[~2025-10-04 13:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-04 1:56 [PATCH 0/2] iio: health: max30100: Add DT pulse-width support Shrikant Raskar
2025-10-04 1:56 ` [PATCH 1/2] dt-bindings: iio: max30100: Add pulse-width property Shrikant Raskar
2025-10-04 3:22 ` Bhanu Seshu Kumar Valluri
2025-10-04 6:19 ` Shrikant
2025-10-04 13:12 ` Jonathan Cameron
2025-10-06 3:04 ` Shrikant
2025-10-12 14:11 ` Jonathan Cameron
2025-10-12 16:52 ` Shrikant
2025-10-06 14:40 ` Krzysztof Kozlowski
2025-10-04 1:56 ` [PATCH 2/2] iio: health: max30100: Add pulse-width configuration via DT Shrikant Raskar
2025-10-04 13:16 ` Jonathan Cameron [this message]
2025-10-09 13:28 ` kernel test robot
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=20251004141644.7fcb9106@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=david.hunter.linux@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=matt@ranostay.sg \
--cc=nuno.sa@analog.com \
--cc=raskar.shree97@gmail.com \
--cc=robh@kernel.org \
--cc=skhan@linuxfoundation.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