aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/c2port/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/c2port/core.c')
-rw-r--r--drivers/misc/c2port/core.c83
1 files changed, 45 insertions, 38 deletions
diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
index f32550a74bdd..464419b36440 100644
--- a/drivers/misc/c2port/core.c
+++ b/drivers/misc/c2port/core.c
@@ -311,6 +311,7 @@ static ssize_t c2port_show_name(struct device *dev,
311 311
312 return sprintf(buf, "%s\n", c2dev->name); 312 return sprintf(buf, "%s\n", c2dev->name);
313} 313}
314static DEVICE_ATTR(name, 0444, c2port_show_name, NULL);
314 315
315static ssize_t c2port_show_flash_blocks_num(struct device *dev, 316static ssize_t c2port_show_flash_blocks_num(struct device *dev,
316 struct device_attribute *attr, char *buf) 317 struct device_attribute *attr, char *buf)
@@ -320,6 +321,7 @@ static ssize_t c2port_show_flash_blocks_num(struct device *dev,
320 321
321 return sprintf(buf, "%d\n", ops->blocks_num); 322 return sprintf(buf, "%d\n", ops->blocks_num);
322} 323}
324static DEVICE_ATTR(flash_blocks_num, 0444, c2port_show_flash_blocks_num, NULL);
323 325
324static ssize_t c2port_show_flash_block_size(struct device *dev, 326static ssize_t c2port_show_flash_block_size(struct device *dev,
325 struct device_attribute *attr, char *buf) 327 struct device_attribute *attr, char *buf)
@@ -329,6 +331,7 @@ static ssize_t c2port_show_flash_block_size(struct device *dev,
329 331
330 return sprintf(buf, "%d\n", ops->block_size); 332 return sprintf(buf, "%d\n", ops->block_size);
331} 333}
334static DEVICE_ATTR(flash_block_size, 0444, c2port_show_flash_block_size, NULL);
332 335
333static ssize_t c2port_show_flash_size(struct device *dev, 336static ssize_t c2port_show_flash_size(struct device *dev,
334 struct device_attribute *attr, char *buf) 337 struct device_attribute *attr, char *buf)
@@ -338,18 +341,18 @@ static ssize_t c2port_show_flash_size(struct device *dev,
338 341
339 return sprintf(buf, "%d\n", ops->blocks_num * ops->block_size); 342 return sprintf(buf, "%d\n", ops->blocks_num * ops->block_size);
340} 343}
344static DEVICE_ATTR(flash_size, 0444, c2port_show_flash_size, NULL);
341 345
342static ssize_t c2port_show_access(struct device *dev, 346static ssize_t access_show(struct device *dev, struct device_attribute *attr,
343 struct device_attribute *attr, char *buf) 347 char *buf)
344{ 348{
345 struct c2port_device *c2dev = dev_get_drvdata(dev); 349 struct c2port_device *c2dev = dev_get_drvdata(dev);
346 350
347 return sprintf(buf, "%d\n", c2dev->access); 351 return sprintf(buf, "%d\n", c2dev->access);
348} 352}
349 353
350static ssize_t c2port_store_access(struct device *dev, 354static ssize_t access_store(struct device *dev, struct device_attribute *attr,
351 struct device_attribute *attr, 355 const char *buf, size_t count)
352 const char *buf, size_t count)
353{ 356{
354 struct c2port_device *c2dev = dev_get_drvdata(dev); 357 struct c2port_device *c2dev = dev_get_drvdata(dev);
355 struct c2port_ops *ops = c2dev->ops; 358 struct c2port_ops *ops = c2dev->ops;
@@ -375,6 +378,7 @@ static ssize_t c2port_store_access(struct device *dev,
375 378
376 return count; 379 return count;
377} 380}
381static DEVICE_ATTR_RW(access);
378 382
379static ssize_t c2port_store_reset(struct device *dev, 383static ssize_t c2port_store_reset(struct device *dev,
380 struct device_attribute *attr, 384 struct device_attribute *attr,
@@ -395,6 +399,7 @@ static ssize_t c2port_store_reset(struct device *dev,
395 399
396 return count; 400 return count;
397} 401}
402static DEVICE_ATTR(reset, 0200, NULL, c2port_store_reset);
398 403
399static ssize_t __c2port_show_dev_id(struct c2port_device *dev, char *buf) 404static ssize_t __c2port_show_dev_id(struct c2port_device *dev, char *buf)
400{ 405{
@@ -431,6 +436,7 @@ static ssize_t c2port_show_dev_id(struct device *dev,
431 436
432 return ret; 437 return ret;
433} 438}
439static DEVICE_ATTR(dev_id, 0444, c2port_show_dev_id, NULL);
434 440
435static ssize_t __c2port_show_rev_id(struct c2port_device *dev, char *buf) 441static ssize_t __c2port_show_rev_id(struct c2port_device *dev, char *buf)
436{ 442{
@@ -467,6 +473,7 @@ static ssize_t c2port_show_rev_id(struct device *dev,
467 473
468 return ret; 474 return ret;
469} 475}
476static DEVICE_ATTR(rev_id, 0444, c2port_show_rev_id, NULL);
470 477
471static ssize_t c2port_show_flash_access(struct device *dev, 478static ssize_t c2port_show_flash_access(struct device *dev,
472 struct device_attribute *attr, char *buf) 479 struct device_attribute *attr, char *buf)
@@ -536,6 +543,8 @@ static ssize_t c2port_store_flash_access(struct device *dev,
536 543
537 return count; 544 return count;
538} 545}
546static DEVICE_ATTR(flash_access, 0644, c2port_show_flash_access,
547 c2port_store_flash_access);
539 548
540static ssize_t __c2port_write_flash_erase(struct c2port_device *dev) 549static ssize_t __c2port_write_flash_erase(struct c2port_device *dev)
541{ 550{
@@ -616,6 +625,7 @@ static ssize_t c2port_store_flash_erase(struct device *dev,
616 625
617 return count; 626 return count;
618} 627}
628static DEVICE_ATTR(flash_erase, 0200, NULL, c2port_store_flash_erase);
619 629
620static ssize_t __c2port_read_flash_data(struct c2port_device *dev, 630static ssize_t __c2port_read_flash_data(struct c2port_device *dev,
621 char *buffer, loff_t offset, size_t count) 631 char *buffer, loff_t offset, size_t count)
@@ -846,35 +856,40 @@ static ssize_t c2port_write_flash_data(struct file *filp, struct kobject *kobj,
846 856
847 return ret; 857 return ret;
848} 858}
859/* size is computed at run-time */
860static BIN_ATTR(flash_data, 0644, c2port_read_flash_data,
861 c2port_write_flash_data, 0);
849 862
850/* 863/*
851 * Class attributes 864 * Class attributes
852 */ 865 */
866static struct attribute *c2port_attrs[] = {
867 &dev_attr_name.attr,
868 &dev_attr_flash_blocks_num.attr,
869 &dev_attr_flash_block_size.attr,
870 &dev_attr_flash_size.attr,
871 &dev_attr_access.attr,
872 &dev_attr_reset.attr,
873 &dev_attr_dev_id.attr,
874 &dev_attr_rev_id.attr,
875 &dev_attr_flash_access.attr,
876 &dev_attr_flash_erase.attr,
877 NULL,
878};
853 879
854static struct device_attribute c2port_attrs[] = { 880static struct bin_attribute *c2port_bin_attrs[] = {
855 __ATTR(name, 0444, c2port_show_name, NULL), 881 &bin_attr_flash_data,
856 __ATTR(flash_blocks_num, 0444, c2port_show_flash_blocks_num, NULL), 882 NULL,
857 __ATTR(flash_block_size, 0444, c2port_show_flash_block_size, NULL),
858 __ATTR(flash_size, 0444, c2port_show_flash_size, NULL),
859 __ATTR(access, 0644, c2port_show_access, c2port_store_access),
860 __ATTR(reset, 0200, NULL, c2port_store_reset),
861 __ATTR(dev_id, 0444, c2port_show_dev_id, NULL),
862 __ATTR(rev_id, 0444, c2port_show_rev_id, NULL),
863
864 __ATTR(flash_access, 0644, c2port_show_flash_access,
865 c2port_store_flash_access),
866 __ATTR(flash_erase, 0200, NULL, c2port_store_flash_erase),
867 __ATTR_NULL,
868}; 883};
869 884
870static struct bin_attribute c2port_bin_attrs = { 885static const struct attribute_group c2port_group = {
871 .attr = { 886 .attrs = c2port_attrs,
872 .name = "flash_data", 887 .bin_attrs = c2port_bin_attrs,
873 .mode = 0644 888};
874 }, 889
875 .read = c2port_read_flash_data, 890static const struct attribute_group *c2port_groups[] = {
876 .write = c2port_write_flash_data, 891 &c2port_group,
877 /* .size is computed at run-time */ 892 NULL,
878}; 893};
879 894
880/* 895/*
@@ -907,6 +922,8 @@ struct c2port_device *c2port_device_register(char *name,
907 goto error_idr_alloc; 922 goto error_idr_alloc;
908 c2dev->id = ret; 923 c2dev->id = ret;
909 924
925 bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
926
910 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev, 927 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
911 "c2port%d", c2dev->id); 928 "c2port%d", c2dev->id);
912 if (unlikely(IS_ERR(c2dev->dev))) { 929 if (unlikely(IS_ERR(c2dev->dev))) {
@@ -919,12 +936,6 @@ struct c2port_device *c2port_device_register(char *name,
919 c2dev->ops = ops; 936 c2dev->ops = ops;
920 mutex_init(&c2dev->mutex); 937 mutex_init(&c2dev->mutex);
921 938
922 /* Create binary file */
923 c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
924 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
925 if (unlikely(ret))
926 goto error_device_create_bin_file;
927
928 /* By default C2 port access is off */ 939 /* By default C2 port access is off */
929 c2dev->access = c2dev->flash_access = 0; 940 c2dev->access = c2dev->flash_access = 0;
930 ops->access(c2dev, 0); 941 ops->access(c2dev, 0);
@@ -937,9 +948,6 @@ struct c2port_device *c2port_device_register(char *name,
937 948
938 return c2dev; 949 return c2dev;
939 950
940error_device_create_bin_file:
941 device_destroy(c2port_class, 0);
942
943error_device_create: 951error_device_create:
944 spin_lock_irq(&c2port_idr_lock); 952 spin_lock_irq(&c2port_idr_lock);
945 idr_remove(&c2port_idr, c2dev->id); 953 idr_remove(&c2port_idr, c2dev->id);
@@ -959,7 +967,6 @@ void c2port_device_unregister(struct c2port_device *c2dev)
959 967
960 dev_info(c2dev->dev, "C2 port %s removed\n", c2dev->name); 968 dev_info(c2dev->dev, "C2 port %s removed\n", c2dev->name);
961 969
962 device_remove_bin_file(c2dev->dev, &c2port_bin_attrs);
963 spin_lock_irq(&c2port_idr_lock); 970 spin_lock_irq(&c2port_idr_lock);
964 idr_remove(&c2port_idr, c2dev->id); 971 idr_remove(&c2port_idr, c2dev->id);
965 spin_unlock_irq(&c2port_idr_lock); 972 spin_unlock_irq(&c2port_idr_lock);
@@ -984,7 +991,7 @@ static int __init c2port_init(void)
984 printk(KERN_ERR "c2port: failed to allocate class\n"); 991 printk(KERN_ERR "c2port: failed to allocate class\n");
985 return PTR_ERR(c2port_class); 992 return PTR_ERR(c2port_class);
986 } 993 }
987 c2port_class->dev_attrs = c2port_attrs; 994 c2port_class->dev_groups = c2port_groups;
988 995
989 return 0; 996 return 0;
990} 997}