2 * File Attributes for Zorro Devices
4 * Copyright (C) 2003 Geert Uytterhoeven
6 * Loosely based on drivers/pci/pci-sysfs.c
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive
14 #include <linux/kernel.h>
15 #include <linux/zorro.h>
16 #include <linux/stat.h>
21 /* show configuration fields */
22 #define zorro_config_attr(name, field, format_string) \
24 show_##name(struct device *dev, char *buf) \
26 struct zorro_dev *z; \
28 z = to_zorro_dev(dev); \
29 return sprintf(buf, format_string, z->field); \
31 static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
33 zorro_config_attr(id
, id
, "0x%08x\n");
34 zorro_config_attr(type
, rom
.er_Type
, "0x%02x\n");
35 zorro_config_attr(serial
, rom
.er_SerialNumber
, "0x%08x\n");
36 zorro_config_attr(slotaddr
, slotaddr
, "0x%04x\n");
37 zorro_config_attr(slotsize
, slotsize
, "0x%04x\n");
39 static ssize_t
zorro_show_resource(struct device
*dev
, char *buf
)
41 struct zorro_dev
*z
= to_zorro_dev(dev
);
43 return sprintf(buf
, "0x%08lx 0x%08lx 0x%08lx\n",
44 zorro_resource_start(z
), zorro_resource_end(z
),
45 zorro_resource_flags(z
));
48 static DEVICE_ATTR(resource
, S_IRUGO
, zorro_show_resource
, NULL
);
50 static ssize_t
zorro_read_config(struct kobject
*kobj
, char *buf
, loff_t off
,
53 struct zorro_dev
*z
= to_zorro_dev(container_of(kobj
, struct device
,
56 unsigned int size
= sizeof(cd
);
63 /* Construct a ConfigDev */
64 memset(&cd
, 0, sizeof(cd
));
66 cd
.cd_SlotAddr
= z
->slotaddr
;
67 cd
.cd_SlotSize
= z
->slotsize
;
68 cd
.cd_BoardAddr
= (void *)zorro_resource_start(z
);
69 cd
.cd_BoardSize
= zorro_resource_len(z
);
71 memcpy(buf
, (void *)&cd
+off
, count
);
75 static struct bin_attribute zorro_config_attr
= {
78 .mode
= S_IRUGO
| S_IWUSR
,
81 .size
= sizeof(struct ConfigDev
),
82 .read
= zorro_read_config
,
85 void zorro_create_sysfs_dev_files(struct zorro_dev
*z
)
87 struct device
*dev
= &z
->dev
;
89 /* current configuration's attributes */
90 device_create_file(dev
, &dev_attr_id
);
91 device_create_file(dev
, &dev_attr_type
);
92 device_create_file(dev
, &dev_attr_serial
);
93 device_create_file(dev
, &dev_attr_slotaddr
);
94 device_create_file(dev
, &dev_attr_slotsize
);
95 device_create_file(dev
, &dev_attr_resource
);
96 sysfs_create_bin_file(&dev
->kobj
, &zorro_config_attr
);