11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds * File Attributes for DIO Devices
31da177e4SLinus Torvalds *
41da177e4SLinus Torvalds * Copyright (C) 2004 Jochen Friedrich
51da177e4SLinus Torvalds *
61da177e4SLinus Torvalds * Loosely based on drivers/pci/pci-sysfs.c and drivers/zorro/zorro-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/dio.h>
161da177e4SLinus Torvalds #include <linux/stat.h>
171da177e4SLinus Torvalds
181da177e4SLinus Torvalds /* show configuration fields */
191da177e4SLinus Torvalds
dio_show_id(struct device * dev,struct device_attribute * attr,char * buf)2074880c06SYani Ioannou static ssize_t dio_show_id(struct device *dev, struct device_attribute *attr, char *buf)
211da177e4SLinus Torvalds {
221da177e4SLinus Torvalds struct dio_dev *d;
231da177e4SLinus Torvalds
241da177e4SLinus Torvalds d = to_dio_dev(dev);
251da177e4SLinus Torvalds return sprintf(buf, "0x%02x\n", (d->id & 0xff));
261da177e4SLinus Torvalds }
271da177e4SLinus Torvalds static DEVICE_ATTR(id, S_IRUGO, dio_show_id, NULL);
281da177e4SLinus Torvalds
dio_show_ipl(struct device * dev,struct device_attribute * attr,char * buf)2974880c06SYani Ioannou static ssize_t dio_show_ipl(struct device *dev, struct device_attribute *attr, char *buf)
301da177e4SLinus Torvalds {
311da177e4SLinus Torvalds struct dio_dev *d;
321da177e4SLinus Torvalds
331da177e4SLinus Torvalds d = to_dio_dev(dev);
341da177e4SLinus Torvalds return sprintf(buf, "0x%02x\n", d->ipl);
351da177e4SLinus Torvalds }
361da177e4SLinus Torvalds static DEVICE_ATTR(ipl, S_IRUGO, dio_show_ipl, NULL);
371da177e4SLinus Torvalds
dio_show_secid(struct device * dev,struct device_attribute * attr,char * buf)3874880c06SYani Ioannou static ssize_t dio_show_secid(struct device *dev, struct device_attribute *attr, char *buf)
391da177e4SLinus Torvalds {
401da177e4SLinus Torvalds struct dio_dev *d;
411da177e4SLinus Torvalds
421da177e4SLinus Torvalds d = to_dio_dev(dev);
431da177e4SLinus Torvalds return sprintf(buf, "0x%02x\n", ((d->id >> 8)& 0xff));
441da177e4SLinus Torvalds }
451da177e4SLinus Torvalds static DEVICE_ATTR(secid, S_IRUGO, dio_show_secid, NULL);
461da177e4SLinus Torvalds
dio_show_name(struct device * dev,struct device_attribute * attr,char * buf)4774880c06SYani Ioannou static ssize_t dio_show_name(struct device *dev, struct device_attribute *attr, char *buf)
481da177e4SLinus Torvalds {
491da177e4SLinus Torvalds struct dio_dev *d;
501da177e4SLinus Torvalds
511da177e4SLinus Torvalds d = to_dio_dev(dev);
521da177e4SLinus Torvalds return sprintf(buf, "%s\n", d->name);
531da177e4SLinus Torvalds }
541da177e4SLinus Torvalds static DEVICE_ATTR(name, S_IRUGO, dio_show_name, NULL);
551da177e4SLinus Torvalds
dio_show_resource(struct device * dev,struct device_attribute * attr,char * buf)5674880c06SYani Ioannou static ssize_t dio_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
571da177e4SLinus Torvalds {
581da177e4SLinus Torvalds struct dio_dev *d = to_dio_dev(dev);
591da177e4SLinus Torvalds
601da177e4SLinus Torvalds return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
61*fae3306aSGeert Uytterhoeven (unsigned long)dio_resource_start(d),
62*fae3306aSGeert Uytterhoeven (unsigned long)dio_resource_end(d),
631da177e4SLinus Torvalds dio_resource_flags(d));
641da177e4SLinus Torvalds }
651da177e4SLinus Torvalds static DEVICE_ATTR(resource, S_IRUGO, dio_show_resource, NULL);
661da177e4SLinus Torvalds
dio_create_sysfs_dev_files(struct dio_dev * d)672e4c77beSGeert Uytterhoeven int dio_create_sysfs_dev_files(struct dio_dev *d)
681da177e4SLinus Torvalds {
691da177e4SLinus Torvalds struct device *dev = &d->dev;
702e4c77beSGeert Uytterhoeven int error;
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds /* current configuration's attributes */
732e4c77beSGeert Uytterhoeven if ((error = device_create_file(dev, &dev_attr_id)) ||
742e4c77beSGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_ipl)) ||
752e4c77beSGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_secid)) ||
762e4c77beSGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_name)) ||
772e4c77beSGeert Uytterhoeven (error = device_create_file(dev, &dev_attr_resource)))
782e4c77beSGeert Uytterhoeven return error;
792e4c77beSGeert Uytterhoeven
802e4c77beSGeert Uytterhoeven return 0;
811da177e4SLinus Torvalds }
821da177e4SLinus Torvalds
83