18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci *  File Attributes for DIO Devices
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci *  Copyright (C) 2004 Jochen Friedrich
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci *  Loosely based on drivers/pci/pci-sysfs.c and drivers/zorro/zorro-sysfs.c
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci *  This file is subject to the terms and conditions of the GNU General Public
98c2ecf20Sopenharmony_ci *  License.  See the file COPYING in the main directory of this archive
108c2ecf20Sopenharmony_ci *  for more details.
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/kernel.h>
158c2ecf20Sopenharmony_ci#include <linux/dio.h>
168c2ecf20Sopenharmony_ci#include <linux/stat.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/* show configuration fields */
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistatic ssize_t dio_show_id(struct device *dev, struct device_attribute *attr, char *buf)
218c2ecf20Sopenharmony_ci{
228c2ecf20Sopenharmony_ci	struct dio_dev *d;
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci	d = to_dio_dev(dev);
258c2ecf20Sopenharmony_ci	return sprintf(buf, "0x%02x\n", (d->id & 0xff));
268c2ecf20Sopenharmony_ci}
278c2ecf20Sopenharmony_cistatic DEVICE_ATTR(id, S_IRUGO, dio_show_id, NULL);
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic ssize_t dio_show_ipl(struct device *dev, struct device_attribute *attr, char *buf)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	struct dio_dev *d;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	d = to_dio_dev(dev);
348c2ecf20Sopenharmony_ci	return sprintf(buf, "0x%02x\n", d->ipl);
358c2ecf20Sopenharmony_ci}
368c2ecf20Sopenharmony_cistatic DEVICE_ATTR(ipl, S_IRUGO, dio_show_ipl, NULL);
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistatic ssize_t dio_show_secid(struct device *dev, struct device_attribute *attr, char *buf)
398c2ecf20Sopenharmony_ci{
408c2ecf20Sopenharmony_ci	struct dio_dev *d;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	d = to_dio_dev(dev);
438c2ecf20Sopenharmony_ci	return sprintf(buf, "0x%02x\n", ((d->id >> 8)& 0xff));
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_cistatic DEVICE_ATTR(secid, S_IRUGO, dio_show_secid, NULL);
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistatic ssize_t dio_show_name(struct device *dev, struct device_attribute *attr, char *buf)
488c2ecf20Sopenharmony_ci{
498c2ecf20Sopenharmony_ci	struct dio_dev *d;
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	d = to_dio_dev(dev);
528c2ecf20Sopenharmony_ci	return sprintf(buf, "%s\n", d->name);
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_cistatic DEVICE_ATTR(name, S_IRUGO, dio_show_name, NULL);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic ssize_t dio_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
578c2ecf20Sopenharmony_ci{
588c2ecf20Sopenharmony_ci	struct dio_dev *d = to_dio_dev(dev);
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
618c2ecf20Sopenharmony_ci		       (unsigned long)dio_resource_start(d),
628c2ecf20Sopenharmony_ci		       (unsigned long)dio_resource_end(d),
638c2ecf20Sopenharmony_ci		       dio_resource_flags(d));
648c2ecf20Sopenharmony_ci}
658c2ecf20Sopenharmony_cistatic DEVICE_ATTR(resource, S_IRUGO, dio_show_resource, NULL);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciint dio_create_sysfs_dev_files(struct dio_dev *d)
688c2ecf20Sopenharmony_ci{
698c2ecf20Sopenharmony_ci	struct device *dev = &d->dev;
708c2ecf20Sopenharmony_ci	int error;
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	/* current configuration's attributes */
738c2ecf20Sopenharmony_ci	if ((error = device_create_file(dev, &dev_attr_id)) ||
748c2ecf20Sopenharmony_ci	    (error = device_create_file(dev, &dev_attr_ipl)) ||
758c2ecf20Sopenharmony_ci	    (error = device_create_file(dev, &dev_attr_secid)) ||
768c2ecf20Sopenharmony_ci	    (error = device_create_file(dev, &dev_attr_name)) ||
778c2ecf20Sopenharmony_ci	    (error = device_create_file(dev, &dev_attr_resource)))
788c2ecf20Sopenharmony_ci		return error;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	return 0;
818c2ecf20Sopenharmony_ci}
828c2ecf20Sopenharmony_ci
83