bus.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. #ifdef CONFIG_BCM47XX_BCMA
  19. #include <asm/mach-bcm47xx/bcm47xx.h>
  20. #endif
  21. #include "b43.h"
  22. #include "bus.h"
  23. /* BCMA */
  24. #ifdef CONFIG_B43_BCMA
  25. static int b43_bus_bcma_bus_may_powerdown(struct b43_bus_dev *dev)
  26. {
  27. return 0; /* bcma_bus_may_powerdown(dev->bdev->bus); */
  28. }
  29. static int b43_bus_bcma_bus_powerup(struct b43_bus_dev *dev,
  30. bool dynamic_pctl)
  31. {
  32. return 0; /* bcma_bus_powerup(dev->sdev->bus, dynamic_pctl); */
  33. }
  34. static int b43_bus_bcma_device_is_enabled(struct b43_bus_dev *dev)
  35. {
  36. return bcma_core_is_enabled(dev->bdev);
  37. }
  38. static void b43_bus_bcma_device_enable(struct b43_bus_dev *dev,
  39. u32 core_specific_flags)
  40. {
  41. bcma_core_enable(dev->bdev, core_specific_flags);
  42. }
  43. static void b43_bus_bcma_device_disable(struct b43_bus_dev *dev,
  44. u32 core_specific_flags)
  45. {
  46. bcma_core_disable(dev->bdev, core_specific_flags);
  47. }
  48. static u16 b43_bus_bcma_read16(struct b43_bus_dev *dev, u16 offset)
  49. {
  50. return bcma_read16(dev->bdev, offset);
  51. }
  52. static u32 b43_bus_bcma_read32(struct b43_bus_dev *dev, u16 offset)
  53. {
  54. return bcma_read32(dev->bdev, offset);
  55. }
  56. static
  57. void b43_bus_bcma_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
  58. {
  59. bcma_write16(dev->bdev, offset, value);
  60. }
  61. static
  62. void b43_bus_bcma_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
  63. {
  64. bcma_write32(dev->bdev, offset, value);
  65. }
  66. static
  67. void b43_bus_bcma_block_read(struct b43_bus_dev *dev, void *buffer,
  68. size_t count, u16 offset, u8 reg_width)
  69. {
  70. bcma_block_read(dev->bdev, buffer, count, offset, reg_width);
  71. }
  72. static
  73. void b43_bus_bcma_block_write(struct b43_bus_dev *dev, const void *buffer,
  74. size_t count, u16 offset, u8 reg_width)
  75. {
  76. bcma_block_write(dev->bdev, buffer, count, offset, reg_width);
  77. }
  78. struct b43_bus_dev *b43_bus_dev_bcma_init(struct bcma_device *core)
  79. {
  80. struct b43_bus_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  81. if (!dev)
  82. return NULL;
  83. dev->bus_type = B43_BUS_BCMA;
  84. dev->bdev = core;
  85. dev->bus_may_powerdown = b43_bus_bcma_bus_may_powerdown;
  86. dev->bus_powerup = b43_bus_bcma_bus_powerup;
  87. dev->device_is_enabled = b43_bus_bcma_device_is_enabled;
  88. dev->device_enable = b43_bus_bcma_device_enable;
  89. dev->device_disable = b43_bus_bcma_device_disable;
  90. dev->read16 = b43_bus_bcma_read16;
  91. dev->read32 = b43_bus_bcma_read32;
  92. dev->write16 = b43_bus_bcma_write16;
  93. dev->write32 = b43_bus_bcma_write32;
  94. dev->block_read = b43_bus_bcma_block_read;
  95. dev->block_write = b43_bus_bcma_block_write;
  96. #ifdef CONFIG_BCM47XX_BCMA
  97. if (b43_bus_host_is_pci(dev) &&
  98. bcm47xx_bus_type == BCM47XX_BUS_TYPE_BCMA &&
  99. bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4716)
  100. dev->flush_writes = true;
  101. #endif
  102. dev->dev = &core->dev;
  103. dev->dma_dev = core->dma_dev;
  104. dev->irq = core->irq;
  105. dev->board_vendor = core->bus->boardinfo.vendor;
  106. dev->board_type = core->bus->boardinfo.type;
  107. dev->board_rev = core->bus->sprom.board_rev;
  108. dev->chip_id = core->bus->chipinfo.id;
  109. dev->chip_rev = core->bus->chipinfo.rev;
  110. dev->chip_pkg = core->bus->chipinfo.pkg;
  111. dev->bus_sprom = &core->bus->sprom;
  112. dev->core_id = core->id.id;
  113. dev->core_rev = core->id.rev;
  114. return dev;
  115. }
  116. #endif /* CONFIG_B43_BCMA */
  117. /* SSB */
  118. #ifdef CONFIG_B43_SSB
  119. static int b43_bus_ssb_bus_may_powerdown(struct b43_bus_dev *dev)
  120. {
  121. return ssb_bus_may_powerdown(dev->sdev->bus);
  122. }
  123. static int b43_bus_ssb_bus_powerup(struct b43_bus_dev *dev,
  124. bool dynamic_pctl)
  125. {
  126. return ssb_bus_powerup(dev->sdev->bus, dynamic_pctl);
  127. }
  128. static int b43_bus_ssb_device_is_enabled(struct b43_bus_dev *dev)
  129. {
  130. return ssb_device_is_enabled(dev->sdev);
  131. }
  132. static void b43_bus_ssb_device_enable(struct b43_bus_dev *dev,
  133. u32 core_specific_flags)
  134. {
  135. ssb_device_enable(dev->sdev, core_specific_flags);
  136. }
  137. static void b43_bus_ssb_device_disable(struct b43_bus_dev *dev,
  138. u32 core_specific_flags)
  139. {
  140. ssb_device_disable(dev->sdev, core_specific_flags);
  141. }
  142. static u16 b43_bus_ssb_read16(struct b43_bus_dev *dev, u16 offset)
  143. {
  144. return ssb_read16(dev->sdev, offset);
  145. }
  146. static u32 b43_bus_ssb_read32(struct b43_bus_dev *dev, u16 offset)
  147. {
  148. return ssb_read32(dev->sdev, offset);
  149. }
  150. static void b43_bus_ssb_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
  151. {
  152. ssb_write16(dev->sdev, offset, value);
  153. }
  154. static void b43_bus_ssb_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
  155. {
  156. ssb_write32(dev->sdev, offset, value);
  157. }
  158. static void b43_bus_ssb_block_read(struct b43_bus_dev *dev, void *buffer,
  159. size_t count, u16 offset, u8 reg_width)
  160. {
  161. ssb_block_read(dev->sdev, buffer, count, offset, reg_width);
  162. }
  163. static
  164. void b43_bus_ssb_block_write(struct b43_bus_dev *dev, const void *buffer,
  165. size_t count, u16 offset, u8 reg_width)
  166. {
  167. ssb_block_write(dev->sdev, buffer, count, offset, reg_width);
  168. }
  169. struct b43_bus_dev *b43_bus_dev_ssb_init(struct ssb_device *sdev)
  170. {
  171. struct b43_bus_dev *dev;
  172. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  173. if (!dev)
  174. return NULL;
  175. dev->bus_type = B43_BUS_SSB;
  176. dev->sdev = sdev;
  177. dev->bus_may_powerdown = b43_bus_ssb_bus_may_powerdown;
  178. dev->bus_powerup = b43_bus_ssb_bus_powerup;
  179. dev->device_is_enabled = b43_bus_ssb_device_is_enabled;
  180. dev->device_enable = b43_bus_ssb_device_enable;
  181. dev->device_disable = b43_bus_ssb_device_disable;
  182. dev->read16 = b43_bus_ssb_read16;
  183. dev->read32 = b43_bus_ssb_read32;
  184. dev->write16 = b43_bus_ssb_write16;
  185. dev->write32 = b43_bus_ssb_write32;
  186. dev->block_read = b43_bus_ssb_block_read;
  187. dev->block_write = b43_bus_ssb_block_write;
  188. dev->dev = sdev->dev;
  189. dev->dma_dev = sdev->dma_dev;
  190. dev->irq = sdev->irq;
  191. dev->board_vendor = sdev->bus->boardinfo.vendor;
  192. dev->board_type = sdev->bus->boardinfo.type;
  193. dev->board_rev = sdev->bus->sprom.board_rev;
  194. dev->chip_id = sdev->bus->chip_id;
  195. dev->chip_rev = sdev->bus->chip_rev;
  196. dev->chip_pkg = sdev->bus->chip_package;
  197. dev->bus_sprom = &sdev->bus->sprom;
  198. dev->core_id = sdev->id.coreid;
  199. dev->core_rev = sdev->id.revision;
  200. return dev;
  201. }
  202. #endif /* CONFIG_B43_SSB */
  203. void *b43_bus_get_wldev(struct b43_bus_dev *dev)
  204. {
  205. switch (dev->bus_type) {
  206. #ifdef CONFIG_B43_BCMA
  207. case B43_BUS_BCMA:
  208. return bcma_get_drvdata(dev->bdev);
  209. #endif
  210. #ifdef CONFIG_B43_SSB
  211. case B43_BUS_SSB:
  212. return ssb_get_drvdata(dev->sdev);
  213. #endif
  214. }
  215. return NULL;
  216. }
  217. void b43_bus_set_wldev(struct b43_bus_dev *dev, void *wldev)
  218. {
  219. switch (dev->bus_type) {
  220. #ifdef CONFIG_B43_BCMA
  221. case B43_BUS_BCMA:
  222. bcma_set_drvdata(dev->bdev, wldev);
  223. break;
  224. #endif
  225. #ifdef CONFIG_B43_SSB
  226. case B43_BUS_SSB:
  227. ssb_set_drvdata(dev->sdev, wldev);
  228. break;
  229. #endif
  230. }
  231. }