| 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(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(winNum), decRegs.sizeReg); |
| 141 | MV_REG_WRITE( MV_AUDIO_WIN_BASE_REG(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(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(winNum) ); |
| 176 | decRegs.sizeReg = MV_REG_READ( MV_AUDIO_WIN_CTRL_REG(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 mvAudioAddrDecShow(MV_VOID) |
| 220 | { |
| 221 | |
| 222 | MV_AUDIO_DEC_WIN win; |
| 223 | int i; |
| 224 | |
| 225 | if (MV_FALSE == mvCtrlPwrClckGet(AUDIO_UNIT_ID, 0)) |
| 226 | return; |
| 227 | |
| 228 | |
| 229 | mvOsOutput( "\n" ); |
| 230 | mvOsOutput( "AUDIO:\n" ); |
| 231 | mvOsOutput( "----\n" ); |
| 232 | |
| 233 | for( i = 0; i < MV_AUDIO_MAX_ADDR_DECODE_WIN; i++ ) |
| 234 | { |
| 235 | memset( &win, 0, sizeof(MV_AUDIO_DEC_WIN) ); |
| 236 | |
| 237 | mvOsOutput( "win%d - ", i ); |
| 238 | |
| 239 | if( mvAudioWinGet( i, &win ) == MV_OK ) |
| 240 | { |
| 241 | if( win.enable ) |
| 242 | { |
| 243 | mvOsOutput( "%s base %08x, ", |
| 244 | mvCtrlTargetNameGet(win.target), win.addrWin.baseLow ); |
| 245 | mvOsOutput( "...." ); |
| 246 | |
| 247 | mvSizePrint( win.addrWin.size ); |
| 248 | |
| 249 | mvOsOutput( "\n" ); |
| 250 | } |
| 251 | else |
| 252 | mvOsOutput( "disable\n" ); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | |
| 258 | /******************************************************************************* |
| 259 | * mvAudioWinInit - Initialize the integrated AUDIO target address window. |
| 260 | * |
| 261 | * DESCRIPTION: |
| 262 | * Initialize the AUDIO peripheral target address window. |
| 263 | * |
| 264 | * INPUT: |
| 265 | * |
| 266 | * |
| 267 | * OUTPUT: |
| 268 | * |
| 269 | * |
| 270 | * RETURN: |
| 271 | * MV_ERROR if register parameters are invalid. |
| 272 | * |
| 273 | *******************************************************************************/ |
| 274 | MV_STATUS mvAudioInit(MV_VOID) |
| 275 | { |
| 276 | int winNum; |
| 277 | MV_AUDIO_DEC_WIN audioWin; |
| 278 | MV_CPU_DEC_WIN cpuAddrDecWin; |
| 279 | MV_U32 status; |
| 280 | |
| 281 | mvAudioHalInit(); |
| 282 | |
| 283 | /* Initiate Audio address decode */ |
| 284 | |
| 285 | /* First disable all address decode windows */ |
| 286 | for(winNum = 0; winNum < MV_AUDIO_MAX_ADDR_DECODE_WIN; winNum++) |
| 287 | { |
| 288 | MV_U32 regVal = MV_REG_READ(MV_AUDIO_WIN_CTRL_REG(winNum)); |
| 289 | regVal &= ~MV_AUDIO_WIN_ENABLE_MASK; |
| 290 | MV_REG_WRITE(MV_AUDIO_WIN_CTRL_REG(winNum), regVal); |
| 291 | } |
| 292 | |
| 293 | for(winNum = 0; winNum < MV_AUDIO_MAX_ADDR_DECODE_WIN; winNum++) |
| 294 | { |
| 295 | |
| 296 | /* We will set the Window to DRAM_CS0 in default */ |
| 297 | /* first get attributes from CPU If */ |
| 298 | status = mvCpuIfTargetWinGet(SDRAM_CS0, |
| 299 | &cpuAddrDecWin); |
| 300 | |
| 301 | if (MV_OK != status) |
| 302 | { |
| 303 | mvOsPrintf("%s: ERR. mvCpuIfTargetWinGet failed\n", __FUNCTION__); |
| 304 | return MV_ERROR; |
| 305 | } |
| 306 | |
| 307 | if (cpuAddrDecWin.enable == MV_TRUE) |
| 308 | { |
| 309 | audioWin.addrWin.baseHigh = cpuAddrDecWin.addrWin.baseHigh; |
| 310 | audioWin.addrWin.baseLow = cpuAddrDecWin.addrWin.baseLow; |
| 311 | audioWin.addrWin.size = cpuAddrDecWin.addrWin.size; |
| 312 | audioWin.enable = MV_TRUE; |
| 313 | audioWin.target = SDRAM_CS0; |
| 314 | |
| 315 | if(MV_OK != mvAudioWinSet(winNum, &audioWin)) |
| 316 | { |
| 317 | return MV_ERROR; |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | return MV_OK; |
| 323 | } |
| 324 | |
| 325 | |