macio_sysfs.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
  37. char *buf)
  38. {
  39. struct of_device *of;
  40. char *compat;
  41. int cplen;
  42. int length;
  43. of = &to_macio_device (dev)->ofdev;
  44. compat = (char *) get_property (of->node, "compatible", &cplen);
  45. if (!compat) compat = "", cplen = 1;
  46. length = sprintf (buf, "of:N%sT%s", of->node->name, of->node->type);
  47. buf += length;
  48. while (cplen > 0) {
  49. int l;
  50. length += sprintf (buf, "C%s", compat);
  51. buf += length;
  52. l = strlen (compat) + 1;
  53. compat += l;
  54. cplen -= l;
  55. }
  56. return length;
  57. }
  58. macio_config_of_attr (name, "%s\n");
  59. macio_config_of_attr (type, "%s\n");
  60. struct device_attribute macio_dev_attrs[] = {
  61. __ATTR_RO(name),
  62. __ATTR_RO(type),
  63. __ATTR_RO(compatible),
  64. __ATTR_RO(modalias),
  65. __ATTR_NULL
  66. };