Commit a78587d3 authored by Song Hongyan's avatar Song Hongyan Committed by Jonathan Cameron

iio: hid-sensor-rotation: Add "scale" and "offset" properties parse support

Add orientation sensor "scale" and "offset" parse support.
These two properties are needed for exponent data conversion.
Signed-off-by: default avatarSong Hongyan <hongyan.song@intel.com>
Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@intel.com>
Reviewed-by: default avatarXu Even <even.xu@intel.com>
Acked-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 00907c7a
...@@ -69,6 +69,12 @@ static struct { ...@@ -69,6 +69,12 @@ static struct {
{HID_USAGE_SENSOR_TIME_TIMESTAMP, HID_USAGE_SENSOR_UNITS_MILLISECOND, {HID_USAGE_SENSOR_TIME_TIMESTAMP, HID_USAGE_SENSOR_UNITS_MILLISECOND,
1000000, 0}, 1000000, 0},
{HID_USAGE_SENSOR_DEVICE_ORIENTATION, 0, 1, 0},
{HID_USAGE_SENSOR_RELATIVE_ORIENTATION, 0, 1, 0},
{HID_USAGE_SENSOR_GEOMAGNETIC_ORIENTATION, 0, 1, 0},
{HID_USAGE_SENSOR_TEMPERATURE, 0, 1000, 0}, {HID_USAGE_SENSOR_TEMPERATURE, 0, 1000, 0},
{HID_USAGE_SENSOR_TEMPERATURE, HID_USAGE_SENSOR_UNITS_DEGREES, 1000, 0}, {HID_USAGE_SENSOR_TEMPERATURE, HID_USAGE_SENSOR_UNITS_DEGREES, 1000, 0},
......
...@@ -31,6 +31,10 @@ struct dev_rot_state { ...@@ -31,6 +31,10 @@ struct dev_rot_state {
struct hid_sensor_common common_attributes; struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info quaternion; struct hid_sensor_hub_attribute_info quaternion;
u32 sampled_vals[4]; u32 sampled_vals[4];
int scale_pre_decml;
int scale_post_decml;
int scale_precision;
int value_offset;
}; };
/* Channel definitions */ /* Channel definitions */
...@@ -41,6 +45,8 @@ static const struct iio_chan_spec dev_rot_channels[] = { ...@@ -41,6 +45,8 @@ static const struct iio_chan_spec dev_rot_channels[] = {
.channel2 = IIO_MOD_QUATERNION, .channel2 = IIO_MOD_QUATERNION,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) |
BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_HYSTERESIS) BIT(IIO_CHAN_INFO_HYSTERESIS)
} }
}; };
...@@ -80,6 +86,15 @@ static int dev_rot_read_raw(struct iio_dev *indio_dev, ...@@ -80,6 +86,15 @@ static int dev_rot_read_raw(struct iio_dev *indio_dev,
} else } else
ret_type = -EINVAL; ret_type = -EINVAL;
break; break;
case IIO_CHAN_INFO_SCALE:
vals[0] = rot_state->scale_pre_decml;
vals[1] = rot_state->scale_post_decml;
return rot_state->scale_precision;
case IIO_CHAN_INFO_OFFSET:
*vals = rot_state->value_offset;
return IIO_VAL_INT;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
ret_type = hid_sensor_read_samp_freq_value( ret_type = hid_sensor_read_samp_freq_value(
&rot_state->common_attributes, &vals[0], &vals[1]); &rot_state->common_attributes, &vals[0], &vals[1]);
...@@ -199,6 +214,11 @@ static int dev_rot_parse_report(struct platform_device *pdev, ...@@ -199,6 +214,11 @@ static int dev_rot_parse_report(struct platform_device *pdev,
dev_dbg(&pdev->dev, "dev_rot: attrib size %d\n", dev_dbg(&pdev->dev, "dev_rot: attrib size %d\n",
st->quaternion.size); st->quaternion.size);
st->scale_precision = hid_sensor_format_scale(
hsdev->usage,
&st->quaternion,
&st->scale_pre_decml, &st->scale_post_decml);
/* Set Sensitivity field ids, when there is no individual modifier */ /* Set Sensitivity field ids, when there is no individual modifier */
if (st->common_attributes.sensitivity.index < 0) { if (st->common_attributes.sensitivity.index < 0) {
sensor_hub_input_get_attribute_info(hsdev, sensor_hub_input_get_attribute_info(hsdev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment