macio_sysfs.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <linux/config.h>
  2. #include <linux/kernel.h>
  3. #include <linux/stat.h>
  4. #include <asm/macio.h>
  5. #define macio_config_of_attr(field, format_string) \
  6. static ssize_t \
  7. field##_show (struct device *dev, struct device_attribute *attr, \
  8. char *buf) \
  9. { \
  10. struct macio_dev *mdev = to_macio_device (dev); \
  11. return sprintf (buf, format_string, mdev->ofdev.node->field); \
  12. }
  13. static ssize_t
  14. compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
  15. {
  16. struct of_device *of;
  17. char *compat;
  18. int cplen;
  19. int length = 0;
  20. of = &to_macio_device (dev)->ofdev;
  21. compat = (char *) get_property(of->node, "compatible", &cplen);
  22. if (!compat) {
  23. *buf = '\0';
  24. return 0;
  25. }
  26. while (cplen > 0) {
  27. int l;
  28. length += sprintf (buf, "%s\n", compat);
  29. buf += length;
  30. l = strlen (compat) + 1;
  31. compat += l;
  32. cplen -= l;
  33. }
  34. return length;
  35. }
  36. macio_config_of_attr (name, "%s\n");
  37. macio_config_of_attr (type, "%s\n");
  38. struct device_attribute macio_dev_attrs[] = {
  39. __ATTR_RO(name),
  40. __ATTR_RO(type),
  41. __ATTR_RO(compatible),
  42. __ATTR_NULL
  43. };