Ignore:
Timestamp:
Mar 18, 2021, 8:57:36 PM (4 years ago)
Author:
David Azarewicz
Message:

Merge changes from Paul's uniaud32next branch.

Location:
GPL/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk

  • GPL/trunk/alsa-kernel/pci/es1968.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Driver for ESS Maestro 1/2/2E Sound Card (started 21.8.99)
     
    1011 *  TODO:
    1112 *   Perhaps Synth
    12  *
    13  *   This program is free software; you can redistribute it and/or modify
    14  *   it under the terms of the GNU General Public License as published by
    15  *   the Free Software Foundation; either version 2 of the License, or
    16  *   (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 of
    20  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    21  *   GNU General Public License for more details.
    22  *
    23  *   You should have received a copy of the GNU General Public License
    24  *   along with this program; if not, write to the Free Software
    25  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    26  *
    2713 *
    2814 *  Notes from Zach Brown about the driver code
     
    9581 */
    9682
    97 #include <asm/io.h>
     83#include <linux/io.h>
    9884#include <linux/delay.h>
    9985#include <linux/interrupt.h>
     
    10389#include <linux/slab.h>
    10490#include <linux/gameport.h>
    105 #include <linux/moduleparam.h>
     91#include <linux/module.h>
    10692#include <linux/mutex.h>
    10793#include <linux/input.h>
     
    11399#include <sound/initval.h>
    114100
     101#ifdef CONFIG_SND_ES1968_RADIO
     102#include <media/drv-intf/tea575x.h>
     103#endif
     104
    115105#define CARD_NAME "ESS Maestro1/2"
    116106#define DRIVER_NAME "ES1968"
    117107
     108#ifdef TARGET_OS2
     109#define KBUILD_MODNAME "es1968"
     110#endif
    118111MODULE_DESCRIPTION("ESS Maestro");
    119112MODULE_LICENSE("GPL");
     
    123116                "{TerraTec,DMX}}");
    124117
    125 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
     118#if IS_REACHABLE(CONFIG_GAMEPORT)
    126119#define SUPPORT_JOYSTICK 1
    127120#endif
     
    129122static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 1-MAX */
    130123static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    131 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable this card */
     124static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable this card */
    132125#ifndef TARGET_OS2
    133126static int total_bufsize[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1024 };
     
    146139#endif
    147140#ifdef SUPPORT_JOYSTICK
    148 static int joystick[SNDRV_CARDS];
     141static bool joystick[SNDRV_CARDS];
    149142#endif
    150 
     143#ifndef TARGET_OS2
     144static int radio_nr[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
     145#else
     146static int radio_nr[SNDRV_CARDS] =  { REPEAT_SNDRV(1) };
     147#endif
    151148module_param_array(index, int, NULL, 0444);
    152149MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
     
    171168MODULE_PARM_DESC(joystick, "Enable joystick.");
    172169#endif
     170module_param_array(radio_nr, int, NULL, 0444);
     171MODULE_PARM_DESC(radio_nr, "Radio device numbers");
     172
    173173
    174174
     
    493493        struct list_head list;
    494494
    495 #ifdef CONFIG_PM
     495#ifdef CONFIG_PM_SLEEP
    496496        u16 wc_map[4];
    497497#endif
     
    546546        spinlock_t substream_lock;
    547547
    548 #ifdef CONFIG_PM
     548#ifdef CONFIG_PM_SLEEP
    549549        u16 apu_map[NR_APUS][NR_APU_REGS];
    550550#endif
     
    560560        struct snd_kcontrol *master_switch; /* for h/w volume control */
    561561        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;
    564569#endif
    565570};
     
    567572static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id);
    568573
    569 static DEFINE_PCI_DEVICE_TABLE(snd_es1968_ids) = {
     574static const struct pci_device_id snd_es1968_ids[] = {
    570575        /* Maestro 1 */
    571576        { 0x1285, 0x0100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, TYPE_MAESTRO },
     
    629634                cond_resched();
    630635        }
    631         snd_printd("es1968: ac97 timeout\n");
     636        dev_dbg(chip->card->dev, "ac97 timeout\n");
    632637        return 1; /* timeout */
    633638}
     
    641646                        return 0;
    642647        }
    643         snd_printd("es1968: ac97 timeout\n");
     648        dev_dbg(chip->card->dev, "ac97 timeout\n");
    644649        return 1; /* timeout */
    645650}
     
    648653{
    649654        struct es1968 *chip = ac97->private_data;
    650 #ifndef CONFIG_SND_ES1968_INPUT
    651         unsigned long flags;
    652 #endif
    653655
    654656        snd_es1968_ac97_wait(chip);
    655657
    656658        /* Write the bus */
    657 #ifndef CONFIG_SND_ES1968_INPUT
    658         spin_lock_irqsave(&chip->ac97_lock, flags);
    659 #endif
    660659        outw(val, chip->io_port + ESM_AC97_DATA);
    661660        /*msleep(1);*/
    662661        outb(reg, chip->io_port + ESM_AC97_INDEX);
    663662        /*msleep(1);*/
    664 #ifndef CONFIG_SND_ES1968_INPUT
    665         spin_unlock_irqrestore(&chip->ac97_lock, flags);
    666 #endif
    667663}
    668664
     
    671667        u16 data = 0;
    672668        struct es1968 *chip = ac97->private_data;
    673 #ifndef CONFIG_SND_ES1968_INPUT
    674         unsigned long flags;
    675 #endif
    676669
    677670        snd_es1968_ac97_wait(chip);
    678671
    679 #ifndef CONFIG_SND_ES1968_INPUT
    680         spin_lock_irqsave(&chip->ac97_lock, flags);
    681 #endif
    682672        outb(reg | 0x80, chip->io_port + ESM_AC97_INDEX);
    683673        /*msleep(1);*/
     
    687677                /*msleep(1);*/
    688678        }
    689 #ifndef CONFIG_SND_ES1968_INPUT
    690         spin_unlock_irqrestore(&chip->ac97_lock, flags);
    691 #endif
    692679
    693680        return data;
     
    702689                if (__maestro_read(chip, IDR1_CRAM_POINTER) == index)
    703690                        return;
    704         snd_printd("es1968: APU register select failed. (Timeout)\n");
     691        dev_dbg(chip->card->dev, "APU register select failed. (Timeout)\n");
    705692}
    706693
     
    714701                __maestro_write(chip, IDR0_DATA_PORT, data);
    715702        }
    716         snd_printd("es1968: APU register set probably failed (Timeout)!\n");
     703        dev_dbg(chip->card->dev, "APU register set probably failed (Timeout)!\n");
    717704}
    718705
     
    722709        if (snd_BUG_ON(channel >= NR_APUS))
    723710                return;
    724 #ifdef CONFIG_PM
     711#ifdef CONFIG_PM_SLEEP
    725712        chip->apu_map[channel][reg] = data;
    726713#endif
     
    1009996        wave_set_register(chip, es->apu[channel] << 3, tmpval);
    1010997
    1011 #ifdef CONFIG_PM
     998#ifdef CONFIG_PM_SLEEP
    1012999        es->wc_map[channel] = tmpval;
    10131000#endif
     
    13051292}
    13061293
    1307 static struct snd_pcm_hardware snd_es1968_playback = {
     1294static const struct snd_pcm_hardware snd_es1968_playback = {
    13081295        .info =                 (SNDRV_PCM_INFO_MMAP |
    13091296                                 SNDRV_PCM_INFO_MMAP_VALID |
     
    13261313};
    13271314
    1328 static struct snd_pcm_hardware snd_es1968_capture = {
     1315static const struct snd_pcm_hardware snd_es1968_capture = {
    13291316        .info =                 (SNDRV_PCM_INFO_NONINTERLEAVED |
    13301317                                 SNDRV_PCM_INFO_MMAP |
     
    14371424        if (! chip->dma.area)
    14381425                return;
    1439         snd_dma_reserve_buf(&chip->dma, snd_dma_pci_buf_id(chip->pci));
     1426        snd_dma_free_pages(&chip->dma);
    14401427        while ((p = chip->buf_list.next) != &chip->buf_list) {
    14411428                struct esm_memory *chunk = list_entry(p, struct esm_memory, list);
     
    14451432}
    14461433
    1447 static int __devinit
     1434static int
    14481435snd_es1968_init_dmabuf(struct es1968 *chip)
    14491436{
     
    14511438        struct esm_memory *chunk;
    14521439
    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;
    14691453        }
    14701454
     
    15061490        chan->memory = snd_es1968_new_memory(chip, size);
    15071491        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);
    15091494                return -ENOMEM;
    15101495        }
     
    16921677}
    16931678
    1694 static struct snd_pcm_ops snd_es1968_playback_ops = {
     1679static const struct snd_pcm_ops snd_es1968_playback_ops = {
    16951680        .open =         snd_es1968_playback_open,
    16961681        .close =        snd_es1968_playback_close,
    1697         .ioctl =        snd_pcm_lib_ioctl,
    16981682        .hw_params =    snd_es1968_hw_params,
    16991683        .hw_free =      snd_es1968_hw_free,
     
    17031687};
    17041688
    1705 static struct snd_pcm_ops snd_es1968_capture_ops = {
     1689static const struct snd_pcm_ops snd_es1968_capture_ops = {
    17061690        .open =         snd_es1968_capture_open,
    17071691        .close =        snd_es1968_capture_close,
    1708         .ioctl =        snd_pcm_lib_ioctl,
    17091692        .hw_params =    snd_es1968_hw_params,
    17101693        .hw_free =      snd_es1968_hw_free,
     
    17201703#define CLOCK_MEASURE_BUFSIZE   16768   /* enough large for a single shot */
    17211704
    1722 static void __devinit es1968_measure_clock(struct es1968 *chip)
     1705static void es1968_measure_clock(struct es1968 *chip)
    17231706{
    17241707        int i, apu;
    17251708        unsigned int pa, offset, t;
    17261709        struct esm_memory *memory;
     1710#ifndef TARGET_OS2
     1711        ktime_t start_time, stop_time;
     1712        ktime_t diff;
     1713#else
    17271714        struct timeval start_time, stop_time;
     1715#endif
    17281716
    17291717        if (chip->clock == 0)
     
    17321720        /* search 2 APUs (although one apu is enough) */
    17331721        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");
    17351723                return;
    17361724        }
    17371725        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);
    17391729                snd_es1968_free_apu_pair(chip, apu);
    17401730                return;
     
    17741764        __apu_set_register(chip, apu, 5, pa & 0xffff);
    17751765        snd_es1968_trigger_apu(chip, apu, ESM_APU_16BITLINEAR);
     1766#ifndef TARGET_OS2
     1767        start_time = ktime_get();
     1768#else
    17761769        do_gettimeofday(&start_time);
     1770#endif
    17771771        spin_unlock_irq(&chip->reg_lock);
    17781772        msleep(50);
    17791773        spin_lock_irq(&chip->reg_lock);
    17801774        offset = __apu_get_register(chip, apu, 5);
     1775#ifndef TARGET_OS2
     1776        stop_time = ktime_get();
     1777#else
    17811778        do_gettimeofday(&stop_time);
     1779#endif
    17821780        snd_es1968_trigger_apu(chip, apu, 0); /* stop */
    17831781        snd_es1968_bob_dec(chip);
     
    17901788        offset += chip->measure_count * (CLOCK_MEASURE_BUFSIZE/2);
    17911789
     1790#ifndef TARGET_OS2
     1791        diff = ktime_sub(stop_time, start_time);
     1792        t = ktime_to_us(diff);
     1793#else
    17921794        t = stop_time.tv_sec - start_time.tv_sec;
    17931795        t *= 1000000;
     
    17961798        else
    17971799                t += stop_time.tv_usec - start_time.tv_usec;
     1800#endif
    17981801        if (t == 0) {
    1799                 snd_printk(KERN_ERR "?? calculation error..\n");
     1802                dev_err(chip->card->dev, "?? calculation error..\n");
    18001803        } else {
    18011804                offset *= 1000;
     
    18051808                                chip->clock = (chip->clock * offset) / 48000;
    18061809                }
    1807                 printk(KERN_INFO "es1968: clocking to %d\n", chip->clock);
     1810                dev_info(chip->card->dev, "clocking to %d\n", chip->clock);
    18081811        }
    18091812        snd_es1968_free_memory(chip, memory);
     
    18221825}
    18231826
    1824 static int __devinit
     1827static int
    18251828snd_es1968_pcm(struct es1968 *chip, int device)
    18261829{
     
    19061909   generating an interrupt. The pair of counters is stored in bits 1-3 and 5-7
    19071910   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;
     1911static void es1968_update_hw_volume(struct work_struct *work)
     1912{
     1913        struct es1968 *chip = container_of(work, struct es1968, hwvol_work);
    19111914        int x, val;
    1912 #ifndef CONFIG_SND_ES1968_INPUT
    1913         unsigned long flags;
    1914 #endif
    19151915
    19161916        /* Figure out which volume control button was pushed,
     
    19311931                return;
    19321932
    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);
    19361934        switch (x) {
    19371935        case 0x88:
    19381936                /* mute */
    19391937                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);
    19451938                break;
    19461939        case 0xaa:
     
    19501943                if ((val & 0x7f00) > 0)
    19511944                        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);
    19571945                break;
    19581946        case 0x66:
     
    19621950                if ((val & 0x7f00) < 0x1f00)
    19631951                        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))
    19671955                snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
    19681956                               &chip->master_volume->id);
    1969                 break;
    1970         }
    1971         spin_unlock_irqrestore(&chip->ac97_lock, flags);
    19721957#else
    19731958        if (!chip->input_dev)
     
    20152000
    20162001        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);
    20222003
    20232004        /* else ack 'em all, i imagine */
     
    20542035 */
    20552036
    2056 static int __devinit
     2037static int
    20572038snd_es1968_mixer(struct es1968 *chip)
    20582039{
     
    20632044#endif
    20642045        int err;
    2065         static struct snd_ac97_bus_ops ops = {
     2046        static const struct snd_ac97_bus_ops ops = {
    20662047                .write = snd_es1968_ac97_write,
    20672048                .read = snd_es1968_ac97_read,
     
    21472128
    21482129#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");
    21502131        /* try and do a software reset */
    21512132        outb(0x80 | 0x7c, ioaddr + 0x30);
     
    23292310
    23302311        /* it appears some maestros (dell 7500) only work if these are set,
    2331            regardless of wether we use the assp or not. */
     2312           regardless of whether we use the assp or not. */
    23322313
    23332314        outb(0, iobase + ASSP_CONTROL_B);
     
    24152396}
    24162397
    2417 #ifdef CONFIG_PM
     2398#ifdef CONFIG_PM_SLEEP
    24182399/*
    24192400 * PM support
    24202401 */
    2421 static int es1968_suspend(struct pci_dev *pci, pm_message_t state)
    2422 {
    2423         struct snd_card *card = pci_get_drvdata(pci);
     2402static int es1968_suspend(struct device *dev)
     2403{
     2404        struct snd_card *card = dev_get_drvdata(dev);
    24242405        struct es1968 *chip = card->private_data;
    24252406
     
    24282409
    24292410        chip->in_suspend = 1;
     2411        cancel_work_sync(&chip->hwvol_work);
    24302412        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    2431         snd_pcm_suspend_all(chip->pcm);
    24322413        snd_ac97_suspend(chip->ac97);
    24332414        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));
    24382415        return 0;
    24392416}
    24402417
    2441 static int es1968_resume(struct pci_dev *pci)
    2442 {
    2443         struct snd_card *card = pci_get_drvdata(pci);
     2418static int es1968_resume(struct device *dev)
     2419{
     2420        struct snd_card *card = dev_get_drvdata(dev);
    24442421        struct es1968 *chip = card->private_data;
    24452422        struct esschan *es;
     
    24472424        if (! chip->do_pm)
    24482425                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);
    24602426
    24612427        snd_es1968_chip_init(chip);
     
    24912457        return 0;
    24922458}
    2493 #endif /* CONFIG_PM */
     2459
     2460static 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 */
    24942465
    24952466#ifdef SUPPORT_JOYSTICK
    24962467#define JOYSTICK_ADDR   0x200
    2497 static int __devinit snd_es1968_create_gameport(struct es1968 *chip, int dev)
     2468static int snd_es1968_create_gameport(struct es1968 *chip, int dev)
    24982469{
    24992470        struct gameport *gp;
     
    25102481        chip->gameport = gp = gameport_allocate_port();
    25112482        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");
    25132485                release_and_free_resource(r);
    25142486                return -ENOMEM;
     
    25462518
    25472519#ifdef CONFIG_SND_ES1968_INPUT
    2548 static int __devinit snd_es1968_input_register(struct es1968 *chip)
     2520static int snd_es1968_input_register(struct es1968 *chip)
    25492521{
    25502522        struct input_dev *input_dev;
     
    25812553#endif /* CONFIG_SND_ES1968_INPUT */
    25822554
     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 */
     2563struct snd_es1968_tea575x_gpio {
     2564        u8 data, clk, wren, most;
     2565        char *name;
     2566};
     2567
     2568static 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
     2577static 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
     2590static 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
     2605static 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
     2625static 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
    25832632static int snd_es1968_free(struct es1968 *chip)
    25842633{
     2634        cancel_work_sync(&chip->hwvol_work);
    25852635#ifdef CONFIG_SND_ES1968_INPUT
    25862636        if (chip->input_dev)
     
    25892639
    25902640        if (chip->io_port) {
    2591                 if (chip->irq >= 0)
    2592                         synchronize_irq(chip->irq);
    25932641                outw(1, chip->io_port + 0x04); /* clear WP interrupts */
    25942642                outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */
    25952643        }
     2644
     2645#ifdef CONFIG_SND_ES1968_RADIO
     2646        snd_tea575x_exit(&chip->tea);
     2647        v4l2_device_unregister(&chip->v4l2_dev);
     2648#endif
    25962649
    25972650        if (chip->irq >= 0)
     
    26152668};
    26162669
    2617 static struct ess_device_list pm_whitelist[] __devinitdata = {
     2670static const struct ess_device_list pm_allowlist[] = {
    26182671        { TYPE_MAESTRO2E, 0x0e11 },     /* Compaq Armada */
    26192672        { TYPE_MAESTRO2E, 0x1028 },
     
    26222675        { TYPE_MAESTRO2E, 0x14c0 },     /* HP omnibook 4150 */
    26232676        { 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 */
    26242679};
    26252680
    2626 static struct ess_device_list mpu_blacklist[] __devinitdata = {
     2681static const struct ess_device_list mpu_denylist[] = {
    26272682        { TYPE_MAESTRO2, 0x125d },
    26282683};
    26292684
    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 = {
     2685static 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 = {
    26402696                .dev_free =     snd_es1968_dev_free,
    26412697        };
     
    26492705                return err;
    26502706        /* 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");
    26542711                pci_disable_device(pci);
    26552712                return -ENXIO;
     
    26692726        INIT_LIST_HEAD(&chip->substream_list);
    26702727        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);
    26752729        chip->card = card;
    26762730        chip->pci = pci;
     
    26872741        chip->io_port = pci_resource_start(pci, 0);
    26882742        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);
    26912745                snd_es1968_free(chip);
    26922746                return -EBUSY;
    26932747        }
    26942748        chip->irq = pci->irq;
     2749        card->sync_irq = chip->irq;
    26952750               
    26962751        /* Clear Maestro_map */
     
    27062761
    27072762        if (do_pm > 1) {
    2708                 /* disable power-management if not on the whitelist */
     2763                /* disable power-management if not on the allowlist */
    27092764                unsigned short vend;
    27102765                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) {
    27142769                                do_pm = 1;
    27152770                                break;
     
    27182773                if (do_pm > 1) {
    27192774                        /* not matched; disabling pm */
    2720                         printk(KERN_INFO "es1968: not attempting power management.\n");
     2775                        dev_info(card->dev, "not attempting power management.\n");
    27212776                        do_pm = 0;
    27222777                }
     
    27312786        }
    27322787
    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        }
     2812no_radio:
     2813#endif
    27342814
    27352815        *chip_ret = chip;
     
    27412821/*
    27422822 */
    2743 static int __devinit snd_es1968_probe(struct pci_dev *pci,
    2744                                       const struct pci_device_id *pci_id)
     2823static int snd_es1968_probe(struct pci_dev *pci,
     2824                            const struct pci_device_id *pci_id)
    27452825{
    27462826        static int dev;
     
    27572837        }
    27582838
    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);
    27602841        if (err < 0)
    27612842                return err;
     
    27712852                                     pci_id->driver_data,
    27722853                                     use_pm[dev],
     2854                                     radio_nr[dev],
    27732855                                     &chip)) < 0) {
    27742856                snd_card_free(card);
     
    28032885
    28042886        if (enable_mpu[dev] == 2) {
    2805                 /* check the black list */
     2887                /* check the deny list */
    28062888                unsigned short vend;
    28072889                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) {
    28112893                                enable_mpu[dev] = 0;
    28122894                                break;
     
    28172899                if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
    28182900                                               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");
    28222905                }
    28232906        }
     
    28282911        err = snd_es1968_input_register(chip);
    28292912        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);
    28322915#endif
    28332916
     
    28502933}
    28512934
    2852 static void __devexit snd_es1968_remove(struct pci_dev *pci)
     2935static void snd_es1968_remove(struct pci_dev *pci)
    28532936{
    28542937        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
     2940static struct pci_driver es1968_driver = {
     2941        .name = KBUILD_MODNAME,
    28602942        .id_table = snd_es1968_ids,
    28612943        .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        },
    28672948};
    28682949
    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)
     2950module_pci_driver(es1968_driver);
Note: See TracChangeset for help on using the changeset viewer.