bus.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. Broadcom B43 wireless driver
  3. Bus abstraction layer
  4. Copyright (c) 2011 Rafał Miłecki <zajec5@gmail.com>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; see the file COPYING. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  16. Boston, MA 02110-1301, USA.
  17. */
  18. #include "b43.h"
  19. #include "bus.h"
  20. /* BCMA */
  21. #ifdef CONFIG_B43_BCMA
  22. static int b43_bus_bcma_bus_may_powerdown(struct b43_bus_dev *dev)
  23. {
  24. return 0; /* bcma_bus_may_powerdown(dev->bdev->bus); */
  25. }
  26. static int b43_bus_bcma_bus_powerup(struct b43_bus_dev *dev,
  27. bool dynamic_pctl)
  28. {
  29. return 0; /* bcma_bus_powerup(dev->sdev->bus, dynamic_pctl); */
  30. }
  31. static int b43_bus_bcma_device_is_enabled(struct b43_bus_dev *dev)
  32. {
  33. return bcma_core_is_enabled(dev->bdev);
  34. }
  35. static void b43_bus_bcma_device_enable(struct b43_bus_dev *dev,
  36. u32 core_specific_flags)
  37. {
  38. bcma_core_enable(dev->bdev, core_specific_flags);
  39. }
  40. static void b43_bus_bcma_device_disable(struct b43_bus_dev *dev,
  41. u32 core_specific_flags)
  42. {
  43. bcma_core_disable(dev->bdev, core_specific_flags);
  44. }
  45. static u16 b43_bus_bcma_read16(struct b43_bus_dev *dev, u16 offset)
  46. {
  47. return bcma_read16(dev->bdev, offset);
  48. }
  49. static u32 b43_bus_bcma_read32(struct b43_bus_dev *dev, u16 offset)
  50. {
  51. return bcma_read32(dev->bdev, offset);
  52. }
  53. static
  54. void b43_bus_bcma_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
  55. {
  56. bcma_write16(dev->bdev, offset, value);
  57. }
  58. static
  59. void b43_bus_bcma_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
  60. {
  61. bcma_write32(dev->bdev, offset, value);
  62. }
  63. static
  64. void b43_bus_bcma_block_read(struct b43_bus_dev *dev, void *buffer,
  65. size_t count, u16 offset, u8 reg_width)
  66. {
  67. bcma_block_read(dev->bdev, buffer, count, offset, reg_width);
  68. }
  69. static
  70. void b43_bus_bcma_block_write(struct b43_bus_dev *dev, const void *buffer,
  71. size_t count, u16 offset, u8 reg_width)
  72. {
  73. bcma_block_write(dev->bdev, buffer, count, offset, reg_width);
  74. }
  75. struct b43_bus_dev *b43_bus_dev_bcma_init(struct bcma_device *core)
  76. {
  77. struct b43_bus_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  78. if (!dev)
  79. return NULL;
  80. dev->bus_type = B43_BUS_BCMA;
  81. dev->bdev = core;
  82. dev->bus_may_powerdown = b43_bus_bcma_bus_may_powerdown;
  83. dev->bus_powerup = b43_bus_bcma_bus_powerup;
  84. dev->device_is_enabled = b43_bus_bcma_device_is_enabled;
  85. dev->device_enable = b43_bus_bcma_device_enable;
  86. dev->device_disable = b43_bus_bcma_device_disable;
  87. dev->read16 = b43_bus_bcma_read16;
  88. dev->read32 = b43_bus_bcma_read32;
  89. dev->write16 = b43_bus_bcma_write16;
  90. dev->write32 = b43_bus_bcma_write32;
  91. dev->block_read = b43_bus_bcma_block_read;
  92. dev->block_write = b43_bus_bcma_block_write;
  93. dev->dev = &core->dev;
  94. dev->dma_dev = core->dma_dev;
  95. dev->irq = core->irq;
  96. /*
  97. dev->board_vendor = core->bus->boardinfo.vendor;
  98. dev->board_type = core->bus->boardinfo.type;
  99. dev->board_rev = core->bus->boardinfo.rev;
  100. */
  101. dev->chip_id = core->bus->chipinfo.id;
  102. dev->chip_rev = core->bus->chipinfo.rev;
  103. dev->chip_pkg = core->bus->chipinfo.pkg;
  104. dev->bus_sprom = &core->bus->sprom;
  105. dev->core_id = core->id.id;
  106. dev->core_rev = core->id.rev;
  107. return dev;
  108. }
  109. #endif /* CONFIG_B43_BCMA */
  110. /* SSB */
  111. #ifdef CONFIG_B43_SSB
  112. static int b43_bus_ssb_bus_may_powerdown(struct b43_bus_dev *dev)
  113. {
  114. return ssb_bus_may_powerdown(dev->sdev->bus);
  115. }
  116. static int b43_bus_ssb_bus_powerup(struct b43_bus_dev *dev,
  117. bool dynamic_pctl)
  118. {
  119. return ssb_bus_powerup(dev->sdev->bus, dynamic_pctl);
  120. }
  121. static int b43_bus_ssb_device_is_enabled(struct b43_bus_dev *dev)
  122. {
  123. return ssb_device_is_enabled(dev->sdev);
  124. }
  125. static void b43_bus_ssb_device_enable(struct b43_bus_dev *dev,
  126. u32 core_specific_flags)
  127. {
  128. ssb_device_enable(dev->sdev, core_specific_flags);
  129. }
  130. static void b43_bus_ssb_device_disable(struct b43_bus_dev *dev,
  131. u32 core_specific_flags)
  132. {
  133. ssb_device_disable(dev->sdev, core_specific_flags);
  134. }
  135. static u16 b43_bus_ssb_read16(struct b43_bus_dev *dev, u16 offset)
  136. {
  137. return ssb_read16(dev->sdev, offset);
  138. }
  139. static u32 b43_bus_ssb_read32(struct b43_bus_dev *dev, u16 offset)
  140. {
  141. return ssb_read32(dev->sdev, offset);
  142. }
  143. static void b43_bus_ssb_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
  144. {
  145. ssb_write16(dev->sdev, offset, value);
  146. }
  147. static void b43_bus_ssb_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
  148. {
  149. ssb_write32(dev->sdev, offset, value);
  150. }
  151. static void b43_bus_ssb_block_read(struct b43_bus_dev *dev, void *buffer,
  152. size_t count, u16 offset, u8 reg_width)
  153. {
  154. ssb_block_read(dev->sdev, buffer, count, offset, reg_width);
  155. }
  156. static
  157. void b43_bus_ssb_block_write(struct b43_bus_dev *dev, const void *buffer,
  158. size_t count, u16 offset, u8 reg_width)
  159. {
  160. ssb_block_write(dev->sdev, buffer, count, offset, reg_width);
  161. }
  162. struct b43_bus_dev *b43_bus_dev_ssb_init(struct ssb_device *sdev)
  163. {
  164. struct b43_bus_dev *dev;
  165. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  166. if (!dev)
  167. return NULL;
  168. dev->bus_type = B43_BUS_SSB;
  169. dev->sdev = sdev;
  170. dev->bus_may_powerdown = b43_bus_ssb_bus_may_powerdown;
  171. dev->bus_powerup = b43_bus_ssb_bus_powerup;
  172. dev->device_is_enabled = b43_bus_ssb_device_is_enabled;
  173. dev->device_enable = b43_bus_ssb_device_enable;
  174. dev->device_disable = b43_bus_ssb_device_disable;
  175. dev->read16 = b43_bus_ssb_read16;
  176. dev->read32 = b43_bus_ssb_read32;
  177. dev->write16 = b43_bus_ssb_write16;
  178. dev->write32 = b43_bus_ssb_write32;
  179. dev->block_read = b43_bus_ssb_block_read;
  180. dev->block_write = b43_bus_ssb_block_write;
  181. dev->dev = sdev->dev;
  182. dev->dma_dev = sdev->dma_dev;
  183. dev->irq = sdev->irq;
  184. dev->board_vendor = sdev->bus->boardinfo.vendor;
  185. dev->board_type = sdev->bus->boardinfo.type;
  186. dev->board_rev = sdev->bus->boardinfo.rev;
  187. dev->chip_id = sdev->bus->chip_id;
  188. dev->chip_rev = sdev->bus->chip_rev;
  189. dev->chip_pkg = sdev->bus->chip_package;
  190. dev->bus_sprom = &sdev->bus->sprom;
  191. dev->core_id = sdev->id.coreid;
  192. dev->core_rev = sdev->id.revision;
  193. return dev;
  194. }
  195. #endif /* CONFIG_B43_SSB */
  196. void *b43_bus_get_wldev(struct b43_bus_dev *dev)
  197. {
  198. switch (dev->bus_type) {
  199. #ifdef CONFIG_B43_BCMA
  200. case B43_BUS_BCMA:
  201. return bcma_get_drvdata(dev->bdev);
  202. #endif
  203. #ifdef CONFIG_B43_SSB
  204. case B43_BUS_SSB:
  205. return ssb_get_drvdata(dev->sdev);
  206. #endif
  207. }
  208. return NULL;
  209. }
  210. void b43_bus_set_wldev(struct b43_bus_dev *dev, void *wldev)
  211. {
  212. switch (dev->bus_type) {
  213. #ifdef CONFIG_B43_BCMA
  214. case B43_BUS_BCMA:
  215. bcma_set_drvdata(dev->bdev, wldev);
  216. break;
  217. #endif
  218. #ifdef CONFIG_B43_SSB
  219. case B43_BUS_SSB:
  220. ssb_set_drvdata(dev->sdev, wldev);
  221. break;
  222. #endif
  223. }
  224. }