linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] iio: Add support for max_sampling_frequency
@ 2016-12-30  9:23 Song Hongyan
  2016-12-30  9:23 ` [PATCH 2/4] iio: hid-sensors: API add max_sample_frequency Song Hongyan
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Song Hongyan @ 2016-12-30  9:23 UTC (permalink / raw)
  To: linux-iio; +Cc: jikos, jic23, srinivas.pandruvada, Song Hongyan

Add support for max_sampling_frequency, this will help user to
set sampling frequency to an acceptable range.

Signed-off-by: Song Hongyan <hongyan.song@intel.com>
---
 Documentation/ABI/testing/sysfs-bus-iio | 7 +++++++
 drivers/iio/industrialio-core.c         | 1 +
 include/linux/iio/iio.h                 | 1 +
 3 files changed, 9 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index 60b7406..cbcd2b8 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -54,6 +54,13 @@ Description:
 		relevant directories.  If it effects all of the above
 		then it is to be found in the base device directory.
 
+What:		/sys/bus/iio/devices/iio:deviceX/max_sampling_frequency
+KernelVersion:	4.11
+Contact:	linux-iio@vger.kernel.org
+Description:
+		This parameter shows the max sampling frequency, which can
+		help user to set sampling frequency to an acceptable range.
+
 What:		/sys/bus/iio/devices/iio:deviceX/sampling_frequency_available
 What:		/sys/.../iio:deviceX/buffer/sampling_frequency_available
 What:		/sys/bus/iio/devices/triggerX/sampling_frequency_available
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 72fc96a..5203e75 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -140,6 +140,7 @@ struct bus_type iio_bus_type = {
 	[IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY]
 	= "filter_high_pass_3db_frequency",
 	[IIO_CHAN_INFO_SAMP_FREQ] = "sampling_frequency",
+	[IIO_CHAN_INFO_MAX_SAMP_FREQ] = "max_sampling_frequency",
 	[IIO_CHAN_INFO_FREQUENCY] = "frequency",
 	[IIO_CHAN_INFO_PHASE] = "phase",
 	[IIO_CHAN_INFO_HARDWAREGAIN] = "hardwaregain",
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index b4a0679..f9eba2e 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -34,6 +34,7 @@ enum iio_chan_info_enum {
 	IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY,
 	IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY,
 	IIO_CHAN_INFO_SAMP_FREQ,
+	IIO_CHAN_INFO_MAX_SAMP_FREQ,
 	IIO_CHAN_INFO_FREQUENCY,
 	IIO_CHAN_INFO_PHASE,
 	IIO_CHAN_INFO_HARDWAREGAIN,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] iio: hid-sensors: API add max_sample_frequency
  2016-12-30  9:23 [PATCH 1/4] iio: Add support for max_sampling_frequency Song Hongyan
@ 2016-12-30  9:23 ` Song Hongyan
  2016-12-30  9:23 ` [PATCH 3/4] iio: hid-sensor-attributes: Add input sample frequency check Song Hongyan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Song Hongyan @ 2016-12-30  9:23 UTC (permalink / raw)
  To: linux-iio; +Cc: jikos, jic23, srinivas.pandruvada, Song Hongyan

This interface is used to help user to set sampling
frequency to an acceptable range.

Signed-off-by: Song Hongyan <hongyan.song@intel.com>
---
 .../iio/common/hid-sensors/hid-sensor-attributes.c | 35 ++++++++++++++++++++--
 include/linux/hid-sensor-hub.h                     |  4 ++-
 include/linux/hid-sensor-ids.h                     |  1 +
 3 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index b5beea53..ad30814 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -194,6 +194,30 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
 }
 EXPORT_SYMBOL(hid_sensor_read_samp_freq_value);
 
+int hid_sensor_read_max_samp_freq_value(struct hid_sensor_common *st,
+				int *val1, int *val2)
+{
+	s32 value;
+	int ret;
+
+	ret = sensor_hub_get_feature(st->hsdev,
+				st->min_report_inter.report_id,
+				st->min_report_inter.index, sizeof(value),
+				&value);
+	if (ret < 0 || value < 0)
+		return -EINVAL;
+
+	if (st->poll.units == HID_USAGE_SENSOR_UNITS_MILLISECOND)
+		simple_div(1000, value, val1, val2);
+	else if (st->poll.units == HID_USAGE_SENSOR_UNITS_SECOND)
+		simple_div(1, value, val1, val2);
+	else
+		return -EINVAL;
+
+	return IIO_VAL_INT_PLUS_MICRO;
+}
+EXPORT_SYMBOL(hid_sensor_read_max_samp_freq_value);
+
 int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
 				int val1, int val2)
 {
@@ -382,11 +406,18 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 			HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS,
 			 &st->sensitivity);
 
-	hid_dbg(hsdev->hdev, "common attributes: %x:%x, %x:%x, %x:%x %x:%x\n",
+	sensor_hub_input_get_attribute_info(hsdev,
+			HID_FEATURE_REPORT, usage_id,
+			HID_USAGE_SENSOR_PROP_MIN_REPORT_INTER,
+			&st->min_report_inter);
+
+	hid_dbg(hsdev->hdev, "common attributes: %x:%x, %x:%x, %x:%x %x:%x, %x:%x\n",
 			st->poll.index, st->poll.report_id,
 			st->report_state.index, st->report_state.report_id,
 			st->power_state.index, st->power_state.report_id,
-			st->sensitivity.index, st->sensitivity.report_id);
+			st->sensitivity.index, st->sensitivity.report_id,
+			st->min_report_inter.index,
+			st->min_report_inter.report_id);
 
 	return 0;
 }
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
index dd85f35..3410777 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -236,6 +236,7 @@ struct hid_sensor_common {
 	struct hid_sensor_hub_attribute_info report_state;
 	struct hid_sensor_hub_attribute_info power_state;
 	struct hid_sensor_hub_attribute_info sensitivity;
+	struct hid_sensor_hub_attribute_info min_report_inter;
 	struct work_struct work;
 };
 
@@ -261,7 +262,8 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
 					int val1, int val2);
 int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
 					int *val1, int *val2);
-
+int hid_sensor_read_max_samp_freq_value(struct hid_sensor_common *st,
+					int *val1, int *val2);
 int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
 				u32 report_id, int field_index, u32 usage_id);
 
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index b6778fd2..3e56e50 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -140,6 +140,7 @@
 #define HID_USAGE_SENSOR_PROP_RANGE_MINIMUM			0x200315
 #define HID_USAGE_SENSOR_PROP_REPORT_STATE			0x200316
 #define HID_USAGE_SENSOR_PROY_POWER_STATE			0x200319
+#define HID_USAGE_SENSOR_PROP_MIN_REPORT_INTER			0x200304
 
 /* Per data field properties */
 #define HID_USAGE_SENSOR_DATA_MOD_NONE					0x00
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] iio: hid-sensor-attributes: Add input sample frequency check
  2016-12-30  9:23 [PATCH 1/4] iio: Add support for max_sampling_frequency Song Hongyan
  2016-12-30  9:23 ` [PATCH 2/4] iio: hid-sensors: API add max_sample_frequency Song Hongyan
@ 2016-12-30  9:23 ` Song Hongyan
  2016-12-30 20:32   ` Jonathan Cameron
  2016-12-30  9:23 ` [PATCH 4/4] iio: hid: Expose sensors max_sample_frequency nodes Song Hongyan
  2016-12-30 20:31 ` [PATCH 1/4] iio: Add support for max_sampling_frequency Jonathan Cameron
  3 siblings, 1 reply; 6+ messages in thread
From: Song Hongyan @ 2016-12-30  9:23 UTC (permalink / raw)
  To: linux-iio; +Cc: jikos, jic23, srinivas.pandruvada, Song Hongyan

Check the validity of the sampling frequency set by user.

Signed-off-by: Song Hongyan <hongyan.song@intel.com>
---
 drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index ad30814..408c16e 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -221,12 +221,26 @@ int hid_sensor_read_max_samp_freq_value(struct hid_sensor_common *st,
 int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
 				int val1, int val2)
 {
+	int max_freq_int, max_freq_dec;
 	s32 value;
 	int ret;
 
 	if (val1 < 0 || val2 < 0)
 		ret = -EINVAL;
 
+	ret = hid_sensor_read_max_samp_freq_value(st, &max_freq_int,
+						&max_freq_dec);
+	if (ret >= 0) {
+		/*
+		 * check whether the input sample freqency value is larger than
+		 * the max_freq_value.
+		 */
+		if (val1 > max_freq_int || (val1 == max_freq_int &&
+				val2 > max_freq_dec))
+			return -EINVAL;
+	} else {
+		hid_info(st->hsdev->hdev, "No max_sample_frequency!!!\n");
+	}
 	value = val1 * pow_10(6) + val2;
 	if (value) {
 		if (st->poll.units == HID_USAGE_SENSOR_UNITS_MILLISECOND)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] iio: hid: Expose sensors max_sample_frequency nodes
  2016-12-30  9:23 [PATCH 1/4] iio: Add support for max_sampling_frequency Song Hongyan
  2016-12-30  9:23 ` [PATCH 2/4] iio: hid-sensors: API add max_sample_frequency Song Hongyan
  2016-12-30  9:23 ` [PATCH 3/4] iio: hid-sensor-attributes: Add input sample frequency check Song Hongyan
@ 2016-12-30  9:23 ` Song Hongyan
  2016-12-30 20:31 ` [PATCH 1/4] iio: Add support for max_sampling_frequency Jonathan Cameron
  3 siblings, 0 replies; 6+ messages in thread
From: Song Hongyan @ 2016-12-30  9:23 UTC (permalink / raw)
  To: linux-iio; +Cc: jikos, jic23, srinivas.pandruvada, Song Hongyan

Each sensor has their own min_report_interval which means
has max_sample_frequency, expose this node/attribute.

Signed-off-by: Song Hongyan <hongyan.song@intel.com>
---
 drivers/iio/accel/hid-sensor-accel-3d.c       | 12 ++++++++++++
 drivers/iio/gyro/hid-sensor-gyro-3d.c         |  7 +++++++
 drivers/iio/light/hid-sensor-als.c            |  5 +++++
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 11 +++++++++++
 drivers/iio/orientation/hid-sensor-incl-3d.c  |  7 +++++++
 drivers/iio/orientation/hid-sensor-rotation.c |  5 +++++
 drivers/iio/pressure/hid-sensor-press.c       |  5 +++++
 7 files changed, 52 insertions(+)

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 9edd574..cef3eb5 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -65,6 +65,7 @@ struct accel_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_X,
 	}, {
@@ -75,6 +76,7 @@ struct accel_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_Y,
 	}, {
@@ -85,6 +87,7 @@ struct accel_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_Z,
 	}
@@ -100,6 +103,7 @@ struct accel_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_X,
 	}, {
@@ -110,6 +114,7 @@ struct accel_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_Y,
 	}, {
@@ -120,6 +125,7 @@ struct accel_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_Z,
 	}
@@ -183,6 +189,12 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev,
 		ret_type = hid_sensor_read_samp_freq_value(
 			&accel_state->common_attributes, val, val2);
 		break;
+
+	case IIO_CHAN_INFO_MAX_SAMP_FREQ:
+		ret_type = hid_sensor_read_max_samp_freq_value(
+			&accel_state->common_attributes, val, val2);
+		break;
+
 	case IIO_CHAN_INFO_HYSTERESIS:
 		ret_type = hid_sensor_read_raw_hyst_value(
 			&accel_state->common_attributes, val, val2);
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index c67ce2a..f6c66ee 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -65,6 +65,7 @@ struct gyro_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_X,
 	}, {
@@ -75,6 +76,7 @@ struct gyro_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_Y,
 	}, {
@@ -85,6 +87,7 @@ struct gyro_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_Z,
 	}
@@ -147,6 +150,10 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev,
 		ret_type = hid_sensor_read_samp_freq_value(
 			&gyro_state->common_attributes, val, val2);
 		break;
+	case IIO_CHAN_INFO_MAX_SAMP_FREQ:
+		ret_type = hid_sensor_read_max_samp_freq_value(
+			&gyro_state->common_attributes, val, val2);
+		break;
 	case IIO_CHAN_INFO_HYSTERESIS:
 		ret_type = hid_sensor_read_raw_hyst_value(
 			&gyro_state->common_attributes, val, val2);
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 8bb1f90..acce7cf4 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -54,6 +54,7 @@ struct als_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_ILLUM,
 	}
@@ -124,6 +125,10 @@ static int als_read_raw(struct iio_dev *indio_dev,
 		ret_type = hid_sensor_read_samp_freq_value(
 				&als_state->common_attributes, val, val2);
 		break;
+	case IIO_CHAN_INFO_MAX_SAMP_FREQ:
+		ret_type = hid_sensor_read_max_samp_freq_value(
+			&als_state->common_attributes, val, val2);
+		break;
 	case IIO_CHAN_INFO_HYSTERESIS:
 		ret_type = hid_sensor_read_raw_hyst_value(
 				&als_state->common_attributes, val, val2);
diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index d8a0c8d..8b588ae 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -78,6 +78,7 @@ struct magn_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 	}, {
 		.type = IIO_MAGN,
@@ -87,6 +88,7 @@ struct magn_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 	}, {
 		.type = IIO_MAGN,
@@ -96,6 +98,7 @@ struct magn_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 	}, {
 		.type = IIO_ROT,
@@ -105,6 +108,7 @@ struct magn_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 	}, {
 		.type = IIO_ROT,
@@ -114,6 +118,7 @@ struct magn_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 	}, {
 		.type = IIO_ROT,
@@ -123,6 +128,7 @@ struct magn_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 	}, {
 		.type = IIO_ROT,
@@ -132,6 +138,7 @@ struct magn_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 	}
 };
@@ -194,6 +201,10 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev,
 		ret_type = hid_sensor_read_samp_freq_value(
 			&magn_state->common_attributes, val, val2);
 		break;
+	case IIO_CHAN_INFO_MAX_SAMP_FREQ:
+		ret_type = hid_sensor_read_max_samp_freq_value(
+			&magn_state->common_attributes, val, val2);
+		break;
 	case IIO_CHAN_INFO_HYSTERESIS:
 		ret_type = hid_sensor_read_raw_hyst_value(
 			&magn_state->common_attributes, val, val2);
diff --git a/drivers/iio/orientation/hid-sensor-incl-3d.c b/drivers/iio/orientation/hid-sensor-incl-3d.c
index fd1b369..d242cd2 100644
--- a/drivers/iio/orientation/hid-sensor-incl-3d.c
+++ b/drivers/iio/orientation/hid-sensor-incl-3d.c
@@ -65,6 +65,7 @@ struct incl_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_X,
 	}, {
@@ -75,6 +76,7 @@ struct incl_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_Y,
 	}, {
@@ -85,6 +87,7 @@ struct incl_3d_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_Z,
 	}
@@ -147,6 +150,10 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev,
 		ret_type = hid_sensor_read_samp_freq_value(
 			&incl_state->common_attributes, val, val2);
 		break;
+	case IIO_CHAN_INFO_MAX_SAMP_FREQ:
+		ret_type = hid_sensor_read_max_samp_freq_value(
+			&incl_state->common_attributes, val, val2);
+		break;
 	case IIO_CHAN_INFO_HYSTERESIS:
 		ret_type = hid_sensor_read_raw_hyst_value(
 			&incl_state->common_attributes, val, val2);
diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
index a97e802c..d4f579c 100644
--- a/drivers/iio/orientation/hid-sensor-rotation.c
+++ b/drivers/iio/orientation/hid-sensor-rotation.c
@@ -41,6 +41,7 @@ struct dev_rot_state {
 		.channel2 = IIO_MOD_QUATERNION,
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+					BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 					BIT(IIO_CHAN_INFO_HYSTERESIS)
 	}
 };
@@ -84,6 +85,10 @@ static int dev_rot_read_raw(struct iio_dev *indio_dev,
 		ret_type = hid_sensor_read_samp_freq_value(
 			&rot_state->common_attributes, &vals[0], &vals[1]);
 		break;
+	case IIO_CHAN_INFO_MAX_SAMP_FREQ:
+		ret_type = hid_sensor_read_max_samp_freq_value(
+			&rot_state->common_attributes, &vals[0], &vals[1]);
+		break;
 	case IIO_CHAN_INFO_HYSTERESIS:
 		ret_type = hid_sensor_read_raw_hyst_value(
 			&rot_state->common_attributes, &vals[0], &vals[1]);
diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c
index 6848d8c..4e822d1 100644
--- a/drivers/iio/pressure/hid-sensor-press.c
+++ b/drivers/iio/pressure/hid-sensor-press.c
@@ -51,6 +51,7 @@ struct press_state {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
 		BIT(IIO_CHAN_INFO_SCALE) |
 		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_MAX_SAMP_FREQ) |
 		BIT(IIO_CHAN_INFO_HYSTERESIS),
 		.scan_index = CHANNEL_SCAN_INDEX_PRESSURE,
 	}
@@ -121,6 +122,10 @@ static int press_read_raw(struct iio_dev *indio_dev,
 		ret_type = hid_sensor_read_samp_freq_value(
 				&press_state->common_attributes, val, val2);
 		break;
+	case IIO_CHAN_INFO_MAX_SAMP_FREQ:
+		ret_type = hid_sensor_read_max_samp_freq_value(
+				&press_state->common_attributes, val, val2);
+		break;
 	case IIO_CHAN_INFO_HYSTERESIS:
 		ret_type = hid_sensor_read_raw_hyst_value(
 				&press_state->common_attributes, val, val2);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/4] iio: Add support for max_sampling_frequency
  2016-12-30  9:23 [PATCH 1/4] iio: Add support for max_sampling_frequency Song Hongyan
                   ` (2 preceding siblings ...)
  2016-12-30  9:23 ` [PATCH 4/4] iio: hid: Expose sensors max_sample_frequency nodes Song Hongyan
@ 2016-12-30 20:31 ` Jonathan Cameron
  3 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2016-12-30 20:31 UTC (permalink / raw)
  To: Song Hongyan, linux-iio; +Cc: jikos, srinivas.pandruvada

On 30/12/16 09:23, Song Hongyan wrote:
> Add support for max_sampling_frequency, this will help user to
> set sampling frequency to an acceptable range.
> 
> Signed-off-by: Song Hongyan <hongyan.song@intel.com>
Hi,

We've recently added an extended version of _available which includes
the option for
[start_value step end_value] which will handle this well without having
to added additional ABI.

It's not well (read as 'not') documented as yet though except for
a few specific drivers that use it.  It's one of the tasks on my todo
list once I've caught up with reviews.

See the read_avail callback in struct iio_info and the associated
info_mask_separate_available etc.

Hopefully this new approach will finally solve the whole 'range'
of an attribute question.

Jonathan


> ---
>  Documentation/ABI/testing/sysfs-bus-iio | 7 +++++++
>  drivers/iio/industrialio-core.c         | 1 +
>  include/linux/iio/iio.h                 | 1 +
>  3 files changed, 9 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
> index 60b7406..cbcd2b8 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio
> +++ b/Documentation/ABI/testing/sysfs-bus-iio
> @@ -54,6 +54,13 @@ Description:
>  		relevant directories.  If it effects all of the above
>  		then it is to be found in the base device directory.
>  
> +What:		/sys/bus/iio/devices/iio:deviceX/max_sampling_frequency
> +KernelVersion:	4.11
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		This parameter shows the max sampling frequency, which can
> +		help user to set sampling frequency to an acceptable range.
> +
>  What:		/sys/bus/iio/devices/iio:deviceX/sampling_frequency_available
>  What:		/sys/.../iio:deviceX/buffer/sampling_frequency_available
>  What:		/sys/bus/iio/devices/triggerX/sampling_frequency_available
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 72fc96a..5203e75 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -140,6 +140,7 @@ struct bus_type iio_bus_type = {
>  	[IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY]
>  	= "filter_high_pass_3db_frequency",
>  	[IIO_CHAN_INFO_SAMP_FREQ] = "sampling_frequency",
> +	[IIO_CHAN_INFO_MAX_SAMP_FREQ] = "max_sampling_frequency",
>  	[IIO_CHAN_INFO_FREQUENCY] = "frequency",
>  	[IIO_CHAN_INFO_PHASE] = "phase",
>  	[IIO_CHAN_INFO_HARDWAREGAIN] = "hardwaregain",
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index b4a0679..f9eba2e 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -34,6 +34,7 @@ enum iio_chan_info_enum {
>  	IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY,
>  	IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY,
>  	IIO_CHAN_INFO_SAMP_FREQ,
> +	IIO_CHAN_INFO_MAX_SAMP_FREQ,
>  	IIO_CHAN_INFO_FREQUENCY,
>  	IIO_CHAN_INFO_PHASE,
>  	IIO_CHAN_INFO_HARDWAREGAIN,
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/4] iio: hid-sensor-attributes: Add input sample frequency check
  2016-12-30  9:23 ` [PATCH 3/4] iio: hid-sensor-attributes: Add input sample frequency check Song Hongyan
@ 2016-12-30 20:32   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2016-12-30 20:32 UTC (permalink / raw)
  To: Song Hongyan, linux-iio; +Cc: jikos, srinivas.pandruvada

On 30/12/16 09:23, Song Hongyan wrote:
> Check the validity of the sampling frequency set by user.
> 
> Signed-off-by: Song Hongyan <hongyan.song@intel.com>
Looks like a sensible addition. Will pick up when the rest of the series
is ready to go.

Jonathan
> ---
>  drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> index ad30814..408c16e 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> @@ -221,12 +221,26 @@ int hid_sensor_read_max_samp_freq_value(struct hid_sensor_common *st,
>  int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
>  				int val1, int val2)
>  {
> +	int max_freq_int, max_freq_dec;
>  	s32 value;
>  	int ret;
>  
>  	if (val1 < 0 || val2 < 0)
>  		ret = -EINVAL;
>  
> +	ret = hid_sensor_read_max_samp_freq_value(st, &max_freq_int,
> +						&max_freq_dec);
> +	if (ret >= 0) {
> +		/*
> +		 * check whether the input sample freqency value is larger than
> +		 * the max_freq_value.
> +		 */
> +		if (val1 > max_freq_int || (val1 == max_freq_int &&
> +				val2 > max_freq_dec))
> +			return -EINVAL;
> +	} else {
> +		hid_info(st->hsdev->hdev, "No max_sample_frequency!!!\n");
> +	}
>  	value = val1 * pow_10(6) + val2;
>  	if (value) {
>  		if (st->poll.units == HID_USAGE_SENSOR_UNITS_MILLISECOND)
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-12-30 20:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-30  9:23 [PATCH 1/4] iio: Add support for max_sampling_frequency Song Hongyan
2016-12-30  9:23 ` [PATCH 2/4] iio: hid-sensors: API add max_sample_frequency Song Hongyan
2016-12-30  9:23 ` [PATCH 3/4] iio: hid-sensor-attributes: Add input sample frequency check Song Hongyan
2016-12-30 20:32   ` Jonathan Cameron
2016-12-30  9:23 ` [PATCH 4/4] iio: hid: Expose sensors max_sample_frequency nodes Song Hongyan
2016-12-30 20:31 ` [PATCH 1/4] iio: Add support for max_sampling_frequency Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).