sysfs.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include <linux/device.h>
  16. #include <net/cfg802154.h>
  17. #include "core.h"
  18. #include "sysfs.h"
  19. static inline struct cfg802154_registered_device *
  20. dev_to_rdev(struct device *dev)
  21. {
  22. return container_of(dev, struct cfg802154_registered_device,
  23. wpan_phy.dev);
  24. }
  25. #define SHOW_FMT(name, fmt, member) \
  26. static ssize_t name ## _show(struct device *dev, \
  27. struct device_attribute *attr, \
  28. char *buf) \
  29. { \
  30. return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \
  31. } \
  32. static DEVICE_ATTR_RO(name)
  33. SHOW_FMT(index, "%d", wpan_phy_idx);
  34. static ssize_t name_show(struct device *dev,
  35. struct device_attribute *attr,
  36. char *buf)
  37. {
  38. struct wpan_phy *wpan_phy = &dev_to_rdev(dev)->wpan_phy;
  39. return sprintf(buf, "%s\n", dev_name(&wpan_phy->dev));
  40. }
  41. static DEVICE_ATTR_RO(name);
  42. static void wpan_phy_release(struct device *dev)
  43. {
  44. struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
  45. cfg802154_dev_free(rdev);
  46. }
  47. static struct attribute *pmib_attrs[] = {
  48. &dev_attr_index.attr,
  49. &dev_attr_name.attr,
  50. NULL,
  51. };
  52. ATTRIBUTE_GROUPS(pmib);
  53. struct class wpan_phy_class = {
  54. .name = "ieee802154",
  55. .dev_release = wpan_phy_release,
  56. .dev_groups = pmib_groups,
  57. };
  58. int wpan_phy_sysfs_init(void)
  59. {
  60. return class_register(&wpan_phy_class);
  61. }
  62. void wpan_phy_sysfs_exit(void)
  63. {
  64. class_unregister(&wpan_phy_class);
  65. }