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
*******************************************************************************/
64
#include "mvSysAudio.h"
66
/*******************************************************************************
67
* mvAudioWinSet - Set AUDIO target address window
70
* This function sets a peripheral target (e.g. SDRAM bank0, PCI_MEM0)
71
* address window, also known as address decode window.
72
* After setting this target window, the AUDIO will be able to access the
73
* target within the address window.
76
* winNum - AUDIO target address decode window number.
77
* pAddrDecWin - AUDIO target window data structure.
83
* MV_ERROR if address window overlapps with other address decode windows.
84
* MV_BAD_PARAM if base address is invalid parameter or target is
87
*******************************************************************************/
88
MV_STATUS mvAudioWinSet(int unit, MV_U32 winNum, MV_AUDIO_DEC_WIN *pAddrDecWin)
90
MV_TARGET_ATTRIB targetAttribs;
93
/* Parameter checking */
94
if (winNum >= MV_AUDIO_MAX_ADDR_DECODE_WIN)
96
mvOsPrintf("%s: ERR. Invalid win num %d\n",__FUNCTION__, winNum);
100
/* check if address is aligned to the size */
101
if(MV_IS_NOT_ALIGN(pAddrDecWin->addrWin.baseLow, pAddrDecWin->addrWin.size))
103
mvOsPrintf("mvAudioWinSet:Error setting AUDIO window %d to "\
104
"target %s.\nAddress 0x%08x is unaligned to size 0x%x.\n",
106
mvCtrlTargetNameGet(pAddrDecWin->target),
107
pAddrDecWin->addrWin.baseLow,
108
pAddrDecWin->addrWin.size);
115
if (MV_OK != mvCtrlAddrDecToReg(&(pAddrDecWin->addrWin),&decRegs))
117
mvOsPrintf("%s: mvCtrlAddrDecToReg Failed\n", __FUNCTION__);
121
mvCtrlAttribGet(pAddrDecWin->target, &targetAttribs);
124
decRegs.sizeReg &= ~MV_AUDIO_WIN_ATTR_MASK;
125
decRegs.sizeReg |= (targetAttribs.attrib << MV_AUDIO_WIN_ATTR_OFFSET);
128
decRegs.sizeReg &= ~MV_AUDIO_WIN_TARGET_MASK;
129
decRegs.sizeReg |= (targetAttribs.targetId << MV_AUDIO_WIN_TARGET_OFFSET);
131
if (pAddrDecWin->enable == MV_TRUE)
133
decRegs.sizeReg |= MV_AUDIO_WIN_ENABLE_MASK;
137
decRegs.sizeReg &= ~MV_AUDIO_WIN_ENABLE_MASK;
140
MV_REG_WRITE( MV_AUDIO_WIN_CTRL_REG(unit, winNum), decRegs.sizeReg);
141
MV_REG_WRITE( MV_AUDIO_WIN_BASE_REG(unit, winNum), decRegs.baseReg);
146
/*******************************************************************************
147
* mvAudioWinGet - Get AUDIO peripheral target address window.
150
* Get AUDIO peripheral target address window.
153
* winNum - AUDIO target address decode window number.
156
* pAddrDecWin - AUDIO target window data structure.
159
* MV_ERROR if register parameters are invalid.
161
*******************************************************************************/
162
MV_STATUS mvAudioWinGet(int unit, MV_U32 winNum, MV_AUDIO_DEC_WIN *pAddrDecWin)
165
MV_TARGET_ATTRIB targetAttrib;
167
/* Parameter checking */
168
if (winNum >= MV_AUDIO_MAX_ADDR_DECODE_WIN)
170
mvOsPrintf("%s : ERR. Invalid winNum %d\n",
171
__FUNCTION__, winNum);
172
return MV_NOT_SUPPORTED;
175
decRegs.baseReg = MV_REG_READ( MV_AUDIO_WIN_BASE_REG(unit, winNum) );
176
decRegs.sizeReg = MV_REG_READ( MV_AUDIO_WIN_CTRL_REG(unit, winNum) );
178
if (MV_OK != mvCtrlRegToAddrDec(&decRegs, &pAddrDecWin->addrWin) )
180
mvOsPrintf("%s: mvCtrlRegToAddrDec Failed\n", __FUNCTION__);
184
/* attrib and targetId */
185
targetAttrib.attrib = (decRegs.sizeReg & MV_AUDIO_WIN_ATTR_MASK) >>
186
MV_AUDIO_WIN_ATTR_OFFSET;
187
targetAttrib.targetId = (decRegs.sizeReg & MV_AUDIO_WIN_TARGET_MASK) >>
188
MV_AUDIO_WIN_TARGET_OFFSET;
190
pAddrDecWin->target = mvCtrlTargetGet(&targetAttrib);
192
/* Check if window is enabled */
193
if(decRegs.sizeReg & MV_AUDIO_WIN_ENABLE_MASK)
195
pAddrDecWin->enable = MV_TRUE;
199
pAddrDecWin->enable = MV_FALSE;
203
/*******************************************************************************
204
* mvAudioAddrDecShow - Print the AUDIO address decode map.
207
* This function print the AUDIO address decode map.
218
*******************************************************************************/
219
MV_VOID mvAudioUnitAddrDecShow(int unit)
221
MV_AUDIO_DEC_WIN win;
225
mvOsOutput( "AUDIO:\n" );
226
mvOsOutput( "----\n" );
228
for( i = 0; i < MV_AUDIO_MAX_ADDR_DECODE_WIN; i++ )
230
memset( &win, 0, sizeof(MV_AUDIO_DEC_WIN) );
232
mvOsOutput( "win%d - ", i );
234
if( mvAudioWinGet(unit, i, &win) == MV_OK )
238
mvOsOutput( "%s base %08x, ",
239
mvCtrlTargetNameGet(win.target), win.addrWin.baseLow );
240
mvOsOutput( "...." );
242
mvSizePrint( win.addrWin.size );
247
mvOsOutput( "disable\n" );
252
MV_VOID mvAudioAddrDecShow(MV_VOID)
256
for (unit = 0; unit < MV_AUDIO_MAX_UNITS; unit++)
258
if (MV_FALSE == mvCtrlPwrClckGet(AUDIO_UNIT_ID, unit)) continue;
260
mvAudioUnitAddrDecShow(unit);
265
/*******************************************************************************
266
* mvAudioWinInit - Initialize the integrated AUDIO target address window.
269
* Initialize the AUDIO peripheral target address window.
278
* MV_ERROR if register parameters are invalid.
280
*******************************************************************************/
281
MV_STATUS mvAudioWinInit(int unit)
284
MV_AUDIO_DEC_WIN audioWin;
285
MV_CPU_DEC_WIN cpuAddrDecWin;
288
/* Initiate Audio address decode */
290
/* First disable all address decode windows */
291
for(winNum = 0; winNum < MV_AUDIO_MAX_ADDR_DECODE_WIN; winNum++)
293
MV_U32 regVal = MV_REG_READ(MV_AUDIO_WIN_CTRL_REG(unit, winNum));
294
regVal &= ~MV_AUDIO_WIN_ENABLE_MASK;
295
MV_REG_WRITE(MV_AUDIO_WIN_CTRL_REG(unit, winNum), regVal);
298
for(winNum = 0; winNum < MV_AUDIO_MAX_ADDR_DECODE_WIN; winNum++)
300
/* We will set the Window to DRAM_CS0 in default */
301
/* first get attributes from CPU If */
302
status = mvCpuIfTargetWinGet(SDRAM_CS0, &cpuAddrDecWin);
306
mvOsPrintf("%s: ERR. mvCpuIfTargetWinGet failed\n", __FUNCTION__);
310
if (cpuAddrDecWin.enable == MV_TRUE)
312
audioWin.addrWin.baseHigh = cpuAddrDecWin.addrWin.baseHigh;
313
audioWin.addrWin.baseLow = cpuAddrDecWin.addrWin.baseLow;
314
audioWin.addrWin.size = cpuAddrDecWin.addrWin.size;
315
audioWin.enable = MV_TRUE;
316
audioWin.target = SDRAM_CS0;
318
if(MV_OK != mvAudioWinSet(unit, winNum, &audioWin))
330
MV_STATUS mvAudioInit(MV_U8 unit)
332
mvAudioWinInit(unit);
333
mvAudioHalInit(unit);