cs4281.c (942baad211336efefb93a8369478888ab845c450) | cs4281.c (393e95cda08115f1543cf76ccf1c1bf9c8893b03) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Driver for Cirrus Logic CS4281 based PCI soundcard 4 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>, 5 */ 6 7#include <linux/io.h> 8#include <linux/delay.h> --- 1054 unchanged lines hidden (view full) --- 1063 struct snd_card *card = chip->card; 1064 struct snd_ac97_template ac97; 1065 int err; 1066 static const struct snd_ac97_bus_ops ops = { 1067 .write = snd_cs4281_ac97_write, 1068 .read = snd_cs4281_ac97_read, 1069 }; 1070 | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Driver for Cirrus Logic CS4281 based PCI soundcard 4 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>, 5 */ 6 7#include <linux/io.h> 8#include <linux/delay.h> --- 1054 unchanged lines hidden (view full) --- 1063 struct snd_card *card = chip->card; 1064 struct snd_ac97_template ac97; 1065 int err; 1066 static const struct snd_ac97_bus_ops ops = { 1067 .write = snd_cs4281_ac97_write, 1068 .read = snd_cs4281_ac97_read, 1069 }; 1070 |
1071 if ((err = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus)) < 0) | 1071 err = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus); 1072 if (err < 0) |
1072 return err; 1073 chip->ac97_bus->private_free = snd_cs4281_mixer_free_ac97_bus; 1074 1075 memset(&ac97, 0, sizeof(ac97)); 1076 ac97.private_data = chip; 1077 ac97.private_free = snd_cs4281_mixer_free_ac97; | 1073 return err; 1074 chip->ac97_bus->private_free = snd_cs4281_mixer_free_ac97_bus; 1075 1076 memset(&ac97, 0, sizeof(ac97)); 1077 ac97.private_data = chip; 1078 ac97.private_free = snd_cs4281_mixer_free_ac97; |
1078 if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0) | 1079 err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97); 1080 if (err < 0) |
1079 return err; 1080 if (chip->dual_codec) { 1081 ac97.num = 1; | 1081 return err; 1082 if (chip->dual_codec) { 1083 ac97.num = 1; |
1082 if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97_secondary)) < 0) | 1084 err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97_secondary); 1085 if (err < 0) |
1083 return err; 1084 } | 1086 return err; 1087 } |
1085 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4281_fm_vol, chip))) < 0) | 1088 err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4281_fm_vol, chip)); 1089 if (err < 0) |
1086 return err; | 1090 return err; |
1087 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4281_pcm_vol, chip))) < 0) | 1091 err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4281_pcm_vol, chip)); 1092 if (err < 0) |
1088 return err; 1089 return 0; 1090} 1091 1092 1093/* 1094 * proc interface 1095 */ --- 207 unchanged lines hidden (view full) --- 1303 struct cs4281 *chip; 1304 unsigned int tmp; 1305 int err; 1306 static const struct snd_device_ops ops = { 1307 .dev_free = snd_cs4281_dev_free, 1308 }; 1309 1310 *rchip = NULL; | 1093 return err; 1094 return 0; 1095} 1096 1097 1098/* 1099 * proc interface 1100 */ --- 207 unchanged lines hidden (view full) --- 1308 struct cs4281 *chip; 1309 unsigned int tmp; 1310 int err; 1311 static const struct snd_device_ops ops = { 1312 .dev_free = snd_cs4281_dev_free, 1313 }; 1314 1315 *rchip = NULL; |
1311 if ((err = pci_enable_device(pci)) < 0) | 1316 err = pci_enable_device(pci); 1317 if (err < 0) |
1312 return err; 1313 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1314 if (chip == NULL) { 1315 pci_disable_device(pci); 1316 return -ENOMEM; 1317 } 1318 spin_lock_init(&chip->reg_lock); 1319 chip->card = card; 1320 chip->pci = pci; 1321 chip->irq = -1; 1322 pci_set_master(pci); 1323 if (dual_codec < 0 || dual_codec > 3) { 1324 dev_err(card->dev, "invalid dual_codec option %d\n", dual_codec); 1325 dual_codec = 0; 1326 } 1327 chip->dual_codec = dual_codec; 1328 | 1318 return err; 1319 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1320 if (chip == NULL) { 1321 pci_disable_device(pci); 1322 return -ENOMEM; 1323 } 1324 spin_lock_init(&chip->reg_lock); 1325 chip->card = card; 1326 chip->pci = pci; 1327 chip->irq = -1; 1328 pci_set_master(pci); 1329 if (dual_codec < 0 || dual_codec > 3) { 1330 dev_err(card->dev, "invalid dual_codec option %d\n", dual_codec); 1331 dual_codec = 0; 1332 } 1333 chip->dual_codec = dual_codec; 1334 |
1329 if ((err = pci_request_regions(pci, "CS4281")) < 0) { | 1335 err = pci_request_regions(pci, "CS4281"); 1336 if (err < 0) { |
1330 kfree(chip); 1331 pci_disable_device(pci); 1332 return err; 1333 } 1334 chip->ba0_addr = pci_resource_start(pci, 0); 1335 chip->ba1_addr = pci_resource_start(pci, 1); 1336 1337 chip->ba0 = pci_ioremap_bar(pci, 0); --- 13 unchanged lines hidden (view full) --- 1351 card->sync_irq = chip->irq; 1352 1353 tmp = snd_cs4281_chip_init(chip); 1354 if (tmp) { 1355 snd_cs4281_free(chip); 1356 return tmp; 1357 } 1358 | 1337 kfree(chip); 1338 pci_disable_device(pci); 1339 return err; 1340 } 1341 chip->ba0_addr = pci_resource_start(pci, 0); 1342 chip->ba1_addr = pci_resource_start(pci, 1); 1343 1344 chip->ba0 = pci_ioremap_bar(pci, 0); --- 13 unchanged lines hidden (view full) --- 1358 card->sync_irq = chip->irq; 1359 1360 tmp = snd_cs4281_chip_init(chip); 1361 if (tmp) { 1362 snd_cs4281_free(chip); 1363 return tmp; 1364 } 1365 |
1359 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { | 1366 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); 1367 if (err < 0) { |
1360 snd_cs4281_free(chip); 1361 return err; 1362 } 1363 1364 snd_cs4281_proc_init(chip); 1365 1366 *rchip = chip; 1367 return 0; --- 22 unchanged lines hidden (view full) --- 1390 } 1391 } 1392 1393 /* Set the 'Configuration Write Protect' register 1394 * to 4281h. Allows vendor-defined configuration 1395 * space between 0e4h and 0ffh to be written. */ 1396 snd_cs4281_pokeBA0(chip, BA0_CWPR, 0x4281); 1397 | 1368 snd_cs4281_free(chip); 1369 return err; 1370 } 1371 1372 snd_cs4281_proc_init(chip); 1373 1374 *rchip = chip; 1375 return 0; --- 22 unchanged lines hidden (view full) --- 1398 } 1399 } 1400 1401 /* Set the 'Configuration Write Protect' register 1402 * to 4281h. Allows vendor-defined configuration 1403 * space between 0e4h and 0ffh to be written. */ 1404 snd_cs4281_pokeBA0(chip, BA0_CWPR, 0x4281); 1405 |
1398 if ((tmp = snd_cs4281_peekBA0(chip, BA0_SERC1)) != (BA0_SERC1_SO1EN | BA0_SERC1_AC97)) { | 1406 tmp = snd_cs4281_peekBA0(chip, BA0_SERC1); 1407 if (tmp != (BA0_SERC1_SO1EN | BA0_SERC1_AC97)) { |
1399 dev_err(chip->card->dev, 1400 "SERC1 AC'97 check failed (0x%x)\n", tmp); 1401 return -EIO; 1402 } | 1408 dev_err(chip->card->dev, 1409 "SERC1 AC'97 check failed (0x%x)\n", tmp); 1410 return -EIO; 1411 } |
1403 if ((tmp = snd_cs4281_peekBA0(chip, BA0_SERC2)) != (BA0_SERC2_SI1EN | BA0_SERC2_AC97)) { | 1412 tmp = snd_cs4281_peekBA0(chip, BA0_SERC2); 1413 if (tmp != (BA0_SERC2_SI1EN | BA0_SERC2_AC97)) { |
1404 dev_err(chip->card->dev, 1405 "SERC2 AC'97 check failed (0x%x)\n", tmp); 1406 return -EIO; 1407 } 1408 1409 /* Sound System Power Management */ 1410 snd_cs4281_pokeBA0(chip, BA0_SSPM, BA0_SSPM_MIXEN | BA0_SSPM_CSRCEN | 1411 BA0_SSPM_PSRCEN | BA0_SSPM_JSEN | --- 331 unchanged lines hidden (view full) --- 1743 .trigger = snd_cs4281_midi_input_trigger, 1744}; 1745 1746static int snd_cs4281_midi(struct cs4281 *chip, int device) 1747{ 1748 struct snd_rawmidi *rmidi; 1749 int err; 1750 | 1414 dev_err(chip->card->dev, 1415 "SERC2 AC'97 check failed (0x%x)\n", tmp); 1416 return -EIO; 1417 } 1418 1419 /* Sound System Power Management */ 1420 snd_cs4281_pokeBA0(chip, BA0_SSPM, BA0_SSPM_MIXEN | BA0_SSPM_CSRCEN | 1421 BA0_SSPM_PSRCEN | BA0_SSPM_JSEN | --- 331 unchanged lines hidden (view full) --- 1753 .trigger = snd_cs4281_midi_input_trigger, 1754}; 1755 1756static int snd_cs4281_midi(struct cs4281 *chip, int device) 1757{ 1758 struct snd_rawmidi *rmidi; 1759 int err; 1760 |
1751 if ((err = snd_rawmidi_new(chip->card, "CS4281", device, 1, 1, &rmidi)) < 0) | 1761 err = snd_rawmidi_new(chip->card, "CS4281", device, 1, 1, &rmidi); 1762 if (err < 0) |
1752 return err; 1753 strcpy(rmidi->name, "CS4281"); 1754 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_cs4281_midi_output); 1755 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_cs4281_midi_input); 1756 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; 1757 rmidi->private_data = chip; 1758 chip->rmidi = rmidi; 1759 return 0; --- 116 unchanged lines hidden (view full) --- 1876 return -ENOENT; 1877 } 1878 1879 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 1880 0, &card); 1881 if (err < 0) 1882 return err; 1883 | 1763 return err; 1764 strcpy(rmidi->name, "CS4281"); 1765 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_cs4281_midi_output); 1766 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_cs4281_midi_input); 1767 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; 1768 rmidi->private_data = chip; 1769 chip->rmidi = rmidi; 1770 return 0; --- 116 unchanged lines hidden (view full) --- 1887 return -ENOENT; 1888 } 1889 1890 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 1891 0, &card); 1892 if (err < 0) 1893 return err; 1894 |
1884 if ((err = snd_cs4281_create(card, pci, &chip, dual_codec[dev])) < 0) { | 1895 err = snd_cs4281_create(card, pci, &chip, dual_codec[dev]); 1896 if (err < 0) { |
1885 snd_card_free(card); 1886 return err; 1887 } 1888 card->private_data = chip; 1889 | 1897 snd_card_free(card); 1898 return err; 1899 } 1900 card->private_data = chip; 1901 |
1890 if ((err = snd_cs4281_mixer(chip)) < 0) { | 1902 err = snd_cs4281_mixer(chip); 1903 if (err < 0) { |
1891 snd_card_free(card); 1892 return err; 1893 } | 1904 snd_card_free(card); 1905 return err; 1906 } |
1894 if ((err = snd_cs4281_pcm(chip, 0)) < 0) { | 1907 err = snd_cs4281_pcm(chip, 0); 1908 if (err < 0) { |
1895 snd_card_free(card); 1896 return err; 1897 } | 1909 snd_card_free(card); 1910 return err; 1911 } |
1898 if ((err = snd_cs4281_midi(chip, 0)) < 0) { | 1912 err = snd_cs4281_midi(chip, 0); 1913 if (err < 0) { |
1899 snd_card_free(card); 1900 return err; 1901 } | 1914 snd_card_free(card); 1915 return err; 1916 } |
1902 if ((err = snd_opl3_new(card, OPL3_HW_OPL3_CS4281, &opl3)) < 0) { | 1917 err = snd_opl3_new(card, OPL3_HW_OPL3_CS4281, &opl3); 1918 if (err < 0) { |
1903 snd_card_free(card); 1904 return err; 1905 } 1906 opl3->private_data = chip; 1907 opl3->command = snd_cs4281_opl3_command; 1908 snd_opl3_init(opl3); | 1919 snd_card_free(card); 1920 return err; 1921 } 1922 opl3->private_data = chip; 1923 opl3->command = snd_cs4281_opl3_command; 1924 snd_opl3_init(opl3); |
1909 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { | 1925 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); 1926 if (err < 0) { |
1910 snd_card_free(card); 1911 return err; 1912 } 1913 snd_cs4281_create_gameport(chip); 1914 strcpy(card->driver, "CS4281"); 1915 strcpy(card->shortname, "Cirrus Logic CS4281"); 1916 sprintf(card->longname, "%s at 0x%lx, irq %d", 1917 card->shortname, 1918 chip->ba0_addr, 1919 chip->irq); 1920 | 1927 snd_card_free(card); 1928 return err; 1929 } 1930 snd_cs4281_create_gameport(chip); 1931 strcpy(card->driver, "CS4281"); 1932 strcpy(card->shortname, "Cirrus Logic CS4281"); 1933 sprintf(card->longname, "%s at 0x%lx, irq %d", 1934 card->shortname, 1935 chip->ba0_addr, 1936 chip->irq); 1937 |
1921 if ((err = snd_card_register(card)) < 0) { | 1938 err = snd_card_register(card); 1939 if (err < 0) { |
1922 snd_card_free(card); 1923 return err; 1924 } 1925 1926 pci_set_drvdata(pci, card); 1927 dev++; 1928 return 0; 1929} --- 116 unchanged lines hidden --- | 1940 snd_card_free(card); 1941 return err; 1942 } 1943 1944 pci_set_drvdata(pci, card); 1945 dev++; 1946 return 0; 1947} --- 116 unchanged lines hidden --- |