blob: 3d34dba9bb2dd488ffe509792940e51336c1852e [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) \
Dmitry Torokhov87e715d2017-02-14 12:24:09 -080026static ssize_t name##_show(struct device *dev, \
27 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} \
Dmitry Torokhov87e715d2017-02-14 12:24:09 -080034static DEVICE_ATTR_RO(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
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
Dmitry Torokhov87e715d2017-02-14 12:24:09 -080041static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
42 char *buf)
Geert Uytterhoevenbd9ba8f2013-10-04 09:38:53 +020043{
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}
Dmitry Torokhov87e715d2017-02-14 12:24:09 -080049static DEVICE_ATTR_RO(serial);
Geert Uytterhoevenbd9ba8f2013-10-04 09:38:53 +020050
Dmitry Torokhov87e715d2017-02-14 12:24:09 -080051static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
52 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}
Dmitry Torokhov87e715d2017-02-14 12:24:09 -080061static DEVICE_ATTR_RO(resource);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Dmitry Torokhov87e715d2017-02-14 12:24:09 -080063static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
64 char *buf)
65{
66 struct zorro_dev *z = to_zorro_dev(dev);
67
68 return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
69}
70static DEVICE_ATTR_RO(modalias);
71
72static struct attribute *zorro_device_attrs[] = {
73 &dev_attr_id.attr,
74 &dev_attr_type.attr,
75 &dev_attr_serial.attr,
76 &dev_attr_slotaddr.attr,
77 &dev_attr_slotsize.attr,
78 &dev_attr_resource.attr,
79 &dev_attr_modalias.attr,
80 NULL
81};
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Chris Wright2c3c8be2010-05-12 18:28:57 -070083static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +080084 struct bin_attribute *bin_attr,
85 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Geliang Tanga9c9d9a2016-01-06 23:28:39 +080087 struct zorro_dev *z = to_zorro_dev(kobj_to_dev(kobj));
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 struct ConfigDev cd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90 /* Construct a ConfigDev */
91 memset(&cd, 0, sizeof(cd));
92 cd.cd_Rom = z->rom;
Geert Uytterhoevenbd9ba8f2013-10-04 09:38:53 +020093 cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
94 cd.cd_SlotSize = cpu_to_be16(z->slotsize);
95 cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
96 cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
akinobu.mita@gmail.comfa7f2892008-07-17 21:16:17 +020098 return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
101static struct bin_attribute zorro_config_attr = {
102 .attr = {
103 .name = "config",
Geert Uytterhoevena0108662007-08-22 14:01:34 -0700104 .mode = S_IRUGO,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 },
106 .size = sizeof(struct ConfigDev),
107 .read = zorro_read_config,
108};
109
Dmitry Torokhov87e715d2017-02-14 12:24:09 -0800110static struct bin_attribute *zorro_device_bin_attrs[] = {
111 &zorro_config_attr,
112 NULL
113};
Geert Uytterhoevenbf54a2b2008-11-18 21:13:53 +0100114
Dmitry Torokhov87e715d2017-02-14 12:24:09 -0800115static const struct attribute_group zorro_device_attr_group = {
116 .attrs = zorro_device_attrs,
117 .bin_attrs = zorro_device_bin_attrs,
118};
Geert Uytterhoevenbf54a2b2008-11-18 21:13:53 +0100119
Dmitry Torokhov87e715d2017-02-14 12:24:09 -0800120const struct attribute_group *zorro_device_attribute_groups[] = {
121 &zorro_device_attr_group,
122 NULL
123};