zorro-sysfs.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "zorro.h"
  17. /* show configuration fields */
  18. #define zorro_config_attr(name, field, format_string) \
  19. static ssize_t \
  20. show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
  21. { \
  22. struct zorro_dev *z; \
  23. \
  24. z = to_zorro_dev(dev); \
  25. return sprintf(buf, format_string, z->field); \
  26. } \
  27. static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
  28. zorro_config_attr(id, id, "0x%08x\n");
  29. zorro_config_attr(type, rom.er_Type, "0x%02x\n");
  30. zorro_config_attr(serial, rom.er_SerialNumber, "0x%08x\n");
  31. zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
  32. zorro_config_attr(slotsize, slotsize, "0x%04x\n");
  33. static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
  34. {
  35. struct zorro_dev *z = to_zorro_dev(dev);
  36. return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
  37. (unsigned long)zorro_resource_start(z),
  38. (unsigned long)zorro_resource_end(z),
  39. zorro_resource_flags(z));
  40. }
  41. static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL);
  42. static ssize_t zorro_read_config(struct kobject *kobj,
  43. struct bin_attribute *bin_attr,
  44. char *buf, loff_t off, size_t count)
  45. {
  46. struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device,
  47. kobj));
  48. struct ConfigDev cd;
  49. /* Construct a ConfigDev */
  50. memset(&cd, 0, sizeof(cd));
  51. cd.cd_Rom = z->rom;
  52. cd.cd_SlotAddr = z->slotaddr;
  53. cd.cd_SlotSize = z->slotsize;
  54. cd.cd_BoardAddr = (void *)zorro_resource_start(z);
  55. cd.cd_BoardSize = zorro_resource_len(z);
  56. return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
  57. }
  58. static struct bin_attribute zorro_config_attr = {
  59. .attr = {
  60. .name = "config",
  61. .mode = S_IRUGO,
  62. },
  63. .size = sizeof(struct ConfigDev),
  64. .read = zorro_read_config,
  65. };
  66. int zorro_create_sysfs_dev_files(struct zorro_dev *z)
  67. {
  68. struct device *dev = &z->dev;
  69. int error;
  70. /* current configuration's attributes */
  71. if ((error = device_create_file(dev, &dev_attr_id)) ||
  72. (error = device_create_file(dev, &dev_attr_type)) ||
  73. (error = device_create_file(dev, &dev_attr_serial)) ||
  74. (error = device_create_file(dev, &dev_attr_slotaddr)) ||
  75. (error = device_create_file(dev, &dev_attr_slotsize)) ||
  76. (error = device_create_file(dev, &dev_attr_resource)) ||
  77. (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr)))
  78. return error;
  79. return 0;
  80. }