Ignore:
Timestamp:
Mar 24, 2008, 2:43:42 AM (17 years ago)
Author:
Paul Smedley
Message:

Update source to ALSA 1.0.16 level

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GPL/branches/uniaud-2.0/alsa-kernel/pci/fm801.c

    r135 r305  
    11/*
    22 *  The driver for the ForteMedia FM801 based soundcards
    3  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
     3 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
    44 *
     5 *  Support FM only card by Andy Shevchenko <andy@smile.org.ua>
    56 *
    67 *   This program is free software; you can redistribute it and/or modify
     
    2021 */
    2122
    22 #include <sound/driver.h>
    2323#include <linux/delay.h>
    2424#include <linux/init.h>
     
    2626#include <linux/pci.h>
    2727#include <linux/slab.h>
    28 //#include <linux/moduleparam.h>
     28#include <linux/moduleparam.h>
    2929#include <sound/core.h>
    3030#include <sound/pcm.h>
     31#include <sound/tlv.h>
    3132#include <sound/ac97_codec.h>
    3233#include <sound/mpu401.h>
     
    3637#include <asm/io.h>
    3738
    38 #if (defined(CONFIG_SND_FM801_TEA575X) || defined(CONFIG_SND_FM801_TEA575X_MODULE)) && (defined(CONFIG_VIDEO_DEV) || defined(CONFIG_VIDEO_DEV_MODULE))
     39#ifdef CONFIG_SND_FM801_TEA575X_BOOL
    3940#include <sound/tea575x-tuner.h>
    4041#define TEA575X_RADIO 1
    4142#endif
    4243
    43 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
     44MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
    4445MODULE_DESCRIPTION("ForteMedia FM801");
    4546MODULE_LICENSE("GPL");
     
    5556 *    2 = MediaForte 256-PCPR
    5657 *    3 = MediaForte 64-PCR
     58 *   16 = setup tuner only (this is additional bit), i.e. SF-64-PCR FM card
    5759 *  High 16-bits are video (radio) device number + 1
    5860 */
    59 static int tea575x_tuner[SNDRV_CARDS] = { 0 };
    60 
    61 //module_param_array(index, int, NULL, 0444);
     61static int tea575x_tuner[SNDRV_CARDS];
     62
     63module_param_array(index, int, NULL, 0444);
    6264MODULE_PARM_DESC(index, "Index value for the FM801 soundcard.");
    63 //module_param_array(id, charp, NULL, 0444);
     65module_param_array(id, charp, NULL, 0444);
    6466MODULE_PARM_DESC(id, "ID string for the FM801 soundcard.");
    65 //module_param_array(enable, bool, NULL, 0444);
     67module_param_array(enable, bool, NULL, 0444);
    6668MODULE_PARM_DESC(enable, "Enable FM801 soundcard.");
    67 //module_param_array(tea575x_tuner, bool, NULL, 0444);
     69module_param_array(tea575x_tuner, int, NULL, 0444);
    6870MODULE_PARM_DESC(tea575x_tuner, "Enable TEA575x tuner.");
    6971
     
    104106#define FM801_POWERDOWN         0x70    /* Blocks Power Down Control */
    105107
    106 #define FM801_AC97_ADDR_SHIFT   10
     108/* codec access */
     109#define FM801_AC97_READ         (1<<7)  /* read=1, write=0 */
     110#define FM801_AC97_VALID        (1<<8)  /* port valid=1 */
     111#define FM801_AC97_BUSY         (1<<9)  /* busy=1 */
     112#define FM801_AC97_ADDR_SHIFT   10      /* codec id (2bit) */
    107113
    108114/* playback and record control register bits */
     
    148154 */
    149155
    150 typedef struct _snd_fm801 fm801_t;
    151 
    152 struct _snd_fm801 {
     156struct fm801 {
    153157        int irq;
    154158
     
    157161                     secondary: 1;      /* secondary codec */
    158162        unsigned char secondary_addr;   /* address of the secondary codec */
     163        unsigned int tea575x_tuner;     /* tuner flags */
    159164
    160165        unsigned short ply_ctrl; /* playback control */
     
    173178        unsigned int cap_pos;
    174179
    175         ac97_bus_t *ac97_bus;
    176         ac97_t *ac97;
    177         ac97_t *ac97_sec;
     180        struct snd_ac97_bus *ac97_bus;
     181        struct snd_ac97 *ac97;
     182        struct snd_ac97 *ac97_sec;
    178183
    179184        struct pci_dev *pci;
    180         snd_card_t *card;
    181         snd_pcm_t *pcm;
    182         snd_rawmidi_t *rmidi;
    183         snd_pcm_substream_t *playback_substream;
    184         snd_pcm_substream_t *capture_substream;
     185        struct snd_card *card;
     186        struct snd_pcm *pcm;
     187        struct snd_rawmidi *rmidi;
     188        struct snd_pcm_substream *playback_substream;
     189        struct snd_pcm_substream *capture_substream;
    185190        unsigned int p_dma_size;
    186191        unsigned int c_dma_size;
    187192
    188193        spinlock_t reg_lock;
    189         snd_info_entry_t *proc_entry;
     194        struct snd_info_entry *proc_entry;
    190195
    191196#ifdef TEA575X_RADIO
    192         tea575x_t tea;
     197        struct snd_tea575x tea;
     198#endif
     199
     200#ifdef CONFIG_PM
     201        u16 saved_regs[0x20];
    193202#endif
    194203};
     
    196205static struct pci_device_id snd_fm801_ids[] = {
    197206        { 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, },   /* FM801 */
     207        { 0x5213, 0x0510, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, },   /* Gallant Odyssey Sound 4 */
    198208        { 0, }
    199209};
     
    205215 */
    206216
    207 static int snd_fm801_update_bits(fm801_t *chip, unsigned short reg,
     217static int snd_fm801_update_bits(struct fm801 *chip, unsigned short reg,
    208218                                 unsigned short mask, unsigned short value)
    209219{
    210     int change;
    211     unsigned long flags;
    212     unsigned short old, new;
    213 
    214     spin_lock_irqsave(&chip->reg_lock, flags);
     220        int change;
     221        unsigned long flags;
     222        unsigned short old, new;
     223
     224        spin_lock_irqsave(&chip->reg_lock, flags);
    215225        old = inw(chip->port + reg);
    216226        new = (old & ~mask) | value;
    217227        change = old != new;
    218228        if (change)
    219             outw(new, chip->port + reg);
    220         spin_unlock_irqrestore(&chip->reg_lock, flags);
     229                outw(new, chip->port + reg);
     230        spin_unlock_irqrestore(&chip->reg_lock, flags);
    221231        return change;
    222232}
    223233
    224 static void snd_fm801_codec_write(ac97_t *ac97,
     234static void snd_fm801_codec_write(struct snd_ac97 *ac97,
    225235                                  unsigned short reg,
    226236                                  unsigned short val)
    227237{
    228         fm801_t *chip = ac97->private_data;
     238        struct fm801 *chip = ac97->private_data;
    229239        int idx;
    230240
     
    233243         */
    234244        for (idx = 0; idx < 100; idx++) {
    235                 if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))
     245                if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
    236246                        goto ok1;
    237247                udelay(10);
    238248        }
    239         snd_printk("AC'97 interface is busy (1)\n");
     249        snd_printk(KERN_ERR "AC'97 interface is busy (1)\n");
    240250        return;
    241251
     
    248258         */
    249259        for (idx = 0; idx < 1000; idx++) {
    250                 if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))
     260                if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
    251261                        return;
    252262                udelay(10);
    253263        }
    254         snd_printk("AC'97 interface #%d is busy (2)\n", ac97->num);
    255 }
    256 
    257 static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
    258 {
    259         fm801_t *chip = ac97->private_data;
     264        snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
     265}
     266
     267static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short reg)
     268{
     269        struct fm801 *chip = ac97->private_data;
    260270        int idx;
    261271
     
    264274         */
    265275        for (idx = 0; idx < 100; idx++) {
    266                 if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))
     276                if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
    267277                        goto ok1;
    268278                udelay(10);
    269279        }
    270         snd_printk("AC'97 interface is busy (1)\n");
     280        snd_printk(KERN_ERR "AC'97 interface is busy (1)\n");
    271281        return 0;
    272282
    273283 ok1:
    274284        /* read command */
    275         outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | (1<<7), FM801_REG(chip, AC97_CMD));
     285        outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ,
     286             FM801_REG(chip, AC97_CMD));
    276287        for (idx = 0; idx < 100; idx++) {
    277                 if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))
     288                if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
    278289                        goto ok2;
    279290                udelay(10);
    280291        }
    281         snd_printk("AC'97 interface #%d is busy (2)\n", ac97->num);
     292        snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
    282293        return 0;
    283294
    284295 ok2:
    285296        for (idx = 0; idx < 1000; idx++) {
    286                 if (inw(FM801_REG(chip, AC97_CMD)) & (1<<8))
     297                if (inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_VALID)
    287298                        goto ok3;
    288299                udelay(10);
    289300        }
    290         snd_printk("AC'97 interface #%d is not valid (2)\n", ac97->num);
     301        snd_printk(KERN_ERR "AC'97 interface #%d is not valid (2)\n", ac97->num);
    291302        return 0;
    292303
     
    301312};
    302313
    303 static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
    304        /* .count = */ ARRAY_SIZE(rates),
    305        /* .list = */rates,
    306        /* .mask = */0,
     314static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
     315        .count = ARRAY_SIZE(rates),
     316        .list = rates,
     317        .mask = 0,
    307318};
    308319
     
    311322};
    312323
    313 #define CHANNELS sizeof(channels) / sizeof(channels[0])
    314 
    315 static snd_pcm_hw_constraint_list_t hw_constraints_channels = {
    316        /* .count = */CHANNELS,
    317        /* .list = */channels,
    318        /* .mask = */0,
     324static struct snd_pcm_hw_constraint_list hw_constraints_channels = {
     325        .count = ARRAY_SIZE(channels),
     326        .list = channels,
     327        .mask = 0,
    319328};
    320329
     
    338347 */
    339348
    340 static int snd_fm801_playback_trigger(snd_pcm_substream_t * substream,
     349static int snd_fm801_playback_trigger(struct snd_pcm_substream *substream,
    341350                                      int cmd)
    342351{
    343         fm801_t *chip = snd_pcm_substream_chip(substream);
     352        struct fm801 *chip = snd_pcm_substream_chip(substream);
    344353
    345354        spin_lock(&chip->reg_lock);
     
    356365                break;
    357366        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
     367        case SNDRV_PCM_TRIGGER_SUSPEND:
    358368                chip->ply_ctrl |= FM801_PAUSE;
    359369                break;
    360370        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
     371        case SNDRV_PCM_TRIGGER_RESUME:
    361372                chip->ply_ctrl &= ~FM801_PAUSE;
    362373                break;
     
    371382}
    372383
    373 static int snd_fm801_capture_trigger(snd_pcm_substream_t * substream,
     384static int snd_fm801_capture_trigger(struct snd_pcm_substream *substream,
    374385                                     int cmd)
    375386{
    376         fm801_t *chip = snd_pcm_substream_chip(substream);
     387        struct fm801 *chip = snd_pcm_substream_chip(substream);
    377388
    378389        spin_lock(&chip->reg_lock);
     
    389400                break;
    390401        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
     402        case SNDRV_PCM_TRIGGER_SUSPEND:
    391403                chip->cap_ctrl |= FM801_PAUSE;
    392404                break;
    393405        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
     406        case SNDRV_PCM_TRIGGER_RESUME:
    394407                chip->cap_ctrl &= ~FM801_PAUSE;
    395408                break;
     
    404417}
    405418
    406 static int snd_fm801_hw_params(snd_pcm_substream_t * substream,
    407                                snd_pcm_hw_params_t * hw_params)
     419static int snd_fm801_hw_params(struct snd_pcm_substream *substream,
     420                               struct snd_pcm_hw_params *hw_params)
    408421{
    409422        return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
    410423}
    411424
    412 static int snd_fm801_hw_free(snd_pcm_substream_t * substream)
     425static int snd_fm801_hw_free(struct snd_pcm_substream *substream)
    413426{
    414427        return snd_pcm_lib_free_pages(substream);
    415428}
    416429
    417 static int snd_fm801_playback_prepare(snd_pcm_substream_t * substream)
    418 {
    419         fm801_t *chip = snd_pcm_substream_chip(substream);
    420         snd_pcm_runtime_t *runtime = substream->runtime;
     430static int snd_fm801_playback_prepare(struct snd_pcm_substream *substream)
     431{
     432        struct fm801 *chip = snd_pcm_substream_chip(substream);
     433        struct snd_pcm_runtime *runtime = substream->runtime;
    421434
    422435        chip->ply_size = snd_pcm_lib_buffer_bytes(substream);
    423         chip->ply_count = snd_pcm_lib_period_bytes(substream);
    424         spin_lock_irq(&chip->reg_lock);
     436        chip->ply_count = snd_pcm_lib_period_bytes(substream);
     437        spin_lock_irq(&chip->reg_lock);
    425438        chip->ply_ctrl &= ~(FM801_START | FM801_16BIT |
    426439                             FM801_STEREO | FM801_RATE_MASK |
     
    442455        chip->ply_pos = 0;
    443456        outl(chip->ply_buffer, FM801_REG(chip, PLY_BUF1));
    444         outl(chip->ply_buffer + (chip->ply_count % chip->ply_size), FM801_REG(chip, PLY_BUF2));
    445         spin_unlock_irq(&chip->reg_lock);
    446         return 0;
    447 }
    448 
    449 static int snd_fm801_capture_prepare(snd_pcm_substream_t * substream)
    450 {
    451         fm801_t *chip = snd_pcm_substream_chip(substream);
    452         snd_pcm_runtime_t *runtime = substream->runtime;
     457        outl(chip->ply_buffer + (chip->ply_count % chip->ply_size), FM801_REG(chip, PLY_BUF2));
     458        spin_unlock_irq(&chip->reg_lock);
     459        return 0;
     460}
     461
     462static int snd_fm801_capture_prepare(struct snd_pcm_substream *substream)
     463{
     464        struct fm801 *chip = snd_pcm_substream_chip(substream);
     465        struct snd_pcm_runtime *runtime = substream->runtime;
    453466
    454467        chip->cap_size = snd_pcm_lib_buffer_bytes(substream);
    455         chip->cap_count = snd_pcm_lib_period_bytes(substream);
    456         spin_lock_irq(&chip->reg_lock);
     468        chip->cap_count = snd_pcm_lib_period_bytes(substream);
     469        spin_lock_irq(&chip->reg_lock);
    457470        chip->cap_ctrl &= ~(FM801_START | FM801_16BIT |
    458471                             FM801_STEREO | FM801_RATE_MASK);
     
    468481        chip->cap_pos = 0;
    469482        outl(chip->cap_buffer, FM801_REG(chip, CAP_BUF1));
    470         outl(chip->cap_buffer + (chip->cap_count % chip->cap_size), FM801_REG(chip, CAP_BUF2));
    471         spin_unlock_irq(&chip->reg_lock);
    472         return 0;
    473 }
    474 
    475 static snd_pcm_uframes_t snd_fm801_playback_pointer(snd_pcm_substream_t * substream)
    476 {
    477         fm801_t *chip = snd_pcm_substream_chip(substream);
     483        outl(chip->cap_buffer + (chip->cap_count % chip->cap_size), FM801_REG(chip, CAP_BUF2));
     484        spin_unlock_irq(&chip->reg_lock);
     485        return 0;
     486}
     487
     488static snd_pcm_uframes_t snd_fm801_playback_pointer(struct snd_pcm_substream *substream)
     489{
     490        struct fm801 *chip = snd_pcm_substream_chip(substream);
    478491        size_t ptr;
    479492
     
    490503}
    491504
    492 static snd_pcm_uframes_t snd_fm801_capture_pointer(snd_pcm_substream_t * substream)
    493 {
    494         fm801_t *chip = snd_pcm_substream_chip(substream);
     505static snd_pcm_uframes_t snd_fm801_capture_pointer(struct snd_pcm_substream *substream)
     506{
     507        struct fm801 *chip = snd_pcm_substream_chip(substream);
    495508        size_t ptr;
    496509
     
    507520}
    508521
    509 static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id, struct pt_regs *regs)
    510 {
    511         fm801_t *chip = dev_id;
     522static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id)
     523{
     524        struct fm801 *chip = dev_id;
    512525        unsigned short status;
    513526        unsigned int tmp;
     
    516529        status &= FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU|FM801_IRQ_VOLUME;
    517530        if (! status)
    518             return IRQ_NONE;
    519 
     531                return IRQ_NONE;
    520532        /* ack first */
    521533        outw(status, FM801_REG(chip, IRQ_STATUS));
     
    549561        }
    550562        if (chip->rmidi && (status & FM801_IRQ_MPU))
    551                 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
     563                snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
    552564        if (status & FM801_IRQ_VOLUME)
    553565                ;/* TODO */
    554 #ifdef TARGET_OS2
    555         eoi_irq(irq);
    556 #endif //TARGET_OS2
    557566
    558567        return IRQ_HANDLED;
    559568}
    560569
    561 static snd_pcm_hardware_t snd_fm801_playback =
    562 {
    563         /*.info =             */        (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     570static struct snd_pcm_hardware snd_fm801_playback =
     571{
     572        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
    564573                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
    565                                  SNDRV_PCM_INFO_PAUSE |
     574                                 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
    566575                                 SNDRV_PCM_INFO_MMAP_VALID),
    567         /*.formats =           */ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
    568         /*.rates =             */ SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
    569         /*.rate_min =          */ 5500,
    570         /*.rate_max =          */ 48000,
    571         /*.channels_min =      */       1,
    572         /*.channels_max =      */       2,
    573         /*.buffer_bytes_max =  */ (128*1024),
    574         /*.period_bytes_min =  */ 64,
    575         /*.period_bytes_max =  */ (128*1024),
    576         /*.periods_min =       */       1,
    577         /*.periods_max =       */       1024,
    578         /*.fifo_size =         */ 0,
     576        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
     577        .rates =                SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
     578        .rate_min =             5500,
     579        .rate_max =             48000,
     580        .channels_min =         1,
     581        .channels_max =         2,
     582        .buffer_bytes_max =     (128*1024),
     583        .period_bytes_min =     64,
     584        .period_bytes_max =     (128*1024),
     585        .periods_min =          1,
     586        .periods_max =          1024,
     587        .fifo_size =            0,
    579588};
    580589
    581 static snd_pcm_hardware_t snd_fm801_capture =
    582 {
    583         /*.info =              */       (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
     590static struct snd_pcm_hardware snd_fm801_capture =
     591{
     592        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
    584593                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
    585                                  SNDRV_PCM_INFO_PAUSE |
     594                                 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
    586595                                 SNDRV_PCM_INFO_MMAP_VALID),
    587         /*.formats =           */ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
    588         /*.rates =             */ SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
    589         /*.rate_min =          */ 5500,
    590         /*.rate_max =          */ 48000,
    591         /*.channels_min =      */       1,
    592         /*.channels_max =      */       2,
    593         /*.buffer_bytes_max =  */ (128*1024),
    594         /*.period_bytes_min =  */ 64,
    595         /*.period_bytes_max =  */ (128*1024),
    596         /*.periods_min =       */       1,
    597         /*.periods_max =       */       1024,
    598         /*.fifo_size =         */ 0,
     596        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
     597        .rates =                SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
     598        .rate_min =             5500,
     599        .rate_max =             48000,
     600        .channels_min =         1,
     601        .channels_max =         2,
     602        .buffer_bytes_max =     (128*1024),
     603        .period_bytes_min =     64,
     604        .period_bytes_max =     (128*1024),
     605        .periods_min =          1,
     606        .periods_max =          1024,
     607        .fifo_size =            0,
    599608};
    600609
    601 static int snd_fm801_playback_open(snd_pcm_substream_t * substream)
    602 {
    603         fm801_t *chip = snd_pcm_substream_chip(substream);
    604         snd_pcm_runtime_t *runtime = substream->runtime;
     610static int snd_fm801_playback_open(struct snd_pcm_substream *substream)
     611{
     612        struct fm801 *chip = snd_pcm_substream_chip(substream);
     613        struct snd_pcm_runtime *runtime = substream->runtime;
    605614        int err;
    606615
    607616        chip->playback_substream = substream;
    608617        runtime->hw = snd_fm801_playback;
    609         snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
     618        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
     619                                   &hw_constraints_rates);
    610620        if (chip->multichannel) {
    611621                runtime->hw.channels_max = 6;
    612                 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels);
     622                snd_pcm_hw_constraint_list(runtime, 0,
     623                                           SNDRV_PCM_HW_PARAM_CHANNELS,
     624                                           &hw_constraints_channels);
    613625        }
    614626        if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
     
    617629}
    618630
    619 static int snd_fm801_capture_open(snd_pcm_substream_t * substream)
    620 {
    621         fm801_t *chip = snd_pcm_substream_chip(substream);
    622         snd_pcm_runtime_t *runtime = substream->runtime;
     631static int snd_fm801_capture_open(struct snd_pcm_substream *substream)
     632{
     633        struct fm801 *chip = snd_pcm_substream_chip(substream);
     634        struct snd_pcm_runtime *runtime = substream->runtime;
    623635        int err;
    624636
    625637        chip->capture_substream = substream;
    626638        runtime->hw = snd_fm801_capture;
    627         snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
     639        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
     640                                   &hw_constraints_rates);
    628641        if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
    629642                return err;
     
    631644}
    632645
    633 static int snd_fm801_playback_close(snd_pcm_substream_t * substream)
    634 {
    635         fm801_t *chip = snd_pcm_substream_chip(substream);
     646static int snd_fm801_playback_close(struct snd_pcm_substream *substream)
     647{
     648        struct fm801 *chip = snd_pcm_substream_chip(substream);
    636649
    637650        chip->playback_substream = NULL;
     
    639652}
    640653
    641 static int snd_fm801_capture_close(snd_pcm_substream_t * substream)
    642 {
    643         fm801_t *chip = snd_pcm_substream_chip(substream);
     654static int snd_fm801_capture_close(struct snd_pcm_substream *substream)
     655{
     656        struct fm801 *chip = snd_pcm_substream_chip(substream);
    644657
    645658        chip->capture_substream = NULL;
     
    647660}
    648661
    649 static snd_pcm_ops_t snd_fm801_playback_ops = {
    650         /*.open =      */ snd_fm801_playback_open,
    651         /*.close =     */ snd_fm801_playback_close,
    652         /*.ioctl =     */ snd_pcm_lib_ioctl,
    653         /*.hw_params = */ snd_fm801_hw_params,
    654         /*.hw_free =   */ snd_fm801_hw_free,
    655         /*.prepare =   */ snd_fm801_playback_prepare,
    656         /*.trigger =   */ snd_fm801_playback_trigger,
    657         /*.pointer =   */ snd_fm801_playback_pointer,
    658         0,0,0,0
     662static struct snd_pcm_ops snd_fm801_playback_ops = {
     663        .open =         snd_fm801_playback_open,
     664        .close =        snd_fm801_playback_close,
     665        .ioctl =        snd_pcm_lib_ioctl,
     666        .hw_params =    snd_fm801_hw_params,
     667        .hw_free =      snd_fm801_hw_free,
     668        .prepare =      snd_fm801_playback_prepare,
     669        .trigger =      snd_fm801_playback_trigger,
     670        .pointer =      snd_fm801_playback_pointer,
    659671};
    660672
    661 static snd_pcm_ops_t snd_fm801_capture_ops = {
    662         /*.open =      */ snd_fm801_capture_open,
    663         /*.close =     */ snd_fm801_capture_close,
    664         /*.ioctl =     */ snd_pcm_lib_ioctl,
    665         /*.hw_params = */ snd_fm801_hw_params,
    666         /*.hw_free =   */ snd_fm801_hw_free,
    667         /*.prepare =   */ snd_fm801_capture_prepare,
    668         /*.trigger =   */ snd_fm801_capture_trigger,
    669         /*.pointer =   */ snd_fm801_capture_pointer,
    670         0,0,0,0
     673static struct snd_pcm_ops snd_fm801_capture_ops = {
     674        .open =         snd_fm801_capture_open,
     675        .close =        snd_fm801_capture_close,
     676        .ioctl =        snd_pcm_lib_ioctl,
     677        .hw_params =    snd_fm801_hw_params,
     678        .hw_free =      snd_fm801_hw_free,
     679        .prepare =      snd_fm801_capture_prepare,
     680        .trigger =      snd_fm801_capture_trigger,
     681        .pointer =      snd_fm801_capture_pointer,
    671682};
    672683
    673 static void snd_fm801_pcm_free(snd_pcm_t *pcm)
    674 {
    675         fm801_t *chip = pcm->private_data;
    676         chip->pcm = NULL;
    677         snd_pcm_lib_preallocate_free_for_all(pcm);
    678 }
    679 
    680 static int __devinit snd_fm801_pcm(fm801_t *chip, int device, snd_pcm_t ** rpcm)
    681 {
    682         snd_pcm_t *pcm;
     684static int __devinit snd_fm801_pcm(struct fm801 *chip, int device, struct snd_pcm ** rpcm)
     685{
     686        struct snd_pcm *pcm;
    683687        int err;
    684688
     
    692696
    693697        pcm->private_data = chip;
    694         pcm->private_free = snd_fm801_pcm_free;
    695698        pcm->info_flags = 0;
    696699        strcpy(pcm->name, "FM801");
     
    717720#define TEA_256PCS_BUS_CLOCK            3
    718721
    719 static void snd_fm801_tea575x_256pcs_write(tea575x_t *tea, unsigned int val)
    720 {
    721         fm801_t *chip = tea->private_data;
     722static void snd_fm801_tea575x_256pcs_write(struct snd_tea575x *tea, unsigned int val)
     723{
     724        struct fm801 *chip = tea->private_data;
    722725        unsigned short reg;
    723726        int i = 25;
     
    761764}
    762765
    763 static unsigned int snd_fm801_tea575x_256pcs_read(tea575x_t *tea)
    764 {
    765         fm801_t *chip = tea->private_data;
     766static unsigned int snd_fm801_tea575x_256pcs_read(struct snd_tea575x *tea)
     767{
     768        struct fm801 *chip = tea->private_data;
    766769        unsigned short reg;
    767770        unsigned int val = 0;
     
    805808#define TEA_256PCPR_WRITE_ENABLE        2       /* inverted */
    806809
    807 static void snd_fm801_tea575x_256pcpr_write(tea575x_t *tea, unsigned int val)
    808 {
    809         fm801_t *chip = tea->private_data;
     810static void snd_fm801_tea575x_256pcpr_write(struct snd_tea575x *tea, unsigned int val)
     811{
     812        struct fm801 *chip = tea->private_data;
    810813        unsigned short reg;
    811814        int i = 25;
     
    849852}
    850853
    851 static unsigned int snd_fm801_tea575x_256pcpr_read(tea575x_t *tea)
    852 {
    853         fm801_t *chip = tea->private_data;
     854static unsigned int snd_fm801_tea575x_256pcpr_read(struct snd_tea575x *tea)
     855{
     856        struct fm801 *chip = tea->private_data;
    854857        unsigned short reg;
    855858        unsigned int val = 0;
     
    893896#define TEA_64PCR_DATA                  2
    894897
    895 static void snd_fm801_tea575x_64pcr_write(tea575x_t *tea, unsigned int val)
    896 {
    897         fm801_t *chip = tea->private_data;
     898static void snd_fm801_tea575x_64pcr_write(struct snd_tea575x *tea, unsigned int val)
     899{
     900        struct fm801 *chip = tea->private_data;
    898901        unsigned short reg;
    899902        int i = 25;
     
    937940}
    938941
    939 static unsigned int snd_fm801_tea575x_64pcr_read(tea575x_t *tea)
    940 {
    941         fm801_t *chip = tea->private_data;
     942static unsigned int snd_fm801_tea575x_64pcr_read(struct snd_tea575x *tea)
     943{
     944        struct fm801 *chip = tea->private_data;
    942945        unsigned short reg;
    943946        unsigned int val = 0;
     
    976979}
    977980
     981static void snd_fm801_tea575x_64pcr_mute(struct snd_tea575x *tea,
     982                                          unsigned int mute)
     983{
     984        struct fm801 *chip = tea->private_data;
     985        unsigned short reg;
     986
     987        spin_lock_irq(&chip->reg_lock);
     988
     989        reg = inw(FM801_REG(chip, GPIO_CTRL));
     990        if (mute)
     991                /* 0xf800 (mute) */
     992                reg &= ~FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE);
     993        else
     994                /* 0xf802 (unmute) */
     995                reg |= FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE);
     996        outw(reg, FM801_REG(chip, GPIO_CTRL));
     997        udelay(1);
     998
     999        spin_unlock_irq(&chip->reg_lock);
     1000}
     1001
    9781002static struct snd_tea575x_ops snd_fm801_tea_ops[3] = {
    9791003        {
     
    9911015                .write = snd_fm801_tea575x_64pcr_write,
    9921016                .read = snd_fm801_tea575x_64pcr_read,
     1017                .mute = snd_fm801_tea575x_64pcr_mute,
    9931018        }
    9941019};
     
    10001025
    10011026#define FM801_SINGLE(xname, reg, shift, mask, invert) \
    1002 { SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, xname, 0,0,0, snd_fm801_info_single, \
    1003   snd_fm801_get_single, snd_fm801_put_single, \
    1004   0, reg | (shift << 8) | (mask << 16) | (invert << 24) }
    1005 
    1006 static int snd_fm801_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1027{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_single, \
     1028  .get = snd_fm801_get_single, .put = snd_fm801_put_single, \
     1029  .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
     1030
     1031static int snd_fm801_info_single(struct snd_kcontrol *kcontrol,
     1032                                 struct snd_ctl_elem_info *uinfo)
    10071033{
    10081034        int mask = (kcontrol->private_value >> 16) & 0xff;
     
    10151041}
    10161042
    1017 static int snd_fm801_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    1018 {
    1019         fm801_t *chip = snd_kcontrol_chip(kcontrol);
     1043static int snd_fm801_get_single(struct snd_kcontrol *kcontrol,
     1044                                struct snd_ctl_elem_value *ucontrol)
     1045{
     1046        struct fm801 *chip = snd_kcontrol_chip(kcontrol);
    10201047        int reg = kcontrol->private_value & 0xff;
    10211048        int shift = (kcontrol->private_value >> 8) & 0xff;
     
    10291056}
    10301057
    1031 static int snd_fm801_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    1032 {
    1033         fm801_t *chip = snd_kcontrol_chip(kcontrol);
     1058static int snd_fm801_put_single(struct snd_kcontrol *kcontrol,
     1059                                struct snd_ctl_elem_value *ucontrol)
     1060{
     1061        struct fm801 *chip = snd_kcontrol_chip(kcontrol);
    10341062        int reg = kcontrol->private_value & 0xff;
    10351063        int shift = (kcontrol->private_value >> 8) & 0xff;
     
    10451073
    10461074#define FM801_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
    1047 { SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, xname, 0,0,0, snd_fm801_info_double, \
    1048   snd_fm801_get_double, snd_fm801_put_double, \
    1049   0, reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) }
    1050 
    1051 static int snd_fm801_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1075{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_double, \
     1076  .get = snd_fm801_get_double, .put = snd_fm801_put_double, \
     1077  .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) }
     1078#define FM801_DOUBLE_TLV(xname, reg, shift_left, shift_right, mask, invert, xtlv) \
     1079{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
     1080  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
     1081  .name = xname, .info = snd_fm801_info_double, \
     1082  .get = snd_fm801_get_double, .put = snd_fm801_put_double, \
     1083  .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24), \
     1084  .tlv = { .p = (xtlv) } }
     1085
     1086static int snd_fm801_info_double(struct snd_kcontrol *kcontrol,
     1087                                 struct snd_ctl_elem_info *uinfo)
    10521088{
    10531089        int mask = (kcontrol->private_value >> 16) & 0xff;
     
    10601096}
    10611097
    1062 static int snd_fm801_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    1063 {
    1064         fm801_t *chip = snd_kcontrol_chip(kcontrol);
     1098static int snd_fm801_get_double(struct snd_kcontrol *kcontrol,
     1099                                struct snd_ctl_elem_value *ucontrol)
     1100{
     1101        struct fm801 *chip = snd_kcontrol_chip(kcontrol);
    10651102        int reg = kcontrol->private_value & 0xff;
    10661103        int shift_left = (kcontrol->private_value >> 8) & 0x0f;
     
    10801117}
    10811118
    1082 static int snd_fm801_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    1083 {
    1084         fm801_t *chip = snd_kcontrol_chip(kcontrol);
     1119static int snd_fm801_put_double(struct snd_kcontrol *kcontrol,
     1120                                struct snd_ctl_elem_value *ucontrol)
     1121{
     1122        struct fm801 *chip = snd_kcontrol_chip(kcontrol);
    10851123        int reg = kcontrol->private_value & 0xff;
    10861124        int shift_left = (kcontrol->private_value >> 8) & 0x0f;
     
    11011139}
    11021140
    1103 static int snd_fm801_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
     1141static int snd_fm801_info_mux(struct snd_kcontrol *kcontrol,
     1142                              struct snd_ctl_elem_info *uinfo)
    11041143{
    11051144        static char *texts[5] = {
     
    11161155}
    11171156
    1118 static int snd_fm801_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    1119 {
    1120         fm801_t *chip = snd_kcontrol_chip(kcontrol);
     1157static int snd_fm801_get_mux(struct snd_kcontrol *kcontrol,
     1158                             struct snd_ctl_elem_value *ucontrol)
     1159{
     1160        struct fm801 *chip = snd_kcontrol_chip(kcontrol);
    11211161        unsigned short val;
    11221162 
     
    11281168}
    11291169
    1130 static int snd_fm801_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
    1131 {
    1132         fm801_t *chip = snd_kcontrol_chip(kcontrol);
     1170static int snd_fm801_put_mux(struct snd_kcontrol *kcontrol,
     1171                             struct snd_ctl_elem_value *ucontrol)
     1172{
     1173        struct fm801 *chip = snd_kcontrol_chip(kcontrol);
    11331174        unsigned short val;
    11341175 
     
    11381179}
    11391180
    1140 #define FM801_CONTROLS (sizeof(snd_fm801_controls)/sizeof(snd_kcontrol_new_t))
    1141 
    1142 static snd_kcontrol_new_t snd_fm801_controls[] __devinitdata = {
    1143 FM801_DOUBLE("Wave Playback Volume", FM801_PCM_VOL, 0, 8, 31, 1),
     1181static const DECLARE_TLV_DB_SCALE(db_scale_dsp, -3450, 150, 0);
     1182
     1183#define FM801_CONTROLS ARRAY_SIZE(snd_fm801_controls)
     1184
     1185static struct snd_kcontrol_new snd_fm801_controls[] __devinitdata = {
     1186FM801_DOUBLE_TLV("Wave Playback Volume", FM801_PCM_VOL, 0, 8, 31, 1,
     1187                 db_scale_dsp),
    11441188FM801_SINGLE("Wave Playback Switch", FM801_PCM_VOL, 15, 1, 1),
    1145 FM801_DOUBLE("I2S Playback Volume", FM801_I2S_VOL, 0, 8, 31, 1),
     1189FM801_DOUBLE_TLV("I2S Playback Volume", FM801_I2S_VOL, 0, 8, 31, 1,
     1190                 db_scale_dsp),
    11461191FM801_SINGLE("I2S Playback Switch", FM801_I2S_VOL, 15, 1, 1),
    1147 FM801_DOUBLE("FM Playback Volume", FM801_FM_VOL, 0, 8, 31, 1),
     1192FM801_DOUBLE_TLV("FM Playback Volume", FM801_FM_VOL, 0, 8, 31, 1,
     1193                 db_scale_dsp),
    11481194FM801_SINGLE("FM Playback Switch", FM801_FM_VOL, 15, 1, 1),
    11491195{
    1150         SNDRV_CTL_ELEM_IFACE_MIXER, 0,0,
    1151         "Digital Capture Source",0,0,0,
    1152         snd_fm801_info_mux,
    1153         snd_fm801_get_mux,
    1154         snd_fm801_put_mux,0
     1196        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
     1197        .name = "Digital Capture Source",
     1198        .info = snd_fm801_info_mux,
     1199        .get = snd_fm801_get_mux,
     1200        .put = snd_fm801_put_mux,
    11551201}
    11561202};
    11571203
    1158 #define FM801_CONTROLS_MULTI (sizeof(snd_fm801_controls_multi)/sizeof(snd_kcontrol_new_t))
    1159 
    1160 static snd_kcontrol_new_t snd_fm801_controls_multi[] __devinitdata = {
     1204#define FM801_CONTROLS_MULTI ARRAY_SIZE(snd_fm801_controls_multi)
     1205
     1206static struct snd_kcontrol_new snd_fm801_controls_multi[] __devinitdata = {
    11611207FM801_SINGLE("AC97 2ch->4ch Copy Switch", FM801_CODEC_CTRL, 7, 1, 0),
    11621208FM801_SINGLE("AC97 18-bit Switch", FM801_CODEC_CTRL, 10, 1, 0),
    1163 FM801_SINGLE("IEC958 Capture Switch", FM801_I2S_MODE, 8, 1, 0),
    1164 FM801_SINGLE("IEC958 Raw Data Playback Switch", FM801_I2S_MODE, 9, 1, 0),
    1165 FM801_SINGLE("IEC958 Raw Data Capture Switch", FM801_I2S_MODE, 10, 1, 0),
    1166 FM801_SINGLE("IEC958 Playback Switch", FM801_GEN_CTRL, 2, 1, 0),
     1209FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), FM801_I2S_MODE, 8, 1, 0),
     1210FM801_SINGLE(SNDRV_CTL_NAME_IEC958("Raw Data ",PLAYBACK,SWITCH), FM801_I2S_MODE, 9, 1, 0),
     1211FM801_SINGLE(SNDRV_CTL_NAME_IEC958("Raw Data ",CAPTURE,SWITCH), FM801_I2S_MODE, 10, 1, 0),
     1212FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), FM801_GEN_CTRL, 2, 1, 0),
    11671213};
    11681214
    1169 static void snd_fm801_mixer_free_ac97_bus(ac97_bus_t *bus)
    1170 {
    1171         fm801_t *chip = bus->private_data;
     1215static void snd_fm801_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
     1216{
     1217        struct fm801 *chip = bus->private_data;
    11721218        chip->ac97_bus = NULL;
    11731219}
    11741220
    1175 static void snd_fm801_mixer_free_ac97(ac97_t *ac97)
    1176 {
    1177         fm801_t *chip = ac97->private_data;
     1221static void snd_fm801_mixer_free_ac97(struct snd_ac97 *ac97)
     1222{
     1223        struct fm801 *chip = ac97->private_data;
    11781224        if (ac97->num == 0) {
    11791225                chip->ac97 = NULL;
     
    11831229}
    11841230
    1185 static int __devinit snd_fm801_mixer(fm801_t *chip)
    1186 {
    1187         ac97_template_t ac97;
     1231static int __devinit snd_fm801_mixer(struct fm801 *chip)
     1232{
     1233        struct snd_ac97_template ac97;
    11881234        unsigned int i;
    11891235        int err;
    1190         static ac97_bus_ops_t ops = {
    1191             0, 0, snd_fm801_codec_write,
    1192             snd_fm801_codec_read, 0,0
     1236        static struct snd_ac97_bus_ops ops = {
     1237                .write = snd_fm801_codec_write,
     1238                .read = snd_fm801_codec_read,
    11931239        };
    11941240
     
    12211267 */
    12221268
    1223 static int snd_fm801_free(fm801_t *chip)
     1269static int wait_for_codec(struct fm801 *chip, unsigned int codec_id,
     1270                          unsigned short reg, unsigned long waits)
     1271{
     1272        unsigned long timeout = jiffies + waits;
     1273
     1274        outw(FM801_AC97_READ | (codec_id << FM801_AC97_ADDR_SHIFT) | reg,
     1275             FM801_REG(chip, AC97_CMD));
     1276        udelay(5);
     1277        do {
     1278                if ((inw(FM801_REG(chip, AC97_CMD)) & (FM801_AC97_VALID|FM801_AC97_BUSY))
     1279                    == FM801_AC97_VALID)
     1280                        return 0;
     1281                schedule_timeout_uninterruptible(1);
     1282        } while (time_after(timeout, jiffies));
     1283        return -EIO;
     1284}
     1285
     1286static int snd_fm801_chip_init(struct fm801 *chip, int resume)
     1287{
     1288        int id;
     1289        unsigned short cmdw;
     1290
     1291        if (chip->tea575x_tuner & 0x0010)
     1292                goto __ac97_ok;
     1293
     1294        /* codec cold reset + AC'97 warm reset */
     1295        outw((1<<5) | (1<<6), FM801_REG(chip, CODEC_CTRL));
     1296        inw(FM801_REG(chip, CODEC_CTRL)); /* flush posting data */
     1297        udelay(100);
     1298        outw(0, FM801_REG(chip, CODEC_CTRL));
     1299
     1300        if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0) {
     1301                snd_printk(KERN_ERR "Primary AC'97 codec not found\n");
     1302                if (! resume)
     1303                        return -EIO;
     1304        }
     1305
     1306        if (chip->multichannel) {
     1307                if (chip->secondary_addr) {
     1308                        wait_for_codec(chip, chip->secondary_addr,
     1309                                       AC97_VENDOR_ID1, msecs_to_jiffies(50));
     1310                } else {
     1311                        /* my card has the secondary codec */
     1312                        /* at address #3, so the loop is inverted */
     1313                        for (id = 3; id > 0; id--) {
     1314                                if (! wait_for_codec(chip, id, AC97_VENDOR_ID1,
     1315                                                     msecs_to_jiffies(50))) {
     1316                                        cmdw = inw(FM801_REG(chip, AC97_DATA));
     1317                                        if (cmdw != 0xffff && cmdw != 0) {
     1318                                                chip->secondary = 1;
     1319                                                chip->secondary_addr = id;
     1320                                                break;
     1321                                        }
     1322                                }
     1323                        }
     1324                }
     1325
     1326                /* the recovery phase, it seems that probing for non-existing codec might */
     1327                /* cause timeout problems */
     1328                wait_for_codec(chip, 0, AC97_VENDOR_ID1, msecs_to_jiffies(750));
     1329        }
     1330
     1331      __ac97_ok:
     1332
     1333        /* init volume */
     1334        outw(0x0808, FM801_REG(chip, PCM_VOL));
     1335        outw(0x9f1f, FM801_REG(chip, FM_VOL));
     1336        outw(0x8808, FM801_REG(chip, I2S_VOL));
     1337
     1338        /* I2S control - I2S mode */
     1339        outw(0x0003, FM801_REG(chip, I2S_MODE));
     1340
     1341        /* interrupt setup */
     1342        cmdw = inw(FM801_REG(chip, IRQ_MASK));
     1343        if (chip->irq < 0)
     1344                cmdw |= 0x00c3;         /* mask everything, no PCM nor MPU */
     1345        else
     1346                cmdw &= ~0x0083;        /* unmask MPU, PLAYBACK & CAPTURE */
     1347        outw(cmdw, FM801_REG(chip, IRQ_MASK));
     1348
     1349        /* interrupt clear */
     1350        outw(FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU, FM801_REG(chip, IRQ_STATUS));
     1351
     1352        return 0;
     1353}
     1354
     1355
     1356static int snd_fm801_free(struct fm801 *chip)
    12241357{
    12251358        unsigned short cmdw;
     
    12381371#endif
    12391372        if (chip->irq >= 0)
    1240                 free_irq(chip->irq, (void *)chip);
     1373                free_irq(chip->irq, chip);
    12411374        pci_release_regions(chip->pci);
    12421375        pci_disable_device(chip->pci);
     
    12461379}
    12471380
    1248 static int snd_fm801_dev_free(snd_device_t *device)
    1249 {
    1250         fm801_t *chip = device->device_data;
     1381static int snd_fm801_dev_free(struct snd_device *device)
     1382{
     1383        struct fm801 *chip = device->device_data;
    12511384        return snd_fm801_free(chip);
    12521385}
    12531386
    1254 static int __devinit snd_fm801_create(snd_card_t * card,
     1387static int __devinit snd_fm801_create(struct snd_card *card,
    12551388                                      struct pci_dev * pci,
    12561389                                      int tea575x_tuner,
    1257                                       fm801_t ** rchip)
    1258 {
    1259         fm801_t *chip;
    1260         unsigned char rev, id;
    1261         unsigned short cmdw;
    1262         unsigned long timeout;
     1390                                      struct fm801 ** rchip)
     1391{
     1392        struct fm801 *chip;
    12631393        int err;
    1264         static snd_device_ops_t ops = {
    1265                 snd_fm801_dev_free, 0,0,0
     1394        static struct snd_device_ops ops = {
     1395                .dev_free =     snd_fm801_dev_free,
    12661396        };
    12671397
     
    12691399        if ((err = pci_enable_device(pci)) < 0)
    12701400                return err;
    1271         chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
     1401        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
    12721402        if (chip == NULL) {
    12731403                pci_disable_device(pci);
     
    12781408        chip->pci = pci;
    12791409        chip->irq = -1;
     1410        chip->tea575x_tuner = tea575x_tuner;
    12801411        if ((err = pci_request_regions(pci, "FM801")) < 0) {
    12811412                kfree(chip);
     
    12841415        }
    12851416        chip->port = pci_resource_start(pci, 0);
    1286         if (request_irq(pci->irq, snd_fm801_interrupt, SA_INTERRUPT|SA_SHIRQ, "FM801", (void *)chip)) {
    1287                 snd_printk("unable to grab IRQ %d\n", chip->irq);
    1288                 snd_fm801_free(chip);
    1289                 return -EBUSY;
    1290         }
    1291         chip->irq = pci->irq;
    1292         pci_set_master(pci);
    1293 
    1294         pci_read_config_byte(pci, PCI_REVISION_ID, &rev);
    1295         if (rev >= 0xb1)        /* FM801-AU */
     1417        if ((tea575x_tuner & 0x0010) == 0) {
     1418                if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED,
     1419                                "FM801", chip)) {
     1420                        snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq);
     1421                        snd_fm801_free(chip);
     1422                        return -EBUSY;
     1423                }
     1424                chip->irq = pci->irq;
     1425                pci_set_master(pci);
     1426        }
     1427
     1428#ifndef TARGET_OS2
     1429        if (pci->revision >= 0xb1)      /* FM801-AU */
     1430#else
     1431        if (snd_pci_revision(pci) >= 0xb1)      /* FM801-AU */
     1432#endif
    12961433                chip->multichannel = 1;
    12971434
    1298         /* codec cold reset + AC'97 warm reset */
    1299         outw((1<<5)|(1<<6), FM801_REG(chip, CODEC_CTRL));
    1300         inw(FM801_REG(chip, CODEC_CTRL)); /* flush posting data */
    1301         udelay(100);
    1302         outw(0, FM801_REG(chip, CODEC_CTRL));
    1303 
    1304         timeout = (jiffies + (3 * HZ) / 4) + 1;         /* min 750ms */
    1305 
    1306         outw((1<<7) | (0 << FM801_AC97_ADDR_SHIFT), FM801_REG(chip, AC97_CMD));
    1307         udelay(5);
    1308         do {
    1309                 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8))
    1310                         goto __ac97_secondary;
    1311                 set_current_state(TASK_UNINTERRUPTIBLE);
    1312                 schedule_timeout(1);
    1313         } while (time_after(timeout, jiffies));
    1314         snd_printk("Primary AC'97 codec not found\n");
    1315         snd_fm801_free(chip);
    1316         return -EIO;
    1317 
    1318       __ac97_secondary:
    1319         if (!chip->multichannel)        /* lookup is not required */
    1320                 goto __ac97_ok;
    1321         for (id = 3; id > 0; id--) {    /* my card has the secondary codec */
    1322                                         /* at address #3, so the loop is inverted */
    1323 
    1324                 timeout = jiffies + HZ / 20;
    1325 
    1326                 outw((1<<7) | (id << FM801_AC97_ADDR_SHIFT) | AC97_VENDOR_ID1, FM801_REG(chip, AC97_CMD));
    1327                 udelay(5);
    1328                 do {
    1329                         if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8)) {
    1330                                 cmdw = inw(FM801_REG(chip, AC97_DATA));
    1331                                 if (cmdw != 0xffff && cmdw != 0) {
    1332                                         chip->secondary = 1;
    1333                                         chip->secondary_addr = id;
    1334                                         goto __ac97_ok;
    1335                                 }
    1336                         }
    1337                         set_current_state(TASK_UNINTERRUPTIBLE);
    1338                         schedule_timeout(1);
    1339                 } while (time_after(timeout, jiffies));
    1340         }
    1341 
    1342         /* the recovery phase, it seems that probing for non-existing codec might */
    1343         /* cause timeout problems */
    1344         timeout = (jiffies + (3 * HZ) / 4) + 1;         /* min 750ms */
    1345 
    1346         outw((1<<7) | (0 << FM801_AC97_ADDR_SHIFT), FM801_REG(chip, AC97_CMD));
    1347         udelay(5);
    1348         do {
    1349                 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8))
    1350                         goto __ac97_ok;
    1351                 set_current_state(TASK_UNINTERRUPTIBLE);
    1352                 schedule_timeout(1);
    1353         } while (time_after(timeout, jiffies));
    1354         snd_printk("Primary AC'97 codec not responding\n");
    1355         snd_fm801_free(chip);
    1356         return -EIO;
    1357 
    1358       __ac97_ok:
    1359 
    1360         /* init volume */
    1361         outw(0x0808, FM801_REG(chip, PCM_VOL));
    1362         outw(0x9f1f, FM801_REG(chip, FM_VOL));
    1363         outw(0x8808, FM801_REG(chip, I2S_VOL));
    1364 
    1365         /* I2S control - I2S mode */
    1366         outw(0x0003, FM801_REG(chip, I2S_MODE));
    1367 
    1368         /* interrupt setup - unmask MPU, PLAYBACK & CAPTURE */
    1369         cmdw = inw(FM801_REG(chip, IRQ_MASK));
    1370         cmdw &= ~0x0083;
    1371         outw(cmdw, FM801_REG(chip, IRQ_MASK));
    1372 
    1373         /* interrupt clear */
    1374         outw(FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU, FM801_REG(chip, IRQ_STATUS));
     1435        snd_fm801_chip_init(chip, 0);
    13751436
    13761437        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
     
    13821443
    13831444#ifdef TEA575X_RADIO
    1384         if (tea575x_tuner > 0 && (tea575x_tuner & 0xffff) < 4) {
     1445        if (tea575x_tuner > 0 && (tea575x_tuner & 0x000f) < 4) {
    13851446                chip->tea.dev_nr = tea575x_tuner >> 16;
    13861447                chip->tea.card = card;
    13871448                chip->tea.freq_fixup = 10700;
    13881449                chip->tea.private_data = chip;
    1389                 chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & 0xffff) - 1];
     1450                chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & 0x000f) - 1];
    13901451                snd_tea575x_init(&chip->tea);
    13911452        }
     
    14001461{
    14011462        static int dev;
    1402         snd_card_t *card;
    1403         fm801_t *chip;
    1404         opl3_t *opl3;
     1463        struct snd_card *card;
     1464        struct fm801 *chip;
     1465        struct snd_opl3 *opl3;
    14051466        int err;
    14061467
     
    14191480                return err;
    14201481        }
     1482        card->private_data = chip;
    14211483
    14221484        strcpy(card->driver, "FM801");
     
    14261488                card->shortname, chip->port, chip->irq);
    14271489
     1490        if (tea575x_tuner[dev] & 0x0010)
     1491                goto __fm801_tuner_only;
     1492
    14281493        if ((err = snd_fm801_pcm(chip, 0, NULL)) < 0) {
    14291494                snd_card_free(card);
     
    14341499                return err;
    14351500        }
    1436         if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801,
    1437                                        FM801_REG(chip, MPU401_DATA),
     1501        if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801,
     1502                                       FM801_REG(chip, MPU401_DATA),
    14381503                                       MPU401_INFO_INTEGRATED,
    14391504                                       chip->irq, 0, &chip->rmidi)) < 0) {
     
    14521517        }
    14531518
     1519      __fm801_tuner_only:
    14541520        if ((err = snd_card_register(card)) < 0) {
    14551521                snd_card_free(card);
     
    14671533}
    14681534
     1535#ifdef CONFIG_PM
     1536static unsigned char saved_regs[] = {
     1537        FM801_PCM_VOL, FM801_I2S_VOL, FM801_FM_VOL, FM801_REC_SRC,
     1538        FM801_PLY_CTRL, FM801_PLY_COUNT, FM801_PLY_BUF1, FM801_PLY_BUF2,
     1539        FM801_CAP_CTRL, FM801_CAP_COUNT, FM801_CAP_BUF1, FM801_CAP_BUF2,
     1540        FM801_CODEC_CTRL, FM801_I2S_MODE, FM801_VOLUME, FM801_GEN_CTRL,
     1541};
     1542
     1543static int snd_fm801_suspend(struct pci_dev *pci, pm_message_t state)
     1544{
     1545        struct snd_card *card = pci_get_drvdata(pci);
     1546        struct fm801 *chip = card->private_data;
     1547        int i;
     1548
     1549        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
     1550        snd_pcm_suspend_all(chip->pcm);
     1551        snd_ac97_suspend(chip->ac97);
     1552        snd_ac97_suspend(chip->ac97_sec);
     1553        for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
     1554                chip->saved_regs[i] = inw(chip->port + saved_regs[i]);
     1555        /* FIXME: tea575x suspend */
     1556
     1557        pci_disable_device(pci);
     1558        pci_save_state(pci);
     1559        pci_set_power_state(pci, pci_choose_state(pci, state));
     1560        return 0;
     1561}
     1562
     1563static int snd_fm801_resume(struct pci_dev *pci)
     1564{
     1565        struct snd_card *card = pci_get_drvdata(pci);
     1566        struct fm801 *chip = card->private_data;
     1567        int i;
     1568
     1569        pci_set_power_state(pci, PCI_D0);
     1570        pci_restore_state(pci);
     1571        if (pci_enable_device(pci) < 0) {
     1572                printk(KERN_ERR "fm801: pci_enable_device failed, "
     1573                       "disabling device\n");
     1574                snd_card_disconnect(card);
     1575                return -EIO;
     1576        }
     1577        pci_set_master(pci);
     1578
     1579        snd_fm801_chip_init(chip, 1);
     1580        snd_ac97_resume(chip->ac97);
     1581        snd_ac97_resume(chip->ac97_sec);
     1582        for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
     1583                outw(chip->saved_regs[i], chip->port + saved_regs[i]);
     1584
     1585        snd_power_change_state(card, SNDRV_CTL_POWER_D0);
     1586        return 0;
     1587}
     1588#endif
     1589
    14691590static struct pci_driver driver = {
    1470     0,0,0,
    1471     "FM801",
    1472     snd_fm801_ids,
    1473     snd_card_fm801_probe,
    1474     snd_card_fm801_remove,
    1475     0,0
     1591        .name = "FM801",
     1592        .id_table = snd_fm801_ids,
     1593        .probe = snd_card_fm801_probe,
     1594        .remove = __devexit_p(snd_card_fm801_remove),
     1595#ifdef CONFIG_PM
     1596        .suspend = snd_fm801_suspend,
     1597        .resume = snd_fm801_resume,
     1598#endif
    14761599};
    14771600
    14781601static int __init alsa_card_fm801_init(void)
    14791602{
    1480         return pci_module_init(&driver);
     1603        return pci_register_driver(&driver);
    14811604}
    14821605
Note: See TracChangeset for help on using the changeset viewer.