aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/emc6w201.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/emc6w201.c')
-rw-r--r--drivers/hwmon/emc6w201.c58
1 files changed, 44 insertions, 14 deletions
diff --git a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c
index e0ef32378ac6..0064432f361f 100644
--- a/drivers/hwmon/emc6w201.c
+++ b/drivers/hwmon/emc6w201.c
@@ -78,8 +78,9 @@ static u16 emc6w201_read16(struct i2c_client *client, u8 reg)
78 78
79 lsb = i2c_smbus_read_byte_data(client, reg); 79 lsb = i2c_smbus_read_byte_data(client, reg);
80 msb = i2c_smbus_read_byte_data(client, reg + 1); 80 msb = i2c_smbus_read_byte_data(client, reg + 1);
81 if (lsb < 0 || msb < 0) { 81 if (unlikely(lsb < 0 || msb < 0)) {
82 dev_err(&client->dev, "16-bit read failed at 0x%02x\n", reg); 82 dev_err(&client->dev, "%d-bit %s failed at 0x%02x\n",
83 16, "read", reg);
83 return 0xFFFF; /* Arbitrary value */ 84 return 0xFFFF; /* Arbitrary value */
84 } 85 }
85 86
@@ -95,10 +96,39 @@ static int emc6w201_write16(struct i2c_client *client, u8 reg, u16 val)
95 int err; 96 int err;
96 97
97 err = i2c_smbus_write_byte_data(client, reg, val & 0xff); 98 err = i2c_smbus_write_byte_data(client, reg, val & 0xff);
98 if (!err) 99 if (likely(!err))
99 err = i2c_smbus_write_byte_data(client, reg + 1, val >> 8); 100 err = i2c_smbus_write_byte_data(client, reg + 1, val >> 8);
100 if (err < 0) 101 if (unlikely(err < 0))
101 dev_err(&client->dev, "16-bit write failed at 0x%02x\n", reg); 102 dev_err(&client->dev, "%d-bit %s failed at 0x%02x\n",
103 16, "write", reg);
104
105 return err;
106}
107
108/* Read 8-bit value from register */
109static u8 emc6w201_read8(struct i2c_client *client, u8 reg)
110{
111 int val;
112
113 val = i2c_smbus_read_byte_data(client, reg);
114 if (unlikely(val < 0)) {
115 dev_err(&client->dev, "%d-bit %s failed at 0x%02x\n",
116 8, "read", reg);
117 return 0x00; /* Arbitrary value */
118 }
119
120 return val;
121}
122
123/* Write 8-bit value to register */
124static int emc6w201_write8(struct i2c_client *client, u8 reg, u8 val)
125{
126 int err;
127
128 err = i2c_smbus_write_byte_data(client, reg, val);
129 if (unlikely(err < 0))
130 dev_err(&client->dev, "%d-bit %s failed at 0x%02x\n",
131 8, "write", reg);
102 132
103 return err; 133 return err;
104} 134}
@@ -114,25 +144,25 @@ static struct emc6w201_data *emc6w201_update_device(struct device *dev)
114 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 144 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
115 for (nr = 0; nr < 6; nr++) { 145 for (nr = 0; nr < 6; nr++) {
116 data->in[input][nr] = 146 data->in[input][nr] =
117 i2c_smbus_read_byte_data(client, 147 emc6w201_read8(client,
118 EMC6W201_REG_IN(nr)); 148 EMC6W201_REG_IN(nr));
119 data->in[min][nr] = 149 data->in[min][nr] =
120 i2c_smbus_read_byte_data(client, 150 emc6w201_read8(client,
121 EMC6W201_REG_IN_LOW(nr)); 151 EMC6W201_REG_IN_LOW(nr));
122 data->in[max][nr] = 152 data->in[max][nr] =
123 i2c_smbus_read_byte_data(client, 153 emc6w201_read8(client,
124 EMC6W201_REG_IN_HIGH(nr)); 154 EMC6W201_REG_IN_HIGH(nr));
125 } 155 }
126 156
127 for (nr = 0; nr < 6; nr++) { 157 for (nr = 0; nr < 6; nr++) {
128 data->temp[input][nr] = 158 data->temp[input][nr] =
129 i2c_smbus_read_byte_data(client, 159 emc6w201_read8(client,
130 EMC6W201_REG_TEMP(nr)); 160 EMC6W201_REG_TEMP(nr));
131 data->temp[min][nr] = 161 data->temp[min][nr] =
132 i2c_smbus_read_byte_data(client, 162 emc6w201_read8(client,
133 EMC6W201_REG_TEMP_LOW(nr)); 163 EMC6W201_REG_TEMP_LOW(nr));
134 data->temp[max][nr] = 164 data->temp[max][nr] =
135 i2c_smbus_read_byte_data(client, 165 emc6w201_read8(client,
136 EMC6W201_REG_TEMP_HIGH(nr)); 166 EMC6W201_REG_TEMP_HIGH(nr));
137 } 167 }
138 168
@@ -192,7 +222,7 @@ static ssize_t set_in(struct device *dev, struct device_attribute *devattr,
192 222
193 mutex_lock(&data->update_lock); 223 mutex_lock(&data->update_lock);
194 data->in[sf][nr] = SENSORS_LIMIT(val, 0, 255); 224 data->in[sf][nr] = SENSORS_LIMIT(val, 0, 255);
195 err = i2c_smbus_write_byte_data(client, reg, data->in[sf][nr]); 225 err = emc6w201_write8(client, reg, data->in[sf][nr]);
196 mutex_unlock(&data->update_lock); 226 mutex_unlock(&data->update_lock);
197 227
198 return err < 0 ? err : count; 228 return err < 0 ? err : count;
@@ -229,7 +259,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
229 259
230 mutex_lock(&data->update_lock); 260 mutex_lock(&data->update_lock);
231 data->temp[sf][nr] = SENSORS_LIMIT(val, -127, 128); 261 data->temp[sf][nr] = SENSORS_LIMIT(val, -127, 128);
232 err = i2c_smbus_write_byte_data(client, reg, data->temp[sf][nr]); 262 err = emc6w201_write8(client, reg, data->temp[sf][nr]);
233 mutex_unlock(&data->update_lock); 263 mutex_unlock(&data->update_lock);
234 264
235 return err < 0 ? err : count; 265 return err < 0 ? err : count;
@@ -444,7 +474,7 @@ static int emc6w201_detect(struct i2c_client *client,
444 474
445 /* Check configuration */ 475 /* Check configuration */
446 config = i2c_smbus_read_byte_data(client, EMC6W201_REG_CONFIG); 476 config = i2c_smbus_read_byte_data(client, EMC6W201_REG_CONFIG);
447 if ((config & 0xF4) != 0x04) 477 if (config < 0 || (config & 0xF4) != 0x04)
448 return -ENODEV; 478 return -ENODEV;
449 if (!(config & 0x01)) { 479 if (!(config & 0x01)) {
450 dev_err(&client->dev, "Monitoring not enabled\n"); 480 dev_err(&client->dev, "Monitoring not enabled\n");