1 // SPDX-License-Identifier: GPL-2.0-only
5 * Alexander Aring <aar@pengutronix.de>
7 * Based on: net/wireless/sysfs.c
10 #include <linux/device.h>
11 #include <linux/rtnetlink.h>
13 #include <net/cfg802154.h>
19 static inline struct cfg802154_registered_device *
20 dev_to_rdev(struct device *dev)
22 return container_of(dev, struct cfg802154_registered_device,
26 #define SHOW_FMT(name, fmt, member) \
27 static ssize_t name ## _show(struct device *dev, \
28 struct device_attribute *attr, \
31 return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \
33 static DEVICE_ATTR_RO(name)
35 SHOW_FMT(index, "%d", wpan_phy_idx);
37 static ssize_t name_show(struct device *dev,
38 struct device_attribute *attr,
41 struct wpan_phy *wpan_phy = &dev_to_rdev(dev)->wpan_phy;
43 return sprintf(buf, "%s\n", dev_name(&wpan_phy->dev));
45 static DEVICE_ATTR_RO(name);
47 static void wpan_phy_release(struct device *dev)
49 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
51 cfg802154_dev_free(rdev);
54 static struct attribute *pmib_attrs[] = {
59 ATTRIBUTE_GROUPS(pmib);
61 #ifdef CONFIG_PM_SLEEP
62 static int wpan_phy_suspend(struct device *dev)
64 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
67 if (rdev->ops->suspend) {
69 ret = rdev_suspend(rdev);
76 static int wpan_phy_resume(struct device *dev)
78 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
81 if (rdev->ops->resume) {
83 ret = rdev_resume(rdev);
90 static SIMPLE_DEV_PM_OPS(wpan_phy_pm_ops, wpan_phy_suspend, wpan_phy_resume);
91 #define WPAN_PHY_PM_OPS (&wpan_phy_pm_ops)
93 #define WPAN_PHY_PM_OPS NULL
96 struct class wpan_phy_class = {
98 .dev_release = wpan_phy_release,
99 .dev_groups = pmib_groups,
100 .pm = WPAN_PHY_PM_OPS,
103 int wpan_phy_sysfs_init(void)
105 return class_register(&wpan_phy_class);
108 void wpan_phy_sysfs_exit(void)
110 class_unregister(&wpan_phy_class);