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) \ 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 41bd9ba8f4SGeert Uytterhoeven static ssize_t 42bd9ba8f4SGeert Uytterhoeven show_serial(struct device *dev, struct device_attribute *attr, 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 } 49bd9ba8f4SGeert Uytterhoeven 50bd9ba8f4SGeert Uytterhoeven static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL); 51bd9ba8f4SGeert 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 { 68a9c9d9acSGeliang Tang struct zorro_dev *z = to_zorro_dev(kobj_to_dev(kobj)); 691da177e4SLinus Torvalds struct ConfigDev cd; 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds /* Construct a ConfigDev */ 721da177e4SLinus Torvalds memset(&cd, 0, sizeof(cd)); 731da177e4SLinus Torvalds cd.cd_Rom = z->rom; 74bd9ba8f4SGeert Uytterhoeven cd.cd_SlotAddr = cpu_to_be16(z->slotaddr); 75bd9ba8f4SGeert Uytterhoeven cd.cd_SlotSize = cpu_to_be16(z->slotsize); 76bd9ba8f4SGeert Uytterhoeven cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z)); 77bd9ba8f4SGeert Uytterhoeven cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z)); 781da177e4SLinus Torvalds 79fa7f2893Sakinobu.mita@gmail.com return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd)); 801da177e4SLinus Torvalds } 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds static struct bin_attribute zorro_config_attr = { 831da177e4SLinus Torvalds .attr = { 841da177e4SLinus Torvalds .name = "config", 85a0108668SGeert Uytterhoeven .mode = S_IRUGO, 861da177e4SLinus Torvalds }, 871da177e4SLinus Torvalds .size = sizeof(struct ConfigDev), 881da177e4SLinus Torvalds .read = zorro_read_config, 891da177e4SLinus Torvalds }; 901da177e4SLinus Torvalds 91bf54a2b3SGeert Uytterhoeven static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, 92bf54a2b3SGeert Uytterhoeven char *buf) 93bf54a2b3SGeert Uytterhoeven { 94bf54a2b3SGeert Uytterhoeven struct zorro_dev *z = to_zorro_dev(dev); 95bf54a2b3SGeert Uytterhoeven 96bf54a2b3SGeert Uytterhoeven return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id); 97bf54a2b3SGeert Uytterhoeven } 98bf54a2b3SGeert Uytterhoeven 99bf54a2b3SGeert Uytterhoeven static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL); 100bf54a2b3SGeert Uytterhoeven 10111a8b2c5SGeert Uytterhoeven int zorro_create_sysfs_dev_files(struct zorro_dev *z) 1021da177e4SLinus Torvalds { 1031da177e4SLinus Torvalds struct device *dev = &z->dev; 10411a8b2c5SGeert Uytterhoeven int error; 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds /* current configuration's attributes */ 10711a8b2c5SGeert Uytterhoeven if ((error = device_create_file(dev, &dev_attr_id)) || 10811a8b2c5SGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_type)) || 10911a8b2c5SGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_serial)) || 11011a8b2c5SGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_slotaddr)) || 11111a8b2c5SGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_slotsize)) || 11211a8b2c5SGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_resource)) || 113bf54a2b3SGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_modalias)) || 11411a8b2c5SGeert Uytterhoeven (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr))) 11511a8b2c5SGeert Uytterhoeven return error; 11611a8b2c5SGeert Uytterhoeven 11711a8b2c5SGeert Uytterhoeven return 0; 1181da177e4SLinus Torvalds } 1191da177e4SLinus Torvalds 120