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 19*bd9ba8f4SGeert Uytterhoeven #include <asm/byteorder.h> 20*bd9ba8f4SGeert 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) \ 261da177e4SLinus Torvalds static ssize_t \ 27060b8845SYani Ioannou show_##name(struct device *dev, 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 } \ 341da177e4SLinus Torvalds static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); 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 41*bd9ba8f4SGeert Uytterhoeven static ssize_t 42*bd9ba8f4SGeert Uytterhoeven show_serial(struct device *dev, struct device_attribute *attr, char *buf) 43*bd9ba8f4SGeert Uytterhoeven { 44*bd9ba8f4SGeert Uytterhoeven struct zorro_dev *z; 45*bd9ba8f4SGeert Uytterhoeven 46*bd9ba8f4SGeert Uytterhoeven z = to_zorro_dev(dev); 47*bd9ba8f4SGeert Uytterhoeven return sprintf(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber)); 48*bd9ba8f4SGeert Uytterhoeven } 49*bd9ba8f4SGeert Uytterhoeven 50*bd9ba8f4SGeert Uytterhoeven static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL); 51*bd9ba8f4SGeert Uytterhoeven 52060b8845SYani Ioannou static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, 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 } 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL); 631da177e4SLinus Torvalds 642c3c8beaSChris Wright static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj, 6591a69029SZhang Rui struct bin_attribute *bin_attr, 6691a69029SZhang Rui char *buf, loff_t off, size_t count) 671da177e4SLinus Torvalds { 681da177e4SLinus Torvalds struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device, 691da177e4SLinus Torvalds kobj)); 701da177e4SLinus Torvalds struct ConfigDev cd; 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds /* Construct a ConfigDev */ 731da177e4SLinus Torvalds memset(&cd, 0, sizeof(cd)); 741da177e4SLinus Torvalds cd.cd_Rom = z->rom; 75*bd9ba8f4SGeert Uytterhoeven cd.cd_SlotAddr = cpu_to_be16(z->slotaddr); 76*bd9ba8f4SGeert Uytterhoeven cd.cd_SlotSize = cpu_to_be16(z->slotsize); 77*bd9ba8f4SGeert Uytterhoeven cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z)); 78*bd9ba8f4SGeert Uytterhoeven cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z)); 791da177e4SLinus Torvalds 80fa7f2893Sakinobu.mita@gmail.com return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd)); 811da177e4SLinus Torvalds } 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds static struct bin_attribute zorro_config_attr = { 841da177e4SLinus Torvalds .attr = { 851da177e4SLinus Torvalds .name = "config", 86a0108668SGeert Uytterhoeven .mode = S_IRUGO, 871da177e4SLinus Torvalds }, 881da177e4SLinus Torvalds .size = sizeof(struct ConfigDev), 891da177e4SLinus Torvalds .read = zorro_read_config, 901da177e4SLinus Torvalds }; 911da177e4SLinus Torvalds 92bf54a2b3SGeert Uytterhoeven static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, 93bf54a2b3SGeert Uytterhoeven char *buf) 94bf54a2b3SGeert Uytterhoeven { 95bf54a2b3SGeert Uytterhoeven struct zorro_dev *z = to_zorro_dev(dev); 96bf54a2b3SGeert Uytterhoeven 97bf54a2b3SGeert Uytterhoeven return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id); 98bf54a2b3SGeert Uytterhoeven } 99bf54a2b3SGeert Uytterhoeven 100bf54a2b3SGeert Uytterhoeven static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL); 101bf54a2b3SGeert Uytterhoeven 10211a8b2c5SGeert Uytterhoeven int zorro_create_sysfs_dev_files(struct zorro_dev *z) 1031da177e4SLinus Torvalds { 1041da177e4SLinus Torvalds struct device *dev = &z->dev; 10511a8b2c5SGeert Uytterhoeven int error; 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds /* current configuration's attributes */ 10811a8b2c5SGeert Uytterhoeven if ((error = device_create_file(dev, &dev_attr_id)) || 10911a8b2c5SGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_type)) || 11011a8b2c5SGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_serial)) || 11111a8b2c5SGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_slotaddr)) || 11211a8b2c5SGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_slotsize)) || 11311a8b2c5SGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_resource)) || 114bf54a2b3SGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_modalias)) || 11511a8b2c5SGeert Uytterhoeven (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr))) 11611a8b2c5SGeert Uytterhoeven return error; 11711a8b2c5SGeert Uytterhoeven 11811a8b2c5SGeert Uytterhoeven return 0; 1191da177e4SLinus Torvalds } 1201da177e4SLinus Torvalds 121