Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio:imu:mpu6050: enhance mounting matrix support

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_data mechanism only.

Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Gregor Boirie and committed by
Jonathan Cameron
eb379846 97eacb91

+55 -5
+2
Documentation/ABI/testing/sysfs-bus-iio
··· 1516 1516 What: /sys/bus/iio/devices/iio:deviceX/mount_matrix 1517 1517 What: /sys/bus/iio/devices/iio:deviceX/in_mount_matrix 1518 1518 What: /sys/bus/iio/devices/iio:deviceX/out_mount_matrix 1519 + What: /sys/bus/iio/devices/iio:deviceX/in_anglvel_mount_matrix 1520 + What: /sys/bus/iio/devices/iio:deviceX/in_accel_mount_matrix 1519 1521 KernelVersion: 4.6 1520 1522 Contact: linux-iio@vger.kernel.org 1521 1523 Description:
+13
Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
··· 8 8 - interrupt-parent : should be the phandle for the interrupt controller 9 9 - interrupts : interrupt mapping for GPIO IRQ 10 10 11 + Optional properties: 12 + - mount-matrix: an optional 3x3 mounting rotation matrix 13 + 14 + 11 15 Example: 12 16 mpu6050@68 { 13 17 compatible = "invensense,mpu6050"; 14 18 reg = <0x68>; 15 19 interrupt-parent = <&gpio1>; 16 20 interrupts = <18 1>; 21 + mount-matrix = "-0.984807753012208", /* x0 */ 22 + "0", /* y0 */ 23 + "-0.173648177666930", /* z0 */ 24 + "0", /* x1 */ 25 + "-1", /* y1 */ 26 + "0", /* z1 */ 27 + "-0.173648177666930", /* x2 */ 28 + "0", /* y2 */ 29 + "0.984807753012208"; /* z2 */ 17 30 };
+33 -3
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
··· 600 600 /** 601 601 * inv_attr_show() - calling this function will show current 602 602 * parameters. 603 + * 604 + * Deprecated in favor of IIO mounting matrix API. 605 + * 606 + * See inv_get_mount_matrix() 603 607 */ 604 608 static ssize_t inv_attr_show(struct device *dev, struct device_attribute *attr, 605 609 char *buf) ··· 648 644 return 0; 649 645 } 650 646 647 + static const struct iio_mount_matrix * 648 + inv_get_mount_matrix(const struct iio_dev *indio_dev, 649 + const struct iio_chan_spec *chan) 650 + { 651 + return &((struct inv_mpu6050_state *)iio_priv(indio_dev))->orientation; 652 + } 653 + 654 + static const struct iio_chan_spec_ext_info inv_ext_info[] = { 655 + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, inv_get_mount_matrix), 656 + { }, 657 + }; 658 + 651 659 #define INV_MPU6050_CHAN(_type, _channel2, _index) \ 652 660 { \ 653 661 .type = _type, \ ··· 676 660 .shift = 0, \ 677 661 .endianness = IIO_BE, \ 678 662 }, \ 663 + .ext_info = inv_ext_info, \ 679 664 } 680 665 681 666 static const struct iio_chan_spec inv_mpu_channels[] = { ··· 709 692 "0.000598 0.001196 0.002392 0.004785"); 710 693 static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, inv_fifo_rate_show, 711 694 inv_mpu6050_fifo_rate_store); 695 + 696 + /* Deprecated: kept for userspace backward compatibility. */ 712 697 static IIO_DEVICE_ATTR(in_gyro_matrix, S_IRUGO, inv_attr_show, NULL, 713 698 ATTR_GYRO_MATRIX); 714 699 static IIO_DEVICE_ATTR(in_accel_matrix, S_IRUGO, inv_attr_show, NULL, 715 700 ATTR_ACCL_MATRIX); 716 701 717 702 static struct attribute *inv_attributes[] = { 718 - &iio_dev_attr_in_gyro_matrix.dev_attr.attr, 719 - &iio_dev_attr_in_accel_matrix.dev_attr.attr, 703 + &iio_dev_attr_in_gyro_matrix.dev_attr.attr, /* deprecated */ 704 + &iio_dev_attr_in_accel_matrix.dev_attr.attr, /* deprecated */ 720 705 &iio_dev_attr_sampling_frequency.dev_attr.attr, 721 706 &iio_const_attr_sampling_frequency_available.dev_attr.attr, 722 707 &iio_const_attr_in_accel_scale_available.dev_attr.attr, ··· 798 779 st->powerup_count = 0; 799 780 st->irq = irq; 800 781 st->map = regmap; 782 + 801 783 pdata = dev_get_platdata(dev); 802 - if (pdata) 784 + if (!pdata) { 785 + result = of_iio_read_mount_matrix(dev, "mount-matrix", 786 + &st->orientation); 787 + if (result) { 788 + dev_err(dev, "Failed to retrieve mounting matrix %d\n", 789 + result); 790 + return result; 791 + } 792 + } else { 803 793 st->plat_data = *pdata; 794 + } 795 + 804 796 /* power is turned on inside check chip type*/ 805 797 result = inv_check_and_setup_chip(st); 806 798 if (result)
+3 -1
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
··· 114 114 * @hw: Other hardware-specific information. 115 115 * @chip_type: chip type. 116 116 * @time_stamp_lock: spin lock to time stamp. 117 - * @plat_data: platform data. 117 + * @plat_data: platform data (deprecated in favor of @orientation). 118 + * @orientation: sensor chip orientation relative to main hardware. 118 119 * @timestamps: kfifo queue to store time stamp. 119 120 * @map regmap pointer. 120 121 * @irq interrupt number. ··· 132 131 struct i2c_client *mux_client; 133 132 unsigned int powerup_count; 134 133 struct inv_mpu6050_platform_data plat_data; 134 + struct iio_mount_matrix orientation; 135 135 DECLARE_KFIFO(timestamps, long long, TIMESTAMP_FIFO_SIZE); 136 136 struct regmap *map; 137 137 int irq;
+4 -1
include/linux/platform_data/invensense_mpu6050.h
··· 16 16 17 17 /** 18 18 * struct inv_mpu6050_platform_data - Platform data for the mpu driver 19 - * @orientation: Orientation matrix of the chip 19 + * @orientation: Orientation matrix of the chip (deprecated in favor of 20 + * mounting matrix retrieved from device-tree) 20 21 * 21 22 * Contains platform specific information on how to configure the MPU6050 to 22 23 * work on this platform. The orientation matricies are 3x3 rotation matricies 23 24 * that are applied to the data to rotate from the mounting orientation to the 24 25 * platform orientation. The values must be one of 0, 1, or -1 and each row and 25 26 * column should have exactly 1 non-zero value. 27 + * 28 + * Deprecated in favor of mounting matrix retrieved from device-tree. 26 29 */ 27 30 struct inv_mpu6050_platform_data { 28 31 __s8 orientation[9];