43 #include <linux/module.h>
45 #include <linux/slab.h>
46 #include <linux/i2c.h>
57 static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
61 #define LM92_REG_CONFIG 0x01
62 #define LM92_REG_TEMP 0x00
63 #define LM92_REG_TEMP_HYST 0x02
64 #define LM92_REG_TEMP_CRIT 0x03
65 #define LM92_REG_TEMP_LOW 0x04
66 #define LM92_REG_TEMP_HIGH 0x05
67 #define LM92_REG_MAN_ID 0x07
78 return reg / 8 * 625 / 10;
84 return -60000 * 10 / 625 * 8;
86 return 160000 * 10 / 625 * 8;
87 return val * 10 / 625 * 8;
124 dev_dbg(&client->
dev,
"Updating lm92 data\n");
125 data->
temp1_input = i2c_smbus_read_word_swapped(client,
127 data->
temp1_hyst = i2c_smbus_read_word_swapped(client,
129 data->
temp1_crit = i2c_smbus_read_word_swapped(client,
131 data->
temp1_min = i2c_smbus_read_word_swapped(client,
133 data->
temp1_max = i2c_smbus_read_word_swapped(client,
145 #define show_temp(value) \
146 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, \
149 struct lm92_data *data = lm92_update_device(dev); \
150 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \
157 #define set_temp(value, reg) \
158 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \
162 struct i2c_client *client = to_i2c_client(dev); \
163 struct lm92_data *data = i2c_get_clientdata(client); \
165 int err = kstrtol(buf, 10, &val); \
169 mutex_lock(&data->update_lock); \
170 data->value = TEMP_TO_REG(val); \
171 i2c_smbus_write_word_swapped(client, reg, data->value); \
172 mutex_unlock(&data->update_lock); \
189 struct lm92_data *data = lm92_update_device(dev);
196 struct lm92_data *data = lm92_update_device(dev);
203 const char *buf,
size_t count)
206 struct lm92_data *data = i2c_get_clientdata(client);
210 err = kstrtol(buf, 10, &val);
225 struct lm92_data *data = lm92_update_device(dev);
233 struct lm92_data *data = lm92_update_device(dev);
241 set_temp1_crit_hyst);
258 static void lm92_init_client(
struct i2c_client *client)
276 static int max6635_check(
struct i2c_client *client)
278 u16 temp_low, temp_high, temp_hyst, temp_crit;
294 if ((temp_low & 0x7f00) || (temp_high & 0x7f00))
298 if ((temp_hyst & 0x7f00) || (temp_crit & 0x7f00))
308 for (i = 16; i < 96; i *= 2) {
325 static struct attribute *lm92_attributes[] = {
326 &dev_attr_temp1_input.attr,
327 &dev_attr_temp1_crit.attr,
328 &dev_attr_temp1_crit_hyst.attr,
329 &dev_attr_temp1_min.attr,
330 &dev_attr_temp1_min_hyst.attr,
331 &dev_attr_temp1_max.attr,
332 &dev_attr_temp1_max_hyst.attr,
333 &dev_attr_alarms.attr,
334 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
335 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
336 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
341 .attrs = lm92_attributes,
345 static int lm92_detect(
struct i2c_client *new_client,
359 if ((config & 0xe0) == 0x00 && man_id == 0x0180)
360 pr_info(
"lm92: Found National Semiconductor LM92 chip\n");
361 else if (max6635_check(new_client))
362 pr_info(
"lm92: Found Maxim MAX6635 chip\n");
371 static int lm92_probe(
struct i2c_client *new_client,
382 i2c_set_clientdata(new_client, data);
387 lm92_init_client(new_client);
407 static int lm92_remove(
struct i2c_client *client)
409 struct lm92_data *data = i2c_get_clientdata(client);
435 .remove = lm92_remove,
437 .detect = lm92_detect,
438 .address_list = normal_i2c,