lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250406133349.50633-1-brajeshpatil11@gmail.com>
Date: Sun,  6 Apr 2025 19:03:49 +0530
From: Brajesh Patil <brajeshpatil11@...il.com>
To: linux-iio@...r.kernel.org
Cc: jic23@...nel.org,
	lars@...afoo.de,
	linux-kernel@...r.kernel.org,
	outreachy@...ts.linux.dev,
	Brajesh Patil <brajeshpatil11@...il.com>
Subject: [PATCH v1 1/1] iio: dummy: Add 3-axis compass (magnetometer) channels to the iio_simple_dummy

This patch adds support for 3-axis magnetometer data (X, Y, Z) in the
iio_simple_dummy driver. It introduces three new IIO_MAGN channels and
populates them with dummy values for testing and prototyping purposes.

Signed-off-by: Brajesh Patil <brajeshpatil11@...il.com>
---
 drivers/iio/dummy/iio_simple_dummy.c | 71 +++++++++++++++++++++++++++-
 drivers/iio/dummy/iio_simple_dummy.h |  6 +++
 2 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c
index 8575d4a08..713b764c9 100644
--- a/drivers/iio/dummy/iio_simple_dummy.c
+++ b/drivers/iio/dummy/iio_simple_dummy.c
@@ -222,7 +222,7 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
         * Convenience macro for timestamps. 4 is the index in
         * the buffer.
         */
-       IIO_CHAN_SOFT_TIMESTAMP(4),
+	IIO_CHAN_SOFT_TIMESTAMP(DUMMY_INDEX_SOFT_TIMESTAMP),
        /* DAC channel out_voltage0_raw */
        {
                .type = IIO_VOLTAGE,
@@ -265,6 +265,48 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
                .num_event_specs = 1,
 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
        },
+	{
+		.type = IIO_MAGN,
+		.modified = 1,
+		.channel2 = IIO_MOD_X,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+		.scan_index = DUMMY_MAGN_X,
+		.scan_type = {
+			.sign = 'u',
+			.realbits = 16,
+			.storagebits = 16,
+			.shift = 0,
+		},
+	},
+	{
+		.type = IIO_MAGN,
+		.modified = 1,
+		.channel2 = IIO_MOD_Y,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+		.scan_index = DUMMY_MAGN_Y,
+		.scan_type = {
+			.sign = 'u',
+			.realbits = 16,
+			.storagebits = 16,
+			.shift = 0,
+		},
+	},
+	{
+		.type = IIO_MAGN,
+		.modified = 1,
+		.channel2 = IIO_MOD_Z,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+		.scan_index = DUMMY_MAGN_Z,
+		.scan_type = {
+			.sign = 'u',
+			.realbits = 16,
+			.storagebits = 16,
+			.shift = 0,
+		},
+	},
 };
 
 static int __iio_dummy_read_raw(struct iio_dev *indio_dev,
@@ -294,6 +336,22 @@ static int __iio_dummy_read_raw(struct iio_dev *indio_dev,
        case IIO_ACCEL:
                *val = st->accel_val;
                return IIO_VAL_INT;
+	case IIO_MAGN:
+		switch (chan->scan_index) {
+		case DUMMY_MAGN_X:
+			*val = st->buffer_compass[0];
+			break;
+		case DUMMY_MAGN_Y:
+			*val = st->buffer_compass[1];
+			break;
+		case DUMMY_MAGN_Z:
+			*val = st->buffer_compass[2];
+			break;
+		default:
+			*val = 99;
+			break;
+		}
+		return IIO_VAL_INT;
        default:
                return -EINVAL;
        }
@@ -378,6 +436,11 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
                        default:
                                return -EINVAL;
                        }
+		case IIO_MAGN:
+			// Just add some dummy values
+			*val = 0;
+			*val2 = 2;
+			return IIO_VAL_INT_PLUS_MICRO;
                default:
                        return -EINVAL;
                }
@@ -562,6 +625,10 @@ static int iio_dummy_init_device(struct iio_dev *indio_dev)
        st->activity_running = 98;
        st->activity_walking = 4;
 
+	st->buffer_compass[0] = 78;
+	st->buffer_compass[1] = 10;
+	st->buffer_compass[2] = 3;
+
        return 0;
 }
 
@@ -732,5 +799,5 @@ static struct iio_sw_device_type iio_dummy_device = {
 module_iio_sw_device_driver(iio_dummy_device);
 
 MODULE_AUTHOR("Jonathan Cameron <jic23@...nel.org>");
-MODULE_DESCRIPTION("IIO dummy driver");
+MODULE_DESCRIPTION("IIO dummy driver -> IIO dummy modified by Me");
 MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/dummy/iio_simple_dummy.h b/drivers/iio/dummy/iio_simple_dummy.h
index 8246f25db..e05d8b5cc 100644
--- a/drivers/iio/dummy/iio_simple_dummy.h
+++ b/drivers/iio/dummy/iio_simple_dummy.h
@@ -12,6 +12,7 @@
 struct iio_dummy_accel_calibscale;
 struct iio_dummy_regs;
 
+#define DUMMY_AXIS_XYZ 3
 /**
  * struct iio_dummy_state - device instance specific state.
  * @dac_val:                   cache for dac value
@@ -39,6 +40,7 @@ struct iio_dummy_state {
        int steps_enabled;
        int steps;
        int height;
+	u16 buffer_compass[DUMMY_AXIS_XYZ];
 #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
        int event_irq;
        int event_val;
@@ -107,6 +109,10 @@ enum iio_simple_dummy_scan_elements {
        DUMMY_INDEX_DIFFVOLTAGE_1M2,
        DUMMY_INDEX_DIFFVOLTAGE_3M4,
        DUMMY_INDEX_ACCELX,
+	DUMMY_INDEX_SOFT_TIMESTAMP,
+	DUMMY_MAGN_X,
+	DUMMY_MAGN_Y,
+	DUMMY_MAGN_Z,
 };
 
 #ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
-- 
2.43.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ