linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3 v2] iio: accel: bmc150-accel: Add DT bindings
@ 2020-11-12 21:54 Linus Walleij
  2020-11-12 21:54 ` [PATCH 2/3 v2] 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-12 21:54 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	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>
---
ChangeLog v1->v2:
- Rename to simply bosch,bma255.yaml after one of the
  common accelerometers.
- Specify that the SPI uses a 4-wire interface.
- Specify maximum SPI clock frequency to 10MHz. (Checked
  all the datasheets.)
---
 .../bindings/iio/accel/bosch,bma255.yaml      | 73 +++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml

diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml
new file mode 100644
index 000000000000..5f48bdcf382c
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml
@@ -0,0 +1,73 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/accel/bosch,bma255.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Bosch BMA255 and Similar Accelerometers
+
+maintainers:
+  - Linus Walleij <linus.walleij@linaro.org>
+
+description:
+  3 axis accelerometers with varying range and I2C or SPI
+  4-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:
+    maximum: 10000000
+
+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 v2] iio: accel: bmc150-accel: Add support for BMA222
  2020-11-12 21:54 [PATCH 1/3 v2] iio: accel: bmc150-accel: Add DT bindings Linus Walleij
@ 2020-11-12 21:54 ` Linus Walleij
  2020-11-14 16:41   ` Jonathan Cameron
  2020-11-12 21:54 ` [PATCH 3/3 v2] iio: accel: bmc150-accel: Add rudimentary regulator support Linus Walleij
  2020-11-14 16:35 ` [PATCH 1/3 v2] iio: accel: bmc150-accel: Add DT bindings Jonathan Cameron
  2 siblings, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2020-11-12 21:54 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	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>
---
ChangeLog v1->v2:
- None, resend with the other patches.
---
 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 v2] iio: accel: bmc150-accel: Add rudimentary regulator support
  2020-11-12 21:54 [PATCH 1/3 v2] iio: accel: bmc150-accel: Add DT bindings Linus Walleij
  2020-11-12 21:54 ` [PATCH 2/3 v2] iio: accel: bmc150-accel: Add support for BMA222 Linus Walleij
@ 2020-11-12 21:54 ` Linus Walleij
  2020-11-14 16:42   ` Jonathan Cameron
  2020-11-14 16:35 ` [PATCH 1/3 v2] iio: accel: bmc150-accel: Add DT bindings Jonathan Cameron
  2 siblings, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2020-11-12 21:54 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	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>
---
ChangeLog v1->v2:
- Use dev_err_probe() to simplify the errorpath.
---
 drivers/iio/accel/bmc150-accel-core.c | 35 +++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index 0dafe4052856..a9714cfacf4d 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,33 @@ 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)
+		return dev_err_probe(dev, ret, "failed to get regulators\n");
+
+	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 +1638,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 +1699,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 +1726,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 v2] iio: accel: bmc150-accel: Add DT bindings
  2020-11-12 21:54 [PATCH 1/3 v2] iio: accel: bmc150-accel: Add DT bindings Linus Walleij
  2020-11-12 21:54 ` [PATCH 2/3 v2] iio: accel: bmc150-accel: Add support for BMA222 Linus Walleij
  2020-11-12 21:54 ` [PATCH 3/3 v2] iio: accel: bmc150-accel: Add rudimentary regulator support Linus Walleij
@ 2020-11-14 16:35 ` Jonathan Cameron
  2 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2020-11-14 16:35 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, devicetree

On Thu, 12 Nov 2020 22:54:49 +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>

One little note inline on consistency.

Jonathan

> ---
> ChangeLog v1->v2:
> - Rename to simply bosch,bma255.yaml after one of the
>   common accelerometers.
> - Specify that the SPI uses a 4-wire interface.
> - Specify maximum SPI clock frequency to 10MHz. (Checked
>   all the datasheets.)
> ---
>  .../bindings/iio/accel/bosch,bma255.yaml      | 73 +++++++++++++++++++
>  1 file changed, 73 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml
> 
> diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml
> new file mode 100644
> index 000000000000..5f48bdcf382c
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml
> @@ -0,0 +1,73 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/iio/accel/bosch,bma255.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Bosch BMA255 and Similar Accelerometers
> +
> +maintainers:
> +  - Linus Walleij <linus.walleij@linaro.org>
> +
> +description:
> +  3 axis accelerometers with varying range and I2C or SPI
> +  4-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:
> +    maximum: 10000000
> +
> +required:
> +  - compatible
> +  - reg
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    i2c {
> +        #include <dt-bindings/interrupt-controller/irq.h>
Off the top of my head I'm not sure it matters, but this placement of the
include is inconsistent with the spi case below.  Move it outside the i2c {

If that's all that comes up in this round I'll do it whilst applying.

> +        #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 v2] iio: accel: bmc150-accel: Add support for BMA222
  2020-11-12 21:54 ` [PATCH 2/3 v2] iio: accel: bmc150-accel: Add support for BMA222 Linus Walleij
@ 2020-11-14 16:41   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2020-11-14 16:41 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler

On Thu, 12 Nov 2020 22:54:50 +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>

Noticed something new this time...

It doesn't really matter when adding this device as the wasted space
is small, but we may end up adding more devices in future and this
will get worse each time.

Thanks,

Jonathan


> ---
> ChangeLog v1->v2:
> - None, resend with the other patches.
> ---
>  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);

Why introduce an exact replica of the entry below it?
I guess the compiler 'might' notice and squish these.  It's common
enough to have multiple device type entries point at an existing
iio_chan_spec array.


>  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),

Just set these to bma222e_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 v2] iio: accel: bmc150-accel: Add rudimentary regulator support
  2020-11-12 21:54 ` [PATCH 3/3 v2] iio: accel: bmc150-accel: Add rudimentary regulator support Linus Walleij
@ 2020-11-14 16:42   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2020-11-14 16:42 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler

On Thu, 12 Nov 2020 22:54:51 +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>
Looks good.

J
> ---
> ChangeLog v1->v2:
> - Use dev_err_probe() to simplify the errorpath.
> ---
>  drivers/iio/accel/bmc150-accel-core.c | 35 +++++++++++++++++++++++++--
>  1 file changed, 33 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
> index 0dafe4052856..a9714cfacf4d 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,33 @@ 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)
> +		return dev_err_probe(dev, ret, "failed to get regulators\n");
> +
> +	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 +1638,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 +1699,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 +1726,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-14 16:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-12 21:54 [PATCH 1/3 v2] iio: accel: bmc150-accel: Add DT bindings Linus Walleij
2020-11-12 21:54 ` [PATCH 2/3 v2] iio: accel: bmc150-accel: Add support for BMA222 Linus Walleij
2020-11-14 16:41   ` Jonathan Cameron
2020-11-12 21:54 ` [PATCH 3/3 v2] iio: accel: bmc150-accel: Add rudimentary regulator support Linus Walleij
2020-11-14 16:42   ` Jonathan Cameron
2020-11-14 16:35 ` [PATCH 1/3 v2] 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).