pal.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "uwb-internal.h"
  22. /**
  23. * uwb_pal_init - initialize a UWB PAL
  24. * @pal: the PAL to initialize
  25. */
  26. void uwb_pal_init(struct uwb_pal *pal)
  27. {
  28. INIT_LIST_HEAD(&pal->node);
  29. }
  30. EXPORT_SYMBOL_GPL(uwb_pal_init);
  31. /**
  32. * uwb_pal_register - register a UWB PAL
  33. * @pal: the PAL
  34. *
  35. * The PAL must be initialized with uwb_pal_init().
  36. */
  37. int uwb_pal_register(struct uwb_pal *pal)
  38. {
  39. struct uwb_rc *rc = pal->rc;
  40. int ret;
  41. if (pal->device) {
  42. ret = sysfs_create_link(&pal->device->kobj,
  43. &rc->uwb_dev.dev.kobj, "uwb_rc");
  44. if (ret < 0)
  45. return ret;
  46. ret = sysfs_create_link(&rc->uwb_dev.dev.kobj,
  47. &pal->device->kobj, pal->name);
  48. if (ret < 0) {
  49. sysfs_remove_link(&pal->device->kobj, "uwb_rc");
  50. return ret;
  51. }
  52. }
  53. pal->debugfs_dir = uwb_dbg_create_pal_dir(pal);
  54. mutex_lock(&rc->uwb_dev.mutex);
  55. list_add(&pal->node, &rc->pals);
  56. mutex_unlock(&rc->uwb_dev.mutex);
  57. return 0;
  58. }
  59. EXPORT_SYMBOL_GPL(uwb_pal_register);
  60. /**
  61. * uwb_pal_register - unregister a UWB PAL
  62. * @pal: the PAL
  63. */
  64. void uwb_pal_unregister(struct uwb_pal *pal)
  65. {
  66. struct uwb_rc *rc = pal->rc;
  67. uwb_radio_stop(pal);
  68. mutex_lock(&rc->uwb_dev.mutex);
  69. list_del(&pal->node);
  70. mutex_unlock(&rc->uwb_dev.mutex);
  71. debugfs_remove(pal->debugfs_dir);
  72. if (pal->device) {
  73. sysfs_remove_link(&rc->uwb_dev.dev.kobj, pal->name);
  74. sysfs_remove_link(&pal->device->kobj, "uwb_rc");
  75. }
  76. }
  77. EXPORT_SYMBOL_GPL(uwb_pal_unregister);
  78. /**
  79. * uwb_rc_pal_init - initialize the PAL related parts of a radio controller
  80. * @rc: the radio controller
  81. */
  82. void uwb_rc_pal_init(struct uwb_rc *rc)
  83. {
  84. INIT_LIST_HEAD(&rc->pals);
  85. }