Path: blob/master/sound/pcmcia/pdaudiocf/pdaudiocf.c
10819 views
/*1* Driver for Sound Core PDAudioCF soundcard2*3* Copyright (c) 2003 by Jaroslav Kysela <[email protected]>4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*/1920#include <sound/core.h>21#include <linux/slab.h>22#include <linux/moduleparam.h>23#include <pcmcia/ciscode.h>24#include <pcmcia/cisreg.h>25#include "pdaudiocf.h"26#include <sound/initval.h>27#include <linux/init.h>2829/*30*/3132#define CARD_NAME "PDAudio-CF"3334MODULE_AUTHOR("Jaroslav Kysela <[email protected]>");35MODULE_DESCRIPTION("Sound Core " CARD_NAME);36MODULE_LICENSE("GPL");37MODULE_SUPPORTED_DEVICE("{{Sound Core," CARD_NAME "}}");3839static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */40static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */41static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */4243module_param_array(index, int, NULL, 0444);44MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");45module_param_array(id, charp, NULL, 0444);46MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");47module_param_array(enable, bool, NULL, 0444);48MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard.");4950/*51*/5253static struct snd_card *card_list[SNDRV_CARDS];5455/*56* prototypes57*/58static int pdacf_config(struct pcmcia_device *link);59static void snd_pdacf_detach(struct pcmcia_device *p_dev);6061static void pdacf_release(struct pcmcia_device *link)62{63pcmcia_disable_device(link);64}6566/*67* destructor68*/69static int snd_pdacf_free(struct snd_pdacf *pdacf)70{71struct pcmcia_device *link = pdacf->p_dev;7273pdacf_release(link);7475card_list[pdacf->index] = NULL;76pdacf->card = NULL;7778kfree(pdacf);79return 0;80}8182static int snd_pdacf_dev_free(struct snd_device *device)83{84struct snd_pdacf *chip = device->device_data;85return snd_pdacf_free(chip);86}8788/*89* snd_pdacf_attach - attach callback for cs90*/91static int snd_pdacf_probe(struct pcmcia_device *link)92{93int i, err;94struct snd_pdacf *pdacf;95struct snd_card *card;96static struct snd_device_ops ops = {97.dev_free = snd_pdacf_dev_free,98};99100snd_printdd(KERN_DEBUG "pdacf_attach called\n");101/* find an empty slot from the card list */102for (i = 0; i < SNDRV_CARDS; i++) {103if (! card_list[i])104break;105}106if (i >= SNDRV_CARDS) {107snd_printk(KERN_ERR "pdacf: too many cards found\n");108return -EINVAL;109}110if (! enable[i])111return -ENODEV; /* disabled explicitly */112113/* ok, create a card instance */114err = snd_card_create(index[i], id[i], THIS_MODULE, 0, &card);115if (err < 0) {116snd_printk(KERN_ERR "pdacf: cannot create a card instance\n");117return err;118}119120pdacf = snd_pdacf_create(card);121if (!pdacf) {122snd_card_free(card);123return -ENOMEM;124}125126err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, pdacf, &ops);127if (err < 0) {128kfree(pdacf);129snd_card_free(card);130return err;131}132133snd_card_set_dev(card, &link->dev);134135pdacf->index = i;136card_list[i] = card;137138pdacf->p_dev = link;139link->priv = pdacf;140141link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;142link->resource[0]->end = 16;143144link->config_flags = CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ;145link->config_index = 1;146link->config_regs = PRESENT_OPTION;147148return pdacf_config(link);149}150151152/**153* snd_pdacf_assign_resources - initialize the hardware and card instance.154* @port: i/o port for the card155* @irq: irq number for the card156*157* this function assigns the specified port and irq, boot the card,158* create pcm and control instances, and initialize the rest hardware.159*160* returns 0 if successful, or a negative error code.161*/162static int snd_pdacf_assign_resources(struct snd_pdacf *pdacf, int port, int irq)163{164int err;165struct snd_card *card = pdacf->card;166167snd_printdd(KERN_DEBUG "pdacf assign resources: port = 0x%x, irq = %d\n", port, irq);168pdacf->port = port;169pdacf->irq = irq;170pdacf->chip_status |= PDAUDIOCF_STAT_IS_CONFIGURED;171172err = snd_pdacf_ak4117_create(pdacf);173if (err < 0)174return err;175176strcpy(card->driver, "PDAudio-CF");177sprintf(card->shortname, "Core Sound %s", card->driver);178sprintf(card->longname, "%s at 0x%x, irq %i",179card->shortname, port, irq);180181err = snd_pdacf_pcm_new(pdacf);182if (err < 0)183return err;184185if ((err = snd_card_register(card)) < 0)186return err;187188return 0;189}190191192/*193* snd_pdacf_detach - detach callback for cs194*/195static void snd_pdacf_detach(struct pcmcia_device *link)196{197struct snd_pdacf *chip = link->priv;198199snd_printdd(KERN_DEBUG "pdacf_detach called\n");200201if (chip->chip_status & PDAUDIOCF_STAT_IS_CONFIGURED)202snd_pdacf_powerdown(chip);203chip->chip_status |= PDAUDIOCF_STAT_IS_STALE; /* to be sure */204snd_card_disconnect(chip->card);205snd_card_free_when_closed(chip->card);206}207208/*209* configuration callback210*/211212static int pdacf_config(struct pcmcia_device *link)213{214struct snd_pdacf *pdacf = link->priv;215int ret;216217snd_printdd(KERN_DEBUG "pdacf_config called\n");218link->config_index = 0x5;219link->config_flags |= CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ;220221ret = pcmcia_request_io(link);222if (ret)223goto failed;224225ret = pcmcia_request_exclusive_irq(link, pdacf_interrupt);226if (ret)227goto failed;228229ret = pcmcia_enable_device(link);230if (ret)231goto failed;232233if (snd_pdacf_assign_resources(pdacf, link->resource[0]->start,234link->irq) < 0)235goto failed;236237return 0;238239failed:240pcmcia_disable_device(link);241return -ENODEV;242}243244#ifdef CONFIG_PM245246static int pdacf_suspend(struct pcmcia_device *link)247{248struct snd_pdacf *chip = link->priv;249250snd_printdd(KERN_DEBUG "SUSPEND\n");251if (chip) {252snd_printdd(KERN_DEBUG "snd_pdacf_suspend calling\n");253snd_pdacf_suspend(chip, PMSG_SUSPEND);254}255256return 0;257}258259static int pdacf_resume(struct pcmcia_device *link)260{261struct snd_pdacf *chip = link->priv;262263snd_printdd(KERN_DEBUG "RESUME\n");264if (pcmcia_dev_present(link)) {265if (chip) {266snd_printdd(KERN_DEBUG "calling snd_pdacf_resume\n");267snd_pdacf_resume(chip);268}269}270snd_printdd(KERN_DEBUG "resume done!\n");271272return 0;273}274275#endif276277/*278* Module entry points279*/280static const struct pcmcia_device_id snd_pdacf_ids[] = {281/* this is too general PCMCIA_DEVICE_MANF_CARD(0x015d, 0x4c45), */282PCMCIA_DEVICE_PROD_ID12("Core Sound","PDAudio-CF",0x396d19d2,0x71717b49),283PCMCIA_DEVICE_NULL284};285MODULE_DEVICE_TABLE(pcmcia, snd_pdacf_ids);286287static struct pcmcia_driver pdacf_cs_driver = {288.owner = THIS_MODULE,289.name = "snd-pdaudiocf",290.probe = snd_pdacf_probe,291.remove = snd_pdacf_detach,292.id_table = snd_pdacf_ids,293#ifdef CONFIG_PM294.suspend = pdacf_suspend,295.resume = pdacf_resume,296#endif297298};299300static int __init init_pdacf(void)301{302return pcmcia_register_driver(&pdacf_cs_driver);303}304305static void __exit exit_pdacf(void)306{307pcmcia_unregister_driver(&pdacf_cs_driver);308}309310module_init(init_pdacf);311module_exit(exit_pdacf);312313314