18 #include <linux/kernel.h>
19 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/i2c.h>
30 #define SMM665_VREF_ADC_X1000 1250
42 #define SMM665_MISC16_ADC_DATA_A 0x00
43 #define SMM665_MISC16_ADC_DATA_B 0x01
44 #define SMM665_MISC16_ADC_DATA_C 0x02
45 #define SMM665_MISC16_ADC_DATA_D 0x03
46 #define SMM665_MISC16_ADC_DATA_E 0x04
47 #define SMM665_MISC16_ADC_DATA_F 0x05
48 #define SMM665_MISC16_ADC_DATA_VDD 0x06
49 #define SMM665_MISC16_ADC_DATA_12V 0x07
50 #define SMM665_MISC16_ADC_DATA_INT_TEMP 0x08
51 #define SMM665_MISC16_ADC_DATA_AIN1 0x09
52 #define SMM665_MISC16_ADC_DATA_AIN2 0x0a
57 #define SMM665_MISC8_CMD_STS 0x80
58 #define SMM665_MISC8_STATUS1 0x81
59 #define SMM665_MISC8_STATUSS2 0x82
60 #define SMM665_MISC8_IO_POLARITY 0x83
61 #define SMM665_MISC8_PUP_POLARITY 0x84
62 #define SMM665_MISC8_ADOC_STATUS1 0x85
63 #define SMM665_MISC8_ADOC_STATUS2 0x86
64 #define SMM665_MISC8_WRITE_PROT 0x87
65 #define SMM665_MISC8_STS_TRACK 0x88
70 #define SMM665_ADOC_ENABLE 0x0d
71 #define SMM665_LIMIT_BASE 0x80
76 #define SMM665_TRIGGER_RST 0x8000
77 #define SMM665_TRIGGER_HEALTHY 0x4000
78 #define SMM665_TRIGGER_POWEROFF 0x2000
79 #define SMM665_TRIGGER_SHUTDOWN 0x1000
80 #define SMM665_ADC_MASK 0x03ff
82 #define smm665_is_critical(lim) ((lim) & (SMM665_TRIGGER_RST \
83 | SMM665_TRIGGER_POWEROFF \
84 | SMM665_TRIGGER_SHUTDOWN))
90 #define SMM665_FAULT_A 0x0001
91 #define SMM665_FAULT_B 0x0002
92 #define SMM665_FAULT_C 0x0004
93 #define SMM665_FAULT_D 0x0008
94 #define SMM665_FAULT_E 0x0010
95 #define SMM665_FAULT_F 0x0020
96 #define SMM665_FAULT_VDD 0x0040
97 #define SMM665_FAULT_12V 0x0080
98 #define SMM665_FAULT_TEMP 0x0100
99 #define SMM665_FAULT_AIN1 0x0200
100 #define SMM665_FAULT_AIN2 0x0400
108 #define SMM665_REGMASK 0x78
109 #define SMM665_CMDREG_BASE 0x48
110 #define SMM665_CONFREG_BASE 0x50
119 #define SMM665_VMON_ADC_TO_VOLTS(adc) ((adc) * vref / 256)
122 #define SMM665_12VIN_ADC_TO_VOLTS(adc) ((adc) * vref * 3 / 256)
125 #define SMM665_AIN_ADC_TO_VOLTS(adc) ((adc) * vref / 512)
128 #define SMM665_TEMP_ADC_TO_CELSIUS(adc) (((adc) <= 511) ? \
129 ((int)(adc) * 1000 / 4) : \
130 (((int)(adc) - 0x400) * 1000 / 4))
132 #define SMM665_NUM_ADC 11
137 #define SMM665_ADC_WAIT_SMM665 70
138 #define SMM665_ADC_WAIT_SMM766 185
207 "Unexpected return code %d when setting ADC index", rv);
208 return (rv < 0) ? rv : -
EIO;
222 rv = i2c_smbus_read_word_swapped(client, 0);
224 dev_dbg(&client->
dev,
"Failed to read ADC value: error %d", rv);
230 radc = (rv >> 11) & 0x0f;
232 dev_dbg(&client->
dev,
"Unexpected RADC: Expected %d got %d",
243 struct smm665_data *data = i2c_get_clientdata(client);
263 val = smm665_read_adc(data, i);
279 static int smm665_convert(
u16 adcval,
int index)
316 static int smm665_get_min(
struct device *dev,
int index)
319 struct smm665_data *data = i2c_get_clientdata(client);
324 static int smm665_get_max(
struct device *dev,
int index)
327 struct smm665_data *data = i2c_get_clientdata(client);
332 static int smm665_get_lcrit(
struct device *dev,
int index)
335 struct smm665_data *data = i2c_get_clientdata(client);
340 static int smm665_get_crit(
struct device *dev,
int index)
343 struct smm665_data *data = i2c_get_clientdata(client);
352 struct smm665_data *data = smm665_update_device(dev);
356 return PTR_ERR(data);
368 struct smm665_data *data = smm665_update_device(dev);
369 int adc = attr->
index;
373 return PTR_ERR(data);
375 val = smm665_convert(data->
adc[adc], adc);
379 #define SMM665_SHOW(what) \
380 static ssize_t smm665_show_##what(struct device *dev, \
381 struct device_attribute *da, char *buf) \
383 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
384 const int val = smm665_get_##what(dev, attr->index); \
385 return snprintf(buf, PAGE_SIZE, "%d\n", val); \
399 #define SMM665_ATTR(name, type, cmd_idx) \
400 static SENSOR_DEVICE_ATTR(name##_##type, S_IRUGO, \
401 smm665_show_##type, NULL, cmd_idx)
489 static struct attribute *smm665_attributes[] = {
490 &sensor_dev_attr_in1_input.dev_attr.attr,
491 &sensor_dev_attr_in1_min.dev_attr.attr,
492 &sensor_dev_attr_in1_max.dev_attr.attr,
493 &sensor_dev_attr_in1_lcrit.dev_attr.attr,
494 &sensor_dev_attr_in1_crit.dev_attr.attr,
495 &sensor_dev_attr_in1_crit_alarm.dev_attr.attr,
497 &sensor_dev_attr_in2_input.dev_attr.attr,
498 &sensor_dev_attr_in2_min.dev_attr.attr,
499 &sensor_dev_attr_in2_max.dev_attr.attr,
500 &sensor_dev_attr_in2_lcrit.dev_attr.attr,
501 &sensor_dev_attr_in2_crit.dev_attr.attr,
502 &sensor_dev_attr_in2_crit_alarm.dev_attr.attr,
504 &sensor_dev_attr_in3_input.dev_attr.attr,
505 &sensor_dev_attr_in3_min.dev_attr.attr,
506 &sensor_dev_attr_in3_max.dev_attr.attr,
507 &sensor_dev_attr_in3_lcrit.dev_attr.attr,
508 &sensor_dev_attr_in3_crit.dev_attr.attr,
509 &sensor_dev_attr_in3_crit_alarm.dev_attr.attr,
511 &sensor_dev_attr_in4_input.dev_attr.attr,
512 &sensor_dev_attr_in4_min.dev_attr.attr,
513 &sensor_dev_attr_in4_max.dev_attr.attr,
514 &sensor_dev_attr_in4_lcrit.dev_attr.attr,
515 &sensor_dev_attr_in4_crit.dev_attr.attr,
516 &sensor_dev_attr_in4_crit_alarm.dev_attr.attr,
518 &sensor_dev_attr_in5_input.dev_attr.attr,
519 &sensor_dev_attr_in5_min.dev_attr.attr,
520 &sensor_dev_attr_in5_max.dev_attr.attr,
521 &sensor_dev_attr_in5_lcrit.dev_attr.attr,
522 &sensor_dev_attr_in5_crit.dev_attr.attr,
523 &sensor_dev_attr_in5_crit_alarm.dev_attr.attr,
525 &sensor_dev_attr_in6_input.dev_attr.attr,
526 &sensor_dev_attr_in6_min.dev_attr.attr,
527 &sensor_dev_attr_in6_max.dev_attr.attr,
528 &sensor_dev_attr_in6_lcrit.dev_attr.attr,
529 &sensor_dev_attr_in6_crit.dev_attr.attr,
530 &sensor_dev_attr_in6_crit_alarm.dev_attr.attr,
532 &sensor_dev_attr_in7_input.dev_attr.attr,
533 &sensor_dev_attr_in7_min.dev_attr.attr,
534 &sensor_dev_attr_in7_max.dev_attr.attr,
535 &sensor_dev_attr_in7_lcrit.dev_attr.attr,
536 &sensor_dev_attr_in7_crit.dev_attr.attr,
537 &sensor_dev_attr_in7_crit_alarm.dev_attr.attr,
539 &sensor_dev_attr_in8_input.dev_attr.attr,
540 &sensor_dev_attr_in8_min.dev_attr.attr,
541 &sensor_dev_attr_in8_max.dev_attr.attr,
542 &sensor_dev_attr_in8_lcrit.dev_attr.attr,
543 &sensor_dev_attr_in8_crit.dev_attr.attr,
544 &sensor_dev_attr_in8_crit_alarm.dev_attr.attr,
546 &sensor_dev_attr_in9_input.dev_attr.attr,
547 &sensor_dev_attr_in9_min.dev_attr.attr,
548 &sensor_dev_attr_in9_max.dev_attr.attr,
549 &sensor_dev_attr_in9_lcrit.dev_attr.attr,
550 &sensor_dev_attr_in9_crit.dev_attr.attr,
551 &sensor_dev_attr_in9_crit_alarm.dev_attr.attr,
553 &sensor_dev_attr_in10_input.dev_attr.attr,
554 &sensor_dev_attr_in10_min.dev_attr.attr,
555 &sensor_dev_attr_in10_max.dev_attr.attr,
556 &sensor_dev_attr_in10_lcrit.dev_attr.attr,
557 &sensor_dev_attr_in10_crit.dev_attr.attr,
558 &sensor_dev_attr_in10_crit_alarm.dev_attr.attr,
560 &sensor_dev_attr_temp1_input.dev_attr.attr,
561 &sensor_dev_attr_temp1_min.dev_attr.attr,
562 &sensor_dev_attr_temp1_max.dev_attr.attr,
563 &sensor_dev_attr_temp1_lcrit.dev_attr.attr,
564 &sensor_dev_attr_temp1_crit.dev_attr.attr,
565 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
571 .attrs = smm665_attributes,
574 static int smm665_probe(
struct i2c_client *client,
592 i2c_set_clientdata(client, data);
595 data->
type =
id->driver_data;
601 switch (data->
type) {
643 = smm665_convert(val, i);
655 = smm665_convert(val, i);
673 goto out_remove_group;
685 static int smm665_remove(
struct i2c_client *client)
687 struct smm665_data *data = i2c_get_clientdata(client);
712 .probe = smm665_probe,
713 .remove = smm665_remove,
714 .id_table = smm665_id,