[PATCH v2 1/2] hwmon: (sht21) Update data sheet URLs

2018-02-02 Thread Danilo Bargen
The previously used URLs are dead.

Sensirion provides permalinks for their product datasheets at
https://www.sensirion.com/en/about-us/links/.

Signed-off-by: Danilo Bargen 
---
 Documentation/hwmon/sht21 | 6 +++---
 drivers/hwmon/sht21.c | 3 +--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/Documentation/hwmon/sht21 b/Documentation/hwmon/sht21
index 47f4765db256..8b3cdda541c1 100644
--- a/Documentation/hwmon/sht21
+++ b/Documentation/hwmon/sht21
@@ -6,13 +6,13 @@ Supported chips:
 Prefix: 'sht21'
 Addresses scanned: none
 Datasheet: Publicly available at the Sensirion website
-
http://www.sensirion.com/en/pdf/product_information/Datasheet-humidity-sensor-SHT21.pdf
+http://www.sensirion.com/file/datasheet_sht21
 
   * Sensirion SHT25
-Prefix: 'sht21'
+Prefix: 'sht25'
 Addresses scanned: none
 Datasheet: Publicly available at the Sensirion website
-
http://www.sensirion.com/en/pdf/product_information/Datasheet-humidity-sensor-SHT25.pdf
+http://www.sensirion.com/file/datasheet_sht25
 
 Author:
   Urs Fleisch 
diff --git a/drivers/hwmon/sht21.c b/drivers/hwmon/sht21.c
index 06706d288355..e23736e21422 100644
--- a/drivers/hwmon/sht21.c
+++ b/drivers/hwmon/sht21.c
@@ -16,8 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA
  *
- * Data sheet available (5/2010) at
- * 
http://www.sensirion.com/en/pdf/product_information/Datasheet-humidity-sensor-SHT21.pdf
+ * Data sheet available at http://www.sensirion.com/file/datasheet_sht21
  */
 
 #include 
-- 
2.16.1


--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/2] hwmon: (sht3x) Update data sheet URL

2018-02-02 Thread Danilo Bargen
The previously used URL is dead.

Sensirion provides permalinks for their product datasheets at
https://www.sensirion.com/en/about-us/links/.

Signed-off-by: Danilo Bargen 
---
 Documentation/hwmon/sht3x | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/hwmon/sht3x b/Documentation/hwmon/sht3x
index b0d88184f48e..d9daa6ab1e8e 100644
--- a/Documentation/hwmon/sht3x
+++ b/Documentation/hwmon/sht3x
@@ -5,7 +5,7 @@ Supported chips:
   * Sensirion SHT3x-DIS
 Prefix: 'sht3x'
 Addresses scanned: none
-Datasheet: 
http://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/Humidity/Sensirion_Humidity_Datasheet_SHT3x_DIS.pdf
+Datasheet: https://www.sensirion.com/file/datasheet_sht3x_digital
 
 Author:
   David Frey 
-- 
2.16.1


--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] hwmon: (sht21) Update data sheet URLs

2018-02-02 Thread Danilo Bargen
Hello Guenter

> Some prosa expected here.
> ...
> This does a bit more than updating the link to the datasheet.

Thanks, I will submit a patch with some more explanation in the commit message
and without the license header change (which was suggested by 
scripts/checkpatch.pl).

Danilo
--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] hwmon: (sht21) Don't use clock stretching

2018-01-31 Thread Danilo Bargen
Hello Guenter

Thank you for your fast review!

> The driver must now support I2C_FUNC_I2C which is a significant change in 
> functionality
> since it will no longer work on SMBus-only adapters.

You are right of course, I wasn't aware of that.

> You'll have to find a better
> solution, one that retains the old functionality but also works on the 
> Raspberry Pi.

What are my options? A separate driver (sht21nhm) would probably not be 
accepted, right?

Or should I instead try to submit it to the Raspberry Pi kernel tree directly?

> FWIW, this should really be solved in the infrastructure. Many devices 
> support and
> depend on clock stretching, and we can not mess up the drivers for all those 
> devices
> to deal with a broken adapter.

Could you elaborate what you mean with "in the infrastructure"? Could there be a
way to solve this on the i2c / adapter driver level?

An interesting sidenote is that the driver used to work on the Raspberry Pi with
older kernel versions, but not on current ones. (I'd have to look up the exact
versions, but I think it changed sometime last year.) Maybe something about the
timing was changed that broke clock stretching.

> Has this been discussed on the i2c mailing list ?

I did not submit a discussion so far, and the mailing list search did not
turn up anything related. Should I start a discussion there?

Cheers and thanks for your time,
Danilo Bargen
--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] hwmon: (sht21) Don't use clock stretching

2018-01-26 Thread Danilo Bargen
The current driver uses clock stretching (hold master) mode to retrieve
the measurements. This blocks the bus and may cause problems on some
systems like the BCM2835 (Raspberry Pi) that have buggy I2C hardware¹.

¹ http://www.advamation.com/knowhow/raspberrypi/rpi-i2c-bug.html

Signed-off-by: Danilo Bargen 
Reviewed-by: Andreas Brauchli 
---
 drivers/hwmon/sht21.c | 79 ++-
 1 file changed, 60 insertions(+), 19 deletions(-)

diff --git a/drivers/hwmon/sht21.c b/drivers/hwmon/sht21.c
index 984f14b3e89a..56aa13b15682 100644
--- a/drivers/hwmon/sht21.c
+++ b/drivers/hwmon/sht21.c
@@ -25,15 +25,24 @@
 #include 
 #include 
 #include 
+#include 
 
-/* I2C command bytes */
-#define SHT21_TRIG_T_MEASUREMENT_HM  0xe3
-#define SHT21_TRIG_RH_MEASUREMENT_HM 0xe5
+/* I2C commands */
+static const char sht21_trig_t_measurement_nh[] = { 0xf3 };
+static const char sht21_trig_rh_measurement_nh[] = { 0xf5 };
 #define SHT21_READ_SNB_CMD1 0xFA
 #define SHT21_READ_SNB_CMD2 0x0F
 #define SHT21_READ_SNAC_CMD1 0xFC
 #define SHT21_READ_SNAC_CMD2 0xC9
 
+/* I2C lengths */
+#define SHT21_CMD_LENGTH 1
+#define SHT21_RESPONSE_LENGTH 3
+
+/* Max waiting times in ms at max resolution, datasheet table 7 */
+#define SHT21_WAIT_T 85
+#define SHT21_WAIT_RH 29
+
 /**
  * struct sht21 - SHT21 device specific data
  * @hwmon_dev: device registered with hwmon
@@ -93,6 +102,7 @@ static inline int sht21_rh_ticks_to_per_cent_mille(int ticks)
 static int sht21_update_measurements(struct device *dev)
 {
int ret = 0;
+   unsigned char buf[SHT21_RESPONSE_LENGTH];
struct sht21 *sht21 = dev_get_drvdata(dev);
struct i2c_client *client = sht21->client;
 
@@ -103,22 +113,60 @@ static int sht21_update_measurements(struct device *dev)
 * maximum two measurements per second at 12bit accuracy shall be made.
 */
if (time_after(jiffies, sht21->last_update + HZ / 2) || !sht21->valid) {
-   ret = i2c_smbus_read_word_swapped(client,
- SHT21_TRIG_T_MEASUREMENT_HM);
-   if (ret < 0)
+   /*
+* Read from the SHT21 in non blocking mode
+* (no clock stretching).
+*/
+
+   /* Trigger temperature measurement */
+   ret = i2c_master_send(client,
+ sht21_trig_t_measurement_nh,
+ SHT21_CMD_LENGTH);
+   if (ret != SHT21_CMD_LENGTH) {
+   dev_err(dev, "failed to send command: %d\n", ret);
+   ret = -EIO;
+   goto out;
+   }
+   msleep(SHT21_WAIT_T);
+
+   /* Read temperature data */
+   ret = i2c_master_recv(client, buf, sizeof(buf));
+   if (ret != SHT21_RESPONSE_LENGTH) {
+   dev_err(dev, "failed to read values: %d\n", ret);
+   ret = -EIO;
+   goto out;
+   }
+   sht21->temperature = sht21_temp_ticks_to_millicelsius(
+   (buf[0] << 8) | buf[1]
+   );
+
+   /* Trigger humidity measurement */
+   ret = i2c_master_send(client,
+ sht21_trig_rh_measurement_nh,
+ SHT21_CMD_LENGTH);
+   if (ret != SHT21_CMD_LENGTH) {
+   dev_err(dev, "failed to send command: %d\n", ret);
+   ret = -EIO;
goto out;
-   sht21->temperature = sht21_temp_ticks_to_millicelsius(ret);
-   ret = i2c_smbus_read_word_swapped(client,
- SHT21_TRIG_RH_MEASUREMENT_HM);
-   if (ret < 0)
+   }
+   msleep(SHT21_WAIT_RH);
+
+   /* Read humidity data */
+   ret = i2c_master_recv(client, buf, sizeof(buf));
+   if (ret != SHT21_RESPONSE_LENGTH) {
+   dev_err(dev, "failed to read values: %d\n", ret);
+   ret = -EIO;
goto out;
-   sht21->humidity = sht21_rh_ticks_to_per_cent_mille(ret);
+   }
+   sht21->humidity = sht21_rh_ticks_to_per_cent_mille(
+   (buf[0] << 8) | buf[1]
+   );
+
sht21->last_update = jiffies;
sht21->valid = 1;
}
 out:
mutex_unlock(&sht21->lock);
-
return ret >= 0 ? 0 : ret;
 }
 
@@ -269,13 +317,6 @@ static int sht21_probe(struct i2c_client *client,
struct device *hwmon_dev;
struct sht21 *sht21;
 
-   if (!i2c_check_functionality(client->adapter,
-I2C_FUNC_SMBUS_WORD_DATA)) {
-  

[PATCH] hwmon: (sht21) Update data sheet URLs

2018-01-26 Thread Danilo Bargen
Signed-off-by: Danilo Bargen 
---
 Documentation/hwmon/sht21 | 6 +++---
 drivers/hwmon/sht21.c | 7 +--
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/Documentation/hwmon/sht21 b/Documentation/hwmon/sht21
index 47f4765db256..e913605e1d70 100644
--- a/Documentation/hwmon/sht21
+++ b/Documentation/hwmon/sht21
@@ -6,13 +6,13 @@ Supported chips:
 Prefix: 'sht21'
 Addresses scanned: none
 Datasheet: Publicly available at the Sensirion website
-
http://www.sensirion.com/en/pdf/product_information/Datasheet-humidity-sensor-SHT21.pdf
+
https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/2_Humidity_Sensors/Sensirion_Humidity_Sensors_SHT21_Datasheet.pdf
 
   * Sensirion SHT25
-Prefix: 'sht21'
+Prefix: 'sht25'
 Addresses scanned: none
 Datasheet: Publicly available at the Sensirion website
-
http://www.sensirion.com/en/pdf/product_information/Datasheet-humidity-sensor-SHT25.pdf
+
https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/2_Humidity_Sensors/Sensirion_Humidity_Sensors_SHT25_Datasheet.pdf
 
 Author:
   Urs Fleisch 
diff --git a/drivers/hwmon/sht21.c b/drivers/hwmon/sht21.c
index 06706d288355..984f14b3e89a 100644
--- a/drivers/hwmon/sht21.c
+++ b/drivers/hwmon/sht21.c
@@ -12,12 +12,7 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Data sheet available (5/2010) at
- * 
http://www.sensirion.com/en/pdf/product_information/Datasheet-humidity-sensor-SHT21.pdf
+ * Data sheet available at https://www.sensirion.com/sht2x/
  */
 
 #include 
-- 
2.15.1

--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html