iio: imu: bmi160: added regulator and mount-matrix support
Subsystems (2)
v4 cover iio: imu: bmi160: added regulator and mount-matrix support
v4:
- add maintainer
- clean up of documentation
- added case concerning the need to add regulators, see [PATCH v4 4/5]
v3:
- separate typo fix into another patch
- clean up of documentation
- clean up of patch messages
https://lore.kernel.org/linux-iio/[email protected]/
v2:
- fixed missing description for iio: imu: bmi160: added regulator support
https://lore.kernel.org/linux-iio/[email protected]/
v1:
- initial patch submission
https://lore.kernel.org/linux-iio/[email protected]/
Convert txt format documentation to yaml.
Add documentation about vdd-supply, vddio-supply and mount-matrix.
Add vdd-supply and vddio-supply support.
Add mount-matrix binding support. As chip could have different orientations a mount matrix support is needed to correctly translate these differences.
Jonathan Albrieux (5):
dt-bindings: iio: imu: bmi160: convert format to yaml, add maintainer
dt-bindings: iio: imu: bmi160: add regulators and mount-matrix
iio: imu: bmi160: fix typo
iio: imu: bmi160: added regulator support
iio: imu: bmi160: added mount-matrix support
.../devicetree/bindings/iio/imu/bmi160.txt | 37 -------- .../bindings/iio/imu/bosch,bmi160.yaml | 91 +++++++++++++++++++ drivers/iio/imu/bmi160/bmi160.h | 3 + drivers/iio/imu/bmi160/bmi160_core.c | 46 +++++++++- 4 files changed, 139 insertions(+), 38 deletions(-) delete mode 100644 Documentation/devicetree/bindings/iio/imu/bmi160.txt create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml
Signature · 1 line
2.17.1
PATCH v4 1/5 dt-bindings: iio: imu: bmi160: convert format to yaml, add maintainer
Converts documentation from txt format to yaml.
--- .../devicetree/bindings/iio/imu/bmi160.txt | 37 --------- .../bindings/iio/imu/bosch,bmi160.yaml | 75 +++++++++++++++++++ 2 files changed, 75 insertions(+), 37 deletions(-) delete mode 100644 Documentation/devicetree/bindings/iio/imu/bmi160.txt create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml
Documentation/devicetree/bindings/iio/imu/bmi160.txt deleted +0 -37
@@ -1,37 +0,0 @@ -Bosch BMI160 - Inertial Measurement Unit with Accelerometer, Gyroscope -and externally connectable Magnetometer - -https://www.bosch-sensortec.com/bst/products/all_products/bmi160 - -Required properties: - - compatible : should be "bosch,bmi160" - - reg : the I2C address or SPI chip select number of the sensor - - spi-max-frequency : set maximum clock frequency (only for SPI) - -Optional properties: - - interrupts : interrupt mapping for IRQ - - interrupt-names : set to "INT1" if INT1 pin should be used as interrupt - input, set to "INT2" if INT2 pin should be used instead - - drive-open-drain : set if the specified interrupt pin should be configured as - open drain. If not set, defaults to push-pull. - -Examples: - -bmi160@68 { - compatible = "bosch,bmi160"; - reg = <0x68>; - - interrupt-parent = <&gpio4>; - interrupts = <12 IRQ_TYPE_EDGE_RISING>; - interrupt-names = "INT1"; -}; - -bmi160@0 { - compatible = "bosch,bmi160"; - reg = <0>; - spi-max-frequency = <10000000>; - - interrupt-parent = <&gpio2>; - interrupts = <12 IRQ_TYPE_LEVEL_LOW>; - interrupt-names = "INT2"; -};
Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v4 1/5] dt-bindings: iio: imu: bmi160: convert format to yaml, add maintainer
Quoted 10 lines · Jonathan Albrieux
Converts documentation from txt format to yaml.
Signed-off-by Jonathan Albrieux <[email protected]>--- .../devicetree/bindings/iio/imu/bmi160.txt | 37 --------- .../bindings/iio/imu/bosch,bmi160.yaml | 75 +++++++++++++++++++ 2 files changed, 75 insertions(+), 37 deletions(-) delete mode 100644 Documentation/devicetree/bindings/iio/imu/bmi160.txt create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml
Jonathan Cameron
maintainerRe: [PATCH v4 1/5] dt-bindings: iio: imu: bmi160: convert format to yaml, add maintainer
Quoted 12 lines · On Fri, 29 May 2020 11:08:34 -0600 Rob Herring <[email protected]> wrote:
Quoted 10 lines · Jonathan Albrieux
Converts documentation from txt format to yaml.
Signed-off-by Jonathan Albrieux <[email protected]>--- .../devicetree/bindings/iio/imu/bmi160.txt | 37 --------- .../bindings/iio/imu/bosch,bmi160.yaml | 75 +++++++++++++++++++ 2 files changed, 75 insertions(+), 37 deletions(-) delete mode 100644 Documentation/devicetree/bindings/iio/imu/bmi160.txt create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml
Quoted 1 line
Reviewed-by Rob Herring <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to poke at.
Thanks,
Jonathan
PATCH v4 2/5 dt-bindings: iio: imu: bmi160: add regulators and mount-matrix
In reply to Jonathan AlbrieuxAdd vdd-supply and vddio-supply support.
Add mount-matrix support.
--- .../bindings/iio/imu/bosch,bmi160.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml +16 -0
@@ -37,6 +37,17 @@ properties: set if the specified interrupt pin should be configured as open drain. If not set, defaults to push-pull. + vdd-supply: + maxItems: 1 + description: provide VDD power to the sensor. + + vddio-supply: + maxItems: 1 + description: provide VDD IO power to the sensor. + + mount-matrix: + description: an optional 3x3 mounting rotation matrix + required: - compatible - reg
@@ -52,9 +63,14 @@ examples: bmi160@68 { compatible = "bosch,bmi160"; reg = <0x68>; + vdd-supply = <&pm8916_l17>; + vddio-supply = <&pm8916_l6>; interrupt-parent = <&gpio4>; interrupts = <12 IRQ_TYPE_EDGE_RISING>; interrupt-names = "INT1"; + mount-matrix = "0", "1", "0", + "-1", "0", "0", + "0", "0", "1"; }; }; - |
Signature · 1 line
2.17.1
Rob Herring
maintainerRe: [PATCH v4 2/5] dt-bindings: iio: imu: bmi160: add regulators and mount-matrix
Quoted 13 lines · Jonathan Albrieux
Add vdd-supply and vddio-supply support.
Add mount-matrix support.Signed-off-by Jonathan Albrieux <[email protected]>--- .../bindings/iio/imu/bosch,bmi160.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml +0
-0
Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml properties: · line 41
Quoted 5 lines
Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml +2
-0@@ -37,6 +37,17 @@ properties: set if the specified interrupt pin should be configured as open drain. If not set, defaults to push-pull. + vdd-supply: + maxItems: 1
Supplies are always a single item, so don't need this.
Quoted 30 lines
Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml +14
-0+ description: provide VDD power to the sensor. + + vddio-supply: + maxItems: 1 + description: provide VDD IO power to the sensor. + + mount-matrix: + description: an optional 3x3 mounting rotation matrix + required: - compatible - reg@@ -52,9 +63,14 @@ examples: bmi160@68 { compatible = "bosch,bmi160"; reg = <0x68>; + vdd-supply = <&pm8916_l17>; + vddio-supply = <&pm8916_l6>; interrupt-parent = <&gpio4>; interrupts = <12 IRQ_TYPE_EDGE_RISING>; interrupt-names = "INT1"; + mount-matrix = "0", "1", "0", + "-1", "0", "0", + "0", "0", "1"; }; }; - |Signature · 1 line
2.17.1
Jonathan Cameron
maintainerRe: [PATCH v4 2/5] dt-bindings: iio: imu: bmi160: add regulators and mount-matrix
Quoted 17 lines · On Fri, 29 May 2020 11:09:43 -0600 Rob Herring <[email protected]> wrote:
Quoted 16 lines · Jonathan Albrieux
Add vdd-supply and vddio-supply support.
Add mount-matrix support.Signed-off-by Jonathan Albrieux <[email protected]>--- .../bindings/iio/imu/bosch,bmi160.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml +0
-0@@ -37,6 +37,17 @@ properties: set if the specified interrupt pin should be configured as open drain. If not set, defaults to push-pull.
Quoted 4 lines
Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml properties: · line 41
Quoted 2 lines
Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml +2
-0+ vdd-supply: + maxItems: 1Supplies are always a single item, so don't need this.
Given this (and case below) were it outstanding for this patch I fixed them up whilst applying rather than getting Jonathan to go around again.
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 31 lines
Quoted 31 lines
Documentation/devicetree/bindings/iio/imu/bosch,bmi160.yaml +14
-0+ description: provide VDD power to the sensor. + + vddio-supply: + maxItems: 1 + description: provide VDD IO power to the sensor. + + mount-matrix: + description: an optional 3x3 mounting rotation matrix + required: - compatible - reg@@ -52,9 +63,14 @@ examples: bmi160@68 { compatible = "bosch,bmi160"; reg = <0x68>; + vdd-supply = <&pm8916_l17>; + vddio-supply = <&pm8916_l6>; interrupt-parent = <&gpio4>; interrupts = <12 IRQ_TYPE_EDGE_RISING>; interrupt-names = "INT1"; + mount-matrix = "0", "1", "0", + "-1", "0", "0", + "0", "0", "1"; }; }; - |Signature · 1 line
2.17.1
PATCH v4 3/5 iio: imu: bmi160: fix typo
In reply to Jonathan AlbrieuxFix a typo in MODULE_AUTHOR() argument.
--- drivers/iio/imu/bmi160/bmi160_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/imu/bmi160/bmi160_core.c +1 -1
@@ -853,6 +853,6 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, }EXPORT_SYMBOL_GPL (bmi160_core_probe); -MODULE_AUTHOR ("Daniel Baluta <[email protected]" ); +MODULE_AUTHOR ("Daniel Baluta <[email protected]>" );MODULE_DESCRIPTION ("Bosch BMI160 driver" );MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.17.1
Re: [PATCH v4 3/5] iio: imu: bmi160: fix typo
Quoted 3 lines · On Mon, 25 May 2020 18:46:02 +0200 Jonathan Albrieux…
Fix a typo in
MODULE_AUTHOR()argument.Signed-off-by Jonathan Albrieux <[email protected]>
applied
Thanks,
J
Quoted 16 lines
--- drivers/iio/imu/bmi160/bmi160_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/imu/bmi160/bmi160_core.c +1
-1@@ -853,6 +853,6 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, }EXPORT_SYMBOL_GPL (bmi160_core_probe); -MODULE_AUTHOR ("Daniel Baluta <[email protected]" ); +MODULE_AUTHOR ("Daniel Baluta <[email protected]>" );MODULE_DESCRIPTION ("Bosch BMI160 driver" );MODULE_LICENSE ("GPL v2" );
PATCH v4 4/5 iio: imu: bmi160: added regulator support
In reply to Jonathan AlbrieuxAdd vdd-supply and vddio-supply support.
While working on an msm8916 device and having explicit declarations for regulators, without setting these regulators to regulators-always-on it happened those lines weren't ready because they could have been controlled by other components, causing failure in module's probe.
This patch aim is to solve this situation by adding regulators control during bmi160_chip_init() and bmi160_chip_uninit(), assuring power to this component.
--- drivers/iio/imu/bmi160/bmi160.h | 2 ++ drivers/iio/imu/bmi160/bmi160_core.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+)
drivers/iio/imu/bmi160/bmi160.h +2 -0
@@ -3,10 +3,12 @@#define BMI160_H_ #include <linux/iio/iio.h> +#include <linux/regulator/consumer.h> struct bmi160_data {struct regmap *regmap;struct iio_trigger *trig; +struct regulator_bulk_data supplies[2 ]; };extern const struct regmap_config bmi160_regmap_config;
drivers/iio/imu/bmi160/bmi160_core.c +24 -0
@@ -15,6 +15,7 @@#include <linux/delay.h> #include <linux/irq.h> #include <linux/of_irq.h> +#include <linux/regulator/consumer.h> #include <linux/iio/iio.h> #include <linux/iio/triggered_buffer.h>
@@ -709,6 +710,12 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)unsigned int val;struct device *dev =regmap_get_device (data->regmap); + ret =regulator_bulk_enable (ARRAY_SIZE (data->supplies), data->supplies); +if (ret) { +dev_err (dev,"Failed to enable regulators: %d\n" , ret); +return ret; + } + ret =regmap_write (data->regmap,BMI160_REG_CMD ,BMI160_CMD_SOFTRESET );if (ret)return ret;
@@ -793,9 +800,16 @@ int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type)static void bmi160_chip_uninit (void *data) {struct bmi160_data *bmi_data = data; +struct device *dev =regmap_get_device (bmi_data->regmap); +int ret;bmi160_set_mode (bmi_data,BMI160_GYRO , false);bmi160_set_mode (bmi_data,BMI160_ACCEL , false); + + ret =regulator_bulk_disable (ARRAY_SIZE (bmi_data->supplies), + bmi_data->supplies); +if (ret) +dev_err (dev,"Failed to disable regulators: %d\n" , ret); } int bmi160_core_probe(struct device *dev, struct regmap *regmap,
@@ -815,6 +829,16 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap,dev_set_drvdata (dev, indio_dev); data->regmap = regmap; + data->supplies[0 ].supply ="vdd" ; + data->supplies[1 ].supply ="vddio" ; + ret =devm_regulator_bulk_get (dev, +ARRAY_SIZE (data->supplies), + data->supplies); +if (ret) { +dev_err (dev,"Failed to get regulators: %d\n" , ret); +return ret; + } + ret =bmi160_chip_init (data, use_spi);if (ret)return ret;
Signature · 1 line
2.17.1
Re: [PATCH v4 4/5] iio: imu: bmi160: added regulator support
Quoted 7 lines · On Mon, 25 May 2020 18:46:03 +0200 Jonathan Albrieux…
Add vdd-supply and vddio-supply support.
While working on an msm8916 device and having explicit declarations for regulators, without setting these regulators to regulators-always-on it happened those lines weren't ready because they could have been controlled by other components, causing failure in module's probe.
Quoted 5 lines
This patch aim is to solve this situation by adding regulators control during
bmi160_chip_init()andbmi160_chip_uninit(), assuring power to this component.Signed-off-by Jonathan Albrieux <[email protected]>
Applied,
Thanks,
Jonathan
Quoted 81 lines
--- drivers/iio/imu/bmi160/bmi160.h | 2 ++ drivers/iio/imu/bmi160/bmi160_core.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+)drivers/iio/imu/bmi160/bmi160.h +2
-0@@ -3,10 +3,12 @@#define BMI160_H_ #include <linux/iio/iio.h> +#include <linux/regulator/consumer.h> struct bmi160_data {struct regmap *regmap;struct iio_trigger *trig; +struct regulator_bulk_data supplies[2 ]; };extern const struct regmap_config bmi160_regmap_config;drivers/iio/imu/bmi160/bmi160_core.c +24
-0@@ -15,6 +15,7 @@#include <linux/delay.h> #include <linux/irq.h> #include <linux/of_irq.h> +#include <linux/regulator/consumer.h> #include <linux/iio/iio.h> #include <linux/iio/triggered_buffer.h> @@ -709,6 +710,12 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)unsigned int val;struct device *dev =regmap_get_device (data->regmap); + ret =regulator_bulk_enable (ARRAY_SIZE (data->supplies), data->supplies); +if (ret) { +dev_err (dev,"Failed to enable regulators: %d\n" , ret); +return ret; + } + ret =regmap_write (data->regmap,BMI160_REG_CMD ,BMI160_CMD_SOFTRESET );if (ret)return ret;@@ -793,9 +800,16 @@ int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type)static void bmi160_chip_uninit (void *data) {struct bmi160_data *bmi_data = data; +struct device *dev =regmap_get_device (bmi_data->regmap); +int ret;bmi160_set_mode (bmi_data,BMI160_GYRO , false);bmi160_set_mode (bmi_data,BMI160_ACCEL , false); + + ret =regulator_bulk_disable (ARRAY_SIZE (bmi_data->supplies), + bmi_data->supplies); +if (ret) +dev_err (dev,"Failed to disable regulators: %d\n" , ret); } int bmi160_core_probe(struct device *dev, struct regmap *regmap,@@ -815,6 +829,16 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap,dev_set_drvdata (dev, indio_dev); data->regmap = regmap; + data->supplies[0 ].supply ="vdd" ; + data->supplies[1 ].supply ="vddio" ; + ret =devm_regulator_bulk_get (dev, +ARRAY_SIZE (data->supplies), + data->supplies); +if (ret) { +dev_err (dev,"Failed to get regulators: %d\n" , ret); +return ret; + } + ret =bmi160_chip_init (data, use_spi);if (ret)return ret;
PATCH v4 5/5 iio: imu: bmi160: added mount-matrix support
In reply to Jonathan AlbrieuxAdd mount-matrix binding support. As chip could have different orientations a mount matrix support is needed to correctly translate these differences.
--- drivers/iio/imu/bmi160/bmi160.h | 1 + drivers/iio/imu/bmi160/bmi160_core.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)
drivers/iio/imu/bmi160/bmi160.h +1 -0
@@ -9,6 +9,7 @@ struct bmi160_data {struct regmap *regmap;struct iio_trigger *trig;struct regulator_bulk_data supplies[2 ]; +struct iio_mount_matrix orientation; };extern const struct regmap_config bmi160_regmap_config;
drivers/iio/imu/bmi160/bmi160_core.c +20 -0
@@ -110,6 +110,7 @@ .storagebits = 16, \ .endianness = IIO_LE, \ }, \ + .ext_info = bmi160_ext_info, \ }/* scan indexes follow DATA register order */
@@ -265,6 +266,20 @@ static const struct bmi160_odr_item bmi160_odr_table[] = { }, }; +static const struct iio_mount_matrix * +bmi160_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct bmi160_data *data =iio_priv (indio_dev); + +return &data->orientation; +} + +static const struct iio_chan_spec_ext_info bmi160_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_DIR , bmi160_get_mount_matrix), + { } +}; +static const struct iio_chan_spec bmi160_channels[] = {BMI160_CHANNEL (IIO_ACCEL ,X ,BMI160_SCAN_ACCEL_X ),BMI160_CHANNEL (IIO_ACCEL ,Y ,BMI160_SCAN_ACCEL_Y ),
@@ -839,6 +854,11 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap,return ret; } + ret =iio_read_mount_matrix (dev,"mount-matrix" , + &data->orientation); +if (ret) +return ret; + ret =bmi160_chip_init (data, use_spi);if (ret)return ret;
Signature · 1 line
2.17.1