linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lm87: Allow LM87_REG_CHANNEL_MODE to be set via DT
@ 2016-11-10 17:19 Jason Gunthorpe
  2016-11-10 23:47 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Gunthorpe @ 2016-11-10 17:19 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: devicetree, linux-kernel, linux-hwmon

This compliments the existing scheme that lets it be set via
platform_data.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
---
 Documentation/devicetree/bindings/hwmon/lm87.txt | 27 ++++++++++++++++++++++++
 drivers/hwmon/lm87.c                             |  8 ++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/lm87.txt

diff --git a/Documentation/devicetree/bindings/hwmon/lm87.txt b/Documentation/devicetree/bindings/hwmon/lm87.txt
new file mode 100644
index 00000000000000..4ea2646ce8d2f0
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/lm87.txt
@@ -0,0 +1,27 @@
+* LM87 I2C Temperature and Fan sensor
+
+Required properties:
+- compatible: should contain one of
+		* "national,lm87"
+		* "ti,lm87"
+
+Optional properties:
+- channel-mode: Write the specified value to register 0x16. If not specified
+                the driver will read the value from the chip at startup.
+
+		The value controls how the driver operates certain multi-use
+		pins, eg bit 2 will select between temp_input3 or
+		in0&in5 operation.
+
+See Documentation/devicetree/bindings/i2c/i2c.txt for more required and
+optional properties.
+
+Example:
+
+i2c_master {
+	temperature-sensor@0 {
+		compatible = "ti,lm87";
+		channel-mode = <0x4>;
+		reg = <0>;
+	};
+};
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index 81cb898245a107..ccc0c913b4534e 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -853,9 +853,15 @@ static void lm87_restore_config(void *arg)
 static int lm87_init_client(struct i2c_client *client)
 {
 	struct lm87_data *data = i2c_get_clientdata(client);
+	u32 channel;
 	int rc;
 
-	if (dev_get_platdata(&client->dev)) {
+	if (client->dev.of_node &&
+	    !of_property_read_u32(client->dev.of_node, "channel-mode",
+				  &channel)) {
+		data->channel = channel;
+		lm87_write_value(client, LM87_REG_CHANNEL_MODE, data->channel);
+	} else if (dev_get_platdata(&client->dev)) {
 		data->channel = *(u8 *)dev_get_platdata(&client->dev);
 		lm87_write_value(client,
 				 LM87_REG_CHANNEL_MODE, data->channel);
-- 
2.7.4

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

* Re: [PATCH] lm87: Allow LM87_REG_CHANNEL_MODE to be set via DT
  2016-11-10 17:19 [PATCH] lm87: Allow LM87_REG_CHANNEL_MODE to be set via DT Jason Gunthorpe
@ 2016-11-10 23:47 ` Guenter Roeck
  2016-11-11  0:31   ` Jason Gunthorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2016-11-10 23:47 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: devicetree, linux-kernel, linux-hwmon

On Thu, Nov 10, 2016 at 10:19:36AM -0700, Jason Gunthorpe wrote:
> This compliments the existing scheme that lets it be set via
> platform_data.
> 
> Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>

I would prefer https://www.spinics.net/lists/devicetree/msg148819.html
which appears to address the same problem and is less cryptic.

NACK unless someone convinces me otherwise.

Guenter

> ---
>  Documentation/devicetree/bindings/hwmon/lm87.txt | 27 ++++++++++++++++++++++++
>  drivers/hwmon/lm87.c                             |  8 ++++++-
>  2 files changed, 34 insertions(+), 1 deletion(-)
>  create mode 100644 Documentation/devicetree/bindings/hwmon/lm87.txt
> 
> diff --git a/Documentation/devicetree/bindings/hwmon/lm87.txt b/Documentation/devicetree/bindings/hwmon/lm87.txt
> new file mode 100644
> index 00000000000000..4ea2646ce8d2f0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/hwmon/lm87.txt
> @@ -0,0 +1,27 @@
> +* LM87 I2C Temperature and Fan sensor
> +
> +Required properties:
> +- compatible: should contain one of
> +		* "national,lm87"
> +		* "ti,lm87"
> +
> +Optional properties:
> +- channel-mode: Write the specified value to register 0x16. If not specified
> +                the driver will read the value from the chip at startup.
> +
> +		The value controls how the driver operates certain multi-use
> +		pins, eg bit 2 will select between temp_input3 or
> +		in0&in5 operation.
> +
> +See Documentation/devicetree/bindings/i2c/i2c.txt for more required and
> +optional properties.
> +
> +Example:
> +
> +i2c_master {
> +	temperature-sensor@0 {
> +		compatible = "ti,lm87";
> +		channel-mode = <0x4>;
> +		reg = <0>;
> +	};
> +};
> diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
> index 81cb898245a107..ccc0c913b4534e 100644
> --- a/drivers/hwmon/lm87.c
> +++ b/drivers/hwmon/lm87.c
> @@ -853,9 +853,15 @@ static void lm87_restore_config(void *arg)
>  static int lm87_init_client(struct i2c_client *client)
>  {
>  	struct lm87_data *data = i2c_get_clientdata(client);
> +	u32 channel;
>  	int rc;
>  
> -	if (dev_get_platdata(&client->dev)) {
> +	if (client->dev.of_node &&
> +	    !of_property_read_u32(client->dev.of_node, "channel-mode",
> +				  &channel)) {
> +		data->channel = channel;
> +		lm87_write_value(client, LM87_REG_CHANNEL_MODE, data->channel);
> +	} else if (dev_get_platdata(&client->dev)) {
>  		data->channel = *(u8 *)dev_get_platdata(&client->dev);
>  		lm87_write_value(client,
>  				 LM87_REG_CHANNEL_MODE, data->channel);
> -- 
> 2.7.4

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

* Re: [PATCH] lm87: Allow LM87_REG_CHANNEL_MODE to be set via DT
  2016-11-10 23:47 ` Guenter Roeck
@ 2016-11-11  0:31   ` Jason Gunthorpe
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2016-11-11  0:31 UTC (permalink / raw)
  To: Guenter Roeck, Mahoda Ratnayaka; +Cc: devicetree, linux-kernel, linux-hwmon

On Thu, Nov 10, 2016 at 03:47:07PM -0800, Guenter Roeck wrote:
> On Thu, Nov 10, 2016 at 10:19:36AM -0700, Jason Gunthorpe wrote:
> > This compliments the existing scheme that lets it be set via
> > platform_data.
> > 
> > Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
> 
> I would prefer https://www.spinics.net/lists/devicetree/msg148819.html
> which appears to address the same problem and is less cryptic.

Is there a patch someplace that implements that proposed DT binding? I
couldn't find anything.

> NACK unless someone convinces me otherwise.

*shrug* both styles of definition seem to be used in various device
tree bindings.

The downside with Mahoda's proposal is that it only covers 3 of the 8
configuration bits, and will require alot of code for parsing. It
seems really clunky, and why is a regulator involved to set the A/D
sensitivity? Weird.

But I only need has-temp3, so if a patch appears please cc me and I'll
review it here..

Regards,
Jason

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

end of thread, other threads:[~2016-11-11  0:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-10 17:19 [PATCH] lm87: Allow LM87_REG_CHANNEL_MODE to be set via DT Jason Gunthorpe
2016-11-10 23:47 ` Guenter Roeck
2016-11-11  0:31   ` Jason Gunthorpe

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