24 #include <linux/module.h>
26 #include <linux/slab.h>
28 #include <linux/i2c.h>
39 #define ADT7410_TEMPERATURE 0
40 #define ADT7410_STATUS 2
41 #define ADT7410_CONFIG 3
42 #define ADT7410_T_ALARM_HIGH 4
43 #define ADT7410_T_ALARM_LOW 6
44 #define ADT7410_T_CRIT 8
45 #define ADT7410_T_HYST 0xA
50 #define ADT7410_STAT_T_LOW (1 << 4)
51 #define ADT7410_STAT_T_HIGH (1 << 5)
52 #define ADT7410_STAT_T_CRIT (1 << 6)
53 #define ADT7410_STAT_NOT_RDY (1 << 7)
58 #define ADT7410_FAULT_QUEUE_MASK (1 << 0 | 1 << 1)
59 #define ADT7410_CT_POLARITY (1 << 2)
60 #define ADT7410_INT_POLARITY (1 << 3)
61 #define ADT7410_EVENT_MODE (1 << 4)
62 #define ADT7410_MODE_MASK (1 << 5 | 1 << 6)
63 #define ADT7410_FULL (0 << 5 | 0 << 6)
64 #define ADT7410_PD (1 << 5 | 1 << 6)
65 #define ADT7410_RESOLUTION (1 << 7)
70 #define ADT7410_T13_VALUE_MASK 0xFFF8
71 #define ADT7410_T_HYST_MASK 0xF
74 #define ADT7410_TEMP_MIN (-55000)
75 #define ADT7410_TEMP_MAX 150000
82 static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
85 static const u8 ADT7410_REG_TEMP[4] = {
115 for (i = 0; i < 6; i++) {
139 status = adt7410_temp_ready(client);
141 ret = ERR_PTR(status);
145 status = i2c_smbus_read_word_swapped(client,
146 ADT7410_REG_TEMP[i]);
149 "Failed to read value: reg %d, error %d\n",
150 ADT7410_REG_TEMP[i], status);
151 ret = ERR_PTR(status);
159 "Failed to read value: reg %d, error %d\n",
161 ret = ERR_PTR(status);
174 static s16 ADT7410_TEMP_TO_REG(
long temp)
203 return PTR_ERR(data);
205 return sprintf(buf,
"%d\n", ADT7410_REG_TO_TEMP(data,
211 const char *buf,
size_t count)
220 ret = kstrtol(buf, 10, &temp);
225 data->
temp[
nr] = ADT7410_TEMP_TO_REG(temp);
226 ret = i2c_smbus_write_word_swapped(client, ADT7410_REG_TEMP[nr],
240 int nr = attr->
index;
243 data = adt7410_update_device(dev);
245 return PTR_ERR(data);
255 ADT7410_REG_TO_TEMP(data, data->
temp[nr]) - hyst);
260 const char *buf,
size_t count)
267 ret = kstrtol(buf, 10, &hyst);
271 limit = ADT7410_REG_TO_TEMP(data, data->
temp[1]);
299 adt7410_show_temp, adt7410_set_temp, 1);
301 adt7410_show_temp, adt7410_set_temp, 2);
303 adt7410_show_temp, adt7410_set_temp, 3);
305 adt7410_show_t_hyst, adt7410_set_t_hyst, 1);
307 adt7410_show_t_hyst,
NULL, 2);
309 adt7410_show_t_hyst,
NULL, 3);
317 static struct attribute *adt7410_attributes[] = {
318 &sensor_dev_attr_temp1_input.dev_attr.attr,
319 &sensor_dev_attr_temp1_max.dev_attr.attr,
320 &sensor_dev_attr_temp1_min.dev_attr.attr,
321 &sensor_dev_attr_temp1_crit.dev_attr.attr,
322 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
323 &sensor_dev_attr_temp1_min_hyst.dev_attr.attr,
324 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
325 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
326 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
327 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
332 .attrs = adt7410_attributes,
339 static int adt7410_probe(
struct i2c_client *client,
345 if (!i2c_check_functionality(client->
adapter,
354 i2c_set_clientdata(client, data);
360 dev_dbg(&client->
dev,
"Can't read config? %d\n", ret);
399 static int adt7410_remove(
struct i2c_client *client)
418 static int adt7410_suspend(
struct device *dev)
429 static int adt7410_resume(
struct device *dev)
439 static const struct dev_pm_ops adt7410_dev_pm_ops = {
441 .resume = adt7410_resume,
443 #define ADT7410_DEV_PM_OPS (&adt7410_dev_pm_ops)
445 #define ADT7410_DEV_PM_OPS NULL
454 .probe = adt7410_probe,
455 .remove = adt7410_remove,
456 .id_table = adt7410_ids,
457 .address_list = normal_i2c,