Blame view

drivers/zorro/zorro-sysfs.c 3.08 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  /*
   *  File Attributes for Zorro Devices
   *
   *  Copyright (C) 2003 Geert Uytterhoeven
   *
   *  Loosely based on drivers/pci/pci-sysfs.c
   *
   *  This file is subject to the terms and conditions of the GNU General Public
   *  License.  See the file COPYING in the main directory of this archive
   *  for more details.
   */
  
  
  #include <linux/kernel.h>
  #include <linux/zorro.h>
  #include <linux/stat.h>
4e57b6817   Tim Schmielau   [PATCH] fix missi...
17
  #include <linux/string.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
19
20
21
22
23
24
  
  #include "zorro.h"
  
  
  /* show configuration fields */
  #define zorro_config_attr(name, field, format_string)			\
  static ssize_t								\
060b8845e   Yani Ioannou   [PATCH] Driver Co...
25
  show_##name(struct device *dev, struct device_attribute *attr, char *buf)				\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  {									\
  	struct zorro_dev *z;						\
  									\
  	z = to_zorro_dev(dev);						\
  	return sprintf(buf, format_string, z->field);			\
  }									\
  static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
  
  zorro_config_attr(id, id, "0x%08x
  ");
  zorro_config_attr(type, rom.er_Type, "0x%02x
  ");
  zorro_config_attr(serial, rom.er_SerialNumber, "0x%08x
  ");
  zorro_config_attr(slotaddr, slotaddr, "0x%04x
  ");
  zorro_config_attr(slotsize, slotsize, "0x%04x
  ");
060b8845e   Yani Ioannou   [PATCH] Driver Co...
44
  static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
46
47
48
49
  {
  	struct zorro_dev *z = to_zorro_dev(dev);
  
  	return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx
  ",
318175766   Geert Uytterhoeven   Amiga Zorro bus: ...
50
51
  		       (unsigned long)zorro_resource_start(z),
  		       (unsigned long)zorro_resource_end(z),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
53
54
55
  		       zorro_resource_flags(z));
  }
  
  static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL);
2c3c8bea6   Chris Wright   sysfs: add struct...
56
  static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj,
91a690295   Zhang Rui   sysfs: add parame...
57
58
  				 struct bin_attribute *bin_attr,
  				 char *buf, loff_t off, size_t count)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
60
61
62
  {
  	struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device,
  					   kobj));
  	struct ConfigDev cd;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
64
65
66
67
68
69
70
  
  	/* Construct a ConfigDev */
  	memset(&cd, 0, sizeof(cd));
  	cd.cd_Rom = z->rom;
  	cd.cd_SlotAddr = z->slotaddr;
  	cd.cd_SlotSize = z->slotsize;
  	cd.cd_BoardAddr = (void *)zorro_resource_start(z);
  	cd.cd_BoardSize = zorro_resource_len(z);
fa7f28939   akinobu.mita@gmail.com   zorro: use memory...
71
  	return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
73
74
75
76
  }
  
  static struct bin_attribute zorro_config_attr = {
  	.attr =	{
  		.name = "config",
a01086687   Geert Uytterhoeven   zorro: Make sysfs...
77
  		.mode = S_IRUGO,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
79
80
81
  	},
  	.size = sizeof(struct ConfigDev),
  	.read = zorro_read_config,
  };
bf54a2b3c   Geert Uytterhoeven   m68k: amiga - Zor...
82
83
84
85
86
87
88
89
90
91
  static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
  			     char *buf)
  {
  	struct zorro_dev *z = to_zorro_dev(dev);
  
  	return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "
  ", z->id);
  }
  
  static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL);
11a8b2c5c   Geert Uytterhoeven   m68k: zorro - Kil...
92
  int zorro_create_sysfs_dev_files(struct zorro_dev *z)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
93
94
  {
  	struct device *dev = &z->dev;
11a8b2c5c   Geert Uytterhoeven   m68k: zorro - Kil...
95
  	int error;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
97
  
  	/* current configuration's attributes */
11a8b2c5c   Geert Uytterhoeven   m68k: zorro - Kil...
98
99
100
101
102
103
  	if ((error = device_create_file(dev, &dev_attr_id)) ||
  	    (error = device_create_file(dev, &dev_attr_type)) ||
  	    (error = device_create_file(dev, &dev_attr_serial)) ||
  	    (error = device_create_file(dev, &dev_attr_slotaddr)) ||
  	    (error = device_create_file(dev, &dev_attr_slotsize)) ||
  	    (error = device_create_file(dev, &dev_attr_resource)) ||
bf54a2b3c   Geert Uytterhoeven   m68k: amiga - Zor...
104
  	    (error = device_create_file(dev, &dev_attr_modalias)) ||
11a8b2c5c   Geert Uytterhoeven   m68k: zorro - Kil...
105
106
107
108
  	    (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr)))
  		return error;
  
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
  }