31 #include <linux/module.h>
40 #define SNDRV_LEGACY_FIND_FREE_IOPORT
41 #define SNDRV_LEGACY_FIND_FREE_IRQ
42 #define SNDRV_LEGACY_FIND_FREE_DMA
50 "{Miro,miroSOUND PCM12}, "
51 "{Miro,miroSOUND PCM20 Radio}}");
65 static bool isapnp = 1;
92 MODULE_PARM_DESC(isapnp,
"Enable ISA PnP detection for specified soundcard.");
95 #define OPTi9XX_HW_DETECT 0
96 #define OPTi9XX_HW_82C928 1
97 #define OPTi9XX_HW_82C929 2
98 #define OPTi9XX_HW_82C924 3
99 #define OPTi9XX_HW_82C925 4
100 #define OPTi9XX_HW_82C930 5
101 #define OPTi9XX_HW_82C931 6
102 #define OPTi9XX_HW_82C933 7
103 #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
105 #define OPTi9XX_MC_REG(n) n
135 static char * snd_opti9xx_names[] = {
139 "82C930",
"82C931",
"82C933"
142 static int snd_miro_pnp_is_probed;
149 .devs = { {
"MIR0000" }, {
"MIR0002" }, {
"MIR0005" } }, },
166 for (timeout = 1; timeout <=
ACI_MINTIME + 30; timeout++) {
168 if ((byte & 1) == 0) {
194 static inline int aci_write(
struct snd_miro_aci *aci,
unsigned char byte)
196 if (aci_busy_wait(aci) >= 0) {
209 if (aci_busy_wait(aci) >= 0) {
220 int write[] = {write1, write2, write3};
226 for (i=0; i<3; i++) {
227 if (write[i]< 0 || write[i] > 255)
230 value = aci_write(aci, write[i]);
236 value = aci_read(aci);
256 if (aci_device.aci_port == 0)
266 #define snd_miro_info_capture snd_ctl_boolean_mono_info
268 static int snd_miro_get_capture(
struct snd_kcontrol *kcontrol,
281 ucontrol->
value.integer.value[0] = value & 0x20;
286 static int snd_miro_put_capture(
struct snd_kcontrol *kcontrol,
292 value = !(ucontrol->
value.integer.value[0]);
301 change = (value != miro->
aci->aci_solomode);
307 static int snd_miro_info_preamp(
struct snd_kcontrol *kcontrol,
318 static int snd_miro_get_preamp(
struct snd_kcontrol *kcontrol,
324 if (miro->
aci->aci_version <= 176) {
332 ucontrol->
value.integer.value[0] = miro->
aci->aci_preamp;
348 static int snd_miro_put_preamp(
struct snd_kcontrol *kcontrol,
354 value = ucontrol->
value.integer.value[0];
363 change = (value != miro->
aci->aci_preamp);
369 #define snd_miro_info_amp snd_ctl_boolean_mono_info
371 static int snd_miro_get_amp(
struct snd_kcontrol *kcontrol,
375 ucontrol->
value.integer.value[0] = miro->
aci->aci_amp;
380 static int snd_miro_put_amp(
struct snd_kcontrol *kcontrol,
386 value = ucontrol->
value.integer.value[0];
394 change = (value != miro->
aci->aci_amp);
400 #define MIRO_DOUBLE(ctl_name, ctl_index, get_right_reg, set_right_reg) \
401 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
403 .index = ctl_index, \
404 .info = snd_miro_info_double, \
405 .get = snd_miro_get_double, \
406 .put = snd_miro_put_double, \
407 .private_value = get_right_reg | (set_right_reg << 8) \
410 static int snd_miro_info_double(
struct snd_kcontrol *kcontrol,
435 static int snd_miro_get_double(
struct snd_kcontrol *kcontrol,
439 int left_val, right_val;
442 int left_reg = right_reg + 1;
444 right_val = aci_getvalue(miro->
aci, right_reg);
450 left_val = aci_getvalue(miro->
aci, left_reg);
460 if (left_val < 0x80) {
461 uinfo->
value.integer.value[0] = left_val;
463 uinfo->
value.integer.value[0] = 0x80 - left_val;
466 if (right_val < 0x80) {
467 uinfo->
value.integer.value[1] = right_val;
469 uinfo->
value.integer.value[1] = 0x80 - right_val;
476 uinfo->
value.integer.value[0] = 0x20 - left_val;
477 uinfo->
value.integer.value[1] = 0x20 - right_val;
483 static int snd_miro_put_double(
struct snd_kcontrol *kcontrol,
489 int setreg_left, setreg_right, getreg_left, getreg_right;
492 left = ucontrol->
value.integer.value[0];
493 right = ucontrol->
value.integer.value[1];
496 setreg_left = setreg_right + 8;
501 getreg_left = getreg_right + 1;
503 left_old = aci_getvalue(aci, getreg_left);
509 right_old = aci_getvalue(aci, getreg_right);
519 if (left < -0x7f || left > 0x7f ||
520 right < -0x7f || right > 0x7f)
524 left_old = 0x80 - left_old;
525 if (right_old > 0x80)
526 right_old = 0x80 - right_old;
529 error = aci_setvalue(aci, setreg_left, left);
536 error = aci_setvalue(aci, setreg_left, 0x80 - left);
545 error = aci_setvalue(aci, setreg_right, right);
552 error = aci_setvalue(aci, setreg_right, 0x80 - right);
555 0x80 - right, error);
564 if (left < 0 || left > 0x20 ||
565 right < 0 || right > 0x20)
568 left_old = 0x20 - left_old;
569 right_old = 0x20 - right_old;
571 error = aci_setvalue(aci, setreg_left, 0x20 - left);
577 error = aci_setvalue(aci, setreg_right, 0x20 - right);
580 0x20 - right, error);
585 change = (left != left_old) || (right != right_old);
625 .info = snd_miro_info_preamp,
626 .get = snd_miro_get_preamp,
627 .put = snd_miro_put_preamp,
633 .name =
"Line Boost",
636 .get = snd_miro_get_amp,
637 .put = snd_miro_put_amp,
643 .name =
"PCM Capture Switch",
646 .get = snd_miro_get_capture,
647 .put = snd_miro_put_capture,
650 static unsigned char aci_init_values[][2] __devinitdata = {
700 for (idx = 0; idx <
ARRAY_SIZE(aci_init_values); idx++) {
701 error = aci_setvalue(aci, aci_init_values[idx][0],
702 aci_init_values[idx][1]);
705 aci_init_values[idx][0], error);
737 for (idx = 0; idx <
ARRAY_SIZE(snd_miro_controls); idx++) {
742 if ((miro->
aci->aci_product ==
'A') ||
743 (miro->
aci->aci_product ==
'B')) {
751 if ((miro->
aci->aci_product ==
'B') ||
752 (miro->
aci->aci_product ==
'C')) {
756 if (miro->
aci->aci_version >= 176)
761 if (miro->
aci->aci_product ==
'C') {
765 for (idx = 0; idx <
ARRAY_SIZE(snd_miro_eq_controls); idx++) {
777 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
780 strcpy(chip->
name, snd_opti9xx_names[hardware]);
820 static unsigned char snd_miro_read(
struct snd_miro *chip,
824 unsigned char retval = 0xff;
846 spin_unlock_irqrestore(&chip->
lock, flags);
850 static void snd_miro_write(
struct snd_miro *chip,
unsigned char reg,
875 spin_unlock_irqrestore(&chip->
lock, flags);
879 #define snd_miro_write_mask(chip, reg, value, mask) \
880 snd_miro_write(chip, reg, \
881 (snd_miro_read(chip, reg) & ~(mask)) | ((value) & (mask)))
892 char*
model =
"unknown";
901 model =
"miroSOUND PCM1 pro";
904 model =
"miroSOUND PCM1 pro / (early) PCM12";
916 model =
"miroSOUND PCM12";
919 model =
"miroSOUND PCM12 (Rev. E)";
922 model =
"miroSOUND PCM12 / PCM12 pnp";
934 model =
"miroSOUND PCM20 radio (Rev. E)";
937 model =
"miroSOUND PCM20 radio";
942 snd_iprintf(buffer,
"\nGeneral information:\n");
943 snd_iprintf(buffer,
" model : %s\n",
model);
944 snd_iprintf(buffer,
" opti : %s\n", miro->
name);
945 snd_iprintf(buffer,
" codec : %s\n", miro->
pcm->name);
946 snd_iprintf(buffer,
" port : 0x%lx\n", miro->
wss_base);
947 snd_iprintf(buffer,
" irq : %d\n", miro->
irq);
948 snd_iprintf(buffer,
" dma : %d,%d\n\n", miro->
dma1, miro->
dma2);
950 snd_iprintf(buffer,
"MPU-401:\n");
951 snd_iprintf(buffer,
" port : 0x%lx\n", miro->
mpu_port);
952 snd_iprintf(buffer,
" irq : %d\n\n", miro->
mpu_irq);
954 snd_iprintf(buffer,
"ACI information:\n");
955 snd_iprintf(buffer,
" vendor : ");
958 snd_iprintf(buffer,
"Miro\n");
961 snd_iprintf(buffer,
"unknown (0x%x)\n", aci->
aci_vendor);
965 snd_iprintf(buffer,
" product : ");
968 snd_iprintf(buffer,
"miroSOUND PCM1 pro / (early) PCM12\n");
971 snd_iprintf(buffer,
"miroSOUND PCM12\n");
974 snd_iprintf(buffer,
"miroSOUND PCM20 radio\n");
977 snd_iprintf(buffer,
"unknown (0x%x)\n", aci->
aci_product);
981 snd_iprintf(buffer,
" firmware: %d (0x%x)\n",
983 snd_iprintf(buffer,
" port : 0x%lx-0x%lx\n",
985 snd_iprintf(buffer,
" wss : 0x%x\n", wss);
986 snd_iprintf(buffer,
" ide : 0x%x\n", ide);
987 snd_iprintf(buffer,
" solomode: 0x%x\n", aci->
aci_solomode);
988 snd_iprintf(buffer,
" amp : 0x%x\n", aci->
aci_amp);
989 snd_iprintf(buffer,
" preamp : 0x%x\n", aci->
aci_preamp);
997 if (!snd_card_proc_new(card,
"miro", &entry))
998 snd_info_set_text_ops(entry, miro, snd_miro_proc_read);
1007 unsigned char wss_base_bits;
1008 unsigned char irq_bits;
1009 unsigned char dma_bits;
1010 unsigned char mpu_port_bits = 0;
1011 unsigned char mpu_irq_bits;
1012 unsigned long flags;
1036 wss_base_bits = 0x00;
1040 wss_base_bits = 0x03;
1044 wss_base_bits = 0x01;
1048 wss_base_bits = 0x02;
1057 switch (chip->
irq) {
1075 goto __skip_resources;
1078 switch (chip->
dma1) {
1090 goto __skip_resources;
1098 switch (chip->
dma2) {
1104 goto __skip_resources;
1110 spin_unlock_irqrestore(&chip->
lock, flags);
1119 mpu_port_bits = 0x03;
1122 mpu_port_bits = 0x02;
1125 mpu_port_bits = 0x01;
1128 mpu_port_bits = 0x00;
1138 mpu_irq_bits = 0x02;
1141 mpu_irq_bits = 0x03;
1144 mpu_irq_bits = 0x00;
1147 mpu_irq_bits = 0x01;
1157 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
1167 unsigned char value;
1192 if ((err = snd_miro_init(chip, i)) < 0)
1195 err = snd_miro_opti_check(chip);
1217 aci->
aci_port = (regval & 0x10) ? 0x344 : 0x354;
1227 for (i = 0; i < 3; i++)
1258 static void snd_card_miro_free(
struct snd_card *card)
1264 miro->
aci->aci_port = 0;
1280 "miro (OPTi9xx MC)");
1287 error = snd_card_miro_aci_detect(card, miro);
1301 snd_miro_proc_init(card, miro);
1303 error = snd_miro_configure(miro);
1327 error = snd_miro_mixer(card, miro);
1331 if (miro->
aci->aci_vendor ==
'm') {
1333 switch (miro->
aci->aci_product) {
1336 "miroSOUND PCM1 pro / PCM12");
1344 "miroSOUND PCM20 radio");
1366 mpu_port, 0, miro->
mpu_irq, &rmidi);
1377 2, &opl3, &opl4) < 0)
1382 error = snd_set_aci_init_values(miro);
1389 static int __devinit snd_miro_isa_match(
struct device *devptr,
unsigned int n)
1392 if (snd_miro_pnp_is_probed)
1400 static int __devinit snd_miro_isa_probe(
struct device *devptr,
unsigned int n)
1402 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
1403 static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1};
1404 static int possible_irqs[] = {11, 9, 10, 7, -1};
1405 static int possible_mpu_irqs[] = {10, 5, 9, 7, -1};
1406 static int possible_dma1s[] = {3, 1, 0, -1};
1407 static int possible_dma2s[][2] = { {1, -1}, {0, -1}, {-1, -1},
1422 error = snd_card_miro_detect(card, miro);
1430 port = snd_legacy_find_free_ioport(possible_ports, 4);
1439 mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2);
1443 "unable to find a free MPU401 port\n");
1449 irq = snd_legacy_find_free_irq(possible_irqs);
1457 mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs);
1461 "unable to find a free MPU401 IRQ\n");
1466 dma1 = snd_legacy_find_free_dma(possible_dma1s);
1474 dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4]);
1484 error = snd_miro_probe(card);
1502 #define DEV_NAME "miro"
1505 .match = snd_miro_isa_match,
1506 .probe = snd_miro_isa_probe,
1550 port = pnp_port_start(pdev, 1);
1551 fm_port = pnp_port_start(pdev, 2) + 8;
1557 chip->
mc_base = pnp_port_start(devmc, 0) - 1;
1571 mpu_port = pnp_port_start(devmpu, 0);
1584 if (snd_miro_pnp_is_probed)
1596 err = snd_card_miro_pnp(miro, pcard, pid);
1609 err = snd_miro_opti_check(miro);
1617 err = snd_miro_probe(card);
1622 pnp_set_card_drvdata(pcard, card);
1623 snd_miro_pnp_is_probed = 1;
1630 pnp_set_card_drvdata(pcard,
NULL);
1631 snd_miro_pnp_is_probed = 0;
1637 .id_table = snd_miro_pnpids,
1638 .probe = snd_miro_pnp_probe,
1643 static int __init alsa_card_miro_init(
void)
1647 if (snd_miro_pnp_is_probed)
1654 static void __exit alsa_card_miro_exit(
void)
1656 if (!snd_miro_pnp_is_probed) {