^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * File Attributes for DIO Devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2004 Jochen Friedrich
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Loosely based on drivers/pci/pci-sysfs.c and drivers/zorro/zorro-sysfs.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * License. See the file COPYING in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/dio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* show configuration fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static ssize_t dio_show_id(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct dio_dev *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) d = to_dio_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) return sprintf(buf, "0x%02x\n", (d->id & 0xff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static DEVICE_ATTR(id, S_IRUGO, dio_show_id, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static ssize_t dio_show_ipl(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct dio_dev *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) d = to_dio_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return sprintf(buf, "0x%02x\n", d->ipl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static DEVICE_ATTR(ipl, S_IRUGO, dio_show_ipl, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static ssize_t dio_show_secid(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct dio_dev *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) d = to_dio_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return sprintf(buf, "0x%02x\n", ((d->id >> 8)& 0xff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static DEVICE_ATTR(secid, S_IRUGO, dio_show_secid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static ssize_t dio_show_name(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct dio_dev *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) d = to_dio_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return sprintf(buf, "%s\n", d->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static DEVICE_ATTR(name, S_IRUGO, dio_show_name, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static ssize_t dio_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct dio_dev *d = to_dio_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) (unsigned long)dio_resource_start(d),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) (unsigned long)dio_resource_end(d),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) dio_resource_flags(d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static DEVICE_ATTR(resource, S_IRUGO, dio_show_resource, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) int dio_create_sysfs_dev_files(struct dio_dev *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct device *dev = &d->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* current configuration's attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if ((error = device_create_file(dev, &dev_attr_id)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) (error = device_create_file(dev, &dev_attr_ipl)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) (error = device_create_file(dev, &dev_attr_secid)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) (error = device_create_file(dev, &dev_attr_name)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) (error = device_create_file(dev, &dev_attr_resource)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)