Lines Matching +full:hardware +full:- +full:wise

1 // SPDX-License-Identifier: GPL-2.0+
3 * Hardware monitoring driver for EMC2305 fan controller
59 * struct emc2305_cdev_data - device-specific cooling device state
67 * according to some system wise considerations, like absence of some replaceable units (PSU or
75 * From other side, fan speed is to be updated in hardware through 'pwm' only in case the
87 * struct emc2305_data - device-specific data
119 return data->pwm_num; in emc2305_get_max_channel()
124 struct emc2305_data *data = cdev->devdata; in emc2305_get_cdev_idx()
125 size_t len = strlen(cdev->type); in emc2305_get_cdev_idx()
129 return -EINVAL; in emc2305_get_cdev_idx()
140 if (!data->pwm_separate) in emc2305_get_cdev_idx()
143 ret = cdev->type[len - 1]; in emc2305_get_cdev_idx()
146 return ret - '1'; in emc2305_get_cdev_idx()
150 return -EINVAL; in emc2305_get_cdev_idx()
156 struct emc2305_data *data = cdev->devdata; in emc2305_get_cur_state()
162 *state = data->cdev_data[cdev_idx].cur_state; in emc2305_get_cur_state()
168 struct emc2305_data *data = cdev->devdata; in emc2305_get_max_state()
169 *state = data->max_state; in emc2305_get_max_state()
176 struct i2c_client *client = data->client; in __emc2305_set_cur_state()
179 state = max_t(unsigned long, state, data->cdev_data[cdev_idx].last_hwmon_state); in __emc2305_set_cur_state()
181 val = EMC2305_PWM_STATE2DUTY(state, data->max_state, EMC2305_FAN_MAX); in __emc2305_set_cur_state()
183 data->cdev_data[cdev_idx].cur_state = state; in __emc2305_set_cur_state()
184 if (data->pwm_separate) { in __emc2305_set_cur_state()
193 for (i = 0; i < data->pwm_num; i++) { in __emc2305_set_cur_state()
206 struct emc2305_data *data = cdev->devdata; in emc2305_set_cur_state()
208 if (state > data->max_state) in emc2305_set_cur_state()
209 return -EINVAL; in emc2305_set_cur_state()
216 data->cdev_data[cdev_idx].last_thermal_state = state; in emc2305_set_cur_state()
233 struct i2c_client *client = data->client; in emc2305_show_fault()
246 struct i2c_client *client = data->client; in emc2305_show_fan()
264 struct i2c_client *client = data->client; in emc2305_show_pwm()
272 struct i2c_client *client = data->client; in emc2305_set_pwm()
275 if (val < data->pwm_min[channel] || val > EMC2305_FAN_MAX) in emc2305_set_pwm()
276 return -EINVAL; in emc2305_set_pwm()
281 data->cdev_data[channel].cur_state = EMC2305_PWM_DUTY2STATE(val, data->max_state, in emc2305_set_pwm()
292 cdev_idx = (idx) ? idx - 1 : 0; in emc2305_set_single_tz()
293 pwm = data->pwm_min[cdev_idx]; in emc2305_set_single_tz()
295 data->cdev_data[cdev_idx].cdev = in emc2305_set_single_tz()
299 if (IS_ERR(data->cdev_data[cdev_idx].cdev)) { in emc2305_set_single_tz()
301 return PTR_ERR(data->cdev_data[cdev_idx].cdev); in emc2305_set_single_tz()
304 if (data->pwm_separate) { in emc2305_set_single_tz()
309 for (i = 0; i < data->pwm_num; i++) { in emc2305_set_single_tz()
315 data->cdev_data[cdev_idx].cur_state = in emc2305_set_single_tz()
316 EMC2305_PWM_DUTY2STATE(data->pwm_min[cdev_idx], data->max_state, in emc2305_set_single_tz()
318 data->cdev_data[cdev_idx].last_hwmon_state = in emc2305_set_single_tz()
319 EMC2305_PWM_DUTY2STATE(data->pwm_min[cdev_idx], data->max_state, in emc2305_set_single_tz()
329 if (!data->pwm_separate) in emc2305_set_tz()
332 for (i = 0; i < data->pwm_num; i++) { in emc2305_set_tz()
351 if (data->cdev_data[i].cdev) in emc2305_unset_tz()
352 thermal_cooling_device_unregister(data->cdev_data[i].cdev); in emc2305_unset_tz()
399 /* If thermal is configured - handle PWM limit setting. */ in emc2305_write()
401 if (data->pwm_separate) in emc2305_write()
405 data->cdev_data[cdev_idx].last_hwmon_state = in emc2305_write()
406 EMC2305_PWM_DUTY2STATE(val, data->max_state, in emc2305_write()
412 if (data->cdev_data[cdev_idx].last_hwmon_state >= in emc2305_write()
413 data->cdev_data[cdev_idx].last_thermal_state) in emc2305_write()
415 data->cdev_data[cdev_idx].last_hwmon_state); in emc2305_write()
427 return -EOPNOTSUPP; in emc2305_write()
470 return -EOPNOTSUPP; in emc2305_read()
512 data->pwm_num = 5; in emc2305_identify()
515 data->pwm_num = 3; in emc2305_identify()
518 data->pwm_num = 2; in emc2305_identify()
521 data->pwm_num = 1; in emc2305_identify()
524 return -ENODEV; in emc2305_identify()
532 struct i2c_adapter *adapter = client->adapter; in emc2305_probe()
533 struct device *dev = &client->dev; in emc2305_probe()
541 return -ENODEV; in emc2305_probe()
545 return -ENODEV; in emc2305_probe()
549 return -ENOMEM; in emc2305_probe()
552 data->client = client; in emc2305_probe()
558 pdata = dev_get_platdata(&client->dev); in emc2305_probe()
560 if (!pdata->max_state || pdata->max_state > EMC2305_FAN_MAX_STATE) in emc2305_probe()
561 return -EINVAL; in emc2305_probe()
562 data->max_state = pdata->max_state; in emc2305_probe()
568 if (!pdata->pwm_num || pdata->pwm_num > EMC2305_PWM_MAX) in emc2305_probe()
569 return -EINVAL; in emc2305_probe()
570 data->pwm_num = pdata->pwm_num; in emc2305_probe()
571 data->pwm_separate = pdata->pwm_separate; in emc2305_probe()
573 data->pwm_min[i] = pdata->pwm_min[i]; in emc2305_probe()
575 data->max_state = EMC2305_FAN_MAX_STATE; in emc2305_probe()
576 data->pwm_separate = false; in emc2305_probe()
578 data->pwm_min[i] = EMC2305_FAN_MIN; in emc2305_probe()
581 data->hwmon_dev = devm_hwmon_device_register_with_info(dev, "emc2305", data, in emc2305_probe()
583 if (IS_ERR(data->hwmon_dev)) in emc2305_probe()
584 return PTR_ERR(data->hwmon_dev); in emc2305_probe()
592 for (i = 0; i < data->pwm_num; i++) { in emc2305_probe()
594 data->pwm_min[i]); in emc2305_probe()
604 struct device *dev = &client->dev; in emc2305_remove()