1 /*
2 * Copyright 2022, Cypress Semiconductor Corporation (an Infineon company)
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #include "whd_chip_constants.h"
19 #include "whd_wlioctl.h"
20 #include "whd_int.h"
21 #include "whd_types_int.h"
22 #include "bus_protocols/whd_chip_reg.h"
23
24 /******************************************************
25 * Function Definitions
26 ******************************************************/
27
whd_chip_set_chip_id(whd_driver_t whd_driver,uint16_t id)28 uint32_t whd_chip_set_chip_id(whd_driver_t whd_driver, uint16_t id)
29 {
30 whd_driver->chip_info.chip_id = id;
31
32 return 0;
33 }
34
whd_chip_get_chip_id(whd_driver_t whd_driver)35 uint16_t whd_chip_get_chip_id(whd_driver_t whd_driver)
36 {
37 return whd_driver->chip_info.chip_id;
38 }
39
get_whd_var(whd_driver_t whd_driver,chip_var_t var)40 uint32_t get_whd_var(whd_driver_t whd_driver, chip_var_t var)
41 {
42 uint32_t val = 0;
43
44 uint16_t wlan_chip_id = whd_chip_get_chip_id(whd_driver);
45 switch (var)
46 {
47 case ARM_CORE_BASE_ADDRESS:
48 CHECK_RETURN(get_arm_core_base_address(wlan_chip_id, &val) );
49 break;
50 case SOCSRAM_BASE_ADDRESS:
51 CHECK_RETURN(get_socsram_base_address(wlan_chip_id, &val, false) );
52 break;
53 case SOCSRAM_WRAPPER_BASE_ADDRESS:
54 CHECK_RETURN(get_socsram_base_address(wlan_chip_id, &val, true) );
55 break;
56 case SDIOD_CORE_BASE_ADDRESS:
57 CHECK_RETURN(get_sdiod_core_base_address(wlan_chip_id, &val) );
58 break;
59 case PMU_BASE_ADDRESS:
60 CHECK_RETURN(get_pmu_base_address(wlan_chip_id, &val) );
61 break;
62 case CHIP_RAM_SIZE:
63 CHECK_RETURN(get_chip_ram_size(wlan_chip_id, &val) );
64 break;
65 case ATCM_RAM_BASE_ADDRESS:
66 CHECK_RETURN(get_atcm_ram_base_address(wlan_chip_id, &val) );
67 break;
68 case SOCRAM_SRMEM_SIZE:
69 CHECK_RETURN(get_socsram_srmem_size(wlan_chip_id, &val) );
70 break;
71 case CHANSPEC_BAND_MASK:
72 CHECK_RETURN(get_wl_chanspec_band_mask(wlan_chip_id, &val) );
73 break;
74 case CHANSPEC_BAND_2G:
75 CHECK_RETURN(get_wl_chanspec_band_2G(wlan_chip_id, &val) );
76 break;
77 case CHANSPEC_BAND_5G:
78 CHECK_RETURN(get_wl_chanspec_band_5G(wlan_chip_id, &val) );
79 break;
80 case CHANSPEC_BAND_SHIFT:
81 CHECK_RETURN(get_wl_chanspec_band_shift(wlan_chip_id, &val) );
82 break;
83 case CHANSPEC_BW_10:
84 CHECK_RETURN(get_wl_chanspec_bw_10(wlan_chip_id, &val) );
85 break;
86 case CHANSPEC_BW_20:
87 CHECK_RETURN(get_wl_chanspec_bw_20(wlan_chip_id, &val) );
88 break;
89 case CHANSPEC_BW_40:
90 CHECK_RETURN(get_wl_chanspec_bw_40(wlan_chip_id, &val) );
91 break;
92 case CHANSPEC_BW_MASK:
93 CHECK_RETURN(get_wl_chanspec_bw_mask(wlan_chip_id, &val) );
94 break;
95 case CHANSPEC_BW_SHIFT:
96 CHECK_RETURN(get_wl_chanspec_bw_shift(wlan_chip_id, &val) );
97 break;
98 case CHANSPEC_CTL_SB_LOWER:
99 CHECK_RETURN(get_wl_chanspec_ctl_sb_lower(wlan_chip_id, &val) );
100 break;
101 case CHANSPEC_CTL_SB_UPPER:
102 CHECK_RETURN(get_wl_chanspec_ctl_sb_upper(wlan_chip_id, &val) );
103 break;
104 case CHANSPEC_CTL_SB_NONE:
105 CHECK_RETURN(get_wl_chanspec_ctl_sb_none(wlan_chip_id, &val) );
106 break;
107 case CHANSPEC_CTL_SB_MASK:
108 CHECK_RETURN(get_wl_chanspec_ctl_sb_mask(wlan_chip_id, &val) );
109 break;
110 default:
111 break;
112 }
113 return val;
114 }
115
get_arm_core_base_address(uint16_t wlan_chip_id,uint32_t * addr)116 whd_result_t get_arm_core_base_address(uint16_t wlan_chip_id, uint32_t *addr)
117 {
118 switch (wlan_chip_id)
119 {
120 case 0x4373:
121 *addr = 0x18002000 + WRAPPER_REGISTER_OFFSET;
122 break;
123 case 43012:
124 case 43430:
125 case 43439:
126 *addr = 0x18003000 + WRAPPER_REGISTER_OFFSET;
127 break;
128 case 43909:
129 case 43907:
130 case 54907:
131 *addr = 0x18011000 + WRAPPER_REGISTER_OFFSET;
132 break;
133 default:
134 return WHD_BADARG;
135 }
136 return WHD_SUCCESS;
137 }
138
get_socsram_base_address(uint16_t wlan_chip_id,uint32_t * addr,whd_bool_t wrapper)139 whd_result_t get_socsram_base_address(uint16_t wlan_chip_id, uint32_t *addr, whd_bool_t wrapper)
140 {
141 uint32_t offset = 0;
142 if (wrapper)
143 {
144 offset = WRAPPER_REGISTER_OFFSET;
145 }
146 switch (wlan_chip_id)
147 {
148 case 43012:
149 case 43430:
150 case 43439:
151 *addr = 0x18004000 + offset;
152 break;
153 default:
154 return WHD_BADARG;
155 }
156 return WHD_SUCCESS;
157 }
158
get_sdiod_core_base_address(uint16_t wlan_chip_id,uint32_t * addr)159 whd_result_t get_sdiod_core_base_address(uint16_t wlan_chip_id, uint32_t *addr)
160 {
161 switch (wlan_chip_id)
162 {
163 case 0x4373:
164 *addr = 0x18005000;
165 break;
166 case 43012:
167 case 43430:
168 case 43439:
169 *addr = 0x18002000;
170 break;
171 default:
172 return WHD_BADARG;
173 }
174 return WHD_SUCCESS;
175 }
176
get_pmu_base_address(uint16_t wlan_chip_id,uint32_t * addr)177 whd_result_t get_pmu_base_address(uint16_t wlan_chip_id, uint32_t *addr)
178 {
179 switch (wlan_chip_id)
180 {
181 case 0x4373:
182 case 43430:
183 case 43439:
184 *addr = CHIPCOMMON_BASE_ADDRESS;
185 break;
186 case 43012:
187 *addr = 0x18012000;
188 break;
189 case 43909:
190 case 43907:
191 case 54907:
192 *addr = 0x18011000;
193 break;
194 default:
195 return WHD_BADARG;
196 }
197 return WHD_SUCCESS;
198 }
199
get_chip_ram_size(uint16_t wlan_chip_id,uint32_t * size)200 whd_result_t get_chip_ram_size(uint16_t wlan_chip_id, uint32_t *size)
201 {
202 *size = 0;
203 if ( (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) || (wlan_chip_id == 43430) ||
204 (wlan_chip_id == 43439) )
205 {
206 *size = (512 * 1024);
207 }
208 else if ( (wlan_chip_id == 43362) || (wlan_chip_id == 4390) )
209 {
210 *size = 0x3C000;
211 }
212 else if ( (wlan_chip_id == 43909) || (wlan_chip_id == 43907) || (wlan_chip_id == 54907) )
213 {
214 *size = 0x90000;
215 }
216 else if (wlan_chip_id == 43012)
217 {
218 *size = 0xA0000;
219 }
220 else if (wlan_chip_id == 0x4373)
221 {
222 *size = 0xE0000;
223 }
224 else
225 {
226 *size = 0x80000;
227 }
228 return WHD_SUCCESS;
229 }
230
get_atcm_ram_base_address(uint16_t wlan_chip_id,uint32_t * size)231 whd_result_t get_atcm_ram_base_address(uint16_t wlan_chip_id, uint32_t *size)
232 {
233 *size = 0;
234 if (wlan_chip_id == 0x4373)
235 {
236 *size = 0x160000;
237 }
238 else if ( (wlan_chip_id == 43909) || (wlan_chip_id == 43907) || (wlan_chip_id == 54907) )
239 {
240 *size = 0x1B0000;
241 }
242 else
243 {
244 *size = 0;
245 }
246 return WHD_SUCCESS;
247 }
248
get_socsram_srmem_size(uint16_t wlan_chip_id,uint32_t * mem_size)249 whd_result_t get_socsram_srmem_size(uint16_t wlan_chip_id, uint32_t *mem_size)
250 {
251 *mem_size = 0;
252 if ( (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
253 {
254 *mem_size = (32 * 1024);
255 }
256 else if ( (wlan_chip_id == 43430) || (wlan_chip_id == 43439) )
257 {
258 *mem_size = (64 * 1024);
259 }
260 else
261 {
262 *mem_size = 0;
263 }
264 return WHD_SUCCESS;
265 }
266
get_wl_chanspec_band_mask(uint16_t wlan_chip_id,uint32_t * band_mask)267 whd_result_t get_wl_chanspec_band_mask(uint16_t wlan_chip_id, uint32_t *band_mask)
268 {
269 *band_mask = 0;
270 if ( (wlan_chip_id == 43362) || (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
271 {
272 *band_mask = 0xf000;
273 }
274 else
275 {
276 *band_mask = 0xc000;
277 }
278 return WHD_SUCCESS;
279 }
280
get_wl_chanspec_band_2G(uint16_t wlan_chip_id,uint32_t * band_2g)281 whd_result_t get_wl_chanspec_band_2G(uint16_t wlan_chip_id, uint32_t *band_2g)
282 {
283 *band_2g = 0;
284 if ( (wlan_chip_id == 43362) || (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
285 {
286 *band_2g = 0x2000;
287 }
288 else
289 {
290 *band_2g = 0x0000;
291 }
292 return WHD_SUCCESS;
293 }
294
get_wl_chanspec_band_5G(uint16_t wlan_chip_id,uint32_t * band_5g)295 whd_result_t get_wl_chanspec_band_5G(uint16_t wlan_chip_id, uint32_t *band_5g)
296 {
297 *band_5g = 0;
298 if ( (wlan_chip_id == 43362) || (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
299 {
300 *band_5g = 0x1000;
301 }
302 else
303 {
304 *band_5g = 0xc000;
305 }
306 return WHD_SUCCESS;
307 }
308
get_wl_chanspec_band_shift(uint16_t wlan_chip_id,uint32_t * band_shift)309 whd_result_t get_wl_chanspec_band_shift(uint16_t wlan_chip_id, uint32_t *band_shift)
310 {
311 *band_shift = 0;
312 if ( (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
313 {
314 *band_shift = 12;
315 }
316 else
317 {
318 *band_shift = 14;
319 }
320 return WHD_SUCCESS;
321 }
322
get_wl_chanspec_bw_10(uint16_t wlan_chip_id,uint32_t * bw_10)323 whd_result_t get_wl_chanspec_bw_10(uint16_t wlan_chip_id, uint32_t *bw_10)
324 {
325 *bw_10 = 0;
326 if ( (wlan_chip_id == 43362) || (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
327 {
328 *bw_10 = 0x0400;
329 }
330 else
331 {
332 *bw_10 = 0x0800;
333 }
334 return WHD_SUCCESS;
335 }
336
get_wl_chanspec_bw_20(uint16_t wlan_chip_id,uint32_t * bw_20)337 whd_result_t get_wl_chanspec_bw_20(uint16_t wlan_chip_id, uint32_t *bw_20)
338 {
339 *bw_20 = 0;
340 if ( (wlan_chip_id == 43362) || (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
341 {
342 *bw_20 = 0x0800;
343 }
344 else
345 {
346 *bw_20 = 0x1000;
347 }
348 return WHD_SUCCESS;
349 }
350
get_wl_chanspec_bw_40(uint16_t wlan_chip_id,uint32_t * bw_40)351 whd_result_t get_wl_chanspec_bw_40(uint16_t wlan_chip_id, uint32_t *bw_40)
352 {
353 *bw_40 = 0;
354 if ( (wlan_chip_id == 43362) || (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
355 {
356 *bw_40 = 0x0C00;
357 }
358 else
359 {
360 *bw_40 = 0x1800;
361 }
362 return WHD_SUCCESS;
363 }
364
get_wl_chanspec_bw_mask(uint16_t wlan_chip_id,uint32_t * bw_mask)365 whd_result_t get_wl_chanspec_bw_mask(uint16_t wlan_chip_id, uint32_t *bw_mask)
366 {
367 *bw_mask = 0;
368 if ( (wlan_chip_id == 43362) || (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
369 {
370 *bw_mask = 0x0C00;
371 }
372 else
373 {
374 *bw_mask = 0x3800;
375 }
376 return WHD_SUCCESS;
377 }
378
get_wl_chanspec_bw_shift(uint16_t wlan_chip_id,uint32_t * bw_shift)379 whd_result_t get_wl_chanspec_bw_shift(uint16_t wlan_chip_id, uint32_t *bw_shift)
380 {
381 *bw_shift = 0;
382 if ( (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
383 {
384 *bw_shift = 10;
385 }
386 else
387 {
388 *bw_shift = 11;
389 }
390 return WHD_SUCCESS;
391 }
392
get_wl_chanspec_ctl_sb_lower(uint16_t wlan_chip_id,uint32_t * sb_lower)393 whd_result_t get_wl_chanspec_ctl_sb_lower(uint16_t wlan_chip_id, uint32_t *sb_lower)
394 {
395 *sb_lower = 0;
396 if ( (wlan_chip_id == 43362) || (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
397 {
398 *sb_lower = 0x0100;
399 }
400 else
401 {
402 *sb_lower = WL_CHANSPEC_CTL_SB_LLL;
403 }
404 return WHD_SUCCESS;
405 }
406
get_wl_chanspec_ctl_sb_upper(uint16_t wlan_chip_id,uint32_t * sb_upper)407 whd_result_t get_wl_chanspec_ctl_sb_upper(uint16_t wlan_chip_id, uint32_t *sb_upper)
408 {
409 *sb_upper = 0;
410 if ( (wlan_chip_id == 43362) || (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
411 {
412 *sb_upper = 0x0200;
413 }
414 else
415 {
416 *sb_upper = WL_CHANSPEC_CTL_SB_LLU;
417 }
418 return WHD_SUCCESS;
419 }
420
get_wl_chanspec_ctl_sb_none(uint16_t wlan_chip_id,uint32_t * sb_none)421 whd_result_t get_wl_chanspec_ctl_sb_none(uint16_t wlan_chip_id, uint32_t *sb_none)
422 {
423 *sb_none = 0;
424 if ( (wlan_chip_id == 43362) || (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
425 {
426 *sb_none = 0x0300;
427 }
428 else
429 {
430 *sb_none = WL_CHANSPEC_CTL_SB_LLL;
431 }
432 return WHD_SUCCESS;
433 }
434
get_wl_chanspec_ctl_sb_mask(uint16_t wlan_chip_id,uint32_t * sb_mask)435 whd_result_t get_wl_chanspec_ctl_sb_mask(uint16_t wlan_chip_id, uint32_t *sb_mask)
436 {
437 *sb_mask = 0;
438 if ( (wlan_chip_id == 43362) || (wlan_chip_id == 4334) || (wlan_chip_id == 43340) || (wlan_chip_id == 43342) )
439 {
440 *sb_mask = 0x0300;
441 }
442 else
443 {
444 *sb_mask = 0x0700;
445 }
446 return WHD_SUCCESS;
447 }
448