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

iio:ak8975: add mounting matrix support

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.

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
97eacb91 dfc57732

+56 -4
+10
Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt
··· 9 9 10 10 - gpios : should be device tree identifier of the magnetometer DRDY pin 11 11 - vdd-supply: an optional regulator that needs to be on to provide VDD 12 + - mount-matrix: an optional 3x3 mounting rotation matrix 12 13 13 14 Example: 14 15 ··· 18 17 reg = <0x0c>; 19 18 gpios = <&gpj0 7 0>; 20 19 vdd-supply = <&ldo_3v3_gnss>; 20 + mount-matrix = "-0.984807753012208", /* x0 */ 21 + "0", /* y0 */ 22 + "-0.173648177666930", /* z0 */ 23 + "0", /* x1 */ 24 + "-1", /* y1 */ 25 + "0", /* z1 */ 26 + "-0.173648177666930", /* x2 */ 27 + "0", /* y2 */ 28 + "0.984807753012208"; /* z2 */ 21 29 };
+30 -4
drivers/iio/magnetometer/ak8975.c
··· 40 40 #include <linux/iio/trigger.h> 41 41 #include <linux/iio/trigger_consumer.h> 42 42 #include <linux/iio/triggered_buffer.h> 43 - #include <linux/regulator/consumer.h> 43 + 44 + #include <linux/iio/magnetometer/ak8975.h> 44 45 45 46 /* 46 47 * Register definitions, as well as various shifts and masks to get at the ··· 377 376 wait_queue_head_t data_ready_queue; 378 377 unsigned long flags; 379 378 u8 cntl_cache; 379 + struct iio_mount_matrix orientation; 380 380 struct regulator *vdd; 381 381 }; 382 382 ··· 728 726 return -EINVAL; 729 727 } 730 728 729 + static const struct iio_mount_matrix * 730 + ak8975_get_mount_matrix(const struct iio_dev *indio_dev, 731 + const struct iio_chan_spec *chan) 732 + { 733 + return &((struct ak8975_data *)iio_priv(indio_dev))->orientation; 734 + } 735 + 736 + static const struct iio_chan_spec_ext_info ak8975_ext_info[] = { 737 + IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, ak8975_get_mount_matrix), 738 + { }, 739 + }; 740 + 731 741 #define AK8975_CHANNEL(axis, index) \ 732 742 { \ 733 743 .type = IIO_MAGN, \ ··· 754 740 .realbits = 16, \ 755 741 .storagebits = 16, \ 756 742 .endianness = IIO_CPU \ 757 - } \ 743 + }, \ 744 + .ext_info = ak8975_ext_info, \ 758 745 } 759 746 760 747 static const struct iio_chan_spec ak8975_channels[] = { ··· 852 837 int err; 853 838 const char *name = NULL; 854 839 enum asahi_compass_chipset chipset; 840 + const struct ak8975_platform_data *pdata = 841 + dev_get_platdata(&client->dev); 855 842 856 843 /* Grab and set up the supplied GPIO. */ 857 - if (client->dev.platform_data) 858 - eoc_gpio = *(int *)(client->dev.platform_data); 844 + if (pdata) 845 + eoc_gpio = pdata->eoc_gpio; 859 846 else if (client->dev.of_node) 860 847 eoc_gpio = of_get_gpio(client->dev.of_node, 0); 861 848 else ··· 890 873 data->client = client; 891 874 data->eoc_gpio = eoc_gpio; 892 875 data->eoc_irq = 0; 876 + 877 + if (!pdata) { 878 + err = of_iio_read_mount_matrix(&client->dev, 879 + "mount-matrix", 880 + &data->orientation); 881 + if (err) 882 + return err; 883 + } else 884 + data->orientation = pdata->orientation; 893 885 894 886 /* id will be NULL when enumerated via ACPI */ 895 887 if (id) {
+16
include/linux/iio/magnetometer/ak8975.h
··· 1 + #ifndef __IIO_MAGNETOMETER_AK8975_H__ 2 + #define __IIO_MAGNETOMETER_AK8975_H__ 3 + 4 + #include <linux/iio/iio.h> 5 + 6 + /** 7 + * struct ak8975_platform_data - AK8975 magnetometer driver platform data 8 + * @eoc_gpio: data ready event gpio 9 + * @orientation: mounting matrix relative to main hardware 10 + */ 11 + struct ak8975_platform_data { 12 + int eoc_gpio; 13 + struct iio_mount_matrix orientation; 14 + }; 15 + 16 + #endif