macio_sysfs.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. l = sprintf (buf, "C%s", compat);
  50. length += l;
  51. buf += l;
  52. l = strlen (compat) + 1;
  53. compat += l;
  54. cplen -= l;
  55. }
  56. length += sprintf(buf, "\n");
  57. return length;
  58. }
  59. macio_config_of_attr (name, "%s\n");
  60. macio_config_of_attr (type, "%s\n");
  61. struct device_attribute macio_dev_attrs[] = {
  62. __ATTR_RO(name),
  63. __ATTR_RO(type),
  64. __ATTR_RO(compatible),
  65. __ATTR_RO(modalias),
  66. __ATTR_NULL
  67. };