All of lore.kernel.org
 help / color / mirror / Atom feed
From: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
To: qing-wu.li@leica-geosystems.com.cn, jic23@kernel.org,
	lars@metafoo.de, robh+dt@kernel.org, tomas.melin@vaisala.com,
	andy.shevchenko@gmail.com, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
Subject: [PATCH V1 2/6] iio: accel: sca3300: Add interface for operation modes.
Date: Mon, 24 Jan 2022 09:39:08 +0000	[thread overview]
Message-ID: <20220124093912.2429190-3-Qing-wu.Li@leica-geosystems.com.cn> (raw)
In-Reply-To: <20220124093912.2429190-1-Qing-wu.Li@leica-geosystems.com.cn>

The acceleration scale and the frequency were set via operation modes,
the scal and frequency are both non-uniqueness,
this leads to logic confusion for setting scale.and.frequency.
it getting worse if add more different sensor types into the driver.

The commit add an interface for set and get the operation modes.
the following interfaces added:
in_accel_op_mode_available
in_op_mode

SCA3300 operation modes table:
| Mode | Full-scale | low pass filter frequency |
| ---- | ---------- | ------------------------- |
| 1    | ± 3 g      | 70 Hz                     |
| 2    | ± 6 g      | 70 Hz                     |
| 3    | ± 1.5 g    | 70 Hz                     |
| 4    | ± 1.5 g    | 10 Hz                     |

Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
---
 drivers/iio/accel/sca3300.c | 55 +++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/drivers/iio/accel/sca3300.c b/drivers/iio/accel/sca3300.c
index 083ae2a47ad9..e26b3175b3c6 100644
--- a/drivers/iio/accel/sca3300.c
+++ b/drivers/iio/accel/sca3300.c
@@ -42,6 +42,38 @@
 /* Device return status and mask */
 #define SCA3300_VALUE_RS_ERROR	0x3
 #define SCA3300_MASK_RS_STATUS	GENMASK(1, 0)
+enum sca3300_op_mode_indexes {
+	OP_MOD_1 = 0,
+	OP_MOD_2,
+	OP_MOD_3,
+	OP_MOD_4,
+	OP_MOD_CNT
+};
+
+static const char * const sca3300_op_modes[] = {
+	[OP_MOD_1] = "1",
+	[OP_MOD_2] = "2",
+	[OP_MOD_3] = "3",
+	[OP_MOD_4] = "4"
+};
+
+static int sca3300_get_op_mode(struct iio_dev *indio_dev,
+		const struct iio_chan_spec *chan);
+static int sca3300_set_op_mode(struct iio_dev *indio_dev,
+		const struct iio_chan_spec *chan, unsigned int mode);
+
+static const struct iio_enum sca3300_op_mode_enum = {
+	.items = sca3300_op_modes,
+	.num_items = ARRAY_SIZE(sca3300_op_modes),
+	.get = sca3300_get_op_mode,
+	.set = sca3300_set_op_mode,
+};
+
+static const struct iio_chan_spec_ext_info sca3300_ext_info[] = {
+	IIO_ENUM("op_mode", IIO_SHARED_BY_DIR, &sca3300_op_mode_enum),
+	IIO_ENUM_AVAILABLE("op_mode", &sca3300_op_mode_enum),
+	{ }
+};
 
 enum sca3300_scan_indexes {
 	SCA3300_ACC_X = 0,
@@ -70,6 +102,7 @@ enum sca3300_scan_indexes {
 		.storagebits = 16,					\
 		.endianness = IIO_CPU,					\
 	},								\
+	.ext_info = sca3300_ext_info,					\
 }
 
 #define SCA3300_TEMP_CHANNEL(index, reg) {				\
@@ -400,6 +433,28 @@ static int sca3300_read_avail(struct iio_dev *indio_dev,
 	}
 }
 
+static int sca3300_get_op_mode(struct iio_dev *indio_dev,
+		const struct iio_chan_spec *chan)
+{
+	int mode;
+	int ret;
+	struct sca3300_data *data = iio_priv(indio_dev);
+
+	ret = sca3300_read_reg(data, SCA3300_REG_MODE, &mode);
+	if (ret)
+		return ret;
+	return mode;
+
+}
+
+static int sca3300_set_op_mode(struct iio_dev *indio_dev,
+		const struct iio_chan_spec *chan, unsigned int mode)
+{
+	struct sca3300_data *data = iio_priv(indio_dev);
+
+	return sca3300_write_reg(data, SCA3300_REG_MODE, mode);
+}
+
 static const struct iio_info sca3300_info = {
 	.read_raw = sca3300_read_raw,
 	.write_raw = sca3300_write_raw,
-- 
2.25.1


  parent reply	other threads:[~2022-01-24  9:39 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24  9:39 [PATCH V1 0/6] i iio: accel: sca3300: add compitible for scl3300 LI Qingwu
2022-01-24  9:39 ` [PATCH V1 1/6] iio: accel: sca3300: add define for temp channel for reuse LI Qingwu
2022-01-24  9:39 ` LI Qingwu [this message]
2022-01-24 13:03   ` [PATCH V1 2/6] iio: accel: sca3300: Add interface for operation modes Andy Shevchenko
2022-01-24 13:49   ` kernel test robot
2022-01-24 13:49     ` kernel test robot
2022-01-24 13:59   ` kernel test robot
2022-01-24 13:59     ` kernel test robot
2022-01-30 11:40   ` Jonathan Cameron
2022-02-10 10:08     ` LI Qingwu
2022-02-10 15:40       ` Jonathan Cameron
2022-01-24  9:39 ` [PATCH V1 3/6] iio: accel: sca3300: modified to support multi chips LI Qingwu
2022-01-24 13:08   ` Andy Shevchenko
2022-01-24 15:01   ` kernel test robot
2022-01-24 15:01     ` kernel test robot
2022-01-24 15:32   ` kernel test robot
2022-01-24 15:32     ` kernel test robot
2022-01-24  9:39 ` [PATCH V1 4/6] iio: accel: sca3300: Add support for SCL3300 LI Qingwu
2022-01-24 13:12   ` Andy Shevchenko
2022-01-24  9:39 ` [PATCH V1 5/6] iio: accel: sca3300: Add inclination channels LI Qingwu
2022-01-24 13:19   ` Andy Shevchenko
2022-01-30 11:46     ` Jonathan Cameron
2022-01-24  9:39 ` [PATCH V1 6/6] dt-bindings: iio: accel: sca3300: Document murata,scl3300 LI Qingwu
2022-02-09  3:08   ` Rob Herring
2022-01-30 11:35 ` [PATCH V1 0/6] i iio: accel: sca3300: add compitible for scl3300 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=20220124093912.2429190-3-Qing-wu.Li@leica-geosystems.com.cn \
    --to=qing-wu.li@leica-geosystems.com.cn \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=tomas.melin@vaisala.com \
    /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.