Lines Matching +full:channel +full:- +full:7

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2012 Guenter Roeck <linux@roeck-us.net>
38 * Applies to alert register and over-temperature register.
41 #define MAX6697_EXTERNAL_MASK_DT GENMASK(7, 1)
44 #define MAX6697_LOCAL_MASK_CHIP BIT(7)
46 /* alert - local channel is in bit 6 */
50 /* over-temperature - local channel is in bit 7 */
73 #define MAX6581_OFFSET_MIN -31750
76 #define MAX6697_CONV_TIME 156 /* ms per channel, worst case */
126 .channels = 7,
133 .channels = 7,
140 .channels = 7,
156 .channels = 7,
163 .channels = 7,
178 static int max6697_alarm_channel_map(int channel) in max6697_alarm_channel_map() argument
180 switch (channel) { in max6697_alarm_channel_map()
183 case 7: in max6697_alarm_channel_map()
184 return 7; in max6697_alarm_channel_map()
186 return channel - 1; in max6697_alarm_channel_map()
191 u32 attr, int channel, long *val) in max6697_read() argument
194 unsigned int temp_regs[2] = { MAX6697_REG_TEMP[channel], in max6697_read()
195 MAX6697_REG_TEMP_EXT[channel] }; in max6697_read()
197 struct regmap *regmap = data->regmap; in max6697_read()
205 data->chip->have_ext & BIT(channel) ? 2 : 1); in max6697_read()
208 *val = (((regdata[0] - data->temp_offset) << 3) | (regdata[1] >> 5)) * 125; in max6697_read()
211 ret = regmap_read(regmap, MAX6697_REG_MAX[channel], &regval); in max6697_read()
214 *val = ((int)regval - data->temp_offset) * 1000; in max6697_read()
217 ret = regmap_read(regmap, MAX6697_REG_CRIT[channel], &regval); in max6697_read()
220 *val = ((int)regval - data->temp_offset) * 1000; in max6697_read()
226 *val = ((int)regval - data->temp_offset) * 1000; in max6697_read()
233 if (!(regdata[0] & BIT(channel - 1))) in max6697_read()
236 *val = sign_extend32(regdata[1], 7) * 250; in max6697_read()
242 if (data->type == max6581) in max6697_read()
243 *val = !!(regval & BIT(channel - 1)); in max6697_read()
245 *val = !!(regval & BIT(channel)); in max6697_read()
252 * In the MAX6581 datasheet revision 0 to 3, the local channel in max6697_read()
254 * and the overtemperature status for remote channel 7 is in max6697_read()
255 * reported in bit 7. In Revision 4 and later, the local channel in max6697_read()
256 * overtemperature status is reported in bit 7, and the remote in max6697_read()
257 * channel 7 overtemperature status is reported in bit 6. A real in max6697_read()
261 *val = !!(regval & BIT(channel ? channel - 1 : 7)); in max6697_read()
267 *val = !!(regval & BIT(max6697_alarm_channel_map(channel))); in max6697_read()
273 *val = !!(regval & BIT(max6697_alarm_channel_map(channel))); in max6697_read()
276 return -EOPNOTSUPP; in max6697_read()
282 u32 attr, int channel, long val) in max6697_write() argument
285 struct regmap *regmap = data->regmap; in max6697_write()
290 val = clamp_val(val, -1000000, 1000000); /* prevent underflow */ in max6697_write()
291 val = DIV_ROUND_CLOSEST(val, 1000) + data->temp_offset; in max6697_write()
292 val = clamp_val(val, 0, data->type == max6581 ? 255 : 127); in max6697_write()
293 return regmap_write(regmap, MAX6697_REG_MAX[channel], val); in max6697_write()
295 val = clamp_val(val, -1000000, 1000000); /* prevent underflow */ in max6697_write()
296 val = DIV_ROUND_CLOSEST(val, 1000) + data->temp_offset; in max6697_write()
297 val = clamp_val(val, 0, data->type == max6581 ? 255 : 127); in max6697_write()
298 return regmap_write(regmap, MAX6697_REG_CRIT[channel], val); in max6697_write()
300 val = clamp_val(val, -1000000, 1000000); /* prevent underflow */ in max6697_write()
301 val = DIV_ROUND_CLOSEST(val, 1000) + data->temp_offset; in max6697_write()
305 mutex_lock(&data->update_lock); in max6697_write()
308 if (!val) { /* disable this (and only this) channel */ in max6697_write()
310 BIT(channel - 1)); in max6697_write()
312 /* enable channel and update offset */ in max6697_write()
314 BIT(channel - 1)); in max6697_write()
320 mutex_unlock(&data->update_lock); in max6697_write()
323 return -EOPNOTSUPP; in max6697_write()
328 u32 attr, int channel) in max6697_is_visible() argument
331 const struct max6697_chip_data *chip = data->chip; in max6697_is_visible()
333 if (channel >= chip->channels) in max6697_is_visible()
343 if (data->type == max6581) in max6697_is_visible()
344 return channel ? 0444 : 0644; in max6697_is_visible()
347 if (data->type == max6581) in max6697_is_visible()
351 if (chip->have_crit & BIT(channel)) in max6697_is_visible()
355 if (chip->have_crit & BIT(channel)) in max6697_is_visible()
359 if (chip->have_fault & BIT(channel)) in max6697_is_visible()
363 if (data->type == max6581 && channel) in max6697_is_visible()
372 /* Return 0 if detection is successful, -ENODEV otherwise */
422 const struct max6697_chip_data *chip = data->chip; in max6697_config_of()
423 struct regmap *regmap = data->regmap; in max6697_config_of()
428 if (of_property_read_bool(node, "smbus-timeout-disable") && in max6697_config_of()
429 (chip->valid_conf & MAX6697_CONF_TIMEOUT)) { in max6697_config_of()
432 if (of_property_read_bool(node, "extended-range-enable") && in max6697_config_of()
433 (chip->valid_conf & MAX6581_CONF_EXTENDED)) { in max6697_config_of()
435 data->temp_offset = 64; in max6697_config_of()
437 if (of_property_read_bool(node, "beta-compensation-enable") && in max6697_config_of()
438 (chip->valid_conf & MAX6693_CONF_BETA)) { in max6697_config_of()
442 if (of_property_read_u32(node, "alert-mask", vals)) in max6697_config_of()
449 if (of_property_read_u32(node, "over-temperature-mask", vals)) in max6697_config_of()
456 if (data->type != max6581) { in max6697_config_of()
457 if (of_property_read_bool(node, "resistance-cancellation") && in max6697_config_of()
458 chip->valid_conf & MAX6697_CONF_RESISTANCE) { in max6697_config_of()
462 if (of_property_read_u32(node, "resistance-cancellation", &vals[0])) { in max6697_config_of()
463 if (of_property_read_bool(node, "resistance-cancellation")) in max6697_config_of()
474 if (of_property_read_u32_array(node, "transistor-ideality", vals, 2)) { in max6697_config_of()
500 struct regmap *regmap = data->regmap; in max6697_init_chip()
505 if (data->type == max6581) { in max6697_init_chip()
507 data->temp_offset = 64; in max6697_init_chip()
545 struct device *dev = &client->dev; in max6697_probe()
557 return -ENOMEM; in max6697_probe()
559 data->regmap = regmap; in max6697_probe()
560 data->type = (uintptr_t)i2c_get_match_data(client); in max6697_probe()
561 data->chip = &max6697_chip_data[data->type]; in max6697_probe()
562 mutex_init(&data->update_lock); in max6697_probe()
564 err = max6697_init_chip(client->dev.of_node, data); in max6697_probe()
568 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data, in max6697_probe()
644 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");