zorro-sysfs.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 file *filp, 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. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
  67. char *buf)
  68. {
  69. struct zorro_dev *z = to_zorro_dev(dev);
  70. return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
  71. }
  72. static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL);
  73. int zorro_create_sysfs_dev_files(struct zorro_dev *z)
  74. {
  75. struct device *dev = &z->dev;
  76. int error;
  77. /* current configuration's attributes */
  78. if ((error = device_create_file(dev, &dev_attr_id)) ||
  79. (error = device_create_file(dev, &dev_attr_type)) ||
  80. (error = device_create_file(dev, &dev_attr_serial)) ||
  81. (error = device_create_file(dev, &dev_attr_slotaddr)) ||
  82. (error = device_create_file(dev, &dev_attr_slotsize)) ||
  83. (error = device_create_file(dev, &dev_attr_resource)) ||
  84. (error = device_create_file(dev, &dev_attr_modalias)) ||
  85. (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr)))
  86. return error;
  87. return 0;
  88. }