aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/slaves/w1_ds28e04.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/w1/slaves/w1_ds28e04.c')
-rw-r--r--drivers/w1/slaves/w1_ds28e04.c112
1 files changed, 42 insertions, 70 deletions
diff --git a/drivers/w1/slaves/w1_ds28e04.c b/drivers/w1/slaves/w1_ds28e04.c
index cd30a6d95ea5..365d6dff21de 100644
--- a/drivers/w1/slaves/w1_ds28e04.c
+++ b/drivers/w1/slaves/w1_ds28e04.c
@@ -118,9 +118,9 @@ static int w1_f1C_read(struct w1_slave *sl, int addr, int len, char *data)
118 return w1_read_block(sl->master, data, len); 118 return w1_read_block(sl->master, data, len);
119} 119}
120 120
121static ssize_t w1_f1C_read_bin(struct file *filp, struct kobject *kobj, 121static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
122 struct bin_attribute *bin_attr, 122 struct bin_attribute *bin_attr, char *buf,
123 char *buf, loff_t off, size_t count) 123 loff_t off, size_t count)
124{ 124{
125 struct w1_slave *sl = kobj_to_w1_slave(kobj); 125 struct w1_slave *sl = kobj_to_w1_slave(kobj);
126 struct w1_f1C_data *data = sl->family_data; 126 struct w1_f1C_data *data = sl->family_data;
@@ -226,9 +226,9 @@ static int w1_f1C_write(struct w1_slave *sl, int addr, int len, const u8 *data)
226 return 0; 226 return 0;
227} 227}
228 228
229static ssize_t w1_f1C_write_bin(struct file *filp, struct kobject *kobj, 229static ssize_t eeprom_write(struct file *filp, struct kobject *kobj,
230 struct bin_attribute *bin_attr, 230 struct bin_attribute *bin_attr, char *buf,
231 char *buf, loff_t off, size_t count) 231 loff_t off, size_t count)
232 232
233{ 233{
234 struct w1_slave *sl = kobj_to_w1_slave(kobj); 234 struct w1_slave *sl = kobj_to_w1_slave(kobj);
@@ -280,9 +280,11 @@ out_up:
280 return count; 280 return count;
281} 281}
282 282
283static ssize_t w1_f1C_read_pio(struct file *filp, struct kobject *kobj, 283static BIN_ATTR_RW(eeprom, W1_EEPROM_SIZE);
284 struct bin_attribute *bin_attr, 284
285 char *buf, loff_t off, size_t count) 285static ssize_t pio_read(struct file *filp, struct kobject *kobj,
286 struct bin_attribute *bin_attr, char *buf, loff_t off,
287 size_t count)
286 288
287{ 289{
288 struct w1_slave *sl = kobj_to_w1_slave(kobj); 290 struct w1_slave *sl = kobj_to_w1_slave(kobj);
@@ -299,9 +301,9 @@ static ssize_t w1_f1C_read_pio(struct file *filp, struct kobject *kobj,
299 return ret; 301 return ret;
300} 302}
301 303
302static ssize_t w1_f1C_write_pio(struct file *filp, struct kobject *kobj, 304static ssize_t pio_write(struct file *filp, struct kobject *kobj,
303 struct bin_attribute *bin_attr, 305 struct bin_attribute *bin_attr, char *buf, loff_t off,
304 char *buf, loff_t off, size_t count) 306 size_t count)
305 307
306{ 308{
307 struct w1_slave *sl = kobj_to_w1_slave(kobj); 309 struct w1_slave *sl = kobj_to_w1_slave(kobj);
@@ -339,8 +341,10 @@ static ssize_t w1_f1C_write_pio(struct file *filp, struct kobject *kobj,
339 return count; 341 return count;
340} 342}
341 343
342static ssize_t w1_f1C_show_crccheck(struct device *dev, 344static BIN_ATTR_RW(pio, 1);
343 struct device_attribute *attr, char *buf) 345
346static ssize_t crccheck_show(struct device *dev, struct device_attribute *attr,
347 char *buf)
344{ 348{
345 if (put_user(w1_enable_crccheck + 0x30, buf)) 349 if (put_user(w1_enable_crccheck + 0x30, buf))
346 return -EFAULT; 350 return -EFAULT;
@@ -348,9 +352,8 @@ static ssize_t w1_f1C_show_crccheck(struct device *dev,
348 return sizeof(w1_enable_crccheck); 352 return sizeof(w1_enable_crccheck);
349} 353}
350 354
351static ssize_t w1_f1C_store_crccheck(struct device *dev, 355static ssize_t crccheck_store(struct device *dev, struct device_attribute *attr,
352 struct device_attribute *attr, 356 const char *buf, size_t count)
353 const char *buf, size_t count)
354{ 357{
355 char val; 358 char val;
356 359
@@ -371,35 +374,31 @@ static ssize_t w1_f1C_store_crccheck(struct device *dev,
371 return sizeof(w1_enable_crccheck); 374 return sizeof(w1_enable_crccheck);
372} 375}
373 376
374#define NB_SYSFS_BIN_FILES 2 377static DEVICE_ATTR_RW(crccheck);
375static struct bin_attribute w1_f1C_bin_attr[NB_SYSFS_BIN_FILES] = { 378
376 { 379static struct attribute *w1_f1C_attrs[] = {
377 .attr = { 380 &dev_attr_crccheck.attr,
378 .name = "eeprom", 381 NULL,
379 .mode = S_IRUGO | S_IWUSR,
380 },
381 .size = W1_EEPROM_SIZE,
382 .read = w1_f1C_read_bin,
383 .write = w1_f1C_write_bin,
384 },
385 {
386 .attr = {
387 .name = "pio",
388 .mode = S_IRUGO | S_IWUSR,
389 },
390 .size = 1,
391 .read = w1_f1C_read_pio,
392 .write = w1_f1C_write_pio,
393 }
394}; 382};
395 383
396static DEVICE_ATTR(crccheck, S_IWUSR | S_IRUGO, 384static struct bin_attribute *w1_f1C_bin_attrs[] = {
397 w1_f1C_show_crccheck, w1_f1C_store_crccheck); 385 &bin_attr_eeprom,
386 &bin_attr_pio,
387 NULL,
388};
389
390static const struct attribute_group w1_f1C_group = {
391 .attrs = w1_f1C_attrs,
392 .bin_attrs = w1_f1C_bin_attrs,
393};
394
395static const struct attribute_group *w1_f1C_groups[] = {
396 &w1_f1C_group,
397 NULL,
398};
398 399
399static int w1_f1C_add_slave(struct w1_slave *sl) 400static int w1_f1C_add_slave(struct w1_slave *sl)
400{ 401{
401 int err = 0;
402 int i;
403 struct w1_f1C_data *data = NULL; 402 struct w1_f1C_data *data = NULL;
404 403
405 if (w1_enable_crccheck) { 404 if (w1_enable_crccheck) {
@@ -409,46 +408,19 @@ static int w1_f1C_add_slave(struct w1_slave *sl)
409 sl->family_data = data; 408 sl->family_data = data;
410 } 409 }
411 410
412 /* create binary sysfs attributes */ 411 return 0;
413 for (i = 0; i < NB_SYSFS_BIN_FILES && !err; ++i)
414 err = sysfs_create_bin_file(
415 &sl->dev.kobj, &(w1_f1C_bin_attr[i]));
416
417 if (!err) {
418 /* create device attributes */
419 err = device_create_file(&sl->dev, &dev_attr_crccheck);
420 }
421
422 if (err) {
423 /* remove binary sysfs attributes */
424 for (i = 0; i < NB_SYSFS_BIN_FILES; ++i)
425 sysfs_remove_bin_file(
426 &sl->dev.kobj, &(w1_f1C_bin_attr[i]));
427
428 kfree(data);
429 }
430
431 return err;
432} 412}
433 413
434static void w1_f1C_remove_slave(struct w1_slave *sl) 414static void w1_f1C_remove_slave(struct w1_slave *sl)
435{ 415{
436 int i;
437
438 kfree(sl->family_data); 416 kfree(sl->family_data);
439 sl->family_data = NULL; 417 sl->family_data = NULL;
440
441 /* remove device attributes */
442 device_remove_file(&sl->dev, &dev_attr_crccheck);
443
444 /* remove binary sysfs attributes */
445 for (i = 0; i < NB_SYSFS_BIN_FILES; ++i)
446 sysfs_remove_bin_file(&sl->dev.kobj, &(w1_f1C_bin_attr[i]));
447} 418}
448 419
449static struct w1_family_ops w1_f1C_fops = { 420static struct w1_family_ops w1_f1C_fops = {
450 .add_slave = w1_f1C_add_slave, 421 .add_slave = w1_f1C_add_slave,
451 .remove_slave = w1_f1C_remove_slave, 422 .remove_slave = w1_f1C_remove_slave,
423 .groups = w1_f1C_groups,
452}; 424};
453 425
454static struct w1_family w1_family_1C = { 426static struct w1_family w1_family_1C = {