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
99
1010 - gpios : should be device tree identifier of the magnetometer DRDY pin
1111 - vdd-supply: an optional regulator that needs to be on to provide VDD
12+ - mount-matrix: an optional 3x3 mounting rotation matrix
1213
1314 Example:
1415
@@ -17,4 +18,13 @@ ak8975@0c { · 2 unmodified lines
1718 reg = <0x0c>;
1819 gpios = <&gpj0 7 0>;
1920 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 */
2030 };
drivers/iio/magnetometer/ak8975.c+30−4
@@ -40,7 +40,8 @@ · 39 unmodified lines
4040 #include <linux/iio/trigger.h>
4141 #include <linux/iio/trigger_consumer.h>
4242 #include <linux/iio/triggered_buffer.h>
43−#include <linux/regulator/consumer.h>
43+
44+#include <linux/iio/magnetometer/ak8975.h>
4445
4546 /*
4647 * Register definitions, as well as various shifts and masks to get at the
@@ -376,6 +377,7 @@ struct ak8975_data { · 329 unmodified lines
376377 wait_queue_head_t data_ready_queue;
377378 unsigned long flags;
378379 u8 cntl_cache;
380+ struct iio_mount_matrix orientation;
379381 struct regulator *vdd;
380382 };
381383
@@ -726,6 +728,18 @@ static int ak8975_read_raw(struct iio_dev *indio_dev, · 344 unmodified lines
726728 return -EINVAL;
727729 }
728730
731+static const struct iio_mount_matrix *
732+ak8975_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+
738+static 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+
729743 #define AK8975_CHANNEL(axis, index) \
730744 { \
731745 .type = IIO_MAGN, \
@@ -740,7 +754,8 @@ static int ak8975_read_raw(struct iio_dev *indio_dev, · 8 unmodified lines
740754 .realbits = 16, \
741755 .storagebits = 16, \
742756 .endianness = IIO_CPU \
743− } \
757+ }, \
758+ .ext_info = ak8975_ext_info, \
744759 }
745760
746761 static const struct iio_chan_spec ak8975_channels[] = {
@@ -837,10 +852,12 @@ static int ak8975_probe(struct i2c_client *client, · 90 unmodified lines
837852 int err;
838853 const char *name = NULL;
839854 enum asahi_compass_chipset chipset;
855+ const struct ak8975_platform_data *pdata =
856+ dev_get_platdata(&client->dev);
840857
841858 /* Grab and set up the supplied GPIO. */
842− if (client->dev.platform_data)
843− eoc_gpio = *(int *)(client->dev.platform_data);
859+ if (pdata)
860+ eoc_gpio = pdata->eoc_gpio;
844861 else if (client->dev.of_node)
845862 eoc_gpio = of_get_gpio(client->dev.of_node, 0);
846863 else
@@ -874,6 +891,15 @@ static int ak8975_probe(struct i2c_client *client, · 27 unmodified lines
874891 data->eoc_gpio = eoc_gpio;
875892 data->eoc_irq = 0;
876893
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+
877903 /* id will be NULL when enumerated via ACPI */
878904 if (id) {
879905 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+ */
11+struct 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