aboutsummaryrefslogtreecommitdiffstats
path: root/sound/isa/sscape.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/isa/sscape.c')
-rw-r--r--sound/isa/sscape.c189
1 files changed, 38 insertions, 151 deletions
diff --git a/sound/isa/sscape.c b/sound/isa/sscape.c
index 4025fb558c50..66187122377c 100644
--- a/sound/isa/sscape.c
+++ b/sound/isa/sscape.c
@@ -89,9 +89,6 @@ MODULE_DEVICE_TABLE(pnp_card, sscape_pnpids);
89#endif 89#endif
90 90
91 91
92#define MPU401_IO(i) ((i) + 0)
93#define MIDI_DATA_IO(i) ((i) + 0)
94#define MIDI_CTRL_IO(i) ((i) + 1)
95#define HOST_CTRL_IO(i) ((i) + 2) 92#define HOST_CTRL_IO(i) ((i) + 2)
96#define HOST_DATA_IO(i) ((i) + 3) 93#define HOST_DATA_IO(i) ((i) + 3)
97#define ODIE_ADDR_IO(i) ((i) + 4) 94#define ODIE_ADDR_IO(i) ((i) + 4)
@@ -129,9 +126,6 @@ enum GA_REG {
129#define DMA_8BIT 0x80 126#define DMA_8BIT 0x80
130 127
131 128
132#define AD1845_FREQ_SEL_MSB 0x16
133#define AD1845_FREQ_SEL_LSB 0x17
134
135enum card_type { 129enum card_type {
136 SSCAPE, 130 SSCAPE,
137 SSCAPE_PNP, 131 SSCAPE_PNP,
@@ -141,8 +135,6 @@ enum card_type {
141struct soundscape { 135struct soundscape {
142 spinlock_t lock; 136 spinlock_t lock;
143 unsigned io_base; 137 unsigned io_base;
144 unsigned wss_base;
145 int codec_type;
146 int ic_type; 138 int ic_type;
147 enum card_type type; 139 enum card_type type;
148 struct resource *io_res; 140 struct resource *io_res;
@@ -330,7 +322,7 @@ static int host_write_ctrl_unsafe(unsigned io_base, unsigned char data,
330 */ 322 */
331static inline int verify_mpu401(const struct snd_mpu401 * mpu) 323static inline int verify_mpu401(const struct snd_mpu401 * mpu)
332{ 324{
333 return ((inb(MIDI_CTRL_IO(mpu->port)) & 0xc0) == 0x80); 325 return ((inb(MPU401C(mpu)) & 0xc0) == 0x80);
334} 326}
335 327
336/* 328/*
@@ -338,7 +330,7 @@ static inline int verify_mpu401(const struct snd_mpu401 * mpu)
338 */ 330 */
339static inline void initialise_mpu401(const struct snd_mpu401 * mpu) 331static inline void initialise_mpu401(const struct snd_mpu401 * mpu)
340{ 332{
341 outb(0, MIDI_DATA_IO(mpu->port)); 333 outb(0, MPU401D(mpu));
342} 334}
343 335
344/* 336/*
@@ -396,20 +388,20 @@ static int sscape_wait_dma_unsafe(unsigned io_base, enum GA_REG reg, unsigned ti
396 */ 388 */
397static int obp_startup_ack(struct soundscape *s, unsigned timeout) 389static int obp_startup_ack(struct soundscape *s, unsigned timeout)
398{ 390{
399 while (timeout != 0) { 391 unsigned long end_time = jiffies + msecs_to_jiffies(timeout);
392
393 do {
400 unsigned long flags; 394 unsigned long flags;
401 unsigned char x; 395 unsigned char x;
402 396
403 schedule_timeout_uninterruptible(1);
404
405 spin_lock_irqsave(&s->lock, flags); 397 spin_lock_irqsave(&s->lock, flags);
406 x = inb(HOST_DATA_IO(s->io_base)); 398 x = inb(HOST_DATA_IO(s->io_base));
407 spin_unlock_irqrestore(&s->lock, flags); 399 spin_unlock_irqrestore(&s->lock, flags);
408 if ((x & 0xfe) == 0xfe) 400 if ((x & 0xfe) == 0xfe)
409 return 1; 401 return 1;
410 402
411 --timeout; 403 msleep(10);
412 } /* while */ 404 } while (time_before(jiffies, end_time));
413 405
414 return 0; 406 return 0;
415} 407}
@@ -423,20 +415,20 @@ static int obp_startup_ack(struct soundscape *s, unsigned timeout)
423 */ 415 */
424static int host_startup_ack(struct soundscape *s, unsigned timeout) 416static int host_startup_ack(struct soundscape *s, unsigned timeout)
425{ 417{
426 while (timeout != 0) { 418 unsigned long end_time = jiffies + msecs_to_jiffies(timeout);
419
420 do {
427 unsigned long flags; 421 unsigned long flags;
428 unsigned char x; 422 unsigned char x;
429 423
430 schedule_timeout_uninterruptible(1);
431
432 spin_lock_irqsave(&s->lock, flags); 424 spin_lock_irqsave(&s->lock, flags);
433 x = inb(HOST_DATA_IO(s->io_base)); 425 x = inb(HOST_DATA_IO(s->io_base));
434 spin_unlock_irqrestore(&s->lock, flags); 426 spin_unlock_irqrestore(&s->lock, flags);
435 if (x == 0xfe) 427 if (x == 0xfe)
436 return 1; 428 return 1;
437 429
438 --timeout; 430 msleep(10);
439 } /* while */ 431 } while (time_before(jiffies, end_time));
440 432
441 return 0; 433 return 0;
442} 434}
@@ -532,10 +524,10 @@ static int upload_dma_data(struct soundscape *s,
532 * give it 5 seconds (max) ... 524 * give it 5 seconds (max) ...
533 */ 525 */
534 ret = 0; 526 ret = 0;
535 if (!obp_startup_ack(s, 5)) { 527 if (!obp_startup_ack(s, 5000)) {
536 snd_printk(KERN_ERR "sscape: No response from on-board processor after upload\n"); 528 snd_printk(KERN_ERR "sscape: No response from on-board processor after upload\n");
537 ret = -EAGAIN; 529 ret = -EAGAIN;
538 } else if (!host_startup_ack(s, 5)) { 530 } else if (!host_startup_ack(s, 5000)) {
539 snd_printk(KERN_ERR "sscape: SoundScape failed to initialise\n"); 531 snd_printk(KERN_ERR "sscape: SoundScape failed to initialise\n");
540 ret = -EAGAIN; 532 ret = -EAGAIN;
541 } 533 }
@@ -732,13 +724,7 @@ static int sscape_midi_get(struct snd_kcontrol *kctl,
732 unsigned long flags; 724 unsigned long flags;
733 725
734 spin_lock_irqsave(&s->lock, flags); 726 spin_lock_irqsave(&s->lock, flags);
735 set_host_mode_unsafe(s->io_base); 727 uctl->value.integer.value[0] = s->midi_vol;
736
737 if (host_write_ctrl_unsafe(s->io_base, CMD_GET_MIDI_VOL, 100)) {
738 uctl->value.integer.value[0] = host_read_ctrl_unsafe(s->io_base, 100);
739 }
740
741 set_midi_mode_unsafe(s->io_base);
742 spin_unlock_irqrestore(&s->lock, flags); 728 spin_unlock_irqrestore(&s->lock, flags);
743 return 0; 729 return 0;
744} 730}
@@ -773,6 +759,7 @@ static int sscape_midi_put(struct snd_kcontrol *kctl,
773 change = (host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100) 759 change = (host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100)
774 && host_write_ctrl_unsafe(s->io_base, ((unsigned char) uctl->value.integer. value[0]) & 127, 100) 760 && host_write_ctrl_unsafe(s->io_base, ((unsigned char) uctl->value.integer. value[0]) & 127, 100)
775 && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100)); 761 && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100));
762 s->midi_vol = (unsigned char) uctl->value.integer.value[0] & 127;
776 __skip_change: 763 __skip_change:
777 764
778 /* 765 /*
@@ -815,12 +802,11 @@ static unsigned __devinit get_irq_config(int irq)
815 * Perform certain arcane port-checks to see whether there 802 * Perform certain arcane port-checks to see whether there
816 * is a SoundScape board lurking behind the given ports. 803 * is a SoundScape board lurking behind the given ports.
817 */ 804 */
818static int __devinit detect_sscape(struct soundscape *s) 805static int __devinit detect_sscape(struct soundscape *s, long wss_io)
819{ 806{
820 unsigned long flags; 807 unsigned long flags;
821 unsigned d; 808 unsigned d;
822 int retval = 0; 809 int retval = 0;
823 int codec = s->wss_base;
824 810
825 spin_lock_irqsave(&s->lock, flags); 811 spin_lock_irqsave(&s->lock, flags);
826 812
@@ -836,13 +822,11 @@ static int __devinit detect_sscape(struct soundscape *s)
836 if ((d & 0x80) != 0) 822 if ((d & 0x80) != 0)
837 goto _done; 823 goto _done;
838 824
839 if (d == 0) { 825 if (d == 0)
840 s->codec_type = 1;
841 s->ic_type = IC_ODIE; 826 s->ic_type = IC_ODIE;
842 } else if ((d & 0x60) != 0) { 827 else if ((d & 0x60) != 0)
843 s->codec_type = 2;
844 s->ic_type = IC_OPUS; 828 s->ic_type = IC_OPUS;
845 } else 829 else
846 goto _done; 830 goto _done;
847 831
848 outb(0xfa, ODIE_ADDR_IO(s->io_base)); 832 outb(0xfa, ODIE_ADDR_IO(s->io_base));
@@ -862,10 +846,10 @@ static int __devinit detect_sscape(struct soundscape *s)
862 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0); 846 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);
863 847
864 if (s->type == SSCAPE_VIVO) 848 if (s->type == SSCAPE_VIVO)
865 codec += 4; 849 wss_io += 4;
866 /* wait for WSS codec */ 850 /* wait for WSS codec */
867 for (d = 0; d < 500; d++) { 851 for (d = 0; d < 500; d++) {
868 if ((inb(codec) & 0x80) == 0) 852 if ((inb(wss_io) & 0x80) == 0)
869 break; 853 break;
870 spin_unlock_irqrestore(&s->lock, flags); 854 spin_unlock_irqrestore(&s->lock, flags);
871 msleep(1); 855 msleep(1);
@@ -955,82 +939,6 @@ static int __devinit create_mpu401(struct snd_card *card, int devnum, unsigned l
955 939
956 940
957/* 941/*
958 * Override for the CS4231 playback format function.
959 * The AD1845 has much simpler format and rate selection.
960 */
961static void ad1845_playback_format(struct snd_wss *chip,
962 struct snd_pcm_hw_params *params,
963 unsigned char format)
964{
965 unsigned long flags;
966 unsigned rate = params_rate(params);
967
968 /*
969 * The AD1845 can't handle sample frequencies
970 * outside of 4 kHZ to 50 kHZ
971 */
972 if (rate > 50000)
973 rate = 50000;
974 else if (rate < 4000)
975 rate = 4000;
976
977 spin_lock_irqsave(&chip->reg_lock, flags);
978
979 /*
980 * Program the AD1845 correctly for the playback stream.
981 * Note that we do NOT need to toggle the MCE bit because
982 * the PLAYBACK_ENABLE bit of the Interface Configuration
983 * register is set.
984 *
985 * NOTE: We seem to need to write to the MSB before the LSB
986 * to get the correct sample frequency.
987 */
988 snd_wss_out(chip, CS4231_PLAYBK_FORMAT, (format & 0xf0));
989 snd_wss_out(chip, AD1845_FREQ_SEL_MSB, (unsigned char) (rate >> 8));
990 snd_wss_out(chip, AD1845_FREQ_SEL_LSB, (unsigned char) rate);
991
992 spin_unlock_irqrestore(&chip->reg_lock, flags);
993}
994
995/*
996 * Override for the CS4231 capture format function.
997 * The AD1845 has much simpler format and rate selection.
998 */
999static void ad1845_capture_format(struct snd_wss *chip,
1000 struct snd_pcm_hw_params *params,
1001 unsigned char format)
1002{
1003 unsigned long flags;
1004 unsigned rate = params_rate(params);
1005
1006 /*
1007 * The AD1845 can't handle sample frequencies
1008 * outside of 4 kHZ to 50 kHZ
1009 */
1010 if (rate > 50000)
1011 rate = 50000;
1012 else if (rate < 4000)
1013 rate = 4000;
1014
1015 spin_lock_irqsave(&chip->reg_lock, flags);
1016
1017 /*
1018 * Program the AD1845 correctly for the playback stream.
1019 * Note that we do NOT need to toggle the MCE bit because
1020 * the CAPTURE_ENABLE bit of the Interface Configuration
1021 * register is set.
1022 *
1023 * NOTE: We seem to need to write to the MSB before the LSB
1024 * to get the correct sample frequency.
1025 */
1026 snd_wss_out(chip, CS4231_REC_FORMAT, (format & 0xf0));
1027 snd_wss_out(chip, AD1845_FREQ_SEL_MSB, (unsigned char) (rate >> 8));
1028 snd_wss_out(chip, AD1845_FREQ_SEL_LSB, (unsigned char) rate);
1029
1030 spin_unlock_irqrestore(&chip->reg_lock, flags);
1031}
1032
1033/*
1034 * Create an AD1845 PCM subdevice on the SoundScape. The AD1845 942 * Create an AD1845 PCM subdevice on the SoundScape. The AD1845
1035 * is very much like a CS4231, with a few extra bits. We will 943 * is very much like a CS4231, with a few extra bits. We will
1036 * try to support at least some of the extra bits by overriding 944 * try to support at least some of the extra bits by overriding
@@ -1055,11 +963,6 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1055 unsigned long flags; 963 unsigned long flags;
1056 struct snd_pcm *pcm; 964 struct snd_pcm *pcm;
1057 965
1058#define AD1845_FREQ_SEL_ENABLE 0x08
1059
1060#define AD1845_PWR_DOWN_CTRL 0x1b
1061#define AD1845_CRYS_CLOCK_SEL 0x1d
1062
1063/* 966/*
1064 * It turns out that the PLAYBACK_ENABLE bit is set 967 * It turns out that the PLAYBACK_ENABLE bit is set
1065 * by the lowlevel driver ... 968 * by the lowlevel driver ...
@@ -1074,7 +977,6 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1074 */ 977 */
1075 978
1076 if (sscape->type != SSCAPE_VIVO) { 979 if (sscape->type != SSCAPE_VIVO) {
1077 int val;
1078 /* 980 /*
1079 * The input clock frequency on the SoundScape must 981 * The input clock frequency on the SoundScape must
1080 * be 14.31818 MHz, because we must set this register 982 * be 14.31818 MHz, because we must set this register
@@ -1082,22 +984,10 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1082 */ 984 */
1083 snd_wss_mce_up(chip); 985 snd_wss_mce_up(chip);
1084 spin_lock_irqsave(&chip->reg_lock, flags); 986 spin_lock_irqsave(&chip->reg_lock, flags);
1085 snd_wss_out(chip, AD1845_CRYS_CLOCK_SEL, 0x20); 987 snd_wss_out(chip, AD1845_CLOCK, 0x20);
1086 spin_unlock_irqrestore(&chip->reg_lock, flags); 988 spin_unlock_irqrestore(&chip->reg_lock, flags);
1087 snd_wss_mce_down(chip); 989 snd_wss_mce_down(chip);
1088 990
1089 /*
1090 * More custom configuration:
1091 * a) select "mode 2" and provide a current drive of 8mA
1092 * b) enable frequency selection (for capture/playback)
1093 */
1094 spin_lock_irqsave(&chip->reg_lock, flags);
1095 snd_wss_out(chip, CS4231_MISC_INFO,
1096 CS4231_MODE2 | 0x10);
1097 val = snd_wss_in(chip, AD1845_PWR_DOWN_CTRL);
1098 snd_wss_out(chip, AD1845_PWR_DOWN_CTRL,
1099 val | AD1845_FREQ_SEL_ENABLE);
1100 spin_unlock_irqrestore(&chip->reg_lock, flags);
1101 } 991 }
1102 992
1103 err = snd_wss_pcm(chip, 0, &pcm); 993 err = snd_wss_pcm(chip, 0, &pcm);
@@ -1113,11 +1003,13 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1113 "for AD1845 chip\n"); 1003 "for AD1845 chip\n");
1114 goto _error; 1004 goto _error;
1115 } 1005 }
1116 err = snd_wss_timer(chip, 0, NULL); 1006 if (chip->hardware != WSS_HW_AD1848) {
1117 if (err < 0) { 1007 err = snd_wss_timer(chip, 0, NULL);
1118 snd_printk(KERN_ERR "sscape: No timer device " 1008 if (err < 0) {
1119 "for AD1845 chip\n"); 1009 snd_printk(KERN_ERR "sscape: No timer device "
1120 goto _error; 1010 "for AD1845 chip\n");
1011 goto _error;
1012 }
1121 } 1013 }
1122 1014
1123 if (sscape->type != SSCAPE_VIVO) { 1015 if (sscape->type != SSCAPE_VIVO) {
@@ -1128,8 +1020,6 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1128 "MIDI mixer control\n"); 1020 "MIDI mixer control\n");
1129 goto _error; 1021 goto _error;
1130 } 1022 }
1131 chip->set_playback_format = ad1845_playback_format;
1132 chip->set_capture_format = ad1845_capture_format;
1133 } 1023 }
1134 1024
1135 strcpy(card->driver, "SoundScape"); 1025 strcpy(card->driver, "SoundScape");
@@ -1157,7 +1047,6 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1157 unsigned dma_cfg; 1047 unsigned dma_cfg;
1158 unsigned irq_cfg; 1048 unsigned irq_cfg;
1159 unsigned mpu_irq_cfg; 1049 unsigned mpu_irq_cfg;
1160 unsigned xport;
1161 struct resource *io_res; 1050 struct resource *io_res;
1162 struct resource *wss_res; 1051 struct resource *wss_res;
1163 unsigned long flags; 1052 unsigned long flags;
@@ -1177,15 +1066,15 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1177 printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]); 1066 printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]);
1178 return -ENXIO; 1067 return -ENXIO;
1179 } 1068 }
1180 xport = port[dev];
1181 1069
1182 /* 1070 /*
1183 * Grab IO ports that we will need to probe so that we 1071 * Grab IO ports that we will need to probe so that we
1184 * can detect and control this hardware ... 1072 * can detect and control this hardware ...
1185 */ 1073 */
1186 io_res = request_region(xport, 8, "SoundScape"); 1074 io_res = request_region(port[dev], 8, "SoundScape");
1187 if (!io_res) { 1075 if (!io_res) {
1188 snd_printk(KERN_ERR "sscape: can't grab port 0x%x\n", xport); 1076 snd_printk(KERN_ERR
1077 "sscape: can't grab port 0x%lx\n", port[dev]);
1189 return -EBUSY; 1078 return -EBUSY;
1190 } 1079 }
1191 wss_res = NULL; 1080 wss_res = NULL;
@@ -1212,10 +1101,9 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1212 spin_lock_init(&sscape->fwlock); 1101 spin_lock_init(&sscape->fwlock);
1213 sscape->io_res = io_res; 1102 sscape->io_res = io_res;
1214 sscape->wss_res = wss_res; 1103 sscape->wss_res = wss_res;
1215 sscape->io_base = xport; 1104 sscape->io_base = port[dev];
1216 sscape->wss_base = wss_port[dev];
1217 1105
1218 if (!detect_sscape(sscape)) { 1106 if (!detect_sscape(sscape, wss_port[dev])) {
1219 printk(KERN_ERR "sscape: hardware not detected at 0x%x\n", sscape->io_base); 1107 printk(KERN_ERR "sscape: hardware not detected at 0x%x\n", sscape->io_base);
1220 err = -ENODEV; 1108 err = -ENODEV;
1221 goto _release_dma; 1109 goto _release_dma;
@@ -1288,12 +1176,11 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1288 } 1176 }
1289#define MIDI_DEVNUM 0 1177#define MIDI_DEVNUM 0
1290 if (sscape->type != SSCAPE_VIVO) { 1178 if (sscape->type != SSCAPE_VIVO) {
1291 err = create_mpu401(card, MIDI_DEVNUM, 1179 err = create_mpu401(card, MIDI_DEVNUM, port[dev], mpu_irq[dev]);
1292 MPU401_IO(xport), mpu_irq[dev]);
1293 if (err < 0) { 1180 if (err < 0) {
1294 printk(KERN_ERR "sscape: Failed to create " 1181 printk(KERN_ERR "sscape: Failed to create "
1295 "MPU-401 device at 0x%x\n", 1182 "MPU-401 device at 0x%lx\n",
1296 MPU401_IO(xport)); 1183 port[dev]);
1297 goto _release_dma; 1184 goto _release_dma;
1298 } 1185 }
1299 1186