Lines Matching +full:data +full:- +full:bits

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * max31790.c - Part of lm_sensors, Linux kernel modules for hardware
28 /* Fan Config register bits */
34 /* Fan Dynamics register bits */
53 * Client data (each client gets its own)
72 struct max31790_data *data = dev_get_drvdata(dev); in max31790_update_device() local
73 struct i2c_client *client = data->client; in max31790_update_device()
74 struct max31790_data *ret = data; in max31790_update_device()
78 mutex_lock(&data->update_lock); in max31790_update_device()
80 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { in max31790_update_device()
85 data->fault_status |= rv & 0x3F; in max31790_update_device()
91 data->fault_status |= (rv & 0x3F) << 6; in max31790_update_device()
98 data->tach[i] = rv; in max31790_update_device()
100 if (data->fan_config[i] in max31790_update_device()
107 data->tach[NR_CHANNEL + i] = rv; in max31790_update_device()
113 data->pwm[i] = rv; in max31790_update_device()
119 data->target_count[i] = rv; in max31790_update_device()
123 data->last_updated = jiffies; in max31790_update_device()
124 data->valid = true; in max31790_update_device()
129 data->valid = false; in max31790_update_device()
133 mutex_unlock(&data->update_lock); in max31790_update_device()
147 u8 bits; in bits_for_tach_period() local
150 bits = 0x0; in bits_for_tach_period()
152 bits = 0x1; in bits_for_tach_period()
154 bits = 0x2; in bits_for_tach_period()
156 bits = 0x3; in bits_for_tach_period()
158 bits = 0x4; in bits_for_tach_period()
160 bits = 0x5; in bits_for_tach_period()
162 return bits; in bits_for_tach_period()
168 struct max31790_data *data = max31790_update_device(dev); in max31790_read_fan() local
171 if (IS_ERR(data)) in max31790_read_fan()
172 return PTR_ERR(data); in max31790_read_fan()
176 sr = get_tach_period(data->fan_dynamics[channel % NR_CHANNEL]); in max31790_read_fan()
177 if (data->tach[channel] == FAN_COUNT_REG_MAX) in max31790_read_fan()
180 rpm = RPM_FROM_REG(data->tach[channel], sr); in max31790_read_fan()
184 sr = get_tach_period(data->fan_dynamics[channel]); in max31790_read_fan()
185 rpm = RPM_FROM_REG(data->target_count[channel], sr); in max31790_read_fan()
189 mutex_lock(&data->update_lock); in max31790_read_fan()
190 *val = !!(data->fault_status & (1 << channel)); in max31790_read_fan()
191 data->fault_status &= ~(1 << channel); in max31790_read_fan()
200 i2c_smbus_write_byte_data(data->client, reg, in max31790_read_fan()
201 data->target_count[channel % NR_CHANNEL] >> 8); in max31790_read_fan()
203 mutex_unlock(&data->update_lock); in max31790_read_fan()
206 *val = !!(data->fan_config[channel] & MAX31790_FAN_CFG_TACH_INPUT_EN); in max31790_read_fan()
209 return -EOPNOTSUPP; in max31790_read_fan()
216 struct max31790_data *data = dev_get_drvdata(dev); in max31790_write_fan() local
217 struct i2c_client *client = data->client; in max31790_write_fan()
220 u8 bits, fan_config; in max31790_write_fan() local
223 mutex_lock(&data->update_lock); in max31790_write_fan()
228 bits = bits_for_tach_period(val); in max31790_write_fan()
229 data->fan_dynamics[channel] = in max31790_write_fan()
230 ((data->fan_dynamics[channel] & in max31790_write_fan()
232 (bits << MAX31790_FAN_DYN_SR_SHIFT)); in max31790_write_fan()
235 data->fan_dynamics[channel]); in max31790_write_fan()
239 sr = get_tach_period(data->fan_dynamics[channel]); in max31790_write_fan()
243 data->target_count[channel] = target_count << 5; in max31790_write_fan()
247 data->target_count[channel]); in max31790_write_fan()
250 fan_config = data->fan_config[channel]; in max31790_write_fan()
256 err = -EINVAL; in max31790_write_fan()
259 if (fan_config != data->fan_config[channel]) { in max31790_write_fan()
263 data->fan_config[channel] = fan_config; in max31790_write_fan()
267 err = -EOPNOTSUPP; in max31790_write_fan()
271 mutex_unlock(&data->update_lock); in max31790_write_fan()
278 const struct max31790_data *data = _data; in max31790_fan_is_visible() local
279 u8 fan_config = data->fan_config[channel % NR_CHANNEL]; in max31790_fan_is_visible()
305 struct max31790_data *data = max31790_update_device(dev); in max31790_read_pwm() local
308 if (IS_ERR(data)) in max31790_read_pwm()
309 return PTR_ERR(data); in max31790_read_pwm()
311 fan_config = data->fan_config[channel]; in max31790_read_pwm()
315 *val = data->pwm[channel] >> 8; in max31790_read_pwm()
326 return -EOPNOTSUPP; in max31790_read_pwm()
333 struct max31790_data *data = dev_get_drvdata(dev); in max31790_write_pwm() local
334 struct i2c_client *client = data->client; in max31790_write_pwm()
338 mutex_lock(&data->update_lock); in max31790_write_pwm()
343 err = -EINVAL; in max31790_write_pwm()
346 data->valid = false; in max31790_write_pwm()
352 fan_config = data->fan_config[channel]; in max31790_write_pwm()
372 err = -EINVAL; in max31790_write_pwm()
375 if (fan_config != data->fan_config[channel]) { in max31790_write_pwm()
379 data->fan_config[channel] = fan_config; in max31790_write_pwm()
383 err = -EOPNOTSUPP; in max31790_write_pwm()
387 mutex_unlock(&data->update_lock); in max31790_write_pwm()
394 const struct max31790_data *data = _data; in max31790_pwm_is_visible() local
395 u8 fan_config = data->fan_config[channel]; in max31790_pwm_is_visible()
417 return -EOPNOTSUPP; in max31790_read()
430 return -EOPNOTSUPP; in max31790_write()
434 static umode_t max31790_is_visible(const void *data, in max31790_is_visible() argument
440 return max31790_fan_is_visible(data, attr, channel); in max31790_is_visible()
442 return max31790_pwm_is_visible(data, attr, channel); in max31790_is_visible()
484 struct max31790_data *data) in max31790_init_client() argument
493 data->fan_config[i] = rv; in max31790_init_client()
499 data->fan_dynamics[i] = rv; in max31790_init_client()
507 struct i2c_adapter *adapter = client->adapter; in max31790_probe()
508 struct device *dev = &client->dev; in max31790_probe()
509 struct max31790_data *data; in max31790_probe() local
515 return -ENODEV; in max31790_probe()
517 data = devm_kzalloc(dev, sizeof(struct max31790_data), GFP_KERNEL); in max31790_probe()
518 if (!data) in max31790_probe()
519 return -ENOMEM; in max31790_probe()
521 data->client = client; in max31790_probe()
522 mutex_init(&data->update_lock); in max31790_probe()
527 err = max31790_init_client(client, data); in max31790_probe()
531 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, in max31790_probe()
532 data, in max31790_probe()