Lines Matching +full:pwm +full:- +full:channels +full:- +full:mask
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * amc6821.c - Part of lm_sensors, Linux kernel modules for hardware
11 * Copyright (C) 2024 Guenter Roeck <linux@roeck-us.net>
19 #include <linux/hwmon-sysfs.h>
40 static int pwminv; /*Inverted PWM output. */
43 static int init = 1; /*Power-on initialization.*/
132 * temps[0]: Passive cooling temperature, applies to both channels
158 temps[2] = temps[1] + DIV_ROUND_CLOSEST(255 - regvals[0], slope); in amc6821_get_auto_point_temps()
184 return -EOPNOTSUPP; in amc6821_temp_read_values()
196 int reg, mask, err; in amc6821_read_alarms() local
204 mask = channel ? AMC6821_STAT1_RTL : AMC6821_STAT1_LTL; in amc6821_read_alarms()
208 mask = channel ? AMC6821_STAT1_RTH : AMC6821_STAT1_LTH; in amc6821_read_alarms()
212 mask = channel ? AMC6821_STAT2_RTC : AMC6821_STAT2_LTC; in amc6821_read_alarms()
216 mask = AMC6821_STAT1_RTF; in amc6821_read_alarms()
219 return -EOPNOTSUPP; in amc6821_read_alarms()
226 mask = AMC6821_STAT1_FANS; in amc6821_read_alarms()
229 return -EOPNOTSUPP; in amc6821_read_alarms()
233 return -EOPNOTSUPP; in amc6821_read_alarms()
238 *val = !!(regval & mask); in amc6821_read_alarms()
251 return amc6821_temp_read_values(data->regmap, attr, channel, val); in amc6821_temp_read()
256 return amc6821_read_alarms(data->regmap, hwmon_temp, attr, channel, val); in amc6821_temp_read()
258 return -EOPNOTSUPP; in amc6821_temp_read()
267 val = DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), 1000); in amc6821_temp_write()
280 return -EOPNOTSUPP; in amc6821_temp_write()
282 return regmap_write(data->regmap, reg, val); in amc6821_temp_write()
288 struct regmap *regmap = data->regmap; in amc6821_pwm_read()
342 return -EOPNOTSUPP; in amc6821_pwm_read()
349 struct regmap *regmap = data->regmap; in amc6821_pwm_write()
368 return -EINVAL; in amc6821_pwm_write()
375 return -EINVAL; in amc6821_pwm_write()
382 return -EINVAL; in amc6821_pwm_write()
385 return -EOPNOTSUPP; in amc6821_pwm_write()
409 return -EOPNOTSUPP; in amc6821_fan_read_rpm()
425 struct regmap *regmap = data->regmap; in amc6821_fan_read()
444 return -EOPNOTSUPP; in amc6821_fan_read()
451 struct regmap *regmap = data->regmap; in amc6821_fan_write()
457 return -EINVAL; in amc6821_fan_write()
464 return -EINVAL; in amc6821_fan_write()
469 return -EINVAL; in amc6821_fan_write()
477 return -EINVAL; in amc6821_fan_write()
481 return -EOPNOTSUPP; in amc6821_fan_write()
490 return regmap_bulk_write(data->regmap, reg, regs, 2); in amc6821_fan_write()
498 int ix = to_sensor_dev_attr_2(devattr)->index; in temp_auto_point_temp_show()
499 int nr = to_sensor_dev_attr_2(devattr)->nr; in temp_auto_point_temp_show()
503 mutex_lock(&data->update_lock); in temp_auto_point_temp_show()
504 err = amc6821_get_auto_point_temps(data->regmap, nr, temps); in temp_auto_point_temp_show()
505 mutex_unlock(&data->update_lock); in temp_auto_point_temp_show()
517 int ix = to_sensor_dev_attr(devattr)->index; in pwm1_auto_point_pwm_show()
526 err = regmap_read(data->regmap, AMC6821_REG_DCY_LOW_TEMP, &val); in pwm1_auto_point_pwm_show()
538 * Set TEMP[0-4] (low temperature) and SLP[0-2] (slope) of local or remote
539 * TEMP-FAN control register.
550 u32 pwm; in set_slope_register() local
552 err = regmap_read(regmap, AMC6821_REG_DCY_LOW_TEMP, &pwm); in set_slope_register()
556 dpwm = 255 - pwm; in set_slope_register()
558 dt = temps[2] - temps[1]; in set_slope_register()
559 for (tmp = 4; tmp > 0; tmp--) { in set_slope_register()
575 int ix = to_sensor_dev_attr_2(attr)->index; in temp_auto_point_temp_store()
576 int nr = to_sensor_dev_attr_2(attr)->nr; in temp_auto_point_temp_store()
577 struct regmap *regmap = data->regmap; in temp_auto_point_temp_store()
586 mutex_lock(&data->update_lock); in temp_auto_point_temp_store()
588 ret = amc6821_get_auto_point_temps(data->regmap, nr, temps); in temp_auto_point_temp_store()
596 * of both channels. in temp_auto_point_temp_store()
598 ret = amc6821_get_auto_point_temps(data->regmap, 1 - nr, otemps); in temp_auto_point_temp_store()
613 /* Auto-adjust high limit if necessary */ in temp_auto_point_temp_store()
624 ret = -EINVAL; in temp_auto_point_temp_store()
628 mutex_unlock(&data->update_lock); in temp_auto_point_temp_store()
637 struct regmap *regmap = data->regmap; in pwm1_auto_point_pwm_store()
645 mutex_lock(&data->update_lock); in pwm1_auto_point_pwm_store()
661 mutex_unlock(&data->update_lock); in pwm1_auto_point_pwm_store()
707 return -EOPNOTSUPP; in amc6821_read()
722 return -EOPNOTSUPP; in amc6821_write()
787 HWMON_CHANNEL_INFO(pwm,
804 /* Return 0 if detection is successful, -ENODEV otherwise */
807 struct i2c_adapter *adapter = client->adapter; in amc6821_detect()
808 int address = client->addr; in amc6821_detect()
811 dev_dbg(&adapter->dev, "amc6821_detect called.\n"); in amc6821_detect()
814 dev_dbg(&adapter->dev, in amc6821_detect()
817 return -ENODEV; in amc6821_detect()
823 dev_dbg(&adapter->dev, in amc6821_detect()
826 return -ENODEV; in amc6821_detect()
836 dev_dbg(&adapter->dev, in amc6821_detect()
839 return -ENODEV; in amc6821_detect()
842 dev_info(&adapter->dev, "amc6821: chip found at 0x%02x.\n", address); in amc6821_detect()
843 strscpy(info->type, "amc6821", I2C_NAME_SIZE); in amc6821_detect()
850 struct regmap *regmap = data->regmap; in amc6821_init_client()
903 struct device *dev = &client->dev; in amc6821_probe()
911 return -ENOMEM; in amc6821_probe()
917 data->regmap = regmap; in amc6821_probe()
923 if (of_device_is_compatible(dev->of_node, "tsd,mule")) { in amc6821_probe()
927 "Failed to create sub-devices\n"); in amc6821_probe()
930 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, in amc6821_probe()