diff mbox series

[v2,06/10] iio: gyro: itg3200: add mount matrix support

Message ID ad1f1af237439dcf2a0769280f9e7b1806d484f2.1550768574.git.hns@goldelico.com (mailing list archive)
State New, archived
Headers show
Series iio mount matrix - revitalize missing bindings documentation and provide code for bmc150, bmg160, bma180, itg3200, hmc584x | expand

Commit Message

H. Nikolaus Schaller Feb. 21, 2019, 5:02 p.m. UTC
This patch allows to read a mount-matrix device tree
property and report to user-space or in-kernel iio
clients.

Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
---
 drivers/iio/gyro/itg3200_core.c  | 20 ++++++++++++++++++++
 include/linux/iio/gyro/itg3200.h |  1 +
 2 files changed, 21 insertions(+)

Comments

Jonathan Cameron March 3, 2019, 3:22 p.m. UTC | #1
On Thu, 21 Feb 2019 18:02:51 +0100
"H. Nikolaus Schaller" <hns@goldelico.com> wrote:

> This patch allows to read a mount-matrix device tree
> property and report to user-space or in-kernel iio
> clients.
> 
> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
Applied.

Thanks,

Jonathan

> ---
>  drivers/iio/gyro/itg3200_core.c  | 20 ++++++++++++++++++++
>  include/linux/iio/gyro/itg3200.h |  1 +
>  2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/iio/gyro/itg3200_core.c b/drivers/iio/gyro/itg3200_core.c
> index 7adecb562c81..203a6be33b70 100644
> --- a/drivers/iio/gyro/itg3200_core.c
> +++ b/drivers/iio/gyro/itg3200_core.c
> @@ -242,6 +242,20 @@ static int itg3200_initial_setup(struct iio_dev *indio_dev)
>  	return ret;
>  }
>  
> +static const struct iio_mount_matrix *
> +itg3200_get_mount_matrix(const struct iio_dev *indio_dev,
> +			  const struct iio_chan_spec *chan)
> +{
> +	struct itg3200 *data = iio_priv(indio_dev);
> +
> +	return &data->orientation;
> +}
> +
> +static const struct iio_chan_spec_ext_info itg3200_ext_info[] = {
> +	IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, itg3200_get_mount_matrix),
> +	{ }
> +};
> +
>  #define ITG3200_ST						\
>  	{ .sign = 's', .realbits = 16, .storagebits = 16, .endianness = IIO_BE }
>  
> @@ -255,6 +269,7 @@ static int itg3200_initial_setup(struct iio_dev *indio_dev)
>  	.address = ITG3200_REG_GYRO_ ## _mod ## OUT_H, \
>  	.scan_index = ITG3200_SCAN_GYRO_ ## _mod, \
>  	.scan_type = ITG3200_ST, \
> +	.ext_info = itg3200_ext_info, \
>  }
>  
>  static const struct iio_chan_spec itg3200_channels[] = {
> @@ -297,6 +312,11 @@ static int itg3200_probe(struct i2c_client *client,
>  
>  	st = iio_priv(indio_dev);
>  
> +	ret = iio_read_mount_matrix(&client->dev, "mount-matrix",
> +				&st->orientation);
> +	if (ret)
> +		return ret;
> +
>  	i2c_set_clientdata(client, indio_dev);
>  	st->i2c = client;
>  
> diff --git a/include/linux/iio/gyro/itg3200.h b/include/linux/iio/gyro/itg3200.h
> index 2a820850f284..0a30fddccfb3 100644
> --- a/include/linux/iio/gyro/itg3200.h
> +++ b/include/linux/iio/gyro/itg3200.h
> @@ -104,6 +104,7 @@
>  struct itg3200 {
>  	struct i2c_client	*i2c;
>  	struct iio_trigger	*trig;
> +	struct iio_mount_matrix orientation;
>  };
>  
>  enum ITG3200_SCAN_INDEX {
diff mbox series

Patch

diff --git a/drivers/iio/gyro/itg3200_core.c b/drivers/iio/gyro/itg3200_core.c
index 7adecb562c81..203a6be33b70 100644
--- a/drivers/iio/gyro/itg3200_core.c
+++ b/drivers/iio/gyro/itg3200_core.c
@@ -242,6 +242,20 @@  static int itg3200_initial_setup(struct iio_dev *indio_dev)
 	return ret;
 }
 
+static const struct iio_mount_matrix *
+itg3200_get_mount_matrix(const struct iio_dev *indio_dev,
+			  const struct iio_chan_spec *chan)
+{
+	struct itg3200 *data = iio_priv(indio_dev);
+
+	return &data->orientation;
+}
+
+static const struct iio_chan_spec_ext_info itg3200_ext_info[] = {
+	IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, itg3200_get_mount_matrix),
+	{ }
+};
+
 #define ITG3200_ST						\
 	{ .sign = 's', .realbits = 16, .storagebits = 16, .endianness = IIO_BE }
 
@@ -255,6 +269,7 @@  static int itg3200_initial_setup(struct iio_dev *indio_dev)
 	.address = ITG3200_REG_GYRO_ ## _mod ## OUT_H, \
 	.scan_index = ITG3200_SCAN_GYRO_ ## _mod, \
 	.scan_type = ITG3200_ST, \
+	.ext_info = itg3200_ext_info, \
 }
 
 static const struct iio_chan_spec itg3200_channels[] = {
@@ -297,6 +312,11 @@  static int itg3200_probe(struct i2c_client *client,
 
 	st = iio_priv(indio_dev);
 
+	ret = iio_read_mount_matrix(&client->dev, "mount-matrix",
+				&st->orientation);
+	if (ret)
+		return ret;
+
 	i2c_set_clientdata(client, indio_dev);
 	st->i2c = client;
 
diff --git a/include/linux/iio/gyro/itg3200.h b/include/linux/iio/gyro/itg3200.h
index 2a820850f284..0a30fddccfb3 100644
--- a/include/linux/iio/gyro/itg3200.h
+++ b/include/linux/iio/gyro/itg3200.h
@@ -104,6 +104,7 @@ 
 struct itg3200 {
 	struct i2c_client	*i2c;
 	struct iio_trigger	*trig;
+	struct iio_mount_matrix orientation;
 };
 
 enum ITG3200_SCAN_INDEX {