0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/device.h>
0011 #include <linux/rtnetlink.h>
0012
0013 #include <net/cfg802154.h>
0014
0015 #include "core.h"
0016 #include "sysfs.h"
0017 #include "rdev-ops.h"
0018
0019 static inline struct cfg802154_registered_device *
0020 dev_to_rdev(struct device *dev)
0021 {
0022 return container_of(dev, struct cfg802154_registered_device,
0023 wpan_phy.dev);
0024 }
0025
0026 #define SHOW_FMT(name, fmt, member) \
0027 static ssize_t name ## _show(struct device *dev, \
0028 struct device_attribute *attr, \
0029 char *buf) \
0030 { \
0031 return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \
0032 } \
0033 static DEVICE_ATTR_RO(name)
0034
0035 SHOW_FMT(index, "%d", wpan_phy_idx);
0036
0037 static ssize_t name_show(struct device *dev,
0038 struct device_attribute *attr,
0039 char *buf)
0040 {
0041 struct wpan_phy *wpan_phy = &dev_to_rdev(dev)->wpan_phy;
0042
0043 return sprintf(buf, "%s\n", dev_name(&wpan_phy->dev));
0044 }
0045 static DEVICE_ATTR_RO(name);
0046
0047 static void wpan_phy_release(struct device *dev)
0048 {
0049 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
0050
0051 cfg802154_dev_free(rdev);
0052 }
0053
0054 static struct attribute *pmib_attrs[] = {
0055 &dev_attr_index.attr,
0056 &dev_attr_name.attr,
0057 NULL,
0058 };
0059 ATTRIBUTE_GROUPS(pmib);
0060
0061 #ifdef CONFIG_PM_SLEEP
0062 static int wpan_phy_suspend(struct device *dev)
0063 {
0064 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
0065 int ret = 0;
0066
0067 if (rdev->ops->suspend) {
0068 rtnl_lock();
0069 ret = rdev_suspend(rdev);
0070 rtnl_unlock();
0071 }
0072
0073 return ret;
0074 }
0075
0076 static int wpan_phy_resume(struct device *dev)
0077 {
0078 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
0079 int ret = 0;
0080
0081 if (rdev->ops->resume) {
0082 rtnl_lock();
0083 ret = rdev_resume(rdev);
0084 rtnl_unlock();
0085 }
0086
0087 return ret;
0088 }
0089
0090 static SIMPLE_DEV_PM_OPS(wpan_phy_pm_ops, wpan_phy_suspend, wpan_phy_resume);
0091 #define WPAN_PHY_PM_OPS (&wpan_phy_pm_ops)
0092 #else
0093 #define WPAN_PHY_PM_OPS NULL
0094 #endif
0095
0096 struct class wpan_phy_class = {
0097 .name = "ieee802154",
0098 .dev_release = wpan_phy_release,
0099 .dev_groups = pmib_groups,
0100 .pm = WPAN_PHY_PM_OPS,
0101 };
0102
0103 int wpan_phy_sysfs_init(void)
0104 {
0105 return class_register(&wpan_phy_class);
0106 }
0107
0108 void wpan_phy_sysfs_exit(void)
0109 {
0110 class_unregister(&wpan_phy_class);
0111 }