Merge branch 'linus' into x86/x2apic
[deliverable/linux.git] / drivers / zorro / zorro-sysfs.c
CommitLineData
1da177e4
LT
1/*
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>
4e57b681 17#include <linux/string.h>
fa7f2893 18#include <linux/fs.h>
1da177e4
LT
19
20#include "zorro.h"
21
22
23/* show configuration fields */
24#define zorro_config_attr(name, field, format_string) \
25static ssize_t \
060b8845 26show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
27{ \
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
060b8845 41static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
42{
43 struct zorro_dev *z = to_zorro_dev(dev);
44
45 return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
31817576
GU
46 (unsigned long)zorro_resource_start(z),
47 (unsigned long)zorro_resource_end(z),
1da177e4
LT
48 zorro_resource_flags(z));
49}
50
51static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL);
52
91a69029
ZR
53static ssize_t zorro_read_config(struct kobject *kobj,
54 struct bin_attribute *bin_attr,
55 char *buf, loff_t off, size_t count)
1da177e4
LT
56{
57 struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device,
58 kobj));
59 struct ConfigDev cd;
1da177e4
LT
60
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
fa7f2893 69 return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
1da177e4
LT
70}
71
72static struct bin_attribute zorro_config_attr = {
73 .attr = {
74 .name = "config",
a0108668 75 .mode = S_IRUGO,
1da177e4
LT
76 },
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
This page took 0.466433 seconds and 5 git commands to generate.