Commit 0e41fd51 authored by Ye Xiang's avatar Ye Xiang Committed by Jonathan Cameron
Browse files

iio: hid-sensors: Move get sensitivity attribute to hid-sensor-common



No functional change has been made with this patch. The main intent here
is to reduce code repetition of getting sensitivity attribute.

In the current implementation, sensor_hub_input_get_attribute_info() is
called from multiple drivers to get attribute info for sensitivity
field. Moving this to common place will avoid code repetition.

Signed-off-by: default avatarYe Xiang <xiang.ye@intel.com>
Acked-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210201054921.18214-2-xiang.ye@intel.com


Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 6bc5ebe8
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
@@ -43,6 +43,10 @@ static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = {
	HID_USAGE_SENSOR_ACCEL_Z_AXIS
};

static const u32 accel_3d_sensitivity_addresses[] = {
	HID_USAGE_SENSOR_DATA_ACCELERATION,
};

/* Channel definitions */
static const struct iio_chan_spec accel_3d_channels[] = {
	{
@@ -317,18 +321,6 @@ static int accel_3d_parse_report(struct platform_device *pdev,
				&st->accel[CHANNEL_SCAN_INDEX_X],
				&st->scale_pre_decml, &st->scale_post_decml);

	/* Set Sensitivity field ids, when there is no individual modifier */
	if (st->common_attributes.sensitivity.index < 0) {
		sensor_hub_input_get_attribute_info(hsdev,
			HID_FEATURE_REPORT, usage_id,
			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
			HID_USAGE_SENSOR_DATA_ACCELERATION,
			&st->common_attributes.sensitivity);
		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
			st->common_attributes.sensitivity.index,
			st->common_attributes.sensitivity.report_id);
	}

	return ret;
}

@@ -366,8 +358,11 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
		channel_size = sizeof(gravity_channels);
		indio_dev->num_channels = ARRAY_SIZE(gravity_channels);
	}
	ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage,
					&accel_state->common_attributes);
	ret = hid_sensor_parse_common_attributes(hsdev,
						 hsdev->usage,
						 &accel_state->common_attributes,
						 accel_3d_sensitivity_addresses,
						 ARRAY_SIZE(accel_3d_sensitivity_addresses));
	if (ret) {
		dev_err(&pdev->dev, "failed to setup common attributes\n");
		return ret;
+16 −1
Original line number Diff line number Diff line
@@ -448,12 +448,15 @@ EXPORT_SYMBOL(hid_sensor_batch_mode_supported);

int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
					u32 usage_id,
					struct hid_sensor_common *st)
					struct hid_sensor_common *st,
					const u32 *sensitivity_addresses,
					u32 sensitivity_addresses_len)
{

	struct hid_sensor_hub_attribute_info timestamp;
	s32 value;
	int ret;
	int i;

	hid_sensor_get_reporting_interval(hsdev, usage_id, st);

@@ -475,6 +478,18 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
			HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS,
			 &st->sensitivity);

	/*
	 * Set Sensitivity field ids, when there is no individual modifier, will
	 * check absolute sensitivity of data field
	 */
	for (i = 0; i < sensitivity_addresses_len && st->sensitivity.index < 0; i++) {
		sensor_hub_input_get_attribute_info(hsdev,
				HID_FEATURE_REPORT, usage_id,
				HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
					sensitivity_addresses[i],
				&st->sensitivity);
	}

	st->raw_hystersis = -1;

	sensor_hub_input_get_attribute_info(hsdev,
+7 −12
Original line number Diff line number Diff line
@@ -45,6 +45,10 @@ static const u32 gyro_3d_addresses[GYRO_3D_CHANNEL_MAX] = {
	HID_USAGE_SENSOR_ANGL_VELOCITY_Z_AXIS
};

static const u32 gryo_3d_sensitivity_addresses[] = {
	HID_USAGE_SENSOR_DATA_ANGL_VELOCITY,
};

/* Channel definitions */
static const struct iio_chan_spec gyro_3d_channels[] = {
	{
@@ -271,17 +275,6 @@ static int gyro_3d_parse_report(struct platform_device *pdev,
				&st->gyro[CHANNEL_SCAN_INDEX_X],
				&st->scale_pre_decml, &st->scale_post_decml);

	/* Set Sensitivity field ids, when there is no individual modifier */
	if (st->common_attributes.sensitivity.index < 0) {
		sensor_hub_input_get_attribute_info(hsdev,
			HID_FEATURE_REPORT, usage_id,
			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
			HID_USAGE_SENSOR_DATA_ANGL_VELOCITY,
			&st->common_attributes.sensitivity);
		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
			st->common_attributes.sensitivity.index,
			st->common_attributes.sensitivity.report_id);
	}
	return ret;
}

@@ -305,7 +298,9 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)

	ret = hid_sensor_parse_common_attributes(hsdev,
						HID_USAGE_SENSOR_GYRO_3D,
						&gyro_state->common_attributes);
						&gyro_state->common_attributes,
						gryo_3d_sensitivity_addresses,
						ARRAY_SIZE(gryo_3d_sensitivity_addresses));
	if (ret) {
		dev_err(&pdev->dev, "failed to setup common attributes\n");
		return ret;
+7 −9
Original line number Diff line number Diff line
@@ -22,6 +22,10 @@ struct hid_humidity_state {
	int value_offset;
};

static const u32 humidity_sensitivity_addresses[] = {
	HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY,
};

/* Channel definitions */
static const struct iio_chan_spec humidity_channels[] = {
	{
@@ -174,14 +178,6 @@ static int humidity_parse_report(struct platform_device *pdev,
						&st->scale_pre_decml,
						&st->scale_post_decml);

	/* Set Sensitivity field ids, when there is no individual modifier */
	if (st->common_attributes.sensitivity.index < 0)
		sensor_hub_input_get_attribute_info(hsdev,
			HID_FEATURE_REPORT, usage_id,
			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
			HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY,
			&st->common_attributes.sensitivity);

	return ret;
}

@@ -210,7 +206,9 @@ static int hid_humidity_probe(struct platform_device *pdev)

	ret = hid_sensor_parse_common_attributes(hsdev,
					HID_USAGE_SENSOR_HUMIDITY,
					&humid_st->common_attributes);
					&humid_st->common_attributes,
					humidity_sensitivity_addresses,
					ARRAY_SIZE(humidity_sensitivity_addresses));
	if (ret)
		return ret;

+7 −12
Original line number Diff line number Diff line
@@ -39,6 +39,10 @@ struct als_state {
	s64 timestamp;
};

static const u32 als_sensitivity_addresses[] = {
	HID_USAGE_SENSOR_DATA_LIGHT,
};

/* Channel definitions */
static const struct iio_chan_spec als_channels[] = {
	{
@@ -252,17 +256,6 @@ static int als_parse_report(struct platform_device *pdev,
				&st->als_illum,
				&st->scale_pre_decml, &st->scale_post_decml);

	/* Set Sensitivity field ids, when there is no individual modifier */
	if (st->common_attributes.sensitivity.index < 0) {
		sensor_hub_input_get_attribute_info(hsdev,
			HID_FEATURE_REPORT, usage_id,
			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
			HID_USAGE_SENSOR_DATA_LIGHT,
			&st->common_attributes.sensitivity);
		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
			st->common_attributes.sensitivity.index,
			st->common_attributes.sensitivity.report_id);
	}
	return ret;
}

@@ -285,7 +278,9 @@ static int hid_als_probe(struct platform_device *pdev)
	als_state->common_attributes.pdev = pdev;

	ret = hid_sensor_parse_common_attributes(hsdev, HID_USAGE_SENSOR_ALS,
					&als_state->common_attributes);
					&als_state->common_attributes,
					als_sensitivity_addresses,
					ARRAY_SIZE(als_sensitivity_addresses));
	if (ret) {
		dev_err(&pdev->dev, "failed to setup common attributes\n");
		return ret;
Loading