46 #include <linux/module.h>
47 #include <linux/stddef.h>
48 #include <linux/slab.h>
89 #define MD_1845_SSCAPE 9
99 short mixer_reroute[32];
120 static int nr_ad1848_devs;
122 static bool deskpro_xl;
123 static bool deskpro_m;
124 static bool soundpro;
126 static volatile signed char irq2dev[17] = {
127 -1, -1, -1, -1, -1, -1, -1, -1,
128 -1, -1, -1, -1, -1, -1, -1, -1, -1
131 #ifndef EXCLUDE_TIMERS
132 static int timer_installed = -1;
137 static int ad_format_mask[13 ] =
156 #define io_Index_Addr(d) ((d)->base)
157 #define io_Indexed_Data(d) ((d)->base+1)
158 #define io_Status(d) ((d)->base+2)
159 #define io_Polled_IO(d) ((d)->base+3)
163 #define CAP_F_TIMER 0x01
178 static int isapnp = 1;
179 static int isapnpjump;
182 static int audio_activated;
189 static int ad1848_open(
int dev,
int mode);
190 static void ad1848_close(
int dev);
191 static void ad1848_output_block(
int dev,
unsigned long buf,
int count,
int intrflag);
192 static void ad1848_start_input(
int dev,
unsigned long buf,
int count,
int intrflag);
193 static int ad1848_prepare_for_output(
int dev,
int bsize,
int bcount);
194 static int ad1848_prepare_for_input(
int dev,
int bsize,
int bcount);
195 static void ad1848_halt(
int dev);
196 static void ad1848_halt_input(
int dev);
197 static void ad1848_halt_output(
int dev);
198 static void ad1848_trigger(
int dev,
int bits);
201 #ifndef EXCLUDE_TIMERS
202 static int ad1848_tmr_install(
int dev);
203 static void ad1848_tmr_reprogram(
int dev);
211 while (timeout > 0 &&
inb(devc->
base) == 0x80)
223 xreg = (reg & 0xff) - 32;
224 xra = (((xreg & 0x0f) << 4) & 0xf0) | 0x08 | ((xreg & 0x10) >> 2);
235 int timeout = 900000;
237 while (timeout > 0 &&
inb(devc->
base) == 0x80)
249 xreg = (reg & 0xff) - 32;
250 xra = (((xreg & 0x0f) << 4) & 0xf0) | 0x08 | ((xreg & 0x10) >> 2);
257 static void wait_for_calibration(
ad1848_info * devc)
269 while (timeout > 0 &&
inb(devc->
base) == 0x80)
275 while (timeout > 0 && !(ad_read(devc, 11) & 0x20))
277 if (!(ad_read(devc, 11) & 0x20))
281 while (timeout > 0 && (ad_read(devc, 11) & 0x20))
283 if (ad_read(devc, 11) & 0x20)
297 for (i = 6; i < 8; i++)
313 while (timeout > 0 &&
inb(devc->
base) == 0x80)
327 unsigned char prev, acal;
330 while (timeout > 0 &&
inb(devc->
base) == 0x80)
333 acal = ad_read(devc, 9);
339 if ((prev & 0x40) == 0)
345 wait_for_calibration(devc);
350 unsigned char recdev;
357 for (i = 0; i < 32; i++)
370 for (i = 0; i < 32; i++)
382 for (i = 0; i < 32; i++)
414 ad_write(devc, 0, (ad_read(devc, 0) & 0x3f) | recdev);
415 ad_write(devc, 1, (ad_read(devc, 1) & 0x3f) | recdev);
421 for (i = 0; i < 32; i++) {
434 set_rec_bit = ((mask & (1 <<
i)) != 0) ^ devc->
mix_devices[i][j].recpol;
436 val = ad_read(devc, devc->
mix_devices[i][j].recreg);
439 ad_write(devc, devc->
mix_devices[i][j].recreg, val);
443 spin_unlock_irqrestore(&devc->
lock,flags);
446 for (i = 0; i < 32; i++)
462 unsigned char *muteval,
int dev,
int chn,
int newval)
470 set_mute_bit = (newval == 0) ^ devc->
mix_devices[dev][chn].mutepol;
473 newval = 100 - newval;
489 newval = (
int) ((newval * mask) + 50) / 100;
490 *regval &= ~(mask << shift);
491 *regval |= (newval &
mask) << shift;
493 *muteval &= mutemask;
497 static int ad1848_mixer_get(
ad1848_info * devc,
int dev)
509 int regoffs, muteregoffs;
510 unsigned char val, muteval;
515 val = ad_read(devc, regoffs);
517 if (muteregoffs != regoffs) {
518 muteval = ad_read(devc, muteregoffs);
519 oss_change_bits(devc, &val, &muteval, dev, channel, value);
522 oss_change_bits(devc, &val, &val, dev, channel, value);
525 ad_write(devc, regoffs, val);
527 if (muteregoffs != regoffs) {
528 ad_write(devc, muteregoffs, muteval);
531 spin_unlock_irqrestore(&devc->
lock,flags);
534 static int ad1848_mixer_set(
ad1848_info * devc,
int dev,
int value)
536 int left = value & 0x000000ff;
537 int right = (value & 0x0000ff00) >> 8;
559 retvol = left | (right << 8);
562 left = mix_cvt[
left];
563 right = mix_cvt[
right];
570 ad1848_mixer_set_channel(devc, dev, left,
LEFT_CHN);
577 ad1848_mixer_set_channel(devc, dev, right,
RIGHT_CHN);
593 for (i = 0; i < 32; i++)
648 ad1848_mixer_set(devc, i, devc->
levels[i]);
658 ad_write(devc, 26, ad_read(devc, 26) & ~0x40);
660 ad_write(devc, 26, ad_read(devc, 26) | 0x40);
667 ad_write(devc, 16, 0x60);
669 spin_unlock_irqrestore(&devc->
lock,flags);
672 static int ad1848_mixer_ioctl(
int dev,
unsigned int cmd,
void __user *
arg)
679 if (
get_user(val, (
int __user *)arg))
691 ad_write(devc, 26, ad_read(devc, 26) & ~0x40);
693 ad_write(devc, 26, ad_read(devc, 26) | 0x40);
694 spin_unlock_irqrestore(&devc->
lock,flags);
697 return put_user(val, (
int __user *)arg);
701 if (
get_user(val, (
int __user *)arg))
705 if (((cmd >> 8) & 0xff) ==
'M')
712 if (
get_user(val, (
int __user *)arg))
714 val = ad1848_set_recmask(devc, val);
718 if (
get_user(val, (
int __user *)arg))
720 val = ad1848_mixer_set(devc, cmd & 0xff, val);
723 return put_user(val, (
int __user *)arg);
756 val = ad1848_mixer_get(devc, cmd & 0xff);
759 return put_user(val, (
int __user *)arg);
766 static int ad1848_set_speed(
int dev,
int arg)
786 static speed_struct speed_table[] =
788 {5510, (0 << 1) | 1},
789 {5510, (0 << 1) | 1},
790 {6620, (7 << 1) | 1},
791 {8000, (0 << 1) | 0},
792 {9600, (7 << 1) | 0},
793 {11025, (1 << 1) | 1},
794 {16000, (1 << 1) | 0},
795 {18900, (2 << 1) | 1},
796 {22050, (3 << 1) | 1},
797 {27420, (2 << 1) | 0},
798 {32000, (3 << 1) | 0},
799 {33075, (6 << 1) | 1},
800 {37800, (4 << 1) | 1},
801 {44100, (5 << 1) | 1},
802 {48000, (6 << 1) | 0}
805 int i,
n, selected = -1;
807 n =
sizeof(speed_table) /
sizeof(speed_struct);
823 if (arg < speed_table[0].speed)
825 if (arg > speed_table[n - 1].speed)
828 for (i = 1 ; selected == -1 && i <
n; i++)
830 if (speed_table[i].speed == arg)
832 else if (speed_table[i].speed > arg)
836 diff1 = arg - speed_table[i - 1].speed;
837 diff2 = speed_table[
i].speed -
arg;
850 portc->
speed = speed_table[selected].speed;
851 portc->
speed_bits = speed_table[selected].bits;
855 static short ad1848_set_channels(
int dev,
short arg)
859 if (arg != 1 && arg != 2)
866 static unsigned int ad1848_set_bits(
int dev,
unsigned int arg)
871 static struct format_tbl
918 int i, n =
sizeof(format2bits) /
sizeof(
struct format_tbl);
923 if (!(arg & ad_format_mask[devc->
model]))
928 for (i = 0; i <
n; i++)
929 if (format2bits[i].
format == arg)
931 if ((portc->
format_bits = format2bits[i].bits) == 0)
945 .close = ad1848_close,
946 .output_block = ad1848_output_block,
947 .start_input = ad1848_start_input,
948 .prepare_for_input = ad1848_prepare_for_input,
949 .prepare_for_output = ad1848_prepare_for_output,
950 .halt_io = ad1848_halt,
951 .halt_input = ad1848_halt_input,
952 .halt_output = ad1848_halt_output,
953 .trigger = ad1848_trigger,
954 .set_speed = ad1848_set_speed,
955 .set_bits = ad1848_set_bits,
956 .set_channels = ad1848_set_channels
963 .name =
"AD1848/CS4248/CS4231",
964 .ioctl = ad1848_mixer_ioctl
967 static int ad1848_open(
int dev,
int mode)
980 spin_lock(&devc->
lock);
983 spin_unlock(&devc->
lock);
996 spin_unlock(&devc->
lock);
997 ad1848_trigger(dev, 0);
1008 spin_unlock_irqrestore(&devc->
lock,flags);
1013 static void ad1848_close(
int dev)
1015 unsigned long flags;
1031 spin_unlock_irqrestore(&devc->
lock,flags);
1034 static void ad1848_output_block(
int dev,
unsigned long buf,
int count,
int intrflag)
1067 ad_write(devc, 15, (
unsigned char) (cnt & 0xff));
1068 ad_write(devc, 14, (
unsigned char) ((cnt >> 8) & 0xff));
1073 spin_unlock_irqrestore(&devc->
lock,flags);
1076 static void ad1848_start_input(
int dev,
unsigned long buf,
int count,
int intrflag)
1110 ad_write(devc, 15, (
unsigned char) (cnt & 0xff));
1111 ad_write(devc, 14, (
unsigned char) ((cnt >> 8) & 0xff));
1115 ad_write(devc, 31, (
unsigned char) (cnt & 0xff));
1116 ad_write(devc, 30, (
unsigned char) ((cnt >> 8) & 0xff));
1124 spin_unlock_irqrestore(&devc->
lock,flags);
1127 static int ad1848_prepare_for_output(
int dev,
int bsize,
int bcount)
1130 unsigned char fs, old_fs,
tmp = 0;
1131 unsigned long flags;
1149 ad_write(devc, 22, (portc->
speed >> 8) & 0xff);
1150 ad_write(devc, 23, portc->
speed & 0xff);
1152 old_fs = ad_read(devc, 8);
1156 tmp = ad_read(devc, 16);
1157 ad_write(devc, 16, tmp | 0x30);
1160 ad_write(devc, 17, 0xc2);
1162 ad_write(devc, 8, fs);
1169 while (timeout < 100 &&
inb(devc->
base) != 0x80)
1172 while (timeout < 10000 &&
inb(devc->
base) == 0x80)
1176 ad_write(devc, 16, tmp & ~0x30);
1181 spin_unlock_irqrestore(&devc->
lock,flags);
1184 #ifndef EXCLUDE_TIMERS
1186 if ((fs & 0x01) != (old_fs & 0x01))
1188 ad1848_tmr_reprogram(dev);
1191 ad1848_halt_output(dev);
1195 static int ad1848_prepare_for_input(
int dev,
int bsize,
int bcount)
1198 unsigned char fs, old_fs, tmp = 0;
1199 unsigned long flags;
1218 ad_write(devc, 22, (portc->
speed >> 8) & 0xff);
1219 ad_write(devc, 23, portc->
speed & 0xff);
1223 tmp = ad_read(devc, 16);
1224 ad_write(devc, 16, tmp | 0x30);
1227 ad_write(devc, 17, 0xc2);
1235 old_fs = ad_read(devc, 28);
1236 ad_write(devc, 28, fs);
1243 while (timeout < 100 &&
inb(devc->
base) != 0x80)
1247 while (timeout < 10000 &&
inb(devc->
base) == 0x80)
1257 unsigned char tmp = portc->
speed_bits | (ad_read(devc, 8) & 0xf0);
1259 ad_write(devc, 8, tmp);
1264 while (timeout < 100 &&
inb(devc->
base) != 0x80)
1268 while (timeout < 10000 &&
inb(devc->
base) == 0x80)
1275 old_fs = ad_read(devc, 8);
1276 ad_write(devc, 8, fs);
1281 while (timeout < 100 &&
inb(devc->
base) != 0x80)
1284 while (timeout < 10000 &&
inb(devc->
base) == 0x80)
1289 ad_write(devc, 16, tmp & ~0x30);
1294 spin_unlock_irqrestore(&devc->
lock,flags);
1297 #ifndef EXCLUDE_TIMERS
1300 if ((fs & 0x01) != (old_fs & 0x01))
1302 ad1848_tmr_reprogram(dev);
1306 ad1848_halt_input(dev);
1310 static void ad1848_halt(
int dev)
1315 unsigned char bits = ad_read(devc, 9);
1318 ad1848_halt_output(dev);
1320 if (bits & 0x02 && (portc->
open_mode & OPEN_READ))
1321 ad1848_halt_input(dev);
1325 static void ad1848_halt_input(
int dev)
1328 unsigned long flags;
1330 if (!(ad_read(devc, 9) & 0x02))
1343 for (tmout = 0; tmout < 100000; tmout++)
1344 if (ad_read(devc, 11) & 0x10)
1346 ad_write(devc, 9, ad_read(devc, 9) & ~0x02);
1358 spin_unlock_irqrestore(&devc->
lock,flags);
1361 static void ad1848_halt_output(
int dev)
1364 unsigned long flags;
1366 if (!(ad_read(devc, 9) & 0x01))
1378 for (tmout = 0; tmout < 100000; tmout++)
1379 if (ad_read(devc, 11) & 0x10)
1381 ad_write(devc, 9, ad_read(devc, 9) & ~0x01);
1394 spin_unlock_irqrestore(&devc->
lock,flags);
1397 static void ad1848_trigger(
int dev,
int state)
1401 unsigned long flags;
1402 unsigned char tmp, old;
1407 tmp = old = ad_read(devc, 9);
1426 ad_write(devc, 9, tmp);
1429 spin_unlock_irqrestore(&devc->
lock,flags);
1440 static int init_values_a[] =
1442 0xa8, 0xa8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1443 0x00, 0x0c, 0x02, 0x00, 0x8a, 0x01, 0x00, 0x00,
1446 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x40,
1447 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1450 static int init_values_b[] =
1462 0xa8, 0xa8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1463 0x00, 0x00, 0x06, 0x00, 0xe0, 0x01, 0x00, 0x00,
1464 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x40,
1465 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1472 init_values = init_values_a;
1474 init_values = init_values_b;
1476 for (i = 0; i < 16; i++)
1477 ad_write(devc, i, init_values[i]);
1486 ad_write(devc, 12, ad_read(devc, 12) | 0x50);
1488 ad_write(devc, 12, ad_read(devc, 12) | 0x40);
1491 ad_write(devc, 12, 0x6c);
1494 for (i = 16; i < 32; i++)
1495 ad_write(devc, i, init_values[i]);
1498 ad_write(devc, 16, 0x30);
1503 ad_write(devc, 9, ad_read(devc, 9) & ~0x04);
1505 ad_write(devc, 9, ad_read(devc, 9) | 0x04);
1508 ad_write(devc, 27, ad_read(devc, 27) | 0x08);
1512 ad_write(devc, 12, 0x6c);
1513 ad_write(devc, 16, 0x30);
1514 ad_write(devc, 17, 0xc2);
1520 ad_write(devc, 9, ad_read(devc, 9) | 0x04);
1522 ad_write(devc, 12, ad_read(devc, 12) | 0x40);
1534 ad1848_mixer_reset(devc);
1541 unsigned char tmp1 = 0xff, tmp2 = 0xff;
1544 int ad1847_flag = 0;
1545 int cs4248_flag = 0;
1546 int sscape_flag = 0;
1551 DDB(
printk(
"ad1848_detect(%x)\n", io_base));
1555 if (*ad_flags == 0x12345678)
1561 if (*ad_flags == 0x87654321)
1567 if (*ad_flags == 0x12345677)
1602 DDB(
printk(
"ad1848_detect: The base I/O address appears to be dead\n"));
1609 DDB(
printk(
"ad1848_detect() - step 0\n"));
1611 for (i = 0; i < 10000000; i++)
1613 unsigned char x =
inb(devc->
base);
1615 if (x == 0xff || !(x & 0x80))
1619 DDB(
printk(
"ad1848_detect() - step A\n"));
1624 if ((
inb(devc->
base) & 0x80) != 0x00)
1626 DDB(
printk(
"ad1848 detect error - step A (%02x)\n", (
int)
inb(devc->
base)));
1636 DDB(
printk(
"ad1848_detect() - step B\n"));
1637 ad_write(devc, 0, 0xaa);
1638 ad_write(devc, 1, 0x45);
1640 if ((tmp1 = ad_read(devc, 0)) != 0xaa || (tmp2 = ad_read(devc, 1)) != 0x45)
1646 DDB(
printk(
"ad1848 detect error - step B (%x/%x)\n", tmp1, tmp2));
1650 DDB(
printk(
"ad1848_detect() - step C\n"));
1651 ad_write(devc, 0, 0x45);
1652 ad_write(devc, 1, 0xaa);
1654 if ((tmp1 = ad_read(devc, 0)) != 0x45 || (tmp2 = ad_read(devc, 1)) != 0xaa)
1660 DDB(
printk(
"ad1848 detect error - step C (%x/%x)\n", tmp1, tmp2));
1670 DDB(
printk(
"ad1848_detect() - step D\n"));
1671 tmp = ad_read(devc, 12);
1672 ad_write(devc, 12, (~tmp) & 0x0f);
1674 if ((tmp & 0x0f) != ((tmp1 = ad_read(devc, 12)) & 0x0f))
1676 DDB(
printk(
"ad1848 detect error - step D (%x)\n", tmp1));
1699 DDB(
printk(
"ad1848_detect() - step F\n"));
1700 ad_write(devc, 12, 0);
1702 for (i = 0; i < 16; i++)
1704 if ((tmp1 = ad_read(devc, i)) != (tmp2 = ad_read(devc, i + 16)))
1706 DDB(
printk(
"ad1848 detect step F(%d/%x/%x) - OPTi chip???\n", i, tmp1, tmp2));
1718 DDB(
printk(
"ad1848_detect() - step G\n"));
1720 if (ad_flags && *ad_flags == 400)
1723 ad_write(devc, 12, 0x40);
1729 tmp1 = ad_read(devc, 12);
1737 if (optiC930 || (tmp1 & 0xc0) == (0x80 | 0x40))
1745 DDB(
printk(
"ad1848_detect() - step H\n"));
1746 ad_write(devc, 16, 0);
1748 ad_write(devc, 0, 0x45);
1749 if ((tmp1 = ad_read(devc, 16)) != 0x45)
1751 ad_write(devc, 0, 0xaa);
1752 if ((tmp1 = ad_read(devc, 16)) == 0xaa)
1754 DDB(
printk(
"ad1848 detect error - step H(%x)\n", tmp1));
1762 DDB(
printk(
"ad1848_detect() - step I\n"));
1763 tmp1 = ad_read(devc, 25);
1764 ad_write(devc, 25, ~tmp1);
1765 if ((ad_read(devc, 25) & 0xe7) == (tmp1 & 0xe7))
1782 id = ad_read(devc, 25);
1783 if ((
id & 0xe7) == 0x80)
1784 id = ad_read(devc, 25);
1785 if ((
id & 0xe7) == 0x80)
1786 id = ad_read(devc, 25);
1787 DDB(
printk(
"ad1848_detect() - step J (%02x/%02x)\n",
id, ad_read(devc, 25)));
1789 if ((
id & 0xe7) == 0x80) {
1797 unsigned char tmp = ad_read(devc, 23);
1798 ad_write(devc, 23, ~tmp);
1805 else if (ad_read(devc, 23) != tmp)
1810 else if (cs4248_flag)
1816 ad_write(devc, 12, ad_read(devc, 12) & ~0x40);
1818 ad_write(devc, 23, tmp);
1822 switch (
id & 0x1f) {
1826 ad_write(devc, 12, ad_read(devc, 12) | 0x60);
1827 ad_write(devc, 23, 0x9c);
1829 ad_write(devc, 12, ad_read(devc, 12) & ~0x60);
1862 printk(
"Chip ident is %X.\n", xid&0x1F);
1876 if ((
id & 0xe0) == 0xa0)
1889 DDB(
printk(
"ad1848: I25 = %02x/%02x\n", ad_read(devc, 25), ad_read(devc, 25) & 0xe7));
1903 ad_write(devc, 25, tmp1);
1905 DDB(
printk(
"ad1848_detect() - step K\n"));
1907 }
else if (tmp1 == 0x0a) {
1918 for (i = 0; i < 16; i++) {
1919 if ((tmp1 = ad_read(devc, i)) != (tmp2 = ad_read(devc, i + 16))) {
1920 DDB(
printk(
"ad1848 detect step H(%d/%x/%x) - SoundPro chip?\n", i, tmp1, tmp2));
1928 DDB(
printk(
"ad1848_detect() - step L\n"));
1934 DDB(
printk(
"ad1848_detect() - Detected OK\n"));
1940 if (sscape_flag == 1)
1947 int dma_capture,
int share_dma,
int *osp,
struct module *
owner)
1963 devc->
irq = (irq > 0) ? irq : 0;
1966 devc->
dma1 = dma_playback;
1967 devc->
dma2 = dma_capture;
1974 if (name !=
NULL && name[0] != 0)
1979 "Generic audio codec (%s)", devc->
chip_name);
2004 &ad1848_audio_driver,
2007 ad_format_mask[devc->
model],
2021 memset((
char *) portc, 0,
sizeof(*portc));
2025 ad1848_init_hw(devc);
2031 (
void *)(
long)my_dev) < 0)
2041 unsigned char tmp = ad_read(devc, 16);
2046 ad_write(devc, 21, 0x00);
2047 ad_write(devc, 20, 0x10);
2049 ad_write(devc, 16, tmp | 0x40);
2050 for (x = 0; x < 100000 && devc->
timer_ticks == 0; x++);
2051 ad_write(devc, 16, tmp & ~0x40);
2067 irq2dev[-irq] = devc->
dev_no = my_dev;
2069 #ifndef EXCLUDE_TIMERS
2072 ad1848_tmr_install(my_dev);
2080 if (dma_capture != dma_playback)
2087 &ad1848_mixer_operations,
2101 unsigned long flags;
2103 if (nr_ad1848_devs < 1)
2106 devc = &adev_info[nr_ad1848_devs - 1];
2115 ad_write(devc, 29, (ad_read(devc, 29) & 0x1f) | (arg << 5));
2117 spin_unlock_irqrestore(&devc->
lock,flags);
2122 int o = (arg >> 8) & 0xff;
2125 if (o < 0 || o >= SOUND_MIXER_NRDEVICES)
2134 ad1848_mixer_set(devc, o, 0);
2141 if (n < 0 || n >= SOUND_MIXER_NRDEVICES)
2160 int i, mixer, dev = 0;
2163 for (i = 0; devc ==
NULL && i < nr_ad1848_devs; i++)
2165 if (adev_info[i].
base == io_base)
2167 devc = &adev_info[
i];
2184 if (dma_playback != dma_capture)
2193 for ( ; i < nr_ad1848_devs ; i++)
2194 adev_info[i] = adev_info[i+1];
2197 printk(
KERN_ERR "ad1848: Can't find device to be unloaded. Base=%x\n", io_base);
2205 int alt_stat = 0xff;
2206 unsigned char c930_stat = 0;
2226 spin_lock(&devc->
lock);
2232 c930_stat =
inb(0xe0f);
2233 outb((~c930_stat), 0xe0f);
2235 spin_unlock(&devc->
lock);
2237 alt_stat = (c930_stat << 2) & 0x30;
2241 spin_lock(&devc->
lock);
2242 alt_stat = ad_read(devc, 24);
2243 ad_write(devc, 24, ad_read(devc, 24) & ~alt_stat);
2244 spin_unlock(&devc->
lock);
2259 #ifndef EXCLUDE_TIMERS
2273 goto interrupt_again;
2283 static int init_deskpro_m(
struct address_info *hw_config)
2287 if ((tmp =
inb(0xc44)) == 0xff)
2289 DDB(
printk(
"init_deskpro_m: Dead port 0xc44\n"));
2311 static int init_deskpro(
struct address_info *hw_config)
2315 if ((tmp =
inb(0xc44)) == 0xff)
2317 DDB(
printk(
"init_deskpro: Dead port 0xc44\n"));
2320 outb((tmp | 0x04), 0xc44);
2321 if (
inb(0xc44) != 0x04)
2323 DDB(
printk(
"init_deskpro: Invalid bank1 signature in port 0xc44\n"));
2359 printk(
"Port 0xc44 (before): ");
2360 outb((tmp & ~0x04), 0xc44);
2362 outb((tmp | 0x04), 0xc44);
2387 outb((tmp & ~0x04), 0xc44);
2391 printk(
"Port 0xc44 (after): ");
2392 outb((tmp & ~0x04), 0xc44);
2394 outb((tmp | 0x04), 0xc44);
2410 printk(
"Port 0xc45 (before): ");
2411 outb((tmp & ~0x04), 0xc44);
2413 outb((tmp | 0x04), 0xc44);
2417 outb((tmp & ~0x04), 0xc44);
2418 outb((0x88), 0xc45);
2419 outb((tmp | 0x04), 0xc44);
2420 outb((0x10), 0xc45);
2424 printk(
"Port 0xc45 (after): ");
2425 outb((tmp & ~0x04), 0xc44);
2427 outb((tmp | 0x04), 0xc44);
2441 printk(
"Port 0xc46 (before): ");
2442 outb((tmp & ~0x04), 0xc44);
2444 outb((tmp | 0x04), 0xc44);
2448 outb((tmp & ~0x04), 0xc44);
2449 outb((0x03), 0xc46);
2450 outb((tmp | 0x04), 0xc44);
2451 outb((0x11), 0xc46);
2455 printk(
"Port 0xc46 (after): ");
2456 outb((tmp & ~0x04), 0xc44);
2458 outb((tmp | 0x04), 0xc44);
2471 printk(
"Port 0xc47 (before): ");
2472 outb((tmp & ~0x04), 0xc44);
2474 outb((tmp | 0x04), 0xc44);
2478 outb((tmp & ~0x04), 0xc44);
2479 outb((0x7c), 0xc47);
2480 outb((tmp | 0x04), 0xc44);
2481 outb((0x00), 0xc47);
2485 printk(
"Port 0xc47 (after): ");
2486 outb((tmp & ~0x04), 0xc44);
2488 outb((tmp | 0x04), 0xc44);
2497 printk(
"Port 0xc6f (before) = %02x\n",
inb(0xc6f));
2500 outb((0x80), 0xc6f);
2503 printk(
"Port 0xc6f (after) = %02x\n",
inb(0xc6f));
2523 if (!init_deskpro(hw_config))
2529 if (!init_deskpro_m(hw_config))
2539 if ((tmp =
inb(hw_config->
io_base + 3)) == 0xff)
2543 DDB(
printk(
"I/O address is inactive (%x)\n", tmp));
2548 DDB(
printk(
"MSS signature = %x\n", tmp & 0x3f));
2549 if ((tmp & 0x3f) != 0x04 &&
2550 (tmp & 0x3f) != 0x0f &&
2551 (tmp & 0x3f) != 0x00)
2556 DDB(
printk(
"Trying to detect codec anyway but IRQ/DMA may not work\n"));
2563 if ((hw_config->
irq != 5) &&
2564 (hw_config->
irq != 7) &&
2565 (hw_config->
irq != 9) &&
2566 (hw_config->
irq != 10) &&
2567 (hw_config->
irq != 11) &&
2568 (hw_config->
irq != 12))
2573 if (hw_config->
dma != 0 && hw_config->
dma != 1 && hw_config->
dma != 3)
2582 if (hw_config->
dma == 0 &&
inb(hw_config->
io_base + 3) & 0x80)
2587 if (hw_config->
irq > 7 && hw_config->
irq != 9 &&
inb(hw_config->
io_base + 3) & 0x80)
2589 printk(
KERN_ERR "MSS: Can't use IRQ%d with a 8 bit card/slot\n", hw_config->
irq);
2597 static signed char interrupt_bits[12] =
2599 -1, -1, -1, -1, -1, 0x00, -1, 0x08, -1, 0x10, 0x18, 0x20
2604 static char dma_bits[4] =
2609 int config_port = hw_config->
io_base + 0;
2610 int version_port = hw_config->
io_base + 3;
2611 int dma = hw_config->
dma;
2612 int dma2 = hw_config->
dma2;
2628 bits = interrupt_bits[hw_config->
irq];
2636 outb((bits | 0x40), config_port);
2637 if ((
inb(version_port) & 0x40) == 0)
2644 if (dma2 != -1 && dma2 != dma)
2646 if (!((dma == 0 && dma2 == 1) ||
2647 (dma == 1 && dma2 == 0) ||
2648 (dma == 3 && dma2 == 0)))
2655 if ((dma == 0 && dma2 == 1) ||
2656 (dma == 1 && dma2 == 0) ||
2657 (dma == 3 && dma2 == 0))
2673 hw_config->
dma2 = dma2;
2675 outb((bits | dma_bits[dma] | dma2_bit), config_port);
2689 hw_config->
dma2, 0);
2694 #ifndef EXCLUDE_TIMERS
2700 static unsigned int current_interval;
2702 static unsigned int ad1848_tmr_start(
int dev,
unsigned int usecs)
2704 unsigned long flags;
2706 unsigned long xtal_nsecs;
2707 unsigned long divider;
2724 else if (ad_read(devc, 8) & 0x01)
2729 divider = (usecs * 1000 + xtal_nsecs / 2) / xtal_nsecs;
2734 if (divider > 65535)
2737 ad_write(devc, 21, (divider >> 8) & 0xff);
2738 ad_write(devc, 20, divider & 0xff);
2739 ad_write(devc, 16, ad_read(devc, 16) | 0x40);
2741 spin_unlock_irqrestore(&devc->
lock,flags);
2743 return current_interval = (divider * xtal_nsecs + 500) / 1000;
2746 static void ad1848_tmr_reprogram(
int dev)
2753 ad1848_tmr_start(dev, current_interval);
2757 static void ad1848_tmr_disable(
int dev)
2759 unsigned long flags;
2763 ad_write(devc, 16, ad_read(devc, 16) & ~0x40);
2765 spin_unlock_irqrestore(&devc->
lock,flags);
2768 static void ad1848_tmr_restart(
int dev)
2770 unsigned long flags;
2773 if (current_interval == 0)
2777 ad_write(devc, 16, ad_read(devc, 16) | 0x40);
2779 spin_unlock_irqrestore(&devc->
lock,flags);
2791 static int ad1848_tmr_install(
int dev)
2793 if (timer_installed != -1)
2796 timer_installed = ad1848_tmr.
dev =
dev;
2830 MODULE_PARM_DESC(isapnp,
"When set to 0, Plug & Play support will be disabled");
2831 MODULE_PARM_DESC(isapnpjump,
"Jumps to a specific slot in the driver's PnP table. Use the source, Luke.");
2832 MODULE_PARM_DESC(reverse,
"When set to 1, will reverse ISAPnP search order");
2839 unsigned short card_vendor, card_device,
2841 short mss_io, irq,
dma, dma2;
2844 {
"CMI 8330 SoundPRO",
2848 {
"CS4232 based card",
2852 {
"CS4232 based card",
2856 {
"OPL3-SA2 WSS mode",
2860 {
"Advanced Gravis InterWave Audio",
2885 static struct pnp_dev *activate_dev(
char *devname,
char *resname,
struct pnp_dev *dev)
2894 printk(
KERN_ERR "ad1848: %s %s config failed (out of resources?)[%d]\n", devname, resname, err);
2900 audio_activated = 1;
2909 if((ad1848_dev =
pnp_find_dev(bus, ad1848_isapnp_list[slot].
vendor, ad1848_isapnp_list[slot].
function,
NULL)))
2911 if((ad1848_dev = activate_dev(ad1848_isapnp_list[slot].name,
"ad1848", ad1848_dev)))
2913 hw_config->
io_base = pnp_port_start(ad1848_dev, ad1848_isapnp_list[slot].mss_io);
2914 hw_config->
irq =
pnp_irq(ad1848_dev, ad1848_isapnp_list[slot].irq);
2915 hw_config->
dma =
pnp_dma(ad1848_dev, ad1848_isapnp_list[slot].dma);
2916 if(ad1848_isapnp_list[slot].dma2 != -1)
2917 hw_config->
dma2 =
pnp_dma(ad1848_dev, ad1848_isapnp_list[slot].dma2);
2919 hw_config->
dma2 = -1;
2931 char *busname = bus->
name[0] ? bus->
name : ad1848_isapnp_list[
slot].name;
2935 if(ad1848_init_generic(bus, hw_config, slot)) {
2949 static int first = 1;
2953 for (i = 0; ad1848_isapnp_list[
i].card_vendor != 0; i++);
2957 if( isapnpjump < 0 || isapnpjump > i) {
2958 isapnpjump = reverse ? i : 0;
2959 printk(
KERN_ERR "ad1848: Valid range for isapnpjump is 0-%d. Adjusted to %d.\n", i, isapnpjump);
2962 if(!first || !reverse)
2965 while(ad1848_isapnp_list[i].card_vendor != 0) {
2969 ad1848_isapnp_list[i].card_vendor,
2970 ad1848_isapnp_list[i].card_device,
2973 if(ad1848_isapnp_init(hw_config, bus, i)) {
2978 i += reverse ? -1 : 1;
2986 static int __init init_ad1848(
void)
2988 printk(
KERN_INFO "ad1848/cs4248 codec driver Copyright (C) by Hannu Savolainen 1993-1996\n");
2991 if(isapnp && (ad1848_isapnp_probe(&
cfg) < 0) ) {
3001 if(irq == -1 || dma == -1) {
3034 static void __exit cleanup_ad1848(
void)
3051 static int __init setup_ad1848(
char *
str)
3067 __setup(
"ad1848=", setup_ad1848);