diff options
author | José Miguel Gonçalves <jose.goncalves@inov.pt> | 2013-12-11 06:11:13 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-12-20 10:45:07 -0500 |
commit | d4fa5279d77716bdcadcefee942629433ae45554 (patch) | |
tree | 8f6d8cbff3d2205632f6f71019538991bdf179dd /drivers/hwmon | |
parent | 223cc81c8c68c4c6b09cf8c024b1881084f29e5d (diff) |
hwmon: HIH-6130: Support I2C bus drivers without I2C_FUNC_SMBUS_QUICK
commit efabcc2123f0ed47870033b8d6fc73b50d76d635 upstream.
Some I2C bus drivers do not allow zero-length data transfers which are
required to start a measurement with the HIH6130/1 sensor. Nevertheless,
we can overcome this limitation by writing a zero dummy byte. This byte
is ignored by the sensor and was verified to be working with the OMAP
I2C bus driver in a BeagleBone board.
Signed-off-by: José Miguel Gonçalves <jose.goncalves@inov.pt>
[Guenter Roeck: Simplified complexity of write_length initialization]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/hih6130.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/drivers/hwmon/hih6130.c b/drivers/hwmon/hih6130.c index 2dc37c7c6947..7d68a08baaa8 100644 --- a/drivers/hwmon/hih6130.c +++ b/drivers/hwmon/hih6130.c | |||
@@ -43,6 +43,7 @@ | |||
43 | * @last_update: time of last update (jiffies) | 43 | * @last_update: time of last update (jiffies) |
44 | * @temperature: cached temperature measurement value | 44 | * @temperature: cached temperature measurement value |
45 | * @humidity: cached humidity measurement value | 45 | * @humidity: cached humidity measurement value |
46 | * @write_length: length for I2C measurement request | ||
46 | */ | 47 | */ |
47 | struct hih6130 { | 48 | struct hih6130 { |
48 | struct device *hwmon_dev; | 49 | struct device *hwmon_dev; |
@@ -51,6 +52,7 @@ struct hih6130 { | |||
51 | unsigned long last_update; | 52 | unsigned long last_update; |
52 | int temperature; | 53 | int temperature; |
53 | int humidity; | 54 | int humidity; |
55 | size_t write_length; | ||
54 | }; | 56 | }; |
55 | 57 | ||
56 | /** | 58 | /** |
@@ -121,8 +123,15 @@ static int hih6130_update_measurements(struct i2c_client *client) | |||
121 | */ | 123 | */ |
122 | if (time_after(jiffies, hih6130->last_update + HZ) || !hih6130->valid) { | 124 | if (time_after(jiffies, hih6130->last_update + HZ) || !hih6130->valid) { |
123 | 125 | ||
124 | /* write to slave address, no data, to request a measurement */ | 126 | /* |
125 | ret = i2c_master_send(client, tmp, 0); | 127 | * Write to slave address to request a measurement. |
128 | * According with the datasheet it should be with no data, but | ||
129 | * for systems with I2C bus drivers that do not allow zero | ||
130 | * length packets we write one dummy byte to allow sensor | ||
131 | * measurements on them. | ||
132 | */ | ||
133 | tmp[0] = 0; | ||
134 | ret = i2c_master_send(client, tmp, hih6130->write_length); | ||
126 | if (ret < 0) | 135 | if (ret < 0) |
127 | goto out; | 136 | goto out; |
128 | 137 | ||
@@ -252,6 +261,9 @@ static int hih6130_probe(struct i2c_client *client, | |||
252 | goto fail_remove_sysfs; | 261 | goto fail_remove_sysfs; |
253 | } | 262 | } |
254 | 263 | ||
264 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_QUICK)) | ||
265 | hih6130->write_length = 1; | ||
266 | |||
255 | return 0; | 267 | return 0; |
256 | 268 | ||
257 | fail_remove_sysfs: | 269 | fail_remove_sysfs: |