22 #include <linux/module.h>
24 #include <linux/slab.h>
26 #include <linux/i2c.h>
34 static const unsigned short normal_i2c[] = {
35 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e,
I2C_CLIENT_END };
45 #define ADM1021_REG_TEMP(nr) (nr)
46 #define ADM1021_REG_STATUS 0x02
48 #define ADM1021_REG_MAN_ID 0xFE
50 #define ADM1021_REG_DEV_ID 0xFF
52 #define ADM1021_REG_CONFIG_R 0x03
53 #define ADM1021_REG_CONFIG_W 0x09
54 #define ADM1021_REG_CONV_RATE_R 0x04
55 #define ADM1021_REG_CONV_RATE_W 0x0A
57 #define ADM1023_REG_REM_TEMP_PREC 0x10
58 #define ADM1023_REG_REM_OFFSET 0x11
59 #define ADM1023_REG_REM_OFFSET_PREC 0x12
60 #define ADM1023_REG_REM_TOS_PREC 0x13
61 #define ADM1023_REG_REM_THYST_PREC 0x14
64 #define ADM1021_REG_TOS_R(nr) (0x05 + 2 * (nr))
65 #define ADM1021_REG_TOS_W(nr) (0x0B + 2 * (nr))
66 #define ADM1021_REG_THYST_R(nr) (0x06 + 2 * (nr))
67 #define ADM1021_REG_THYST_W(nr) (0x0C + 2 * (nr))
69 #define ADM1021_REG_ONESHOT 0x0F
130 .probe = adm1021_probe,
131 .remove = adm1021_remove,
132 .id_table = adm1021_id,
133 .detect = adm1021_detect,
134 .address_list = normal_i2c,
182 const char *buf,
size_t count)
190 err = kstrtol(buf, 10, &temp);
207 const char *buf,
size_t count)
215 err = kstrtol(buf, 10, &temp);
239 const char *buf,
size_t count)
247 err = kstrtoul(buf, 10, &val);
250 low_power = val != 0;
258 (config & 0xBF) | (low_power << 6));
285 static struct attribute *adm1021_attributes[] = {
286 &sensor_dev_attr_temp1_max.dev_attr.attr,
287 &sensor_dev_attr_temp1_min.dev_attr.attr,
288 &sensor_dev_attr_temp1_input.dev_attr.attr,
289 &sensor_dev_attr_temp2_max.dev_attr.attr,
290 &sensor_dev_attr_temp2_min.dev_attr.attr,
291 &sensor_dev_attr_temp2_input.dev_attr.attr,
292 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
293 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
294 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
295 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
296 &sensor_dev_attr_temp2_fault.dev_attr.attr,
297 &dev_attr_alarms.attr,
298 &dev_attr_low_power.attr,
303 .attrs = adm1021_attributes,
307 static int adm1021_detect(
struct i2c_client *client,
311 const char *type_name;
316 "smbus byte data not supported!\n");
326 if ((status & 0x03) || (config & 0x3F) || (conv_rate & 0xF8)) {
327 pr_debug(
"adm1021: detect failed, chip not detected!\n");
335 if (man_id == 0x4d && dev_id == 0x01)
336 type_name =
"max1617a";
337 else if (man_id == 0x41) {
338 if ((dev_id & 0xF0) == 0x30)
339 type_name =
"adm1023";
341 type_name =
"adm1021";
342 }
else if (man_id == 0x49)
343 type_name =
"thmc10";
344 else if (man_id == 0x23)
345 type_name =
"gl523sm";
346 else if (man_id == 0x54)
347 type_name =
"mc1066";
349 else if (conv_rate == 0x00
350 && (config & 0x7F) == 0x00
351 && (status & 0xAB) == 0x00)
354 type_name =
"max1617";
356 pr_debug(
"adm1021: Detected chip %s at adapter %d, address 0x%02x.\n",
357 type_name, i2c_adapter_id(adapter), client->
addr);
363 static int adm1021_probe(
struct i2c_client *client,
372 pr_debug(
"adm1021: detect failed, devm_kzalloc failed!\n");
376 i2c_set_clientdata(client, data);
377 data->
type =
id->driver_data;
382 adm1021_init_client(client);
402 static void adm1021_init_client(
struct i2c_client *client)
411 static int adm1021_remove(
struct i2c_client *client)
432 dev_dbg(&client->
dev,
"Starting adm1021 update\n");
434 for (i = 0; i < 2; i++) {
435 data->
temp[
i] = 1000 *