25 #include <linux/module.h>
27 #include <linux/slab.h>
29 #include <linux/i2c.h>
36 static const unsigned short normal_i2c[] = {
40 #define JC42_REG_CAP 0x00
41 #define JC42_REG_CONFIG 0x01
42 #define JC42_REG_TEMP_UPPER 0x02
43 #define JC42_REG_TEMP_LOWER 0x03
44 #define JC42_REG_TEMP_CRITICAL 0x04
45 #define JC42_REG_TEMP 0x05
46 #define JC42_REG_MANID 0x06
47 #define JC42_REG_DEVICEID 0x07
50 #define JC42_ALARM_CRIT_BIT 15
51 #define JC42_ALARM_MAX_BIT 14
52 #define JC42_ALARM_MIN_BIT 13
55 #define JC42_CFG_CRIT_ONLY (1 << 2)
56 #define JC42_CFG_TCRIT_LOCK (1 << 6)
57 #define JC42_CFG_EVENT_LOCK (1 << 7)
58 #define JC42_CFG_SHUTDOWN (1 << 8)
59 #define JC42_CFG_HYST_SHIFT 9
60 #define JC42_CFG_HYST_MASK (0x03 << 9)
63 #define JC42_CAP_RANGE (1 << 2)
66 #define ADT_MANID 0x11d4
67 #define ATMEL_MANID 0x001f
68 #define MAX_MANID 0x004d
69 #define IDT_MANID 0x00b3
70 #define MCP_MANID 0x0054
71 #define NXP_MANID 0x1131
72 #define ONS_MANID 0x1b09
73 #define STM_MANID 0x104a
78 #define ADT7408_DEVID 0x0801
79 #define ADT7408_DEVID_MASK 0xffff
82 #define AT30TS00_DEVID 0x8201
83 #define AT30TS00_DEVID_MASK 0xffff
86 #define TS3000B3_DEVID 0x2903
87 #define TS3000B3_DEVID_MASK 0xffff
89 #define TS3000GB2_DEVID 0x2912
90 #define TS3000GB2_DEVID_MASK 0xffff
93 #define MAX6604_DEVID 0x3e00
94 #define MAX6604_DEVID_MASK 0xffff
97 #define MCP9804_DEVID 0x0200
98 #define MCP9804_DEVID_MASK 0xfffc
100 #define MCP98242_DEVID 0x2000
101 #define MCP98242_DEVID_MASK 0xfffc
103 #define MCP98243_DEVID 0x2100
104 #define MCP98243_DEVID_MASK 0xfffc
106 #define MCP9843_DEVID 0x0000
107 #define MCP9843_DEVID_MASK 0xfffe
110 #define SE97_DEVID 0xa200
111 #define SE97_DEVID_MASK 0xfffc
113 #define SE98_DEVID 0xa100
114 #define SE98_DEVID_MASK 0xfffc
117 #define CAT6095_DEVID 0x0800
118 #define CAT6095_DEVID_MASK 0xffe0
121 #define STTS424_DEVID 0x0101
122 #define STTS424_DEVID_MASK 0xffff
124 #define STTS424E_DEVID 0x0000
125 #define STTS424E_DEVID_MASK 0xfffe
127 #define STTS2002_DEVID 0x0300
128 #define STTS2002_DEVID_MASK 0xffff
130 #define STTS3000_DEVID 0x0200
131 #define STTS3000_DEVID_MASK 0xffff
133 static u16 jc42_hysteresis[] = { 0, 1500, 3000, 6000 };
190 static int jc42_suspend(
struct device *
dev)
200 static int jc42_resume(
struct device *
dev)
210 static const struct dev_pm_ops jc42_dev_pm_ops = {
212 .resume = jc42_resume,
215 #define JC42_DEV_PM_OPS (&jc42_dev_pm_ops)
217 #define JC42_DEV_PM_OPS NULL
228 .remove = jc42_remove,
230 .detect = jc42_detect,
231 .address_list = normal_i2c,
234 #define JC42_TEMP_MIN_EXTENDED (-40000)
235 #define JC42_TEMP_MIN 0
236 #define JC42_TEMP_MAX 125000
238 static u16 jc42_temp_to_reg(
int temp,
bool extended)
240 int ntemp = SENSORS_LIMIT(temp,
245 return (ntemp * 2 / 125) & 0x1fff;
248 static int jc42_temp_from_reg(
s16 reg)
257 return reg * 125 / 2;
263 #define show(value) \
264 static ssize_t show_##value(struct device *dev, \
265 struct device_attribute *attr, \
268 struct jc42_data *data = jc42_update_device(dev); \
270 return PTR_ERR(data); \
271 return sprintf(buf, "%d\n", jc42_temp_from_reg(data->value)); \
287 return PTR_ERR(data);
289 temp = jc42_temp_from_reg(data->
temp_crit);
292 return sprintf(buf,
"%d\n", temp - hyst);
298 struct jc42_data *data = jc42_update_device(dev);
302 return PTR_ERR(data);
304 temp = jc42_temp_from_reg(data->
temp_max);
307 return sprintf(buf,
"%d\n", temp - hyst);
311 #define set(value, reg) \
312 static ssize_t set_##value(struct device *dev, \
313 struct device_attribute *attr, \
314 const char *buf, size_t count) \
316 struct i2c_client *client = to_i2c_client(dev); \
317 struct jc42_data *data = i2c_get_clientdata(client); \
318 int err, ret = count; \
320 if (kstrtol(buf, 10, &val) < 0) \
322 mutex_lock(&data->update_lock); \
323 data->value = jc42_temp_to_reg(val, data->extended); \
324 err = i2c_smbus_write_word_swapped(client, reg, data->value); \
327 mutex_unlock(&data->update_lock); \
341 const char *buf,
size_t count)
344 struct jc42_data *data = i2c_get_clientdata(client);
350 if (kstrtoul(buf, 10, &val) < 0)
358 else if (diff < 4500)
379 struct jc42_data *data = jc42_update_device(dev);
383 return PTR_ERR(data);
388 return sprintf(buf,
"%u\n", (val >> bit) & 1);
392 show_temp_input,
NULL);
394 show_temp_crit, set_temp_crit);
396 show_temp_min, set_temp_min);
398 show_temp_max, set_temp_max);
401 show_temp_crit_hyst, set_temp_crit_hyst);
403 show_temp_max_hyst,
NULL);
412 static struct attribute *jc42_attributes[] = {
413 &dev_attr_temp1_input.attr,
414 &dev_attr_temp1_crit.attr,
415 &dev_attr_temp1_min.attr,
416 &dev_attr_temp1_max.attr,
417 &dev_attr_temp1_crit_hyst.attr,
418 &dev_attr_temp1_max_hyst.attr,
419 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
420 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
421 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
430 struct jc42_data *data = i2c_get_clientdata(client);
434 if (attr == &dev_attr_temp1_crit.attr)
436 else if (attr == &dev_attr_temp1_min.attr ||
437 attr == &dev_attr_temp1_max.attr)
439 else if (attr == &dev_attr_temp1_crit_hyst.attr)
448 .attrs = jc42_attributes,
449 .is_visible = jc42_attribute_mode,
462 cap = i2c_smbus_read_word_swapped(client,
JC42_REG_CAP);
467 if (cap < 0 || config < 0 || manid < 0 || devid < 0)
470 if ((cap & 0xff00) || (config & 0xf800))
473 for (i = 0; i <
ARRAY_SIZE(jc42_chips); i++) {
474 struct jc42_chips *
chip = &jc42_chips[
i];
475 if (manid == chip->
manid &&
494 i2c_set_clientdata(client, data);
497 cap = i2c_smbus_read_word_swapped(client,
JC42_REG_CAP);
509 config &= ~JC42_CFG_SHUTDOWN;
532 static int jc42_remove(
struct i2c_client *client)
534 struct jc42_data *data = i2c_get_clientdata(client);
553 struct jc42_data *data = i2c_get_clientdata(client);
567 val = i2c_smbus_read_word_swapped(client,