Lines Matching +full:x +full:- +full:min

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * emc6w201.c - Hardware monitoring driver for the SMSC EMC6W201
13 #include <linux/hwmon-sysfs.h>
39 enum subfeature { input, min, max }; enumerator
42 * Per-device data
59 * Locking: must be called with data->update_lock held
68 dev_err(&client->dev, "%d-bit %s failed at 0x%02x\n", in emc6w201_read16()
77 * Write 16-bit value to LSB and MSB registers
78 * Locking: must be called with data->update_lock held
88 dev_err(&client->dev, "%d-bit %s failed at 0x%02x\n", in emc6w201_write16()
94 /* Read 8-bit value from register */
101 dev_err(&client->dev, "%d-bit %s failed at 0x%02x\n", in emc6w201_read8()
109 /* Write 8-bit value to register */
116 dev_err(&client->dev, "%d-bit %s failed at 0x%02x\n", in emc6w201_write8()
125 struct i2c_client *client = data->client; in emc6w201_update_device()
128 mutex_lock(&data->update_lock); in emc6w201_update_device()
130 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { in emc6w201_update_device()
132 data->in[input][nr] = in emc6w201_update_device()
135 data->in[min][nr] = in emc6w201_update_device()
138 data->in[max][nr] = in emc6w201_update_device()
144 data->temp[input][nr] = in emc6w201_update_device()
147 data->temp[min][nr] = in emc6w201_update_device()
150 data->temp[max][nr] = in emc6w201_update_device()
156 data->fan[input][nr] = in emc6w201_update_device()
159 data->fan[min][nr] = in emc6w201_update_device()
164 data->last_updated = jiffies; in emc6w201_update_device()
165 data->valid = true; in emc6w201_update_device()
168 mutex_unlock(&data->update_lock); in emc6w201_update_device()
183 int sf = to_sensor_dev_attr_2(devattr)->index; in in_show()
184 int nr = to_sensor_dev_attr_2(devattr)->nr; in in_show()
187 (unsigned)data->in[sf][nr] * nominal_mv[nr] / 0xC0); in in_show()
194 struct i2c_client *client = data->client; in in_store()
195 int sf = to_sensor_dev_attr_2(devattr)->index; in in_store()
196 int nr = to_sensor_dev_attr_2(devattr)->nr; in in_store()
207 reg = (sf == min) ? EMC6W201_REG_IN_LOW(nr) in in_store()
210 mutex_lock(&data->update_lock); in in_store()
211 data->in[sf][nr] = val; in in_store()
212 err = emc6w201_write8(client, reg, data->in[sf][nr]); in in_store()
213 mutex_unlock(&data->update_lock); in in_store()
222 int sf = to_sensor_dev_attr_2(devattr)->index; in temp_show()
223 int nr = to_sensor_dev_attr_2(devattr)->nr; in temp_show()
225 return sprintf(buf, "%d\n", (int)data->temp[sf][nr] * 1000); in temp_show()
233 struct i2c_client *client = data->client; in temp_store()
234 int sf = to_sensor_dev_attr_2(devattr)->index; in temp_store()
235 int nr = to_sensor_dev_attr_2(devattr)->nr; in temp_store()
244 val = clamp_val(val, -127000, 127000); in temp_store()
246 reg = (sf == min) ? EMC6W201_REG_TEMP_LOW(nr) in temp_store()
249 mutex_lock(&data->update_lock); in temp_store()
250 data->temp[sf][nr] = val; in temp_store()
251 err = emc6w201_write8(client, reg, data->temp[sf][nr]); in temp_store()
252 mutex_unlock(&data->update_lock); in temp_store()
261 int sf = to_sensor_dev_attr_2(devattr)->index; in fan_show()
262 int nr = to_sensor_dev_attr_2(devattr)->nr; in fan_show()
265 if (data->fan[sf][nr] == 0 || data->fan[sf][nr] == 0xFFFF) in fan_show()
268 rpm = 5400000U / data->fan[sf][nr]; in fan_show()
277 struct i2c_client *client = data->client; in fan_store()
278 int sf = to_sensor_dev_attr_2(devattr)->index; in fan_store()
279 int nr = to_sensor_dev_attr_2(devattr)->nr; in fan_store()
294 mutex_lock(&data->update_lock); in fan_store()
295 data->fan[sf][nr] = val; in fan_store()
297 data->fan[sf][nr]); in fan_store()
298 mutex_unlock(&data->update_lock); in fan_store()
304 static SENSOR_DEVICE_ATTR_2_RW(in0_min, in, 0, min);
307 static SENSOR_DEVICE_ATTR_2_RW(in1_min, in, 1, min);
310 static SENSOR_DEVICE_ATTR_2_RW(in2_min, in, 2, min);
313 static SENSOR_DEVICE_ATTR_2_RW(in3_min, in, 3, min);
316 static SENSOR_DEVICE_ATTR_2_RW(in4_min, in, 4, min);
319 static SENSOR_DEVICE_ATTR_2_RW(in5_min, in, 5, min);
323 static SENSOR_DEVICE_ATTR_2_RW(temp1_min, temp, 0, min);
326 static SENSOR_DEVICE_ATTR_2_RW(temp2_min, temp, 1, min);
329 static SENSOR_DEVICE_ATTR_2_RW(temp3_min, temp, 2, min);
332 static SENSOR_DEVICE_ATTR_2_RW(temp4_min, temp, 3, min);
335 static SENSOR_DEVICE_ATTR_2_RW(temp5_min, temp, 4, min);
338 static SENSOR_DEVICE_ATTR_2_RW(temp6_min, temp, 5, min);
342 static SENSOR_DEVICE_ATTR_2_RW(fan1_min, fan, 0, min);
344 static SENSOR_DEVICE_ATTR_2_RW(fan2_min, fan, 1, min);
346 static SENSOR_DEVICE_ATTR_2_RW(fan3_min, fan, 2, min);
348 static SENSOR_DEVICE_ATTR_2_RW(fan4_min, fan, 3, min);
350 static SENSOR_DEVICE_ATTR_2_RW(fan5_min, fan, 4, min);
410 /* Return 0 if detection is successful, -ENODEV otherwise */
414 struct i2c_adapter *adapter = client->adapter; in emc6w201_detect()
418 return -ENODEV; in emc6w201_detect()
423 return -ENODEV; in emc6w201_detect()
426 return -ENODEV; in emc6w201_detect()
428 dev_dbg(&client->dev, "Unknown EMC6W201 stepping %d\n", in emc6w201_detect()
430 return -ENODEV; in emc6w201_detect()
436 return -ENODEV; in emc6w201_detect()
438 dev_err(&client->dev, "Monitoring not enabled\n"); in emc6w201_detect()
439 return -ENODEV; in emc6w201_detect()
442 strscpy(info->type, "emc6w201", I2C_NAME_SIZE); in emc6w201_detect()
449 struct device *dev = &client->dev; in emc6w201_probe()
455 return -ENOMEM; in emc6w201_probe()
457 data->client = client; in emc6w201_probe()
458 mutex_init(&data->update_lock); in emc6w201_probe()
460 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in emc6w201_probe()