driver.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Ultra Wide Band
  3. * Driver initialization, etc
  4. *
  5. * Copyright (C) 2005-2006 Intel Corporation
  6. * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License version
  10. * 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301, USA.
  21. *
  22. *
  23. * FIXME: docs
  24. *
  25. * Life cycle: FIXME: explain
  26. *
  27. * UWB radio controller:
  28. *
  29. * 1. alloc a uwb_rc, zero it
  30. * 2. call uwb_rc_init() on it to set it up + ops (won't do any
  31. * kind of allocation)
  32. * 3. register (now it is owned by the UWB stack--deregister before
  33. * freeing/destroying).
  34. * 4. It lives on it's own now (UWB stack handles)--when it
  35. * disconnects, call unregister()
  36. * 5. free it.
  37. *
  38. * Make sure you have a reference to the uwb_rc before calling
  39. * any of the UWB API functions.
  40. *
  41. * TODO:
  42. *
  43. * 1. Locking and life cycle management is crappy still. All entry
  44. * points to the UWB HCD API assume you have a reference on the
  45. * uwb_rc structure and that it won't go away. They mutex lock it
  46. * before doing anything.
  47. */
  48. #include <linux/kernel.h>
  49. #include <linux/init.h>
  50. #include <linux/module.h>
  51. #include <linux/device.h>
  52. #include <linux/err.h>
  53. #include <linux/kdev_t.h>
  54. #include <linux/random.h>
  55. #include "uwb-internal.h"
  56. /* UWB stack attributes (or 'global' constants) */
  57. /**
  58. * If a beacon disappears for longer than this, then we consider the
  59. * device who was represented by that beacon to be gone.
  60. *
  61. * ECMA-368[17.2.3, last para] establishes that a device must not
  62. * consider a device to be its neighbour if he doesn't receive a beacon
  63. * for more than mMaxLostBeacons. mMaxLostBeacons is defined in
  64. * ECMA-368[17.16] as 3; because we can get only one beacon per
  65. * superframe, that'd be 3 * 65ms = 195 ~ 200 ms. Let's give it time
  66. * for jitter and stuff and make it 500 ms.
  67. */
  68. unsigned long beacon_timeout_ms = 500;
  69. static
  70. ssize_t beacon_timeout_ms_show(struct class *class,
  71. struct class_attribute *attr,
  72. char *buf)
  73. {
  74. return scnprintf(buf, PAGE_SIZE, "%lu\n", beacon_timeout_ms);
  75. }
  76. static
  77. ssize_t beacon_timeout_ms_store(struct class *class,
  78. struct class_attribute *attr,
  79. const char *buf, size_t size)
  80. {
  81. unsigned long bt;
  82. ssize_t result;
  83. result = sscanf(buf, "%lu", &bt);
  84. if (result != 1)
  85. return -EINVAL;
  86. beacon_timeout_ms = bt;
  87. return size;
  88. }
  89. static struct class_attribute uwb_class_attrs[] = {
  90. __ATTR(beacon_timeout_ms, S_IWUSR | S_IRUGO,
  91. beacon_timeout_ms_show, beacon_timeout_ms_store),
  92. __ATTR_NULL,
  93. };
  94. /** Device model classes */
  95. struct class uwb_rc_class = {
  96. .name = "uwb_rc",
  97. .class_attrs = uwb_class_attrs,
  98. };
  99. static int __init uwb_subsys_init(void)
  100. {
  101. int result = 0;
  102. result = uwb_est_create();
  103. if (result < 0) {
  104. printk(KERN_ERR "uwb: Can't initialize EST subsystem\n");
  105. goto error_est_init;
  106. }
  107. result = class_register(&uwb_rc_class);
  108. if (result < 0)
  109. goto error_uwb_rc_class_register;
  110. uwb_dbg_init();
  111. return 0;
  112. error_uwb_rc_class_register:
  113. uwb_est_destroy();
  114. error_est_init:
  115. return result;
  116. }
  117. module_init(uwb_subsys_init);
  118. static void __exit uwb_subsys_exit(void)
  119. {
  120. uwb_dbg_exit();
  121. class_unregister(&uwb_rc_class);
  122. uwb_est_destroy();
  123. return;
  124. }
  125. module_exit(uwb_subsys_exit);
  126. MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>");
  127. MODULE_DESCRIPTION("Ultra Wide Band core");
  128. MODULE_LICENSE("GPL");