Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  File Attributes for Zorro Devices
0003  *
0004  *  Copyright (C) 2003 Geert Uytterhoeven
0005  *
0006  *  Loosely based on drivers/pci/pci-sysfs.c
0007  *
0008  *  This file is subject to the terms and conditions of the GNU General Public
0009  *  License.  See the file COPYING in the main directory of this archive
0010  *  for more details.
0011  */
0012 
0013 
0014 #include <linux/kernel.h>
0015 #include <linux/zorro.h>
0016 #include <linux/stat.h>
0017 #include <linux/string.h>
0018 
0019 #include <asm/byteorder.h>
0020 
0021 #include "zorro.h"
0022 
0023 
0024 /* show configuration fields */
0025 #define zorro_config_attr(name, field, format_string)           \
0026 static ssize_t name##_show(struct device *dev,              \
0027                struct device_attribute *attr, char *buf)    \
0028 {                                   \
0029     struct zorro_dev *z;                        \
0030                                     \
0031     z = to_zorro_dev(dev);                      \
0032     return sprintf(buf, format_string, z->field);           \
0033 }                                   \
0034 static DEVICE_ATTR_RO(name);
0035 
0036 zorro_config_attr(id, id, "0x%08x\n");
0037 zorro_config_attr(type, rom.er_Type, "0x%02x\n");
0038 zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
0039 zorro_config_attr(slotsize, slotsize, "0x%04x\n");
0040 
0041 static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
0042                char *buf)
0043 {
0044     struct zorro_dev *z;
0045 
0046     z = to_zorro_dev(dev);
0047     return sprintf(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber));
0048 }
0049 static DEVICE_ATTR_RO(serial);
0050 
0051 static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
0052                  char *buf)
0053 {
0054     struct zorro_dev *z = to_zorro_dev(dev);
0055 
0056     return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
0057                (unsigned long)zorro_resource_start(z),
0058                (unsigned long)zorro_resource_end(z),
0059                zorro_resource_flags(z));
0060 }
0061 static DEVICE_ATTR_RO(resource);
0062 
0063 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
0064                  char *buf)
0065 {
0066     struct zorro_dev *z = to_zorro_dev(dev);
0067 
0068     return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
0069 }
0070 static DEVICE_ATTR_RO(modalias);
0071 
0072 static struct attribute *zorro_device_attrs[] = {
0073     &dev_attr_id.attr,
0074     &dev_attr_type.attr,
0075     &dev_attr_serial.attr,
0076     &dev_attr_slotaddr.attr,
0077     &dev_attr_slotsize.attr,
0078     &dev_attr_resource.attr,
0079     &dev_attr_modalias.attr,
0080     NULL
0081 };
0082 
0083 static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj,
0084                  struct bin_attribute *bin_attr,
0085                  char *buf, loff_t off, size_t count)
0086 {
0087     struct zorro_dev *z = to_zorro_dev(kobj_to_dev(kobj));
0088     struct ConfigDev cd;
0089 
0090     /* Construct a ConfigDev */
0091     memset(&cd, 0, sizeof(cd));
0092     cd.cd_Rom = z->rom;
0093     cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
0094     cd.cd_SlotSize = cpu_to_be16(z->slotsize);
0095     cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
0096     cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
0097 
0098     return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
0099 }
0100 
0101 static struct bin_attribute zorro_config_attr = {
0102     .attr = {
0103         .name = "config",
0104         .mode = S_IRUGO,
0105     },
0106     .size = sizeof(struct ConfigDev),
0107     .read = zorro_read_config,
0108 };
0109 
0110 static struct bin_attribute *zorro_device_bin_attrs[] = {
0111     &zorro_config_attr,
0112     NULL
0113 };
0114 
0115 static const struct attribute_group zorro_device_attr_group = {
0116     .attrs      = zorro_device_attrs,
0117     .bin_attrs  = zorro_device_bin_attrs,
0118 };
0119 
0120 const struct attribute_group *zorro_device_attribute_groups[] = {
0121     &zorro_device_attr_group,
0122     NULL
0123 };