1 /*
2 * sound/pss.c
3 *
4 * The low level driver for the Personal Sound System (ECHO ESC614).
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Thomas Sailer ioctl code reworked (vmalloc/vfree removed)
15 * Alan Cox modularisation, clean up.
16 *
17 * 98-02-21: Vladimir Michl <vladimir.michl@upol.cz>
18 * Added mixer device for Beethoven ADSP-16 (master volume,
19 * bass, treble, synth), only for speakers.
20 * Fixed bug in pss_write (exchange parameters)
21 * Fixed config port of SB
22 * Requested two regions for PSS (PSS mixer, PSS config)
23 * Modified pss_download_boot
24 * To probe_pss_mss added test for initialize AD1848
25 * 98-05-28: Vladimir Michl <vladimir.michl@upol.cz>
26 * Fixed computation of mixer volumes
27 * 04-05-1999: Anthony Barbachan <barbcode@xmen.cis.fordham.edu>
28 * Added code that allows the user to enable his cdrom and/or
29 * joystick through the module parameters pss_cdrom_port and
30 * pss_enable_joystick. pss_cdrom_port takes a port address as its
31 * argument. pss_enable_joystick takes either a 0 or a non-0 as its
32 * argument.
33 * 04-06-1999: Anthony Barbachan <barbcode@xmen.cis.fordham.edu>
34 * Separated some code into new functions for easier reuse.
35 * Cleaned up and streamlined new code. Added code to allow a user
36 * to only use this driver for enabling non-sound components
37 * through the new module parameter pss_no_sound (flag). Added
38 * code that would allow a user to decide whether the driver should
39 * reset the configured hardware settings for the PSS board through
40 * the module parameter pss_keep_settings (flag). This flag will
41 * allow a user to free up resources in use by this card if needbe,
42 * furthermore it allows him to use this driver to just enable the
43 * emulations and then be unloaded as it is no longer needed. Both
44 * new settings are only available to this driver if compiled as a
45 * module. The default settings of all new parameters are set to
46 * load the driver as it did in previous versions.
47 * 04-07-1999: Anthony Barbachan <barbcode@xmen.cis.fordham.edu>
48 * Added module parameter pss_firmware to allow the user to tell
49 * the driver where the fireware file is located. The default
50 * setting is the previous hardcoded setting "/etc/sound/pss_synth".
51 * 00-03-03: Christoph Hellwig <chhellwig@gmx.net>
52 * Adapted to module_init/module_exit
53 * 11-10-2000: Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
54 * Added __init to probe_pss(), attach_pss() and probe_pss_mpu()
55 */
56
57
58 #include <linux/config.h>
59 #include <linux/init.h>
60 #include <linux/module.h>
61
62 #include "sound_config.h"
63 #include "sound_firmware.h"
64
65 #include "ad1848.h"
66 #include "mpu401.h"
67
68 /*
69 * PSS registers.
70 */
71 #define REG(x) (devc->base+x)
72 #define PSS_DATA 0
73 #define PSS_STATUS 2
74 #define PSS_CONTROL 2
75 #define PSS_ID 4
76 #define PSS_IRQACK 4
77 #define PSS_PIO 0x1a
78
79 /*
80 * Config registers
81 */
82 #define CONF_PSS 0x10
83 #define CONF_WSS 0x12
84 #define CONF_SB 0x14
85 #define CONF_CDROM 0x16
86 #define CONF_MIDI 0x18
87
88 /*
89 * Status bits.
90 */
91 #define PSS_FLAG3 0x0800
92 #define PSS_FLAG2 0x0400
93 #define PSS_FLAG1 0x1000
94 #define PSS_FLAG0 0x0800
95 #define PSS_WRITE_EMPTY 0x8000
96 #define PSS_READ_FULL 0x4000
97
98 /*
99 * WSS registers
100 */
101 #define WSS_INDEX 4
102 #define WSS_DATA 5
103
104 /*
105 * WSS status bits
106 */
107 #define WSS_INITIALIZING 0x80
108 #define WSS_AUTOCALIBRATION 0x20
109
110 #define NO_WSS_MIXER -1
111
112 #include "coproc.h"
113
114 #include "pss_boot.h"
115
116 /* If compiled into kernel, it enable or disable pss mixer */
117 #ifdef CONFIG_PSS_MIXER
118 static unsigned char pss_mixer = 1;
119 #else
120 static unsigned char pss_mixer = 0;
121 #endif
122
123
124 typedef struct pss_mixerdata {
125 unsigned int volume_l;
126 unsigned int volume_r;
127 unsigned int bass;
128 unsigned int treble;
129 unsigned int synth;
130 } pss_mixerdata;
131
132 typedef struct pss_confdata {
133 int base;
134 int irq;
135 int dma;
136 int *osp;
137 pss_mixerdata mixer;
138 int ad_mixer_dev;
139 } pss_confdata;
140
141 static pss_confdata pss_data;
142 static pss_confdata *devc = &pss_data;
143
144 static int pss_initialized = 0;
145 static int nonstandard_microcode = 0;
146 static int pss_cdrom_port = -1; /* Parameter for the PSS cdrom port */
147 static int pss_enable_joystick = 0;/* Parameter for enabling the joystick */
148
149 static void pss_write(pss_confdata *devc, int data)
150 {
151 int i, limit;
152
153 limit = jiffies + HZ/10; /* The timeout is 0.1 seconds */
154 /*
155 * Note! the i<5000000 is an emergency exit. The dsp_command() is sometimes
156 * called while interrupts are disabled. This means that the timer is
157 * disabled also. However the timeout situation is a abnormal condition.
158 * Normally the DSP should be ready to accept commands after just couple of
159 * loops.
160 */
161
162 for (i = 0; i < 5000000 && time_before(jiffies, limit); i++)
163 {
164 if (inw(REG(PSS_STATUS)) & PSS_WRITE_EMPTY)
165 {
166 outw(data, REG(PSS_DATA));
167 return;
168 }
169 }
170 printk(KERN_WARNING "PSS: DSP Command (%04x) Timeout.\n", data);
171 }
172
173 int __init probe_pss(struct address_info *hw_config)
174 {
175 unsigned short id;
176 int irq, dma;
177
178 devc->base = hw_config->io_base;
179 irq = devc->irq = hw_config->irq;
180 dma = devc->dma = hw_config->dma;
181 devc->osp = hw_config->osp;
182
183 if (devc->base != 0x220 && devc->base != 0x240)
184 if (devc->base != 0x230 && devc->base != 0x250) /* Some cards use these */
185 return 0;
186
187 if (check_region(devc->base, 0x19 /*16*/)) {
188 printk(KERN_ERR "PSS: I/O port conflict\n");
189 return 0;
190 }
191 id = inw(REG(PSS_ID));
192 if ((id >> 8) != 'E') {
193 printk(KERN_ERR "No PSS signature detected at 0x%x (0x%x)\n", devc->base, id);
194 return 0;
195 }
196 return 1;
197 }
198
199 static int set_irq(pss_confdata * devc, int dev, int irq)
200 {
201 static unsigned short irq_bits[16] =
202 {
203 0x0000, 0x0000, 0x0000, 0x0008,
204 0x0000, 0x0010, 0x0000, 0x0018,
205 0x0000, 0x0020, 0x0028, 0x0030,
206 0x0038, 0x0000, 0x0000, 0x0000
207 };
208
209 unsigned short tmp, bits;
210
211 if (irq < 0 || irq > 15)
212 return 0;
213
214 tmp = inw(REG(dev)) & ~0x38; /* Load confreg, mask IRQ bits out */
215
216 if ((bits = irq_bits[irq]) == 0 && irq != 0)
217 {
218 printk(KERN_ERR "PSS: Invalid IRQ %d\n", irq);
219 return 0;
220 }
221 outw(tmp | bits, REG(dev));
222 return 1;
223 }
224
225 static int set_io_base(pss_confdata * devc, int dev, int base)
226 {
227 unsigned short tmp = inw(REG(dev)) & 0x003f;
228 unsigned short bits = (base & 0x0ffc) << 4;
229
230 outw(bits | tmp, REG(dev));
231
232 return 1;
233 }
234
235 static int set_dma(pss_confdata * devc, int dev, int dma)
236 {
237 static unsigned short dma_bits[8] =
238 {
239 0x0001, 0x0002, 0x0000, 0x0003,
240 0x0000, 0x0005, 0x0006, 0x0007
241 };
242
243 unsigned short tmp, bits;
244
245 if (dma < 0 || dma > 7)
246 return 0;
247
248 tmp = inw(REG(dev)) & ~0x07; /* Load confreg, mask DMA bits out */
249
250 if ((bits = dma_bits[dma]) == 0 && dma != 4)
251 {
252 printk(KERN_ERR "PSS: Invalid DMA %d\n", dma);
253 return 0;
254 }
255 outw(tmp | bits, REG(dev));
256 return 1;
257 }
258
259 static int pss_reset_dsp(pss_confdata * devc)
260 {
261 unsigned long i, limit = jiffies + HZ/10;
262
263 outw(0x2000, REG(PSS_CONTROL));
264 for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
265 inw(REG(PSS_CONTROL));
266 outw(0x0000, REG(PSS_CONTROL));
267 return 1;
268 }
269
270 static int pss_put_dspword(pss_confdata * devc, unsigned short word)
271 {
272 int i, val;
273
274 for (i = 0; i < 327680; i++)
275 {
276 val = inw(REG(PSS_STATUS));
277 if (val & PSS_WRITE_EMPTY)
278 {
279 outw(word, REG(PSS_DATA));
280 return 1;
281 }
282 }
283 return 0;
284 }
285
286 static int pss_get_dspword(pss_confdata * devc, unsigned short *word)
287 {
288 int i, val;
289
290 for (i = 0; i < 327680; i++)
291 {
292 val = inw(REG(PSS_STATUS));
293 if (val & PSS_READ_FULL)
294 {
295 *word = inw(REG(PSS_DATA));
296 return 1;
297 }
298 }
299 return 0;
300 }
301
302 static int pss_download_boot(pss_confdata * devc, unsigned char *block, int size, int flags)
303 {
304 int i, limit, val, count;
305
306 if (flags & CPF_FIRST)
307 {
308 /*_____ Warn DSP software that a boot is coming */
309 outw(0x00fe, REG(PSS_DATA));
310
311 limit = jiffies + HZ/10;
312 for (i = 0; i < 32768 && time_before(jiffies, limit); i++)
313 if (inw(REG(PSS_DATA)) == 0x5500)
314 break;
315
316 outw(*block++, REG(PSS_DATA));
317 pss_reset_dsp(devc);
318 }
319 count = 1;
320 while ((flags&CPF_LAST) || count<size )
321 {
322 int j;
323
324 for (j = 0; j < 327670; j++)
325 {
326 /*_____ Wait for BG to appear */
327 if (inw(REG(PSS_STATUS)) & PSS_FLAG3)
328 break;
329 }
330
331 if (j == 327670)
332 {
333 /* It's ok we timed out when the file was empty */
334 if (count >= size && flags & CPF_LAST)
335 break;
336 else
337 {
338 printk("\n");
339 printk(KERN_ERR "PSS: Download timeout problems, byte %d=%d\n", count, size);
340 return 0;
341 }
342 }
343 /*_____ Send the next byte */
344 if (count >= size)
345 {
346 /* If not data in block send 0xffff */
347 outw (0xffff, REG (PSS_DATA));
348 }
349 else
350 {
351 /*_____ Send the next byte */
352 outw (*block++, REG (PSS_DATA));
353 };
354 count++;
355 }
356
357 if (flags & CPF_LAST)
358 {
359 /*_____ Why */
360 outw(0, REG(PSS_DATA));
361
362 limit = jiffies + HZ/10;
363 for (i = 0; i < 32768 && (limit - jiffies >= 0); i++)
364 val = inw(REG(PSS_STATUS));
365
366 limit = jiffies + HZ/10;
367 for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
368 {
369 val = inw(REG(PSS_STATUS));
370 if (val & 0x4000)
371 break;
372 }
373
374 /* now read the version */
375 for (i = 0; i < 32000; i++)
376 {
377 val = inw(REG(PSS_STATUS));
378 if (val & PSS_READ_FULL)
379 break;
380 }
381 if (i == 32000)
382 return 0;
383
384 val = inw(REG(PSS_DATA));
385 /* printk( "<PSS: microcode version %d.%d loaded>", val/16, val % 16); */
386 }
387 return 1;
388 }
389
390 /* Mixer */
391 static void set_master_volume(pss_confdata *devc, int left, int right)
392 {
393 static unsigned char log_scale[101] = {
394 0xdb, 0xe0, 0xe3, 0xe5, 0xe7, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xed, 0xee,
395 0xef, 0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3,
396 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7,
397 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
398 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb,
399 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
400 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
401 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
402 0xfe, 0xfe, 0xff, 0xff, 0xff
403 };
404 pss_write(devc, 0x0010);
405 pss_write(devc, log_scale[left] | 0x0000);
406 pss_write(devc, 0x0010);
407 pss_write(devc, log_scale[right] | 0x0100);
408 }
409
410 static void set_synth_volume(pss_confdata *devc, int volume)
411 {
412 int vol = ((0x8000*volume)/100L);
413 pss_write(devc, 0x0080);
414 pss_write(devc, vol);
415 pss_write(devc, 0x0081);
416 pss_write(devc, vol);
417 }
418
419 static void set_bass(pss_confdata *devc, int level)
420 {
421 int vol = (int)(((0xfd - 0xf0) * level)/100L) + 0xf0;
422 pss_write(devc, 0x0010);
423 pss_write(devc, vol | 0x0200);
424 };
425
426 static void set_treble(pss_confdata *devc, int level)
427 {
428 int vol = (((0xfd - 0xf0) * level)/100L) + 0xf0;
429 pss_write(devc, 0x0010);
430 pss_write(devc, vol | 0x0300);
431 };
432
433 static void pss_mixer_reset(pss_confdata *devc)
434 {
435 set_master_volume(devc, 33, 33);
436 set_bass(devc, 50);
437 set_treble(devc, 50);
438 set_synth_volume(devc, 30);
439 pss_write (devc, 0x0010);
440 pss_write (devc, 0x0800 | 0xce); /* Stereo */
441
442 if(pss_mixer)
443 {
444 devc->mixer.volume_l = devc->mixer.volume_r = 33;
445 devc->mixer.bass = 50;
446 devc->mixer.treble = 50;
447 devc->mixer.synth = 30;
448 }
449 }
450
451 static void arg_to_volume_mono(unsigned int volume, int *aleft)
452 {
453 int left;
454
455 left = volume & 0x00ff;
456 if (left > 100)
457 left = 100;
458 *aleft = left;
459 }
460
461 static void arg_to_volume_stereo(unsigned int volume, int *aleft, int *aright)
462 {
463 arg_to_volume_mono(volume, aleft);
464 arg_to_volume_mono(volume >> 8, aright);
465 }
466
467 static int ret_vol_mono(int left)
468 {
469 return ((left << 8) | left);
470 }
471
472 static int ret_vol_stereo(int left, int right)
473 {
474 return ((right << 8) | left);
475 }
476
477 static int call_ad_mixer(pss_confdata *devc,unsigned int cmd, caddr_t arg)
478 {
479 if (devc->ad_mixer_dev != NO_WSS_MIXER)
480 return mixer_devs[devc->ad_mixer_dev]->ioctl(devc->ad_mixer_dev, cmd, arg);
481 else
482 return -EINVAL;
483 }
484
485 static int pss_mixer_ioctl (int dev, unsigned int cmd, caddr_t arg)
486 {
487 pss_confdata *devc = mixer_devs[dev]->devc;
488 int cmdf = cmd & 0xff;
489
490 if ((cmdf != SOUND_MIXER_VOLUME) && (cmdf != SOUND_MIXER_BASS) &&
491 (cmdf != SOUND_MIXER_TREBLE) && (cmdf != SOUND_MIXER_SYNTH) &&
492 (cmdf != SOUND_MIXER_DEVMASK) && (cmdf != SOUND_MIXER_STEREODEVS) &&
493 (cmdf != SOUND_MIXER_RECMASK) && (cmdf != SOUND_MIXER_CAPS) &&
494 (cmdf != SOUND_MIXER_RECSRC))
495 {
496 return call_ad_mixer(devc, cmd, arg);
497 }
498
499 if (((cmd >> 8) & 0xff) != 'M')
500 return -EINVAL;
501
502 if (_SIOC_DIR (cmd) & _SIOC_WRITE)
503 {
504 switch (cmdf)
505 {
506 case SOUND_MIXER_RECSRC:
507 if (devc->ad_mixer_dev != NO_WSS_MIXER)
508 return call_ad_mixer(devc, cmd, arg);
509 else
510 {
511 if (*(int *)arg != 0)
512 return -EINVAL;
513 return 0;
514 }
515 case SOUND_MIXER_VOLUME:
516 arg_to_volume_stereo(*(unsigned int *)arg, &devc->mixer.volume_l,
517 &devc->mixer.volume_r);
518 set_master_volume(devc, devc->mixer.volume_l,
519 devc->mixer.volume_r);
520 return ret_vol_stereo(devc->mixer.volume_l,
521 devc->mixer.volume_r);
522
523 case SOUND_MIXER_BASS:
524 arg_to_volume_mono(*(unsigned int *)arg,
525 &devc->mixer.bass);
526 set_bass(devc, devc->mixer.bass);
527 return ret_vol_mono(devc->mixer.bass);
528
529 case SOUND_MIXER_TREBLE:
530 arg_to_volume_mono(*(unsigned int *)arg,
531 &devc->mixer.treble);
532 set_treble(devc, devc->mixer.treble);
533 return ret_vol_mono(devc->mixer.treble);
534
535 case SOUND_MIXER_SYNTH:
536 arg_to_volume_mono(*(unsigned int *)arg,
537 &devc->mixer.synth);
538 set_synth_volume(devc, devc->mixer.synth);
539 return ret_vol_mono(devc->mixer.synth);
540
541 default:
542 return -EINVAL;
543 }
544 }
545 else
546 {
547 /*
548 * Return parameters
549 */
550 switch (cmdf)
551 {
552
553 case SOUND_MIXER_DEVMASK:
554 if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
555 *(int *)arg = 0; /* no mixer devices */
556 return (*(int *)arg |= SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_SYNTH);
557
558 case SOUND_MIXER_STEREODEVS:
559 if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
560 *(int *)arg = 0; /* no stereo devices */
561 return (*(int *)arg |= SOUND_MASK_VOLUME);
562
563 case SOUND_MIXER_RECMASK:
564 if (devc->ad_mixer_dev != NO_WSS_MIXER)
565 return call_ad_mixer(devc, cmd, arg);
566 else
567 return (*(int *)arg = 0); /* no record devices */
568
569 case SOUND_MIXER_CAPS:
570 if (devc->ad_mixer_dev != NO_WSS_MIXER)
571 return call_ad_mixer(devc, cmd, arg);
572 else
573 return (*(int *)arg = SOUND_CAP_EXCL_INPUT);
574
575 case SOUND_MIXER_RECSRC:
576 if (devc->ad_mixer_dev != NO_WSS_MIXER)
577 return call_ad_mixer(devc, cmd, arg);
578 else
579 return (*(int *)arg = 0); /* no record source */
580
581 case SOUND_MIXER_VOLUME:
582 return (*(int *)arg = ret_vol_stereo(devc->mixer.volume_l, devc->mixer.volume_r));
583
584 case SOUND_MIXER_BASS:
585 return (*(int *)arg = ret_vol_mono(devc->mixer.bass));
586
587 case SOUND_MIXER_TREBLE:
588 return (*(int *)arg = ret_vol_mono(devc->mixer.treble));
589
590 case SOUND_MIXER_SYNTH:
591 return (*(int *)arg = ret_vol_mono(devc->mixer.synth));
592 default:
593 return -EINVAL;
594 }
595 }
596 }
597
598 static struct mixer_operations pss_mixer_operations =
599 {
600 owner: THIS_MODULE,
601 id: "SOUNDPORT",
602 name: "PSS-AD1848",
603 ioctl: pss_mixer_ioctl
604 };
605
606 void disable_all_emulations(void)
607 {
608 outw(0x0000, REG(CONF_PSS)); /* 0x0400 enables joystick */
609 outw(0x0000, REG(CONF_WSS));
610 outw(0x0000, REG(CONF_SB));
611 outw(0x0000, REG(CONF_MIDI));
612 outw(0x0000, REG(CONF_CDROM));
613 }
614
615 void configure_nonsound_components(void)
616 {
617 /* Configure Joystick port */
618
619 if(pss_enable_joystick)
620 {
621 outw(0x0400, REG(CONF_PSS)); /* 0x0400 enables joystick */
622 printk(KERN_INFO "PSS: joystick enabled.\n");
623 }
624 else
625 {
626 printk(KERN_INFO "PSS: joystick port not enabled.\n");
627 }
628
629 /* Configure CDROM port */
630
631 if(pss_cdrom_port == -1) /* If cdrom port enablation wasn't requested */
632 {
633 printk(KERN_INFO "PSS: CDROM port not enabled.\n");
634 }
635 else if(check_region(pss_cdrom_port, 2))
636 {
637 printk(KERN_ERR "PSS: CDROM I/O port conflict.\n");
638 }
639 else if(!set_io_base(devc, CONF_CDROM, pss_cdrom_port))
640 {
641 printk(KERN_ERR "PSS: CDROM I/O port could not be set.\n");
642 }
643 else /* CDROM port successfully configured */
644 {
645 printk(KERN_INFO "PSS: CDROM I/O port set to 0x%x.\n", pss_cdrom_port);
646 }
647 }
648
649 void __init attach_pss(struct address_info *hw_config)
650 {
651 unsigned short id;
652 char tmp[100];
653
654 devc->base = hw_config->io_base;
655 devc->irq = hw_config->irq;
656 devc->dma = hw_config->dma;
657 devc->osp = hw_config->osp;
658 devc->ad_mixer_dev = NO_WSS_MIXER;
659
660 if (!probe_pss(hw_config))
661 return;
662
663 request_region(hw_config->io_base, 0x10, "PSS mixer, SB emulation");
664 request_region(hw_config->io_base + 0x10, 0x9, "PSS config");
665
666 id = inw(REG(PSS_ID)) & 0x00ff;
667
668 /*
669 * Disable all emulations. Will be enabled later (if required).
670 */
671
672 disable_all_emulations();
673
674 #if YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
675 if (sound_alloc_dma(hw_config->dma, "PSS"))
676 {
677 printk("pss.c: Can't allocate DMA channel.\n");
678 return;
679 }
680 if (!set_irq(devc, CONF_PSS, devc->irq))
681 {
682 printk("PSS: IRQ allocation error.\n");
683 return;
684 }
685 if (!set_dma(devc, CONF_PSS, devc->dma))
686 {
687 printk(KERN_ERR "PSS: DMA allocation error\n");
688 return;
689 }
690 #endif
691
692 configure_nonsound_components();
693 pss_initialized = 1;
694 sprintf(tmp, "ECHO-PSS Rev. %d", id);
695 conf_printf(tmp, hw_config);
696 }
697
698 int __init probe_pss_mpu(struct address_info *hw_config)
699 {
700 int timeout;
701
702 if (!pss_initialized)
703 return 0;
704
705 if (check_region(hw_config->io_base, 2))
706 {
707 printk(KERN_ERR "PSS: MPU I/O port conflict\n");
708 return 0;
709 }
710 if (!set_io_base(devc, CONF_MIDI, hw_config->io_base))
711 {
712 printk(KERN_ERR "PSS: MIDI base could not be set.\n");
713 return 0;
714 }
715 if (!set_irq(devc, CONF_MIDI, hw_config->irq))
716 {
717 printk(KERN_ERR "PSS: MIDI IRQ allocation error.\n");
718 return 0;
719 }
720 if (!pss_synthLen)
721 {
722 printk(KERN_ERR "PSS: Can't enable MPU. MIDI synth microcode not available.\n");
723 return 0;
724 }
725 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
726 {
727 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
728 return 0;
729 }
730
731 /*
732 * Finally wait until the DSP algorithm has initialized itself and
733 * deactivates receive interrupt.
734 */
735
736 for (timeout = 900000; timeout > 0; timeout--)
737 {
738 if ((inb(hw_config->io_base + 1) & 0x80) == 0) /* Input data avail */
739 inb(hw_config->io_base); /* Discard it */
740 else
741 break; /* No more input */
742 }
743
744 return probe_mpu401(hw_config);
745 }
746
747 static int pss_coproc_open(void *dev_info, int sub_device)
748 {
749 switch (sub_device)
750 {
751 case COPR_MIDI:
752 if (pss_synthLen == 0)
753 {
754 printk(KERN_ERR "PSS: MIDI synth microcode not available.\n");
755 return -EIO;
756 }
757 if (nonstandard_microcode)
758 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
759 {
760 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
761 return -EIO;
762 }
763 nonstandard_microcode = 0;
764 break;
765
766 default:
767 }
768 return 0;
769 }
770
771 static void pss_coproc_close(void *dev_info, int sub_device)
772 {
773 return;
774 }
775
776 static void pss_coproc_reset(void *dev_info)
777 {
778 if (pss_synthLen)
779 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
780 {
781 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
782 }
783 nonstandard_microcode = 0;
784 }
785
786 static int download_boot_block(void *dev_info, copr_buffer * buf)
787 {
788 if (buf->len <= 0 || buf->len > sizeof(buf->data))
789 return -EINVAL;
790
791 if (!pss_download_boot(devc, buf->data, buf->len, buf->flags))
792 {
793 printk(KERN_ERR "PSS: Unable to load microcode block to DSP.\n");
794 return -EIO;
795 }
796 nonstandard_microcode = 1; /* The MIDI microcode has been overwritten */
797 return 0;
798 }
799
800 static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, caddr_t arg, int local)
801 {
802 copr_buffer *buf;
803 copr_msg *mbuf;
804 copr_debug_buf dbuf;
805 unsigned short tmp;
806 unsigned long flags;
807 unsigned short *data;
808 int i, err;
809 /* printk( "PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
810
811 switch (cmd)
812 {
813 case SNDCTL_COPR_RESET:
814 pss_coproc_reset(dev_info);
815 return 0;
816
817 case SNDCTL_COPR_LOAD:
818 buf = (copr_buffer *) vmalloc(sizeof(copr_buffer));
819 if (buf == NULL)
820 return -ENOSPC;
821 if (copy_from_user(buf, arg, sizeof(copr_buffer))) {
822 vfree(buf);
823 return -EFAULT;
824 }
825 err = download_boot_block(dev_info, buf);
826 vfree(buf);
827 return err;
828
829 case SNDCTL_COPR_SENDMSG:
830 mbuf = (copr_msg *)vmalloc(sizeof(copr_msg));
831 if (mbuf == NULL)
832 return -ENOSPC;
833 if (copy_from_user(mbuf, arg, sizeof(copr_msg))) {
834 vfree(mbuf);
835 return -EFAULT;
836 }
837 data = (unsigned short *)(mbuf->data);
838 save_flags(flags);
839 cli();
840 for (i = 0; i < mbuf->len; i++) {
841 if (!pss_put_dspword(devc, *data++)) {
842 restore_flags(flags);
843 mbuf->len = i; /* feed back number of WORDs sent */
844 err = copy_to_user(arg, mbuf, sizeof(copr_msg));
845 vfree(mbuf);
846 return err ? -EFAULT : -EIO;
847 }
848 }
849 restore_flags(flags);
850 vfree(mbuf);
851 return 0;
852
853 case SNDCTL_COPR_RCVMSG:
854 err = 0;
855 mbuf = (copr_msg *)vmalloc(sizeof(copr_msg));
856 if (mbuf == NULL)
857 return -ENOSPC;
858 data = (unsigned short *)mbuf->data;
859 save_flags(flags);
860 cli();
861 for (i = 0; i < sizeof(mbuf->data)/sizeof(unsigned short); i++) {
862 mbuf->len = i; /* feed back number of WORDs read */
863 if (!pss_get_dspword(devc, data++)) {
864 if (i == 0)
865 err = -EIO;
866 break;
867 }
868 }
869 restore_flags(flags);
870 if (copy_to_user(arg, mbuf, sizeof(copr_msg)))
871 err = -EFAULT;
872 vfree(mbuf);
873 return err;
874
875 case SNDCTL_COPR_RDATA:
876 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
877 return -EFAULT;
878 save_flags(flags);
879 cli();
880 if (!pss_put_dspword(devc, 0x00d0)) {
881 restore_flags(flags);
882 return -EIO;
883 }
884 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
885 restore_flags(flags);
886 return -EIO;
887 }
888 if (!pss_get_dspword(devc, &tmp)) {
889 restore_flags(flags);
890 return -EIO;
891 }
892 dbuf.parm1 = tmp;
893 restore_flags(flags);
894 if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
895 return -EFAULT;
896 return 0;
897
898 case SNDCTL_COPR_WDATA:
899 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
900 return -EFAULT;
901 save_flags(flags);
902 cli();
903 if (!pss_put_dspword(devc, 0x00d1)) {
904 restore_flags(flags);
905 return -EIO;
906 }
907 if (!pss_put_dspword(devc, (unsigned short) (dbuf.parm1 & 0xffff))) {
908 restore_flags(flags);
909 return -EIO;
910 }
911 tmp = (unsigned int)dbuf.parm2 & 0xffff;
912 if (!pss_put_dspword(devc, tmp)) {
913 restore_flags(flags);
914 return -EIO;
915 }
916 restore_flags(flags);
917 return 0;
918
919 case SNDCTL_COPR_WCODE:
920 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
921 return -EFAULT;
922 save_flags(flags);
923 cli();
924 if (!pss_put_dspword(devc, 0x00d3)) {
925 restore_flags(flags);
926 return -EIO;
927 }
928 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
929 restore_flags(flags);
930 return -EIO;
931 }
932 tmp = (unsigned int)dbuf.parm2 & 0x00ff;
933 if (!pss_put_dspword(devc, tmp)) {
934 restore_flags(flags);
935 return -EIO;
936 }
937 tmp = ((unsigned int)dbuf.parm2 >> 8) & 0xffff;
938 if (!pss_put_dspword(devc, tmp)) {
939 restore_flags(flags);
940 return -EIO;
941 }
942 restore_flags(flags);
943 return 0;
944
945 case SNDCTL_COPR_RCODE:
946 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
947 return -EFAULT;
948 save_flags(flags);
949 cli();
950 if (!pss_put_dspword(devc, 0x00d2)) {
951 restore_flags(flags);
952 return -EIO;
953 }
954 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
955 restore_flags(flags);
956 return -EIO;
957 }
958 if (!pss_get_dspword(devc, &tmp)) { /* Read MSB */
959 restore_flags(flags);
960 return -EIO;
961 }
962 dbuf.parm1 = tmp << 8;
963 if (!pss_get_dspword(devc, &tmp)) { /* Read LSB */
964 restore_flags(flags);
965 return -EIO;
966 }
967 dbuf.parm1 |= tmp & 0x00ff;
968 restore_flags(flags);
969 if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
970 return -EFAULT;
971 return 0;
972
973 default:
974 return -EINVAL;
975 }
976 return -EINVAL;
977 }
978
979 static coproc_operations pss_coproc_operations =
980 {
981 "ADSP-2115",
982 pss_coproc_open,
983 pss_coproc_close,
984 pss_coproc_ioctl,
985 pss_coproc_reset,
986 &pss_data
987 };
988
989 static void __init attach_pss_mpu(struct address_info *hw_config)
990 {
991 attach_mpu401(hw_config, THIS_MODULE); /* Slot 1 */
992 if (hw_config->slots[1] != -1) /* The MPU driver installed itself */
993 midi_devs[hw_config->slots[1]]->coproc = &pss_coproc_operations;
994 }
995
996 static int __init probe_pss_mss(struct address_info *hw_config)
997 {
998 volatile int timeout;
999
1000 if (!pss_initialized)
1001 return 0;
1002
1003 if (check_region(hw_config->io_base, 8))
1004 {
1005 printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
1006 return 0;
1007 }
1008 if (!set_io_base(devc, CONF_WSS, hw_config->io_base))
1009 {
1010 printk("PSS: WSS base not settable.\n");
1011 return 0;
1012 }
1013 if (!set_irq(devc, CONF_WSS, hw_config->irq))
1014 {
1015 printk("PSS: WSS IRQ allocation error.\n");
1016 return 0;
1017 }
1018 if (!set_dma(devc, CONF_WSS, hw_config->dma))
1019 {
1020 printk(KERN_ERR "PSS: WSS DMA allocation error\n");
1021 return 0;
1022 }
1023 /*
1024 * For some reason the card returns 0xff in the WSS status register
1025 * immediately after boot. Probably MIDI+SB emulation algorithm
1026 * downloaded to the ADSP2115 spends some time initializing the card.
1027 * Let's try to wait until it finishes this task.
1028 */
1029 for (timeout = 0; timeout < 100000 && (inb(hw_config->io_base + WSS_INDEX) &
1030 WSS_INITIALIZING); timeout++)
1031 ;
1032
1033 outb((0x0b), hw_config->io_base + WSS_INDEX); /* Required by some cards */
1034
1035 for (timeout = 0; (inb(hw_config->io_base + WSS_DATA) & WSS_AUTOCALIBRATION) &&
1036 (timeout < 100000); timeout++)
1037 ;
1038
1039 return probe_ms_sound(hw_config);
1040 }
1041
1042 static void __init attach_pss_mss(struct address_info *hw_config)
1043 {
1044 int my_mix = -999; /* gcc shut up */
1045
1046 devc->ad_mixer_dev = NO_WSS_MIXER;
1047 if (pss_mixer)
1048 {
1049 if ((my_mix = sound_install_mixer (MIXER_DRIVER_VERSION,
1050 "PSS-SPEAKERS and AD1848 (through MSS audio codec)",
1051 &pss_mixer_operations,
1052 sizeof (struct mixer_operations),
1053 devc)) < 0)
1054 {
1055 printk(KERN_ERR "Could not install PSS mixer\n");
1056 return;
1057 }
1058 }
1059 pss_mixer_reset(devc);
1060 attach_ms_sound(hw_config, THIS_MODULE); /* Slot 0 */
1061
1062 if (hw_config->slots[0] != -1)
1063 {
1064 /* The MSS driver installed itself */
1065 audio_devs[hw_config->slots[0]]->coproc = &pss_coproc_operations;
1066 if (pss_mixer && (num_mixers == (my_mix + 2)))
1067 {
1068 /* The MSS mixer installed */
1069 devc->ad_mixer_dev = audio_devs[hw_config->slots[0]]->mixer_dev;
1070 }
1071 }
1072 }
1073
1074 static inline void __exit unload_pss(struct address_info *hw_config)
1075 {
1076 release_region(hw_config->io_base, 0x10);
1077 release_region(hw_config->io_base+0x10, 0x9);
1078 }
1079
1080 static inline void __exit unload_pss_mpu(struct address_info *hw_config)
1081 {
1082 unload_mpu401(hw_config);
1083 }
1084
1085 static inline void __exit unload_pss_mss(struct address_info *hw_config)
1086 {
1087 unload_ms_sound(hw_config);
1088 }
1089
1090
1091 static struct address_info cfg;
1092 static struct address_info cfg2;
1093 static struct address_info cfg_mpu;
1094
1095 static int pss_io __initdata = -1;
1096 static int mss_io __initdata = -1;
1097 static int mss_irq __initdata = -1;
1098 static int mss_dma __initdata = -1;
1099 static int mpu_io __initdata = -1;
1100 static int mpu_irq __initdata = -1;
1101 static int pss_no_sound __initdata = 0; /* Just configure non-sound components */
1102 static int pss_keep_settings = 1; /* Keep hardware settings at module exit */
1103 static char *pss_firmware = "/etc/sound/pss_synth";
1104
1105 MODULE_PARM(pss_io, "i");
1106 MODULE_PARM_DESC(pss_io, "Set i/o base of PSS card (probably 0x220 or 0x240)");
1107 MODULE_PARM(mss_io, "i");
1108 MODULE_PARM_DESC(mss_io, "Set WSS (audio) i/o base (0x530, 0x604, 0xE80, 0xF40, or other. Address must end in 0 or 4 and must be from 0x100 to 0xFF4)");
1109 MODULE_PARM(mss_irq, "i");
1110 MODULE_PARM_DESC(mss_irq, "Set WSS (audio) IRQ (3, 5, 7, 9, 10, 11, 12)");
1111 MODULE_PARM(mss_dma, "i");
1112 MODULE_PARM_DESC(mss_dma, "Set WSS (audio) DMA (0, 1, 3)");
1113 MODULE_PARM(mpu_io, "i");
1114 MODULE_PARM_DESC(mpu_io, "Set MIDI i/o base (0x330 or other. Address must be on 4 location boundaries and must be from 0x100 to 0xFFC)");
1115 MODULE_PARM(mpu_irq, "i");
1116 MODULE_PARM_DESC(mpu_irq, "Set MIDI IRQ (3, 5, 7, 9, 10, 11, 12)");
1117 MODULE_PARM(pss_cdrom_port, "i");
1118 MODULE_PARM_DESC(pss_cdrom_port, "Set the PSS CDROM port i/o base (0x340 or other)");
1119 MODULE_PARM(pss_enable_joystick, "i");
1120 MODULE_PARM_DESC(pss_enable_joystick, "Enables the PSS joystick port (1 to enable, 0 to disable)");
1121 MODULE_PARM(pss_no_sound, "i");
1122 MODULE_PARM_DESC(pss_no_sound, "Configure sound compoents (0 - no, 1 - yes)");
1123 MODULE_PARM(pss_keep_settings, "i");
1124 MODULE_PARM_DESC(pss_keep_settings, "Keep hardware setting at driver unloading (0 - no, 1 - yes)");
1125 MODULE_PARM(pss_firmware, "s");
1126 MODULE_PARM_DESC(pss_firmware, "Location of the firmware file (default - /etc/sound/pss_synth)");
1127 MODULE_PARM(pss_mixer, "b");
1128 MODULE_PARM_DESC(pss_mixer, "Enable (1) or disable (0) PSS mixer (controlling of output volume, bass, treble, synth volume). The mixer is not available on all PSS cards.");
1129 MODULE_AUTHOR("Hannu Savolainen, Vladimir Michl");
1130 MODULE_DESCRIPTION("Module for PSS sound cards (based on AD1848, ADSP-2115 and ESC614). This module includes control of output amplifier and synth volume of the Beethoven ADSP-16 card (this may work with other PSS cards).\n");
1131
1132 static int fw_load = 0;
1133 static int pssmpu = 0, pssmss = 0;
1134
1135 /*
1136 * Load a PSS sound card module
1137 */
1138
1139 static int __init init_pss(void)
1140 {
1141
1142 if(pss_no_sound) /* If configuring only nonsound components */
1143 {
1144 cfg.io_base = pss_io;
1145 if(!probe_pss(&cfg))
1146 return -ENODEV;
1147 printk(KERN_INFO "ECHO-PSS Rev. %d\n", inw(REG(PSS_ID)) & 0x00ff);
1148 printk(KERN_INFO "PSS: loading in no sound mode.\n");
1149 disable_all_emulations();
1150 configure_nonsound_components();
1151 return 0;
1152 }
1153
1154 cfg.io_base = pss_io;
1155
1156 cfg2.io_base = mss_io;
1157 cfg2.irq = mss_irq;
1158 cfg2.dma = mss_dma;
1159
1160 cfg_mpu.io_base = mpu_io;
1161 cfg_mpu.irq = mpu_irq;
1162
1163 if (cfg.io_base == -1 || cfg2.io_base == -1 || cfg2.irq == -1 || cfg.dma == -1) {
1164 printk(KERN_INFO "pss: mss_io, mss_dma, mss_irq and pss_io must be set.\n");
1165 return -EINVAL;
1166 }
1167
1168 if (!pss_synth) {
1169 fw_load = 1;
1170 pss_synthLen = mod_firmware_load(pss_firmware, (void *) &pss_synth);
1171 }
1172 if (!probe_pss(&cfg))
1173 return -ENODEV;
1174 attach_pss(&cfg);
1175 /*
1176 * Attach stuff
1177 */
1178 if (probe_pss_mpu(&cfg_mpu)) {
1179 pssmpu = 1;
1180 attach_pss_mpu(&cfg_mpu);
1181 }
1182 if (probe_pss_mss(&cfg2)) {
1183 pssmss = 1;
1184 attach_pss_mss(&cfg2);
1185 }
1186
1187 return 0;
1188 }
1189
1190 static void __exit cleanup_pss(void)
1191 {
1192 if(!pss_no_sound)
1193 {
1194 if(fw_load && pss_synth)
1195 vfree(pss_synth);
1196 if(pssmss)
1197 unload_pss_mss(&cfg2);
1198 if(pssmpu)
1199 unload_pss_mpu(&cfg_mpu);
1200 unload_pss(&cfg);
1201 }
1202
1203 if(!pss_keep_settings) /* Keep hardware settings if asked */
1204 {
1205 disable_all_emulations();
1206 printk(KERN_INFO "Resetting PSS sound card configurations.\n");
1207 }
1208 }
1209
1210 module_init(init_pss);
1211 module_exit(cleanup_pss);
1212
1213 #ifndef MODULE
1214 static int __init setup_pss(char *str)
1215 {
1216 /* io, mss_io, mss_irq, mss_dma, mpu_io, mpu_irq */
1217 int ints[7];
1218
1219 str = get_options(str, ARRAY_SIZE(ints), ints);
1220
1221 pss_io = ints[1];
1222 mss_io = ints[2];
1223 mss_irq = ints[3];
1224 mss_dma = ints[4];
1225 mpu_io = ints[5];
1226 mpu_irq = ints[6];
1227
1228 return 1;
1229 }
1230
1231 __setup("pss=", setup_pss);
1232 #endif
1233
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.