miro.c (611ac726f9ebbb12f2113e5345ef109660954eeb) | miro.c (2973ee4a5b5495090af6b24d9adbb765bca04aaf) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * ALSA soundcard driver for Miro miroSOUND PCM1 pro 4 * miroSOUND PCM12 5 * miroSOUND PCM20 Radio 6 * 7 * Copyright (C) 2004-2005 Martin Langer <martin-langer@gmx.de> 8 * --- 1145 unchanged lines hidden (view full) --- 1154 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3, 1155 0xf8); 1156 } 1157__skip_mpu: 1158 1159 return 0; 1160} 1161 | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * ALSA soundcard driver for Miro miroSOUND PCM1 pro 4 * miroSOUND PCM12 5 * miroSOUND PCM20 Radio 6 * 7 * Copyright (C) 2004-2005 Martin Langer <martin-langer@gmx.de> 8 * --- 1145 unchanged lines hidden (view full) --- 1154 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3, 1155 0xf8); 1156 } 1157__skip_mpu: 1158 1159 return 0; 1160} 1161 |
1162static int snd_miro_opti_check(struct snd_miro *chip) | 1162static int snd_miro_opti_check(struct snd_card *card, struct snd_miro *chip) |
1163{ 1164 unsigned char value; 1165 | 1163{ 1164 unsigned char value; 1165 |
1166 chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, 1167 "OPTi9xx MC"); | 1166 chip->res_mc_base = 1167 devm_request_region(card->dev, chip->mc_base, 1168 chip->mc_base_size, "OPTi9xx MC"); |
1168 if (chip->res_mc_base == NULL) 1169 return -ENOMEM; 1170 1171 value = snd_miro_read(chip, OPTi9XX_MC_REG(1)); 1172 if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1))) 1173 if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1))) 1174 return 0; 1175 | 1169 if (chip->res_mc_base == NULL) 1170 return -ENOMEM; 1171 1172 value = snd_miro_read(chip, OPTi9XX_MC_REG(1)); 1173 if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1))) 1174 if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1))) 1175 return 0; 1176 |
1176 release_and_free_resource(chip->res_mc_base); | 1177 devm_release_resource(card->dev, chip->res_mc_base); |
1177 chip->res_mc_base = NULL; 1178 1179 return -ENODEV; 1180} 1181 1182static int snd_card_miro_detect(struct snd_card *card, 1183 struct snd_miro *chip) 1184{ 1185 int i, err; 1186 1187 for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) { 1188 1189 err = snd_miro_init(chip, i); 1190 if (err < 0) 1191 return err; 1192 | 1178 chip->res_mc_base = NULL; 1179 1180 return -ENODEV; 1181} 1182 1183static int snd_card_miro_detect(struct snd_card *card, 1184 struct snd_miro *chip) 1185{ 1186 int i, err; 1187 1188 for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) { 1189 1190 err = snd_miro_init(chip, i); 1191 if (err < 0) 1192 return err; 1193 |
1193 err = snd_miro_opti_check(chip); | 1194 err = snd_miro_opti_check(card, chip); |
1194 if (err == 0) 1195 return 1; 1196 } 1197 1198 return -ENODEV; 1199} 1200 1201static int snd_card_miro_aci_detect(struct snd_card *card, --- 7 unchanged lines hidden (view full) --- 1209 1210 mutex_init(&aci->aci_mutex); 1211 1212 /* get ACI port from OPTi9xx MC 4 */ 1213 1214 regval=inb(miro->mc_base + 4); 1215 aci->aci_port = (regval & 0x10) ? 0x344 : 0x354; 1216 | 1195 if (err == 0) 1196 return 1; 1197 } 1198 1199 return -ENODEV; 1200} 1201 1202static int snd_card_miro_aci_detect(struct snd_card *card, --- 7 unchanged lines hidden (view full) --- 1210 1211 mutex_init(&aci->aci_mutex); 1212 1213 /* get ACI port from OPTi9xx MC 4 */ 1214 1215 regval=inb(miro->mc_base + 4); 1216 aci->aci_port = (regval & 0x10) ? 0x344 : 0x354; 1217 |
1217 miro->res_aci_port = request_region(aci->aci_port, 3, "miro aci"); | 1218 miro->res_aci_port = 1219 devm_request_region(card->dev, aci->aci_port, 3, "miro aci"); |
1218 if (miro->res_aci_port == NULL) { 1219 snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n", 1220 aci->aci_port, aci->aci_port+2); 1221 return -ENOMEM; 1222 } 1223 1224 /* force ACI into a known state */ 1225 for (i = 0; i < 3; i++) --- 22 unchanged lines hidden (view full) --- 1248 snd_aci_cmd(aci, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) { 1249 snd_printk(KERN_ERR "can't initialize aci.\n"); 1250 return -ENXIO; 1251 } 1252 1253 return 0; 1254} 1255 | 1220 if (miro->res_aci_port == NULL) { 1221 snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n", 1222 aci->aci_port, aci->aci_port+2); 1223 return -ENOMEM; 1224 } 1225 1226 /* force ACI into a known state */ 1227 for (i = 0; i < 3; i++) --- 22 unchanged lines hidden (view full) --- 1250 snd_aci_cmd(aci, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) { 1251 snd_printk(KERN_ERR "can't initialize aci.\n"); 1252 return -ENXIO; 1253 } 1254 1255 return 0; 1256} 1257 |
1256static void snd_card_miro_free(struct snd_card *card) 1257{ 1258 struct snd_miro *miro = card->private_data; 1259 1260 release_and_free_resource(miro->res_aci_port); 1261 if (miro->aci) 1262 miro->aci->aci_port = 0; 1263 release_and_free_resource(miro->res_mc_base); 1264} 1265 | |
1266static int snd_miro_probe(struct snd_card *card) 1267{ 1268 int error; 1269 struct snd_miro *miro = card->private_data; 1270 struct snd_wss *codec; 1271 struct snd_rawmidi *rmidi; 1272 1273 if (!miro->res_mc_base) { | 1258static int snd_miro_probe(struct snd_card *card) 1259{ 1260 int error; 1261 struct snd_miro *miro = card->private_data; 1262 struct snd_wss *codec; 1263 struct snd_rawmidi *rmidi; 1264 1265 if (!miro->res_mc_base) { |
1274 miro->res_mc_base = request_region(miro->mc_base, 1275 miro->mc_base_size, 1276 "miro (OPTi9xx MC)"); | 1266 miro->res_mc_base = devm_request_region(card->dev, 1267 miro->mc_base, 1268 miro->mc_base_size, 1269 "miro (OPTi9xx MC)"); |
1277 if (miro->res_mc_base == NULL) { 1278 snd_printk(KERN_ERR "request for OPTI9xx MC failed\n"); 1279 return -ENOMEM; 1280 } 1281 } 1282 1283 error = snd_card_miro_aci_detect(card, miro); 1284 if (error < 0) { --- 118 unchanged lines hidden (view full) --- 1403 static const int possible_dma1s[] = {3, 1, 0, -1}; 1404 static const int possible_dma2s[][2] = { {1, -1}, {0, -1}, {-1, -1}, 1405 {0, -1} }; 1406 1407 int error; 1408 struct snd_miro *miro; 1409 struct snd_card *card; 1410 | 1270 if (miro->res_mc_base == NULL) { 1271 snd_printk(KERN_ERR "request for OPTI9xx MC failed\n"); 1272 return -ENOMEM; 1273 } 1274 } 1275 1276 error = snd_card_miro_aci_detect(card, miro); 1277 if (error < 0) { --- 118 unchanged lines hidden (view full) --- 1396 static const int possible_dma1s[] = {3, 1, 0, -1}; 1397 static const int possible_dma2s[][2] = { {1, -1}, {0, -1}, {-1, -1}, 1398 {0, -1} }; 1399 1400 int error; 1401 struct snd_miro *miro; 1402 struct snd_card *card; 1403 |
1411 error = snd_card_new(devptr, index, id, THIS_MODULE, 1412 sizeof(struct snd_miro), &card); | 1404 error = snd_devm_card_new(devptr, index, id, THIS_MODULE, 1405 sizeof(struct snd_miro), &card); |
1413 if (error < 0) 1414 return error; 1415 | 1406 if (error < 0) 1407 return error; 1408 |
1416 card->private_free = snd_card_miro_free; | |
1417 miro = card->private_data; 1418 1419 error = snd_card_miro_detect(card, miro); 1420 if (error < 0) { | 1409 miro = card->private_data; 1410 1411 error = snd_card_miro_detect(card, miro); 1412 if (error < 0) { |
1421 snd_card_free(card); | |
1422 snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n"); 1423 return -ENODEV; 1424 } 1425 1426 if (port == SNDRV_AUTO_PORT) { 1427 port = snd_legacy_find_free_ioport(possible_ports, 4); 1428 if (port < 0) { | 1413 snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n"); 1414 return -ENODEV; 1415 } 1416 1417 if (port == SNDRV_AUTO_PORT) { 1418 port = snd_legacy_find_free_ioport(possible_ports, 4); 1419 if (port < 0) { |
1429 snd_card_free(card); | |
1430 snd_printk(KERN_ERR "unable to find a free WSS port\n"); 1431 return -EBUSY; 1432 } 1433 } 1434 1435 if (mpu_port == SNDRV_AUTO_PORT) { 1436 mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2); 1437 if (mpu_port < 0) { | 1420 snd_printk(KERN_ERR "unable to find a free WSS port\n"); 1421 return -EBUSY; 1422 } 1423 } 1424 1425 if (mpu_port == SNDRV_AUTO_PORT) { 1426 mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2); 1427 if (mpu_port < 0) { |
1438 snd_card_free(card); | |
1439 snd_printk(KERN_ERR 1440 "unable to find a free MPU401 port\n"); 1441 return -EBUSY; 1442 } 1443 } 1444 1445 if (irq == SNDRV_AUTO_IRQ) { 1446 irq = snd_legacy_find_free_irq(possible_irqs); 1447 if (irq < 0) { | 1428 snd_printk(KERN_ERR 1429 "unable to find a free MPU401 port\n"); 1430 return -EBUSY; 1431 } 1432 } 1433 1434 if (irq == SNDRV_AUTO_IRQ) { 1435 irq = snd_legacy_find_free_irq(possible_irqs); 1436 if (irq < 0) { |
1448 snd_card_free(card); | |
1449 snd_printk(KERN_ERR "unable to find a free IRQ\n"); 1450 return -EBUSY; 1451 } 1452 } 1453 if (mpu_irq == SNDRV_AUTO_IRQ) { 1454 mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs); 1455 if (mpu_irq < 0) { | 1437 snd_printk(KERN_ERR "unable to find a free IRQ\n"); 1438 return -EBUSY; 1439 } 1440 } 1441 if (mpu_irq == SNDRV_AUTO_IRQ) { 1442 mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs); 1443 if (mpu_irq < 0) { |
1456 snd_card_free(card); | |
1457 snd_printk(KERN_ERR 1458 "unable to find a free MPU401 IRQ\n"); 1459 return -EBUSY; 1460 } 1461 } 1462 if (dma1 == SNDRV_AUTO_DMA) { 1463 dma1 = snd_legacy_find_free_dma(possible_dma1s); 1464 if (dma1 < 0) { | 1444 snd_printk(KERN_ERR 1445 "unable to find a free MPU401 IRQ\n"); 1446 return -EBUSY; 1447 } 1448 } 1449 if (dma1 == SNDRV_AUTO_DMA) { 1450 dma1 = snd_legacy_find_free_dma(possible_dma1s); 1451 if (dma1 < 0) { |
1465 snd_card_free(card); | |
1466 snd_printk(KERN_ERR "unable to find a free DMA1\n"); 1467 return -EBUSY; 1468 } 1469 } 1470 if (dma2 == SNDRV_AUTO_DMA) { 1471 dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4]); 1472 if (dma2 < 0) { | 1452 snd_printk(KERN_ERR "unable to find a free DMA1\n"); 1453 return -EBUSY; 1454 } 1455 } 1456 if (dma2 == SNDRV_AUTO_DMA) { 1457 dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4]); 1458 if (dma2 < 0) { |
1473 snd_card_free(card); | |
1474 snd_printk(KERN_ERR "unable to find a free DMA2\n"); 1475 return -EBUSY; 1476 } 1477 } 1478 1479 error = snd_miro_probe(card); | 1459 snd_printk(KERN_ERR "unable to find a free DMA2\n"); 1460 return -EBUSY; 1461 } 1462 } 1463 1464 error = snd_miro_probe(card); |
1480 if (error < 0) { 1481 snd_card_free(card); | 1465 if (error < 0) |
1482 return error; | 1466 return error; |
1483 } | |
1484 1485 dev_set_drvdata(devptr, card); 1486 return 0; 1487} 1488 | 1467 1468 dev_set_drvdata(devptr, card); 1469 return 0; 1470} 1471 |
1489static void snd_miro_isa_remove(struct device *devptr, 1490 unsigned int dev) 1491{ 1492 snd_card_free(dev_get_drvdata(devptr)); 1493} 1494 | |
1495#define DEV_NAME "miro" 1496 1497static struct isa_driver snd_miro_driver = { 1498 .match = snd_miro_isa_match, 1499 .probe = snd_miro_isa_probe, | 1472#define DEV_NAME "miro" 1473 1474static struct isa_driver snd_miro_driver = { 1475 .match = snd_miro_isa_match, 1476 .probe = snd_miro_isa_probe, |
1500 .remove = snd_miro_isa_remove, | |
1501 /* FIXME: suspend/resume */ 1502 .driver = { 1503 .name = DEV_NAME 1504 }, 1505}; 1506 1507#ifdef CONFIG_PNP 1508 --- 64 unchanged lines hidden (view full) --- 1573 struct snd_card *card; 1574 int err; 1575 struct snd_miro *miro; 1576 1577 if (snd_miro_pnp_is_probed) 1578 return -EBUSY; 1579 if (!isapnp) 1580 return -ENODEV; | 1477 /* FIXME: suspend/resume */ 1478 .driver = { 1479 .name = DEV_NAME 1480 }, 1481}; 1482 1483#ifdef CONFIG_PNP 1484 --- 64 unchanged lines hidden (view full) --- 1549 struct snd_card *card; 1550 int err; 1551 struct snd_miro *miro; 1552 1553 if (snd_miro_pnp_is_probed) 1554 return -EBUSY; 1555 if (!isapnp) 1556 return -ENODEV; |
1581 err = snd_card_new(&pcard->card->dev, index, id, THIS_MODULE, 1582 sizeof(struct snd_miro), &card); | 1557 err = snd_devm_card_new(&pcard->card->dev, index, id, THIS_MODULE, 1558 sizeof(struct snd_miro), &card); |
1583 if (err < 0) 1584 return err; 1585 | 1559 if (err < 0) 1560 return err; 1561 |
1586 card->private_free = snd_card_miro_free; | |
1587 miro = card->private_data; 1588 1589 err = snd_card_miro_pnp(miro, pcard, pid); | 1562 miro = card->private_data; 1563 1564 err = snd_card_miro_pnp(miro, pcard, pid); |
1590 if (err) { 1591 snd_card_free(card); | 1565 if (err) |
1592 return err; | 1566 return err; |
1593 } | |
1594 1595 /* only miroSOUND PCM20 and PCM12 == OPTi924 */ 1596 err = snd_miro_init(miro, OPTi9XX_HW_82C924); | 1567 1568 /* only miroSOUND PCM20 and PCM12 == OPTi924 */ 1569 err = snd_miro_init(miro, OPTi9XX_HW_82C924); |
1597 if (err) { 1598 snd_card_free(card); | 1570 if (err) |
1599 return err; | 1571 return err; |
1600 } | |
1601 | 1572 |
1602 err = snd_miro_opti_check(miro); | 1573 err = snd_miro_opti_check(card, miro); |
1603 if (err) { 1604 snd_printk(KERN_ERR "OPTI chip not found\n"); | 1574 if (err) { 1575 snd_printk(KERN_ERR "OPTI chip not found\n"); |
1605 snd_card_free(card); | |
1606 return err; 1607 } 1608 1609 err = snd_miro_probe(card); | 1576 return err; 1577 } 1578 1579 err = snd_miro_probe(card); |
1610 if (err < 0) { 1611 snd_card_free(card); | 1580 if (err < 0) |
1612 return err; | 1581 return err; |
1613 } | |
1614 pnp_set_card_drvdata(pcard, card); 1615 snd_miro_pnp_is_probed = 1; 1616 return 0; 1617} 1618 1619static void snd_miro_pnp_remove(struct pnp_card_link *pcard) 1620{ | 1582 pnp_set_card_drvdata(pcard, card); 1583 snd_miro_pnp_is_probed = 1; 1584 return 0; 1585} 1586 1587static void snd_miro_pnp_remove(struct pnp_card_link *pcard) 1588{ |
1621 snd_card_free(pnp_get_card_drvdata(pcard)); 1622 pnp_set_card_drvdata(pcard, NULL); | |
1623 snd_miro_pnp_is_probed = 0; 1624} 1625 1626static struct pnp_card_driver miro_pnpc_driver = { 1627 .flags = PNP_DRIVER_RES_DISABLE, 1628 .name = "miro", 1629 .id_table = snd_miro_pnpids, 1630 .probe = snd_miro_pnp_probe, --- 28 unchanged lines hidden --- | 1589 snd_miro_pnp_is_probed = 0; 1590} 1591 1592static struct pnp_card_driver miro_pnpc_driver = { 1593 .flags = PNP_DRIVER_RES_DISABLE, 1594 .name = "miro", 1595 .id_table = snd_miro_pnpids, 1596 .probe = snd_miro_pnp_probe, --- 28 unchanged lines hidden --- |