zorro-sysfs.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * File Attributes for Zorro Devices
  3. *
  4. * Copyright (C) 2003 Geert Uytterhoeven
  5. *
  6. * Loosely based on drivers/pci/pci-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/zorro.h>
  14. #include <linux/stat.h>
  15. #include <linux/string.h>
  16. #include <asm/byteorder.h>
  17. #include "zorro.h"
  18. /* show configuration fields */
  19. #define zorro_config_attr(name, field, format_string) \
  20. static ssize_t name##_show(struct device *dev, \
  21. struct device_attribute *attr, char *buf) \
  22. { \
  23. struct zorro_dev *z; \
  24. \
  25. z = to_zorro_dev(dev); \
  26. return sprintf(buf, format_string, z->field); \
  27. } \
  28. static DEVICE_ATTR_RO(name);
  29. zorro_config_attr(id, id, "0x%08x\n");
  30. zorro_config_attr(type, rom.er_Type, "0x%02x\n");
  31. zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
  32. zorro_config_attr(slotsize, slotsize, "0x%04x\n");
  33. static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
  34. char *buf)
  35. {
  36. struct zorro_dev *z;
  37. z = to_zorro_dev(dev);
  38. return sprintf(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber));
  39. }
  40. static DEVICE_ATTR_RO(serial);
  41. static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
  42. char *buf)
  43. {
  44. struct zorro_dev *z = to_zorro_dev(dev);
  45. return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
  46. (unsigned long)zorro_resource_start(z),
  47. (unsigned long)zorro_resource_end(z),
  48. zorro_resource_flags(z));
  49. }
  50. static DEVICE_ATTR_RO(resource);
  51. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
  52. char *buf)
  53. {
  54. struct zorro_dev *z = to_zorro_dev(dev);
  55. return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
  56. }
  57. static DEVICE_ATTR_RO(modalias);
  58. static struct attribute *zorro_device_attrs[] = {
  59. &dev_attr_id.attr,
  60. &dev_attr_type.attr,
  61. &dev_attr_serial.attr,
  62. &dev_attr_slotaddr.attr,
  63. &dev_attr_slotsize.attr,
  64. &dev_attr_resource.attr,
  65. &dev_attr_modalias.attr,
  66. NULL
  67. };
  68. static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj,
  69. struct bin_attribute *bin_attr,
  70. char *buf, loff_t off, size_t count)
  71. {
  72. struct zorro_dev *z = to_zorro_dev(kobj_to_dev(kobj));
  73. struct ConfigDev cd;
  74. /* Construct a ConfigDev */
  75. memset(&cd, 0, sizeof(cd));
  76. cd.cd_Rom = z->rom;
  77. cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
  78. cd.cd_SlotSize = cpu_to_be16(z->slotsize);
  79. cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
  80. cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
  81. return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
  82. }
  83. static struct bin_attribute zorro_config_attr = {
  84. .attr = {
  85. .name = "config",
  86. .mode = S_IRUGO,
  87. },
  88. .size = sizeof(struct ConfigDev),
  89. .read = zorro_read_config,
  90. };
  91. static struct bin_attribute *zorro_device_bin_attrs[] = {
  92. &zorro_config_attr,
  93. NULL
  94. };
  95. static const struct attribute_group zorro_device_attr_group = {
  96. .attrs = zorro_device_attrs,
  97. .bin_attrs = zorro_device_bin_attrs,
  98. };
  99. const struct attribute_group *zorro_device_attribute_groups[] = {
  100. &zorro_device_attr_group,
  101. NULL
  102. };