Ignore:
Timestamp:
Apr 3, 2017, 4:51:56 PM (8 years ago)
Author:
David Azarewicz
Message:

Merged/reintegrated v2 branch into trunk. Trunk is now v2

Location:
GPL/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk

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

    r426 r598  
    4242#include <linux/moduleparam.h>
    4343#include <linux/firmware.h>
     44#include <linux/input.h>
    4445#include <sound/core.h>
    4546#include <sound/info.h>
     
    849850
    850851        spinlock_t reg_lock;
     852
     853#ifdef CONFIG_SND_MAESTRO3_INPUT
     854        struct input_dev *input_dev;
     855        char phys[64];                  /* physical device path */
     856#else
    851857        spinlock_t ac97_lock;
    852 
    853858        struct snd_kcontrol *master_switch;
    854859        struct snd_kcontrol *master_volume;
    855860        struct tasklet_struct hwvol_tq;
     861#endif
     862
     863        unsigned int in_suspend;
    856864
    857865#ifdef CONFIG_PM
     
    866874 * pci ids
    867875 */
    868 static struct pci_device_id snd_m3_ids[] = {
     876static DEFINE_PCI_DEVICE_TABLE(snd_m3_ids) = {
    869877        {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ALLEGRO_1, PCI_ANY_ID, PCI_ANY_ID,
    870878         PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
     
    889897
    890898static struct snd_pci_quirk m3_amp_quirk_list[] __devinitdata = {
     899        SND_PCI_QUIRK(0x0E11, 0x0094, "Compaq Evo N600c", 0x0c),
    891900        SND_PCI_QUIRK(0x10f7, 0x833e, "Panasonic CF-28", 0x0d),
    892901        SND_PCI_QUIRK(0x10f7, 0x833d, "Panasonic CF-72", 0x0d),
     
    16011610}
    16021611
     1612/* The m3's hardware volume works by incrementing / decrementing 2 counters
     1613   (without wrap around) in response to volume button presses and then
     1614   generating an interrupt. The pair of counters is stored in bits 1-3 and 5-7
     1615   of a byte wide register. The meaning of bits 0 and 4 is unknown. */
    16031616static void snd_m3_update_hw_volume(unsigned long private_data)
    16041617{
    16051618        struct snd_m3 *chip = (struct snd_m3 *) private_data;
    16061619        int x, val;
     1620#ifndef CONFIG_SND_MAESTRO3_INPUT
    16071621        unsigned long flags;
     1622#endif
    16081623
    16091624        /* Figure out which volume control button was pushed,
     
    16121627        x = inb(chip->iobase + SHADOW_MIX_REG_VOICE) & 0xee;
    16131628
    1614         /* Reset the volume control registers. */
     1629        /* Reset the volume counters to 4. Tests on the allegro integrated
     1630           into a Compaq N600C laptop, have revealed that:
     1631           1) Writing any value will result in the 2 counters being reset to
     1632              4 so writing 0x88 is not strictly necessary
     1633           2) Writing to any of the 4 involved registers will reset all 4
     1634              of them (and reading them always returns the same value for all
     1635              of them)
     1636           It could be that a maestro deviates from this, so leave the code
     1637           as is. */
    16151638        outb(0x88, chip->iobase + SHADOW_MIX_REG_VOICE);
    16161639        outb(0x88, chip->iobase + HW_VOL_COUNTER_VOICE);
     
    16181641        outb(0x88, chip->iobase + HW_VOL_COUNTER_MASTER);
    16191642
     1643        /* Ignore spurious HV interrupts during suspend / resume, this avoids
     1644           mistaking them for a mute button press. */
     1645        if (chip->in_suspend)
     1646                return;
     1647
     1648#ifndef CONFIG_SND_MAESTRO3_INPUT
    16201649        if (!chip->master_switch || !chip->master_volume)
    16211650                return;
     
    16271656        switch (x) {
    16281657        case 0x88:
    1629                 /* mute */
     1658                /* The counters have not changed, yet we've received a HV
     1659                   interrupt. According to tests run by various people this
     1660                   happens when pressing the mute button. */
    16301661                val ^= 0x8000;
    16311662                chip->ac97->regs[AC97_MASTER_VOL] = val;
     
    16361667                break;
    16371668        case 0xaa:
    1638                 /* volume up */
     1669                /* counters increased by 1 -> volume up */
    16391670                if ((val & 0x7f) > 0)
    16401671                        val--;
     
    16481679                break;
    16491680        case 0x66:
    1650                 /* volume down */
     1681                /* counters decreased by 1 -> volume down */
    16511682                if ((val & 0x7f) < 0x1f)
    16521683                        val++;
     
    16611692        }
    16621693        spin_unlock_irqrestore(&chip->ac97_lock, flags);
     1694#else
     1695        if (!chip->input_dev)
     1696                return;
     1697
     1698        val = 0;
     1699        switch (x) {
     1700        case 0x88:
     1701                /* The counters have not changed, yet we've received a HV
     1702                   interrupt. According to tests run by various people this
     1703                   happens when pressing the mute button. */
     1704                val = KEY_MUTE;
     1705                break;
     1706        case 0xaa:
     1707                /* counters increased by 1 -> volume up */
     1708                val = KEY_VOLUMEUP;
     1709                break;
     1710        case 0x66:
     1711                /* counters decreased by 1 -> volume down */
     1712                val = KEY_VOLUMEDOWN;
     1713                break;
     1714        }
     1715
     1716        if (val) {
     1717                input_report_key(chip->input_dev, val, 1);
     1718                input_sync(chip->input_dev);
     1719                input_report_key(chip->input_dev, val, 0);
     1720                input_sync(chip->input_dev);
     1721        }
     1722#endif
    16631723}
    16641724
     
    16751735
    16761736        if (status & HV_INT_PENDING)
     1737#ifdef CONFIG_SND_MAESTRO3_INPUT
     1738                snd_m3_update_hw_volume((unsigned long)chip);
     1739#else
    16771740                tasklet_schedule(&chip->hwvol_tq);
     1741#endif
    16781742
    16791743        /*
     
    19412005{
    19422006        struct snd_m3 *chip = ac97->private_data;
     2007#ifndef CONFIG_SND_MAESTRO3_INPUT
    19432008        unsigned long flags;
     2009#endif
    19442010        unsigned short data = 0xffff;
    19452011
    19462012        if (snd_m3_ac97_wait(chip))
    19472013                goto fail;
     2014#ifndef CONFIG_SND_MAESTRO3_INPUT
    19482015        spin_lock_irqsave(&chip->ac97_lock, flags);
     2016#endif
    19492017        snd_m3_outb(chip, 0x80 | (reg & 0x7f), CODEC_COMMAND);
    19502018        if (snd_m3_ac97_wait(chip))
     
    19522020        data = snd_m3_inw(chip, CODEC_DATA);
    19532021fail_unlock:
     2022#ifndef CONFIG_SND_MAESTRO3_INPUT
    19542023        spin_unlock_irqrestore(&chip->ac97_lock, flags);
     2024#endif
    19552025fail:
    19562026        return data;
     
    19612031{
    19622032        struct snd_m3 *chip = ac97->private_data;
     2033#ifndef CONFIG_SND_MAESTRO3_INPUT
    19632034        unsigned long flags;
     2035#endif
    19642036
    19652037        if (snd_m3_ac97_wait(chip))
    19662038                return;
     2039#ifndef CONFIG_SND_MAESTRO3_INPUT
    19672040        spin_lock_irqsave(&chip->ac97_lock, flags);
     2041#endif
    19682042        snd_m3_outw(chip, val, CODEC_DATA);
    19692043        snd_m3_outb(chip, reg & 0x7f, CODEC_COMMAND);
     2044#ifndef CONFIG_SND_MAESTRO3_INPUT
    19702045        spin_unlock_irqrestore(&chip->ac97_lock, flags);
     2046#endif
    19712047}
    19722048
     
    20752151        struct snd_ac97_bus *pbus;
    20762152        struct snd_ac97_template ac97;
     2153#ifndef CONFIG_SND_MAESTRO3_INPUT
    20772154        struct snd_ctl_elem_id elem_id;
     2155#endif
    20782156        int err;
    20792157        static struct snd_ac97_bus_ops ops = {
     
    20952173        snd_ac97_write(chip->ac97, AC97_PCM, 0);
    20962174
     2175#ifndef CONFIG_SND_MAESTRO3_INPUT
    20972176        memset(&elem_id, 0, sizeof(elem_id));
    20982177        elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     
    21032182        strcpy(elem_id.name, "Master Playback Volume");
    21042183        chip->master_volume = snd_ctl_find_id(chip->card, &elem_id);
     2184#endif
    21052185
    21062186        return 0;
     
    23682448        if (chip->hv_config & HV_CTRL_ENABLE)
    23692449                val |= HV_INT_ENABLE;
     2450        outb(val, chip->iobase + HOST_INT_STATUS);
    23702451        outw(val, io + HOST_INT_CTRL);
    23712452        outb(inb(io + ASSP_CONTROL_C) | ASSP_HOST_INT_ENABLE,
     
    23812462        struct m3_dma *s;
    23822463        int i;
     2464
     2465#ifdef CONFIG_SND_MAESTRO3_INPUT
     2466        if (chip->input_dev)
     2467                input_unregister_device(chip->input_dev);
     2468#endif
    23832469
    23842470        if (chip->substreams) {
     
    24292515                return 0;
    24302516
     2517        chip->in_suspend = 1;
    24312518        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    24322519        snd_pcm_suspend_all(chip->pcm);
     
    25022589
    25032590        snd_power_change_state(card, SNDRV_CTL_POWER_D0);
     2591        chip->in_suspend = 0;
    25042592        return 0;
    25052593}
    25062594#endif /* CONFIG_PM */
    25072595
     2596#ifdef CONFIG_SND_MAESTRO3_INPUT
     2597static int __devinit snd_m3_input_register(struct snd_m3 *chip)
     2598{
     2599        struct input_dev *input_dev;
     2600        int err;
     2601
     2602        input_dev = input_allocate_device();
     2603        if (!input_dev)
     2604                return -ENOMEM;
     2605
     2606        snprintf(chip->phys, sizeof(chip->phys), "pci-%s/input0",
     2607                 pci_name(chip->pci));
     2608
     2609        input_dev->name = chip->card->driver;
     2610        input_dev->phys = chip->phys;
     2611        input_dev->id.bustype = BUS_PCI;
     2612        input_dev->id.vendor  = chip->pci->vendor;
     2613        input_dev->id.product = chip->pci->device;
     2614        input_dev->dev.parent = &chip->pci->dev;
     2615
     2616        __set_bit(EV_KEY, input_dev->evbit);
     2617        __set_bit(KEY_MUTE, input_dev->keybit);
     2618        __set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
     2619        __set_bit(KEY_VOLUMEUP, input_dev->keybit);
     2620
     2621        err = input_register_device(input_dev);
     2622        if (err) {
     2623                input_free_device(input_dev);
     2624                return err;
     2625        }
     2626
     2627        chip->input_dev = input_dev;
     2628        return 0;
     2629}
     2630#endif /* CONFIG_INPUT */
    25082631
    25092632/*
     
    25492672
    25502673        spin_lock_init(&chip->reg_lock);
     2674#ifndef CONFIG_SND_MAESTRO3_INPUT
    25512675        spin_lock_init(&chip->ac97_lock);
     2676#endif
    25522677
    25532678        switch (pci->device) {
     
    26362761        snd_m3_hv_init(chip);
    26372762
     2763#ifndef CONFIG_SND_MAESTRO3_INPUT
    26382764        tasklet_init(&chip->hwvol_tq, snd_m3_update_hw_volume, (unsigned long)chip);
     2765#endif
    26392766
    26402767        if (request_irq(pci->irq, snd_m3_interrupt, IRQF_SHARED,
     
    26682795        if ((err = snd_m3_pcm(chip, 0)) < 0)
    26692796                return err;
    2670    
     2797
     2798#ifdef CONFIG_SND_MAESTRO3_INPUT
     2799        if (chip->hv_config & HV_CTRL_ENABLE) {
     2800                err = snd_m3_input_register(chip);
     2801                if (err)
     2802                        snd_printk(KERN_WARNING "Input device registration "
     2803                                "failed with error %i", err);
     2804        }
     2805#endif
     2806
    26712807        snd_m3_enable_ints(chip);
    26722808        snd_m3_assp_continue(chip);
Note: See TracChangeset for help on using the changeset viewer.