Lines Matching +full:max +full:- +full:cur

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * lm77.c - Part of lm_sensors, Linux kernel modules for hardware
21 #include <linux/hwmon-sysfs.h>
65 #define LM77_TEMP_MIN (-55000)
83 * All registers are word-sized, except for the configuration register.
84 * The LM77 uses the high-byte first convention.
105 struct i2c_client *client = data->client; in lm77_update_device()
108 mutex_lock(&data->update_lock); in lm77_update_device()
110 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) in lm77_update_device()
111 || !data->valid) { in lm77_update_device()
112 dev_dbg(&client->dev, "Starting lm77 update\n"); in lm77_update_device()
114 data->temp[i] = in lm77_update_device()
118 data->alarms = in lm77_update_device()
120 data->last_updated = jiffies; in lm77_update_device()
121 data->valid = true; in lm77_update_device()
124 mutex_unlock(&data->update_lock); in lm77_update_device()
137 return sprintf(buf, "%d\n", data->temp[attr->index]); in temp_show()
145 int nr = attr->index; in temp_hyst_show()
148 temp = nr == t_min ? data->temp[nr] + data->temp[t_hyst] : in temp_hyst_show()
149 data->temp[nr] - data->temp[t_hyst]; in temp_hyst_show()
160 struct i2c_client *client = data->client; in temp_store()
161 int nr = attr->index; in temp_store()
170 mutex_lock(&data->update_lock); in temp_store()
171 data->temp[nr] = val; in temp_store()
173 mutex_unlock(&data->update_lock); in temp_store()
186 struct i2c_client *client = data->client; in temp_hyst_store()
194 mutex_lock(&data->update_lock); in temp_hyst_store()
195 val = clamp_val(data->temp[t_crit] - val, LM77_TEMP_MIN, LM77_TEMP_MAX); in temp_hyst_store()
196 data->temp[t_hyst] = val; in temp_hyst_store()
198 LM77_TEMP_TO_REG(data->temp[t_hyst])); in temp_hyst_store()
199 mutex_unlock(&data->update_lock); in temp_hyst_store()
206 int bitnr = to_sensor_dev_attr(attr)->index; in alarm_show()
208 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); in alarm_show()
239 /* Return 0 if detection is successful, -ENODEV otherwise */
242 struct i2c_adapter *adapter = client->adapter; in lm77_detect()
243 int i, cur, conf, hyst, crit, min, max; in lm77_detect() local
247 return -ENODEV; in lm77_detect()
258 * 4. registers cycling over 8-address boundaries in lm77_detect()
260 * Word-sized registers are high-byte first. in lm77_detect()
264 cur = i2c_smbus_read_word_data(client, 0); in lm77_detect()
269 max = i2c_smbus_read_word_data(client, 5); in lm77_detect()
275 || i2c_smbus_read_word_data(client, i + 5) != max) in lm77_detect()
276 return -ENODEV; in lm77_detect()
280 if (((cur & 0x00f0) != 0xf0 && (cur & 0x00f0) != 0x0) in lm77_detect()
284 || ((max & 0x00f0) != 0xf0 && (max & 0x00f0) != 0x0)) in lm77_detect()
285 return -ENODEV; in lm77_detect()
289 return -ENODEV; in lm77_detect()
292 cur = i2c_smbus_read_word_data(client, 0); in lm77_detect()
293 if (i2c_smbus_read_word_data(client, 6) != cur in lm77_detect()
294 || i2c_smbus_read_word_data(client, 7) != cur) in lm77_detect()
295 return -ENODEV; in lm77_detect()
299 return -ENODEV; in lm77_detect()
303 return -ENODEV; in lm77_detect()
305 strscpy(info->type, "lm77", I2C_NAME_SIZE); in lm77_detect()
312 /* Initialize the LM77 chip - turn off shutdown mode */ in lm77_init_client()
320 struct device *dev = &client->dev; in lm77_probe()
326 return -ENOMEM; in lm77_probe()
328 data->client = client; in lm77_probe()
329 mutex_init(&data->update_lock); in lm77_probe()
334 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in lm77_probe()