Re: [PATCH v6 5/9] w1_therm: adding resolution sysfs entry

2020-05-11 Thread Akira shimahara
Hi,

Le dimanche 10 mai 2020 à 20:25 -0700, Randy Dunlap a écrit :
> Hi,
> 
> 
> 
> The kernel-doc comment changes look good.  Thanks for doing that.
> 
> 
> 
> 
> 
> On 5/10/20 7:17 AM, Akira Shimahara wrote:
> 
> 
> 
> > diff --git a/drivers/w1/slaves/w1_therm.c
> > b/drivers/w1/slaves/w1_therm.c
> > index 08579dc..b1734ae 100644
> > --- a/drivers/w1/slaves/w1_therm.c
> > +++ b/drivers/w1/slaves/w1_therm.c
> > @@ -50,12 +50,24 @@ module_param_named(strong_pullup,
> > w1_strong_pullup, int, 0);
> >   
> >   /* Helpers Macros */
> >   
> > +/* return a pointer on the slave w1_therm_family_converter struct:
> > + * always test family data existence before
> > + */
> 
> 
> /*
> 
>  * Kernel multi-line comment coding style (except for networking
> source code)
> 
>  * is like this.
> 
>  */
> 
> 
> 
> (in multiple places)
> 
> 
> 
> > +/**
> > + * write_scratchpad() - write nb_bytes in the device RAM
> > + * @sl: pointer to the slave to write in
> > + * @data: pointer to an array of 3 bytes, as 3 bytes MUST be
> > written
> > + * @nb_bytes: Nb bytes to be written (2 for DS18S20, 3 for other
> > devices)
> 
> 
> If Nb means Number, please spell it out.
> 
> 
> 
> > + *
> > + * Return: 0 if success, -kernel error code otherwise
> > + */
> > +static int write_scratchpad(struct w1_slave *sl, const u8 *data,
> > u8 nb_bytes);
> > +
> >   /**
> >* read_powermode() - Query the power mode of the slave
> >* @sl: slave to retrieve the power mode
> 
> 
> 
> 
> thanks.
> 
> --
> 
> ~Randy

Thanks for your comments and your time,
well noted, I will do
accordingly.

Akira Shimahara



Re: [PATCH v6 5/9] w1_therm: adding resolution sysfs entry

2020-05-10 Thread Randy Dunlap
Hi,

The kernel-doc comment changes look good.  Thanks for doing that.


On 5/10/20 7:17 AM, Akira Shimahara wrote:

> diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
> index 08579dc..b1734ae 100644
> --- a/drivers/w1/slaves/w1_therm.c
> +++ b/drivers/w1/slaves/w1_therm.c
> @@ -50,12 +50,24 @@ module_param_named(strong_pullup, w1_strong_pullup, int, 
> 0);
>  
>  /* Helpers Macros */
>  
> +/* return a pointer on the slave w1_therm_family_converter struct:
> + * always test family data existence before
> + */

/*
 * Kernel multi-line comment coding style (except for networking source code)
 * is like this.
 */

(in multiple places)

> +/**
> + * write_scratchpad() - write nb_bytes in the device RAM
> + * @sl: pointer to the slave to write in
> + * @data: pointer to an array of 3 bytes, as 3 bytes MUST be written
> + * @nb_bytes: Nb bytes to be written (2 for DS18S20, 3 for other devices)

If Nb means Number, please spell it out.

> + *
> + * Return: 0 if success, -kernel error code otherwise
> + */
> +static int write_scratchpad(struct w1_slave *sl, const u8 *data, u8 
> nb_bytes);
> +
>  /**
>   * read_powermode() - Query the power mode of the slave
>   * @sl: slave to retrieve the power mode


thanks.
-- 
~Randy



[PATCH v6 5/9] w1_therm: adding resolution sysfs entry

2020-05-10 Thread Akira Shimahara
Adding resolution sysfs entry (RW) to get or set the device resolution
Write values are managed as follow:
* '9..12': resolution to set in bit
* Anything else: do nothing
Read values are :
* '9..12': device resolution in bit
* '-xx': xx is kernel error when reading the resolution

Only supported devices will show the sysfs entry. A new family has been
created for DS18S20 devices as they do not implement resolution feature.

The resolution of each device is check when the device is
discover by the bus master, in 'w1_therm_add_slave(struct w1_slave *)'.
The status is stored in the device structure w1_therm_family_data so
that the driver always knows the resolution of each device, which could
be used later to determine the required conversion duration (resolution
dependent).

The resolution is re evaluate each time a user read or write the sysfs
entry.

To avoid looping through the w1_therm_families at run time, the pointer
'specific_functions' is set up to the correct 'w1_therm_family_converter'
when the slave is added (which mean when it is discovered by the master).
This initialization is done by a helper function 
'device_family(struct w1_slave *sl)', and a dedicated macro 
'SLAVE_SPECIFIC_FUNC(sl)' allow the access to the specific function of the
slave device.

'read_scratchpad' and 'write_scratchpad' are the hardware functions to
access the device RAM, as per protocol specification.

It cancel the former 'precision' functions, which was only set and never
read (so not stored in the device struct).

Updating Documentation/ABI/testing/sysfs-driver-w1_therm accordingly.

Signed-off-by: Akira Shimahara 
---
Changes in v5:
- All patch serie in one .c file
- Correcting some comments
- adding  include
Changes in v6:
- Formatting code comments according to kernel-doc requirements

 .../ABI/testing/sysfs-driver-w1_therm |  17 +
 drivers/w1/slaves/w1_therm.c  | 438 ++
 2 files changed, 357 insertions(+), 98 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-driver-w1_therm 
b/Documentation/ABI/testing/sysfs-driver-w1_therm
index 99d73ee..7ed95e9 100644
--- a/Documentation/ABI/testing/sysfs-driver-w1_therm
+++ b/Documentation/ABI/testing/sysfs-driver-w1_therm
@@ -10,6 +10,23 @@ Users:   any user space application which wants 
to communicate with
w1_term device
 
 
+What:  /sys/bus/w1/devices/.../resolution
+Date:  May 2020
+Contact:   Akira Shimahara 
+Description:
+   (RW) get or set the device resolution (on supported devices,
+   if not, this entry is not present). Note that the resolution
+   will be changed only in device RAM, so it will be cleared when
+   power is lost. Trigger a 'save' to EEPROM command to keep
+   values after power-on. Read or write are :
+   * '9..12': device resolution in bit
+   or resolution to set in bit
+   * '-xx': xx is kernel error when reading the resolution
+   * Anything else: do nothing
+Users: any user space application which wants to communicate with
+   w1_term device
+
+
 What:  /sys/bus/w1/devices/.../w1_slave
 Date:  May 2020
 Contact:   Akira Shimahara 
diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index 08579dc..b1734ae 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -50,12 +50,24 @@ module_param_named(strong_pullup, w1_strong_pullup, int, 0);
 
 /* Helpers Macros */
 
+/* return a pointer on the slave w1_therm_family_converter struct:
+ * always test family data existence before
+ */
+#define SLAVE_SPECIFIC_FUNC(sl) \
+   (((struct w1_therm_family_data *)(sl->family_data))->specific_functions)
+
 /* return the power mode of the sl slave : 1-ext, 0-parasite, <0 unknown
  * always test family data existence before
  */
 #define SLAVE_POWERMODE(sl) \
(((struct w1_therm_family_data *)(sl->family_data))->external_powered)
 
+/* return the resolution in bit of the sl slave : <0 unknown
+ * always test family data existence before
+ */
+#define SLAVE_RESOLUTION(sl) \
+   (((struct w1_therm_family_data *)(sl->family_data))->resolution)
+
 /* return the address of the refcnt in the family data */
 #define THERM_REFCNT(family_data) \
(&((struct w1_therm_family_data *)family_data)->refcnt)
@@ -68,7 +80,8 @@ module_param_named(strong_pullup, w1_strong_pullup, int, 0);
  * @reserved: not used here
  * @f: pointer to the device binding structure
  * @convert: pointer to the device conversion function
- * @precision: pointer to the device precicion function
+ * @set_resolution: pointer to the device set_resolution function
+ * @get_resolution: pointer to the device get_resolution function
  * @eeprom: pointer to eeprom function
  */
 struct w1_therm_family_converter {
@@ -76,7 +89,8 @@ struct