Re: [PATCH] w1: add ability to set (SRAM) and store (EEPROM) configuration for temp sensors like DS18B20

2016-05-01 Thread Greg KH
On Wed, Apr 27, 2016 at 02:13:31PM +0300, Evgeniy Polyakov wrote:
> Hi
> 
> 17.04.2016, 02:08, "x29a" <0.x29...@googlemail.com>:
> > based on the PR (https://github.com/raspberrypi/linux/pull/1412) for the 
> > raspberry pi kernel, i would like to propose my changes upstream as well.
> >
> > The changes entitle basic write operations for the 1Wire driver which are 
> > needed to change e.g. the precision of temperature sensors like the very 
> > popular DS18B20. Writing to SRAM and commiting the values to EEPROM is 
> > possible.
> >
> > Since many sensors come "preconfigured" with a lower precision, people are 
> > stuck that precision when running on a kernel based device (unlike the 
> > Dallas 1Wire library for e.g. Arduino, which supports writing the 
> > configuration/scratchpad).
> 
> This looks good to me, Greg, please pull it into your tree
> 
> > Signed-off-by: x29a <0.x29...@gmail.com>
> 
> Acked-by: Evgeniy Polyakov 

I can't, I need a "real" name for a patch.

"x29a", can you resend this with your real name on it, and I will be
glad to apply it to the tree.

thanks,

greg k-h


Re: [PATCH] w1: add ability to set (SRAM) and store (EEPROM) configuration for temp sensors like DS18B20

2016-05-01 Thread Greg KH
On Wed, Apr 27, 2016 at 02:13:31PM +0300, Evgeniy Polyakov wrote:
> Hi
> 
> 17.04.2016, 02:08, "x29a" <0.x29...@googlemail.com>:
> > based on the PR (https://github.com/raspberrypi/linux/pull/1412) for the 
> > raspberry pi kernel, i would like to propose my changes upstream as well.
> >
> > The changes entitle basic write operations for the 1Wire driver which are 
> > needed to change e.g. the precision of temperature sensors like the very 
> > popular DS18B20. Writing to SRAM and commiting the values to EEPROM is 
> > possible.
> >
> > Since many sensors come "preconfigured" with a lower precision, people are 
> > stuck that precision when running on a kernel based device (unlike the 
> > Dallas 1Wire library for e.g. Arduino, which supports writing the 
> > configuration/scratchpad).
> 
> This looks good to me, Greg, please pull it into your tree
> 
> > Signed-off-by: x29a <0.x29...@gmail.com>
> 
> Acked-by: Evgeniy Polyakov 

I can't, I need a "real" name for a patch.

"x29a", can you resend this with your real name on it, and I will be
glad to apply it to the tree.

thanks,

greg k-h


Re: [PATCH] w1: add ability to set (SRAM) and store (EEPROM) configuration for temp sensors like DS18B20

2016-04-27 Thread Evgeniy Polyakov
Hi

17.04.2016, 02:08, "x29a" <0.x29...@googlemail.com>:
> based on the PR (https://github.com/raspberrypi/linux/pull/1412) for the 
> raspberry pi kernel, i would like to propose my changes upstream as well.
>
> The changes entitle basic write operations for the 1Wire driver which are 
> needed to change e.g. the precision of temperature sensors like the very 
> popular DS18B20. Writing to SRAM and commiting the values to EEPROM is 
> possible.
>
> Since many sensors come "preconfigured" with a lower precision, people are 
> stuck that precision when running on a kernel based device (unlike the Dallas 
> 1Wire library for e.g. Arduino, which supports writing the 
> configuration/scratchpad).

This looks good to me, Greg, please pull it into your tree

> Signed-off-by: x29a <0.x29...@gmail.com>

Acked-by: Evgeniy Polyakov 

> ---
>  Documentation/w1/slaves/w1_therm | 10 +-
>  drivers/w1/slaves/w1_therm.c | 218 +--
>  drivers/w1/w1.h | 2 +
>  3 files changed, 222 insertions(+), 8 deletions(-)
>
> diff --git a/Documentation/w1/slaves/w1_therm 
> b/Documentation/w1/slaves/w1_therm
> index 13411fe..d1f93af 100644
> --- a/Documentation/w1/slaves/w1_therm
> +++ b/Documentation/w1/slaves/w1_therm
> @@ -33,7 +33,15 @@ temperature conversion at a time. If none of the devices 
> are parasite
>  powered it would be possible to convert all the devices at the same
>  time and then go back to read individual sensors. That isn't
>  currently supported. The driver also doesn't support reduced
> -precision (which would also reduce the conversion time).
> +precision (which would also reduce the conversion time) when reading values.
> +
> +Writing a value between 9 and 12 to the sysfs w1_slave file will change the
> +precision of the sensor for the next readings. This value is in (volatile)
> +SRAM, so it is reset when the sensor gets power-cycled.
> +
> +To store the current precision configuration into EEPROM, the value 0
> +has to be written to the sysfs w1_slave file. Since the EEPROM has a limited
> +amount of writes (>50k), this command should be used wisely.
>
>  The module parameter strong_pullup can be set to 0 to disable the
>  strong pullup, 1 to enable autodetection or 2 to force strong pullup.
> diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
> index 2f029e8..581a300 100644
> --- a/drivers/w1/slaves/w1_therm.c
> +++ b/drivers/w1/slaves/w1_therm.c
> @@ -92,10 +92,13 @@ static void w1_therm_remove_slave(struct w1_slave *sl)
>  static ssize_t w1_slave_show(struct device *device,
>  struct device_attribute *attr, char *buf);
>
> +static ssize_t w1_slave_store(struct device *device,
> + struct device_attribute *attr, const char *buf, size_t size);
> +
>  static ssize_t w1_seq_show(struct device *device,
>  struct device_attribute *attr, char *buf);
>
> -static DEVICE_ATTR_RO(w1_slave);
> +static DEVICE_ATTR_RW(w1_slave);
>  static DEVICE_ATTR_RO(w1_seq);
>
>  static struct attribute *w1_therm_attrs[] = {
> @@ -154,8 +157,17 @@ struct w1_therm_family_converter
>  u16 reserved;
>  struct w1_family *f;
>  int (*convert)(u8 rom[9]);
> + int (*precision)(struct device *device, int val);
> + int (*eeprom)(struct device *device);
>  };
>
> +/* write configuration to eeprom */
> +static inline int w1_therm_eeprom(struct device *device);
> +
> +/* Set precision for conversion */
> +static inline int w1_DS18B20_precision(struct device *device, int val);
> +static inline int w1_DS18S20_precision(struct device *device, int val);
> +
>  /* The return value is millidegrees Centigrade. */
>  static inline int w1_DS18B20_convert_temp(u8 rom[9]);
>  static inline int w1_DS18S20_convert_temp(u8 rom[9]);
> @@ -163,26 +175,194 @@ static inline int w1_DS18S20_convert_temp(u8 rom[9]);
>  static struct w1_therm_family_converter w1_therm_families[] = {
>  {
>  .f = _therm_family_DS18S20,
> - .convert = w1_DS18S20_convert_temp
> + .convert = w1_DS18S20_convert_temp,
> + .precision = w1_DS18S20_precision,
> + .eeprom = w1_therm_eeprom
>  },
>  {
>  .f = _therm_family_DS1822,
> - .convert = w1_DS18B20_convert_temp
> + .convert = w1_DS18B20_convert_temp,
> + .precision = w1_DS18S20_precision,
> + .eeprom = w1_therm_eeprom
>  },
>  {
>  .f = _therm_family_DS18B20,
> - .convert = w1_DS18B20_convert_temp
> + .convert = w1_DS18B20_convert_temp,
> + .precision = w1_DS18B20_precision,
> + .eeprom = w1_therm_eeprom
>  },
>  {
>  .f = _therm_family_DS28EA00,
> - .convert = w1_DS18B20_convert_temp
> + .convert = w1_DS18B20_convert_temp,
> + .precision = w1_DS18S20_precision,
> + .eeprom = w1_therm_eeprom
>  },
>  {
>  .f = _therm_family_DS1825,
> - .convert = w1_DS18B20_convert_temp
> + .convert = w1_DS18B20_convert_temp,
> + .precision = w1_DS18S20_precision,
> + .eeprom = 

Re: [PATCH] w1: add ability to set (SRAM) and store (EEPROM) configuration for temp sensors like DS18B20

2016-04-27 Thread Evgeniy Polyakov
Hi

17.04.2016, 02:08, "x29a" <0.x29...@googlemail.com>:
> based on the PR (https://github.com/raspberrypi/linux/pull/1412) for the 
> raspberry pi kernel, i would like to propose my changes upstream as well.
>
> The changes entitle basic write operations for the 1Wire driver which are 
> needed to change e.g. the precision of temperature sensors like the very 
> popular DS18B20. Writing to SRAM and commiting the values to EEPROM is 
> possible.
>
> Since many sensors come "preconfigured" with a lower precision, people are 
> stuck that precision when running on a kernel based device (unlike the Dallas 
> 1Wire library for e.g. Arduino, which supports writing the 
> configuration/scratchpad).

This looks good to me, Greg, please pull it into your tree

> Signed-off-by: x29a <0.x29...@gmail.com>

Acked-by: Evgeniy Polyakov 

> ---
>  Documentation/w1/slaves/w1_therm | 10 +-
>  drivers/w1/slaves/w1_therm.c | 218 +--
>  drivers/w1/w1.h | 2 +
>  3 files changed, 222 insertions(+), 8 deletions(-)
>
> diff --git a/Documentation/w1/slaves/w1_therm 
> b/Documentation/w1/slaves/w1_therm
> index 13411fe..d1f93af 100644
> --- a/Documentation/w1/slaves/w1_therm
> +++ b/Documentation/w1/slaves/w1_therm
> @@ -33,7 +33,15 @@ temperature conversion at a time. If none of the devices 
> are parasite
>  powered it would be possible to convert all the devices at the same
>  time and then go back to read individual sensors. That isn't
>  currently supported. The driver also doesn't support reduced
> -precision (which would also reduce the conversion time).
> +precision (which would also reduce the conversion time) when reading values.
> +
> +Writing a value between 9 and 12 to the sysfs w1_slave file will change the
> +precision of the sensor for the next readings. This value is in (volatile)
> +SRAM, so it is reset when the sensor gets power-cycled.
> +
> +To store the current precision configuration into EEPROM, the value 0
> +has to be written to the sysfs w1_slave file. Since the EEPROM has a limited
> +amount of writes (>50k), this command should be used wisely.
>
>  The module parameter strong_pullup can be set to 0 to disable the
>  strong pullup, 1 to enable autodetection or 2 to force strong pullup.
> diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
> index 2f029e8..581a300 100644
> --- a/drivers/w1/slaves/w1_therm.c
> +++ b/drivers/w1/slaves/w1_therm.c
> @@ -92,10 +92,13 @@ static void w1_therm_remove_slave(struct w1_slave *sl)
>  static ssize_t w1_slave_show(struct device *device,
>  struct device_attribute *attr, char *buf);
>
> +static ssize_t w1_slave_store(struct device *device,
> + struct device_attribute *attr, const char *buf, size_t size);
> +
>  static ssize_t w1_seq_show(struct device *device,
>  struct device_attribute *attr, char *buf);
>
> -static DEVICE_ATTR_RO(w1_slave);
> +static DEVICE_ATTR_RW(w1_slave);
>  static DEVICE_ATTR_RO(w1_seq);
>
>  static struct attribute *w1_therm_attrs[] = {
> @@ -154,8 +157,17 @@ struct w1_therm_family_converter
>  u16 reserved;
>  struct w1_family *f;
>  int (*convert)(u8 rom[9]);
> + int (*precision)(struct device *device, int val);
> + int (*eeprom)(struct device *device);
>  };
>
> +/* write configuration to eeprom */
> +static inline int w1_therm_eeprom(struct device *device);
> +
> +/* Set precision for conversion */
> +static inline int w1_DS18B20_precision(struct device *device, int val);
> +static inline int w1_DS18S20_precision(struct device *device, int val);
> +
>  /* The return value is millidegrees Centigrade. */
>  static inline int w1_DS18B20_convert_temp(u8 rom[9]);
>  static inline int w1_DS18S20_convert_temp(u8 rom[9]);
> @@ -163,26 +175,194 @@ static inline int w1_DS18S20_convert_temp(u8 rom[9]);
>  static struct w1_therm_family_converter w1_therm_families[] = {
>  {
>  .f = _therm_family_DS18S20,
> - .convert = w1_DS18S20_convert_temp
> + .convert = w1_DS18S20_convert_temp,
> + .precision = w1_DS18S20_precision,
> + .eeprom = w1_therm_eeprom
>  },
>  {
>  .f = _therm_family_DS1822,
> - .convert = w1_DS18B20_convert_temp
> + .convert = w1_DS18B20_convert_temp,
> + .precision = w1_DS18S20_precision,
> + .eeprom = w1_therm_eeprom
>  },
>  {
>  .f = _therm_family_DS18B20,
> - .convert = w1_DS18B20_convert_temp
> + .convert = w1_DS18B20_convert_temp,
> + .precision = w1_DS18B20_precision,
> + .eeprom = w1_therm_eeprom
>  },
>  {
>  .f = _therm_family_DS28EA00,
> - .convert = w1_DS18B20_convert_temp
> + .convert = w1_DS18B20_convert_temp,
> + .precision = w1_DS18S20_precision,
> + .eeprom = w1_therm_eeprom
>  },
>  {
>  .f = _therm_family_DS1825,
> - .convert = w1_DS18B20_convert_temp
> + .convert = w1_DS18B20_convert_temp,
> + .precision = w1_DS18S20_precision,
> + .eeprom = w1_therm_eeprom
>  }
> 

[PATCH] w1: add ability to set (SRAM) and store (EEPROM) configuration for temp sensors like DS18B20

2016-04-16 Thread x29a
based on the PR (https://github.com/raspberrypi/linux/pull/1412) for the 
raspberry pi kernel, i would like to propose my changes upstream as well.

The changes entitle basic write operations for the 1Wire driver which are 
needed to change e.g. the precision of temperature sensors like the very 
popular DS18B20. Writing to SRAM and commiting the values to EEPROM is possible.

Since many sensors come "preconfigured" with a lower precision, people are 
stuck that precision when running on a kernel based device (unlike the Dallas 
1Wire library for e.g. Arduino, which supports writing the 
configuration/scratchpad).

Signed-off-by: x29a <0.x29...@gmail.com>
---
 Documentation/w1/slaves/w1_therm |  10 +-
 drivers/w1/slaves/w1_therm.c | 218 +--
 drivers/w1/w1.h  |   2 +
 3 files changed, 222 insertions(+), 8 deletions(-)

diff --git a/Documentation/w1/slaves/w1_therm b/Documentation/w1/slaves/w1_therm
index 13411fe..d1f93af 100644
--- a/Documentation/w1/slaves/w1_therm
+++ b/Documentation/w1/slaves/w1_therm
@@ -33,7 +33,15 @@ temperature conversion at a time.  If none of the devices 
are parasite
 powered it would be possible to convert all the devices at the same
 time and then go back to read individual sensors.  That isn't
 currently supported.  The driver also doesn't support reduced
-precision (which would also reduce the conversion time).
+precision (which would also reduce the conversion time) when reading values.
+
+Writing a value between 9 and 12 to the sysfs w1_slave file will change the
+precision of the sensor for the next readings. This value is in (volatile)
+SRAM, so it is reset when the sensor gets power-cycled.
+
+To store the current precision configuration into EEPROM, the value 0
+has to be written to the sysfs w1_slave file. Since the EEPROM has a limited
+amount of writes (>50k), this command should be used wisely.
 
 The module parameter strong_pullup can be set to 0 to disable the
 strong pullup, 1 to enable autodetection or 2 to force strong pullup.
diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index 2f029e8..581a300 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -92,10 +92,13 @@ static void w1_therm_remove_slave(struct w1_slave *sl)
 static ssize_t w1_slave_show(struct device *device,
struct device_attribute *attr, char *buf);
 
+static ssize_t w1_slave_store(struct device *device,
+   struct device_attribute *attr, const char *buf, size_t size);
+
 static ssize_t w1_seq_show(struct device *device,
struct device_attribute *attr, char *buf);
 
-static DEVICE_ATTR_RO(w1_slave);
+static DEVICE_ATTR_RW(w1_slave);
 static DEVICE_ATTR_RO(w1_seq);
 
 static struct attribute *w1_therm_attrs[] = {
@@ -154,8 +157,17 @@ struct w1_therm_family_converter
u16 reserved;
struct w1_family*f;
int (*convert)(u8 rom[9]);
+   int (*precision)(struct device *device, int val);
+   int (*eeprom)(struct device *device);
 };
 
+/* write configuration to eeprom */
+static inline int w1_therm_eeprom(struct device *device);
+
+/* Set precision for conversion */
+static inline int w1_DS18B20_precision(struct device *device, int val);
+static inline int w1_DS18S20_precision(struct device *device, int val);
+
 /* The return value is millidegrees Centigrade. */
 static inline int w1_DS18B20_convert_temp(u8 rom[9]);
 static inline int w1_DS18S20_convert_temp(u8 rom[9]);
@@ -163,26 +175,194 @@ static inline int w1_DS18S20_convert_temp(u8 rom[9]);
 static struct w1_therm_family_converter w1_therm_families[] = {
{
.f  = _therm_family_DS18S20,
-   .convert= w1_DS18S20_convert_temp
+   .convert= w1_DS18S20_convert_temp,
+   .precision  = w1_DS18S20_precision,
+   .eeprom = w1_therm_eeprom
},
{
.f  = _therm_family_DS1822,
-   .convert= w1_DS18B20_convert_temp
+   .convert= w1_DS18B20_convert_temp,
+   .precision  = w1_DS18S20_precision,
+   .eeprom = w1_therm_eeprom
},
{
.f  = _therm_family_DS18B20,
-   .convert= w1_DS18B20_convert_temp
+   .convert= w1_DS18B20_convert_temp,
+   .precision  = w1_DS18B20_precision,
+   .eeprom = w1_therm_eeprom
},
{
.f  = _therm_family_DS28EA00,
-   .convert= w1_DS18B20_convert_temp
+   .convert= w1_DS18B20_convert_temp,
+   .precision  = w1_DS18S20_precision,
+   .eeprom = w1_therm_eeprom
},
{
.f  = _therm_family_DS1825,
-  

[PATCH] w1: add ability to set (SRAM) and store (EEPROM) configuration for temp sensors like DS18B20

2016-04-16 Thread x29a
based on the PR (https://github.com/raspberrypi/linux/pull/1412) for the 
raspberry pi kernel, i would like to propose my changes upstream as well.

The changes entitle basic write operations for the 1Wire driver which are 
needed to change e.g. the precision of temperature sensors like the very 
popular DS18B20. Writing to SRAM and commiting the values to EEPROM is possible.

Since many sensors come "preconfigured" with a lower precision, people are 
stuck that precision when running on a kernel based device (unlike the Dallas 
1Wire library for e.g. Arduino, which supports writing the 
configuration/scratchpad).

Signed-off-by: x29a <0.x29...@gmail.com>
---
 Documentation/w1/slaves/w1_therm |  10 +-
 drivers/w1/slaves/w1_therm.c | 218 +--
 drivers/w1/w1.h  |   2 +
 3 files changed, 222 insertions(+), 8 deletions(-)

diff --git a/Documentation/w1/slaves/w1_therm b/Documentation/w1/slaves/w1_therm
index 13411fe..d1f93af 100644
--- a/Documentation/w1/slaves/w1_therm
+++ b/Documentation/w1/slaves/w1_therm
@@ -33,7 +33,15 @@ temperature conversion at a time.  If none of the devices 
are parasite
 powered it would be possible to convert all the devices at the same
 time and then go back to read individual sensors.  That isn't
 currently supported.  The driver also doesn't support reduced
-precision (which would also reduce the conversion time).
+precision (which would also reduce the conversion time) when reading values.
+
+Writing a value between 9 and 12 to the sysfs w1_slave file will change the
+precision of the sensor for the next readings. This value is in (volatile)
+SRAM, so it is reset when the sensor gets power-cycled.
+
+To store the current precision configuration into EEPROM, the value 0
+has to be written to the sysfs w1_slave file. Since the EEPROM has a limited
+amount of writes (>50k), this command should be used wisely.
 
 The module parameter strong_pullup can be set to 0 to disable the
 strong pullup, 1 to enable autodetection or 2 to force strong pullup.
diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index 2f029e8..581a300 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -92,10 +92,13 @@ static void w1_therm_remove_slave(struct w1_slave *sl)
 static ssize_t w1_slave_show(struct device *device,
struct device_attribute *attr, char *buf);
 
+static ssize_t w1_slave_store(struct device *device,
+   struct device_attribute *attr, const char *buf, size_t size);
+
 static ssize_t w1_seq_show(struct device *device,
struct device_attribute *attr, char *buf);
 
-static DEVICE_ATTR_RO(w1_slave);
+static DEVICE_ATTR_RW(w1_slave);
 static DEVICE_ATTR_RO(w1_seq);
 
 static struct attribute *w1_therm_attrs[] = {
@@ -154,8 +157,17 @@ struct w1_therm_family_converter
u16 reserved;
struct w1_family*f;
int (*convert)(u8 rom[9]);
+   int (*precision)(struct device *device, int val);
+   int (*eeprom)(struct device *device);
 };
 
+/* write configuration to eeprom */
+static inline int w1_therm_eeprom(struct device *device);
+
+/* Set precision for conversion */
+static inline int w1_DS18B20_precision(struct device *device, int val);
+static inline int w1_DS18S20_precision(struct device *device, int val);
+
 /* The return value is millidegrees Centigrade. */
 static inline int w1_DS18B20_convert_temp(u8 rom[9]);
 static inline int w1_DS18S20_convert_temp(u8 rom[9]);
@@ -163,26 +175,194 @@ static inline int w1_DS18S20_convert_temp(u8 rom[9]);
 static struct w1_therm_family_converter w1_therm_families[] = {
{
.f  = _therm_family_DS18S20,
-   .convert= w1_DS18S20_convert_temp
+   .convert= w1_DS18S20_convert_temp,
+   .precision  = w1_DS18S20_precision,
+   .eeprom = w1_therm_eeprom
},
{
.f  = _therm_family_DS1822,
-   .convert= w1_DS18B20_convert_temp
+   .convert= w1_DS18B20_convert_temp,
+   .precision  = w1_DS18S20_precision,
+   .eeprom = w1_therm_eeprom
},
{
.f  = _therm_family_DS18B20,
-   .convert= w1_DS18B20_convert_temp
+   .convert= w1_DS18B20_convert_temp,
+   .precision  = w1_DS18B20_precision,
+   .eeprom = w1_therm_eeprom
},
{
.f  = _therm_family_DS28EA00,
-   .convert= w1_DS18B20_convert_temp
+   .convert= w1_DS18B20_convert_temp,
+   .precision  = w1_DS18S20_precision,
+   .eeprom = w1_therm_eeprom
},
{
.f  = _therm_family_DS1825,
-