pal.c 2.2 KB

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