Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * tp3780i.c -- board driver for 3780i on ThinkPads |
| 4 | * |
| 5 | * |
| 6 | * Written By: Mike Sullivan IBM Corporation |
| 7 | * |
| 8 | * Copyright (C) 1999 IBM Corporation |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * NO WARRANTY |
| 21 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 22 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT |
| 23 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, |
| 24 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is |
| 25 | * solely responsible for determining the appropriateness of using and |
| 26 | * distributing the Program and assumes all risks associated with its |
| 27 | * exercise of rights under this Agreement, including but not limited to |
| 28 | * the risks and costs of program errors, damage to or loss of data, |
| 29 | * programs or equipment, and unavailability or interruption of operations. |
| 30 | * |
| 31 | * DISCLAIMER OF LIABILITY |
| 32 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY |
| 33 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 34 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND |
| 35 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 36 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 37 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED |
| 38 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES |
| 39 | * |
| 40 | * You should have received a copy of the GNU General Public License |
| 41 | * along with this program; if not, write to the Free Software |
| 42 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 43 | * |
| 44 | * |
| 45 | * 10/23/2000 - Alpha Release |
| 46 | * First release to the public |
| 47 | */ |
| 48 | |
| 49 | #include <linux/version.h> |
| 50 | #include <linux/interrupt.h> |
| 51 | #include <linux/kernel.h> |
| 52 | #include <linux/ptrace.h> |
| 53 | #include <linux/ioport.h> |
| 54 | #include <asm/io.h> |
| 55 | #include "smapi.h" |
| 56 | #include "mwavedd.h" |
| 57 | #include "tp3780i.h" |
| 58 | #include "3780i.h" |
| 59 | #include "mwavepub.h" |
| 60 | |
| 61 | extern MWAVE_DEVICE_DATA mwave_s_mdd; |
| 62 | |
| 63 | static unsigned short s_ausThinkpadIrqToField[16] = |
| 64 | { 0xFFFF, 0xFFFF, 0xFFFF, 0x0001, 0x0002, 0x0003, 0xFFFF, 0x0004, |
| 65 | 0xFFFF, 0xFFFF, 0x0005, 0x0006, 0xFFFF, 0xFFFF, 0xFFFF, 0x0007 }; |
| 66 | static unsigned short s_ausThinkpadDmaToField[8] = |
| 67 | { 0x0001, 0x0002, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0003, 0x0004 }; |
| 68 | static unsigned short s_numIrqs = 16, s_numDmas = 8; |
| 69 | |
| 70 | |
| 71 | static void EnableSRAM(THINKPAD_BD_DATA * pBDData) |
| 72 | { |
| 73 | DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings; |
| 74 | unsigned short usDspBaseIO = pSettings->usDspBaseIO; |
| 75 | DSP_GPIO_OUTPUT_DATA_15_8 rGpioOutputData; |
| 76 | DSP_GPIO_DRIVER_ENABLE_15_8 rGpioDriverEnable; |
| 77 | DSP_GPIO_MODE_15_8 rGpioMode; |
| 78 | |
| 79 | PRINTK_1(TRACE_TP3780I, "tp3780i::EnableSRAM, entry\n"); |
| 80 | |
| 81 | MKWORD(rGpioMode) = ReadMsaCfg(DSP_GpioModeControl_15_8); |
| 82 | rGpioMode.GpioMode10 = 0; |
| 83 | WriteMsaCfg(DSP_GpioModeControl_15_8, MKWORD(rGpioMode)); |
| 84 | |
| 85 | MKWORD(rGpioDriverEnable) = 0; |
| 86 | rGpioDriverEnable.Enable10 = TRUE; |
| 87 | rGpioDriverEnable.Mask10 = TRUE; |
| 88 | WriteMsaCfg(DSP_GpioDriverEnable_15_8, MKWORD(rGpioDriverEnable)); |
| 89 | |
| 90 | MKWORD(rGpioOutputData) = 0; |
| 91 | rGpioOutputData.Latch10 = 0; |
| 92 | rGpioOutputData.Mask10 = TRUE; |
| 93 | WriteMsaCfg(DSP_GpioOutputData_15_8, MKWORD(rGpioOutputData)); |
| 94 | |
| 95 | PRINTK_1(TRACE_TP3780I, "tp3780i::EnableSRAM exit\n"); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | static irqreturn_t UartInterrupt(int irq, void *dev_id, struct pt_regs *regs) |
| 100 | { |
| 101 | PRINTK_3(TRACE_TP3780I, |
| 102 | "tp3780i::UartInterrupt entry irq %x dev_id %p\n", irq, dev_id); |
| 103 | return IRQ_HANDLED; |
| 104 | } |
| 105 | |
| 106 | static irqreturn_t DspInterrupt(int irq, void *dev_id, struct pt_regs *regs) |
| 107 | { |
| 108 | pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd; |
| 109 | DSP_3780I_CONFIG_SETTINGS *pSettings = &pDrvData->rBDData.rDspSettings; |
| 110 | unsigned short usDspBaseIO = pSettings->usDspBaseIO; |
| 111 | unsigned short usIPCSource = 0, usIsolationMask, usPCNum; |
| 112 | |
| 113 | PRINTK_3(TRACE_TP3780I, |
| 114 | "tp3780i::DspInterrupt entry irq %x dev_id %p\n", irq, dev_id); |
| 115 | |
| 116 | if (dsp3780I_GetIPCSource(usDspBaseIO, &usIPCSource) == 0) { |
| 117 | PRINTK_2(TRACE_TP3780I, |
| 118 | "tp3780i::DspInterrupt, return from dsp3780i_GetIPCSource, usIPCSource %x\n", |
| 119 | usIPCSource); |
| 120 | usIsolationMask = 1; |
| 121 | for (usPCNum = 1; usPCNum <= 16; usPCNum++) { |
| 122 | if (usIPCSource & usIsolationMask) { |
| 123 | usIPCSource &= ~usIsolationMask; |
| 124 | PRINTK_3(TRACE_TP3780I, |
| 125 | "tp3780i::DspInterrupt usPCNum %x usIPCSource %x\n", |
| 126 | usPCNum, usIPCSource); |
| 127 | if (pDrvData->IPCs[usPCNum - 1].usIntCount == 0) { |
| 128 | pDrvData->IPCs[usPCNum - 1].usIntCount = 1; |
| 129 | } |
| 130 | PRINTK_2(TRACE_TP3780I, |
| 131 | "tp3780i::DspInterrupt usIntCount %x\n", |
| 132 | pDrvData->IPCs[usPCNum - 1].usIntCount); |
| 133 | if (pDrvData->IPCs[usPCNum - 1].bIsEnabled == TRUE) { |
| 134 | PRINTK_2(TRACE_TP3780I, |
| 135 | "tp3780i::DspInterrupt, waking up usPCNum %x\n", |
| 136 | usPCNum - 1); |
| 137 | wake_up_interruptible(&pDrvData->IPCs[usPCNum - 1].ipc_wait_queue); |
| 138 | } else { |
| 139 | PRINTK_2(TRACE_TP3780I, |
| 140 | "tp3780i::DspInterrupt, no one waiting for IPC %x\n", |
| 141 | usPCNum - 1); |
| 142 | } |
| 143 | } |
| 144 | if (usIPCSource == 0) |
| 145 | break; |
| 146 | /* try next IPC */ |
| 147 | usIsolationMask = usIsolationMask << 1; |
| 148 | } |
| 149 | } else { |
| 150 | PRINTK_1(TRACE_TP3780I, |
| 151 | "tp3780i::DspInterrupt, return false from dsp3780i_GetIPCSource\n"); |
| 152 | } |
| 153 | PRINTK_1(TRACE_TP3780I, "tp3780i::DspInterrupt exit\n"); |
| 154 | return IRQ_HANDLED; |
| 155 | } |
| 156 | |
| 157 | |
| 158 | int tp3780I_InitializeBoardData(THINKPAD_BD_DATA * pBDData) |
| 159 | { |
| 160 | int retval = 0; |
| 161 | DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings; |
| 162 | |
| 163 | |
| 164 | PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_InitializeBoardData entry pBDData %p\n", pBDData); |
| 165 | |
| 166 | pBDData->bDSPEnabled = FALSE; |
| 167 | pSettings->bInterruptClaimed = FALSE; |
| 168 | |
| 169 | retval = smapi_init(); |
| 170 | if (retval) { |
| 171 | PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_InitializeBoardData: Error: SMAPI is not available on this machine\n"); |
| 172 | } else { |
| 173 | if (mwave_3780i_irq || mwave_3780i_io || mwave_uart_irq || mwave_uart_io) { |
| 174 | retval = smapi_set_DSP_cfg(); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_InitializeBoardData exit retval %x\n", retval); |
| 179 | |
| 180 | return retval; |
| 181 | } |
| 182 | |
| 183 | int tp3780I_Cleanup(THINKPAD_BD_DATA * pBDData) |
| 184 | { |
| 185 | int retval = 0; |
| 186 | |
| 187 | PRINTK_2(TRACE_TP3780I, |
| 188 | "tp3780i::tp3780I_Cleanup entry and exit pBDData %p\n", pBDData); |
| 189 | |
| 190 | return retval; |
| 191 | } |
| 192 | |
| 193 | int tp3780I_CalcResources(THINKPAD_BD_DATA * pBDData) |
| 194 | { |
| 195 | SMAPI_DSP_SETTINGS rSmapiInfo; |
| 196 | DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings; |
| 197 | |
| 198 | PRINTK_2(TRACE_TP3780I, |
| 199 | "tp3780i::tp3780I_CalcResources entry pBDData %p\n", pBDData); |
| 200 | |
| 201 | if (smapi_query_DSP_cfg(&rSmapiInfo)) { |
| 202 | PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_CalcResources: Error: Could not query DSP config. Aborting.\n"); |
| 203 | return -EIO; |
| 204 | } |
| 205 | |
| 206 | /* Sanity check */ |
| 207 | if ( |
| 208 | ( rSmapiInfo.usDspIRQ == 0 ) |
| 209 | || ( rSmapiInfo.usDspBaseIO == 0 ) |
| 210 | || ( rSmapiInfo.usUartIRQ == 0 ) |
| 211 | || ( rSmapiInfo.usUartBaseIO == 0 ) |
| 212 | ) { |
| 213 | PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_CalcResources: Error: Illegal resource setting. Aborting.\n"); |
| 214 | return -EIO; |
| 215 | } |
| 216 | |
| 217 | pSettings->bDSPEnabled = (rSmapiInfo.bDSPEnabled && rSmapiInfo.bDSPPresent); |
| 218 | pSettings->bModemEnabled = rSmapiInfo.bModemEnabled; |
| 219 | pSettings->usDspIrq = rSmapiInfo.usDspIRQ; |
| 220 | pSettings->usDspDma = rSmapiInfo.usDspDMA; |
| 221 | pSettings->usDspBaseIO = rSmapiInfo.usDspBaseIO; |
| 222 | pSettings->usUartIrq = rSmapiInfo.usUartIRQ; |
| 223 | pSettings->usUartBaseIO = rSmapiInfo.usUartBaseIO; |
| 224 | |
| 225 | pSettings->uDStoreSize = TP_ABILITIES_DATA_SIZE; |
| 226 | pSettings->uIStoreSize = TP_ABILITIES_INST_SIZE; |
| 227 | pSettings->uIps = TP_ABILITIES_INTS_PER_SEC; |
| 228 | |
| 229 | if (pSettings->bDSPEnabled && pSettings->bModemEnabled && pSettings->usDspIrq == pSettings->usUartIrq) { |
| 230 | pBDData->bShareDspIrq = pBDData->bShareUartIrq = 1; |
| 231 | } else { |
| 232 | pBDData->bShareDspIrq = pBDData->bShareUartIrq = 0; |
| 233 | } |
| 234 | |
| 235 | PRINTK_1(TRACE_TP3780I, "tp3780i::tp3780I_CalcResources exit\n"); |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | |
| 241 | int tp3780I_ClaimResources(THINKPAD_BD_DATA * pBDData) |
| 242 | { |
| 243 | int retval = 0; |
| 244 | DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | struct resource *pres; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | PRINTK_2(TRACE_TP3780I, |
| 248 | "tp3780i::tp3780I_ClaimResources entry pBDData %p\n", pBDData); |
| 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | pres = request_region(pSettings->usDspBaseIO, 16, "mwave_3780i"); |
| 251 | if ( pres == NULL ) retval = -EIO; |
Adrian Bunk | c97f97b | 2005-06-25 14:58:55 -0700 | [diff] [blame^] | 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | if (retval) { |
| 254 | PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_ClaimResources: Error: Could not claim I/O region starting at %x\n", pSettings->usDspBaseIO); |
| 255 | retval = -EIO; |
| 256 | } |
| 257 | |
| 258 | PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_ClaimResources exit retval %x\n", retval); |
| 259 | |
| 260 | return retval; |
| 261 | } |
| 262 | |
| 263 | int tp3780I_ReleaseResources(THINKPAD_BD_DATA * pBDData) |
| 264 | { |
| 265 | int retval = 0; |
| 266 | DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings; |
| 267 | |
| 268 | PRINTK_2(TRACE_TP3780I, |
| 269 | "tp3780i::tp3780I_ReleaseResources entry pBDData %p\n", pBDData); |
| 270 | |
| 271 | release_region(pSettings->usDspBaseIO & (~3), 16); |
| 272 | |
| 273 | if (pSettings->bInterruptClaimed) { |
| 274 | free_irq(pSettings->usDspIrq, NULL); |
| 275 | pSettings->bInterruptClaimed = FALSE; |
| 276 | } |
| 277 | |
| 278 | PRINTK_2(TRACE_TP3780I, |
| 279 | "tp3780i::tp3780I_ReleaseResources exit retval %x\n", retval); |
| 280 | |
| 281 | return retval; |
| 282 | } |
| 283 | |
| 284 | |
| 285 | |
| 286 | int tp3780I_EnableDSP(THINKPAD_BD_DATA * pBDData) |
| 287 | { |
| 288 | DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings; |
| 289 | BOOLEAN bDSPPoweredUp = FALSE, bDSPEnabled = FALSE, bInterruptAllocated = FALSE; |
| 290 | |
| 291 | PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_EnableDSP entry pBDData %p\n", pBDData); |
| 292 | |
| 293 | if (pBDData->bDSPEnabled) { |
| 294 | PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: DSP already enabled!\n"); |
| 295 | goto exit_cleanup; |
| 296 | } |
| 297 | |
| 298 | if (!pSettings->bDSPEnabled) { |
| 299 | PRINTK_ERROR(KERN_ERR_MWAVE "tp3780::tp3780I_EnableDSP: Error: pSettings->bDSPEnabled not set\n"); |
| 300 | goto exit_cleanup; |
| 301 | } |
| 302 | |
| 303 | if ( |
| 304 | (pSettings->usDspIrq >= s_numIrqs) |
| 305 | || (pSettings->usDspDma >= s_numDmas) |
| 306 | || (s_ausThinkpadIrqToField[pSettings->usDspIrq] == 0xFFFF) |
| 307 | || (s_ausThinkpadDmaToField[pSettings->usDspDma] == 0xFFFF) |
| 308 | ) { |
| 309 | PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: invalid irq %x\n", pSettings->usDspIrq); |
| 310 | goto exit_cleanup; |
| 311 | } |
| 312 | |
| 313 | if ( |
| 314 | ((pSettings->usDspBaseIO & 0xF00F) != 0) |
| 315 | || (pSettings->usDspBaseIO & 0x0FF0) == 0 |
| 316 | ) { |
| 317 | PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: Invalid DSP base I/O address %x\n", pSettings->usDspBaseIO); |
| 318 | goto exit_cleanup; |
| 319 | } |
| 320 | |
| 321 | if (pSettings->bModemEnabled) { |
| 322 | if ( |
| 323 | pSettings->usUartIrq >= s_numIrqs |
| 324 | || s_ausThinkpadIrqToField[pSettings->usUartIrq] == 0xFFFF |
| 325 | ) { |
| 326 | PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: Invalid UART IRQ %x\n", pSettings->usUartIrq); |
| 327 | goto exit_cleanup; |
| 328 | } |
| 329 | switch (pSettings->usUartBaseIO) { |
| 330 | case 0x03F8: |
| 331 | case 0x02F8: |
| 332 | case 0x03E8: |
| 333 | case 0x02E8: |
| 334 | break; |
| 335 | |
| 336 | default: |
| 337 | PRINTK_ERROR("tp3780i::tp3780I_EnableDSP: Error: Invalid UART base I/O address %x\n", pSettings->usUartBaseIO); |
| 338 | goto exit_cleanup; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | pSettings->bDspIrqActiveLow = pSettings->bDspIrqPulse = TRUE; |
| 343 | pSettings->bUartIrqActiveLow = pSettings->bUartIrqPulse = TRUE; |
| 344 | |
| 345 | if (pBDData->bShareDspIrq) { |
| 346 | pSettings->bDspIrqActiveLow = FALSE; |
| 347 | } |
| 348 | if (pBDData->bShareUartIrq) { |
| 349 | pSettings->bUartIrqActiveLow = FALSE; |
| 350 | } |
| 351 | |
| 352 | pSettings->usNumTransfers = TP_CFG_NumTransfers; |
| 353 | pSettings->usReRequest = TP_CFG_RerequestTimer; |
| 354 | pSettings->bEnableMEMCS16 = TP_CFG_MEMCS16; |
| 355 | pSettings->usIsaMemCmdWidth = TP_CFG_IsaMemCmdWidth; |
| 356 | pSettings->bGateIOCHRDY = TP_CFG_GateIOCHRDY; |
| 357 | pSettings->bEnablePwrMgmt = TP_CFG_EnablePwrMgmt; |
| 358 | pSettings->usHBusTimerLoadValue = TP_CFG_HBusTimerValue; |
| 359 | pSettings->bDisableLBusTimeout = TP_CFG_DisableLBusTimeout; |
| 360 | pSettings->usN_Divisor = TP_CFG_N_Divisor; |
| 361 | pSettings->usM_Multiplier = TP_CFG_M_Multiplier; |
| 362 | pSettings->bPllBypass = TP_CFG_PllBypass; |
| 363 | pSettings->usChipletEnable = TP_CFG_ChipletEnable; |
| 364 | |
| 365 | if (request_irq(pSettings->usUartIrq, &UartInterrupt, 0, "mwave_uart", NULL)) { |
| 366 | PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: Could not get UART IRQ %x\n", pSettings->usUartIrq); |
| 367 | goto exit_cleanup; |
| 368 | } else { /* no conflict just release */ |
| 369 | free_irq(pSettings->usUartIrq, NULL); |
| 370 | } |
| 371 | |
| 372 | if (request_irq(pSettings->usDspIrq, &DspInterrupt, 0, "mwave_3780i", NULL)) { |
| 373 | PRINTK_ERROR("tp3780i::tp3780I_EnableDSP: Error: Could not get 3780i IRQ %x\n", pSettings->usDspIrq); |
| 374 | goto exit_cleanup; |
| 375 | } else { |
| 376 | PRINTK_3(TRACE_TP3780I, |
| 377 | "tp3780i::tp3780I_EnableDSP, got interrupt %x bShareDspIrq %x\n", |
| 378 | pSettings->usDspIrq, pBDData->bShareDspIrq); |
| 379 | bInterruptAllocated = TRUE; |
| 380 | pSettings->bInterruptClaimed = TRUE; |
| 381 | } |
| 382 | |
| 383 | smapi_set_DSP_power_state(FALSE); |
| 384 | if (smapi_set_DSP_power_state(TRUE)) { |
| 385 | PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: smapi_set_DSP_power_state(TRUE) failed\n"); |
| 386 | goto exit_cleanup; |
| 387 | } else { |
| 388 | bDSPPoweredUp = TRUE; |
| 389 | } |
| 390 | |
| 391 | if (dsp3780I_EnableDSP(pSettings, s_ausThinkpadIrqToField, s_ausThinkpadDmaToField)) { |
| 392 | PRINTK_ERROR("tp3780i::tp3780I_EnableDSP: Error: dsp7880I_EnableDSP() failed\n"); |
| 393 | goto exit_cleanup; |
| 394 | } else { |
| 395 | bDSPEnabled = TRUE; |
| 396 | } |
| 397 | |
| 398 | EnableSRAM(pBDData); |
| 399 | |
| 400 | pBDData->bDSPEnabled = TRUE; |
| 401 | |
| 402 | PRINTK_1(TRACE_TP3780I, "tp3780i::tp3780I_EnableDSP exit\n"); |
| 403 | |
| 404 | return 0; |
| 405 | |
| 406 | exit_cleanup: |
| 407 | PRINTK_ERROR("tp3780i::tp3780I_EnableDSP: Cleaning up\n"); |
| 408 | if (bDSPEnabled) |
| 409 | dsp3780I_DisableDSP(pSettings); |
| 410 | if (bDSPPoweredUp) |
| 411 | smapi_set_DSP_power_state(FALSE); |
| 412 | if (bInterruptAllocated) { |
| 413 | free_irq(pSettings->usDspIrq, NULL); |
| 414 | pSettings->bInterruptClaimed = FALSE; |
| 415 | } |
| 416 | return -EIO; |
| 417 | } |
| 418 | |
| 419 | |
| 420 | int tp3780I_DisableDSP(THINKPAD_BD_DATA * pBDData) |
| 421 | { |
| 422 | int retval = 0; |
| 423 | DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings; |
| 424 | |
| 425 | PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_DisableDSP entry pBDData %p\n", pBDData); |
| 426 | |
| 427 | if (pBDData->bDSPEnabled) { |
| 428 | dsp3780I_DisableDSP(&pBDData->rDspSettings); |
| 429 | if (pSettings->bInterruptClaimed) { |
| 430 | free_irq(pSettings->usDspIrq, NULL); |
| 431 | pSettings->bInterruptClaimed = FALSE; |
| 432 | } |
| 433 | smapi_set_DSP_power_state(FALSE); |
| 434 | pBDData->bDSPEnabled = FALSE; |
| 435 | } |
| 436 | |
| 437 | PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_DisableDSP exit retval %x\n", retval); |
| 438 | |
| 439 | return retval; |
| 440 | } |
| 441 | |
| 442 | |
| 443 | int tp3780I_ResetDSP(THINKPAD_BD_DATA * pBDData) |
| 444 | { |
| 445 | int retval = 0; |
| 446 | DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings; |
| 447 | |
| 448 | PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_ResetDSP entry pBDData %p\n", |
| 449 | pBDData); |
| 450 | |
| 451 | if (dsp3780I_Reset(pSettings) == 0) { |
| 452 | EnableSRAM(pBDData); |
| 453 | } else { |
| 454 | retval = -EIO; |
| 455 | } |
| 456 | |
| 457 | PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_ResetDSP exit retval %x\n", retval); |
| 458 | |
| 459 | return retval; |
| 460 | } |
| 461 | |
| 462 | |
| 463 | int tp3780I_StartDSP(THINKPAD_BD_DATA * pBDData) |
| 464 | { |
| 465 | int retval = 0; |
| 466 | DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings; |
| 467 | |
| 468 | PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_StartDSP entry pBDData %p\n", pBDData); |
| 469 | |
| 470 | if (dsp3780I_Run(pSettings) == 0) { |
| 471 | // @BUG @TBD EnableSRAM(pBDData); |
| 472 | } else { |
| 473 | retval = -EIO; |
| 474 | } |
| 475 | |
| 476 | PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_StartDSP exit retval %x\n", retval); |
| 477 | |
| 478 | return retval; |
| 479 | } |
| 480 | |
| 481 | |
| 482 | int tp3780I_QueryAbilities(THINKPAD_BD_DATA * pBDData, MW_ABILITIES * pAbilities) |
| 483 | { |
| 484 | int retval = 0; |
| 485 | |
| 486 | PRINTK_2(TRACE_TP3780I, |
| 487 | "tp3780i::tp3780I_QueryAbilities entry pBDData %p\n", pBDData); |
| 488 | |
| 489 | /* fill out standard constant fields */ |
| 490 | pAbilities->instr_per_sec = pBDData->rDspSettings.uIps; |
| 491 | pAbilities->data_size = pBDData->rDspSettings.uDStoreSize; |
| 492 | pAbilities->inst_size = pBDData->rDspSettings.uIStoreSize; |
| 493 | pAbilities->bus_dma_bw = pBDData->rDspSettings.uDmaBandwidth; |
| 494 | |
| 495 | /* fill out dynamically determined fields */ |
| 496 | pAbilities->component_list[0] = 0x00010000 | MW_ADC_MASK; |
| 497 | pAbilities->component_list[1] = 0x00010000 | MW_ACI_MASK; |
| 498 | pAbilities->component_list[2] = 0x00010000 | MW_AIC1_MASK; |
| 499 | pAbilities->component_list[3] = 0x00010000 | MW_AIC2_MASK; |
| 500 | pAbilities->component_list[4] = 0x00010000 | MW_CDDAC_MASK; |
| 501 | pAbilities->component_list[5] = 0x00010000 | MW_MIDI_MASK; |
| 502 | pAbilities->component_list[6] = 0x00010000 | MW_UART_MASK; |
| 503 | pAbilities->component_count = 7; |
| 504 | |
| 505 | /* Fill out Mwave OS and BIOS task names */ |
| 506 | |
| 507 | memcpy(pAbilities->mwave_os_name, TP_ABILITIES_MWAVEOS_NAME, |
| 508 | sizeof(TP_ABILITIES_MWAVEOS_NAME)); |
| 509 | memcpy(pAbilities->bios_task_name, TP_ABILITIES_BIOSTASK_NAME, |
| 510 | sizeof(TP_ABILITIES_BIOSTASK_NAME)); |
| 511 | |
| 512 | PRINTK_1(TRACE_TP3780I, |
| 513 | "tp3780i::tp3780I_QueryAbilities exit retval=SUCCESSFUL\n"); |
| 514 | |
| 515 | return retval; |
| 516 | } |
| 517 | |
| 518 | int tp3780I_ReadWriteDspDStore(THINKPAD_BD_DATA * pBDData, unsigned int uOpcode, |
| 519 | void __user *pvBuffer, unsigned int uCount, |
| 520 | unsigned long ulDSPAddr) |
| 521 | { |
| 522 | int retval = 0; |
| 523 | DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings; |
| 524 | unsigned short usDspBaseIO = pSettings->usDspBaseIO; |
| 525 | BOOLEAN bRC = 0; |
| 526 | |
| 527 | PRINTK_6(TRACE_TP3780I, |
| 528 | "tp3780i::tp3780I_ReadWriteDspDStore entry pBDData %p, uOpcode %x, pvBuffer %p, uCount %x, ulDSPAddr %lx\n", |
| 529 | pBDData, uOpcode, pvBuffer, uCount, ulDSPAddr); |
| 530 | |
| 531 | if (pBDData->bDSPEnabled) { |
| 532 | switch (uOpcode) { |
| 533 | case IOCTL_MW_READ_DATA: |
| 534 | bRC = dsp3780I_ReadDStore(usDspBaseIO, pvBuffer, uCount, ulDSPAddr); |
| 535 | break; |
| 536 | |
| 537 | case IOCTL_MW_READCLEAR_DATA: |
| 538 | bRC = dsp3780I_ReadAndClearDStore(usDspBaseIO, pvBuffer, uCount, ulDSPAddr); |
| 539 | break; |
| 540 | |
| 541 | case IOCTL_MW_WRITE_DATA: |
| 542 | bRC = dsp3780I_WriteDStore(usDspBaseIO, pvBuffer, uCount, ulDSPAddr); |
| 543 | break; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | retval = (bRC) ? -EIO : 0; |
| 548 | PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_ReadWriteDspDStore exit retval %x\n", retval); |
| 549 | |
| 550 | return retval; |
| 551 | } |
| 552 | |
| 553 | |
| 554 | int tp3780I_ReadWriteDspIStore(THINKPAD_BD_DATA * pBDData, unsigned int uOpcode, |
| 555 | void __user *pvBuffer, unsigned int uCount, |
| 556 | unsigned long ulDSPAddr) |
| 557 | { |
| 558 | int retval = 0; |
| 559 | DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings; |
| 560 | unsigned short usDspBaseIO = pSettings->usDspBaseIO; |
| 561 | BOOLEAN bRC = 0; |
| 562 | |
| 563 | PRINTK_6(TRACE_TP3780I, |
| 564 | "tp3780i::tp3780I_ReadWriteDspIStore entry pBDData %p, uOpcode %x, pvBuffer %p, uCount %x, ulDSPAddr %lx\n", |
| 565 | pBDData, uOpcode, pvBuffer, uCount, ulDSPAddr); |
| 566 | |
| 567 | if (pBDData->bDSPEnabled) { |
| 568 | switch (uOpcode) { |
| 569 | case IOCTL_MW_READ_INST: |
| 570 | bRC = dsp3780I_ReadIStore(usDspBaseIO, pvBuffer, uCount, ulDSPAddr); |
| 571 | break; |
| 572 | |
| 573 | case IOCTL_MW_WRITE_INST: |
| 574 | bRC = dsp3780I_WriteIStore(usDspBaseIO, pvBuffer, uCount, ulDSPAddr); |
| 575 | break; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | retval = (bRC) ? -EIO : 0; |
| 580 | |
| 581 | PRINTK_2(TRACE_TP3780I, |
| 582 | "tp3780i::tp3780I_ReadWriteDspIStore exit retval %x\n", retval); |
| 583 | |
| 584 | return retval; |
| 585 | } |
| 586 | |