iio sensor mounting matrix support
Subsystems (3)
cover iio sensor mounting matrix support
This patch series follows up on Rob Herring and Jonathan Cameron comments about ak8975 magnetometer mounting matrix support. Thread starts here:
http://www.spinics.net/lists/devicetree/msg121646.html
As a recall, we want to expose a rotation matrix to indicate userspace the chip placement with respect to the overall hardware system. This allows an application to adjust coordinates sampled from a sensor chip when its position deviates from the main hardware system.
Rob mentionned that the interface could be appropriate for other sensors such as gyro, accelero, etc... This would prevent from "ending up with a bunch of similar yet different interfaces".
Requirements:
1. delegate computation to userspace ;
2. floating point arithmetics support ;
3. per sample type matrix ;
4. remain compliant with legacy interface (mpu6050).
Point 1. above allows application to perform arbitrary transformations in addition to sensor alignment handling.
Point 2. is required for flexible chip positioning.
Point 3. comes from the fact that chips, such as ADIS16407, may implement different axis direction references for each measurement space.
See http://www.analog.com/media/en/technical-documentation/data-sheets/ADIS16407.pdf
Implementation relies upon generic extended channel infos, coming with following additional benefits :
* clearly structure sysfs attributes according to IIO ABI conventions,
* limit proliferation of arbitrary driver sysfs attributes,
* reduce amount of per driver code.
We should end up with something like the following for a magneto + gyro + accelero + temperature chip :
iio:deviceX/in_anglvel_mount_matrix, applicable to all 3 gyro channels iio:deviceX/in_accel_mount_matrix, applicable to all 3 accelero channels iio:deviceX/in_magn_mount_matrix, applicable to all 3 magneto channels Here mount matrix attribute is channel type specific. It is not applicable to temperature channel.
Another case such as the ak8975 magneto driver modified in patch 2 would show a simpler:
iio:deviceX/in_mount_matrix, applicable to all 3 magneto channels. Here mount matrix attribute is channel direction specific and applicable to all channels.
Last patch relates to mpu6050 mounting matrix evolutions : legacy attribute was extracted from platform_data. For sake of simplicity and as platform data mechanism is becoming more and more "obsolete", New mounting matrix API support is implemented for device-tree nodes only.
Best regards,
gregor.
Gregor Boirie (3):
iio:core: mounting matrix support iio:ak8975: add mounting matrix support iio:imu:mpu6050: enhance mounting matrix support
Documentation/ABI/testing/sysfs-bus-iio | 53 ++++++++++++++ .../devicetree/bindings/iio/imu/inv_mpu6050.txt | 13 ++++ .../bindings/iio/magnetometer/ak8975.txt | 10 +++ drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 36 +++++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 4 +- drivers/iio/industrialio-core.c | 82 ++++++++++++++++++++++ drivers/iio/magnetometer/ak8975.c | 34 +++++++-- include/linux/iio/iio.h | 31 ++++++++ include/linux/iio/magnetometer/ak8975.h | 16 +++++ include/linux/platform_data/invensense_mpu6050.h | 5 +- 10 files changed, 275 insertions(+), 9 deletions(-) create mode 100644 include/linux/iio/magnetometer/ak8975.h
Signature · 1 line
2.1.4
A message that is not in the archive (sent off-list or not yet received): cover.1461170293.git.gregor.boirie-ITF29qwbsa/[email protected]
PATCH 1/3 iio:core: mounting matrix support
Expose a rotation matrix to indicate userspace the chip placement with respect to the overall hardware system. This is needed to adjust coordinates sampled from a sensor chip when its position deviates from the main hardware system.
Final coordinates computation is delegated to userspace since:
* computation may involve floating point arithmetics ;
* it allows an application to combine adjustments with arbitrary transformations.
This 3 dimentional space rotation matrix is expressed as 3x3 array of strings to support floating point numbers. It may be retrieved from a "[<dir>_][<type>_]mount_matrix" sysfs attribute file. It is declared into a device / driver specific DTS property or platform data.
--- Documentation/ABI/testing/sysfs-bus-iio | 51 ++++++++++++++++++++ drivers/iio/industrialio-core.c | 82 +++++++++++++++++++++++++++++++++ include/linux/iio/iio.h | 31 +++++++++++++ 3 files changed, 164 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +51 -0
@@ -1512,3 +1512,54 @@ Contact: [email protected] Description: Raw (unscaled no offset etc.) pH reading of a substance as a negative base-10 logarithm of hydrodium ions in a litre of water. + +What: /sys/bus/iio/devices/iio:deviceX/mount_matrix +What: /sys/bus/iio/devices/iio:deviceX/in_mount_matrix +What: /sys/bus/iio/devices/iio:deviceX/out_mount_matrix +KernelVersion: 4.6 +Contact: [email protected] +Description: + Mounting matrix for IIO sensors. This is a rotation matrix which + informs userspace about sensor chip's placement relative to the + main hardware it is mounted on. + Main hardware placement is defined according to the local + reference frame related to the physical quantity the sensor + measures. + Given that the rotation matrix is defined in a board specific + way (platform data and / or device-tree), the main hardware + reference frame definition is left to the implementor's choice + (see below for a magnetometer example). + Applications should apply this rotation matrix to samples so + that when main hardware reference frame is aligned onto local + reference frame, then sensor chip reference frame is also + perfectly aligned with it. + Matrix is a 3x3 unitary matrix and typically looks like + [0, 1, 0; 1, 0, 0; 0, 0, -1]. Identity matrix + [1, 0, 0; 0, 1, 0; 0, 0, 1] means sensor chip and main hardware + are perfectly aligned with each other. + + For example, a mounting matrix for a magnetometer sensor informs + userspace about sensor chip's ORIENTATION relative to the main + hardware. + More specifically, main hardware orientation is defined with + respect to the LOCAL EARTH GEOMAGNETIC REFERENCE FRAME where : + * Y is in the ground plane and positive towards magnetic North ; + * X is in the ground plane, perpendicular to the North axis and + positive towards the East ; + * Z is perpendicular to the ground plane and positive upwards. + + An implementor might consider that for a hand-held device, a + 'natural' orientation would be 'front facing camera at the top'. + The main hardware reference frame could then be described as : + * Y is in the plane of the screen and is positive towards the + top of the screen ; + * X is in the plane of the screen, perpendicular to Y axis, and + positive towards the right hand side of the screen ; + * Z is perpendicular to the screen plane and positive out of the + screen. + Another example for a quadrotor UAV might be : + * Y is in the plane of the propellers and positive towards the + front-view camera; + * X is in the plane of the propellers, perpendicular to Y axis, + and positive towards the starboard side of the UAV ; + * Z is perpendicular to propellers plane and positive upwards.
drivers/iio/industrialio-core.c +82 -0
88 lines not on this page · raw message
include/linux/iio/iio.h +31 -0
@@ -148,6 +148,37 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev, }/** +* struct iio_mount_matrix - iio mounting matrix +* @rotation: 3 dimensional space rotation matrix defining sensor alignment with +* main hardware +*/ +struct iio_mount_matrix { +const char *rotation[9 ]; +}; + +ssize_t iio_show_mount_matrix (struct iio_dev *indio_dev,uintptr_t priv, +const struct iio_chan_spec *chan,char *buf); +int of_iio_read_mount_matrix (const struct device *dev,const char *propname, +struct iio_mount_matrix *matrix); + +typedef const struct iio_mount_matrix * + (iio_get_mount_matrix_t )(const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan); + +/** +* IIO_MOUNT_MATRIX() - Initialize mount matrix extended channel attribute +* @_shared: Whether the attribute is shared between all channels +* @_get: Pointer to an iio_get_mount_matrix_t accessor +*/ +#define IIO_MOUNT_MATRIX (_shared, _get) \ +{ \ + .name = "mount_matrix", \ + .shared = (_shared), \ + .read = iio_show_mount_matrix, \ + .private = (uintptr_t)(_get), \ +} + +/** * struct iio_event_spec - specification for a channel event * @type: Type of the event * @dir: Direction of the event
Signature · 1 line
2.1.4
A message that is not in the archive (sent off-list or not yet received): 0910cde3dad40284f8aad9148a156c5ef54dacc4.1461170293.git.gregor.boirie-ITF29qwbsa/[email protected]
Re: [PATCH v1 1/3] iio:core: mounting matrix support
Quoted 10 lines · Gregor Boirie
Expose a rotation matrix to indicate userspace the chip placement with respect to the overall hardware system. This is needed to adjust coordinates sampled from a sensor chip when its position deviates from the main hardware system.
Final coordinates computation is delegated to userspace since:
* computation may involve floating point arithmetics ;
* it allows an application to combine adjustments with arbitrary transformations.
Quoted 6 lines
This 3 dimentional space rotation matrix is expressed as 3x3 array of strings to support floating point numbers. It may be retrieved from a "[<dir>_][<type>_]mount_matrix" sysfs attribute file. It is declared into a device / driver specific DTS property or platform data.
Applied to the togreg branch of iio.git - initially pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 201 lines
--- Documentation/ABI/testing/sysfs-bus-iio | 51 ++++++++++++++++++++ drivers/iio/industrialio-core.c | 82 +++++++++++++++++++++++++++++++++ include/linux/iio/iio.h | 31 +++++++++++++ 3 files changed, 164 insertions(+)Documentation/ABI/testing/sysfs-bus-iio +51
-0@@ -1512,3 +1512,54 @@ Contact: [email protected] Description: Raw (unscaled no offset etc.) pH reading of a substance as a negative base-10 logarithm of hydrodium ions in a litre of water. + +What: /sys/bus/iio/devices/iio:deviceX/mount_matrix +What: /sys/bus/iio/devices/iio:deviceX/in_mount_matrix +What: /sys/bus/iio/devices/iio:deviceX/out_mount_matrix +KernelVersion: 4.6 +Contact: [email protected] +Description: + Mounting matrix for IIO sensors. This is a rotation matrix which + informs userspace about sensor chip's placement relative to the + main hardware it is mounted on. + Main hardware placement is defined according to the local + reference frame related to the physical quantity the sensor + measures. + Given that the rotation matrix is defined in a board specific + way (platform data and / or device-tree), the main hardware + reference frame definition is left to the implementor's choice + (see below for a magnetometer example). + Applications should apply this rotation matrix to samples so + that when main hardware reference frame is aligned onto local + reference frame, then sensor chip reference frame is also + perfectly aligned with it. + Matrix is a 3x3 unitary matrix and typically looks like + [0, 1, 0; 1, 0, 0; 0, 0, -1]. Identity matrix + [1, 0, 0; 0, 1, 0; 0, 0, 1] means sensor chip and main hardware + are perfectly aligned with each other. + + For example, a mounting matrix for a magnetometer sensor informs + userspace about sensor chip's ORIENTATION relative to the main + hardware. + More specifically, main hardware orientation is defined with + respect to the LOCAL EARTH GEOMAGNETIC REFERENCE FRAME where : + * Y is in the ground plane and positive towards magnetic North ; + * X is in the ground plane, perpendicular to the North axis and + positive towards the East ; + * Z is perpendicular to the ground plane and positive upwards. + + An implementor might consider that for a hand-held device, a + 'natural' orientation would be 'front facing camera at the top'. + The main hardware reference frame could then be described as : + * Y is in the plane of the screen and is positive towards the + top of the screen ; + * X is in the plane of the screen, perpendicular to Y axis, and + positive towards the right hand side of the screen ; + * Z is perpendicular to the screen plane and positive out of the + screen. + Another example for a quadrotor UAV might be : + * Y is in the plane of the propellers and positive towards the + front-view camera; + * X is in the plane of the propellers, perpendicular to Y axis, + and positive towards the starboard side of the UAV ; + * Z is perpendicular to propellers plane and positive upwards.drivers/iio/industrialio-core.c +82
-0@@ -412,6 +412,88 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev, }EXPORT_SYMBOL_GPL (iio_enum_write); +static const struct iio_mount_matrix iio_mount_idmatrix = { + .rotation = { +"1" ,"0" ,"0" , +"0" ,"1" ,"0" , +"0" ,"0" ,"1" + } +}; + +static int iio_setup_mount_idmatrix (const struct device *dev, +struct iio_mount_matrix *matrix) +{ + *matrix = iio_mount_idmatrix; +dev_info (dev,"mounting matrix not found: using identity...\n" ); +return 0 ; +} + +ssize_t iio_show_mount_matrix (struct iio_dev *indio_dev,uintptr_t priv, +const struct iio_chan_spec *chan,char *buf) +{ +const struct iio_mount_matrix *mtx = ((iio_get_mount_matrix_t *) + priv)(indio_dev, chan); + +if (IS_ERR (mtx)) +return PTR_ERR (mtx); + +if (!mtx) + mtx = &iio_mount_idmatrix; + +return snprintf (buf,PAGE_SIZE ,"%s, %s, %s; %s, %s, %s; %s, %s, %s\n" , + mtx->rotation[0 ], mtx->rotation[1 ], mtx->rotation[2 ], + mtx->rotation[3 ], mtx->rotation[4 ], mtx->rotation[5 ], + mtx->rotation[6 ], mtx->rotation[7 ], mtx->rotation[8 ]); +} +EXPORT_SYMBOL_GPL (iio_show_mount_matrix); + +/** +* of_iio_read_mount_matrix() - retrieve iio device mounting matrix from +* device-tree "mount-matrix" property +* @dev: device the mounting matrix property is assigned to +* @propname: device specific mounting matrix property name +* @matrix: where to store retrieved matrix +* +* If device is assigned no mounting matrix property, a default 3x3 identity +* matrix will be filled in. +* +* Return: 0 if success, or a negative error code on failure. +*/ +#ifdef CONFIG_OF +int of_iio_read_mount_matrix (const struct device *dev, +const char *propname, +struct iio_mount_matrix *matrix) +{ +if (dev->of_node) { +int err =of_property_read_string_array (dev->of_node, + propname, matrix->rotation, +ARRAY_SIZE (iio_mount_idmatrix.rotation)); + +if (err ==ARRAY_SIZE (iio_mount_idmatrix.rotation)) +return 0 ; + +if (err >=0 ) +/* Invalid number of matrix entries. */ +return -EINVAL ; + +if (err != -EINVAL ) +/* Invalid matrix declaration format. */ +return err; + } + +/* Matrix was not declared at all: fallback to identity. */ +return iio_setup_mount_idmatrix (dev, matrix); +} +#else +int of_iio_read_mount_matrix (const struct device *dev, +const char *propname, +struct iio_mount_matrix *matrix) +{ +return iio_setup_mount_idmatrix (dev, matrix); +} +#endif +EXPORT_SYMBOL (of_iio_read_mount_matrix); +/** * iio_format_value() - Formats a IIO value into its string representation * @buf: The buffer to which the formatted value gets written include/linux/iio/iio.h +31
-0@@ -148,6 +148,37 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev, }/** +* struct iio_mount_matrix - iio mounting matrix +* @rotation: 3 dimensional space rotation matrix defining sensor alignment with +* main hardware +*/ +struct iio_mount_matrix { +const char *rotation[9 ]; +}; + +ssize_t iio_show_mount_matrix (struct iio_dev *indio_dev,uintptr_t priv, +const struct iio_chan_spec *chan,char *buf); +int of_iio_read_mount_matrix (const struct device *dev,const char *propname, +struct iio_mount_matrix *matrix); + +typedef const struct iio_mount_matrix * + (iio_get_mount_matrix_t )(const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan); + +/** +* IIO_MOUNT_MATRIX() - Initialize mount matrix extended channel attribute +* @_shared: Whether the attribute is shared between all channels +* @_get: Pointer to an iio_get_mount_matrix_t accessor +*/ +#define IIO_MOUNT_MATRIX (_shared, _get) \ +{ \ + .name = "mount_matrix", \ + .shared = (_shared), \ + .read = iio_show_mount_matrix, \ + .private = (uintptr_t)(_get), \ +} + +/** * struct iio_event_spec - specification for a channel event * @type: Type of the event * @dir: Direction of the event
PATCH 2/3 iio:ak8975: add mounting matrix support
In reply to a message not in the archiveExpose a rotation matrix to indicate userspace the chip orientation with respect to the overall hardware system.
Matrix is retrieved from "in_mount_matrix". It is declared into ak8975 DTS entry as a "mount-matrix" property.
--- .../bindings/iio/magnetometer/ak8975.txt | 10 +++++++ drivers/iio/magnetometer/ak8975.c | 34 +++++++++++++++++++--- include/linux/iio/magnetometer/ak8975.h | 16 ++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 include/linux/iio/magnetometer/ak8975.h
Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt +10 -0
@@ -9,6 +9,7 @@ Optional properties: - gpios : should be device tree identifier of the magnetometer DRDY pin - vdd-supply: an optional regulator that needs to be on to provide VDD + - mount-matrix: an optional 3x3 mounting rotation matrix Example:
@@ -17,4 +18,13 @@ ak8975@0c { reg = <0x0c>; gpios = <&gpj0 7 0>; vdd-supply = <&ldo_3v3_gnss>; + mount-matrix = "-0.984807753012208", /* x0 */ + "0", /* y0 */ + "-0.173648177666930", /* z0 */ + "0", /* x1 */ + "-1", /* y1 */ + "0", /* z1 */ + "-0.173648177666930", /* x2 */ + "0", /* y2 */ + "0.984807753012208"; /* z2 */ };
drivers/iio/magnetometer/ak8975.c +30 -4
@@ -40,7 +40,8 @@#include <linux/iio/trigger.h> #include <linux/iio/trigger_consumer.h> #include <linux/iio/triggered_buffer.h> -#include <linux/regulator/consumer.h> + +#include <linux/iio/magnetometer/ak8975.h> /* * Register definitions, as well as various shifts and masks to get at the
@@ -376,6 +377,7 @@ struct ak8975_data {wait_queue_head_t data_ready_queue;unsigned long flags;u8 cntl_cache; +struct iio_mount_matrix orientation;struct regulator *vdd; };
@@ -726,6 +728,18 @@ static int ak8975_read_raw(struct iio_dev *indio_dev,return -EINVAL ; } +static const struct iio_mount_matrix * +ak8975_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +return &((struct ak8975_data *)iio_priv (indio_dev))->orientation; +} + +static const struct iio_chan_spec_ext_info ak8975_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_DIR , ak8975_get_mount_matrix), + { }, +}; +#define AK8975_CHANNEL (axis, index) \ { \ .type = IIO_MAGN, \
@@ -740,7 +754,8 @@ static int ak8975_read_raw(struct iio_dev *indio_dev, .realbits = 16, \ .storagebits = 16, \ .endianness = IIO_CPU \ - } \ + }, \ + .ext_info = ak8975_ext_info, \ } static const struct iio_chan_spec ak8975_channels[] = {
@@ -837,10 +852,12 @@ static int ak8975_probe(struct i2c_client *client,int err;const char *name =NULL ;enum asahi_compass_chipset chipset; +const struct ak8975_platform_data *pdata = +dev_get_platdata (&client->dev);/* Grab and set up the supplied GPIO. */ -if (client->dev.platform_data) - eoc_gpio = *(int *)(client->dev.platform_data); +if (pdata) + eoc_gpio = pdata->eoc_gpio;else if (client->dev.of_node) eoc_gpio =of_get_gpio (client->dev.of_node,0 );else
@@ -874,6 +891,15 @@ static int ak8975_probe(struct i2c_client *client, data->eoc_gpio = eoc_gpio; data->eoc_irq =0 ; +if (!pdata) { + err =of_iio_read_mount_matrix (&client->dev, +"mount-matrix" , + &data->orientation); +if (err) +return err; + }else + data->orientation = pdata->orientation; +/* id will be NULL when enumerated via ACPI */ if (id) { chipset = (enum asahi_compass_chipset )(id->driver_data);
include/linux/iio/magnetometer/ak8975.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef __IIO_MAGNETOMETER_AK8975_H__ +#define __IIO_MAGNETOMETER_AK8975_H__ + +#include <linux/iio/iio.h> + +/** +* struct ak8975_platform_data - AK8975 magnetometer driver platform data +* @eoc_gpio: data ready event gpio +* @orientation: mounting matrix relative to main hardware +*/ +struct ak8975_platform_data { +int eoc_gpio; +struct iio_mount_matrix orientation; +}; + +#endif
Signature · 1 line
2.1.4
A message that is not in the archive (sent off-list or not yet received): 43de59ea1cc5ba93bebd721b761da4749956afa0.1461170293.git.gregor.boirie-ITF29qwbsa/[email protected]
Rob Herring
Acked-byRe: [PATCH v1 2/3] iio:ak8975: add mounting matrix support
Quoted 8 lines · Gregor Boirie
Expose a rotation matrix to indicate userspace the chip orientation with respect to the overall hardware system.
Matrix is retrieved from "in_mount_matrix". It is declared into ak8975 DTS entry as a "mount-matrix" property.--- .../bindings/iio/magnetometer/ak8975.txt | 10 +++++++
Quoted 4 lines
drivers/iio/magnetometer/ak8975.c | 34 +++++++++++++++++++--- include/linux/iio/magnetometer/ak8975.h | 16 ++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 include/linux/iio/magnetometer/ak8975.h
Re: [PATCH v1 2/3] iio:ak8975: add mounting matrix support
Quoted 11 lines · Rob Herring
Quoted 8 lines · Gregor Boirie
Expose a rotation matrix to indicate userspace the chip orientation with respect to the overall hardware system.
Matrix is retrieved from "in_mount_matrix". It is declared into ak8975 DTS entry as a "mount-matrix" property.--- .../bindings/iio/magnetometer/ak8975.txt | 10 +++++++Acked-by Rob Herring <[email protected]>
Applied to the togreg branch of iio.git - initially pushed out as testing. Thanks!
Jonathan
Quoted 10 lines
Quoted 5 lines
drivers/iio/magnetometer/ak8975.c | 34 +++++++++++++++++++--- include/linux/iio/magnetometer/ak8975.h | 16 ++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 include/linux/iio/magnetometer/ak8975.h--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/3 iio:imu:mpu6050: enhance mounting matrix support
In reply to a message not in the archiveAdd a new rotation matrix sysfs attribute compliant with IIO core mounting matrix API.
Matrix is retrieved from "in_anglvel_mount_matrix" and "in_accel_mount_matrix" sysfs attributes. It is declared into mpu6050 DTS entry as a "mount-matrix" property.
Old interface is kept for backward userspace compatibility and may be retrieved from legacy platform_data mechanism only.
--- Documentation/ABI/testing/sysfs-bus-iio | 2 ++ .../devicetree/bindings/iio/imu/inv_mpu6050.txt | 13 ++++++++ drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 36 ++++++++++++++++++++-- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 4 ++- include/linux/platform_data/invensense_mpu6050.h | 5 ++- 5 files changed, 55 insertions(+), 5 deletions(-)
Documentation/ABI/testing/sysfs-bus-iio +2 -0
@@ -1516,6 +1516,8 @@ Description: What: /sys/bus/iio/devices/iio:deviceX/mount_matrix What: /sys/bus/iio/devices/iio:deviceX/in_mount_matrix What: /sys/bus/iio/devices/iio:deviceX/out_mount_matrix +What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_mount_matrix +What: /sys/bus/iio/devices/iio:deviceX/in_accel_mount_matrix KernelVersion: 4.6 Contact: [email protected] Description:
Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt +13 -0
@@ -8,10 +8,23 @@ Required properties: - interrupt-parent : should be the phandle for the interrupt controller - interrupts : interrupt mapping for GPIO IRQ +Optional properties: + - mount-matrix: an optional 3x3 mounting rotation matrix + + Example: mpu6050@68 { compatible = "invensense,mpu6050"; reg = <0x68>; interrupt-parent = <&gpio1>; interrupts = <18 1>; + mount-matrix = "-0.984807753012208", /* x0 */ + "0", /* y0 */ + "-0.173648177666930", /* z0 */ + "0", /* x1 */ + "-1", /* y1 */ + "0", /* z1 */ + "-0.173648177666930", /* x2 */ + "0", /* y2 */ + "0.984807753012208"; /* z2 */ };
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +33 -3
@@ -600,6 +600,10 @@ inv_fifo_rate_show(struct device *dev, struct device_attribute *attr,/** * inv_attr_show() - calling this function will show current * parameters. +* +* Deprecated in favor of IIO mounting matrix API. +* +* See inv_get_mount_matrix() */ static ssize_t inv_attr_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -644,6 +648,18 @@ static int inv_mpu6050_validate_trigger(struct iio_dev *indio_dev,return 0 ; } +static const struct iio_mount_matrix * +inv_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +return &((struct inv_mpu6050_state *)iio_priv (indio_dev))->orientation; +} + +static const struct iio_chan_spec_ext_info inv_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , inv_get_mount_matrix), + { }, +}; +#define INV_MPU6050_CHAN (_type, _channel2, _index) \ { \ .type = _type, \
@@ -660,6 +676,7 @@ static int inv_mpu6050_validate_trigger(struct iio_dev *indio_dev, .shift = 0, \ .endianness = IIO_BE, \ }, \ + .ext_info = inv_ext_info, \ } static const struct iio_chan_spec inv_mpu_channels[] = {
@@ -692,14 +709,16 @@ static IIO_CONST_ATTR(in_accel_scale_available, "0.000598 0.001196 0.002392 0.004785"); static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, inv_fifo_rate_show, inv_mpu6050_fifo_rate_store); + +/* Deprecated: kept for userspace backward compatibility. */ static IIO_DEVICE_ATTR(in_gyro_matrix, S_IRUGO, inv_attr_show, NULL, ATTR_GYRO_MATRIX); static IIO_DEVICE_ATTR(in_accel_matrix, S_IRUGO, inv_attr_show, NULL, ATTR_ACCL_MATRIX);static struct attribute *inv_attributes[] = { - &iio_dev_attr_in_gyro_matrix.dev_attr.attr, - &iio_dev_attr_in_accel_matrix.dev_attr.attr, + &iio_dev_attr_in_gyro_matrix.dev_attr.attr,/* deprecated */ + &iio_dev_attr_in_accel_matrix.dev_attr.attr,/* deprecated */ &iio_dev_attr_sampling_frequency.dev_attr.attr, &iio_const_attr_sampling_frequency_available.dev_attr.attr, &iio_const_attr_in_accel_scale_available.dev_attr.attr,
@@ -779,9 +798,20 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, st->powerup_count =0 ; st->irq = irq; st->map = regmap; + pdata =dev_get_platdata (dev); -if (pdata) +if (!pdata) { + result =of_iio_read_mount_matrix (dev,"mount-matrix" , + &st->orientation); +if (result) { +dev_err (dev,"Failed to retrieve mounting matrix %d\n" , + result); +return result; + } + }else { st->plat_data = *pdata; + } +/* power is turned on inside check chip type*/ result =inv_check_and_setup_chip (st);if (result)
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +3 -1
@@ -114,7 +114,8 @@ struct inv_mpu6050_hw {* @hw: Other hardware-specific information. * @chip_type: chip type. * @time_stamp_lock: spin lock to time stamp. -* @plat_data: platform data. +* @plat_data: platform data (deprecated in favor of @orientation). +* @orientation: sensor chip orientation relative to main hardware. * @timestamps: kfifo queue to store time stamp. * @map regmap pointer. * @irq interrupt number.
@@ -131,6 +132,7 @@ struct inv_mpu6050_state {struct i2c_client *mux_client;unsigned int powerup_count;struct inv_mpu6050_platform_data plat_data; +struct iio_mount_matrix orientation; DECLARE_KFIFO(timestamps, long long, TIMESTAMP_FIFO_SIZE);struct regmap *map;int irq;
include/linux/platform_data/invensense_mpu6050.h +4 -1
@@ -16,13 +16,16 @@/** * struct inv_mpu6050_platform_data - Platform data for the mpu driver -* @orientation: Orientation matrix of the chip +* @orientation: Orientation matrix of the chip (deprecated in favor of +* mounting matrix retrieved from device-tree) * * Contains platform specific information on how to configure the MPU6050 to * work on this platform. The orientation matricies are 3x3 rotation matricies * that are applied to the data to rotate from the mounting orientation to the * platform orientation. The values must be one of 0, 1, or -1 and each row and * column should have exactly 1 non-zero value. +* +* Deprecated in favor of mounting matrix retrieved from device-tree. */ struct inv_mpu6050_platform_data {__s8 orientation[9 ];
Signature · 1 line
2.1.4
A message that is not in the archive (sent off-list or not yet received): 09429500c3879ba07731ce170d0a2242a0399422.1461170293.git.gregor.boirie-ITF29qwbsa/[email protected]
Rob Herring
Acked-byRe: [PATCH v1 3/3] iio:imu:mpu6050: enhance mounting matrix support
Quoted 9 lines · Gregor Boirie
Add a new rotation matrix sysfs attribute compliant with IIO core mounting matrix API.
Matrix is retrieved from "in_anglvel_mount_matrix" and "in_accel_mount_matrix" sysfs attributes. It is declared into mpu6050 DTS entry as a "mount-matrix" property.Old interface is kept for backward userspace compatibility and may be retrieved from legacy
platform_datamechanism only.
Quoted 8 lines
--- Documentation/ABI/testing/sysfs-bus-iio | 2 ++ .../devicetree/bindings/iio/imu/inv_mpu6050.txt | 13 ++++++++ drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 36 ++++++++++++++++++++-- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 4 ++- include/linux/platform_data/invensense_mpu6050.h | 5 ++- 5 files changed, 55 insertions(+), 5 deletions(-)
Jonathan Cameron
AppliedRe: [PATCH v1 3/3] iio:imu:mpu6050: enhance mounting matrix support
Quoted 19 lines · Rob Herring
Quoted 9 lines · Gregor Boirie
Add a new rotation matrix sysfs attribute compliant with IIO core mounting matrix API.
Matrix is retrieved from "in_anglvel_mount_matrix" and "in_accel_mount_matrix" sysfs attributes. It is declared into mpu6050 DTS entry as a "mount-matrix" property.Old interface is kept for backward userspace compatibility and may be retrieved from legacy
platform_datamechanism only.Quoted 8 lines
--- Documentation/ABI/testing/sysfs-bus-iio | 2 ++ .../devicetree/bindings/iio/imu/inv_mpu6050.txt | 13 ++++++++ drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 36 ++++++++++++++++++++-- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 4 ++- include/linux/platform_data/invensense_mpu6050.h | 5 ++- 5 files changed, 55 insertions(+), 5 deletions(-)
Quoted 1 line
Acked-by Rob Herring <[email protected]>
Applied, thanks,
Jonathan
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html