Lines Matching +full:target +full:- +full:rpm
1 // SPDX-License-Identifier: GPL-2.0-or-later
20 * http://pdfserv.maxim-ic.com/en/ds/MAX6620.pdf
95 /* Minimum and maximum values of the FAN-RPM */
142 u16 target[4]; member
150 static u16 max6620_fan_rpm_to_tach(u8 div, int rpm) in max6620_fan_rpm_to_tach() argument
152 return (60 * div * MAX6620_CLOCK_FREQ) / (rpm * MAX6620_PULSE_PER_REV); in max6620_fan_rpm_to_tach()
163 struct i2c_client *client = data->client; in max6620_update_device()
167 mutex_lock(&data->update_lock); in max6620_update_device()
169 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { in max6620_update_device()
174 data->fancfg[i] = ret; in max6620_update_device()
179 data->fandyn[i] = ret; in max6620_update_device()
184 data->tach[i] = (ret << 3) & 0x7f8; in max6620_update_device()
188 data->tach[i] |= (ret >> 5) & 0x7; in max6620_update_device()
193 data->target[i] = (ret << 3) & 0x7f8; in max6620_update_device()
197 data->target[i] |= (ret >> 5) & 0x7; in max6620_update_device()
208 data->fault |= (ret >> 4) & (ret & 0x0F); in max6620_update_device()
210 data->last_updated = jiffies; in max6620_update_device()
211 data->valid = true; in max6620_update_device()
215 mutex_unlock(&data->update_lock); in max6620_update_device()
258 client = data->client; in max6620_read()
264 mutex_lock(&data->update_lock); in max6620_read()
265 *val = !!(data->fault & BIT(channel)); in max6620_read()
267 /* Setting TACH count to re-enable fan fault detection */ in max6620_read()
269 val1 = (data->target[channel] >> 3) & 0xff; in max6620_read()
270 val2 = (data->target[channel] << 5) & 0xe0; in max6620_read()
274 mutex_unlock(&data->update_lock); in max6620_read()
280 mutex_unlock(&data->update_lock); in max6620_read()
284 data->fault &= ~BIT(channel); in max6620_read()
286 mutex_unlock(&data->update_lock); in max6620_read()
290 *val = max6620_fan_div_from_reg(data->fandyn[channel]); in max6620_read()
293 if (data->tach[channel] == 0) { in max6620_read()
296 div = max6620_fan_div_from_reg(data->fandyn[channel]); in max6620_read()
297 *val = max6620_fan_tach_to_rpm(div, data->tach[channel]); in max6620_read()
301 if (data->target[channel] == 0) { in max6620_read()
304 div = max6620_fan_div_from_reg(data->fandyn[channel]); in max6620_read()
305 *val = max6620_fan_tach_to_rpm(div, data->target[channel]); in max6620_read()
309 return -EOPNOTSUPP; in max6620_read()
314 return -EOPNOTSUPP; in max6620_read()
336 client = data->client; in max6620_write()
337 mutex_lock(&data->update_lock); in max6620_write()
363 ret = -EINVAL; in max6620_write()
366 data->fandyn[channel] &= 0x1F; in max6620_write()
367 data->fandyn[channel] |= div << 5; in max6620_write()
369 data->fandyn[channel]); in max6620_write()
373 div = max6620_fan_div_from_reg(data->fandyn[channel]); in max6620_write()
384 /* Setting TACH count re-enables fan fault detection */ in max6620_write()
385 data->fault &= ~BIT(channel); in max6620_write()
389 ret = -EOPNOTSUPP; in max6620_write()
395 ret = -EOPNOTSUPP; in max6620_write()
400 mutex_unlock(&data->update_lock); in max6620_write()
426 struct i2c_client *client = data->client; in max6620_init_client()
434 dev_err(&client->dev, "Error reading config, aborting.\n"); in max6620_init_client()
444 dev_err(&client->dev, "Config write error, aborting.\n"); in max6620_init_client()
452 data->fancfg[i] = reg; in max6620_init_client()
454 /* Enable RPM mode */ in max6620_init_client()
455 data->fancfg[i] |= 0xa8; in max6620_init_client()
456 err = i2c_smbus_write_byte_data(client, config_reg[i], data->fancfg[i]); in max6620_init_client()
461 data->fandyn[i] = 0x30; in max6620_init_client()
462 err = i2c_smbus_write_byte_data(client, dyn_reg[i], data->fandyn[i]); in max6620_init_client()
471 struct device *dev = &client->dev; in max6620_probe()
478 return -ENOMEM; in max6620_probe()
480 data->client = client; in max6620_probe()
481 mutex_init(&data->update_lock); in max6620_probe()
487 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, in max6620_probe()