31 #include <linux/module.h>
87 static int isa_registered;
88 static int pnp_registered;
91 { .
id =
"ENS3081", .devs = { {
"ENS0000" } } },
92 { .id =
"ENS4081", .devs = { {
"ENS1011" } } },
100 #define HOST_CTRL_IO(i) ((i) + 2)
101 #define HOST_DATA_IO(i) ((i) + 3)
102 #define ODIE_ADDR_IO(i) ((i) + 4)
103 #define ODIE_DATA_IO(i) ((i) + 5)
104 #define CODEC_IO(i) ((i) + 8)
109 #define RX_READY 0x01
110 #define TX_READY 0x02
113 #define CMD_SET_MIDI_VOL 0x84
114 #define CMD_GET_MIDI_VOL 0x85
115 #define CMD_XXX_MIDI_VOL 0x86
116 #define CMD_SET_EXTMIDI 0x8a
117 #define CMD_GET_EXTMIDI 0x8b
118 #define CMD_SET_MT32 0x8c
119 #define CMD_GET_MT32 0x8d
134 #define DMA_8BIT 0x80
156 #define INVALID_IRQ ((unsigned)-1)
177 "%lu bytes for DMA\n",
191 if (buf && buf->
area)
217 sscape_write_unsafe(s->
io_base, reg, val);
218 spin_unlock_irqrestore(&s->
lock, flags);
225 static inline unsigned char sscape_read_unsafe(
unsigned io_base,
235 static inline void set_host_mode_unsafe(
unsigned io_base)
243 static inline void set_midi_mode_unsafe(
unsigned io_base)
252 static inline int host_read_unsafe(
unsigned io_base)
266 static int host_read_ctrl_unsafe(
unsigned io_base,
unsigned timeout)
270 while (((data = host_read_unsafe(io_base)) < 0) && (timeout != 0)) {
282 static inline int host_write_unsafe(
unsigned io_base,
unsigned char data)
297 static int host_write_ctrl_unsafe(
unsigned io_base,
unsigned char data,
302 while (!(err = host_write_unsafe(io_base, data)) && (timeout != 0)) {
317 static inline int verify_mpu401(
const struct snd_mpu401 *mpu)
325 static inline void initialise_mpu401(
const struct snd_mpu401 *mpu)
335 static void activate_ad1845_unsafe(
unsigned io_base)
337 unsigned char val = sscape_read_unsafe(io_base,
GA_HMCTL_REG);
338 sscape_write_unsafe(io_base,
GA_HMCTL_REG, (val & 0xcf) | 0x10);
345 static void soundscape_free(
struct snd_card *
c)
347 struct soundscape *sscape = get_card_soundscape(c);
357 static void sscape_start_dma_unsafe(
unsigned io_base,
enum GA_REG reg)
359 sscape_write_unsafe(io_base, reg,
360 sscape_read_unsafe(io_base, reg) | 0x01);
361 sscape_write_unsafe(io_base, reg,
362 sscape_read_unsafe(io_base, reg) & 0xfe);
369 static int sscape_wait_dma_unsafe(
unsigned io_base,
enum GA_REG reg,
372 while (!(sscape_read_unsafe(io_base, reg) & 0x01) && (timeout != 0)) {
377 return sscape_read_unsafe(io_base, reg) & 0x01;
387 static int obp_startup_ack(
struct soundscape *
s,
unsigned timeout)
396 x = host_read_unsafe(s->
io_base);
397 spin_unlock_irqrestore(&s->
lock, flags);
398 if (x == 0xfe || x == 0xff)
414 static int host_startup_ack(
struct soundscape *s,
unsigned timeout)
423 x = host_read_unsafe(s->
io_base);
424 spin_unlock_irqrestore(&s->
lock, flags);
437 static int upload_dma_data(
struct soundscape *s,
const unsigned char *data,
476 len =
min(size,
dma.bytes);
487 spin_unlock_irqrestore(&s->
lock, flags);
490 "sscape: DMA upload has timed out\n");
496 set_host_mode_unsafe(s->
io_base);
504 spin_unlock_irqrestore(&s->
lock, flags);
512 if (!obp_startup_ack(s, 5000)) {
514 "from on-board processor after upload\n");
516 }
else if (!host_startup_ack(s, 5000)) {
518 "sscape: SoundScape failed to initialise\n");
537 static int sscape_upload_bootblock(
struct snd_card *
card)
539 struct soundscape *sscape = get_card_soundscape(card);
550 ret = upload_dma_data(sscape, init_fw->
data, init_fw->
size);
556 data = host_read_ctrl_unsafe(sscape->
io_base, 100);
561 spin_unlock_irqrestore(&sscape->
lock, flags);
564 if (ret == 0 && data > 7) {
566 "sscape: timeout reading firmware version\n");
570 return (ret == 0) ? data :
ret;
578 struct soundscape *sscape = get_card_soundscape(card);
583 snprintf(name,
sizeof(name),
"sndscape.co%d", version);
591 err = upload_dma_data(sscape, init_fw->
data, init_fw->
size);
594 init_fw->
size >> 10);
619 register struct soundscape *s = get_card_soundscape(card);
624 spin_unlock_irqrestore(&s->
lock, flags);
633 struct soundscape *s = get_card_soundscape(card);
636 unsigned char new_val;
640 new_val = uctl->
value.integer.value[0] & 127;
645 set_host_mode_unsafe(s->
io_base);
658 && host_write_ctrl_unsafe(s->
io_base, new_val, 100)
660 && host_write_ctrl_unsafe(s->
io_base, new_val, 100);
667 set_midi_mode_unsafe(s->
io_base);
669 spin_unlock_irqrestore(&s->
lock, flags);
676 .info = sscape_midi_info,
677 .get = sscape_midi_get,
678 .put = sscape_midi_put
686 static unsigned __devinit get_irq_config(
int sscape_type,
int irq)
688 static const int valid_irq[] = { 9, 5, 7, 10 };
689 static const int old_irq[] = { 9, 7, 5, 15 };
694 if (irq == old_irq[cfg])
698 if (irq == valid_irq[cfg])
731 else if ((d & 0x60) != 0)
750 activate_ad1845_unsafe(s->
io_base);
759 for (d = 0; d < 500; d++) {
760 if ((
inb(wss_io) & 0x80) == 0)
762 spin_unlock_irqrestore(&s->
lock, flags);
767 if ((
inb(wss_io) & 0x80) != 0)
770 if (
inb(wss_io + 2) == 0xff)
776 if ((
inb(wss_io) & 0x80) != 0)
782 for (d = 0; d < 500; d++) {
783 if ((
inb(wss_io) & 0x80) == 0)
785 spin_unlock_irqrestore(&s->
lock, flags);
796 spin_unlock_irqrestore(&s->
lock, flags);
806 static int mpu401_open(
struct snd_mpu401 *mpu)
808 if (!verify_mpu401(mpu)) {
810 "please load firmware\n");
821 unsigned long port,
int irq)
823 struct soundscape *sscape = get_card_soundscape(card);
835 initialise_mpu401(mpu);
849 int irq,
int dma1,
int dma2)
851 register struct soundscape *sscape = get_card_soundscape(card);
856 switch (sscape->
type) {
891 spin_unlock_irqrestore(&chip->
reg_lock, flags);
899 "for AD1845 chip\n");
906 "for AD1845 chip\n");
913 "for AD1845 chip\n");
923 "MIDI mixer control\n");
942 struct soundscape *sscape = get_card_soundscape(card);
945 unsigned mpu_irq_cfg;
960 "sscape: can't grab port 0x%lx\n", port[dev]);
970 goto _release_region;
980 goto _release_region;
988 if (!detect_sscape(sscape, wss_port[dev])) {
995 switch (sscape->
type) {
997 name =
"MediaFX/SoundFX";
1000 name =
"Soundscape";
1003 name =
"Soundscape PnP";
1006 name =
"Soundscape VIVO";
1009 name =
"unknown Soundscape";
1013 printk(
KERN_INFO "sscape: %s card detected at 0x%x, using IRQ %d, DMA %d\n",
1019 irq_cfg = get_irq_config(sscape->
type, irq[dev]);
1026 mpu_irq_cfg = get_irq_config(sscape->
type, mpu_irq[dev]);
1050 mpu_irq_cfg |= mpu_irq_cfg << 2;
1056 sscape_write_unsafe(sscape->
io_base,
1058 | (
dma[dev] << 4) | (irq_cfg << 1));
1064 spin_unlock_irqrestore(&sscape->
lock, flags);
1070 err = create_ad1845(card, wss_port[dev], irq[dev],
1071 dma[dev], dma2[dev]);
1074 "sscape: No AD1845 device at 0x%lx, IRQ %d\n",
1075 wss_port[dev], irq[dev]);
1081 "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n",
1082 name, sscape->
chip->port, sscape->
chip->irq,
1083 sscape->
chip->dma1, sscape->
chip->dma2);
1085 #define MIDI_DEVNUM 0
1087 err = sscape_upload_bootblock(card);
1089 err = sscape_upload_microcode(card, err);
1092 err = create_mpu401(card, MIDI_DEVNUM, port[dev],
1096 "MPU-401 device at 0x%lx\n",
1106 host_write_ctrl_unsafe(sscape->
io_base,
1108 host_write_ctrl_unsafe(sscape->
io_base,
1110 host_write_ctrl_unsafe(sscape->
io_base,
1112 host_write_ctrl_unsafe(sscape->
io_base,
1114 host_write_ctrl_unsafe(sscape->
io_base,
1116 host_write_ctrl_unsafe(sscape->
io_base,
1120 set_midi_mode_unsafe(sscape->
io_base);
1121 spin_unlock_irqrestore(&sscape->
lock, flags);
1158 "sscape: insufficient parameters, "
1159 "need IO, IRQ, MPU-IRQ and DMA\n");
1166 static int __devinit snd_sscape_probe(
struct device *pdev,
unsigned int dev)
1177 sscape = get_card_soundscape(card);
1183 ret = create_sscape(dev, card);
1200 static int __devexit snd_sscape_remove(
struct device *devptr,
unsigned int dev)
1207 #define DEV_NAME "sscape"
1209 static struct isa_driver snd_sscape_driver = {
1210 .match = snd_sscape_match,
1211 .probe = snd_sscape_probe,
1220 static inline int __devinit get_next_autoindex(
int i)
1241 idx = get_next_autoindex(idx);
1268 sscape = get_card_soundscape(card);
1281 port[
idx] = pnp_port_start(dev, 0);
1289 wss_port[
idx] = pnp_port_start(dev, 1);
1294 ret = create_sscape(idx, card);
1304 pnp_set_card_drvdata(pcard, card);
1316 pnp_set_card_drvdata(pcard,
NULL);
1322 .id_table = sscape_pnpids,
1323 .probe = sscape_pnp_detect,
1329 static int __init sscape_init(
void)
1348 static void __exit sscape_exit(
void)