blob: 808b4f8675c5609ccd195deb755c40233ddf3059 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * File Attributes for Zorro Devices
3 *
4 * Copyright (C) 2003 Geert Uytterhoeven
5 *
6 * Loosely based on drivers/pci/pci-sysfs.c
7 *
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
10 * for more details.
11 */
12
13
14#include <linux/kernel.h>
15#include <linux/zorro.h>
16#include <linux/stat.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080017#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#include "zorro.h"
20
21
22/* show configuration fields */
23#define zorro_config_attr(name, field, format_string) \
24static ssize_t \
Yani Ioannou060b8842005-05-17 06:44:04 -040025show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{ \
27 struct zorro_dev *z; \
28 \
29 z = to_zorro_dev(dev); \
30 return sprintf(buf, format_string, z->field); \
31} \
32static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
33
34zorro_config_attr(id, id, "0x%08x\n");
35zorro_config_attr(type, rom.er_Type, "0x%02x\n");
36zorro_config_attr(serial, rom.er_SerialNumber, "0x%08x\n");
37zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
38zorro_config_attr(slotsize, slotsize, "0x%04x\n");
39
Yani Ioannou060b8842005-05-17 06:44:04 -040040static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
42 struct zorro_dev *z = to_zorro_dev(dev);
43
44 return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
Geert Uytterhoeven31817572007-05-01 22:33:04 +020045 (unsigned long)zorro_resource_start(z),
46 (unsigned long)zorro_resource_end(z),
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 zorro_resource_flags(z));
48}
49
50static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL);
51
Zhang Rui91a69022007-06-09 13:57:22 +080052static ssize_t zorro_read_config(struct kobject *kobj,
53 struct bin_attribute *bin_attr,
54 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device,
57 kobj));
58 struct ConfigDev cd;
59 unsigned int size = sizeof(cd);
60
61 if (off > size)
62 return 0;
63 if (off+count > size)
64 count = size-off;
65
66 /* Construct a ConfigDev */
67 memset(&cd, 0, sizeof(cd));
68 cd.cd_Rom = z->rom;
69 cd.cd_SlotAddr = z->slotaddr;
70 cd.cd_SlotSize = z->slotsize;
71 cd.cd_BoardAddr = (void *)zorro_resource_start(z);
72 cd.cd_BoardSize = zorro_resource_len(z);
73
74 memcpy(buf, (void *)&cd+off, count);
75 return count;
76}
77
78static struct bin_attribute zorro_config_attr = {
79 .attr = {
80 .name = "config",
Geert Uytterhoevena0108662007-08-22 14:01:34 -070081 .mode = S_IRUGO,
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 },
83 .size = sizeof(struct ConfigDev),
84 .read = zorro_read_config,
85};
86
87void zorro_create_sysfs_dev_files(struct zorro_dev *z)
88{
89 struct device *dev = &z->dev;
90
91 /* current configuration's attributes */
92 device_create_file(dev, &dev_attr_id);
93 device_create_file(dev, &dev_attr_type);
94 device_create_file(dev, &dev_attr_serial);
95 device_create_file(dev, &dev_attr_slotaddr);
96 device_create_file(dev, &dev_attr_slotsize);
97 device_create_file(dev, &dev_attr_resource);
98 sysfs_create_bin_file(&dev->kobj, &zorro_config_attr);
99}
100