diff options
| author | Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> | 2014-04-18 19:22:00 -0400 |
|---|---|---|
| committer | Jonathan Cameron <jic23@kernel.org> | 2014-05-05 05:59:50 -0400 |
| commit | 0964f706dc7feed8b676cba2dc28937a88e5c4f8 (patch) | |
| tree | 5561f0a2296326e6662e397bdd56c248aa0f8565 | |
| parent | c639945323253e962be6a56063273db1dbefc116 (diff) | |
iio: hid-sensors: Gyro 3D: Raw read support
Added support for raw reading of channel. If the sensor is powered
off, it will turn on for reading value.
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
| -rw-r--r-- | drivers/iio/gyro/hid-sensor-gyro-3d.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c index 392c30b8cd74..40f4e4935d0d 100644 --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | #include <linux/interrupt.h> | 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/irq.h> | 23 | #include <linux/irq.h> |
| 24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
| 25 | #include <linux/delay.h> | ||
| 25 | #include <linux/hid-sensor-hub.h> | 26 | #include <linux/hid-sensor-hub.h> |
| 26 | #include <linux/iio/iio.h> | 27 | #include <linux/iio/iio.h> |
| 27 | #include <linux/iio/sysfs.h> | 28 | #include <linux/iio/sysfs.h> |
| @@ -60,6 +61,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = { | |||
| 60 | .type = IIO_ANGL_VEL, | 61 | .type = IIO_ANGL_VEL, |
| 61 | .modified = 1, | 62 | .modified = 1, |
| 62 | .channel2 = IIO_MOD_X, | 63 | .channel2 = IIO_MOD_X, |
| 64 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), | ||
| 63 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | | 65 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | |
| 64 | BIT(IIO_CHAN_INFO_SCALE) | | 66 | BIT(IIO_CHAN_INFO_SCALE) | |
| 65 | BIT(IIO_CHAN_INFO_SAMP_FREQ) | | 67 | BIT(IIO_CHAN_INFO_SAMP_FREQ) | |
| @@ -69,6 +71,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = { | |||
| 69 | .type = IIO_ANGL_VEL, | 71 | .type = IIO_ANGL_VEL, |
| 70 | .modified = 1, | 72 | .modified = 1, |
| 71 | .channel2 = IIO_MOD_Y, | 73 | .channel2 = IIO_MOD_Y, |
| 74 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), | ||
| 72 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | | 75 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | |
| 73 | BIT(IIO_CHAN_INFO_SCALE) | | 76 | BIT(IIO_CHAN_INFO_SCALE) | |
| 74 | BIT(IIO_CHAN_INFO_SAMP_FREQ) | | 77 | BIT(IIO_CHAN_INFO_SAMP_FREQ) | |
| @@ -78,6 +81,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = { | |||
| 78 | .type = IIO_ANGL_VEL, | 81 | .type = IIO_ANGL_VEL, |
| 79 | .modified = 1, | 82 | .modified = 1, |
| 80 | .channel2 = IIO_MOD_Z, | 83 | .channel2 = IIO_MOD_Z, |
| 84 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), | ||
| 81 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | | 85 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | |
| 82 | BIT(IIO_CHAN_INFO_SCALE) | | 86 | BIT(IIO_CHAN_INFO_SCALE) | |
| 83 | BIT(IIO_CHAN_INFO_SAMP_FREQ) | | 87 | BIT(IIO_CHAN_INFO_SAMP_FREQ) | |
| @@ -108,22 +112,33 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev, | |||
| 108 | u32 address; | 112 | u32 address; |
| 109 | int ret; | 113 | int ret; |
| 110 | int ret_type; | 114 | int ret_type; |
| 115 | s32 poll_value; | ||
| 111 | 116 | ||
| 112 | *val = 0; | 117 | *val = 0; |
| 113 | *val2 = 0; | 118 | *val2 = 0; |
| 114 | switch (mask) { | 119 | switch (mask) { |
| 115 | case 0: | 120 | case 0: |
| 121 | poll_value = hid_sensor_read_poll_value( | ||
| 122 | &gyro_state->common_attributes); | ||
| 123 | if (poll_value < 0) | ||
| 124 | return -EINVAL; | ||
| 125 | |||
| 126 | hid_sensor_power_state(&gyro_state->common_attributes, true); | ||
| 127 | msleep_interruptible(poll_value * 2); | ||
| 116 | report_id = gyro_state->gyro[chan->scan_index].report_id; | 128 | report_id = gyro_state->gyro[chan->scan_index].report_id; |
| 117 | address = gyro_3d_addresses[chan->scan_index]; | 129 | address = gyro_3d_addresses[chan->scan_index]; |
| 118 | if (report_id >= 0) | 130 | if (report_id >= 0) |
| 119 | *val = sensor_hub_input_attr_get_raw_value( | 131 | *val = sensor_hub_input_attr_get_raw_value( |
| 120 | gyro_state->common_attributes.hsdev, | 132 | gyro_state->common_attributes.hsdev, |
| 121 | HID_USAGE_SENSOR_GYRO_3D, address, | 133 | HID_USAGE_SENSOR_GYRO_3D, address, |
| 122 | report_id); | 134 | report_id); |
| 123 | else { | 135 | else { |
| 124 | *val = 0; | 136 | *val = 0; |
| 137 | hid_sensor_power_state(&gyro_state->common_attributes, | ||
| 138 | false); | ||
| 125 | return -EINVAL; | 139 | return -EINVAL; |
| 126 | } | 140 | } |
| 141 | hid_sensor_power_state(&gyro_state->common_attributes, false); | ||
| 127 | ret_type = IIO_VAL_INT; | 142 | ret_type = IIO_VAL_INT; |
| 128 | break; | 143 | break; |
| 129 | case IIO_CHAN_INFO_SCALE: | 144 | case IIO_CHAN_INFO_SCALE: |
