macio_sysfs.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/kernel.h>
  3. #include <linux/of.h>
  4. #include <linux/of_device.h>
  5. #include <linux/stat.h>
  6. #include <asm/macio.h>
  7. static ssize_t
  8. compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
  9. {
  10. struct platform_device *of;
  11. const char *compat;
  12. int cplen;
  13. int length = 0;
  14. of = &to_macio_device (dev)->ofdev;
  15. compat = of_get_property(of->dev.of_node, "compatible", &cplen);
  16. if (!compat) {
  17. *buf = '\0';
  18. return 0;
  19. }
  20. while (cplen > 0) {
  21. int l;
  22. length += sprintf (buf, "%s\n", compat);
  23. buf += length;
  24. l = strlen (compat) + 1;
  25. compat += l;
  26. cplen -= l;
  27. }
  28. return length;
  29. }
  30. static DEVICE_ATTR_RO(compatible);
  31. static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
  32. char *buf)
  33. {
  34. return of_device_modalias(dev, buf, PAGE_SIZE);
  35. }
  36. static ssize_t devspec_show(struct device *dev,
  37. struct device_attribute *attr, char *buf)
  38. {
  39. struct platform_device *ofdev;
  40. ofdev = to_platform_device(dev);
  41. return sprintf(buf, "%pOF\n", ofdev->dev.of_node);
  42. }
  43. static DEVICE_ATTR_RO(modalias);
  44. static DEVICE_ATTR_RO(devspec);
  45. static ssize_t name_show(struct device *dev,
  46. struct device_attribute *attr, char *buf)
  47. {
  48. return sprintf(buf, "%pOFn\n", dev->of_node);
  49. }
  50. static DEVICE_ATTR_RO(name);
  51. static ssize_t type_show(struct device *dev,
  52. struct device_attribute *attr, char *buf)
  53. {
  54. return sprintf(buf, "%s\n", of_node_get_device_type(dev->of_node));
  55. }
  56. static DEVICE_ATTR_RO(type);
  57. static struct attribute *macio_dev_attrs[] = {
  58. &dev_attr_name.attr,
  59. &dev_attr_type.attr,
  60. &dev_attr_compatible.attr,
  61. &dev_attr_modalias.attr,
  62. &dev_attr_devspec.attr,
  63. NULL,
  64. };
  65. static const struct attribute_group macio_dev_group = {
  66. .attrs = macio_dev_attrs,
  67. };
  68. const struct attribute_group *macio_dev_groups[] = {
  69. &macio_dev_group,
  70. NULL,
  71. };