28 #include <linux/module.h>
30 #include <linux/slab.h>
32 #include <linux/i2c.h>
39 static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
43 #define LM77_REG_TEMP 0x00
44 #define LM77_REG_CONF 0x01
45 #define LM77_REG_TEMP_HYST 0x02
46 #define LM77_REG_TEMP_CRIT 0x03
47 #define LM77_REG_TEMP_MIN 0x04
48 #define LM77_REG_TEMP_MAX 0x05
88 .remove = lm77_remove,
90 .detect = lm77_detect,
91 .address_list = normal_i2c,
95 #define LM77_TEMP_MIN (-55000)
96 #define LM77_TEMP_MAX 125000
102 static inline s16 LM77_TEMP_TO_REG(
int temp)
105 return (ntemp / 500) * 8;
108 static inline int LM77_TEMP_FROM_REG(
s16 reg)
110 return (reg / 8) * 500;
116 #define show(value) \
117 static ssize_t show_##value(struct device *dev, \
118 struct device_attribute *attr, \
121 struct lm77_data *data = lm77_update_device(dev); \
122 return sprintf(buf, "%d\n", data->value); \
151 #define set(value, reg) \
152 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \
153 const char *buf, size_t count) \
155 struct i2c_client *client = to_i2c_client(dev); \
156 struct lm77_data *data = i2c_get_clientdata(client); \
158 int err = kstrtol(buf, 10, &val); \
162 mutex_lock(&data->update_lock); \
164 lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \
165 mutex_unlock(&data->update_lock); \
185 err = kstrtoul(buf, 10, &val);
207 err = kstrtoul(buf, 10, &val);
227 struct lm77_data *data = lm77_update_device(dev);
232 show_temp_input,
NULL);
234 show_temp_crit, set_temp_crit);
236 show_temp_min, set_temp_min);
238 show_temp_max, set_temp_max);
241 show_temp_crit_hyst, set_temp_crit_hyst);
243 show_temp_min_hyst,
NULL);
245 show_temp_max_hyst,
NULL);
251 static struct attribute *lm77_attributes[] = {
252 &dev_attr_temp1_input.attr,
253 &dev_attr_temp1_crit.attr,
254 &dev_attr_temp1_min.attr,
255 &dev_attr_temp1_max.attr,
256 &dev_attr_temp1_crit_hyst.attr,
257 &dev_attr_temp1_min_hyst.attr,
258 &dev_attr_temp1_max_hyst.attr,
259 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
260 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
261 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
266 .attrs = lm77_attributes,
300 for (i = 8; i <= 0xff; i += 8) {
310 if (((cur & 0x00f0) != 0xf0 && (cur & 0x00f0) != 0x0)
311 || ((hyst & 0x00f0) != 0xf0 && (hyst & 0x00f0) != 0x0)
312 || ((crit & 0x00f0) != 0xf0 && (crit & 0x00f0) != 0x0)
313 || ((min & 0x00f0) != 0xf0 && (min & 0x00f0) != 0x0)
314 || ((max & 0x00f0) != 0xf0 && (max & 0x00f0) != 0x0))
350 i2c_set_clientdata(client, data);
355 lm77_init_client(client);
375 static int lm77_remove(
struct i2c_client *client)
377 struct lm77_data *data = i2c_get_clientdata(client);
392 return i2c_smbus_read_word_swapped(client, reg);
400 return i2c_smbus_write_word_swapped(client, reg, value);
403 static void lm77_init_client(
struct i2c_client *client)
414 struct lm77_data *data = i2c_get_clientdata(client);
420 dev_dbg(&client->
dev,
"Starting lm77 update\n");
422 LM77_TEMP_FROM_REG(lm77_read_value(client,
425 LM77_TEMP_FROM_REG(lm77_read_value(client,
428 LM77_TEMP_FROM_REG(lm77_read_value(client,
431 LM77_TEMP_FROM_REG(lm77_read_value(client,
434 LM77_TEMP_FROM_REG(lm77_read_value(client,