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/emu10k1/p16v.c

    r464 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
     
    7071 *    DAC: CS4382-K (8-channel, 24bit, 192Khz)
    7172 *
    72  *  This code was initally based on code from ALSA's emu10k1x.c which is:
     73 *  This code was initially based on code from ALSA's emu10k1x.c which is:
    7374 *  Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
    74  *
    75  *   This program is free software; you can redistribute it and/or modify
    76  *   it under the terms of the GNU General Public License as published by
    77  *   the Free Software Foundation; either version 2 of the License, or
    78  *   (at your option) any later version.
    79  *
    80  *   This program is distributed in the hope that it will be useful,
    81  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    82  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    83  *   GNU General Public License for more details.
    84  *
    85  *   You should have received a copy of the GNU General Public License
    86  *   along with this program; if not, write to the Free Software
    87  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    88  *
    8975 */
    9076#include <linux/delay.h>
     
    123109
    124110 /* hardware definition */
    125 static struct snd_pcm_hardware snd_p16v_playback_hw = {
     111static const struct snd_pcm_hardware snd_p16v_playback_hw = {
    126112        .info =                 SNDRV_PCM_INFO_MMAP |
    127113                                SNDRV_PCM_INFO_INTERLEAVED |
     
    144130};
    145131
    146 static struct snd_pcm_hardware snd_p16v_capture_hw = {
     132static const struct snd_pcm_hardware snd_p16v_capture_hw = {
    147133        .info =                 (SNDRV_PCM_INFO_MMAP |
    148134                                 SNDRV_PCM_INFO_INTERLEAVED |
     
    167153{
    168154        struct snd_emu10k1_pcm *epcm = runtime->private_data;
    169  
    170         if (epcm) {
    171                 /* snd_printk(KERN_DEBUG "epcm free: %p\n", epcm); */
    172                 kfree(epcm);
    173         }
     155
     156        kfree(epcm);
    174157}
    175158
     
    184167
    185168        epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
    186         /* snd_printk(KERN_DEBUG "epcm kcalloc: %p\n", epcm); */
     169        /* dev_dbg(emu->card->dev, "epcm kcalloc: %p\n", epcm); */
    187170
    188171        if (epcm == NULL)
     
    191174        epcm->substream = substream;
    192175        /*
    193         snd_printk(KERN_DEBUG "epcm device=%d, channel_id=%d\n",
     176        dev_dbg(emu->card->dev, "epcm device=%d, channel_id=%d\n",
    194177                   substream->pcm->device, channel_id);
    195178        */
     
    204187        channel->use=1;
    205188#if 0 /* debug */
    206         snd_printk(KERN_DEBUG
     189        dev_dbg(emu->card->dev,
    207190                   "p16v: open channel_id=%d, channel=%p, use=0x%x\n",
    208191                   channel_id, channel, channel->use);
    209         printk(KERN_DEBUG "open:channel_id=%d, chip=%p, channel=%p\n",
     192        dev_dbg(emu->card->dev, "open:channel_id=%d, chip=%p, channel=%p\n",
    210193               channel_id, chip, channel);
    211194#endif /* debug */
     
    232215
    233216        epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
    234         /* snd_printk(KERN_DEBUG "epcm kcalloc: %p\n", epcm); */
     217        /* dev_dbg(emu->card->dev, "epcm kcalloc: %p\n", epcm); */
    235218
    236219        if (epcm == NULL)
     
    239222        epcm->substream = substream;
    240223        /*
    241         snd_printk(KERN_DEBUG "epcm device=%d, channel_id=%d\n",
     224        dev_dbg(emu->card->dev, "epcm device=%d, channel_id=%d\n",
    242225                   substream->pcm->device, channel_id);
    243226        */
     
    252235        channel->use=1;
    253236#if 0 /* debug */
    254         snd_printk(KERN_DEBUG
     237        dev_dbg(emu->card->dev,
    255238                   "p16v: open channel_id=%d, channel=%p, use=0x%x\n",
    256239                   channel_id, channel, channel->use);
    257         printk(KERN_DEBUG "open:channel_id=%d, chip=%p, channel=%p\n",
     240        dev_dbg(emu->card->dev, "open:channel_id=%d, chip=%p, channel=%p\n",
    258241               channel_id, chip, channel);
    259242#endif /* debug */
     
    299282        return snd_p16v_pcm_open_capture_channel(substream, 0);
    300283}
    301 
    302 /* hw_params callback */
    303 static int snd_p16v_pcm_hw_params_playback(struct snd_pcm_substream *substream,
    304                                       struct snd_pcm_hw_params *hw_params)
    305 {
    306         int result;
    307         result = snd_pcm_lib_malloc_pages(substream,
    308                                         params_buffer_bytes(hw_params));
    309         return result;
    310 }
    311 
    312 /* hw_params callback */
    313 static int snd_p16v_pcm_hw_params_capture(struct snd_pcm_substream *substream,
    314                                       struct snd_pcm_hw_params *hw_params)
    315 {
    316         int result;
    317         result = snd_pcm_lib_malloc_pages(substream,
    318                                         params_buffer_bytes(hw_params));
    319         return result;
    320 }
    321 
    322 
    323 /* hw_free callback */
    324 static int snd_p16v_pcm_hw_free_playback(struct snd_pcm_substream *substream)
    325 {
    326         int result;
    327         result = snd_pcm_lib_free_pages(substream);
    328         return result;
    329 }
    330 
    331 /* hw_free callback */
    332 static int snd_p16v_pcm_hw_free_capture(struct snd_pcm_substream *substream)
    333 {
    334         int result;
    335         result = snd_pcm_lib_free_pages(substream);
    336         return result;
    337 }
    338 
    339284
    340285/* prepare playback callback */
     
    350295       
    351296#if 0 /* debug */
    352         snd_printk(KERN_DEBUG "prepare:channel_number=%d, rate=%d, "
     297        dev_dbg(emu->card->dev,
     298                "prepare:channel_number=%d, rate=%d, "
    353299                   "format=0x%x, channels=%d, buffer_size=%ld, "
    354300                   "period_size=%ld, periods=%u, frames_to_bytes=%d\n",
     
    356302                   runtime->buffer_size, runtime->period_size,
    357303                   runtime->periods, frames_to_bytes(runtime, 1));
    358         snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, table_base=%p\n",
     304        dev_dbg(emu->card->dev,
     305                "dma_addr=%x, dma_area=%p, table_base=%p\n",
    359306                   runtime->dma_addr, runtime->dma_area, table_base);
    360         snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",
     307        dev_dbg(emu->card->dev,
     308                "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",
    361309                   emu->p16v_buffer.addr, emu->p16v_buffer.area,
    362310                   emu->p16v_buffer.bytes);
     
    406354
    407355        /*
    408         printk(KERN_DEBUG "prepare capture:channel_number=%d, rate=%d, "
     356        dev_dbg(emu->card->dev, "prepare capture:channel_number=%d, rate=%d, "
    409357               "format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, "
    410358               "frames_to_bytes=%d\n",
     
    492440                epcm = runtime->private_data;
    493441                channel = substream->pcm->device-emu->p16v_device_offset;
    494                 /* snd_printk(KERN_DEBUG "p16v channel=%d\n", channel); */
     442                /* dev_dbg(emu->card->dev, "p16v channel=%d\n", channel); */
    495443                epcm->running = running;
    496444                basic |= (0x1<<channel);
     
    498446                snd_pcm_trigger_done(s, substream);
    499447        }
    500         /* snd_printk(KERN_DEBUG "basic=0x%x, inte=0x%x\n", basic, inte); */
     448        /* dev_dbg(emu->card->dev, "basic=0x%x, inte=0x%x\n", basic, inte); */
    501449
    502450        switch (cmd) {
     
    589537        if (ptr >= runtime->buffer_size) {
    590538                ptr -= runtime->buffer_size;
    591                 printk(KERN_WARNING "buffer capture limited!\n");
     539                dev_warn(emu->card->dev, "buffer capture limited!\n");
    592540        }
    593541        /*
    594         printk(KERN_DEBUG "ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, "
     542        dev_dbg(emu->card->dev, "ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, "
    595543               "buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n",
    596544               ptr1, ptr2, ptr, (int)runtime->buffer_size,
     
    602550
    603551/* operators */
    604 static struct snd_pcm_ops snd_p16v_playback_front_ops = {
     552static const struct snd_pcm_ops snd_p16v_playback_front_ops = {
    605553        .open =        snd_p16v_pcm_open_playback_front,
    606554        .close =       snd_p16v_pcm_close_playback,
    607         .ioctl =       snd_pcm_lib_ioctl,
    608         .hw_params =   snd_p16v_pcm_hw_params_playback,
    609         .hw_free =     snd_p16v_pcm_hw_free_playback,
    610555        .prepare =     snd_p16v_pcm_prepare_playback,
    611556        .trigger =     snd_p16v_pcm_trigger_playback,
     
    613558};
    614559
    615 static struct snd_pcm_ops snd_p16v_capture_ops = {
     560static const struct snd_pcm_ops snd_p16v_capture_ops = {
    616561        .open =        snd_p16v_pcm_open_capture,
    617562        .close =       snd_p16v_pcm_close_capture,
    618         .ioctl =       snd_pcm_lib_ioctl,
    619         .hw_params =   snd_p16v_pcm_hw_params_capture,
    620         .hw_free =     snd_p16v_pcm_hw_free_capture,
    621563        .prepare =     snd_p16v_pcm_prepare_capture,
    622564        .trigger =     snd_p16v_pcm_trigger_capture,
     
    631573                snd_dma_free_pages(&chip->p16v_buffer);
    632574                /*
    633                 snd_printk(KERN_DEBUG "period lables free: %p\n",
     575                dev_dbg(chip->card->dev, "period lables free: %p\n",
    634576                           &chip->p16v_buffer);
    635577                */
     
    638580}
    639581
    640 int __devinit snd_p16v_pcm(struct snd_emu10k1 *emu, int device, struct snd_pcm **rpcm)
     582int snd_p16v_pcm(struct snd_emu10k1 *emu, int device)
    641583{
    642584        struct snd_pcm *pcm;
     
    645587        int capture=1;
    646588 
    647         /* snd_printk(KERN_DEBUG "snd_p16v_pcm called. device=%d\n", device); */
     589        /* dev_dbg(emu->card->dev, "snd_p16v_pcm called. device=%d\n", device); */
    648590        emu->p16v_device_offset = device;
    649         if (rpcm)
    650                 *rpcm = NULL;
    651591
    652592        if ((err = snd_pcm_new(emu->card, "p16v", device, 1, capture, &pcm)) < 0)
     
    667607            substream;
    668608            substream = substream->next) {
    669                 if ((err = snd_pcm_lib_preallocate_pages(substream,
    670                                                          SNDRV_DMA_TYPE_DEV,
    671                                                          snd_dma_pci_data(emu->pci),
    672                                                          ((65536 - 64) * 8), ((65536 - 64) * 8))) < 0)
    673                         return err;
     609                snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV,
     610                                           &emu->pci->dev,
     611                                           (65536 - 64) * 8,
     612                                           (65536 - 64) * 8);
    674613                /*
    675                 snd_printk(KERN_DEBUG
     614                dev_dbg(emu->card->dev,
    676615                           "preallocate playback substream: err=%d\n", err);
    677616                */
     
    681620              substream;
    682621              substream = substream->next) {
    683                 if ((err = snd_pcm_lib_preallocate_pages(substream,
    684                                                    SNDRV_DMA_TYPE_DEV,
    685                                                    snd_dma_pci_data(emu->pci),
    686                                                    65536 - 64, 65536 - 64)) < 0)
    687                         return err;
     622                snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV,
     623                                           &emu->pci->dev,
     624                                           65536 - 64, 65536 - 64);
    688625                /*
    689                 snd_printk(KERN_DEBUG
     626                dev_dbg(emu->card->dev,
    690627                           "preallocate capture substream: err=%d\n", err);
    691628                */
    692629        }
    693  
    694         if (rpcm)
    695                 *rpcm = pcm;
    696630 
    697631        return 0;
     
    755689                                        struct snd_ctl_elem_info *uinfo)
    756690{
    757         static char *texts[8] = {
     691        static const char * const texts[8] = {
    758692                "SPDIF", "I2S", "SRC48", "SRCMulti_SPDIF", "SRCMulti_I2S",
    759693                "CDIF", "FX", "AC97"
    760694        };
    761695
    762         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    763         uinfo->count = 1;
    764         uinfo->value.enumerated.items = 8;
    765         if (uinfo->value.enumerated.item > 7)
    766                 uinfo->value.enumerated.item = 7;
    767         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    768         return 0;
     696        return snd_ctl_enum_info(uinfo, 1, 8, texts);
    769697}
    770698
     
    803731                                         struct snd_ctl_elem_info *uinfo)
    804732{
    805         static char *texts[4] = { "0", "1", "2", "3",  };
    806 
    807         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    808         uinfo->count = 1;
    809         uinfo->value.enumerated.items = 4;
    810         if (uinfo->value.enumerated.item > 3)
    811                 uinfo->value.enumerated.item = 3;
    812         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    813         return 0;
     733        static const char * const texts[4] = { "0", "1", "2", "3", };
     734
     735        return snd_ctl_enum_info(uinfo, 1, 4, texts);
    814736}
    815737
     
    855777}
    856778
    857 static struct snd_kcontrol_new p16v_mixer_controls[] __devinitdata = {
     779static const struct snd_kcontrol_new p16v_mixer_controls[] = {
    858780        P16V_VOL("HD Analog Front Playback Volume", PLAYBACK_VOLUME_MIXER9, 0),
    859781        P16V_VOL("HD Analog Rear Playback Volume", PLAYBACK_VOLUME_MIXER10, 1),
     
    881803
    882804
    883 int __devinit snd_p16v_mixer(struct snd_emu10k1 *emu)
     805int snd_p16v_mixer(struct snd_emu10k1 *emu)
    884806{
    885807        int i, err;
     
    894816}
    895817
    896 #ifdef CONFIG_PM
     818#ifdef CONFIG_PM_SLEEP
    897819
    898820#define NUM_CHS 1       /* up to 4, but only first channel is used */
    899821
    900 int __devinit snd_p16v_alloc_pm_buffer(struct snd_emu10k1 *emu)
    901 {
     822int snd_p16v_alloc_pm_buffer(struct snd_emu10k1 *emu)
     823{
     824#ifdef TARGET_OS2
     825        emu->p16v_saved = vmalloc(array_size(NUM_CHS * 4, 0x80));
     826#else
    902827        emu->p16v_saved = vmalloc(NUM_CHS * 4 * 0x80);
     828#endif
    903829        if (! emu->p16v_saved)
    904830                return -ENOMEM;
Note: See TracChangeset for help on using the changeset viewer.