1
/*******************************************************************************
2
Copyright (C) Marvell International Ltd. and its affiliates
4
This software file (the "File") is owned and distributed by Marvell
5
International Ltd. and/or its affiliates ("Marvell") under the following
6
alternative licensing terms. Once you have made an election to distribute the
7
File under one of the following license alternatives, please (i) delete this
8
introductory statement regarding license alternatives, (ii) delete the two
9
license alternatives that you have not elected to use and (iii) preserve the
10
Marvell copyright notice above.
12
********************************************************************************
13
Marvell Commercial License Option
15
If you received this File from Marvell and you have entered into a commercial
16
license agreement (a "Commercial License") with Marvell, the File is licensed
17
to you under the terms of the applicable Commercial License.
19
********************************************************************************
20
Marvell GPL License Option
22
If you received this File from Marvell, you may opt to use, redistribute and/or
23
modify this File in accordance with the terms and conditions of the General
24
Public License Version 2, June 1991 (the "GPL License"), a copy of which is
25
available along with the File in the license.txt file or by writing to the Free
26
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
27
on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
29
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
30
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
31
DISCLAIMED. The GPL License provides additional details about this warranty
33
********************************************************************************
34
Marvell BSD License Option
36
If you received this File from Marvell, you may opt to use, redistribute and/or
37
modify this File under the following licensing terms.
38
Redistribution and use in source and binary forms, with or without modification,
39
are permitted provided that the following conditions are met:
41
* Redistributions of source code must retain the above copyright notice,
42
this list of conditions and the following disclaimer.
44
* Redistributions in binary form must reproduce the above copyright
45
notice, this list of conditions and the following disclaimer in the
46
documentation and/or other materials provided with the distribution.
48
* Neither the name of Marvell nor the names of its contributors may be
49
used to endorse or promote products derived from this software without
50
specific prior written permission.
52
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
53
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
54
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
55
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
56
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
57
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
58
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
59
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
61
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63
*******************************************************************************/
65
#include "voiceband/tdm/mvTdm.h"
76
static MV_TARGET tdmAddrDecPrioTap[] =
92
static MV_STATUS tdmWinOverlapDetect(MV_U32 winNum, MV_ADDR_WIN *pAddrWin);
94
/*******************************************************************************
95
* mvTdmWinInit - Initialize TDM address decode windows
98
* This function initialize TDM window decode unit. It set the
99
* default address decode
100
* windows of the unit.
109
* MV_ERROR if setting fail.
110
*******************************************************************************/
112
MV_STATUS mvTdmWinInit(void)
115
MV_U32 winPrioIndex = 0;
116
MV_CPU_DEC_WIN cpuAddrDecWin;
117
MV_TDM_DEC_WIN tdmWin;
120
/*Disable all windows*/
121
for (winNum = 0; winNum < TDM_MBUS_MAX_WIN; winNum++)
123
mvTdmWinEnable(winNum, MV_FALSE);
126
for (winNum = 0; ((tdmAddrDecPrioTap[winPrioIndex] != TBL_TERM) &&
127
(winNum < TDM_MBUS_MAX_WIN)); )
129
status = mvCpuIfTargetWinGet(tdmAddrDecPrioTap[winPrioIndex],
131
if (MV_NO_SUCH == status)
138
mvOsPrintf("mvTdmInit: ERR. mvCpuIfTargetWinGet failed\n");
142
if (cpuAddrDecWin.enable == MV_TRUE)
144
tdmWin.addrWin.baseHigh = cpuAddrDecWin.addrWin.baseHigh;
145
tdmWin.addrWin.baseLow = cpuAddrDecWin.addrWin.baseLow;
146
tdmWin.addrWin.size = cpuAddrDecWin.addrWin.size;
147
tdmWin.enable = MV_TRUE;
148
tdmWin.target = tdmAddrDecPrioTap[winPrioIndex];
149
if (MV_OK != mvTdmWinSet(winNum, &tdmWin))
160
/*******************************************************************************
161
* mvTdmWinSet - Set TDM target address window
164
* This function sets a peripheral target (e.g. SDRAM bank0, PCI_MEM0)
165
* address window, also known as address decode window.
166
* After setting this target window, the TDM will be able to access the
167
* target within the address window.
170
* winNum - TDM to target address decode window number.
171
* pAddrDecWin - TDM target window data structure.
177
* MV_ERROR if address window overlapps with other address decode windows.
178
* MV_BAD_PARAM if base address is invalid parameter or target is
181
*******************************************************************************/
183
MV_STATUS mvTdmWinSet(MV_U32 winNum, MV_TDM_DEC_WIN *pAddrDecWin)
185
MV_TARGET_ATTRIB targetAttribs;
189
/* Parameter checking */
190
if (winNum >= TDM_MBUS_MAX_WIN)
192
mvOsPrintf("mvTdmWinSet: ERR. Invalid win num %d\n",winNum);
196
/* Check if the requested window overlapps with current windows */
197
if (MV_TRUE == tdmWinOverlapDetect(winNum, &pAddrDecWin->addrWin))
199
mvOsPrintf("mvTdmWinSet: ERR. Window %d overlap\n", winNum);
203
/* check if address is aligned to the size */
204
if (MV_IS_NOT_ALIGN(pAddrDecWin->addrWin.baseLow, pAddrDecWin->addrWin.size))
206
mvOsPrintf("mvTdmWinSet: Error setting TDM window %d to "\
207
"target %s.\nAddress 0x%08x is unaligned to size 0x%x.\n",
209
mvCtrlTargetNameGet(pAddrDecWin->target),
210
pAddrDecWin->addrWin.baseLow,
211
pAddrDecWin->addrWin.size);
215
decRegs.baseReg = MV_REG_READ(TDM_WIN_BASE_REG(winNum));
216
decRegs.sizeReg = (MV_REG_READ(TDM_WIN_CTRL_REG(winNum)) & TDM_WIN_SIZE_MASK) >> TDM_WIN_SIZE_OFFS;
218
if (MV_OK != mvCtrlAddrDecToReg(&(pAddrDecWin->addrWin),&decRegs))
220
mvOsPrintf("mvTdmWinSet: mvCtrlAddrDecToReg Failed\n");
224
mvCtrlAttribGet(pAddrDecWin->target, &targetAttribs);
226
/* for the safe side we disable the window before writing the new
228
mvTdmWinEnable(winNum, MV_FALSE);
230
ctrlReg |= (targetAttribs.attrib << TDM_WIN_ATTRIB_OFFS);
231
ctrlReg |= (targetAttribs.targetId << TDM_WIN_TARGET_OFFS);
232
ctrlReg |= (decRegs.sizeReg << TDM_WIN_SIZE_OFFS);
234
/* Write to address base and control registers */
235
MV_REG_WRITE(TDM_WIN_BASE_REG(winNum), decRegs.baseReg);
236
MV_REG_WRITE(TDM_WIN_CTRL_REG(winNum), ctrlReg);
237
/* Enable address decode target window */
238
if (pAddrDecWin->enable == MV_TRUE)
240
mvTdmWinEnable(winNum, MV_TRUE);
245
/*******************************************************************************
246
* mvTdmWinGet - Get peripheral target address window.
249
* Get TDM peripheral target address window.
252
* winNum - TDM to target address decode window number.
255
* pAddrDecWin - TDM target window data structure.
258
* MV_ERROR if register parameters are invalid.
260
*******************************************************************************/
262
MV_STATUS mvTdmWinGet(MV_U32 winNum, MV_TDM_DEC_WIN *pAddrDecWin)
266
MV_TARGET_ATTRIB targetAttrib;
268
/* Parameter checking */
269
if (winNum >= TDM_MBUS_MAX_WIN)
271
mvOsPrintf("mvTdmWinGet: ERR. Invalid winNum %d\n", winNum);
272
return MV_NOT_SUPPORTED;
275
decRegs.baseReg = MV_REG_READ(TDM_WIN_BASE_REG(winNum));
276
decRegs.sizeReg = (MV_REG_READ(TDM_WIN_CTRL_REG(winNum)) & TDM_WIN_SIZE_MASK) >> TDM_WIN_SIZE_OFFS;
278
if (MV_OK != mvCtrlRegToAddrDec(&decRegs,&(pAddrDecWin->addrWin)))
280
mvOsPrintf("mvTdmWinGet: mvCtrlRegToAddrDec Failed \n");
284
/* attrib and targetId */
285
targetAttrib.attrib =
286
(MV_REG_READ(TDM_WIN_CTRL_REG(winNum)) & TDM_WIN_ATTRIB_MASK) >> TDM_WIN_ATTRIB_OFFS;
287
targetAttrib.targetId =
288
(MV_REG_READ(TDM_WIN_CTRL_REG(winNum)) & TDM_WIN_TARGET_MASK) >> TDM_WIN_TARGET_OFFS;
290
pAddrDecWin->target = mvCtrlTargetGet(&targetAttrib);
292
/* Check if window is enabled */
293
if (MV_REG_READ(TDM_WIN_CTRL_REG(winNum)) & TDM_WIN_ENABLE_MASK)
295
pAddrDecWin->enable = MV_TRUE;
299
pAddrDecWin->enable = MV_FALSE;
305
/*******************************************************************************
306
* mvTdmWinEnable - Enable/disable a TDM to target address window
309
* This function enable/disable a TDM to target address window.
310
* According to parameter 'enable' the routine will enable the
311
* window, thus enabling TDM accesses (before enabling the window it is
312
* tested for overlapping). Otherwise, the window will be disabled.
315
* winNum - TDM to target address decode window number.
316
* enable - Enable/disable parameter.
322
* MV_ERROR if decode window number was wrong or enabled window overlapps.
324
*******************************************************************************/
325
MV_STATUS mvTdmWinEnable(int winNum, MV_BOOL enable)
327
MV_TDM_DEC_WIN addrDecWin;
329
if (MV_TRUE == enable)
331
if (winNum >= TDM_MBUS_MAX_WIN)
333
mvOsPrintf("mvTdmWinEnable:ERR. Invalid winNum%d\n",winNum);
337
/* First check for overlap with other enabled windows */
338
/* Get current window */
339
if (MV_OK != mvTdmWinGet(winNum, &addrDecWin))
341
mvOsPrintf("mvTdmWinEnable:ERR. targetWinGet fail\n");
344
/* Check for overlapping */
345
if (MV_FALSE == tdmWinOverlapDetect(winNum, &(addrDecWin.addrWin)))
347
/* No Overlap. Enable address decode target window */
348
MV_REG_BIT_SET(TDM_WIN_CTRL_REG(winNum), TDM_WIN_ENABLE_MASK);
351
{ /* Overlap detected */
352
mvOsPrintf("mvTdmWinEnable:ERR. Overlap detected\n");
358
MV_REG_BIT_RESET(TDM_WIN_CTRL_REG(winNum), TDM_WIN_ENABLE_MASK);
364
/*******************************************************************************
365
* tdmWinOverlapDetect - Detect TDM address windows overlapping
368
* An unpredicted behaviour is expected in case TDM address decode
370
* This function detects TDM address decode windows overlapping of a
371
* specified window. The function does not check the window itself for
372
* overlapping. The function also skipps disabled address decode windows.
375
* winNum - address decode window number.
376
* pAddrDecWin - An address decode window struct.
382
* MV_TRUE if the given address window overlap current address
383
* decode map, MV_FALSE otherwise, MV_ERROR if reading invalid data
386
*******************************************************************************/
387
static MV_STATUS tdmWinOverlapDetect(MV_U32 winNum, MV_ADDR_WIN *pAddrWin)
390
MV_TDM_DEC_WIN addrDecWin;
392
for (winNumIndex = 0; winNumIndex < TDM_MBUS_MAX_WIN; winNumIndex++)
394
/* Do not check window itself */
395
if (winNumIndex == winNum)
399
/* Do not check disabled windows */
400
if (MV_REG_READ(TDM_WIN_CTRL_REG(winNum)) & TDM_WIN_ENABLE_MASK)
402
/* Get window parameters */
403
if (MV_OK != mvTdmWinGet(winNumIndex, &addrDecWin))
405
DB(mvOsPrintf("dmaWinOverlapDetect: ERR. TargetWinGet failed\n"));
409
if (MV_TRUE == ctrlWinOverlapTest(pAddrWin, &(addrDecWin.addrWin)))
418
/*******************************************************************************
419
* mvTdmAddrDecShow - Print the TDM address decode map.
422
* This function print the TDM address decode map.
433
*******************************************************************************/
434
MV_VOID mvTdmAddrDecShow(MV_VOID)
440
mvOsOutput( "TDM:\n" );
441
mvOsOutput( "----\n" );
443
for( i = 0; i < TDM_MBUS_MAX_WIN; i++ )
445
memset( &win, 0, sizeof(MV_TDM_DEC_WIN) );
447
mvOsOutput( "win%d - ", i );
449
if (mvTdmWinGet(i, &win ) == MV_OK )
453
mvOsOutput( "%s base %08x, ",
454
mvCtrlTargetNameGet(win.target), win.addrWin.baseLow);
455
mvOsOutput( "...." );
456
mvSizePrint( win.addrWin.size );
460
mvOsOutput( "disable\n" );