blob: 3da712cc7708c43986765f13e2b51880ba7aca39 [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>
akinobu.mita@gmail.comfa7f2892008-07-17 21:16:17 +020018#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include "zorro.h"
21
22
23/* show configuration fields */
24#define zorro_config_attr(name, field, format_string) \
25static ssize_t \
Yani Ioannou060b8842005-05-17 06:44:04 -040026show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{ \
28 struct zorro_dev *z; \
29 \
30 z = to_zorro_dev(dev); \
31 return sprintf(buf, format_string, z->field); \
32} \
33static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
34
35zorro_config_attr(id, id, "0x%08x\n");
36zorro_config_attr(type, rom.er_Type, "0x%02x\n");
37zorro_config_attr(serial, rom.er_SerialNumber, "0x%08x\n");
38zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
39zorro_config_attr(slotsize, slotsize, "0x%04x\n");
40
Yani Ioannou060b8842005-05-17 06:44:04 -040041static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
43 struct zorro_dev *z = to_zorro_dev(dev);
44
45 return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
Geert Uytterhoeven31817572007-05-01 22:33:04 +020046 (unsigned long)zorro_resource_start(z),
47 (unsigned long)zorro_resource_end(z),
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 zorro_resource_flags(z));
49}
50
51static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL);
52
Zhang Rui91a69022007-06-09 13:57:22 +080053static ssize_t zorro_read_config(struct kobject *kobj,
54 struct bin_attribute *bin_attr,
55 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
57 struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device,
58 kobj));
59 struct ConfigDev cd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 /* Construct a ConfigDev */
62 memset(&cd, 0, sizeof(cd));
63 cd.cd_Rom = z->rom;
64 cd.cd_SlotAddr = z->slotaddr;
65 cd.cd_SlotSize = z->slotsize;
66 cd.cd_BoardAddr = (void *)zorro_resource_start(z);
67 cd.cd_BoardSize = zorro_resource_len(z);
68
akinobu.mita@gmail.comfa7f2892008-07-17 21:16:17 +020069 return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
71
72static struct bin_attribute zorro_config_attr = {
73 .attr = {
74 .name = "config",
Geert Uytterhoevena0108662007-08-22 14:01:34 -070075 .mode = S_IRUGO,
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 },
77 .size = sizeof(struct ConfigDev),
78 .read = zorro_read_config,
79};
80
81void zorro_create_sysfs_dev_files(struct zorro_dev *z)
82{
83 struct device *dev = &z->dev;
84
85 /* current configuration's attributes */
86 device_create_file(dev, &dev_attr_id);
87 device_create_file(dev, &dev_attr_type);
88 device_create_file(dev, &dev_attr_serial);
89 device_create_file(dev, &dev_attr_slotaddr);
90 device_create_file(dev, &dev_attr_slotsize);
91 device_create_file(dev, &dev_attr_resource);
92 sysfs_create_bin_file(&dev->kobj, &zorro_config_attr);
93}
94