dio-sysfs.c 2.2 KB

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