Lines Matching +full:fan +full:- +full:stop +full:- +full:to +full:- +full:start +full:- +full:us

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2007 - 2009 Hans de Goede <[email protected]>
15 * <thilo.cestonaro.external@fujitsu-siemens.com>
28 #include <linux/hwmon-sysfs.h>
39 /* Addresses to scan */
81 /* voltages, weird order is to keep the same order as the old drivers */
95 * minimum pwm at which the fan is driven (pwm can be increased depending on
110 /* actual fan speed */
121 /* fan status registers */
132 /* fan ripple / divider registers */
145 /* Fan status register bitmasks */
176 * temperature high limit registers, FSC does not document these. Proven to be
179 * at these addresses, but doesn't want to confirm they are the same as with
198 * the fan speed.
224 * Driver data (common to all clients)
266 char watchdog_name[10]; /* must be unique to avoid sysfs conflict */
281 u8 fan_status[7]; /* fan status */
282 u8 fan_min[7]; /* fan min value for rps */
287 * Global variables to hold information read from special DMI tables, which are
288 * available on FSC machines with an fscher or later chip. There is no need to
290 * which always gets called with the i2c-core lock held and never accessed
295 static int dmi_vref = -1;
300 * method to get to ones device data from the open fop.
308 * references to our watchdog device are released
324 int index = to_sensor_dev_attr(devattr)->index; in in_value_show()
327 if (data->kind == fscher || data->kind >= fschrc) in in_value_show()
328 return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref * in in_value_show()
331 return sprintf(buf, "%d\n", (data->volt[index] * in in_value_show()
336 #define TEMP_FROM_REG(val) (((val) - 128) * 1000)
341 int index = to_sensor_dev_attr(devattr)->index; in temp_value_show()
344 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_act[index])); in temp_value_show()
350 int index = to_sensor_dev_attr(devattr)->index; in temp_max_show()
353 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[index])); in temp_max_show()
360 int index = to_sensor_dev_attr(devattr)->index; in temp_max_store()
369 v = clamp_val(v / 1000, -128, 127) + 128; in temp_max_store()
371 mutex_lock(&data->update_lock); in temp_max_store()
373 FSCHMD_REG_TEMP_LIMIT[data->kind][index], v); in temp_max_store()
374 data->temp_max[index] = v; in temp_max_store()
375 mutex_unlock(&data->update_lock); in temp_max_store()
383 int index = to_sensor_dev_attr(devattr)->index; in temp_fault_show()
387 if (data->temp_status[index] & FSCHMD_TEMP_WORKING) in temp_fault_show()
396 int index = to_sensor_dev_attr(devattr)->index; in temp_alarm_show()
399 if ((data->temp_status[index] & FSCHMD_TEMP_ALARM_MASK) == in temp_alarm_show()
412 int index = to_sensor_dev_attr(devattr)->index; in fan_value_show()
415 return sprintf(buf, "%u\n", RPM_FROM_REG(data->fan_act[index])); in fan_value_show()
421 int index = to_sensor_dev_attr(devattr)->index; in fan_div_show()
425 return sprintf(buf, "%d\n", 1 << (data->fan_ripple[index] & 3)); in fan_div_show()
433 int index = to_sensor_dev_attr(devattr)->index; in fan_div_store()
457 return -EINVAL; in fan_div_store()
460 mutex_lock(&data->update_lock); in fan_div_store()
463 FSCHMD_REG_FAN_RIPPLE[data->kind][index]); in fan_div_store()
470 FSCHMD_REG_FAN_RIPPLE[data->kind][index], reg); in fan_div_store()
472 data->fan_ripple[index] = reg; in fan_div_store()
474 mutex_unlock(&data->update_lock); in fan_div_store()
482 int index = to_sensor_dev_attr(devattr)->index; in fan_alarm_show()
485 if (data->fan_status[index] & FSCHMD_FAN_ALARM) in fan_alarm_show()
494 int index = to_sensor_dev_attr(devattr)->index; in fan_fault_show()
497 if (data->fan_status[index] & FSCHMD_FAN_NOT_PRESENT) in fan_fault_show()
508 int index = to_sensor_dev_attr(devattr)->index; in pwm_auto_point1_pwm_show()
510 int val = data->fan_min[index]; in pwm_auto_point1_pwm_show()
512 /* 0 = allow turning off (except on the syl), 1-255 = 50-100% */ in pwm_auto_point1_pwm_show()
513 if (val || data->kind == fscsyl) in pwm_auto_point1_pwm_show()
523 int index = to_sensor_dev_attr(devattr)->index; in pwm_auto_point1_pwm_store()
532 /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */ in pwm_auto_point1_pwm_store()
533 if (v || data->kind == fscsyl) { in pwm_auto_point1_pwm_store()
535 v = (v - 128) * 2 + 1; in pwm_auto_point1_pwm_store()
538 mutex_lock(&data->update_lock); in pwm_auto_point1_pwm_store()
541 FSCHMD_REG_FAN_MIN[data->kind][index], v); in pwm_auto_point1_pwm_store()
542 data->fan_min[index] = v; in pwm_auto_point1_pwm_store()
544 mutex_unlock(&data->update_lock); in pwm_auto_point1_pwm_store()
551 * The FSC hwmon family has the ability to force an attached alert led to flash
559 if (data->global_control & FSCHMD_CONTROL_ALERT_LED) in alert_led_show()
577 mutex_lock(&data->update_lock); in alert_led_store()
588 data->global_control = reg; in alert_led_store()
590 mutex_unlock(&data->update_lock); in alert_led_store()
699 int kind = data->kind + 1; /* 0-x array index -> 1-x module param */ in watchdog_set_timeout()
708 return -EINVAL; in watchdog_set_timeout()
710 mutex_lock(&data->watchdog_lock); in watchdog_set_timeout()
711 if (!data->client) { in watchdog_set_timeout()
712 ret = -ENODEV; in watchdog_set_timeout()
717 data->watchdog_control &= ~FSCHMD_WDOG_CONTROL_RESOLUTION; in watchdog_set_timeout()
719 data->watchdog_control |= FSCHMD_WDOG_CONTROL_RESOLUTION; in watchdog_set_timeout()
721 data->watchdog_preset = DIV_ROUND_UP(timeout, resolution); in watchdog_set_timeout()
724 i2c_smbus_write_byte_data(data->client, in watchdog_set_timeout()
725 FSCHMD_REG_WDOG_PRESET[data->kind], data->watchdog_preset); in watchdog_set_timeout()
727 i2c_smbus_write_byte_data(data->client, in watchdog_set_timeout()
728 FSCHMD_REG_WDOG_CONTROL[data->kind], in watchdog_set_timeout()
729 data->watchdog_control & ~FSCHMD_WDOG_CONTROL_TRIGGER); in watchdog_set_timeout()
731 ret = data->watchdog_preset * resolution; in watchdog_set_timeout()
734 mutex_unlock(&data->watchdog_lock); in watchdog_set_timeout()
742 mutex_lock(&data->watchdog_lock); in watchdog_get_timeout()
743 if (data->watchdog_control & FSCHMD_WDOG_CONTROL_RESOLUTION) in watchdog_get_timeout()
744 timeout = data->watchdog_preset * 60; in watchdog_get_timeout()
746 timeout = data->watchdog_preset * 2; in watchdog_get_timeout()
747 mutex_unlock(&data->watchdog_lock); in watchdog_get_timeout()
756 mutex_lock(&data->watchdog_lock); in watchdog_trigger()
757 if (!data->client) { in watchdog_trigger()
758 ret = -ENODEV; in watchdog_trigger()
762 data->watchdog_control |= FSCHMD_WDOG_CONTROL_TRIGGER; in watchdog_trigger()
763 i2c_smbus_write_byte_data(data->client, in watchdog_trigger()
764 FSCHMD_REG_WDOG_CONTROL[data->kind], in watchdog_trigger()
765 data->watchdog_control); in watchdog_trigger()
767 mutex_unlock(&data->watchdog_lock); in watchdog_trigger()
775 mutex_lock(&data->watchdog_lock); in watchdog_stop()
776 if (!data->client) { in watchdog_stop()
777 ret = -ENODEV; in watchdog_stop()
781 data->watchdog_control &= ~FSCHMD_WDOG_CONTROL_STARTED; in watchdog_stop()
783 * Don't store the stop flag in our watchdog control register copy, as in watchdog_stop()
786 i2c_smbus_write_byte_data(data->client, in watchdog_stop()
787 FSCHMD_REG_WDOG_CONTROL[data->kind], in watchdog_stop()
788 data->watchdog_control | FSCHMD_WDOG_CONTROL_STOP); in watchdog_stop()
790 mutex_unlock(&data->watchdog_lock); in watchdog_stop()
806 return -ERESTARTSYS; in watchdog_open()
808 if (pos->watchdog_miscdev.minor == iminor(inode)) { in watchdog_open()
814 watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open); in watchdog_open()
816 kref_get(&data->kref); in watchdog_open()
820 return -EBUSY; in watchdog_open()
822 /* Start the watchdog */ in watchdog_open()
824 filp->private_data = data; in watchdog_open()
831 struct fschmd_data *data = filp->private_data; in watchdog_release()
833 if (data->watchdog_expect_close) { in watchdog_release()
835 data->watchdog_expect_close = 0; in watchdog_release()
838 dev_crit(&data->client->dev, in watchdog_release()
842 clear_bit(0, &data->watchdog_is_open); in watchdog_release()
845 kref_put(&data->kref, fschmd_release_resources); in watchdog_release()
855 struct fschmd_data *data = filp->private_data; in watchdog_write()
862 data->watchdog_expect_close = 0; in watchdog_write()
867 return -EFAULT; in watchdog_write()
869 data->watchdog_expect_close = 1; in watchdog_write()
888 struct fschmd_data *data = filp->private_data; in watchdog_ioctl()
892 ident.firmware_version = data->revision; in watchdog_ioctl()
896 ret = -EFAULT; in watchdog_ioctl()
904 if (data->watchdog_state & FSCHMD_WDOG_STATE_CARDRESET) in watchdog_ioctl()
921 ret = -EFAULT; in watchdog_ioctl()
931 ret = -EFAULT; in watchdog_ioctl()
940 ret = -EINVAL; in watchdog_ioctl()
944 ret = -ENOTTY; in watchdog_ioctl()
964 * DMI decode routine to read voltage scaling factors from special DMI tables,
974 * reality this address holds header->length bytes of which the header in fschmd_dmi_decode()
979 /* We are looking for OEM-specific type 185 */ in fschmd_dmi_decode()
980 if (header->type != 185) in fschmd_dmi_decode()
987 if (header->length < 5 || dmi_data[4] != 19) in fschmd_dmi_decode()
993 * 2 16-bit words in LSB first order in fschmd_dmi_decode()
995 for (i = 6; (i + 4) < header->length; i += 5) { in fschmd_dmi_decode()
996 /* entity 1 - 3: voltage multiplier and offset */ in fschmd_dmi_decode()
1000 int in = shuffle[dmi_data[i] - 1]; in fschmd_dmi_decode()
1030 * According to the docs there should be separate dmi entries in fschmd_dmi_decode()
1031 * for the mult's and offsets of in3-5 of the syl, but on in fschmd_dmi_decode()
1048 struct i2c_adapter *adapter = client->adapter; in fschmd_detect()
1052 return -ENODEV; in fschmd_detect()
1075 return -ENODEV; in fschmd_detect()
1077 strscpy(info->type, fschmd_id[kind].name, I2C_NAME_SIZE); in fschmd_detect()
1093 return -ENOMEM; in fschmd_probe()
1096 mutex_init(&data->update_lock); in fschmd_probe()
1097 mutex_init(&data->watchdog_lock); in fschmd_probe()
1098 INIT_LIST_HEAD(&data->list); in fschmd_probe()
1099 kref_init(&data->kref); in fschmd_probe()
1105 data->client = client; in fschmd_probe()
1106 data->kind = kind; in fschmd_probe()
1113 data->temp_max[0] = 70 + 128; in fschmd_probe()
1114 data->temp_max[1] = 50 + 128; in fschmd_probe()
1115 data->temp_max[2] = 50 + 128; in fschmd_probe()
1119 if ((kind == fscher || kind >= fschrc) && dmi_vref == -1) { in fschmd_probe()
1121 if (dmi_vref == -1) { in fschmd_probe()
1122 dev_warn(&client->dev, in fschmd_probe()
1130 data->revision = i2c_smbus_read_byte_data(client, FSCHMD_REG_REVISION); in fschmd_probe()
1131 data->global_control = i2c_smbus_read_byte_data(client, in fschmd_probe()
1133 data->watchdog_control = i2c_smbus_read_byte_data(client, in fschmd_probe()
1134 FSCHMD_REG_WDOG_CONTROL[data->kind]); in fschmd_probe()
1135 data->watchdog_state = i2c_smbus_read_byte_data(client, in fschmd_probe()
1136 FSCHMD_REG_WDOG_STATE[data->kind]); in fschmd_probe()
1137 data->watchdog_preset = i2c_smbus_read_byte_data(client, in fschmd_probe()
1138 FSCHMD_REG_WDOG_PRESET[data->kind]); in fschmd_probe()
1140 err = device_create_file(&client->dev, &dev_attr_alert_led); in fschmd_probe()
1144 for (i = 0; i < FSCHMD_NO_VOLT_SENSORS[data->kind]; i++) { in fschmd_probe()
1145 err = device_create_file(&client->dev, in fschmd_probe()
1151 for (i = 0; i < (FSCHMD_NO_TEMP_SENSORS[data->kind] * 4); i++) { in fschmd_probe()
1159 data->temp_status[i / 4] = in fschmd_probe()
1162 [data->kind][i / 4]); in fschmd_probe()
1163 if (data->temp_status[i / 4] & FSCHMD_TEMP_DISABLED) in fschmd_probe()
1167 err = device_create_file(&client->dev, in fschmd_probe()
1173 for (i = 0; i < (FSCHMD_NO_FAN_SENSORS[data->kind] * 5); i++) { in fschmd_probe()
1174 /* Poseidon doesn't have a FAN_MIN register for its 3rd fan */ in fschmd_probe()
1182 data->fan_status[i / 5] = in fschmd_probe()
1185 [data->kind][i / 5]); in fschmd_probe()
1186 if (data->fan_status[i / 5] & FSCHMD_FAN_DISABLED) in fschmd_probe()
1190 err = device_create_file(&client->dev, in fschmd_probe()
1196 data->hwmon_dev = hwmon_device_register(&client->dev); in fschmd_probe()
1197 if (IS_ERR(data->hwmon_dev)) { in fschmd_probe()
1198 err = PTR_ERR(data->hwmon_dev); in fschmd_probe()
1199 data->hwmon_dev = NULL; in fschmd_probe()
1206 * our data to the watchdog_data_list (and set the default timeout) in fschmd_probe()
1211 snprintf(data->watchdog_name, sizeof(data->watchdog_name), in fschmd_probe()
1213 data->watchdog_miscdev.name = data->watchdog_name; in fschmd_probe()
1214 data->watchdog_miscdev.fops = &watchdog_fops; in fschmd_probe()
1215 data->watchdog_miscdev.minor = watchdog_minors[i]; in fschmd_probe()
1216 err = misc_register(&data->watchdog_miscdev); in fschmd_probe()
1217 if (err == -EBUSY) in fschmd_probe()
1220 data->watchdog_miscdev.minor = 0; in fschmd_probe()
1221 dev_err(&client->dev, in fschmd_probe()
1226 list_add(&data->list, &watchdog_data_list); in fschmd_probe()
1228 dev_info(&client->dev, in fschmd_probe()
1234 data->watchdog_miscdev.minor = 0; in fschmd_probe()
1235 dev_warn(&client->dev, in fschmd_probe()
1236 "Couldn't register watchdog chardev (due to no free minor)\n"); in fschmd_probe()
1240 dev_info(&client->dev, "Detected FSC %s chip, revision: %d\n", in fschmd_probe()
1241 names[data->kind], (int) data->revision); in fschmd_probe()
1246 fschmd_remove(client); /* will also free data for us */ in fschmd_probe()
1256 if (data->watchdog_miscdev.minor) { in fschmd_remove()
1257 misc_deregister(&data->watchdog_miscdev); in fschmd_remove()
1258 if (data->watchdog_is_open) { in fschmd_remove()
1259 dev_warn(&client->dev, in fschmd_remove()
1265 list_del(&data->list); in fschmd_remove()
1268 mutex_lock(&data->watchdog_lock); in fschmd_remove()
1269 data->client = NULL; in fschmd_remove()
1270 mutex_unlock(&data->watchdog_lock); in fschmd_remove()
1275 * to cleanup after an error in fschmd_remove()
1277 if (data->hwmon_dev) in fschmd_remove()
1278 hwmon_device_unregister(data->hwmon_dev); in fschmd_remove()
1280 device_remove_file(&client->dev, &dev_attr_alert_led); in fschmd_remove()
1281 for (i = 0; i < (FSCHMD_NO_VOLT_SENSORS[data->kind]); i++) in fschmd_remove()
1282 device_remove_file(&client->dev, &fschmd_attr[i].dev_attr); in fschmd_remove()
1283 for (i = 0; i < (FSCHMD_NO_TEMP_SENSORS[data->kind] * 4); i++) in fschmd_remove()
1284 device_remove_file(&client->dev, in fschmd_remove()
1286 for (i = 0; i < (FSCHMD_NO_FAN_SENSORS[data->kind] * 5); i++) in fschmd_remove()
1287 device_remove_file(&client->dev, in fschmd_remove()
1291 kref_put(&data->kref, fschmd_release_resources); in fschmd_remove()
1301 mutex_lock(&data->update_lock); in fschmd_update_device()
1303 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { in fschmd_update_device()
1305 for (i = 0; i < FSCHMD_NO_TEMP_SENSORS[data->kind]; i++) { in fschmd_update_device()
1306 data->temp_act[i] = i2c_smbus_read_byte_data(client, in fschmd_update_device()
1307 FSCHMD_REG_TEMP_ACT[data->kind][i]); in fschmd_update_device()
1308 data->temp_status[i] = i2c_smbus_read_byte_data(client, in fschmd_update_device()
1309 FSCHMD_REG_TEMP_STATE[data->kind][i]); in fschmd_update_device()
1312 if (FSCHMD_REG_TEMP_LIMIT[data->kind][i]) in fschmd_update_device()
1313 data->temp_max[i] = i2c_smbus_read_byte_data( in fschmd_update_device()
1315 FSCHMD_REG_TEMP_LIMIT[data->kind][i]); in fschmd_update_device()
1321 if ((data->temp_status[i] & FSCHMD_TEMP_ALARM_MASK) == in fschmd_update_device()
1323 data->temp_act[i] < data->temp_max[i]) in fschmd_update_device()
1325 FSCHMD_REG_TEMP_STATE[data->kind][i], in fschmd_update_device()
1326 data->temp_status[i]); in fschmd_update_device()
1329 for (i = 0; i < FSCHMD_NO_FAN_SENSORS[data->kind]; i++) { in fschmd_update_device()
1330 data->fan_act[i] = i2c_smbus_read_byte_data(client, in fschmd_update_device()
1331 FSCHMD_REG_FAN_ACT[data->kind][i]); in fschmd_update_device()
1332 data->fan_status[i] = i2c_smbus_read_byte_data(client, in fschmd_update_device()
1333 FSCHMD_REG_FAN_STATE[data->kind][i]); in fschmd_update_device()
1334 data->fan_ripple[i] = i2c_smbus_read_byte_data(client, in fschmd_update_device()
1335 FSCHMD_REG_FAN_RIPPLE[data->kind][i]); in fschmd_update_device()
1337 /* The fscpos third fan doesn't have a fan_min */ in fschmd_update_device()
1338 if (FSCHMD_REG_FAN_MIN[data->kind][i]) in fschmd_update_device()
1339 data->fan_min[i] = i2c_smbus_read_byte_data( in fschmd_update_device()
1341 FSCHMD_REG_FAN_MIN[data->kind][i]); in fschmd_update_device()
1343 /* reset fan status if speed is back to > 0 */ in fschmd_update_device()
1344 if ((data->fan_status[i] & FSCHMD_FAN_ALARM) && in fschmd_update_device()
1345 data->fan_act[i]) in fschmd_update_device()
1347 FSCHMD_REG_FAN_STATE[data->kind][i], in fschmd_update_device()
1348 data->fan_status[i]); in fschmd_update_device()
1351 for (i = 0; i < FSCHMD_NO_VOLT_SENSORS[data->kind]; i++) in fschmd_update_device()
1352 data->volt[i] = i2c_smbus_read_byte_data(client, in fschmd_update_device()
1353 FSCHMD_REG_VOLT[data->kind][i]); in fschmd_update_device()
1355 data->last_updated = jiffies; in fschmd_update_device()
1356 data->valid = true; in fschmd_update_device()
1359 mutex_unlock(&data->update_lock); in fschmd_update_device()