linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] iio: accel: bmc150-accel: Add DT bindings
@ 2020-11-01 12:28 Linus Walleij
  2020-11-01 12:28 ` [PATCH 2/3] iio: accel: bmc150-accel: Add support for BMA222 Linus Walleij
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Linus Walleij @ 2020-11-01 12:28 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	linux-input, Linus Walleij, devicetree

These accelerometers have bindings used in the kernel and
several device trees but no proper bindings documentation.
Add it.

Also add a compatible for the BMA222 that I am right now
adding support for in the driver.

Cc: devicetree@vger.kernel.org
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 .../bindings/iio/accel/bosch,bmc-bmi-bma.yaml | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/accel/bosch,bmc-bmi-bma.yaml

diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bmc-bmi-bma.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bmc-bmi-bma.yaml
new file mode 100644
index 000000000000..11b8b68aaf3e
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/accel/bosch,bmc-bmi-bma.yaml
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/accel/bosch,bmc-bmi-bma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Bosch BMCxxx, BMIxxx and BMAxxx Accelerometers
+
+maintainers:
+  - Linus Walleij <linus.walleij@linaro.org>
+
+description:
+  3 axis accelerometers with varying range and I2C or SPI
+  3-wire interface.
+
+properties:
+  compatible:
+    enum:
+      - bosch,bmc150
+      - bosch,bmi055
+      - bosch,bma255
+      - bosch,bma250e
+      - bosch,bma222
+      - bosch,bma222e
+      - bosch,bma280
+
+  reg:
+    maxItems: 1
+
+  vdd-supply: true
+  vddio-supply: true
+
+  interrupts:
+    maxItems: 1
+
+  mount-matrix:
+    description: an optional 3x3 mounting rotation matrix.
+
+  spi-max-frequency: true
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #include <dt-bindings/interrupt-controller/irq.h>
+        #address-cells = <1>;
+        #size-cells = <0>;
+        accelerometer@8 {
+            compatible = "bosch,bma222";
+            reg = <0x08>;
+            vddio-supply = <&vddio>;
+            vdd-supply = <&vdd>;
+            interrupts = <57 IRQ_TYPE_EDGE_FALLING>;
+        };
+    };
+  - |
+    # include <dt-bindings/interrupt-controller/irq.h>
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        accel@0 {
+            compatible = "bosch,bma222";
+            reg = <0>;
+            spi-max-frequency = <10000000>;
+        };
+    };
+...
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] iio: accel: bmc150-accel: Add support for BMA222
  2020-11-01 12:28 [PATCH 1/3] iio: accel: bmc150-accel: Add DT bindings Linus Walleij
@ 2020-11-01 12:28 ` Linus Walleij
  2020-11-01 20:47   ` Jonathan Cameron
  2020-11-01 12:28 ` [PATCH 3/3] iio: accel: bmc150-accel: Add rudimentary regulator support Linus Walleij
  2020-11-01 20:44 ` [PATCH 1/3] iio: accel: bmc150-accel: Add DT bindings Jonathan Cameron
  2 siblings, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2020-11-01 12:28 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	linux-input, Linus Walleij

This adds support for the BMA222 version of this sensor,
found in for example the Samsung GT-I9070 mobile phone.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/accel/bmc150-accel-core.c | 17 +++++++++++++++++
 drivers/iio/accel/bmc150-accel-i2c.c  |  4 ++++
 drivers/iio/accel/bmc150-accel-spi.c  |  2 ++
 drivers/iio/accel/bmc150-accel.h      |  1 +
 4 files changed, 24 insertions(+)

diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index 48435865fdaf..0dafe4052856 100644
--- a/drivers/iio/accel/bmc150-accel-core.c
+++ b/drivers/iio/accel/bmc150-accel-core.c
@@ -5,6 +5,7 @@
  *  - BMI055
  *  - BMA255
  *  - BMA250E
+ *  - BMA222
  *  - BMA222E
  *  - BMA280
  *
@@ -1013,6 +1014,8 @@ static const struct iio_event_spec bmc150_accel_event = {
 	IIO_CHAN_SOFT_TIMESTAMP(3),					\
 }
 
+static const struct iio_chan_spec bma222_accel_channels[] =
+	BMC150_ACCEL_CHANNELS(8);
 static const struct iio_chan_spec bma222e_accel_channels[] =
 	BMC150_ACCEL_CHANNELS(8);
 static const struct iio_chan_spec bma250e_accel_channels[] =
@@ -1063,6 +1066,20 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
 				 {153277, BMC150_ACCEL_DEF_RANGE_8G},
 				 {306457, BMC150_ACCEL_DEF_RANGE_16G} },
 	},
+	[bma222] = {
+		.name = "BMA222",
+		.chip_id = 0x03,
+		.channels = bma222_accel_channels,
+		.num_channels = ARRAY_SIZE(bma222_accel_channels),
+		/*
+		 * The datasheet page 17 says:
+		 * 15.6, 31.3, 62.5 and 125 mg per LSB.
+		 */
+		.scale_table = { {156000, BMC150_ACCEL_DEF_RANGE_2G},
+				 {313000, BMC150_ACCEL_DEF_RANGE_4G},
+				 {625000, BMC150_ACCEL_DEF_RANGE_8G},
+				 {1250000, BMC150_ACCEL_DEF_RANGE_16G} },
+	},
 	[bma222e] = {
 		.name = "BMA222E",
 		.chip_id = 0xF8,
diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c
index 06021c8685a7..bba92dd33179 100644
--- a/drivers/iio/accel/bmc150-accel-i2c.c
+++ b/drivers/iio/accel/bmc150-accel-i2c.c
@@ -5,6 +5,7 @@
  *  - BMI055
  *  - BMA255
  *  - BMA250E
+ *  - BMA222
  *  - BMA222E
  *  - BMA280
  *
@@ -54,6 +55,7 @@ static const struct acpi_device_id bmc150_accel_acpi_match[] = {
 	{"BMI055A",	bmi055},
 	{"BMA0255",	bma255},
 	{"BMA250E",	bma250e},
+	{"BMA222",	bma222},
 	{"BMA222E",	bma222e},
 	{"BMA0280",	bma280},
 	{"BOSC0200"},
@@ -66,6 +68,7 @@ static const struct i2c_device_id bmc150_accel_id[] = {
 	{"bmi055_accel",	bmi055},
 	{"bma255",		bma255},
 	{"bma250e",		bma250e},
+	{"bma222",		bma222},
 	{"bma222e",		bma222e},
 	{"bma280",		bma280},
 	{}
@@ -78,6 +81,7 @@ static const struct of_device_id bmc150_accel_of_match[] = {
 	{ .compatible = "bosch,bmi055_accel" },
 	{ .compatible = "bosch,bma255" },
 	{ .compatible = "bosch,bma250e" },
+	{ .compatible = "bosch,bma222" },
 	{ .compatible = "bosch,bma222e" },
 	{ .compatible = "bosch,bma280" },
 	{ },
diff --git a/drivers/iio/accel/bmc150-accel-spi.c b/drivers/iio/accel/bmc150-accel-spi.c
index 2a8c311d6f5a..74a8aee4f612 100644
--- a/drivers/iio/accel/bmc150-accel-spi.c
+++ b/drivers/iio/accel/bmc150-accel-spi.c
@@ -39,6 +39,7 @@ static const struct acpi_device_id bmc150_accel_acpi_match[] = {
 	{"BMI055A",	bmi055},
 	{"BMA0255",	bma255},
 	{"BMA250E",	bma250e},
+	{"BMA222",	bma222},
 	{"BMA222E",	bma222e},
 	{"BMA0280",	bma280},
 	{ },
@@ -50,6 +51,7 @@ static const struct spi_device_id bmc150_accel_id[] = {
 	{"bmi055_accel",	bmi055},
 	{"bma255",		bma255},
 	{"bma250e",		bma250e},
+	{"bma222",		bma222},
 	{"bma222e",		bma222e},
 	{"bma280",		bma280},
 	{}
diff --git a/drivers/iio/accel/bmc150-accel.h b/drivers/iio/accel/bmc150-accel.h
index ae6118ae11b1..f5427103574d 100644
--- a/drivers/iio/accel/bmc150-accel.h
+++ b/drivers/iio/accel/bmc150-accel.h
@@ -9,6 +9,7 @@ enum {
 	bmi055,
 	bma255,
 	bma250e,
+	bma222,
 	bma222e,
 	bma280,
 };
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] iio: accel: bmc150-accel: Add rudimentary regulator support
  2020-11-01 12:28 [PATCH 1/3] iio: accel: bmc150-accel: Add DT bindings Linus Walleij
  2020-11-01 12:28 ` [PATCH 2/3] iio: accel: bmc150-accel: Add support for BMA222 Linus Walleij
@ 2020-11-01 12:28 ` Linus Walleij
  2020-11-01 20:52   ` Jonathan Cameron
  2020-11-01 20:44 ` [PATCH 1/3] iio: accel: bmc150-accel: Add DT bindings Jonathan Cameron
  2 siblings, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2020-11-01 12:28 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	linux-input, Linus Walleij

These Bosch accelerometers have two supplies, VDD and VDDIO.
Add some rudimentary support to obtain and enable these
regulators during probe() and disable them during remove()
or on the errorpath.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/accel/bmc150-accel-core.c | 37 +++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index 0dafe4052856..a69a4f54d69a 100644
--- a/drivers/iio/accel/bmc150-accel-core.c
+++ b/drivers/iio/accel/bmc150-accel-core.c
@@ -28,6 +28,7 @@
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 
 #include "bmc150-accel.h"
 
@@ -184,6 +185,7 @@ enum bmc150_accel_trigger_id {
 
 struct bmc150_accel_data {
 	struct regmap *regmap;
+	struct regulator_bulk_data regulators[2];
 	int irq;
 	struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS];
 	struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS];
@@ -1593,10 +1595,35 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
 				     &data->orientation);
 	if (ret)
 		return ret;
+	/*
+	 * VDD   is the analog and digital domain voltage supply
+	 * VDDIO is the digital I/O voltage supply
+	 */
+	data->regulators[0].supply = "vdd";
+	data->regulators[1].supply = "vddio";
+	ret = devm_regulator_bulk_get(dev,
+				      ARRAY_SIZE(data->regulators),
+				      data->regulators);
+	if (ret) {
+		if (ret != -EPROBE_DEFER)
+			dev_err(dev, "Failed to get regulators %d\n", ret);
+		return ret;
+	}
+	ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
+				    data->regulators);
+	if (ret) {
+		dev_err(dev, "failed to enable regulators: %d\n", ret);
+		return ret;
+	}
+	/*
+	 * 2ms or 3ms power-on time according to datasheets, let's better
+	 * be safe than sorry and set this delay to 5ms.
+	 */
+	msleep(5);
 
 	ret = bmc150_accel_chip_init(data);
 	if (ret < 0)
-		return ret;
+		goto err_disable_regulators;
 
 	mutex_init(&data->mutex);
 
@@ -1613,7 +1640,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
 					 &bmc150_accel_buffer_ops);
 	if (ret < 0) {
 		dev_err(dev, "Failed: iio triggered buffer setup\n");
-		return ret;
+		goto err_disable_regulators;
 	}
 
 	if (data->irq > 0) {
@@ -1674,6 +1701,9 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
 	bmc150_accel_unregister_triggers(data, BMC150_ACCEL_TRIGGERS - 1);
 err_buffer_cleanup:
 	iio_triggered_buffer_cleanup(indio_dev);
+err_disable_regulators:
+	regulator_bulk_disable(ARRAY_SIZE(data->regulators),
+			       data->regulators);
 
 	return ret;
 }
@@ -1698,6 +1728,9 @@ int bmc150_accel_core_remove(struct device *dev)
 	bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_DEEP_SUSPEND, 0);
 	mutex_unlock(&data->mutex);
 
+	regulator_bulk_disable(ARRAY_SIZE(data->regulators),
+			       data->regulators);
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(bmc150_accel_core_remove);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] iio: accel: bmc150-accel: Add DT bindings
  2020-11-01 12:28 [PATCH 1/3] iio: accel: bmc150-accel: Add DT bindings Linus Walleij
  2020-11-01 12:28 ` [PATCH 2/3] iio: accel: bmc150-accel: Add support for BMA222 Linus Walleij
  2020-11-01 12:28 ` [PATCH 3/3] iio: accel: bmc150-accel: Add rudimentary regulator support Linus Walleij
@ 2020-11-01 20:44 ` Jonathan Cameron
  2 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2020-11-01 20:44 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-input, devicetree

On Sun,  1 Nov 2020 13:28:31 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> These accelerometers have bindings used in the kernel and
> several device trees but no proper bindings documentation.
> Add it.
> 
> Also add a compatible for the BMA222 that I am right now
> adding support for in the driver.
> 
> Cc: devicetree@vger.kernel.org
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Hi Linus,

A few minor things inline.

Great to be plugging some of the holes in binding docs.
Doing a complete check is on my todo list :)

Jonathan

> ---
>  .../bindings/iio/accel/bosch,bmc-bmi-bma.yaml | 72 +++++++++++++++++++

So far we only have a few bindings that aren't named after a supported part.
Give we have other devices that match these letters, I don't think we want to
do it here.  Just confused people!

Pick a part and name it after that.

>  1 file changed, 72 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/iio/accel/bosch,bmc-bmi-bma.yaml
> 
> diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bmc-bmi-bma.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bmc-bmi-bma.yaml
> new file mode 100644
> index 000000000000..11b8b68aaf3e
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/accel/bosch,bmc-bmi-bma.yaml
> @@ -0,0 +1,72 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/iio/accel/bosch,bmc-bmi-bma.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Bosch BMCxxx, BMIxxx and BMAxxx Accelerometers

Some of them...  see bma180.txt in the same directory.
I'd go with bma255 and similar (chose your favourite part number)
> +
> +maintainers:
> +  - Linus Walleij <linus.walleij@linaro.org>
> +
> +description:
> +  3 axis accelerometers with varying range and I2C or SPI
> +  3-wire interface.

Looks like 4-wire to me.  CSB, SPI-CLK, SDO, SDI.

> +
> +properties:
> +  compatible:
> +    enum:
> +      - bosch,bmc150
> +      - bosch,bmi055
> +      - bosch,bma255
> +      - bosch,bma250e
> +      - bosch,bma222
> +      - bosch,bma222e
> +      - bosch,bma280
> +
> +  reg:
> +    maxItems: 1
> +
> +  vdd-supply: true
> +  vddio-supply: true
> +
> +  interrupts:
> +    maxItems: 1
> +
> +  mount-matrix:
> +    description: an optional 3x3 mounting rotation matrix.
> +
> +  spi-max-frequency: true

Don't suppose these all share a common max?
I looked at a few and 10MHz was the value for those.
Always nice to pin things down a bit if we can!

> +
> +required:
> +  - compatible
> +  - reg
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    i2c {
> +        #include <dt-bindings/interrupt-controller/irq.h>
> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +        accelerometer@8 {
> +            compatible = "bosch,bma222";
> +            reg = <0x08>;
> +            vddio-supply = <&vddio>;
> +            vdd-supply = <&vdd>;
> +            interrupts = <57 IRQ_TYPE_EDGE_FALLING>;
> +        };
> +    };
> +  - |
> +    # include <dt-bindings/interrupt-controller/irq.h>
> +    spi {
> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +        accel@0 {
> +            compatible = "bosch,bma222";
> +            reg = <0>;
> +            spi-max-frequency = <10000000>;
> +        };
> +    };
> +...


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] iio: accel: bmc150-accel: Add support for BMA222
  2020-11-01 12:28 ` [PATCH 2/3] iio: accel: bmc150-accel: Add support for BMA222 Linus Walleij
@ 2020-11-01 20:47   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2020-11-01 20:47 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-input

On Sun,  1 Nov 2020 13:28:32 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> This adds support for the BMA222 version of this sensor,
> found in for example the Samsung GT-I9070 mobile phone.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Looks good to me.

Jonathan

> ---
>  drivers/iio/accel/bmc150-accel-core.c | 17 +++++++++++++++++
>  drivers/iio/accel/bmc150-accel-i2c.c  |  4 ++++
>  drivers/iio/accel/bmc150-accel-spi.c  |  2 ++
>  drivers/iio/accel/bmc150-accel.h      |  1 +
>  4 files changed, 24 insertions(+)
> 
> diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
> index 48435865fdaf..0dafe4052856 100644
> --- a/drivers/iio/accel/bmc150-accel-core.c
> +++ b/drivers/iio/accel/bmc150-accel-core.c
> @@ -5,6 +5,7 @@
>   *  - BMI055
>   *  - BMA255
>   *  - BMA250E
> + *  - BMA222
>   *  - BMA222E
>   *  - BMA280
>   *
> @@ -1013,6 +1014,8 @@ static const struct iio_event_spec bmc150_accel_event = {
>  	IIO_CHAN_SOFT_TIMESTAMP(3),					\
>  }
>  
> +static const struct iio_chan_spec bma222_accel_channels[] =
> +	BMC150_ACCEL_CHANNELS(8);
>  static const struct iio_chan_spec bma222e_accel_channels[] =
>  	BMC150_ACCEL_CHANNELS(8);
>  static const struct iio_chan_spec bma250e_accel_channels[] =
> @@ -1063,6 +1066,20 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
>  				 {153277, BMC150_ACCEL_DEF_RANGE_8G},
>  				 {306457, BMC150_ACCEL_DEF_RANGE_16G} },
>  	},
> +	[bma222] = {
> +		.name = "BMA222",
> +		.chip_id = 0x03,
> +		.channels = bma222_accel_channels,
> +		.num_channels = ARRAY_SIZE(bma222_accel_channels),
> +		/*
> +		 * The datasheet page 17 says:
> +		 * 15.6, 31.3, 62.5 and 125 mg per LSB.
> +		 */
> +		.scale_table = { {156000, BMC150_ACCEL_DEF_RANGE_2G},
> +				 {313000, BMC150_ACCEL_DEF_RANGE_4G},
> +				 {625000, BMC150_ACCEL_DEF_RANGE_8G},
> +				 {1250000, BMC150_ACCEL_DEF_RANGE_16G} },
> +	},
>  	[bma222e] = {
>  		.name = "BMA222E",
>  		.chip_id = 0xF8,
> diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c
> index 06021c8685a7..bba92dd33179 100644
> --- a/drivers/iio/accel/bmc150-accel-i2c.c
> +++ b/drivers/iio/accel/bmc150-accel-i2c.c
> @@ -5,6 +5,7 @@
>   *  - BMI055
>   *  - BMA255
>   *  - BMA250E
> + *  - BMA222
>   *  - BMA222E
>   *  - BMA280
>   *
> @@ -54,6 +55,7 @@ static const struct acpi_device_id bmc150_accel_acpi_match[] = {
>  	{"BMI055A",	bmi055},
>  	{"BMA0255",	bma255},
>  	{"BMA250E",	bma250e},
> +	{"BMA222",	bma222},
>  	{"BMA222E",	bma222e},
>  	{"BMA0280",	bma280},
>  	{"BOSC0200"},
> @@ -66,6 +68,7 @@ static const struct i2c_device_id bmc150_accel_id[] = {
>  	{"bmi055_accel",	bmi055},
>  	{"bma255",		bma255},
>  	{"bma250e",		bma250e},
> +	{"bma222",		bma222},
>  	{"bma222e",		bma222e},
>  	{"bma280",		bma280},
>  	{}
> @@ -78,6 +81,7 @@ static const struct of_device_id bmc150_accel_of_match[] = {
>  	{ .compatible = "bosch,bmi055_accel" },
>  	{ .compatible = "bosch,bma255" },
>  	{ .compatible = "bosch,bma250e" },
> +	{ .compatible = "bosch,bma222" },
>  	{ .compatible = "bosch,bma222e" },
>  	{ .compatible = "bosch,bma280" },
>  	{ },
> diff --git a/drivers/iio/accel/bmc150-accel-spi.c b/drivers/iio/accel/bmc150-accel-spi.c
> index 2a8c311d6f5a..74a8aee4f612 100644
> --- a/drivers/iio/accel/bmc150-accel-spi.c
> +++ b/drivers/iio/accel/bmc150-accel-spi.c
> @@ -39,6 +39,7 @@ static const struct acpi_device_id bmc150_accel_acpi_match[] = {
>  	{"BMI055A",	bmi055},
>  	{"BMA0255",	bma255},
>  	{"BMA250E",	bma250e},
> +	{"BMA222",	bma222},
>  	{"BMA222E",	bma222e},
>  	{"BMA0280",	bma280},
>  	{ },
> @@ -50,6 +51,7 @@ static const struct spi_device_id bmc150_accel_id[] = {
>  	{"bmi055_accel",	bmi055},
>  	{"bma255",		bma255},
>  	{"bma250e",		bma250e},
> +	{"bma222",		bma222},
>  	{"bma222e",		bma222e},
>  	{"bma280",		bma280},
>  	{}
> diff --git a/drivers/iio/accel/bmc150-accel.h b/drivers/iio/accel/bmc150-accel.h
> index ae6118ae11b1..f5427103574d 100644
> --- a/drivers/iio/accel/bmc150-accel.h
> +++ b/drivers/iio/accel/bmc150-accel.h
> @@ -9,6 +9,7 @@ enum {
>  	bmi055,
>  	bma255,
>  	bma250e,
> +	bma222,
>  	bma222e,
>  	bma280,
>  };


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] iio: accel: bmc150-accel: Add rudimentary regulator support
  2020-11-01 12:28 ` [PATCH 3/3] iio: accel: bmc150-accel: Add rudimentary regulator support Linus Walleij
@ 2020-11-01 20:52   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2020-11-01 20:52 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-input

On Sun,  1 Nov 2020 13:28:33 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> These Bosch accelerometers have two supplies, VDD and VDDIO.
> Add some rudimentary support to obtain and enable these
> regulators during probe() and disable them during remove()
> or on the errorpath.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Minor suggestion inline using new dev_err_probe()

thanks,

Jonathan
> ---
>  drivers/iio/accel/bmc150-accel-core.c | 37 +++++++++++++++++++++++++--
>  1 file changed, 35 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
> index 0dafe4052856..a69a4f54d69a 100644
> --- a/drivers/iio/accel/bmc150-accel-core.c
> +++ b/drivers/iio/accel/bmc150-accel-core.c
> @@ -28,6 +28,7 @@
>  #include <linux/iio/trigger_consumer.h>
>  #include <linux/iio/triggered_buffer.h>
>  #include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
>  
>  #include "bmc150-accel.h"
>  
> @@ -184,6 +185,7 @@ enum bmc150_accel_trigger_id {
>  
>  struct bmc150_accel_data {
>  	struct regmap *regmap;
> +	struct regulator_bulk_data regulators[2];
>  	int irq;
>  	struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS];
>  	struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS];
> @@ -1593,10 +1595,35 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
>  				     &data->orientation);
>  	if (ret)
>  		return ret;
> +	/*
> +	 * VDD   is the analog and digital domain voltage supply
> +	 * VDDIO is the digital I/O voltage supply
> +	 */
> +	data->regulators[0].supply = "vdd";
> +	data->regulators[1].supply = "vddio";
> +	ret = devm_regulator_bulk_get(dev,
> +				      ARRAY_SIZE(data->regulators),
> +				      data->regulators);
> +	if (ret) {
> +		if (ret != -EPROBE_DEFER)
> +			dev_err(dev, "Failed to get regulators %d\n", ret);
We have a magic print function for this now

return dev_err_probe(ret, "Failed to get regulators\n");

should do the job I think...

> +		return ret;
> +	}
> +	ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
> +				    data->regulators);
> +	if (ret) {
> +		dev_err(dev, "failed to enable regulators: %d\n", ret);
> +		return ret;
> +	}
> +	/*
> +	 * 2ms or 3ms power-on time according to datasheets, let's better
> +	 * be safe than sorry and set this delay to 5ms.
> +	 */
> +	msleep(5);
>  
>  	ret = bmc150_accel_chip_init(data);
>  	if (ret < 0)
> -		return ret;
> +		goto err_disable_regulators;
>  
>  	mutex_init(&data->mutex);
>  
> @@ -1613,7 +1640,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
>  					 &bmc150_accel_buffer_ops);
>  	if (ret < 0) {
>  		dev_err(dev, "Failed: iio triggered buffer setup\n");
> -		return ret;
> +		goto err_disable_regulators;
>  	}
>  
>  	if (data->irq > 0) {
> @@ -1674,6 +1701,9 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
>  	bmc150_accel_unregister_triggers(data, BMC150_ACCEL_TRIGGERS - 1);
>  err_buffer_cleanup:
>  	iio_triggered_buffer_cleanup(indio_dev);
> +err_disable_regulators:
> +	regulator_bulk_disable(ARRAY_SIZE(data->regulators),
> +			       data->regulators);
>  
>  	return ret;
>  }
> @@ -1698,6 +1728,9 @@ int bmc150_accel_core_remove(struct device *dev)
>  	bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_DEEP_SUSPEND, 0);
>  	mutex_unlock(&data->mutex);
>  
> +	regulator_bulk_disable(ARRAY_SIZE(data->regulators),
> +			       data->regulators);
> +
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(bmc150_accel_core_remove);


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-11-01 20:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-01 12:28 [PATCH 1/3] iio: accel: bmc150-accel: Add DT bindings Linus Walleij
2020-11-01 12:28 ` [PATCH 2/3] iio: accel: bmc150-accel: Add support for BMA222 Linus Walleij
2020-11-01 20:47   ` Jonathan Cameron
2020-11-01 12:28 ` [PATCH 3/3] iio: accel: bmc150-accel: Add rudimentary regulator support Linus Walleij
2020-11-01 20:52   ` Jonathan Cameron
2020-11-01 20:44 ` [PATCH 1/3] iio: accel: bmc150-accel: Add DT bindings Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).