31 #include <linux/module.h>
42 #define SNDRV_LEGACY_FIND_FREE_IOPORT
43 #define SNDRV_LEGACY_FIND_FREE_IRQ
44 #define SNDRV_LEGACY_FIND_FREE_DMA
56 "{OPTi,82C925 (CS4231)}}");
60 "{OPTi,82C925 (AD1848)},"
69 static bool isapnp =
true;
77 #if defined(CS4231) || defined(OPTi93X)
89 MODULE_PARM_DESC(isapnp,
"Enable ISA PnP detection for specified soundcard.");
103 #if defined(CS4231) || defined(OPTi93X)
108 #define OPTi9XX_HW_82C928 1
109 #define OPTi9XX_HW_82C929 2
110 #define OPTi9XX_HW_82C924 3
111 #define OPTi9XX_HW_82C925 4
112 #define OPTi9XX_HW_82C930 5
113 #define OPTi9XX_HW_82C931 6
114 #define OPTi9XX_HW_82C933 7
115 #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
117 #define OPTi9XX_MC_REG(n) n
121 #define OPTi93X_STATUS 0x02
122 #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r)
124 #define OPTi93X_IRQ_PLAYBACK 0x04
125 #define OPTi93X_IRQ_CAPTURE 0x08
138 unsigned long mc_indir_index;
150 static int snd_opti9xx_pnp_is_probed;
158 .devs = { {
"OPT0000" }, {
"OPT0002" }, {
"OPT0005" } },
159 .driver_data = 0x0924 },
162 .devs = { {
"OPT9250" }, {
"OPT0002" }, {
"OPT0005" } },
163 .driver_data = 0x0925 },
166 { .id =
"OPT0931", .devs = { {
"OPT9310" }, {
"OPT0002" } },
167 .driver_data = 0x0931 },
177 #define DEV_NAME "opti93x"
179 #define DEV_NAME "opti92x"
182 static char * snd_opti9xx_names[] = {
186 "82C930",
"82C931",
"82C933"
192 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
195 strcpy(chip->
name, snd_opti9xx_names[hardware]);
235 if (!chip->mc_indir_index)
236 chip->mc_indir_index = 0xe0e;
249 static unsigned char snd_opti9xx_read(
struct snd_opti9xx *chip,
253 unsigned char retval = 0xff;
278 outb(reg, chip->mc_indir_index);
280 retval =
inb(chip->mc_indir_index + 1);
288 spin_unlock_irqrestore(&chip->
lock, flags);
292 static void snd_opti9xx_write(
struct snd_opti9xx *chip,
unsigned char reg,
320 outb(reg, chip->mc_indir_index);
322 outb(value, chip->mc_indir_index + 1);
330 spin_unlock_irqrestore(&chip->
lock, flags);
334 #define snd_opti9xx_write_mask(chip, reg, value, mask) \
335 snd_opti9xx_write(chip, reg, \
336 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
339 static int snd_opti9xx_configure(
struct snd_opti9xx *chip,
341 int irq,
int dma1,
int dma2,
342 long mpu_port,
int mpu_irq)
344 unsigned char wss_base_bits;
345 unsigned char irq_bits;
346 unsigned char dma_bits;
347 unsigned char mpu_port_bits = 0;
348 unsigned char mpu_irq_bits;
420 switch (port & 0x3ff) {
423 wss_base_bits = 0x00;
427 wss_base_bits = 0x03;
431 wss_base_bits = 0x01;
435 wss_base_bits = 0x02;
464 goto __skip_resources;
479 goto __skip_resources;
482 #if defined(CS4231) || defined(OPTi93X)
494 goto __skip_resources;
502 snd_opti9xx_write(chip,
OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
512 mpu_port_bits = 0x03;
515 mpu_port_bits = 0x02;
518 mpu_port_bits = 0x01;
521 mpu_port_bits = 0x00;
525 "MPU-401 port 0x%lx not valid\n", mpu_port);
549 (mpu_port <= 0) ? 0x00 :
550 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
569 db_scale_5bit_3db_step),
575 db_scale_4bit_12db_max),
580 db_scale_4bit_12db_max),
585 db_scale_4bit_12db_max),
588 db_scale_4bit_12db_max),
593 db_scale_4bit_12db_max),
635 for (idx = 0; idx <
ARRAY_SIZE(snd_opti93x_controls); idx++) {
688 if (chip->res_mc_indir ==
NULL)
693 outb(((chip->mc_indir_index & 0x1f0) >> 4), chip->
mc_base);
694 spin_unlock_irqrestore(&chip->
lock, flags);
702 chip->res_mc_indir =
NULL;
720 err = snd_opti9xx_init(chip, i);
724 err = snd_opti9xx_read_check(chip);
728 chip->mc_indir_index = 0;
757 port = pnp_port_start(pdev, 0) - 4;
758 fm_port = pnp_port_start(pdev, 1) + 8;
761 chip->mc_indir_index = (pnp_port_start(pdev, 3) & ~0xf) | 0
xe;
773 port = pnp_port_start(pdev, 1);
774 fm_port = pnp_port_start(pdev, 2) + 8;
779 chip->
mc_base = pnp_port_start(devmc, 0) - 1;
784 #if defined(CS4231) || defined(OPTi93X)
790 if (devmpu && mpu_port > 0) {
796 mpu_port = pnp_port_start(devmpu, 0);
804 static void snd_card_opti9xx_free(
struct snd_card *card)
822 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
834 #if defined(CS4231) || defined(OPTi93X)
841 port = snd_legacy_find_free_ioport(possible_ports, 4);
847 error = snd_opti9xx_configure(chip,
port, irq, dma1, xdma2,
869 error = snd_opti93x_mixer(codec);
889 #if defined(CS4231) || defined(OPTi93X)
892 chip->
wss_base + 4, irq, dma1, xdma2);
902 mpu_port, 0, mpu_irq, &rmidi);
919 2, &opl3, &opl4) < 0) {
941 static int snd_opti9xx_card_new(
struct snd_card **cardp)
959 if (snd_opti9xx_pnp_is_probed)
972 static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
974 static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
976 static int possible_irqs[] = {9, 10, 11, 7, -1};
978 static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
979 static int possible_dma1s[] = {3, 1, 0, -1};
980 #if defined(CS4231) || defined(OPTi93X)
981 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
985 if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
991 if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
997 if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
1003 if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
1008 #if defined(CS4231) || defined(OPTi93X)
1010 if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) {
1017 error = snd_opti9xx_card_new(&card);
1021 if ((error = snd_card_opti9xx_detect(card, card->
private_data)) < 0) {
1026 if ((error = snd_opti9xx_probe(card)) < 0) {
1043 static int snd_opti9xx_suspend(
struct snd_card *card)
1052 static int snd_opti9xx_resume(
struct snd_card *card)
1056 #if defined(CS4231) || defined(OPTi93X)
1062 error = snd_opti9xx_configure(chip,
port, irq, dma1, xdma2,
1071 static int snd_opti9xx_isa_suspend(
struct device *dev,
unsigned int n,
1077 static int snd_opti9xx_isa_resume(
struct device *dev,
unsigned int n)
1083 static struct isa_driver snd_opti9xx_driver = {
1084 .match = snd_opti9xx_isa_match,
1085 .probe = snd_opti9xx_isa_probe,
1088 .suspend = snd_opti9xx_isa_suspend,
1089 .resume = snd_opti9xx_isa_resume,
1104 if (snd_opti9xx_pnp_is_probed)
1108 error = snd_opti9xx_card_new(&card);
1113 hw = snd_card_opti9xx_pnp(chip, pcard, pid);
1129 if ((error = snd_opti9xx_init(chip, hw))) {
1133 error = snd_opti9xx_read_check(chip);
1140 if ((error = snd_opti9xx_probe(card)) < 0) {
1144 pnp_set_card_drvdata(pcard, card);
1145 snd_opti9xx_pnp_is_probed = 1;
1152 pnp_set_card_drvdata(pcard,
NULL);
1153 snd_opti9xx_pnp_is_probed = 0;
1157 static int snd_opti9xx_pnp_suspend(
struct pnp_card_link *pcard,
1160 return snd_opti9xx_suspend(pnp_get_card_drvdata(pcard));
1163 static int snd_opti9xx_pnp_resume(
struct pnp_card_link *pcard)
1165 return snd_opti9xx_resume(pnp_get_card_drvdata(pcard));
1172 .id_table = snd_opti9xx_pnpids,
1173 .probe = snd_opti9xx_pnp_probe,
1176 .suspend = snd_opti9xx_pnp_suspend,
1177 .resume = snd_opti9xx_pnp_resume,
1183 #define CHIP_NAME "82C93x"
1185 #define CHIP_NAME "82C92x"
1188 static int __init alsa_card_opti9xx_init(
void)
1192 if (snd_opti9xx_pnp_is_probed)
1199 static void __exit alsa_card_opti9xx_exit(
void)
1201 if (!snd_opti9xx_pnp_is_probed) {