zorro-sysfs.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 \
  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(slotaddr, slotaddr, "0x%04x\n");
  32. zorro_config_attr(slotsize, slotsize, "0x%04x\n");
  33. static ssize_t
  34. show_serial(struct device *dev, struct device_attribute *attr, 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(serial, S_IRUGO, show_serial, NULL);
  41. static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
  42. {
  43. struct zorro_dev *z = to_zorro_dev(dev);
  44. return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
  45. (unsigned long)zorro_resource_start(z),
  46. (unsigned long)zorro_resource_end(z),
  47. zorro_resource_flags(z));
  48. }
  49. static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL);
  50. static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj,
  51. struct bin_attribute *bin_attr,
  52. char *buf, loff_t off, size_t count)
  53. {
  54. struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device,
  55. kobj));
  56. struct ConfigDev cd;
  57. /* Construct a ConfigDev */
  58. memset(&cd, 0, sizeof(cd));
  59. cd.cd_Rom = z->rom;
  60. cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
  61. cd.cd_SlotSize = cpu_to_be16(z->slotsize);
  62. cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
  63. cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
  64. return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
  65. }
  66. static struct bin_attribute zorro_config_attr = {
  67. .attr = {
  68. .name = "config",
  69. .mode = S_IRUGO,
  70. },
  71. .size = sizeof(struct ConfigDev),
  72. .read = zorro_read_config,
  73. };
  74. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
  75. char *buf)
  76. {
  77. struct zorro_dev *z = to_zorro_dev(dev);
  78. return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
  79. }
  80. static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL);
  81. int zorro_create_sysfs_dev_files(struct zorro_dev *z)
  82. {
  83. struct device *dev = &z->dev;
  84. int error;
  85. /* current configuration's attributes */
  86. if ((error = device_create_file(dev, &dev_attr_id)) ||
  87. (error = device_create_file(dev, &dev_attr_type)) ||
  88. (error = device_create_file(dev, &dev_attr_serial)) ||
  89. (error = device_create_file(dev, &dev_attr_slotaddr)) ||
  90. (error = device_create_file(dev, &dev_attr_slotsize)) ||
  91. (error = device_create_file(dev, &dev_attr_resource)) ||
  92. (error = device_create_file(dev, &dev_attr_modalias)) ||
  93. (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr)))
  94. return error;
  95. return 0;
  96. }