All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakob Hauser <jahau@rocketmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Hans de Goede <hdegoede@redhat.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	phone-devel@vger.kernel.org,
	~postmarketos/upstreaming@lists.sr.ht,
	Jakob Hauser <jahau@rocketmail.com>
Subject: [PATCH v6 11/14] iio: magnetometer: yas530: Add IIO scaling to "chip_info"
Date: Sat, 13 Aug 2022 00:05:00 +0200	[thread overview]
Message-ID: <a12f892633bbee13a8856c231dc793ebbc5d3a03.1660337264.git.jahau@rocketmail.com> (raw)
In-Reply-To: <cover.1660337264.git.jahau@rocketmail.com>

Add IIO scaling to the "chip_info" structure to ease the handling to
different YAS variants.

Signed-off-by: Jakob Hauser <jahau@rocketmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/iio/magnetometer/yamaha-yas530.c | 28 ++++++------------------
 1 file changed, 7 insertions(+), 21 deletions(-)

diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c
index fa317b975f8f..af5c090098fb 100644
--- a/drivers/iio/magnetometer/yamaha-yas530.c
+++ b/drivers/iio/magnetometer/yamaha-yas530.c
@@ -130,6 +130,7 @@ struct yas5xx;
  * @version_names: version letters or namings
  * @volatile_reg: device-specific volatile registers
  * @volatile_reg_qty: quantity of device-specific volatile registers
+ * @scaling_val2: scaling value for IIO_CHAN_INFO_SCALE
  */
 struct yas5xx_chip_info {
 	unsigned int devid;
@@ -137,6 +138,7 @@ struct yas5xx_chip_info {
 	char *version_names[2];
 	const int *volatile_reg;
 	int volatile_reg_qty;
+	u32 scaling_val2;
 };
 
 /**
@@ -504,27 +506,8 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev,
 		}
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
-		switch (ci->devid) {
-		case YAS530_DEVICE_ID:
-			/*
-			 * Raw values of YAS530 are in picotesla. Divide by
-			 * 100000000 (10^8) to get Gauss.
-			 */
-			*val = 1;
-			*val2 = 100000000;
-			break;
-		case YAS532_DEVICE_ID:
-			/*
-			 * Raw values of YAS532 are in nanotesla. Divide by
-			 * 100000 (10^5) to get Gauss.
-			 */
-			*val = 1;
-			*val2 = 100000;
-			break;
-		default:
-			dev_err(yas5xx->dev, "unknown device type\n");
-			return -EINVAL;
-		}
+		*val = 1;
+		*val2 = ci->scaling_val2;
 		return IIO_VAL_FRACTIONAL;
 	default:
 		/* Unknown request */
@@ -951,6 +934,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
 		.version_names = { "A", "B" },
 		.volatile_reg = yas530_volatile_reg,
 		.volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg),
+		.scaling_val2 = 100000000, /* picotesla to Gauss */
 	},
 	[yas532] = {
 		.devid = YAS532_DEVICE_ID,
@@ -958,6 +942,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
 		.version_names = { "AB", "AC" },
 		.volatile_reg = yas530_volatile_reg,
 		.volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg),
+		.scaling_val2 = 100000, /* nanotesla to Gauss */
 	},
 	[yas533] = {
 		.devid = YAS532_DEVICE_ID,
@@ -965,6 +950,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
 		.version_names = { "AB", "AC" },
 		.volatile_reg = yas530_volatile_reg,
 		.volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg),
+		.scaling_val2 = 100000, /* nanotesla to Gauss */
 	},
 };
 
-- 
2.35.1


  parent reply	other threads:[~2022-08-12 22:05 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1660337264.git.jahau.ref@rocketmail.com>
2022-08-12 21:54 ` [PATCH v6 00/14] Add support for magnetometer Yamaha YAS537 Jakob Hauser
2022-08-12 21:54   ` [PATCH v6 01/14] iio: magnetometer: yas530: Change data type of hard_offsets to signed Jakob Hauser
2022-08-12 21:54   ` [PATCH v6 02/14] iio: magnetometer: yas530: Change range of data in volatile register Jakob Hauser
2022-08-12 21:54   ` [PATCH v6 03/14] iio: magnetometer: yas530: Correct scaling of magnetic axes Jakob Hauser
2022-08-12 21:54   ` [PATCH v6 04/14] iio: magnetometer: yas530: Correct temperature handling Jakob Hauser
2022-08-12 21:54   ` [PATCH v6 05/14] iio: magnetometer: yas530: Change data type of calibration coefficients Jakob Hauser
2022-08-12 21:54   ` [PATCH v6 06/14] iio: magnetometer: yas530: Rename functions and registers Jakob Hauser
2022-08-12 21:54   ` [PATCH v6 07/14] iio: magnetometer: yas530: Move printk %*ph parameters out from stack Jakob Hauser
2022-08-13 19:57     ` Linus Walleij
2022-08-12 21:54   ` [PATCH v6 08/14] iio: magnetometer: yas530: Apply documentation and style fixes Jakob Hauser
2022-08-12 21:54   ` [PATCH v6 09/14] iio: magnetometer: yas530: Introduce "chip_info" structure Jakob Hauser
2022-08-13 19:58     ` Linus Walleij
2022-08-12 21:54   ` [PATCH v6 10/14] iio: magnetometer: yas530: Add volatile registers to "chip_info" Jakob Hauser
2022-08-13 19:58     ` Linus Walleij
2022-08-12 22:05   ` Jakob Hauser [this message]
2022-08-13 19:59     ` [PATCH v6 11/14] iio: magnetometer: yas530: Add IIO scaling " Linus Walleij
2022-08-12 22:05   ` [PATCH v6 12/14] iio: magnetometer: yas530: Add temperature calculation " Jakob Hauser
2022-08-13 19:59     ` Linus Walleij
2022-08-12 22:05   ` [PATCH v6 13/14] iio: magnetometer: yas530: Add function pointers " Jakob Hauser
2022-08-13 20:00     ` Linus Walleij
2022-08-12 22:05   ` [PATCH v6 14/14] iio: magnetometer: yas530: Add YAS537 variant Jakob Hauser
2022-08-14 16:54   ` [PATCH v6 00/14] Add support for magnetometer Yamaha YAS537 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=a12f892633bbee13a8856c231dc793ebbc5d3a03.1660337264.git.jahau@rocketmail.com \
    --to=jahau@rocketmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=phone-devel@vger.kernel.org \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.