linux/sound/oss/sb_card.c
<<
>>
Prefs
   1/*
   2 * sound/oss/sb_card.c
   3 *
   4 * Detection routine for the ISA Sound Blaster and compatable sound
   5 * cards.
   6 *
   7 * This file is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
   8 * Version 2 (June 1991). See the "COPYING" file distributed with this
   9 * software for more info.
  10 *
  11 * This is a complete rewrite of the detection routines. This was
  12 * prompted by the PnP API change during v2.5 and the ugly state the
  13 * code was in.
  14 *
  15 * Copyright (C) by Paul Laufer 2002. Based on code originally by
  16 * Hannu Savolainen which was modified by many others over the
  17 * years. Authors specifically mentioned in the previous version were:
  18 * Daniel Stone, Alessandro Zummo, Jeff Garzik, Arnaldo Carvalho de
  19 * Melo, Daniel Church, and myself.
  20 *
  21 * 02-05-2003 Original Release, Paul Laufer <paul@laufernet.com>
  22 * 02-07-2003 Bug made it into first release. Take two.
  23 */
  24
  25#include <linux/config.h>
  26#include <linux/module.h>
  27#include <linux/moduleparam.h>
  28#include <linux/init.h>
  29#ifdef CONFIG_MCA
  30#include <linux/mca.h>
  31#endif /* CONFIG_MCA */
  32#include "sound_config.h"
  33#include "sb_mixer.h"
  34#include "sb.h"
  35#ifdef CONFIG_PNP
  36#include <linux/pnp.h>
  37#endif /* CONFIG_PNP */
  38#include "sb_card.h"
  39
  40MODULE_DESCRIPTION("OSS Soundblaster ISA PnP and legacy sound driver");
  41MODULE_LICENSE("GPL");
  42
  43extern void *smw_free;
  44
  45static int __initdata mpu_io    = 0;
  46static int __initdata io        = -1;
  47static int __initdata irq       = -1;
  48static int __initdata dma       = -1;
  49static int __initdata dma16     = -1;
  50static int __initdata type      = 0; /* Can set this to a specific card type */
  51static int __initdata esstype   = 0; /* ESS chip type */
  52static int __initdata acer      = 0; /* Do acer notebook init? */
  53static int __initdata sm_games  = 0; /* Logitech soundman games? */
  54
  55static struct sb_card_config *legacy = NULL;
  56
  57#ifdef CONFIG_PNP
  58static int __initdata pnp       = 1;
  59/*
  60static int __initdata uart401   = 0;
  61*/
  62#else
  63static int __initdata pnp       = 0;
  64#endif
  65
  66module_param(io, int, 000);
  67MODULE_PARM_DESC(io,       "Soundblaster i/o base address (0x220,0x240,0x260,0x280)");
  68module_param(irq, int, 000);
  69MODULE_PARM_DESC(irq,      "IRQ (5,7,9,10)");
  70module_param(dma, int, 000);
  71MODULE_PARM_DESC(dma,      "8-bit DMA channel (0,1,3)");
  72module_param(dma16, int, 000);
  73MODULE_PARM_DESC(dma16,    "16-bit DMA channel (5,6,7)");
  74module_param(mpu_io, int, 000);
  75MODULE_PARM_DESC(mpu_io,   "MPU base address");
  76module_param(type, int, 000);
  77MODULE_PARM_DESC(type,     "You can set this to specific card type (doesn't " \
  78                 "work with pnp)");
  79module_param(sm_games, int, 000);
  80MODULE_PARM_DESC(sm_games, "Enable support for Logitech soundman games " \
  81                 "(doesn't work with pnp)");
  82module_param(esstype, int, 000);
  83MODULE_PARM_DESC(esstype,  "ESS chip type (doesn't work with pnp)");
  84module_param(acer, int, 000);
  85MODULE_PARM_DESC(acer,     "Set this to detect cards in some ACER notebooks "\
  86                 "(doesn't work with pnp)");
  87
  88#ifdef CONFIG_PNP
  89module_param(pnp, int, 000);
  90MODULE_PARM_DESC(pnp,     "Went set to 0 will disable detection using PnP. "\
  91                  "Default is 1.\n");
  92/* Not done yet.... */
  93/*
  94module_param(uart401, int, 000);
  95MODULE_PARM_DESC(uart401,  "When set to 1, will attempt to detect and enable"\
  96                 "the mpu on some clones");
  97*/
  98#endif /* CONFIG_PNP */
  99
 100/* OSS subsystem card registration shared by PnP and legacy routines */
 101static int sb_register_oss(struct sb_card_config *scc, struct sb_module_options *sbmo)
 102{
 103        if (!request_region(scc->conf.io_base, 16, "soundblaster")) {
 104                printk(KERN_ERR "sb: ports busy.\n");
 105                kfree(scc);
 106                return -EBUSY;
 107        }
 108
 109        if (!sb_dsp_detect(&scc->conf, 0, 0, sbmo)) {
 110                release_region(scc->conf.io_base, 16);
 111                printk(KERN_ERR "sb: Failed DSP Detect.\n");
 112                kfree(scc);
 113                return -ENODEV;
 114        }
 115        if(!sb_dsp_init(&scc->conf, THIS_MODULE)) {
 116                printk(KERN_ERR "sb: Failed DSP init.\n");
 117                kfree(scc);
 118                return -ENODEV;
 119        }
 120        if(scc->mpucnf.io_base > 0) {
 121                scc->mpu = 1;
 122                printk(KERN_INFO "sb: Turning on MPU\n");
 123                if(!probe_sbmpu(&scc->mpucnf, THIS_MODULE))
 124                        scc->mpu = 0;
 125        }
 126
 127        return 1;
 128}
 129
 130static void sb_unload(struct sb_card_config *scc)
 131{
 132        sb_dsp_unload(&scc->conf, 0);
 133        if(scc->mpu)
 134                unload_sbmpu(&scc->mpucnf);
 135        kfree(scc);
 136}
 137
 138/* Register legacy card with OSS subsystem */
 139static int sb_init_legacy(void)
 140{
 141        struct sb_module_options sbmo = {0};
 142
 143        if((legacy = kmalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
 144                printk(KERN_ERR "sb: Error: Could not allocate memory\n");
 145                return -ENOMEM;
 146        }
 147        memset(legacy, 0, sizeof(struct sb_card_config));
 148
 149        legacy->conf.io_base      = io;
 150        legacy->conf.irq          = irq;
 151        legacy->conf.dma          = dma;
 152        legacy->conf.dma2         = dma16;
 153        legacy->conf.card_subtype = type;
 154
 155        legacy->mpucnf.io_base = mpu_io;
 156        legacy->mpucnf.irq     = -1;
 157        legacy->mpucnf.dma     = -1;
 158        legacy->mpucnf.dma2    = -1;
 159
 160        sbmo.esstype  = esstype;
 161        sbmo.sm_games = sm_games;
 162        sbmo.acer     = acer;
 163
 164        return sb_register_oss(legacy, &sbmo);
 165}
 166
 167#ifdef CONFIG_PNP
 168
 169/* Populate the OSS subsystem structures with information from PnP */
 170static void sb_dev2cfg(struct pnp_dev *dev, struct sb_card_config *scc)
 171{
 172        scc->conf.io_base   = -1;
 173        scc->conf.irq       = -1;
 174        scc->conf.dma       = -1;
 175        scc->conf.dma2      = -1;
 176        scc->mpucnf.io_base = -1;
 177        scc->mpucnf.irq     = -1;
 178        scc->mpucnf.dma     = -1;
 179        scc->mpucnf.dma2    = -1;
 180
 181        /* All clones layout their PnP tables differently and some use
 182           different logical devices for the MPU */
 183        if(!strncmp("CTL",scc->card_id,3)) {
 184                scc->conf.io_base   = pnp_port_start(dev,0);
 185                scc->conf.irq       = pnp_irq(dev,0);
 186                scc->conf.dma       = pnp_dma(dev,0);
 187                scc->conf.dma2      = pnp_dma(dev,1);
 188                scc->mpucnf.io_base = pnp_port_start(dev,1);
 189                return;
 190        }
 191        if(!strncmp("tBA",scc->card_id,3)) {
 192                scc->conf.io_base   = pnp_port_start(dev,0);
 193                scc->conf.irq       = pnp_irq(dev,0);
 194                scc->conf.dma       = pnp_dma(dev,0);
 195                scc->conf.dma2      = pnp_dma(dev,1);
 196                return;
 197        }
 198        if(!strncmp("ESS",scc->card_id,3)) {
 199                scc->conf.io_base   = pnp_port_start(dev,0);
 200                scc->conf.irq       = pnp_irq(dev,0);
 201                scc->conf.dma       = pnp_dma(dev,0);
 202                scc->conf.dma2      = pnp_dma(dev,1);
 203                scc->mpucnf.io_base = pnp_port_start(dev,2);
 204                return;
 205        }
 206        if(!strncmp("CMI",scc->card_id,3)) {
 207                scc->conf.io_base = pnp_port_start(dev,0);
 208                scc->conf.irq     = pnp_irq(dev,0);
 209                scc->conf.dma     = pnp_dma(dev,0);
 210                scc->conf.dma2    = pnp_dma(dev,1);
 211                return;
 212        }
 213        if(!strncmp("RWB",scc->card_id,3)) {
 214                scc->conf.io_base = pnp_port_start(dev,0);
 215                scc->conf.irq     = pnp_irq(dev,0);
 216                scc->conf.dma     = pnp_dma(dev,0);
 217                return;
 218        }
 219        if(!strncmp("ALS",scc->card_id,3)) {
 220                if(!strncmp("ALS0007",scc->card_id,7)) {
 221                        scc->conf.io_base = pnp_port_start(dev,0);
 222                        scc->conf.irq     = pnp_irq(dev,0);
 223                        scc->conf.dma     = pnp_dma(dev,0);
 224                } else {
 225                        scc->conf.io_base = pnp_port_start(dev,0);
 226                        scc->conf.irq     = pnp_irq(dev,0);
 227                        scc->conf.dma     = pnp_dma(dev,1);
 228                        scc->conf.dma2    = pnp_dma(dev,0);
 229                }
 230                return;
 231        }
 232        if(!strncmp("RTL",scc->card_id,3)) {
 233                scc->conf.io_base = pnp_port_start(dev,0);
 234                scc->conf.irq     = pnp_irq(dev,0);
 235                scc->conf.dma     = pnp_dma(dev,1);
 236                scc->conf.dma2    = pnp_dma(dev,0);
 237        }
 238}
 239
 240/* Probe callback function for the PnP API */
 241static int sb_pnp_probe(struct pnp_card_link *card, const struct pnp_card_device_id *card_id)
 242{
 243        struct sb_card_config *scc;
 244        struct sb_module_options sbmo = {0}; /* Default to 0 for PnP */
 245        struct pnp_dev *dev = pnp_request_card_device(card, card_id->devs[0].id, NULL);
 246        
 247        if(!dev){
 248                return -EBUSY;
 249        }
 250
 251        if((scc = kmalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
 252                printk(KERN_ERR "sb: Error: Could not allocate memory\n");
 253                return -ENOMEM;
 254        }
 255        memset(scc, 0, sizeof(struct sb_card_config));
 256
 257        printk(KERN_INFO "sb: PnP: Found Card Named = \"%s\", Card PnP id = " \
 258               "%s, Device PnP id = %s\n", card->card->name, card_id->id,
 259               dev->id->id);
 260
 261        scc->card_id = card_id->id;
 262        scc->dev_id = dev->id->id;
 263        sb_dev2cfg(dev, scc);
 264
 265        printk(KERN_INFO "sb: PnP:      Detected at: io=0x%x, irq=%d, " \
 266               "dma=%d, dma16=%d\n", scc->conf.io_base, scc->conf.irq,
 267               scc->conf.dma, scc->conf.dma2);
 268
 269        pnp_set_card_drvdata(card, scc);
 270
 271        return sb_register_oss(scc, &sbmo);
 272}
 273
 274static void sb_pnp_remove(struct pnp_card_link *card)
 275{
 276        struct sb_card_config *scc = pnp_get_card_drvdata(card);
 277
 278        if(!scc)
 279                return;
 280
 281        printk(KERN_INFO "sb: PnP: Removing %s\n", scc->card_id);
 282
 283        sb_unload(scc);
 284}
 285
 286static struct pnp_card_driver sb_pnp_driver = {
 287        .name          = "OSS SndBlstr", /* 16 character limit */
 288        .id_table      = sb_pnp_card_table,
 289        .probe         = sb_pnp_probe,
 290        .remove        = sb_pnp_remove,
 291};
 292#endif /* CONFIG_PNP */
 293
 294static int __init sb_init(void)
 295{
 296        int lres = 0;
 297        int pres = 0;
 298
 299        printk(KERN_INFO "sb: Init: Starting Probe...\n");
 300
 301        if(io != -1 && irq != -1 && dma != -1) {
 302                printk(KERN_INFO "sb: Probing legacy card with io=%x, "\
 303                       "irq=%d, dma=%d, dma16=%d\n",io, irq, dma, dma16);
 304                lres = sb_init_legacy();
 305        } else if((io != -1 || irq != -1 || dma != -1) ||
 306                  (!pnp && (io == -1 && irq == -1 && dma == -1)))
 307                printk(KERN_ERR "sb: Error: At least io, irq, and dma "\
 308                       "must be set for legacy cards.\n");
 309
 310#ifdef CONFIG_PNP
 311        if(pnp) {
 312                pres = pnp_register_card_driver(&sb_pnp_driver);
 313        }
 314#endif
 315        printk(KERN_INFO "sb: Init: Done\n");
 316
 317        /* If either PnP or Legacy registered a card then return
 318         * success */
 319        if (pres <= 0 && lres <= 0) {
 320#ifdef CONFIG_PNP
 321                pnp_unregister_card_driver(&sb_pnp_driver);
 322#endif
 323                return -ENODEV;
 324        }
 325        return 0;
 326}
 327
 328static void __exit sb_exit(void)
 329{
 330        printk(KERN_INFO "sb: Unloading...\n");
 331
 332        /* Unload legacy card */
 333        if (legacy) {
 334                printk (KERN_INFO "sb: Unloading legacy card\n");
 335                sb_unload(legacy);
 336        }
 337
 338#ifdef CONFIG_PNP
 339        pnp_unregister_card_driver(&sb_pnp_driver);
 340#endif
 341
 342        if (smw_free) {
 343                vfree(smw_free);
 344                smw_free = NULL;
 345        }
 346}
 347
 348module_init(sb_init);
 349module_exit(sb_exit);
 350
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.