Lines Matching +full:smart +full:- +full:sensors
1 // SPDX-License-Identifier: GPL-2.0-only
3 * w83l786ng.c - Linux kernel driver for hardware monitoring
19 #include <linux/hwmon-sysfs.h>
79 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
87 (val) - 0x100 : (val)) * 1000)
129 u8 pwm_mode[2]; /* 0->DC variable voltage
130 * 1->PWM variable duty cycle */
132 u8 pwm_enable[2]; /* 1->manual
133 * 2->thermal cruise (also called SmartFan I) */
152 struct i2c_client *client = data->client; in w83l786ng_update_device()
156 mutex_lock(&data->update_lock); in w83l786ng_update_device()
157 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) in w83l786ng_update_device()
158 || !data->valid) { in w83l786ng_update_device()
159 dev_dbg(&client->dev, "Updating w83l786ng data.\n"); in w83l786ng_update_device()
163 data->in[i] = w83l786ng_read_value(client, in w83l786ng_update_device()
165 data->in_min[i] = w83l786ng_read_value(client, in w83l786ng_update_device()
167 data->in_max[i] = w83l786ng_read_value(client, in w83l786ng_update_device()
173 data->fan[i] = w83l786ng_read_value(client, in w83l786ng_update_device()
175 data->fan_min[i] = w83l786ng_read_value(client, in w83l786ng_update_device()
181 data->fan_div[0] = reg_tmp & 0x07; in w83l786ng_update_device()
182 data->fan_div[1] = (reg_tmp >> 4) & 0x07; in w83l786ng_update_device()
186 data->pwm_mode[i] = in w83l786ng_update_device()
189 data->pwm_enable[i] = in w83l786ng_update_device()
191 data->pwm[i] = in w83l786ng_update_device()
197 /* Update the temperature sensors */ in w83l786ng_update_device()
200 data->temp[i][j] = w83l786ng_read_value(client, in w83l786ng_update_device()
205 /* Update Smart Fan I/II tolerance */ in w83l786ng_update_device()
207 data->tolerance[0] = reg_tmp & 0x0f; in w83l786ng_update_device()
208 data->tolerance[1] = (reg_tmp >> 4) & 0x0f; in w83l786ng_update_device()
210 data->last_updated = jiffies; in w83l786ng_update_device()
211 data->valid = true; in w83l786ng_update_device()
215 mutex_unlock(&data->update_lock); in w83l786ng_update_device()
226 int nr = to_sensor_dev_attr(attr)->index; \
228 return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
240 int nr = to_sensor_dev_attr(attr)->index; \
242 struct i2c_client *client = data->client; \
247 mutex_lock(&data->update_lock); \
248 data->in_##reg[nr] = IN_TO_REG(val); \
250 data->in_##reg[nr]); \
251 mutex_unlock(&data->update_lock); \
280 int nr = to_sensor_dev_attr(attr)->index; \
283 FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
293 int nr = to_sensor_dev_attr(attr)->index; in store_fan_min()
295 struct i2c_client *client = data->client; in store_fan_min()
303 mutex_lock(&data->update_lock); in store_fan_min()
304 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); in store_fan_min()
306 data->fan_min[nr]); in store_fan_min()
307 mutex_unlock(&data->update_lock); in store_fan_min()
316 int nr = to_sensor_dev_attr(attr)->index; in show_fan_div()
318 return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr])); in show_fan_div()
331 int nr = to_sensor_dev_attr(attr)->index; in store_fan_div()
333 struct i2c_client *client = data->client; in store_fan_div()
349 mutex_lock(&data->update_lock); in store_fan_div()
350 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); in store_fan_div()
352 data->fan_div[nr] = DIV_TO_REG(val); in store_fan_div()
368 tmp_fan_div = (data->fan_div[nr] << new_shift) & ~keep_mask; in store_fan_div()
374 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); in store_fan_div()
376 data->fan_min[nr]); in store_fan_div()
377 mutex_unlock(&data->update_lock); in store_fan_div()
409 int nr = sensor_attr->nr; in show_temp()
410 int index = sensor_attr->index; in show_temp()
412 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index])); in show_temp()
421 int nr = sensor_attr->nr; in store_temp()
422 int index = sensor_attr->index; in store_temp()
424 struct i2c_client *client = data->client; in store_temp()
432 mutex_lock(&data->update_lock); in store_temp()
433 data->temp[nr][index] = TEMP_TO_REG(val); in store_temp()
435 data->temp[nr][index]); in store_temp()
436 mutex_unlock(&data->update_lock); in store_temp()
465 int nr = to_sensor_dev_attr(attr)->index; \
466 return sprintf(buf, "%d\n", data->reg[nr]); \
477 int nr = to_sensor_dev_attr(attr)->index; in show_pwm_reg()
479 struct i2c_client *client = data->client; in show_pwm_reg()
489 return -EINVAL; in show_pwm_reg()
490 mutex_lock(&data->update_lock); in show_pwm_reg()
491 data->pwm_mode[nr] = val; in show_pwm_reg()
497 mutex_unlock(&data->update_lock); in show_pwm_reg()
505 int nr = to_sensor_dev_attr(attr)->index; in store_pwm()
507 struct i2c_client *client = data->client; in store_pwm()
517 mutex_lock(&data->update_lock); in store_pwm()
518 data->pwm[nr] = val * 0x11; in store_pwm()
521 mutex_unlock(&data->update_lock); in store_pwm()
529 int nr = to_sensor_dev_attr(attr)->index; in store_pwm_enable()
531 struct i2c_client *client = data->client; in store_pwm_enable()
541 return -EINVAL; in store_pwm_enable()
543 mutex_lock(&data->update_lock); in store_pwm_enable()
545 data->pwm_enable[nr] = val; in store_pwm_enable()
547 reg |= (val - 1) << W83L786NG_PWM_ENABLE_SHIFT[nr]; in store_pwm_enable()
549 mutex_unlock(&data->update_lock); in store_pwm_enable()
572 /* For Smart Fan I/Thermal Cruise and Smart Fan II */
576 int nr = to_sensor_dev_attr(attr)->index; in show_tolerance()
578 return sprintf(buf, "%ld\n", (long)data->tolerance[nr]); in show_tolerance()
585 int nr = to_sensor_dev_attr(attr)->index; in store_tolerance()
587 struct i2c_client *client = data->client; in store_tolerance()
596 mutex_lock(&data->update_lock); in store_tolerance()
601 data->tolerance[nr] = tol_tmp; in store_tolerance()
607 mutex_unlock(&data->update_lock); in store_tolerance()
662 struct i2c_adapter *adapter = client->adapter; in w83l786ng_detect()
667 return -ENODEV; in w83l786ng_detect()
671 dev_dbg(&adapter->dev, "W83L786NG detection failed at 0x%02x\n", in w83l786ng_detect()
672 client->addr); in w83l786ng_detect()
673 return -ENODEV; in w83l786ng_detect()
683 dev_dbg(&adapter->dev, in w83l786ng_detect()
686 return -ENODEV; in w83l786ng_detect()
689 strscpy(info->type, "w83l786ng", I2C_NAME_SIZE); in w83l786ng_detect()
710 struct device *dev = &client->dev; in w83l786ng_probe()
718 return -ENOMEM; in w83l786ng_probe()
720 data->client = client; in w83l786ng_probe()
721 mutex_init(&data->update_lock); in w83l786ng_probe()
728 data->fan_min[i] = w83l786ng_read_value(client, in w83l786ng_probe()
734 data->fan_div[0] = reg_tmp & 0x07; in w83l786ng_probe()
735 data->fan_div[1] = (reg_tmp >> 4) & 0x07; in w83l786ng_probe()
737 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in w83l786ng_probe()