diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-04-12 12:17:37 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-05-21 19:02:20 -0400 |
commit | 48dbd6ff142d518e01888d2addfab731ff65460e (patch) | |
tree | ff3eae95dd9ae785d7eaa7546a19e83aded6cbc6 | |
parent | 50bf46509f24c914562b4d818a155d8dc8f45e10 (diff) |
hwmon: (lm77) Drop function macros
Function macros make the code harder to read and increase code size,
so drop them.
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/lm77.c | 182 |
1 files changed, 75 insertions, 107 deletions
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c index 85e5b3355be4..ab1752a5b46f 100644 --- a/drivers/hwmon/lm77.c +++ b/drivers/hwmon/lm77.c | |||
@@ -43,17 +43,30 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, | |||
43 | #define LM77_REG_TEMP_MIN 0x04 | 43 | #define LM77_REG_TEMP_MIN 0x04 |
44 | #define LM77_REG_TEMP_MAX 0x05 | 44 | #define LM77_REG_TEMP_MAX 0x05 |
45 | 45 | ||
46 | enum temp_index { | ||
47 | t_input = 0, | ||
48 | t_crit, | ||
49 | t_min, | ||
50 | t_max, | ||
51 | t_hyst, | ||
52 | t_num_temp | ||
53 | }; | ||
54 | |||
55 | static const u8 temp_regs[t_num_temp] = { | ||
56 | [t_input] = LM77_REG_TEMP, | ||
57 | [t_min] = LM77_REG_TEMP_MIN, | ||
58 | [t_max] = LM77_REG_TEMP_MAX, | ||
59 | [t_crit] = LM77_REG_TEMP_CRIT, | ||
60 | [t_hyst] = LM77_REG_TEMP_HYST, | ||
61 | }; | ||
62 | |||
46 | /* Each client has this additional data */ | 63 | /* Each client has this additional data */ |
47 | struct lm77_data { | 64 | struct lm77_data { |
48 | struct device *hwmon_dev; | 65 | struct device *hwmon_dev; |
49 | struct mutex update_lock; | 66 | struct mutex update_lock; |
50 | char valid; | 67 | char valid; |
51 | unsigned long last_updated; /* In jiffies */ | 68 | unsigned long last_updated; /* In jiffies */ |
52 | int temp_input; /* Temperatures */ | 69 | int temp[t_num_temp]; /* index using temp_index */ |
53 | int temp_crit; | ||
54 | int temp_min; | ||
55 | int temp_max; | ||
56 | int temp_hyst; | ||
57 | u8 alarms; | 70 | u8 alarms; |
58 | }; | 71 | }; |
59 | 72 | ||
@@ -100,27 +113,18 @@ static struct lm77_data *lm77_update_device(struct device *dev) | |||
100 | { | 113 | { |
101 | struct i2c_client *client = to_i2c_client(dev); | 114 | struct i2c_client *client = to_i2c_client(dev); |
102 | struct lm77_data *data = i2c_get_clientdata(client); | 115 | struct lm77_data *data = i2c_get_clientdata(client); |
116 | int i; | ||
103 | 117 | ||
104 | mutex_lock(&data->update_lock); | 118 | mutex_lock(&data->update_lock); |
105 | 119 | ||
106 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 120 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
107 | || !data->valid) { | 121 | || !data->valid) { |
108 | dev_dbg(&client->dev, "Starting lm77 update\n"); | 122 | dev_dbg(&client->dev, "Starting lm77 update\n"); |
109 | data->temp_input = | 123 | for (i = 0; i < t_num_temp; i++) { |
110 | LM77_TEMP_FROM_REG(lm77_read_value(client, | 124 | data->temp[i] = |
111 | LM77_REG_TEMP)); | 125 | LM77_TEMP_FROM_REG(lm77_read_value(client, |
112 | data->temp_hyst = | 126 | temp_regs[i])); |
113 | LM77_TEMP_FROM_REG(lm77_read_value(client, | 127 | } |
114 | LM77_REG_TEMP_HYST)); | ||
115 | data->temp_crit = | ||
116 | LM77_TEMP_FROM_REG(lm77_read_value(client, | ||
117 | LM77_REG_TEMP_CRIT)); | ||
118 | data->temp_min = | ||
119 | LM77_TEMP_FROM_REG(lm77_read_value(client, | ||
120 | LM77_REG_TEMP_MIN)); | ||
121 | data->temp_max = | ||
122 | LM77_TEMP_FROM_REG(lm77_read_value(client, | ||
123 | LM77_REG_TEMP_MAX)); | ||
124 | data->alarms = | 128 | data->alarms = |
125 | lm77_read_value(client, LM77_REG_TEMP) & 0x0007; | 129 | lm77_read_value(client, LM77_REG_TEMP) & 0x0007; |
126 | data->last_updated = jiffies; | 130 | data->last_updated = jiffies; |
@@ -134,89 +138,56 @@ static struct lm77_data *lm77_update_device(struct device *dev) | |||
134 | 138 | ||
135 | /* sysfs stuff */ | 139 | /* sysfs stuff */ |
136 | 140 | ||
137 | /* read routines for temperature limits */ | 141 | static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, |
138 | #define show(value) \ | 142 | char *buf) |
139 | static ssize_t show_##value(struct device *dev, \ | ||
140 | struct device_attribute *attr, \ | ||
141 | char *buf) \ | ||
142 | { \ | ||
143 | struct lm77_data *data = lm77_update_device(dev); \ | ||
144 | return sprintf(buf, "%d\n", data->value); \ | ||
145 | } | ||
146 | |||
147 | show(temp_input); | ||
148 | show(temp_crit); | ||
149 | show(temp_min); | ||
150 | show(temp_max); | ||
151 | |||
152 | /* read routines for hysteresis values */ | ||
153 | static ssize_t show_temp_crit_hyst(struct device *dev, | ||
154 | struct device_attribute *attr, char *buf) | ||
155 | { | 143 | { |
144 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
156 | struct lm77_data *data = lm77_update_device(dev); | 145 | struct lm77_data *data = lm77_update_device(dev); |
157 | return sprintf(buf, "%d\n", data->temp_crit - data->temp_hyst); | 146 | |
158 | } | 147 | return sprintf(buf, "%d\n", data->temp[attr->index]); |
159 | static ssize_t show_temp_min_hyst(struct device *dev, | ||
160 | struct device_attribute *attr, char *buf) | ||
161 | { | ||
162 | struct lm77_data *data = lm77_update_device(dev); | ||
163 | return sprintf(buf, "%d\n", data->temp_min + data->temp_hyst); | ||
164 | } | 148 | } |
165 | static ssize_t show_temp_max_hyst(struct device *dev, | 149 | |
166 | struct device_attribute *attr, char *buf) | 150 | static ssize_t show_temp_hyst(struct device *dev, |
151 | struct device_attribute *devattr, char *buf) | ||
167 | { | 152 | { |
153 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
168 | struct lm77_data *data = lm77_update_device(dev); | 154 | struct lm77_data *data = lm77_update_device(dev); |
169 | return sprintf(buf, "%d\n", data->temp_max - data->temp_hyst); | 155 | int nr = attr->index; |
170 | } | 156 | int temp; |
171 | 157 | ||
172 | /* write routines */ | 158 | temp = nr == t_min ? data->temp[nr] + data->temp[t_hyst] : |
173 | #define set(value, reg) \ | 159 | data->temp[nr] - data->temp[t_hyst]; |
174 | static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \ | ||
175 | const char *buf, size_t count) \ | ||
176 | { \ | ||
177 | struct i2c_client *client = to_i2c_client(dev); \ | ||
178 | struct lm77_data *data = i2c_get_clientdata(client); \ | ||
179 | long val; \ | ||
180 | int err = kstrtol(buf, 10, &val); \ | ||
181 | if (err) \ | ||
182 | return err; \ | ||
183 | \ | ||
184 | mutex_lock(&data->update_lock); \ | ||
185 | data->value = val; \ | ||
186 | lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \ | ||
187 | mutex_unlock(&data->update_lock); \ | ||
188 | return count; \ | ||
189 | } | ||
190 | 160 | ||
191 | set(temp_min, LM77_REG_TEMP_MIN); | 161 | return sprintf(buf, "%d\n", temp); |
192 | set(temp_max, LM77_REG_TEMP_MAX); | 162 | } |
193 | 163 | ||
194 | /* | 164 | static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, |
195 | * hysteresis is stored as a relative value on the chip, so it has to be | 165 | const char *buf, size_t count) |
196 | * converted first | ||
197 | */ | ||
198 | static ssize_t set_temp_crit_hyst(struct device *dev, | ||
199 | struct device_attribute *attr, | ||
200 | const char *buf, size_t count) | ||
201 | { | 166 | { |
167 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
202 | struct i2c_client *client = to_i2c_client(dev); | 168 | struct i2c_client *client = to_i2c_client(dev); |
203 | struct lm77_data *data = i2c_get_clientdata(client); | 169 | struct lm77_data *data = i2c_get_clientdata(client); |
204 | unsigned long val; | 170 | int nr = attr->index; |
171 | long val; | ||
205 | int err; | 172 | int err; |
206 | 173 | ||
207 | err = kstrtoul(buf, 10, &val); | 174 | err = kstrtol(buf, 10, &val); |
208 | if (err) | 175 | if (err) |
209 | return err; | 176 | return err; |
210 | 177 | ||
211 | mutex_lock(&data->update_lock); | 178 | mutex_lock(&data->update_lock); |
212 | data->temp_hyst = data->temp_crit - val; | 179 | data->temp[nr] = val; |
213 | lm77_write_value(client, LM77_REG_TEMP_HYST, | 180 | lm77_write_value(client, temp_regs[nr], LM77_TEMP_TO_REG(val)); |
214 | LM77_TEMP_TO_REG(data->temp_hyst)); | ||
215 | mutex_unlock(&data->update_lock); | 181 | mutex_unlock(&data->update_lock); |
216 | return count; | 182 | return count; |
217 | } | 183 | } |
218 | 184 | ||
219 | static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, | 185 | /* |
186 | * hysteresis is stored as a relative value on the chip, so it has to be | ||
187 | * converted first. | ||
188 | */ | ||
189 | static ssize_t set_temp_hyst(struct device *dev, | ||
190 | struct device_attribute *devattr, | ||
220 | const char *buf, size_t count) | 191 | const char *buf, size_t count) |
221 | { | 192 | { |
222 | struct i2c_client *client = to_i2c_client(dev); | 193 | struct i2c_client *client = to_i2c_client(dev); |
@@ -229,9 +200,9 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, | |||
229 | return err; | 200 | return err; |
230 | 201 | ||
231 | mutex_lock(&data->update_lock); | 202 | mutex_lock(&data->update_lock); |
232 | data->temp_crit = val; | 203 | data->temp[t_hyst] = data->temp[t_crit] - val; |
233 | lm77_write_value(client, LM77_REG_TEMP_CRIT, | 204 | lm77_write_value(client, LM77_REG_TEMP_HYST, |
234 | LM77_TEMP_TO_REG(data->temp_crit)); | 205 | LM77_TEMP_TO_REG(data->temp[t_hyst])); |
235 | mutex_unlock(&data->update_lock); | 206 | mutex_unlock(&data->update_lock); |
236 | return count; | 207 | return count; |
237 | } | 208 | } |
@@ -244,34 +215,31 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, | |||
244 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); | 215 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
245 | } | 216 | } |
246 | 217 | ||
247 | static DEVICE_ATTR(temp1_input, S_IRUGO, | 218 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, t_input); |
248 | show_temp_input, NULL); | 219 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp, set_temp, |
249 | static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, | 220 | t_crit); |
250 | show_temp_crit, set_temp_crit); | 221 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, |
251 | static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, | 222 | t_min); |
252 | show_temp_min, set_temp_min); | 223 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, |
253 | static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, | 224 | t_max); |
254 | show_temp_max, set_temp_max); | 225 | |
255 | 226 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_hyst, | |
256 | static DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, | 227 | set_temp_hyst, t_crit); |
257 | show_temp_crit_hyst, set_temp_crit_hyst); | 228 | static SENSOR_DEVICE_ATTR(temp1_min_hyst, S_IRUGO, show_temp_hyst, NULL, t_min); |
258 | static DEVICE_ATTR(temp1_min_hyst, S_IRUGO, | 229 | static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_temp_hyst, NULL, t_max); |
259 | show_temp_min_hyst, NULL); | ||
260 | static DEVICE_ATTR(temp1_max_hyst, S_IRUGO, | ||
261 | show_temp_max_hyst, NULL); | ||
262 | 230 | ||
263 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2); | 231 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2); |
264 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0); | 232 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0); |
265 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1); | 233 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1); |
266 | 234 | ||
267 | static struct attribute *lm77_attributes[] = { | 235 | static struct attribute *lm77_attributes[] = { |
268 | &dev_attr_temp1_input.attr, | 236 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
269 | &dev_attr_temp1_crit.attr, | 237 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
270 | &dev_attr_temp1_min.attr, | 238 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
271 | &dev_attr_temp1_max.attr, | 239 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
272 | &dev_attr_temp1_crit_hyst.attr, | 240 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, |
273 | &dev_attr_temp1_min_hyst.attr, | 241 | &sensor_dev_attr_temp1_min_hyst.dev_attr.attr, |
274 | &dev_attr_temp1_max_hyst.attr, | 242 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, |
275 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, | 243 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, |
276 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, | 244 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, |
277 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | 245 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |