History

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.

Gregor Boirie committed 10 years ago

Commit 97eacb91 parent dfc57733 files · +56 −4Browse files

Unified · Split

3 files
  1. Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt +10 −0
  2. drivers/iio/magnetometer/ak8975.c +30 −4
  3. include/linux/iio/magnetometer/ak8975.h +16 −0
Documentation/devicetree/bindings/iio/magnetometer/ak8975.txt+10−0
@@ -9,6 +9,7 @@ Optional properties: · 8 unmodified lines
9 9
10 - gpios : should be device tree identifier of the magnetometer DRDY pin10 - gpios : should be device tree identifier of the magnetometer DRDY pin
11 - vdd-supply: an optional regulator that needs to be on to provide VDD11 - vdd-supply: an optional regulator that needs to be on to provide VDD
12 - mount-matrix: an optional 3x3 mounting rotation matrix
12 13
13Example:14Example:
14 15
@@ -17,4 +18,13 @@ ak8975@0c { · 2 unmodified lines
17 reg = <0x0c>;18 reg = <0x0c>;
18 gpios = <&gpj0 7 0>;19 gpios = <&gpj0 7 0>;
19 vdd-supply = <&ldo_3v3_gnss>;20 vdd-supply = <&ldo_3v3_gnss>;
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 */
20};30};
drivers/iio/magnetometer/ak8975.c+30−4
@@ -40,7 +40,8 @@ · 39 unmodified lines
40#include <linux/iio/trigger.h>40#include <linux/iio/trigger.h>
41#include <linux/iio/trigger_consumer.h>41#include <linux/iio/trigger_consumer.h>
42#include <linux/iio/triggered_buffer.h>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 * Register definitions, as well as various shifts and masks to get at the47 * Register definitions, as well as various shifts and masks to get at the
@@ -376,6 +377,7 @@ struct ak8975_data { · 329 unmodified lines
376 wait_queue_head_t data_ready_queue;377 wait_queue_head_t data_ready_queue;
377 unsigned long flags;378 unsigned long flags;
378 u8 cntl_cache;379 u8 cntl_cache;
380 struct iio_mount_matrix orientation;
379 struct regulator *vdd;381 struct regulator *vdd;
380};382};
381 383
@@ -726,6 +728,18 @@ static int ak8975_read_raw(struct iio_dev *indio_dev, · 344 unmodified lines
726 return -EINVAL;728 return -EINVAL;
727}729}
728 730
731static const struct iio_mount_matrix *
732ak8975_get_mount_matrix(const struct iio_dev *indio_dev,
733 const struct iio_chan_spec *chan)
734{
735 return &((struct ak8975_data *)iio_priv(indio_dev))->orientation;
736}
737
738static const struct iio_chan_spec_ext_info ak8975_ext_info[] = {
739 IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, ak8975_get_mount_matrix),
740 { },
741};
742
729#define AK8975_CHANNEL(axis, index) \743#define AK8975_CHANNEL(axis, index) \
730 { \744 { \
731 .type = IIO_MAGN, \745 .type = IIO_MAGN, \
@@ -740,7 +754,8 @@ static int ak8975_read_raw(struct iio_dev *indio_dev, · 8 unmodified lines
740 .realbits = 16, \754 .realbits = 16, \
741 .storagebits = 16, \755 .storagebits = 16, \
742 .endianness = IIO_CPU \756 .endianness = IIO_CPU \
743 } \757 }, \
758 .ext_info = ak8975_ext_info, \
744 }759 }
745 760
746static const struct iio_chan_spec ak8975_channels[] = {761static const struct iio_chan_spec ak8975_channels[] = {
@@ -837,10 +852,12 @@ static int ak8975_probe(struct i2c_client *client, · 90 unmodified lines
837 int err;852 int err;
838 const char *name = NULL;853 const char *name = NULL;
839 enum asahi_compass_chipset chipset;854 enum asahi_compass_chipset chipset;
855 const struct ak8975_platform_data *pdata =
856 dev_get_platdata(&client->dev);
840 857
841 /* Grab and set up the supplied GPIO. */858 /* Grab and set up the supplied GPIO. */
842 if (client->dev.platform_data)859 if (pdata)
843 eoc_gpio = *(int *)(client->dev.platform_data);860 eoc_gpio = pdata->eoc_gpio;
844 else if (client->dev.of_node)861 else if (client->dev.of_node)
845 eoc_gpio = of_get_gpio(client->dev.of_node, 0);862 eoc_gpio = of_get_gpio(client->dev.of_node, 0);
846 else863 else
@@ -874,6 +891,15 @@ static int ak8975_probe(struct i2c_client *client, · 27 unmodified lines
874 data->eoc_gpio = eoc_gpio;891 data->eoc_gpio = eoc_gpio;
875 data->eoc_irq = 0;892 data->eoc_irq = 0;
876 893
894 if (!pdata) {
895 err = of_iio_read_mount_matrix(&client->dev,
896 "mount-matrix",
897 &data->orientation);
898 if (err)
899 return err;
900 } else
901 data->orientation = pdata->orientation;
902
877 /* id will be NULL when enumerated via ACPI */903 /* id will be NULL when enumerated via ACPI */
878 if (id) {904 if (id) {
879 chipset = (enum asahi_compass_chipset)(id->driver_data);905 chipset = (enum asahi_compass_chipset)(id->driver_data);
include/linux/iio/magnetometer/ak8975.h+16−0
@@ -0,0 +1,16 @@
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 */
11struct ak8975_platform_data {
12 int eoc_gpio;
13 struct iio_mount_matrix orientation;
14};
15
16#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t