1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Utility routines for configuring different memories in Broadcom chips.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Portions of this code are copyright (c) 2021 Cypress Semiconductor Corporation
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 1999-2017, Broadcom Corporation
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Unless you and Broadcom execute a separate written software license
9*4882a593Smuzhiyun * agreement governing use of this software, this software is licensed to you
10*4882a593Smuzhiyun * under the terms of the GNU General Public License version 2 (the "GPL"),
11*4882a593Smuzhiyun * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12*4882a593Smuzhiyun * following added to such license:
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * As a special exception, the copyright holders of this software give you
15*4882a593Smuzhiyun * permission to link this software with independent modules, and to copy and
16*4882a593Smuzhiyun * distribute the resulting executable under terms of your choice, provided that
17*4882a593Smuzhiyun * you also meet, for each linked independent module, the terms and conditions of
18*4882a593Smuzhiyun * the license of that module. An independent module is a module which is not
19*4882a593Smuzhiyun * derived from this software. The special exception does not apply to any
20*4882a593Smuzhiyun * modifications of the software.
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * Notwithstanding the above, under no circumstances may you combine this
23*4882a593Smuzhiyun * software in any way with any other Broadcom software provided under a license
24*4882a593Smuzhiyun * other than the GPL, without Broadcom's express prior written consent.
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun *
27*4882a593Smuzhiyun * <<Broadcom-WL-IPTag/Open:>>
28*4882a593Smuzhiyun *
29*4882a593Smuzhiyun * $Id: $
30*4882a593Smuzhiyun */
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #include <typedefs.h>
33*4882a593Smuzhiyun #include <sbchipc.h>
34*4882a593Smuzhiyun #include <hndsoc.h>
35*4882a593Smuzhiyun #include <bcmdevs.h>
36*4882a593Smuzhiyun #include <osl.h>
37*4882a593Smuzhiyun #include <sbgci.h>
38*4882a593Smuzhiyun #include <siutils.h>
39*4882a593Smuzhiyun #include <bcmutils.h>
40*4882a593Smuzhiyun #include <hndmem.h>
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun #define IS_MEMTYPE_VALID(mem) ((mem >= MEM_SOCRAM) && (mem < MEM_MAX))
43*4882a593Smuzhiyun #define IS_MEMCONFIG_VALID(cfg) ((cfg >= PDA_CONFIG_CLEAR) && (cfg < PDA_CONFIG_MAX))
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun /* Returns the number of banks in a given memory */
46*4882a593Smuzhiyun int
hndmem_num_banks(si_t * sih,int mem)47*4882a593Smuzhiyun hndmem_num_banks(si_t *sih, int mem)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun uint32 savecore, mem_info;
50*4882a593Smuzhiyun int num_banks = 0;
51*4882a593Smuzhiyun gciregs_t *gciregs;
52*4882a593Smuzhiyun osl_t *osh = si_osh(sih);
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun if (!IS_MEMTYPE_VALID(mem)) {
55*4882a593Smuzhiyun goto exit;
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun savecore = si_coreidx(sih);
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun /* TODO: Check whether SOCRAM core is present or not. If not, bail out */
61*4882a593Smuzhiyun /* In future we need to add code for TCM based chips as well */
62*4882a593Smuzhiyun if (!si_setcore(sih, SOCRAM_CORE_ID, 0)) {
63*4882a593Smuzhiyun goto exit;
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun if (sih->gcirev >= 9) {
67*4882a593Smuzhiyun gciregs = si_setcore(sih, GCI_CORE_ID, 0);
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun mem_info = R_REG(osh, &gciregs->wlan_mem_info);
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun switch (mem) {
72*4882a593Smuzhiyun case MEM_SOCRAM:
73*4882a593Smuzhiyun num_banks = (mem_info & WLAN_MEM_INFO_REG_NUMSOCRAMBANKS_MASK) >>
74*4882a593Smuzhiyun WLAN_MEM_INFO_REG_NUMSOCRAMBANKS_SHIFT;
75*4882a593Smuzhiyun break;
76*4882a593Smuzhiyun case MEM_BM:
77*4882a593Smuzhiyun num_banks = (mem_info & WLAN_MEM_INFO_REG_NUMD11MACBM_MASK) >>
78*4882a593Smuzhiyun WLAN_MEM_INFO_REG_NUMD11MACBM_SHIFT;
79*4882a593Smuzhiyun break;
80*4882a593Smuzhiyun case MEM_UCM:
81*4882a593Smuzhiyun num_banks = (mem_info & WLAN_MEM_INFO_REG_NUMD11MACUCM_MASK) >>
82*4882a593Smuzhiyun WLAN_MEM_INFO_REG_NUMD11MACUCM_SHIFT;
83*4882a593Smuzhiyun break;
84*4882a593Smuzhiyun case MEM_SHM:
85*4882a593Smuzhiyun num_banks = (mem_info & WLAN_MEM_INFO_REG_NUMD11MACSHM_MASK) >>
86*4882a593Smuzhiyun WLAN_MEM_INFO_REG_NUMD11MACSHM_SHIFT;
87*4882a593Smuzhiyun break;
88*4882a593Smuzhiyun default:
89*4882a593Smuzhiyun ASSERT(0);
90*4882a593Smuzhiyun break;
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun } else {
93*4882a593Smuzhiyun /* TODO: Figure out bank information using SOCRAM registers */
94*4882a593Smuzhiyun }
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun si_setcoreidx(sih, savecore);
97*4882a593Smuzhiyun exit:
98*4882a593Smuzhiyun return num_banks;
99*4882a593Smuzhiyun }
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun /* Returns the size of a give bank in a given memory */
102*4882a593Smuzhiyun int
hndmem_bank_size(si_t * sih,hndmem_type_t mem,int bank_num)103*4882a593Smuzhiyun hndmem_bank_size(si_t *sih, hndmem_type_t mem, int bank_num)
104*4882a593Smuzhiyun {
105*4882a593Smuzhiyun uint32 savecore, bank_info, reg_data;
106*4882a593Smuzhiyun int bank_sz = 0;
107*4882a593Smuzhiyun gciregs_t *gciregs;
108*4882a593Smuzhiyun osl_t *osh = si_osh(sih);
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun if (!IS_MEMTYPE_VALID(mem)) {
111*4882a593Smuzhiyun goto exit;
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun savecore = si_coreidx(sih);
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun /* TODO: Check whether SOCRAM core is present or not. If not, bail out */
117*4882a593Smuzhiyun /* In future we need to add code for TCM based chips as well */
118*4882a593Smuzhiyun if (!si_setcore(sih, SOCRAM_CORE_ID, 0)) {
119*4882a593Smuzhiyun goto exit;
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun if (sih->gcirev >= 9) {
123*4882a593Smuzhiyun gciregs = si_setcore(sih, GCI_CORE_ID, 0);
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun reg_data = ((mem &
126*4882a593Smuzhiyun GCI_INDIRECT_ADDRESS_REG_GPIOINDEX_MASK) <<
127*4882a593Smuzhiyun GCI_INDIRECT_ADDRESS_REG_GPIOINDEX_SHIFT) |
128*4882a593Smuzhiyun ((bank_num & GCI_INDIRECT_ADDRESS_REG_REGINDEX_MASK)
129*4882a593Smuzhiyun << GCI_INDIRECT_ADDRESS_REG_REGINDEX_SHIFT);
130*4882a593Smuzhiyun W_REG(osh, &gciregs->gci_indirect_addr, reg_data);
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun bank_info = R_REG(osh, &gciregs->wlan_bankxinfo);
133*4882a593Smuzhiyun bank_sz = (bank_info & WLAN_BANKXINFO_BANK_SIZE_MASK) >>
134*4882a593Smuzhiyun WLAN_BANKXINFO_BANK_SIZE_SHIFT;
135*4882a593Smuzhiyun } else {
136*4882a593Smuzhiyun /* TODO: Figure out bank size using SOCRAM registers */
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun si_setcoreidx(sih, savecore);
140*4882a593Smuzhiyun exit:
141*4882a593Smuzhiyun return bank_sz;
142*4882a593Smuzhiyun }
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun /* Returns the start address of given memory */
145*4882a593Smuzhiyun uint32
hndmem_mem_base(si_t * sih,hndmem_type_t mem)146*4882a593Smuzhiyun hndmem_mem_base(si_t *sih, hndmem_type_t mem)
147*4882a593Smuzhiyun {
148*4882a593Smuzhiyun uint32 savecore, base_addr = 0;
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun /* Currently only support of SOCRAM is available in hardware */
151*4882a593Smuzhiyun if (mem != MEM_SOCRAM) {
152*4882a593Smuzhiyun goto exit;
153*4882a593Smuzhiyun }
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun savecore = si_coreidx(sih);
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun if (si_setcore(sih, SOCRAM_CORE_ID, 0))
158*4882a593Smuzhiyun {
159*4882a593Smuzhiyun base_addr = si_get_slaveport_addr(sih, CORE_SLAVE_PORT_1,
160*4882a593Smuzhiyun CORE_BASE_ADDR_0, SOCRAM_CORE_ID, 0);
161*4882a593Smuzhiyun } else {
162*4882a593Smuzhiyun /* TODO: Add code to get the base address of TCM */
163*4882a593Smuzhiyun base_addr = 0;
164*4882a593Smuzhiyun }
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun si_setcoreidx(sih, savecore);
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun exit:
169*4882a593Smuzhiyun return base_addr;
170*4882a593Smuzhiyun }
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun #ifdef BCMDEBUG
173*4882a593Smuzhiyun char *hndmem_type_str[] =
174*4882a593Smuzhiyun {
175*4882a593Smuzhiyun "SOCRAM", /* 0 */
176*4882a593Smuzhiyun "BM", /* 1 */
177*4882a593Smuzhiyun "UCM", /* 2 */
178*4882a593Smuzhiyun "SHM", /* 3 */
179*4882a593Smuzhiyun };
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun /* Dumps the complete memory information */
182*4882a593Smuzhiyun void
hndmem_dump_meminfo_all(si_t * sih)183*4882a593Smuzhiyun hndmem_dump_meminfo_all(si_t *sih)
184*4882a593Smuzhiyun {
185*4882a593Smuzhiyun int mem, bank, bank_cnt, bank_sz;
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun for (mem = MEM_SOCRAM; mem < MEM_MAX; mem++) {
188*4882a593Smuzhiyun bank_cnt = hndmem_num_banks(sih, mem);
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun printf("\nMemtype: %s\n", hndmem_type_str[mem]);
191*4882a593Smuzhiyun for (bank = 0; bank < bank_cnt; bank++) {
192*4882a593Smuzhiyun bank_sz = hndmem_bank_size(sih, mem, bank);
193*4882a593Smuzhiyun printf("Bank-%d: %d KB\n", bank, bank_sz);
194*4882a593Smuzhiyun }
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun #endif /* BCMDEBUG */
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun /* Configures the Sleep PDA for a particular bank for a given memory type */
200*4882a593Smuzhiyun int
hndmem_sleeppda_bank_config(si_t * sih,hndmem_type_t mem,int bank_num,hndmem_config_t config,uint32 pda)201*4882a593Smuzhiyun hndmem_sleeppda_bank_config(si_t *sih, hndmem_type_t mem, int bank_num,
202*4882a593Smuzhiyun hndmem_config_t config, uint32 pda)
203*4882a593Smuzhiyun {
204*4882a593Smuzhiyun uint32 savecore, reg_data;
205*4882a593Smuzhiyun gciregs_t *gciregs;
206*4882a593Smuzhiyun int err = BCME_OK;
207*4882a593Smuzhiyun osl_t *osh = si_osh(sih);
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun /* TODO: Check whether SOCRAM core is present or not. If not, bail out */
210*4882a593Smuzhiyun /* In future we need to add code for TCM based chips as well */
211*4882a593Smuzhiyun if (!si_setcore(sih, SOCRAM_CORE_ID, 0)) {
212*4882a593Smuzhiyun err = BCME_UNSUPPORTED;
213*4882a593Smuzhiyun goto exit;
214*4882a593Smuzhiyun }
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun /* Sleep PDA is supported only by GCI rev >= 9 */
217*4882a593Smuzhiyun if (sih->gcirev < 9) {
218*4882a593Smuzhiyun err = BCME_UNSUPPORTED;
219*4882a593Smuzhiyun goto exit;
220*4882a593Smuzhiyun }
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun if (!IS_MEMTYPE_VALID(mem)) {
223*4882a593Smuzhiyun err = BCME_BADOPTION;
224*4882a593Smuzhiyun goto exit;
225*4882a593Smuzhiyun }
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun if (!IS_MEMCONFIG_VALID(config)) {
228*4882a593Smuzhiyun err = BCME_BADOPTION;
229*4882a593Smuzhiyun goto exit;
230*4882a593Smuzhiyun }
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun savecore = si_coreidx(sih);
233*4882a593Smuzhiyun gciregs = si_setcore(sih, GCI_CORE_ID, 0);
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun reg_data = ((mem &
236*4882a593Smuzhiyun GCI_INDIRECT_ADDRESS_REG_GPIOINDEX_MASK) <<
237*4882a593Smuzhiyun GCI_INDIRECT_ADDRESS_REG_GPIOINDEX_SHIFT) |
238*4882a593Smuzhiyun ((bank_num & GCI_INDIRECT_ADDRESS_REG_REGINDEX_MASK)
239*4882a593Smuzhiyun << GCI_INDIRECT_ADDRESS_REG_REGINDEX_SHIFT);
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun W_REG(osh, &gciregs->gci_indirect_addr, reg_data);
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun if (config == PDA_CONFIG_SET_PARTIAL) {
244*4882a593Smuzhiyun W_REG(osh, &gciregs->wlan_bankxsleeppda, pda);
245*4882a593Smuzhiyun W_REG(osh, &gciregs->wlan_bankxkill, 0);
246*4882a593Smuzhiyun }
247*4882a593Smuzhiyun else if (config == PDA_CONFIG_SET_FULL) {
248*4882a593Smuzhiyun W_REG(osh, &gciregs->wlan_bankxsleeppda, WLAN_BANKX_SLEEPPDA_REG_SLEEPPDA_MASK);
249*4882a593Smuzhiyun W_REG(osh, &gciregs->wlan_bankxkill, WLAN_BANKX_PKILL_REG_SLEEPPDA_MASK);
250*4882a593Smuzhiyun } else {
251*4882a593Smuzhiyun W_REG(osh, &gciregs->wlan_bankxsleeppda, 0);
252*4882a593Smuzhiyun W_REG(osh, &gciregs->wlan_bankxkill, 0);
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun si_setcoreidx(sih, savecore);
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun exit:
258*4882a593Smuzhiyun return err;
259*4882a593Smuzhiyun }
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun /* Configures the Active PDA for a particular bank for a given memory type */
262*4882a593Smuzhiyun int
hndmem_activepda_bank_config(si_t * sih,hndmem_type_t mem,int bank_num,hndmem_config_t config,uint32 pda)263*4882a593Smuzhiyun hndmem_activepda_bank_config(si_t *sih, hndmem_type_t mem,
264*4882a593Smuzhiyun int bank_num, hndmem_config_t config, uint32 pda)
265*4882a593Smuzhiyun {
266*4882a593Smuzhiyun uint32 savecore, reg_data;
267*4882a593Smuzhiyun gciregs_t *gciregs;
268*4882a593Smuzhiyun int err = BCME_OK;
269*4882a593Smuzhiyun osl_t *osh = si_osh(sih);
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun if (!IS_MEMTYPE_VALID(mem)) {
272*4882a593Smuzhiyun err = BCME_BADOPTION;
273*4882a593Smuzhiyun goto exit;
274*4882a593Smuzhiyun }
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun if (!IS_MEMCONFIG_VALID(config)) {
277*4882a593Smuzhiyun err = BCME_BADOPTION;
278*4882a593Smuzhiyun goto exit;
279*4882a593Smuzhiyun }
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun savecore = si_coreidx(sih);
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun /* TODO: Check whether SOCRAM core is present or not. If not, bail out */
284*4882a593Smuzhiyun /* In future we need to add code for TCM based chips as well */
285*4882a593Smuzhiyun if (!si_setcore(sih, SOCRAM_CORE_ID, 0)) {
286*4882a593Smuzhiyun err = BCME_UNSUPPORTED;
287*4882a593Smuzhiyun goto exit;
288*4882a593Smuzhiyun }
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun if (sih->gcirev >= 9) {
291*4882a593Smuzhiyun gciregs = si_setcore(sih, GCI_CORE_ID, 0);
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun reg_data = ((mem &
294*4882a593Smuzhiyun GCI_INDIRECT_ADDRESS_REG_GPIOINDEX_MASK) <<
295*4882a593Smuzhiyun GCI_INDIRECT_ADDRESS_REG_GPIOINDEX_SHIFT) |
296*4882a593Smuzhiyun ((bank_num & GCI_INDIRECT_ADDRESS_REG_REGINDEX_MASK)
297*4882a593Smuzhiyun << GCI_INDIRECT_ADDRESS_REG_REGINDEX_SHIFT);
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun W_REG(osh, &gciregs->gci_indirect_addr, reg_data);
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun if (config == PDA_CONFIG_SET_PARTIAL) {
302*4882a593Smuzhiyun W_REG(osh, &gciregs->wlan_bankxactivepda, pda);
303*4882a593Smuzhiyun }
304*4882a593Smuzhiyun else if (config == PDA_CONFIG_SET_FULL) {
305*4882a593Smuzhiyun W_REG(osh, &gciregs->wlan_bankxactivepda,
306*4882a593Smuzhiyun WLAN_BANKX_SLEEPPDA_REG_SLEEPPDA_MASK);
307*4882a593Smuzhiyun } else {
308*4882a593Smuzhiyun W_REG(osh, &gciregs->wlan_bankxactivepda, 0);
309*4882a593Smuzhiyun }
310*4882a593Smuzhiyun } else {
311*4882a593Smuzhiyun /* TODO: Configure SOCRAM PDA using SOCRAM registers */
312*4882a593Smuzhiyun err = BCME_UNSUPPORTED;
313*4882a593Smuzhiyun }
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun si_setcoreidx(sih, savecore);
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun exit:
318*4882a593Smuzhiyun return err;
319*4882a593Smuzhiyun }
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun /* Configures the Sleep PDA for all the banks for a given memory type */
322*4882a593Smuzhiyun int
hndmem_sleeppda_config(si_t * sih,hndmem_type_t mem,hndmem_config_t config)323*4882a593Smuzhiyun hndmem_sleeppda_config(si_t *sih, hndmem_type_t mem, hndmem_config_t config)
324*4882a593Smuzhiyun {
325*4882a593Smuzhiyun int bank;
326*4882a593Smuzhiyun int num_banks = hndmem_num_banks(sih, mem);
327*4882a593Smuzhiyun int err = BCME_OK;
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun /* Sleep PDA is supported only by GCI rev >= 9 */
330*4882a593Smuzhiyun if (sih->gcirev < 9) {
331*4882a593Smuzhiyun err = BCME_UNSUPPORTED;
332*4882a593Smuzhiyun goto exit;
333*4882a593Smuzhiyun }
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun if (!IS_MEMTYPE_VALID(mem)) {
336*4882a593Smuzhiyun err = BCME_BADOPTION;
337*4882a593Smuzhiyun goto exit;
338*4882a593Smuzhiyun }
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun if (!IS_MEMCONFIG_VALID(config)) {
341*4882a593Smuzhiyun err = BCME_BADOPTION;
342*4882a593Smuzhiyun goto exit;
343*4882a593Smuzhiyun }
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun for (bank = 0; bank < num_banks; bank++)
346*4882a593Smuzhiyun {
347*4882a593Smuzhiyun err = hndmem_sleeppda_bank_config(sih, mem, bank, config, 0);
348*4882a593Smuzhiyun }
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun exit:
351*4882a593Smuzhiyun return err;
352*4882a593Smuzhiyun }
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun /* Configures the Active PDA for all the banks for a given memory type */
355*4882a593Smuzhiyun int
hndmem_activepda_config(si_t * sih,hndmem_type_t mem,hndmem_config_t config)356*4882a593Smuzhiyun hndmem_activepda_config(si_t *sih, hndmem_type_t mem, hndmem_config_t config)
357*4882a593Smuzhiyun {
358*4882a593Smuzhiyun int bank;
359*4882a593Smuzhiyun int num_banks = hndmem_num_banks(sih, mem);
360*4882a593Smuzhiyun int err = BCME_OK;
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun if (!IS_MEMTYPE_VALID(mem)) {
363*4882a593Smuzhiyun err = BCME_BADOPTION;
364*4882a593Smuzhiyun goto exit;
365*4882a593Smuzhiyun }
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun if (!IS_MEMCONFIG_VALID(config)) {
368*4882a593Smuzhiyun err = BCME_BADOPTION;
369*4882a593Smuzhiyun goto exit;
370*4882a593Smuzhiyun }
371*4882a593Smuzhiyun
372*4882a593Smuzhiyun for (bank = 0; bank < num_banks; bank++)
373*4882a593Smuzhiyun {
374*4882a593Smuzhiyun err = hndmem_activepda_bank_config(sih, mem, bank, config, 0);
375*4882a593Smuzhiyun }
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun exit:
378*4882a593Smuzhiyun return err;
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun /* Turn off/on all the possible banks in a given memory range.
382*4882a593Smuzhiyun * Currently this works only for SOCRAM as this is restricted by HW.
383*4882a593Smuzhiyun */
384*4882a593Smuzhiyun int
hndmem_activepda_mem_config(si_t * sih,hndmem_type_t mem,uint32 mem_start,uint32 size,hndmem_config_t config)385*4882a593Smuzhiyun hndmem_activepda_mem_config(si_t *sih, hndmem_type_t mem, uint32 mem_start,
386*4882a593Smuzhiyun uint32 size, hndmem_config_t config)
387*4882a593Smuzhiyun {
388*4882a593Smuzhiyun int bank, bank_sz, num_banks;
389*4882a593Smuzhiyun int mem_end;
390*4882a593Smuzhiyun int bank_start_addr, bank_end_addr;
391*4882a593Smuzhiyun int err = BCME_OK;
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun /* We can get bank size for only SOCRAM/TCM only. Support is not avilable
394*4882a593Smuzhiyun * for other memories (BM, UCM and SHM)
395*4882a593Smuzhiyun */
396*4882a593Smuzhiyun if (mem != MEM_SOCRAM) {
397*4882a593Smuzhiyun err = BCME_UNSUPPORTED;
398*4882a593Smuzhiyun goto exit;
399*4882a593Smuzhiyun }
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun num_banks = hndmem_num_banks(sih, mem);
402*4882a593Smuzhiyun bank_start_addr = hndmem_mem_base(sih, mem);
403*4882a593Smuzhiyun mem_end = mem_start + size - 1;
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun for (bank = 0; bank < num_banks; bank++)
406*4882a593Smuzhiyun {
407*4882a593Smuzhiyun /* Bank size is spcified in bankXinfo register in terms on KBs */
408*4882a593Smuzhiyun bank_sz = 1024 * hndmem_bank_size(sih, mem, bank);
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun bank_end_addr = bank_start_addr + bank_sz - 1;
411*4882a593Smuzhiyun
412*4882a593Smuzhiyun if (config == PDA_CONFIG_SET_FULL) {
413*4882a593Smuzhiyun /* Check if the bank is completely overlapping with the given mem range */
414*4882a593Smuzhiyun if ((mem_start <= bank_start_addr) && (mem_end >= bank_end_addr)) {
415*4882a593Smuzhiyun err = hndmem_activepda_bank_config(sih, mem, bank, config, 0);
416*4882a593Smuzhiyun }
417*4882a593Smuzhiyun } else {
418*4882a593Smuzhiyun /* Check if the bank is completely overlaped with the given mem range */
419*4882a593Smuzhiyun if (((mem_start <= bank_start_addr) && (mem_end >= bank_end_addr)) ||
420*4882a593Smuzhiyun /* Check if the bank is partially overlaped with the given range */
421*4882a593Smuzhiyun ((mem_start <= bank_end_addr) && (mem_end >= bank_start_addr))) {
422*4882a593Smuzhiyun err = hndmem_activepda_bank_config(sih, mem, bank, config, 0);
423*4882a593Smuzhiyun }
424*4882a593Smuzhiyun }
425*4882a593Smuzhiyun
426*4882a593Smuzhiyun bank_start_addr += bank_sz;
427*4882a593Smuzhiyun }
428*4882a593Smuzhiyun
429*4882a593Smuzhiyun exit:
430*4882a593Smuzhiyun return err;
431*4882a593Smuzhiyun }
432