linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: (ads7828) Make sample interval configurable
@ 2015-01-16 12:05 Robert Rosengren
  2015-01-16 14:52 ` Guenter Roeck
  2015-01-16 20:30 ` Guenter Roeck
  0 siblings, 2 replies; 25+ messages in thread
From: Robert Rosengren @ 2015-01-16 12:05 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, lm-sensors
  Cc: linux-kernel, Robert Rosengren, Johan Adolfsson

The default sample interval may be too slow for certain clients. This
patch makes it configurable via the platform_data.

Signed-off-by: Robert Rosengren <robert.rosengren@axis.com>
Signed-off-by: Johan Adolfsson <johan.adolfsson@axis.com>
---
 drivers/hwmon/ads7828.c               | 11 ++++++++++-
 include/linux/platform_data/ads7828.h |  2 ++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index a622d40..fd5eabf7 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -45,6 +45,9 @@
 #define ADS7828_EXT_VREF_MV_MIN	50	/* External vref min value 0.05V */
 #define ADS7828_EXT_VREF_MV_MAX	5250	/* External vref max value 5.25V */
 
+/* Default sample interval */
+#define ADS7828_SAMPLE_INTERVAL (HZ + HZ / 2)
+
 /* List of supported devices */
 enum ads7828_chips { ads7828, ads7830 };
 
@@ -58,6 +61,7 @@ struct ads7828_data {
 	bool diff_input;		/* Differential input */
 	bool ext_vref;			/* External voltage reference */
 	unsigned int vref_mv;		/* voltage reference value */
+	unsigned int sample_interval;   /* sample interval */
 	u8 cmd_byte;			/* Command byte without channel bits */
 	unsigned int lsb_resol;		/* Resolution of the ADC sample LSB */
 	s32 (*read_channel)(const struct i2c_client *client, u8 command);
@@ -77,7 +81,7 @@ static struct ads7828_data *ads7828_update_device(struct device *dev)
 
 	mutex_lock(&data->update_lock);
 
-	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+	if (time_after(jiffies, data->last_updated + data->sample_interval)
 			|| !data->valid) {
 		unsigned int ch;
 		dev_dbg(&client->dev, "Starting ads7828 update\n");
@@ -147,6 +151,8 @@ static int ads7828_probe(struct i2c_client *client,
 		data->ext_vref = pdata->ext_vref;
 		if (data->ext_vref)
 			data->vref_mv = pdata->vref_mv;
+		if (pdata->sample_interval)
+			data->sample_interval = pdata->sample_interval;
 	}
 
 	/* Bound Vref with min/max values if it was provided */
@@ -157,6 +163,9 @@ static int ads7828_probe(struct i2c_client *client,
 	else
 		data->vref_mv = ADS7828_INT_VREF_MV;
 
+	if (!data->sample_interval)
+		data->sample_interval = ADS7828_SAMPLE_INTERVAL;
+
 	/* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */
 	if (id->driver_data == ads7828) {
 		data->lsb_resol = DIV_ROUND_CLOSEST(data->vref_mv * 1000, 4096);
diff --git a/include/linux/platform_data/ads7828.h b/include/linux/platform_data/ads7828.h
index 3245f45..bdae0bb 100644
--- a/include/linux/platform_data/ads7828.h
+++ b/include/linux/platform_data/ads7828.h
@@ -19,11 +19,13 @@
  * @diff_input:		Differential input mode.
  * @ext_vref:		Use an external voltage reference.
  * @vref_mv:		Voltage reference value, if external.
+ * @sample_interval:	Sample interval.
  */
 struct ads7828_platform_data {
 	bool diff_input;
 	bool ext_vref;
 	unsigned int vref_mv;
+	unsigned int sample_interval;
 };
 
 #endif /* _PDATA_ADS7828_H */
-- 
2.1.4


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

* Re: [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-16 12:05 [PATCH] hwmon: (ads7828) Make sample interval configurable Robert Rosengren
@ 2015-01-16 14:52 ` Guenter Roeck
  2015-01-16 18:30   ` [lm-sensors] " Guenter Roeck
  2015-01-16 20:30 ` Guenter Roeck
  1 sibling, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2015-01-16 14:52 UTC (permalink / raw)
  To: Robert Rosengren, Jean Delvare, lm-sensors
  Cc: linux-kernel, Robert Rosengren, Johan Adolfsson

On 01/16/2015 04:05 AM, Robert Rosengren wrote:
> The default sample interval may be too slow for certain clients. This
> patch makes it configurable via the platform_data.
>
> Signed-off-by: Robert Rosengren <robert.rosengren@axis.com>
> Signed-off-by: Johan Adolfsson <johan.adolfsson@axis.com>

I am basically fine with the patch, though I would prefer replacing
the entire update handling and chip access with regmap. Would you be
interested in doing that ?

Thanks,
Guenter


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-16 14:52 ` Guenter Roeck
@ 2015-01-16 18:30   ` Guenter Roeck
  2015-01-19 11:14     ` SV: " Robert Rosengren
  2015-01-27  7:59     ` Robert Rosengren
  0 siblings, 2 replies; 25+ messages in thread
From: Guenter Roeck @ 2015-01-16 18:30 UTC (permalink / raw)
  To: Robert Rosengren, Jean Delvare, lm-sensors
  Cc: Johan Adolfsson, Robert Rosengren, linux-kernel

On Fri, Jan 16, 2015 at 06:52:06AM -0800, Guenter Roeck wrote:
> On 01/16/2015 04:05 AM, Robert Rosengren wrote:
> >The default sample interval may be too slow for certain clients. This
> >patch makes it configurable via the platform_data.
> >
> >Signed-off-by: Robert Rosengren <robert.rosengren@axis.com>
> >Signed-off-by: Johan Adolfsson <johan.adolfsson@axis.com>
> 
> I am basically fine with the patch, though I would prefer replacing
> the entire update handling and chip access with regmap. Would you be
> interested in doing that ?
> 
I sent a couple of patches a minute ago which should take care of the issue.
Would be great if you can test it.

Thanks,
Guenter

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

* Re: [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-16 12:05 [PATCH] hwmon: (ads7828) Make sample interval configurable Robert Rosengren
  2015-01-16 14:52 ` Guenter Roeck
@ 2015-01-16 20:30 ` Guenter Roeck
  1 sibling, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2015-01-16 20:30 UTC (permalink / raw)
  To: Robert Rosengren
  Cc: Jean Delvare, lm-sensors, linux-kernel, Robert Rosengren,
	Johan Adolfsson

On Fri, Jan 16, 2015 at 01:05:22PM +0100, Robert Rosengren wrote:
> The default sample interval may be too slow for certain clients. This
> patch makes it configurable via the platform_data.
> 
> Signed-off-by: Robert Rosengren <robert.rosengren@axis.com>
> Signed-off-by: Johan Adolfsson <johan.adolfsson@axis.com>

Robert,

can you send me the output of i2cdump for this chip ? I would like
to write a module test for the driver.

Thanks,
Guenter

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

* SV: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-16 18:30   ` [lm-sensors] " Guenter Roeck
@ 2015-01-19 11:14     ` Robert Rosengren
  2015-01-27  7:59     ` Robert Rosengren
  1 sibling, 0 replies; 25+ messages in thread
From: Robert Rosengren @ 2015-01-19 11:14 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare, lm-sensors; +Cc: Johan Adolfsson, linux-kernel


> On Fri, Jan 16, 2015 at 06:52:06AM -0800, Guenter Roeck wrote:
> > I am basically fine with the patch, though I would prefer replacing
> > the entire update handling and chip access with regmap. Would you be
> > interested in doing that ?
> >
> I sent a couple of patches a minute ago which should take care of the issue.
> Would be great if you can test it.
>
> Thanks,
> Guenter

OK, great. I will look into your patch next week, since I'm currently out of office.

BR, 
Robert

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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-16 18:30   ` [lm-sensors] " Guenter Roeck
  2015-01-19 11:14     ` SV: " Robert Rosengren
@ 2015-01-27  7:59     ` Robert Rosengren
  2015-01-27 10:37       ` Jean Delvare
                         ` (3 more replies)
  1 sibling, 4 replies; 25+ messages in thread
From: Robert Rosengren @ 2015-01-27  7:59 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare, lm-sensors; +Cc: Johan Adolfsson, linux-kernel

On 01/16/2015 07:30 PM, Guenter Roeck wrote:
> I sent a couple of patches a minute ago which should take care of the issue.
> Would be great if you can test it.
I applied the v2 versions of the patches for a quick test, but it was 
not successful. Haven't done any further investigation on what the 
problem might be, but when trying to read the sysfs driver I get "read 
error: No such device or address".

The sysfs path have moved with the REGMAP settings, from 
/sys/bus/i2c/devices/<x>/in0_input to 
/sys/bus/i2c/devices/<x>/hwmon/hwmon0/in0_input.

Any ideas? Haven't had REGMAP configured in my kernel earlier, might it 
be some specific configuration I miss?

BR,
Robert

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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-27  7:59     ` Robert Rosengren
@ 2015-01-27 10:37       ` Jean Delvare
  2015-01-27 14:23         ` Guenter Roeck
  2015-01-27 14:07       ` Guenter Roeck
                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 25+ messages in thread
From: Jean Delvare @ 2015-01-27 10:37 UTC (permalink / raw)
  To: Robert Rosengren; +Cc: Guenter Roeck, lm-sensors, Johan Adolfsson, linux-kernel

Hi Robert,

Le Tuesday 27 January 2015 à 08:59 +0100, Robert Rosengren a écrit :
> On 01/16/2015 07:30 PM, Guenter Roeck wrote:
> > I sent a couple of patches a minute ago which should take care of the issue.
> > Would be great if you can test it.
> I applied the v2 versions of the patches for a quick test, but it was 
> not successful. Haven't done any further investigation on what the 
> problem might be, but when trying to read the sysfs driver I get "read 
> error: No such device or address".
> 
> The sysfs path have moved with the REGMAP settings, from 
> /sys/bus/i2c/devices/<x>/in0_input to 
> /sys/bus/i2c/devices/<x>/hwmon/hwmon0/in0_input.

This is expected, shouldn't be an issue if you are using a
libsensors-based application with a recent enough version of libsensors.

> Any ideas? Haven't had REGMAP configured in my kernel earlier, might it 
> be some specific configuration I miss?

How are you testing/reading exactly?

-- 
Jean Delvare
SUSE L3 Support


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-27  7:59     ` Robert Rosengren
  2015-01-27 10:37       ` Jean Delvare
@ 2015-01-27 14:07       ` Guenter Roeck
  2015-01-27 19:54         ` Robert Rosengren
  2015-01-27 14:26       ` Guenter Roeck
  2015-01-27 16:37       ` Guenter Roeck
  3 siblings, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2015-01-27 14:07 UTC (permalink / raw)
  To: Robert Rosengren, Jean Delvare, lm-sensors; +Cc: Johan Adolfsson, linux-kernel

On 01/26/2015 11:59 PM, Robert Rosengren wrote:
> On 01/16/2015 07:30 PM, Guenter Roeck wrote:
>> I sent a couple of patches a minute ago which should take care of the issue.
>> Would be great if you can test it.
> I applied the v2 versions of the patches for a quick test, but it was not successful. Haven't done any further investigation on what the problem might be, but when trying to read the sysfs driver I get "read error: No such device or address".
>
> The sysfs path have moved with the REGMAP settings, from /sys/bus/i2c/devices/<x>/in0_input to /sys/bus/i2c/devices/<x>/hwmon/hwmon0/in0_input.
>
> Any ideas? Haven't had REGMAP configured in my kernel earlier, might it be some specific configuration I miss?
>

Did you configure REGMAP ? That would now be necessary.
The "official" sysfs path would be /sys/class/hwmon/hwmonX (hwmon0 in your case).

Guenter


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-27 10:37       ` Jean Delvare
@ 2015-01-27 14:23         ` Guenter Roeck
  0 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2015-01-27 14:23 UTC (permalink / raw)
  To: Jean Delvare, Robert Rosengren; +Cc: lm-sensors, Johan Adolfsson, linux-kernel

On 01/27/2015 02:37 AM, Jean Delvare wrote:
> Hi Robert,
>
> Le Tuesday 27 January 2015 à 08:59 +0100, Robert Rosengren a écrit :
>> On 01/16/2015 07:30 PM, Guenter Roeck wrote:
>>> I sent a couple of patches a minute ago which should take care of the issue.
>>> Would be great if you can test it.
>> I applied the v2 versions of the patches for a quick test, but it was
>> not successful. Haven't done any further investigation on what the
>> problem might be, but when trying to read the sysfs driver I get "read
>> error: No such device or address".
>>
>> The sysfs path have moved with the REGMAP settings, from
>> /sys/bus/i2c/devices/<x>/in0_input to
>> /sys/bus/i2c/devices/<x>/hwmon/hwmon0/in0_input.
>
> This is expected, shouldn't be an issue if you are using a
> libsensors-based application with a recent enough version of libsensors.
>

Odd though, thinking about it, since the move was done with a separate
patch, not with the regmap patch.

Guenter


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-27  7:59     ` Robert Rosengren
  2015-01-27 10:37       ` Jean Delvare
  2015-01-27 14:07       ` Guenter Roeck
@ 2015-01-27 14:26       ` Guenter Roeck
  2015-01-27 16:37       ` Guenter Roeck
  3 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2015-01-27 14:26 UTC (permalink / raw)
  To: Robert Rosengren, Jean Delvare, lm-sensors; +Cc: Johan Adolfsson, linux-kernel

On 01/26/2015 11:59 PM, Robert Rosengren wrote:
> On 01/16/2015 07:30 PM, Guenter Roeck wrote:
>> I sent a couple of patches a minute ago which should take care of the issue.
>> Would be great if you can test it.
> I applied the v2 versions of the patches for a quick test, but it was not successful. Haven't done any further investigation on what the problem might be, but when trying to read the sysfs driver I get "read error: No such device or address".
>
> The sysfs path have moved with the REGMAP settings, from /sys/bus/i2c/devices/<x>/in0_input to /sys/bus/i2c/devices/<x>/hwmon/hwmon0/in0_input.
>
> Any ideas? Haven't had REGMAP configured in my kernel earlier, might it be some specific configuration I miss?
>

Robert,

Another thought: What is your kernel version, and what is your i2c controller ?

SMBus support was added to regmap only recently, so if your controller only
supports SMBus (not raw i2c transactions), and you have an older kernel,
this might not work. The driver should fail to instantiate in that case,
though, if I recall correctly.

Thanks,
Guenter


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-27  7:59     ` Robert Rosengren
                         ` (2 preceding siblings ...)
  2015-01-27 14:26       ` Guenter Roeck
@ 2015-01-27 16:37       ` Guenter Roeck
  3 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2015-01-27 16:37 UTC (permalink / raw)
  To: Robert Rosengren; +Cc: Jean Delvare, lm-sensors, Johan Adolfsson, linux-kernel

On Tue, Jan 27, 2015 at 08:59:35AM +0100, Robert Rosengren wrote:
> On 01/16/2015 07:30 PM, Guenter Roeck wrote:
> >I sent a couple of patches a minute ago which should take care of the issue.
> >Would be great if you can test it.
> I applied the v2 versions of the patches for a quick test, but it was not
> successful. Haven't done any further investigation on what the problem might
> be, but when trying to read the sysfs driver I get "read error: No such
> device or address".
> 
> The sysfs path have moved with the REGMAP settings, from
> /sys/bus/i2c/devices/<x>/in0_input to
> /sys/bus/i2c/devices/<x>/hwmon/hwmon0/in0_input.
> 
> Any ideas? Haven't had REGMAP configured in my kernel earlier, might it be
> some specific configuration I miss?
> 

My module test script at github.com/groeck/module-tests.git passes. Only
downside is that it doesn't use real register values since I do not have
a register dump.

I requested samples for both ads2828 and ads2830, so I should be able
to test the code myself on real hardware in a couple of days.

Guenter

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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-27 14:07       ` Guenter Roeck
@ 2015-01-27 19:54         ` Robert Rosengren
  2015-01-27 20:05           ` Guenter Roeck
  0 siblings, 1 reply; 25+ messages in thread
From: Robert Rosengren @ 2015-01-27 19:54 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare, lm-sensors; +Cc: Johan Adolfsson, linux-kernel

Guenter and Jean, 

To sum up, my problems was related my kernel and hardware configuration, and it now works. Many thanks for your input!

However, the values retrieved from hwmon sysfs is not the same as before the regmap patch. Guenter, the byte swap for the regval retrieved by regmap_read. In what order is the bits returned from that function, because it seems as if I disabled that code I get values as I expect (i.e. before the regmap patch).

BR,
Robert


> On 01/26/2015 11:59 PM, Robert Rosengren wrote:
>> On 01/16/2015 07:30 PM, Guenter Roeck wrote:
>>> I sent a couple of patches a minute ago which should take care of the issue.
>>> Would be great if you can test it.
>> I applied the v2 versions of the patches for a quick test, but it was not successful. Haven't done any further investigation on what the problem might be, but when trying to read the sysfs driver I get "read error: No such device or address".
>>
>> The sysfs path have moved with the REGMAP settings, from /sys/bus/i2c/devices/<x>/in0_input to /sys/bus/i2c/devices/<x>/hwmon/hwmon0/in0_input.
>>
>> Any ideas? Haven't had REGMAP configured in my kernel earlier, might it be some specific configuration I miss?
>>
>
> Did you configure REGMAP ? That would now be necessary.
> The "official" sysfs path would be /sys/class/hwmon/hwmonX (hwmon0 in your case).
>
> Guenter


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-27 19:54         ` Robert Rosengren
@ 2015-01-27 20:05           ` Guenter Roeck
  2015-01-27 22:34             ` Jean Delvare
  0 siblings, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2015-01-27 20:05 UTC (permalink / raw)
  To: Robert Rosengren; +Cc: Jean Delvare, lm-sensors, Johan Adolfsson, linux-kernel

On Tue, Jan 27, 2015 at 08:54:34PM +0100, Robert Rosengren wrote:
> Guenter and Jean, 
> 
> To sum up, my problems was related my kernel and hardware configuration, and it now works. Many thanks for your input!
> 
> However, the values retrieved from hwmon sysfs is not the same as before the regmap patch. Guenter, the byte swap for the regval retrieved by regmap_read. In what order is the bits returned from that function, because it seems as if I disabled that code I get values as I expect (i.e. before the regmap patch).
> 
Trying to understand. Are you saying everything works as expected
if you keep byte_swap set to false ?

That might well be, though it might mean that regmap has a bug
in how it treats i2c word read operations. I'll have to look into it 
some more.

Can you send me your diffs on top of mine to help me understand what
you changed ?

Thanks,
Guenter

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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-27 20:05           ` Guenter Roeck
@ 2015-01-27 22:34             ` Jean Delvare
  2015-01-28  4:06               ` Guenter Roeck
  0 siblings, 1 reply; 25+ messages in thread
From: Jean Delvare @ 2015-01-27 22:34 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Robert Rosengren, lm-sensors, Johan Adolfsson, linux-kernel

On Tue, 27 Jan 2015 12:05:53 -0800, Guenter Roeck wrote:
> On Tue, Jan 27, 2015 at 08:54:34PM +0100, Robert Rosengren wrote:
> > Guenter and Jean, 
> > 
> > To sum up, my problems was related my kernel and hardware configuration, and it now works. Many thanks for your input!
> > 
> > However, the values retrieved from hwmon sysfs is not the same as before the regmap patch. Guenter, the byte swap for the regval retrieved by regmap_read. In what order is the bits returned from that function, because it seems as if I disabled that code I get values as I expect (i.e. before the regmap patch).
> > 
> Trying to understand. Are you saying everything works as expected
> if you keep byte_swap set to false ?
> 
> That might well be, though it might mean that regmap has a bug
> in how it treats i2c word read operations. I'll have to look into it 
> some more.

Remember that SMBus specifies that the LSB comes first (and i2c-core
implement things that way) while real I2C devices typically send the MSB
first. This has always caused confusion. This is why a lot of drivers
need byte-swapping.

-- 
Jean Delvare
SUSE L3 Support

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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-27 22:34             ` Jean Delvare
@ 2015-01-28  4:06               ` Guenter Roeck
       [not found]                 ` <54C87F3C.2020105@axis.com>
  0 siblings, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2015-01-28  4:06 UTC (permalink / raw)
  To: Jean Delvare; +Cc: Robert Rosengren, lm-sensors, Johan Adolfsson, linux-kernel

On 01/27/2015 02:34 PM, Jean Delvare wrote:
> On Tue, 27 Jan 2015 12:05:53 -0800, Guenter Roeck wrote:
>> On Tue, Jan 27, 2015 at 08:54:34PM +0100, Robert Rosengren wrote:
>>> Guenter and Jean,
>>>
>>> To sum up, my problems was related my kernel and hardware configuration, and it now works. Many thanks for your input!
>>>
>>> However, the values retrieved from hwmon sysfs is not the same as before the regmap patch. Guenter, the byte swap for the regval retrieved by regmap_read. In what order is the bits returned from that function, because it seems as if I disabled that code I get values as I expect (i.e. before the regmap patch).
>>>
>> Trying to understand. Are you saying everything works as expected
>> if you keep byte_swap set to false ?
>>
>> That might well be, though it might mean that regmap has a bug
>> in how it treats i2c word read operations. I'll have to look into it
>> some more.
>
> Remember that SMBus specifies that the LSB comes first (and i2c-core
> implement things that way) while real I2C devices typically send the MSB
> first. This has always caused confusion. This is why a lot of drivers
> need byte-swapping.
>

regmap specifies "normal" i2c accesses as MSB first. When SMBus accesses
are used, it specifies LSB first. I guess that means that regmap assumes
the more common case of MSB first, meaning the driver would not need a byte
swap since the chip reports data with MSB first.

I just hope I interpret it correctly this time.

There is also a configuration flag "val_format_endian" which can be set to
REGMAP_ENDIAN_BIG or REGMAP_ENDIAN_LITTLE. Maybe that can be used as well
if needed. Either case I'll wait for the samples before I send an updated
version of the patch.

Guenter


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
       [not found]                 ` <54C87F3C.2020105@axis.com>
@ 2015-01-28  6:28                   ` Robert Rosengren
  2015-01-28 14:50                   ` Guenter Roeck
  1 sibling, 0 replies; 25+ messages in thread
From: Robert Rosengren @ 2015-01-28  6:28 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare; +Cc: lm-sensors, Johan Adolfsson, linux-kernel

My previous mail got blocked by mailing lists for some reasons, so 
trying once more. I apologize if spamming.

On 01/28/2015 07:18 AM, Robert Rosengren wrote:
> On 01/28/2015 05:06 AM, Guenter Roeck wrote:
>> On 01/27/2015 02:34 PM, Jean Delvare wrote:
>>> >On Tue, 27 Jan 2015 12:05:53 -0800, Guenter Roeck wrote:
>>>> >>On Tue, Jan 27, 2015 at 08:54:34PM +0100, Robert Rosengren wrote:
>>>>> >>>Guenter and Jean,
>>>>> >>>
>>>>> >>>To sum up, my problems was related my kernel and hardware configuration, and it now works. Many thanks for your input!
>>>>> >>>
>>>>> >>>However, the values retrieved from hwmon sysfs is not the same as before the regmap patch. Guenter, the byte swap for the regval retrieved by regmap_read. In what order is the bits returned from that function, because it seems as if I disabled that code I get values as I expect (i.e. before the regmap patch).
>>>>> >>>
>>>> >>Trying to understand. Are you saying everything works as expected
>>>> >>if you keep byte_swap set to false ?
> Yes it works as expected, i.e. I can get values from sysfs. The 
> problems I experienced was actually due to moving from an old 
> ads7828-implementation where specific i2c addresses where scanned from 
> the driver, and I first missed to set the correct i2c address for the 
> new driver in the board info.
>
>>>> >>
>>>> >>That might well be, though it might mean that regmap has a bug
>>>> >>in how it treats i2c word read operations. I'll have to look into it
>>>> >>some more.
>>> >
>>> >Remember that SMBus specifies that the LSB comes first (and i2c-core
>>> >implement things that way) while real I2C devices typically send the MSB
>>> >first. This has always caused confusion. This is why a lot of drivers
>>> >need byte-swapping.
>>> >
>> regmap specifies "normal" i2c accesses as MSB first. When SMBus accesses
>> are used, it specifies LSB first. I guess that means that regmap assumes
>> the more common case of MSB first, meaning the driver would not need a byte
>> swap since the chip reports data with MSB first.
>>
>> I just hope I interpret it correctly this time.
>>
>> There is also a configuration flag "val_format_endian" which can be set to
>> REGMAP_ENDIAN_BIG or REGMAP_ENDIAN_LITTLE. Maybe that can be used as well
>> if needed. Either case I'll wait for the samples before I send an updated
>> version of the patch.
>>
>> Guenter
>>
> I tested the driver on 3.15 version of the kernel. Having looked in 
> the git log of regmap.c and regmap-i2c.c, there has been some 
> endianess-related patches going into the kernel in newer versions. 
> Maybe that is the reason for me seeing this problem? I will try to 
> look into that further.
>
> I my test I only disabled following two lines of code
> +	if (data->byte_swap)
> +		regval = swab16(regval);
>
> BR, Robert
>


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
       [not found]                 ` <54C87F3C.2020105@axis.com>
  2015-01-28  6:28                   ` Robert Rosengren
@ 2015-01-28 14:50                   ` Guenter Roeck
  2015-01-29  7:00                     ` Robert Rosengren
  1 sibling, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2015-01-28 14:50 UTC (permalink / raw)
  To: Robert Rosengren, Jean Delvare; +Cc: lm-sensors, Johan Adolfsson, linux-kernel

On 01/27/2015 10:18 PM, Robert Rosengren wrote:

>>
> I tested the driver on 3.15 version of the kernel. Having looked in the git log of regmap.c and regmap-i2c.c, there has been some endianess-related patches going into the kernel in newer versions. Maybe that is the reason for me seeing this problem? I will try to look into that further.
>
> I my test I only disabled following two lines of code
>
> +	if (data->byte_swap)
> +		regval = swab16(regval);
>
Can you possibly send me the output from i2cdump ? That might help figuring out what is going on.

Thanks,
Guenter


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-28 14:50                   ` Guenter Roeck
@ 2015-01-29  7:00                     ` Robert Rosengren
  2015-01-29  7:05                       ` Guenter Roeck
  0 siblings, 1 reply; 25+ messages in thread
From: Robert Rosengren @ 2015-01-29  7:00 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare; +Cc: lm-sensors, Johan Adolfsson, linux-kernel

On 01/28/2015 03:50 PM, Guenter Roeck wrote:
> Can you possibly send me the output from i2cdump ? That might help figuring out what is going on.
I don't have i2cdump (I suppose that you mean the lm-sensors tool) 
available for my hardware. I'll give it a go to compile it...

BR,
Robert

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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-29  7:00                     ` Robert Rosengren
@ 2015-01-29  7:05                       ` Guenter Roeck
  2015-01-29 12:07                         ` Robert Rosengren
  0 siblings, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2015-01-29  7:05 UTC (permalink / raw)
  To: Robert Rosengren, Jean Delvare; +Cc: lm-sensors, Johan Adolfsson, linux-kernel

On 01/28/2015 11:00 PM, Robert Rosengren wrote:
> On 01/28/2015 03:50 PM, Guenter Roeck wrote:
>> Can you possibly send me the output from i2cdump ? That might help figuring out what is going on.
> I don't have i2cdump (I suppose that you mean the lm-sensors tool) available for my hardware. I'll give it a go to compile it...
>

Ah, don't bother then. I should hopefully get the samples in a couple of days.

Is your hardware big endian or little endian ?

Thanks,
Guenter


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-29  7:05                       ` Guenter Roeck
@ 2015-01-29 12:07                         ` Robert Rosengren
  2015-01-29 14:10                           ` Guenter Roeck
  2015-01-29 19:30                           ` Guenter Roeck
  0 siblings, 2 replies; 25+ messages in thread
From: Robert Rosengren @ 2015-01-29 12:07 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare; +Cc: lm-sensors, Johan Adolfsson, linux-kernel

On 01/29/2015 08:05 AM, Guenter Roeck wrote:
> Ah, don't bother then. I should hopefully get the samples in a couple of days.

i2cdump was easily built, so here is the output:
      0,8  1,9  2,a  3,b  4,c  5,d  6,e  7,f
00: 1301 1301 1301 1301 1301 1301 1301 1301
08: 4101 6901 6a01 6901 6901 6901 6901 6901
10: 0200 0100 0100 0100 0100 0100 0100 0100
18: 0100 0100 0100 0100 0100 0100 0100 0100
20: 0200 0100 0100 0100 0100 0100 0100 0100
28: 0100 0100 0100 0100 0100 0100 0100 0100
30: 0200 0100 0100 0100 0100 0100 0100 0100
38: 0100 0100 0100 0100 0100 0100 0100 0100
40: 0000 0000 0000 0000 0000 0000 0000 0000
48: 0000 0000 0000 0000 0000 0000 0000 0000
50: 0200 0100 0100 0100 0100 0100 0100 0100
58: 0100 0100 0100 0100 0100 0100 0200 0100
60: 0100 0100 0100 0100 0100 0100 0100 0100
68: 0100 0100 0100 0100 0100 0100 0100 0100
70: 0200 0100 0100 0100 0100 0100 0100 0100
78: 0100 0100 0100 0100 0100 0100 0100 0100
80: 6501 2401 1701 1401 1301 1301 1301 1301
88: 4201 6901 6901 6901 6901 6901 6901 6901
90: 0200 0100 0100 0100 0100 0100 0100 0100
98: 0100 0100 0100 0100 0100 0100 0100 0100
a0: 6701 2501 1901 1601 1501 1501 1501 1501
a8: 4401 6c01 6c01 6c01 6c01 6c01 6c01 6c01
b0: 0200 0100 0100 0100 0100 0100 0100 0100
b8: 0100 0100 0100 0100 0100 0100 0100 0100
c0: 0200 0100 0100 0100 0100 0100 0100 0100
c8: 0100 0100 0100 0100 0100 0100 0100 0100
d0: 0200 0100 0100 0100 0100 0100 0100 0100
d8: 0100 0100 0100 0100 0100 0100 0100 0100
e0: 6701 2801 1b01 1701 1601 1501 1501 1501
e8: 4401 6c01 6c01 6c01 6c01 6c01 6c01 6c01
f0: 0200 0100 0100 0100 0100 0100 0100 0100
f8: 0100 0100 0100 0100 0100 0100 0100 0100

I checked the value at 0x84 (channel 0, and using single-ended and 
external reference). I got 222 when reading from corresponding sysfs, 
and 0x131 * lsb_resolution (806) / 1000 is 222 in decimal. So it seems 
as data above is correct.

Is the data what you expected?

>
> Is your hardware big endian or little endian ?
CONFIG_CPU_LITTLE_ENDIAN=y

BR,
Robert


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-29 12:07                         ` Robert Rosengren
@ 2015-01-29 14:10                           ` Guenter Roeck
  2015-01-29 19:30                           ` Guenter Roeck
  1 sibling, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2015-01-29 14:10 UTC (permalink / raw)
  To: Robert Rosengren, Jean Delvare; +Cc: lm-sensors, Johan Adolfsson, linux-kernel

On 01/29/2015 04:07 AM, Robert Rosengren wrote:
> On 01/29/2015 08:05 AM, Guenter Roeck wrote:
>> Ah, don't bother then. I should hopefully get the samples in a couple of days.
>
> i2cdump was easily built, so here is the output:
>       0,8  1,9  2,a  3,b  4,c  5,d  6,e  7,f
> 00: 1301 1301 1301 1301 1301 1301 1301 1301
> 08: 4101 6901 6a01 6901 6901 6901 6901 6901
> 10: 0200 0100 0100 0100 0100 0100 0100 0100
> 18: 0100 0100 0100 0100 0100 0100 0100 0100
> 20: 0200 0100 0100 0100 0100 0100 0100 0100
> 28: 0100 0100 0100 0100 0100 0100 0100 0100
> 30: 0200 0100 0100 0100 0100 0100 0100 0100
> 38: 0100 0100 0100 0100 0100 0100 0100 0100
> 40: 0000 0000 0000 0000 0000 0000 0000 0000
> 48: 0000 0000 0000 0000 0000 0000 0000 0000
> 50: 0200 0100 0100 0100 0100 0100 0100 0100
> 58: 0100 0100 0100 0100 0100 0100 0200 0100
> 60: 0100 0100 0100 0100 0100 0100 0100 0100
> 68: 0100 0100 0100 0100 0100 0100 0100 0100
> 70: 0200 0100 0100 0100 0100 0100 0100 0100
> 78: 0100 0100 0100 0100 0100 0100 0100 0100
> 80: 6501 2401 1701 1401 1301 1301 1301 1301
> 88: 4201 6901 6901 6901 6901 6901 6901 6901
> 90: 0200 0100 0100 0100 0100 0100 0100 0100
> 98: 0100 0100 0100 0100 0100 0100 0100 0100
> a0: 6701 2501 1901 1601 1501 1501 1501 1501
> a8: 4401 6c01 6c01 6c01 6c01 6c01 6c01 6c01
> b0: 0200 0100 0100 0100 0100 0100 0100 0100
> b8: 0100 0100 0100 0100 0100 0100 0100 0100
> c0: 0200 0100 0100 0100 0100 0100 0100 0100
> c8: 0100 0100 0100 0100 0100 0100 0100 0100
> d0: 0200 0100 0100 0100 0100 0100 0100 0100
> d8: 0100 0100 0100 0100 0100 0100 0100 0100
> e0: 6701 2801 1b01 1701 1601 1501 1501 1501
> e8: 4401 6c01 6c01 6c01 6c01 6c01 6c01 6c01
> f0: 0200 0100 0100 0100 0100 0100 0100 0100
> f8: 0100 0100 0100 0100 0100 0100 0100 0100
>
> I checked the value at 0x84 (channel 0, and using single-ended and external reference). I got 222 when reading from corresponding sysfs, and 0x131 * lsb_resolution (806) / 1000 is 222 in decimal. So it seems as data above is correct.
>
> Is the data what you expected?
>
Yes and no. With the above data, the old version of the driver
(non-regmap) works as expected. The driver supporting regmap,
however, needs the byte swap to work correctly.

Guenter


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-29 12:07                         ` Robert Rosengren
  2015-01-29 14:10                           ` Guenter Roeck
@ 2015-01-29 19:30                           ` Guenter Roeck
  2015-01-31 20:11                             ` Guenter Roeck
  1 sibling, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2015-01-29 19:30 UTC (permalink / raw)
  To: Robert Rosengren; +Cc: Jean Delvare, lm-sensors, Johan Adolfsson, linux-kernel

On Thu, Jan 29, 2015 at 01:07:10PM +0100, Robert Rosengren wrote:
> 
> >
> >Is your hardware big endian or little endian ?
> CONFIG_CPU_LITTLE_ENDIAN=y
> 
Hi Robert,

I have another question: What is your i2c controller type ?

Thanks,
Guenter

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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-29 19:30                           ` Guenter Roeck
@ 2015-01-31 20:11                             ` Guenter Roeck
  2015-02-02  8:12                               ` Robert Rosengren
  0 siblings, 1 reply; 25+ messages in thread
From: Guenter Roeck @ 2015-01-31 20:11 UTC (permalink / raw)
  To: Robert Rosengren; +Cc: Johan Adolfsson, linux-kernel, lm-sensors

On 01/29/2015 11:30 AM, Guenter Roeck wrote:
> On Thu, Jan 29, 2015 at 01:07:10PM +0100, Robert Rosengren wrote:
>>
>>>
>>> Is your hardware big endian or little endian ?
>> CONFIG_CPU_LITTLE_ENDIAN=y
>>
> Hi Robert,
>
> I have another question: What is your i2c controller type ?
>

Robert,

I now tried both 3.15 and 3.19-rc6. Both kernels require the byte swap code.

The only reason I can imagine why you don't need it in your code would be
that your i2c controller does not support i2c functionality but only SMBus.
This would be the case, for example, with the i801 controller. So it would
be quite helpful to know which controller your system uses to access the
ads7828.

Thanks,
Guenter


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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-01-31 20:11                             ` Guenter Roeck
@ 2015-02-02  8:12                               ` Robert Rosengren
  2015-02-02 16:21                                 ` Guenter Roeck
  0 siblings, 1 reply; 25+ messages in thread
From: Robert Rosengren @ 2015-02-02  8:12 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Johan Adolfsson, linux-kernel, lm-sensors

On 01/31/2015 09:11 PM, Guenter Roeck wrote:
> On 01/29/2015 11:30 AM, Guenter Roeck wrote:
>> On Thu, Jan 29, 2015 at 01:07:10PM +0100, Robert Rosengren wrote:
>>>> Is your hardware big endian or little endian ?
>>> CONFIG_CPU_LITTLE_ENDIAN=y
>>>
>> Hi Robert,
>>
>> I have another question: What is your i2c controller type ?
>>
> Robert,
>
> I now tried both 3.15 and 3.19-rc6. Both kernels require the byte swap code.

Agrees, no difference for me when trying with 3.15 and 3.18 version.

The i2c is a bit-bang driver, specific for the hardware I am running on.

>
> The only reason I can imagine why you don't need it in your code would be
> that your i2c controller does not support i2c functionality but only SMBus.
> This would be the case, for example, with the i801 controller. So it would
> be quite helpful to know which controller your system uses to access the
> ads7828.
>
> Thanks,
> Guenter
>

I tried your latest patch set (the 3 patches submitted last night) and 
it works fine for me. Great work!

Please change my Cc-tag in the patches to Reviewed-by or Tested-by (I 
have done both, but one tag is enough). Thanks :-)

BR,
Robert

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

* Re: [lm-sensors] [PATCH] hwmon: (ads7828) Make sample interval configurable
  2015-02-02  8:12                               ` Robert Rosengren
@ 2015-02-02 16:21                                 ` Guenter Roeck
  0 siblings, 0 replies; 25+ messages in thread
From: Guenter Roeck @ 2015-02-02 16:21 UTC (permalink / raw)
  To: Robert Rosengren; +Cc: Johan Adolfsson, linux-kernel, lm-sensors

On Mon, Feb 02, 2015 at 09:12:57AM +0100, Robert Rosengren wrote:
> On 01/31/2015 09:11 PM, Guenter Roeck wrote:
> >On 01/29/2015 11:30 AM, Guenter Roeck wrote:
> >>On Thu, Jan 29, 2015 at 01:07:10PM +0100, Robert Rosengren wrote:
> >>>>Is your hardware big endian or little endian ?
> >>>CONFIG_CPU_LITTLE_ENDIAN=y
> >>>
> >>Hi Robert,
> >>
> >>I have another question: What is your i2c controller type ?
> >>
> >Robert,
> >
> >I now tried both 3.15 and 3.19-rc6. Both kernels require the byte swap code.
> 
> Agrees, no difference for me when trying with 3.15 and 3.18 version.
> 
> The i2c is a bit-bang driver, specific for the hardware I am running on.
> 
> >
> >The only reason I can imagine why you don't need it in your code would be
> >that your i2c controller does not support i2c functionality but only SMBus.
> >This would be the case, for example, with the i801 controller. So it would
> >be quite helpful to know which controller your system uses to access the
> >ads7828.
> >
> >Thanks,
> >Guenter
> >
> 
> I tried your latest patch set (the 3 patches submitted last night) and it
> works fine for me. Great work!
> 
> Please change my Cc-tag in the patches to Reviewed-by or Tested-by (I have
> done both, but one tag is enough). Thanks :-)
> 
I made it Reviewed-and-Tested-by.

Thanks a lot!
Guenter

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

end of thread, other threads:[~2015-02-02 16:21 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-16 12:05 [PATCH] hwmon: (ads7828) Make sample interval configurable Robert Rosengren
2015-01-16 14:52 ` Guenter Roeck
2015-01-16 18:30   ` [lm-sensors] " Guenter Roeck
2015-01-19 11:14     ` SV: " Robert Rosengren
2015-01-27  7:59     ` Robert Rosengren
2015-01-27 10:37       ` Jean Delvare
2015-01-27 14:23         ` Guenter Roeck
2015-01-27 14:07       ` Guenter Roeck
2015-01-27 19:54         ` Robert Rosengren
2015-01-27 20:05           ` Guenter Roeck
2015-01-27 22:34             ` Jean Delvare
2015-01-28  4:06               ` Guenter Roeck
     [not found]                 ` <54C87F3C.2020105@axis.com>
2015-01-28  6:28                   ` Robert Rosengren
2015-01-28 14:50                   ` Guenter Roeck
2015-01-29  7:00                     ` Robert Rosengren
2015-01-29  7:05                       ` Guenter Roeck
2015-01-29 12:07                         ` Robert Rosengren
2015-01-29 14:10                           ` Guenter Roeck
2015-01-29 19:30                           ` Guenter Roeck
2015-01-31 20:11                             ` Guenter Roeck
2015-02-02  8:12                               ` Robert Rosengren
2015-02-02 16:21                                 ` Guenter Roeck
2015-01-27 14:26       ` Guenter Roeck
2015-01-27 16:37       ` Guenter Roeck
2015-01-16 20:30 ` Guenter Roeck

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