Changeset 679 for GPL/trunk/alsa-kernel/pci/rme9652/hdsp.c
- Timestamp:
- Mar 18, 2021, 8:57:36 PM (4 years ago)
- Location:
- GPL/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/trunk
- Property svn:mergeinfo changed
/GPL/branches/uniaud32-linux-3.2.102 (added) merged: 611-614 /GPL/branches/uniaud32-next (added) merged: 615-678
- Property svn:mergeinfo changed
-
GPL/trunk/alsa-kernel/pci/rme9652/hdsp.c
r598 r679 1 // SPDX-License-Identifier: GPL-2.0-or-later 1 2 /* 2 3 * ALSA driver for RME Hammerfall DSP audio interface(s) … … 5 6 * Marcus Andersson 6 7 * Thomas Charbonnel 7 *8 * This program is free software; you can redistribute it and/or modify9 * it under the terms of the GNU General Public License as published by10 * the Free Software Foundation; either version 2 of the License, or11 * (at your option) any later version.12 *13 * This program is distributed in the hope that it will be useful,14 * but WITHOUT ANY WARRANTY; without even the implied warranty of15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16 * GNU General Public License for more details.17 *18 * You should have received a copy of the GNU General Public License19 * along with this program; if not, write to the Free Software20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA21 *22 8 */ 23 9 … … 27 13 #include <linux/pci.h> 28 14 #include <linux/firmware.h> 29 #include <linux/module param.h>15 #include <linux/module.h> 30 16 #include <linux/math64.h> 17 #include <linux/vmalloc.h> 18 #include <linux/io.h> 19 #include <linux/nospec.h> 31 20 32 21 #include <sound/core.h> … … 42 31 #include <asm/byteorder.h> 43 32 #include <asm/current.h> 44 #include <asm/io.h>45 33 46 34 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 47 35 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 48 static intenable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */36 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 49 37 50 38 module_param_array(index, int, NULL, 0444); … … 60 48 "{RME HDSP-9652}," 61 49 "{RME HDSP-9632}}"); 62 #ifdef HDSP_FW_LOADER63 50 MODULE_FIRMWARE("rpm_firmware.bin"); 64 51 MODULE_FIRMWARE("multiface_firmware.bin"); … … 66 53 MODULE_FIRMWARE("digiface_firmware.bin"); 67 54 MODULE_FIRMWARE("digiface_firmware_rev11.bin"); 68 #endif69 55 70 56 #define HDSP_MAX_CHANNELS 26 … … 152 138 #define HDSP_CONFIG_MODE_0 0x040 153 139 #define HDSP_CONFIG_MODE_1 0x080 154 #define HDSP_VERSION_BIT 0x100140 #define HDSP_VERSION_BIT (0x100 | HDSP_S_LOAD) 155 141 #define HDSP_BIGENDIAN_MODE 0x200 156 142 #define HDSP_RD_MULTIPLE 0x400 157 143 #define HDSP_9652_ENABLE_MIXER 0x800 144 #define HDSP_S200 0x800 145 #define HDSP_S300 (0x100 | HDSP_S200) /* dummy, purpose of 0x100 unknown */ 146 #define HDSP_CYCLIC_MODE 0x1000 158 147 #define HDSP_TDO 0x10000000 159 148 160 #define HDSP_S_PROGRAM (HDSP_PROGRAM|HDSP_CONFIG_MODE_0)161 #define HDSP_S_LOAD (HDSP_PROGRAM|HDSP_CONFIG_MODE_1)149 #define HDSP_S_PROGRAM (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_0) 150 #define HDSP_S_LOAD (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_1) 162 151 163 152 /* Control Register bits */ … … 424 413 #define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024) 425 414 426 /* use hotplug firmware loader? */ 427 #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE) 428 #if !defined(HDSP_USE_HWDEP_LOADER) 429 #define HDSP_FW_LOADER 430 #endif 431 #endif 415 #define HDSP_FIRMWARE_SIZE (24413 * 4) 432 416 433 417 struct hdsp_9632_meters { … … 464 448 struct snd_pcm_substream *playback_substream; 465 449 struct hdsp_midi midi[2]; 466 struct tasklet_struct midi_tasklet;467 int use_midi_ tasklet;450 struct work_struct midi_work; 451 int use_midi_work; 468 452 int precise_ptr; 469 453 u32 control_register; /* cached value */ … … 476 460 unsigned short firmware_rev; 477 461 unsigned short state; /* stores state bits */ 478 u32 firmware_cache[24413]; /* this helps recover from accidental iobox power failure */ 462 const struct firmware *firmware; 463 u32 *fw_uploaded; 479 464 size_t period_bytes; /* guess what this is */ 480 465 unsigned char max_channels; … … 495 480 int running; 496 481 int system_sample_rate; 497 c har*channel_map;482 const char *channel_map; 498 483 int dev; 499 484 int irq; … … 517 502 */ 518 503 519 static c har channel_map_df_ss[HDSP_MAX_CHANNELS] = {504 static const char channel_map_df_ss[HDSP_MAX_CHANNELS] = { 520 505 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 521 506 18, 19, 20, 21, 22, 23, 24, 25 522 507 }; 523 508 524 static c har channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */509 static const char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */ 525 510 /* Analog */ 526 511 0, 1, 2, 3, 4, 5, 6, 7, … … 532 517 }; 533 518 534 static c har channel_map_ds[HDSP_MAX_CHANNELS] = {519 static const char channel_map_ds[HDSP_MAX_CHANNELS] = { 535 520 /* ADAT channels are remapped */ 536 521 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, … … 541 526 }; 542 527 543 static c har channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {528 static const char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = { 544 529 /* ADAT channels */ 545 530 0, 1, 2, 3, 4, 5, 6, 7, … … 555 540 }; 556 541 557 static c har channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {542 static const char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = { 558 543 /* ADAT */ 559 544 1, 3, 5, 7, … … 569 554 }; 570 555 571 static c har channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {556 static const char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = { 572 557 /* ADAT is disabled in this mode */ 573 558 /* SPDIF */ … … 585 570 static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size) 586 571 { 587 dmab->dev.type = SNDRV_DMA_TYPE_DEV; 588 dmab->dev.dev = snd_dma_pci_data(pci); 589 if (snd_dma_get_reserved_buf(dmab, snd_dma_pci_buf_id(pci))) { 590 if (dmab->bytes >= size) 591 return 0; 592 } 593 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 594 size, dmab) < 0) 595 return -ENOMEM; 596 return 0; 572 return snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, size, dmab); 597 573 } 598 574 599 575 static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci) 600 576 { 601 if (dmab->area) { 602 dmab->dev.dev = NULL; /* make it anonymous */ 603 snd_dma_reserve_buf(dmab, snd_dma_pci_buf_id(pci)); 604 } 605 } 606 607 608 static DEFINE_PCI_DEVICE_TABLE(snd_hdsp_ids) = { 577 if (dmab->area) 578 snd_dma_free_pages(dmab); 579 } 580 581 582 static const struct pci_device_id snd_hdsp_ids[] = { 609 583 { 610 584 .vendor = PCI_VENDOR_ID_XILINX, … … 677 651 static int hdsp_check_for_iobox (struct hdsp *hdsp) 678 652 { 653 int i; 654 679 655 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0; 680 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) { 681 snd_printk("Hammerfall-DSP: no IO box connected!\n"); 682 hdsp->state &= ~HDSP_FirmwareLoaded; 683 return -EIO; 684 } 685 return 0; 656 for (i = 0; i < 500; i++) { 657 if (0 == (hdsp_read(hdsp, HDSP_statusRegister) & 658 HDSP_ConfigError)) { 659 if (i) { 660 dev_dbg(hdsp->card->dev, 661 "IO box found after %d ms\n", 662 (20 * i)); 663 } 664 return 0; 665 } 666 msleep(20); 667 } 668 dev_err(hdsp->card->dev, "no IO box connected!\n"); 669 hdsp->state &= ~HDSP_FirmwareLoaded; 670 return -EIO; 686 671 } 687 672 … … 698 683 msleep(delay); 699 684 else { 700 snd_printd("Hammerfall-DSP:iobox found after %ums!\n",685 dev_dbg(hdsp->card->dev, "iobox found after %ums!\n", 701 686 i * delay); 702 687 return 0; … … 704 689 } 705 690 706 snd_printk("Hammerfall-DSP:no IO box connected!\n");691 dev_info(hdsp->card->dev, "no IO box connected!\n"); 707 692 hdsp->state &= ~HDSP_FirmwareLoaded; 708 693 return -EIO; … … 713 698 int i; 714 699 unsigned long flags; 700 const u32 *cache; 701 702 if (hdsp->fw_uploaded) 703 cache = hdsp->fw_uploaded; 704 else { 705 if (!hdsp->firmware) 706 return -ENODEV; 707 cache = (u32 *)hdsp->firmware->data; 708 if (!cache) 709 return -ENODEV; 710 } 715 711 716 712 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 717 713 718 snd_printk ("Hammerfall-DSP:loading firmware\n");714 dev_info(hdsp->card->dev, "loading firmware\n"); 719 715 720 716 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM); … … 722 718 723 719 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) { 724 snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n"); 720 dev_info(hdsp->card->dev, 721 "timeout waiting for download preparation\n"); 722 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200); 725 723 return -EIO; 726 724 } … … 728 726 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD); 729 727 730 for (i = 0; i < 24413; ++i) {731 hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);728 for (i = 0; i < HDSP_FIRMWARE_SIZE / 4; ++i) { 729 hdsp_write(hdsp, HDSP_fifoData, cache[i]); 732 730 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) { 733 snd_printk ("Hammerfall-DSP: timeout during firmware loading\n"); 731 dev_info(hdsp->card->dev, 732 "timeout during firmware loading\n"); 733 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200); 734 734 return -EIO; 735 735 } 736 736 } 737 737 738 hdsp_fifo_wait(hdsp, 3, HDSP_LONG_WAIT); 739 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200); 740 738 741 ssleep(3); 739 740 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {741 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n");742 return -EIO;743 }744 745 742 #ifdef SNDRV_BIG_ENDIAN 746 743 hdsp->control2_register = HDSP_BIGENDIAN_MODE; … … 749 746 #endif 750 747 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register); 751 snd_printk ("Hammerfall-DSP:finished firmware loading\n");748 dev_info(hdsp->card->dev, "finished firmware loading\n"); 752 749 753 750 } 754 751 if (hdsp->state & HDSP_InitializationComplete) { 755 snd_printk(KERN_INFO "Hammerfall-DSP: firmware loaded from cache, restoring defaults\n"); 752 dev_info(hdsp->card->dev, 753 "firmware loaded from cache, restoring defaults\n"); 756 754 spin_lock_irqsave(&hdsp->lock, flags); 757 755 snd_hdsp_set_defaults(hdsp); … … 768 766 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 769 767 770 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM); 768 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD); 769 hdsp_write(hdsp, HDSP_fifoData, 0); 770 771 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) { 772 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300); 773 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD); 774 } 775 776 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200 | HDSP_PROGRAM); 771 777 hdsp_write (hdsp, HDSP_fifoData, 0); 772 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) 773 return -EIO; 774 775 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD); 776 hdsp_write (hdsp, HDSP_fifoData, 0); 777 778 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT)) { 779 hdsp_write(hdsp, HDSP_control2Reg, HDSP_VERSION_BIT); 780 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD); 781 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT)) 782 hdsp->io_type = RPM; 783 else 784 hdsp->io_type = Multiface; 785 } else { 778 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) 779 goto set_multi; 780 781 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD); 782 hdsp_write(hdsp, HDSP_fifoData, 0); 783 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) { 786 784 hdsp->io_type = Digiface; 785 dev_info(hdsp->card->dev, "Digiface found\n"); 786 return 0; 787 787 } 788 789 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300); 790 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD); 791 hdsp_write(hdsp, HDSP_fifoData, 0); 792 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) 793 goto set_multi; 794 795 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300); 796 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD); 797 hdsp_write(hdsp, HDSP_fifoData, 0); 798 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) 799 goto set_multi; 800 801 hdsp->io_type = RPM; 802 dev_info(hdsp->card->dev, "RPM found\n"); 803 return 0; 788 804 } else { 789 805 /* firmware was already loaded, get iobox type */ … … 796 812 } 797 813 return 0; 798 } 799 800 801 #ifdef HDSP_FW_LOADER 814 815 set_multi: 816 hdsp->io_type = Multiface; 817 dev_info(hdsp->card->dev, "Multiface found\n"); 818 return 0; 819 } 820 821 802 822 static int hdsp_request_fw_loader(struct hdsp *hdsp); 803 #endif804 823 805 824 static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand) … … 811 830 if (! load_on_demand) 812 831 return -EIO; 813 snd_printk(KERN_ERR "Hammerfall-DSP:firmware not present.\n");832 dev_err(hdsp->card->dev, "firmware not present.\n"); 814 833 /* try to load firmware */ 815 834 if (! (hdsp->state & HDSP_FirmwareCached)) { 816 #ifdef HDSP_FW_LOADER817 835 if (! hdsp_request_fw_loader(hdsp)) 818 836 return 0; 819 #endif 820 snd_printk(KERN_ERR 821 "Hammerfall-DSP: No firmware loaded nor " 822 "cached, please upload firmware.\n"); 837 dev_err(hdsp->card->dev, 838 "No firmware loaded nor cached, please upload firmware.\n"); 823 839 return -EIO; 824 840 } 825 841 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) { 826 snd_printk(KERN_ERR 827 "Hammerfall-DSP: Firmware loading from " 828 "cache failed, please upload manually.\n"); 842 dev_err(hdsp->card->dev, 843 "Firmware loading from cache failed, please upload manually.\n"); 829 844 return -EIO; 830 845 } … … 854 869 } 855 870 856 snd_printk ("Hammerfall-DSP: wait for FIFO status <= %d failed after %d iterations\n", 871 dev_warn(hdsp->card->dev, 872 "wait for FIFO status <= %d failed after %d iterations\n", 857 873 count, timeout); 858 874 return -1; … … 971 987 break; 972 988 } 973 snd_printk ("Hammerfall-DSP: unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status); 989 dev_warn(hdsp->card->dev, 990 "unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", 991 rate_bits, status); 974 992 return 0; 975 993 } … … 1105 1123 if (called_internally) { 1106 1124 /* request from ctl or card initialization */ 1107 snd_printk(KERN_ERR "Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n"); 1125 dev_err(hdsp->card->dev, 1126 "device is not running as a clock master: cannot set sample rate.\n"); 1108 1127 return -1; 1109 1128 } else { … … 1113 1132 1114 1133 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) 1115 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in double speed mode\n"); 1134 dev_info(hdsp->card->dev, 1135 "Detected ADAT in double speed mode\n"); 1116 1136 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) 1117 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in quad speed mode\n"); 1137 dev_info(hdsp->card->dev, 1138 "Detected ADAT in quad speed mode\n"); 1118 1139 else if (rate != external_freq) { 1119 snd_printk(KERN_INFO "Hammerfall-DSP: No AutoSync source for requested rate\n"); 1140 dev_info(hdsp->card->dev, 1141 "No AutoSync source for requested rate\n"); 1120 1142 return -1; 1121 1143 } … … 1189 1211 1190 1212 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) { 1191 snd_printk ("Hammerfall-DSP: cannot change speed mode (capture PID = %d, playback PID = %d)\n", 1213 dev_warn(hdsp->card->dev, 1214 "cannot change speed mode (capture PID = %d, playback PID = %d)\n", 1192 1215 hdsp->capture_pid, 1193 1216 hdsp->playback_pid); … … 1363 1386 } else { 1364 1387 hdsp->control_register &= ~ie; 1365 tasklet_kill(&hdsp->midi_tasklet);1366 1388 } 1367 1389 … … 1370 1392 } 1371 1393 1372 static void snd_hdsp_midi_output_timer( unsigned long data)1373 { 1374 struct hdsp_midi *hmidi = (struct hdsp_midi *) data;1394 static void snd_hdsp_midi_output_timer(struct timer_list *t) 1395 { 1396 struct hdsp_midi *hmidi = from_timer(hmidi, t, timer); 1375 1397 unsigned long flags; 1376 1398 … … 1384 1406 */ 1385 1407 1386 if (hmidi->istimer) { 1387 hmidi->timer.expires = 1 + jiffies; 1388 add_timer(&hmidi->timer); 1389 } 1408 if (hmidi->istimer) 1409 mod_timer(&hmidi->timer, 1 + jiffies); 1390 1410 1391 1411 spin_unlock_irqrestore (&hmidi->lock, flags); … … 1401 1421 if (up) { 1402 1422 if (!hmidi->istimer) { 1403 init_timer(&hmidi->timer); 1404 hmidi->timer.function = snd_hdsp_midi_output_timer; 1405 hmidi->timer.data = (unsigned long) hmidi; 1406 hmidi->timer.expires = 1 + jiffies; 1407 add_timer(&hmidi->timer); 1423 timer_setup(&hmidi->timer, snd_hdsp_midi_output_timer, 1424 0); 1425 mod_timer(&hmidi->timer, 1 + jiffies); 1408 1426 hmidi->istimer++; 1409 1427 } … … 1470 1488 } 1471 1489 1472 static struct snd_rawmidi_ops snd_hdsp_midi_output =1490 static const struct snd_rawmidi_ops snd_hdsp_midi_output = 1473 1491 { 1474 1492 .open = snd_hdsp_midi_output_open, … … 1477 1495 }; 1478 1496 1479 static struct snd_rawmidi_ops snd_hdsp_midi_input =1497 static const struct snd_rawmidi_ops snd_hdsp_midi_input = 1480 1498 { 1481 1499 .open = snd_hdsp_midi_input_open, … … 1486 1504 static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int id) 1487 1505 { 1488 char buf[ 32];1506 char buf[40]; 1489 1507 1490 1508 hdsp->midi[id].id = id; … … 1497 1515 spin_lock_init (&hdsp->midi[id].lock); 1498 1516 1499 s printf (buf, "%s MIDI %d", card->shortname, id+1);1517 snprintf(buf, sizeof(buf), "%s MIDI %d", card->shortname, id + 1); 1500 1518 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0) 1501 1519 return -1; … … 1636 1654 static int snd_hdsp_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1637 1655 { 1638 static char *texts[4] = {"Optical", "Coaxial", "Internal", "AES"}; 1656 static const char * const texts[4] = { 1657 "Optical", "Coaxial", "Internal", "AES" 1658 }; 1639 1659 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1640 1660 1641 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1642 uinfo->count = 1; 1643 uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3); 1644 if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2)) 1645 uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2); 1646 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1647 return 0; 1661 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 4 : 3, 1662 texts); 1648 1663 } 1649 1664 … … 1673 1688 } 1674 1689 1675 #define HDSP_SPDIF_OUT(xname, xindex) \ 1676 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 1677 .info = snd_hdsp_info_spdif_bits, \ 1678 .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out } 1679 1680 static int hdsp_spdif_out(struct hdsp *hdsp) 1681 { 1682 return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0; 1683 } 1684 1685 static int hdsp_set_spdif_output(struct hdsp *hdsp, int out) 1690 #define HDSP_TOGGLE_SETTING(xname, xindex) \ 1691 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 1692 .name = xname, \ 1693 .private_value = xindex, \ 1694 .info = snd_hdsp_info_toggle_setting, \ 1695 .get = snd_hdsp_get_toggle_setting, \ 1696 .put = snd_hdsp_put_toggle_setting \ 1697 } 1698 1699 static int hdsp_toggle_setting(struct hdsp *hdsp, u32 regmask) 1700 { 1701 return (hdsp->control_register & regmask) ? 1 : 0; 1702 } 1703 1704 static int hdsp_set_toggle_setting(struct hdsp *hdsp, u32 regmask, int out) 1686 1705 { 1687 1706 if (out) 1688 hdsp->control_register |= HDSP_SPDIFOpticalOut;1707 hdsp->control_register |= regmask; 1689 1708 else 1690 hdsp->control_register &= ~ HDSP_SPDIFOpticalOut;1709 hdsp->control_register &= ~regmask; 1691 1710 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1692 return 0; 1693 } 1694 1695 #define snd_hdsp_info_spdif_bits snd_ctl_boolean_mono_info 1696 1697 static int snd_hdsp_get_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1711 1712 return 0; 1713 } 1714 1715 #define snd_hdsp_info_toggle_setting snd_ctl_boolean_mono_info 1716 1717 static int snd_hdsp_get_toggle_setting(struct snd_kcontrol *kcontrol, 1718 struct snd_ctl_elem_value *ucontrol) 1698 1719 { 1699 1720 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1700 1701 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp); 1702 return 0; 1703 } 1704 1705 static int snd_hdsp_put_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1721 u32 regmask = kcontrol->private_value; 1722 1723 spin_lock_irq(&hdsp->lock); 1724 ucontrol->value.integer.value[0] = hdsp_toggle_setting(hdsp, regmask); 1725 spin_unlock_irq(&hdsp->lock); 1726 return 0; 1727 } 1728 1729 static int snd_hdsp_put_toggle_setting(struct snd_kcontrol *kcontrol, 1730 struct snd_ctl_elem_value *ucontrol) 1706 1731 { 1707 1732 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1733 u32 regmask = kcontrol->private_value; 1708 1734 int change; 1709 1735 unsigned int val; … … 1713 1739 val = ucontrol->value.integer.value[0] & 1; 1714 1740 spin_lock_irq(&hdsp->lock); 1715 change = (int)val != hdsp_spdif_out(hdsp); 1716 hdsp_set_spdif_output(hdsp, val); 1717 spin_unlock_irq(&hdsp->lock); 1718 return change; 1719 } 1720 1721 #define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \ 1722 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 1723 .info = snd_hdsp_info_spdif_bits, \ 1724 .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional } 1725 1726 static int hdsp_spdif_professional(struct hdsp *hdsp) 1727 { 1728 return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0; 1729 } 1730 1731 static int hdsp_set_spdif_professional(struct hdsp *hdsp, int val) 1732 { 1733 if (val) 1734 hdsp->control_register |= HDSP_SPDIFProfessional; 1735 else 1736 hdsp->control_register &= ~HDSP_SPDIFProfessional; 1737 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1738 return 0; 1739 } 1740 1741 static int snd_hdsp_get_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1742 { 1743 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1744 1745 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp); 1746 return 0; 1747 } 1748 1749 static int snd_hdsp_put_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1750 { 1751 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1752 int change; 1753 unsigned int val; 1754 1755 if (!snd_hdsp_use_is_exclusive(hdsp)) 1756 return -EBUSY; 1757 val = ucontrol->value.integer.value[0] & 1; 1758 spin_lock_irq(&hdsp->lock); 1759 change = (int)val != hdsp_spdif_professional(hdsp); 1760 hdsp_set_spdif_professional(hdsp, val); 1761 spin_unlock_irq(&hdsp->lock); 1762 return change; 1763 } 1764 1765 #define HDSP_SPDIF_EMPHASIS(xname, xindex) \ 1766 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 1767 .info = snd_hdsp_info_spdif_bits, \ 1768 .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis } 1769 1770 static int hdsp_spdif_emphasis(struct hdsp *hdsp) 1771 { 1772 return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0; 1773 } 1774 1775 static int hdsp_set_spdif_emphasis(struct hdsp *hdsp, int val) 1776 { 1777 if (val) 1778 hdsp->control_register |= HDSP_SPDIFEmphasis; 1779 else 1780 hdsp->control_register &= ~HDSP_SPDIFEmphasis; 1781 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1782 return 0; 1783 } 1784 1785 static int snd_hdsp_get_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1786 { 1787 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1788 1789 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp); 1790 return 0; 1791 } 1792 1793 static int snd_hdsp_put_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1794 { 1795 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1796 int change; 1797 unsigned int val; 1798 1799 if (!snd_hdsp_use_is_exclusive(hdsp)) 1800 return -EBUSY; 1801 val = ucontrol->value.integer.value[0] & 1; 1802 spin_lock_irq(&hdsp->lock); 1803 change = (int)val != hdsp_spdif_emphasis(hdsp); 1804 hdsp_set_spdif_emphasis(hdsp, val); 1805 spin_unlock_irq(&hdsp->lock); 1806 return change; 1807 } 1808 1809 #define HDSP_SPDIF_NON_AUDIO(xname, xindex) \ 1810 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 1811 .info = snd_hdsp_info_spdif_bits, \ 1812 .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio } 1813 1814 static int hdsp_spdif_nonaudio(struct hdsp *hdsp) 1815 { 1816 return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0; 1817 } 1818 1819 static int hdsp_set_spdif_nonaudio(struct hdsp *hdsp, int val) 1820 { 1821 if (val) 1822 hdsp->control_register |= HDSP_SPDIFNonAudio; 1823 else 1824 hdsp->control_register &= ~HDSP_SPDIFNonAudio; 1825 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1826 return 0; 1827 } 1828 1829 static int snd_hdsp_get_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1830 { 1831 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1832 1833 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp); 1834 return 0; 1835 } 1836 1837 static int snd_hdsp_put_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1838 { 1839 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1840 int change; 1841 unsigned int val; 1842 1843 if (!snd_hdsp_use_is_exclusive(hdsp)) 1844 return -EBUSY; 1845 val = ucontrol->value.integer.value[0] & 1; 1846 spin_lock_irq(&hdsp->lock); 1847 change = (int)val != hdsp_spdif_nonaudio(hdsp); 1848 hdsp_set_spdif_nonaudio(hdsp, val); 1741 change = (int) val != hdsp_toggle_setting(hdsp, regmask); 1742 if (change) 1743 hdsp_set_toggle_setting(hdsp, regmask, val); 1849 1744 spin_unlock_irq(&hdsp->lock); 1850 1745 return change; … … 1862 1757 static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1863 1758 { 1864 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"}; 1759 static const char * const texts[] = { 1760 "32000", "44100", "48000", "64000", "88200", "96000", 1761 "None", "128000", "176400", "192000" 1762 }; 1865 1763 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1866 1764 1867 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1868 uinfo->count = 1; 1869 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7; 1870 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 1871 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 1872 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1873 return 0; 1765 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7, 1766 texts); 1874 1767 } 1875 1768 … … 1948 1841 { 1949 1842 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1950 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"}; 1951 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1952 uinfo->count = 1; 1953 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ; 1954 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 1955 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 1956 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1957 return 0; 1843 static const char * const texts[] = { 1844 "32000", "44100", "48000", "64000", "88200", "96000", 1845 "None", "128000", "176400", "192000" 1846 }; 1847 1848 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7, 1849 texts); 1958 1850 } 1959 1851 … … 2016 1908 static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2017 1909 { 2018 static char *texts[] = {"Master", "Slave" }; 2019 2020 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2021 uinfo->count = 1; 2022 uinfo->value.enumerated.items = 2; 2023 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2024 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2025 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2026 return 0; 1910 static const char * const texts[] = {"Master", "Slave" }; 1911 1912 return snd_ctl_enum_info(uinfo, 1, 2, texts); 2027 1913 } 2028 1914 … … 2125 2011 static int snd_hdsp_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2126 2012 { 2127 static char *texts[] = {"AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz", "Internal 192.0 KHz" }; 2013 static const char * const texts[] = { 2014 "AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", 2015 "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", 2016 "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz", 2017 "Internal 192.0 KHz" 2018 }; 2128 2019 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2129 2020 2130 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2131 uinfo->count = 1; 2132 if (hdsp->io_type == H9632) 2133 uinfo->value.enumerated.items = 10; 2134 else 2135 uinfo->value.enumerated.items = 7; 2136 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2137 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2138 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2139 return 0; 2021 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7, 2022 texts); 2140 2023 } 2141 2024 … … 2241 2124 static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2242 2125 { 2243 static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"}; 2244 2245 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2246 uinfo->count = 1; 2247 uinfo->value.enumerated.items = 3; 2248 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2249 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2250 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2251 return 0; 2126 static const char * const texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"}; 2127 2128 return snd_ctl_enum_info(uinfo, 1, 3, texts); 2252 2129 } 2253 2130 … … 2326 2203 static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2327 2204 { 2328 static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"}; 2329 2330 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2331 uinfo->count = 1; 2332 uinfo->value.enumerated.items = 3; 2333 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2334 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2335 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2336 return 0; 2205 static const char * const texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"}; 2206 2207 return snd_ctl_enum_info(uinfo, 1, 3, texts); 2337 2208 } 2338 2209 … … 2411 2282 static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2412 2283 { 2413 static char *texts[] = {"0 dB", "-6 dB", "-12 dB"}; 2414 2415 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2416 uinfo->count = 1; 2417 uinfo->value.enumerated.items = 3; 2418 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2419 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2420 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2421 return 0; 2284 static const char * const texts[] = {"0 dB", "-6 dB", "-12 dB"}; 2285 2286 return snd_ctl_enum_info(uinfo, 1, 3, texts); 2422 2287 } 2423 2288 … … 2446 2311 else 2447 2312 change = 0; 2448 spin_unlock_irq(&hdsp->lock);2449 return change;2450 }2451 2452 #define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \2453 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \2454 .name = xname, \2455 .index = xindex, \2456 .info = snd_hdsp_info_xlr_breakout_cable, \2457 .get = snd_hdsp_get_xlr_breakout_cable, \2458 .put = snd_hdsp_put_xlr_breakout_cable \2459 }2460 2461 static int hdsp_xlr_breakout_cable(struct hdsp *hdsp)2462 {2463 if (hdsp->control_register & HDSP_XLRBreakoutCable)2464 return 1;2465 return 0;2466 }2467 2468 static int hdsp_set_xlr_breakout_cable(struct hdsp *hdsp, int mode)2469 {2470 if (mode)2471 hdsp->control_register |= HDSP_XLRBreakoutCable;2472 else2473 hdsp->control_register &= ~HDSP_XLRBreakoutCable;2474 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);2475 return 0;2476 }2477 2478 #define snd_hdsp_info_xlr_breakout_cable snd_ctl_boolean_mono_info2479 2480 static int snd_hdsp_get_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)2481 {2482 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);2483 2484 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);2485 return 0;2486 }2487 2488 static int snd_hdsp_put_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)2489 {2490 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);2491 int change;2492 int val;2493 2494 if (!snd_hdsp_use_is_exclusive(hdsp))2495 return -EBUSY;2496 val = ucontrol->value.integer.value[0] & 1;2497 spin_lock_irq(&hdsp->lock);2498 change = (int)val != hdsp_xlr_breakout_cable(hdsp);2499 hdsp_set_xlr_breakout_cable(hdsp, val);2500 spin_unlock_irq(&hdsp->lock);2501 return change;2502 }2503 2504 /* (De)activates old RME Analog Extension Board2505 These are connected to the internal ADAT connector2506 Switching this on desactivates external ADAT2507 */2508 #define HDSP_AEB(xname, xindex) \2509 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \2510 .name = xname, \2511 .index = xindex, \2512 .info = snd_hdsp_info_aeb, \2513 .get = snd_hdsp_get_aeb, \2514 .put = snd_hdsp_put_aeb \2515 }2516 2517 static int hdsp_aeb(struct hdsp *hdsp)2518 {2519 if (hdsp->control_register & HDSP_AnalogExtensionBoard)2520 return 1;2521 return 0;2522 }2523 2524 static int hdsp_set_aeb(struct hdsp *hdsp, int mode)2525 {2526 if (mode)2527 hdsp->control_register |= HDSP_AnalogExtensionBoard;2528 else2529 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;2530 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);2531 return 0;2532 }2533 2534 #define snd_hdsp_info_aeb snd_ctl_boolean_mono_info2535 2536 static int snd_hdsp_get_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)2537 {2538 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);2539 2540 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);2541 return 0;2542 }2543 2544 static int snd_hdsp_put_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)2545 {2546 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);2547 int change;2548 int val;2549 2550 if (!snd_hdsp_use_is_exclusive(hdsp))2551 return -EBUSY;2552 val = ucontrol->value.integer.value[0] & 1;2553 spin_lock_irq(&hdsp->lock);2554 change = (int)val != hdsp_aeb(hdsp);2555 hdsp_set_aeb(hdsp, val);2556 2313 spin_unlock_irq(&hdsp->lock); 2557 2314 return change; … … 2623 2380 static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2624 2381 { 2625 static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" }; 2382 static const char * const texts[] = { 2383 "Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" 2384 }; 2626 2385 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2627 2628 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2629 uinfo->count = 1; 2386 int num_items; 2630 2387 2631 2388 switch (hdsp->io_type) { 2632 2389 case Digiface: 2633 2390 case H9652: 2634 uinfo->value.enumerated.items = 6;2391 num_items = 6; 2635 2392 break; 2636 2393 case Multiface: 2637 uinfo->value.enumerated.items = 4;2394 num_items = 4; 2638 2395 break; 2639 2396 case H9632: 2640 uinfo->value.enumerated.items = 3;2397 num_items = 3; 2641 2398 break; 2642 2399 default: 2643 uinfo->value.enumerated.items = 0; 2644 break; 2645 } 2646 2647 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2648 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2649 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2650 return 0; 2400 return -EINVAL; 2401 } 2402 2403 return snd_ctl_enum_info(uinfo, 1, num_items, texts); 2651 2404 } 2652 2405 … … 2728 2481 static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2729 2482 { 2730 static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" }; 2731 2732 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2733 uinfo->count = 1; 2734 uinfo->value.enumerated.items = 7; 2735 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2736 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2737 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2738 return 0; 2483 static const char * const texts[] = { 2484 "Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" 2485 }; 2486 2487 return snd_ctl_enum_info(uinfo, 1, 7, texts); 2739 2488 } 2740 2489 … … 2745 2494 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp); 2746 2495 return 0; 2747 }2748 2749 #define HDSP_LINE_OUT(xname, xindex) \2750 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \2751 .name = xname, \2752 .index = xindex, \2753 .info = snd_hdsp_info_line_out, \2754 .get = snd_hdsp_get_line_out, \2755 .put = snd_hdsp_put_line_out \2756 }2757 2758 static int hdsp_line_out(struct hdsp *hdsp)2759 {2760 return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;2761 }2762 2763 static int hdsp_set_line_output(struct hdsp *hdsp, int out)2764 {2765 if (out)2766 hdsp->control_register |= HDSP_LineOut;2767 else2768 hdsp->control_register &= ~HDSP_LineOut;2769 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);2770 return 0;2771 }2772 2773 #define snd_hdsp_info_line_out snd_ctl_boolean_mono_info2774 2775 static int snd_hdsp_get_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)2776 {2777 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);2778 2779 spin_lock_irq(&hdsp->lock);2780 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);2781 spin_unlock_irq(&hdsp->lock);2782 return 0;2783 }2784 2785 static int snd_hdsp_put_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)2786 {2787 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);2788 int change;2789 unsigned int val;2790 2791 if (!snd_hdsp_use_is_exclusive(hdsp))2792 return -EBUSY;2793 val = ucontrol->value.integer.value[0] & 1;2794 spin_lock_irq(&hdsp->lock);2795 change = (int)val != hdsp_line_out(hdsp);2796 hdsp_set_line_output(hdsp, val);2797 spin_unlock_irq(&hdsp->lock);2798 return change;2799 2496 } 2800 2497 … … 2845 2542 } 2846 2543 2847 #define HDSP_USE_MIDI_ TASKLET(xname, xindex) \2544 #define HDSP_USE_MIDI_WORK(xname, xindex) \ 2848 2545 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \ 2849 2546 .name = xname, \ 2850 2547 .index = xindex, \ 2851 .info = snd_hdsp_info_use_midi_ tasklet, \2852 .get = snd_hdsp_get_use_midi_ tasklet, \2853 .put = snd_hdsp_put_use_midi_ tasklet\2854 } 2855 2856 static int hdsp_set_use_midi_ tasklet(struct hdsp *hdsp, int use_tasklet)2857 { 2858 if (use_ tasklet)2859 hdsp->use_midi_ tasklet= 1;2548 .info = snd_hdsp_info_use_midi_work, \ 2549 .get = snd_hdsp_get_use_midi_work, \ 2550 .put = snd_hdsp_put_use_midi_work \ 2551 } 2552 2553 static int hdsp_set_use_midi_work(struct hdsp *hdsp, int use_work) 2554 { 2555 if (use_work) 2556 hdsp->use_midi_work = 1; 2860 2557 else 2861 hdsp->use_midi_ tasklet= 0;2862 return 0; 2863 } 2864 2865 #define snd_hdsp_info_use_midi_ taskletsnd_ctl_boolean_mono_info2866 2867 static int snd_hdsp_get_use_midi_ tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)2558 hdsp->use_midi_work = 0; 2559 return 0; 2560 } 2561 2562 #define snd_hdsp_info_use_midi_work snd_ctl_boolean_mono_info 2563 2564 static int snd_hdsp_get_use_midi_work(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2868 2565 { 2869 2566 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2870 2567 2871 2568 spin_lock_irq(&hdsp->lock); 2872 ucontrol->value.integer.value[0] = hdsp->use_midi_ tasklet;2569 ucontrol->value.integer.value[0] = hdsp->use_midi_work; 2873 2570 spin_unlock_irq(&hdsp->lock); 2874 2571 return 0; 2875 2572 } 2876 2573 2877 static int snd_hdsp_put_use_midi_ tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)2574 static int snd_hdsp_put_use_midi_work(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2878 2575 { 2879 2576 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); … … 2885 2582 val = ucontrol->value.integer.value[0] & 1; 2886 2583 spin_lock_irq(&hdsp->lock); 2887 change = (int)val != hdsp->use_midi_ tasklet;2888 hdsp_set_use_midi_ tasklet(hdsp, val);2584 change = (int)val != hdsp->use_midi_work; 2585 hdsp_set_use_midi_work(hdsp, val); 2889 2586 spin_unlock_irq(&hdsp->lock); 2890 2587 return change; … … 2975 2672 static int snd_hdsp_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2976 2673 { 2977 static char *texts[] = {"No Lock", "Lock", "Sync" }; 2978 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2979 uinfo->count = 1; 2980 uinfo->value.enumerated.items = 3; 2981 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2982 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2983 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2984 return 0; 2674 static const char * const texts[] = {"No Lock", "Lock", "Sync" }; 2675 2676 return snd_ctl_enum_info(uinfo, 1, 3, texts); 2985 2677 } 2986 2678 … … 3092 2784 3093 2785 offset = ucontrol->id.index - 1; 3094 snd_BUG_ON(offset < 0); 2786 if (snd_BUG_ON(offset < 0)) 2787 return -EINVAL; 3095 2788 3096 2789 switch (hdsp->io_type) { … … 3164 2857 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 3165 2858 3166 ucontrol->value. enumerated.item[0] = hdsp_dds_offset(hdsp);2859 ucontrol->value.integer.value[0] = hdsp_dds_offset(hdsp); 3167 2860 return 0; 3168 2861 } … … 3176 2869 if (!snd_hdsp_use_is_exclusive(hdsp)) 3177 2870 return -EBUSY; 3178 val = ucontrol->value. enumerated.item[0];2871 val = ucontrol->value.integer.value[0]; 3179 2872 spin_lock_irq(&hdsp->lock); 3180 2873 if (val != hdsp_dds_offset(hdsp)) … … 3186 2879 } 3187 2880 3188 static struct snd_kcontrol_new snd_hdsp_9632_controls[] = {2881 static const struct snd_kcontrol_new snd_hdsp_9632_controls[] = { 3189 2882 HDSP_DA_GAIN("DA Gain", 0), 3190 2883 HDSP_AD_GAIN("AD Gain", 0), 3191 2884 HDSP_PHONE_GAIN("Phones Gain", 0), 3192 HDSP_ XLR_BREAKOUT_CABLE("XLR Breakout Cable", 0),2885 HDSP_TOGGLE_SETTING("XLR Breakout Cable", HDSP_XLRBreakoutCable), 3193 2886 HDSP_DDS_OFFSET("DDS Sample Rate Offset", 0) 3194 2887 }; 3195 2888 3196 static struct snd_kcontrol_new snd_hdsp_controls[] = {2889 static const struct snd_kcontrol_new snd_hdsp_controls[] = { 3197 2890 { 3198 2891 .iface = SNDRV_CTL_ELEM_IFACE_PCM, … … 3232 2925 HDSP_MIXER("Mixer", 0), 3233 2926 HDSP_SPDIF_IN("IEC958 Input Connector", 0), 3234 HDSP_ SPDIF_OUT("IEC958 Output also on ADAT1", 0),3235 HDSP_ SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),3236 HDSP_ SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),3237 HDSP_ SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),2927 HDSP_TOGGLE_SETTING("IEC958 Output also on ADAT1", HDSP_SPDIFOpticalOut), 2928 HDSP_TOGGLE_SETTING("IEC958 Professional Bit", HDSP_SPDIFProfessional), 2929 HDSP_TOGGLE_SETTING("IEC958 Emphasis Bit", HDSP_SPDIFEmphasis), 2930 HDSP_TOGGLE_SETTING("IEC958 Non-audio Bit", HDSP_SPDIFNonAudio), 3238 2931 /* 'Sample Clock Source' complies with the alsa control naming scheme */ 3239 2932 HDSP_CLOCK_SOURCE("Sample Clock Source", 0), … … 3255 2948 HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0), 3256 2949 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0), 3257 HDSP_ LINE_OUT("Line Out", 0),2950 HDSP_TOGGLE_SETTING("Line Out", HDSP_LineOut), 3258 2951 HDSP_PRECISE_POINTER("Precise Pointer", 0), 3259 HDSP_USE_MIDI_ TASKLET("Use Midi Tasklet", 0),2952 HDSP_USE_MIDI_WORK("Use Midi Tasklet", 0), 3260 2953 }; 3261 2954 … … 3338 3031 static int snd_hdsp_info_rpm_input(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 3339 3032 { 3340 static char *texts[] = {"Phono +6dB", "Phono 0dB", "Phono -6dB", "Line 0dB", "Line -6dB"}; 3341 3342 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 3343 uinfo->count = 1; 3344 uinfo->value.enumerated.items = 5; 3345 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 3346 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 3347 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 3348 return 0; 3033 static const char * const texts[] = { 3034 "Phono +6dB", "Phono 0dB", "Phono -6dB", "Line 0dB", "Line -6dB" 3035 }; 3036 3037 return snd_ctl_enum_info(uinfo, 1, 5, texts); 3349 3038 } 3350 3039 … … 3471 3160 static int snd_hdsp_info_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 3472 3161 { 3473 static char *texts[] = {"On", "Off"}; 3474 3475 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 3476 uinfo->count = 1; 3477 uinfo->value.enumerated.items = 2; 3478 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 3479 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 3480 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 3481 return 0; 3162 static const char * const texts[] = {"On", "Off"}; 3163 3164 return snd_ctl_enum_info(uinfo, 1, 2, texts); 3482 3165 } 3483 3166 … … 3528 3211 static int snd_hdsp_info_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 3529 3212 { 3530 static char *texts[] = {"On", "Off"}; 3531 3532 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 3533 uinfo->count = 1; 3534 uinfo->value.enumerated.items = 2; 3535 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 3536 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 3537 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 3538 return 0; 3539 } 3540 3541 static struct snd_kcontrol_new snd_hdsp_rpm_controls[] = { 3213 static const char * const texts[] = {"On", "Off"}; 3214 3215 return snd_ctl_enum_info(uinfo, 1, 2, texts); 3216 } 3217 3218 static const struct snd_kcontrol_new snd_hdsp_rpm_controls[] = { 3542 3219 { 3543 3220 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, … … 3572 3249 }; 3573 3250 3574 static struct snd_kcontrol_new snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0); 3251 static const struct snd_kcontrol_new snd_hdsp_96xx_aeb = 3252 HDSP_TOGGLE_SETTING("Analog Extension Board", 3253 HDSP_AnalogExtensionBoard); 3575 3254 static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK; 3576 3255 … … 3674 3353 } 3675 3354 } else { 3676 int err = -EINVAL;3677 #ifdef HDSP_FW_LOADER 3355 int err; 3356 3678 3357 err = hdsp_request_fw_loader(hdsp); 3679 #endif3680 3358 if (err < 0) { 3681 3359 snd_iprintf(buffer, … … 3692 3370 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1)); 3693 3371 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1)); 3694 snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_ tasklet? "on" : "off");3372 snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_work ? "on" : "off"); 3695 3373 3696 3374 snd_iprintf(buffer, "\n"); … … 3997 3675 snd_iprintf(buffer, "Phones Gain : %s\n", tmp); 3998 3676 3999 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no"); 3677 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", 3678 hdsp_toggle_setting(hdsp, HDSP_XLRBreakoutCable) ? 3679 "yes" : "no"); 4000 3680 4001 3681 if (hdsp->control_register & HDSP_AnalogExtensionBoard) … … 4010 3690 static void snd_hdsp_proc_init(struct hdsp *hdsp) 4011 3691 { 4012 struct snd_info_entry *entry; 4013 4014 if (! snd_card_proc_new(hdsp->card, "hdsp", &entry)) 4015 snd_info_set_text_ops(entry, hdsp, snd_hdsp_proc_read); 3692 snd_card_ro_proc_new(hdsp->card, "hdsp", hdsp, snd_hdsp_proc_read); 4016 3693 } 4017 3694 … … 4022 3699 } 4023 3700 4024 static int __devinitsnd_hdsp_initialize_memory(struct hdsp *hdsp)3701 static int snd_hdsp_initialize_memory(struct hdsp *hdsp) 4025 3702 { 4026 3703 unsigned long pb_bus, cb_bus; … … 4030 3707 if (hdsp->capture_dma_buf.area) 4031 3708 snd_dma_free_pages(&hdsp->capture_dma_buf); 4032 printk(KERN_ERR "%s: no buffers available\n", hdsp->card_name); 3709 dev_err(hdsp->card->dev, 3710 "%s: no buffers available\n", hdsp->card_name); 4033 3711 return -ENOMEM; 4034 3712 } … … 4113 3791 } 4114 3792 4115 static void hdsp_midi_ tasklet(unsigned long arg)4116 { 4117 struct hdsp *hdsp = (struct hdsp *)arg;3793 static void hdsp_midi_work(struct work_struct *work) 3794 { 3795 struct hdsp *hdsp = container_of(work, struct hdsp, midi_work); 4118 3796 4119 3797 if (hdsp->midi[0].pending) … … 4160 3838 4161 3839 if (midi0 && midi0status) { 4162 if (hdsp->use_midi_ tasklet) {3840 if (hdsp->use_midi_work) { 4163 3841 /* we disable interrupts for this input until processing is done */ 4164 3842 hdsp->control_register &= ~HDSP_Midi0InterruptEnable; … … 4171 3849 } 4172 3850 if (hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632 && midi1 && midi1status) { 4173 if (hdsp->use_midi_ tasklet) {3851 if (hdsp->use_midi_work) { 4174 3852 /* we disable interrupts for this input until processing is done */ 4175 3853 hdsp->control_register &= ~HDSP_Midi1InterruptEnable; … … 4181 3859 } 4182 3860 } 4183 if (hdsp->use_midi_ tasklet&& schedule)4184 tasklet_schedule(&hdsp->midi_tasklet);3861 if (hdsp->use_midi_work && schedule) 3862 queue_work(system_highpri_wq, &hdsp->midi_work); 4185 3863 return IRQ_HANDLED; 4186 3864 } … … 4211 3889 } 4212 3890 4213 static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream, int channel, 4214 snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count) 3891 static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream, 3892 int channel, unsigned long pos, 3893 void __user *src, unsigned long count) 4215 3894 { 4216 3895 struct hdsp *hdsp = snd_pcm_substream_chip(substream); 4217 3896 char *channel_buf; 4218 3897 4219 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES / 4))3898 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES)) 4220 3899 return -EINVAL; 4221 3900 … … 4223 3902 if (snd_BUG_ON(!channel_buf)) 4224 3903 return -EIO; 4225 if (copy_from_user(channel_buf + pos * 4, src, count * 4))3904 if (copy_from_user(channel_buf + pos, src, count)) 4226 3905 return -EFAULT; 4227 return count; 4228 } 4229 4230 static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream, int channel, 4231 snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count) 3906 return 0; 3907 } 3908 3909 static int snd_hdsp_playback_copy_kernel(struct snd_pcm_substream *substream, 3910 int channel, unsigned long pos, 3911 void *src, unsigned long count) 4232 3912 { 4233 3913 struct hdsp *hdsp = snd_pcm_substream_chip(substream); 4234 3914 char *channel_buf; 4235 3915 4236 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES / 4)) 3916 channel_buf = hdsp_channel_buffer_location(hdsp, substream->pstr->stream, channel); 3917 if (snd_BUG_ON(!channel_buf)) 3918 return -EIO; 3919 memcpy(channel_buf + pos, src, count); 3920 return 0; 3921 } 3922 3923 static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream, 3924 int channel, unsigned long pos, 3925 void __user *dst, unsigned long count) 3926 { 3927 struct hdsp *hdsp = snd_pcm_substream_chip(substream); 3928 char *channel_buf; 3929 3930 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES)) 4237 3931 return -EINVAL; 4238 3932 … … 4240 3934 if (snd_BUG_ON(!channel_buf)) 4241 3935 return -EIO; 4242 if (copy_to_user(dst, channel_buf + pos * 4, count * 4))3936 if (copy_to_user(dst, channel_buf + pos, count)) 4243 3937 return -EFAULT; 4244 return count; 4245 } 4246 4247 static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream, int channel, 4248 snd_pcm_uframes_t pos, snd_pcm_uframes_t count) 3938 return 0; 3939 } 3940 3941 static int snd_hdsp_capture_copy_kernel(struct snd_pcm_substream *substream, 3942 int channel, unsigned long pos, 3943 void *dst, unsigned long count) 3944 { 3945 struct hdsp *hdsp = snd_pcm_substream_chip(substream); 3946 char *channel_buf; 3947 3948 channel_buf = hdsp_channel_buffer_location(hdsp, substream->pstr->stream, channel); 3949 if (snd_BUG_ON(!channel_buf)) 3950 return -EIO; 3951 memcpy(dst, channel_buf + pos, count); 3952 return 0; 3953 } 3954 3955 static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream, 3956 int channel, unsigned long pos, 3957 unsigned long count) 4249 3958 { 4250 3959 struct hdsp *hdsp = snd_pcm_substream_chip(substream); … … 4254 3963 if (snd_BUG_ON(!channel_buf)) 4255 3964 return -EIO; 4256 memset(channel_buf + pos * 4, 0, count * 4);4257 return count;3965 memset(channel_buf + pos, 0, count); 3966 return 0; 4258 3967 } 4259 3968 … … 4363 4072 { 4364 4073 struct hdsp *hdsp = snd_pcm_substream_chip(substream); 4365 int mapped_channel;4366 4367 if (snd_BUG_ON( info->channel >= hdsp->max_channels))4074 unsigned int channel = info->channel; 4075 4076 if (snd_BUG_ON(channel >= hdsp->max_channels)) 4368 4077 return -EINVAL; 4369 4370 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) 4078 channel = array_index_nospec(channel, hdsp->max_channels); 4079 4080 if (hdsp->channel_map[channel] < 0) 4371 4081 return -EINVAL; 4372 4082 4373 info->offset = mapped_channel* HDSP_CHANNEL_BUFFER_BYTES;4083 info->offset = hdsp->channel_map[channel] * HDSP_CHANNEL_BUFFER_BYTES; 4374 4084 info->first = 0; 4375 4085 info->step = 32; … … 4478 4188 } 4479 4189 4480 static struct snd_pcm_hardware snd_hdsp_playback_subinfo =4190 static const struct snd_pcm_hardware snd_hdsp_playback_subinfo = 4481 4191 { 4482 4192 .info = (SNDRV_PCM_INFO_MMAP | … … 4508 4218 }; 4509 4219 4510 static struct snd_pcm_hardware snd_hdsp_capture_subinfo =4220 static const struct snd_pcm_hardware snd_hdsp_capture_subinfo = 4511 4221 { 4512 4222 .info = (SNDRV_PCM_INFO_MMAP | … … 4537 4247 }; 4538 4248 4539 static unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };4540 4541 static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_period_sizes = {4249 static const unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 }; 4250 4251 static const struct snd_pcm_hw_constraint_list hdsp_hw_constraints_period_sizes = { 4542 4252 .count = ARRAY_SIZE(hdsp_period_sizes), 4543 4253 .list = hdsp_period_sizes, … … 4545 4255 }; 4546 4256 4547 static unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };4548 4549 static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_9632_sample_rates = {4257 static const unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 }; 4258 4259 static const struct snd_pcm_hw_constraint_list hdsp_hw_constraints_9632_sample_rates = { 4550 4260 .count = ARRAY_SIZE(hdsp_9632_sample_rates), 4551 4261 .list = hdsp_9632_sample_rates, … … 4992 4702 4993 4703 if (!(hdsp->state & HDSP_FirmwareLoaded)) { 4994 snd_printk(KERN_ERR "Hammerfall-DSP: firmware needs to be uploaded to the card.\n"); 4704 dev_err(hdsp->card->dev, 4705 "firmware needs to be uploaded to the card.\n"); 4995 4706 return -EINVAL; 4996 4707 } … … 5028 4739 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i); 5029 4740 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp); 5030 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp); 5031 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp); 5032 info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp); 5033 info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp); 4741 info.spdif_out = (unsigned char)hdsp_toggle_setting(hdsp, 4742 HDSP_SPDIFOpticalOut); 4743 info.spdif_professional = (unsigned char) 4744 hdsp_toggle_setting(hdsp, HDSP_SPDIFProfessional); 4745 info.spdif_emphasis = (unsigned char) 4746 hdsp_toggle_setting(hdsp, HDSP_SPDIFEmphasis); 4747 info.spdif_nonaudio = (unsigned char) 4748 hdsp_toggle_setting(hdsp, HDSP_SPDIFNonAudio); 5034 4749 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp); 5035 4750 info.system_sample_rate = hdsp->system_sample_rate; … … 5038 4753 info.clock_source = (unsigned char)hdsp_clock_source(hdsp); 5039 4754 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp); 5040 info.line_out = (unsigned char)hdsp_line_out(hdsp); 4755 info.line_out = (unsigned char) 4756 hdsp_toggle_setting(hdsp, HDSP_LineOut); 5041 4757 if (hdsp->io_type == H9632) { 5042 4758 info.da_gain = (unsigned char)hdsp_da_gain(hdsp); 5043 4759 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp); 5044 4760 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp); 5045 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp); 4761 info.xlr_breakout_cable = 4762 (unsigned char)hdsp_toggle_setting(hdsp, 4763 HDSP_XLRBreakoutCable); 5046 4764 5047 4765 } else if (hdsp->io_type == RPM) { … … 5050 4768 } 5051 4769 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) 5052 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp); 4770 info.analog_extension_board = 4771 (unsigned char)hdsp_toggle_setting(hdsp, 4772 HDSP_AnalogExtensionBoard); 5053 4773 spin_unlock_irqrestore(&hdsp->lock, flags); 5054 4774 if (copy_to_user(argp, &info, sizeof(info))) … … 5075 4795 return err; 5076 4796 } 4797 memset(&hdsp_version, 0, sizeof(hdsp_version)); 5077 4798 hdsp_version.io_type = hdsp->io_type; 5078 4799 hdsp_version.firmware_rev = hdsp->firmware_rev; … … 5082 4803 } 5083 4804 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: { 5084 struct hdsp_firmware __user *firmware;4805 struct hdsp_firmware firmware; 5085 4806 u32 __user *firmware_data; 5086 4807 int err; … … 5093 4814 return -EBUSY; 5094 4815 5095 snd_printk(KERN_INFO "Hammerfall-DSP: initializing firmware upload\n"); 5096 firmware = (struct hdsp_firmware __user *)argp; 5097 5098 if (get_user(firmware_data, &firmware->firmware_data)) 4816 dev_info(hdsp->card->dev, 4817 "initializing firmware upload\n"); 4818 if (copy_from_user(&firmware, argp, sizeof(firmware))) 5099 4819 return -EFAULT; 4820 firmware_data = (u32 __user *)firmware.firmware_data; 5100 4821 5101 4822 if (hdsp_check_for_iobox (hdsp)) 5102 4823 return -EIO; 5103 4824 5104 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0) 4825 if (!hdsp->fw_uploaded) { 4826 hdsp->fw_uploaded = vmalloc(HDSP_FIRMWARE_SIZE); 4827 if (!hdsp->fw_uploaded) 4828 return -ENOMEM; 4829 } 4830 4831 if (copy_from_user(hdsp->fw_uploaded, firmware_data, 4832 HDSP_FIRMWARE_SIZE)) { 4833 vfree(hdsp->fw_uploaded); 4834 hdsp->fw_uploaded = NULL; 5105 4835 return -EFAULT; 4836 } 5106 4837 5107 4838 hdsp->state |= HDSP_FirmwareCached; … … 5118 4849 5119 4850 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) { 5120 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n"); 4851 dev_err(hdsp->card->dev, 4852 "error creating alsa devices\n"); 5121 4853 return err; 5122 4854 } … … 5136 4868 } 5137 4869 5138 static struct snd_pcm_ops snd_hdsp_playback_ops = {4870 static const struct snd_pcm_ops snd_hdsp_playback_ops = { 5139 4871 .open = snd_hdsp_playback_open, 5140 4872 .close = snd_hdsp_playback_release, … … 5144 4876 .trigger = snd_hdsp_trigger, 5145 4877 .pointer = snd_hdsp_hw_pointer, 5146 .copy = snd_hdsp_playback_copy, 5147 .silence = snd_hdsp_hw_silence, 4878 .copy_user = snd_hdsp_playback_copy, 4879 .copy_kernel = snd_hdsp_playback_copy_kernel, 4880 .fill_silence = snd_hdsp_hw_silence, 5148 4881 }; 5149 4882 5150 static struct snd_pcm_ops snd_hdsp_capture_ops = {4883 static const struct snd_pcm_ops snd_hdsp_capture_ops = { 5151 4884 .open = snd_hdsp_capture_open, 5152 4885 .close = snd_hdsp_capture_release, … … 5156 4889 .trigger = snd_hdsp_trigger, 5157 4890 .pointer = snd_hdsp_hw_pointer, 5158 .copy = snd_hdsp_capture_copy, 4891 .copy_user = snd_hdsp_capture_copy, 4892 .copy_kernel = snd_hdsp_capture_copy_kernel, 5159 4893 }; 5160 4894 … … 5172 4906 5173 4907 hw->ops.ioctl = snd_hdsp_hwdep_ioctl; 4908 hw->ops.ioctl_compat = snd_hdsp_hwdep_ioctl; 5174 4909 5175 4910 return 0; … … 5207 4942 5208 4943 if (hdsp_fifo_wait (hdsp, 0, 100)) { 5209 snd_printk(KERN_ERR "Hammerfall-DSP: enable_io fifo_wait failed\n"); 4944 dev_err(hdsp->card->dev, 4945 "enable_io fifo_wait failed\n"); 5210 4946 return -EIO; 5211 4947 } … … 5281 5017 5282 5018 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) { 5283 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating pcm interface\n"); 5019 dev_err(card->dev, 5020 "Error creating pcm interface\n"); 5284 5021 return err; 5285 5022 } … … 5287 5024 5288 5025 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) { 5289 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating first midi interface\n"); 5026 dev_err(card->dev, 5027 "Error creating first midi interface\n"); 5290 5028 return err; 5291 5029 } … … 5293 5031 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) { 5294 5032 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) { 5295 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating second midi interface\n"); 5033 dev_err(card->dev, 5034 "Error creating second midi interface\n"); 5296 5035 return err; 5297 5036 } … … 5299 5038 5300 5039 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) { 5301 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating ctl interface\n"); 5040 dev_err(card->dev, 5041 "Error creating ctl interface\n"); 5302 5042 return err; 5303 5043 } … … 5312 5052 5313 5053 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) { 5314 snd_printk(KERN_ERR "Hammerfall-DSP: Error setting default values\n"); 5054 dev_err(card->dev, 5055 "Error setting default values\n"); 5315 5056 return err; 5316 5057 } … … 5322 5063 5323 5064 if ((err = snd_card_register(card)) < 0) { 5324 snd_printk(KERN_ERR "Hammerfall-DSP: error registering card\n"); 5065 dev_err(card->dev, 5066 "error registering card\n"); 5325 5067 return err; 5326 5068 } … … 5331 5073 } 5332 5074 5333 #ifdef HDSP_FW_LOADER5334 5075 /* load firmware via hotplug fw loader */ 5335 5076 static int hdsp_request_fw_loader(struct hdsp *hdsp) … … 5366 5107 break; 5367 5108 default: 5368 snd_printk(KERN_ERR "Hammerfall-DSP: invalid io_type %d\n", hdsp->io_type); 5109 dev_err(hdsp->card->dev, 5110 "invalid io_type %d\n", hdsp->io_type); 5369 5111 return -EINVAL; 5370 5112 } 5371 5113 5372 5114 if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) { 5373 snd_printk(KERN_ERR "Hammerfall-DSP: cannot load firmware %s\n", fwfile); 5115 dev_err(hdsp->card->dev, 5116 "cannot load firmware %s\n", fwfile); 5374 5117 return -ENOENT; 5375 5118 } 5376 if (fw->size < sizeof(hdsp->firmware_cache)) { 5377 snd_printk(KERN_ERR "Hammerfall-DSP: too short firmware size %d (expected %d)\n", 5378 (int)fw->size, (int)sizeof(hdsp->firmware_cache)); 5119 if (fw->size < HDSP_FIRMWARE_SIZE) { 5120 dev_err(hdsp->card->dev, 5121 "too short firmware size %d (expected %d)\n", 5122 (int)fw->size, HDSP_FIRMWARE_SIZE); 5379 5123 release_firmware(fw); 5380 5124 return -EINVAL; 5381 5125 } 5382 5126 5383 memcpy(hdsp->firmware_cache, fw->data, sizeof(hdsp->firmware_cache)); 5384 5385 release_firmware(fw); 5127 hdsp->firmware = fw; 5386 5128 5387 5129 hdsp->state |= HDSP_FirmwareCached; … … 5395 5137 5396 5138 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) { 5397 snd_printk(KERN_ERR "Hammerfall-DSP: error creating hwdep device\n"); 5139 dev_err(hdsp->card->dev, 5140 "error creating hwdep device\n"); 5398 5141 return err; 5399 5142 } … … 5401 5144 snd_hdsp_initialize_midi_flush(hdsp); 5402 5145 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) { 5403 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n"); 5146 dev_err(hdsp->card->dev, 5147 "error creating alsa devices\n"); 5404 5148 return err; 5405 5149 } … … 5407 5151 return 0; 5408 5152 } 5409 #endif 5410 5411 static int __devinit snd_hdsp_create(struct snd_card *card, 5412 struct hdsp *hdsp) 5153 5154 static int snd_hdsp_create(struct snd_card *card, 5155 struct hdsp *hdsp) 5413 5156 { 5414 5157 struct pci_dev *pci = hdsp->pci; … … 5439 5182 spin_lock_init(&hdsp->lock); 5440 5183 5441 tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);5184 INIT_WORK(&hdsp->midi_work, hdsp_midi_work); 5442 5185 5443 5186 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev); … … 5477 5220 return err; 5478 5221 hdsp->port = pci_resource_start(pci, 0); 5479 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) { 5480 snd_printk(KERN_ERR "Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1); 5222 if ((hdsp->iobase = ioremap(hdsp->port, HDSP_IO_EXTENT)) == NULL) { 5223 dev_err(hdsp->card->dev, "unable to remap region 0x%lx-0x%lx\n", 5224 hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1); 5481 5225 return -EBUSY; 5482 5226 } 5483 5227 5484 5228 if (request_irq(pci->irq, snd_hdsp_interrupt, IRQF_SHARED, 5485 "hdsp", hdsp)) {5486 snd_printk(KERN_ERR "Hammerfall-DSP:unable to use IRQ %d\n", pci->irq);5229 KBUILD_MODNAME, hdsp)) { 5230 dev_err(hdsp->card->dev, "unable to use IRQ %d\n", pci->irq); 5487 5231 return -EBUSY; 5488 5232 } 5489 5233 5490 5234 hdsp->irq = pci->irq; 5235 card->sync_irq = hdsp->irq; 5491 5236 hdsp->precise_ptr = 0; 5492 hdsp->use_midi_ tasklet= 1;5237 hdsp->use_midi_work = 1; 5493 5238 hdsp->dds_value = 0; 5494 5239 … … 5505 5250 5506 5251 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 5507 #ifdef HDSP_FW_LOADER5508 5252 if ((err = hdsp_request_fw_loader(hdsp)) < 0) 5509 5253 /* we don't fail as this can happen … … 5511 5255 firmware upload 5512 5256 */ 5513 snd_printk(KERN_ERR "Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n"); 5257 dev_err(hdsp->card->dev, 5258 "couldn't get firmware from userspace. try using hdsploader\n"); 5514 5259 else 5515 5260 /* init is complete, we return */ 5516 5261 return 0; 5517 #endif5518 5262 /* we defer initialization */ 5519 snd_printk(KERN_INFO "Hammerfall-DSP: card initialization pending : waiting for firmware\n"); 5263 dev_info(hdsp->card->dev, 5264 "card initialization pending : waiting for firmware\n"); 5520 5265 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) 5521 5266 return err; 5522 5267 return 0; 5523 5268 } else { 5524 snd_printk(KERN_INFO "Hammerfall-DSP: Firmware already present, initializing card.\n"); 5269 dev_info(hdsp->card->dev, 5270 "Firmware already present, initializing card.\n"); 5525 5271 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2) 5526 5272 hdsp->io_type = RPM; … … 5559 5305 if (hdsp->port) { 5560 5306 /* stop the audio, and cancel all interrupts */ 5561 tasklet_kill(&hdsp->midi_tasklet);5307 cancel_work_sync(&hdsp->midi_work); 5562 5308 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable); 5563 5309 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register); … … 5569 5315 snd_hdsp_free_buffers(hdsp); 5570 5316 5571 if (hdsp->iobase) 5572 iounmap(hdsp->iobase); 5317 release_firmware(hdsp->firmware); 5318 vfree(hdsp->fw_uploaded); 5319 iounmap(hdsp->iobase); 5573 5320 5574 5321 if (hdsp->port) … … 5587 5334 } 5588 5335 5589 static int __devinitsnd_hdsp_probe(struct pci_dev *pci,5590 5336 static int snd_hdsp_probe(struct pci_dev *pci, 5337 const struct pci_device_id *pci_id) 5591 5338 { 5592 5339 static int dev; … … 5602 5349 } 5603 5350 5604 err = snd_card_ create(index[dev], id[dev], THIS_MODULE,5605 5351 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 5352 sizeof(struct hdsp), &card); 5606 5353 if (err < 0) 5607 5354 return err; … … 5611 5358 hdsp->dev = dev; 5612 5359 hdsp->pci = pci; 5613 snd_card_set_dev(card, &pci->dev); 5614 5615 if ((err = snd_hdsp_create(card, hdsp)) < 0) { 5616 snd_card_free(card); 5617 return err; 5618 } 5360 err = snd_hdsp_create(card, hdsp); 5361 if (err) 5362 goto free_card; 5619 5363 5620 5364 strcpy(card->shortname, "Hammerfall DSP"); 5621 5365 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name, 5622 5366 hdsp->port, hdsp->irq); 5623 5624 if ((err = snd_card_register(card)) < 0) { 5367 err = snd_card_register(card); 5368 if (err) { 5369 free_card: 5625 5370 snd_card_free(card); 5626 5371 return err; … … 5631 5376 } 5632 5377 5633 static void __devexitsnd_hdsp_remove(struct pci_dev *pci)5378 static void snd_hdsp_remove(struct pci_dev *pci) 5634 5379 { 5635 5380 snd_card_free(pci_get_drvdata(pci)); 5636 pci_set_drvdata(pci, NULL); 5637 } 5638 5639 static struct pci_driver driver = { 5640 .name = "RME Hammerfall DSP", 5381 } 5382 5383 static struct pci_driver hdsp_driver = { 5384 .name = KBUILD_MODNAME, 5641 5385 .id_table = snd_hdsp_ids, 5642 5386 .probe = snd_hdsp_probe, 5643 .remove = __devexit_p(snd_hdsp_remove),5387 .remove = snd_hdsp_remove, 5644 5388 }; 5645 5389 5646 static int __init alsa_card_hdsp_init(void) 5647 { 5648 return pci_register_driver(&driver); 5649 } 5650 5651 static void __exit alsa_card_hdsp_exit(void) 5652 { 5653 pci_unregister_driver(&driver); 5654 } 5655 5656 module_init(alsa_card_hdsp_init) 5657 module_exit(alsa_card_hdsp_exit) 5390 module_pci_driver(hdsp_driver);
Note:
See TracChangeset
for help on using the changeset viewer.