phy_shim.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /*
  17. * This is "two-way" interface, acting as the SHIM layer between driver
  18. * and PHY layer. The driver can optionally call this translation layer
  19. * to do some preprocessing, then reach PHY. On the PHY->driver direction,
  20. * all calls go through this layer since PHY doesn't have access to the
  21. * driver's brcms_hardware pointer.
  22. */
  23. #include <linux/slab.h>
  24. #include <net/mac80211.h>
  25. #include "main.h"
  26. #include "mac80211_if.h"
  27. #include "phy_shim.h"
  28. /* PHY SHIM module specific state */
  29. struct phy_shim_info {
  30. struct brcms_hardware *wlc_hw; /* pointer to main wlc_hw structure */
  31. struct brcms_c_info *wlc; /* pointer to main wlc structure */
  32. struct brcms_info *wl; /* pointer to os-specific private state */
  33. };
  34. struct phy_shim_info *wlc_phy_shim_attach(struct brcms_hardware *wlc_hw,
  35. struct brcms_info *wl,
  36. struct brcms_c_info *wlc) {
  37. struct phy_shim_info *physhim = NULL;
  38. physhim = kzalloc(sizeof(struct phy_shim_info), GFP_ATOMIC);
  39. if (!physhim)
  40. return NULL;
  41. physhim->wlc_hw = wlc_hw;
  42. physhim->wlc = wlc;
  43. physhim->wl = wl;
  44. return physhim;
  45. }
  46. void wlc_phy_shim_detach(struct phy_shim_info *physhim)
  47. {
  48. kfree(physhim);
  49. }
  50. struct wlapi_timer *wlapi_init_timer(struct phy_shim_info *physhim,
  51. void (*fn)(struct brcms_phy *pi),
  52. void *arg, const char *name)
  53. {
  54. return (struct wlapi_timer *)
  55. brcms_init_timer(physhim->wl, (void (*)(void *))fn,
  56. arg, name);
  57. }
  58. void wlapi_free_timer(struct wlapi_timer *t)
  59. {
  60. brcms_free_timer((struct brcms_timer *)t);
  61. }
  62. void
  63. wlapi_add_timer(struct wlapi_timer *t, uint ms, int periodic)
  64. {
  65. brcms_add_timer((struct brcms_timer *)t, ms, periodic);
  66. }
  67. bool wlapi_del_timer(struct wlapi_timer *t)
  68. {
  69. return brcms_del_timer((struct brcms_timer *)t);
  70. }
  71. void wlapi_intrson(struct phy_shim_info *physhim)
  72. {
  73. brcms_intrson(physhim->wl);
  74. }
  75. u32 wlapi_intrsoff(struct phy_shim_info *physhim)
  76. {
  77. return brcms_intrsoff(physhim->wl);
  78. }
  79. void wlapi_intrsrestore(struct phy_shim_info *physhim, u32 macintmask)
  80. {
  81. brcms_intrsrestore(physhim->wl, macintmask);
  82. }
  83. void wlapi_bmac_write_shm(struct phy_shim_info *physhim, uint offset, u16 v)
  84. {
  85. brcms_b_write_shm(physhim->wlc_hw, offset, v);
  86. }
  87. u16 wlapi_bmac_read_shm(struct phy_shim_info *physhim, uint offset)
  88. {
  89. return brcms_b_read_shm(physhim->wlc_hw, offset);
  90. }
  91. void
  92. wlapi_bmac_mhf(struct phy_shim_info *physhim, u8 idx, u16 mask,
  93. u16 val, int bands)
  94. {
  95. brcms_b_mhf(physhim->wlc_hw, idx, mask, val, bands);
  96. }
  97. void wlapi_bmac_corereset(struct phy_shim_info *physhim, u32 flags)
  98. {
  99. brcms_b_corereset(physhim->wlc_hw, flags);
  100. }
  101. void wlapi_suspend_mac_and_wait(struct phy_shim_info *physhim)
  102. {
  103. brcms_c_suspend_mac_and_wait(physhim->wlc);
  104. }
  105. void wlapi_switch_macfreq(struct phy_shim_info *physhim, u8 spurmode)
  106. {
  107. brcms_b_switch_macfreq(physhim->wlc_hw, spurmode);
  108. }
  109. void wlapi_enable_mac(struct phy_shim_info *physhim)
  110. {
  111. brcms_c_enable_mac(physhim->wlc);
  112. }
  113. void wlapi_bmac_mctrl(struct phy_shim_info *physhim, u32 mask, u32 val)
  114. {
  115. brcms_b_mctrl(physhim->wlc_hw, mask, val);
  116. }
  117. void wlapi_bmac_phy_reset(struct phy_shim_info *physhim)
  118. {
  119. brcms_b_phy_reset(physhim->wlc_hw);
  120. }
  121. void wlapi_bmac_bw_set(struct phy_shim_info *physhim, u16 bw)
  122. {
  123. brcms_b_bw_set(physhim->wlc_hw, bw);
  124. }
  125. u16 wlapi_bmac_get_txant(struct phy_shim_info *physhim)
  126. {
  127. return brcms_b_get_txant(physhim->wlc_hw);
  128. }
  129. void wlapi_bmac_phyclk_fgc(struct phy_shim_info *physhim, bool clk)
  130. {
  131. brcms_b_phyclk_fgc(physhim->wlc_hw, clk);
  132. }
  133. void wlapi_bmac_macphyclk_set(struct phy_shim_info *physhim, bool clk)
  134. {
  135. brcms_b_macphyclk_set(physhim->wlc_hw, clk);
  136. }
  137. void wlapi_bmac_core_phypll_ctl(struct phy_shim_info *physhim, bool on)
  138. {
  139. brcms_b_core_phypll_ctl(physhim->wlc_hw, on);
  140. }
  141. void wlapi_bmac_core_phypll_reset(struct phy_shim_info *physhim)
  142. {
  143. brcms_b_core_phypll_reset(physhim->wlc_hw);
  144. }
  145. void wlapi_bmac_ucode_wake_override_phyreg_set(struct phy_shim_info *physhim)
  146. {
  147. brcms_c_ucode_wake_override_set(physhim->wlc_hw,
  148. BRCMS_WAKE_OVERRIDE_PHYREG);
  149. }
  150. void wlapi_bmac_ucode_wake_override_phyreg_clear(struct phy_shim_info *physhim)
  151. {
  152. brcms_c_ucode_wake_override_clear(physhim->wlc_hw,
  153. BRCMS_WAKE_OVERRIDE_PHYREG);
  154. }
  155. void
  156. wlapi_bmac_write_template_ram(struct phy_shim_info *physhim, int offset,
  157. int len, void *buf)
  158. {
  159. brcms_b_write_template_ram(physhim->wlc_hw, offset, len, buf);
  160. }
  161. u16 wlapi_bmac_rate_shm_offset(struct phy_shim_info *physhim, u8 rate)
  162. {
  163. return brcms_b_rate_shm_offset(physhim->wlc_hw, rate);
  164. }
  165. void wlapi_ucode_sample_init(struct phy_shim_info *physhim)
  166. {
  167. }
  168. void
  169. wlapi_copyfrom_objmem(struct phy_shim_info *physhim, uint offset, void *buf,
  170. int len, u32 sel)
  171. {
  172. brcms_b_copyfrom_objmem(physhim->wlc_hw, offset, buf, len, sel);
  173. }
  174. void
  175. wlapi_copyto_objmem(struct phy_shim_info *physhim, uint offset, const void *buf,
  176. int l, u32 sel)
  177. {
  178. brcms_b_copyto_objmem(physhim->wlc_hw, offset, buf, l, sel);
  179. }