Merge branches 'acpi-soc', 'acpi-misc', 'acpi-pci' and 'device-properties'
[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>
1da177e4 18
bd9ba8f4
GU
19#include <asm/byteorder.h>
20
1da177e4
LT
21#include "zorro.h"
22
23
24/* show configuration fields */
25#define zorro_config_attr(name, field, format_string) \
26static ssize_t \
060b8845 27show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
28{ \
29 struct zorro_dev *z; \
30 \
31 z = to_zorro_dev(dev); \
32 return sprintf(buf, format_string, z->field); \
33} \
34static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
35
36zorro_config_attr(id, id, "0x%08x\n");
37zorro_config_attr(type, rom.er_Type, "0x%02x\n");
1da177e4
LT
38zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
39zorro_config_attr(slotsize, slotsize, "0x%04x\n");
40
bd9ba8f4
GU
41static ssize_t
42show_serial(struct device *dev, struct device_attribute *attr, char *buf)
43{
44 struct zorro_dev *z;
45
46 z = to_zorro_dev(dev);
47 return sprintf(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber));
48}
49
50static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
51
060b8845 52static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
53{
54 struct zorro_dev *z = to_zorro_dev(dev);
55
56 return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
31817576
GU
57 (unsigned long)zorro_resource_start(z),
58 (unsigned long)zorro_resource_end(z),
1da177e4
LT
59 zorro_resource_flags(z));
60}
61
62static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL);
63
2c3c8bea 64static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj,
91a69029
ZR
65 struct bin_attribute *bin_attr,
66 char *buf, loff_t off, size_t count)
1da177e4 67{
a9c9d9ac 68 struct zorro_dev *z = to_zorro_dev(kobj_to_dev(kobj));
1da177e4 69 struct ConfigDev cd;
1da177e4
LT
70
71 /* Construct a ConfigDev */
72 memset(&cd, 0, sizeof(cd));
73 cd.cd_Rom = z->rom;
bd9ba8f4
GU
74 cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
75 cd.cd_SlotSize = cpu_to_be16(z->slotsize);
76 cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
77 cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
1da177e4 78
fa7f2893 79 return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
1da177e4
LT
80}
81
82static struct bin_attribute zorro_config_attr = {
83 .attr = {
84 .name = "config",
a0108668 85 .mode = S_IRUGO,
1da177e4
LT
86 },
87 .size = sizeof(struct ConfigDev),
88 .read = zorro_read_config,
89};
90
bf54a2b3
GU
91static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
92 char *buf)
93{
94 struct zorro_dev *z = to_zorro_dev(dev);
95
96 return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
97}
98
99static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL);
100
11a8b2c5 101int zorro_create_sysfs_dev_files(struct zorro_dev *z)
1da177e4
LT
102{
103 struct device *dev = &z->dev;
11a8b2c5 104 int error;
1da177e4
LT
105
106 /* current configuration's attributes */
11a8b2c5
GU
107 if ((error = device_create_file(dev, &dev_attr_id)) ||
108 (error = device_create_file(dev, &dev_attr_type)) ||
109 (error = device_create_file(dev, &dev_attr_serial)) ||
110 (error = device_create_file(dev, &dev_attr_slotaddr)) ||
111 (error = device_create_file(dev, &dev_attr_slotsize)) ||
112 (error = device_create_file(dev, &dev_attr_resource)) ||
bf54a2b3 113 (error = device_create_file(dev, &dev_attr_modalias)) ||
11a8b2c5
GU
114 (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr)))
115 return error;
116
117 return 0;
1da177e4
LT
118}
119
This page took 1.32268 seconds and 5 git commands to generate.