Changeset 679 for GPL/trunk/alsa-kernel/pci/es1968.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/es1968.c
r598 r679 1 // SPDX-License-Identifier: GPL-2.0-or-later 1 2 /* 2 3 * Driver for ESS Maestro 1/2/2E Sound Card (started 21.8.99) … … 10 11 * TODO: 11 12 * Perhaps Synth 12 *13 * This program is free software; you can redistribute it and/or modify14 * it under the terms of the GNU General Public License as published by15 * the Free Software Foundation; either version 2 of the License, or16 * (at your option) any later version.17 *18 * This program is distributed in the hope that it will be useful,19 * but WITHOUT ANY WARRANTY; without even the implied warranty of20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the21 * GNU General Public License for more details.22 *23 * You should have received a copy of the GNU General Public License24 * along with this program; if not, write to the Free Software25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA26 *27 13 * 28 14 * Notes from Zach Brown about the driver code … … 95 81 */ 96 82 97 #include < asm/io.h>83 #include <linux/io.h> 98 84 #include <linux/delay.h> 99 85 #include <linux/interrupt.h> … … 103 89 #include <linux/slab.h> 104 90 #include <linux/gameport.h> 105 #include <linux/module param.h>91 #include <linux/module.h> 106 92 #include <linux/mutex.h> 107 93 #include <linux/input.h> … … 113 99 #include <sound/initval.h> 114 100 101 #ifdef CONFIG_SND_ES1968_RADIO 102 #include <media/drv-intf/tea575x.h> 103 #endif 104 115 105 #define CARD_NAME "ESS Maestro1/2" 116 106 #define DRIVER_NAME "ES1968" 117 107 108 #ifdef TARGET_OS2 109 #define KBUILD_MODNAME "es1968" 110 #endif 118 111 MODULE_DESCRIPTION("ESS Maestro"); 119 112 MODULE_LICENSE("GPL"); … … 123 116 "{TerraTec,DMX}}"); 124 117 125 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))118 #if IS_REACHABLE(CONFIG_GAMEPORT) 126 119 #define SUPPORT_JOYSTICK 1 127 120 #endif … … 129 122 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 1-MAX */ 130 123 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 131 static intenable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */124 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 132 125 #ifndef TARGET_OS2 133 126 static int total_bufsize[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1024 }; … … 146 139 #endif 147 140 #ifdef SUPPORT_JOYSTICK 148 static intjoystick[SNDRV_CARDS];141 static bool joystick[SNDRV_CARDS]; 149 142 #endif 150 143 #ifndef TARGET_OS2 144 static int radio_nr[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1}; 145 #else 146 static int radio_nr[SNDRV_CARDS] = { REPEAT_SNDRV(1) }; 147 #endif 151 148 module_param_array(index, int, NULL, 0444); 152 149 MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard."); … … 171 168 MODULE_PARM_DESC(joystick, "Enable joystick."); 172 169 #endif 170 module_param_array(radio_nr, int, NULL, 0444); 171 MODULE_PARM_DESC(radio_nr, "Radio device numbers"); 172 173 173 174 174 … … 493 493 struct list_head list; 494 494 495 #ifdef CONFIG_PM 495 #ifdef CONFIG_PM_SLEEP 496 496 u16 wc_map[4]; 497 497 #endif … … 546 546 spinlock_t substream_lock; 547 547 548 #ifdef CONFIG_PM 548 #ifdef CONFIG_PM_SLEEP 549 549 u16 apu_map[NR_APUS][NR_APU_REGS]; 550 550 #endif … … 560 560 struct snd_kcontrol *master_switch; /* for h/w volume control */ 561 561 struct snd_kcontrol *master_volume; 562 spinlock_t ac97_lock; 563 struct tasklet_struct hwvol_tq; 562 #endif 563 struct work_struct hwvol_work; 564 565 #ifdef CONFIG_SND_ES1968_RADIO 566 struct v4l2_device v4l2_dev; 567 struct snd_tea575x tea; 568 unsigned int tea575x_tuner; 564 569 #endif 565 570 }; … … 567 572 static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id); 568 573 569 static DEFINE_PCI_DEVICE_TABLE(snd_es1968_ids)= {574 static const struct pci_device_id snd_es1968_ids[] = { 570 575 /* Maestro 1 */ 571 576 { 0x1285, 0x0100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, TYPE_MAESTRO }, … … 629 634 cond_resched(); 630 635 } 631 snd_printd("es1968:ac97 timeout\n");636 dev_dbg(chip->card->dev, "ac97 timeout\n"); 632 637 return 1; /* timeout */ 633 638 } … … 641 646 return 0; 642 647 } 643 snd_printd("es1968:ac97 timeout\n");648 dev_dbg(chip->card->dev, "ac97 timeout\n"); 644 649 return 1; /* timeout */ 645 650 } … … 648 653 { 649 654 struct es1968 *chip = ac97->private_data; 650 #ifndef CONFIG_SND_ES1968_INPUT651 unsigned long flags;652 #endif653 655 654 656 snd_es1968_ac97_wait(chip); 655 657 656 658 /* Write the bus */ 657 #ifndef CONFIG_SND_ES1968_INPUT658 spin_lock_irqsave(&chip->ac97_lock, flags);659 #endif660 659 outw(val, chip->io_port + ESM_AC97_DATA); 661 660 /*msleep(1);*/ 662 661 outb(reg, chip->io_port + ESM_AC97_INDEX); 663 662 /*msleep(1);*/ 664 #ifndef CONFIG_SND_ES1968_INPUT665 spin_unlock_irqrestore(&chip->ac97_lock, flags);666 #endif667 663 } 668 664 … … 671 667 u16 data = 0; 672 668 struct es1968 *chip = ac97->private_data; 673 #ifndef CONFIG_SND_ES1968_INPUT674 unsigned long flags;675 #endif676 669 677 670 snd_es1968_ac97_wait(chip); 678 671 679 #ifndef CONFIG_SND_ES1968_INPUT680 spin_lock_irqsave(&chip->ac97_lock, flags);681 #endif682 672 outb(reg | 0x80, chip->io_port + ESM_AC97_INDEX); 683 673 /*msleep(1);*/ … … 687 677 /*msleep(1);*/ 688 678 } 689 #ifndef CONFIG_SND_ES1968_INPUT690 spin_unlock_irqrestore(&chip->ac97_lock, flags);691 #endif692 679 693 680 return data; … … 702 689 if (__maestro_read(chip, IDR1_CRAM_POINTER) == index) 703 690 return; 704 snd_printd("es1968:APU register select failed. (Timeout)\n");691 dev_dbg(chip->card->dev, "APU register select failed. (Timeout)\n"); 705 692 } 706 693 … … 714 701 __maestro_write(chip, IDR0_DATA_PORT, data); 715 702 } 716 snd_printd("es1968:APU register set probably failed (Timeout)!\n");703 dev_dbg(chip->card->dev, "APU register set probably failed (Timeout)!\n"); 717 704 } 718 705 … … 722 709 if (snd_BUG_ON(channel >= NR_APUS)) 723 710 return; 724 #ifdef CONFIG_PM 711 #ifdef CONFIG_PM_SLEEP 725 712 chip->apu_map[channel][reg] = data; 726 713 #endif … … 1009 996 wave_set_register(chip, es->apu[channel] << 3, tmpval); 1010 997 1011 #ifdef CONFIG_PM 998 #ifdef CONFIG_PM_SLEEP 1012 999 es->wc_map[channel] = tmpval; 1013 1000 #endif … … 1305 1292 } 1306 1293 1307 static struct snd_pcm_hardware snd_es1968_playback = {1294 static const struct snd_pcm_hardware snd_es1968_playback = { 1308 1295 .info = (SNDRV_PCM_INFO_MMAP | 1309 1296 SNDRV_PCM_INFO_MMAP_VALID | … … 1326 1313 }; 1327 1314 1328 static struct snd_pcm_hardware snd_es1968_capture = {1315 static const struct snd_pcm_hardware snd_es1968_capture = { 1329 1316 .info = (SNDRV_PCM_INFO_NONINTERLEAVED | 1330 1317 SNDRV_PCM_INFO_MMAP | … … 1437 1424 if (! chip->dma.area) 1438 1425 return; 1439 snd_dma_ reserve_buf(&chip->dma, snd_dma_pci_buf_id(chip->pci));1426 snd_dma_free_pages(&chip->dma); 1440 1427 while ((p = chip->buf_list.next) != &chip->buf_list) { 1441 1428 struct esm_memory *chunk = list_entry(p, struct esm_memory, list); … … 1445 1432 } 1446 1433 1447 static int __devinit1434 static int 1448 1435 snd_es1968_init_dmabuf(struct es1968 *chip) 1449 1436 { … … 1451 1438 struct esm_memory *chunk; 1452 1439 1453 chip->dma.dev.type = SNDRV_DMA_TYPE_DEV; 1454 chip->dma.dev.dev = snd_dma_pci_data(chip->pci); 1455 if (! snd_dma_get_reserved_buf(&chip->dma, snd_dma_pci_buf_id(chip->pci))) { 1456 err = snd_dma_alloc_pages_fallback(SNDRV_DMA_TYPE_DEV, 1457 snd_dma_pci_data(chip->pci), 1458 chip->total_bufsize, &chip->dma); 1459 if (err < 0 || ! chip->dma.area) { 1460 snd_printk(KERN_ERR "es1968: can't allocate dma pages for size %d\n", 1461 chip->total_bufsize); 1462 return -ENOMEM; 1463 } 1464 if ((chip->dma.addr + chip->dma.bytes - 1) & ~((1 << 28) - 1)) { 1465 snd_dma_free_pages(&chip->dma); 1466 snd_printk(KERN_ERR "es1968: DMA buffer beyond 256MB.\n"); 1467 return -ENOMEM; 1468 } 1440 err = snd_dma_alloc_pages_fallback(SNDRV_DMA_TYPE_DEV, 1441 &chip->pci->dev, 1442 chip->total_bufsize, &chip->dma); 1443 if (err < 0 || ! chip->dma.area) { 1444 dev_err(chip->card->dev, 1445 "can't allocate dma pages for size %d\n", 1446 chip->total_bufsize); 1447 return -ENOMEM; 1448 } 1449 if ((chip->dma.addr + chip->dma.bytes - 1) & ~((1 << 28) - 1)) { 1450 snd_dma_free_pages(&chip->dma); 1451 dev_err(chip->card->dev, "DMA buffer beyond 256MB.\n"); 1452 return -ENOMEM; 1469 1453 } 1470 1454 … … 1506 1490 chan->memory = snd_es1968_new_memory(chip, size); 1507 1491 if (chan->memory == NULL) { 1508 // snd_printd("cannot allocate dma buffer: size = %d\n", size); 1492 dev_dbg(chip->card->dev, 1493 "cannot allocate dma buffer: size = %d\n", size); 1509 1494 return -ENOMEM; 1510 1495 } … … 1692 1677 } 1693 1678 1694 static struct snd_pcm_ops snd_es1968_playback_ops = {1679 static const struct snd_pcm_ops snd_es1968_playback_ops = { 1695 1680 .open = snd_es1968_playback_open, 1696 1681 .close = snd_es1968_playback_close, 1697 .ioctl = snd_pcm_lib_ioctl,1698 1682 .hw_params = snd_es1968_hw_params, 1699 1683 .hw_free = snd_es1968_hw_free, … … 1703 1687 }; 1704 1688 1705 static struct snd_pcm_ops snd_es1968_capture_ops = {1689 static const struct snd_pcm_ops snd_es1968_capture_ops = { 1706 1690 .open = snd_es1968_capture_open, 1707 1691 .close = snd_es1968_capture_close, 1708 .ioctl = snd_pcm_lib_ioctl,1709 1692 .hw_params = snd_es1968_hw_params, 1710 1693 .hw_free = snd_es1968_hw_free, … … 1720 1703 #define CLOCK_MEASURE_BUFSIZE 16768 /* enough large for a single shot */ 1721 1704 1722 static void __devinites1968_measure_clock(struct es1968 *chip)1705 static void es1968_measure_clock(struct es1968 *chip) 1723 1706 { 1724 1707 int i, apu; 1725 1708 unsigned int pa, offset, t; 1726 1709 struct esm_memory *memory; 1710 #ifndef TARGET_OS2 1711 ktime_t start_time, stop_time; 1712 ktime_t diff; 1713 #else 1727 1714 struct timeval start_time, stop_time; 1715 #endif 1728 1716 1729 1717 if (chip->clock == 0) … … 1732 1720 /* search 2 APUs (although one apu is enough) */ 1733 1721 if ((apu = snd_es1968_alloc_apu_pair(chip, ESM_APU_PCM_PLAY)) < 0) { 1734 snd_printk(KERN_ERR"Hmm, cannot find empty APU pair!?\n");1722 dev_err(chip->card->dev, "Hmm, cannot find empty APU pair!?\n"); 1735 1723 return; 1736 1724 } 1737 1725 if ((memory = snd_es1968_new_memory(chip, CLOCK_MEASURE_BUFSIZE)) == NULL) { 1738 snd_printk(KERN_ERR "cannot allocate dma buffer - using default clock %d\n", chip->clock); 1726 dev_warn(chip->card->dev, 1727 "cannot allocate dma buffer - using default clock %d\n", 1728 chip->clock); 1739 1729 snd_es1968_free_apu_pair(chip, apu); 1740 1730 return; … … 1774 1764 __apu_set_register(chip, apu, 5, pa & 0xffff); 1775 1765 snd_es1968_trigger_apu(chip, apu, ESM_APU_16BITLINEAR); 1766 #ifndef TARGET_OS2 1767 start_time = ktime_get(); 1768 #else 1776 1769 do_gettimeofday(&start_time); 1770 #endif 1777 1771 spin_unlock_irq(&chip->reg_lock); 1778 1772 msleep(50); 1779 1773 spin_lock_irq(&chip->reg_lock); 1780 1774 offset = __apu_get_register(chip, apu, 5); 1775 #ifndef TARGET_OS2 1776 stop_time = ktime_get(); 1777 #else 1781 1778 do_gettimeofday(&stop_time); 1779 #endif 1782 1780 snd_es1968_trigger_apu(chip, apu, 0); /* stop */ 1783 1781 snd_es1968_bob_dec(chip); … … 1790 1788 offset += chip->measure_count * (CLOCK_MEASURE_BUFSIZE/2); 1791 1789 1790 #ifndef TARGET_OS2 1791 diff = ktime_sub(stop_time, start_time); 1792 t = ktime_to_us(diff); 1793 #else 1792 1794 t = stop_time.tv_sec - start_time.tv_sec; 1793 1795 t *= 1000000; … … 1796 1798 else 1797 1799 t += stop_time.tv_usec - start_time.tv_usec; 1800 #endif 1798 1801 if (t == 0) { 1799 snd_printk(KERN_ERR"?? calculation error..\n");1802 dev_err(chip->card->dev, "?? calculation error..\n"); 1800 1803 } else { 1801 1804 offset *= 1000; … … 1805 1808 chip->clock = (chip->clock * offset) / 48000; 1806 1809 } 1807 printk(KERN_INFO "es1968:clocking to %d\n", chip->clock);1810 dev_info(chip->card->dev, "clocking to %d\n", chip->clock); 1808 1811 } 1809 1812 snd_es1968_free_memory(chip, memory); … … 1822 1825 } 1823 1826 1824 static int __devinit1827 static int 1825 1828 snd_es1968_pcm(struct es1968 *chip, int device) 1826 1829 { … … 1906 1909 generating an interrupt. The pair of counters is stored in bits 1-3 and 5-7 1907 1910 of a byte wide register. The meaning of bits 0 and 4 is unknown. */ 1908 static void es1968_update_hw_volume( unsigned long private_data)1909 { 1910 struct es1968 *chip = (struct es1968 *) private_data;1911 static void es1968_update_hw_volume(struct work_struct *work) 1912 { 1913 struct es1968 *chip = container_of(work, struct es1968, hwvol_work); 1911 1914 int x, val; 1912 #ifndef CONFIG_SND_ES1968_INPUT1913 unsigned long flags;1914 #endif1915 1915 1916 1916 /* Figure out which volume control button was pushed, … … 1931 1931 return; 1932 1932 1933 /* FIXME: we can't call snd_ac97_* functions since here is in tasklet. */ 1934 spin_lock_irqsave(&chip->ac97_lock, flags); 1935 val = chip->ac97->regs[AC97_MASTER]; 1933 val = snd_ac97_read(chip->ac97, AC97_MASTER); 1936 1934 switch (x) { 1937 1935 case 0x88: 1938 1936 /* mute */ 1939 1937 val ^= 0x8000; 1940 chip->ac97->regs[AC97_MASTER] = val;1941 outw(val, chip->io_port + ESM_AC97_DATA);1942 outb(AC97_MASTER, chip->io_port + ESM_AC97_INDEX);1943 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,1944 &chip->master_switch->id);1945 1938 break; 1946 1939 case 0xaa: … … 1950 1943 if ((val & 0x7f00) > 0) 1951 1944 val -= 0x0100; 1952 chip->ac97->regs[AC97_MASTER] = val;1953 outw(val, chip->io_port + ESM_AC97_DATA);1954 outb(AC97_MASTER, chip->io_port + ESM_AC97_INDEX);1955 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,1956 &chip->master_volume->id);1957 1945 break; 1958 1946 case 0x66: … … 1962 1950 if ((val & 0x7f00) < 0x1f00) 1963 1951 val += 0x0100; 1964 chip->ac97->regs[AC97_MASTER] = val;1965 outw(val, chip->io_port + ESM_AC97_DATA);1966 outb(AC97_MASTER, chip->io_port + ESM_AC97_INDEX);1952 break; 1953 } 1954 if (snd_ac97_update(chip->ac97, AC97_MASTER, val)) 1967 1955 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, 1968 1956 &chip->master_volume->id); 1969 break;1970 }1971 spin_unlock_irqrestore(&chip->ac97_lock, flags);1972 1957 #else 1973 1958 if (!chip->input_dev) … … 2015 2000 2016 2001 if (event & ESM_HWVOL_IRQ) 2017 #ifdef CONFIG_SND_ES1968_INPUT 2018 es1968_update_hw_volume((unsigned long)chip); 2019 #else 2020 tasklet_schedule(&chip->hwvol_tq); /* we'll do this later */ 2021 #endif 2002 schedule_work(&chip->hwvol_work); 2022 2003 2023 2004 /* else ack 'em all, i imagine */ … … 2054 2035 */ 2055 2036 2056 static int __devinit2037 static int 2057 2038 snd_es1968_mixer(struct es1968 *chip) 2058 2039 { … … 2063 2044 #endif 2064 2045 int err; 2065 static struct snd_ac97_bus_ops ops = {2046 static const struct snd_ac97_bus_ops ops = { 2066 2047 .write = snd_es1968_ac97_write, 2067 2048 .read = snd_es1968_ac97_read, … … 2147 2128 2148 2129 #if 0 /* the loop here needs to be much better if we want it.. */ 2149 snd_printk(KERN_INFO"trying software reset\n");2130 dev_info(chip->card->dev, "trying software reset\n"); 2150 2131 /* try and do a software reset */ 2151 2132 outb(0x80 | 0x7c, ioaddr + 0x30); … … 2329 2310 2330 2311 /* it appears some maestros (dell 7500) only work if these are set, 2331 regardless of w ether we use the assp or not. */2312 regardless of whether we use the assp or not. */ 2332 2313 2333 2314 outb(0, iobase + ASSP_CONTROL_B); … … 2415 2396 } 2416 2397 2417 #ifdef CONFIG_PM 2398 #ifdef CONFIG_PM_SLEEP 2418 2399 /* 2419 2400 * PM support 2420 2401 */ 2421 static int es1968_suspend(struct pci_dev *pci, pm_message_t state)2422 { 2423 struct snd_card *card = pci_get_drvdata(pci);2402 static int es1968_suspend(struct device *dev) 2403 { 2404 struct snd_card *card = dev_get_drvdata(dev); 2424 2405 struct es1968 *chip = card->private_data; 2425 2406 … … 2428 2409 2429 2410 chip->in_suspend = 1; 2411 cancel_work_sync(&chip->hwvol_work); 2430 2412 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 2431 snd_pcm_suspend_all(chip->pcm);2432 2413 snd_ac97_suspend(chip->ac97); 2433 2414 snd_es1968_bob_stop(chip); 2434 2435 pci_disable_device(pci);2436 pci_save_state(pci);2437 pci_set_power_state(pci, pci_choose_state(pci, state));2438 2415 return 0; 2439 2416 } 2440 2417 2441 static int es1968_resume(struct pci_dev *pci)2442 { 2443 struct snd_card *card = pci_get_drvdata(pci);2418 static int es1968_resume(struct device *dev) 2419 { 2420 struct snd_card *card = dev_get_drvdata(dev); 2444 2421 struct es1968 *chip = card->private_data; 2445 2422 struct esschan *es; … … 2447 2424 if (! chip->do_pm) 2448 2425 return 0; 2449 2450 /* restore all our config */2451 pci_set_power_state(pci, PCI_D0);2452 pci_restore_state(pci);2453 if (pci_enable_device(pci) < 0) {2454 printk(KERN_ERR "es1968: pci_enable_device failed, "2455 "disabling device\n");2456 snd_card_disconnect(card);2457 return -EIO;2458 }2459 pci_set_master(pci);2460 2426 2461 2427 snd_es1968_chip_init(chip); … … 2491 2457 return 0; 2492 2458 } 2493 #endif /* CONFIG_PM */ 2459 2460 static SIMPLE_DEV_PM_OPS(es1968_pm, es1968_suspend, es1968_resume); 2461 #define ES1968_PM_OPS &es1968_pm 2462 #else 2463 #define ES1968_PM_OPS NULL 2464 #endif /* CONFIG_PM_SLEEP */ 2494 2465 2495 2466 #ifdef SUPPORT_JOYSTICK 2496 2467 #define JOYSTICK_ADDR 0x200 2497 static int __devinitsnd_es1968_create_gameport(struct es1968 *chip, int dev)2468 static int snd_es1968_create_gameport(struct es1968 *chip, int dev) 2498 2469 { 2499 2470 struct gameport *gp; … … 2510 2481 chip->gameport = gp = gameport_allocate_port(); 2511 2482 if (!gp) { 2512 printk(KERN_ERR "es1968: cannot allocate memory for gameport\n"); 2483 dev_err(chip->card->dev, 2484 "cannot allocate memory for gameport\n"); 2513 2485 release_and_free_resource(r); 2514 2486 return -ENOMEM; … … 2546 2518 2547 2519 #ifdef CONFIG_SND_ES1968_INPUT 2548 static int __devinitsnd_es1968_input_register(struct es1968 *chip)2520 static int snd_es1968_input_register(struct es1968 *chip) 2549 2521 { 2550 2522 struct input_dev *input_dev; … … 2581 2553 #endif /* CONFIG_SND_ES1968_INPUT */ 2582 2554 2555 #ifdef CONFIG_SND_ES1968_RADIO 2556 #define GPIO_DATA 0x60 2557 #define IO_MASK 4 /* mask register offset from GPIO_DATA 2558 bits 1=unmask write to given bit */ 2559 #define IO_DIR 8 /* direction register offset from GPIO_DATA 2560 bits 0/1=read/write direction */ 2561 2562 /* GPIO to TEA575x maps */ 2563 struct snd_es1968_tea575x_gpio { 2564 u8 data, clk, wren, most; 2565 char *name; 2566 }; 2567 2568 static const struct snd_es1968_tea575x_gpio snd_es1968_tea575x_gpios[] = { 2569 { .data = 6, .clk = 7, .wren = 8, .most = 9, .name = "SF64-PCE2" }, 2570 { .data = 7, .clk = 8, .wren = 6, .most = 10, .name = "M56VAP" }, 2571 }; 2572 2573 #define get_tea575x_gpio(chip) \ 2574 (&snd_es1968_tea575x_gpios[(chip)->tea575x_tuner]) 2575 2576 2577 static void snd_es1968_tea575x_set_pins(struct snd_tea575x *tea, u8 pins) 2578 { 2579 struct es1968 *chip = tea->private_data; 2580 struct snd_es1968_tea575x_gpio gpio = *get_tea575x_gpio(chip); 2581 u16 val = 0; 2582 2583 val |= (pins & TEA575X_DATA) ? (1 << gpio.data) : 0; 2584 val |= (pins & TEA575X_CLK) ? (1 << gpio.clk) : 0; 2585 val |= (pins & TEA575X_WREN) ? (1 << gpio.wren) : 0; 2586 2587 outw(val, chip->io_port + GPIO_DATA); 2588 } 2589 2590 static u8 snd_es1968_tea575x_get_pins(struct snd_tea575x *tea) 2591 { 2592 struct es1968 *chip = tea->private_data; 2593 struct snd_es1968_tea575x_gpio gpio = *get_tea575x_gpio(chip); 2594 u16 val = inw(chip->io_port + GPIO_DATA); 2595 u8 ret = 0; 2596 2597 if (val & (1 << gpio.data)) 2598 ret |= TEA575X_DATA; 2599 if (val & (1 << gpio.most)) 2600 ret |= TEA575X_MOST; 2601 2602 return ret; 2603 } 2604 2605 static void snd_es1968_tea575x_set_direction(struct snd_tea575x *tea, bool output) 2606 { 2607 struct es1968 *chip = tea->private_data; 2608 unsigned long io = chip->io_port + GPIO_DATA; 2609 u16 odir = inw(io + IO_DIR); 2610 struct snd_es1968_tea575x_gpio gpio = *get_tea575x_gpio(chip); 2611 2612 if (output) { 2613 outw(~((1 << gpio.data) | (1 << gpio.clk) | (1 << gpio.wren)), 2614 io + IO_MASK); 2615 outw(odir | (1 << gpio.data) | (1 << gpio.clk) | (1 << gpio.wren), 2616 io + IO_DIR); 2617 } else { 2618 outw(~((1 << gpio.clk) | (1 << gpio.wren) | (1 << gpio.data) | (1 << gpio.most)), 2619 io + IO_MASK); 2620 outw((odir & ~((1 << gpio.data) | (1 << gpio.most))) 2621 | (1 << gpio.clk) | (1 << gpio.wren), io + IO_DIR); 2622 } 2623 } 2624 2625 static const struct snd_tea575x_ops snd_es1968_tea_ops = { 2626 .set_pins = snd_es1968_tea575x_set_pins, 2627 .get_pins = snd_es1968_tea575x_get_pins, 2628 .set_direction = snd_es1968_tea575x_set_direction, 2629 }; 2630 #endif 2631 2583 2632 static int snd_es1968_free(struct es1968 *chip) 2584 2633 { 2634 cancel_work_sync(&chip->hwvol_work); 2585 2635 #ifdef CONFIG_SND_ES1968_INPUT 2586 2636 if (chip->input_dev) … … 2589 2639 2590 2640 if (chip->io_port) { 2591 if (chip->irq >= 0)2592 synchronize_irq(chip->irq);2593 2641 outw(1, chip->io_port + 0x04); /* clear WP interrupts */ 2594 2642 outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */ 2595 2643 } 2644 2645 #ifdef CONFIG_SND_ES1968_RADIO 2646 snd_tea575x_exit(&chip->tea); 2647 v4l2_device_unregister(&chip->v4l2_dev); 2648 #endif 2596 2649 2597 2650 if (chip->irq >= 0) … … 2615 2668 }; 2616 2669 2617 static struct ess_device_list pm_whitelist[] __devinitdata= {2670 static const struct ess_device_list pm_allowlist[] = { 2618 2671 { TYPE_MAESTRO2E, 0x0e11 }, /* Compaq Armada */ 2619 2672 { TYPE_MAESTRO2E, 0x1028 }, … … 2622 2675 { TYPE_MAESTRO2E, 0x14c0 }, /* HP omnibook 4150 */ 2623 2676 { TYPE_MAESTRO2E, 0x1558 }, 2677 { TYPE_MAESTRO2E, 0x125d }, /* a PCI card, e.g. Terratec DMX */ 2678 { TYPE_MAESTRO2, 0x125d }, /* a PCI card, e.g. SF64-PCE2 */ 2624 2679 }; 2625 2680 2626 static struct ess_device_list mpu_blacklist[] __devinitdata= {2681 static const struct ess_device_list mpu_denylist[] = { 2627 2682 { TYPE_MAESTRO2, 0x125d }, 2628 2683 }; 2629 2684 2630 static int __devinit snd_es1968_create(struct snd_card *card, 2631 struct pci_dev *pci, 2632 int total_bufsize, 2633 int play_streams, 2634 int capt_streams, 2635 int chip_type, 2636 int do_pm, 2637 struct es1968 **chip_ret) 2638 { 2639 static struct snd_device_ops ops = { 2685 static int snd_es1968_create(struct snd_card *card, 2686 struct pci_dev *pci, 2687 int total_bufsize, 2688 int play_streams, 2689 int capt_streams, 2690 int chip_type, 2691 int do_pm, 2692 int radio_nr, 2693 struct es1968 **chip_ret) 2694 { 2695 static const struct snd_device_ops ops = { 2640 2696 .dev_free = snd_es1968_dev_free, 2641 2697 }; … … 2649 2705 return err; 2650 2706 /* check, if we can restrict PCI DMA transfers to 28 bits */ 2651 if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 || 2652 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) { 2653 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n"); 2707 if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 || 2708 dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(28)) < 0) { 2709 dev_err(card->dev, 2710 "architecture does not support 28bit PCI busmaster DMA\n"); 2654 2711 pci_disable_device(pci); 2655 2712 return -ENXIO; … … 2669 2726 INIT_LIST_HEAD(&chip->substream_list); 2670 2727 mutex_init(&chip->memory_mutex); 2671 #ifndef CONFIG_SND_ES1968_INPUT 2672 spin_lock_init(&chip->ac97_lock); 2673 tasklet_init(&chip->hwvol_tq, es1968_update_hw_volume, (unsigned long)chip); 2674 #endif 2728 INIT_WORK(&chip->hwvol_work, es1968_update_hw_volume); 2675 2729 chip->card = card; 2676 2730 chip->pci = pci; … … 2687 2741 chip->io_port = pci_resource_start(pci, 0); 2688 2742 if (request_irq(pci->irq, snd_es1968_interrupt, IRQF_SHARED, 2689 "ESS Maestro", chip)) {2690 snd_printk(KERN_ERR"unable to grab IRQ %d\n", pci->irq);2743 KBUILD_MODNAME, chip)) { 2744 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); 2691 2745 snd_es1968_free(chip); 2692 2746 return -EBUSY; 2693 2747 } 2694 2748 chip->irq = pci->irq; 2749 card->sync_irq = chip->irq; 2695 2750 2696 2751 /* Clear Maestro_map */ … … 2706 2761 2707 2762 if (do_pm > 1) { 2708 /* disable power-management if not on the whitelist */2763 /* disable power-management if not on the allowlist */ 2709 2764 unsigned short vend; 2710 2765 pci_read_config_word(chip->pci, PCI_SUBSYSTEM_VENDOR_ID, &vend); 2711 for (i = 0; i < (int)ARRAY_SIZE(pm_ whitelist); i++) {2712 if (chip->type == pm_ whitelist[i].type &&2713 vend == pm_ whitelist[i].vendor) {2766 for (i = 0; i < (int)ARRAY_SIZE(pm_allowlist); i++) { 2767 if (chip->type == pm_allowlist[i].type && 2768 vend == pm_allowlist[i].vendor) { 2714 2769 do_pm = 1; 2715 2770 break; … … 2718 2773 if (do_pm > 1) { 2719 2774 /* not matched; disabling pm */ 2720 printk(KERN_INFO "es1968:not attempting power management.\n");2775 dev_info(card->dev, "not attempting power management.\n"); 2721 2776 do_pm = 0; 2722 2777 } … … 2731 2786 } 2732 2787 2733 snd_card_set_dev(card, &pci->dev); 2788 #ifdef CONFIG_SND_ES1968_RADIO 2789 /* don't play with GPIOs on laptops */ 2790 if (chip->pci->subsystem_vendor != 0x125d) 2791 goto no_radio; 2792 err = v4l2_device_register(&pci->dev, &chip->v4l2_dev); 2793 if (err < 0) { 2794 snd_es1968_free(chip); 2795 return err; 2796 } 2797 chip->tea.v4l2_dev = &chip->v4l2_dev; 2798 chip->tea.private_data = chip; 2799 chip->tea.radio_nr = radio_nr; 2800 chip->tea.ops = &snd_es1968_tea_ops; 2801 sprintf(chip->tea.bus_info, "PCI:%s", pci_name(pci)); 2802 for (i = 0; i < ARRAY_SIZE(snd_es1968_tea575x_gpios); i++) { 2803 chip->tea575x_tuner = i; 2804 if (!snd_tea575x_init(&chip->tea, THIS_MODULE)) { 2805 dev_info(card->dev, "detected TEA575x radio type %s\n", 2806 get_tea575x_gpio(chip)->name); 2807 strlcpy(chip->tea.card, get_tea575x_gpio(chip)->name, 2808 sizeof(chip->tea.card)); 2809 break; 2810 } 2811 } 2812 no_radio: 2813 #endif 2734 2814 2735 2815 *chip_ret = chip; … … 2741 2821 /* 2742 2822 */ 2743 static int __devinitsnd_es1968_probe(struct pci_dev *pci,2744 2823 static int snd_es1968_probe(struct pci_dev *pci, 2824 const struct pci_device_id *pci_id) 2745 2825 { 2746 2826 static int dev; … … 2757 2837 } 2758 2838 2759 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2839 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 2840 0, &card); 2760 2841 if (err < 0) 2761 2842 return err; … … 2771 2852 pci_id->driver_data, 2772 2853 use_pm[dev], 2854 radio_nr[dev], 2773 2855 &chip)) < 0) { 2774 2856 snd_card_free(card); … … 2803 2885 2804 2886 if (enable_mpu[dev] == 2) { 2805 /* check the blacklist */2887 /* check the deny list */ 2806 2888 unsigned short vend; 2807 2889 pci_read_config_word(chip->pci, PCI_SUBSYSTEM_VENDOR_ID, &vend); 2808 for (i = 0; i < ARRAY_SIZE(mpu_ blacklist); i++) {2809 if (chip->type == mpu_ blacklist[i].type &&2810 vend == mpu_ blacklist[i].vendor) {2890 for (i = 0; i < ARRAY_SIZE(mpu_denylist); i++) { 2891 if (chip->type == mpu_denylist[i].type && 2892 vend == mpu_denylist[i].vendor) { 2811 2893 enable_mpu[dev] = 0; 2812 2894 break; … … 2817 2899 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 2818 2900 chip->io_port + ESM_MPU401_PORT, 2819 MPU401_INFO_INTEGRATED, 2820 chip->irq, 0, &chip->rmidi)) < 0) { 2821 printk(KERN_WARNING "es1968: skipping MPU-401 MIDI support..\n"); 2901 MPU401_INFO_INTEGRATED | 2902 MPU401_INFO_IRQ_HOOK, 2903 -1, &chip->rmidi)) < 0) { 2904 dev_warn(card->dev, "skipping MPU-401 MIDI support..\n"); 2822 2905 } 2823 2906 } … … 2828 2911 err = snd_es1968_input_register(chip); 2829 2912 if (err) 2830 snd_printk(KERN_WARNING "Input device registration "2831 "failed with error %i", err);2913 dev_warn(card->dev, 2914 "Input device registration failed with error %i", err); 2832 2915 #endif 2833 2916 … … 2850 2933 } 2851 2934 2852 static void __devexitsnd_es1968_remove(struct pci_dev *pci)2935 static void snd_es1968_remove(struct pci_dev *pci) 2853 2936 { 2854 2937 snd_card_free(pci_get_drvdata(pci)); 2855 pci_set_drvdata(pci, NULL); 2856 } 2857 2858 static struct pci_driver driver = { 2859 .name = "ES1968 (ESS Maestro)", 2938 } 2939 2940 static struct pci_driver es1968_driver = { 2941 .name = KBUILD_MODNAME, 2860 2942 .id_table = snd_es1968_ids, 2861 2943 .probe = snd_es1968_probe, 2862 .remove = __devexit_p(snd_es1968_remove), 2863 #ifdef CONFIG_PM 2864 .suspend = es1968_suspend, 2865 .resume = es1968_resume, 2866 #endif 2944 .remove = snd_es1968_remove, 2945 .driver = { 2946 .pm = ES1968_PM_OPS, 2947 }, 2867 2948 }; 2868 2949 2869 static int __init alsa_card_es1968_init(void) 2870 { 2871 return pci_register_driver(&driver); 2872 } 2873 2874 static void __exit alsa_card_es1968_exit(void) 2875 { 2876 pci_unregister_driver(&driver); 2877 } 2878 2879 module_init(alsa_card_es1968_init) 2880 module_exit(alsa_card_es1968_exit) 2950 module_pci_driver(es1968_driver);
Note:
See TracChangeset
for help on using the changeset viewer.