Linux Audio

Check our new training course

Embedded Linux training

Mar 31-Apr 8, 2025
Register
Loading...
v5.9
  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>
 17#include <linux/string.h>
 18
 19#include <asm/byteorder.h>
 20
 21#include "zorro.h"
 22
 23
 24/* show configuration fields */
 25#define zorro_config_attr(name, field, format_string)			\
 26static ssize_t name##_show(struct device *dev,				\
 27			   struct device_attribute *attr, char *buf)	\
 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_RO(name);
 35
 36zorro_config_attr(id, id, "0x%08x\n");
 37zorro_config_attr(type, rom.er_Type, "0x%02x\n");
 
 38zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
 39zorro_config_attr(slotsize, slotsize, "0x%04x\n");
 40
 41static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
 42			   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}
 49static DEVICE_ATTR_RO(serial);
 50
 51static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
 52			     char *buf)
 53{
 54	struct zorro_dev *z = to_zorro_dev(dev);
 55
 56	return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
 57		       (unsigned long)zorro_resource_start(z),
 58		       (unsigned long)zorro_resource_end(z),
 59		       zorro_resource_flags(z));
 60}
 61static DEVICE_ATTR_RO(resource);
 62
 63static 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};
 82
 83static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj,
 84				 struct bin_attribute *bin_attr,
 85				 char *buf, loff_t off, size_t count)
 86{
 87	struct zorro_dev *z = to_zorro_dev(kobj_to_dev(kobj));
 
 88	struct ConfigDev cd;
 89
 90	/* Construct a ConfigDev */
 91	memset(&cd, 0, sizeof(cd));
 92	cd.cd_Rom = z->rom;
 93	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));
 97
 98	return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
 99}
100
101static struct bin_attribute zorro_config_attr = {
102	.attr =	{
103		.name = "config",
104		.mode = S_IRUGO,
105	},
106	.size = sizeof(struct ConfigDev),
107	.read = zorro_read_config,
108};
109
110static struct bin_attribute *zorro_device_bin_attrs[] = {
111	&zorro_config_attr,
112	NULL
113};
114
115static const struct attribute_group zorro_device_attr_group = {
116	.attrs		= zorro_device_attrs,
117	.bin_attrs	= zorro_device_bin_attrs,
118};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
120const struct attribute_group *zorro_device_attribute_groups[] = {
121	&zorro_device_attr_group,
122	NULL
123};
v3.1
  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>
 17#include <linux/string.h>
 18
 
 
 19#include "zorro.h"
 20
 21
 22/* show configuration fields */
 23#define zorro_config_attr(name, field, format_string)			\
 24static ssize_t								\
 25show_##name(struct device *dev, struct device_attribute *attr, char *buf)				\
 26{									\
 27	struct zorro_dev *z;						\
 28									\
 29	z = to_zorro_dev(dev);						\
 30	return sprintf(buf, format_string, z->field);			\
 31}									\
 32static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
 33
 34zorro_config_attr(id, id, "0x%08x\n");
 35zorro_config_attr(type, rom.er_Type, "0x%02x\n");
 36zorro_config_attr(serial, rom.er_SerialNumber, "0x%08x\n");
 37zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
 38zorro_config_attr(slotsize, slotsize, "0x%04x\n");
 39
 40static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
 
 
 
 
 
 
 
 
 
 
 
 41{
 42	struct zorro_dev *z = to_zorro_dev(dev);
 43
 44	return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
 45		       (unsigned long)zorro_resource_start(z),
 46		       (unsigned long)zorro_resource_end(z),
 47		       zorro_resource_flags(z));
 48}
 
 49
 50static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 51
 52static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj,
 53				 struct bin_attribute *bin_attr,
 54				 char *buf, loff_t off, size_t count)
 55{
 56	struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device,
 57					   kobj));
 58	struct ConfigDev cd;
 59
 60	/* Construct a ConfigDev */
 61	memset(&cd, 0, sizeof(cd));
 62	cd.cd_Rom = z->rom;
 63	cd.cd_SlotAddr = z->slotaddr;
 64	cd.cd_SlotSize = z->slotsize;
 65	cd.cd_BoardAddr = (void *)zorro_resource_start(z);
 66	cd.cd_BoardSize = zorro_resource_len(z);
 67
 68	return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
 69}
 70
 71static struct bin_attribute zorro_config_attr = {
 72	.attr =	{
 73		.name = "config",
 74		.mode = S_IRUGO,
 75	},
 76	.size = sizeof(struct ConfigDev),
 77	.read = zorro_read_config,
 78};
 79
 80static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
 81			     char *buf)
 82{
 83	struct zorro_dev *z = to_zorro_dev(dev);
 84
 85	return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
 86}
 87
 88static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL);
 89
 90int zorro_create_sysfs_dev_files(struct zorro_dev *z)
 91{
 92	struct device *dev = &z->dev;
 93	int error;
 94
 95	/* current configuration's attributes */
 96	if ((error = device_create_file(dev, &dev_attr_id)) ||
 97	    (error = device_create_file(dev, &dev_attr_type)) ||
 98	    (error = device_create_file(dev, &dev_attr_serial)) ||
 99	    (error = device_create_file(dev, &dev_attr_slotaddr)) ||
100	    (error = device_create_file(dev, &dev_attr_slotsize)) ||
101	    (error = device_create_file(dev, &dev_attr_resource)) ||
102	    (error = device_create_file(dev, &dev_attr_modalias)) ||
103	    (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr)))
104		return error;
105
106	return 0;
107}
108