zorro-sysfs.c 2.6 KB

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