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/*
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.
23 */
24#include <linux/slab.h>
25#include <net/mac80211.h>
26
27#include "main.h"
28#include "mac80211_if.h"
29#include "phy_shim.h"
30
31/* PHY SHIM module specific state */
32struct 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 */
36};
37
38struct 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;
42
43	physhim = kzalloc(sizeof(struct phy_shim_info), GFP_ATOMIC);
44	if (!physhim)
45		return NULL;
46
47	physhim->wlc_hw = wlc_hw;
48	physhim->wlc = wlc;
49	physhim->wl = wl;
50
51	return physhim;
52}
53
54void wlc_phy_shim_detach(struct phy_shim_info *physhim)
55{
56	kfree(physhim);
57}
58
59struct wlapi_timer *wlapi_init_timer(struct phy_shim_info *physhim,
60				     void (*fn)(struct brcms_phy *pi),
61				     void *arg, const char *name)
62{
63	return (struct wlapi_timer *)
64			brcms_init_timer(physhim->wl, (void (*)(void *))fn,
65					 arg, name);
66}
67
68void wlapi_free_timer(struct wlapi_timer *t)
69{
70	brcms_free_timer((struct brcms_timer *)t);
71}
72
73void
74wlapi_add_timer(struct wlapi_timer *t, uint ms, int periodic)
75{
76	brcms_add_timer((struct brcms_timer *)t, ms, periodic);
77}
78
79bool wlapi_del_timer(struct wlapi_timer *t)
80{
81	return brcms_del_timer((struct brcms_timer *)t);
82}
83
84void wlapi_intrson(struct phy_shim_info *physhim)
85{
86	brcms_intrson(physhim->wl);
87}
88
89u32 wlapi_intrsoff(struct phy_shim_info *physhim)
90{
91	return brcms_intrsoff(physhim->wl);
92}
93
94void wlapi_intrsrestore(struct phy_shim_info *physhim, u32 macintmask)
95{
96	brcms_intrsrestore(physhim->wl, macintmask);
97}
98
99void wlapi_bmac_write_shm(struct phy_shim_info *physhim, uint offset, u16 v)
100{
101	brcms_b_write_shm(physhim->wlc_hw, offset, v);
102}
103
104u16 wlapi_bmac_read_shm(struct phy_shim_info *physhim, uint offset)
105{
106	return brcms_b_read_shm(physhim->wlc_hw, offset);
107}
108
109void
110wlapi_bmac_mhf(struct phy_shim_info *physhim, u8 idx, u16 mask,
111	       u16 val, int bands)
112{
113	brcms_b_mhf(physhim->wlc_hw, idx, mask, val, bands);
114}
115
116void wlapi_bmac_corereset(struct phy_shim_info *physhim, u32 flags)
117{
118	brcms_b_corereset(physhim->wlc_hw, flags);
119}
120
121void wlapi_suspend_mac_and_wait(struct phy_shim_info *physhim)
122{
123	brcms_c_suspend_mac_and_wait(physhim->wlc);
124}
125
126void wlapi_switch_macfreq(struct phy_shim_info *physhim, u8 spurmode)
127{
128	brcms_b_switch_macfreq(physhim->wlc_hw, spurmode);
129}
130
131void wlapi_enable_mac(struct phy_shim_info *physhim)
132{
133	brcms_c_enable_mac(physhim->wlc);
134}
135
136void wlapi_bmac_mctrl(struct phy_shim_info *physhim, u32 mask, u32 val)
137{
138	brcms_b_mctrl(physhim->wlc_hw, mask, val);
139}
140
141void wlapi_bmac_phy_reset(struct phy_shim_info *physhim)
142{
143	brcms_b_phy_reset(physhim->wlc_hw);
144}
145
146void wlapi_bmac_bw_set(struct phy_shim_info *physhim, u16 bw)
147{
148	brcms_b_bw_set(physhim->wlc_hw, bw);
149}
150
151u16 wlapi_bmac_get_txant(struct phy_shim_info *physhim)
152{
153	return brcms_b_get_txant(physhim->wlc_hw);
154}
155
156void wlapi_bmac_phyclk_fgc(struct phy_shim_info *physhim, bool clk)
157{
158	brcms_b_phyclk_fgc(physhim->wlc_hw, clk);
159}
160
161void wlapi_bmac_macphyclk_set(struct phy_shim_info *physhim, bool clk)
162{
163	brcms_b_macphyclk_set(physhim->wlc_hw, clk);
164}
165
166void wlapi_bmac_core_phypll_ctl(struct phy_shim_info *physhim, bool on)
167{
168	brcms_b_core_phypll_ctl(physhim->wlc_hw, on);
169}
170
171void wlapi_bmac_core_phypll_reset(struct phy_shim_info *physhim)
172{
173	brcms_b_core_phypll_reset(physhim->wlc_hw);
174}
175
176void wlapi_bmac_ucode_wake_override_phyreg_set(struct phy_shim_info *physhim)
177{
178	brcms_c_ucode_wake_override_set(physhim->wlc_hw,
179					BRCMS_WAKE_OVERRIDE_PHYREG);
180}
181
182void wlapi_bmac_ucode_wake_override_phyreg_clear(struct phy_shim_info *physhim)
183{
184	brcms_c_ucode_wake_override_clear(physhim->wlc_hw,
185					  BRCMS_WAKE_OVERRIDE_PHYREG);
186}
187
188void
189wlapi_bmac_write_template_ram(struct phy_shim_info *physhim, int offset,
190			      int len, void *buf)
191{
192	brcms_b_write_template_ram(physhim->wlc_hw, offset, len, buf);
193}
194
195u16 wlapi_bmac_rate_shm_offset(struct phy_shim_info *physhim, u8 rate)
196{
197	return brcms_b_rate_shm_offset(physhim->wlc_hw, rate);
198}
199
200void wlapi_ucode_sample_init(struct phy_shim_info *physhim)
201{
202}
203
204void
205wlapi_copyfrom_objmem(struct phy_shim_info *physhim, uint offset, void *buf,
206		      int len, u32 sel)
207{
208	brcms_b_copyfrom_objmem(physhim->wlc_hw, offset, buf, len, sel);
209}
210
211void
212wlapi_copyto_objmem(struct phy_shim_info *physhim, uint offset, const void *buf,
213		    int l, u32 sel)
214{
215	brcms_b_copyto_objmem(physhim->wlc_hw, offset, buf, l, sel);
216}
217