xref: /openbmc/linux/drivers/zorro/zorro-sysfs.c (revision a976c2951d8f376112361830aa7762beff83a205)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  File Attributes for Zorro Devices
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *  Copyright (C) 2003 Geert Uytterhoeven
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *  Loosely based on drivers/pci/pci-sysfs.c
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  *  This file is subject to the terms and conditions of the GNU General Public
91da177e4SLinus Torvalds  *  License.  See the file COPYING in the main directory of this archive
101da177e4SLinus Torvalds  *  for more details.
111da177e4SLinus Torvalds  */
121da177e4SLinus Torvalds 
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds #include <linux/kernel.h>
151da177e4SLinus Torvalds #include <linux/zorro.h>
161da177e4SLinus Torvalds #include <linux/stat.h>
174e57b681STim Schmielau #include <linux/string.h>
181da177e4SLinus Torvalds 
19bd9ba8f4SGeert Uytterhoeven #include <asm/byteorder.h>
20bd9ba8f4SGeert Uytterhoeven 
211da177e4SLinus Torvalds #include "zorro.h"
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds /* show configuration fields */
251da177e4SLinus Torvalds #define zorro_config_attr(name, field, format_string)			\
26*87e715deSDmitry Torokhov static ssize_t name##_show(struct device *dev,				\
27*87e715deSDmitry Torokhov 			   struct device_attribute *attr, char *buf)	\
281da177e4SLinus Torvalds {									\
291da177e4SLinus Torvalds 	struct zorro_dev *z;						\
301da177e4SLinus Torvalds 									\
311da177e4SLinus Torvalds 	z = to_zorro_dev(dev);						\
321da177e4SLinus Torvalds 	return sprintf(buf, format_string, z->field);			\
331da177e4SLinus Torvalds }									\
34*87e715deSDmitry Torokhov static DEVICE_ATTR_RO(name);
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds zorro_config_attr(id, id, "0x%08x\n");
371da177e4SLinus Torvalds zorro_config_attr(type, rom.er_Type, "0x%02x\n");
381da177e4SLinus Torvalds zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
391da177e4SLinus Torvalds zorro_config_attr(slotsize, slotsize, "0x%04x\n");
401da177e4SLinus Torvalds 
serial_show(struct device * dev,struct device_attribute * attr,char * buf)41*87e715deSDmitry Torokhov static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
42*87e715deSDmitry Torokhov 			   char *buf)
43bd9ba8f4SGeert Uytterhoeven {
44bd9ba8f4SGeert Uytterhoeven 	struct zorro_dev *z;
45bd9ba8f4SGeert Uytterhoeven 
46bd9ba8f4SGeert Uytterhoeven 	z = to_zorro_dev(dev);
47bd9ba8f4SGeert Uytterhoeven 	return sprintf(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber));
48bd9ba8f4SGeert Uytterhoeven }
49*87e715deSDmitry Torokhov static DEVICE_ATTR_RO(serial);
50bd9ba8f4SGeert Uytterhoeven 
resource_show(struct device * dev,struct device_attribute * attr,char * buf)51*87e715deSDmitry Torokhov static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
52*87e715deSDmitry Torokhov 			     char *buf)
531da177e4SLinus Torvalds {
541da177e4SLinus Torvalds 	struct zorro_dev *z = to_zorro_dev(dev);
551da177e4SLinus Torvalds 
561da177e4SLinus Torvalds 	return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
5731817576SGeert Uytterhoeven 		       (unsigned long)zorro_resource_start(z),
5831817576SGeert Uytterhoeven 		       (unsigned long)zorro_resource_end(z),
591da177e4SLinus Torvalds 		       zorro_resource_flags(z));
601da177e4SLinus Torvalds }
61*87e715deSDmitry Torokhov static DEVICE_ATTR_RO(resource);
621da177e4SLinus Torvalds 
modalias_show(struct device * dev,struct device_attribute * attr,char * buf)63*87e715deSDmitry Torokhov static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
64*87e715deSDmitry Torokhov 			     char *buf)
65*87e715deSDmitry Torokhov {
66*87e715deSDmitry Torokhov 	struct zorro_dev *z = to_zorro_dev(dev);
67*87e715deSDmitry Torokhov 
68*87e715deSDmitry Torokhov 	return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
69*87e715deSDmitry Torokhov }
70*87e715deSDmitry Torokhov static DEVICE_ATTR_RO(modalias);
71*87e715deSDmitry Torokhov 
72*87e715deSDmitry Torokhov static struct attribute *zorro_device_attrs[] = {
73*87e715deSDmitry Torokhov 	&dev_attr_id.attr,
74*87e715deSDmitry Torokhov 	&dev_attr_type.attr,
75*87e715deSDmitry Torokhov 	&dev_attr_serial.attr,
76*87e715deSDmitry Torokhov 	&dev_attr_slotaddr.attr,
77*87e715deSDmitry Torokhov 	&dev_attr_slotsize.attr,
78*87e715deSDmitry Torokhov 	&dev_attr_resource.attr,
79*87e715deSDmitry Torokhov 	&dev_attr_modalias.attr,
80*87e715deSDmitry Torokhov 	NULL
81*87e715deSDmitry Torokhov };
821da177e4SLinus Torvalds 
zorro_read_config(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t off,size_t count)832c3c8beaSChris Wright static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj,
8491a69029SZhang Rui 				 struct bin_attribute *bin_attr,
8591a69029SZhang Rui 				 char *buf, loff_t off, size_t count)
861da177e4SLinus Torvalds {
87a9c9d9acSGeliang Tang 	struct zorro_dev *z = to_zorro_dev(kobj_to_dev(kobj));
881da177e4SLinus Torvalds 	struct ConfigDev cd;
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds 	/* Construct a ConfigDev */
911da177e4SLinus Torvalds 	memset(&cd, 0, sizeof(cd));
921da177e4SLinus Torvalds 	cd.cd_Rom = z->rom;
93bd9ba8f4SGeert Uytterhoeven 	cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
94bd9ba8f4SGeert Uytterhoeven 	cd.cd_SlotSize = cpu_to_be16(z->slotsize);
95bd9ba8f4SGeert Uytterhoeven 	cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
96bd9ba8f4SGeert Uytterhoeven 	cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
971da177e4SLinus Torvalds 
98fa7f2893Sakinobu.mita@gmail.com 	return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
991da177e4SLinus Torvalds }
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds static struct bin_attribute zorro_config_attr = {
1021da177e4SLinus Torvalds 	.attr =	{
1031da177e4SLinus Torvalds 		.name = "config",
104a0108668SGeert Uytterhoeven 		.mode = S_IRUGO,
1051da177e4SLinus Torvalds 	},
1061da177e4SLinus Torvalds 	.size = sizeof(struct ConfigDev),
1071da177e4SLinus Torvalds 	.read = zorro_read_config,
1081da177e4SLinus Torvalds };
1091da177e4SLinus Torvalds 
110*87e715deSDmitry Torokhov static struct bin_attribute *zorro_device_bin_attrs[] = {
111*87e715deSDmitry Torokhov 	&zorro_config_attr,
112*87e715deSDmitry Torokhov 	NULL
113*87e715deSDmitry Torokhov };
114bf54a2b3SGeert Uytterhoeven 
115*87e715deSDmitry Torokhov static const struct attribute_group zorro_device_attr_group = {
116*87e715deSDmitry Torokhov 	.attrs		= zorro_device_attrs,
117*87e715deSDmitry Torokhov 	.bin_attrs	= zorro_device_bin_attrs,
118*87e715deSDmitry Torokhov };
119bf54a2b3SGeert Uytterhoeven 
120*87e715deSDmitry Torokhov const struct attribute_group *zorro_device_attribute_groups[] = {
121*87e715deSDmitry Torokhov 	&zorro_device_attr_group,
122*87e715deSDmitry Torokhov 	NULL
123*87e715deSDmitry Torokhov };
124