Lines Matching +full:target +full:- +full:rpm
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * emc2103.c - Support for SMSC EMC2103
13 #include <linux/hwmon-sysfs.h>
35 /* equation 4 from datasheet: rpm = (3932160 * multipler) / count */
39 * 2103-2 and 2103-4's 3rd temperature sensor can be connected to two diodes
40 * in anti-parallel mode, and in this configuration both can be read
43 * it. Default is to leave the device in the state it's already in (-1).
46 static int apd = -1;
48 MODULE_PARM_DESC(apd, "Set to zero to disable anti-parallel diode mode");
52 u8 fraction; /* 0-7 multiples of 0.125 */
77 dev_warn(&client->dev, "reg 0x%02x, err %d\n", in read_u8_from_i2c()
96 temp->degrees = degrees; in read_temp_from_i2c()
97 temp->fraction = (fractional & 0xe0) >> 5; in read_temp_from_i2c()
131 data->fan_multiplier = 1 << ((conf1 & 0x60) >> 5); in read_fan_config_from_i2c()
132 data->fan_rpm_control = (conf1 & 0x80) != 0; in read_fan_config_from_i2c()
138 struct i2c_client *client = data->client; in emc2103_update_device()
140 mutex_lock(&data->update_lock); in emc2103_update_device()
142 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) in emc2103_update_device()
143 || !data->valid) { in emc2103_update_device()
146 for (i = 0; i < data->temp_count; i++) { in emc2103_update_device()
147 read_temp_from_i2c(client, REG_TEMP[i], &data->temp[i]); in emc2103_update_device()
149 &data->temp_min[i]); in emc2103_update_device()
151 &data->temp_max[i]); in emc2103_update_device()
155 &data->temp_min_alarm); in emc2103_update_device()
157 &data->temp_max_alarm); in emc2103_update_device()
159 read_fan_from_i2c(client, &data->fan_tach, in emc2103_update_device()
161 read_fan_from_i2c(client, &data->fan_target, in emc2103_update_device()
165 data->last_updated = jiffies; in emc2103_update_device()
166 data->valid = true; in emc2103_update_device()
169 mutex_unlock(&data->update_lock); in emc2103_update_device()
177 int nr = to_sensor_dev_attr(da)->index; in temp_show()
179 int millidegrees = data->temp[nr].degrees * 1000 in temp_show()
180 + data->temp[nr].fraction * 125; in temp_show()
187 int nr = to_sensor_dev_attr(da)->index; in temp_min_show()
189 int millidegrees = data->temp_min[nr] * 1000; in temp_min_show()
196 int nr = to_sensor_dev_attr(da)->index; in temp_max_show()
198 int millidegrees = data->temp_max[nr] * 1000; in temp_max_show()
205 int nr = to_sensor_dev_attr(da)->index; in temp_fault_show()
207 bool fault = (data->temp[nr].degrees == -128); in temp_fault_show()
215 int nr = to_sensor_dev_attr(da)->index; in temp_min_alarm_show()
217 bool alarm = data->temp_min_alarm & (1 << nr); in temp_min_alarm_show()
225 int nr = to_sensor_dev_attr(da)->index; in temp_max_alarm_show()
227 bool alarm = data->temp_max_alarm & (1 << nr); in temp_max_alarm_show()
234 int nr = to_sensor_dev_attr(da)->index; in temp_min_store()
236 struct i2c_client *client = data->client; in temp_min_store()
243 val = DIV_ROUND_CLOSEST(clamp_val(val, -63000, 127000), 1000); in temp_min_store()
245 mutex_lock(&data->update_lock); in temp_min_store()
246 data->temp_min[nr] = val; in temp_min_store()
248 mutex_unlock(&data->update_lock); in temp_min_store()
256 int nr = to_sensor_dev_attr(da)->index; in temp_max_store()
258 struct i2c_client *client = data->client; in temp_max_store()
265 val = DIV_ROUND_CLOSEST(clamp_val(val, -63000, 127000), 1000); in temp_max_store()
267 mutex_lock(&data->update_lock); in temp_max_store()
268 data->temp_max[nr] = val; in temp_max_store()
270 mutex_unlock(&data->update_lock); in temp_max_store()
279 int rpm = 0; in fan1_input_show() local
280 if (data->fan_tach != 0) in fan1_input_show()
281 rpm = (FAN_RPM_FACTOR * data->fan_multiplier) / data->fan_tach; in fan1_input_show()
282 return sprintf(buf, "%d\n", rpm); in fan1_input_show()
289 int fan_div = 8 / data->fan_multiplier; in fan1_div_show()
294 * Note: we also update the fan target here, because its value is
296 * of least surprise; the user doesn't expect the fan target to change just
303 struct i2c_client *client = data->client; in fan1_div_store()
304 int new_range_bits, old_div = 8 / data->fan_multiplier; in fan1_div_store()
328 return -EINVAL; in fan1_div_store()
331 mutex_lock(&data->update_lock); in fan1_div_store()
335 dev_dbg(&client->dev, "reg 0x%02x, err %d\n", in fan1_div_store()
337 mutex_unlock(&data->update_lock); in fan1_div_store()
344 data->fan_multiplier = 8 / new_div; in fan1_div_store()
346 /* update fan target if high byte is not disabled */ in fan1_div_store()
347 if ((data->fan_target & 0x1fe0) != 0x1fe0) { in fan1_div_store()
348 u16 new_target = (data->fan_target * old_div) / new_div; in fan1_div_store()
349 data->fan_target = min(new_target, (u16)0x1fff); in fan1_div_store()
350 write_fan_target_to_i2c(client, data->fan_target); in fan1_div_store()
353 /* invalidate data to force re-read from hardware */ in fan1_div_store()
354 data->valid = false; in fan1_div_store()
356 mutex_unlock(&data->update_lock); in fan1_div_store()
364 int rpm = 0; in fan1_target_show() local
367 if ((data->fan_target != 0) && ((data->fan_target & 0x1fe0) != 0x1fe0)) in fan1_target_show()
368 rpm = (FAN_RPM_FACTOR * data->fan_multiplier) in fan1_target_show()
369 / data->fan_target; in fan1_target_show()
371 return sprintf(buf, "%d\n", rpm); in fan1_target_show()
379 struct i2c_client *client = data->client; in fan1_target_store()
386 /* Datasheet states 16384 as maximum RPM target (table 3.2) */ in fan1_target_store()
389 mutex_lock(&data->update_lock); in fan1_target_store()
392 data->fan_target = 0x1fff; in fan1_target_store()
394 data->fan_target = clamp_val( in fan1_target_store()
395 (FAN_RPM_FACTOR * data->fan_multiplier) / rpm_target, in fan1_target_store()
398 write_fan_target_to_i2c(client, data->fan_target); in fan1_target_store()
400 mutex_unlock(&data->update_lock); in fan1_target_store()
408 bool fault = ((data->fan_tach & 0x1fe0) == 0x1fe0); in fan1_fault_show()
416 return sprintf(buf, "%d\n", data->fan_rpm_control ? 3 : 0); in pwm1_enable_show()
424 struct i2c_client *client = data->client; in pwm1_enable_store()
432 mutex_lock(&data->update_lock); in pwm1_enable_store()
435 data->fan_rpm_control = false; in pwm1_enable_store()
438 data->fan_rpm_control = true; in pwm1_enable_store()
441 count = -EINVAL; in pwm1_enable_store()
451 if (data->fan_rpm_control) in pwm1_enable_store()
458 mutex_unlock(&data->update_lock); in pwm1_enable_store()
519 /* extra temperature sensors only present on 2103-2 and 2103-4 */
530 /* extra temperature sensors only present on 2103-2 and 2103-4 in APD mode */
560 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in emc2103_probe()
561 return -EIO; in emc2103_probe()
563 data = devm_kzalloc(&client->dev, sizeof(struct emc2103_data), in emc2103_probe()
566 return -ENOMEM; in emc2103_probe()
569 data->client = client; in emc2103_probe()
570 mutex_init(&data->update_lock); in emc2103_probe()
572 /* 2103-2 and 2103-4 have 3 external diodes, 2103-1 has 1 */ in emc2103_probe()
575 /* 2103-1 only has 1 external diode */ in emc2103_probe()
576 data->temp_count = 2; in emc2103_probe()
578 /* 2103-2 and 2103-4 have 3 or 4 external diodes */ in emc2103_probe()
581 dev_dbg(&client->dev, "reg 0x%02x, err %d\n", REG_CONF1, in emc2103_probe()
587 data->temp_count = (status & 0x01) ? 4 : 3; in emc2103_probe()
592 data->temp_count = 3; in emc2103_probe()
597 data->temp_count = 4; in emc2103_probe()
604 data->groups[idx++] = &emc2103_group; in emc2103_probe()
605 if (data->temp_count >= 3) in emc2103_probe()
606 data->groups[idx++] = &emc2103_temp3_group; in emc2103_probe()
607 if (data->temp_count == 4) in emc2103_probe()
608 data->groups[idx++] = &emc2103_temp4_group; in emc2103_probe()
610 hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, in emc2103_probe()
611 client->name, data, in emc2103_probe()
612 data->groups); in emc2103_probe()
616 dev_info(&client->dev, "%s: sensor '%s'\n", in emc2103_probe()
617 dev_name(hwmon_dev), client->name); in emc2103_probe()
628 /* Return 0 if detection is successful, -ENODEV otherwise */
632 struct i2c_adapter *adapter = new_client->adapter; in emc2103_detect()
636 return -ENODEV; in emc2103_detect()
640 return -ENODEV; in emc2103_detect()
644 return -ENODEV; in emc2103_detect()
646 strscpy(info->type, "emc2103", I2C_NAME_SIZE); in emc2103_detect()