macio_sysfs.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <linux/kernel.h>
  2. #include <linux/stat.h>
  3. #include <asm/macio.h>
  4. #define macio_config_of_attr(field, format_string) \
  5. static ssize_t \
  6. field##_show (struct device *dev, struct device_attribute *attr, \
  7. char *buf) \
  8. { \
  9. struct macio_dev *mdev = to_macio_device (dev); \
  10. return sprintf (buf, format_string, mdev->ofdev.node->field); \
  11. }
  12. static ssize_t
  13. compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
  14. {
  15. struct of_device *of;
  16. const char *compat;
  17. int cplen;
  18. int length = 0;
  19. of = &to_macio_device (dev)->ofdev;
  20. compat = get_property(of->node, "compatible", &cplen);
  21. if (!compat) {
  22. *buf = '\0';
  23. return 0;
  24. }
  25. while (cplen > 0) {
  26. int l;
  27. length += sprintf (buf, "%s\n", compat);
  28. buf += length;
  29. l = strlen (compat) + 1;
  30. compat += l;
  31. cplen -= l;
  32. }
  33. return length;
  34. }
  35. static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
  36. char *buf)
  37. {
  38. struct of_device *of;
  39. const char *compat;
  40. int cplen;
  41. int length;
  42. of = &to_macio_device (dev)->ofdev;
  43. compat = get_property(of->node, "compatible", &cplen);
  44. if (!compat) compat = "", cplen = 1;
  45. length = sprintf (buf, "of:N%sT%s", of->node->name, of->node->type);
  46. buf += length;
  47. while (cplen > 0) {
  48. int l;
  49. length += sprintf (buf, "C%s", compat);
  50. buf += length;
  51. l = strlen (compat) + 1;
  52. compat += l;
  53. cplen -= l;
  54. }
  55. return length;
  56. }
  57. macio_config_of_attr (name, "%s\n");
  58. macio_config_of_attr (type, "%s\n");
  59. struct device_attribute macio_dev_attrs[] = {
  60. __ATTR_RO(name),
  61. __ATTR_RO(type),
  62. __ATTR_RO(compatible),
  63. __ATTR_RO(modalias),
  64. __ATTR_NULL
  65. };