Lines Matching +full:msb +full:- +full:justified
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * f75375s.c - driver for the Fintek F75375/SP, F75373 and
5 * Copyright (C) 2006-2007 Riku Voipio
22 #include <linux/hwmon-sysfs.h>
105 * f75387: For remote temperature reading, it uses signed 11-bit
106 * values with LSB = 0.125 degree Celsius, left-justified in 16-bit
107 * registers. For original 8-bit temp readings, the LSB just is 0.
144 if (data->kind == f75387) in f75375_write_pwm()
145 f75375_write16(client, F75375_REG_FAN_EXP(nr), data->pwm[nr]); in f75375_write_pwm()
148 data->pwm[nr]); in f75375_write_pwm()
157 mutex_lock(&data->update_lock); in f75375_update_device()
160 if (time_after(jiffies, data->last_limits + 60 * HZ) in f75375_update_device()
161 || !data->valid) { in f75375_update_device()
163 data->temp_high[nr] = in f75375_update_device()
165 data->temp_max_hyst[nr] = in f75375_update_device()
167 data->fan_max[nr] = in f75375_update_device()
169 data->fan_min[nr] = in f75375_update_device()
171 data->fan_target[nr] = in f75375_update_device()
175 data->in_max[nr] = in f75375_update_device()
177 data->in_min[nr] = in f75375_update_device()
180 data->fan_timer = f75375_read8(client, F75375_REG_FAN_TIMER); in f75375_update_device()
181 data->last_limits = jiffies; in f75375_update_device()
185 if (time_after(jiffies, data->last_updated + 2 * HZ) in f75375_update_device()
186 || !data->valid) { in f75375_update_device()
188 data->pwm[nr] = f75375_read8(client, in f75375_update_device()
190 /* assign MSB, therefore shift it by 8 bits */ in f75375_update_device()
191 data->temp11[nr] = in f75375_update_device()
193 if (data->kind == f75387) in f75375_update_device()
194 /* merge F75387's temperature LSB (11-bit) */ in f75375_update_device()
195 data->temp11[nr] |= in f75375_update_device()
198 data->fan[nr] = in f75375_update_device()
202 data->in[nr] = in f75375_update_device()
205 data->last_updated = jiffies; in f75375_update_device()
206 data->valid = true; in f75375_update_device()
209 mutex_unlock(&data->update_lock); in f75375_update_device()
262 int nr = to_sensor_dev_attr(attr)->index; in set_fan_min()
272 mutex_lock(&data->update_lock); in set_fan_min()
273 data->fan_min[nr] = rpm_to_reg(val); in set_fan_min()
274 f75375_write16(client, F75375_REG_FAN_MIN(nr), data->fan_min[nr]); in set_fan_min()
275 mutex_unlock(&data->update_lock); in set_fan_min()
282 int nr = to_sensor_dev_attr(attr)->index; in set_fan_target()
292 if (auto_mode_enabled(data->pwm_enable[nr])) in set_fan_target()
293 return -EINVAL; in set_fan_target()
294 if (data->kind == f75387 && duty_mode_enabled(data->pwm_enable[nr])) in set_fan_target()
295 return -EINVAL; in set_fan_target()
297 mutex_lock(&data->update_lock); in set_fan_target()
298 data->fan_target[nr] = rpm_to_reg(val); in set_fan_target()
299 f75375_write16(client, F75375_REG_FAN_EXP(nr), data->fan_target[nr]); in set_fan_target()
300 mutex_unlock(&data->update_lock); in set_fan_target()
307 int nr = to_sensor_dev_attr(attr)->index; in set_pwm()
317 if (auto_mode_enabled(data->pwm_enable[nr]) || in set_pwm()
318 !duty_mode_enabled(data->pwm_enable[nr])) in set_pwm()
319 return -EINVAL; in set_pwm()
321 mutex_lock(&data->update_lock); in set_pwm()
322 data->pwm[nr] = clamp_val(val, 0, 255); in set_pwm()
324 mutex_unlock(&data->update_lock); in set_pwm()
331 int nr = to_sensor_dev_attr(attr)->index; in show_pwm_enable()
333 return sprintf(buf, "%d\n", data->pwm_enable[nr]); in show_pwm_enable()
342 return -EINVAL; in set_pwm_enable_direct()
345 if (data->kind == f75387) { in set_pwm_enable_direct()
347 if (duty_mode_enabled(data->pwm_enable[nr]) != in set_pwm_enable_direct()
349 return -EOPNOTSUPP; in set_pwm_enable_direct()
357 data->pwm[nr] = 255; in set_pwm_enable_direct()
378 data->pwm[nr] = 255; in set_pwm_enable_direct()
389 return -EINVAL; in set_pwm_enable_direct()
394 data->pwm_enable[nr] = val; in set_pwm_enable_direct()
403 int nr = to_sensor_dev_attr(attr)->index; in set_pwm_enable()
413 mutex_lock(&data->update_lock); in set_pwm_enable()
415 mutex_unlock(&data->update_lock); in set_pwm_enable()
422 int nr = to_sensor_dev_attr(attr)->index; in set_pwm_mode()
435 return -EINVAL; in set_pwm_mode()
438 if (data->kind == f75373 && val == 0) in set_pwm_mode()
439 return -EINVAL; in set_pwm_mode()
442 if (data->kind == f75387) { in set_pwm_mode()
450 mutex_lock(&data->update_lock); in set_pwm_mode()
458 data->pwm_mode[nr] = val; in set_pwm_mode()
459 mutex_unlock(&data->update_lock); in set_pwm_mode()
466 int nr = to_sensor_dev_attr(attr)->index; in show_pwm()
468 return sprintf(buf, "%d\n", data->pwm[nr]); in show_pwm()
474 int nr = to_sensor_dev_attr(attr)->index; in show_pwm_mode()
476 return sprintf(buf, "%d\n", data->pwm_mode[nr]); in show_pwm_mode()
485 int nr = to_sensor_dev_attr(attr)->index; in show_in()
487 return sprintf(buf, "%d\n", VOLT_FROM_REG(data->in[nr])); in show_in()
493 int nr = to_sensor_dev_attr(attr)->index; in show_in_max()
495 return sprintf(buf, "%d\n", VOLT_FROM_REG(data->in_max[nr])); in show_in_max()
501 int nr = to_sensor_dev_attr(attr)->index; in show_in_min()
503 return sprintf(buf, "%d\n", VOLT_FROM_REG(data->in_min[nr])); in show_in_min()
509 int nr = to_sensor_dev_attr(attr)->index; in set_in_max()
520 mutex_lock(&data->update_lock); in set_in_max()
521 data->in_max[nr] = val; in set_in_max()
522 f75375_write8(client, F75375_REG_VOLT_HIGH(nr), data->in_max[nr]); in set_in_max()
523 mutex_unlock(&data->update_lock); in set_in_max()
530 int nr = to_sensor_dev_attr(attr)->index; in set_in_min()
541 mutex_lock(&data->update_lock); in set_in_min()
542 data->in_min[nr] = val; in set_in_min()
543 f75375_write8(client, F75375_REG_VOLT_LOW(nr), data->in_min[nr]); in set_in_min()
544 mutex_unlock(&data->update_lock); in set_in_min()
554 int nr = to_sensor_dev_attr(attr)->index; in show_temp11()
556 return sprintf(buf, "%d\n", TEMP11_FROM_REG(data->temp11[nr])); in show_temp11()
562 int nr = to_sensor_dev_attr(attr)->index; in show_temp_max()
564 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])); in show_temp_max()
570 int nr = to_sensor_dev_attr(attr)->index; in show_temp_max_hyst()
572 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[nr])); in show_temp_max_hyst()
578 int nr = to_sensor_dev_attr(attr)->index; in set_temp_max()
589 mutex_lock(&data->update_lock); in set_temp_max()
590 data->temp_high[nr] = val; in set_temp_max()
591 f75375_write8(client, F75375_REG_TEMP_HIGH(nr), data->temp_high[nr]); in set_temp_max()
592 mutex_unlock(&data->update_lock); in set_temp_max()
599 int nr = to_sensor_dev_attr(attr)->index; in set_temp_max_hyst()
610 mutex_lock(&data->update_lock); in set_temp_max_hyst()
611 data->temp_max_hyst[nr] = val; in set_temp_max_hyst()
613 data->temp_max_hyst[nr]); in set_temp_max_hyst()
614 mutex_unlock(&data->update_lock); in set_temp_max_hyst()
622 int nr = to_sensor_dev_attr(attr)->index;\
624 return sprintf(buf, "%d\n", rpm_from_reg(data->thing[nr])); \
739 if (data->kind == f75387) { in f75375_init()
743 data->pwm_mode[nr] = 1; in f75375_init()
749 data->pwm_enable[nr] = 4; in f75375_init()
752 data->pwm_enable[nr] = 3; in f75375_init()
755 data->pwm_enable[nr] = 2; in f75375_init()
758 data->pwm_enable[nr] = 1; in f75375_init()
761 data->pwm_mode[nr] = 1; in f75375_init()
765 data->pwm_enable[nr] = 3; in f75375_init()
768 data->pwm_enable[nr] = 2; in f75375_init()
771 data->pwm_enable[nr] = 1; in f75375_init()
779 set_pwm_enable_direct(client, 0, f75375s_pdata->pwm_enable[0]); in f75375_init()
780 set_pwm_enable_direct(client, 1, f75375s_pdata->pwm_enable[1]); in f75375_init()
782 if (auto_mode_enabled(f75375s_pdata->pwm_enable[nr]) || in f75375_init()
783 !duty_mode_enabled(f75375s_pdata->pwm_enable[nr])) in f75375_init()
785 data->pwm[nr] = clamp_val(f75375s_pdata->pwm[nr], 0, 255); in f75375_init()
795 dev_get_platdata(&client->dev); in f75375_probe()
798 if (!i2c_check_functionality(client->adapter, in f75375_probe()
800 return -EIO; in f75375_probe()
801 data = devm_kzalloc(&client->dev, sizeof(struct f75375_data), in f75375_probe()
804 return -ENOMEM; in f75375_probe()
807 mutex_init(&data->update_lock); in f75375_probe()
808 data->kind = (uintptr_t)i2c_get_match_data(client); in f75375_probe()
810 err = sysfs_create_group(&client->dev.kobj, &f75375_group); in f75375_probe()
814 if (data->kind != f75373) { in f75375_probe()
815 err = sysfs_chmod_file(&client->dev.kobj, in f75375_probe()
820 err = sysfs_chmod_file(&client->dev.kobj, in f75375_probe()
827 data->hwmon_dev = hwmon_device_register(&client->dev); in f75375_probe()
828 if (IS_ERR(data->hwmon_dev)) { in f75375_probe()
829 err = PTR_ERR(data->hwmon_dev); in f75375_probe()
838 sysfs_remove_group(&client->dev.kobj, &f75375_group); in f75375_probe()
845 hwmon_device_unregister(data->hwmon_dev); in f75375_remove()
846 sysfs_remove_group(&client->dev.kobj, &f75375_group); in f75375_remove()
849 /* Return 0 if detection is successful, -ENODEV otherwise */
853 struct i2c_adapter *adapter = client->adapter; in f75375_detect()
861 return -ENODEV; in f75375_detect()
870 return -ENODEV; in f75375_detect()
873 dev_info(&adapter->dev, "found %s version: %02X\n", name, version); in f75375_detect()
874 strscpy(info->type, name, I2C_NAME_SIZE); in f75375_detect()