Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / peci / sysfs.c
blobc04244075794c7e0a6581d66fcc2c955b2cc1b80
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2021 Intel Corporation
4 #include <linux/device.h>
5 #include <linux/kernel.h>
6 #include <linux/peci.h>
8 #include "internal.h"
10 static int rescan_controller(struct device *dev, void *data)
12 if (dev->type != &peci_controller_type)
13 return 0;
15 return peci_controller_scan_devices(to_peci_controller(dev));
18 static ssize_t rescan_store(const struct bus_type *bus, const char *buf, size_t count)
20 bool res;
21 int ret;
23 ret = kstrtobool(buf, &res);
24 if (ret)
25 return ret;
27 if (!res)
28 return count;
30 ret = bus_for_each_dev(&peci_bus_type, NULL, NULL, rescan_controller);
31 if (ret)
32 return ret;
34 return count;
36 static BUS_ATTR_WO(rescan);
38 static struct attribute *peci_bus_attrs[] = {
39 &bus_attr_rescan.attr,
40 NULL
43 static const struct attribute_group peci_bus_group = {
44 .attrs = peci_bus_attrs,
47 const struct attribute_group *peci_bus_groups[] = {
48 &peci_bus_group,
49 NULL
52 static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
53 const char *buf, size_t count)
55 struct peci_device *device = to_peci_device(dev);
56 bool res;
57 int ret;
59 ret = kstrtobool(buf, &res);
60 if (ret)
61 return ret;
63 if (res && device_remove_file_self(dev, attr))
64 peci_device_destroy(device);
66 return count;
68 static DEVICE_ATTR_IGNORE_LOCKDEP(remove, 0200, NULL, remove_store);
70 static struct attribute *peci_device_attrs[] = {
71 &dev_attr_remove.attr,
72 NULL
75 static const struct attribute_group peci_device_group = {
76 .attrs = peci_device_attrs,
79 const struct attribute_group *peci_device_groups[] = {
80 &peci_device_group,
81 NULL