Lines Matching +full:pulses +full:- +full:per +full:- +full:revolution
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * max6639.c - Support for Maxim MAX6639
5 * 2-Channel Temperature Monitor with Dual PWM Fan-Speed Controller
19 #include <linux/hwmon-sysfs.h>
83 u8 temp_therm[2]; /* THERM Temperature, 0..255 C (->_max) */
84 u8 temp_alert[2]; /* ALERT Temperature, 0..255 C (->_crit) */
85 u8 temp_ot[2]; /* OT Temperature, 0..255 C (->_emergency) */
88 u8 ppr; /* Pulses per rotation 0..3 for 1..4 ppr */
95 struct i2c_client *client = data->client; in max6639_update_device()
100 mutex_lock(&data->update_lock); in max6639_update_device()
102 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { in max6639_update_device()
105 dev_dbg(&client->dev, "Starting max6639 update\n"); in max6639_update_device()
114 data->status = status_reg; in max6639_update_device()
123 data->fan[i] = res; in max6639_update_device()
131 data->temp[i] = res >> 5; in max6639_update_device()
132 data->temp_fault[i] = res & 0x01; in max6639_update_device()
140 data->temp[i] |= res << 3; in max6639_update_device()
143 data->last_updated = jiffies; in max6639_update_device()
144 data->valid = 1; in max6639_update_device()
147 mutex_unlock(&data->update_lock); in max6639_update_device()
162 temp = data->temp[attr->index] * 125; in temp_input_show()
175 return sprintf(buf, "%d\n", data->temp_fault[attr->index]); in temp_fault_show()
184 return sprintf(buf, "%d\n", (data->temp_therm[attr->index] * 1000)); in temp_max_show()
193 struct i2c_client *client = data->client; in temp_max_store()
201 mutex_lock(&data->update_lock); in temp_max_store()
202 data->temp_therm[attr->index] = TEMP_LIMIT_TO_REG(val); in temp_max_store()
204 MAX6639_REG_THERM_LIMIT(attr->index), in temp_max_store()
205 data->temp_therm[attr->index]); in temp_max_store()
206 mutex_unlock(&data->update_lock); in temp_max_store()
216 return sprintf(buf, "%d\n", (data->temp_alert[attr->index] * 1000)); in temp_crit_show()
225 struct i2c_client *client = data->client; in temp_crit_store()
233 mutex_lock(&data->update_lock); in temp_crit_store()
234 data->temp_alert[attr->index] = TEMP_LIMIT_TO_REG(val); in temp_crit_store()
236 MAX6639_REG_ALERT_LIMIT(attr->index), in temp_crit_store()
237 data->temp_alert[attr->index]); in temp_crit_store()
238 mutex_unlock(&data->update_lock); in temp_crit_store()
249 return sprintf(buf, "%d\n", (data->temp_ot[attr->index] * 1000)); in temp_emergency_show()
258 struct i2c_client *client = data->client; in temp_emergency_store()
266 mutex_lock(&data->update_lock); in temp_emergency_store()
267 data->temp_ot[attr->index] = TEMP_LIMIT_TO_REG(val); in temp_emergency_store()
269 MAX6639_REG_OT_LIMIT(attr->index), in temp_emergency_store()
270 data->temp_ot[attr->index]); in temp_emergency_store()
271 mutex_unlock(&data->update_lock); in temp_emergency_store()
281 return sprintf(buf, "%d\n", data->pwm[attr->index] * 255 / 120); in pwm_show()
290 struct i2c_client *client = data->client; in pwm_store()
300 mutex_lock(&data->update_lock); in pwm_store()
301 data->pwm[attr->index] = (u8)(val * 120 / 255); in pwm_store()
303 MAX6639_REG_TARGTDUTY(attr->index), in pwm_store()
304 data->pwm[attr->index]); in pwm_store()
305 mutex_unlock(&data->update_lock); in pwm_store()
318 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index], in fan_input_show()
319 data->rpm_range)); in fan_input_show()
331 return sprintf(buf, "%d\n", !!(data->status & (1 << attr->index))); in alarm_show()
405 dev_get_platdata(&client->dev); in max6639_init_client()
416 /* Fans pulse per revolution is 2 by default */ in max6639_init_client()
417 if (max6639_info && max6639_info->ppr > 0 && in max6639_init_client()
418 max6639_info->ppr < 5) in max6639_init_client()
419 data->ppr = max6639_info->ppr; in max6639_init_client()
421 data->ppr = 2; in max6639_init_client()
422 data->ppr -= 1; in max6639_init_client()
425 rpm_range = rpm_range_to_reg(max6639_info->rpm_range); in max6639_init_client()
426 data->rpm_range = rpm_range; in max6639_init_client()
430 /* Set Fan pulse per revolution */ in max6639_init_client()
433 data->ppr << 6); in max6639_init_client()
445 if (max6639_info && max6639_info->pwm_polarity == 0) in max6639_init_client()
465 data->temp_therm[i] = 80; in max6639_init_client()
466 data->temp_alert[i] = 90; in max6639_init_client()
467 data->temp_ot[i] = 100; in max6639_init_client()
470 data->temp_therm[i]); in max6639_init_client()
475 data->temp_alert[i]); in max6639_init_client()
479 MAX6639_REG_OT_LIMIT(i), data->temp_ot[i]); in max6639_init_client()
484 data->pwm[i] = 120; in max6639_init_client()
486 MAX6639_REG_TARGTDUTY(i), data->pwm[i]); in max6639_init_client()
498 /* Return 0 if detection is successful, -ENODEV otherwise */
502 struct i2c_adapter *adapter = client->adapter; in max6639_detect()
506 return -ENODEV; in max6639_detect()
512 return -ENODEV; in max6639_detect()
514 strlcpy(info->type, "max6639", I2C_NAME_SIZE); in max6639_detect()
521 struct device *dev = &client->dev; in max6639_probe()
528 return -ENOMEM; in max6639_probe()
530 data->client = client; in max6639_probe()
531 mutex_init(&data->update_lock); in max6639_probe()
538 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, in max6639_probe()