提交 a3476ac6 编写于 作者: G Greg Kroah-Hartman

Merge tag 'iio-for-3.16b' of...

Merge tag 'iio-for-3.16b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next

Jonathan writes:

Second set of IIO new drivers, cleanups and functionality for the 3.16 cycle.

This set contains a change to the ABI for the hid-sensors drivers to bring them
in line with the long published documentation.  Unfortunately, rather than
reporting true scale and offset values via sysfs they were reporting
some magic numbers that could only be converted to anything useful using
the HID sensors specification. I missed this entirely through the introduction
of a number of drivers, only picking up on it recently.  Srinivas has had
user feedback about this as well. The patch set is too large to go as a fix
at this stage in the cycle and is not a regression fix as this was never
right and so will have to wait for the next merge window. Srinivas assures
me that there are relatively few pieces of hardware out there and he has
had a number of people contact him to point out that the drivers did not
obey the ABI.  Hence hopefully the fallout of this, if any will be minor.
If we don't fix it now, it will only get worse going forward. There is no
sensible way of maintaining the incorrect ABI as it is simply returning
the wrong values through the standard interfaces.

Non IIO elements
* Introduce devm_kmemdup.  Does what it says on the tin.

New drivers:
* hid-sensors rotation devices (output as quaternion)
* Freescale MPL115A2 presure and temperature sensor.
* Melexis mlx90614 contactless infrared sensor.
* Freescale MMA8452Q 3-axis accelerometer.

New functionality:
* Addition of multiple element callback to allow for sysfs interfaces to access
  elements such as quaternions which have no useful meaning if all 4 elements
  are not presented together.  Other future usecases for this include
  rotation matrices.
* Support for multiple element buffer entries for exactly the same uses as
  the sysfs related elements described above.
* Quaternion support via the quaternion IIO modifier.
* TEMP_AMBIENT and TEMP_OBJECT modifiers to distinguish cases with thermopile
  devices.
* hid-sensors gain sysfs access to the sensor readings. Previously these
  drivers used the buffered interface only.  This change involves some
  additional hid-sensors core support to read poll values back from the devices
  to allow the drivers to know roughly how long to wait for a result when
  polling the sensor.  There is also an associated hid-sensors abi to allow
  the devices to be turned off between reads and powered up on demand.

Cleanups and fixes
* Hid sensors fix as described above. Result is to make the _scale and _offset
  attributes applicable in the same way as for all other IIO drivers.
* Some additional documentation - mostly covering stuff that graduated from
  staging without managing to take it's ABI docs with it.
* A series of little tidy ups to the exynos_adc driver that make the code
  nicer to read and improve handling of some corner cases.
* A tidy up to mag3110 (logical fix rather than a real one ;). Also enable
  user offset calibration for this device.
* Drop some left over IS_ERR() checks from ad799x that snuck through during
  the cleanup in the last IIO patch set.
* Fix a naming issue from clashing patches in ak8975 - note the clash only
  occured in the last IIO patch set, hence the fix needs to go through this
  tree.
* A format string missmatch fix in ad7280.c. Unlikely to have ever had an
  impact so not worth rushing through.
...@@ -114,14 +114,17 @@ What: /sys/bus/iio/devices/iio:deviceX/in_temp_raw ...@@ -114,14 +114,17 @@ What: /sys/bus/iio/devices/iio:deviceX/in_temp_raw
What: /sys/bus/iio/devices/iio:deviceX/in_tempX_raw What: /sys/bus/iio/devices/iio:deviceX/in_tempX_raw
What: /sys/bus/iio/devices/iio:deviceX/in_temp_x_raw What: /sys/bus/iio/devices/iio:deviceX/in_temp_x_raw
What: /sys/bus/iio/devices/iio:deviceX/in_temp_y_raw What: /sys/bus/iio/devices/iio:deviceX/in_temp_y_raw
What: /sys/bus/iio/devices/iio:deviceX/in_temp_z_raw What: /sys/bus/iio/devices/iio:deviceX/in_temp_ambient_raw
What: /sys/bus/iio/devices/iio:deviceX/in_temp_object_raw
KernelVersion: 2.6.35 KernelVersion: 2.6.35
Contact: linux-iio@vger.kernel.org Contact: linux-iio@vger.kernel.org
Description: Description:
Raw (unscaled no bias removal etc.) temperature measurement. Raw (unscaled no bias removal etc.) temperature measurement.
If an axis is specified it generally means that the temperature If an axis is specified it generally means that the temperature
sensor is associated with one part of a compound device (e.g. sensor is associated with one part of a compound device (e.g.
a gyroscope axis). Units after application of scale and offset a gyroscope axis). The ambient and object modifiers distinguish
between ambient (reference) and distant temperature for contact-
less measurements. Units after application of scale and offset
are milli degrees Celsius. are milli degrees Celsius.
What: /sys/bus/iio/devices/iio:deviceX/in_tempX_input What: /sys/bus/iio/devices/iio:deviceX/in_tempX_input
...@@ -792,6 +795,7 @@ What: /sys/.../iio:deviceX/scan_elements/in_incli_x_en ...@@ -792,6 +795,7 @@ What: /sys/.../iio:deviceX/scan_elements/in_incli_x_en
What: /sys/.../iio:deviceX/scan_elements/in_incli_y_en What: /sys/.../iio:deviceX/scan_elements/in_incli_y_en
What: /sys/.../iio:deviceX/scan_elements/in_pressureY_en What: /sys/.../iio:deviceX/scan_elements/in_pressureY_en
What: /sys/.../iio:deviceX/scan_elements/in_pressure_en What: /sys/.../iio:deviceX/scan_elements/in_pressure_en
What: /sys/.../iio:deviceX/scan_elements/in_rot_quaternion_en
KernelVersion: 2.6.37 KernelVersion: 2.6.37
Contact: linux-iio@vger.kernel.org Contact: linux-iio@vger.kernel.org
Description: Description:
...@@ -807,6 +811,7 @@ What: /sys/.../iio:deviceX/scan_elements/in_voltageY_supply_type ...@@ -807,6 +811,7 @@ What: /sys/.../iio:deviceX/scan_elements/in_voltageY_supply_type
What: /sys/.../iio:deviceX/scan_elements/in_timestamp_type What: /sys/.../iio:deviceX/scan_elements/in_timestamp_type
What: /sys/.../iio:deviceX/scan_elements/in_pressureY_type What: /sys/.../iio:deviceX/scan_elements/in_pressureY_type
What: /sys/.../iio:deviceX/scan_elements/in_pressure_type What: /sys/.../iio:deviceX/scan_elements/in_pressure_type
What: /sys/.../iio:deviceX/scan_elements/in_rot_quaternion_type
KernelVersion: 2.6.37 KernelVersion: 2.6.37
Contact: linux-iio@vger.kernel.org Contact: linux-iio@vger.kernel.org
Description: Description:
...@@ -853,6 +858,7 @@ What: /sys/.../iio:deviceX/scan_elements/in_incli_y_index ...@@ -853,6 +858,7 @@ What: /sys/.../iio:deviceX/scan_elements/in_incli_y_index
What: /sys/.../iio:deviceX/scan_elements/in_timestamp_index What: /sys/.../iio:deviceX/scan_elements/in_timestamp_index
What: /sys/.../iio:deviceX/scan_elements/in_pressureY_index What: /sys/.../iio:deviceX/scan_elements/in_pressureY_index
What: /sys/.../iio:deviceX/scan_elements/in_pressure_index What: /sys/.../iio:deviceX/scan_elements/in_pressure_index
What: /sys/.../iio:deviceX/scan_elements/in_rot_quaternion_index
KernelVersion: 2.6.37 KernelVersion: 2.6.37
Contact: linux-iio@vger.kernel.org Contact: linux-iio@vger.kernel.org
Description: Description:
...@@ -889,6 +895,25 @@ Description: ...@@ -889,6 +895,25 @@ Description:
on-chip EEPROM. After power-up or chip reset the device will on-chip EEPROM. After power-up or chip reset the device will
automatically load the saved configuration. automatically load the saved configuration.
What: /sys/.../iio:deviceX/in_illuminanceY_input
What: /sys/.../iio:deviceX/in_illuminanceY_raw
What: /sys/.../iio:deviceX/in_illuminanceY_mean_raw
KernelVersion: 3.4
Contact: linux-iio@vger.kernel.org
Description:
Illuminance measurement, units after application of scale
and offset are lux.
What: /sys/.../iio:deviceX/in_intensityY_raw
What: /sys/.../iio:deviceX/in_intensityY_ir_raw
What: /sys/.../iio:deviceX/in_intensityY_both_raw
KernelVersion: 3.4
Contact: linux-iio@vger.kernel.org
Description:
Unit-less light intensity. Modifiers both and ir indicate
that measurements contains visible and infrared light
components or just infrared light, respectively.
What: /sys/.../iio:deviceX/in_intensity_red_integration_time What: /sys/.../iio:deviceX/in_intensity_red_integration_time
What: /sys/.../iio:deviceX/in_intensity_green_integration_time What: /sys/.../iio:deviceX/in_intensity_green_integration_time
What: /sys/.../iio:deviceX/in_intensity_blue_integration_time What: /sys/.../iio:deviceX/in_intensity_blue_integration_time
...@@ -899,3 +924,12 @@ Contact: linux-iio@vger.kernel.org ...@@ -899,3 +924,12 @@ Contact: linux-iio@vger.kernel.org
Description: Description:
This attribute is used to get/set the integration time in This attribute is used to get/set the integration time in
seconds. seconds.
What: /sys/bus/iio/devices/iio:deviceX/in_rot_quaternion_raw
KernelVersion: 3.15
Contact: linux-iio@vger.kernel.org
Description:
Raw value of quaternion components using a format
x y z w. Here x, y, and z component represents the axis about
which a rotation will occur and w component represents the
amount of rotation.
...@@ -236,6 +236,7 @@ certainly invest a bit more effort into libata core layer). ...@@ -236,6 +236,7 @@ certainly invest a bit more effort into libata core layer).
MEM MEM
devm_kzalloc() devm_kzalloc()
devm_kfree() devm_kfree()
devm_kmemdup()
IIO IIO
devm_iio_device_alloc() devm_iio_device_alloc()
......
...@@ -831,3 +831,24 @@ void devm_kfree(struct device *dev, void *p) ...@@ -831,3 +831,24 @@ void devm_kfree(struct device *dev, void *p)
WARN_ON(rc); WARN_ON(rc);
} }
EXPORT_SYMBOL_GPL(devm_kfree); EXPORT_SYMBOL_GPL(devm_kfree);
/**
* devm_kmemdup - Resource-managed kmemdup
* @dev: Device this memory belongs to
* @src: Memory region to duplicate
* @len: Memory region length
* @gfp: GFP mask to use
*
* Duplicate region of a memory using resource managed kmalloc
*/
void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp)
{
void *p;
p = devm_kmalloc(dev, len, gfp);
if (p)
memcpy(p, src, len);
return p;
}
EXPORT_SYMBOL_GPL(devm_kmemdup);
...@@ -65,4 +65,16 @@ config KXSD9 ...@@ -65,4 +65,16 @@ config KXSD9
Say yes here to build support for the Kionix KXSD9 accelerometer. Say yes here to build support for the Kionix KXSD9 accelerometer.
Currently this only supports the device via an SPI interface. Currently this only supports the device via an SPI interface.
config MMA8452
tristate "Freescale MMA8452Q Accelerometer Driver"
depends on I2C
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
help
Say yes here to build support for the Freescale MMA8452Q 3-axis
accelerometer.
To compile this driver as a module, choose M here: the module
will be called mma8452.
endmenu endmenu
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
obj-$(CONFIG_BMA180) += bma180.o obj-$(CONFIG_BMA180) += bma180.o
obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
obj-$(CONFIG_KXSD9) += kxsd9.o obj-$(CONFIG_KXSD9) += kxsd9.o
obj-$(CONFIG_MMA8452) += mma8452.o
obj-$(CONFIG_IIO_ST_ACCEL_3AXIS) += st_accel.o obj-$(CONFIG_IIO_ST_ACCEL_3AXIS) += st_accel.o
st_accel-y := st_accel_core.o st_accel-y := st_accel_core.o
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/delay.h>
#include <linux/hid-sensor-hub.h> #include <linux/hid-sensor-hub.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
...@@ -42,6 +43,10 @@ struct accel_3d_state { ...@@ -42,6 +43,10 @@ struct accel_3d_state {
struct hid_sensor_common common_attributes; struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX]; struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX];
u32 accel_val[ACCEL_3D_CHANNEL_MAX]; u32 accel_val[ACCEL_3D_CHANNEL_MAX];
int scale_pre_decml;
int scale_post_decml;
int scale_precision;
int value_offset;
}; };
static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = { static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = {
...@@ -56,6 +61,7 @@ static const struct iio_chan_spec accel_3d_channels[] = { ...@@ -56,6 +61,7 @@ static const struct iio_chan_spec accel_3d_channels[] = {
.type = IIO_ACCEL, .type = IIO_ACCEL,
.modified = 1, .modified = 1,
.channel2 = IIO_MOD_X, .channel2 = IIO_MOD_X,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_SAMP_FREQ) |
...@@ -65,6 +71,7 @@ static const struct iio_chan_spec accel_3d_channels[] = { ...@@ -65,6 +71,7 @@ static const struct iio_chan_spec accel_3d_channels[] = {
.type = IIO_ACCEL, .type = IIO_ACCEL,
.modified = 1, .modified = 1,
.channel2 = IIO_MOD_Y, .channel2 = IIO_MOD_Y,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_SAMP_FREQ) |
...@@ -74,6 +81,7 @@ static const struct iio_chan_spec accel_3d_channels[] = { ...@@ -74,6 +81,7 @@ static const struct iio_chan_spec accel_3d_channels[] = {
.type = IIO_ACCEL, .type = IIO_ACCEL,
.modified = 1, .modified = 1,
.channel2 = IIO_MOD_Z, .channel2 = IIO_MOD_Z,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_SAMP_FREQ) |
...@@ -104,31 +112,42 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev, ...@@ -104,31 +112,42 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev,
u32 address; u32 address;
int ret; int ret;
int ret_type; int ret_type;
s32 poll_value;
*val = 0; *val = 0;
*val2 = 0; *val2 = 0;
switch (mask) { switch (mask) {
case 0: case 0:
poll_value = hid_sensor_read_poll_value(
&accel_state->common_attributes);
if (poll_value < 0)
return -EINVAL;
hid_sensor_power_state(&accel_state->common_attributes, true);
msleep_interruptible(poll_value * 2);
report_id = accel_state->accel[chan->scan_index].report_id; report_id = accel_state->accel[chan->scan_index].report_id;
address = accel_3d_addresses[chan->scan_index]; address = accel_3d_addresses[chan->scan_index];
if (report_id >= 0) if (report_id >= 0)
*val = sensor_hub_input_attr_get_raw_value( *val = sensor_hub_input_attr_get_raw_value(
accel_state->common_attributes.hsdev, accel_state->common_attributes.hsdev,
HID_USAGE_SENSOR_ACCEL_3D, address, HID_USAGE_SENSOR_ACCEL_3D, address,
report_id); report_id);
else { else {
*val = 0; *val = 0;
hid_sensor_power_state(&accel_state->common_attributes,
false);
return -EINVAL; return -EINVAL;
} }
hid_sensor_power_state(&accel_state->common_attributes, false);
ret_type = IIO_VAL_INT; ret_type = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
*val = accel_state->accel[CHANNEL_SCAN_INDEX_X].units; *val = accel_state->scale_pre_decml;
ret_type = IIO_VAL_INT; *val2 = accel_state->scale_post_decml;
ret_type = accel_state->scale_precision;
break; break;
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
*val = hid_sensor_convert_exponent( *val = accel_state->value_offset;
accel_state->accel[CHANNEL_SCAN_INDEX_X].unit_expo);
ret_type = IIO_VAL_INT; ret_type = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
...@@ -197,9 +216,8 @@ static int accel_3d_proc_event(struct hid_sensor_hub_device *hsdev, ...@@ -197,9 +216,8 @@ static int accel_3d_proc_event(struct hid_sensor_hub_device *hsdev,
struct iio_dev *indio_dev = platform_get_drvdata(priv); struct iio_dev *indio_dev = platform_get_drvdata(priv);
struct accel_3d_state *accel_state = iio_priv(indio_dev); struct accel_3d_state *accel_state = iio_priv(indio_dev);
dev_dbg(&indio_dev->dev, "accel_3d_proc_event [%d]\n", dev_dbg(&indio_dev->dev, "accel_3d_proc_event\n");
accel_state->common_attributes.data_ready); if (atomic_read(&accel_state->common_attributes.data_ready))
if (accel_state->common_attributes.data_ready)
hid_sensor_push_data(indio_dev, hid_sensor_push_data(indio_dev,
accel_state->accel_val, accel_state->accel_val,
sizeof(accel_state->accel_val)); sizeof(accel_state->accel_val));
...@@ -262,6 +280,11 @@ static int accel_3d_parse_report(struct platform_device *pdev, ...@@ -262,6 +280,11 @@ static int accel_3d_parse_report(struct platform_device *pdev,
st->accel[1].index, st->accel[1].report_id, st->accel[1].index, st->accel[1].report_id,
st->accel[2].index, st->accel[2].report_id); st->accel[2].index, st->accel[2].report_id);
st->scale_precision = hid_sensor_format_scale(
HID_USAGE_SENSOR_ACCEL_3D,
&st->accel[CHANNEL_SCAN_INDEX_X],
&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,
...@@ -333,7 +356,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev) ...@@ -333,7 +356,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "failed to initialize trigger buffer\n"); dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
goto error_free_dev_mem; goto error_free_dev_mem;
} }
accel_state->common_attributes.data_ready = false; atomic_set(&accel_state->common_attributes.data_ready, 0);
ret = hid_sensor_setup_trigger(indio_dev, name, ret = hid_sensor_setup_trigger(indio_dev, name,
&accel_state->common_attributes); &accel_state->common_attributes);
if (ret < 0) { if (ret < 0) {
......
/*
* mma8452.c - Support for Freescale MMA8452Q 3-axis 12-bit accelerometer
*
* Copyright 2014 Peter Meerwald <pmeerw@pmeerw.net>
*
* This file is subject to the terms and conditions of version 2 of
* the GNU General Public License. See the file COPYING in the main
* directory of this archive for more details.
*
* 7-bit I2C slave address 0x1c/0x1d (pin selectable)
*
* TODO: interrupt, thresholding, orientation / freefall events, autosleep
*/
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/buffer.h>
#include <linux/iio/triggered_buffer.h>
#include <linux/delay.h>
#define MMA8452_STATUS 0x00
#define MMA8452_OUT_X 0x01 /* MSB first, 12-bit */
#define MMA8452_OUT_Y 0x03
#define MMA8452_OUT_Z 0x05
#define MMA8452_WHO_AM_I 0x0d
#define MMA8452_DATA_CFG 0x0e
#define MMA8452_OFF_X 0x2f
#define MMA8452_OFF_Y 0x30
#define MMA8452_OFF_Z 0x31
#define MMA8452_CTRL_REG1 0x2a
#define MMA8452_CTRL_REG2 0x2b
#define MMA8452_STATUS_DRDY (BIT(2) | BIT(1) | BIT(0))
#define MMA8452_CTRL_DR_MASK (BIT(5) | BIT(4) | BIT(3))
#define MMA8452_CTRL_DR_SHIFT 3
#define MMA8452_CTRL_DR_DEFAULT 0x4 /* 50 Hz sample frequency */
#define MMA8452_CTRL_ACTIVE BIT(0)
#define MMA8452_DATA_CFG_FS_MASK (BIT(1) | BIT(0))
#define MMA8452_DATA_CFG_FS_2G 0
#define MMA8452_DATA_CFG_FS_4G 1
#define MMA8452_DATA_CFG_FS_8G 2
#define MMA8452_DEVICE_ID 0x2a
struct mma8452_data {
struct i2c_client *client;
struct mutex lock;
u8 ctrl_reg1;
u8 data_cfg;
};
static int mma8452_drdy(struct mma8452_data *data)
{
int tries = 150;
while (tries-- > 0) {
int ret = i2c_smbus_read_byte_data(data->client,
MMA8452_STATUS);
if (ret < 0)
return ret;
if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY)
return 0;
msleep(20);
}
dev_err(&data->client->dev, "data not ready\n");
return -EIO;
}
static int mma8452_read(struct mma8452_data *data, __be16 buf[3])
{
int ret = mma8452_drdy(data);
if (ret < 0)
return ret;
return i2c_smbus_read_i2c_block_data(data->client,
MMA8452_OUT_X, 3 * sizeof(__be16), (u8 *) buf);
}
static ssize_t mma8452_show_int_plus_micros(char *buf,
const int (*vals)[2], int n)
{
size_t len = 0;
while (n-- > 0)
len += scnprintf(buf + len, PAGE_SIZE - len,
"%d.%06d ", vals[n][0], vals[n][1]);
/* replace trailing space by newline */
buf[len - 1] = '\n';
return len;
}
static int mma8452_get_int_plus_micros_index(const int (*vals)[2], int n,
int val, int val2)
{
while (n-- > 0)
if (val == vals[n][0] && val2 == vals[n][1])
return n;
return -EINVAL;
}
static const int mma8452_samp_freq[8][2] = {
{800, 0}, {400, 0}, {200, 0}, {100, 0}, {50, 0}, {12, 500000},
{6, 250000}, {1, 560000}
};
static const int mma8452_scales[3][2] = {
{0, 977}, {0, 1953}, {0, 3906}
};
static ssize_t mma8452_show_samp_freq_avail(struct device *dev,
struct device_attribute *attr, char *buf)
{
return mma8452_show_int_plus_micros(buf, mma8452_samp_freq,
ARRAY_SIZE(mma8452_samp_freq));
}
static ssize_t mma8452_show_scale_avail(struct device *dev,
struct device_attribute *attr, char *buf)
{
return mma8452_show_int_plus_micros(buf, mma8452_scales,
ARRAY_SIZE(mma8452_scales));
}
static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(mma8452_show_samp_freq_avail);
static IIO_DEVICE_ATTR(in_accel_scale_available, S_IRUGO,
mma8452_show_scale_avail, NULL, 0);
static int mma8452_get_samp_freq_index(struct mma8452_data *data,
int val, int val2)
{
return mma8452_get_int_plus_micros_index(mma8452_samp_freq,
ARRAY_SIZE(mma8452_samp_freq), val, val2);
}
static int mma8452_get_scale_index(struct mma8452_data *data,
int val, int val2)
{
return mma8452_get_int_plus_micros_index(mma8452_scales,
ARRAY_SIZE(mma8452_scales), val, val2);
}
static int mma8452_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct mma8452_data *data = iio_priv(indio_dev);
__be16 buffer[3];
int i, ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
if (iio_buffer_enabled(indio_dev))
return -EBUSY;
mutex_lock(&data->lock);
ret = mma8452_read(data, buffer);
mutex_unlock(&data->lock);
if (ret < 0)
return ret;
*val = sign_extend32(
be16_to_cpu(buffer[chan->scan_index]) >> 4, 11);
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
i = data->data_cfg & MMA8452_DATA_CFG_FS_MASK;
*val = mma8452_scales[i][0];
*val2 = mma8452_scales[i][1];
return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_SAMP_FREQ:
i = (data->ctrl_reg1 & MMA8452_CTRL_DR_MASK) >>
MMA8452_CTRL_DR_SHIFT;
*val = mma8452_samp_freq[i][0];
*val2 = mma8452_samp_freq[i][1];
return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_CALIBBIAS:
ret = i2c_smbus_read_byte_data(data->client, MMA8452_OFF_X +
chan->scan_index);
if (ret < 0)
return ret;
*val = sign_extend32(ret, 7);
return IIO_VAL_INT;
}
return -EINVAL;
}
static int mma8452_standby(struct mma8452_data *data)
{
return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
data->ctrl_reg1 & ~MMA8452_CTRL_ACTIVE);
}
static int mma8452_active(struct mma8452_data *data)
{
return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
data->ctrl_reg1);
}
static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val)
{
int ret;
mutex_lock(&data->lock);
/* config can only be changed when in standby */
ret = mma8452_standby(data);
if (ret < 0)
goto fail;
ret = i2c_smbus_write_byte_data(data->client, reg, val);
if (ret < 0)
goto fail;
ret = mma8452_active(data);
if (ret < 0)
goto fail;
ret = 0;
fail:
mutex_unlock(&data->lock);
return ret;
}
static int mma8452_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val, int val2, long mask)
{
struct mma8452_data *data = iio_priv(indio_dev);
int i;
if (iio_buffer_enabled(indio_dev))
return -EBUSY;
switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ:
i = mma8452_get_samp_freq_index(data, val, val2);
if (i < 0)
return -EINVAL;
data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;
return mma8452_change_config(data, MMA8452_CTRL_REG1,
data->ctrl_reg1);
case IIO_CHAN_INFO_SCALE:
i = mma8452_get_scale_index(data, val, val2);
if (i < 0)
return -EINVAL;
data->data_cfg &= ~MMA8452_DATA_CFG_FS_MASK;
data->data_cfg |= i;
return mma8452_change_config(data, MMA8452_DATA_CFG,
data->data_cfg);
case IIO_CHAN_INFO_CALIBBIAS:
if (val < -128 || val > 127)
return -EINVAL;
return mma8452_change_config(data, MMA8452_OFF_X +
chan->scan_index, val);
default:
return -EINVAL;
}
}
static irqreturn_t mma8452_trigger_handler(int irq, void *p)
{
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
struct mma8452_data *data = iio_priv(indio_dev);
u8 buffer[16]; /* 3 16-bit channels + padding + ts */
int ret;
ret = mma8452_read(data, (__be16 *) buffer);
if (ret < 0)
goto done;
iio_push_to_buffers_with_timestamp(indio_dev, buffer,
iio_get_time_ns());
done:
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
}
#define MMA8452_CHANNEL(axis, idx) { \
.type = IIO_ACCEL, \
.modified = 1, \
.channel2 = IIO_MOD_##axis, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
BIT(IIO_CHAN_INFO_CALIBBIAS), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
BIT(IIO_CHAN_INFO_SCALE), \
.scan_index = idx, \
.scan_type = { \
.sign = 's', \
.realbits = 12, \
.storagebits = 16, \
.shift = 4, \
.endianness = IIO_BE, \
}, \
}
static const struct iio_chan_spec mma8452_channels[] = {
MMA8452_CHANNEL(X, 0),
MMA8452_CHANNEL(Y, 1),
MMA8452_CHANNEL(Z, 2),
IIO_CHAN_SOFT_TIMESTAMP(3),
};
static struct attribute *mma8452_attributes[] = {
&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
&iio_dev_attr_in_accel_scale_available.dev_attr.attr,
NULL
};
static const struct attribute_group mma8452_group = {
.attrs = mma8452_attributes,
};
static const struct iio_info mma8452_info = {
.attrs = &mma8452_group,
.read_raw = &mma8452_read_raw,
.write_raw = &mma8452_write_raw,
.driver_module = THIS_MODULE,
};
static const unsigned long mma8452_scan_masks[] = {0x7, 0};
static int mma8452_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct mma8452_data *data;
struct iio_dev *indio_dev;
int ret;
ret = i2c_smbus_read_byte_data(client, MMA8452_WHO_AM_I);
if (ret < 0)
return ret;
if (ret != MMA8452_DEVICE_ID)
return -ENODEV;
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
if (!indio_dev)
return -ENOMEM;
data = iio_priv(indio_dev);
data->client = client;
mutex_init(&data->lock);
i2c_set_clientdata(client, indio_dev);
indio_dev->info = &mma8452_info;
indio_dev->name = id->name;
indio_dev->dev.parent = &client->dev;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = mma8452_channels;
indio_dev->num_channels = ARRAY_SIZE(mma8452_channels);
indio_dev->available_scan_masks = mma8452_scan_masks;
data->ctrl_reg1 = MMA8452_CTRL_ACTIVE |
(MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT);
ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1,
data->ctrl_reg1);
if (ret < 0)
return ret;
data->data_cfg = MMA8452_DATA_CFG_FS_2G;
ret = i2c_smbus_write_byte_data(client, MMA8452_DATA_CFG,
data->data_cfg);
if (ret < 0)
return ret;
ret = iio_triggered_buffer_setup(indio_dev, NULL,
mma8452_trigger_handler, NULL);
if (ret < 0)
return ret;
ret = iio_device_register(indio_dev);
if (ret < 0)
goto buffer_cleanup;
return 0;
buffer_cleanup:
iio_triggered_buffer_cleanup(indio_dev);
return ret;
}
static int mma8452_remove(struct i2c_client *client)
{
struct iio_dev *indio_dev = i2c_get_clientdata(client);
iio_device_unregister(indio_dev);
iio_triggered_buffer_cleanup(indio_dev);
mma8452_standby(iio_priv(indio_dev));
return 0;
}
#ifdef CONFIG_PM_SLEEP
static int mma8452_suspend(struct device *dev)
{
return mma8452_standby(iio_priv(i2c_get_clientdata(
to_i2c_client(dev))));
}
static int mma8452_resume(struct device *dev)
{
return mma8452_active(iio_priv(i2c_get_clientdata(
to_i2c_client(dev))));
}
static SIMPLE_DEV_PM_OPS(mma8452_pm_ops, mma8452_suspend, mma8452_resume);
#define MMA8452_PM_OPS (&mma8452_pm_ops)
#else
#define MMA8452_PM_OPS NULL
#endif
static const struct i2c_device_id mma8452_id[] = {
{ "mma8452", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, mma8452_id);
static struct i2c_driver mma8452_driver = {
.driver = {
.name = "mma8452",
.pm = MMA8452_PM_OPS,
},
.probe = mma8452_probe,
.remove = mma8452_remove,
.id_table = mma8452_id,
};
module_i2c_driver(mma8452_driver);
MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
MODULE_DESCRIPTION("Freescale MMA8452 accelerometer driver");
MODULE_LICENSE("GPL");
...@@ -717,7 +717,7 @@ static int ad799x_probe(struct i2c_client *client, ...@@ -717,7 +717,7 @@ static int ad799x_probe(struct i2c_client *client,
ret = iio_triggered_buffer_setup(indio_dev, NULL, ret = iio_triggered_buffer_setup(indio_dev, NULL,
&ad799x_trigger_handler, NULL); &ad799x_trigger_handler, NULL);
if (ret) if (ret)
goto error_disable_reg; goto error_disable_vref;
if (client->irq > 0) { if (client->irq > 0) {
ret = devm_request_threaded_irq(&client->dev, ret = devm_request_threaded_irq(&client->dev,
...@@ -739,11 +739,10 @@ static int ad799x_probe(struct i2c_client *client, ...@@ -739,11 +739,10 @@ static int ad799x_probe(struct i2c_client *client,
error_cleanup_ring: error_cleanup_ring:
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
error_disable_vref:
regulator_disable(st->vref);
error_disable_reg: error_disable_reg:
if (!IS_ERR(st->vref)) regulator_disable(st->reg);
regulator_disable(st->vref);
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
return ret; return ret;
} }
...@@ -756,10 +755,8 @@ static int ad799x_remove(struct i2c_client *client) ...@@ -756,10 +755,8 @@ static int ad799x_remove(struct i2c_client *client)
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
if (!IS_ERR(st->vref)) regulator_disable(st->vref);
regulator_disable(st->vref); regulator_disable(st->reg);
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
kfree(st->rx_buf); kfree(st->rx_buf);
return 0; return 0;
......
...@@ -82,7 +82,7 @@ enum adc_version { ...@@ -82,7 +82,7 @@ enum adc_version {
#define ADC_CON_EN_START (1u << 0) #define ADC_CON_EN_START (1u << 0)
#define ADC_DATX_MASK 0xFFF #define ADC_DATX_MASK 0xFFF
#define EXYNOS_ADC_TIMEOUT (msecs_to_jiffies(1000)) #define EXYNOS_ADC_TIMEOUT (msecs_to_jiffies(100))
struct exynos_adc { struct exynos_adc {
void __iomem *regs; void __iomem *regs;
...@@ -112,6 +112,30 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev) ...@@ -112,6 +112,30 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
return (unsigned int)match->data; return (unsigned int)match->data;
} }
static void exynos_adc_hw_init(struct exynos_adc *info)
{
u32 con1, con2;
if (info->version == ADC_V2) {
con1 = ADC_V2_CON1_SOFT_RESET;
writel(con1, ADC_V2_CON1(info->regs));
con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
writel(con2, ADC_V2_CON2(info->regs));
/* Enable interrupts */
writel(1, ADC_V2_INT_EN(info->regs));
} else {
/* set default prescaler values and Enable prescaler */
con1 = ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
/* Enable 12-bit ADC resolution */
con1 |= ADC_V1_CON_RES;
writel(con1, ADC_V1_CON(info->regs));
}
}
static int exynos_read_raw(struct iio_dev *indio_dev, static int exynos_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, struct iio_chan_spec const *chan,
int *val, int *val,
...@@ -121,11 +145,13 @@ static int exynos_read_raw(struct iio_dev *indio_dev, ...@@ -121,11 +145,13 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
struct exynos_adc *info = iio_priv(indio_dev); struct exynos_adc *info = iio_priv(indio_dev);
unsigned long timeout; unsigned long timeout;
u32 con1, con2; u32 con1, con2;
int ret;
if (mask != IIO_CHAN_INFO_RAW) if (mask != IIO_CHAN_INFO_RAW)
return -EINVAL; return -EINVAL;
mutex_lock(&indio_dev->mlock); mutex_lock(&indio_dev->mlock);
reinit_completion(&info->completion);
/* Select the channel to be used and Trigger conversion */ /* Select the channel to be used and Trigger conversion */
if (info->version == ADC_V2) { if (info->version == ADC_V2) {
...@@ -145,16 +171,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev, ...@@ -145,16 +171,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
ADC_V1_CON(info->regs)); ADC_V1_CON(info->regs));
} }
timeout = wait_for_completion_interruptible_timeout timeout = wait_for_completion_timeout
(&info->completion, EXYNOS_ADC_TIMEOUT); (&info->completion, EXYNOS_ADC_TIMEOUT);
*val = info->value; if (timeout == 0) {
dev_warn(&indio_dev->dev, "Conversion timed out! Resetting\n");
exynos_adc_hw_init(info);
ret = -ETIMEDOUT;
} else {
*val = info->value;
*val2 = 0;
ret = IIO_VAL_INT;
}
mutex_unlock(&indio_dev->mlock); mutex_unlock(&indio_dev->mlock);
if (timeout == 0) return ret;
return -ETIMEDOUT;
return IIO_VAL_INT;
} }
static irqreturn_t exynos_adc_isr(int irq, void *dev_id) static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
...@@ -226,30 +257,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c) ...@@ -226,30 +257,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
return 0; return 0;
} }
static void exynos_adc_hw_init(struct exynos_adc *info)
{
u32 con1, con2;
if (info->version == ADC_V2) {
con1 = ADC_V2_CON1_SOFT_RESET;
writel(con1, ADC_V2_CON1(info->regs));
con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
writel(con2, ADC_V2_CON2(info->regs));
/* Enable interrupts */
writel(1, ADC_V2_INT_EN(info->regs));
} else {
/* set default prescaler values and Enable prescaler */
con1 = ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
/* Enable 12-bit ADC resolution */
con1 |= ADC_V1_CON_RES;
writel(con1, ADC_V1_CON(info->regs));
}
}
static int exynos_adc_probe(struct platform_device *pdev) static int exynos_adc_probe(struct platform_device *pdev)
{ {
struct exynos_adc *info = NULL; struct exynos_adc *info = NULL;
...@@ -290,32 +297,30 @@ static int exynos_adc_probe(struct platform_device *pdev) ...@@ -290,32 +297,30 @@ static int exynos_adc_probe(struct platform_device *pdev)
init_completion(&info->completion); init_completion(&info->completion);
ret = request_irq(info->irq, exynos_adc_isr,
0, dev_name(&pdev->dev), info);
if (ret < 0) {
dev_err(&pdev->dev, "failed requesting irq, irq = %d\n",
info->irq);
return ret;
}
writel(1, info->enable_reg);
info->clk = devm_clk_get(&pdev->dev, "adc"); info->clk = devm_clk_get(&pdev->dev, "adc");
if (IS_ERR(info->clk)) { if (IS_ERR(info->clk)) {
dev_err(&pdev->dev, "failed getting clock, err = %ld\n", dev_err(&pdev->dev, "failed getting clock, err = %ld\n",
PTR_ERR(info->clk)); PTR_ERR(info->clk));
ret = PTR_ERR(info->clk); return PTR_ERR(info->clk);
goto err_irq;
} }
info->vdd = devm_regulator_get(&pdev->dev, "vdd"); info->vdd = devm_regulator_get(&pdev->dev, "vdd");
if (IS_ERR(info->vdd)) { if (IS_ERR(info->vdd)) {
dev_err(&pdev->dev, "failed getting regulator, err = %ld\n", dev_err(&pdev->dev, "failed getting regulator, err = %ld\n",
PTR_ERR(info->vdd)); PTR_ERR(info->vdd));
ret = PTR_ERR(info->vdd); return PTR_ERR(info->vdd);
goto err_irq;
} }
ret = regulator_enable(info->vdd);
if (ret)
return ret;
ret = clk_prepare_enable(info->clk);
if (ret)
goto err_disable_reg;
writel(1, info->enable_reg);
info->version = exynos_adc_get_version(pdev); info->version = exynos_adc_get_version(pdev);
platform_set_drvdata(pdev, indio_dev); platform_set_drvdata(pdev, indio_dev);
...@@ -332,16 +337,18 @@ static int exynos_adc_probe(struct platform_device *pdev) ...@@ -332,16 +337,18 @@ static int exynos_adc_probe(struct platform_device *pdev)
else else
indio_dev->num_channels = MAX_ADC_V2_CHANNELS; indio_dev->num_channels = MAX_ADC_V2_CHANNELS;
ret = request_irq(info->irq, exynos_adc_isr,
0, dev_name(&pdev->dev), info);
if (ret < 0) {
dev_err(&pdev->dev, "failed requesting irq, irq = %d\n",
info->irq);
goto err_disable_clk;
}
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
goto err_irq; goto err_irq;
ret = regulator_enable(info->vdd);
if (ret)
goto err_iio_dev;
clk_prepare_enable(info->clk);
exynos_adc_hw_init(info); exynos_adc_hw_init(info);
ret = of_platform_populate(np, exynos_adc_match, NULL, &pdev->dev); ret = of_platform_populate(np, exynos_adc_match, NULL, &pdev->dev);
...@@ -355,12 +362,14 @@ static int exynos_adc_probe(struct platform_device *pdev) ...@@ -355,12 +362,14 @@ static int exynos_adc_probe(struct platform_device *pdev)
err_of_populate: err_of_populate:
device_for_each_child(&pdev->dev, NULL, device_for_each_child(&pdev->dev, NULL,
exynos_adc_remove_devices); exynos_adc_remove_devices);
regulator_disable(info->vdd);
clk_disable_unprepare(info->clk);
err_iio_dev:
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
err_irq: err_irq:
free_irq(info->irq, info); free_irq(info->irq, info);
err_disable_clk:
writel(0, info->enable_reg);
clk_disable_unprepare(info->clk);
err_disable_reg:
regulator_disable(info->vdd);
return ret; return ret;
} }
...@@ -371,11 +380,11 @@ static int exynos_adc_remove(struct platform_device *pdev) ...@@ -371,11 +380,11 @@ static int exynos_adc_remove(struct platform_device *pdev)
device_for_each_child(&pdev->dev, NULL, device_for_each_child(&pdev->dev, NULL,
exynos_adc_remove_devices); exynos_adc_remove_devices);
regulator_disable(info->vdd);
clk_disable_unprepare(info->clk);
writel(0, info->enable_reg);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
free_irq(info->irq, info); free_irq(info->irq, info);
writel(0, info->enable_reg);
clk_disable_unprepare(info->clk);
regulator_disable(info->vdd);
return 0; return 0;
} }
...@@ -397,8 +406,8 @@ static int exynos_adc_suspend(struct device *dev) ...@@ -397,8 +406,8 @@ static int exynos_adc_suspend(struct device *dev)
writel(con, ADC_V1_CON(info->regs)); writel(con, ADC_V1_CON(info->regs));
} }
clk_disable_unprepare(info->clk);
writel(0, info->enable_reg); writel(0, info->enable_reg);
clk_disable_unprepare(info->clk);
regulator_disable(info->vdd); regulator_disable(info->vdd);
return 0; return 0;
...@@ -414,9 +423,11 @@ static int exynos_adc_resume(struct device *dev) ...@@ -414,9 +423,11 @@ static int exynos_adc_resume(struct device *dev)
if (ret) if (ret)
return ret; return ret;
writel(1, info->enable_reg); ret = clk_prepare_enable(info->clk);
clk_prepare_enable(info->clk); if (ret)
return ret;
writel(1, info->enable_reg);
exynos_adc_hw_init(info); exynos_adc_hw_init(info);
return 0; return 0;
......
...@@ -26,6 +26,40 @@ ...@@ -26,6 +26,40 @@
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
struct {
u32 usage_id;
int unit; /* 0 for default others from HID sensor spec */
int scale_val0; /* scale, whole number */
int scale_val1; /* scale, fraction in micros */
} static unit_conversion[] = {
{HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650},
{HID_USAGE_SENSOR_ACCEL_3D,
HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0},
{HID_USAGE_SENSOR_ACCEL_3D,
HID_USAGE_SENSOR_UNITS_G, 9, 806650},
{HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453},
{HID_USAGE_SENSOR_GYRO_3D,
HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0},
{HID_USAGE_SENSOR_GYRO_3D,
HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0, 17453},
{HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000},
{HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
{HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453},
{HID_USAGE_SENSOR_INCLINOMETER_3D,
HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453},
{HID_USAGE_SENSOR_INCLINOMETER_3D,
HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0},
{HID_USAGE_SENSOR_ALS, 0, 1, 0},
{HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX, 1, 0},
{HID_USAGE_SENSOR_PRESSURE, 0, 100000, 0},
{HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 1, 0},
};
static int pow_10(unsigned power) static int pow_10(unsigned power)
{ {
int i; int i;
...@@ -113,6 +147,26 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2) ...@@ -113,6 +147,26 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
return value; return value;
} }
s32 hid_sensor_read_poll_value(struct hid_sensor_common *st)
{
s32 value = 0;
int ret;
ret = sensor_hub_get_feature(st->hsdev,
st->poll.report_id,
st->poll.index, &value);
if (ret < 0 || value < 0) {
return -EINVAL;
} else {
if (st->poll.units == HID_USAGE_SENSOR_UNITS_SECOND)
value = value * 1000;
}
return value;
}
EXPORT_SYMBOL(hid_sensor_read_poll_value);
int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
int *val1, int *val2) int *val1, int *val2)
{ {
...@@ -209,6 +263,86 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st, ...@@ -209,6 +263,86 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
} }
EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value); EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
/*
* This fuction applies the unit exponent to the scale.
* For example:
* 9.806650 ->exp:2-> val0[980]val1[665000]
* 9.000806 ->exp:2-> val0[900]val1[80600]
* 0.174535 ->exp:2-> val0[17]val1[453500]
* 1.001745 ->exp:0-> val0[1]val1[1745]
* 1.001745 ->exp:2-> val0[100]val1[174500]
* 1.001745 ->exp:4-> val0[10017]val1[450000]
* 9.806650 ->exp:-2-> val0[0]val1[98066]
*/
static void adjust_exponent_micro(int *val0, int *val1, int scale0,
int scale1, int exp)
{
int i;
int x;
int res;
int rem;
if (exp > 0) {
*val0 = scale0 * pow_10(exp);
res = 0;
if (exp > 6) {
*val1 = 0;
return;
}
for (i = 0; i < exp; ++i) {
x = scale1 / pow_10(5 - i);
res += (pow_10(exp - 1 - i) * x);
scale1 = scale1 % pow_10(5 - i);
}
*val0 += res;
*val1 = scale1 * pow_10(exp);
} else if (exp < 0) {
exp = abs(exp);
if (exp > 6) {
*val0 = *val1 = 0;
return;
}
*val0 = scale0 / pow_10(exp);
rem = scale0 % pow_10(exp);
res = 0;
for (i = 0; i < (6 - exp); ++i) {
x = scale1 / pow_10(5 - i);
res += (pow_10(5 - exp - i) * x);
scale1 = scale1 % pow_10(5 - i);
}
*val1 = rem * pow_10(6 - exp) + res;
} else {
*val0 = scale0;
*val1 = scale1;
}
}
int hid_sensor_format_scale(u32 usage_id,
struct hid_sensor_hub_attribute_info *attr_info,
int *val0, int *val1)
{
int i;
int exp;
*val0 = 1;
*val1 = 0;
for (i = 0; ARRAY_SIZE(unit_conversion); ++i) {
if (unit_conversion[i].usage_id == usage_id &&
unit_conversion[i].unit == attr_info->units) {
exp = hid_sensor_convert_exponent(
attr_info->unit_expo);
adjust_exponent_micro(val0, val1,
unit_conversion[i].scale_val0,
unit_conversion[i].scale_val1, exp);
break;
}
}
return IIO_VAL_INT_PLUS_MICRO;
}
EXPORT_SYMBOL(hid_sensor_format_scale);
int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
u32 usage_id, u32 usage_id,
struct hid_sensor_common *st) struct hid_sensor_common *st)
......
...@@ -28,16 +28,17 @@ ...@@ -28,16 +28,17 @@
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
#include "hid-sensor-trigger.h" #include "hid-sensor-trigger.h"
static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, int hid_sensor_power_state(struct hid_sensor_common *st, bool state)
bool state)
{ {
struct hid_sensor_common *st = iio_trigger_get_drvdata(trig);
int state_val; int state_val;
int report_val; int report_val;
if (state) { if (state) {
if (sensor_hub_device_open(st->hsdev)) if (sensor_hub_device_open(st->hsdev))
return -EIO; return -EIO;
atomic_inc(&st->data_ready);
state_val = hid_sensor_get_usage_index(st->hsdev, state_val = hid_sensor_get_usage_index(st->hsdev,
st->power_state.report_id, st->power_state.report_id,
st->power_state.index, st->power_state.index,
...@@ -47,6 +48,8 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, ...@@ -47,6 +48,8 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
st->report_state.index, st->report_state.index,
HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM); HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM);
} else { } else {
if (!atomic_dec_and_test(&st->data_ready))
return 0;
sensor_hub_device_close(st->hsdev); sensor_hub_device_close(st->hsdev);
state_val = hid_sensor_get_usage_index(st->hsdev, state_val = hid_sensor_get_usage_index(st->hsdev,
st->power_state.report_id, st->power_state.report_id,
...@@ -57,7 +60,6 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, ...@@ -57,7 +60,6 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
st->report_state.index, st->report_state.index,
HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM); HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM);
} }
st->data_ready = state;
if (state_val >= 0) { if (state_val >= 0) {
state_val += st->power_state.logical_minimum; state_val += st->power_state.logical_minimum;
...@@ -75,6 +77,13 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, ...@@ -75,6 +77,13 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
return 0; return 0;
} }
EXPORT_SYMBOL(hid_sensor_power_state);
static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
bool state)
{
return hid_sensor_power_state(iio_trigger_get_drvdata(trig), state);
}
void hid_sensor_remove_trigger(struct hid_sensor_common *attrb) void hid_sensor_remove_trigger(struct hid_sensor_common *attrb)
{ {
......
...@@ -22,5 +22,6 @@ ...@@ -22,5 +22,6 @@
int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
struct hid_sensor_common *attrb); struct hid_sensor_common *attrb);
void hid_sensor_remove_trigger(struct hid_sensor_common *attrb); void hid_sensor_remove_trigger(struct hid_sensor_common *attrb);
int hid_sensor_power_state(struct hid_sensor_common *st, bool state);
#endif #endif
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/delay.h>
#include <linux/hid-sensor-hub.h> #include <linux/hid-sensor-hub.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
...@@ -42,6 +43,10 @@ struct gyro_3d_state { ...@@ -42,6 +43,10 @@ struct gyro_3d_state {
struct hid_sensor_common common_attributes; struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX]; struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX];
u32 gyro_val[GYRO_3D_CHANNEL_MAX]; u32 gyro_val[GYRO_3D_CHANNEL_MAX];
int scale_pre_decml;
int scale_post_decml;
int scale_precision;
int value_offset;
}; };
static const u32 gyro_3d_addresses[GYRO_3D_CHANNEL_MAX] = { static const u32 gyro_3d_addresses[GYRO_3D_CHANNEL_MAX] = {
...@@ -56,6 +61,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = { ...@@ -56,6 +61,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = {
.type = IIO_ANGL_VEL, .type = IIO_ANGL_VEL,
.modified = 1, .modified = 1,
.channel2 = IIO_MOD_X, .channel2 = IIO_MOD_X,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_SAMP_FREQ) |
...@@ -65,6 +71,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = { ...@@ -65,6 +71,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = {
.type = IIO_ANGL_VEL, .type = IIO_ANGL_VEL,
.modified = 1, .modified = 1,
.channel2 = IIO_MOD_Y, .channel2 = IIO_MOD_Y,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_SAMP_FREQ) |
...@@ -74,6 +81,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = { ...@@ -74,6 +81,7 @@ static const struct iio_chan_spec gyro_3d_channels[] = {
.type = IIO_ANGL_VEL, .type = IIO_ANGL_VEL,
.modified = 1, .modified = 1,
.channel2 = IIO_MOD_Z, .channel2 = IIO_MOD_Z,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_SAMP_FREQ) |
...@@ -104,31 +112,42 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev, ...@@ -104,31 +112,42 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev,
u32 address; u32 address;
int ret; int ret;
int ret_type; int ret_type;
s32 poll_value;
*val = 0; *val = 0;
*val2 = 0; *val2 = 0;
switch (mask) { switch (mask) {
case 0: case 0:
poll_value = hid_sensor_read_poll_value(
&gyro_state->common_attributes);
if (poll_value < 0)
return -EINVAL;
hid_sensor_power_state(&gyro_state->common_attributes, true);
msleep_interruptible(poll_value * 2);
report_id = gyro_state->gyro[chan->scan_index].report_id; report_id = gyro_state->gyro[chan->scan_index].report_id;
address = gyro_3d_addresses[chan->scan_index]; address = gyro_3d_addresses[chan->scan_index];
if (report_id >= 0) if (report_id >= 0)
*val = sensor_hub_input_attr_get_raw_value( *val = sensor_hub_input_attr_get_raw_value(
gyro_state->common_attributes.hsdev, gyro_state->common_attributes.hsdev,
HID_USAGE_SENSOR_GYRO_3D, address, HID_USAGE_SENSOR_GYRO_3D, address,
report_id); report_id);
else { else {
*val = 0; *val = 0;
hid_sensor_power_state(&gyro_state->common_attributes,
false);
return -EINVAL; return -EINVAL;
} }
hid_sensor_power_state(&gyro_state->common_attributes, false);
ret_type = IIO_VAL_INT; ret_type = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
*val = gyro_state->gyro[CHANNEL_SCAN_INDEX_X].units; *val = gyro_state->scale_pre_decml;
ret_type = IIO_VAL_INT; *val2 = gyro_state->scale_post_decml;
ret_type = gyro_state->scale_precision;
break; break;
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
*val = hid_sensor_convert_exponent( *val = gyro_state->value_offset;
gyro_state->gyro[CHANNEL_SCAN_INDEX_X].unit_expo);
ret_type = IIO_VAL_INT; ret_type = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
...@@ -197,9 +216,8 @@ static int gyro_3d_proc_event(struct hid_sensor_hub_device *hsdev, ...@@ -197,9 +216,8 @@ static int gyro_3d_proc_event(struct hid_sensor_hub_device *hsdev,
struct iio_dev *indio_dev = platform_get_drvdata(priv); struct iio_dev *indio_dev = platform_get_drvdata(priv);
struct gyro_3d_state *gyro_state = iio_priv(indio_dev); struct gyro_3d_state *gyro_state = iio_priv(indio_dev);
dev_dbg(&indio_dev->dev, "gyro_3d_proc_event [%d]\n", dev_dbg(&indio_dev->dev, "gyro_3d_proc_event\n");
gyro_state->common_attributes.data_ready); if (atomic_read(&gyro_state->common_attributes.data_ready))
if (gyro_state->common_attributes.data_ready)
hid_sensor_push_data(indio_dev, hid_sensor_push_data(indio_dev,
gyro_state->gyro_val, gyro_state->gyro_val,
sizeof(gyro_state->gyro_val)); sizeof(gyro_state->gyro_val));
...@@ -262,6 +280,11 @@ static int gyro_3d_parse_report(struct platform_device *pdev, ...@@ -262,6 +280,11 @@ static int gyro_3d_parse_report(struct platform_device *pdev,
st->gyro[1].index, st->gyro[1].report_id, st->gyro[1].index, st->gyro[1].report_id,
st->gyro[2].index, st->gyro[2].report_id); st->gyro[2].index, st->gyro[2].report_id);
st->scale_precision = hid_sensor_format_scale(
HID_USAGE_SENSOR_GYRO_3D,
&st->gyro[CHANNEL_SCAN_INDEX_X],
&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,
...@@ -330,7 +353,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev) ...@@ -330,7 +353,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "failed to initialize trigger buffer\n"); dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
goto error_free_dev_mem; goto error_free_dev_mem;
} }
gyro_state->common_attributes.data_ready = false; atomic_set(&gyro_state->common_attributes.data_ready, 0);
ret = hid_sensor_setup_trigger(indio_dev, name, ret = hid_sensor_setup_trigger(indio_dev, name,
&gyro_state->common_attributes); &gyro_state->common_attributes);
if (ret < 0) { if (ret < 0) {
......
...@@ -35,7 +35,7 @@ int __iio_add_chan_devattr(const char *postfix, ...@@ -35,7 +35,7 @@ int __iio_add_chan_devattr(const char *postfix,
struct list_head *attr_list); struct list_head *attr_list);
void iio_free_chan_devattr_list(struct list_head *attr_list); void iio_free_chan_devattr_list(struct list_head *attr_list);
ssize_t iio_format_value(char *buf, unsigned int type, int val, int val2); ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals);
/* Event interface flags */ /* Event interface flags */
#define IIO_BUSY_BIT_POS 1 #define IIO_BUSY_BIT_POS 1
......
...@@ -150,7 +150,16 @@ static ssize_t iio_show_fixed_type(struct device *dev, ...@@ -150,7 +150,16 @@ static ssize_t iio_show_fixed_type(struct device *dev,
type = IIO_BE; type = IIO_BE;
#endif #endif
} }
return sprintf(buf, "%s:%c%d/%d>>%u\n", if (this_attr->c->scan_type.repeat > 1)
return sprintf(buf, "%s:%c%d/%dX%d>>%u\n",
iio_endian_prefix[type],
this_attr->c->scan_type.sign,
this_attr->c->scan_type.realbits,
this_attr->c->scan_type.storagebits,
this_attr->c->scan_type.repeat,
this_attr->c->scan_type.shift);
else
return sprintf(buf, "%s:%c%d/%d>>%u\n",
iio_endian_prefix[type], iio_endian_prefix[type],
this_attr->c->scan_type.sign, this_attr->c->scan_type.sign,
this_attr->c->scan_type.realbits, this_attr->c->scan_type.realbits,
...@@ -475,14 +484,22 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev, ...@@ -475,14 +484,22 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
for_each_set_bit(i, mask, for_each_set_bit(i, mask,
indio_dev->masklength) { indio_dev->masklength) {
ch = iio_find_channel_from_si(indio_dev, i); ch = iio_find_channel_from_si(indio_dev, i);
length = ch->scan_type.storagebits / 8; if (ch->scan_type.repeat > 1)
length = ch->scan_type.storagebits / 8 *
ch->scan_type.repeat;
else
length = ch->scan_type.storagebits / 8;
bytes = ALIGN(bytes, length); bytes = ALIGN(bytes, length);
bytes += length; bytes += length;
} }
if (timestamp) { if (timestamp) {
ch = iio_find_channel_from_si(indio_dev, ch = iio_find_channel_from_si(indio_dev,
indio_dev->scan_index_timestamp); indio_dev->scan_index_timestamp);
length = ch->scan_type.storagebits / 8; if (ch->scan_type.repeat > 1)
length = ch->scan_type.storagebits / 8 *
ch->scan_type.repeat;
else
length = ch->scan_type.storagebits / 8;
bytes = ALIGN(bytes, length); bytes = ALIGN(bytes, length);
bytes += length; bytes += length;
} }
...@@ -959,7 +976,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev, ...@@ -959,7 +976,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
indio_dev->masklength, indio_dev->masklength,
in_ind + 1); in_ind + 1);
ch = iio_find_channel_from_si(indio_dev, in_ind); ch = iio_find_channel_from_si(indio_dev, in_ind);
length = ch->scan_type.storagebits/8; if (ch->scan_type.repeat > 1)
length = ch->scan_type.storagebits / 8 *
ch->scan_type.repeat;
else
length = ch->scan_type.storagebits / 8;
/* Make sure we are aligned */ /* Make sure we are aligned */
in_loc += length; in_loc += length;
if (in_loc % length) if (in_loc % length)
...@@ -971,7 +992,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev, ...@@ -971,7 +992,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
goto error_clear_mux_table; goto error_clear_mux_table;
} }
ch = iio_find_channel_from_si(indio_dev, in_ind); ch = iio_find_channel_from_si(indio_dev, in_ind);
length = ch->scan_type.storagebits/8; if (ch->scan_type.repeat > 1)
length = ch->scan_type.storagebits / 8 *
ch->scan_type.repeat;
else
length = ch->scan_type.storagebits / 8;
if (out_loc % length) if (out_loc % length)
out_loc += length - out_loc % length; out_loc += length - out_loc % length;
if (in_loc % length) if (in_loc % length)
...@@ -992,7 +1017,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev, ...@@ -992,7 +1017,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
} }
ch = iio_find_channel_from_si(indio_dev, ch = iio_find_channel_from_si(indio_dev,
indio_dev->scan_index_timestamp); indio_dev->scan_index_timestamp);
length = ch->scan_type.storagebits/8; if (ch->scan_type.repeat > 1)
length = ch->scan_type.storagebits / 8 *
ch->scan_type.repeat;
else
length = ch->scan_type.storagebits / 8;
if (out_loc % length) if (out_loc % length)
out_loc += length - out_loc % length; out_loc += length - out_loc % length;
if (in_loc % length) if (in_loc % length)
......
...@@ -84,6 +84,9 @@ static const char * const iio_modifier_names[] = { ...@@ -84,6 +84,9 @@ static const char * const iio_modifier_names[] = {
[IIO_MOD_LIGHT_RED] = "red", [IIO_MOD_LIGHT_RED] = "red",
[IIO_MOD_LIGHT_GREEN] = "green", [IIO_MOD_LIGHT_GREEN] = "green",
[IIO_MOD_LIGHT_BLUE] = "blue", [IIO_MOD_LIGHT_BLUE] = "blue",
[IIO_MOD_QUATERNION] = "quaternion",
[IIO_MOD_TEMP_AMBIENT] = "ambient",
[IIO_MOD_TEMP_OBJECT] = "object",
}; };
/* relies on pairs of these shared then separate */ /* relies on pairs of these shared then separate */
...@@ -373,41 +376,53 @@ EXPORT_SYMBOL_GPL(iio_enum_write); ...@@ -373,41 +376,53 @@ EXPORT_SYMBOL_GPL(iio_enum_write);
* @buf: The buffer to which the formated value gets written * @buf: The buffer to which the formated value gets written
* @type: One of the IIO_VAL_... constants. This decides how the val and val2 * @type: One of the IIO_VAL_... constants. This decides how the val and val2
* parameters are formatted. * parameters are formatted.
* @val: First part of the value, exact meaning depends on the type parameter. * @vals: pointer to the values, exact meaning depends on the type parameter.
* @val2: Second part of the value, exact meaning depends on the type parameter.
*/ */
ssize_t iio_format_value(char *buf, unsigned int type, int val, int val2) ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals)
{ {
unsigned long long tmp; unsigned long long tmp;
bool scale_db = false; bool scale_db = false;
switch (type) { switch (type) {
case IIO_VAL_INT: case IIO_VAL_INT:
return sprintf(buf, "%d\n", val); return sprintf(buf, "%d\n", vals[0]);
case IIO_VAL_INT_PLUS_MICRO_DB: case IIO_VAL_INT_PLUS_MICRO_DB:
scale_db = true; scale_db = true;
case IIO_VAL_INT_PLUS_MICRO: case IIO_VAL_INT_PLUS_MICRO:
if (val2 < 0) if (vals[1] < 0)
return sprintf(buf, "-%ld.%06u%s\n", abs(val), -val2, return sprintf(buf, "-%ld.%06u%s\n", abs(vals[0]),
-vals[1],
scale_db ? " dB" : ""); scale_db ? " dB" : "");
else else
return sprintf(buf, "%d.%06u%s\n", val, val2, return sprintf(buf, "%d.%06u%s\n", vals[0], vals[1],
scale_db ? " dB" : ""); scale_db ? " dB" : "");
case IIO_VAL_INT_PLUS_NANO: case IIO_VAL_INT_PLUS_NANO:
if (val2 < 0) if (vals[1] < 0)
return sprintf(buf, "-%ld.%09u\n", abs(val), -val2); return sprintf(buf, "-%ld.%09u\n", abs(vals[0]),
-vals[1]);
else else
return sprintf(buf, "%d.%09u\n", val, val2); return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
case IIO_VAL_FRACTIONAL: case IIO_VAL_FRACTIONAL:
tmp = div_s64((s64)val * 1000000000LL, val2); tmp = div_s64((s64)vals[0] * 1000000000LL, vals[1]);
val2 = do_div(tmp, 1000000000LL); vals[1] = do_div(tmp, 1000000000LL);
val = tmp; vals[0] = tmp;
return sprintf(buf, "%d.%09u\n", val, val2); return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
case IIO_VAL_FRACTIONAL_LOG2: case IIO_VAL_FRACTIONAL_LOG2:
tmp = (s64)val * 1000000000LL >> val2; tmp = (s64)vals[0] * 1000000000LL >> vals[1];
val2 = do_div(tmp, 1000000000LL); vals[1] = do_div(tmp, 1000000000LL);
val = tmp; vals[0] = tmp;
return sprintf(buf, "%d.%09u\n", val, val2); return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
case IIO_VAL_INT_MULTIPLE:
{
int i;
int len = 0;
for (i = 0; i < size; ++i)
len += snprintf(&buf[len], PAGE_SIZE - len, "%d ",
vals[i]);
len += snprintf(&buf[len], PAGE_SIZE - len, "\n");
return len;
}
default: default:
return 0; return 0;
} }
...@@ -419,14 +434,23 @@ static ssize_t iio_read_channel_info(struct device *dev, ...@@ -419,14 +434,23 @@ static ssize_t iio_read_channel_info(struct device *dev,
{ {
struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
int val, val2; int vals[INDIO_MAX_RAW_ELEMENTS];
int ret = indio_dev->info->read_raw(indio_dev, this_attr->c, int ret;
&val, &val2, this_attr->address); int val_len = 2;
if (indio_dev->info->read_raw_multi)
ret = indio_dev->info->read_raw_multi(indio_dev, this_attr->c,
INDIO_MAX_RAW_ELEMENTS,
vals, &val_len,
this_attr->address);
else
ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
&vals[0], &vals[1], this_attr->address);
if (ret < 0) if (ret < 0)
return ret; return ret;
return iio_format_value(buf, ret, val, val2); return iio_format_value(buf, ret, val_len, vals);
} }
/** /**
......
...@@ -270,7 +270,7 @@ static ssize_t iio_ev_value_show(struct device *dev, ...@@ -270,7 +270,7 @@ static ssize_t iio_ev_value_show(struct device *dev,
{ {
struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
int val, val2; int val, val2, val_arr[2];
int ret; int ret;
ret = indio_dev->info->read_event_value(indio_dev, ret = indio_dev->info->read_event_value(indio_dev,
...@@ -279,7 +279,9 @@ static ssize_t iio_ev_value_show(struct device *dev, ...@@ -279,7 +279,9 @@ static ssize_t iio_ev_value_show(struct device *dev,
&val, &val2); &val, &val2);
if (ret < 0) if (ret < 0)
return ret; return ret;
return iio_format_value(buf, ret, val, val2); val_arr[0] = val;
val_arr[1] = val2;
return iio_format_value(buf, ret, 2, val_arr);
} }
static ssize_t iio_ev_value_store(struct device *dev, static ssize_t iio_ev_value_store(struct device *dev,
......
...@@ -417,12 +417,24 @@ static int iio_channel_read(struct iio_channel *chan, int *val, int *val2, ...@@ -417,12 +417,24 @@ static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,
enum iio_chan_info_enum info) enum iio_chan_info_enum info)
{ {
int unused; int unused;
int vals[INDIO_MAX_RAW_ELEMENTS];
int ret;
int val_len = 2;
if (val2 == NULL) if (val2 == NULL)
val2 = &unused; val2 = &unused;
return chan->indio_dev->info->read_raw(chan->indio_dev, chan->channel, if (chan->indio_dev->info->read_raw_multi) {
val, val2, info); ret = chan->indio_dev->info->read_raw_multi(chan->indio_dev,
chan->channel, INDIO_MAX_RAW_ELEMENTS,
vals, &val_len, info);
*val = vals[0];
*val2 = vals[1];
} else
ret = chan->indio_dev->info->read_raw(chan->indio_dev,
chan->channel, val, val2, info);
return ret;
} }
int iio_read_channel_raw(struct iio_channel *chan, int *val) int iio_read_channel_raw(struct iio_channel *chan, int *val)
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
* IIO features supported by the driver: * IIO features supported by the driver:
* *
* Read-only raw channels: * Read-only raw channels:
* - illiminance_clear [lux] * - illuminance_clear [lux]
* - illiminance_ir * - illuminance_ir
* - proximity * - proximity
* *
* Triggered buffer: * Triggered buffer:
* - illiminance_clear * - illuminance_clear
* - illiminance_ir * - illuminance_ir
* - proximity * - proximity
* *
* Events: * Events:
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/delay.h>
#include <linux/hid-sensor-hub.h> #include <linux/hid-sensor-hub.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
...@@ -37,6 +38,10 @@ struct als_state { ...@@ -37,6 +38,10 @@ struct als_state {
struct hid_sensor_common common_attributes; struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info als_illum; struct hid_sensor_hub_attribute_info als_illum;
u32 illum; u32 illum;
int scale_pre_decml;
int scale_post_decml;
int scale_precision;
int value_offset;
}; };
/* Channel definitions */ /* Channel definitions */
...@@ -45,6 +50,7 @@ static const struct iio_chan_spec als_channels[] = { ...@@ -45,6 +50,7 @@ static const struct iio_chan_spec als_channels[] = {
.type = IIO_INTENSITY, .type = IIO_INTENSITY,
.modified = 1, .modified = 1,
.channel2 = IIO_MOD_LIGHT_BOTH, .channel2 = IIO_MOD_LIGHT_BOTH,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_SAMP_FREQ) |
...@@ -75,6 +81,7 @@ static int als_read_raw(struct iio_dev *indio_dev, ...@@ -75,6 +81,7 @@ static int als_read_raw(struct iio_dev *indio_dev,
u32 address; u32 address;
int ret; int ret;
int ret_type; int ret_type;
s32 poll_value;
*val = 0; *val = 0;
*val2 = 0; *val2 = 0;
...@@ -90,24 +97,35 @@ static int als_read_raw(struct iio_dev *indio_dev, ...@@ -90,24 +97,35 @@ static int als_read_raw(struct iio_dev *indio_dev,
report_id = -1; report_id = -1;
break; break;
} }
if (report_id >= 0) if (report_id >= 0) {
poll_value = hid_sensor_read_poll_value(
&als_state->common_attributes);
if (poll_value < 0)
return -EINVAL;
hid_sensor_power_state(&als_state->common_attributes,
true);
msleep_interruptible(poll_value * 2);
*val = sensor_hub_input_attr_get_raw_value( *val = sensor_hub_input_attr_get_raw_value(
als_state->common_attributes.hsdev, als_state->common_attributes.hsdev,
HID_USAGE_SENSOR_ALS, address, HID_USAGE_SENSOR_ALS, address,
report_id); report_id);
else { hid_sensor_power_state(&als_state->common_attributes,
false);
} else {
*val = 0; *val = 0;
return -EINVAL; return -EINVAL;
} }
ret_type = IIO_VAL_INT; ret_type = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
*val = als_state->als_illum.units; *val = als_state->scale_pre_decml;
ret_type = IIO_VAL_INT; *val2 = als_state->scale_post_decml;
ret_type = als_state->scale_precision;
break; break;
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
*val = hid_sensor_convert_exponent( *val = als_state->value_offset;
als_state->als_illum.unit_expo);
ret_type = IIO_VAL_INT; ret_type = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
...@@ -176,9 +194,8 @@ static int als_proc_event(struct hid_sensor_hub_device *hsdev, ...@@ -176,9 +194,8 @@ static int als_proc_event(struct hid_sensor_hub_device *hsdev,
struct iio_dev *indio_dev = platform_get_drvdata(priv); struct iio_dev *indio_dev = platform_get_drvdata(priv);
struct als_state *als_state = iio_priv(indio_dev); struct als_state *als_state = iio_priv(indio_dev);
dev_dbg(&indio_dev->dev, "als_proc_event [%d]\n", dev_dbg(&indio_dev->dev, "als_proc_event\n");
als_state->common_attributes.data_ready); if (atomic_read(&als_state->common_attributes.data_ready))
if (als_state->common_attributes.data_ready)
hid_sensor_push_data(indio_dev, hid_sensor_push_data(indio_dev,
&als_state->illum, &als_state->illum,
sizeof(als_state->illum)); sizeof(als_state->illum));
...@@ -229,6 +246,11 @@ static int als_parse_report(struct platform_device *pdev, ...@@ -229,6 +246,11 @@ static int als_parse_report(struct platform_device *pdev,
dev_dbg(&pdev->dev, "als %x:%x\n", st->als_illum.index, dev_dbg(&pdev->dev, "als %x:%x\n", st->als_illum.index,
st->als_illum.report_id); st->als_illum.report_id);
st->scale_precision = hid_sensor_format_scale(
HID_USAGE_SENSOR_ALS,
&st->als_illum,
&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,
...@@ -296,7 +318,7 @@ static int hid_als_probe(struct platform_device *pdev) ...@@ -296,7 +318,7 @@ static int hid_als_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "failed to initialize trigger buffer\n"); dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
goto error_free_dev_mem; goto error_free_dev_mem;
} }
als_state->common_attributes.data_ready = false; atomic_set(&als_state->common_attributes.data_ready, 0);
ret = hid_sensor_setup_trigger(indio_dev, name, ret = hid_sensor_setup_trigger(indio_dev, name,
&als_state->common_attributes); &als_state->common_attributes);
if (ret < 0) { if (ret < 0) {
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/delay.h>
#include <linux/hid-sensor-hub.h> #include <linux/hid-sensor-hub.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
...@@ -75,6 +76,7 @@ static int prox_read_raw(struct iio_dev *indio_dev, ...@@ -75,6 +76,7 @@ static int prox_read_raw(struct iio_dev *indio_dev,
u32 address; u32 address;
int ret; int ret;
int ret_type; int ret_type;
s32 poll_value;
*val = 0; *val = 0;
*val2 = 0; *val2 = 0;
...@@ -90,12 +92,24 @@ static int prox_read_raw(struct iio_dev *indio_dev, ...@@ -90,12 +92,24 @@ static int prox_read_raw(struct iio_dev *indio_dev,
report_id = -1; report_id = -1;
break; break;
} }
if (report_id >= 0) if (report_id >= 0) {
poll_value = hid_sensor_read_poll_value(
&prox_state->common_attributes);
if (poll_value < 0)
return -EINVAL;
hid_sensor_power_state(&prox_state->common_attributes,
true);
msleep_interruptible(poll_value * 2);
*val = sensor_hub_input_attr_get_raw_value( *val = sensor_hub_input_attr_get_raw_value(
prox_state->common_attributes.hsdev, prox_state->common_attributes.hsdev,
HID_USAGE_SENSOR_PROX, address, HID_USAGE_SENSOR_PROX, address,
report_id); report_id);
else { hid_sensor_power_state(&prox_state->common_attributes,
false);
} else {
*val = 0; *val = 0;
return -EINVAL; return -EINVAL;
} }
...@@ -176,9 +190,8 @@ static int prox_proc_event(struct hid_sensor_hub_device *hsdev, ...@@ -176,9 +190,8 @@ static int prox_proc_event(struct hid_sensor_hub_device *hsdev,
struct iio_dev *indio_dev = platform_get_drvdata(priv); struct iio_dev *indio_dev = platform_get_drvdata(priv);
struct prox_state *prox_state = iio_priv(indio_dev); struct prox_state *prox_state = iio_priv(indio_dev);
dev_dbg(&indio_dev->dev, "prox_proc_event [%d]\n", dev_dbg(&indio_dev->dev, "prox_proc_event\n");
prox_state->common_attributes.data_ready); if (atomic_read(&prox_state->common_attributes.data_ready))
if (prox_state->common_attributes.data_ready)
hid_sensor_push_data(indio_dev, hid_sensor_push_data(indio_dev,
&prox_state->human_presence, &prox_state->human_presence,
sizeof(prox_state->human_presence)); sizeof(prox_state->human_presence));
...@@ -297,7 +310,7 @@ static int hid_prox_probe(struct platform_device *pdev) ...@@ -297,7 +310,7 @@ static int hid_prox_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "failed to initialize trigger buffer\n"); dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
goto error_free_dev_mem; goto error_free_dev_mem;
} }
prox_state->common_attributes.data_ready = false; atomic_set(&prox_state->common_attributes.data_ready, 0);
ret = hid_sensor_setup_trigger(indio_dev, name, ret = hid_sensor_setup_trigger(indio_dev, name,
&prox_state->common_attributes); &prox_state->common_attributes);
if (ret) { if (ret) {
......
...@@ -569,7 +569,6 @@ static int ak8975_probe(struct i2c_client *client, ...@@ -569,7 +569,6 @@ static int ak8975_probe(struct i2c_client *client,
indio_dev->channels = ak8975_channels; indio_dev->channels = ak8975_channels;
indio_dev->num_channels = ARRAY_SIZE(ak8975_channels); indio_dev->num_channels = ARRAY_SIZE(ak8975_channels);
indio_dev->info = &ak8975_info; indio_dev->info = &ak8975_info;
indio_dev->name = id->name;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->name = name; indio_dev->name = name;
err = iio_device_register(indio_dev); err = iio_device_register(indio_dev);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/delay.h>
#include <linux/hid-sensor-hub.h> #include <linux/hid-sensor-hub.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
...@@ -42,6 +43,10 @@ struct magn_3d_state { ...@@ -42,6 +43,10 @@ struct magn_3d_state {
struct hid_sensor_common common_attributes; struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX]; struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX];
u32 magn_val[MAGN_3D_CHANNEL_MAX]; u32 magn_val[MAGN_3D_CHANNEL_MAX];
int scale_pre_decml;
int scale_post_decml;
int scale_precision;
int value_offset;
}; };
static const u32 magn_3d_addresses[MAGN_3D_CHANNEL_MAX] = { static const u32 magn_3d_addresses[MAGN_3D_CHANNEL_MAX] = {
...@@ -56,6 +61,7 @@ static const struct iio_chan_spec magn_3d_channels[] = { ...@@ -56,6 +61,7 @@ static const struct iio_chan_spec magn_3d_channels[] = {
.type = IIO_MAGN, .type = IIO_MAGN,
.modified = 1, .modified = 1,
.channel2 = IIO_MOD_X, .channel2 = IIO_MOD_X,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_SAMP_FREQ) |
...@@ -65,6 +71,7 @@ static const struct iio_chan_spec magn_3d_channels[] = { ...@@ -65,6 +71,7 @@ static const struct iio_chan_spec magn_3d_channels[] = {
.type = IIO_MAGN, .type = IIO_MAGN,
.modified = 1, .modified = 1,
.channel2 = IIO_MOD_Y, .channel2 = IIO_MOD_Y,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_SAMP_FREQ) |
...@@ -74,6 +81,7 @@ static const struct iio_chan_spec magn_3d_channels[] = { ...@@ -74,6 +81,7 @@ static const struct iio_chan_spec magn_3d_channels[] = {
.type = IIO_MAGN, .type = IIO_MAGN,
.modified = 1, .modified = 1,
.channel2 = IIO_MOD_Z, .channel2 = IIO_MOD_Z,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_SAMP_FREQ) |
...@@ -104,11 +112,20 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev, ...@@ -104,11 +112,20 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev,
u32 address; u32 address;
int ret; int ret;
int ret_type; int ret_type;
s32 poll_value;
*val = 0; *val = 0;
*val2 = 0; *val2 = 0;
switch (mask) { switch (mask) {
case 0: case 0:
poll_value = hid_sensor_read_poll_value(
&magn_state->common_attributes);
if (poll_value < 0)
return -EINVAL;
hid_sensor_power_state(&magn_state->common_attributes, true);
msleep_interruptible(poll_value * 2);
report_id = report_id =
magn_state->magn[chan->scan_index].report_id; magn_state->magn[chan->scan_index].report_id;
address = magn_3d_addresses[chan->scan_index]; address = magn_3d_addresses[chan->scan_index];
...@@ -119,17 +136,20 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev, ...@@ -119,17 +136,20 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev,
report_id); report_id);
else { else {
*val = 0; *val = 0;
hid_sensor_power_state(&magn_state->common_attributes,
false);
return -EINVAL; return -EINVAL;
} }
hid_sensor_power_state(&magn_state->common_attributes, false);
ret_type = IIO_VAL_INT; ret_type = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
*val = magn_state->magn[CHANNEL_SCAN_INDEX_X].units; *val = magn_state->scale_pre_decml;
ret_type = IIO_VAL_INT; *val2 = magn_state->scale_post_decml;
ret_type = magn_state->scale_precision;
break; break;
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
*val = hid_sensor_convert_exponent( *val = magn_state->value_offset;
magn_state->magn[CHANNEL_SCAN_INDEX_X].unit_expo);
ret_type = IIO_VAL_INT; ret_type = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
...@@ -198,9 +218,8 @@ static int magn_3d_proc_event(struct hid_sensor_hub_device *hsdev, ...@@ -198,9 +218,8 @@ static int magn_3d_proc_event(struct hid_sensor_hub_device *hsdev,
struct iio_dev *indio_dev = platform_get_drvdata(priv); struct iio_dev *indio_dev = platform_get_drvdata(priv);
struct magn_3d_state *magn_state = iio_priv(indio_dev); struct magn_3d_state *magn_state = iio_priv(indio_dev);
dev_dbg(&indio_dev->dev, "magn_3d_proc_event [%d]\n", dev_dbg(&indio_dev->dev, "magn_3d_proc_event\n");
magn_state->common_attributes.data_ready); if (atomic_read(&magn_state->common_attributes.data_ready))
if (magn_state->common_attributes.data_ready)
hid_sensor_push_data(indio_dev, hid_sensor_push_data(indio_dev,
magn_state->magn_val, magn_state->magn_val,
sizeof(magn_state->magn_val)); sizeof(magn_state->magn_val));
...@@ -263,6 +282,11 @@ static int magn_3d_parse_report(struct platform_device *pdev, ...@@ -263,6 +282,11 @@ static int magn_3d_parse_report(struct platform_device *pdev,
st->magn[1].index, st->magn[1].report_id, st->magn[1].index, st->magn[1].report_id,
st->magn[2].index, st->magn[2].report_id); st->magn[2].index, st->magn[2].report_id);
st->scale_precision = hid_sensor_format_scale(
HID_USAGE_SENSOR_COMPASS_3D,
&st->magn[CHANNEL_SCAN_INDEX_X],
&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,
...@@ -334,7 +358,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev) ...@@ -334,7 +358,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "failed to initialize trigger buffer\n"); dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
goto error_free_dev_mem; goto error_free_dev_mem;
} }
magn_state->common_attributes.data_ready = false; atomic_set(&magn_state->common_attributes.data_ready, 0);
ret = hid_sensor_setup_trigger(indio_dev, name, ret = hid_sensor_setup_trigger(indio_dev, name,
&magn_state->common_attributes); &magn_state->common_attributes);
if (ret < 0) { if (ret < 0) {
......
...@@ -199,6 +199,13 @@ static int mag3110_read_raw(struct iio_dev *indio_dev, ...@@ -199,6 +199,13 @@ static int mag3110_read_raw(struct iio_dev *indio_dev,
*val = mag3110_samp_freq[i][0]; *val = mag3110_samp_freq[i][0];
*val2 = mag3110_samp_freq[i][1]; *val2 = mag3110_samp_freq[i][1];
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_CALIBBIAS:
ret = i2c_smbus_read_word_swapped(data->client,
MAG3110_OFF_X + 2 * chan->scan_index);
if (ret < 0)
return ret;
*val = sign_extend32(ret >> 1, 14);
return IIO_VAL_INT;
} }
return -EINVAL; return -EINVAL;
} }
...@@ -223,6 +230,11 @@ static int mag3110_write_raw(struct iio_dev *indio_dev, ...@@ -223,6 +230,11 @@ static int mag3110_write_raw(struct iio_dev *indio_dev,
data->ctrl_reg1 |= rate << MAG3110_CTRL_DR_SHIFT; data->ctrl_reg1 |= rate << MAG3110_CTRL_DR_SHIFT;
return i2c_smbus_write_byte_data(data->client, return i2c_smbus_write_byte_data(data->client,
MAG3110_CTRL_REG1, data->ctrl_reg1); MAG3110_CTRL_REG1, data->ctrl_reg1);
case IIO_CHAN_INFO_CALIBBIAS:
if (val < -10000 || val > 10000)
return -EINVAL;
return i2c_smbus_write_word_swapped(data->client,
MAG3110_OFF_X + 2 * chan->scan_index, val << 1);
default: default:
return -EINVAL; return -EINVAL;
} }
...@@ -260,7 +272,8 @@ static irqreturn_t mag3110_trigger_handler(int irq, void *p) ...@@ -260,7 +272,8 @@ static irqreturn_t mag3110_trigger_handler(int irq, void *p)
.type = IIO_MAGN, \ .type = IIO_MAGN, \
.modified = 1, \ .modified = 1, \
.channel2 = IIO_MOD_##axis, \ .channel2 = IIO_MOD_##axis, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
BIT(IIO_CHAN_INFO_CALIBBIAS), \
.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_SCALE), \ BIT(IIO_CHAN_INFO_SCALE), \
.scan_index = idx, \ .scan_index = idx, \
...@@ -338,14 +351,14 @@ static int mag3110_probe(struct i2c_client *client, ...@@ -338,14 +351,14 @@ static int mag3110_probe(struct i2c_client *client,
indio_dev->num_channels = ARRAY_SIZE(mag3110_channels); indio_dev->num_channels = ARRAY_SIZE(mag3110_channels);
indio_dev->available_scan_masks = mag3110_scan_masks; indio_dev->available_scan_masks = mag3110_scan_masks;
data->ctrl_reg1 = MAG3110_CTRL_DR_DEFAULT; data->ctrl_reg1 = MAG3110_CTRL_DR_DEFAULT << MAG3110_CTRL_DR_SHIFT;
ret = i2c_smbus_write_byte_data(client, MAG3110_CTRL_REG1, ret = i2c_smbus_write_byte_data(client, MAG3110_CTRL_REG1,
data->ctrl_reg1); data->ctrl_reg1);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = i2c_smbus_write_byte_data(client, MAG3110_CTRL_REG2, ret = i2c_smbus_write_byte_data(client, MAG3110_CTRL_REG2,
MAG3110_CTRL_AUTO_MRST_EN | MAG3110_CTRL_RAW); MAG3110_CTRL_AUTO_MRST_EN);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -16,4 +16,16 @@ config HID_SENSOR_INCLINOMETER_3D ...@@ -16,4 +16,16 @@ config HID_SENSOR_INCLINOMETER_3D
Say yes here to build support for the HID SENSOR Say yes here to build support for the HID SENSOR
Inclinometer 3D. Inclinometer 3D.
config HID_SENSOR_DEVICE_ROTATION
depends on HID_SENSOR_HUB
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
select HID_SENSOR_IIO_COMMON
select HID_SENSOR_IIO_TRIGGER
tristate "HID Device Rotation"
help
Say yes here to build support for the HID SENSOR
device rotation. The output of a device rotation sensor
is presented using quaternion format.
endmenu endmenu
...@@ -4,3 +4,4 @@ ...@@ -4,3 +4,4 @@
# When adding new entries keep the list in alphabetical order # When adding new entries keep the list in alphabetical order
obj-$(CONFIG_HID_SENSOR_INCLINOMETER_3D) += hid-sensor-incl-3d.o obj-$(CONFIG_HID_SENSOR_INCLINOMETER_3D) += hid-sensor-incl-3d.o
obj-$(CONFIG_HID_SENSOR_DEVICE_ROTATION) += hid-sensor-rotation.o
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/delay.h>
#include <linux/hid-sensor-hub.h> #include <linux/hid-sensor-hub.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
...@@ -42,6 +43,10 @@ struct incl_3d_state { ...@@ -42,6 +43,10 @@ struct incl_3d_state {
struct hid_sensor_common common_attributes; struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info incl[INCLI_3D_CHANNEL_MAX]; struct hid_sensor_hub_attribute_info incl[INCLI_3D_CHANNEL_MAX];
u32 incl_val[INCLI_3D_CHANNEL_MAX]; u32 incl_val[INCLI_3D_CHANNEL_MAX];
int scale_pre_decml;
int scale_post_decml;
int scale_precision;
int value_offset;
}; };
static const u32 incl_3d_addresses[INCLI_3D_CHANNEL_MAX] = { static const u32 incl_3d_addresses[INCLI_3D_CHANNEL_MAX] = {
...@@ -106,11 +111,20 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev, ...@@ -106,11 +111,20 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev,
int report_id = -1; int report_id = -1;
u32 address; u32 address;
int ret_type; int ret_type;
s32 poll_value;
*val = 0; *val = 0;
*val2 = 0; *val2 = 0;
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
poll_value = hid_sensor_read_poll_value(
&incl_state->common_attributes);
if (poll_value < 0)
return -EINVAL;
hid_sensor_power_state(&incl_state->common_attributes, true);
msleep_interruptible(poll_value * 2);
report_id = report_id =
incl_state->incl[chan->scan_index].report_id; incl_state->incl[chan->scan_index].report_id;
address = incl_3d_addresses[chan->scan_index]; address = incl_3d_addresses[chan->scan_index];
...@@ -120,17 +134,20 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev, ...@@ -120,17 +134,20 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev,
HID_USAGE_SENSOR_INCLINOMETER_3D, address, HID_USAGE_SENSOR_INCLINOMETER_3D, address,
report_id); report_id);
else { else {
hid_sensor_power_state(&incl_state->common_attributes,
false);
return -EINVAL; return -EINVAL;
} }
hid_sensor_power_state(&incl_state->common_attributes, false);
ret_type = IIO_VAL_INT; ret_type = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
*val = incl_state->incl[CHANNEL_SCAN_INDEX_X].units; *val = incl_state->scale_pre_decml;
ret_type = IIO_VAL_INT; *val2 = incl_state->scale_post_decml;
ret_type = incl_state->scale_precision;
break; break;
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
*val = hid_sensor_convert_exponent( *val = incl_state->value_offset;
incl_state->incl[CHANNEL_SCAN_INDEX_X].unit_expo);
ret_type = IIO_VAL_INT; ret_type = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
...@@ -196,9 +213,8 @@ static int incl_3d_proc_event(struct hid_sensor_hub_device *hsdev, ...@@ -196,9 +213,8 @@ static int incl_3d_proc_event(struct hid_sensor_hub_device *hsdev,
struct iio_dev *indio_dev = platform_get_drvdata(priv); struct iio_dev *indio_dev = platform_get_drvdata(priv);
struct incl_3d_state *incl_state = iio_priv(indio_dev); struct incl_3d_state *incl_state = iio_priv(indio_dev);
dev_dbg(&indio_dev->dev, "incl_3d_proc_event [%d]\n", dev_dbg(&indio_dev->dev, "incl_3d_proc_event\n");
incl_state->common_attributes.data_ready); if (atomic_read(&incl_state->common_attributes.data_ready))
if (incl_state->common_attributes.data_ready)
hid_sensor_push_data(indio_dev, hid_sensor_push_data(indio_dev,
(u8 *)incl_state->incl_val, (u8 *)incl_state->incl_val,
sizeof(incl_state->incl_val)); sizeof(incl_state->incl_val));
...@@ -279,6 +295,11 @@ static int incl_3d_parse_report(struct platform_device *pdev, ...@@ -279,6 +295,11 @@ static int incl_3d_parse_report(struct platform_device *pdev,
st->incl[1].index, st->incl[1].report_id, st->incl[1].index, st->incl[1].report_id,
st->incl[2].index, st->incl[2].report_id); st->incl[2].index, st->incl[2].report_id);
st->scale_precision = hid_sensor_format_scale(
HID_USAGE_SENSOR_INCLINOMETER_3D,
&st->incl[CHANNEL_SCAN_INDEX_X],
&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,
...@@ -349,7 +370,7 @@ static int hid_incl_3d_probe(struct platform_device *pdev) ...@@ -349,7 +370,7 @@ static int hid_incl_3d_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "failed to initialize trigger buffer\n"); dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
goto error_free_dev_mem; goto error_free_dev_mem;
} }
incl_state->common_attributes.data_ready = false; atomic_set(&incl_state->common_attributes.data_ready, 0);
ret = hid_sensor_setup_trigger(indio_dev, name, ret = hid_sensor_setup_trigger(indio_dev, name,
&incl_state->common_attributes); &incl_state->common_attributes);
if (ret) { if (ret) {
......
/*
* HID Sensors Driver
* Copyright (c) 2014, Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/slab.h>
#include <linux/hid-sensor-hub.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/buffer.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#include "../common/hid-sensors/hid-sensor-trigger.h"
struct dev_rot_state {
struct hid_sensor_hub_callbacks callbacks;
struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info quaternion;
u32 sampled_vals[4];
};
/* Channel definitions */
static const struct iio_chan_spec dev_rot_channels[] = {
{
.type = IIO_ROT,
.modified = 1,
.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_HYSTERESIS)
}
};
/* Adjust channel real bits based on report descriptor */
static void dev_rot_adjust_channel_bit_mask(struct iio_chan_spec *chan,
int size)
{
chan->scan_type.sign = 's';
/* Real storage bits will change based on the report desc. */
chan->scan_type.realbits = size * 8;
/* Maximum size of a sample to capture is u32 */
chan->scan_type.storagebits = sizeof(u32) * 8;
chan->scan_type.repeat = 4;
}
/* Channel read_raw handler */
static int dev_rot_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int size, int *vals, int *val_len,
long mask)
{
struct dev_rot_state *rot_state = iio_priv(indio_dev);
int ret_type;
int i;
vals[0] = 0;
vals[1] = 0;
switch (mask) {
case IIO_CHAN_INFO_RAW:
if (size >= 4) {
for (i = 0; i < 4; ++i)
vals[i] = rot_state->sampled_vals[i];
ret_type = IIO_VAL_INT_MULTIPLE;
*val_len = 4;
} else
ret_type = -EINVAL;
break;
case IIO_CHAN_INFO_SAMP_FREQ:
ret_type = hid_sensor_read_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]);
break;
default:
ret_type = -EINVAL;
break;
}
return ret_type;
}
/* Channel write_raw handler */
static int dev_rot_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val,
int val2,
long mask)
{
struct dev_rot_state *rot_state = iio_priv(indio_dev);
int ret;
switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ:
ret = hid_sensor_write_samp_freq_value(
&rot_state->common_attributes, val, val2);
break;
case IIO_CHAN_INFO_HYSTERESIS:
ret = hid_sensor_write_raw_hyst_value(
&rot_state->common_attributes, val, val2);
break;
default:
ret = -EINVAL;
}
return ret;
}
static const struct iio_info dev_rot_info = {
.driver_module = THIS_MODULE,
.read_raw_multi = &dev_rot_read_raw,
.write_raw = &dev_rot_write_raw,
};
/* Function to push data to buffer */
static void hid_sensor_push_data(struct iio_dev *indio_dev, u8 *data, int len)
{
dev_dbg(&indio_dev->dev, "hid_sensor_push_data >>\n");
iio_push_to_buffers(indio_dev, (u8 *)data);
dev_dbg(&indio_dev->dev, "hid_sensor_push_data <<\n");
}
/* Callback handler to send event after all samples are received and captured */
static int dev_rot_proc_event(struct hid_sensor_hub_device *hsdev,
unsigned usage_id,
void *priv)
{
struct iio_dev *indio_dev = platform_get_drvdata(priv);
struct dev_rot_state *rot_state = iio_priv(indio_dev);
dev_dbg(&indio_dev->dev, "dev_rot_proc_event\n");
if (atomic_read(&rot_state->common_attributes.data_ready))
hid_sensor_push_data(indio_dev,
(u8 *)rot_state->sampled_vals,
sizeof(rot_state->sampled_vals));
return 0;
}
/* Capture samples in local storage */
static int dev_rot_capture_sample(struct hid_sensor_hub_device *hsdev,
unsigned usage_id,
size_t raw_len, char *raw_data,
void *priv)
{
struct iio_dev *indio_dev = platform_get_drvdata(priv);
struct dev_rot_state *rot_state = iio_priv(indio_dev);
if (usage_id == HID_USAGE_SENSOR_ORIENT_QUATERNION) {
memcpy(rot_state->sampled_vals, raw_data,
sizeof(rot_state->sampled_vals));
dev_dbg(&indio_dev->dev, "Recd Quat len:%zu::%zu\n", raw_len,
sizeof(rot_state->sampled_vals));
}
return 0;
}
/* Parse report which is specific to an usage id*/
static int dev_rot_parse_report(struct platform_device *pdev,
struct hid_sensor_hub_device *hsdev,
struct iio_chan_spec *channels,
unsigned usage_id,
struct dev_rot_state *st)
{
int ret;
ret = sensor_hub_input_get_attribute_info(hsdev,
HID_INPUT_REPORT,
usage_id,
HID_USAGE_SENSOR_ORIENT_QUATERNION,
&st->quaternion);
if (ret)
return ret;
dev_rot_adjust_channel_bit_mask(&channels[0],
st->quaternion.size / 4);
dev_dbg(&pdev->dev, "dev_rot %x:%x\n", st->quaternion.index,
st->quaternion.report_id);
dev_dbg(&pdev->dev, "dev_rot: attrib size %d\n",
st->quaternion.size);
/* 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_ORIENTATION,
&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 0;
}
/* Function to initialize the processing for usage id */
static int hid_dev_rot_probe(struct platform_device *pdev)
{
int ret;
static char *name = "dev_rotation";
struct iio_dev *indio_dev;
struct dev_rot_state *rot_state;
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
struct iio_chan_spec *channels;
indio_dev = devm_iio_device_alloc(&pdev->dev,
sizeof(struct dev_rot_state));
if (indio_dev == NULL)
return -ENOMEM;
platform_set_drvdata(pdev, indio_dev);
rot_state = iio_priv(indio_dev);
rot_state->common_attributes.hsdev = hsdev;
rot_state->common_attributes.pdev = pdev;
ret = hid_sensor_parse_common_attributes(hsdev,
HID_USAGE_SENSOR_DEVICE_ORIENTATION,
&rot_state->common_attributes);
if (ret) {
dev_err(&pdev->dev, "failed to setup common attributes\n");
return ret;
}
channels = devm_kmemdup(&pdev->dev, dev_rot_channels,
sizeof(dev_rot_channels), GFP_KERNEL);
if (!channels) {
dev_err(&pdev->dev, "failed to duplicate channels\n");
return -ENOMEM;
}
ret = dev_rot_parse_report(pdev, hsdev, channels,
HID_USAGE_SENSOR_DEVICE_ORIENTATION, rot_state);
if (ret) {
dev_err(&pdev->dev, "failed to setup attributes\n");
return ret;
}
indio_dev->channels = channels;
indio_dev->num_channels = ARRAY_SIZE(dev_rot_channels);
indio_dev->dev.parent = &pdev->dev;
indio_dev->info = &dev_rot_info;
indio_dev->name = name;
indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
NULL, NULL);
if (ret) {
dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
return ret;
}
atomic_set(&rot_state->common_attributes.data_ready, 0);
ret = hid_sensor_setup_trigger(indio_dev, name,
&rot_state->common_attributes);
if (ret) {
dev_err(&pdev->dev, "trigger setup failed\n");
goto error_unreg_buffer_funcs;
}
ret = iio_device_register(indio_dev);
if (ret) {
dev_err(&pdev->dev, "device register failed\n");
goto error_remove_trigger;
}
rot_state->callbacks.send_event = dev_rot_proc_event;
rot_state->callbacks.capture_sample = dev_rot_capture_sample;
rot_state->callbacks.pdev = pdev;
ret = sensor_hub_register_callback(hsdev,
HID_USAGE_SENSOR_DEVICE_ORIENTATION,
&rot_state->callbacks);
if (ret) {
dev_err(&pdev->dev, "callback reg failed\n");
goto error_iio_unreg;
}
return 0;
error_iio_unreg:
iio_device_unregister(indio_dev);
error_remove_trigger:
hid_sensor_remove_trigger(&rot_state->common_attributes);
error_unreg_buffer_funcs:
iio_triggered_buffer_cleanup(indio_dev);
return ret;
}
/* Function to deinitialize the processing for usage id */
static int hid_dev_rot_remove(struct platform_device *pdev)
{
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
struct iio_dev *indio_dev = platform_get_drvdata(pdev);
struct dev_rot_state *rot_state = iio_priv(indio_dev);
sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_DEVICE_ORIENTATION);
iio_device_unregister(indio_dev);
hid_sensor_remove_trigger(&rot_state->common_attributes);
iio_triggered_buffer_cleanup(indio_dev);
return 0;
}
static struct platform_device_id hid_dev_rot_ids[] = {
{
/* Format: HID-SENSOR-usage_id_in_hex_lowercase */
.name = "HID-SENSOR-20008a",
},
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(platform, hid_dev_rot_ids);
static struct platform_driver hid_dev_rot_platform_driver = {
.id_table = hid_dev_rot_ids,
.driver = {
.name = KBUILD_MODNAME,
.owner = THIS_MODULE,
},
.probe = hid_dev_rot_probe,
.remove = hid_dev_rot_remove,
};
module_platform_driver(hid_dev_rot_platform_driver);
MODULE_DESCRIPTION("HID Sensor Device Rotation");
MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
MODULE_LICENSE("GPL");
...@@ -19,6 +19,16 @@ config HID_SENSOR_PRESS ...@@ -19,6 +19,16 @@ config HID_SENSOR_PRESS
To compile this driver as a module, choose M here: the module To compile this driver as a module, choose M here: the module
will be called hid-sensor-press. will be called hid-sensor-press.
config MPL115
tristate "Freescale MPL115A2 pressure sensor driver"
depends on I2C
help
Say yes here to build support for the Freescale MPL115A2
pressure sensor connected via I2C.
To compile this driver as a module, choose M here: the module
will be called mpl115.
config MPL3115 config MPL3115
tristate "Freescale MPL3115A2 pressure sensor driver" tristate "Freescale MPL3115A2 pressure sensor driver"
depends on I2C depends on I2C
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# When adding new entries keep the list in alphabetical order # When adding new entries keep the list in alphabetical order
obj-$(CONFIG_HID_SENSOR_PRESS) += hid-sensor-press.o obj-$(CONFIG_HID_SENSOR_PRESS) += hid-sensor-press.o
obj-$(CONFIG_MPL115) += mpl115.o
obj-$(CONFIG_MPL3115) += mpl3115.o obj-$(CONFIG_MPL3115) += mpl3115.o
obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o
st_pressure-y := st_pressure_core.o st_pressure-y := st_pressure_core.o
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/delay.h>
#include <linux/hid-sensor-hub.h> #include <linux/hid-sensor-hub.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
...@@ -36,6 +37,10 @@ struct press_state { ...@@ -36,6 +37,10 @@ struct press_state {
struct hid_sensor_common common_attributes; struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info press_attr; struct hid_sensor_hub_attribute_info press_attr;
u32 press_data; u32 press_data;
int scale_pre_decml;
int scale_post_decml;
int scale_precision;
int value_offset;
}; };
/* Channel definitions */ /* Channel definitions */
...@@ -75,6 +80,7 @@ static int press_read_raw(struct iio_dev *indio_dev, ...@@ -75,6 +80,7 @@ static int press_read_raw(struct iio_dev *indio_dev,
u32 address; u32 address;
int ret; int ret;
int ret_type; int ret_type;
s32 poll_value;
*val = 0; *val = 0;
*val2 = 0; *val2 = 0;
...@@ -90,24 +96,35 @@ static int press_read_raw(struct iio_dev *indio_dev, ...@@ -90,24 +96,35 @@ static int press_read_raw(struct iio_dev *indio_dev,
report_id = -1; report_id = -1;
break; break;
} }
if (report_id >= 0) if (report_id >= 0) {
poll_value = hid_sensor_read_poll_value(
&press_state->common_attributes);
if (poll_value < 0)
return -EINVAL;
hid_sensor_power_state(&press_state->common_attributes,
true);
msleep_interruptible(poll_value * 2);
*val = sensor_hub_input_attr_get_raw_value( *val = sensor_hub_input_attr_get_raw_value(
press_state->common_attributes.hsdev, press_state->common_attributes.hsdev,
HID_USAGE_SENSOR_PRESSURE, address, HID_USAGE_SENSOR_PRESSURE, address,
report_id); report_id);
else { hid_sensor_power_state(&press_state->common_attributes,
false);
} else {
*val = 0; *val = 0;
return -EINVAL; return -EINVAL;
} }
ret_type = IIO_VAL_INT; ret_type = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
*val = press_state->press_attr.units; *val = press_state->scale_pre_decml;
ret_type = IIO_VAL_INT; *val2 = press_state->scale_post_decml;
ret_type = press_state->scale_precision;
break; break;
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
*val = hid_sensor_convert_exponent( *val = press_state->value_offset;
press_state->press_attr.unit_expo);
ret_type = IIO_VAL_INT; ret_type = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
...@@ -176,9 +193,8 @@ static int press_proc_event(struct hid_sensor_hub_device *hsdev, ...@@ -176,9 +193,8 @@ static int press_proc_event(struct hid_sensor_hub_device *hsdev,
struct iio_dev *indio_dev = platform_get_drvdata(priv); struct iio_dev *indio_dev = platform_get_drvdata(priv);
struct press_state *press_state = iio_priv(indio_dev); struct press_state *press_state = iio_priv(indio_dev);
dev_dbg(&indio_dev->dev, "press_proc_event [%d]\n", dev_dbg(&indio_dev->dev, "press_proc_event\n");
press_state->common_attributes.data_ready); if (atomic_read(&press_state->common_attributes.data_ready))
if (press_state->common_attributes.data_ready)
hid_sensor_push_data(indio_dev, hid_sensor_push_data(indio_dev,
&press_state->press_data, &press_state->press_data,
sizeof(press_state->press_data)); sizeof(press_state->press_data));
...@@ -229,6 +245,11 @@ static int press_parse_report(struct platform_device *pdev, ...@@ -229,6 +245,11 @@ static int press_parse_report(struct platform_device *pdev,
dev_dbg(&pdev->dev, "press %x:%x\n", st->press_attr.index, dev_dbg(&pdev->dev, "press %x:%x\n", st->press_attr.index,
st->press_attr.report_id); st->press_attr.report_id);
st->scale_precision = hid_sensor_format_scale(
HID_USAGE_SENSOR_PRESSURE,
&st->press_attr,
&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,
...@@ -298,7 +319,7 @@ static int hid_press_probe(struct platform_device *pdev) ...@@ -298,7 +319,7 @@ static int hid_press_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "failed to initialize trigger buffer\n"); dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
goto error_free_dev_mem; goto error_free_dev_mem;
} }
press_state->common_attributes.data_ready = false; atomic_set(&press_state->common_attributes.data_ready, 0);
ret = hid_sensor_setup_trigger(indio_dev, name, ret = hid_sensor_setup_trigger(indio_dev, name,
&press_state->common_attributes); &press_state->common_attributes);
if (ret) { if (ret) {
......
/*
* mpl115.c - Support for Freescale MPL115A2 pressure/temperature sensor
*
* Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>
*
* This file is subject to the terms and conditions of version 2 of
* the GNU General Public License. See the file COPYING in the main
* directory of this archive for more details.
*
* (7-bit I2C slave address 0x60)
*
* TODO: shutdown pin
*
*/
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/iio/iio.h>
#include <linux/delay.h>
#define MPL115_PADC 0x00 /* pressure ADC output value, MSB first, 10 bit */
#define MPL115_TADC 0x02 /* temperature ADC output value, MSB first, 10 bit */
#define MPL115_A0 0x04 /* 12 bit integer, 3 bit fraction */
#define MPL115_B1 0x06 /* 2 bit integer, 13 bit fraction */
#define MPL115_B2 0x08 /* 1 bit integer, 14 bit fraction */
#define MPL115_C12 0x0a /* 0 bit integer, 13 bit fraction */
#define MPL115_CONVERT 0x12 /* convert temperature and pressure */
struct mpl115_data {
struct i2c_client *client;
struct mutex lock;
s16 a0;
s16 b1, b2;
s16 c12;
};
static int mpl115_request(struct mpl115_data *data)
{
int ret = i2c_smbus_write_byte_data(data->client, MPL115_CONVERT, 0);
if (ret < 0)
return ret;
usleep_range(3000, 4000);
return 0;
}
static int mpl115_comp_pressure(struct mpl115_data *data, int *val, int *val2)
{
int ret;
u16 padc, tadc;
int a1, y1, pcomp;
unsigned kpa;
mutex_lock(&data->lock);
ret = mpl115_request(data);
if (ret < 0)
goto done;
ret = i2c_smbus_read_word_swapped(data->client, MPL115_PADC);
if (ret < 0)
goto done;
padc = ret >> 6;
ret = i2c_smbus_read_word_swapped(data->client, MPL115_TADC);
if (ret < 0)
goto done;
tadc = ret >> 6;
/* see Freescale AN3785 */
a1 = data->b1 + ((data->c12 * tadc) >> 11);
y1 = (data->a0 << 10) + a1 * padc;
/* compensated pressure with 4 fractional bits */
pcomp = (y1 + ((data->b2 * (int) tadc) >> 1)) >> 9;
kpa = pcomp * (115 - 50) / 1023 + (50 << 4);
*val = kpa >> 4;
*val2 = (kpa & 15) * (1000000 >> 4);
done:
mutex_unlock(&data->lock);
return ret;
}
static int mpl115_read_temp(struct mpl115_data *data)
{
int ret;
mutex_lock(&data->lock);
ret = mpl115_request(data);
if (ret < 0)
goto done;
ret = i2c_smbus_read_word_swapped(data->client, MPL115_TADC);
done:
mutex_unlock(&data->lock);
return ret;
}
static int mpl115_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct mpl115_data *data = iio_priv(indio_dev);
int ret;
switch (mask) {
case IIO_CHAN_INFO_PROCESSED:
ret = mpl115_comp_pressure(data, val, val2);
if (ret < 0)
return ret;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_RAW:
/* temperature -5.35 C / LSB, 472 LSB is 25 C */
ret = mpl115_read_temp(data);
if (ret < 0)
return ret;
*val = ret >> 6;
return IIO_VAL_INT;
case IIO_CHAN_INFO_OFFSET:
*val = 605;
*val2 = 750000;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_SCALE:
*val = -186;
*val2 = 915888;
return IIO_VAL_INT_PLUS_MICRO;
}
return -EINVAL;
}
static const struct iio_chan_spec mpl115_channels[] = {
{
.type = IIO_PRESSURE,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
},
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_SCALE),
},
};
static const struct iio_info mpl115_info = {
.read_raw = &mpl115_read_raw,
.driver_module = THIS_MODULE,
};
static int mpl115_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct mpl115_data *data;
struct iio_dev *indio_dev;
int ret;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))
return -ENODEV;
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
if (!indio_dev)
return -ENOMEM;
data = iio_priv(indio_dev);
data->client = client;
mutex_init(&data->lock);
i2c_set_clientdata(client, indio_dev);
indio_dev->info = &mpl115_info;
indio_dev->name = id->name;
indio_dev->dev.parent = &client->dev;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = mpl115_channels;
indio_dev->num_channels = ARRAY_SIZE(mpl115_channels);
ret = i2c_smbus_read_word_swapped(data->client, MPL115_A0);
if (ret < 0)
return ret;
data->a0 = ret;
ret = i2c_smbus_read_word_swapped(data->client, MPL115_B1);
if (ret < 0)
return ret;
data->b1 = ret;
ret = i2c_smbus_read_word_swapped(data->client, MPL115_B2);
if (ret < 0)
return ret;
data->b2 = ret;
ret = i2c_smbus_read_word_swapped(data->client, MPL115_C12);
if (ret < 0)
return ret;
data->c12 = ret;
return devm_iio_device_register(&client->dev, indio_dev);
}
static const struct i2c_device_id mpl115_id[] = {
{ "mpl115", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, mpl115_id);
static struct i2c_driver mpl115_driver = {
.driver = {
.name = "mpl115",
},
.probe = mpl115_probe,
.id_table = mpl115_id,
};
module_i2c_driver(mpl115_driver);
MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
MODULE_DESCRIPTION("Freescale MPL115 pressure/temperature driver");
MODULE_LICENSE("GPL");
...@@ -3,6 +3,16 @@ ...@@ -3,6 +3,16 @@
# #
menu "Temperature sensors" menu "Temperature sensors"
config MLX90614
tristate "MLX90614 contact-less infrared sensor"
depends on I2C
help
If you say yes here you get support for the Melexis
MLX90614 contact-less infrared sensor connected with I2C.
This driver can also be built as a module. If so, the module will
be called mlx90614.
config TMP006 config TMP006
tristate "TMP006 infrared thermopile sensor" tristate "TMP006 infrared thermopile sensor"
depends on I2C depends on I2C
......
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
# Makefile for industrial I/O temperature drivers # Makefile for industrial I/O temperature drivers
# #
obj-$(CONFIG_MLX90614) += mlx90614.o
obj-$(CONFIG_TMP006) += tmp006.o obj-$(CONFIG_TMP006) += tmp006.o
/*
* mlx90614.c - Support for Melexis MLX90614 contactless IR temperature sensor
*
* Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>
*
* This file is subject to the terms and conditions of version 2 of
* the GNU General Public License. See the file COPYING in the main
* directory of this archive for more details.
*
* Driver for the Melexis MLX90614 I2C 16-bit IR thermopile sensor
*
* (7-bit I2C slave address 0x5a, 100KHz bus speed only!)
*
* TODO: sleep mode, configuration EEPROM
*/
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/iio/iio.h>
#define MLX90614_OP_RAM 0x00
/* RAM offsets with 16-bit data, MSB first */
#define MLX90614_TA 0x06 /* ambient temperature */
#define MLX90614_TOBJ1 0x07 /* object temperature */
struct mlx90614_data {
struct i2c_client *client;
};
static int mlx90614_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *channel, int *val,
int *val2, long mask)
{
struct mlx90614_data *data = iio_priv(indio_dev);
s32 ret;
switch (mask) {
case IIO_CHAN_INFO_RAW: /* 0.02K / LSB */
switch (channel->channel2) {
case IIO_MOD_TEMP_AMBIENT:
ret = i2c_smbus_read_word_data(data->client,
MLX90614_OP_RAM | MLX90614_TA);
if (ret < 0)
return ret;
break;
case IIO_MOD_TEMP_OBJECT:
ret = i2c_smbus_read_word_data(data->client,
MLX90614_OP_RAM | MLX90614_TOBJ1);
if (ret < 0)
return ret;
break;
default:
return -EINVAL;
}
*val = ret;
return IIO_VAL_INT;
case IIO_CHAN_INFO_OFFSET:
*val = 13657;
*val2 = 500000;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_SCALE:
*val = 20;
return IIO_VAL_INT;
default:
return -EINVAL;
}
}
static const struct iio_chan_spec mlx90614_channels[] = {
{
.type = IIO_TEMP,
.modified = 1,
.channel2 = IIO_MOD_TEMP_AMBIENT,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE),
},
{
.type = IIO_TEMP,
.modified = 1,
.channel2 = IIO_MOD_TEMP_OBJECT,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
BIT(IIO_CHAN_INFO_SCALE),
},
};
static const struct iio_info mlx90614_info = {
.read_raw = mlx90614_read_raw,
.driver_module = THIS_MODULE,
};
static int mlx90614_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct iio_dev *indio_dev;
struct mlx90614_data *data;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))
return -ENODEV;
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
if (!indio_dev)
return -ENOMEM;
data = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev);
data->client = client;
indio_dev->dev.parent = &client->dev;
indio_dev->name = id->name;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &mlx90614_info;
indio_dev->channels = mlx90614_channels;
indio_dev->num_channels = ARRAY_SIZE(mlx90614_channels);
return iio_device_register(indio_dev);
}
static int mlx90614_remove(struct i2c_client *client)
{
iio_device_unregister(i2c_get_clientdata(client));
return 0;
}
static const struct i2c_device_id mlx90614_id[] = {
{ "mlx90614", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, mlx90614_id);
static struct i2c_driver mlx90614_driver = {
.driver = {
.name = "mlx90614",
.owner = THIS_MODULE,
},
.probe = mlx90614_probe,
.remove = mlx90614_remove,
.id_table = mlx90614_id,
};
module_i2c_driver(mlx90614_driver);
MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
MODULE_DESCRIPTION("Melexis MLX90614 contactless IR temperature sensor driver");
MODULE_LICENSE("GPL");
...@@ -443,7 +443,7 @@ static ssize_t ad7280_show_balance_timer(struct device *dev, ...@@ -443,7 +443,7 @@ static ssize_t ad7280_show_balance_timer(struct device *dev,
msecs = (ret >> 3) * 71500; msecs = (ret >> 3) * 71500;
return sprintf(buf, "%d\n", msecs); return sprintf(buf, "%u\n", msecs);
} }
static ssize_t ad7280_store_balance_timer(struct device *dev, static ssize_t ad7280_store_balance_timer(struct device *dev,
...@@ -619,7 +619,7 @@ static ssize_t ad7280_read_channel_config(struct device *dev, ...@@ -619,7 +619,7 @@ static ssize_t ad7280_read_channel_config(struct device *dev,
return -EINVAL; return -EINVAL;
} }
return sprintf(buf, "%d\n", val); return sprintf(buf, "%u\n", val);
} }
static ssize_t ad7280_write_channel_config(struct device *dev, static ssize_t ad7280_write_channel_config(struct device *dev,
......
...@@ -623,6 +623,8 @@ static inline void *devm_kcalloc(struct device *dev, ...@@ -623,6 +623,8 @@ static inline void *devm_kcalloc(struct device *dev,
} }
extern void devm_kfree(struct device *dev, void *p); extern void devm_kfree(struct device *dev, void *p);
extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp); extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp);
extern void *devm_kmemdup(struct device *dev, const void *src, size_t len,
gfp_t gfp);
void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
void __iomem *devm_request_and_ioremap(struct device *dev, void __iomem *devm_request_and_ioremap(struct device *dev,
......
...@@ -189,7 +189,7 @@ struct hid_sensor_common { ...@@ -189,7 +189,7 @@ struct hid_sensor_common {
struct hid_sensor_hub_device *hsdev; struct hid_sensor_hub_device *hsdev;
struct platform_device *pdev; struct platform_device *pdev;
unsigned usage_id; unsigned usage_id;
bool data_ready; atomic_t data_ready;
struct iio_trigger *trigger; struct iio_trigger *trigger;
struct hid_sensor_hub_attribute_info poll; struct hid_sensor_hub_attribute_info poll;
struct hid_sensor_hub_attribute_info report_state; struct hid_sensor_hub_attribute_info report_state;
...@@ -223,4 +223,10 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, ...@@ -223,4 +223,10 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev, int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev,
u32 report_id, int field_index, u32 usage_id); u32 report_id, int field_index, u32 usage_id);
int hid_sensor_format_scale(u32 usage_id,
struct hid_sensor_hub_attribute_info *attr_info,
int *val0, int *val1);
s32 hid_sensor_read_poll_value(struct hid_sensor_common *st);
#endif #endif
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
#define HID_USAGE_SENSOR_ORIENT_TILT_Y 0x200480 #define HID_USAGE_SENSOR_ORIENT_TILT_Y 0x200480
#define HID_USAGE_SENSOR_ORIENT_TILT_Z 0x200481 #define HID_USAGE_SENSOR_ORIENT_TILT_Z 0x200481
#define HID_USAGE_SENSOR_DEVICE_ORIENTATION 0x20008A
#define HID_USAGE_SENSOR_ORIENT_ROTATION_MATRIX 0x200482 #define HID_USAGE_SENSOR_ORIENT_ROTATION_MATRIX 0x200482
#define HID_USAGE_SENSOR_ORIENT_QUATERNION 0x200483 #define HID_USAGE_SENSOR_ORIENT_QUATERNION 0x200483
#define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX 0x200484 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX 0x200484
......
...@@ -177,6 +177,12 @@ struct iio_event_spec { ...@@ -177,6 +177,12 @@ struct iio_event_spec {
* shift: Shift right by this before masking out * shift: Shift right by this before masking out
* realbits. * realbits.
* endianness: little or big endian * endianness: little or big endian
* repeat: Number of times real/storage bits
* repeats. When the repeat element is
* more than 1, then the type element in
* sysfs will show a repeat value.
* Otherwise, the number of repetitions is
* omitted.
* @info_mask_separate: What information is to be exported that is specific to * @info_mask_separate: What information is to be exported that is specific to
* this channel. * this channel.
* @info_mask_shared_by_type: What information is to be exported that is shared * @info_mask_shared_by_type: What information is to be exported that is shared
...@@ -219,6 +225,7 @@ struct iio_chan_spec { ...@@ -219,6 +225,7 @@ struct iio_chan_spec {
u8 realbits; u8 realbits;
u8 storagebits; u8 storagebits;
u8 shift; u8 shift;
u8 repeat;
enum iio_endian endianness; enum iio_endian endianness;
} scan_type; } scan_type;
long info_mask_separate; long info_mask_separate;
...@@ -288,6 +295,8 @@ static inline s64 iio_get_time_ns(void) ...@@ -288,6 +295,8 @@ static inline s64 iio_get_time_ns(void)
#define INDIO_ALL_BUFFER_MODES \ #define INDIO_ALL_BUFFER_MODES \
(INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE) (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE)
#define INDIO_MAX_RAW_ELEMENTS 4
struct iio_trigger; /* forward declaration */ struct iio_trigger; /* forward declaration */
struct iio_dev; struct iio_dev;
...@@ -302,6 +311,14 @@ struct iio_dev; ...@@ -302,6 +311,14 @@ struct iio_dev;
* the channel in question. Return value will specify the * the channel in question. Return value will specify the
* type of value returned by the device. val and val2 will * type of value returned by the device. val and val2 will
* contain the elements making up the returned value. * contain the elements making up the returned value.
* @read_raw_multi: function to return values from the device.
* mask specifies which value. Note 0 means a reading of
* the channel in question. Return value will specify the
* type of value returned by the device. vals pointer
* contain the elements making up the returned value.
* max_len specifies maximum number of elements
* vals pointer can contain. val_len is used to return
* length of valid elements in vals.
* @write_raw: function to write a value to the device. * @write_raw: function to write a value to the device.
* Parameters are the same as for read_raw. * Parameters are the same as for read_raw.
* @write_raw_get_fmt: callback function to query the expected * @write_raw_get_fmt: callback function to query the expected
...@@ -328,6 +345,13 @@ struct iio_info { ...@@ -328,6 +345,13 @@ struct iio_info {
int *val2, int *val2,
long mask); long mask);
int (*read_raw_multi)(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int max_len,
int *vals,
int *val_len,
long mask);
int (*write_raw)(struct iio_dev *indio_dev, int (*write_raw)(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, struct iio_chan_spec const *chan,
int val, int val,
......
...@@ -53,6 +53,9 @@ enum iio_modifier { ...@@ -53,6 +53,9 @@ enum iio_modifier {
IIO_MOD_LIGHT_RED, IIO_MOD_LIGHT_RED,
IIO_MOD_LIGHT_GREEN, IIO_MOD_LIGHT_GREEN,
IIO_MOD_LIGHT_BLUE, IIO_MOD_LIGHT_BLUE,
IIO_MOD_QUATERNION,
IIO_MOD_TEMP_AMBIENT,
IIO_MOD_TEMP_OBJECT,
}; };
enum iio_event_type { enum iio_event_type {
...@@ -79,6 +82,7 @@ enum iio_event_direction { ...@@ -79,6 +82,7 @@ enum iio_event_direction {
#define IIO_VAL_INT_PLUS_MICRO 2 #define IIO_VAL_INT_PLUS_MICRO 2
#define IIO_VAL_INT_PLUS_NANO 3 #define IIO_VAL_INT_PLUS_NANO 3
#define IIO_VAL_INT_PLUS_MICRO_DB 4 #define IIO_VAL_INT_PLUS_MICRO_DB 4
#define IIO_VAL_INT_MULTIPLE 5
#define IIO_VAL_FRACTIONAL 10 #define IIO_VAL_FRACTIONAL 10
#define IIO_VAL_FRACTIONAL_LOG2 11 #define IIO_VAL_FRACTIONAL_LOG2 11
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册