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/fm801.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  The driver for the ForteMedia FM801 based soundcards
    34 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
    4  *
    5  *  Support FM only card by Andy Shevchenko <andy@smile.org.ua>
    6  *
    7  *   This program is free software; you can redistribute it and/or modify
    8  *   it under the terms of the GNU General Public License as published by
    9  *   the Free Software Foundation; either version 2 of the License, or
    10  *   (at your option) any later version.
    11  *
    12  *   This program is distributed in the hope that it will be useful,
    13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  *   GNU General Public License for more details.
    16  *
    17  *   You should have received a copy of the GNU General Public License
    18  *   along with this program; if not, write to the Free Software
    19  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    20  *
    215 */
    226
     
    248#include <linux/init.h>
    259#include <linux/interrupt.h>
     10#include <linux/io.h>
    2611#include <linux/pci.h>
    2712#include <linux/slab.h>
    28 #include <linux/moduleparam.h>
     13#include <linux/module.h>
    2914#include <sound/core.h>
    3015#include <sound/pcm.h>
     
    3520#include <sound/initval.h>
    3621
    37 #include <asm/io.h>
     22#ifdef TARGET_OS2
     23#define KBUILD_MODNAME "fm801"
     24#endif
    3825
    3926#ifdef CONFIG_SND_FM801_TEA575X_BOOL
    40 #include <sound/tea575x-tuner.h>
    41 #define TEA575X_RADIO 1
     27#include <media/drv-intf/tea575x.h>
    4228#endif
    4329
     
    5036static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
    5137static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
    52 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable this card */
     38static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable this card */
    5339/*
    5440 *  Enable TEA575x tuner
    5541 *    1 = MediaForte 256-PCS
    56  *    2 = MediaForte 256-PCPR
     42 *    2 = MediaForte 256-PCP
    5743 *    3 = MediaForte 64-PCR
    5844 *   16 = setup tuner only (this is additional bit), i.e. SF64-PCR FM card
     
    6046 */
    6147static int tea575x_tuner[SNDRV_CARDS];
     48#ifndef TARGET_OS2
     49static int radio_nr[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
     50#else
     51static int radio_nr[SNDRV_CARDS] =  { REPEAT_SNDRV(1) };
     52#endif
    6253
    6354module_param_array(index, int, NULL, 0444);
     
    6859MODULE_PARM_DESC(enable, "Enable FM801 soundcard.");
    6960module_param_array(tea575x_tuner, int, NULL, 0444);
    70 MODULE_PARM_DESC(tea575x_tuner, "TEA575x tuner access method (1 = SF256-PCS, 2=SF256-PCPR, 3=SF64-PCR, +16=tuner-only).");
    71 
     61MODULE_PARM_DESC(tea575x_tuner, "TEA575x tuner access method (0 = auto, 1 = SF256-PCS, 2=SF256-PCP, 3=SF64-PCR, 8=disable, +16=tuner-only).");
     62module_param_array(radio_nr, int, NULL, 0444);
     63MODULE_PARM_DESC(radio_nr, "Radio device numbers");
     64
     65
     66#define TUNER_DISABLED          (1<<3)
    7267#define TUNER_ONLY              (1<<4)
    7368#define TUNER_TYPE_MASK         (~TUNER_ONLY & 0xFFFF)
     
    7772 */
    7873
    79 #define FM801_REG(chip, reg)    (chip->port + FM801_##reg)
     74#define fm801_writew(chip,reg,value)    outw((value), chip->port + FM801_##reg)
     75#define fm801_readw(chip,reg)           inw(chip->port + FM801_##reg)
     76
     77#define fm801_writel(chip,reg,value)    outl((value), chip->port + FM801_##reg)
    8078
    8179#define FM801_PCM_VOL           0x00    /* PCM Output Volume */
     
    153151#define FM801_GPIO_GS(x)        (1<<(12+(x)))
    154152       
    155 /*
    156 
     153/**
     154 * struct fm801 - describes FM801 chip
     155 * @dev:                device for this chio
     156 * @irq:                irq number
     157 * @port:               I/O port number
     158 * @multichannel:       multichannel support
     159 * @secondary:          secondary codec
     160 * @secondary_addr:     address of the secondary codec
     161 * @tea575x_tuner:      tuner access method & flags
     162 * @ply_ctrl:           playback control
     163 * @cap_ctrl:           capture control
     164 * @ply_buffer:         playback buffer
     165 * @ply_buf:            playback buffer index
     166 * @ply_count:          playback buffer count
     167 * @ply_size:           playback buffer size
     168 * @ply_pos:            playback position
     169 * @cap_buffer:         capture buffer
     170 * @cap_buf:            capture buffer index
     171 * @cap_count:          capture buffer count
     172 * @cap_size:           capture buffer size
     173 * @cap_pos:            capture position
     174 * @ac97_bus:           ac97 bus handle
     175 * @ac97:               ac97 handle
     176 * @ac97_sec:           ac97 secondary handle
     177 * @card:               ALSA card
     178 * @pcm:                PCM devices
     179 * @rmidi:              rmidi device
     180 * @playback_substream: substream for playback
     181 * @capture_substream:  substream for capture
     182 * @p_dma_size:         playback DMA size
     183 * @c_dma_size:         capture DMA size
     184 * @reg_lock:           lock
     185 * @proc_entry:         /proc entry
     186 * @v4l2_dev:           v4l2 device
     187 * @tea:                tea575a structure
     188 * @saved_regs:         context saved during suspend
    157189 */
    158 
    159190struct fm801 {
     191        struct device *dev;
    160192        int irq;
    161193
    162         unsigned long port;     /* I/O port number */
    163         unsigned int multichannel: 1,   /* multichannel support */
    164                      secondary: 1;      /* secondary codec */
    165         unsigned char secondary_addr;   /* address of the secondary codec */
    166         unsigned int tea575x_tuner;     /* tuner access method & flags */
    167 
    168         unsigned short ply_ctrl; /* playback control */
    169         unsigned short cap_ctrl; /* capture control */
     194        unsigned long port;
     195        unsigned int multichannel: 1,
     196                     secondary: 1;
     197        unsigned char secondary_addr;
     198        unsigned int tea575x_tuner;
     199
     200        unsigned short ply_ctrl;
     201        unsigned short cap_ctrl;
    170202
    171203        unsigned long ply_buffer;
     
    185217        struct snd_ac97 *ac97_sec;
    186218
    187         struct pci_dev *pci;
    188219        struct snd_card *card;
    189220        struct snd_pcm *pcm;
     
    197228        struct snd_info_entry *proc_entry;
    198229
    199 #ifdef TEA575X_RADIO
     230#ifdef CONFIG_SND_FM801_TEA575X_BOOL
     231        struct v4l2_device v4l2_dev;
    200232        struct snd_tea575x tea;
    201233#endif
    202234
    203 #ifdef CONFIG_PM
     235#ifdef CONFIG_PM_SLEEP
    204236        u16 saved_regs[0x20];
    205237#endif
    206238};
    207239
    208 static DEFINE_PCI_DEVICE_TABLE(snd_fm801_ids) = {
     240/*
     241 * IO accessors
     242 */
     243
     244static inline void fm801_iowrite16(struct fm801 *chip, unsigned short offset, u16 value)
     245{
     246        outw(value, chip->port + offset);
     247}
     248
     249static inline u16 fm801_ioread16(struct fm801 *chip, unsigned short offset)
     250{
     251        return inw(chip->port + offset);
     252}
     253
     254static const struct pci_device_id snd_fm801_ids[] = {
    209255        { 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, },   /* FM801 */
    210256        { 0x5213, 0x0510, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, },   /* Gallant Odyssey Sound 4 */
     
    218264 */
    219265
     266static bool fm801_ac97_is_ready(struct fm801 *chip, unsigned int iterations)
     267{
     268        unsigned int idx;
     269
     270        for (idx = 0; idx < iterations; idx++) {
     271                if (!(fm801_readw(chip, AC97_CMD) & FM801_AC97_BUSY))
     272                        return true;
     273                udelay(10);
     274        }
     275        return false;
     276}
     277
     278static bool fm801_ac97_is_valid(struct fm801 *chip, unsigned int iterations)
     279{
     280        unsigned int idx;
     281
     282        for (idx = 0; idx < iterations; idx++) {
     283                if (fm801_readw(chip, AC97_CMD) & FM801_AC97_VALID)
     284                        return true;
     285                udelay(10);
     286        }
     287        return false;
     288}
     289
    220290static int snd_fm801_update_bits(struct fm801 *chip, unsigned short reg,
    221291                                 unsigned short mask, unsigned short value)
     
    226296
    227297        spin_lock_irqsave(&chip->reg_lock, flags);
    228         old = inw(chip->port + reg);
     298        old = fm801_ioread16(chip, reg);
    229299        new = (old & ~mask) | value;
    230300        change = old != new;
    231301        if (change)
    232                 outw(new, chip->port + reg);
     302                fm801_iowrite16(chip, reg, new);
    233303        spin_unlock_irqrestore(&chip->reg_lock, flags);
    234304        return change;
     
    240310{
    241311        struct fm801 *chip = ac97->private_data;
    242         int idx;
    243312
    244313        /*
    245314         *  Wait until the codec interface is not ready..
    246315         */
    247         for (idx = 0; idx < 100; idx++) {
    248                 if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
    249                         goto ok1;
    250                 udelay(10);
    251         }
    252         snd_printk(KERN_ERR "AC'97 interface is busy (1)\n");
    253         return;
    254 
    255  ok1:
     316        if (!fm801_ac97_is_ready(chip, 100)) {
     317                dev_err(chip->card->dev, "AC'97 interface is busy (1)\n");
     318                return;
     319        }
     320
    256321        /* write data and address */
    257         outw(val, FM801_REG(chip, AC97_DATA));
    258         outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT), FM801_REG(chip, AC97_CMD));
     322        fm801_writew(chip, AC97_DATA, val);
     323        fm801_writew(chip, AC97_CMD, reg | (ac97->addr << FM801_AC97_ADDR_SHIFT));
    259324        /*
    260325         *  Wait until the write command is not completed..
    261          */
    262         for (idx = 0; idx < 1000; idx++) {
    263                 if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
    264                         return;
    265                 udelay(10);
    266         }
    267         snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
     326         */
     327        if (!fm801_ac97_is_ready(chip, 1000))
     328                dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)\n",
     329                ac97->num);
    268330}
    269331
     
    271333{
    272334        struct fm801 *chip = ac97->private_data;
    273         int idx;
    274335
    275336        /*
    276337         *  Wait until the codec interface is not ready..
    277338         */
    278         for (idx = 0; idx < 100; idx++) {
    279                 if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
    280                         goto ok1;
    281                 udelay(10);
    282         }
    283         snd_printk(KERN_ERR "AC'97 interface is busy (1)\n");
    284         return 0;
    285 
    286  ok1:
     339        if (!fm801_ac97_is_ready(chip, 100)) {
     340                dev_err(chip->card->dev, "AC'97 interface is busy (1)\n");
     341                return 0;
     342        }
     343
    287344        /* read command */
    288         outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ,
    289              FM801_REG(chip, AC97_CMD));
    290         for (idx = 0; idx < 100; idx++) {
    291                 if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
    292                         goto ok2;
    293                 udelay(10);
    294         }
    295         snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
    296         return 0;
    297 
    298  ok2:
    299         for (idx = 0; idx < 1000; idx++) {
    300                 if (inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_VALID)
    301                         goto ok3;
    302                 udelay(10);
    303         }
    304         snd_printk(KERN_ERR "AC'97 interface #%d is not valid (2)\n", ac97->num);
    305         return 0;
    306 
    307  ok3:
    308         return inw(FM801_REG(chip, AC97_DATA));
    309 }
    310 
    311 static unsigned int rates[] = {
     345        fm801_writew(chip, AC97_CMD,
     346                     reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ);
     347        if (!fm801_ac97_is_ready(chip, 100)) {
     348                dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)\n",
     349                        ac97->num);
     350                return 0;
     351        }
     352
     353        if (!fm801_ac97_is_valid(chip, 1000)) {
     354                dev_err(chip->card->dev,
     355                        "AC'97 interface #%d is not valid (2)\n", ac97->num);
     356                return 0;
     357        }
     358
     359        return fm801_readw(chip, AC97_DATA);
     360}
     361
     362static const unsigned int rates[] = {
    312363  5500,  8000,  9600, 11025,
    313364  16000, 19200, 22050, 32000,
     
    315366};
    316367
    317 static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
     368static const struct snd_pcm_hw_constraint_list hw_constraints_rates = {
    318369        .count = ARRAY_SIZE(rates),
    319370        .list = rates,
     
    321372};
    322373
    323 static unsigned int channels[] = {
     374static const unsigned int channels[] = {
    324375  2, 4, 6
    325376};
    326377
    327 static struct snd_pcm_hw_constraint_list hw_constraints_channels = {
     378static const struct snd_pcm_hw_constraint_list hw_constraints_channels = {
    328379        .count = ARRAY_SIZE(channels),
    329380        .list = channels,
     
    380431                return -EINVAL;
    381432        }
    382         outw(chip->ply_ctrl, FM801_REG(chip, PLY_CTRL));
     433        fm801_writew(chip, PLY_CTRL, chip->ply_ctrl);
    383434        spin_unlock(&chip->reg_lock);
    384435        return 0;
     
    415466                return -EINVAL;
    416467        }
    417         outw(chip->cap_ctrl, FM801_REG(chip, CAP_CTRL));
     468        fm801_writew(chip, CAP_CTRL, chip->cap_ctrl);
    418469        spin_unlock(&chip->reg_lock);
    419470        return 0;
    420 }
    421 
    422 static int snd_fm801_hw_params(struct snd_pcm_substream *substream,
    423                                struct snd_pcm_hw_params *hw_params)
    424 {
    425         return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
    426 }
    427 
    428 static int snd_fm801_hw_free(struct snd_pcm_substream *substream)
    429 {
    430         return snd_pcm_lib_free_pages(substream);
    431471}
    432472
     
    453493        chip->ply_ctrl |= snd_fm801_rate_bits(runtime->rate) << FM801_RATE_SHIFT;
    454494        chip->ply_buf = 0;
    455         outw(chip->ply_ctrl, FM801_REG(chip, PLY_CTRL));
    456         outw(chip->ply_count - 1, FM801_REG(chip, PLY_COUNT));
     495        fm801_writew(chip, PLY_CTRL, chip->ply_ctrl);
     496        fm801_writew(chip, PLY_COUNT, chip->ply_count - 1);
    457497        chip->ply_buffer = runtime->dma_addr;
    458498        chip->ply_pos = 0;
    459         outl(chip->ply_buffer, FM801_REG(chip, PLY_BUF1));
    460         outl(chip->ply_buffer + (chip->ply_count % chip->ply_size), FM801_REG(chip, PLY_BUF2));
     499        fm801_writel(chip, PLY_BUF1, chip->ply_buffer);
     500        fm801_writel(chip, PLY_BUF2,
     501                     chip->ply_buffer + (chip->ply_count % chip->ply_size));
    461502        spin_unlock_irq(&chip->reg_lock);
    462503        return 0;
     
    479520        chip->cap_ctrl |= snd_fm801_rate_bits(runtime->rate) << FM801_RATE_SHIFT;
    480521        chip->cap_buf = 0;
    481         outw(chip->cap_ctrl, FM801_REG(chip, CAP_CTRL));
    482         outw(chip->cap_count - 1, FM801_REG(chip, CAP_COUNT));
     522        fm801_writew(chip, CAP_CTRL, chip->cap_ctrl);
     523        fm801_writew(chip, CAP_COUNT, chip->cap_count - 1);
    483524        chip->cap_buffer = runtime->dma_addr;
    484525        chip->cap_pos = 0;
    485         outl(chip->cap_buffer, FM801_REG(chip, CAP_BUF1));
    486         outl(chip->cap_buffer + (chip->cap_count % chip->cap_size), FM801_REG(chip, CAP_BUF2));
     526        fm801_writel(chip, CAP_BUF1, chip->cap_buffer);
     527        fm801_writel(chip, CAP_BUF2,
     528                     chip->cap_buffer + (chip->cap_count % chip->cap_size));
    487529        spin_unlock_irq(&chip->reg_lock);
    488530        return 0;
     
    497539                return 0;
    498540        spin_lock(&chip->reg_lock);
    499         ptr = chip->ply_pos + (chip->ply_count - 1) - inw(FM801_REG(chip, PLY_COUNT));
    500         if (inw(FM801_REG(chip, IRQ_STATUS)) & FM801_IRQ_PLAYBACK) {
     541        ptr = chip->ply_pos + (chip->ply_count - 1) - fm801_readw(chip, PLY_COUNT);
     542        if (fm801_readw(chip, IRQ_STATUS) & FM801_IRQ_PLAYBACK) {
    501543                ptr += chip->ply_count;
    502544                ptr %= chip->ply_size;
     
    514556                return 0;
    515557        spin_lock(&chip->reg_lock);
    516         ptr = chip->cap_pos + (chip->cap_count - 1) - inw(FM801_REG(chip, CAP_COUNT));
    517         if (inw(FM801_REG(chip, IRQ_STATUS)) & FM801_IRQ_CAPTURE) {
     558        ptr = chip->cap_pos + (chip->cap_count - 1) - fm801_readw(chip, CAP_COUNT);
     559        if (fm801_readw(chip, IRQ_STATUS) & FM801_IRQ_CAPTURE) {
    518560                ptr += chip->cap_count;
    519561                ptr %= chip->cap_size;
     
    529571        unsigned int tmp;
    530572
    531         status = inw(FM801_REG(chip, IRQ_STATUS));
     573        status = fm801_readw(chip, IRQ_STATUS);
    532574        status &= FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU|FM801_IRQ_VOLUME;
    533575        if (! status)
    534576                return IRQ_NONE;
    535577        /* ack first */
    536         outw(status, FM801_REG(chip, IRQ_STATUS));
     578        fm801_writew(chip, IRQ_STATUS, status);
    537579        if (chip->pcm && (status & FM801_IRQ_PLAYBACK) && chip->playback_substream) {
    538580                spin_lock(&chip->reg_lock);
     
    542584                tmp = chip->ply_pos + chip->ply_count;
    543585                tmp %= chip->ply_size;
    544                 outl(chip->ply_buffer + tmp,
    545                                 (chip->ply_buf & 1) ?
    546                                         FM801_REG(chip, PLY_BUF1) :
    547                                         FM801_REG(chip, PLY_BUF2));
     586                if (chip->ply_buf & 1)
     587                        fm801_writel(chip, PLY_BUF1, chip->ply_buffer + tmp);
     588                else
     589                        fm801_writel(chip, PLY_BUF2, chip->ply_buffer + tmp);
    548590                spin_unlock(&chip->reg_lock);
    549591                snd_pcm_period_elapsed(chip->playback_substream);
     
    556598                tmp = chip->cap_pos + chip->cap_count;
    557599                tmp %= chip->cap_size;
    558                 outl(chip->cap_buffer + tmp,
    559                                 (chip->cap_buf & 1) ?
    560                                         FM801_REG(chip, CAP_BUF1) :
    561                                         FM801_REG(chip, CAP_BUF2));
     600                if (chip->cap_buf & 1)
     601                        fm801_writel(chip, CAP_BUF1, chip->cap_buffer + tmp);
     602                else
     603                        fm801_writel(chip, CAP_BUF2, chip->cap_buffer + tmp);
    562604                spin_unlock(&chip->reg_lock);
    563605                snd_pcm_period_elapsed(chip->capture_substream);
     
    565607        if (chip->rmidi && (status & FM801_IRQ_MPU))
    566608                snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
    567         if (status & FM801_IRQ_VOLUME)
    568                 ;/* TODO */
     609        if (status & FM801_IRQ_VOLUME) {
     610                /* TODO */
     611        }
    569612
    570613        return IRQ_HANDLED;
    571614}
    572615
    573 static struct snd_pcm_hardware snd_fm801_playback =
     616static const struct snd_pcm_hardware snd_fm801_playback =
    574617{
    575618        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    591634};
    592635
    593 static struct snd_pcm_hardware snd_fm801_capture =
     636static const struct snd_pcm_hardware snd_fm801_capture =
    594637{
    595638        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     
    663706}
    664707
    665 static struct snd_pcm_ops snd_fm801_playback_ops = {
     708static const struct snd_pcm_ops snd_fm801_playback_ops = {
    666709        .open =         snd_fm801_playback_open,
    667710        .close =        snd_fm801_playback_close,
    668         .ioctl =        snd_pcm_lib_ioctl,
    669         .hw_params =    snd_fm801_hw_params,
    670         .hw_free =      snd_fm801_hw_free,
    671711        .prepare =      snd_fm801_playback_prepare,
    672712        .trigger =      snd_fm801_playback_trigger,
     
    674714};
    675715
    676 static struct snd_pcm_ops snd_fm801_capture_ops = {
     716static const struct snd_pcm_ops snd_fm801_capture_ops = {
    677717        .open =         snd_fm801_capture_open,
    678718        .close =        snd_fm801_capture_close,
    679         .ioctl =        snd_pcm_lib_ioctl,
    680         .hw_params =    snd_fm801_hw_params,
    681         .hw_free =      snd_fm801_hw_free,
    682719        .prepare =      snd_fm801_capture_prepare,
    683720        .trigger =      snd_fm801_capture_trigger,
     
    685722};
    686723
    687 static int __devinit snd_fm801_pcm(struct fm801 *chip, int device, struct snd_pcm ** rpcm)
    688 {
     724static int snd_fm801_pcm(struct fm801 *chip, int device)
     725{
     726        struct pci_dev *pdev = to_pci_dev(chip->dev);
    689727        struct snd_pcm *pcm;
    690728        int err;
    691729
    692         if (rpcm)
    693                 *rpcm = NULL;
    694730        if ((err = snd_pcm_new(chip->card, "FM801", device, 1, 1, &pcm)) < 0)
    695731                return err;
     
    703739        chip->pcm = pcm;
    704740
    705         snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
    706                                               snd_dma_pci_data(chip->pci),
    707                                               chip->multichannel ? 128*1024 : 64*1024, 128*1024);
    708 
    709         if (rpcm)
    710                 *rpcm = pcm;
    711         return 0;
     741        snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &pdev->dev,
     742                                       chip->multichannel ? 128*1024 : 64*1024, 128*1024);
     743
     744        return snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
     745                                     snd_pcm_alt_chmaps,
     746                                     chip->multichannel ? 6 : 2, 0,
     747                                     NULL);
    712748}
    713749
     
    716752 */
    717753
    718 #ifdef TEA575X_RADIO
    719 
    720 /* 256PCS GPIO numbers */
    721 #define TEA_256PCS_DATA                 1
    722 #define TEA_256PCS_WRITE_ENABLE         2       /* inverted */
    723 #define TEA_256PCS_BUS_CLOCK            3
    724 
    725 static void snd_fm801_tea575x_256pcs_write(struct snd_tea575x *tea, unsigned int val)
     754#ifdef CONFIG_SND_FM801_TEA575X_BOOL
     755
     756/* GPIO to TEA575x maps */
     757struct snd_fm801_tea575x_gpio {
     758        u8 data, clk, wren, most;
     759        char *name;
     760};
     761
     762static const struct snd_fm801_tea575x_gpio snd_fm801_tea575x_gpios[] = {
     763        { .data = 1, .clk = 3, .wren = 2, .most = 0, .name = "SF256-PCS" },
     764        { .data = 1, .clk = 0, .wren = 2, .most = 3, .name = "SF256-PCP" },
     765        { .data = 2, .clk = 0, .wren = 1, .most = 3, .name = "SF64-PCR" },
     766};
     767
     768#define get_tea575x_gpio(chip) \
     769        (&snd_fm801_tea575x_gpios[((chip)->tea575x_tuner & TUNER_TYPE_MASK) - 1])
     770
     771static void snd_fm801_tea575x_set_pins(struct snd_tea575x *tea, u8 pins)
    726772{
    727773        struct fm801 *chip = tea->private_data;
    728         unsigned short reg;
    729         int i = 25;
    730 
    731         spin_lock_irq(&chip->reg_lock);
    732         reg = inw(FM801_REG(chip, GPIO_CTRL));
     774        unsigned short reg = fm801_readw(chip, GPIO_CTRL);
     775        struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
     776
     777        reg &= ~(FM801_GPIO_GP(gpio.data) |
     778                 FM801_GPIO_GP(gpio.clk) |
     779                 FM801_GPIO_GP(gpio.wren));
     780
     781        reg |= (pins & TEA575X_DATA) ? FM801_GPIO_GP(gpio.data) : 0;
     782        reg |= (pins & TEA575X_CLK)  ? FM801_GPIO_GP(gpio.clk) : 0;
     783        /* WRITE_ENABLE is inverted */
     784        reg |= (pins & TEA575X_WREN) ? 0 : FM801_GPIO_GP(gpio.wren);
     785
     786        fm801_writew(chip, GPIO_CTRL, reg);
     787}
     788
     789static u8 snd_fm801_tea575x_get_pins(struct snd_tea575x *tea)
     790{
     791        struct fm801 *chip = tea->private_data;
     792        unsigned short reg = fm801_readw(chip, GPIO_CTRL);
     793        struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
     794        u8 ret;
     795
     796        ret = 0;
     797        if (reg & FM801_GPIO_GP(gpio.data))
     798                ret |= TEA575X_DATA;
     799        if (reg & FM801_GPIO_GP(gpio.most))
     800                ret |= TEA575X_MOST;
     801        return ret;
     802}
     803
     804static void snd_fm801_tea575x_set_direction(struct snd_tea575x *tea, bool output)
     805{
     806        struct fm801 *chip = tea->private_data;
     807        unsigned short reg = fm801_readw(chip, GPIO_CTRL);
     808        struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
     809
    733810        /* use GPIO lines and set write enable bit */
    734         reg |= FM801_GPIO_GS(TEA_256PCS_DATA) |
    735                FM801_GPIO_GS(TEA_256PCS_WRITE_ENABLE) |
    736                FM801_GPIO_GS(TEA_256PCS_BUS_CLOCK);
    737         /* all of lines are in the write direction */
    738         /* clear data and clock lines */
    739         reg &= ~(FM801_GPIO_GD(TEA_256PCS_DATA) |
    740                  FM801_GPIO_GD(TEA_256PCS_WRITE_ENABLE) |
    741                  FM801_GPIO_GD(TEA_256PCS_BUS_CLOCK) |
    742                  FM801_GPIO_GP(TEA_256PCS_DATA) |
    743                  FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK) |
    744                  FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE));
    745         outw(reg, FM801_REG(chip, GPIO_CTRL));
    746         udelay(1);
    747 
    748         while (i--) {
    749                 if (val & (1 << i))
    750                         reg |= FM801_GPIO_GP(TEA_256PCS_DATA);
    751                 else
    752                         reg &= ~FM801_GPIO_GP(TEA_256PCS_DATA);
    753                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    754                 udelay(1);
    755                 reg |= FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK);
    756                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    757                 reg &= ~FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK);
    758                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    759                 udelay(1);
    760         }
    761 
    762         /* and reset the write enable bit */
    763         reg |= FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE) |
    764                FM801_GPIO_GP(TEA_256PCS_DATA);
    765         outw(reg, FM801_REG(chip, GPIO_CTRL));
    766         spin_unlock_irq(&chip->reg_lock);
    767 }
    768 
    769 static unsigned int snd_fm801_tea575x_256pcs_read(struct snd_tea575x *tea)
    770 {
    771         struct fm801 *chip = tea->private_data;
    772         unsigned short reg;
    773         unsigned int val = 0;
    774         int i;
    775        
    776         spin_lock_irq(&chip->reg_lock);
    777         reg = inw(FM801_REG(chip, GPIO_CTRL));
    778         /* use GPIO lines, set data direction to input */
    779         reg |= FM801_GPIO_GS(TEA_256PCS_DATA) |
    780                FM801_GPIO_GS(TEA_256PCS_WRITE_ENABLE) |
    781                FM801_GPIO_GS(TEA_256PCS_BUS_CLOCK) |
    782                FM801_GPIO_GD(TEA_256PCS_DATA) |
    783                FM801_GPIO_GP(TEA_256PCS_DATA) |
    784                FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE);
    785         /* all of lines are in the write direction, except data */
    786         /* clear data, write enable and clock lines */
    787         reg &= ~(FM801_GPIO_GD(TEA_256PCS_WRITE_ENABLE) |
    788                  FM801_GPIO_GD(TEA_256PCS_BUS_CLOCK) |
    789                  FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK));
    790 
    791         for (i = 0; i < 24; i++) {
    792                 reg &= ~FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK);
    793                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    794                 udelay(1);
    795                 reg |= FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK);
    796                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    797                 udelay(1);
    798                 val <<= 1;
    799                 if (inw(FM801_REG(chip, GPIO_CTRL)) & FM801_GPIO_GP(TEA_256PCS_DATA))
    800                         val |= 1;
    801         }
    802 
    803         spin_unlock_irq(&chip->reg_lock);
    804 
    805         return val;
    806 }
    807 
    808 /* 256PCPR GPIO numbers */
    809 #define TEA_256PCPR_BUS_CLOCK           0
    810 #define TEA_256PCPR_DATA                1
    811 #define TEA_256PCPR_WRITE_ENABLE        2       /* inverted */
    812 
    813 static void snd_fm801_tea575x_256pcpr_write(struct snd_tea575x *tea, unsigned int val)
    814 {
    815         struct fm801 *chip = tea->private_data;
    816         unsigned short reg;
    817         int i = 25;
    818 
    819         spin_lock_irq(&chip->reg_lock);
    820         reg = inw(FM801_REG(chip, GPIO_CTRL));
    821         /* use GPIO lines and set write enable bit */
    822         reg |= FM801_GPIO_GS(TEA_256PCPR_DATA) |
    823                FM801_GPIO_GS(TEA_256PCPR_WRITE_ENABLE) |
    824                FM801_GPIO_GS(TEA_256PCPR_BUS_CLOCK);
    825         /* all of lines are in the write direction */
    826         /* clear data and clock lines */
    827         reg &= ~(FM801_GPIO_GD(TEA_256PCPR_DATA) |
    828                  FM801_GPIO_GD(TEA_256PCPR_WRITE_ENABLE) |
    829                  FM801_GPIO_GD(TEA_256PCPR_BUS_CLOCK) |
    830                  FM801_GPIO_GP(TEA_256PCPR_DATA) |
    831                  FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK) |
    832                  FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE));
    833         outw(reg, FM801_REG(chip, GPIO_CTRL));
    834         udelay(1);
    835 
    836         while (i--) {
    837                 if (val & (1 << i))
    838                         reg |= FM801_GPIO_GP(TEA_256PCPR_DATA);
    839                 else
    840                         reg &= ~FM801_GPIO_GP(TEA_256PCPR_DATA);
    841                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    842                 udelay(1);
    843                 reg |= FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK);
    844                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    845                 reg &= ~FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK);
    846                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    847                 udelay(1);
    848         }
    849 
    850         /* and reset the write enable bit */
    851         reg |= FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE) |
    852                FM801_GPIO_GP(TEA_256PCPR_DATA);
    853         outw(reg, FM801_REG(chip, GPIO_CTRL));
    854         spin_unlock_irq(&chip->reg_lock);
    855 }
    856 
    857 static unsigned int snd_fm801_tea575x_256pcpr_read(struct snd_tea575x *tea)
    858 {
    859         struct fm801 *chip = tea->private_data;
    860         unsigned short reg;
    861         unsigned int val = 0;
    862         int i;
    863        
    864         spin_lock_irq(&chip->reg_lock);
    865         reg = inw(FM801_REG(chip, GPIO_CTRL));
    866         /* use GPIO lines, set data direction to input */
    867         reg |= FM801_GPIO_GS(TEA_256PCPR_DATA) |
    868                FM801_GPIO_GS(TEA_256PCPR_WRITE_ENABLE) |
    869                FM801_GPIO_GS(TEA_256PCPR_BUS_CLOCK) |
    870                FM801_GPIO_GD(TEA_256PCPR_DATA) |
    871                FM801_GPIO_GP(TEA_256PCPR_DATA) |
    872                FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE);
    873         /* all of lines are in the write direction, except data */
    874         /* clear data, write enable and clock lines */
    875         reg &= ~(FM801_GPIO_GD(TEA_256PCPR_WRITE_ENABLE) |
    876                  FM801_GPIO_GD(TEA_256PCPR_BUS_CLOCK) |
    877                  FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK));
    878 
    879         for (i = 0; i < 24; i++) {
    880                 reg &= ~FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK);
    881                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    882                 udelay(1);
    883                 reg |= FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK);
    884                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    885                 udelay(1);
    886                 val <<= 1;
    887                 if (inw(FM801_REG(chip, GPIO_CTRL)) & FM801_GPIO_GP(TEA_256PCPR_DATA))
    888                         val |= 1;
    889         }
    890 
    891         spin_unlock_irq(&chip->reg_lock);
    892 
    893         return val;
    894 }
    895 
    896 /* 64PCR GPIO numbers */
    897 #define TEA_64PCR_BUS_CLOCK             0
    898 #define TEA_64PCR_WRITE_ENABLE          1       /* inverted */
    899 #define TEA_64PCR_DATA                  2
    900 
    901 static void snd_fm801_tea575x_64pcr_write(struct snd_tea575x *tea, unsigned int val)
    902 {
    903         struct fm801 *chip = tea->private_data;
    904         unsigned short reg;
    905         int i = 25;
    906 
    907         spin_lock_irq(&chip->reg_lock);
    908         reg = inw(FM801_REG(chip, GPIO_CTRL));
    909         /* use GPIO lines and set write enable bit */
    910         reg |= FM801_GPIO_GS(TEA_64PCR_DATA) |
    911                FM801_GPIO_GS(TEA_64PCR_WRITE_ENABLE) |
    912                FM801_GPIO_GS(TEA_64PCR_BUS_CLOCK);
    913         /* all of lines are in the write direction */
    914         /* clear data and clock lines */
    915         reg &= ~(FM801_GPIO_GD(TEA_64PCR_DATA) |
    916                  FM801_GPIO_GD(TEA_64PCR_WRITE_ENABLE) |
    917                  FM801_GPIO_GD(TEA_64PCR_BUS_CLOCK) |
    918                  FM801_GPIO_GP(TEA_64PCR_DATA) |
    919                  FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK) |
    920                  FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE));
    921         outw(reg, FM801_REG(chip, GPIO_CTRL));
    922         udelay(1);
    923 
    924         while (i--) {
    925                 if (val & (1 << i))
    926                         reg |= FM801_GPIO_GP(TEA_64PCR_DATA);
    927                 else
    928                         reg &= ~FM801_GPIO_GP(TEA_64PCR_DATA);
    929                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    930                 udelay(1);
    931                 reg |= FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK);
    932                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    933                 reg &= ~FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK);
    934                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    935                 udelay(1);
    936         }
    937 
    938         /* and reset the write enable bit */
    939         reg |= FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE) |
    940                FM801_GPIO_GP(TEA_64PCR_DATA);
    941         outw(reg, FM801_REG(chip, GPIO_CTRL));
    942         spin_unlock_irq(&chip->reg_lock);
    943 }
    944 
    945 static unsigned int snd_fm801_tea575x_64pcr_read(struct snd_tea575x *tea)
    946 {
    947         struct fm801 *chip = tea->private_data;
    948         unsigned short reg;
    949         unsigned int val = 0;
    950         int i;
    951        
    952         spin_lock_irq(&chip->reg_lock);
    953         reg = inw(FM801_REG(chip, GPIO_CTRL));
    954         /* use GPIO lines, set data direction to input */
    955         reg |= FM801_GPIO_GS(TEA_64PCR_DATA) |
    956                FM801_GPIO_GS(TEA_64PCR_WRITE_ENABLE) |
    957                FM801_GPIO_GS(TEA_64PCR_BUS_CLOCK) |
    958                FM801_GPIO_GD(TEA_64PCR_DATA) |
    959                FM801_GPIO_GP(TEA_64PCR_DATA) |
    960                FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE);
    961         /* all of lines are in the write direction, except data */
    962         /* clear data, write enable and clock lines */
    963         reg &= ~(FM801_GPIO_GD(TEA_64PCR_WRITE_ENABLE) |
    964                  FM801_GPIO_GD(TEA_64PCR_BUS_CLOCK) |
    965                  FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK));
    966 
    967         for (i = 0; i < 24; i++) {
    968                 reg &= ~FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK);
    969                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    970                 udelay(1);
    971                 reg |= FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK);
    972                 outw(reg, FM801_REG(chip, GPIO_CTRL));
    973                 udelay(1);
    974                 val <<= 1;
    975                 if (inw(FM801_REG(chip, GPIO_CTRL)) & FM801_GPIO_GP(TEA_64PCR_DATA))
    976                         val |= 1;
    977         }
    978 
    979         spin_unlock_irq(&chip->reg_lock);
    980 
    981         return val;
    982 }
    983 
    984 static void snd_fm801_tea575x_64pcr_mute(struct snd_tea575x *tea,
    985                                           unsigned int mute)
    986 {
    987         struct fm801 *chip = tea->private_data;
    988         unsigned short reg;
    989 
    990         spin_lock_irq(&chip->reg_lock);
    991 
    992         reg = inw(FM801_REG(chip, GPIO_CTRL));
    993         if (mute)
    994                 /* 0xf800 (mute) */
    995                 reg &= ~FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE);
    996         else
    997                 /* 0xf802 (unmute) */
    998                 reg |= FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE);
    999         outw(reg, FM801_REG(chip, GPIO_CTRL));
    1000         udelay(1);
    1001 
    1002         spin_unlock_irq(&chip->reg_lock);
    1003 }
    1004 
    1005 static struct snd_tea575x_ops snd_fm801_tea_ops[3] = {
    1006         {
    1007                 /* 1 = MediaForte 256-PCS */
    1008                 .write = snd_fm801_tea575x_256pcs_write,
    1009                 .read = snd_fm801_tea575x_256pcs_read,
    1010         },
    1011         {
    1012                 /* 2 = MediaForte 256-PCPR */
    1013                 .write = snd_fm801_tea575x_256pcpr_write,
    1014                 .read = snd_fm801_tea575x_256pcpr_read,
    1015         },
    1016         {
    1017                 /* 3 = MediaForte 64-PCR */
    1018                 .write = snd_fm801_tea575x_64pcr_write,
    1019                 .read = snd_fm801_tea575x_64pcr_read,
    1020                 .mute = snd_fm801_tea575x_64pcr_mute,
    1021         }
     811        reg |= FM801_GPIO_GS(gpio.data) |
     812               FM801_GPIO_GS(gpio.wren) |
     813               FM801_GPIO_GS(gpio.clk) |
     814               FM801_GPIO_GS(gpio.most);
     815        if (output) {
     816                /* all of lines are in the write direction */
     817                /* clear data and clock lines */
     818                reg &= ~(FM801_GPIO_GD(gpio.data) |
     819                         FM801_GPIO_GD(gpio.wren) |
     820                         FM801_GPIO_GD(gpio.clk) |
     821                         FM801_GPIO_GP(gpio.data) |
     822                         FM801_GPIO_GP(gpio.clk) |
     823                         FM801_GPIO_GP(gpio.wren));
     824        } else {
     825                /* use GPIO lines, set data direction to input */
     826                reg |= FM801_GPIO_GD(gpio.data) |
     827                       FM801_GPIO_GD(gpio.most) |
     828                       FM801_GPIO_GP(gpio.data) |
     829                       FM801_GPIO_GP(gpio.most) |
     830                       FM801_GPIO_GP(gpio.wren);
     831                /* all of lines are in the write direction, except data */
     832                /* clear data, write enable and clock lines */
     833                reg &= ~(FM801_GPIO_GD(gpio.wren) |
     834                         FM801_GPIO_GD(gpio.clk) |
     835                         FM801_GPIO_GP(gpio.clk));
     836        }
     837
     838        fm801_writew(chip, GPIO_CTRL, reg);
     839}
     840
     841static const struct snd_tea575x_ops snd_fm801_tea_ops = {
     842        .set_pins = snd_fm801_tea575x_set_pins,
     843        .get_pins = snd_fm801_tea575x_get_pins,
     844        .set_direction = snd_fm801_tea575x_set_direction,
    1022845};
    1023846#endif
     
    1052875        int mask = (kcontrol->private_value >> 16) & 0xff;
    1053876        int invert = (kcontrol->private_value >> 24) & 0xff;
    1054 
    1055         ucontrol->value.integer.value[0] = (inw(chip->port + reg) >> shift) & mask;
     877        long *value = ucontrol->value.integer.value;
     878
     879        value[0] = (fm801_ioread16(chip, reg) >> shift) & mask;
    1056880        if (invert)
    1057                 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
     881                value[0] = mask - value[0];
    1058882        return 0;
    1059883}
     
    1108932        int mask = (kcontrol->private_value >> 16) & 0xff;
    1109933        int invert = (kcontrol->private_value >> 24) & 0xff;
     934        long *value = ucontrol->value.integer.value;
    1110935
    1111936        spin_lock_irq(&chip->reg_lock);
    1112         ucontrol->value.integer.value[0] = (inw(chip->port + reg) >> shift_left) & mask;
    1113         ucontrol->value.integer.value[1] = (inw(chip->port + reg) >> shift_right) & mask;
     937        value[0] = (fm801_ioread16(chip, reg) >> shift_left) & mask;
     938        value[1] = (fm801_ioread16(chip, reg) >> shift_right) & mask;
    1114939        spin_unlock_irq(&chip->reg_lock);
    1115940        if (invert) {
    1116                 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
    1117                 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
     941                value[0] = mask - value[0];
     942                value[1] = mask - value[1];
    1118943        }
    1119944        return 0;
     
    1145970                              struct snd_ctl_elem_info *uinfo)
    1146971{
    1147         static char *texts[5] = {
     972        static const char * const texts[5] = {
    1148973                "AC97 Primary", "FM", "I2S", "PCM", "AC97 Secondary"
    1149974        };
    1150975 
    1151         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
    1152         uinfo->count = 1;
    1153         uinfo->value.enumerated.items = 5;
    1154         if (uinfo->value.enumerated.item > 4)
    1155                 uinfo->value.enumerated.item = 4;
    1156         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
    1157         return 0;
     976        return snd_ctl_enum_info(uinfo, 1, 5, texts);
    1158977}
    1159978
     
    1164983        unsigned short val;
    1165984 
    1166         val = inw(FM801_REG(chip, REC_SRC)) & 7;
     985        val = fm801_readw(chip, REC_SRC) & 7;
    1167986        if (val > 4)
    1168987                val = 4;
     
    11861005#define FM801_CONTROLS ARRAY_SIZE(snd_fm801_controls)
    11871006
    1188 static struct snd_kcontrol_new snd_fm801_controls[] __devinitdata = {
     1007static const struct snd_kcontrol_new snd_fm801_controls[] = {
    11891008FM801_DOUBLE_TLV("Wave Playback Volume", FM801_PCM_VOL, 0, 8, 31, 1,
    11901009                 db_scale_dsp),
     
    12071026#define FM801_CONTROLS_MULTI ARRAY_SIZE(snd_fm801_controls_multi)
    12081027
    1209 static struct snd_kcontrol_new snd_fm801_controls_multi[] __devinitdata = {
     1028static const struct snd_kcontrol_new snd_fm801_controls_multi[] = {
    12101029FM801_SINGLE("AC97 2ch->4ch Copy Switch", FM801_CODEC_CTRL, 7, 1, 0),
    12111030FM801_SINGLE("AC97 18-bit Switch", FM801_CODEC_CTRL, 10, 1, 0),
     
    12321051}
    12331052
    1234 static int __devinit snd_fm801_mixer(struct fm801 *chip)
     1053static int snd_fm801_mixer(struct fm801 *chip)
    12351054{
    12361055        struct snd_ac97_template ac97;
    12371056        unsigned int i;
    12381057        int err;
    1239         static struct snd_ac97_bus_ops ops = {
     1058        static const struct snd_ac97_bus_ops ops = {
    12401059                .write = snd_fm801_codec_write,
    12411060                .read = snd_fm801_codec_read,
     
    12571076                        return err;
    12581077        }
    1259         for (i = 0; i < FM801_CONTROLS; i++)
    1260                 snd_ctl_add(chip->card, snd_ctl_new1(&snd_fm801_controls[i], chip));
     1078        for (i = 0; i < FM801_CONTROLS; i++) {
     1079                err = snd_ctl_add(chip->card,
     1080                        snd_ctl_new1(&snd_fm801_controls[i], chip));
     1081                if (err < 0)
     1082                        return err;
     1083        }
    12611084        if (chip->multichannel) {
    1262                 for (i = 0; i < FM801_CONTROLS_MULTI; i++)
    1263                         snd_ctl_add(chip->card, snd_ctl_new1(&snd_fm801_controls_multi[i], chip));
     1085                for (i = 0; i < FM801_CONTROLS_MULTI; i++) {
     1086                        err = snd_ctl_add(chip->card,
     1087                                snd_ctl_new1(&snd_fm801_controls_multi[i], chip));
     1088                        if (err < 0)
     1089                                return err;
     1090                }
    12641091        }
    12651092        return 0;
     
    12751102        unsigned long timeout = jiffies + waits;
    12761103
    1277         outw(FM801_AC97_READ | (codec_id << FM801_AC97_ADDR_SHIFT) | reg,
    1278              FM801_REG(chip, AC97_CMD));
     1104        fm801_writew(chip, AC97_CMD,
     1105                     reg | (codec_id << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ);
    12791106        udelay(5);
    12801107        do {
    1281                 if ((inw(FM801_REG(chip, AC97_CMD)) & (FM801_AC97_VALID|FM801_AC97_BUSY))
    1282                     == FM801_AC97_VALID)
     1108                if ((fm801_readw(chip, AC97_CMD) &
     1109                     (FM801_AC97_VALID | FM801_AC97_BUSY)) == FM801_AC97_VALID)
    12831110                        return 0;
    12841111                schedule_timeout_uninterruptible(1);
     
    12871114}
    12881115
    1289 static int snd_fm801_chip_init(struct fm801 *chip, int resume)
     1116static int reset_codec(struct fm801 *chip)
     1117{
     1118        /* codec cold reset + AC'97 warm reset */
     1119        fm801_writew(chip, CODEC_CTRL, (1 << 5) | (1 << 6));
     1120        fm801_readw(chip, CODEC_CTRL); /* flush posting data */
     1121        udelay(100);
     1122        fm801_writew(chip, CODEC_CTRL, 0);
     1123
     1124        return wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750));
     1125}
     1126
     1127static void snd_fm801_chip_multichannel_init(struct fm801 *chip)
    12901128{
    12911129        unsigned short cmdw;
    1292 
    1293         if (chip->tea575x_tuner & TUNER_ONLY)
    1294                 goto __ac97_ok;
    1295 
    1296         /* codec cold reset + AC'97 warm reset */
    1297         outw((1<<5) | (1<<6), FM801_REG(chip, CODEC_CTRL));
    1298         inw(FM801_REG(chip, CODEC_CTRL)); /* flush posting data */
    1299         udelay(100);
    1300         outw(0, FM801_REG(chip, CODEC_CTRL));
    1301 
    1302         if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0)
    1303                 if (!resume) {
    1304                         snd_printk(KERN_INFO "Primary AC'97 codec not found, "
    1305                                             "assume SF64-PCR (tuner-only)\n");
    1306                         chip->tea575x_tuner = 3 | TUNER_ONLY;
    1307                         goto __ac97_ok;
    1308                 }
    13091130
    13101131        if (chip->multichannel) {
     
    13191140                                if (!wait_for_codec(chip, i, AC97_VENDOR_ID1,
    13201141                                                     msecs_to_jiffies(50))) {
    1321                                         cmdw = inw(FM801_REG(chip, AC97_DATA));
     1142                                        cmdw = fm801_readw(chip, AC97_DATA);
    13221143                                        if (cmdw != 0xffff && cmdw != 0) {
    13231144                                                chip->secondary = 1;
     
    13331154                wait_for_codec(chip, 0, AC97_VENDOR_ID1, msecs_to_jiffies(750));
    13341155        }
    1335 
    1336       __ac97_ok:
     1156}
     1157
     1158static void snd_fm801_chip_init(struct fm801 *chip)
     1159{
     1160        unsigned short cmdw;
    13371161
    13381162        /* init volume */
    1339         outw(0x0808, FM801_REG(chip, PCM_VOL));
    1340         outw(0x9f1f, FM801_REG(chip, FM_VOL));
    1341         outw(0x8808, FM801_REG(chip, I2S_VOL));
     1163        fm801_writew(chip, PCM_VOL, 0x0808);
     1164        fm801_writew(chip, FM_VOL, 0x9f1f);
     1165        fm801_writew(chip, I2S_VOL, 0x8808);
    13421166
    13431167        /* I2S control - I2S mode */
    1344         outw(0x0003, FM801_REG(chip, I2S_MODE));
     1168        fm801_writew(chip, I2S_MODE, 0x0003);
    13451169
    13461170        /* interrupt setup */
    1347         cmdw = inw(FM801_REG(chip, IRQ_MASK));
     1171        cmdw = fm801_readw(chip, IRQ_MASK);
    13481172        if (chip->irq < 0)
    13491173                cmdw |= 0x00c3;         /* mask everything, no PCM nor MPU */
    13501174        else
    13511175                cmdw &= ~0x0083;        /* unmask MPU, PLAYBACK & CAPTURE */
    1352         outw(cmdw, FM801_REG(chip, IRQ_MASK));
     1176        fm801_writew(chip, IRQ_MASK, cmdw);
    13531177
    13541178        /* interrupt clear */
    1355         outw(FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU, FM801_REG(chip, IRQ_STATUS));
    1356 
    1357         return 0;
    1358 }
    1359 
     1179        fm801_writew(chip, IRQ_STATUS,
     1180                     FM801_IRQ_PLAYBACK | FM801_IRQ_CAPTURE | FM801_IRQ_MPU);
     1181}
    13601182
    13611183static int snd_fm801_free(struct fm801 *chip)
     
    13671189
    13681190        /* interrupt setup - mask everything */
    1369         cmdw = inw(FM801_REG(chip, IRQ_MASK));
     1191        cmdw = fm801_readw(chip, IRQ_MASK);
    13701192        cmdw |= 0x00c3;
    1371         outw(cmdw, FM801_REG(chip, IRQ_MASK));
     1193        fm801_writew(chip, IRQ_MASK, cmdw);
     1194
     1195        devm_free_irq(chip->dev, chip->irq, chip);
    13721196
    13731197      __end_hw:
    1374 #ifdef TEA575X_RADIO
    1375         snd_tea575x_exit(&chip->tea);
     1198#ifdef CONFIG_SND_FM801_TEA575X_BOOL
     1199        if (!(chip->tea575x_tuner & TUNER_DISABLED)) {
     1200                snd_tea575x_exit(&chip->tea);
     1201                v4l2_device_unregister(&chip->v4l2_dev);
     1202        }
    13761203#endif
    1377         if (chip->irq >= 0)
    1378                 free_irq(chip->irq, chip);
    1379         pci_release_regions(chip->pci);
    1380         pci_disable_device(chip->pci);
    1381 
    1382         kfree(chip);
    13831204        return 0;
    13841205}
     
    13901211}
    13911212
    1392 static int __devinit snd_fm801_create(struct snd_card *card,
    1393                                       struct pci_dev * pci,
    1394                                       int tea575x_tuner,
    1395                                       struct fm801 ** rchip)
     1213static int snd_fm801_create(struct snd_card *card,
     1214                            struct pci_dev *pci,
     1215                            int tea575x_tuner,
     1216                            int radio_nr,
     1217                            struct fm801 **rchip)
    13961218{
    13971219        struct fm801 *chip;
    13981220        int err;
    1399         static struct snd_device_ops ops = {
     1221        static const struct snd_device_ops ops = {
    14001222                .dev_free =     snd_fm801_dev_free,
    14011223        };
    14021224
    14031225        *rchip = NULL;
     1226#ifndef TARGET_OS2
     1227        if ((err = pcim_enable_device(pci)) < 0)
     1228                return err;
     1229        chip = devm_kzalloc(&pci->dev, sizeof(*chip), GFP_KERNEL);
     1230#else
    14041231        if ((err = pci_enable_device(pci)) < 0)
    14051232                return err;
    14061233        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
    1407         if (chip == NULL) {
    1408                 pci_disable_device(pci);
     1234#endif
     1235        if (chip == NULL)
    14091236                return -ENOMEM;
    1410         }
    14111237        spin_lock_init(&chip->reg_lock);
    14121238        chip->card = card;
    1413         chip->pci = pci;
     1239        chip->dev = &pci->dev;
    14141240        chip->irq = -1;
    14151241        chip->tea575x_tuner = tea575x_tuner;
    1416         if ((err = pci_request_regions(pci, "FM801")) < 0) {
    1417                 kfree(chip);
    1418                 pci_disable_device(pci);
    1419                 return err;
    1420         }
     1242        if ((err = pci_request_regions(pci, "FM801")) < 0)
     1243                return err;
    14211244        chip->port = pci_resource_start(pci, 0);
    1422         if ((tea575x_tuner & TUNER_ONLY) == 0) {
    1423                 if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED,
    1424                                 "FM801", chip)) {
    1425                         snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq);
    1426                         snd_fm801_free(chip);
    1427                         return -EBUSY;
    1428                 }
    1429                 chip->irq = pci->irq;
    1430                 pci_set_master(pci);
    1431         }
    14321245
    14331246#ifndef TARGET_OS2
     
    14381251                chip->multichannel = 1;
    14391252
    1440         snd_fm801_chip_init(chip, 0);
    1441         /* init might set tuner access method */
    1442         tea575x_tuner = chip->tea575x_tuner;
    1443 
    1444         if (chip->irq >= 0 && (tea575x_tuner & TUNER_ONLY)) {
    1445                 pci_clear_master(pci);
    1446                 free_irq(chip->irq, chip);
    1447                 chip->irq = -1;
    1448         }
     1253        if (!(chip->tea575x_tuner & TUNER_ONLY)) {
     1254                if (reset_codec(chip) < 0) {
     1255                        dev_info(chip->card->dev,
     1256                                 "Primary AC'97 codec not found, assume SF64-PCR (tuner-only)\n");
     1257                        chip->tea575x_tuner = 3 | TUNER_ONLY;
     1258                } else {
     1259                        snd_fm801_chip_multichannel_init(chip);
     1260                }
     1261        }
     1262
     1263        if ((chip->tea575x_tuner & TUNER_ONLY) == 0) {
     1264#ifndef TARGET_OS2
     1265                if (devm_request_irq(&pci->dev, pci->irq, snd_fm801_interrupt,
     1266                                IRQF_SHARED, KBUILD_MODNAME, chip)) {
     1267#else
     1268                if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED,
     1269                                KBUILD_MODNAME, chip)) {
     1270#endif
     1271                        dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
     1272                        snd_fm801_free(chip);
     1273                        return -EBUSY;
     1274                }
     1275                chip->irq = pci->irq;
     1276                card->sync_irq = chip->irq;
     1277                pci_set_master(pci);
     1278        }
     1279
     1280        snd_fm801_chip_init(chip);
    14491281
    14501282        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
     
    14531285        }
    14541286
    1455         snd_card_set_dev(card, &pci->dev);
    1456 
    1457 #ifdef TEA575X_RADIO
    1458         if ((tea575x_tuner & TUNER_TYPE_MASK) > 0 &&
    1459             (tea575x_tuner & TUNER_TYPE_MASK) < 4) {
    1460                 chip->tea.dev_nr = tea575x_tuner >> 16;
    1461                 chip->tea.card = card;
    1462                 chip->tea.freq_fixup = 10700;
    1463                 chip->tea.private_data = chip;
    1464                 chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & TUNER_TYPE_MASK) - 1];
    1465                 snd_tea575x_init(&chip->tea);
     1287#ifdef CONFIG_SND_FM801_TEA575X_BOOL
     1288        err = v4l2_device_register(&pci->dev, &chip->v4l2_dev);
     1289        if (err < 0) {
     1290                snd_fm801_free(chip);
     1291                return err;
     1292        }
     1293        chip->tea.v4l2_dev = &chip->v4l2_dev;
     1294        chip->tea.radio_nr = radio_nr;
     1295        chip->tea.private_data = chip;
     1296        chip->tea.ops = &snd_fm801_tea_ops;
     1297        sprintf(chip->tea.bus_info, "PCI:%s", pci_name(pci));
     1298        if ((chip->tea575x_tuner & TUNER_TYPE_MASK) > 0 &&
     1299            (chip->tea575x_tuner & TUNER_TYPE_MASK) < 4) {
     1300                if (snd_tea575x_init(&chip->tea, THIS_MODULE)) {
     1301                        dev_err(card->dev, "TEA575x radio not found\n");
     1302                        snd_fm801_free(chip);
     1303                        return -ENODEV;
     1304                }
     1305        } else if ((chip->tea575x_tuner & TUNER_TYPE_MASK) == 0) {
     1306                unsigned int tuner_only = chip->tea575x_tuner & TUNER_ONLY;
     1307
     1308                /* autodetect tuner connection */
     1309                for (tea575x_tuner = 1; tea575x_tuner <= 3; tea575x_tuner++) {
     1310                        chip->tea575x_tuner = tea575x_tuner;
     1311                        if (!snd_tea575x_init(&chip->tea, THIS_MODULE)) {
     1312                                dev_info(card->dev,
     1313                                         "detected TEA575x radio type %s\n",
     1314                                           get_tea575x_gpio(chip)->name);
     1315                                break;
     1316                        }
     1317                }
     1318                if (tea575x_tuner == 4) {
     1319                        dev_err(card->dev, "TEA575x radio not found\n");
     1320                        chip->tea575x_tuner = TUNER_DISABLED;
     1321                }
     1322
     1323                chip->tea575x_tuner |= tuner_only;
     1324        }
     1325        if (!(chip->tea575x_tuner & TUNER_DISABLED)) {
     1326                strlcpy(chip->tea.card, get_tea575x_gpio(chip)->name,
     1327                        sizeof(chip->tea.card));
    14661328        }
    14671329#endif
     
    14711333}
    14721334
    1473 static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
    1474                                           const struct pci_device_id *pci_id)
     1335static int snd_card_fm801_probe(struct pci_dev *pci,
     1336                                const struct pci_device_id *pci_id)
    14751337{
    14761338        static int dev;
     
    14871349        }
    14881350
    1489         err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
     1351        err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
     1352                           0, &card);
    14901353        if (err < 0)
    14911354                return err;
    1492         if ((err = snd_fm801_create(card, pci, tea575x_tuner[dev], &chip)) < 0) {
     1355        if ((err = snd_fm801_create(card, pci, tea575x_tuner[dev], radio_nr[dev], &chip)) < 0) {
    14931356                snd_card_free(card);
    14941357                return err;
     
    15051368                goto __fm801_tuner_only;
    15061369
    1507         if ((err = snd_fm801_pcm(chip, 0, NULL)) < 0) {
     1370        if ((err = snd_fm801_pcm(chip, 0)) < 0) {
    15081371                snd_card_free(card);
    15091372                return err;
     
    15141377        }
    15151378        if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801,
    1516                                        FM801_REG(chip, MPU401_DATA),
    1517                                        MPU401_INFO_INTEGRATED,
    1518                                        chip->irq, 0, &chip->rmidi)) < 0) {
     1379                                       chip->port + FM801_MPU401_DATA,
     1380                                       MPU401_INFO_INTEGRATED |
     1381                                       MPU401_INFO_IRQ_HOOK,
     1382                                       -1, &chip->rmidi)) < 0) {
    15191383                snd_card_free(card);
    15201384                return err;
    15211385        }
    1522         if ((err = snd_opl3_create(card, FM801_REG(chip, OPL3_BANK0),
    1523                                    FM801_REG(chip, OPL3_BANK1),
     1386        if ((err = snd_opl3_create(card, chip->port + FM801_OPL3_BANK0,
     1387                                   chip->port + FM801_OPL3_BANK1,
    15241388                                   OPL3_HW_OPL3_FM801, 1, &opl3)) < 0) {
    15251389                snd_card_free(card);
     
    15411405}
    15421406
    1543 static void __devexit snd_card_fm801_remove(struct pci_dev *pci)
     1407static void snd_card_fm801_remove(struct pci_dev *pci)
    15441408{
    15451409        snd_card_free(pci_get_drvdata(pci));
    1546         pci_set_drvdata(pci, NULL);
    1547 }
    1548 
    1549 #ifdef CONFIG_PM
    1550 static unsigned char saved_regs[] = {
     1410}
     1411
     1412#ifdef CONFIG_PM_SLEEP
     1413static const unsigned char saved_regs[] = {
    15511414        FM801_PCM_VOL, FM801_I2S_VOL, FM801_FM_VOL, FM801_REC_SRC,
    15521415        FM801_PLY_CTRL, FM801_PLY_COUNT, FM801_PLY_BUF1, FM801_PLY_BUF2,
     
    15551418};
    15561419
    1557 static int snd_fm801_suspend(struct pci_dev *pci, pm_message_t state)
    1558 {
    1559         struct snd_card *card = pci_get_drvdata(pci);
     1420static int snd_fm801_suspend(struct device *dev)
     1421{
     1422        struct snd_card *card = dev_get_drvdata(dev);
    15601423        struct fm801 *chip = card->private_data;
    15611424        int i;
    15621425
    15631426        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
    1564         snd_pcm_suspend_all(chip->pcm);
    1565         snd_ac97_suspend(chip->ac97);
    1566         snd_ac97_suspend(chip->ac97_sec);
     1427
    15671428        for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
    1568                 chip->saved_regs[i] = inw(chip->port + saved_regs[i]);
    1569         /* FIXME: tea575x suspend */
    1570 
    1571         pci_disable_device(pci);
    1572         pci_save_state(pci);
    1573         pci_set_power_state(pci, pci_choose_state(pci, state));
    1574         return 0;
    1575 }
    1576 
    1577 static int snd_fm801_resume(struct pci_dev *pci)
    1578 {
    1579         struct snd_card *card = pci_get_drvdata(pci);
     1429                chip->saved_regs[i] = fm801_ioread16(chip, saved_regs[i]);
     1430
     1431        if (chip->tea575x_tuner & TUNER_ONLY) {
     1432                /* FIXME: tea575x suspend */
     1433        } else {
     1434                snd_ac97_suspend(chip->ac97);
     1435                snd_ac97_suspend(chip->ac97_sec);
     1436        }
     1437
     1438        return 0;
     1439}
     1440
     1441static int snd_fm801_resume(struct device *dev)
     1442{
     1443        struct snd_card *card = dev_get_drvdata(dev);
    15801444        struct fm801 *chip = card->private_data;
    15811445        int i;
    15821446
    1583         pci_set_power_state(pci, PCI_D0);
    1584         pci_restore_state(pci);
    1585         if (pci_enable_device(pci) < 0) {
    1586                 printk(KERN_ERR "fm801: pci_enable_device failed, "
    1587                        "disabling device\n");
    1588                 snd_card_disconnect(card);
    1589                 return -EIO;
    1590         }
    1591         pci_set_master(pci);
    1592 
    1593         snd_fm801_chip_init(chip, 1);
    1594         snd_ac97_resume(chip->ac97);
    1595         snd_ac97_resume(chip->ac97_sec);
     1447        if (chip->tea575x_tuner & TUNER_ONLY) {
     1448                snd_fm801_chip_init(chip);
     1449        } else {
     1450                reset_codec(chip);
     1451                snd_fm801_chip_multichannel_init(chip);
     1452                snd_fm801_chip_init(chip);
     1453                snd_ac97_resume(chip->ac97);
     1454                snd_ac97_resume(chip->ac97_sec);
     1455        }
     1456
    15961457        for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
    1597                 outw(chip->saved_regs[i], chip->port + saved_regs[i]);
     1458                fm801_iowrite16(chip, saved_regs[i], chip->saved_regs[i]);
     1459
     1460#ifdef CONFIG_SND_FM801_TEA575X_BOOL
     1461        if (!(chip->tea575x_tuner & TUNER_DISABLED))
     1462                snd_tea575x_set_freq(&chip->tea);
     1463#endif
    15981464
    15991465        snd_power_change_state(card, SNDRV_CTL_POWER_D0);
    16001466        return 0;
    16011467}
    1602 #endif
    1603 
    1604 static struct pci_driver driver = {
    1605         .name = "FM801",
     1468
     1469static SIMPLE_DEV_PM_OPS(snd_fm801_pm, snd_fm801_suspend, snd_fm801_resume);
     1470#define SND_FM801_PM_OPS        &snd_fm801_pm
     1471#else
     1472#define SND_FM801_PM_OPS        NULL
     1473#endif /* CONFIG_PM_SLEEP */
     1474
     1475static struct pci_driver fm801_driver = {
     1476        .name = KBUILD_MODNAME,
    16061477        .id_table = snd_fm801_ids,
    16071478        .probe = snd_card_fm801_probe,
    1608         .remove = __devexit_p(snd_card_fm801_remove),
    1609 #ifdef CONFIG_PM
    1610         .suspend = snd_fm801_suspend,
    1611         .resume = snd_fm801_resume,
    1612 #endif
    1613 };
    1614 
    1615 static int __init alsa_card_fm801_init(void)
    1616 {
    1617         return pci_register_driver(&driver);
    1618 }
    1619 
    1620 static void __exit alsa_card_fm801_exit(void)
    1621 {
    1622         pci_unregister_driver(&driver);
    1623 }
    1624 
    1625 module_init(alsa_card_fm801_init)
    1626 module_exit(alsa_card_fm801_exit)
     1479        .remove = snd_card_fm801_remove,
     1480        .driver = {
     1481                .pm = SND_FM801_PM_OPS,
     1482        },
     1483};
     1484
     1485module_pci_driver(fm801_driver);
Note: See TracChangeset for help on using the changeset viewer.