macio_sysfs.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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);
  41. buf[len] = '\n';
  42. buf[len+1] = 0;
  43. return len+1;
  44. }
  45. macio_config_of_attr (name, "%s\n");
  46. macio_config_of_attr (type, "%s\n");
  47. struct device_attribute macio_dev_attrs[] = {
  48. __ATTR_RO(name),
  49. __ATTR_RO(type),
  50. __ATTR_RO(compatible),
  51. __ATTR_RO(modalias),
  52. __ATTR_NULL
  53. };