pal.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. /* create a link to the uwb_rc in the PAL device's directory. */
  44. ret = sysfs_create_link(&pal->device->kobj,
  45. &rc->uwb_dev.dev.kobj, "uwb_rc");
  46. if (ret < 0)
  47. return ret;
  48. /* create a link to the PAL in the UWB device's directory. */
  49. ret = sysfs_create_link(&rc->uwb_dev.dev.kobj,
  50. &pal->device->kobj, pal->name);
  51. if (ret < 0) {
  52. sysfs_remove_link(&pal->device->kobj, "uwb_rc");
  53. return ret;
  54. }
  55. }
  56. pal->debugfs_dir = uwb_dbg_create_pal_dir(pal);
  57. mutex_lock(&rc->uwb_dev.mutex);
  58. list_add(&pal->node, &rc->pals);
  59. mutex_unlock(&rc->uwb_dev.mutex);
  60. return 0;
  61. }
  62. EXPORT_SYMBOL_GPL(uwb_pal_register);
  63. /**
  64. * uwb_pal_register - unregister a UWB PAL
  65. * @pal: the PAL
  66. */
  67. void uwb_pal_unregister(struct uwb_pal *pal)
  68. {
  69. struct uwb_rc *rc = pal->rc;
  70. uwb_radio_stop(pal);
  71. mutex_lock(&rc->uwb_dev.mutex);
  72. list_del(&pal->node);
  73. mutex_unlock(&rc->uwb_dev.mutex);
  74. debugfs_remove(pal->debugfs_dir);
  75. if (pal->device) {
  76. sysfs_remove_link(&rc->uwb_dev.dev.kobj, pal->name);
  77. sysfs_remove_link(&pal->device->kobj, "uwb_rc");
  78. }
  79. }
  80. EXPORT_SYMBOL_GPL(uwb_pal_unregister);
  81. /**
  82. * uwb_rc_pal_init - initialize the PAL related parts of a radio controller
  83. * @rc: the radio controller
  84. */
  85. void uwb_rc_pal_init(struct uwb_rc *rc)
  86. {
  87. INIT_LIST_HEAD(&rc->pals);
  88. }