macio_sysfs.c 1.5 KB

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