summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adt7411.c
diff options
context:
space:
mode:
authorMichael Walle <michael@walle.cc>2016-07-25 05:12:05 -0400
committerGuenter Roeck <linux@roeck-us.net>2016-07-31 18:02:52 -0400
commit601807bbb7b422012492611b283bdf3647d3742c (patch)
treec382edb14f36c98bd93a2c96f614dccade0b9ff6 /drivers/hwmon/adt7411.c
parent5d17d3b4bbf3becb89fd48b74340a50a39736f6d (diff)
hwmon: (adt7411) set sane values for CFG1 and CFG3
According to the datasheet we have to set some bits as 0 and others as 1. Make sure we do this for CFG1 and CFG3. Signed-off-by: Michael Walle <michael@walle.cc> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/adt7411.c')
-rw-r--r--drivers/hwmon/adt7411.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c
index a7f886961830..fc1e65a263a4 100644
--- a/drivers/hwmon/adt7411.c
+++ b/drivers/hwmon/adt7411.c
@@ -30,6 +30,7 @@
30 30
31#define ADT7411_REG_CFG1 0x18 31#define ADT7411_REG_CFG1 0x18
32#define ADT7411_CFG1_START_MONITOR (1 << 0) 32#define ADT7411_CFG1_START_MONITOR (1 << 0)
33#define ADT7411_CFG1_RESERVED_BIT1 (1 << 1)
33#define ADT7411_CFG1_RESERVED_BIT3 (1 << 3) 34#define ADT7411_CFG1_RESERVED_BIT3 (1 << 3)
34 35
35#define ADT7411_REG_CFG2 0x19 36#define ADT7411_REG_CFG2 0x19
@@ -37,6 +38,9 @@
37 38
38#define ADT7411_REG_CFG3 0x1a 39#define ADT7411_REG_CFG3 0x1a
39#define ADT7411_CFG3_ADC_CLK_225 (1 << 0) 40#define ADT7411_CFG3_ADC_CLK_225 (1 << 0)
41#define ADT7411_CFG3_RESERVED_BIT1 (1 << 1)
42#define ADT7411_CFG3_RESERVED_BIT2 (1 << 2)
43#define ADT7411_CFG3_RESERVED_BIT3 (1 << 3)
40#define ADT7411_CFG3_REF_VDD (1 << 4) 44#define ADT7411_CFG3_REF_VDD (1 << 4)
41 45
42#define ADT7411_REG_DEVICE_ID 0x4d 46#define ADT7411_REG_DEVICE_ID 0x4d
@@ -280,6 +284,45 @@ static int adt7411_detect(struct i2c_client *client,
280 return 0; 284 return 0;
281} 285}
282 286
287static int adt7411_init_device(struct adt7411_data *data)
288{
289 int ret;
290 u8 val;
291
292 ret = i2c_smbus_read_byte_data(data->client, ADT7411_REG_CFG3);
293 if (ret < 0)
294 return ret;
295
296 /*
297 * We must only write zero to bit 1 and bit 2 and only one to bit 3
298 * according to the datasheet.
299 */
300 val = ret;
301 val &= ~(ADT7411_CFG3_RESERVED_BIT1 | ADT7411_CFG3_RESERVED_BIT2);
302 val |= ADT7411_CFG3_RESERVED_BIT3;
303
304 ret = i2c_smbus_write_byte_data(data->client, ADT7411_REG_CFG3, val);
305 if (ret < 0)
306 return ret;
307
308 ret = i2c_smbus_read_byte_data(data->client, ADT7411_REG_CFG1);
309 if (ret < 0)
310 return ret;
311
312 /*
313 * We must only write zero to bit 1 and only one to bit 3 according to
314 * the datasheet.
315 */
316 val = ret;
317 val &= ~ADT7411_CFG1_RESERVED_BIT1;
318 val |= ADT7411_CFG1_RESERVED_BIT3;
319
320 /* enable monitoring */
321 val |= ADT7411_CFG1_START_MONITOR;
322
323 return i2c_smbus_write_byte_data(data->client, ADT7411_REG_CFG1, val);
324}
325
283static int adt7411_probe(struct i2c_client *client, 326static int adt7411_probe(struct i2c_client *client,
284 const struct i2c_device_id *id) 327 const struct i2c_device_id *id)
285{ 328{
@@ -297,10 +340,7 @@ static int adt7411_probe(struct i2c_client *client,
297 mutex_init(&data->device_lock); 340 mutex_init(&data->device_lock);
298 mutex_init(&data->update_lock); 341 mutex_init(&data->update_lock);
299 342
300 /* According to the datasheet, we must only write 1 to bit 3 */ 343 ret = adt7411_init_device(data);
301 ret = adt7411_modify_bit(client, ADT7411_REG_CFG1,
302 ADT7411_CFG1_RESERVED_BIT3
303 | ADT7411_CFG1_START_MONITOR, 1);
304 if (ret < 0) 344 if (ret < 0)
305 return ret; 345 return ret;
306 346