From nobody Fri Dec 26 23:36:17 2025 Received: from mail.subdimension.ro (skycaves.subdimension.ro [172.104.132.142]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36E2811736; Fri, 29 Dec 2023 09:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=subdimension.ro Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=subdimension.ro Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=subdimension.ro header.i=@subdimension.ro header.b="jVcZo+Kq" Received: from localhost.localdomain (unknown [188.24.94.216]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mail.subdimension.ro (Postfix) with ESMTPSA id BB45A28B596; Fri, 29 Dec 2023 09:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=subdimension.ro; s=skycaves; t=1703841909; bh=akQy0eNST9HQO0Ptl17uHVfMO9+tHIXtxlAzCJyC6XA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jVcZo+KqlVWn4jUf1spWjrk4er3QmBucmlqknHhIaONBIFQHrbOnmZ2wf45mGvXrV +inYKmz+DsCGtryl1liB3MxbryGg/7I7OFhax+u4hNev7ygpjz2S6A8ITP93w7OZfu DraSC1ZwPVloqutACRzq+w53XmSVqli8sg6QkP/k= From: Petre Rodan To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Petre Rodan , Andreas Klinger , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Angel Iglesias , Matti Vaittinen Subject: [PATCH v3 09/10] iio: pressure: mprls0025pa add triplet property Date: Fri, 29 Dec 2023 11:24:37 +0200 Message-ID: <20231229092445.30180-10-petre.rodan@subdimension.ro> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231229092445.30180-1-petre.rodan@subdimension.ro> References: <20231229092445.30180-1-petre.rodan@subdimension.ro> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add honeywell,pressure-triplet property that automatically initializes pmin-pascal, pmax-pascal so that the user is not required to look-up the chip in the datasheet and convert various units to pascals himself. Co-developed-by: Andreas Klinger Signed-off-by: Andreas Klinger Signed-off-by: Petre Rodan --- v2 -> v3 no changes drivers/iio/pressure/mprls0025pa.c | 105 ++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 8 deletions(-) diff --git a/drivers/iio/pressure/mprls0025pa.c b/drivers/iio/pressure/mprl= s0025pa.c index ce20cf362fac..33a15d4c642c 100644 --- a/drivers/iio/pressure/mprls0025pa.c +++ b/drivers/iio/pressure/mprls0025pa.c @@ -80,6 +80,78 @@ static const struct mpr_func_spec mpr_func_spec[] =3D { [MPR_FUNCTION_C] =3D { .output_min =3D 3355443, .output_max =3D 13421773 = }, }; +enum mpr_variants { + MPR0001BA =3D 0x00, MPR01_6BA =3D 0x01, MPR02_5BA =3D 0x02, MPR0060MG =3D= 0x03, + MPR0100MG =3D 0x04, MPR0160MG =3D 0x05, MPR0250MG =3D 0x06, MPR0400MG =3D= 0x07, + MPR0600MG =3D 0x08, MPR0001BG =3D 0x09, MPR01_6BG =3D 0x0a, MPR02_5BG =3D= 0x0b, + MPR0100KA =3D 0x0c, MPR0160KA =3D 0x0d, MPR0250KA =3D 0x0e, MPR0006KG =3D= 0x0f, + MPR0010KG =3D 0x10, MPR0016KG =3D 0x11, MPR0025KG =3D 0x12, MPR0040KG =3D= 0x13, + MPR0060KG =3D 0x14, MPR0100KG =3D 0x15, MPR0160KG =3D 0x16, MPR0250KG =3D= 0x17, + MPR0015PA =3D 0x18, MPR0025PA =3D 0x19, MPR0030PA =3D 0x1a, MPR0001PG =3D= 0x1b, + MPR0005PG =3D 0x1c, MPR0015PG =3D 0x1d, MPR0030PG =3D 0x1e, MPR0300YG =3D= 0x1f, + MPR_VARIANTS_MAX +}; + +static const char * const mpr_triplet_variants[MPR_VARIANTS_MAX] =3D { + [MPR0001BA] =3D "0001BA", [MPR01_6BA] =3D "01.6BA", [MPR02_5BA] =3D "02.5= BA", + [MPR0060MG] =3D "0060MG", [MPR0100MG] =3D "0100MG", [MPR0160MG] =3D "0160= MG", + [MPR0250MG] =3D "0250MG", [MPR0400MG] =3D "0400MG", [MPR0600MG] =3D "0600= MG", + [MPR0001BG] =3D "0001BG", [MPR01_6BG] =3D "01.6BG", [MPR02_5BG] =3D "02.5= BG", + [MPR0100KA] =3D "0100KA", [MPR0160KA] =3D "0160KA", [MPR0250KA] =3D "0250= KA", + [MPR0006KG] =3D "0006KG", [MPR0010KG] =3D "0010KG", [MPR0016KG] =3D "0016= KG", + [MPR0025KG] =3D "0025KG", [MPR0040KG] =3D "0040KG", [MPR0060KG] =3D "0060= KG", + [MPR0100KG] =3D "0100KG", [MPR0160KG] =3D "0160KG", [MPR0250KG] =3D "0250= KG", + [MPR0015PA] =3D "0015PA", [MPR0025PA] =3D "0025PA", [MPR0030PA] =3D "0030= PA", + [MPR0001PG] =3D "0001PG", [MPR0005PG] =3D "0005PG", [MPR0015PG] =3D "0015= PG", + [MPR0030PG] =3D "0030PG", [MPR0300YG] =3D "0300YG" +}; + +/** + * struct mpr_range_config - list of pressure ranges based on nomenclature + * @pmin: lowest pressure that can be measured + * @pmax: highest pressure that can be measured + */ +struct mpr_range_config { + const s32 pmin; + const s32 pmax; +}; + +/* All min max limits have been converted to pascals */ +static const struct mpr_range_config mpr_range_config[MPR_VARIANTS_MAX] = =3D { + [MPR0001BA] =3D { .pmin =3D 0, .pmax =3D 100000 }, + [MPR01_6BA] =3D { .pmin =3D 0, .pmax =3D 160000 }, + [MPR02_5BA] =3D { .pmin =3D 0, .pmax =3D 250000 }, + [MPR0060MG] =3D { .pmin =3D 0, .pmax =3D 6000 }, + [MPR0100MG] =3D { .pmin =3D 0, .pmax =3D 10000 }, + [MPR0160MG] =3D { .pmin =3D 0, .pmax =3D 16000 }, + [MPR0250MG] =3D { .pmin =3D 0, .pmax =3D 25000 }, + [MPR0400MG] =3D { .pmin =3D 0, .pmax =3D 40000 }, + [MPR0600MG] =3D { .pmin =3D 0, .pmax =3D 60000 }, + [MPR0001BG] =3D { .pmin =3D 0, .pmax =3D 100000 }, + [MPR01_6BG] =3D { .pmin =3D 0, .pmax =3D 160000 }, + [MPR02_5BG] =3D { .pmin =3D 0, .pmax =3D 250000 }, + [MPR0100KA] =3D { .pmin =3D 0, .pmax =3D 100000 }, + [MPR0160KA] =3D { .pmin =3D 0, .pmax =3D 160000 }, + [MPR0250KA] =3D { .pmin =3D 0, .pmax =3D 250000 }, + [MPR0006KG] =3D { .pmin =3D 0, .pmax =3D 6000 }, + [MPR0010KG] =3D { .pmin =3D 0, .pmax =3D 10000 }, + [MPR0016KG] =3D { .pmin =3D 0, .pmax =3D 16000 }, + [MPR0025KG] =3D { .pmin =3D 0, .pmax =3D 25000 }, + [MPR0040KG] =3D { .pmin =3D 0, .pmax =3D 40000 }, + [MPR0060KG] =3D { .pmin =3D 0, .pmax =3D 60000 }, + [MPR0100KG] =3D { .pmin =3D 0, .pmax =3D 100000 }, + [MPR0160KG] =3D { .pmin =3D 0, .pmax =3D 160000 }, + [MPR0250KG] =3D { .pmin =3D 0, .pmax =3D 250000 }, + [MPR0015PA] =3D { .pmin =3D 0, .pmax =3D 103421 }, + [MPR0025PA] =3D { .pmin =3D 0, .pmax =3D 172369 }, + [MPR0030PA] =3D { .pmin =3D 0, .pmax =3D 206843 }, + [MPR0001PG] =3D { .pmin =3D 0, .pmax =3D 6895 }, + [MPR0005PG] =3D { .pmin =3D 0, .pmax =3D 34474 }, + [MPR0015PG] =3D { .pmin =3D 0, .pmax =3D 103421 }, + [MPR0030PG] =3D { .pmin =3D 0, .pmax =3D 206843 }, + [MPR0300YG] =3D { .pmin =3D 0, .pmax =3D 39997 } +}; + static const struct iio_chan_spec mpr_channels[] =3D { { .type =3D IIO_PRESSURE, @@ -257,6 +329,7 @@ int mpr_common_probe(struct device *dev, const struct m= pr_ops *ops, int irq) int ret; struct mpr_data *data; struct iio_dev *indio_dev; + const char *triplet; s64 scale, offset; u32 func; @@ -298,16 +371,32 @@ int mpr_common_probe(struct device *dev, const struct= mpr_ops *ops, int irq) "honeywell,transfer-function %d invalid\n", data->function); - ret =3D device_property_read_u32(dev, "honeywell,pmin-pascal", - &data->pmin); - if (ret) - return dev_err_probe(dev, ret, + ret =3D device_property_read_string(dev, "honeywell,pressure-triplet", + &triplet); + if (ret) { + ret =3D device_property_read_u32(dev, "honeywell,pmin-pascal", + &data->pmin); + if (ret) + return dev_err_probe(dev, ret, "honeywell,pmin-pascal could not be read\n"); - ret =3D device_property_read_u32(dev, "honeywell,pmax-pascal", - &data->pmax); - if (ret) - return dev_err_probe(dev, ret, + + ret =3D device_property_read_u32(dev, "honeywell,pmax-pascal", + &data->pmax); + if (ret) + return dev_err_probe(dev, ret, "honeywell,pmax-pascal could not be read\n"); + } else { + ret =3D device_property_match_property_string(dev, + "honeywell,pressure-triplet", + mpr_triplet_variants, + MPR_VARIANTS_MAX); + if (ret < 0) + return dev_err_probe(dev, -EINVAL, + "honeywell,pressure-triplet is invalid\n"); + + data->pmin =3D mpr_range_config[ret].pmin; + data->pmax =3D mpr_range_config[ret].pmax; + } if (data->pmin >=3D data->pmax) return dev_err_probe(dev, -EINVAL, -- 2.41.0