sysfs.c 1.1 KB

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