2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
18 * This is "two-way" interface, acting as the SHIM layer between driver
19 * and PHY layer. The driver can optionally call this translation layer
20 * to do some preprocessing, then reach PHY. On the PHY->driver direction,
21 * all calls go through this layer since PHY doesn't have access to the
22 * driver's brcms_hardware pointer.
24 #include <linux/slab.h>
25 #include <net/mac80211.h>
28 #include "mac80211_if.h"
31 /* PHY SHIM module specific state */
32 struct phy_shim_info {
33 struct brcms_hardware *wlc_hw; /* pointer to main wlc_hw structure */
34 struct brcms_c_info *wlc; /* pointer to main wlc structure */
35 struct brcms_info *wl; /* pointer to os-specific private state */
38 struct phy_shim_info *wlc_phy_shim_attach(struct brcms_hardware *wlc_hw,
39 struct brcms_info *wl,
40 struct brcms_c_info *wlc) {
41 struct phy_shim_info *physhim = NULL;
43 physhim = kzalloc(sizeof(struct phy_shim_info), GFP_ATOMIC);
45 wiphy_err(wlc_hw->wlc->wiphy,
46 "wl%d: wlc_phy_shim_attach: out of mem\n",
50 physhim->wlc_hw = wlc_hw;
57 void wlc_phy_shim_detach(struct phy_shim_info *physhim)
62 struct wlapi_timer *wlapi_init_timer(struct phy_shim_info *physhim,
63 void (*fn)(struct brcms_phy *pi),
64 void *arg, const char *name)
66 return (struct wlapi_timer *)
67 brcms_init_timer(physhim->wl, (void (*)(void *))fn,
71 void wlapi_free_timer(struct phy_shim_info *physhim, struct wlapi_timer *t)
73 brcms_free_timer(physhim->wl, (struct brcms_timer *)t);
77 wlapi_add_timer(struct phy_shim_info *physhim, struct wlapi_timer *t, uint ms,
80 brcms_add_timer(physhim->wl, (struct brcms_timer *)t, ms, periodic);
83 bool wlapi_del_timer(struct phy_shim_info *physhim, struct wlapi_timer *t)
85 return brcms_del_timer(physhim->wl, (struct brcms_timer *)t);
88 void wlapi_intrson(struct phy_shim_info *physhim)
90 brcms_intrson(physhim->wl);
93 u32 wlapi_intrsoff(struct phy_shim_info *physhim)
95 return brcms_intrsoff(physhim->wl);
98 void wlapi_intrsrestore(struct phy_shim_info *physhim, u32 macintmask)
100 brcms_intrsrestore(physhim->wl, macintmask);
103 void wlapi_bmac_write_shm(struct phy_shim_info *physhim, uint offset, u16 v)
105 brcms_b_write_shm(physhim->wlc_hw, offset, v);
108 u16 wlapi_bmac_read_shm(struct phy_shim_info *physhim, uint offset)
110 return brcms_b_read_shm(physhim->wlc_hw, offset);
114 wlapi_bmac_mhf(struct phy_shim_info *physhim, u8 idx, u16 mask,
117 brcms_b_mhf(physhim->wlc_hw, idx, mask, val, bands);
120 void wlapi_bmac_corereset(struct phy_shim_info *physhim, u32 flags)
122 brcms_b_corereset(physhim->wlc_hw, flags);
125 void wlapi_suspend_mac_and_wait(struct phy_shim_info *physhim)
127 brcms_c_suspend_mac_and_wait(physhim->wlc);
130 void wlapi_switch_macfreq(struct phy_shim_info *physhim, u8 spurmode)
132 brcms_b_switch_macfreq(physhim->wlc_hw, spurmode);
135 void wlapi_enable_mac(struct phy_shim_info *physhim)
137 brcms_c_enable_mac(physhim->wlc);
140 void wlapi_bmac_mctrl(struct phy_shim_info *physhim, u32 mask, u32 val)
142 brcms_b_mctrl(physhim->wlc_hw, mask, val);
145 void wlapi_bmac_phy_reset(struct phy_shim_info *physhim)
147 brcms_b_phy_reset(physhim->wlc_hw);
150 void wlapi_bmac_bw_set(struct phy_shim_info *physhim, u16 bw)
152 brcms_b_bw_set(physhim->wlc_hw, bw);
155 u16 wlapi_bmac_get_txant(struct phy_shim_info *physhim)
157 return brcms_b_get_txant(physhim->wlc_hw);
160 void wlapi_bmac_phyclk_fgc(struct phy_shim_info *physhim, bool clk)
162 brcms_b_phyclk_fgc(physhim->wlc_hw, clk);
165 void wlapi_bmac_macphyclk_set(struct phy_shim_info *physhim, bool clk)
167 brcms_b_macphyclk_set(physhim->wlc_hw, clk);
170 void wlapi_bmac_core_phypll_ctl(struct phy_shim_info *physhim, bool on)
172 brcms_b_core_phypll_ctl(physhim->wlc_hw, on);
175 void wlapi_bmac_core_phypll_reset(struct phy_shim_info *physhim)
177 brcms_b_core_phypll_reset(physhim->wlc_hw);
180 void wlapi_bmac_ucode_wake_override_phyreg_set(struct phy_shim_info *physhim)
182 brcms_c_ucode_wake_override_set(physhim->wlc_hw,
183 BRCMS_WAKE_OVERRIDE_PHYREG);
186 void wlapi_bmac_ucode_wake_override_phyreg_clear(struct phy_shim_info *physhim)
188 brcms_c_ucode_wake_override_clear(physhim->wlc_hw,
189 BRCMS_WAKE_OVERRIDE_PHYREG);
193 wlapi_bmac_write_template_ram(struct phy_shim_info *physhim, int offset,
196 brcms_b_write_template_ram(physhim->wlc_hw, offset, len, buf);
199 u16 wlapi_bmac_rate_shm_offset(struct phy_shim_info *physhim, u8 rate)
201 return brcms_b_rate_shm_offset(physhim->wlc_hw, rate);
204 void wlapi_ucode_sample_init(struct phy_shim_info *physhim)
209 wlapi_copyfrom_objmem(struct phy_shim_info *physhim, uint offset, void *buf,
212 brcms_b_copyfrom_objmem(physhim->wlc_hw, offset, buf, len, sel);
216 wlapi_copyto_objmem(struct phy_shim_info *physhim, uint offset, const void *buf,
219 brcms_b_copyto_objmem(physhim->wlc_hw, offset, buf, l, sel);