Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1552680 > unrolled thread

[PATCH v3 0/4] hwmon: adc128d818: Support missing operation modes

Started byAlexander Koch <mail@alexanderkoch.net>
First post2017-01-06 11:50 +0100
Last post2017-01-10 18:20 +0100
Articles 6 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v3 0/4] hwmon: adc128d818: Support missing operation modes Alexander Koch <mail@alexanderkoch.net> - 2017-01-06 11:50 +0100
    [PATCH v3 4/4] hwmon: adc128d818: Preserve operation mode Alexander Koch <mail@alexanderkoch.net> - 2017-01-06 11:50 +0100
    [PATCH v3 2/4] hwmon: adc128d818: Implement mode selection via dt Alexander Koch <mail@alexanderkoch.net> - 2017-01-06 11:50 +0100
    [PATCH v3 1/4] devicetree: hwmon: Add bindings for ADC128D818 Alexander Koch <mail@alexanderkoch.net> - 2017-01-06 11:50 +0100
      Re: [PATCH v3 1/4] devicetree: hwmon: Add bindings for ADC128D818 Rob Herring <robh@kernel.org> - 2017-01-10 06:40 +0100
    Re: [PATCH v3 0/4] hwmon: adc128d818: Support missing operation modes Guenter Roeck <linux@roeck-us.net> - 2017-01-10 18:20 +0100

#1552680 — [PATCH v3 0/4] hwmon: adc128d818: Support missing operation modes

FromAlexander Koch <mail@alexanderkoch.net>
Date2017-01-06 11:50 +0100
Subject[PATCH v3 0/4] hwmon: adc128d818: Support missing operation modes
Message-ID<sWAfT-w2-7@gated-at.bofh.it>
The ADC128D818 offers four different chip operation modes which vary in the
number and measurement types of the available input signals (see datasheet
sec. 8.4.1).

The current version of the driver only supports the default chip operation
mode (mode 0), providing seven analog values and a temperature reading.

This patch series adds support for operation modes 1-3, selectable through
the device tree attribute 'ti,mode':

        adc1: adc128d818@1d {
                compatible = "ti,adc128d818";
                reg = <0x1d>;
                mode = <1>;
        };

The changes are transparent as the driver defaults to keeping the currently
active operation mode if no mode is specified via device tree (which is
mode 0 on chip initialization).


Changes from v2:
 - Omit device attribute refactoring (for checkpatch.pl), as requested by
   maintainer
 - Add vendor prefix 'ti,' for mode property in device tree
 - Drop size indication for mode property in device tree
 - Preserve chip operation mode if none specified in devicetree
 - Fix missing '\n' in dev_err() calls

Changes from v1:
 - Add bindings document as first patch
 - Preserve logical atomicity of code changes
 - Improve sysfs device node handling (use is_visible() instead of
   duplicate attribute list)
 - Add trivial code refactoring stage for checkpatch.pl to succeed


Alexander Koch (4):
  devicetree: hwmon: Add bindings for ADC128D818
  hwmon: adc128d818: Implement mode selection via dt
  hwmon: adc128d818: Support operation modes 1-3
  hwmon: adc128d818: Preserve operation mode

 .../devicetree/bindings/hwmon/adc128d818.txt       |  39 ++++++
 drivers/hwmon/adc128d818.c                         | 147 +++++++++++++++------
 2 files changed, 149 insertions(+), 37 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adc128d818.txt

-- 
2.11.0

[toc] | [next] | [standalone]


#1552682 — [PATCH v3 4/4] hwmon: adc128d818: Preserve operation mode

FromAlexander Koch <mail@alexanderkoch.net>
Date2017-01-06 11:50 +0100
Subject[PATCH v3 4/4] hwmon: adc128d818: Preserve operation mode
Message-ID<sWAfU-w2-25@gated-at.bofh.it>
In reply to#1552680
Preserve chip operation mode if no mode is specified via devicetree. This
enables operation when chip configuration is done by BIOS/ROMMON.

Signed-off-by: Alexander Koch <mail@alexanderkoch.net>
Acked-by: Michael Hornung <mhornung.linux@gmail.com>
---
 drivers/hwmon/adc128d818.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/adc128d818.c b/drivers/hwmon/adc128d818.c
index 0502af963f73..bbe3a5c5b3f5 100644
--- a/drivers/hwmon/adc128d818.c
+++ b/drivers/hwmon/adc128d818.c
@@ -491,7 +491,7 @@ static int adc128_probe(struct i2c_client *client,
 		data->vref = 2560;	/* 2.56V, in mV */
 	}
 
-	/* Operation mode is optional and defaults to mode 0 */
+	/* Operation mode is optional. If unspecified, keep current mode */
 	if (of_property_read_u8(dev->of_node, "ti,mode", &data->mode) == 0) {
 		if (data->mode > 3) {
 			dev_err(dev, "invalid operation mode %d\n",
@@ -500,7 +500,10 @@ static int adc128_probe(struct i2c_client *client,
 			goto error;
 		}
 	} else {
-		data->mode = 0;
+		err = i2c_smbus_read_byte_data(client, ADC128_REG_CONFIG_ADV);
+		if (err < 0)
+			goto error;
+		data->mode = (err >> 1) & ADC128_REG_MASK;
 	}
 
 	data->client = client;
-- 
2.11.0

[toc] | [prev] | [next] | [standalone]


#1552684 — [PATCH v3 2/4] hwmon: adc128d818: Implement mode selection via dt

FromAlexander Koch <mail@alexanderkoch.net>
Date2017-01-06 11:50 +0100
Subject[PATCH v3 2/4] hwmon: adc128d818: Implement mode selection via dt
Message-ID<sWAfU-w2-31@gated-at.bofh.it>
In reply to#1552680
Implement operation mode selection using the optional 'ti,mode' devicetree
property (see [1]). The ADC128D818 supports four operation modes differing
in the number and type of input readings (see datasheet, sec. 8.4.1), of
which mode 0 is the default.

We only add handling of the 'ti,mode' property here, the driver still
supports nothing else than the default mode 0.

[1] Documentation/devicetree/bindings/hwmon/adc128d818.txt

Signed-off-by: Alexander Koch <mail@alexanderkoch.net>
Acked-by: Michael Hornung <mhornung.linux@gmail.com>
---
 drivers/hwmon/adc128d818.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/hwmon/adc128d818.c b/drivers/hwmon/adc128d818.c
index ad2b47e40345..2b61936c32ff 100644
--- a/drivers/hwmon/adc128d818.c
+++ b/drivers/hwmon/adc128d818.c
@@ -28,6 +28,7 @@
 #include <linux/regulator/consumer.h>
 #include <linux/mutex.h>
 #include <linux/bitops.h>
+#include <linux/of.h>
 
 /* Addresses to scan
  * The chip also supports addresses 0x35..0x37. Don't scan those addresses
@@ -63,6 +64,7 @@ struct adc128_data {
 	struct regulator *regulator;
 	int vref;		/* Reference voltage in mV */
 	struct mutex update_lock;
+	u8 mode;		/* Operation mode */
 	bool valid;		/* true if following fields are valid */
 	unsigned long last_updated;	/* In jiffies */
 
@@ -387,6 +389,15 @@ static int adc128_init_client(struct adc128_data *data)
 	if (err)
 		return err;
 
+	/* Set operation mode, if non-default */
+	if (data->mode != 0) {
+		err = i2c_smbus_write_byte_data(client,
+						ADC128_REG_CONFIG_ADV,
+						data->mode << 1);
+		if (err)
+			return err;
+	}
+
 	/* Start monitoring */
 	err = i2c_smbus_write_byte_data(client, ADC128_REG_CONFIG, 0x01);
 	if (err)
@@ -433,6 +444,19 @@ static int adc128_probe(struct i2c_client *client,
 		data->vref = 2560;	/* 2.56V, in mV */
 	}
 
+	/* Operation mode is optional and defaults to mode 0 */
+	if (of_property_read_u8(dev->of_node, "ti,mode", &data->mode) == 0) {
+		/* Currently only mode 0 supported */
+		if (data->mode != 0) {
+			dev_err(dev, "unsupported operation mode %d\n",
+				data->mode);
+			err = -EINVAL;
+			goto error;
+		}
+	} else {
+		data->mode = 0;
+	}
+
 	data->client = client;
 	i2c_set_clientdata(client, data);
 	mutex_init(&data->update_lock);
-- 
2.11.0

[toc] | [prev] | [next] | [standalone]


#1552685 — [PATCH v3 1/4] devicetree: hwmon: Add bindings for ADC128D818

FromAlexander Koch <mail@alexanderkoch.net>
Date2017-01-06 11:50 +0100
Subject[PATCH v3 1/4] devicetree: hwmon: Add bindings for ADC128D818
Message-ID<sWAfU-w2-27@gated-at.bofh.it>
In reply to#1552680
Add bindings documentation for the ADC128D818 driver, featuring default I2C
properties along with the optional 'mode' property for chip operation mode
selection (see datasheet, sec. 8.4.1).

Signed-off-by: Alexander Koch <mail@alexanderkoch.net>
Acked-by: Michael Hornung <mhornung.linux@gmail.com>
---
 .../devicetree/bindings/hwmon/adc128d818.txt       | 39 ++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adc128d818.txt

diff --git a/Documentation/devicetree/bindings/hwmon/adc128d818.txt b/Documentation/devicetree/bindings/hwmon/adc128d818.txt
new file mode 100644
index 000000000000..db213dcc1391
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/adc128d818.txt
@@ -0,0 +1,39 @@
+TI ADC128D818 ADC System Monitor With Temperature Sensor
+--------------------------------------------------------
+
+Operation modes:
+
+ - Mode 0:  7 single-ended voltage readings (IN0-IN6),
+            1 temperature reading (internal)
+ - Mode 1:  8 single-ended voltage readings (IN0-IN7),
+            no temperature
+ - Mode 2:  4 pseudo-differential voltage readings
+              (IN0-IN1, IN3-IN2, IN4-IN5, IN7-IN6),
+            1 temperature reading (internal)
+ - Mode 3:  4 single-ended voltage readings (IN0-IN3),
+            2 pseudo-differential voltage readings
+              (IN4-IN5, IN7-IN6),
+            1 temperature reading (internal)
+
+If no operation mode is configured via device tree, the driver keeps the
+currently active chip operation mode (default is mode 0).
+
+
+Required node properties:
+
+ - compatible:  must be set to "ti,adc128d818"
+ - reg:         I2C address of the device
+
+Optional node properties:
+
+ - ti,mode:     Operation mode (see above).
+
+
+Example (operation mode 2):
+
+	adc128d818@1d {
+		compatible = "ti,adc128d818";
+		reg = <0x1d>;
+		ti,mode = <2>;
+	};
+
-- 
2.11.0

[toc] | [prev] | [next] | [standalone]


#1554944 — Re: [PATCH v3 1/4] devicetree: hwmon: Add bindings for ADC128D818

FromRob Herring <robh@kernel.org>
Date2017-01-10 06:40 +0100
SubjectRe: [PATCH v3 1/4] devicetree: hwmon: Add bindings for ADC128D818
Message-ID<sXXk5-5LU-7@gated-at.bofh.it>
In reply to#1552685
On Fri, Jan 06, 2017 at 11:38:14AM +0100, Alexander Koch wrote:
> Add bindings documentation for the ADC128D818 driver, featuring default I2C
> properties along with the optional 'mode' property for chip operation mode
> selection (see datasheet, sec. 8.4.1).
> 
> Signed-off-by: Alexander Koch <mail@alexanderkoch.net>
> Acked-by: Michael Hornung <mhornung.linux@gmail.com>
> ---
>  .../devicetree/bindings/hwmon/adc128d818.txt       | 39 ++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/hwmon/adc128d818.txt

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

[toc] | [prev] | [next] | [standalone]


#1555723

FromGuenter Roeck <linux@roeck-us.net>
Date2017-01-10 18:20 +0100
Message-ID<sY8fv-47w-1@gated-at.bofh.it>
In reply to#1552680
On Fri, Jan 06, 2017 at 11:38:13AM +0100, Alexander Koch wrote:
> The ADC128D818 offers four different chip operation modes which vary in the
> number and measurement types of the available input signals (see datasheet
> sec. 8.4.1).
> 
> The current version of the driver only supports the default chip operation
> mode (mode 0), providing seven analog values and a temperature reading.
> 
> This patch series adds support for operation modes 1-3, selectable through
> the device tree attribute 'ti,mode':
> 
>         adc1: adc128d818@1d {
>                 compatible = "ti,adc128d818";
>                 reg = <0x1d>;
>                 mode = <1>;
>         };
> 
> The changes are transparent as the driver defaults to keeping the currently
> active operation mode if no mode is specified via device tree (which is
> mode 0 on chip initialization).
> 
> 
> Changes from v2:
>  - Omit device attribute refactoring (for checkpatch.pl), as requested by
>    maintainer
>  - Add vendor prefix 'ti,' for mode property in device tree
>  - Drop size indication for mode property in device tree
>  - Preserve chip operation mode if none specified in devicetree
>  - Fix missing '\n' in dev_err() calls
> 
> Changes from v1:
>  - Add bindings document as first patch
>  - Preserve logical atomicity of code changes
>  - Improve sysfs device node handling (use is_visible() instead of
>    duplicate attribute list)
>  - Add trivial code refactoring stage for checkpatch.pl to succeed
> 
> 
> Alexander Koch (4):
>   devicetree: hwmon: Add bindings for ADC128D818
>   hwmon: adc128d818: Implement mode selection via dt
>   hwmon: adc128d818: Support operation modes 1-3
>   hwmon: adc128d818: Preserve operation mode
> 
>  .../devicetree/bindings/hwmon/adc128d818.txt       |  39 ++++++
>  drivers/hwmon/adc128d818.c                         | 147 +++++++++++++++------
>  2 files changed, 149 insertions(+), 37 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/hwmon/adc128d818.txt
> 
Series applied to -next.

Thanks,
Guenter

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web