sysfs.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <linux/kernel.h>
  2. #include <linux/stat.h>
  3. /* FIX UP */
  4. #include "soundbus.h"
  5. #define soundbus_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 soundbus_dev *mdev = to_soundbus_device (dev); \
  11. return sprintf (buf, format_string, mdev->ofdev.dev.of_node->field); \
  12. }
  13. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
  14. char *buf)
  15. {
  16. struct soundbus_dev *sdev = to_soundbus_device(dev);
  17. struct platform_device *of = &sdev->ofdev;
  18. int length;
  19. if (*sdev->modalias) {
  20. strlcpy(buf, sdev->modalias, sizeof(sdev->modalias) + 1);
  21. strcat(buf, "\n");
  22. length = strlen(buf);
  23. } else {
  24. length = sprintf(buf, "of:N%sT%s\n",
  25. of->dev.of_node->name, of->dev.of_node->type);
  26. }
  27. return length;
  28. }
  29. soundbus_config_of_attr (name, "%s\n");
  30. soundbus_config_of_attr (type, "%s\n");
  31. struct device_attribute soundbus_dev_attrs[] = {
  32. __ATTR_RO(name),
  33. __ATTR_RO(type),
  34. __ATTR_RO(modalias),
  35. __ATTR_NULL
  36. };