sysfs.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. //
  3. // Copyright(c) 2020 Intel Corporation. All rights reserved.
  4. //
  5. // Author: Cezary Rojewski <[email protected]>
  6. //
  7. #include <linux/pm_runtime.h>
  8. #include "core.h"
  9. static ssize_t fw_version_show(struct device *dev,
  10. struct device_attribute *attr, char *buf)
  11. {
  12. struct catpt_dev *cdev = dev_get_drvdata(dev);
  13. struct catpt_fw_version version;
  14. int ret;
  15. ret = pm_runtime_resume_and_get(cdev->dev);
  16. if (ret < 0 && ret != -EACCES)
  17. return ret;
  18. ret = catpt_ipc_get_fw_version(cdev, &version);
  19. pm_runtime_mark_last_busy(cdev->dev);
  20. pm_runtime_put_autosuspend(cdev->dev);
  21. if (ret)
  22. return CATPT_IPC_ERROR(ret);
  23. return sysfs_emit(buf, "%d.%d.%d.%d\n", version.type, version.major,
  24. version.minor, version.build);
  25. }
  26. static DEVICE_ATTR_RO(fw_version);
  27. static ssize_t fw_info_show(struct device *dev,
  28. struct device_attribute *attr, char *buf)
  29. {
  30. struct catpt_dev *cdev = dev_get_drvdata(dev);
  31. return sysfs_emit(buf, "%s\n", cdev->ipc.config.fw_info);
  32. }
  33. static DEVICE_ATTR_RO(fw_info);
  34. static struct attribute *catpt_attrs[] = {
  35. &dev_attr_fw_version.attr,
  36. &dev_attr_fw_info.attr,
  37. NULL
  38. };
  39. static const struct attribute_group catpt_attr_group = {
  40. .attrs = catpt_attrs,
  41. };
  42. const struct attribute_group *catpt_attr_groups[] = {
  43. &catpt_attr_group,
  44. NULL
  45. };