diff options
| author | Michael Hennerich <michael.hennerich@analog.com> | 2010-05-24 17:33:13 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-05-25 11:07:04 -0400 |
| commit | 0993dbedf2cc2f5fd0701fa3b27afdd303536b87 (patch) | |
| tree | 6ba120759da8e61240062e341d5a9533013a8c2b /drivers/misc | |
| parent | 7d52669b14e36f8365070324be009486d387ad00 (diff) | |
ad525x_dpot: simplify duplicated sysfs defines
Macro away the duplication to make maintenance easier.
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/misc')
| -rw-r--r-- | drivers/misc/ad525x_dpot.c | 238 |
1 files changed, 43 insertions, 195 deletions
diff --git a/drivers/misc/ad525x_dpot.c b/drivers/misc/ad525x_dpot.c index 30a59f2bacd2..e6b274b5dbd6 100644 --- a/drivers/misc/ad525x_dpot.c +++ b/drivers/misc/ad525x_dpot.c | |||
| @@ -158,175 +158,45 @@ static ssize_t sysfs_do_cmd(struct device *dev, | |||
| 158 | 158 | ||
| 159 | /* ------------------------------------------------------------------------- */ | 159 | /* ------------------------------------------------------------------------- */ |
| 160 | 160 | ||
| 161 | static ssize_t show_rdac0(struct device *dev, | 161 | #define DPOT_DEVICE_SHOW(_name, _reg) static ssize_t \ |
| 162 | struct device_attribute *attr, char *buf) | 162 | show_##_name(struct device *dev, \ |
| 163 | { | 163 | struct device_attribute *attr, char *buf) \ |
| 164 | return sysfs_show_reg(dev, attr, buf, AD525X_I2C_RDAC | AD525X_RDAC0); | 164 | { \ |
| 165 | } | 165 | return sysfs_show_reg(dev, attr, buf, _reg); \ |
| 166 | |||
| 167 | static ssize_t set_rdac0(struct device *dev, | ||
| 168 | struct device_attribute *attr, | ||
| 169 | const char *buf, size_t count) | ||
| 170 | { | ||
| 171 | return sysfs_set_reg(dev, attr, buf, count, | ||
| 172 | AD525X_I2C_RDAC | AD525X_RDAC0); | ||
| 173 | } | ||
| 174 | |||
| 175 | static DEVICE_ATTR(rdac0, S_IWUSR | S_IRUGO, show_rdac0, set_rdac0); | ||
| 176 | |||
| 177 | static ssize_t show_eeprom0(struct device *dev, | ||
| 178 | struct device_attribute *attr, char *buf) | ||
| 179 | { | ||
| 180 | return sysfs_show_reg(dev, attr, buf, AD525X_I2C_EEPROM | AD525X_RDAC0); | ||
| 181 | } | ||
| 182 | |||
| 183 | static ssize_t set_eeprom0(struct device *dev, | ||
| 184 | struct device_attribute *attr, | ||
| 185 | const char *buf, size_t count) | ||
| 186 | { | ||
| 187 | return sysfs_set_reg(dev, attr, buf, count, | ||
| 188 | AD525X_I2C_EEPROM | AD525X_RDAC0); | ||
| 189 | } | ||
| 190 | |||
| 191 | static DEVICE_ATTR(eeprom0, S_IWUSR | S_IRUGO, show_eeprom0, set_eeprom0); | ||
| 192 | |||
| 193 | static ssize_t show_tolerance0(struct device *dev, | ||
| 194 | struct device_attribute *attr, char *buf) | ||
| 195 | { | ||
| 196 | return sysfs_show_reg(dev, attr, buf, | ||
| 197 | AD525X_I2C_EEPROM | AD525X_TOL_RDAC0); | ||
| 198 | } | ||
| 199 | |||
| 200 | static DEVICE_ATTR(tolerance0, S_IRUGO, show_tolerance0, NULL); | ||
| 201 | |||
| 202 | /* ------------------------------------------------------------------------- */ | ||
| 203 | |||
| 204 | static ssize_t show_rdac1(struct device *dev, | ||
| 205 | struct device_attribute *attr, char *buf) | ||
| 206 | { | ||
| 207 | return sysfs_show_reg(dev, attr, buf, AD525X_I2C_RDAC | AD525X_RDAC1); | ||
| 208 | } | 166 | } |
| 209 | 167 | ||
| 210 | static ssize_t set_rdac1(struct device *dev, | 168 | #define DPOT_DEVICE_SET(_name, _reg) static ssize_t \ |
| 211 | struct device_attribute *attr, | 169 | set_##_name(struct device *dev, \ |
| 212 | const char *buf, size_t count) | 170 | struct device_attribute *attr, \ |
| 213 | { | 171 | const char *buf, size_t count) \ |
| 214 | return sysfs_set_reg(dev, attr, buf, count, | 172 | { \ |
| 215 | AD525X_I2C_RDAC | AD525X_RDAC1); | 173 | return sysfs_set_reg(dev, attr, buf, count, _reg); \ |
| 216 | } | 174 | } |
| 217 | 175 | ||
| 218 | static DEVICE_ATTR(rdac1, S_IWUSR | S_IRUGO, show_rdac1, set_rdac1); | 176 | #define DPOT_DEVICE_SHOW_SET(name, reg) \ |
| 177 | DPOT_DEVICE_SHOW(name, reg) \ | ||
| 178 | DPOT_DEVICE_SET(name, reg) \ | ||
| 179 | static DEVICE_ATTR(name, S_IWUSR | S_IRUGO, show_##name, set_##name); | ||
| 219 | 180 | ||
| 220 | static ssize_t show_eeprom1(struct device *dev, | 181 | #define DPOT_DEVICE_SHOW_ONLY(name, reg) \ |
| 221 | struct device_attribute *attr, char *buf) | 182 | DPOT_DEVICE_SHOW(name, reg) \ |
| 222 | { | 183 | static DEVICE_ATTR(name, S_IWUSR | S_IRUGO, show_##name, NULL); |
| 223 | return sysfs_show_reg(dev, attr, buf, AD525X_I2C_EEPROM | AD525X_RDAC1); | ||
| 224 | } | ||
| 225 | 184 | ||
| 226 | static ssize_t set_eeprom1(struct device *dev, | 185 | DPOT_DEVICE_SHOW_SET(rdac0, AD525X_I2C_RDAC | AD525X_RDAC0); |
| 227 | struct device_attribute *attr, | 186 | DPOT_DEVICE_SHOW_SET(eeprom0, AD525X_I2C_EEPROM | AD525X_RDAC0); |
| 228 | const char *buf, size_t count) | 187 | DPOT_DEVICE_SHOW_ONLY(tolerance0, AD525X_I2C_EEPROM | AD525X_TOL_RDAC0); |
| 229 | { | ||
| 230 | return sysfs_set_reg(dev, attr, buf, count, | ||
| 231 | AD525X_I2C_EEPROM | AD525X_RDAC1); | ||
| 232 | } | ||
| 233 | 188 | ||
| 234 | static DEVICE_ATTR(eeprom1, S_IWUSR | S_IRUGO, show_eeprom1, set_eeprom1); | 189 | DPOT_DEVICE_SHOW_SET(rdac1, AD525X_I2C_RDAC | AD525X_RDAC1); |
| 190 | DPOT_DEVICE_SHOW_SET(eeprom1, AD525X_I2C_EEPROM | AD525X_RDAC1); | ||
| 191 | DPOT_DEVICE_SHOW_ONLY(tolerance1, AD525X_I2C_EEPROM | AD525X_TOL_RDAC1); | ||
| 235 | 192 | ||
| 236 | static ssize_t show_tolerance1(struct device *dev, | 193 | DPOT_DEVICE_SHOW_SET(rdac2, AD525X_I2C_RDAC | AD525X_RDAC2); |
| 237 | struct device_attribute *attr, char *buf) | 194 | DPOT_DEVICE_SHOW_SET(eeprom2, AD525X_I2C_EEPROM | AD525X_RDAC2); |
| 238 | { | 195 | DPOT_DEVICE_SHOW_ONLY(tolerance2, AD525X_I2C_EEPROM | AD525X_TOL_RDAC2); |
| 239 | return sysfs_show_reg(dev, attr, buf, | ||
| 240 | AD525X_I2C_EEPROM | AD525X_TOL_RDAC1); | ||
| 241 | } | ||
| 242 | |||
| 243 | static DEVICE_ATTR(tolerance1, S_IRUGO, show_tolerance1, NULL); | ||
| 244 | 196 | ||
| 245 | /* ------------------------------------------------------------------------- */ | 197 | DPOT_DEVICE_SHOW_SET(rdac3, AD525X_I2C_RDAC | AD525X_RDAC3); |
| 246 | 198 | DPOT_DEVICE_SHOW_SET(eeprom3, AD525X_I2C_EEPROM | AD525X_RDAC3); | |
| 247 | static ssize_t show_rdac2(struct device *dev, | 199 | DPOT_DEVICE_SHOW_ONLY(tolerance3, AD525X_I2C_EEPROM | AD525X_TOL_RDAC3); |
| 248 | struct device_attribute *attr, char *buf) | ||
| 249 | { | ||
| 250 | return sysfs_show_reg(dev, attr, buf, AD525X_I2C_RDAC | AD525X_RDAC2); | ||
| 251 | } | ||
| 252 | |||
| 253 | static ssize_t set_rdac2(struct device *dev, | ||
| 254 | struct device_attribute *attr, | ||
| 255 | const char *buf, size_t count) | ||
| 256 | { | ||
| 257 | return sysfs_set_reg(dev, attr, buf, count, | ||
| 258 | AD525X_I2C_RDAC | AD525X_RDAC2); | ||
| 259 | } | ||
| 260 | |||
| 261 | static DEVICE_ATTR(rdac2, S_IWUSR | S_IRUGO, show_rdac2, set_rdac2); | ||
| 262 | |||
| 263 | static ssize_t show_eeprom2(struct device *dev, | ||
| 264 | struct device_attribute *attr, char *buf) | ||
| 265 | { | ||
| 266 | return sysfs_show_reg(dev, attr, buf, AD525X_I2C_EEPROM | AD525X_RDAC2); | ||
| 267 | } | ||
| 268 | |||
| 269 | static ssize_t set_eeprom2(struct device *dev, | ||
| 270 | struct device_attribute *attr, | ||
| 271 | const char *buf, size_t count) | ||
| 272 | { | ||
| 273 | return sysfs_set_reg(dev, attr, buf, count, | ||
| 274 | AD525X_I2C_EEPROM | AD525X_RDAC2); | ||
| 275 | } | ||
| 276 | |||
| 277 | static DEVICE_ATTR(eeprom2, S_IWUSR | S_IRUGO, show_eeprom2, set_eeprom2); | ||
| 278 | |||
| 279 | static ssize_t show_tolerance2(struct device *dev, | ||
| 280 | struct device_attribute *attr, char *buf) | ||
| 281 | { | ||
| 282 | return sysfs_show_reg(dev, attr, buf, | ||
| 283 | AD525X_I2C_EEPROM | AD525X_TOL_RDAC2); | ||
| 284 | } | ||
| 285 | |||
| 286 | static DEVICE_ATTR(tolerance2, S_IRUGO, show_tolerance2, NULL); | ||
| 287 | |||
| 288 | /* ------------------------------------------------------------------------- */ | ||
| 289 | |||
| 290 | static ssize_t show_rdac3(struct device *dev, | ||
| 291 | struct device_attribute *attr, char *buf) | ||
| 292 | { | ||
| 293 | return sysfs_show_reg(dev, attr, buf, AD525X_I2C_RDAC | AD525X_RDAC3); | ||
| 294 | } | ||
| 295 | |||
| 296 | static ssize_t set_rdac3(struct device *dev, | ||
| 297 | struct device_attribute *attr, | ||
| 298 | const char *buf, size_t count) | ||
| 299 | { | ||
| 300 | return sysfs_set_reg(dev, attr, buf, count, | ||
| 301 | AD525X_I2C_RDAC | AD525X_RDAC3); | ||
| 302 | } | ||
| 303 | |||
| 304 | static DEVICE_ATTR(rdac3, S_IWUSR | S_IRUGO, show_rdac3, set_rdac3); | ||
| 305 | |||
| 306 | static ssize_t show_eeprom3(struct device *dev, | ||
| 307 | struct device_attribute *attr, char *buf) | ||
| 308 | { | ||
| 309 | return sysfs_show_reg(dev, attr, buf, AD525X_I2C_EEPROM | AD525X_RDAC3); | ||
| 310 | } | ||
| 311 | |||
| 312 | static ssize_t set_eeprom3(struct device *dev, | ||
| 313 | struct device_attribute *attr, | ||
| 314 | const char *buf, size_t count) | ||
| 315 | { | ||
| 316 | return sysfs_set_reg(dev, attr, buf, count, | ||
| 317 | AD525X_I2C_EEPROM | AD525X_RDAC3); | ||
| 318 | } | ||
| 319 | |||
| 320 | static DEVICE_ATTR(eeprom3, S_IWUSR | S_IRUGO, show_eeprom3, set_eeprom3); | ||
| 321 | |||
| 322 | static ssize_t show_tolerance3(struct device *dev, | ||
| 323 | struct device_attribute *attr, char *buf) | ||
| 324 | { | ||
| 325 | return sysfs_show_reg(dev, attr, buf, | ||
| 326 | AD525X_I2C_EEPROM | AD525X_TOL_RDAC3); | ||
| 327 | } | ||
| 328 | |||
| 329 | static DEVICE_ATTR(tolerance3, S_IRUGO, show_tolerance3, NULL); | ||
| 330 | 200 | ||
| 331 | static struct attribute *ad525x_attributes_wipers[4][4] = { | 201 | static struct attribute *ad525x_attributes_wipers[4][4] = { |
| 332 | { | 202 | { |
| @@ -361,41 +231,19 @@ static const struct attribute_group ad525x_group_wipers[] = { | |||
| 361 | 231 | ||
| 362 | /* ------------------------------------------------------------------------- */ | 232 | /* ------------------------------------------------------------------------- */ |
| 363 | 233 | ||
| 364 | static ssize_t set_inc_all(struct device *dev, | 234 | #define DPOT_DEVICE_DO_CMD(_name, _cmd) static ssize_t \ |
| 365 | struct device_attribute *attr, | 235 | set_##_name(struct device *dev, \ |
| 366 | const char *buf, size_t count) | 236 | struct device_attribute *attr, \ |
| 367 | { | 237 | const char *buf, size_t count) \ |
| 368 | return sysfs_do_cmd(dev, attr, buf, count, AD525X_INC_ALL); | 238 | { \ |
| 369 | } | 239 | return sysfs_do_cmd(dev, attr, buf, count, _cmd); \ |
| 370 | 240 | } \ | |
| 371 | static DEVICE_ATTR(inc_all, S_IWUSR, NULL, set_inc_all); | 241 | static DEVICE_ATTR(_name, S_IWUSR | S_IRUGO, NULL, set_##_name); |
| 372 | 242 | ||
| 373 | static ssize_t set_dec_all(struct device *dev, | 243 | DPOT_DEVICE_DO_CMD(inc_all, AD525X_INC_ALL); |
| 374 | struct device_attribute *attr, | 244 | DPOT_DEVICE_DO_CMD(dec_all, AD525X_DEC_ALL); |
| 375 | const char *buf, size_t count) | 245 | DPOT_DEVICE_DO_CMD(inc_all_6db, AD525X_INC_ALL_6DB); |
| 376 | { | 246 | DPOT_DEVICE_DO_CMD(dec_all_6db, AD525X_DEC_ALL_6DB); |
| 377 | return sysfs_do_cmd(dev, attr, buf, count, AD525X_DEC_ALL); | ||
| 378 | } | ||
| 379 | |||
| 380 | static DEVICE_ATTR(dec_all, S_IWUSR, NULL, set_dec_all); | ||
| 381 | |||
| 382 | static ssize_t set_inc_all_6db(struct device *dev, | ||
| 383 | struct device_attribute *attr, | ||
| 384 | const char *buf, size_t count) | ||
| 385 | { | ||
| 386 | return sysfs_do_cmd(dev, attr, buf, count, AD525X_INC_ALL_6DB); | ||
| 387 | } | ||
| 388 | |||
| 389 | static DEVICE_ATTR(inc_all_6db, S_IWUSR, NULL, set_inc_all_6db); | ||
| 390 | |||
| 391 | static ssize_t set_dec_all_6db(struct device *dev, | ||
| 392 | struct device_attribute *attr, | ||
| 393 | const char *buf, size_t count) | ||
| 394 | { | ||
| 395 | return sysfs_do_cmd(dev, attr, buf, count, AD525X_DEC_ALL_6DB); | ||
| 396 | } | ||
| 397 | |||
| 398 | static DEVICE_ATTR(dec_all_6db, S_IWUSR, NULL, set_dec_all_6db); | ||
| 399 | 247 | ||
| 400 | static struct attribute *ad525x_attributes_commands[] = { | 248 | static struct attribute *ad525x_attributes_commands[] = { |
| 401 | &dev_attr_inc_all.attr, | 249 | &dev_attr_inc_all.attr, |
