sysfs.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. // Copyright (c) 2021 Intel Corporation
  3. #include <linux/device.h>
  4. #include <linux/kernel.h>
  5. #include <linux/peci.h>
  6. #include "internal.h"
  7. static int rescan_controller(struct device *dev, void *data)
  8. {
  9. if (dev->type != &peci_controller_type)
  10. return 0;
  11. return peci_controller_scan_devices(to_peci_controller(dev));
  12. }
  13. static ssize_t rescan_store(struct bus_type *bus, const char *buf, size_t count)
  14. {
  15. bool res;
  16. int ret;
  17. ret = kstrtobool(buf, &res);
  18. if (ret)
  19. return ret;
  20. if (!res)
  21. return count;
  22. ret = bus_for_each_dev(&peci_bus_type, NULL, NULL, rescan_controller);
  23. if (ret)
  24. return ret;
  25. return count;
  26. }
  27. static BUS_ATTR_WO(rescan);
  28. static struct attribute *peci_bus_attrs[] = {
  29. &bus_attr_rescan.attr,
  30. NULL
  31. };
  32. static const struct attribute_group peci_bus_group = {
  33. .attrs = peci_bus_attrs,
  34. };
  35. const struct attribute_group *peci_bus_groups[] = {
  36. &peci_bus_group,
  37. NULL
  38. };
  39. static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
  40. const char *buf, size_t count)
  41. {
  42. struct peci_device *device = to_peci_device(dev);
  43. bool res;
  44. int ret;
  45. ret = kstrtobool(buf, &res);
  46. if (ret)
  47. return ret;
  48. if (res && device_remove_file_self(dev, attr))
  49. peci_device_destroy(device);
  50. return count;
  51. }
  52. static DEVICE_ATTR_IGNORE_LOCKDEP(remove, 0200, NULL, remove_store);
  53. static struct attribute *peci_device_attrs[] = {
  54. &dev_attr_remove.attr,
  55. NULL
  56. };
  57. static const struct attribute_group peci_device_group = {
  58. .attrs = peci_device_attrs,
  59. };
  60. const struct attribute_group *peci_device_groups[] = {
  61. &peci_device_group,
  62. NULL
  63. };