Changeset 615 for GPL/branches/uniaud32-next/alsa-kernel/pci/cs4281.c
- Timestamp:
- Jan 1, 2021, 5:31:48 AM (5 years ago)
- Location:
- GPL/branches/uniaud32-next
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
GPL/branches/uniaud32-next/alsa-kernel/pci/cs4281.c
r612 r615 1 // SPDX-License-Identifier: GPL-2.0-or-later 1 2 /* 2 3 * Driver for Cirrus Logic CS4281 based PCI soundcard 3 4 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>, 4 *5 *6 * This program is free software; you can redistribute it and/or modify7 * it under the terms of the GNU General Public License as published by8 * the Free Software Foundation; either version 2 of the License, or9 * (at your option) any later version.10 *11 * This program is distributed in the hope that it will be useful,12 * but WITHOUT ANY WARRANTY; without even the implied warranty of13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14 * GNU General Public License for more details.15 *16 * You should have received a copy of the GNU General Public License17 * along with this program; if not, write to the Free Software18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA19 *20 5 */ 21 6 22 #ifdef TARGET_OS2 23 #define KBUILD_MODNAME "cs4281" 24 #endif 25 26 #include <asm/io.h> 7 #include <linux/io.h> 27 8 #include <linux/delay.h> 28 9 #include <linux/interrupt.h> … … 42 23 43 24 25 #ifdef TARGET_OS2 26 #define KBUILD_MODNAME "cs4281" 27 #endif 44 28 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 45 29 MODULE_DESCRIPTION("Cirrus Logic CS4281"); … … 49 33 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 50 34 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 51 static intenable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */52 static intdual_codec[SNDRV_CARDS]; /* dual codec */35 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */ 36 static bool dual_codec[SNDRV_CARDS]; /* dual codec */ 53 37 54 38 module_param_array(index, int, NULL, 0444); … … 491 475 struct gameport *gameport; 492 476 493 #ifdef CONFIG_PM 477 #ifdef CONFIG_PM_SLEEP 494 478 u32 suspend_regs[SUSPEND_REGISTERS]; 495 479 #endif … … 499 483 static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id); 500 484 501 static DEFINE_PCI_DEVICE_TABLE(snd_cs4281_ids)= {485 static const struct pci_device_id snd_cs4281_ids[] = { 502 486 { PCI_VDEVICE(CIRRUS, 0x6005), 0, }, /* CS4281 */ 503 487 { 0, } … … 569 553 } 570 554 } 571 snd_printk(KERN_ERR "AC'97 write problem, reg = 0x%x, val = 0x%x\n", reg, val); 555 dev_err(chip->card->dev, 556 "AC'97 write problem, reg = 0x%x, val = 0x%x\n", reg, val); 572 557 } 573 558 … … 629 614 } 630 615 631 snd_printk(KERN_ERR "AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg); 616 dev_err(chip->card->dev, 617 "AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg); 632 618 result = 0xffff; 633 619 goto __end; … … 648 634 } 649 635 650 snd_printk(KERN_ERR "AC'97 read problem (ACSTS_VSTS), reg = 0x%x\n", reg); 636 dev_err(chip->card->dev, 637 "AC'97 read problem (ACSTS_VSTS), reg = 0x%x\n", reg); 651 638 result = 0xffff; 652 639 goto __end; … … 711 698 static unsigned int snd_cs4281_rate(unsigned int rate, unsigned int *real_rate) 712 699 { 713 unsigned int val = ~0;700 unsigned int val; 714 701 715 702 if (real_rate) … … 724 711 case 48000: return 0; 725 712 default: 726 goto __variable; 727 } 728 __variable: 713 break; 714 } 729 715 val = 1536000 / rate; 730 716 if (real_rate) … … 840 826 841 827 /* 842 printk(KERN_DEBUG "DCC = 0x%x, buffer_size = 0x%x, jiffies = %li\n", 843 snd_cs4281_peekBA0(chip, dma->regDCC), runtime->buffer_size, 828 dev_dbg(chip->card->dev, 829 "DCC = 0x%x, buffer_size = 0x%x, jiffies = %li\n", 830 snd_cs4281_peekBA0(chip, dma->regDCC), runtime->buffer_size, 844 831 jiffies); 845 832 */ … … 848 835 } 849 836 850 static struct snd_pcm_hardware snd_cs4281_playback =837 static const struct snd_pcm_hardware snd_cs4281_playback = 851 838 { 852 839 .info = SNDRV_PCM_INFO_MMAP | … … 873 860 }; 874 861 875 static struct snd_pcm_hardware snd_cs4281_capture =862 static const struct snd_pcm_hardware snd_cs4281_capture = 876 863 { 877 864 .info = SNDRV_PCM_INFO_MMAP | … … 952 939 } 953 940 954 static struct snd_pcm_ops snd_cs4281_playback_ops = {941 static const struct snd_pcm_ops snd_cs4281_playback_ops = { 955 942 .open = snd_cs4281_playback_open, 956 943 .close = snd_cs4281_playback_close, … … 963 950 }; 964 951 965 static struct snd_pcm_ops snd_cs4281_capture_ops = {952 static const struct snd_pcm_ops snd_cs4281_capture_ops = { 966 953 .open = snd_cs4281_capture_open, 967 954 .close = snd_cs4281_capture_close, … … 974 961 }; 975 962 976 static int __devinit snd_cs4281_pcm(struct cs4281 * chip, int device, 977 struct snd_pcm ** rpcm) 963 static int snd_cs4281_pcm(struct cs4281 *chip, int device) 978 964 { 979 965 struct snd_pcm *pcm; 980 966 int err; 981 967 982 if (rpcm)983 *rpcm = NULL;984 968 err = snd_pcm_new(chip->card, "CS4281", device, 1, 1, &pcm); 985 969 if (err < 0) … … 997 981 snd_dma_pci_data(chip->pci), 64*1024, 512*1024); 998 982 999 if (rpcm)1000 *rpcm = pcm;1001 983 return 0; 1002 984 } … … 1061 1043 static const DECLARE_TLV_DB_SCALE(db_scale_dsp, -4650, 150, 0); 1062 1044 1063 static struct snd_kcontrol_new snd_cs4281_fm_vol =1045 static const struct snd_kcontrol_new snd_cs4281_fm_vol = 1064 1046 { 1065 1047 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, … … 1072 1054 }; 1073 1055 1074 static struct snd_kcontrol_new snd_cs4281_pcm_vol =1056 static const struct snd_kcontrol_new snd_cs4281_pcm_vol = 1075 1057 { 1076 1058 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, … … 1098 1080 } 1099 1081 1100 static int __devinit snd_cs4281_mixer(struct cs4281 *chip)1082 static int snd_cs4281_mixer(struct cs4281 *chip) 1101 1083 { 1102 1084 struct snd_card *card = chip->card; … … 1176 1158 }; 1177 1159 1178 static void __devinit snd_cs4281_proc_init(struct cs4281 *chip)1160 static void snd_cs4281_proc_init(struct cs4281 *chip) 1179 1161 { 1180 1162 struct snd_info_entry *entry; 1181 1163 1182 if (! snd_card_proc_new(chip->card, "cs4281", &entry)) 1183 snd_info_set_text_ops(entry, chip, snd_cs4281_proc_read); 1164 snd_card_ro_proc_new(chip->card, "cs4281", chip, snd_cs4281_proc_read); 1184 1165 if (! snd_card_proc_new(chip->card, "cs4281_BA0", &entry)) { 1185 1166 entry->content = SNDRV_INFO_CONTENT_DATA; … … 1200 1181 */ 1201 1182 1202 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))1183 #if IS_REACHABLE(CONFIG_GAMEPORT) 1203 1184 1204 1185 static void snd_cs4281_gameport_trigger(struct gameport *gameport) … … 1264 1245 } 1265 1246 1266 static int __devinitsnd_cs4281_create_gameport(struct cs4281 *chip)1247 static int snd_cs4281_create_gameport(struct cs4281 *chip) 1267 1248 { 1268 1249 struct gameport *gp; … … 1270 1251 chip->gameport = gp = gameport_allocate_port(); 1271 1252 if (!gp) { 1272 printk(KERN_ERR "cs4281: cannot allocate memory for gameport\n"); 1253 dev_err(chip->card->dev, 1254 "cannot allocate memory for gameport\n"); 1273 1255 return -ENOMEM; 1274 1256 } … … 1301 1283 static inline int snd_cs4281_create_gameport(struct cs4281 *chip) { return -ENOSYS; } 1302 1284 static inline void snd_cs4281_free_gameport(struct cs4281 *chip) { } 1303 #endif /* CONFIG_GAMEPORT || (MODULE && CONFIG_GAMEPORT_MODULE) */1285 #endif /* IS_REACHABLE(CONFIG_GAMEPORT) */ 1304 1286 1305 1287 static int snd_cs4281_free(struct cs4281 *chip) … … 1317 1299 snd_cs4281_pokeBA0(chip, BA0_SSPM, 0); 1318 1300 /* PCI interface - D3 state */ 1319 pci_set_power_state(chip->pci, 3);1301 pci_set_power_state(chip->pci, PCI_D3hot); 1320 1302 1321 1303 if (chip->irq >= 0) 1322 1304 free_irq(chip->irq, chip); 1323 if (chip->ba0) 1324 iounmap(chip->ba0); 1325 if (chip->ba1) 1326 iounmap(chip->ba1); 1305 iounmap(chip->ba0); 1306 iounmap(chip->ba1); 1327 1307 pci_release_regions(chip->pci); 1328 1308 pci_disable_device(chip->pci); … … 1340 1320 static int snd_cs4281_chip_init(struct cs4281 *chip); /* defined below */ 1341 1321 1342 static int __devinitsnd_cs4281_create(struct snd_card *card,1343 1344 struct cs4281 **rchip,1345 1322 static int snd_cs4281_create(struct snd_card *card, 1323 struct pci_dev *pci, 1324 struct cs4281 **rchip, 1325 int dual_codec) 1346 1326 { 1347 1327 struct cs4281 *chip; … … 1366 1346 pci_set_master(pci); 1367 1347 if (dual_codec < 0 || dual_codec > 3) { 1368 snd_printk(KERN_ERR"invalid dual_codec option %d\n", dual_codec);1348 dev_err(card->dev, "invalid dual_codec option %d\n", dual_codec); 1369 1349 dual_codec = 0; 1370 1350 } … … 1388 1368 if (request_irq(pci->irq, snd_cs4281_interrupt, IRQF_SHARED, 1389 1369 KBUILD_MODNAME, chip)) { 1390 snd_printk(KERN_ERR"unable to grab IRQ %d\n", pci->irq);1370 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); 1391 1371 snd_cs4281_free(chip); 1392 1372 return -ENOMEM; … … 1406 1386 1407 1387 snd_cs4281_proc_init(chip); 1408 1409 snd_card_set_dev(card, &pci->dev);1410 1388 1411 1389 *rchip = chip; … … 1430 1408 tmp = snd_cs4281_peekBA0(chip, BA0_CFLR); 1431 1409 if (tmp != BA0_CFLR_DEFAULT) { 1432 snd_printk(KERN_ERR "CFLR setup failed (0x%x)\n", tmp); 1410 dev_err(chip->card->dev, 1411 "CFLR setup failed (0x%x)\n", tmp); 1433 1412 return -EIO; 1434 1413 } … … 1441 1420 1442 1421 if ((tmp = snd_cs4281_peekBA0(chip, BA0_SERC1)) != (BA0_SERC1_SO1EN | BA0_SERC1_AC97)) { 1443 snd_printk(KERN_ERR "SERC1 AC'97 check failed (0x%x)\n", tmp); 1422 dev_err(chip->card->dev, 1423 "SERC1 AC'97 check failed (0x%x)\n", tmp); 1444 1424 return -EIO; 1445 1425 } 1446 1426 if ((tmp = snd_cs4281_peekBA0(chip, BA0_SERC2)) != (BA0_SERC2_SI1EN | BA0_SERC2_AC97)) { 1447 snd_printk(KERN_ERR "SERC2 AC'97 check failed (0x%x)\n", tmp); 1427 dev_err(chip->card->dev, 1428 "SERC2 AC'97 check failed (0x%x)\n", tmp); 1448 1429 return -EIO; 1449 1430 } … … 1507 1488 } while (time_after_eq(end_time, jiffies)); 1508 1489 1509 snd_printk(KERN_ERR"DLLRDY not seen\n");1490 dev_err(chip->card->dev, "DLLRDY not seen\n"); 1510 1491 return -EIO; 1511 1492 … … 1533 1514 } while (time_after_eq(end_time, jiffies)); 1534 1515 1535 snd_printk(KERN_ERR "never read codec ready from AC'97 (0x%x)\n", snd_cs4281_peekBA0(chip, BA0_ACSTS)); 1516 dev_err(chip->card->dev, 1517 "never read codec ready from AC'97 (0x%x)\n", 1518 snd_cs4281_peekBA0(chip, BA0_ACSTS)); 1536 1519 return -EIO; 1537 1520 … … 1544 1527 schedule_timeout_uninterruptible(1); 1545 1528 } while (time_after_eq(end_time, jiffies)); 1546 snd_printk(KERN_INFO "secondary codec doesn't respond. disable it...\n"); 1529 dev_info(chip->card->dev, 1530 "secondary codec doesn't respond. disable it...\n"); 1547 1531 chip->dual_codec = 0; 1548 1532 __codec2_ok: ; … … 1574 1558 if (--retry_count > 0) 1575 1559 goto __retry; 1576 snd_printk(KERN_ERR"never read ISV3 and ISV4 from AC'97\n");1560 dev_err(chip->card->dev, "never read ISV3 and ISV4 from AC'97\n"); 1577 1561 return -EIO; 1578 1562 … … 1770 1754 } 1771 1755 1772 static struct snd_rawmidi_ops snd_cs4281_midi_output =1756 static const struct snd_rawmidi_ops snd_cs4281_midi_output = 1773 1757 { 1774 1758 .open = snd_cs4281_midi_output_open, … … 1777 1761 }; 1778 1762 1779 static struct snd_rawmidi_ops snd_cs4281_midi_input =1763 static const struct snd_rawmidi_ops snd_cs4281_midi_input = 1780 1764 { 1781 1765 .open = snd_cs4281_midi_input_open, … … 1784 1768 }; 1785 1769 1786 static int __devinit snd_cs4281_midi(struct cs4281 * chip, int device, 1787 struct snd_rawmidi **rrawmidi) 1770 static int snd_cs4281_midi(struct cs4281 *chip, int device) 1788 1771 { 1789 1772 struct snd_rawmidi *rmidi; 1790 1773 int err; 1791 1774 1792 if (rrawmidi)1793 *rrawmidi = NULL;1794 1775 if ((err = snd_rawmidi_new(chip->card, "CS4281", device, 1, 1, &rmidi)) < 0) 1795 1776 return err; … … 1800 1781 rmidi->private_data = chip; 1801 1782 chip->rmidi = rmidi; 1802 if (rrawmidi)1803 *rrawmidi = rmidi;1804 1783 return 0; 1805 1784 } … … 1906 1885 } 1907 1886 1908 static int __devinitsnd_cs4281_probe(struct pci_dev *pci,1909 1887 static int snd_cs4281_probe(struct pci_dev *pci, 1888 const struct pci_device_id *pci_id) 1910 1889 { 1911 1890 static int dev; … … 1922 1901 } 1923 1902 1924 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 1903 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 1904 0, &card); 1925 1905 if (err < 0) 1926 1906 return err; … … 1936 1916 return err; 1937 1917 } 1938 if ((err = snd_cs4281_pcm(chip, 0 , NULL)) < 0) {1918 if ((err = snd_cs4281_pcm(chip, 0)) < 0) { 1939 1919 snd_card_free(card); 1940 1920 return err; 1941 1921 } 1942 if ((err = snd_cs4281_midi(chip, 0 , NULL)) < 0) {1922 if ((err = snd_cs4281_midi(chip, 0)) < 0) { 1943 1923 snd_card_free(card); 1944 1924 return err; … … 1973 1953 } 1974 1954 1975 static void __devexitsnd_cs4281_remove(struct pci_dev *pci)1955 static void snd_cs4281_remove(struct pci_dev *pci) 1976 1956 { 1977 1957 snd_card_free(pci_get_drvdata(pci)); 1978 pci_set_drvdata(pci, NULL);1979 1958 } 1980 1959 … … 1982 1961 * Power Management 1983 1962 */ 1984 #ifdef CONFIG_PM 1963 #ifdef CONFIG_PM_SLEEP 1985 1964 1986 1965 static int saved_regs[SUSPEND_REGISTERS] = { … … 2002 1981 #define CLKCR1_CKRA 0x00010000L 2003 1982 2004 static int cs4281_suspend(struct pci_dev *pci, pm_message_t state)2005 { 2006 struct snd_card *card = pci_get_drvdata(pci);1983 static int cs4281_suspend(struct device *dev) 1984 { 1985 struct snd_card *card = dev_get_drvdata(dev); 2007 1986 struct cs4281 *chip = card->private_data; 2008 1987 u32 ulCLK; … … 2010 1989 2011 1990 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 2012 snd_pcm_suspend_all(chip->pcm);2013 2014 1991 snd_ac97_suspend(chip->ac97); 2015 1992 snd_ac97_suspend(chip->ac97_secondary); … … 2042 2019 ulCLK &= ~CLKCR1_CKRA; 2043 2020 snd_cs4281_pokeBA0(chip, BA0_CLKCR1, ulCLK); 2044 2045 pci_disable_device(pci); 2046 pci_save_state(pci); 2047 pci_set_power_state(pci, pci_choose_state(pci, state)); 2048 return 0; 2049 } 2050 2051 static int cs4281_resume(struct pci_dev *pci) 2052 { 2053 struct snd_card *card = pci_get_drvdata(pci); 2021 return 0; 2022 } 2023 2024 static int cs4281_resume(struct device *dev) 2025 { 2026 struct snd_card *card = dev_get_drvdata(dev); 2054 2027 struct cs4281 *chip = card->private_data; 2055 2028 unsigned int i; 2056 2029 u32 ulCLK; 2057 2058 pci_set_power_state(pci, PCI_D0);2059 pci_restore_state(pci);2060 if (pci_enable_device(pci) < 0) {2061 printk(KERN_ERR "cs4281: pci_enable_device failed, "2062 "disabling device\n");2063 snd_card_disconnect(card);2064 return -EIO;2065 }2066 pci_set_master(pci);2067 2030 2068 2031 ulCLK = snd_cs4281_peekBA0(chip, BA0_CLKCR1); … … 2087 2050 return 0; 2088 2051 } 2089 #endif /* CONFIG_PM */ 2090 2091 static struct pci_driver driver = { 2052 2053 static SIMPLE_DEV_PM_OPS(cs4281_pm, cs4281_suspend, cs4281_resume); 2054 #define CS4281_PM_OPS &cs4281_pm 2055 #else 2056 #define CS4281_PM_OPS NULL 2057 #endif /* CONFIG_PM_SLEEP */ 2058 2059 static struct pci_driver cs4281_driver = { 2092 2060 .name = KBUILD_MODNAME, 2093 2061 .id_table = snd_cs4281_ids, 2094 2062 .probe = snd_cs4281_probe, 2095 .remove = __devexit_p(snd_cs4281_remove), 2096 #ifdef CONFIG_PM 2097 .suspend = cs4281_suspend, 2098 .resume = cs4281_resume, 2099 #endif 2063 .remove = snd_cs4281_remove, 2064 .driver = { 2065 .pm = CS4281_PM_OPS, 2066 }, 2100 2067 }; 2101 2068 2102 static int __init alsa_card_cs4281_init(void) 2103 { 2104 return pci_register_driver(&driver); 2105 } 2106 2107 static void __exit alsa_card_cs4281_exit(void) 2108 { 2109 pci_unregister_driver(&driver); 2110 } 2111 2112 module_init(alsa_card_cs4281_init) 2113 module_exit(alsa_card_cs4281_exit) 2069 module_pci_driver(cs4281_driver);
Note:
See TracChangeset
for help on using the changeset viewer.