blob: 133b4280660cfc2f9b651a56a95502991e21840b [file] [log] [blame]
Alexander Aringe23e9ec2014-10-28 18:21:32 +01001/* 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
18#include <net/cfg802154.h>
19
Alexander Aringa5dd1d72014-11-02 04:18:35 +010020#include "core.h"
Alexander Aringc5fbbc42014-11-02 21:43:04 +010021#include "sysfs.h"
Alexander Aringa5dd1d72014-11-02 04:18:35 +010022
23static inline struct cfg802154_registered_device *
24dev_to_rdev(struct device *dev)
25{
26 return container_of(dev, struct cfg802154_registered_device,
27 wpan_phy.dev);
28}
29
Alexander Aringa6fd6932014-11-09 08:36:51 +010030#define SHOW_FMT(name, fmt, member) \
31static ssize_t name ## _show(struct device *dev, \
32 struct device_attribute *attr, \
33 char *buf) \
34{ \
35 return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \
36} \
37static DEVICE_ATTR_RO(name)
38
39SHOW_FMT(index, "%d", wpan_phy_idx);
40
41static ssize_t name_show(struct device *dev,
42 struct device_attribute *attr,
43 char *buf)
44{
45 struct wpan_phy *wpan_phy = &dev_to_rdev(dev)->wpan_phy;
46
47 return sprintf(buf, "%s\n", dev_name(&wpan_phy->dev));
48}
49static DEVICE_ATTR_RO(name);
50
Alexander Aringa5dd1d72014-11-02 04:18:35 +010051static void wpan_phy_release(struct device *dev)
Alexander Aringe23e9ec2014-10-28 18:21:32 +010052{
Alexander Aringa5dd1d72014-11-02 04:18:35 +010053 struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
Alexander Aringe23e9ec2014-10-28 18:21:32 +010054
Alexander Aringa5dd1d72014-11-02 04:18:35 +010055 cfg802154_dev_free(rdev);
Alexander Aringe23e9ec2014-10-28 18:21:32 +010056}
57
58static struct attribute *pmib_attrs[] = {
Alexander Aringa6fd6932014-11-09 08:36:51 +010059 &dev_attr_index.attr,
60 &dev_attr_name.attr,
Alexander Aringe23e9ec2014-10-28 18:21:32 +010061 NULL,
62};
63ATTRIBUTE_GROUPS(pmib);
64
65struct class wpan_phy_class = {
66 .name = "ieee802154",
67 .dev_release = wpan_phy_release,
68 .dev_groups = pmib_groups,
69};
70
71int wpan_phy_sysfs_init(void)
72{
73 return class_register(&wpan_phy_class);
74}
75
76void wpan_phy_sysfs_exit(void)
77{
78 class_unregister(&wpan_phy_class);
79}