29 #include <linux/module.h>
31 #include <linux/slab.h>
33 #include <linux/i2c.h>
40 static const unsigned short normal_i2c[] = {
41 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e,
I2C_CLIENT_END };
47 #define MAX1619_REG_R_MAN_ID 0xFE
48 #define MAX1619_REG_R_CHIP_ID 0xFF
49 #define MAX1619_REG_R_CONFIG 0x03
50 #define MAX1619_REG_W_CONFIG 0x09
51 #define MAX1619_REG_R_CONVRATE 0x04
52 #define MAX1619_REG_W_CONVRATE 0x0A
53 #define MAX1619_REG_R_STATUS 0x02
54 #define MAX1619_REG_R_LOCAL_TEMP 0x00
55 #define MAX1619_REG_R_REMOTE_TEMP 0x01
56 #define MAX1619_REG_R_REMOTE_HIGH 0x07
57 #define MAX1619_REG_W_REMOTE_HIGH 0x0D
58 #define MAX1619_REG_R_REMOTE_LOW 0x08
59 #define MAX1619_REG_W_REMOTE_LOW 0x0E
60 #define MAX1619_REG_R_REMOTE_CRIT 0x10
61 #define MAX1619_REG_W_REMOTE_CRIT 0x12
62 #define MAX1619_REG_R_TCRIT_HYST 0x11
63 #define MAX1619_REG_W_TCRIT_HYST 0x13
69 static int temp_from_reg(
int val)
71 return (val & 0x80 ? val-0x100 : val) * 1000;
74 static int temp_to_reg(
int val)
76 return (val < 0 ? val+0x100*1000 : val) / 1000;
106 .probe = max1619_probe,
107 .remove = max1619_remove,
108 .id_table = max1619_id,
109 .detect = max1619_detect,
110 .address_list = normal_i2c,
135 #define show_temp(value) \
136 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, \
139 struct max1619_data *data = max1619_update_device(dev); \
140 return sprintf(buf, "%d\n", temp_from_reg(data->value)); \
149 #define set_temp2(value, reg) \
150 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \
154 struct i2c_client *client = to_i2c_client(dev); \
155 struct max1619_data *data = i2c_get_clientdata(client); \
157 int err = kstrtol(buf, 10, &val); \
161 mutex_lock(&data->update_lock); \
162 data->value = temp_to_reg(val); \
163 i2c_smbus_write_byte_data(client, reg, data->value); \
164 mutex_unlock(&data->update_lock); \
204 static struct attribute *max1619_attributes[] = {
205 &dev_attr_temp1_input.attr,
206 &dev_attr_temp2_input.attr,
207 &dev_attr_temp2_min.attr,
208 &dev_attr_temp2_max.attr,
209 &dev_attr_temp2_crit.attr,
210 &dev_attr_temp2_crit_hyst.attr,
212 &dev_attr_alarms.attr,
213 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
214 &sensor_dev_attr_temp2_fault.dev_attr.attr,
215 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
216 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
221 .attrs = max1619_attributes,
242 if ((reg_config & 0x03) != 0x00
243 || reg_convrate > 0x07 || (reg_status & 0x61) != 0x00) {
244 dev_dbg(&adapter->
dev,
"MAX1619 detection failed at 0x%02x\n",
252 if (man_id != 0x4D || chip_id != 0x04) {
254 "Unsupported chip (man_id=0x%02X, chip_id=0x%02X).\n",
264 static int max1619_probe(
struct i2c_client *new_client,
275 i2c_set_clientdata(new_client, data);
280 max1619_init_client(new_client);
290 goto exit_remove_files;
300 static void max1619_init_client(
struct i2c_client *client)
315 static int max1619_remove(
struct i2c_client *client)
333 dev_dbg(&client->
dev,
"Updating max1619 data.\n");