1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2012 Guenter Roeck <linux@roeck-us.net>
6 * Copyright (c) 2011 David George <david.george@ska.ac.za>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/slab.h>
12 #include <linux/jiffies.h>
13 #include <linux/i2c.h>
14 #include <linux/hwmon.h>
15 #include <linux/hwmon-sysfs.h>
16 #include <linux/err.h>
17 #include <linux/mutex.h>
20 #include <linux/platform_data/max6697.h>
22 enum chips { max6581, max6602, max6622, max6636, max6689, max6693, max6694,
23 max6697, max6698, max6699 };
25 /* Report local sensor as temp1 */
27 static const u8 MAX6697_REG_TEMP[] = {
28 0x07, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08 };
29 static const u8 MAX6697_REG_TEMP_EXT[] = {
30 0x57, 0x09, 0x52, 0x53, 0x54, 0x55, 0x56, 0 };
31 static const u8 MAX6697_REG_MAX[] = {
32 0x17, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x18 };
33 static const u8 MAX6697_REG_CRIT[] = {
34 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 };
37 * Map device tree / platform data register bit map to chip bit map.
38 * Applies to alert register and over-temperature register.
40 #define MAX6697_ALERT_MAP_BITS(reg) ((((reg) & 0x7e) >> 1) | \
41 (((reg) & 0x01) << 6) | ((reg) & 0x80))
42 #define MAX6697_OVERT_MAP_BITS(reg) (((reg) >> 1) | (((reg) & 0x01) << 7))
44 #define MAX6697_REG_STAT(n) (0x44 + (n))
46 #define MAX6697_REG_CONFIG 0x41
47 #define MAX6581_CONF_EXTENDED (1 << 1)
48 #define MAX6693_CONF_BETA (1 << 2)
49 #define MAX6697_CONF_RESISTANCE (1 << 3)
50 #define MAX6697_CONF_TIMEOUT (1 << 5)
51 #define MAX6697_REG_ALERT_MASK 0x42
52 #define MAX6697_REG_OVERT_MASK 0x43
54 #define MAX6581_REG_RESISTANCE 0x4a
55 #define MAX6581_REG_IDEALITY 0x4b
56 #define MAX6581_REG_IDEALITY_SELECT 0x4c
57 #define MAX6581_REG_OFFSET 0x4d
58 #define MAX6581_REG_OFFSET_SELECT 0x4e
59 #define MAX6581_OFFSET_MIN -31750
60 #define MAX6581_OFFSET_MAX 31750
62 #define MAX6697_CONV_TIME 156 /* ms per channel, worst case */
64 struct max6697_chip_data {
74 struct i2c_client *client;
77 const struct max6697_chip_data *chip;
79 int update_interval; /* in milli-seconds */
80 int temp_offset; /* in degrees C */
82 struct mutex update_lock;
83 unsigned long last_updated; /* In jiffies */
84 bool valid; /* true if following fields are valid */
86 /* 1x local and up to 7x remote */
87 u8 temp[8][4]; /* [nr][0]=temp [1]=ext [2]=max [3]=crit */
88 #define MAX6697_TEMP_INPUT 0
89 #define MAX6697_TEMP_EXT 1
90 #define MAX6697_TEMP_MAX 2
91 #define MAX6697_TEMP_CRIT 3
95 /* Diode fault status bits on MAX6581 are right shifted by one bit */
96 static const u8 max6581_alarm_map[] = {
97 0, 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15,
98 16, 17, 18, 19, 20, 21, 22, 23 };
100 static const struct max6697_chip_data max6697_chip_data[] = {
106 .valid_conf = MAX6581_CONF_EXTENDED | MAX6697_CONF_TIMEOUT,
107 .alarm_map = max6581_alarm_map,
114 .valid_conf = MAX6697_CONF_RESISTANCE | MAX6697_CONF_TIMEOUT,
121 .valid_conf = MAX6697_CONF_RESISTANCE | MAX6697_CONF_TIMEOUT,
128 .valid_conf = MAX6697_CONF_RESISTANCE | MAX6697_CONF_TIMEOUT,
135 .valid_conf = MAX6697_CONF_RESISTANCE | MAX6697_CONF_TIMEOUT,
142 .valid_conf = MAX6697_CONF_RESISTANCE | MAX6693_CONF_BETA |
143 MAX6697_CONF_TIMEOUT,
150 .valid_conf = MAX6697_CONF_RESISTANCE | MAX6693_CONF_BETA |
151 MAX6697_CONF_TIMEOUT,
158 .valid_conf = MAX6697_CONF_RESISTANCE | MAX6697_CONF_TIMEOUT,
165 .valid_conf = MAX6697_CONF_RESISTANCE | MAX6697_CONF_TIMEOUT,
172 .valid_conf = MAX6697_CONF_RESISTANCE | MAX6697_CONF_TIMEOUT,
176 static inline int max6581_offset_to_millic(int val)
178 return sign_extend32(val, 7) * 250;
181 static struct max6697_data *max6697_update_device(struct device *dev)
183 struct max6697_data *data = dev_get_drvdata(dev);
184 struct i2c_client *client = data->client;
185 struct max6697_data *ret = data;
190 mutex_lock(&data->update_lock);
193 !time_after(jiffies, data->last_updated
194 + msecs_to_jiffies(data->update_interval)))
197 for (i = 0; i < data->chip->channels; i++) {
198 if (data->chip->have_ext & (1 << i)) {
199 val = i2c_smbus_read_byte_data(client,
200 MAX6697_REG_TEMP_EXT[i]);
201 if (unlikely(val < 0)) {
205 data->temp[i][MAX6697_TEMP_EXT] = val;
208 val = i2c_smbus_read_byte_data(client, MAX6697_REG_TEMP[i]);
209 if (unlikely(val < 0)) {
213 data->temp[i][MAX6697_TEMP_INPUT] = val;
215 val = i2c_smbus_read_byte_data(client, MAX6697_REG_MAX[i]);
216 if (unlikely(val < 0)) {
220 data->temp[i][MAX6697_TEMP_MAX] = val;
222 if (data->chip->have_crit & (1 << i)) {
223 val = i2c_smbus_read_byte_data(client,
224 MAX6697_REG_CRIT[i]);
225 if (unlikely(val < 0)) {
229 data->temp[i][MAX6697_TEMP_CRIT] = val;
234 for (i = 0; i < 3; i++) {
235 val = i2c_smbus_read_byte_data(client, MAX6697_REG_STAT(i));
236 if (unlikely(val < 0)) {
240 alarms = (alarms << 8) | val;
242 data->alarms = alarms;
243 data->last_updated = jiffies;
246 mutex_unlock(&data->update_lock);
251 static ssize_t temp_input_show(struct device *dev,
252 struct device_attribute *devattr, char *buf)
254 int index = to_sensor_dev_attr(devattr)->index;
255 struct max6697_data *data = max6697_update_device(dev);
259 return PTR_ERR(data);
261 temp = (data->temp[index][MAX6697_TEMP_INPUT] - data->temp_offset) << 3;
262 temp |= data->temp[index][MAX6697_TEMP_EXT] >> 5;
264 return sprintf(buf, "%d\n", temp * 125);
267 static ssize_t temp_show(struct device *dev, struct device_attribute *devattr,
270 int nr = to_sensor_dev_attr_2(devattr)->nr;
271 int index = to_sensor_dev_attr_2(devattr)->index;
272 struct max6697_data *data = max6697_update_device(dev);
276 return PTR_ERR(data);
278 temp = data->temp[nr][index];
279 temp -= data->temp_offset;
281 return sprintf(buf, "%d\n", temp * 1000);
284 static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
287 int index = to_sensor_dev_attr(attr)->index;
288 struct max6697_data *data = max6697_update_device(dev);
291 return PTR_ERR(data);
293 if (data->chip->alarm_map)
294 index = data->chip->alarm_map[index];
296 return sprintf(buf, "%u\n", (data->alarms >> index) & 0x1);
299 static ssize_t temp_store(struct device *dev,
300 struct device_attribute *devattr, const char *buf,
303 int nr = to_sensor_dev_attr_2(devattr)->nr;
304 int index = to_sensor_dev_attr_2(devattr)->index;
305 struct max6697_data *data = dev_get_drvdata(dev);
309 ret = kstrtol(buf, 10, &temp);
313 mutex_lock(&data->update_lock);
314 temp = DIV_ROUND_CLOSEST(temp, 1000) + data->temp_offset;
315 temp = clamp_val(temp, 0, data->type == max6581 ? 255 : 127);
316 data->temp[nr][index] = temp;
317 ret = i2c_smbus_write_byte_data(data->client,
318 index == 2 ? MAX6697_REG_MAX[nr]
319 : MAX6697_REG_CRIT[nr],
321 mutex_unlock(&data->update_lock);
323 return ret < 0 ? ret : count;
326 static ssize_t offset_store(struct device *dev, struct device_attribute *devattr, const char *buf,
329 int val, ret, index, select;
330 struct max6697_data *data;
331 bool channel_enabled;
334 index = to_sensor_dev_attr(devattr)->index;
335 data = dev_get_drvdata(dev);
336 ret = kstrtol(buf, 10, &temp);
340 mutex_lock(&data->update_lock);
341 select = i2c_smbus_read_byte_data(data->client, MAX6581_REG_OFFSET_SELECT);
346 channel_enabled = (select & (1 << (index - 1)));
347 temp = clamp_val(temp, MAX6581_OFFSET_MIN, MAX6581_OFFSET_MAX);
348 val = DIV_ROUND_CLOSEST(temp, 250);
349 /* disable the offset for channel if the new offset is 0 */
352 ret = i2c_smbus_write_byte_data(data->client, MAX6581_REG_OFFSET_SELECT,
353 select & ~(1 << (index - 1)));
354 ret = ret < 0 ? ret : count;
357 if (!channel_enabled) {
358 ret = i2c_smbus_write_byte_data(data->client, MAX6581_REG_OFFSET_SELECT,
359 select | (1 << (index - 1)));
363 ret = i2c_smbus_write_byte_data(data->client, MAX6581_REG_OFFSET, val);
364 ret = ret < 0 ? ret : count;
367 mutex_unlock(&data->update_lock);
371 static ssize_t offset_show(struct device *dev, struct device_attribute *devattr, char *buf)
373 struct max6697_data *data;
374 int select, ret, index;
376 index = to_sensor_dev_attr(devattr)->index;
377 data = dev_get_drvdata(dev);
378 mutex_lock(&data->update_lock);
379 select = i2c_smbus_read_byte_data(data->client, MAX6581_REG_OFFSET_SELECT);
382 else if (select & (1 << (index - 1)))
383 ret = i2c_smbus_read_byte_data(data->client, MAX6581_REG_OFFSET);
386 mutex_unlock(&data->update_lock);
387 return ret < 0 ? ret : sprintf(buf, "%d\n", max6581_offset_to_millic(ret));
390 static SENSOR_DEVICE_ATTR_RO(temp1_input, temp_input, 0);
391 static SENSOR_DEVICE_ATTR_2_RW(temp1_max, temp, 0, MAX6697_TEMP_MAX);
392 static SENSOR_DEVICE_ATTR_2_RW(temp1_crit, temp, 0, MAX6697_TEMP_CRIT);
394 static SENSOR_DEVICE_ATTR_RO(temp2_input, temp_input, 1);
395 static SENSOR_DEVICE_ATTR_2_RW(temp2_max, temp, 1, MAX6697_TEMP_MAX);
396 static SENSOR_DEVICE_ATTR_2_RW(temp2_crit, temp, 1, MAX6697_TEMP_CRIT);
398 static SENSOR_DEVICE_ATTR_RO(temp3_input, temp_input, 2);
399 static SENSOR_DEVICE_ATTR_2_RW(temp3_max, temp, 2, MAX6697_TEMP_MAX);
400 static SENSOR_DEVICE_ATTR_2_RW(temp3_crit, temp, 2, MAX6697_TEMP_CRIT);
402 static SENSOR_DEVICE_ATTR_RO(temp4_input, temp_input, 3);
403 static SENSOR_DEVICE_ATTR_2_RW(temp4_max, temp, 3, MAX6697_TEMP_MAX);
404 static SENSOR_DEVICE_ATTR_2_RW(temp4_crit, temp, 3, MAX6697_TEMP_CRIT);
406 static SENSOR_DEVICE_ATTR_RO(temp5_input, temp_input, 4);
407 static SENSOR_DEVICE_ATTR_2_RW(temp5_max, temp, 4, MAX6697_TEMP_MAX);
408 static SENSOR_DEVICE_ATTR_2_RW(temp5_crit, temp, 4, MAX6697_TEMP_CRIT);
410 static SENSOR_DEVICE_ATTR_RO(temp6_input, temp_input, 5);
411 static SENSOR_DEVICE_ATTR_2_RW(temp6_max, temp, 5, MAX6697_TEMP_MAX);
412 static SENSOR_DEVICE_ATTR_2_RW(temp6_crit, temp, 5, MAX6697_TEMP_CRIT);
414 static SENSOR_DEVICE_ATTR_RO(temp7_input, temp_input, 6);
415 static SENSOR_DEVICE_ATTR_2_RW(temp7_max, temp, 6, MAX6697_TEMP_MAX);
416 static SENSOR_DEVICE_ATTR_2_RW(temp7_crit, temp, 6, MAX6697_TEMP_CRIT);
418 static SENSOR_DEVICE_ATTR_RO(temp8_input, temp_input, 7);
419 static SENSOR_DEVICE_ATTR_2_RW(temp8_max, temp, 7, MAX6697_TEMP_MAX);
420 static SENSOR_DEVICE_ATTR_2_RW(temp8_crit, temp, 7, MAX6697_TEMP_CRIT);
422 static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, 22);
423 static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, alarm, 16);
424 static SENSOR_DEVICE_ATTR_RO(temp3_max_alarm, alarm, 17);
425 static SENSOR_DEVICE_ATTR_RO(temp4_max_alarm, alarm, 18);
426 static SENSOR_DEVICE_ATTR_RO(temp5_max_alarm, alarm, 19);
427 static SENSOR_DEVICE_ATTR_RO(temp6_max_alarm, alarm, 20);
428 static SENSOR_DEVICE_ATTR_RO(temp7_max_alarm, alarm, 21);
429 static SENSOR_DEVICE_ATTR_RO(temp8_max_alarm, alarm, 23);
431 static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, alarm, 14);
432 static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, alarm, 8);
433 static SENSOR_DEVICE_ATTR_RO(temp3_crit_alarm, alarm, 9);
434 static SENSOR_DEVICE_ATTR_RO(temp4_crit_alarm, alarm, 10);
435 static SENSOR_DEVICE_ATTR_RO(temp5_crit_alarm, alarm, 11);
436 static SENSOR_DEVICE_ATTR_RO(temp6_crit_alarm, alarm, 12);
437 static SENSOR_DEVICE_ATTR_RO(temp7_crit_alarm, alarm, 13);
438 static SENSOR_DEVICE_ATTR_RO(temp8_crit_alarm, alarm, 15);
440 static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 1);
441 static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 2);
442 static SENSOR_DEVICE_ATTR_RO(temp4_fault, alarm, 3);
443 static SENSOR_DEVICE_ATTR_RO(temp5_fault, alarm, 4);
444 static SENSOR_DEVICE_ATTR_RO(temp6_fault, alarm, 5);
445 static SENSOR_DEVICE_ATTR_RO(temp7_fault, alarm, 6);
446 static SENSOR_DEVICE_ATTR_RO(temp8_fault, alarm, 7);
448 /* There is no offset for local temperature so starting from temp2 */
449 static SENSOR_DEVICE_ATTR_RW(temp2_offset, offset, 1);
450 static SENSOR_DEVICE_ATTR_RW(temp3_offset, offset, 2);
451 static SENSOR_DEVICE_ATTR_RW(temp4_offset, offset, 3);
452 static SENSOR_DEVICE_ATTR_RW(temp5_offset, offset, 4);
453 static SENSOR_DEVICE_ATTR_RW(temp6_offset, offset, 5);
454 static SENSOR_DEVICE_ATTR_RW(temp7_offset, offset, 6);
455 static SENSOR_DEVICE_ATTR_RW(temp8_offset, offset, 7);
457 static DEVICE_ATTR(dummy, 0, NULL, NULL);
459 static umode_t max6697_is_visible(struct kobject *kobj, struct attribute *attr,
462 struct device *dev = kobj_to_dev(kobj);
463 struct max6697_data *data = dev_get_drvdata(dev);
464 const struct max6697_chip_data *chip = data->chip;
465 int channel = index / 7; /* channel number */
466 int nr = index % 7; /* attribute index within channel */
468 if (channel >= chip->channels)
471 if ((nr == 3 || nr == 4) && !(chip->have_crit & (1 << channel)))
473 if (nr == 5 && !(chip->have_fault & (1 << channel)))
475 /* offset reg is only supported on max6581 remote channels */
477 if (data->type != max6581 || channel == 0)
484 * max6697_is_visible uses the index into the following array to determine
485 * if attributes should be created or not. Any change in order or content
486 * must be matched in max6697_is_visible.
488 static struct attribute *max6697_attributes[] = {
489 &sensor_dev_attr_temp1_input.dev_attr.attr,
490 &sensor_dev_attr_temp1_max.dev_attr.attr,
491 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
492 &sensor_dev_attr_temp1_crit.dev_attr.attr,
493 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
494 &dev_attr_dummy.attr,
495 &dev_attr_dummy.attr,
497 &sensor_dev_attr_temp2_input.dev_attr.attr,
498 &sensor_dev_attr_temp2_max.dev_attr.attr,
499 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
500 &sensor_dev_attr_temp2_crit.dev_attr.attr,
501 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
502 &sensor_dev_attr_temp2_fault.dev_attr.attr,
503 &sensor_dev_attr_temp2_offset.dev_attr.attr,
505 &sensor_dev_attr_temp3_input.dev_attr.attr,
506 &sensor_dev_attr_temp3_max.dev_attr.attr,
507 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
508 &sensor_dev_attr_temp3_crit.dev_attr.attr,
509 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
510 &sensor_dev_attr_temp3_fault.dev_attr.attr,
511 &sensor_dev_attr_temp3_offset.dev_attr.attr,
513 &sensor_dev_attr_temp4_input.dev_attr.attr,
514 &sensor_dev_attr_temp4_max.dev_attr.attr,
515 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
516 &sensor_dev_attr_temp4_crit.dev_attr.attr,
517 &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr,
518 &sensor_dev_attr_temp4_fault.dev_attr.attr,
519 &sensor_dev_attr_temp4_offset.dev_attr.attr,
521 &sensor_dev_attr_temp5_input.dev_attr.attr,
522 &sensor_dev_attr_temp5_max.dev_attr.attr,
523 &sensor_dev_attr_temp5_max_alarm.dev_attr.attr,
524 &sensor_dev_attr_temp5_crit.dev_attr.attr,
525 &sensor_dev_attr_temp5_crit_alarm.dev_attr.attr,
526 &sensor_dev_attr_temp5_fault.dev_attr.attr,
527 &sensor_dev_attr_temp5_offset.dev_attr.attr,
529 &sensor_dev_attr_temp6_input.dev_attr.attr,
530 &sensor_dev_attr_temp6_max.dev_attr.attr,
531 &sensor_dev_attr_temp6_max_alarm.dev_attr.attr,
532 &sensor_dev_attr_temp6_crit.dev_attr.attr,
533 &sensor_dev_attr_temp6_crit_alarm.dev_attr.attr,
534 &sensor_dev_attr_temp6_fault.dev_attr.attr,
535 &sensor_dev_attr_temp6_offset.dev_attr.attr,
537 &sensor_dev_attr_temp7_input.dev_attr.attr,
538 &sensor_dev_attr_temp7_max.dev_attr.attr,
539 &sensor_dev_attr_temp7_max_alarm.dev_attr.attr,
540 &sensor_dev_attr_temp7_crit.dev_attr.attr,
541 &sensor_dev_attr_temp7_crit_alarm.dev_attr.attr,
542 &sensor_dev_attr_temp7_fault.dev_attr.attr,
543 &sensor_dev_attr_temp7_offset.dev_attr.attr,
545 &sensor_dev_attr_temp8_input.dev_attr.attr,
546 &sensor_dev_attr_temp8_max.dev_attr.attr,
547 &sensor_dev_attr_temp8_max_alarm.dev_attr.attr,
548 &sensor_dev_attr_temp8_crit.dev_attr.attr,
549 &sensor_dev_attr_temp8_crit_alarm.dev_attr.attr,
550 &sensor_dev_attr_temp8_fault.dev_attr.attr,
551 &sensor_dev_attr_temp8_offset.dev_attr.attr,
555 static const struct attribute_group max6697_group = {
556 .attrs = max6697_attributes, .is_visible = max6697_is_visible,
558 __ATTRIBUTE_GROUPS(max6697);
560 static void max6697_get_config_of(struct device_node *node,
561 struct max6697_platform_data *pdata)
566 pdata->smbus_timeout_disable =
567 of_property_read_bool(node, "smbus-timeout-disable");
568 pdata->extended_range_enable =
569 of_property_read_bool(node, "extended-range-enable");
570 pdata->beta_compensation =
571 of_property_read_bool(node, "beta-compensation-enable");
573 prop = of_get_property(node, "alert-mask", &len);
574 if (prop && len == sizeof(u32))
575 pdata->alert_mask = be32_to_cpu(prop[0]);
576 prop = of_get_property(node, "over-temperature-mask", &len);
577 if (prop && len == sizeof(u32))
578 pdata->over_temperature_mask = be32_to_cpu(prop[0]);
579 prop = of_get_property(node, "resistance-cancellation", &len);
581 if (len == sizeof(u32))
582 pdata->resistance_cancellation = be32_to_cpu(prop[0]);
584 pdata->resistance_cancellation = 0xfe;
586 prop = of_get_property(node, "transistor-ideality", &len);
587 if (prop && len == 2 * sizeof(u32)) {
588 pdata->ideality_mask = be32_to_cpu(prop[0]);
589 pdata->ideality_value = be32_to_cpu(prop[1]);
593 static int max6697_init_chip(struct max6697_data *data,
594 struct i2c_client *client)
596 struct max6697_platform_data *pdata = dev_get_platdata(&client->dev);
597 struct max6697_platform_data p;
598 const struct max6697_chip_data *chip = data->chip;
599 int factor = chip->channels;
603 * Don't touch configuration if neither platform data nor OF
604 * configuration was specified. If that is the case, use the
605 * current chip configuration.
607 if (!pdata && !client->dev.of_node) {
608 reg = i2c_smbus_read_byte_data(client, MAX6697_REG_CONFIG);
611 if (data->type == max6581) {
612 if (reg & MAX6581_CONF_EXTENDED)
613 data->temp_offset = 64;
614 reg = i2c_smbus_read_byte_data(client,
615 MAX6581_REG_RESISTANCE);
618 factor += hweight8(reg);
620 if (reg & MAX6697_CONF_RESISTANCE)
626 if (client->dev.of_node) {
627 memset(&p, 0, sizeof(p));
628 max6697_get_config_of(client->dev.of_node, &p);
633 if (pdata->smbus_timeout_disable &&
634 (chip->valid_conf & MAX6697_CONF_TIMEOUT)) {
635 reg |= MAX6697_CONF_TIMEOUT;
637 if (pdata->extended_range_enable &&
638 (chip->valid_conf & MAX6581_CONF_EXTENDED)) {
639 reg |= MAX6581_CONF_EXTENDED;
640 data->temp_offset = 64;
642 if (pdata->resistance_cancellation &&
643 (chip->valid_conf & MAX6697_CONF_RESISTANCE)) {
644 reg |= MAX6697_CONF_RESISTANCE;
647 if (pdata->beta_compensation &&
648 (chip->valid_conf & MAX6693_CONF_BETA)) {
649 reg |= MAX6693_CONF_BETA;
652 ret = i2c_smbus_write_byte_data(client, MAX6697_REG_CONFIG, reg);
656 ret = i2c_smbus_write_byte_data(client, MAX6697_REG_ALERT_MASK,
657 MAX6697_ALERT_MAP_BITS(pdata->alert_mask));
661 ret = i2c_smbus_write_byte_data(client, MAX6697_REG_OVERT_MASK,
662 MAX6697_OVERT_MAP_BITS(pdata->over_temperature_mask));
666 if (data->type == max6581) {
667 factor += hweight8(pdata->resistance_cancellation >> 1);
668 ret = i2c_smbus_write_byte_data(client, MAX6581_REG_RESISTANCE,
669 pdata->resistance_cancellation >> 1);
672 ret = i2c_smbus_write_byte_data(client, MAX6581_REG_IDEALITY,
673 pdata->ideality_value);
676 ret = i2c_smbus_write_byte_data(client,
677 MAX6581_REG_IDEALITY_SELECT,
678 pdata->ideality_mask >> 1);
683 data->update_interval = factor * MAX6697_CONV_TIME;
687 static const struct i2c_device_id max6697_id[];
689 static int max6697_probe(struct i2c_client *client)
691 struct i2c_adapter *adapter = client->adapter;
692 struct device *dev = &client->dev;
693 struct max6697_data *data;
694 struct device *hwmon_dev;
697 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
700 data = devm_kzalloc(dev, sizeof(struct max6697_data), GFP_KERNEL);
704 if (client->dev.of_node)
705 data->type = (uintptr_t)of_device_get_match_data(&client->dev);
707 data->type = i2c_match_id(max6697_id, client)->driver_data;
708 data->chip = &max6697_chip_data[data->type];
709 data->client = client;
710 mutex_init(&data->update_lock);
712 err = max6697_init_chip(data, client);
716 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
719 return PTR_ERR_OR_ZERO(hwmon_dev);
722 static const struct i2c_device_id max6697_id[] = {
723 { "max6581", max6581 },
724 { "max6602", max6602 },
725 { "max6622", max6622 },
726 { "max6636", max6636 },
727 { "max6689", max6689 },
728 { "max6693", max6693 },
729 { "max6694", max6694 },
730 { "max6697", max6697 },
731 { "max6698", max6698 },
732 { "max6699", max6699 },
735 MODULE_DEVICE_TABLE(i2c, max6697_id);
737 static const struct of_device_id __maybe_unused max6697_of_match[] = {
739 .compatible = "maxim,max6581",
740 .data = (void *)max6581
743 .compatible = "maxim,max6602",
744 .data = (void *)max6602
747 .compatible = "maxim,max6622",
748 .data = (void *)max6622
751 .compatible = "maxim,max6636",
752 .data = (void *)max6636
755 .compatible = "maxim,max6689",
756 .data = (void *)max6689
759 .compatible = "maxim,max6693",
760 .data = (void *)max6693
763 .compatible = "maxim,max6694",
764 .data = (void *)max6694
767 .compatible = "maxim,max6697",
768 .data = (void *)max6697
771 .compatible = "maxim,max6698",
772 .data = (void *)max6698
775 .compatible = "maxim,max6699",
776 .data = (void *)max6699
780 MODULE_DEVICE_TABLE(of, max6697_of_match);
782 static struct i2c_driver max6697_driver = {
783 .class = I2C_CLASS_HWMON,
786 .of_match_table = of_match_ptr(max6697_of_match),
788 .probe = max6697_probe,
789 .id_table = max6697_id,
792 module_i2c_driver(max6697_driver);
794 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
795 MODULE_DESCRIPTION("MAX6697 temperature sensor driver");
796 MODULE_LICENSE("GPL");