| @@ -40,7 +40,8 @@ · 39 unmodified lines |
| 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 |
| @@ -376,6 +377,7 @@ struct ak8975_data { · 329 unmodified lines |
| 376 | 377 | wait_queue_head_t data_ready_queue; |
| 377 | 378 | unsigned long flags; |
| 378 | 379 | u8 cntl_cache; |
| 380 | + struct iio_mount_matrix orientation; |
| 379 | 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 | 728 | return -EINVAL; |
| 727 | 729 | } |
| 728 | 730 | |
| 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 | + |
| 729 | 743 | #define AK8975_CHANNEL(axis, index) \ |
| 730 | 744 | { \ |
| 731 | 745 | .type = IIO_MAGN, \ |
| @@ -740,7 +754,8 @@ static int ak8975_read_raw(struct iio_dev *indio_dev, · 8 unmodified lines |
| 740 | 754 | .realbits = 16, \ |
| 741 | 755 | .storagebits = 16, \ |
| 742 | 756 | .endianness = IIO_CPU \ |
| 743 | | − } \ |
| 757 | + }, \ |
| 758 | + .ext_info = ak8975_ext_info, \ |
| 744 | 759 | } |
| 745 | 760 | |
| 746 | 761 | static const struct iio_chan_spec ak8975_channels[] = { |
| @@ -837,10 +852,12 @@ static int ak8975_probe(struct i2c_client *client, · 90 unmodified lines |
| 837 | 852 | int err; |
| 838 | 853 | const char *name = NULL; |
| 839 | 854 | enum asahi_compass_chipset chipset; |
| 855 | + const struct ak8975_platform_data *pdata = |
| 856 | + dev_get_platdata(&client->dev); |
| 840 | 857 | |
| 841 | 858 | /* 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; |
| 844 | 861 | else if (client->dev.of_node) |
| 845 | 862 | eoc_gpio = of_get_gpio(client->dev.of_node, 0); |
| 846 | 863 | else |
| @@ -874,6 +891,15 @@ static int ak8975_probe(struct i2c_client *client, · 27 unmodified lines |
| 874 | 891 | data->eoc_gpio = eoc_gpio; |
| 875 | 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 | 903 | /* id will be NULL when enumerated via ACPI */ |
| 878 | 904 | if (id) { |
| 879 | 905 | chipset = (enum asahi_compass_chipset)(id->driver_data); |