Loading...
1/* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License version 2
3 * as published by the Free Software Foundation.
4 *
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.
9 *
10 * Authors:
11 * Alexander Aring <aar@pengutronix.de>
12 *
13 * Based on: net/wireless/sysfs.c
14 */
15
16#include <linux/device.h>
17#include <linux/rtnetlink.h>
18
19#include <net/cfg802154.h>
20
21#include "core.h"
22#include "sysfs.h"
23#include "rdev-ops.h"
24
25static inline struct cfg802154_registered_device *
26dev_to_rdev(struct device *dev)
27{
28 return container_of(dev, struct cfg802154_registered_device,
29 wpan_phy.dev);
30}
31
32#define SHOW_FMT(name, fmt, member) \
33static ssize_t name ## _show(struct device *dev, \
34 struct device_attribute *attr, \
35 char *buf) \
36{ \
37 return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \
38} \
39static DEVICE_ATTR_RO(name)
40
41SHOW_FMT(index, "%d", wpan_phy_idx);
42
43static ssize_t name_show(struct device *dev,
44 struct device_attribute *attr,
45 char *buf)
46{
47 struct wpan_phy *wpan_phy = &dev_to_rdev(dev)->wpan_phy;
48
49 return sprintf(buf, "%s\n", dev_name(&wpan_phy->dev));
50}
51static DEVICE_ATTR_RO(name);
52
53static void wpan_phy_release(struct device *dev)
54{
55 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
56
57 cfg802154_dev_free(rdev);
58}
59
60static struct attribute *pmib_attrs[] = {
61 &dev_attr_index.attr,
62 &dev_attr_name.attr,
63 NULL,
64};
65ATTRIBUTE_GROUPS(pmib);
66
67#ifdef CONFIG_PM_SLEEP
68static int wpan_phy_suspend(struct device *dev)
69{
70 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
71 int ret = 0;
72
73 if (rdev->ops->suspend) {
74 rtnl_lock();
75 ret = rdev_suspend(rdev);
76 rtnl_unlock();
77 }
78
79 return ret;
80}
81
82static int wpan_phy_resume(struct device *dev)
83{
84 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
85 int ret = 0;
86
87 if (rdev->ops->resume) {
88 rtnl_lock();
89 ret = rdev_resume(rdev);
90 rtnl_unlock();
91 }
92
93 return ret;
94}
95
96static SIMPLE_DEV_PM_OPS(wpan_phy_pm_ops, wpan_phy_suspend, wpan_phy_resume);
97#define WPAN_PHY_PM_OPS (&wpan_phy_pm_ops)
98#else
99#define WPAN_PHY_PM_OPS NULL
100#endif
101
102struct class wpan_phy_class = {
103 .name = "ieee802154",
104 .dev_release = wpan_phy_release,
105 .dev_groups = pmib_groups,
106 .pm = WPAN_PHY_PM_OPS,
107};
108
109int wpan_phy_sysfs_init(void)
110{
111 return class_register(&wpan_phy_class);
112}
113
114void wpan_phy_sysfs_exit(void)
115{
116 class_unregister(&wpan_phy_class);
117}
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 *
4 * Authors:
5 * Alexander Aring <aar@pengutronix.de>
6 *
7 * Based on: net/wireless/sysfs.c
8 */
9
10#include <linux/device.h>
11#include <linux/rtnetlink.h>
12
13#include <net/cfg802154.h>
14
15#include "core.h"
16#include "sysfs.h"
17#include "rdev-ops.h"
18
19static inline struct cfg802154_registered_device *
20dev_to_rdev(struct device *dev)
21{
22 return container_of(dev, struct cfg802154_registered_device,
23 wpan_phy.dev);
24}
25
26#define SHOW_FMT(name, fmt, member) \
27static ssize_t name ## _show(struct device *dev, \
28 struct device_attribute *attr, \
29 char *buf) \
30{ \
31 return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \
32} \
33static DEVICE_ATTR_RO(name)
34
35SHOW_FMT(index, "%d", wpan_phy_idx);
36
37static ssize_t name_show(struct device *dev,
38 struct device_attribute *attr,
39 char *buf)
40{
41 struct wpan_phy *wpan_phy = &dev_to_rdev(dev)->wpan_phy;
42
43 return sprintf(buf, "%s\n", dev_name(&wpan_phy->dev));
44}
45static DEVICE_ATTR_RO(name);
46
47static void wpan_phy_release(struct device *dev)
48{
49 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
50
51 cfg802154_dev_free(rdev);
52}
53
54static struct attribute *pmib_attrs[] = {
55 &dev_attr_index.attr,
56 &dev_attr_name.attr,
57 NULL,
58};
59ATTRIBUTE_GROUPS(pmib);
60
61#ifdef CONFIG_PM_SLEEP
62static int wpan_phy_suspend(struct device *dev)
63{
64 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
65 int ret = 0;
66
67 if (rdev->ops->suspend) {
68 rtnl_lock();
69 ret = rdev_suspend(rdev);
70 rtnl_unlock();
71 }
72
73 return ret;
74}
75
76static int wpan_phy_resume(struct device *dev)
77{
78 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
79 int ret = 0;
80
81 if (rdev->ops->resume) {
82 rtnl_lock();
83 ret = rdev_resume(rdev);
84 rtnl_unlock();
85 }
86
87 return ret;
88}
89
90static SIMPLE_DEV_PM_OPS(wpan_phy_pm_ops, wpan_phy_suspend, wpan_phy_resume);
91#define WPAN_PHY_PM_OPS (&wpan_phy_pm_ops)
92#else
93#define WPAN_PHY_PM_OPS NULL
94#endif
95
96struct class wpan_phy_class = {
97 .name = "ieee802154",
98 .dev_release = wpan_phy_release,
99 .dev_groups = pmib_groups,
100 .pm = WPAN_PHY_PM_OPS,
101};
102
103int wpan_phy_sysfs_init(void)
104{
105 return class_register(&wpan_phy_class);
106}
107
108void wpan_phy_sysfs_exit(void)
109{
110 class_unregister(&wpan_phy_class);
111}