~ubuntu-branches/ubuntu/karmic/linux-mvl-dove/karmic-proposed

« back to all changes in this revision

Viewing changes to arch/arm/mach-kirkwood/mv_hal_support/kw_family/ctrlEnv/sys/mvSysAudio.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bader
  • Date: 2010-03-10 22:24:12 UTC
  • mto: (15.1.2 karmic-security)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20100310222412-k86m3r53jw0je7x1
Tags: upstream-2.6.31
ImportĀ upstreamĀ versionĀ 2.6.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
Copyright (C) Marvell International Ltd. and its affiliates
3
 
 
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.
11
 
 
12
 
********************************************************************************
13
 
Marvell Commercial License Option
14
 
 
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.
18
 
 
19
 
********************************************************************************
20
 
Marvell GPL License Option
21
 
 
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. 
28
 
 
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 
32
 
disclaimer.
33
 
********************************************************************************
34
 
Marvell BSD License Option
35
 
 
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:
40
 
 
41
 
    *   Redistributions of source code must retain the above copyright notice,
42
 
            this list of conditions and the following disclaimer. 
43
 
 
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. 
47
 
 
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. 
51
 
    
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.
62
 
 
63
 
*******************************************************************************/
64
 
#include "mvSysAudio.h"
65
 
 
66
 
/*******************************************************************************
67
 
* mvAudioWinSet - Set AUDIO target address window
68
 
*
69
 
* DESCRIPTION:
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. 
74
 
*
75
 
* INPUT:
76
 
*       winNum      - AUDIO target address decode window number.
77
 
*       pAddrDecWin - AUDIO target window data structure.
78
 
*
79
 
* OUTPUT:
80
 
*       None.
81
 
*
82
 
* RETURN:
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 
85
 
*       unknown.
86
 
*
87
 
*******************************************************************************/
88
 
MV_STATUS mvAudioWinSet(int unit, MV_U32 winNum, MV_AUDIO_DEC_WIN *pAddrDecWin)
89
 
{
90
 
    MV_TARGET_ATTRIB    targetAttribs;
91
 
    MV_DEC_REGS         decRegs;
92
 
 
93
 
    /* Parameter checking   */
94
 
    if (winNum >= MV_AUDIO_MAX_ADDR_DECODE_WIN)
95
 
    {
96
 
        mvOsPrintf("%s: ERR. Invalid win num %d\n",__FUNCTION__, winNum);
97
 
        return MV_BAD_PARAM;
98
 
    }
99
 
    
100
 
    /* check if address is aligned to the size */
101
 
    if(MV_IS_NOT_ALIGN(pAddrDecWin->addrWin.baseLow, pAddrDecWin->addrWin.size))
102
 
    {
103
 
                mvOsPrintf("mvAudioWinSet:Error setting AUDIO window %d to "\
104
 
                           "target %s.\nAddress 0x%08x is unaligned to size 0x%x.\n",
105
 
                           winNum,
106
 
                           mvCtrlTargetNameGet(pAddrDecWin->target), 
107
 
                           pAddrDecWin->addrWin.baseLow,
108
 
                           pAddrDecWin->addrWin.size);
109
 
                return MV_ERROR;
110
 
    }
111
 
 
112
 
    decRegs.baseReg = 0;
113
 
    decRegs.sizeReg = 0;
114
 
 
115
 
    if (MV_OK != mvCtrlAddrDecToReg(&(pAddrDecWin->addrWin),&decRegs))
116
 
    {
117
 
        mvOsPrintf("%s: mvCtrlAddrDecToReg Failed\n", __FUNCTION__);
118
 
        return MV_ERROR;
119
 
    }
120
 
 
121
 
    mvCtrlAttribGet(pAddrDecWin->target, &targetAttribs);
122
 
                                                                                                                         
123
 
    /* set attributes */
124
 
    decRegs.sizeReg &= ~MV_AUDIO_WIN_ATTR_MASK;
125
 
    decRegs.sizeReg |= (targetAttribs.attrib << MV_AUDIO_WIN_ATTR_OFFSET);
126
 
 
127
 
    /* set target ID */
128
 
    decRegs.sizeReg &= ~MV_AUDIO_WIN_TARGET_MASK;
129
 
    decRegs.sizeReg |= (targetAttribs.targetId << MV_AUDIO_WIN_TARGET_OFFSET);
130
 
 
131
 
    if (pAddrDecWin->enable == MV_TRUE)
132
 
    {
133
 
        decRegs.sizeReg |= MV_AUDIO_WIN_ENABLE_MASK;
134
 
    }
135
 
    else
136
 
    {
137
 
        decRegs.sizeReg &= ~MV_AUDIO_WIN_ENABLE_MASK;
138
 
    }
139
 
 
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);
142
 
    
143
 
    return MV_OK;
144
 
}
145
 
 
146
 
/*******************************************************************************
147
 
* mvAudioWinGet - Get AUDIO peripheral target address window.
148
 
*
149
 
* DESCRIPTION:
150
 
*       Get AUDIO peripheral target address window.
151
 
*
152
 
* INPUT:
153
 
*       winNum - AUDIO target address decode window number.
154
 
*
155
 
* OUTPUT:
156
 
*       pAddrDecWin - AUDIO target window data structure.
157
 
*
158
 
* RETURN:
159
 
*       MV_ERROR if register parameters are invalid.
160
 
*
161
 
*******************************************************************************/
162
 
MV_STATUS mvAudioWinGet(int unit, MV_U32 winNum, MV_AUDIO_DEC_WIN *pAddrDecWin)
163
 
{
164
 
    MV_DEC_REGS         decRegs;
165
 
    MV_TARGET_ATTRIB    targetAttrib;
166
 
                                                                                                                         
167
 
    /* Parameter checking   */
168
 
    if (winNum >= MV_AUDIO_MAX_ADDR_DECODE_WIN)
169
 
    {
170
 
        mvOsPrintf("%s : ERR. Invalid winNum %d\n", 
171
 
                    __FUNCTION__,  winNum);
172
 
        return MV_NOT_SUPPORTED;
173
 
    }
174
 
 
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) );
177
 
 
178
 
    if (MV_OK != mvCtrlRegToAddrDec(&decRegs, &pAddrDecWin->addrWin) )
179
 
    {
180
 
        mvOsPrintf("%s: mvCtrlRegToAddrDec Failed\n", __FUNCTION__);
181
 
        return MV_ERROR; 
182
 
    }
183
 
       
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;
189
 
 
190
 
    pAddrDecWin->target = mvCtrlTargetGet(&targetAttrib);
191
 
 
192
 
    /* Check if window is enabled   */
193
 
    if(decRegs.sizeReg & MV_AUDIO_WIN_ENABLE_MASK) 
194
 
    {
195
 
        pAddrDecWin->enable = MV_TRUE;
196
 
    }
197
 
    else
198
 
    {
199
 
        pAddrDecWin->enable = MV_FALSE;
200
 
    }
201
 
    return MV_OK;
202
 
}
203
 
/*******************************************************************************
204
 
* mvAudioAddrDecShow - Print the AUDIO address decode map.
205
 
*
206
 
* DESCRIPTION:
207
 
*               This function print the AUDIO address decode map.
208
 
*
209
 
* INPUT:
210
 
*       None.
211
 
*
212
 
* OUTPUT:
213
 
*       None.
214
 
*
215
 
* RETURN:
216
 
*       None.
217
 
*
218
 
*******************************************************************************/
219
 
MV_VOID mvAudioUnitAddrDecShow(int unit)
220
 
{
221
 
        MV_AUDIO_DEC_WIN win;
222
 
        int i;
223
 
 
224
 
        mvOsOutput( "\n" );
225
 
        mvOsOutput( "AUDIO:\n" );
226
 
        mvOsOutput( "----\n" );
227
 
 
228
 
        for( i = 0; i < MV_AUDIO_MAX_ADDR_DECODE_WIN; i++ )
229
 
        {
230
 
            memset( &win, 0, sizeof(MV_AUDIO_DEC_WIN) );
231
 
 
232
 
            mvOsOutput( "win%d - ", i );
233
 
 
234
 
            if( mvAudioWinGet(unit, i, &win) == MV_OK )
235
 
            {
236
 
                if( win.enable )
237
 
                {
238
 
                    mvOsOutput( "%s base %08x, ",
239
 
                    mvCtrlTargetNameGet(win.target), win.addrWin.baseLow );
240
 
                    mvOsOutput( "...." );
241
 
 
242
 
                    mvSizePrint( win.addrWin.size );
243
 
    
244
 
                    mvOsOutput( "\n" );
245
 
                }
246
 
                else
247
 
                mvOsOutput( "disable\n" );
248
 
            }
249
 
        }
250
 
}
251
 
 
252
 
MV_VOID mvAudioAddrDecShow(MV_VOID)
253
 
{
254
 
        int unit;
255
 
 
256
 
        for (unit = 0; unit < MV_AUDIO_MAX_UNITS; unit++)
257
 
        {
258
 
                if (MV_FALSE == mvCtrlPwrClckGet(AUDIO_UNIT_ID, unit)) continue;
259
 
 
260
 
                mvAudioUnitAddrDecShow(unit);
261
 
        } 
262
 
}
263
 
 
264
 
 
265
 
/*******************************************************************************
266
 
* mvAudioWinInit - Initialize the integrated AUDIO target address window.
267
 
*
268
 
* DESCRIPTION:
269
 
*       Initialize the AUDIO peripheral target address window.
270
 
*
271
 
* INPUT:
272
 
*
273
 
*
274
 
* OUTPUT:
275
 
*     
276
 
*
277
 
* RETURN:
278
 
*       MV_ERROR if register parameters are invalid.
279
 
*
280
 
*******************************************************************************/
281
 
MV_STATUS mvAudioWinInit(int unit)
282
 
{
283
 
    int             winNum;
284
 
    MV_AUDIO_DEC_WIN  audioWin;
285
 
    MV_CPU_DEC_WIN  cpuAddrDecWin;
286
 
    MV_U32          status;
287
 
 
288
 
    /* Initiate Audio address decode */
289
 
 
290
 
    /* First disable all address decode windows */
291
 
    for(winNum = 0; winNum < MV_AUDIO_MAX_ADDR_DECODE_WIN; winNum++)
292
 
    {
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);
296
 
    }
297
 
 
298
 
    for(winNum = 0; winNum < MV_AUDIO_MAX_ADDR_DECODE_WIN; winNum++)
299
 
    {
300
 
        /* We will set the Window to DRAM_CS0 in default */
301
 
        /* first get attributes from CPU If */
302
 
        status = mvCpuIfTargetWinGet(SDRAM_CS0, &cpuAddrDecWin);
303
 
        
304
 
        if (MV_OK != status)
305
 
        {
306
 
                mvOsPrintf("%s: ERR. mvCpuIfTargetWinGet failed\n", __FUNCTION__);
307
 
                return MV_ERROR;
308
 
        }
309
 
        
310
 
        if (cpuAddrDecWin.enable == MV_TRUE)
311
 
        {
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;
317
 
        
318
 
                if(MV_OK != mvAudioWinSet(unit, winNum, &audioWin))
319
 
                {
320
 
                        return MV_ERROR;
321
 
                }
322
 
        }
323
 
    }
324
 
 
325
 
    return MV_OK;
326
 
}
327
 
 
328
 
 
329
 
 
330
 
MV_STATUS mvAudioInit(MV_U8 unit)
331
 
{
332
 
        mvAudioWinInit(unit);
333
 
        mvAudioHalInit(unit);
334
 
        return MV_OK;
335
 
}
336
 
 
337