linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead)
@ 2018-08-03  0:18 Brian Masney
  2018-08-03  0:18 ` [PATCH v3 1/9] iio: imu: mpu6050: add support for regulator framework Brian Masney
                   ` (8 more replies)
  0 siblings, 9 replies; 26+ messages in thread
From: Brian Masney @ 2018-08-03  0:18 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc
  Cc: jonathan, jmaneyrol, knaack.h, lars, pmeerw, mkelly,
	fischerdouglasc, bshah, ctatlor97

This patch set adds support for the gyroscope / accelerometer
(mpu6515), magnetometer (ak8963), temperature / pressure (bmp280), and
proximity / ALS (tsl2772) sensors to the LG Nexus 5 (hammerhead) phone.

Changes since v2:
- Updated dt property names for tsl2772: amstaos,proximity-diodes and
  led-max-microamp based on feedback from Jonathan Cameron and Rob
  Herring.
- Removed regulator_enabled flags.
- Refactored tsl2772 regulator code.
- Split out device tree bindings into separate patches.

Changes since v1:
- Correct mpu6050 patch based on feedback from Jonathan Cameron. See
  that patch for more details.
- Add support for proximity / ALS driver (tsl2772).

Brian Masney (9):
  iio: imu: mpu6050: add support for regulator framework
  ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for
    mpu6515
  iio: tsl2772: add support for reading proximity led settings from
    device tree
  dt-bindings: iio: tsl2772: add new bindings
  iio: tsl2772: add support for regulator framework
  dt-bindings: iio: tsl2772: add bindings for regulator framework
  iio: tsl2772: add support for avago,apds9930
  dt-bindings: iio: tsl2772: add binding for avago,apds9930
  ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for ALS /
    proximity

 .../bindings/iio/imu/inv_mpu6050.txt          |   1 +
 .../devicetree/bindings/iio/light/tsl2772.txt |  42 ++++
 .../devicetree/bindings/trivial-devices.txt   |  10 -
 .../qcom-msm8974-lge-nexus5-hammerhead.dts    |  83 ++++++++
 arch/arm/boot/dts/qcom-msm8974.dtsi           |  22 ++
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    |  62 ++++++
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h     |   2 +
 drivers/iio/light/tsl2772.c                   | 194 +++++++++++++++++-
 8 files changed, 403 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/light/tsl2772.txt

-- 
2.17.1


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

* [PATCH v3 1/9] iio: imu: mpu6050: add support for regulator framework
  2018-08-03  0:18 [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead) Brian Masney
@ 2018-08-03  0:18 ` Brian Masney
  2018-08-03 21:44   ` Jonathan Cameron
  2018-08-03  0:18 ` [PATCH v3 2/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for mpu6515 Brian Masney
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Brian Masney @ 2018-08-03  0:18 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc
  Cc: jonathan, jmaneyrol, knaack.h, lars, pmeerw, mkelly,
	fischerdouglasc, bshah, ctatlor97

This patch adds support for the regulator framework to the mpu6050
driver.

Signed-off-by: Brian Masney <masneyb@onstation.org>
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Acked-by: Rob Herring <robh@kernel.org>
---
Changes since v2:
- Dropped regulator_enabled value since it is not needed.

Changes since v1:
- Use devm_regulator_get() instead of devm_regulator_get_optional()
- Use devm_add_action() for cleaning up the regulator.
- Correct ordering of resume code.
- Add regulator_enabled flag to ensure regulator is not disabled twice,
  specifically the case where the device is suspended and then the
  driver is removed.

Original extra changelog from v1:

This is a variation of Jonathan Marek's patch from postmarketOS
https://gitlab.com/postmarketOS/linux-postmarketos/commit/b8ad1ec1859c8bbcbce94944b3f4dd68f8f9fc37
with the following changes:

- Stripped out 6515 variant code.
- Add the regulator to the mpu core instead of only the i2c variant.
- Add error handling.
- Release the regulator on suspend, device remove, etc.
- Device tree documentation.

 .../bindings/iio/imu/inv_mpu6050.txt          |  1 +
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 62 +++++++++++++++++++
 drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h     |  2 +
 3 files changed, 65 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
index b2f27da847b8..6ab9a9d196b0 100644
--- a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
+++ b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
@@ -20,6 +20,7 @@ Required properties:
   bindings.
 
 Optional properties:
+ - vddio-supply: regulator phandle for VDDIO supply
  - mount-matrix: an optional 3x3 mounting rotation matrix
  - i2c-gate node.  These devices also support an auxiliary i2c bus.  This is
    simple enough to be described using the i2c-gate binding. See
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index d80ef468508a..1e428c196a82 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -23,6 +23,7 @@
 #include <linux/iio/iio.h>
 #include <linux/acpi.h>
 #include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
 #include "inv_mpu_iio.h"
 
 /*
@@ -926,6 +927,39 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st)
 	return result;
 }
 
+static int inv_mpu_core_enable_regulator(struct inv_mpu6050_state *st)
+{
+	int result;
+
+	result = regulator_enable(st->vddio_supply);
+	if (result) {
+		dev_err(regmap_get_device(st->map),
+			"Failed to enable regulator: %d\n", result);
+	} else {
+		/* Give the device a little bit of time to start up. */
+		usleep_range(35000, 70000);
+	}
+
+	return result;
+}
+
+static int inv_mpu_core_disable_regulator(struct inv_mpu6050_state *st)
+{
+	int result;
+
+	result = regulator_disable(st->vddio_supply);
+	if (result)
+		dev_err(regmap_get_device(st->map),
+			"Failed to disable regulator: %d\n", result);
+
+	return result;
+}
+
+static void inv_mpu_core_disable_regulator_action(void *_data)
+{
+	inv_mpu_core_disable_regulator(_data);
+}
+
 int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 		int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type)
 {
@@ -992,6 +1026,28 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 		return -EINVAL;
 	}
 
+	st->vddio_supply = devm_regulator_get(dev, "vddio");
+	if (IS_ERR(st->vddio_supply)) {
+		if (PTR_ERR(st->vddio_supply) != -EPROBE_DEFER)
+			dev_err(dev, "Failed to get vddio regulator %d\n",
+				(int)PTR_ERR(st->vddio_supply));
+
+		return PTR_ERR(st->vddio_supply);
+	}
+
+	result = inv_mpu_core_enable_regulator(st);
+	if (result)
+		return result;
+
+	result = devm_add_action(dev, inv_mpu_core_disable_regulator_action,
+				 st);
+	if (result) {
+		inv_mpu_core_disable_regulator_action(st);
+		dev_err(dev, "Failed to setup regulator cleanup action %d\n",
+			result);
+		return result;
+	}
+
 	/* power is turned on inside check chip type*/
 	result = inv_check_and_setup_chip(st);
 	if (result)
@@ -1051,7 +1107,12 @@ static int inv_mpu_resume(struct device *dev)
 	int result;
 
 	mutex_lock(&st->lock);
+	result = inv_mpu_core_enable_regulator(st);
+	if (result)
+		goto out_unlock;
+
 	result = inv_mpu6050_set_power_itg(st, true);
+out_unlock:
 	mutex_unlock(&st->lock);
 
 	return result;
@@ -1064,6 +1125,7 @@ static int inv_mpu_suspend(struct device *dev)
 
 	mutex_lock(&st->lock);
 	result = inv_mpu6050_set_power_itg(st, false);
+	inv_mpu_core_disable_regulator(st);
 	mutex_unlock(&st->lock);
 
 	return result;
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index e69a59659dbc..6bcc11fc1b88 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -129,6 +129,7 @@ struct inv_mpu6050_hw {
  *  @chip_period:	chip internal period estimation (~1kHz).
  *  @it_timestamp:	timestamp from previous interrupt.
  *  @data_timestamp:	timestamp for next data sample.
+ *  @vddio_supply	voltage regulator for the chip.
  */
 struct inv_mpu6050_state {
 	struct mutex lock;
@@ -149,6 +150,7 @@ struct inv_mpu6050_state {
 	s64 chip_period;
 	s64 it_timestamp;
 	s64 data_timestamp;
+	struct regulator *vddio_supply;
 };
 
 /*register and associated bit definition*/
-- 
2.17.1


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

* [PATCH v3 2/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for mpu6515
  2018-08-03  0:18 [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead) Brian Masney
  2018-08-03  0:18 ` [PATCH v3 1/9] iio: imu: mpu6050: add support for regulator framework Brian Masney
@ 2018-08-03  0:18 ` Brian Masney
  2018-08-03 21:46   ` Jonathan Cameron
  2018-08-03  0:18 ` [PATCH v3 3/9] iio: tsl2772: add support for reading proximity led settings from device tree Brian Masney
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Brian Masney @ 2018-08-03  0:18 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc
  Cc: jonathan, jmaneyrol, knaack.h, lars, pmeerw, mkelly,
	fischerdouglasc, bshah, ctatlor97

This patch adds device tree bindings for the mpu6515 to the LG Nexus 5
(hammerhead) phone. Confirmed that the gyroscope / accelerometer
(mpu6515), magnetometer (ak8963), and temperature / pressure (bmp280)
sensors are available on the phone.

Interrupts are not working properly on the ak8963 magnetometer so they
are currently not configured.

The bmp280 retuns temperature/pressure measurement skipped errors but
will reliably work if I run:

    echo 1 > in_pressure_oversampling_ratio
    echo 1 > in_temp_oversampling_ratio

Signed-off-by: Brian Masney <masneyb@onstation.org>
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
---
I'll send follow up patch(es) once I investigate why the skipped errors
are occurring with the bmp280 with the default oversampling ratios.

 .../qcom-msm8974-lge-nexus5-hammerhead.dts    | 56 +++++++++++++++++++
 arch/arm/boot/dts/qcom-msm8974.dtsi           | 11 ++++
 2 files changed, 67 insertions(+)

diff --git a/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts b/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
index c2dc9d09484a..928affae1885 100644
--- a/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
+++ b/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
@@ -241,6 +241,24 @@
 				bias-pull-up;
 			};
 		};
+
+		i2c12_pins: i2c12 {
+			mux {
+				pins = "gpio87", "gpio88";
+				function = "blsp_i2c12";
+				drive-strength = <2>;
+				bias-disable;
+			};
+		};
+
+		mpu6515_pin: mpu6515 {
+			irq {
+				pins = "gpio73";
+				function = "gpio";
+				bias-disable;
+				input-enable;
+			};
+		};
 	};
 
 	sdhci@f9824900 {
@@ -277,6 +295,44 @@
 			linux,code = <KEY_VOLUMEDOWN>;
 		};
 	};
+
+	i2c@f9968000 {
+		status = "ok";
+		pinctrl-names = "default";
+		pinctrl-0 = <&i2c12_pins>;
+		clock-frequency = <100000>;
+		qcom,src-freq = <50000000>;
+
+		mpu6515@68 {
+			compatible = "invensense,mpu6515";
+			reg = <0x68>;
+			interrupts-extended = <&msmgpio 73 IRQ_TYPE_EDGE_FALLING>;
+			vddio-supply = <&pm8941_lvs1>;
+
+			pinctrl-names = "default";
+			pinctrl-0 = <&mpu6515_pin>;
+
+			i2c-gate {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				ak8963@f {
+					compatible = "asahi-kasei,ak8963";
+					reg = <0x0f>;
+					// Currently only works in polling mode.
+					// gpios = <&msmgpio 61 0>;
+					vid-supply = <&pm8941_lvs1>;
+					vdd-supply = <&pm8941_l17>;
+				};
+
+				bmp280@76 {
+					compatible = "bosch,bmp280";
+					reg = <0x76>;
+					vdda-supply = <&pm8941_lvs1>;
+					vddd-supply = <&pm8941_l17>;
+				};
+			};
+		};
+	};
 };
 
 &spmi_bus {
diff --git a/arch/arm/boot/dts/qcom-msm8974.dtsi b/arch/arm/boot/dts/qcom-msm8974.dtsi
index d9019a49b292..cebb6ae9143a 100644
--- a/arch/arm/boot/dts/qcom-msm8974.dtsi
+++ b/arch/arm/boot/dts/qcom-msm8974.dtsi
@@ -737,6 +737,17 @@
 			dma-names = "tx", "rx";
 		};
 
+		blsp_i2c12: i2c@f9968000 {
+			status = "disabled";
+			compatible = "qcom,i2c-qup-v2.1.1";
+			reg = <0xf9968000 0x1000>;
+			interrupts = <0 106 IRQ_TYPE_NONE>;
+			clocks = <&gcc GCC_BLSP2_QUP6_I2C_APPS_CLK>, <&gcc GCC_BLSP2_AHB_CLK>;
+			clock-names = "core", "iface";
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
 		spmi_bus: spmi@fc4cf000 {
 			compatible = "qcom,spmi-pmic-arb";
 			reg-names = "core", "intr", "cnfg";
-- 
2.17.1


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

* [PATCH v3 3/9] iio: tsl2772: add support for reading proximity led settings from device tree
  2018-08-03  0:18 [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead) Brian Masney
  2018-08-03  0:18 ` [PATCH v3 1/9] iio: imu: mpu6050: add support for regulator framework Brian Masney
  2018-08-03  0:18 ` [PATCH v3 2/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for mpu6515 Brian Masney
@ 2018-08-03  0:18 ` Brian Masney
  2018-08-18 17:04   ` Jonathan Cameron
  2018-08-03  0:18 ` [PATCH v3 4/9] dt-bindings: iio: tsl2772: add new bindings Brian Masney
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Brian Masney @ 2018-08-03  0:18 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc
  Cc: jonathan, jmaneyrol, knaack.h, lars, pmeerw, mkelly,
	fischerdouglasc, bshah, ctatlor97

This patch adds support for optionally reading the proximity led diode
and current settings from device tree. This was tested using a LG
Nexus 5 (hammerhead) which requires a different diode than the driver
default for the IR LED.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/iio/light/tsl2772.c | 81 +++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
index df5b2a0da96c..ae00edf0d87e 100644
--- a/drivers/iio/light/tsl2772.c
+++ b/drivers/iio/light/tsl2772.c
@@ -107,6 +107,8 @@
 #define TSL2772_ALS_GAIN_TRIM_MIN	250
 #define TSL2772_ALS_GAIN_TRIM_MAX	4000
 
+#define TSL2772_MAX_PROX_LEDS		2
+
 /* Device family members */
 enum {
 	tsl2571,
@@ -141,6 +143,14 @@ struct tsl2772_chip_info {
 	const struct iio_info *info;
 };
 
+static const int tsl2772_led_currents[][2] = {
+	{ 100000, TSL2772_100_mA },
+	{  50000, TSL2772_50_mA },
+	{  25000, TSL2772_25_mA },
+	{  13000, TSL2772_13_mA },
+	{      0, 0 }
+};
+
 struct tsl2772_chip {
 	kernel_ulong_t id;
 	struct mutex prox_mutex;
@@ -515,6 +525,75 @@ static int tsl2772_get_prox(struct iio_dev *indio_dev)
 	return ret;
 }
 
+static int tsl2772_read_prox_led_current(struct tsl2772_chip *chip)
+{
+	struct device_node *of_node = chip->client->dev.of_node;
+	int ret, tmp, i;
+
+	ret = of_property_read_u32(of_node, "led-max-microamp", &tmp);
+	if (ret < 0)
+		return ret;
+
+	for (i = 0; tsl2772_led_currents[i][0] != 0; i++) {
+		if (tmp == tsl2772_led_currents[i][0]) {
+			chip->settings.prox_power = tsl2772_led_currents[i][1];
+			return 0;
+		}
+	}
+
+	dev_err(&chip->client->dev, "Invalid value %d for led-max-microamp\n",
+		tmp);
+
+	return -EINVAL;
+
+}
+
+static int tsl2772_read_prox_diodes(struct tsl2772_chip *chip)
+{
+	struct device_node *of_node = chip->client->dev.of_node;
+	int i, ret, num_leds, prox_diode_mask;
+	u32 leds[TSL2772_MAX_PROX_LEDS];
+
+	ret = of_property_count_u32_elems(of_node, "amstaos,proximity-diodes");
+	if (ret < 0)
+		return ret;
+
+	num_leds = ret;
+	if (num_leds > TSL2772_MAX_PROX_LEDS)
+		num_leds = TSL2772_MAX_PROX_LEDS;
+
+	ret = of_property_read_u32_array(of_node, "amstaos,proximity-diodes",
+					 leds, num_leds);
+	if (ret < 0) {
+		dev_err(&chip->client->dev,
+			"Invalid value for amstaos,proximity-diodes: %d.\n",
+			ret);
+		return ret;
+	}
+
+	prox_diode_mask = 0;
+	for (i = 0; i < num_leds; i++) {
+		if (leds[i] == 0)
+			prox_diode_mask |= TSL2772_DIODE0;
+		else if (leds[i] == 1)
+			prox_diode_mask |= TSL2772_DIODE1;
+		else {
+			dev_err(&chip->client->dev,
+				"Invalid value %d in amstaos,proximity-diodes.\n",
+				leds[i]);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static void tsl2772_parse_dt(struct tsl2772_chip *chip)
+{
+	tsl2772_read_prox_led_current(chip);
+	tsl2772_read_prox_diodes(chip);
+}
+
 /**
  * tsl2772_defaults() - Populates the device nominal operating parameters
  *                      with those provided by a 'platform' data struct or
@@ -541,6 +620,8 @@ static void tsl2772_defaults(struct tsl2772_chip *chip)
 		memcpy(chip->tsl2772_device_lux,
 		       tsl2772_default_lux_table_group[chip->id],
 		       TSL2772_DEFAULT_TABLE_BYTES);
+
+	tsl2772_parse_dt(chip);
 }
 
 /**
-- 
2.17.1


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

* [PATCH v3 4/9] dt-bindings: iio: tsl2772: add new bindings
  2018-08-03  0:18 [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead) Brian Masney
                   ` (2 preceding siblings ...)
  2018-08-03  0:18 ` [PATCH v3 3/9] iio: tsl2772: add support for reading proximity led settings from device tree Brian Masney
@ 2018-08-03  0:18 ` Brian Masney
  2018-08-03 21:48   ` Jonathan Cameron
  2018-08-03  0:18 ` [PATCH v3 5/9] iio: tsl2772: add support for regulator framework Brian Masney
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Brian Masney @ 2018-08-03  0:18 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc
  Cc: jonathan, jmaneyrol, knaack.h, lars, pmeerw, mkelly,
	fischerdouglasc, bshah, ctatlor97

This patch adds the new properties amstaos,proximity-diodes and
led-max-microamp to the tsl2772 driver. This patch also removes the
driver from the trivial-devices.txt.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
I got a Reviewed-by: Rob Herring <robh@kernel.org> on my last series but
didn't include it due to the new file tsl2772.txt in this patch. Device
tree bindings need to be complete.

 .../devicetree/bindings/iio/light/tsl2772.txt | 37 +++++++++++++++++++
 .../devicetree/bindings/trivial-devices.txt   | 10 -----
 2 files changed, 37 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/light/tsl2772.txt

diff --git a/Documentation/devicetree/bindings/iio/light/tsl2772.txt b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
new file mode 100644
index 000000000000..6f33169344f2
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
@@ -0,0 +1,37 @@
+* AMS/TAOS ALS and proximity sensor
+
+Required properties:
+
+  - compatible: Should be one of
+		"amstaos,tsl2571"
+		"amstaos,tsl2671"
+		"amstaos,tmd2671"
+		"amstaos,tsl2771"
+		"amstaos,tmd2771"
+		"amstaos,tsl2572"
+		"amstaos,tsl2672"
+		"amstaos,tmd2672"
+		"amstaos,tsl2772"
+		"amstaos,tmd2772"
+  - reg: the I2C address of the device
+
+Optional properties:
+
+  - amstaos,proximity-diodes - proximity diodes to enable. <0>, <1>, or <0 1>
+                               are the only valid values.
+  - led-max-microamp - current for the proximity LED. Must be 100000, 50000,
+                       25000, or 13000.
+  - interrupts: the sole interrupt generated by the device
+
+  Refer to interrupt-controller/interrupts.txt for generic interrupt client
+  node bindings.
+
+Example:
+
+tsl2772@39 {
+	compatible = "amstaos,tsl2772";
+	reg = <0x39>;
+	interrupts-extended = <&msmgpio 61 IRQ_TYPE_EDGE_FALLING>;
+	amstaos,proximity-diodes = <0>;
+	led-max-microamp = <100000>;
+};
diff --git a/Documentation/devicetree/bindings/trivial-devices.txt b/Documentation/devicetree/bindings/trivial-devices.txt
index 763a2808a95c..a977ccef7230 100644
--- a/Documentation/devicetree/bindings/trivial-devices.txt
+++ b/Documentation/devicetree/bindings/trivial-devices.txt
@@ -21,16 +21,6 @@ adi,adt7490		+/-1C TDM Extended Temp Range I.C
 adi,adxl345		Three-Axis Digital Accelerometer
 adi,adxl346		Three-Axis Digital Accelerometer (backward-compatibility value "adi,adxl345" must be listed too)
 ams,iaq-core		AMS iAQ-Core VOC Sensor
-amstaos,tsl2571		AMS/TAOS ALS and proximity sensor
-amstaos,tsl2671		AMS/TAOS ALS and proximity sensor
-amstaos,tmd2671		AMS/TAOS ALS and proximity sensor
-amstaos,tsl2771		AMS/TAOS ALS and proximity sensor
-amstaos,tmd2771		AMS/TAOS ALS and proximity sensor
-amstaos,tsl2572		AMS/TAOS ALS and proximity sensor
-amstaos,tsl2672		AMS/TAOS ALS and proximity sensor
-amstaos,tmd2672		AMS/TAOS ALS and proximity sensor
-amstaos,tsl2772		AMS/TAOS ALS and proximity sensor
-amstaos,tmd2772		AMS/TAOS ALS and proximity sensor
 at,24c08		i2c serial eeprom  (24cxx)
 atmel,at97sc3204t	i2c trusted platform module (TPM)
 capella,cm32181		CM32181: Ambient Light Sensor
-- 
2.17.1


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

* [PATCH v3 5/9] iio: tsl2772: add support for regulator framework
  2018-08-03  0:18 [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead) Brian Masney
                   ` (3 preceding siblings ...)
  2018-08-03  0:18 ` [PATCH v3 4/9] dt-bindings: iio: tsl2772: add new bindings Brian Masney
@ 2018-08-03  0:18 ` Brian Masney
  2018-08-03 21:50   ` Jonathan Cameron
  2018-08-03  0:18 ` [PATCH v3 6/9] dt-bindings: iio: tsl2772: add bindings " Brian Masney
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Brian Masney @ 2018-08-03  0:18 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc
  Cc: jonathan, jmaneyrol, knaack.h, lars, pmeerw, mkelly,
	fischerdouglasc, bshah, ctatlor97

This patch adds support for the regulator framework to the tsl2772
driver. Driver was tested using a LG Nexus 5 (hammerhead) phone with
the two regulators and on a Raspberry Pi 2 without any regulators
controlling the power to the sensor.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/iio/light/tsl2772.c | 95 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 94 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
index ae00edf0d87e..4a11bf77a4d0 100644
--- a/drivers/iio/light/tsl2772.c
+++ b/drivers/iio/light/tsl2772.c
@@ -20,6 +20,7 @@
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 #include <linux/platform_data/tsl2772.h>
+#include <linux/regulator/consumer.h>
 
 /* Cal defs */
 #define PROX_STAT_CAL			0
@@ -109,6 +110,9 @@
 
 #define TSL2772_MAX_PROX_LEDS		2
 
+#define TSL2772_BOOT_MIN_SLEEP_TIME	10000
+#define TSL2772_BOOT_MAX_SLEEP_TIME	28000
+
 /* Device family members */
 enum {
 	tsl2571,
@@ -156,6 +160,8 @@ struct tsl2772_chip {
 	struct mutex prox_mutex;
 	struct mutex als_mutex;
 	struct i2c_client *client;
+	struct regulator *vdd_supply;
+	struct regulator *vddio_supply;
 	u16 prox_data;
 	struct tsl2772_als_info als_cur_info;
 	struct tsl2772_settings settings;
@@ -676,6 +682,52 @@ static int tsl2772_als_calibrate(struct iio_dev *indio_dev)
 	return ret;
 }
 
+static void tsl2772_disable_regulators_action(void *_data)
+{
+	struct tsl2772_chip *chip = _data;
+
+	regulator_disable(chip->vdd_supply);
+	regulator_disable(chip->vddio_supply);
+}
+
+static int tsl2772_enable_regulator(struct tsl2772_chip *chip,
+				    struct regulator *regulator)
+{
+	int ret;
+
+	ret = regulator_enable(regulator);
+	if (ret < 0) {
+		dev_err(&chip->client->dev, "Failed to enable regulator: %d\n",
+			ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static struct regulator *tsl2772_get_regulator(struct tsl2772_chip *chip,
+					       char *name)
+{
+	struct regulator *regulator;
+	int ret;
+
+	regulator = devm_regulator_get(&chip->client->dev, name);
+	if (IS_ERR(regulator)) {
+		if (PTR_ERR(regulator) != -EPROBE_DEFER)
+			dev_err(&chip->client->dev,
+				"Failed to get %s regulator %d\n",
+				name, (int)PTR_ERR(regulator));
+
+		return regulator;
+	}
+
+	ret = tsl2772_enable_regulator(chip, regulator);
+	if (ret < 0)
+		return ERR_PTR(ret);
+
+	return regulator;
+}
+
 static int tsl2772_chip_on(struct iio_dev *indio_dev)
 {
 	struct tsl2772_chip *chip = iio_priv(indio_dev);
@@ -1733,6 +1785,27 @@ static int tsl2772_probe(struct i2c_client *clientp,
 	chip->client = clientp;
 	i2c_set_clientdata(clientp, indio_dev);
 
+	chip->vddio_supply = tsl2772_get_regulator(chip, "vddio");
+	if (IS_ERR(chip->vddio_supply))
+		return PTR_ERR(chip->vddio_supply);
+
+	chip->vdd_supply = tsl2772_get_regulator(chip, "vdd");
+	if (IS_ERR(chip->vdd_supply)) {
+		regulator_disable(chip->vddio_supply);
+		return PTR_ERR(chip->vdd_supply);
+	}
+
+	ret = devm_add_action(&clientp->dev, tsl2772_disable_regulators_action,
+			      chip);
+	if (ret < 0) {
+		tsl2772_disable_regulators_action(chip);
+		dev_err(&clientp->dev, "Failed to setup regulator cleanup action %d\n",
+			ret);
+		return ret;
+	}
+
+	usleep_range(TSL2772_BOOT_MIN_SLEEP_TIME, TSL2772_BOOT_MAX_SLEEP_TIME);
+
 	ret = i2c_smbus_read_byte_data(chip->client,
 				       TSL2772_CMD_REG | TSL2772_CHIPID);
 	if (ret < 0)
@@ -1806,13 +1879,33 @@ static int tsl2772_probe(struct i2c_client *clientp,
 static int tsl2772_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
+	int ret;
 
-	return tsl2772_chip_off(indio_dev);
+	ret = tsl2772_chip_off(indio_dev);
+	regulator_disable(chip->vdd_supply);
+	regulator_disable(chip->vddio_supply);
+
+	return ret;
 }
 
 static int tsl2772_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct tsl2772_chip *chip = iio_priv(indio_dev);
+	int ret;
+
+	ret = tsl2772_enable_regulator(chip, chip->vddio_supply);
+	if (ret < 0)
+		return ret;
+
+	ret = tsl2772_enable_regulator(chip, chip->vdd_supply);
+	if (ret < 0) {
+		regulator_disable(chip->vddio_supply);
+		return ret;
+	}
+
+	usleep_range(TSL2772_BOOT_MIN_SLEEP_TIME, TSL2772_BOOT_MAX_SLEEP_TIME);
 
 	return tsl2772_chip_on(indio_dev);
 }
-- 
2.17.1


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

* [PATCH v3 6/9] dt-bindings: iio: tsl2772: add bindings for regulator framework
  2018-08-03  0:18 [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead) Brian Masney
                   ` (4 preceding siblings ...)
  2018-08-03  0:18 ` [PATCH v3 5/9] iio: tsl2772: add support for regulator framework Brian Masney
@ 2018-08-03  0:18 ` Brian Masney
  2018-08-03 21:51   ` Jonathan Cameron
  2018-08-03  0:18 ` [PATCH v3 7/9] iio: tsl2772: add support for avago,apds9930 Brian Masney
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 26+ messages in thread
From: Brian Masney @ 2018-08-03  0:18 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc
  Cc: jonathan, jmaneyrol, knaack.h, lars, pmeerw, mkelly,
	fischerdouglasc, bshah, ctatlor97

This patch adds device tree bindings to the tsl2772 driver for the
regulator framework.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 Documentation/devicetree/bindings/iio/light/tsl2772.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/light/tsl2772.txt b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
index 6f33169344f2..4e7d98627cbf 100644
--- a/Documentation/devicetree/bindings/iio/light/tsl2772.txt
+++ b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
@@ -21,6 +21,8 @@ Optional properties:
                                are the only valid values.
   - led-max-microamp - current for the proximity LED. Must be 100000, 50000,
                        25000, or 13000.
+  - vdd-supply: phandle to the regulator that provides power to the sensor.
+  - vddio-supply: phandle to the regulator that provides power to the bus.
   - interrupts: the sole interrupt generated by the device
 
   Refer to interrupt-controller/interrupts.txt for generic interrupt client
@@ -32,6 +34,8 @@ tsl2772@39 {
 	compatible = "amstaos,tsl2772";
 	reg = <0x39>;
 	interrupts-extended = <&msmgpio 61 IRQ_TYPE_EDGE_FALLING>;
+	vdd-supply = <&pm8941_l17>;
+	vddio-supply = <&pm8941_lvs1>;
 	amstaos,proximity-diodes = <0>;
 	led-max-microamp = <100000>;
 };
-- 
2.17.1


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

* [PATCH v3 7/9] iio: tsl2772: add support for avago,apds9930
  2018-08-03  0:18 [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead) Brian Masney
                   ` (5 preceding siblings ...)
  2018-08-03  0:18 ` [PATCH v3 6/9] dt-bindings: iio: tsl2772: add bindings " Brian Masney
@ 2018-08-03  0:18 ` Brian Masney
  2018-08-03 21:53   ` Jonathan Cameron
  2018-08-03  0:18 ` [PATCH v3 8/9] dt-bindings: iio: tsl2772: add binding " Brian Masney
  2018-08-03  0:19 ` [PATCH v3 9/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for ALS / proximity Brian Masney
  8 siblings, 1 reply; 26+ messages in thread
From: Brian Masney @ 2018-08-03  0:18 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc
  Cc: jonathan, jmaneyrol, knaack.h, lars, pmeerw, mkelly,
	fischerdouglasc, bshah, ctatlor97

The Avago APDS9930 has the same register set as the TAOS/AMS TSL2772 so
this patch adds the correct bindings and the appropriate LUX table
values derived from the values in the datasheet. Driver was tested on a
LG Nexus 5 (hammerhead) phone.

avago,apds9930 datasheet:
https://www.mouser.com/datasheet/2/678/avago_AV02-3190EN_DS_APDS-9930_2014-03-25[1]-1217273.pdf

tsl2772 datasheet:
https://ams.com/eng/content/download/291503/1066377/file/TSL2772_DS000181_2-00.pdf

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/iio/light/tsl2772.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
index 4a11bf77a4d0..83cece921843 100644
--- a/drivers/iio/light/tsl2772.c
+++ b/drivers/iio/light/tsl2772.c
@@ -124,7 +124,8 @@ enum {
 	tsl2672,
 	tmd2672,
 	tsl2772,
-	tmd2772
+	tmd2772,
+	apds9930,
 };
 
 enum {
@@ -213,6 +214,12 @@ static const struct tsl2772_lux tmd2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
 	{     0,      0 },
 };
 
+static const struct tsl2772_lux apds9930_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
+	{ 52000,  96824 },
+	{ 38792,  67132 },
+	{     0,      0 },
+};
+
 static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = {
 	[tsl2571] = tsl2x71_lux_table,
 	[tsl2671] = tsl2x71_lux_table,
@@ -224,6 +231,7 @@ static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = {
 	[tmd2672] = tmd2x72_lux_table,
 	[tsl2772] = tsl2x72_lux_table,
 	[tmd2772] = tmd2x72_lux_table,
+	[apds9930] = apds9930_lux_table,
 };
 
 static const struct tsl2772_settings tsl2772_default_settings = {
@@ -274,6 +282,7 @@ static const int tsl2772_int_time_avail[][6] = {
 	[tmd2672] = { 0, 2730, 0, 2730, 0, 699000 },
 	[tsl2772] = { 0, 2730, 0, 2730, 0, 699000 },
 	[tmd2772] = { 0, 2730, 0, 2730, 0, 699000 },
+	[apds9930] = { 0, 2730, 0, 2730, 0, 699000 },
 };
 
 static int tsl2772_int_calibscale_avail[] = { 1, 8, 16, 120 };
@@ -299,7 +308,8 @@ static const u8 device_channel_config[] = {
 	[tsl2672] = PRX2,
 	[tmd2672] = PRX2,
 	[tsl2772] = ALSPRX2,
-	[tmd2772] = ALSPRX2
+	[tmd2772] = ALSPRX2,
+	[apds9930] = ALSPRX2,
 };
 
 static int tsl2772_read_status(struct tsl2772_chip *chip)
@@ -513,6 +523,7 @@ static int tsl2772_get_prox(struct iio_dev *indio_dev)
 	case tmd2672:
 	case tsl2772:
 	case tmd2772:
+	case apds9930:
 		if (!(ret & TSL2772_STA_PRX_VALID)) {
 			ret = -EINVAL;
 			goto prox_poll_err;
@@ -1393,6 +1404,7 @@ static int tsl2772_device_id_verif(int id, int target)
 	case tmd2672:
 	case tsl2772:
 	case tmd2772:
+	case apds9930:
 		return (id & 0xf0) == SWORDFISH_ID;
 	}
 
@@ -1932,6 +1944,7 @@ static const struct i2c_device_id tsl2772_idtable[] = {
 	{ "tmd2672", tmd2672 },
 	{ "tsl2772", tsl2772 },
 	{ "tmd2772", tmd2772 },
+	{ "apds9930", apds9930},
 	{}
 };
 
@@ -1948,6 +1961,7 @@ static const struct of_device_id tsl2772_of_match[] = {
 	{ .compatible = "amstaos,tmd2672" },
 	{ .compatible = "amstaos,tsl2772" },
 	{ .compatible = "amstaos,tmd2772" },
+	{ .compatible = "avago,apds9930" },
 	{}
 };
 MODULE_DEVICE_TABLE(of, tsl2772_of_match);
-- 
2.17.1


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

* [PATCH v3 8/9] dt-bindings: iio: tsl2772: add binding for avago,apds9930
  2018-08-03  0:18 [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead) Brian Masney
                   ` (6 preceding siblings ...)
  2018-08-03  0:18 ` [PATCH v3 7/9] iio: tsl2772: add support for avago,apds9930 Brian Masney
@ 2018-08-03  0:18 ` Brian Masney
  2018-08-03 21:54   ` Jonathan Cameron
  2018-08-07 17:21   ` Rob Herring
  2018-08-03  0:19 ` [PATCH v3 9/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for ALS / proximity Brian Masney
  8 siblings, 2 replies; 26+ messages in thread
From: Brian Masney @ 2018-08-03  0:18 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc
  Cc: jonathan, jmaneyrol, knaack.h, lars, pmeerw, mkelly,
	fischerdouglasc, bshah, ctatlor97

This patch adds avago,apds9930 to the tsl2772 bindings.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 Documentation/devicetree/bindings/iio/light/tsl2772.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/iio/light/tsl2772.txt b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
index 4e7d98627cbf..1c5e6f17a1df 100644
--- a/Documentation/devicetree/bindings/iio/light/tsl2772.txt
+++ b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
@@ -13,6 +13,7 @@ Required properties:
 		"amstaos,tmd2672"
 		"amstaos,tsl2772"
 		"amstaos,tmd2772"
+		"avago,apds9930"
   - reg: the I2C address of the device
 
 Optional properties:
-- 
2.17.1


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

* [PATCH v3 9/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for ALS / proximity
  2018-08-03  0:18 [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead) Brian Masney
                   ` (7 preceding siblings ...)
  2018-08-03  0:18 ` [PATCH v3 8/9] dt-bindings: iio: tsl2772: add binding " Brian Masney
@ 2018-08-03  0:19 ` Brian Masney
  2018-08-18 17:09   ` Jonathan Cameron
  8 siblings, 1 reply; 26+ messages in thread
From: Brian Masney @ 2018-08-03  0:19 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc
  Cc: jonathan, jmaneyrol, knaack.h, lars, pmeerw, mkelly,
	fischerdouglasc, bshah, ctatlor97

This patch adds device tree bindings for the tsl2772 ALS / proximity
sensor for the LG Nexus 5 (hammerhead) phone.

Signed-off-by: Brian Masney <masneyb@onstation.org>
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
---
 .../qcom-msm8974-lge-nexus5-hammerhead.dts    | 27 +++++++++++++++++++
 arch/arm/boot/dts/qcom-msm8974.dtsi           | 11 ++++++++
 2 files changed, 38 insertions(+)

diff --git a/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts b/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
index 928affae1885..ed8f064d0895 100644
--- a/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
+++ b/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
@@ -242,6 +242,15 @@
 			};
 		};
 
+		i2c3_pins: i2c3 {
+			mux {
+				pins = "gpio10", "gpio11";
+				function = "blsp_i2c3";
+				drive-strength = <2>;
+				bias-disable;
+			};
+		};
+
 		i2c12_pins: i2c12 {
 			mux {
 				pins = "gpio87", "gpio88";
@@ -333,6 +342,24 @@
 			};
 		};
 	};
+
+	i2c@f9925000 {
+		status = "ok";
+		pinctrl-names = "default";
+		pinctrl-0 = <&i2c3_pins>;
+		clock-frequency = <100000>;
+		qcom,src-freq = <50000000>;
+
+		avago_apds993@39 {
+			compatible = "avago,apds9930";
+			reg = <0x39>;
+			interrupts-extended = <&msmgpio 61 IRQ_TYPE_EDGE_FALLING>;
+			vdd-supply = <&pm8941_l17>;
+			vddio-supply = <&pm8941_lvs1>;
+			led-max-microamp = <100000>;
+			amstaos,proximity-diodes = <0>;
+		};
+	};
 };
 
 &spmi_bus {
diff --git a/arch/arm/boot/dts/qcom-msm8974.dtsi b/arch/arm/boot/dts/qcom-msm8974.dtsi
index cebb6ae9143a..6dcf2bee66fb 100644
--- a/arch/arm/boot/dts/qcom-msm8974.dtsi
+++ b/arch/arm/boot/dts/qcom-msm8974.dtsi
@@ -713,6 +713,17 @@
 			#size-cells = <0>;
 		};
 
+		blsp_i2c3: i2c@f9925000 {
+			status = "disabled";
+			compatible = "qcom,i2c-qup-v2.1.1";
+			reg = <0xf9925000 0x1000>;
+			interrupts = <0 97 IRQ_TYPE_NONE>;
+			clocks = <&gcc GCC_BLSP1_QUP3_I2C_APPS_CLK>, <&gcc GCC_BLSP1_AHB_CLK>;
+			clock-names = "core", "iface";
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
 		blsp_i2c8: i2c@f9964000 {
 			status = "disabled";
 			compatible = "qcom,i2c-qup-v2.1.1";
-- 
2.17.1


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

* Re: [PATCH v3 1/9] iio: imu: mpu6050: add support for regulator framework
  2018-08-03  0:18 ` [PATCH v3 1/9] iio: imu: mpu6050: add support for regulator framework Brian Masney
@ 2018-08-03 21:44   ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-03 21:44 UTC (permalink / raw)
  To: Brian Masney
  Cc: robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Thu,  2 Aug 2018 20:18:52 -0400
Brian Masney <masneyb@onstation.org> wrote:

> This patch adds support for the regulator framework to the mpu6050
> driver.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
> Signed-off-by: Jonathan Marek <jonathan@marek.ca>
> Acked-by: Rob Herring <robh@kernel.org>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
> Changes since v2:
> - Dropped regulator_enabled value since it is not needed.
> 
> Changes since v1:
> - Use devm_regulator_get() instead of devm_regulator_get_optional()
> - Use devm_add_action() for cleaning up the regulator.
> - Correct ordering of resume code.
> - Add regulator_enabled flag to ensure regulator is not disabled twice,
>   specifically the case where the device is suspended and then the
>   driver is removed.
> 
> Original extra changelog from v1:
> 
> This is a variation of Jonathan Marek's patch from postmarketOS
> https://gitlab.com/postmarketOS/linux-postmarketos/commit/b8ad1ec1859c8bbcbce94944b3f4dd68f8f9fc37
> with the following changes:
> 
> - Stripped out 6515 variant code.
> - Add the regulator to the mpu core instead of only the i2c variant.
> - Add error handling.
> - Release the regulator on suspend, device remove, etc.
> - Device tree documentation.
> 
>  .../bindings/iio/imu/inv_mpu6050.txt          |  1 +
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c    | 62 +++++++++++++++++++
>  drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h     |  2 +
>  3 files changed, 65 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
> index b2f27da847b8..6ab9a9d196b0 100644
> --- a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
> +++ b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
> @@ -20,6 +20,7 @@ Required properties:
>    bindings.
>  
>  Optional properties:
> + - vddio-supply: regulator phandle for VDDIO supply
>   - mount-matrix: an optional 3x3 mounting rotation matrix
>   - i2c-gate node.  These devices also support an auxiliary i2c bus.  This is
>     simple enough to be described using the i2c-gate binding. See
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index d80ef468508a..1e428c196a82 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -23,6 +23,7 @@
>  #include <linux/iio/iio.h>
>  #include <linux/acpi.h>
>  #include <linux/platform_device.h>
> +#include <linux/regulator/consumer.h>
>  #include "inv_mpu_iio.h"
>  
>  /*
> @@ -926,6 +927,39 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st)
>  	return result;
>  }
>  
> +static int inv_mpu_core_enable_regulator(struct inv_mpu6050_state *st)
> +{
> +	int result;
> +
> +	result = regulator_enable(st->vddio_supply);
> +	if (result) {
> +		dev_err(regmap_get_device(st->map),
> +			"Failed to enable regulator: %d\n", result);
> +	} else {
> +		/* Give the device a little bit of time to start up. */
> +		usleep_range(35000, 70000);
> +	}
> +
> +	return result;
> +}
> +
> +static int inv_mpu_core_disable_regulator(struct inv_mpu6050_state *st)
> +{
> +	int result;
> +
> +	result = regulator_disable(st->vddio_supply);
> +	if (result)
> +		dev_err(regmap_get_device(st->map),
> +			"Failed to disable regulator: %d\n", result);
> +
> +	return result;
> +}
> +
> +static void inv_mpu_core_disable_regulator_action(void *_data)
> +{
> +	inv_mpu_core_disable_regulator(_data);
> +}
> +
>  int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
>  		int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type)
>  {
> @@ -992,6 +1026,28 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
>  		return -EINVAL;
>  	}
>  
> +	st->vddio_supply = devm_regulator_get(dev, "vddio");
> +	if (IS_ERR(st->vddio_supply)) {
> +		if (PTR_ERR(st->vddio_supply) != -EPROBE_DEFER)
> +			dev_err(dev, "Failed to get vddio regulator %d\n",
> +				(int)PTR_ERR(st->vddio_supply));
> +
> +		return PTR_ERR(st->vddio_supply);
> +	}
> +
> +	result = inv_mpu_core_enable_regulator(st);
> +	if (result)
> +		return result;
> +
> +	result = devm_add_action(dev, inv_mpu_core_disable_regulator_action,
> +				 st);
> +	if (result) {
> +		inv_mpu_core_disable_regulator_action(st);
> +		dev_err(dev, "Failed to setup regulator cleanup action %d\n",
> +			result);
> +		return result;
> +	}
> +
>  	/* power is turned on inside check chip type*/
>  	result = inv_check_and_setup_chip(st);
>  	if (result)
> @@ -1051,7 +1107,12 @@ static int inv_mpu_resume(struct device *dev)
>  	int result;
>  
>  	mutex_lock(&st->lock);
> +	result = inv_mpu_core_enable_regulator(st);
> +	if (result)
> +		goto out_unlock;
> +
>  	result = inv_mpu6050_set_power_itg(st, true);
> +out_unlock:
>  	mutex_unlock(&st->lock);
>  
>  	return result;
> @@ -1064,6 +1125,7 @@ static int inv_mpu_suspend(struct device *dev)
>  
>  	mutex_lock(&st->lock);
>  	result = inv_mpu6050_set_power_itg(st, false);
> +	inv_mpu_core_disable_regulator(st);
>  	mutex_unlock(&st->lock);
>  
>  	return result;
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> index e69a59659dbc..6bcc11fc1b88 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -129,6 +129,7 @@ struct inv_mpu6050_hw {
>   *  @chip_period:	chip internal period estimation (~1kHz).
>   *  @it_timestamp:	timestamp from previous interrupt.
>   *  @data_timestamp:	timestamp for next data sample.
> + *  @vddio_supply	voltage regulator for the chip.
>   */
>  struct inv_mpu6050_state {
>  	struct mutex lock;
> @@ -149,6 +150,7 @@ struct inv_mpu6050_state {
>  	s64 chip_period;
>  	s64 it_timestamp;
>  	s64 data_timestamp;
> +	struct regulator *vddio_supply;
>  };
>  
>  /*register and associated bit definition*/


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

* Re: [PATCH v3 2/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for mpu6515
  2018-08-03  0:18 ` [PATCH v3 2/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for mpu6515 Brian Masney
@ 2018-08-03 21:46   ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-03 21:46 UTC (permalink / raw)
  To: Brian Masney
  Cc: robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Thu,  2 Aug 2018 20:18:53 -0400
Brian Masney <masneyb@onstation.org> wrote:

> This patch adds device tree bindings for the mpu6515 to the LG Nexus 5
> (hammerhead) phone. Confirmed that the gyroscope / accelerometer
> (mpu6515), magnetometer (ak8963), and temperature / pressure (bmp280)
> sensors are available on the phone.
> 
> Interrupts are not working properly on the ak8963 magnetometer so they
> are currently not configured.
> 
> The bmp280 retuns temperature/pressure measurement skipped errors but
> will reliably work if I run:
> 
>     echo 1 > in_pressure_oversampling_ratio
>     echo 1 > in_temp_oversampling_ratio
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
> Signed-off-by: Jonathan Marek <jonathan@marek.ca>
I've queued up the regulator patch for IIO but it won't make the coming
merge window.  There is no dependence between this and that patch, but
I would assume the hardware won't work until both are present.

Jonathan

> ---
> I'll send follow up patch(es) once I investigate why the skipped errors
> are occurring with the bmp280 with the default oversampling ratios.
> 
>  .../qcom-msm8974-lge-nexus5-hammerhead.dts    | 56 +++++++++++++++++++
>  arch/arm/boot/dts/qcom-msm8974.dtsi           | 11 ++++
>  2 files changed, 67 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts b/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
> index c2dc9d09484a..928affae1885 100644
> --- a/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
> +++ b/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
> @@ -241,6 +241,24 @@
>  				bias-pull-up;
>  			};
>  		};
> +
> +		i2c12_pins: i2c12 {
> +			mux {
> +				pins = "gpio87", "gpio88";
> +				function = "blsp_i2c12";
> +				drive-strength = <2>;
> +				bias-disable;
> +			};
> +		};
> +
> +		mpu6515_pin: mpu6515 {
> +			irq {
> +				pins = "gpio73";
> +				function = "gpio";
> +				bias-disable;
> +				input-enable;
> +			};
> +		};
>  	};
>  
>  	sdhci@f9824900 {
> @@ -277,6 +295,44 @@
>  			linux,code = <KEY_VOLUMEDOWN>;
>  		};
>  	};
> +
> +	i2c@f9968000 {
> +		status = "ok";
> +		pinctrl-names = "default";
> +		pinctrl-0 = <&i2c12_pins>;
> +		clock-frequency = <100000>;
> +		qcom,src-freq = <50000000>;
> +
> +		mpu6515@68 {
> +			compatible = "invensense,mpu6515";
> +			reg = <0x68>;
> +			interrupts-extended = <&msmgpio 73 IRQ_TYPE_EDGE_FALLING>;
> +			vddio-supply = <&pm8941_lvs1>;
> +
> +			pinctrl-names = "default";
> +			pinctrl-0 = <&mpu6515_pin>;
> +
> +			i2c-gate {
> +				#address-cells = <1>;
> +				#size-cells = <0>;
> +				ak8963@f {
> +					compatible = "asahi-kasei,ak8963";
> +					reg = <0x0f>;
> +					// Currently only works in polling mode.
> +					// gpios = <&msmgpio 61 0>;
> +					vid-supply = <&pm8941_lvs1>;
> +					vdd-supply = <&pm8941_l17>;
> +				};
> +
> +				bmp280@76 {
> +					compatible = "bosch,bmp280";
> +					reg = <0x76>;
> +					vdda-supply = <&pm8941_lvs1>;
> +					vddd-supply = <&pm8941_l17>;
> +				};
> +			};
> +		};
> +	};
>  };
>  
>  &spmi_bus {
> diff --git a/arch/arm/boot/dts/qcom-msm8974.dtsi b/arch/arm/boot/dts/qcom-msm8974.dtsi
> index d9019a49b292..cebb6ae9143a 100644
> --- a/arch/arm/boot/dts/qcom-msm8974.dtsi
> +++ b/arch/arm/boot/dts/qcom-msm8974.dtsi
> @@ -737,6 +737,17 @@
>  			dma-names = "tx", "rx";
>  		};
>  
> +		blsp_i2c12: i2c@f9968000 {
> +			status = "disabled";
> +			compatible = "qcom,i2c-qup-v2.1.1";
> +			reg = <0xf9968000 0x1000>;
> +			interrupts = <0 106 IRQ_TYPE_NONE>;
> +			clocks = <&gcc GCC_BLSP2_QUP6_I2C_APPS_CLK>, <&gcc GCC_BLSP2_AHB_CLK>;
> +			clock-names = "core", "iface";
> +			#address-cells = <1>;
> +			#size-cells = <0>;
> +		};
> +
>  		spmi_bus: spmi@fc4cf000 {
>  			compatible = "qcom,spmi-pmic-arb";
>  			reg-names = "core", "intr", "cnfg";


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

* Re: [PATCH v3 4/9] dt-bindings: iio: tsl2772: add new bindings
  2018-08-03  0:18 ` [PATCH v3 4/9] dt-bindings: iio: tsl2772: add new bindings Brian Masney
@ 2018-08-03 21:48   ` Jonathan Cameron
  2018-08-07 16:54     ` Rob Herring
  0 siblings, 1 reply; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-03 21:48 UTC (permalink / raw)
  To: Brian Masney
  Cc: robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Thu,  2 Aug 2018 20:18:55 -0400
Brian Masney <masneyb@onstation.org> wrote:

> This patch adds the new properties amstaos,proximity-diodes and
> led-max-microamp to the tsl2772 driver. This patch also removes the
> driver from the trivial-devices.txt.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
> ---
This and the implementation look fine to me, but I'll leave them for
now to give Rob time to take a look if he wants to.

Thanks,

Jonathan

> I got a Reviewed-by: Rob Herring <robh@kernel.org> on my last series but
> didn't include it due to the new file tsl2772.txt in this patch. Device
> tree bindings need to be complete.
> 
>  .../devicetree/bindings/iio/light/tsl2772.txt | 37 +++++++++++++++++++
>  .../devicetree/bindings/trivial-devices.txt   | 10 -----
>  2 files changed, 37 insertions(+), 10 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/iio/light/tsl2772.txt
> 
> diff --git a/Documentation/devicetree/bindings/iio/light/tsl2772.txt b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> new file mode 100644
> index 000000000000..6f33169344f2
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> @@ -0,0 +1,37 @@
> +* AMS/TAOS ALS and proximity sensor
> +
> +Required properties:
> +
> +  - compatible: Should be one of
> +		"amstaos,tsl2571"
> +		"amstaos,tsl2671"
> +		"amstaos,tmd2671"
> +		"amstaos,tsl2771"
> +		"amstaos,tmd2771"
> +		"amstaos,tsl2572"
> +		"amstaos,tsl2672"
> +		"amstaos,tmd2672"
> +		"amstaos,tsl2772"
> +		"amstaos,tmd2772"
> +  - reg: the I2C address of the device
> +
> +Optional properties:
> +
> +  - amstaos,proximity-diodes - proximity diodes to enable. <0>, <1>, or <0 1>
> +                               are the only valid values.
> +  - led-max-microamp - current for the proximity LED. Must be 100000, 50000,
> +                       25000, or 13000.
> +  - interrupts: the sole interrupt generated by the device
> +
> +  Refer to interrupt-controller/interrupts.txt for generic interrupt client
> +  node bindings.
> +
> +Example:
> +
> +tsl2772@39 {
> +	compatible = "amstaos,tsl2772";
> +	reg = <0x39>;
> +	interrupts-extended = <&msmgpio 61 IRQ_TYPE_EDGE_FALLING>;
> +	amstaos,proximity-diodes = <0>;
> +	led-max-microamp = <100000>;
> +};
> diff --git a/Documentation/devicetree/bindings/trivial-devices.txt b/Documentation/devicetree/bindings/trivial-devices.txt
> index 763a2808a95c..a977ccef7230 100644
> --- a/Documentation/devicetree/bindings/trivial-devices.txt
> +++ b/Documentation/devicetree/bindings/trivial-devices.txt
> @@ -21,16 +21,6 @@ adi,adt7490		+/-1C TDM Extended Temp Range I.C
>  adi,adxl345		Three-Axis Digital Accelerometer
>  adi,adxl346		Three-Axis Digital Accelerometer (backward-compatibility value "adi,adxl345" must be listed too)
>  ams,iaq-core		AMS iAQ-Core VOC Sensor
> -amstaos,tsl2571		AMS/TAOS ALS and proximity sensor
> -amstaos,tsl2671		AMS/TAOS ALS and proximity sensor
> -amstaos,tmd2671		AMS/TAOS ALS and proximity sensor
> -amstaos,tsl2771		AMS/TAOS ALS and proximity sensor
> -amstaos,tmd2771		AMS/TAOS ALS and proximity sensor
> -amstaos,tsl2572		AMS/TAOS ALS and proximity sensor
> -amstaos,tsl2672		AMS/TAOS ALS and proximity sensor
> -amstaos,tmd2672		AMS/TAOS ALS and proximity sensor
> -amstaos,tsl2772		AMS/TAOS ALS and proximity sensor
> -amstaos,tmd2772		AMS/TAOS ALS and proximity sensor
>  at,24c08		i2c serial eeprom  (24cxx)
>  atmel,at97sc3204t	i2c trusted platform module (TPM)
>  capella,cm32181		CM32181: Ambient Light Sensor


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

* Re: [PATCH v3 5/9] iio: tsl2772: add support for regulator framework
  2018-08-03  0:18 ` [PATCH v3 5/9] iio: tsl2772: add support for regulator framework Brian Masney
@ 2018-08-03 21:50   ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-03 21:50 UTC (permalink / raw)
  To: Brian Masney
  Cc: robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Thu,  2 Aug 2018 20:18:56 -0400
Brian Masney <masneyb@onstation.org> wrote:

> This patch adds support for the regulator framework to the tsl2772
> driver. Driver was tested using a LG Nexus 5 (hammerhead) phone with
> the two regulators and on a Raspberry Pi 2 without any regulators
> controlling the power to the sensor.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
This looks fine, but will wait for the precursors.

Jonathan

> ---
>  drivers/iio/light/tsl2772.c | 95 ++++++++++++++++++++++++++++++++++++-
>  1 file changed, 94 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
> index ae00edf0d87e..4a11bf77a4d0 100644
> --- a/drivers/iio/light/tsl2772.c
> +++ b/drivers/iio/light/tsl2772.c
> @@ -20,6 +20,7 @@
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
>  #include <linux/platform_data/tsl2772.h>
> +#include <linux/regulator/consumer.h>
>  
>  /* Cal defs */
>  #define PROX_STAT_CAL			0
> @@ -109,6 +110,9 @@
>  
>  #define TSL2772_MAX_PROX_LEDS		2
>  
> +#define TSL2772_BOOT_MIN_SLEEP_TIME	10000
> +#define TSL2772_BOOT_MAX_SLEEP_TIME	28000
> +
>  /* Device family members */
>  enum {
>  	tsl2571,
> @@ -156,6 +160,8 @@ struct tsl2772_chip {
>  	struct mutex prox_mutex;
>  	struct mutex als_mutex;
>  	struct i2c_client *client;
> +	struct regulator *vdd_supply;
> +	struct regulator *vddio_supply;
>  	u16 prox_data;
>  	struct tsl2772_als_info als_cur_info;
>  	struct tsl2772_settings settings;
> @@ -676,6 +682,52 @@ static int tsl2772_als_calibrate(struct iio_dev *indio_dev)
>  	return ret;
>  }
>  
> +static void tsl2772_disable_regulators_action(void *_data)
> +{
> +	struct tsl2772_chip *chip = _data;
> +
> +	regulator_disable(chip->vdd_supply);
> +	regulator_disable(chip->vddio_supply);
> +}
> +
> +static int tsl2772_enable_regulator(struct tsl2772_chip *chip,
> +				    struct regulator *regulator)
> +{
> +	int ret;
> +
> +	ret = regulator_enable(regulator);
> +	if (ret < 0) {
> +		dev_err(&chip->client->dev, "Failed to enable regulator: %d\n",
> +			ret);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +static struct regulator *tsl2772_get_regulator(struct tsl2772_chip *chip,
> +					       char *name)
> +{
> +	struct regulator *regulator;
> +	int ret;
> +
> +	regulator = devm_regulator_get(&chip->client->dev, name);
> +	if (IS_ERR(regulator)) {
> +		if (PTR_ERR(regulator) != -EPROBE_DEFER)
> +			dev_err(&chip->client->dev,
> +				"Failed to get %s regulator %d\n",
> +				name, (int)PTR_ERR(regulator));
> +
> +		return regulator;
> +	}
> +
> +	ret = tsl2772_enable_regulator(chip, regulator);
> +	if (ret < 0)
> +		return ERR_PTR(ret);
> +
> +	return regulator;
> +}
> +
>  static int tsl2772_chip_on(struct iio_dev *indio_dev)
>  {
>  	struct tsl2772_chip *chip = iio_priv(indio_dev);
> @@ -1733,6 +1785,27 @@ static int tsl2772_probe(struct i2c_client *clientp,
>  	chip->client = clientp;
>  	i2c_set_clientdata(clientp, indio_dev);
>  
> +	chip->vddio_supply = tsl2772_get_regulator(chip, "vddio");
> +	if (IS_ERR(chip->vddio_supply))
> +		return PTR_ERR(chip->vddio_supply);
> +
> +	chip->vdd_supply = tsl2772_get_regulator(chip, "vdd");
> +	if (IS_ERR(chip->vdd_supply)) {
> +		regulator_disable(chip->vddio_supply);
> +		return PTR_ERR(chip->vdd_supply);
> +	}
> +
> +	ret = devm_add_action(&clientp->dev, tsl2772_disable_regulators_action,
> +			      chip);
> +	if (ret < 0) {
> +		tsl2772_disable_regulators_action(chip);
> +		dev_err(&clientp->dev, "Failed to setup regulator cleanup action %d\n",
> +			ret);
> +		return ret;
> +	}
> +
> +	usleep_range(TSL2772_BOOT_MIN_SLEEP_TIME, TSL2772_BOOT_MAX_SLEEP_TIME);
> +
>  	ret = i2c_smbus_read_byte_data(chip->client,
>  				       TSL2772_CMD_REG | TSL2772_CHIPID);
>  	if (ret < 0)
> @@ -1806,13 +1879,33 @@ static int tsl2772_probe(struct i2c_client *clientp,
>  static int tsl2772_suspend(struct device *dev)
>  {
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
> +	int ret;
>  
> -	return tsl2772_chip_off(indio_dev);
> +	ret = tsl2772_chip_off(indio_dev);
> +	regulator_disable(chip->vdd_supply);
> +	regulator_disable(chip->vddio_supply);
> +
> +	return ret;
>  }
>  
>  static int tsl2772_resume(struct device *dev)
>  {
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct tsl2772_chip *chip = iio_priv(indio_dev);
> +	int ret;
> +
> +	ret = tsl2772_enable_regulator(chip, chip->vddio_supply);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = tsl2772_enable_regulator(chip, chip->vdd_supply);
> +	if (ret < 0) {
> +		regulator_disable(chip->vddio_supply);
> +		return ret;
> +	}
> +
> +	usleep_range(TSL2772_BOOT_MIN_SLEEP_TIME, TSL2772_BOOT_MAX_SLEEP_TIME);
>  
>  	return tsl2772_chip_on(indio_dev);
>  }


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

* Re: [PATCH v3 6/9] dt-bindings: iio: tsl2772: add bindings for regulator framework
  2018-08-03  0:18 ` [PATCH v3 6/9] dt-bindings: iio: tsl2772: add bindings " Brian Masney
@ 2018-08-03 21:51   ` Jonathan Cameron
  2018-08-07 17:20     ` Rob Herring
  0 siblings, 1 reply; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-03 21:51 UTC (permalink / raw)
  To: Brian Masney
  Cc: robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Thu,  2 Aug 2018 20:18:57 -0400
Brian Masney <masneyb@onstation.org> wrote:

> This patch adds device tree bindings to the tsl2772 driver for the
> regulator framework.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
I suspect Rob will tell you this should really have been in the same
patch as the earlier bindings.   There is no need for us to wait
for the driver support as the binding describes what is there, not
what we do with it.

Otherwise it's fine and if nothing else comes up I can merge them ;)

Jonathan

> ---
>  Documentation/devicetree/bindings/iio/light/tsl2772.txt | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/iio/light/tsl2772.txt b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> index 6f33169344f2..4e7d98627cbf 100644
> --- a/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> +++ b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> @@ -21,6 +21,8 @@ Optional properties:
>                                 are the only valid values.
>    - led-max-microamp - current for the proximity LED. Must be 100000, 50000,
>                         25000, or 13000.
> +  - vdd-supply: phandle to the regulator that provides power to the sensor.
> +  - vddio-supply: phandle to the regulator that provides power to the bus.
>    - interrupts: the sole interrupt generated by the device
>  
>    Refer to interrupt-controller/interrupts.txt for generic interrupt client
> @@ -32,6 +34,8 @@ tsl2772@39 {
>  	compatible = "amstaos,tsl2772";
>  	reg = <0x39>;
>  	interrupts-extended = <&msmgpio 61 IRQ_TYPE_EDGE_FALLING>;
> +	vdd-supply = <&pm8941_l17>;
> +	vddio-supply = <&pm8941_lvs1>;
>  	amstaos,proximity-diodes = <0>;
>  	led-max-microamp = <100000>;
>  };


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

* Re: [PATCH v3 7/9] iio: tsl2772: add support for avago,apds9930
  2018-08-03  0:18 ` [PATCH v3 7/9] iio: tsl2772: add support for avago,apds9930 Brian Masney
@ 2018-08-03 21:53   ` Jonathan Cameron
  2018-08-18 17:07     ` Jonathan Cameron
  0 siblings, 1 reply; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-03 21:53 UTC (permalink / raw)
  To: Brian Masney
  Cc: robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Thu,  2 Aug 2018 20:18:58 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The Avago APDS9930 has the same register set as the TAOS/AMS TSL2772 so
> this patch adds the correct bindings and the appropriate LUX table
> values derived from the values in the datasheet. Driver was tested on a
> LG Nexus 5 (hammerhead) phone.
> 
> avago,apds9930 datasheet:
> https://www.mouser.com/datasheet/2/678/avago_AV02-3190EN_DS_APDS-9930_2014-03-25[1]-1217273.pdf
> 
> tsl2772 datasheet:
> https://ams.com/eng/content/download/291503/1066377/file/TSL2772_DS000181_2-00.pdf
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Glad you noticed they were the same.  will apply once precursors are in.

Thanks,

Jonathan

> ---
>  drivers/iio/light/tsl2772.c | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
> index 4a11bf77a4d0..83cece921843 100644
> --- a/drivers/iio/light/tsl2772.c
> +++ b/drivers/iio/light/tsl2772.c
> @@ -124,7 +124,8 @@ enum {
>  	tsl2672,
>  	tmd2672,
>  	tsl2772,
> -	tmd2772
> +	tmd2772,
> +	apds9930,
>  };
>  
>  enum {
> @@ -213,6 +214,12 @@ static const struct tsl2772_lux tmd2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
>  	{     0,      0 },
>  };
>  
> +static const struct tsl2772_lux apds9930_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
> +	{ 52000,  96824 },
> +	{ 38792,  67132 },
> +	{     0,      0 },
> +};
> +
>  static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = {
>  	[tsl2571] = tsl2x71_lux_table,
>  	[tsl2671] = tsl2x71_lux_table,
> @@ -224,6 +231,7 @@ static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = {
>  	[tmd2672] = tmd2x72_lux_table,
>  	[tsl2772] = tsl2x72_lux_table,
>  	[tmd2772] = tmd2x72_lux_table,
> +	[apds9930] = apds9930_lux_table,
>  };
>  
>  static const struct tsl2772_settings tsl2772_default_settings = {
> @@ -274,6 +282,7 @@ static const int tsl2772_int_time_avail[][6] = {
>  	[tmd2672] = { 0, 2730, 0, 2730, 0, 699000 },
>  	[tsl2772] = { 0, 2730, 0, 2730, 0, 699000 },
>  	[tmd2772] = { 0, 2730, 0, 2730, 0, 699000 },
> +	[apds9930] = { 0, 2730, 0, 2730, 0, 699000 },
>  };
>  
>  static int tsl2772_int_calibscale_avail[] = { 1, 8, 16, 120 };
> @@ -299,7 +308,8 @@ static const u8 device_channel_config[] = {
>  	[tsl2672] = PRX2,
>  	[tmd2672] = PRX2,
>  	[tsl2772] = ALSPRX2,
> -	[tmd2772] = ALSPRX2
> +	[tmd2772] = ALSPRX2,
> +	[apds9930] = ALSPRX2,
>  };
>  
>  static int tsl2772_read_status(struct tsl2772_chip *chip)
> @@ -513,6 +523,7 @@ static int tsl2772_get_prox(struct iio_dev *indio_dev)
>  	case tmd2672:
>  	case tsl2772:
>  	case tmd2772:
> +	case apds9930:
>  		if (!(ret & TSL2772_STA_PRX_VALID)) {
>  			ret = -EINVAL;
>  			goto prox_poll_err;
> @@ -1393,6 +1404,7 @@ static int tsl2772_device_id_verif(int id, int target)
>  	case tmd2672:
>  	case tsl2772:
>  	case tmd2772:
> +	case apds9930:
>  		return (id & 0xf0) == SWORDFISH_ID;
>  	}
>  
> @@ -1932,6 +1944,7 @@ static const struct i2c_device_id tsl2772_idtable[] = {
>  	{ "tmd2672", tmd2672 },
>  	{ "tsl2772", tsl2772 },
>  	{ "tmd2772", tmd2772 },
> +	{ "apds9930", apds9930},
>  	{}
>  };
>  
> @@ -1948,6 +1961,7 @@ static const struct of_device_id tsl2772_of_match[] = {
>  	{ .compatible = "amstaos,tmd2672" },
>  	{ .compatible = "amstaos,tsl2772" },
>  	{ .compatible = "amstaos,tmd2772" },
> +	{ .compatible = "avago,apds9930" },
>  	{}
>  };
>  MODULE_DEVICE_TABLE(of, tsl2772_of_match);


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

* Re: [PATCH v3 8/9] dt-bindings: iio: tsl2772: add binding for avago,apds9930
  2018-08-03  0:18 ` [PATCH v3 8/9] dt-bindings: iio: tsl2772: add binding " Brian Masney
@ 2018-08-03 21:54   ` Jonathan Cameron
  2018-08-07 17:21   ` Rob Herring
  1 sibling, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-03 21:54 UTC (permalink / raw)
  To: Brian Masney
  Cc: robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Thu,  2 Aug 2018 20:18:59 -0400
Brian Masney <masneyb@onstation.org> wrote:

> This patch adds avago,apds9930 to the tsl2772 bindings.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
As before I'll pick up with the rest.

Thanks,

Jonathan

> ---
>  Documentation/devicetree/bindings/iio/light/tsl2772.txt | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Documentation/devicetree/bindings/iio/light/tsl2772.txt b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> index 4e7d98627cbf..1c5e6f17a1df 100644
> --- a/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> +++ b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> @@ -13,6 +13,7 @@ Required properties:
>  		"amstaos,tmd2672"
>  		"amstaos,tsl2772"
>  		"amstaos,tmd2772"
> +		"avago,apds9930"
>    - reg: the I2C address of the device
>  
>  Optional properties:


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

* Re: [PATCH v3 4/9] dt-bindings: iio: tsl2772: add new bindings
  2018-08-03 21:48   ` Jonathan Cameron
@ 2018-08-07 16:54     ` Rob Herring
  2018-08-18 17:01       ` Jonathan Cameron
  0 siblings, 1 reply; 26+ messages in thread
From: Rob Herring @ 2018-08-07 16:54 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Brian Masney, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Fri, Aug 03, 2018 at 10:48:38PM +0100, Jonathan Cameron wrote:
> On Thu,  2 Aug 2018 20:18:55 -0400
> Brian Masney <masneyb@onstation.org> wrote:
> 
> > This patch adds the new properties amstaos,proximity-diodes and
> > led-max-microamp to the tsl2772 driver. This patch also removes the
> > driver from the trivial-devices.txt.
> > 
> > Signed-off-by: Brian Masney <masneyb@onstation.org>
> > ---
> This and the implementation look fine to me, but I'll leave them for
> now to give Rob time to take a look if he wants to.
> 
> Thanks,
> 
> Jonathan
> 
> > I got a Reviewed-by: Rob Herring <robh@kernel.org> on my last series but
> > didn't include it due to the new file tsl2772.txt in this patch. Device
> > tree bindings need to be complete.
> > 
> >  .../devicetree/bindings/iio/light/tsl2772.txt | 37 +++++++++++++++++++
> >  .../devicetree/bindings/trivial-devices.txt   | 10 -----
> >  2 files changed, 37 insertions(+), 10 deletions(-)
> >  create mode 100644 Documentation/devicetree/bindings/iio/light/tsl2772.txt

Reviewed-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v3 6/9] dt-bindings: iio: tsl2772: add bindings for regulator framework
  2018-08-03 21:51   ` Jonathan Cameron
@ 2018-08-07 17:20     ` Rob Herring
  2018-08-18 17:02       ` Jonathan Cameron
  0 siblings, 1 reply; 26+ messages in thread
From: Rob Herring @ 2018-08-07 17:20 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Brian Masney, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Fri, Aug 03, 2018 at 10:51:23PM +0100, Jonathan Cameron wrote:
> On Thu,  2 Aug 2018 20:18:57 -0400
> Brian Masney <masneyb@onstation.org> wrote:
> 
> > This patch adds device tree bindings to the tsl2772 driver for the
> > regulator framework.
> > 
> > Signed-off-by: Brian Masney <masneyb@onstation.org>
> I suspect Rob will tell you this should really have been in the same
> patch as the earlier bindings.   There is no need for us to wait
> for the driver support as the binding describes what is there, not
> what we do with it.

Yep.

> 
> Otherwise it's fine and if nothing else comes up I can merge them ;)
> 
> Jonathan
> 
> > ---
> >  Documentation/devicetree/bindings/iio/light/tsl2772.txt | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/Documentation/devicetree/bindings/iio/light/tsl2772.txt b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> > index 6f33169344f2..4e7d98627cbf 100644
> > --- a/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> > +++ b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> > @@ -21,6 +21,8 @@ Optional properties:
> >                                 are the only valid values.
> >    - led-max-microamp - current for the proximity LED. Must be 100000, 50000,
> >                         25000, or 13000.
> > +  - vdd-supply: phandle to the regulator that provides power to the sensor.
> > +  - vddio-supply: phandle to the regulator that provides power to the bus.
> >    - interrupts: the sole interrupt generated by the device
> >  
> >    Refer to interrupt-controller/interrupts.txt for generic interrupt client
> > @@ -32,6 +34,8 @@ tsl2772@39 {
> >  	compatible = "amstaos,tsl2772";
> >  	reg = <0x39>;
> >  	interrupts-extended = <&msmgpio 61 IRQ_TYPE_EDGE_FALLING>;
> > +	vdd-supply = <&pm8941_l17>;
> > +	vddio-supply = <&pm8941_lvs1>;
> >  	amstaos,proximity-diodes = <0>;
> >  	led-max-microamp = <100000>;
> >  };
> 

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

* Re: [PATCH v3 8/9] dt-bindings: iio: tsl2772: add binding for avago,apds9930
  2018-08-03  0:18 ` [PATCH v3 8/9] dt-bindings: iio: tsl2772: add binding " Brian Masney
  2018-08-03 21:54   ` Jonathan Cameron
@ 2018-08-07 17:21   ` Rob Herring
  2018-08-18 17:06     ` Jonathan Cameron
  1 sibling, 1 reply; 26+ messages in thread
From: Rob Herring @ 2018-08-07 17:21 UTC (permalink / raw)
  To: Brian Masney
  Cc: jic23, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Thu, Aug 02, 2018 at 08:18:59PM -0400, Brian Masney wrote:
> This patch adds avago,apds9930 to the tsl2772 bindings.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
> ---
>  Documentation/devicetree/bindings/iio/light/tsl2772.txt | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v3 4/9] dt-bindings: iio: tsl2772: add new bindings
  2018-08-07 16:54     ` Rob Herring
@ 2018-08-18 17:01       ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-18 17:01 UTC (permalink / raw)
  To: Rob Herring
  Cc: Brian Masney, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Tue, 7 Aug 2018 10:54:26 -0600
Rob Herring <robh@kernel.org> wrote:

> On Fri, Aug 03, 2018 at 10:48:38PM +0100, Jonathan Cameron wrote:
> > On Thu,  2 Aug 2018 20:18:55 -0400
> > Brian Masney <masneyb@onstation.org> wrote:
> >   
> > > This patch adds the new properties amstaos,proximity-diodes and
> > > led-max-microamp to the tsl2772 driver. This patch also removes the
> > > driver from the trivial-devices.txt.
> > > 
> > > Signed-off-by: Brian Masney <masneyb@onstation.org>
> > > ---  
> > This and the implementation look fine to me, but I'll leave them for
> > now to give Rob time to take a look if he wants to.
> > 
> > Thanks,
> > 
> > Jonathan
> >   
> > > I got a Reviewed-by: Rob Herring <robh@kernel.org> on my last series but
> > > didn't include it due to the new file tsl2772.txt in this patch. Device
> > > tree bindings need to be complete.
> > > 
> > >  .../devicetree/bindings/iio/light/tsl2772.txt | 37 +++++++++++++++++++
> > >  .../devicetree/bindings/trivial-devices.txt   | 10 -----
> > >  2 files changed, 37 insertions(+), 10 deletions(-)
> > >  create mode 100644 Documentation/devicetree/bindings/iio/light/tsl2772.txt  
> 
> Reviewed-by: Rob Herring <robh@kernel.org>

Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to ignore it.

I'll apply the other dt bits to this as fixups.

Jonathan

> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

* Re: [PATCH v3 6/9] dt-bindings: iio: tsl2772: add bindings for regulator framework
  2018-08-07 17:20     ` Rob Herring
@ 2018-08-18 17:02       ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-18 17:02 UTC (permalink / raw)
  To: Rob Herring
  Cc: Brian Masney, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Tue, 7 Aug 2018 11:20:28 -0600
Rob Herring <robh@kernel.org> wrote:

> On Fri, Aug 03, 2018 at 10:51:23PM +0100, Jonathan Cameron wrote:
> > On Thu,  2 Aug 2018 20:18:57 -0400
> > Brian Masney <masneyb@onstation.org> wrote:
> >   
> > > This patch adds device tree bindings to the tsl2772 driver for the
> > > regulator framework.
> > > 
> > > Signed-off-by: Brian Masney <masneyb@onstation.org>  
> > I suspect Rob will tell you this should really have been in the same
> > patch as the earlier bindings.   There is no need for us to wait
> > for the driver support as the binding describes what is there, not
> > what we do with it.  
> 
> Yep.
> 
> > 
> > Otherwise it's fine and if nothing else comes up I can merge them ;)

I merged them.

Jonathan
> > 
> > Jonathan
> >   
> > > ---
> > >  Documentation/devicetree/bindings/iio/light/tsl2772.txt | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > > 
> > > diff --git a/Documentation/devicetree/bindings/iio/light/tsl2772.txt b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> > > index 6f33169344f2..4e7d98627cbf 100644
> > > --- a/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> > > +++ b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
> > > @@ -21,6 +21,8 @@ Optional properties:
> > >                                 are the only valid values.
> > >    - led-max-microamp - current for the proximity LED. Must be 100000, 50000,
> > >                         25000, or 13000.
> > > +  - vdd-supply: phandle to the regulator that provides power to the sensor.
> > > +  - vddio-supply: phandle to the regulator that provides power to the bus.
> > >    - interrupts: the sole interrupt generated by the device
> > >  
> > >    Refer to interrupt-controller/interrupts.txt for generic interrupt client
> > > @@ -32,6 +34,8 @@ tsl2772@39 {
> > >  	compatible = "amstaos,tsl2772";
> > >  	reg = <0x39>;
> > >  	interrupts-extended = <&msmgpio 61 IRQ_TYPE_EDGE_FALLING>;
> > > +	vdd-supply = <&pm8941_l17>;
> > > +	vddio-supply = <&pm8941_lvs1>;
> > >  	amstaos,proximity-diodes = <0>;
> > >  	led-max-microamp = <100000>;
> > >  };  
> >   


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

* Re: [PATCH v3 3/9] iio: tsl2772: add support for reading proximity led settings from device tree
  2018-08-03  0:18 ` [PATCH v3 3/9] iio: tsl2772: add support for reading proximity led settings from device tree Brian Masney
@ 2018-08-18 17:04   ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-18 17:04 UTC (permalink / raw)
  To: Brian Masney
  Cc: robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Thu,  2 Aug 2018 20:18:54 -0400
Brian Masney <masneyb@onstation.org> wrote:

> This patch adds support for optionally reading the proximity led diode
> and current settings from device tree. This was tested using a LG
> Nexus 5 (hammerhead) which requires a different diode than the driver
> default for the IR LED.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with them.

thanks,

Jonathan

> ---
>  drivers/iio/light/tsl2772.c | 81 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 81 insertions(+)
> 
> diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
> index df5b2a0da96c..ae00edf0d87e 100644
> --- a/drivers/iio/light/tsl2772.c
> +++ b/drivers/iio/light/tsl2772.c
> @@ -107,6 +107,8 @@
>  #define TSL2772_ALS_GAIN_TRIM_MIN	250
>  #define TSL2772_ALS_GAIN_TRIM_MAX	4000
>  
> +#define TSL2772_MAX_PROX_LEDS		2
> +
>  /* Device family members */
>  enum {
>  	tsl2571,
> @@ -141,6 +143,14 @@ struct tsl2772_chip_info {
>  	const struct iio_info *info;
>  };
>  
> +static const int tsl2772_led_currents[][2] = {
> +	{ 100000, TSL2772_100_mA },
> +	{  50000, TSL2772_50_mA },
> +	{  25000, TSL2772_25_mA },
> +	{  13000, TSL2772_13_mA },
> +	{      0, 0 }
> +};
> +
>  struct tsl2772_chip {
>  	kernel_ulong_t id;
>  	struct mutex prox_mutex;
> @@ -515,6 +525,75 @@ static int tsl2772_get_prox(struct iio_dev *indio_dev)
>  	return ret;
>  }
>  
> +static int tsl2772_read_prox_led_current(struct tsl2772_chip *chip)
> +{
> +	struct device_node *of_node = chip->client->dev.of_node;
> +	int ret, tmp, i;
> +
> +	ret = of_property_read_u32(of_node, "led-max-microamp", &tmp);
> +	if (ret < 0)
> +		return ret;
> +
> +	for (i = 0; tsl2772_led_currents[i][0] != 0; i++) {
> +		if (tmp == tsl2772_led_currents[i][0]) {
> +			chip->settings.prox_power = tsl2772_led_currents[i][1];
> +			return 0;
> +		}
> +	}
> +
> +	dev_err(&chip->client->dev, "Invalid value %d for led-max-microamp\n",
> +		tmp);
> +
> +	return -EINVAL;
> +
> +}
> +
> +static int tsl2772_read_prox_diodes(struct tsl2772_chip *chip)
> +{
> +	struct device_node *of_node = chip->client->dev.of_node;
> +	int i, ret, num_leds, prox_diode_mask;
> +	u32 leds[TSL2772_MAX_PROX_LEDS];
> +
> +	ret = of_property_count_u32_elems(of_node, "amstaos,proximity-diodes");
> +	if (ret < 0)
> +		return ret;
> +
> +	num_leds = ret;
> +	if (num_leds > TSL2772_MAX_PROX_LEDS)
> +		num_leds = TSL2772_MAX_PROX_LEDS;
> +
> +	ret = of_property_read_u32_array(of_node, "amstaos,proximity-diodes",
> +					 leds, num_leds);
> +	if (ret < 0) {
> +		dev_err(&chip->client->dev,
> +			"Invalid value for amstaos,proximity-diodes: %d.\n",
> +			ret);
> +		return ret;
> +	}
> +
> +	prox_diode_mask = 0;
> +	for (i = 0; i < num_leds; i++) {
> +		if (leds[i] == 0)
> +			prox_diode_mask |= TSL2772_DIODE0;
> +		else if (leds[i] == 1)
> +			prox_diode_mask |= TSL2772_DIODE1;
> +		else {
> +			dev_err(&chip->client->dev,
> +				"Invalid value %d in amstaos,proximity-diodes.\n",
> +				leds[i]);
> +			return -EINVAL;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static void tsl2772_parse_dt(struct tsl2772_chip *chip)
> +{
> +	tsl2772_read_prox_led_current(chip);
> +	tsl2772_read_prox_diodes(chip);
> +}
> +
>  /**
>   * tsl2772_defaults() - Populates the device nominal operating parameters
>   *                      with those provided by a 'platform' data struct or
> @@ -541,6 +620,8 @@ static void tsl2772_defaults(struct tsl2772_chip *chip)
>  		memcpy(chip->tsl2772_device_lux,
>  		       tsl2772_default_lux_table_group[chip->id],
>  		       TSL2772_DEFAULT_TABLE_BYTES);
> +
> +	tsl2772_parse_dt(chip);
>  }
>  
>  /**


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

* Re: [PATCH v3 8/9] dt-bindings: iio: tsl2772: add binding for avago,apds9930
  2018-08-07 17:21   ` Rob Herring
@ 2018-08-18 17:06     ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-18 17:06 UTC (permalink / raw)
  To: Rob Herring
  Cc: Brian Masney, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Tue, 7 Aug 2018 11:21:01 -0600
Rob Herring <robh@kernel.org> wrote:

> On Thu, Aug 02, 2018 at 08:18:59PM -0400, Brian Masney wrote:
> > This patch adds avago,apds9930 to the tsl2772 bindings.
> > 
> > Signed-off-by: Brian Masney <masneyb@onstation.org>
> > ---
> >  Documentation/devicetree/bindings/iio/light/tsl2772.txt | 1 +
> >  1 file changed, 1 insertion(+)  
> 
> Reviewed-by: Rob Herring <robh@kernel.org>

Applied.  Thanks

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

* Re: [PATCH v3 7/9] iio: tsl2772: add support for avago,apds9930
  2018-08-03 21:53   ` Jonathan Cameron
@ 2018-08-18 17:07     ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-18 17:07 UTC (permalink / raw)
  To: Brian Masney
  Cc: robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Fri, 3 Aug 2018 22:53:36 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> On Thu,  2 Aug 2018 20:18:58 -0400
> Brian Masney <masneyb@onstation.org> wrote:
> 
> > The Avago APDS9930 has the same register set as the TAOS/AMS TSL2772 so
> > this patch adds the correct bindings and the appropriate LUX table
> > values derived from the values in the datasheet. Driver was tested on a
> > LG Nexus 5 (hammerhead) phone.
> > 
> > avago,apds9930 datasheet:
> > https://www.mouser.com/datasheet/2/678/avago_AV02-3190EN_DS_APDS-9930_2014-03-25[1]-1217273.pdf
> > 
> > tsl2772 datasheet:
> > https://ams.com/eng/content/download/291503/1066377/file/TSL2772_DS000181_2-00.pdf
> > 
> > Signed-off-by: Brian Masney <masneyb@onstation.org>  
> Glad you noticed they were the same.  will apply once precursors are in.
> 
Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to play with it.

Thanks,

Jonathan

> Thanks,
> 
> Jonathan
> 
> > ---
> >  drivers/iio/light/tsl2772.c | 18 ++++++++++++++++--
> >  1 file changed, 16 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
> > index 4a11bf77a4d0..83cece921843 100644
> > --- a/drivers/iio/light/tsl2772.c
> > +++ b/drivers/iio/light/tsl2772.c
> > @@ -124,7 +124,8 @@ enum {
> >  	tsl2672,
> >  	tmd2672,
> >  	tsl2772,
> > -	tmd2772
> > +	tmd2772,
> > +	apds9930,
> >  };
> >  
> >  enum {
> > @@ -213,6 +214,12 @@ static const struct tsl2772_lux tmd2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
> >  	{     0,      0 },
> >  };
> >  
> > +static const struct tsl2772_lux apds9930_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
> > +	{ 52000,  96824 },
> > +	{ 38792,  67132 },
> > +	{     0,      0 },
> > +};
> > +
> >  static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = {
> >  	[tsl2571] = tsl2x71_lux_table,
> >  	[tsl2671] = tsl2x71_lux_table,
> > @@ -224,6 +231,7 @@ static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = {
> >  	[tmd2672] = tmd2x72_lux_table,
> >  	[tsl2772] = tsl2x72_lux_table,
> >  	[tmd2772] = tmd2x72_lux_table,
> > +	[apds9930] = apds9930_lux_table,
> >  };
> >  
> >  static const struct tsl2772_settings tsl2772_default_settings = {
> > @@ -274,6 +282,7 @@ static const int tsl2772_int_time_avail[][6] = {
> >  	[tmd2672] = { 0, 2730, 0, 2730, 0, 699000 },
> >  	[tsl2772] = { 0, 2730, 0, 2730, 0, 699000 },
> >  	[tmd2772] = { 0, 2730, 0, 2730, 0, 699000 },
> > +	[apds9930] = { 0, 2730, 0, 2730, 0, 699000 },
> >  };
> >  
> >  static int tsl2772_int_calibscale_avail[] = { 1, 8, 16, 120 };
> > @@ -299,7 +308,8 @@ static const u8 device_channel_config[] = {
> >  	[tsl2672] = PRX2,
> >  	[tmd2672] = PRX2,
> >  	[tsl2772] = ALSPRX2,
> > -	[tmd2772] = ALSPRX2
> > +	[tmd2772] = ALSPRX2,
> > +	[apds9930] = ALSPRX2,
> >  };
> >  
> >  static int tsl2772_read_status(struct tsl2772_chip *chip)
> > @@ -513,6 +523,7 @@ static int tsl2772_get_prox(struct iio_dev *indio_dev)
> >  	case tmd2672:
> >  	case tsl2772:
> >  	case tmd2772:
> > +	case apds9930:
> >  		if (!(ret & TSL2772_STA_PRX_VALID)) {
> >  			ret = -EINVAL;
> >  			goto prox_poll_err;
> > @@ -1393,6 +1404,7 @@ static int tsl2772_device_id_verif(int id, int target)
> >  	case tmd2672:
> >  	case tsl2772:
> >  	case tmd2772:
> > +	case apds9930:
> >  		return (id & 0xf0) == SWORDFISH_ID;
> >  	}
> >  
> > @@ -1932,6 +1944,7 @@ static const struct i2c_device_id tsl2772_idtable[] = {
> >  	{ "tmd2672", tmd2672 },
> >  	{ "tsl2772", tsl2772 },
> >  	{ "tmd2772", tmd2772 },
> > +	{ "apds9930", apds9930},
> >  	{}
> >  };
> >  
> > @@ -1948,6 +1961,7 @@ static const struct of_device_id tsl2772_of_match[] = {
> >  	{ .compatible = "amstaos,tmd2672" },
> >  	{ .compatible = "amstaos,tsl2772" },
> >  	{ .compatible = "amstaos,tmd2772" },
> > +	{ .compatible = "avago,apds9930" },
> >  	{}
> >  };
> >  MODULE_DEVICE_TABLE(of, tsl2772_of_match);  
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

* Re: [PATCH v3 9/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for ALS / proximity
  2018-08-03  0:19 ` [PATCH v3 9/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for ALS / proximity Brian Masney
@ 2018-08-18 17:09   ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-08-18 17:09 UTC (permalink / raw)
  To: Brian Masney
  Cc: robh+dt, mark.rutland, andy.gross, david.brown, linux-iio,
	devicetree, linux-kernel, linux-arm-msm, linux-soc, jonathan,
	jmaneyrol, knaack.h, lars, pmeerw, mkelly, fischerdouglasc,
	bshah, ctatlor97

On Thu,  2 Aug 2018 20:19:00 -0400
Brian Masney <masneyb@onstation.org> wrote:

> This patch adds device tree bindings for the tsl2772 ALS / proximity
> sensor for the LG Nexus 5 (hammerhead) phone.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
> Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Acked-by: Jonathan Cameron <jonathan.cameron@huawei.com>

The precursors are working their way through the iio tree, but
it will be the next merge window before they go upstream.

Thanks,

Jonathan

> ---
>  .../qcom-msm8974-lge-nexus5-hammerhead.dts    | 27 +++++++++++++++++++
>  arch/arm/boot/dts/qcom-msm8974.dtsi           | 11 ++++++++
>  2 files changed, 38 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts b/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
> index 928affae1885..ed8f064d0895 100644
> --- a/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
> +++ b/arch/arm/boot/dts/qcom-msm8974-lge-nexus5-hammerhead.dts
> @@ -242,6 +242,15 @@
>  			};
>  		};
>  
> +		i2c3_pins: i2c3 {
> +			mux {
> +				pins = "gpio10", "gpio11";
> +				function = "blsp_i2c3";
> +				drive-strength = <2>;
> +				bias-disable;
> +			};
> +		};
> +
>  		i2c12_pins: i2c12 {
>  			mux {
>  				pins = "gpio87", "gpio88";
> @@ -333,6 +342,24 @@
>  			};
>  		};
>  	};
> +
> +	i2c@f9925000 {
> +		status = "ok";
> +		pinctrl-names = "default";
> +		pinctrl-0 = <&i2c3_pins>;
> +		clock-frequency = <100000>;
> +		qcom,src-freq = <50000000>;
> +
> +		avago_apds993@39 {
> +			compatible = "avago,apds9930";
> +			reg = <0x39>;
> +			interrupts-extended = <&msmgpio 61 IRQ_TYPE_EDGE_FALLING>;
> +			vdd-supply = <&pm8941_l17>;
> +			vddio-supply = <&pm8941_lvs1>;
> +			led-max-microamp = <100000>;
> +			amstaos,proximity-diodes = <0>;
> +		};
> +	};
>  };
>  
>  &spmi_bus {
> diff --git a/arch/arm/boot/dts/qcom-msm8974.dtsi b/arch/arm/boot/dts/qcom-msm8974.dtsi
> index cebb6ae9143a..6dcf2bee66fb 100644
> --- a/arch/arm/boot/dts/qcom-msm8974.dtsi
> +++ b/arch/arm/boot/dts/qcom-msm8974.dtsi
> @@ -713,6 +713,17 @@
>  			#size-cells = <0>;
>  		};
>  
> +		blsp_i2c3: i2c@f9925000 {
> +			status = "disabled";
> +			compatible = "qcom,i2c-qup-v2.1.1";
> +			reg = <0xf9925000 0x1000>;
> +			interrupts = <0 97 IRQ_TYPE_NONE>;
> +			clocks = <&gcc GCC_BLSP1_QUP3_I2C_APPS_CLK>, <&gcc GCC_BLSP1_AHB_CLK>;
> +			clock-names = "core", "iface";
> +			#address-cells = <1>;
> +			#size-cells = <0>;
> +		};
> +
>  		blsp_i2c8: i2c@f9964000 {
>  			status = "disabled";
>  			compatible = "qcom,i2c-qup-v2.1.1";


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

end of thread, other threads:[~2018-08-18 17:13 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-03  0:18 [PATCH v3 0/9] treewide: add support for various sensors on the LG Nexus 5 (hammerhead) Brian Masney
2018-08-03  0:18 ` [PATCH v3 1/9] iio: imu: mpu6050: add support for regulator framework Brian Masney
2018-08-03 21:44   ` Jonathan Cameron
2018-08-03  0:18 ` [PATCH v3 2/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for mpu6515 Brian Masney
2018-08-03 21:46   ` Jonathan Cameron
2018-08-03  0:18 ` [PATCH v3 3/9] iio: tsl2772: add support for reading proximity led settings from device tree Brian Masney
2018-08-18 17:04   ` Jonathan Cameron
2018-08-03  0:18 ` [PATCH v3 4/9] dt-bindings: iio: tsl2772: add new bindings Brian Masney
2018-08-03 21:48   ` Jonathan Cameron
2018-08-07 16:54     ` Rob Herring
2018-08-18 17:01       ` Jonathan Cameron
2018-08-03  0:18 ` [PATCH v3 5/9] iio: tsl2772: add support for regulator framework Brian Masney
2018-08-03 21:50   ` Jonathan Cameron
2018-08-03  0:18 ` [PATCH v3 6/9] dt-bindings: iio: tsl2772: add bindings " Brian Masney
2018-08-03 21:51   ` Jonathan Cameron
2018-08-07 17:20     ` Rob Herring
2018-08-18 17:02       ` Jonathan Cameron
2018-08-03  0:18 ` [PATCH v3 7/9] iio: tsl2772: add support for avago,apds9930 Brian Masney
2018-08-03 21:53   ` Jonathan Cameron
2018-08-18 17:07     ` Jonathan Cameron
2018-08-03  0:18 ` [PATCH v3 8/9] dt-bindings: iio: tsl2772: add binding " Brian Masney
2018-08-03 21:54   ` Jonathan Cameron
2018-08-07 17:21   ` Rob Herring
2018-08-18 17:06     ` Jonathan Cameron
2018-08-03  0:19 ` [PATCH v3 9/9] ARM: dts: qcom: msm8974-hammerhead: add device tree bindings for ALS / proximity Brian Masney
2018-08-18 17:09   ` 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).