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