hwmon: (lm80) De-macro the sysfs callbacks

Use standard dynamic sysfs callbacks instead of macro-generated
functions. This makes the code more readable, and the binary smaller
(by about 34%).

As a side note, another benefit of this type of cleanup is that they
shrink the build time. For example, this cleanup saves about 29% of
the lm80 driver build time.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>

authored by Jean Delvare and committed by Mark M. Hoffman f8181762 6cc37ee5

+111 -134
+111 -134
drivers/hwmon/lm80.c
··· 27 #include <linux/jiffies.h> 28 #include <linux/i2c.h> 29 #include <linux/hwmon.h> 30 #include <linux/err.h> 31 #include <linux/mutex.h> 32 ··· 159 #define show_in(suffix, value) \ 160 static ssize_t show_in_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 161 { \ 162 struct lm80_data *data = lm80_update_device(dev); \ 163 - return sprintf(buf, "%d\n", IN_FROM_REG(data->value)); \ 164 } 165 - show_in(min0, in_min[0]); 166 - show_in(min1, in_min[1]); 167 - show_in(min2, in_min[2]); 168 - show_in(min3, in_min[3]); 169 - show_in(min4, in_min[4]); 170 - show_in(min5, in_min[5]); 171 - show_in(min6, in_min[6]); 172 - show_in(max0, in_max[0]); 173 - show_in(max1, in_max[1]); 174 - show_in(max2, in_max[2]); 175 - show_in(max3, in_max[3]); 176 - show_in(max4, in_max[4]); 177 - show_in(max5, in_max[5]); 178 - show_in(max6, in_max[6]); 179 - show_in(input0, in[0]); 180 - show_in(input1, in[1]); 181 - show_in(input2, in[2]); 182 - show_in(input3, in[3]); 183 - show_in(input4, in[4]); 184 - show_in(input5, in[5]); 185 - show_in(input6, in[6]); 186 187 #define set_in(suffix, value, reg) \ 188 static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 189 size_t count) \ 190 { \ 191 struct i2c_client *client = to_i2c_client(dev); \ 192 struct lm80_data *data = i2c_get_clientdata(client); \ 193 long val = simple_strtol(buf, NULL, 10); \ 194 \ 195 mutex_lock(&data->update_lock);\ 196 - data->value = IN_TO_REG(val); \ 197 - lm80_write_value(client, reg, data->value); \ 198 mutex_unlock(&data->update_lock);\ 199 return count; \ 200 } 201 - set_in(min0, in_min[0], LM80_REG_IN_MIN(0)); 202 - set_in(min1, in_min[1], LM80_REG_IN_MIN(1)); 203 - set_in(min2, in_min[2], LM80_REG_IN_MIN(2)); 204 - set_in(min3, in_min[3], LM80_REG_IN_MIN(3)); 205 - set_in(min4, in_min[4], LM80_REG_IN_MIN(4)); 206 - set_in(min5, in_min[5], LM80_REG_IN_MIN(5)); 207 - set_in(min6, in_min[6], LM80_REG_IN_MIN(6)); 208 - set_in(max0, in_max[0], LM80_REG_IN_MAX(0)); 209 - set_in(max1, in_max[1], LM80_REG_IN_MAX(1)); 210 - set_in(max2, in_max[2], LM80_REG_IN_MAX(2)); 211 - set_in(max3, in_max[3], LM80_REG_IN_MAX(3)); 212 - set_in(max4, in_max[4], LM80_REG_IN_MAX(4)); 213 - set_in(max5, in_max[5], LM80_REG_IN_MAX(5)); 214 - set_in(max6, in_max[6], LM80_REG_IN_MAX(6)); 215 216 - #define show_fan(suffix, value, div) \ 217 static ssize_t show_fan_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 218 { \ 219 struct lm80_data *data = lm80_update_device(dev); \ 220 - return sprintf(buf, "%d\n", FAN_FROM_REG(data->value, \ 221 - DIV_FROM_REG(data->div))); \ 222 } 223 - show_fan(min1, fan_min[0], fan_div[0]); 224 - show_fan(min2, fan_min[1], fan_div[1]); 225 - show_fan(input1, fan[0], fan_div[0]); 226 - show_fan(input2, fan[1], fan_div[1]); 227 228 - #define show_fan_div(suffix, value) \ 229 - static ssize_t show_fan_div##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 230 - { \ 231 - struct lm80_data *data = lm80_update_device(dev); \ 232 - return sprintf(buf, "%d\n", DIV_FROM_REG(data->value)); \ 233 } 234 - show_fan_div(1, fan_div[0]); 235 - show_fan_div(2, fan_div[1]); 236 237 - #define set_fan(suffix, value, reg, div) \ 238 - static ssize_t set_fan_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 239 - size_t count) \ 240 - { \ 241 - struct i2c_client *client = to_i2c_client(dev); \ 242 - struct lm80_data *data = i2c_get_clientdata(client); \ 243 - long val = simple_strtoul(buf, NULL, 10); \ 244 - \ 245 - mutex_lock(&data->update_lock);\ 246 - data->value = FAN_TO_REG(val, DIV_FROM_REG(data->div)); \ 247 - lm80_write_value(client, reg, data->value); \ 248 - mutex_unlock(&data->update_lock);\ 249 - return count; \ 250 } 251 - set_fan(min1, fan_min[0], LM80_REG_FAN_MIN(1), fan_div[0]); 252 - set_fan(min2, fan_min[1], LM80_REG_FAN_MIN(2), fan_div[1]); 253 254 /* Note: we save and restore the fan minimum here, because its value is 255 determined in part by the fan divisor. This follows the principle of 256 least surprise; the user doesn't expect the fan minimum to change just 257 because the divisor changed. */ 258 - static ssize_t set_fan_div(struct device *dev, const char *buf, 259 - size_t count, int nr) 260 { 261 struct i2c_client *client = to_i2c_client(dev); 262 struct lm80_data *data = i2c_get_clientdata(client); 263 unsigned long min, val = simple_strtoul(buf, NULL, 10); ··· 260 261 return count; 262 } 263 - 264 - #define set_fan_div(number) \ 265 - static ssize_t set_fan_div##number(struct device *dev, struct device_attribute *attr, const char *buf, \ 266 - size_t count) \ 267 - { \ 268 - return set_fan_div(dev, buf, count, number - 1); \ 269 - } 270 - set_fan_div(1); 271 - set_fan_div(2); 272 273 static ssize_t show_temp_input1(struct device *dev, struct device_attribute *attr, char *buf) 274 { ··· 304 return sprintf(buf, "%u\n", data->alarms); 305 } 306 307 - static DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min0, set_in_min0); 308 - static DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min1, set_in_min1); 309 - static DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min2, set_in_min2); 310 - static DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min3, set_in_min3); 311 - static DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min4, set_in_min4); 312 - static DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min5, set_in_min5); 313 - static DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min6, set_in_min6); 314 - static DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max0, set_in_max0); 315 - static DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max1, set_in_max1); 316 - static DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max2, set_in_max2); 317 - static DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max3, set_in_max3); 318 - static DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max4, set_in_max4); 319 - static DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max5, set_in_max5); 320 - static DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max6, set_in_max6); 321 - static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL); 322 - static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL); 323 - static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL); 324 - static DEVICE_ATTR(in3_input, S_IRUGO, show_in_input3, NULL); 325 - static DEVICE_ATTR(in4_input, S_IRUGO, show_in_input4, NULL); 326 - static DEVICE_ATTR(in5_input, S_IRUGO, show_in_input5, NULL); 327 - static DEVICE_ATTR(in6_input, S_IRUGO, show_in_input6, NULL); 328 - static DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min1, 329 - set_fan_min1); 330 - static DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min2, 331 - set_fan_min2); 332 - static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input1, NULL); 333 - static DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input2, NULL); 334 - static DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO, show_fan_div1, set_fan_div1); 335 - static DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO, show_fan_div2, set_fan_div2); 336 static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL); 337 static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_hot_max, 338 set_temp_hot_max); ··· 372 } 373 374 static struct attribute *lm80_attributes[] = { 375 - &dev_attr_in0_min.attr, 376 - &dev_attr_in1_min.attr, 377 - &dev_attr_in2_min.attr, 378 - &dev_attr_in3_min.attr, 379 - &dev_attr_in4_min.attr, 380 - &dev_attr_in5_min.attr, 381 - &dev_attr_in6_min.attr, 382 - &dev_attr_in0_max.attr, 383 - &dev_attr_in1_max.attr, 384 - &dev_attr_in2_max.attr, 385 - &dev_attr_in3_max.attr, 386 - &dev_attr_in4_max.attr, 387 - &dev_attr_in5_max.attr, 388 - &dev_attr_in6_max.attr, 389 - &dev_attr_in0_input.attr, 390 - &dev_attr_in1_input.attr, 391 - &dev_attr_in2_input.attr, 392 - &dev_attr_in3_input.attr, 393 - &dev_attr_in4_input.attr, 394 - &dev_attr_in5_input.attr, 395 - &dev_attr_in6_input.attr, 396 - &dev_attr_fan1_min.attr, 397 - &dev_attr_fan2_min.attr, 398 - &dev_attr_fan1_input.attr, 399 - &dev_attr_fan2_input.attr, 400 - &dev_attr_fan1_div.attr, 401 - &dev_attr_fan2_div.attr, 402 &dev_attr_temp1_input.attr, 403 &dev_attr_temp1_max.attr, 404 &dev_attr_temp1_max_hyst.attr,
··· 27 #include <linux/jiffies.h> 28 #include <linux/i2c.h> 29 #include <linux/hwmon.h> 30 + #include <linux/hwmon-sysfs.h> 31 #include <linux/err.h> 32 #include <linux/mutex.h> 33 ··· 158 #define show_in(suffix, value) \ 159 static ssize_t show_in_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 160 { \ 161 + int nr = to_sensor_dev_attr(attr)->index; \ 162 struct lm80_data *data = lm80_update_device(dev); \ 163 + return sprintf(buf, "%d\n", IN_FROM_REG(data->value[nr])); \ 164 } 165 + show_in(min, in_min) 166 + show_in(max, in_max) 167 + show_in(input, in) 168 169 #define set_in(suffix, value, reg) \ 170 static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 171 size_t count) \ 172 { \ 173 + int nr = to_sensor_dev_attr(attr)->index; \ 174 struct i2c_client *client = to_i2c_client(dev); \ 175 struct lm80_data *data = i2c_get_clientdata(client); \ 176 long val = simple_strtol(buf, NULL, 10); \ 177 \ 178 mutex_lock(&data->update_lock);\ 179 + data->value[nr] = IN_TO_REG(val); \ 180 + lm80_write_value(client, reg(nr), data->value[nr]); \ 181 mutex_unlock(&data->update_lock);\ 182 return count; \ 183 } 184 + set_in(min, in_min, LM80_REG_IN_MIN) 185 + set_in(max, in_max, LM80_REG_IN_MAX) 186 187 + #define show_fan(suffix, value) \ 188 static ssize_t show_fan_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 189 { \ 190 + int nr = to_sensor_dev_attr(attr)->index; \ 191 struct lm80_data *data = lm80_update_device(dev); \ 192 + return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[nr], \ 193 + DIV_FROM_REG(data->fan_div[nr]))); \ 194 } 195 + show_fan(min, fan_min) 196 + show_fan(input, fan) 197 198 + static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, 199 + char *buf) 200 + { 201 + int nr = to_sensor_dev_attr(attr)->index; 202 + struct lm80_data *data = lm80_update_device(dev); 203 + return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); 204 } 205 206 + static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, 207 + const char *buf, size_t count) 208 + { 209 + int nr = to_sensor_dev_attr(attr)->index; 210 + struct i2c_client *client = to_i2c_client(dev); 211 + struct lm80_data *data = i2c_get_clientdata(client); 212 + long val = simple_strtoul(buf, NULL, 10); 213 + 214 + mutex_lock(&data->update_lock); 215 + data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 216 + lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]); 217 + mutex_unlock(&data->update_lock); 218 + return count; 219 } 220 221 /* Note: we save and restore the fan minimum here, because its value is 222 determined in part by the fan divisor. This follows the principle of 223 least surprise; the user doesn't expect the fan minimum to change just 224 because the divisor changed. */ 225 + static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, 226 + const char *buf, size_t count) 227 { 228 + int nr = to_sensor_dev_attr(attr)->index; 229 struct i2c_client *client = to_i2c_client(dev); 230 struct lm80_data *data = i2c_get_clientdata(client); 231 unsigned long min, val = simple_strtoul(buf, NULL, 10); ··· 290 291 return count; 292 } 293 294 static ssize_t show_temp_input1(struct device *dev, struct device_attribute *attr, char *buf) 295 { ··· 343 return sprintf(buf, "%u\n", data->alarms); 344 } 345 346 + static SENSOR_DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO, 347 + show_in_min, set_in_min, 0); 348 + static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, 349 + show_in_min, set_in_min, 1); 350 + static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, 351 + show_in_min, set_in_min, 2); 352 + static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, 353 + show_in_min, set_in_min, 3); 354 + static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, 355 + show_in_min, set_in_min, 4); 356 + static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, 357 + show_in_min, set_in_min, 5); 358 + static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, 359 + show_in_min, set_in_min, 6); 360 + static SENSOR_DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO, 361 + show_in_max, set_in_max, 0); 362 + static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, 363 + show_in_max, set_in_max, 1); 364 + static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, 365 + show_in_max, set_in_max, 2); 366 + static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, 367 + show_in_max, set_in_max, 3); 368 + static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, 369 + show_in_max, set_in_max, 4); 370 + static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, 371 + show_in_max, set_in_max, 5); 372 + static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, 373 + show_in_max, set_in_max, 6); 374 + static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in_input, NULL, 0); 375 + static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in_input, NULL, 1); 376 + static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in_input, NULL, 2); 377 + static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in_input, NULL, 3); 378 + static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in_input, NULL, 4); 379 + static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in_input, NULL, 5); 380 + static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in_input, NULL, 6); 381 + static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, 382 + show_fan_min, set_fan_min, 0); 383 + static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, 384 + show_fan_min, set_fan_min, 1); 385 + static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0); 386 + static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1); 387 + static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO, 388 + show_fan_div, set_fan_div, 0); 389 + static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO, 390 + show_fan_div, set_fan_div, 1); 391 static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL); 392 static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_hot_max, 393 set_temp_hot_max); ··· 395 } 396 397 static struct attribute *lm80_attributes[] = { 398 + &sensor_dev_attr_in0_min.dev_attr.attr, 399 + &sensor_dev_attr_in1_min.dev_attr.attr, 400 + &sensor_dev_attr_in2_min.dev_attr.attr, 401 + &sensor_dev_attr_in3_min.dev_attr.attr, 402 + &sensor_dev_attr_in4_min.dev_attr.attr, 403 + &sensor_dev_attr_in5_min.dev_attr.attr, 404 + &sensor_dev_attr_in6_min.dev_attr.attr, 405 + &sensor_dev_attr_in0_max.dev_attr.attr, 406 + &sensor_dev_attr_in1_max.dev_attr.attr, 407 + &sensor_dev_attr_in2_max.dev_attr.attr, 408 + &sensor_dev_attr_in3_max.dev_attr.attr, 409 + &sensor_dev_attr_in4_max.dev_attr.attr, 410 + &sensor_dev_attr_in5_max.dev_attr.attr, 411 + &sensor_dev_attr_in6_max.dev_attr.attr, 412 + &sensor_dev_attr_in0_input.dev_attr.attr, 413 + &sensor_dev_attr_in1_input.dev_attr.attr, 414 + &sensor_dev_attr_in2_input.dev_attr.attr, 415 + &sensor_dev_attr_in3_input.dev_attr.attr, 416 + &sensor_dev_attr_in4_input.dev_attr.attr, 417 + &sensor_dev_attr_in5_input.dev_attr.attr, 418 + &sensor_dev_attr_in6_input.dev_attr.attr, 419 + &sensor_dev_attr_fan1_min.dev_attr.attr, 420 + &sensor_dev_attr_fan2_min.dev_attr.attr, 421 + &sensor_dev_attr_fan1_input.dev_attr.attr, 422 + &sensor_dev_attr_fan2_input.dev_attr.attr, 423 + &sensor_dev_attr_fan1_div.dev_attr.attr, 424 + &sensor_dev_attr_fan2_div.dev_attr.attr, 425 &dev_attr_temp1_input.attr, 426 &dev_attr_temp1_max.attr, 427 &dev_attr_temp1_max_hyst.attr,