Lines Matching +full:scaled +full:- +full:output +full:- +full:hz
1 // SPDX-License-Identifier: GPL-2.0-or-later
18 * Voltage Six inputs are scaled by chip, VID also reported
21 * Alarms 16-bit map of active alarms
22 * Analog Out 0..1250 mV output
26 * Test hardware: Intel SE440BX-2 desktop motherboard --Grant
35 #include <linux/hwmon-sysfs.h>
37 #include <linux/hwmon-vid.h>
74 return (val * mul - div / 2) / div; in SCALE()
93 /* temperature range: -40..125, 127 disables temperature alarm */
96 val = clamp_val(val, -40000, 127000); in TEMP_TO_REG()
104 return -1; in FAN_FROM_REG()
138 u8 fan_div[2]; /* rw fan1_div, read-only accessor */
139 s16 temp; /* ro temp1_input, 9-bit sign-extended */
140 s8 temp_max[2]; /* rw 0 -> temp_max, 1 -> temp_max_hyst */
144 u8 vrm; /* -- vrm set on startup, no accessor */
147 /* write new fan div, callers must hold data->update_lock */
154 err = regmap_read(data->regmap, ADM9240_REG_VID_FAN_DIV, ®); in adm9240_write_fan_div()
160 err = regmap_write(data->regmap, ADM9240_REG_VID_FAN_DIV, reg); in adm9240_write_fan_div()
163 dev_dbg(&data->client->dev, in adm9240_write_fan_div()
177 err = regmap_bulk_read(data->regmap, ADM9240_REG_IN(0), &data->in[0], 6); in adm9240_update_measure()
180 err = regmap_bulk_read(data->regmap, ADM9240_REG_INT(0), ®s, 2); in adm9240_update_measure()
184 data->alarms = regs[0] | regs[1] << 8; in adm9240_update_measure()
189 * but unlikely aliasing error on lsb reading. --Grant in adm9240_update_measure()
191 err = regmap_read(data->regmap, ADM9240_REG_TEMP, &val); in adm9240_update_measure()
194 data->temp = val << 8; in adm9240_update_measure()
195 err = regmap_read(data->regmap, ADM9240_REG_TEMP_CONF, &val); in adm9240_update_measure()
198 data->temp |= val; in adm9240_update_measure()
200 err = regmap_bulk_read(data->regmap, ADM9240_REG_FAN(0), in adm9240_update_measure()
201 &data->fan[0], 2); in adm9240_update_measure()
207 if (data->valid && data->fan[i] == 255 && in adm9240_update_measure()
208 data->fan_div[i] < 3) { in adm9240_update_measure()
211 ++data->fan_div[i]); in adm9240_update_measure()
216 if (data->fan_min[i] < 255 && in adm9240_update_measure()
217 data->fan_min[i] >= 2) in adm9240_update_measure()
218 data->fan_min[i] /= 2; in adm9240_update_measure()
232 err = regmap_raw_read(data->regmap, ADM9240_REG_IN_MIN(i), in adm9240_update_config()
233 &data->in_min[i], 1); in adm9240_update_config()
236 err = regmap_raw_read(data->regmap, ADM9240_REG_IN_MAX(i), in adm9240_update_config()
237 &data->in_max[i], 1); in adm9240_update_config()
241 err = regmap_bulk_read(data->regmap, ADM9240_REG_FAN_MIN(0), in adm9240_update_config()
242 &data->fan_min[0], 2); in adm9240_update_config()
245 err = regmap_bulk_read(data->regmap, ADM9240_REG_TEMP_MAX(0), in adm9240_update_config()
246 &data->temp_max[0], 2); in adm9240_update_config()
250 /* read fan divs and 5-bit VID */ in adm9240_update_config()
251 err = regmap_read(data->regmap, ADM9240_REG_VID_FAN_DIV, &val); in adm9240_update_config()
254 data->fan_div[0] = (val >> 4) & 3; in adm9240_update_config()
255 data->fan_div[1] = (val >> 6) & 3; in adm9240_update_config()
256 data->vid = val & 0x0f; in adm9240_update_config()
257 err = regmap_read(data->regmap, ADM9240_REG_VID4, &val); in adm9240_update_config()
260 data->vid |= (val & 1) << 4; in adm9240_update_config()
262 err = regmap_raw_read(data->regmap, ADM9240_REG_ANALOG_OUT, in adm9240_update_config()
263 &data->aout, 1); in adm9240_update_config()
273 mutex_lock(&data->update_lock); in adm9240_update_device()
276 if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4)) in adm9240_update_device()
277 || !data->valid) { in adm9240_update_device()
280 data->valid = 0; in adm9240_update_device()
281 mutex_unlock(&data->update_lock); in adm9240_update_device()
284 data->last_updated_measure = jiffies; in adm9240_update_device()
288 if (time_after(jiffies, data->last_updated_config + (HZ * 300)) in adm9240_update_device()
289 || !data->valid) { in adm9240_update_device()
292 data->valid = 0; in adm9240_update_device()
293 mutex_unlock(&data->update_lock); in adm9240_update_device()
296 data->last_updated_config = jiffies; in adm9240_update_device()
297 data->valid = 1; in adm9240_update_device()
299 mutex_unlock(&data->update_lock); in adm9240_update_device()
314 return sprintf(buf, "%d\n", data->temp / 128 * 500); /* 9-bit value */ in temp1_input_show()
326 return sprintf(buf, "%d\n", data->temp_max[attr->index] * 1000); in max_show()
341 mutex_lock(&data->update_lock); in max_store()
342 data->temp_max[attr->index] = TEMP_TO_REG(val); in max_store()
343 err = regmap_write(data->regmap, ADM9240_REG_TEMP_MAX(attr->index), in max_store()
344 data->temp_max[attr->index]); in max_store()
345 mutex_unlock(&data->update_lock); in max_store()
363 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[attr->index], in in_show()
364 attr->index)); in in_show()
376 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[attr->index], in in_min_show()
377 attr->index)); in in_min_show()
389 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[attr->index], in in_max_show()
390 attr->index)); in in_max_show()
406 mutex_lock(&data->update_lock); in in_min_store()
407 data->in_min[attr->index] = IN_TO_REG(val, attr->index); in in_min_store()
408 err = regmap_write(data->regmap, ADM9240_REG_IN_MIN(attr->index), in in_min_store()
409 data->in_min[attr->index]); in in_min_store()
410 mutex_unlock(&data->update_lock); in in_min_store()
427 mutex_lock(&data->update_lock); in in_max_store()
428 data->in_max[attr->index] = IN_TO_REG(val, attr->index); in in_max_store()
429 err = regmap_write(data->regmap, ADM9240_REG_IN_MAX(attr->index), in in_max_store()
430 data->in_max[attr->index]); in in_max_store()
431 mutex_unlock(&data->update_lock); in in_max_store()
464 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index], in fan_show()
465 1 << data->fan_div[attr->index])); in fan_show()
477 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[attr->index], in fan_min_show()
478 1 << data->fan_div[attr->index])); in fan_min_show()
490 return sprintf(buf, "%d\n", 1 << data->fan_div[attr->index]); in fan_div_show()
496 * - value is zero: disable fan speed low limit alarm
498 * - value is below fan speed measurement range: enable fan speed low
501 * - otherwise: select fan clock divider to suit fan speed low limit,
510 struct i2c_client *client = data->client; in fan_min_store()
511 int nr = attr->index; in fan_min_store()
520 mutex_lock(&data->update_lock); in fan_min_store()
523 data->fan_min[nr] = 255; in fan_min_store()
524 new_div = data->fan_div[nr]; in fan_min_store()
526 dev_dbg(&client->dev, "fan%u low limit set disabled\n", in fan_min_store()
531 data->fan_min[nr] = 254; in fan_min_store()
533 dev_dbg(&client->dev, "fan%u low limit set minimum %u\n", in fan_min_store()
547 data->fan_min[nr] = new_min; in fan_min_store()
549 dev_dbg(&client->dev, "fan%u low limit set fan speed %u\n", in fan_min_store()
553 if (new_div != data->fan_div[nr]) { in fan_min_store()
554 data->fan_div[nr] = new_div; in fan_min_store()
557 err = regmap_write(data->regmap, ADM9240_REG_FAN_MIN(nr), in fan_min_store()
558 data->fan_min[nr]); in fan_min_store()
560 mutex_unlock(&data->update_lock); in fan_min_store()
580 return sprintf(buf, "%u\n", data->alarms); in alarms_show()
587 int bitnr = to_sensor_dev_attr(attr)->index; in alarm_show()
593 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); in alarm_show()
614 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); in cpu0_vid_show()
618 /* analog output */
627 return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout)); in aout_output_show()
642 mutex_lock(&data->update_lock); in aout_output_store()
643 data->aout = AOUT_TO_REG(val); in aout_output_store()
644 err = regmap_write(data->regmap, ADM9240_REG_ANALOG_OUT, data->aout); in aout_output_store()
645 mutex_unlock(&data->update_lock); in aout_output_store()
658 return -EINVAL; in alarm_store()
660 mutex_lock(&data->update_lock); in alarm_store()
661 err = regmap_write(data->regmap, ADM9240_REG_CHASSIS_CLEAR, 0x80); in alarm_store()
662 data->valid = 0; /* Force cache refresh */ in alarm_store()
663 mutex_unlock(&data->update_lock); in alarm_store()
666 dev_dbg(&data->client->dev, "chassis intrusion latch cleared\n"); in alarm_store()
720 /* Return 0 if detection is successful, -ENODEV otherwise */
724 struct i2c_adapter *adapter = new_client->adapter; in adm9240_detect()
726 int address = new_client->addr; in adm9240_detect()
730 return -ENODEV; in adm9240_detect()
735 dev_err(&adapter->dev, "detect fail: address match, 0x%02x\n", in adm9240_detect()
737 return -ENODEV; in adm9240_detect()
749 dev_err(&adapter->dev, "detect fail: unknown manuf, 0x%02x\n", in adm9240_detect()
751 return -ENODEV; in adm9240_detect()
756 dev_info(&adapter->dev, "found %s revision %u\n", in adm9240_detect()
760 strlcpy(info->type, name, I2C_NAME_SIZE); in adm9240_detect()
770 err = regmap_raw_read(data->regmap, ADM9240_REG_CONFIG, &conf, 1); in adm9240_init_client()
773 err = regmap_raw_read(data->regmap, ADM9240_REG_TEMP_CONF, &mode, 1); in adm9240_init_client()
778 data->vrm = vid_which_vrm(); /* need this to report vid as mV */ in adm9240_init_client()
780 dev_info(&client->dev, "Using VRM: %d.%d\n", data->vrm / 10, in adm9240_init_client()
781 data->vrm % 10); in adm9240_init_client()
785 dev_info(&client->dev, "status: config 0x%02x mode %u\n", in adm9240_init_client()
792 err = regmap_write(data->regmap, in adm9240_init_client()
796 err = regmap_write(data->regmap, in adm9240_init_client()
802 err = regmap_write(data->regmap, in adm9240_init_client()
808 err = regmap_write(data->regmap, in adm9240_init_client()
815 err = regmap_write(data->regmap, ADM9240_REG_CONFIG, 1); in adm9240_init_client()
819 dev_info(&client->dev, in adm9240_init_client()
835 struct device *dev = &new_client->dev; in adm9240_probe()
842 return -ENOMEM; in adm9240_probe()
844 data->client = new_client; in adm9240_probe()
845 mutex_init(&data->update_lock); in adm9240_probe()
846 data->regmap = devm_regmap_init_i2c(new_client, &adm9240_regmap_config); in adm9240_probe()
847 if (IS_ERR(data->regmap)) in adm9240_probe()
848 return PTR_ERR(data->regmap); in adm9240_probe()
855 new_client->name, in adm9240_probe()