blob: 36b210f9b6b29621fa9e410db063d3df53d7fb75 [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
Geert Uytterhoevenbd9ba8f2013-10-04 09:38:53 +020019#include <asm/byteorder.h>
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include "zorro.h"
22
23
24/* show configuration fields */
25#define zorro_config_attr(name, field, format_string) \
26static ssize_t \
Yani Ioannou060b8842005-05-17 06:44:04 -040027show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{ \
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");
Linus Torvalds1da177e2005-04-16 15:20:36 -070038zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
39zorro_config_attr(slotsize, slotsize, "0x%04x\n");
40
Geert Uytterhoevenbd9ba8f2013-10-04 09:38:53 +020041static 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
Yani Ioannou060b8842005-05-17 06:44:04 -040052static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
54 struct zorro_dev *z = to_zorro_dev(dev);
55
56 return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
Geert Uytterhoeven31817572007-05-01 22:33:04 +020057 (unsigned long)zorro_resource_start(z),
58 (unsigned long)zorro_resource_end(z),
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 zorro_resource_flags(z));
60}
61
62static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL);
63
Chris Wright2c3c8be2010-05-12 18:28:57 -070064static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080065 struct bin_attribute *bin_attr,
66 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
68 struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device,
69 kobj));
70 struct ConfigDev cd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 /* Construct a ConfigDev */
73 memset(&cd, 0, sizeof(cd));
74 cd.cd_Rom = z->rom;
Geert Uytterhoevenbd9ba8f2013-10-04 09:38:53 +020075 cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
76 cd.cd_SlotSize = cpu_to_be16(z->slotsize);
77 cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
78 cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
akinobu.mita@gmail.comfa7f2892008-07-17 21:16:17 +020080 return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
83static struct bin_attribute zorro_config_attr = {
84 .attr = {
85 .name = "config",
Geert Uytterhoevena0108662007-08-22 14:01:34 -070086 .mode = S_IRUGO,
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 },
88 .size = sizeof(struct ConfigDev),
89 .read = zorro_read_config,
90};
91
Geert Uytterhoevenbf54a2b2008-11-18 21:13:53 +010092static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
93 char *buf)
94{
95 struct zorro_dev *z = to_zorro_dev(dev);
96
97 return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
98}
99
100static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL);
101
Geert Uytterhoeven11a8b2c2008-12-30 14:21:19 +0100102int zorro_create_sysfs_dev_files(struct zorro_dev *z)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
104 struct device *dev = &z->dev;
Geert Uytterhoeven11a8b2c2008-12-30 14:21:19 +0100105 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 /* current configuration's attributes */
Geert Uytterhoeven11a8b2c2008-12-30 14:21:19 +0100108 if ((error = device_create_file(dev, &dev_attr_id)) ||
109 (error = device_create_file(dev, &dev_attr_type)) ||
110 (error = device_create_file(dev, &dev_attr_serial)) ||
111 (error = device_create_file(dev, &dev_attr_slotaddr)) ||
112 (error = device_create_file(dev, &dev_attr_slotsize)) ||
113 (error = device_create_file(dev, &dev_attr_resource)) ||
Geert Uytterhoevenbf54a2b2008-11-18 21:13:53 +0100114 (error = device_create_file(dev, &dev_attr_modalias)) ||
Geert Uytterhoeven11a8b2c2008-12-30 14:21:19 +0100115 (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr)))
116 return error;
117
118 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
120