macio_sysfs.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 DEVICE_ATTR_RO(field);
  13. static ssize_t
  14. compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
  15. {
  16. struct platform_device *of;
  17. const char *compat;
  18. int cplen;
  19. int length = 0;
  20. of = &to_macio_device (dev)->ofdev;
  21. compat = of_get_property(of->dev.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 DEVICE_ATTR_RO(compatible);
  37. static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
  38. char *buf)
  39. {
  40. return of_device_modalias(dev, buf, PAGE_SIZE);
  41. }
  42. static ssize_t devspec_show(struct device *dev,
  43. struct device_attribute *attr, char *buf)
  44. {
  45. struct platform_device *ofdev;
  46. ofdev = to_platform_device(dev);
  47. return sprintf(buf, "%pOF\n", ofdev->dev.of_node);
  48. }
  49. static DEVICE_ATTR_RO(modalias);
  50. static DEVICE_ATTR_RO(devspec);
  51. macio_config_of_attr (name, "%s\n");
  52. macio_config_of_attr (type, "%s\n");
  53. static struct attribute *macio_dev_attrs[] = {
  54. &dev_attr_name.attr,
  55. &dev_attr_type.attr,
  56. &dev_attr_compatible.attr,
  57. &dev_attr_modalias.attr,
  58. &dev_attr_devspec.attr,
  59. NULL,
  60. };
  61. static const struct attribute_group macio_dev_group = {
  62. .attrs = macio_dev_attrs,
  63. };
  64. const struct attribute_group *macio_dev_groups[] = {
  65. &macio_dev_group,
  66. NULL,
  67. };