1 /*
2 *
3 * smapi.c -- SMAPI interface routines
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/mc146818rtc.h> /* CMOS defines */
52 #include "smapi.h"
53 #include "mwavedd.h"
54
55 static unsigned short g_usSmapiPort = 0;
56
57
smapi_request(unsigned short inBX,unsigned short inCX,unsigned short inDI,unsigned short inSI,unsigned short * outAX,unsigned short * outBX,unsigned short * outCX,unsigned short * outDX,unsigned short * outDI,unsigned short * outSI)58 int smapi_request(unsigned short inBX, unsigned short inCX,
59 unsigned short inDI, unsigned short inSI,
60 unsigned short *outAX, unsigned short *outBX,
61 unsigned short *outCX, unsigned short *outDX,
62 unsigned short *outDI, unsigned short *outSI)
63 {
64 unsigned short myoutAX = 2, *pmyoutAX = &myoutAX;
65 unsigned short myoutBX = 3, *pmyoutBX = &myoutBX;
66 unsigned short myoutCX = 4, *pmyoutCX = &myoutCX;
67 unsigned short myoutDX = 5, *pmyoutDX = &myoutDX;
68 unsigned short myoutDI = 6, *pmyoutDI = &myoutDI;
69 unsigned short myoutSI = 7, *pmyoutSI = &myoutSI;
70 unsigned short usSmapiOK = -EIO, *pusSmapiOK = &usSmapiOK;
71 unsigned int inBXCX = (inBX << 16) | inCX;
72 unsigned int inDISI = (inDI << 16) | inSI;
73 int retval = 0;
74
75 PRINTK_5(TRACE_SMAPI, "inBX %x inCX %x inDI %x inSI %x\n",
76 inBX, inCX, inDI, inSI);
77
78 __asm__ __volatile__("movw $0x5380,%%ax\n\t"
79 "movl %7,%%ebx\n\t"
80 "shrl $16, %%ebx\n\t"
81 "movw %7,%%cx\n\t"
82 "movl %8,%%edi\n\t"
83 "shrl $16,%%edi\n\t"
84 "movw %8,%%si\n\t"
85 "movw %9,%%dx\n\t"
86 "out %%al,%%dx\n\t"
87 "out %%al,$0x4F\n\t"
88 "cmpb $0x53,%%ah\n\t"
89 "je 2f\n\t"
90 "1:\n\t"
91 "orb %%ah,%%ah\n\t"
92 "jnz 2f\n\t"
93 "movw %%ax,%0\n\t"
94 "movw %%bx,%1\n\t"
95 "movw %%cx,%2\n\t"
96 "movw %%dx,%3\n\t"
97 "movw %%di,%4\n\t"
98 "movw %%si,%5\n\t"
99 "movw $1,%6\n\t"
100 "2:\n\t":"=m"(*(unsigned short *) pmyoutAX),
101 "=m"(*(unsigned short *) pmyoutBX),
102 "=m"(*(unsigned short *) pmyoutCX),
103 "=m"(*(unsigned short *) pmyoutDX),
104 "=m"(*(unsigned short *) pmyoutDI),
105 "=m"(*(unsigned short *) pmyoutSI),
106 "=m"(*(unsigned short *) pusSmapiOK)
107 :"m"(inBXCX), "m"(inDISI), "m"(g_usSmapiPort)
108 :"%eax", "%ebx", "%ecx", "%edx", "%edi",
109 "%esi");
110
111 PRINTK_8(TRACE_SMAPI,
112 "myoutAX %x myoutBX %x myoutCX %x myoutDX %x myoutDI %x myoutSI %x usSmapiOK %x\n",
113 myoutAX, myoutBX, myoutCX, myoutDX, myoutDI, myoutSI,
114 usSmapiOK);
115 *outAX = myoutAX;
116 *outBX = myoutBX;
117 *outCX = myoutCX;
118 *outDX = myoutDX;
119 *outDI = myoutDI;
120 *outSI = myoutSI;
121
122 retval = (usSmapiOK == 1) ? 0 : -EIO;
123 PRINTK_2(TRACE_SMAPI, "smapi::smapi_request exit retval %x\n", retval);
124 return retval;
125 }
126
127
smapi_query_DSP_cfg(SMAPI_DSP_SETTINGS * pSettings)128 int smapi_query_DSP_cfg(SMAPI_DSP_SETTINGS * pSettings)
129 {
130 int bRC = -EIO;
131 unsigned short usAX, usBX, usCX, usDX, usDI, usSI;
132 unsigned short ausDspBases[] = { 0x0030, 0x4E30, 0x8E30, 0xCE30, 0x0130, 0x0350, 0x0070, 0x0DB0 };
133 unsigned short ausUartBases[] = { 0x03F8, 0x02F8, 0x03E8, 0x02E8 };
134 unsigned short numDspBases = 8;
135 unsigned short numUartBases = 4;
136
137 PRINTK_1(TRACE_SMAPI, "smapi::smapi_query_DSP_cfg entry\n");
138
139 bRC = smapi_request(0x1802, 0x0000, 0, 0,
140 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
141 if (bRC) {
142 PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_query_DSP_cfg: Error: Could not get DSP Settings. Aborting.\n");
143 return bRC;
144 }
145
146 PRINTK_1(TRACE_SMAPI, "smapi::smapi_query_DSP_cfg, smapi_request OK\n");
147
148 pSettings->bDSPPresent = ((usBX & 0x0100) != 0);
149 pSettings->bDSPEnabled = ((usCX & 0x0001) != 0);
150 pSettings->usDspIRQ = usSI & 0x00FF;
151 pSettings->usDspDMA = (usSI & 0xFF00) >> 8;
152 if ((usDI & 0x00FF) < numDspBases) {
153 pSettings->usDspBaseIO = ausDspBases[usDI & 0x00FF];
154 } else {
155 pSettings->usDspBaseIO = 0;
156 }
157 PRINTK_6(TRACE_SMAPI,
158 "smapi::smapi_query_DSP_cfg get DSP Settings bDSPPresent %x bDSPEnabled %x usDspIRQ %x usDspDMA %x usDspBaseIO %x\n",
159 pSettings->bDSPPresent, pSettings->bDSPEnabled,
160 pSettings->usDspIRQ, pSettings->usDspDMA,
161 pSettings->usDspBaseIO);
162
163 /* check for illegal values */
164 if ( pSettings->usDspBaseIO == 0 )
165 PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_query_DSP_cfg: Worry: DSP base I/O address is 0\n");
166 if ( pSettings->usDspIRQ == 0 )
167 PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_query_DSP_cfg: Worry: DSP IRQ line is 0\n");
168
169 bRC = smapi_request(0x1804, 0x0000, 0, 0,
170 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
171 if (bRC) {
172 PRINTK_ERROR("smapi::smapi_query_DSP_cfg: Error: Could not get DSP modem settings. Aborting.\n");
173 return bRC;
174 }
175
176 PRINTK_1(TRACE_SMAPI, "smapi::smapi_query_DSP_cfg, smapi_request OK\n");
177
178 pSettings->bModemEnabled = ((usCX & 0x0001) != 0);
179 pSettings->usUartIRQ = usSI & 0x000F;
180 if (((usSI & 0xFF00) >> 8) < numUartBases) {
181 pSettings->usUartBaseIO = ausUartBases[(usSI & 0xFF00) >> 8];
182 } else {
183 pSettings->usUartBaseIO = 0;
184 }
185
186 PRINTK_4(TRACE_SMAPI,
187 "smapi::smapi_query_DSP_cfg get DSP modem settings bModemEnabled %x usUartIRQ %x usUartBaseIO %x\n",
188 pSettings->bModemEnabled,
189 pSettings->usUartIRQ,
190 pSettings->usUartBaseIO);
191
192 /* check for illegal values */
193 if ( pSettings->usUartBaseIO == 0 )
194 PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_query_DSP_cfg: Worry: UART base I/O address is 0\n");
195 if ( pSettings->usUartIRQ == 0 )
196 PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_query_DSP_cfg: Worry: UART IRQ line is 0\n");
197
198 PRINTK_2(TRACE_SMAPI, "smapi::smapi_query_DSP_cfg exit bRC %x\n", bRC);
199
200 return bRC;
201 }
202
203
smapi_set_DSP_cfg(void)204 int smapi_set_DSP_cfg(void)
205 {
206 int bRC = -EIO;
207 int i;
208 unsigned short usAX, usBX, usCX, usDX, usDI, usSI;
209 unsigned short ausDspBases[] = { 0x0030, 0x4E30, 0x8E30, 0xCE30, 0x0130, 0x0350, 0x0070, 0x0DB0 };
210 unsigned short ausUartBases[] = { 0x03F8, 0x02F8, 0x03E8, 0x02E8 };
211 unsigned short ausDspIrqs[] = { 5, 7, 10, 11, 15 };
212 unsigned short ausUartIrqs[] = { 3, 4 };
213
214 unsigned short numDspBases = 8;
215 unsigned short numUartBases = 4;
216 unsigned short numDspIrqs = 5;
217 unsigned short numUartIrqs = 2;
218 unsigned short dspio_index = 0, uartio_index = 0;
219
220 PRINTK_5(TRACE_SMAPI,
221 "smapi::smapi_set_DSP_cfg entry mwave_3780i_irq %x mwave_3780i_io %x mwave_uart_irq %x mwave_uart_io %x\n",
222 mwave_3780i_irq, mwave_3780i_io, mwave_uart_irq, mwave_uart_io);
223
224 if (mwave_3780i_io) {
225 for (i = 0; i < numDspBases; i++) {
226 if (mwave_3780i_io == ausDspBases[i])
227 break;
228 }
229 if (i == numDspBases) {
230 PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_set_DSP_cfg: Error: Invalid mwave_3780i_io address %x. Aborting.\n", mwave_3780i_io);
231 return bRC;
232 }
233 dspio_index = i;
234 }
235
236 if (mwave_3780i_irq) {
237 for (i = 0; i < numDspIrqs; i++) {
238 if (mwave_3780i_irq == ausDspIrqs[i])
239 break;
240 }
241 if (i == numDspIrqs) {
242 PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_set_DSP_cfg: Error: Invalid mwave_3780i_irq %x. Aborting.\n", mwave_3780i_irq);
243 return bRC;
244 }
245 }
246
247 if (mwave_uart_io) {
248 for (i = 0; i < numUartBases; i++) {
249 if (mwave_uart_io == ausUartBases[i])
250 break;
251 }
252 if (i == numUartBases) {
253 PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_set_DSP_cfg: Error: Invalid mwave_uart_io address %x. Aborting.\n", mwave_uart_io);
254 return bRC;
255 }
256 uartio_index = i;
257 }
258
259
260 if (mwave_uart_irq) {
261 for (i = 0; i < numUartIrqs; i++) {
262 if (mwave_uart_irq == ausUartIrqs[i])
263 break;
264 }
265 if (i == numUartIrqs) {
266 PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_set_DSP_cfg: Error: Invalid mwave_uart_irq %x. Aborting.\n", mwave_uart_irq);
267 return bRC;
268 }
269 }
270
271 if (mwave_uart_irq || mwave_uart_io) {
272
273 /* Check serial port A */
274 bRC = smapi_request(0x1402, 0x0000, 0, 0,
275 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
276 if (bRC) goto exit_smapi_request_error;
277 /* bRC == 0 */
278 if (usBX & 0x0100) { /* serial port A is present */
279 if (usCX & 1) { /* serial port is enabled */
280 if ((usSI & 0xFF) == mwave_uart_irq) {
281 #ifndef MWAVE_FUTZ_WITH_OTHER_DEVICES
282 PRINTK_ERROR(KERN_ERR_MWAVE
283 "smapi::smapi_set_DSP_cfg: Serial port A irq %x conflicts with mwave_uart_irq %x\n", usSI & 0xFF, mwave_uart_irq);
284 #else
285 PRINTK_3(TRACE_SMAPI,
286 "smapi::smapi_set_DSP_cfg: Serial port A irq %x conflicts with mwave_uart_irq %x\n", usSI & 0xFF, mwave_uart_irq);
287 #endif
288 #ifdef MWAVE_FUTZ_WITH_OTHER_DEVICES
289 PRINTK_1(TRACE_SMAPI,
290 "smapi::smapi_set_DSP_cfg Disabling conflicting serial port\n");
291 bRC = smapi_request(0x1403, 0x0100, 0, usSI,
292 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
293 if (bRC) goto exit_smapi_request_error;
294 bRC = smapi_request(0x1402, 0x0000, 0, 0,
295 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
296 if (bRC) goto exit_smapi_request_error;
297 #else
298 goto exit_conflict;
299 #endif
300 } else {
301 if ((usSI >> 8) == uartio_index) {
302 #ifndef MWAVE_FUTZ_WITH_OTHER_DEVICES
303 PRINTK_ERROR(KERN_ERR_MWAVE
304 "smapi::smapi_set_DSP_cfg: Serial port A base I/O address %x conflicts with mwave uart I/O %x\n", ausUartBases[usSI >> 8], ausUartBases[uartio_index]);
305 #else
306 PRINTK_3(TRACE_SMAPI,
307 "smapi::smapi_set_DSP_cfg: Serial port A base I/O address %x conflicts with mwave uart I/O %x\n", ausUartBases[usSI >> 8], ausUartBases[uartio_index]);
308 #endif
309 #ifdef MWAVE_FUTZ_WITH_OTHER_DEVICES
310 PRINTK_1(TRACE_SMAPI,
311 "smapi::smapi_set_DSP_cfg Disabling conflicting serial port A\n");
312 bRC = smapi_request (0x1403, 0x0100, 0, usSI,
313 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
314 if (bRC) goto exit_smapi_request_error;
315 bRC = smapi_request (0x1402, 0x0000, 0, 0,
316 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
317 if (bRC) goto exit_smapi_request_error;
318 #else
319 goto exit_conflict;
320 #endif
321 }
322 }
323 }
324 }
325
326 /* Check serial port B */
327 bRC = smapi_request(0x1404, 0x0000, 0, 0,
328 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
329 if (bRC) goto exit_smapi_request_error;
330 /* bRC == 0 */
331 if (usBX & 0x0100) { /* serial port B is present */
332 if (usCX & 1) { /* serial port is enabled */
333 if ((usSI & 0xFF) == mwave_uart_irq) {
334 #ifndef MWAVE_FUTZ_WITH_OTHER_DEVICES
335 PRINTK_ERROR(KERN_ERR_MWAVE
336 "smapi::smapi_set_DSP_cfg: Serial port B irq %x conflicts with mwave_uart_irq %x\n", usSI & 0xFF, mwave_uart_irq);
337 #else
338 PRINTK_3(TRACE_SMAPI,
339 "smapi::smapi_set_DSP_cfg: Serial port B irq %x conflicts with mwave_uart_irq %x\n", usSI & 0xFF, mwave_uart_irq);
340 #endif
341 #ifdef MWAVE_FUTZ_WITH_OTHER_DEVICES
342 PRINTK_1(TRACE_SMAPI,
343 "smapi::smapi_set_DSP_cfg Disabling conflicting serial port B\n");
344 bRC = smapi_request(0x1405, 0x0100, 0, usSI,
345 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
346 if (bRC) goto exit_smapi_request_error;
347 bRC = smapi_request(0x1404, 0x0000, 0, 0,
348 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
349 if (bRC) goto exit_smapi_request_error;
350 #else
351 goto exit_conflict;
352 #endif
353 } else {
354 if ((usSI >> 8) == uartio_index) {
355 #ifndef MWAVE_FUTZ_WITH_OTHER_DEVICES
356 PRINTK_ERROR(KERN_ERR_MWAVE
357 "smapi::smapi_set_DSP_cfg: Serial port B base I/O address %x conflicts with mwave uart I/O %x\n", ausUartBases[usSI >> 8], ausUartBases[uartio_index]);
358 #else
359 PRINTK_3(TRACE_SMAPI,
360 "smapi::smapi_set_DSP_cfg: Serial port B base I/O address %x conflicts with mwave uart I/O %x\n", ausUartBases[usSI >> 8], ausUartBases[uartio_index]);
361 #endif
362 #ifdef MWAVE_FUTZ_WITH_OTHER_DEVICES
363 PRINTK_1 (TRACE_SMAPI,
364 "smapi::smapi_set_DSP_cfg Disabling conflicting serial port B\n");
365 bRC = smapi_request (0x1405, 0x0100, 0, usSI,
366 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
367 if (bRC) goto exit_smapi_request_error;
368 bRC = smapi_request (0x1404, 0x0000, 0, 0,
369 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
370 if (bRC) goto exit_smapi_request_error;
371 #else
372 goto exit_conflict;
373 #endif
374 }
375 }
376 }
377 }
378
379 /* Check IR port */
380 bRC = smapi_request(0x1700, 0x0000, 0, 0,
381 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
382 if (bRC) goto exit_smapi_request_error;
383 bRC = smapi_request(0x1704, 0x0000, 0, 0,
384 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
385 if (bRC) goto exit_smapi_request_error;
386 /* bRC == 0 */
387 if ((usCX & 0xff) != 0xff) { /* IR port not disabled */
388 if ((usCX & 0xff) == mwave_uart_irq) {
389 #ifndef MWAVE_FUTZ_WITH_OTHER_DEVICES
390 PRINTK_ERROR(KERN_ERR_MWAVE
391 "smapi::smapi_set_DSP_cfg: IR port irq %x conflicts with mwave_uart_irq %x\n", usCX & 0xff, mwave_uart_irq);
392 #else
393 PRINTK_3(TRACE_SMAPI,
394 "smapi::smapi_set_DSP_cfg: IR port irq %x conflicts with mwave_uart_irq %x\n", usCX & 0xff, mwave_uart_irq);
395 #endif
396 #ifdef MWAVE_FUTZ_WITH_OTHER_DEVICES
397 PRINTK_1(TRACE_SMAPI,
398 "smapi::smapi_set_DSP_cfg Disabling conflicting IR port\n");
399 bRC = smapi_request(0x1701, 0x0100, 0, 0,
400 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
401 if (bRC) goto exit_smapi_request_error;
402 bRC = smapi_request(0x1700, 0, 0, 0,
403 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
404 if (bRC) goto exit_smapi_request_error;
405 bRC = smapi_request(0x1705, 0x01ff, 0, usSI,
406 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
407 if (bRC) goto exit_smapi_request_error;
408 bRC = smapi_request(0x1704, 0x0000, 0, 0,
409 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
410 if (bRC) goto exit_smapi_request_error;
411 #else
412 goto exit_conflict;
413 #endif
414 } else {
415 if ((usSI & 0xff) == uartio_index) {
416 #ifndef MWAVE_FUTZ_WITH_OTHER_DEVICES
417 PRINTK_ERROR(KERN_ERR_MWAVE
418 "smapi::smapi_set_DSP_cfg: IR port base I/O address %x conflicts with mwave uart I/O %x\n", ausUartBases[usSI & 0xff], ausUartBases[uartio_index]);
419 #else
420 PRINTK_3(TRACE_SMAPI,
421 "smapi::smapi_set_DSP_cfg: IR port base I/O address %x conflicts with mwave uart I/O %x\n", ausUartBases[usSI & 0xff], ausUartBases[uartio_index]);
422 #endif
423 #ifdef MWAVE_FUTZ_WITH_OTHER_DEVICES
424 PRINTK_1(TRACE_SMAPI,
425 "smapi::smapi_set_DSP_cfg Disabling conflicting IR port\n");
426 bRC = smapi_request(0x1701, 0x0100, 0, 0,
427 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
428 if (bRC) goto exit_smapi_request_error;
429 bRC = smapi_request(0x1700, 0, 0, 0,
430 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
431 if (bRC) goto exit_smapi_request_error;
432 bRC = smapi_request(0x1705, 0x01ff, 0, usSI,
433 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
434 if (bRC) goto exit_smapi_request_error;
435 bRC = smapi_request(0x1704, 0x0000, 0, 0,
436 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
437 if (bRC) goto exit_smapi_request_error;
438 #else
439 goto exit_conflict;
440 #endif
441 }
442 }
443 }
444 }
445
446 bRC = smapi_request(0x1802, 0x0000, 0, 0,
447 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
448 if (bRC) goto exit_smapi_request_error;
449
450 if (mwave_3780i_io) {
451 usDI = dspio_index;;
452 }
453 if (mwave_3780i_irq) {
454 usSI = (usSI & 0xff00) | mwave_3780i_irq;
455 }
456
457 bRC = smapi_request(0x1803, 0x0101, usDI, usSI,
458 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
459 if (bRC) goto exit_smapi_request_error;
460
461 bRC = smapi_request(0x1804, 0x0000, 0, 0,
462 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
463 if (bRC) goto exit_smapi_request_error;
464
465 if (mwave_uart_io) {
466 usSI = (usSI & 0x00ff) | (uartio_index << 8);
467 }
468 if (mwave_uart_irq) {
469 usSI = (usSI & 0xff00) | mwave_uart_irq;
470 }
471 bRC = smapi_request(0x1805, 0x0101, 0, usSI,
472 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
473 if (bRC) goto exit_smapi_request_error;
474
475 bRC = smapi_request(0x1802, 0x0000, 0, 0,
476 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
477 if (bRC) goto exit_smapi_request_error;
478
479 bRC = smapi_request(0x1804, 0x0000, 0, 0,
480 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
481 if (bRC) goto exit_smapi_request_error;
482
483 /* normal exit: */
484 PRINTK_1(TRACE_SMAPI, "smapi::smapi_set_DSP_cfg exit\n");
485 return 0;
486
487 exit_conflict:
488 /* Message has already been printed */
489 return -EIO;
490
491 exit_smapi_request_error:
492 PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_set_DSP_cfg exit on smapi_request error bRC %x\n", bRC);
493 return bRC;
494 }
495
496
smapi_set_DSP_power_state(BOOLEAN bOn)497 int smapi_set_DSP_power_state(BOOLEAN bOn)
498 {
499 int bRC = -EIO;
500 unsigned short usAX, usBX, usCX, usDX, usDI, usSI;
501 unsigned short usPowerFunction;
502
503 PRINTK_2(TRACE_SMAPI, "smapi::smapi_set_DSP_power_state entry bOn %x\n", bOn);
504
505 usPowerFunction = (bOn) ? 1 : 0;
506
507 bRC = smapi_request(0x4901, 0x0000, 0, usPowerFunction,
508 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
509
510 PRINTK_2(TRACE_SMAPI, "smapi::smapi_set_DSP_power_state exit bRC %x\n", bRC);
511
512 return bRC;
513 }
514
515
SmapiQuerySystemID(void)516 int SmapiQuerySystemID(void)
517 {
518 int bRC = -EIO;
519 unsigned short usAX = 0xffff, usBX = 0xffff, usCX = 0xffff,
520 usDX = 0xffff, usDI = 0xffff, usSI = 0xffff;
521
522 printk("smapi::SmapiQUerySystemID entry\n");
523 bRC = smapi_request(0x0000, 0, 0, 0,
524 &usAX, &usBX, &usCX, &usDX, &usDI, &usSI);
525
526 if (bRC == 0) {
527 printk("AX=%x, BX=%x, CX=%x, DX=%x, DI=%x, SI=%x\n",
528 usAX, usBX, usCX, usDX, usDI, usSI);
529 } else {
530 printk("smapi::SmapiQuerySystemID smapi_request error\n");
531 }
532
533 return bRC;
534 }
535
536
smapi_init(void)537 int smapi_init(void)
538 {
539 int retval = -EIO;
540 unsigned short usSmapiID = 0;
541 unsigned long flags;
542
543 PRINTK_1(TRACE_SMAPI, "smapi::smapi_init entry\n");
544
545 spin_lock_irqsave(&rtc_lock, flags);
546 usSmapiID = CMOS_READ(0x7C);
547 usSmapiID |= (CMOS_READ(0x7D) << 8);
548 spin_unlock_irqrestore(&rtc_lock, flags);
549 PRINTK_2(TRACE_SMAPI, "smapi::smapi_init usSmapiID %x\n", usSmapiID);
550
551 if (usSmapiID == 0x5349) {
552 spin_lock_irqsave(&rtc_lock, flags);
553 g_usSmapiPort = CMOS_READ(0x7E);
554 g_usSmapiPort |= (CMOS_READ(0x7F) << 8);
555 spin_unlock_irqrestore(&rtc_lock, flags);
556 if (g_usSmapiPort == 0) {
557 PRINTK_ERROR("smapi::smapi_init, ERROR unable to read from SMAPI port\n");
558 } else {
559 PRINTK_2(TRACE_SMAPI,
560 "smapi::smapi_init, exit TRUE g_usSmapiPort %x\n",
561 g_usSmapiPort);
562 retval = 0;
563 //SmapiQuerySystemID();
564 }
565 } else {
566 PRINTK_ERROR("smapi::smapi_init, ERROR invalid usSmapiID\n");
567 retval = -ENXIO;
568 }
569
570 return retval;
571 }
572