Lines Matching +full:gpio +full:- +full:pol
1 // SPDX-License-Identifier: GPL-2.0
12 #include <linux/hwmon-sysfs.h>
66 #define VOLTAGE_MIN -300
77 #define CURRENT_MIN -30000
86 #define POWER_MIN -450000000
98 #define TEMP_MIN -40000
108 #define LTC2947_ALERTS_SIZE (LTC2947_REG_STATVDVCC - LTC2947_REG_STATUS)
126 * complete sequence select_page->read/write needs to be protected.
139 ret = regmap_bulk_read(st->map, reg, &__val, 2); in __ltc2947_val_read16()
154 ret = regmap_bulk_read(st->map, reg, &__val, 3); in __ltc2947_val_read24()
169 ret = regmap_bulk_read(st->map, reg, &__val, 6); in __ltc2947_val_read64()
184 mutex_lock(&st->lock); in ltc2947_val_read()
186 ret = regmap_write(st->map, LTC2947_REG_PAGE_CTRL, page); in ltc2947_val_read()
188 mutex_unlock(&st->lock); in ltc2947_val_read()
192 dev_dbg(st->dev, "Read val, reg:%02X, p:%d sz:%zu\n", reg, page, in ltc2947_val_read()
206 ret = -EINVAL; in ltc2947_val_read()
210 mutex_unlock(&st->lock); in ltc2947_val_read()
215 *val = sign_extend64(__val, (8 * size) - 1); in ltc2947_val_read()
217 dev_dbg(st->dev, "Got s:%lld, u:%016llX\n", *val, __val); in ltc2947_val_read()
228 return regmap_bulk_write(st->map, reg, &__val, 6); in __ltc2947_val_write64()
237 return regmap_bulk_write(st->map, reg, &__val, 2); in __ltc2947_val_write16()
245 mutex_lock(&st->lock); in ltc2947_val_write()
247 ret = regmap_write(st->map, LTC2947_REG_PAGE_CTRL, page); in ltc2947_val_write()
249 mutex_unlock(&st->lock); in ltc2947_val_write()
253 dev_dbg(st->dev, "Write val, r:%02X, p:%d, sz:%zu, val:%016llX\n", in ltc2947_val_write()
264 ret = -EINVAL; in ltc2947_val_write()
268 mutex_unlock(&st->lock); in ltc2947_val_write()
291 u8 offset = reg - LTC2947_REG_STATUS; in ltc2947_alarm_read()
298 mutex_lock(&st->lock); in ltc2947_alarm_read()
300 ret = regmap_write(st->map, LTC2947_REG_PAGE_CTRL, LTC2947_PAGE0); in ltc2947_alarm_read()
304 dev_dbg(st->dev, "Read alarm, reg:%02X, mask:%02X\n", reg, mask); in ltc2947_alarm_read()
308 * multi-byte transaction. in ltc2947_alarm_read()
310 ret = regmap_bulk_read(st->map, LTC2947_REG_STATUS, alarms, in ltc2947_alarm_read()
318 mutex_unlock(&st->lock); in ltc2947_alarm_read()
330 ret = ltc2947_val_read(st, attr->index, LTC2947_PAGE0, 6, &val); in ltc2947_show_value()
334 /* value in microJoule. st->lsb_energy was multiplied by 10E9 */ in ltc2947_show_value()
335 val = div_s64(val * st->lsb_energy, 1000); in ltc2947_show_value()
393 return -ENOTSUPP; in ltc2947_read_temp()
441 return -ENOTSUPP; in ltc2947_read_power()
488 return -ENOTSUPP; in ltc2947_read_curr()
508 dev_err(st->dev, "Invalid chan%d for voltage", channel); in ltc2947_read_in()
509 return -EINVAL; in ltc2947_read_in()
580 return -ENOTSUPP; in ltc2947_read_in()
604 return -ENOTSUPP; in ltc2947_read()
614 dev_err(st->dev, "Invalid chan%d for temperature", channel); in ltc2947_write_temp()
615 return -EINVAL; in ltc2947_write_temp()
621 return -EINVAL; in ltc2947_write_temp()
627 if (!st->gpio_out) in ltc2947_write_temp()
628 return -ENOTSUPP; in ltc2947_write_temp()
633 DIV_ROUND_CLOSEST(val - 550, 204)); in ltc2947_write_temp()
638 DIV_ROUND_CLOSEST(val - 550, 204)); in ltc2947_write_temp()
642 if (!st->gpio_out) in ltc2947_write_temp()
643 return -ENOTSUPP; in ltc2947_write_temp()
648 DIV_ROUND_CLOSEST(val - 550, 204)); in ltc2947_write_temp()
653 DIV_ROUND_CLOSEST(val - 550, 204)); in ltc2947_write_temp()
655 return -ENOTSUPP; in ltc2947_write_temp()
667 return -EINVAL; in ltc2947_write_power()
681 return -ENOTSUPP; in ltc2947_write_power()
693 return -EINVAL; in ltc2947_write_curr()
707 return -ENOTSUPP; in ltc2947_write_curr()
717 dev_err(st->dev, "Invalid chan%d for voltage", channel); in ltc2947_write_in()
718 return -EINVAL; in ltc2947_write_in()
724 return -EINVAL; in ltc2947_write_in()
757 return -ENOTSUPP; in ltc2947_write_in()
775 return -ENOTSUPP; in ltc2947_write()
788 *str = "VP-VM"; in ltc2947_read_labels()
791 *str = "IP-IM"; in ltc2947_read_labels()
803 return -ENOTSUPP; in ltc2947_read_labels()
964 u32 dummy, deadband, pol; in ltc2947_setup() local
968 ret = regmap_read(st->map, LTC2947_REG_STATUS, &dummy); in ltc2947_setup()
986 extclk = devm_clk_get_optional_enabled(st->dev, NULL); in ltc2947_setup()
988 return dev_err_probe(st->dev, PTR_ERR(extclk), in ltc2947_setup()
999 dev_err(st->dev, "Invalid rate:%lu for external clock", in ltc2947_setup()
1001 return -EINVAL; in ltc2947_setup()
1024 ret = regmap_write(st->map, LTC2947_REG_TBCTL, tbctl); in ltc2947_setup()
1033 st->lsb_energy = DIV_ROUND_CLOSEST_ULL(aux, rate_hz); in ltc2947_setup()
1035 /* 19.89E-6 * 10E9 */ in ltc2947_setup()
1036 st->lsb_energy = 19890; in ltc2947_setup()
1038 ret = device_property_read_u32_array(st->dev, "adi,accumulator-ctl-pol", in ltc2947_setup()
1044 ret = regmap_write(st->map, LTC2947_REG_ACCUM_POL, accum_reg); in ltc2947_setup()
1048 ret = device_property_read_u32(st->dev, in ltc2947_setup()
1049 "adi,accumulation-deadband-microamp", in ltc2947_setup()
1053 ret = regmap_write(st->map, LTC2947_REG_ACCUM_DEADBAND, in ltc2947_setup()
1058 /* check gpio cfg */ in ltc2947_setup()
1059 ret = device_property_read_u32(st->dev, "adi,gpio-out-pol", &pol); in ltc2947_setup()
1061 /* setup GPIO as output */ in ltc2947_setup()
1063 LTC2947_GPIO_FAN_POL(pol); in ltc2947_setup()
1065 st->gpio_out = true; in ltc2947_setup()
1066 ret = regmap_write(st->map, LTC2947_REG_GPIOSTATCTL, gpio_ctl); in ltc2947_setup()
1070 ret = device_property_read_u32_array(st->dev, "adi,gpio-in-accum", in ltc2947_setup()
1080 if (st->gpio_out) { in ltc2947_setup()
1081 dev_err(st->dev, in ltc2947_setup()
1082 "Cannot have input gpio config if already configured as output"); in ltc2947_setup()
1083 return -EINVAL; in ltc2947_setup()
1086 ret = regmap_write(st->map, LTC2947_REG_GPIO_ACCUM, accum_val); in ltc2947_setup()
1092 return regmap_update_bits(st->map, LTC2947_REG_CTRL, in ltc2947_setup()
1105 return -ENOMEM; in ltc2947_core_probe()
1107 st->map = map; in ltc2947_core_probe()
1108 st->dev = dev; in ltc2947_core_probe()
1110 mutex_init(&st->lock); in ltc2947_core_probe()
1130 ret = regmap_read(st->map, LTC2947_REG_CTRL, &ctrl); in ltc2947_resume()
1138 ret = regmap_read(st->map, LTC2947_REG_CTRL, &ctrl); in ltc2947_resume()
1143 dev_err(st->dev, "Device failed to wake up, ctl:%02X\n", ctrl); in ltc2947_resume()
1144 return -ETIMEDOUT; in ltc2947_resume()
1148 return regmap_update_bits(st->map, LTC2947_REG_CTRL, in ltc2947_resume()
1156 return regmap_update_bits(st->map, LTC2947_REG_CTRL, in ltc2947_suspend()