lm95241.c (27739e694a3c34b5e371575d74e500d60111c689) lm95241.c (0c2a40e2fe4f4af0410f57e84b95b817ec15aa70)
1/*
2 * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com>
3 *
4 * The LM95241 is a sensor chip made by National Semiconductors.
5 * It reports up to three temperatures (its own plus up to two external ones).
6 * Complete datasheet can be obtained from National's website at:
7 * http://www.national.com/ds.cgi/LM/LM95241.pdf
8 *

--- 84 unchanged lines hidden (view full) ---

93 unsigned long last_updated, interval; /* in jiffies */
94 char valid; /* zero until following fields are valid */
95 /* registers values */
96 u8 temp[ARRAY_SIZE(lm95241_reg_address)];
97 u8 config, model, trutherm;
98};
99
100/* Conversions */
1/*
2 * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com>
3 *
4 * The LM95241 is a sensor chip made by National Semiconductors.
5 * It reports up to three temperatures (its own plus up to two external ones).
6 * Complete datasheet can be obtained from National's website at:
7 * http://www.national.com/ds.cgi/LM/LM95241.pdf
8 *

--- 84 unchanged lines hidden (view full) ---

93 unsigned long last_updated, interval; /* in jiffies */
94 char valid; /* zero until following fields are valid */
95 /* registers values */
96 u8 temp[ARRAY_SIZE(lm95241_reg_address)];
97 u8 config, model, trutherm;
98};
99
100/* Conversions */
101static int TempFromReg(u8 val_h, u8 val_l)
101static int temp_from_reg_signed(u8 val_h, u8 val_l)
102{
102{
103 if (val_h & 0x80)
104 return val_h - 0x100;
105 return val_h * 1000 + val_l * 1000 / 256;
103 s16 val_hl = (val_h << 8) | val_l;
104 return val_hl * 1000 / 256;
106}
107
105}
106
107static int temp_from_reg_unsigned(u8 val_h, u8 val_l)
108{
109 u16 val_hl = (val_h << 8) | val_l;
110 return val_hl * 1000 / 256;
111}
112
108static struct lm95241_data *lm95241_update_device(struct device *dev)
109{
110 struct i2c_client *client = to_i2c_client(dev);
111 struct lm95241_data *data = i2c_get_clientdata(client);
112
113 mutex_lock(&data->update_lock);
114
115 if (time_after(jiffies, data->last_updated + data->interval) ||

--- 14 unchanged lines hidden (view full) ---

130 return data;
131}
132
133/* Sysfs stuff */
134static ssize_t show_input(struct device *dev, struct device_attribute *attr,
135 char *buf)
136{
137 struct lm95241_data *data = lm95241_update_device(dev);
113static struct lm95241_data *lm95241_update_device(struct device *dev)
114{
115 struct i2c_client *client = to_i2c_client(dev);
116 struct lm95241_data *data = i2c_get_clientdata(client);
117
118 mutex_lock(&data->update_lock);
119
120 if (time_after(jiffies, data->last_updated + data->interval) ||

--- 14 unchanged lines hidden (view full) ---

135 return data;
136}
137
138/* Sysfs stuff */
139static ssize_t show_input(struct device *dev, struct device_attribute *attr,
140 char *buf)
141{
142 struct lm95241_data *data = lm95241_update_device(dev);
143 int index = to_sensor_dev_attr(attr)->index;
138
139 return snprintf(buf, PAGE_SIZE - 1, "%d\n",
144
145 return snprintf(buf, PAGE_SIZE - 1, "%d\n",
140 TempFromReg(data->temp[to_sensor_dev_attr(attr)->index],
141 data->temp[to_sensor_dev_attr(attr)->index + 1]));
146 index == 0 || (data->config & (1 << (index / 2))) ?
147 temp_from_reg_signed(data->temp[index], data->temp[index + 1]) :
148 temp_from_reg_unsigned(data->temp[index],
149 data->temp[index + 1]));
142}
143
144static ssize_t show_type(struct device *dev, struct device_attribute *attr,
145 char *buf)
146{
147 struct i2c_client *client = to_i2c_client(dev);
148 struct lm95241_data *data = i2c_get_clientdata(client);
149

--- 309 unchanged lines hidden ---
150}
151
152static ssize_t show_type(struct device *dev, struct device_attribute *attr,
153 char *buf)
154{
155 struct i2c_client *client = to_i2c_client(dev);
156 struct lm95241_data *data = i2c_get_clientdata(client);
157

--- 309 unchanged lines hidden ---