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/kernel.h>
51 #include <linux/ptrace.h>
52 #include <linux/ioport.h>
53 #include <asm/io.h>
54 #include "smapi.h"
55 #include "mwavedd.h"
56 #include "tp3780i.h"
57 #include "3780i.h"
58 #include "mwavepub.h"
59 
60 extern MWAVE_DEVICE_DATA mwave_s_mdd;
61 
62 static unsigned short s_ausThinkpadIrqToField[16] =
63 	{ 0xFFFF, 0xFFFF, 0xFFFF, 0x0001, 0x0002, 0x0003, 0xFFFF, 0x0004,
64 	0xFFFF, 0xFFFF, 0x0005, 0x0006, 0xFFFF, 0xFFFF, 0xFFFF, 0x0007 };
65 static unsigned short s_ausThinkpadDmaToField[8] =
66 	{ 0x0001, 0x0002, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0003, 0x0004 };
67 static unsigned short s_numIrqs = 16, s_numDmas = 8;
68 
69 
EnableSRAM(THINKPAD_BD_DATA * pBDData)70 static void EnableSRAM(THINKPAD_BD_DATA * pBDData)
71 {
72 	DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings;
73 	unsigned short usDspBaseIO = pSettings->usDspBaseIO;
74 	DSP_GPIO_OUTPUT_DATA_15_8 rGpioOutputData;
75 	DSP_GPIO_DRIVER_ENABLE_15_8 rGpioDriverEnable;
76 	DSP_GPIO_MODE_15_8 rGpioMode;
77 
78 	PRINTK_1(TRACE_TP3780I, "tp3780i::EnableSRAM, entry\n");
79 
80 	MKWORD(rGpioMode) = ReadMsaCfg(DSP_GpioModeControl_15_8);
81 	rGpioMode.GpioMode10 = 0;
82 	WriteMsaCfg(DSP_GpioModeControl_15_8, MKWORD(rGpioMode));
83 
84 	MKWORD(rGpioDriverEnable) = 0;
85 	rGpioDriverEnable.Enable10 = TRUE;
86 	rGpioDriverEnable.Mask10 = TRUE;
87 	WriteMsaCfg(DSP_GpioDriverEnable_15_8, MKWORD(rGpioDriverEnable));
88 
89 	MKWORD(rGpioOutputData) = 0;
90 	rGpioOutputData.Latch10 = 0;
91 	rGpioOutputData.Mask10 = TRUE;
92 	WriteMsaCfg(DSP_GpioOutputData_15_8, MKWORD(rGpioOutputData));
93 
94 	PRINTK_1(TRACE_TP3780I, "tp3780i::EnableSRAM exit\n");
95 }
96 
97 
UartInterrupt(int irq,void * dev_id,struct pt_regs * regs)98 static void UartInterrupt(int irq, void *dev_id, struct pt_regs *regs)
99 {
100 	PRINTK_3(TRACE_TP3780I,
101 		"tp3780i::UartInterrupt entry irq %x dev_id %x\n", irq, (int) dev_id);
102 }
103 
DspInterrupt(int irq,void * dev_id,struct pt_regs * regs)104 static void DspInterrupt(int irq, void *dev_id, struct pt_regs *regs)
105 {
106 	pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd;
107 	DSP_3780I_CONFIG_SETTINGS *pSettings = &pDrvData->rBDData.rDspSettings;
108 	unsigned short usDspBaseIO = pSettings->usDspBaseIO;
109 	unsigned short usIPCSource = 0, usIsolationMask, usPCNum;
110 
111 	PRINTK_3(TRACE_TP3780I,
112 		"tp3780i::DspInterrupt entry irq %x dev_id %x\n", irq, (int) dev_id);
113 
114 	if (dsp3780I_GetIPCSource(usDspBaseIO, &usIPCSource) == 0) {
115 		PRINTK_2(TRACE_TP3780I,
116 			"tp3780i::DspInterrupt, return from dsp3780i_GetIPCSource, usIPCSource %x\n",
117 			usIPCSource);
118 		usIsolationMask = 1;
119 		for (usPCNum = 1; usPCNum <= 16; usPCNum++) {
120 			if (usIPCSource & usIsolationMask) {
121 				usIPCSource &= ~usIsolationMask;
122 				PRINTK_3(TRACE_TP3780I,
123 					"tp3780i::DspInterrupt usPCNum %x usIPCSource %x\n",
124 					usPCNum, usIPCSource);
125 				if (pDrvData->IPCs[usPCNum - 1].usIntCount == 0) {
126 					pDrvData->IPCs[usPCNum - 1].usIntCount = 1;
127 				}
128 				PRINTK_2(TRACE_TP3780I,
129 					"tp3780i::DspInterrupt usIntCount %x\n",
130 					pDrvData->IPCs[usPCNum - 1].usIntCount);
131 				if (pDrvData->IPCs[usPCNum - 1].bIsEnabled == TRUE) {
132 					PRINTK_2(TRACE_TP3780I,
133 						"tp3780i::DspInterrupt, waking up usPCNum %x\n",
134 						usPCNum - 1);
135 					wake_up_interruptible(&pDrvData->IPCs[usPCNum - 1].ipc_wait_queue);
136 				} else {
137 					PRINTK_2(TRACE_TP3780I,
138 						"tp3780i::DspInterrupt, no one waiting for IPC %x\n",
139 						usPCNum - 1);
140 				}
141 			}
142 			if (usIPCSource == 0)
143 				break;
144 			/* try next IPC */
145 			usIsolationMask = usIsolationMask << 1;
146 		}
147 	} else {
148 		PRINTK_1(TRACE_TP3780I,
149 			"tp3780i::DspInterrupt, return false from dsp3780i_GetIPCSource\n");
150 	}
151 	PRINTK_1(TRACE_TP3780I, "tp3780i::DspInterrupt exit\n");
152 }
153 
154 
tp3780I_InitializeBoardData(THINKPAD_BD_DATA * pBDData)155 int tp3780I_InitializeBoardData(THINKPAD_BD_DATA * pBDData)
156 {
157 	int retval = 0;
158 	DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings;
159 
160 
161 	PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_InitializeBoardData entry pBDData %p\n", pBDData);
162 
163 	pBDData->bDSPEnabled = FALSE;
164 	pSettings->bInterruptClaimed = FALSE;
165 
166 	retval = smapi_init();
167 	if (retval) {
168 		PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_InitializeBoardData: Error: SMAPI is not available on this machine\n");
169 	} else {
170 		if (mwave_3780i_irq || mwave_3780i_io || mwave_uart_irq || mwave_uart_io) {
171 			retval = smapi_set_DSP_cfg();
172 		}
173 	}
174 
175 	PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_InitializeBoardData exit retval %x\n", retval);
176 
177 	return retval;
178 }
179 
tp3780I_Cleanup(THINKPAD_BD_DATA * pBDData)180 int tp3780I_Cleanup(THINKPAD_BD_DATA * pBDData)
181 {
182 	int retval = 0;
183 
184 	PRINTK_2(TRACE_TP3780I,
185 		"tp3780i::tp3780I_Cleanup entry and exit pBDData %p\n", pBDData);
186 
187 	return retval;
188 }
189 
tp3780I_CalcResources(THINKPAD_BD_DATA * pBDData)190 int tp3780I_CalcResources(THINKPAD_BD_DATA * pBDData)
191 {
192 	SMAPI_DSP_SETTINGS rSmapiInfo;
193 	DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings;
194 
195 	PRINTK_2(TRACE_TP3780I,
196 		"tp3780i::tp3780I_CalcResources entry pBDData %p\n", pBDData);
197 
198 	if (smapi_query_DSP_cfg(&rSmapiInfo)) {
199 		PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_CalcResources: Error: Could not query DSP config. Aborting.\n");
200 		return -EIO;
201 	}
202 
203 	/* Sanity check */
204 	if (
205 		( rSmapiInfo.usDspIRQ == 0 )
206 		|| ( rSmapiInfo.usDspBaseIO ==  0 )
207 		|| ( rSmapiInfo.usUartIRQ ==  0 )
208 		|| ( rSmapiInfo.usUartBaseIO ==  0 )
209 	) {
210 		PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_CalcResources: Error: Illegal resource setting. Aborting.\n");
211 		return -EIO;
212 	}
213 
214 	pSettings->bDSPEnabled = (rSmapiInfo.bDSPEnabled && rSmapiInfo.bDSPPresent);
215 	pSettings->bModemEnabled = rSmapiInfo.bModemEnabled;
216 	pSettings->usDspIrq = rSmapiInfo.usDspIRQ;
217 	pSettings->usDspDma = rSmapiInfo.usDspDMA;
218 	pSettings->usDspBaseIO = rSmapiInfo.usDspBaseIO;
219 	pSettings->usUartIrq = rSmapiInfo.usUartIRQ;
220 	pSettings->usUartBaseIO = rSmapiInfo.usUartBaseIO;
221 
222 	pSettings->uDStoreSize = TP_ABILITIES_DATA_SIZE;
223 	pSettings->uIStoreSize = TP_ABILITIES_INST_SIZE;
224 	pSettings->uIps = TP_ABILITIES_INTS_PER_SEC;
225 
226 	if (pSettings->bDSPEnabled && pSettings->bModemEnabled && pSettings->usDspIrq == pSettings->usUartIrq) {
227 		pBDData->bShareDspIrq = pBDData->bShareUartIrq = 1;
228 	} else {
229 		pBDData->bShareDspIrq = pBDData->bShareUartIrq = 0;
230 	}
231 
232 	PRINTK_1(TRACE_TP3780I, "tp3780i::tp3780I_CalcResources exit\n");
233 
234 	return 0;
235 }
236 
237 
tp3780I_ClaimResources(THINKPAD_BD_DATA * pBDData)238 int tp3780I_ClaimResources(THINKPAD_BD_DATA * pBDData)
239 {
240 	int retval = 0;
241 	DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings;
242 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
243 	struct resource *pres;
244 #endif
245 
246 	PRINTK_2(TRACE_TP3780I,
247 		"tp3780i::tp3780I_ClaimResources entry pBDData %p\n", pBDData);
248 
249 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
250 	pres = request_region(pSettings->usDspBaseIO, 16, "mwave_3780i");
251 	if ( pres == NULL ) retval = -EIO;
252 #else
253 	retval = check_region(pSettings->usDspBaseIO, 16);
254 	if (!retval) request_region(pSettings->usDspBaseIO, 16, "mwave_3780i");
255 #endif
256 	if (retval) {
257 		PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_ClaimResources: Error: Could not claim I/O region starting at %x\n", pSettings->usDspBaseIO);
258 		retval = -EIO;
259 	}
260 
261 	PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_ClaimResources exit retval %x\n", retval);
262 
263 	return retval;
264 }
265 
tp3780I_ReleaseResources(THINKPAD_BD_DATA * pBDData)266 int tp3780I_ReleaseResources(THINKPAD_BD_DATA * pBDData)
267 {
268 	int retval = 0;
269 	DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings;
270 
271 	PRINTK_2(TRACE_TP3780I,
272 		"tp3780i::tp3780I_ReleaseResources entry pBDData %p\n", pBDData);
273 
274 	release_region(pSettings->usDspBaseIO & (~3), 16);
275 
276 	if (pSettings->bInterruptClaimed) {
277 		free_irq(pSettings->usDspIrq, 0);
278 		pSettings->bInterruptClaimed = FALSE;
279 	}
280 
281 	PRINTK_2(TRACE_TP3780I,
282 		"tp3780i::tp3780I_ReleaseResources exit retval %x\n", retval);
283 
284 	return retval;
285 }
286 
287 
288 
tp3780I_EnableDSP(THINKPAD_BD_DATA * pBDData)289 int tp3780I_EnableDSP(THINKPAD_BD_DATA * pBDData)
290 {
291 	DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings;
292 	BOOLEAN bDSPPoweredUp = FALSE, bDSPEnabled = FALSE, bInterruptAllocated = FALSE;
293 
294 	PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_EnableDSP entry pBDData %p\n", pBDData);
295 
296 	if (pBDData->bDSPEnabled) {
297 		PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: DSP already enabled!\n");
298 		goto exit_cleanup;
299 	}
300 
301 	if (!pSettings->bDSPEnabled) {
302 		PRINTK_ERROR(KERN_ERR_MWAVE "tp3780::tp3780I_EnableDSP: Error: pSettings->bDSPEnabled not set\n");
303 		goto exit_cleanup;
304 	}
305 
306 	if (
307 		(pSettings->usDspIrq >= s_numIrqs)
308 		|| (pSettings->usDspDma >= s_numDmas)
309 		|| (s_ausThinkpadIrqToField[pSettings->usDspIrq] == 0xFFFF)
310 		|| (s_ausThinkpadDmaToField[pSettings->usDspDma] == 0xFFFF)
311 	) {
312 		PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: invalid irq %x\n", pSettings->usDspIrq);
313 		goto exit_cleanup;
314 	}
315 
316 	if (
317 		((pSettings->usDspBaseIO & 0xF00F) != 0)
318 		|| (pSettings->usDspBaseIO & 0x0FF0) == 0
319 	) {
320 		PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: Invalid DSP base I/O address %x\n", pSettings->usDspBaseIO);
321 		goto exit_cleanup;
322 	}
323 
324 	if (pSettings->bModemEnabled) {
325 		if (
326 			pSettings->usUartIrq >= s_numIrqs
327 			|| s_ausThinkpadIrqToField[pSettings->usUartIrq] == 0xFFFF
328 		) {
329 			PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: Invalid UART IRQ %x\n", pSettings->usUartIrq);
330 			goto exit_cleanup;
331 		}
332 		switch (pSettings->usUartBaseIO) {
333 			case 0x03F8:
334 			case 0x02F8:
335 			case 0x03E8:
336 			case 0x02E8:
337 				break;
338 
339 			default:
340 				PRINTK_ERROR("tp3780i::tp3780I_EnableDSP: Error: Invalid UART base I/O address %x\n", pSettings->usUartBaseIO);
341 				goto exit_cleanup;
342 		}
343 	}
344 
345 	pSettings->bDspIrqActiveLow = pSettings->bDspIrqPulse = TRUE;
346 	pSettings->bUartIrqActiveLow = pSettings->bUartIrqPulse = TRUE;
347 
348 	if (pBDData->bShareDspIrq) {
349 		pSettings->bDspIrqActiveLow = FALSE;
350 	}
351 	if (pBDData->bShareUartIrq) {
352 		pSettings->bUartIrqActiveLow = FALSE;
353 	}
354 
355 	pSettings->usNumTransfers = TP_CFG_NumTransfers;
356 	pSettings->usReRequest = TP_CFG_RerequestTimer;
357 	pSettings->bEnableMEMCS16 = TP_CFG_MEMCS16;
358 	pSettings->usIsaMemCmdWidth = TP_CFG_IsaMemCmdWidth;
359 	pSettings->bGateIOCHRDY = TP_CFG_GateIOCHRDY;
360 	pSettings->bEnablePwrMgmt = TP_CFG_EnablePwrMgmt;
361 	pSettings->usHBusTimerLoadValue = TP_CFG_HBusTimerValue;
362 	pSettings->bDisableLBusTimeout = TP_CFG_DisableLBusTimeout;
363 	pSettings->usN_Divisor = TP_CFG_N_Divisor;
364 	pSettings->usM_Multiplier = TP_CFG_M_Multiplier;
365 	pSettings->bPllBypass = TP_CFG_PllBypass;
366 	pSettings->usChipletEnable = TP_CFG_ChipletEnable;
367 
368 	if (request_irq(pSettings->usUartIrq, &UartInterrupt, 0, "mwave_uart", 0)) {
369 		PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: Could not get UART IRQ %x\n", pSettings->usUartIrq);
370 		goto exit_cleanup;
371 	} else {		/* no conflict just release */
372 		free_irq(pSettings->usUartIrq, 0);
373 	}
374 
375 	if (request_irq(pSettings->usDspIrq, &DspInterrupt, 0, "mwave_3780i", 0)) {
376 		PRINTK_ERROR("tp3780i::tp3780I_EnableDSP: Error: Could not get 3780i IRQ %x\n", pSettings->usDspIrq);
377 		goto exit_cleanup;
378 	} else {
379 		PRINTK_3(TRACE_TP3780I,
380 			"tp3780i::tp3780I_EnableDSP, got interrupt %x bShareDspIrq %x\n",
381 			pSettings->usDspIrq, pBDData->bShareDspIrq);
382 		bInterruptAllocated = TRUE;
383 		pSettings->bInterruptClaimed = TRUE;
384 	}
385 
386 	smapi_set_DSP_power_state(FALSE);
387 	if (smapi_set_DSP_power_state(TRUE)) {
388 		PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: smapi_set_DSP_power_state(TRUE) failed\n");
389 		goto exit_cleanup;
390 	} else {
391 		bDSPPoweredUp = TRUE;
392 	}
393 
394 	if (dsp3780I_EnableDSP(pSettings, s_ausThinkpadIrqToField, s_ausThinkpadDmaToField)) {
395 		PRINTK_ERROR("tp3780i::tp3780I_EnableDSP: Error: dsp7880I_EnableDSP() failed\n");
396 		goto exit_cleanup;
397 	} else {
398 		bDSPEnabled = TRUE;
399 	}
400 
401 	EnableSRAM(pBDData);
402 
403 	pBDData->bDSPEnabled = TRUE;
404 
405 	PRINTK_1(TRACE_TP3780I, "tp3780i::tp3780I_EnableDSP exit\n");
406 
407 	return 0;
408 
409 exit_cleanup:
410 	PRINTK_ERROR("tp3780i::tp3780I_EnableDSP: Cleaning up\n");
411 	if (bDSPEnabled)
412 		dsp3780I_DisableDSP(pSettings);
413 	if (bDSPPoweredUp)
414 		smapi_set_DSP_power_state(FALSE);
415 	if (bInterruptAllocated) {
416 		free_irq(pSettings->usDspIrq, 0);
417 		pSettings->bInterruptClaimed = FALSE;
418 	}
419 	return -EIO;
420 }
421 
422 
tp3780I_DisableDSP(THINKPAD_BD_DATA * pBDData)423 int tp3780I_DisableDSP(THINKPAD_BD_DATA * pBDData)
424 {
425 	int retval = 0;
426 	DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings;
427 
428 	PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_DisableDSP entry pBDData %p\n", pBDData);
429 
430 	if (pBDData->bDSPEnabled) {
431 		dsp3780I_DisableDSP(&pBDData->rDspSettings);
432 		if (pSettings->bInterruptClaimed) {
433 			free_irq(pSettings->usDspIrq, 0);
434 			pSettings->bInterruptClaimed = FALSE;
435 		}
436 		smapi_set_DSP_power_state(FALSE);
437 		pBDData->bDSPEnabled = FALSE;
438 	}
439 
440 	PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_DisableDSP exit retval %x\n", retval);
441 
442 	return retval;
443 }
444 
445 
tp3780I_ResetDSP(THINKPAD_BD_DATA * pBDData)446 int tp3780I_ResetDSP(THINKPAD_BD_DATA * pBDData)
447 {
448 	int retval = 0;
449 	DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings;
450 
451 	PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_ResetDSP entry pBDData %p\n",
452 		pBDData);
453 
454 	if (dsp3780I_Reset(pSettings) == 0) {
455 		EnableSRAM(pBDData);
456 	} else {
457 		retval = -EIO;
458 	}
459 
460 	PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_ResetDSP exit retval %x\n", retval);
461 
462 	return retval;
463 }
464 
465 
tp3780I_StartDSP(THINKPAD_BD_DATA * pBDData)466 int tp3780I_StartDSP(THINKPAD_BD_DATA * pBDData)
467 {
468 	int retval = 0;
469 	DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings;
470 
471 	PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_StartDSP entry pBDData %p\n", pBDData);
472 
473 	if (dsp3780I_Run(pSettings) == 0) {
474 		// @BUG @TBD EnableSRAM(pBDData);
475 	} else {
476 		retval = -EIO;
477 	}
478 
479 	PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_StartDSP exit retval %x\n", retval);
480 
481 	return retval;
482 }
483 
484 
tp3780I_QueryAbilities(THINKPAD_BD_DATA * pBDData,MW_ABILITIES * pAbilities)485 int tp3780I_QueryAbilities(THINKPAD_BD_DATA * pBDData, MW_ABILITIES * pAbilities)
486 {
487 	int retval = 0;
488 
489 	PRINTK_2(TRACE_TP3780I,
490 		"tp3780i::tp3780I_QueryAbilities entry pBDData %p\n", pBDData);
491 
492 	/* fill out standard constant fields */
493 	pAbilities->instr_per_sec = pBDData->rDspSettings.uIps;
494 	pAbilities->data_size = pBDData->rDspSettings.uDStoreSize;
495 	pAbilities->inst_size = pBDData->rDspSettings.uIStoreSize;
496 	pAbilities->bus_dma_bw = pBDData->rDspSettings.uDmaBandwidth;
497 
498 	/* fill out dynamically determined fields */
499 	pAbilities->component_list[0] = 0x00010000 | MW_ADC_MASK;
500 	pAbilities->component_list[1] = 0x00010000 | MW_ACI_MASK;
501 	pAbilities->component_list[2] = 0x00010000 | MW_AIC1_MASK;
502 	pAbilities->component_list[3] = 0x00010000 | MW_AIC2_MASK;
503 	pAbilities->component_list[4] = 0x00010000 | MW_CDDAC_MASK;
504 	pAbilities->component_list[5] = 0x00010000 | MW_MIDI_MASK;
505 	pAbilities->component_list[6] = 0x00010000 | MW_UART_MASK;
506 	pAbilities->component_count = 7;
507 
508 	/* Fill out Mwave OS and BIOS task names */
509 
510 	memcpy(pAbilities->mwave_os_name, TP_ABILITIES_MWAVEOS_NAME,
511 		sizeof(TP_ABILITIES_MWAVEOS_NAME));
512 	memcpy(pAbilities->bios_task_name, TP_ABILITIES_BIOSTASK_NAME,
513 		sizeof(TP_ABILITIES_BIOSTASK_NAME));
514 
515 	PRINTK_1(TRACE_TP3780I,
516 		"tp3780i::tp3780I_QueryAbilities exit retval=SUCCESSFUL\n");
517 
518 	return retval;
519 }
520 
tp3780I_ReadWriteDspDStore(THINKPAD_BD_DATA * pBDData,unsigned int uOpcode,void * pvBuffer,unsigned int uCount,unsigned long ulDSPAddr)521 int tp3780I_ReadWriteDspDStore(THINKPAD_BD_DATA * pBDData, unsigned int uOpcode,
522                                void *pvBuffer, unsigned int uCount,
523                                unsigned long ulDSPAddr)
524 {
525 	int retval = 0;
526 	DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings;
527 	unsigned short usDspBaseIO = pSettings->usDspBaseIO;
528 	BOOLEAN bRC = 0;
529 
530 	PRINTK_6(TRACE_TP3780I,
531 		"tp3780i::tp3780I_ReadWriteDspDStore entry pBDData %p, uOpcode %x, pvBuffer %p, uCount %x, ulDSPAddr %lx\n",
532 		pBDData, uOpcode, pvBuffer, uCount, ulDSPAddr);
533 
534 	if (pBDData->bDSPEnabled) {
535 		switch (uOpcode) {
536 		case IOCTL_MW_READ_DATA:
537 			bRC = dsp3780I_ReadDStore(usDspBaseIO, pvBuffer, uCount, ulDSPAddr);
538 			break;
539 
540 		case IOCTL_MW_READCLEAR_DATA:
541 			bRC = dsp3780I_ReadAndClearDStore(usDspBaseIO, pvBuffer, uCount, ulDSPAddr);
542 			break;
543 
544 		case IOCTL_MW_WRITE_DATA:
545 			bRC = dsp3780I_WriteDStore(usDspBaseIO, pvBuffer, uCount, ulDSPAddr);
546 			break;
547 		}
548 	}
549 
550 	retval = (bRC) ? -EIO : 0;
551 	PRINTK_2(TRACE_TP3780I, "tp3780i::tp3780I_ReadWriteDspDStore exit retval %x\n", retval);
552 
553 	return retval;
554 }
555 
556 
tp3780I_ReadWriteDspIStore(THINKPAD_BD_DATA * pBDData,unsigned int uOpcode,void * pvBuffer,unsigned int uCount,unsigned long ulDSPAddr)557 int tp3780I_ReadWriteDspIStore(THINKPAD_BD_DATA * pBDData, unsigned int uOpcode,
558                                void *pvBuffer, unsigned int uCount,
559                                unsigned long ulDSPAddr)
560 {
561 	int retval = 0;
562 	DSP_3780I_CONFIG_SETTINGS *pSettings = &pBDData->rDspSettings;
563 	unsigned short usDspBaseIO = pSettings->usDspBaseIO;
564 	BOOLEAN bRC = 0;
565 
566 	PRINTK_6(TRACE_TP3780I,
567 		"tp3780i::tp3780I_ReadWriteDspIStore entry pBDData %p, uOpcode %x, pvBuffer %p, uCount %x, ulDSPAddr %lx\n",
568 		pBDData, uOpcode, pvBuffer, uCount, ulDSPAddr);
569 
570 	if (pBDData->bDSPEnabled) {
571 		switch (uOpcode) {
572 		case IOCTL_MW_READ_INST:
573 			bRC = dsp3780I_ReadIStore(usDspBaseIO, pvBuffer, uCount, ulDSPAddr);
574 			break;
575 
576 		case IOCTL_MW_WRITE_INST:
577 			bRC = dsp3780I_WriteIStore(usDspBaseIO, pvBuffer, uCount, ulDSPAddr);
578 			break;
579 		}
580 	}
581 
582 	retval = (bRC) ? -EIO : 0;
583 
584 	PRINTK_2(TRACE_TP3780I,
585 		"tp3780i::tp3780I_ReadWriteDspIStore exit retval %x\n", retval);
586 
587 	return retval;
588 }
589 
590