pal.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * UWB PAL support.
  3. *
  4. * Copyright (C) 2008 Cambridge Silicon Radio Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/debugfs.h>
  20. #include <linux/uwb.h>
  21. #include <linux/export.h>
  22. #include "uwb-internal.h"
  23. /**
  24. * uwb_pal_init - initialize a UWB PAL
  25. * @pal: the PAL to initialize
  26. */
  27. void uwb_pal_init(struct uwb_pal *pal)
  28. {
  29. INIT_LIST_HEAD(&pal->node);
  30. }
  31. EXPORT_SYMBOL_GPL(uwb_pal_init);
  32. /**
  33. * uwb_pal_register - register a UWB PAL
  34. * @pal: the PAL
  35. *
  36. * The PAL must be initialized with uwb_pal_init().
  37. */
  38. int uwb_pal_register(struct uwb_pal *pal)
  39. {
  40. struct uwb_rc *rc = pal->rc;
  41. int ret;
  42. if (pal->device) {
  43. ret = sysfs_create_link(&pal->device->kobj,
  44. &rc->uwb_dev.dev.kobj, "uwb_rc");
  45. if (ret < 0)
  46. return ret;
  47. ret = sysfs_create_link(&rc->uwb_dev.dev.kobj,
  48. &pal->device->kobj, pal->name);
  49. if (ret < 0) {
  50. sysfs_remove_link(&pal->device->kobj, "uwb_rc");
  51. return ret;
  52. }
  53. }
  54. pal->debugfs_dir = uwb_dbg_create_pal_dir(pal);
  55. mutex_lock(&rc->uwb_dev.mutex);
  56. list_add(&pal->node, &rc->pals);
  57. mutex_unlock(&rc->uwb_dev.mutex);
  58. return 0;
  59. }
  60. EXPORT_SYMBOL_GPL(uwb_pal_register);
  61. /**
  62. * uwb_pal_register - unregister a UWB PAL
  63. * @pal: the PAL
  64. */
  65. void uwb_pal_unregister(struct uwb_pal *pal)
  66. {
  67. struct uwb_rc *rc = pal->rc;
  68. uwb_radio_stop(pal);
  69. mutex_lock(&rc->uwb_dev.mutex);
  70. list_del(&pal->node);
  71. mutex_unlock(&rc->uwb_dev.mutex);
  72. debugfs_remove(pal->debugfs_dir);
  73. if (pal->device) {
  74. sysfs_remove_link(&rc->uwb_dev.dev.kobj, pal->name);
  75. sysfs_remove_link(&pal->device->kobj, "uwb_rc");
  76. }
  77. }
  78. EXPORT_SYMBOL_GPL(uwb_pal_unregister);
  79. /**
  80. * uwb_rc_pal_init - initialize the PAL related parts of a radio controller
  81. * @rc: the radio controller
  82. */
  83. void uwb_rc_pal_init(struct uwb_rc *rc)
  84. {
  85. INIT_LIST_HEAD(&rc->pals);
  86. }