macio_sysfs.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 = of_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 *ofdev = to_of_device(dev);
  39. int len;
  40. len = of_device_get_modalias(ofdev, buf, PAGE_SIZE - 2);
  41. buf[len] = '\n';
  42. buf[len+1] = 0;
  43. return len+1;
  44. }
  45. static ssize_t devspec_show(struct device *dev,
  46. struct device_attribute *attr, char *buf)
  47. {
  48. struct of_device *ofdev;
  49. ofdev = to_of_device(dev);
  50. return sprintf(buf, "%s\n", ofdev->node->full_name);
  51. }
  52. macio_config_of_attr (name, "%s\n");
  53. macio_config_of_attr (type, "%s\n");
  54. struct device_attribute macio_dev_attrs[] = {
  55. __ATTR_RO(name),
  56. __ATTR_RO(type),
  57. __ATTR_RO(compatible),
  58. __ATTR_RO(modalias),
  59. __ATTR_RO(devspec),
  60. __ATTR_NULL
  61. };