2019-05-27 14:55:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Driver for Sound Core PDAudioCF soundcard
|
|
|
|
*
|
2007-10-15 15:50:19 +08:00
|
|
|
* Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <linux/slab.h>
|
2011-07-16 01:13:37 +08:00
|
|
|
#include <linux/module.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <pcmcia/ciscode.h>
|
|
|
|
#include <pcmcia/cisreg.h>
|
|
|
|
#include "pdaudiocf.h"
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CARD_NAME "PDAudio-CF"
|
|
|
|
|
2007-10-15 15:50:19 +08:00
|
|
|
MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
|
2005-04-17 06:20:36 +08:00
|
|
|
MODULE_DESCRIPTION("Sound Core " CARD_NAME);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_SUPPORTED_DEVICE("{{Sound Core," CARD_NAME "}}");
|
|
|
|
|
|
|
|
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
|
|
|
|
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
|
2011-12-15 11:19:36 +08:00
|
|
|
static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
module_param_array(index, int, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
|
|
|
|
module_param_array(id, charp, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
|
|
|
|
module_param_array(enable, bool, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard.");
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
2005-11-17 22:07:38 +08:00
|
|
|
static struct snd_card *card_list[SNDRV_CARDS];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes
|
|
|
|
*/
|
2006-03-31 23:26:06 +08:00
|
|
|
static int pdacf_config(struct pcmcia_device *link);
|
2006-01-06 07:27:16 +08:00
|
|
|
static void snd_pdacf_detach(struct pcmcia_device *p_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
static void pdacf_release(struct pcmcia_device *link)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-09-10 20:58:59 +08:00
|
|
|
free_irq(link->irq, link->priv);
|
2006-03-31 23:21:06 +08:00
|
|
|
pcmcia_disable_device(link);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* destructor
|
|
|
|
*/
|
2005-11-17 22:07:38 +08:00
|
|
|
static int snd_pdacf_free(struct snd_pdacf *pdacf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-03-31 23:21:06 +08:00
|
|
|
struct pcmcia_device *link = pdacf->p_dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
pdacf_release(link);
|
|
|
|
|
|
|
|
card_list[pdacf->index] = NULL;
|
|
|
|
pdacf->card = NULL;
|
|
|
|
|
|
|
|
kfree(pdacf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 22:07:38 +08:00
|
|
|
static int snd_pdacf_dev_free(struct snd_device *device)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:07:38 +08:00
|
|
|
struct snd_pdacf *chip = device->device_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
return snd_pdacf_free(chip);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* snd_pdacf_attach - attach callback for cs
|
|
|
|
*/
|
2006-03-31 23:26:06 +08:00
|
|
|
static int snd_pdacf_probe(struct pcmcia_device *link)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-12-28 23:45:02 +08:00
|
|
|
int i, err;
|
2005-11-17 22:07:38 +08:00
|
|
|
struct snd_pdacf *pdacf;
|
|
|
|
struct snd_card *card;
|
|
|
|
static struct snd_device_ops ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.dev_free = snd_pdacf_dev_free,
|
|
|
|
};
|
|
|
|
|
|
|
|
snd_printdd(KERN_DEBUG "pdacf_attach called\n");
|
|
|
|
/* find an empty slot from the card list */
|
|
|
|
for (i = 0; i < SNDRV_CARDS; i++) {
|
|
|
|
if (! card_list[i])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= SNDRV_CARDS) {
|
|
|
|
snd_printk(KERN_ERR "pdacf: too many cards found\n");
|
2006-01-06 07:27:16 +08:00
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (! enable[i])
|
2006-01-06 07:27:16 +08:00
|
|
|
return -ENODEV; /* disabled explicitly */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* ok, create a card instance */
|
2014-01-29 21:37:20 +08:00
|
|
|
err = snd_card_new(&link->dev, index[i], id[i], THIS_MODULE,
|
|
|
|
0, &card);
|
2008-12-28 23:45:02 +08:00
|
|
|
if (err < 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_printk(KERN_ERR "pdacf: cannot create a card instance\n");
|
2008-12-28 23:45:02 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pdacf = snd_pdacf_create(card);
|
2008-12-28 23:59:41 +08:00
|
|
|
if (!pdacf) {
|
|
|
|
snd_card_free(card);
|
2008-12-29 00:03:56 +08:00
|
|
|
return -ENOMEM;
|
2008-12-28 23:59:41 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-12-29 00:03:56 +08:00
|
|
|
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, pdacf, &ops);
|
|
|
|
if (err < 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(pdacf);
|
|
|
|
snd_card_free(card);
|
2008-12-29 00:03:56 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pdacf->index = i;
|
|
|
|
card_list[i] = card;
|
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
pdacf->p_dev = link;
|
2005-04-17 06:20:36 +08:00
|
|
|
link->priv = pdacf;
|
|
|
|
|
2010-07-24 23:23:51 +08:00
|
|
|
link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
|
|
|
|
link->resource[0]->end = 16;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-30 01:27:09 +08:00
|
|
|
link->config_flags = CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ;
|
2010-07-30 00:35:47 +08:00
|
|
|
link->config_index = 1;
|
|
|
|
link->config_regs = PRESENT_OPTION;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-31 23:26:06 +08:00
|
|
|
return pdacf_config(link);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_pdacf_assign_resources - initialize the hardware and card instance.
|
|
|
|
* @port: i/o port for the card
|
|
|
|
* @irq: irq number for the card
|
|
|
|
*
|
|
|
|
* this function assigns the specified port and irq, boot the card,
|
|
|
|
* create pcm and control instances, and initialize the rest hardware.
|
|
|
|
*
|
|
|
|
* returns 0 if successful, or a negative error code.
|
|
|
|
*/
|
2005-11-17 22:07:38 +08:00
|
|
|
static int snd_pdacf_assign_resources(struct snd_pdacf *pdacf, int port, int irq)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err;
|
2005-11-17 22:07:38 +08:00
|
|
|
struct snd_card *card = pdacf->card;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
snd_printdd(KERN_DEBUG "pdacf assign resources: port = 0x%x, irq = %d\n", port, irq);
|
|
|
|
pdacf->port = port;
|
|
|
|
pdacf->irq = irq;
|
|
|
|
pdacf->chip_status |= PDAUDIOCF_STAT_IS_CONFIGURED;
|
|
|
|
|
|
|
|
err = snd_pdacf_ak4117_create(pdacf);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
strcpy(card->driver, "PDAudio-CF");
|
|
|
|
sprintf(card->shortname, "Core Sound %s", card->driver);
|
|
|
|
sprintf(card->longname, "%s at 0x%x, irq %i",
|
|
|
|
card->shortname, port, irq);
|
|
|
|
|
|
|
|
err = snd_pdacf_pcm_new(pdacf);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if ((err = snd_card_register(card)) < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* snd_pdacf_detach - detach callback for cs
|
|
|
|
*/
|
2006-03-31 23:21:06 +08:00
|
|
|
static void snd_pdacf_detach(struct pcmcia_device *link)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:07:38 +08:00
|
|
|
struct snd_pdacf *chip = link->priv;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
snd_printdd(KERN_DEBUG "pdacf_detach called\n");
|
2006-01-06 07:27:16 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (chip->chip_status & PDAUDIOCF_STAT_IS_CONFIGURED)
|
|
|
|
snd_pdacf_powerdown(chip);
|
|
|
|
chip->chip_status |= PDAUDIOCF_STAT_IS_STALE; /* to be sure */
|
|
|
|
snd_card_disconnect(chip->card);
|
2006-06-23 20:38:26 +08:00
|
|
|
snd_card_free_when_closed(chip->card);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* configuration callback
|
|
|
|
*/
|
|
|
|
|
2006-03-31 23:26:06 +08:00
|
|
|
static int pdacf_config(struct pcmcia_device *link)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:07:38 +08:00
|
|
|
struct snd_pdacf *pdacf = link->priv;
|
2009-10-24 21:55:12 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
snd_printdd(KERN_DEBUG "pdacf_config called\n");
|
2010-07-30 00:35:47 +08:00
|
|
|
link->config_index = 0x5;
|
2010-07-30 01:27:09 +08:00
|
|
|
link->config_flags |= CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-24 23:23:51 +08:00
|
|
|
ret = pcmcia_request_io(link);
|
2009-10-24 21:55:12 +08:00
|
|
|
if (ret)
|
2014-09-10 20:58:59 +08:00
|
|
|
goto failed_preirq;
|
2009-10-24 21:55:12 +08:00
|
|
|
|
2014-09-10 20:58:59 +08:00
|
|
|
ret = request_threaded_irq(link->irq, pdacf_interrupt,
|
|
|
|
pdacf_threaded_irq,
|
|
|
|
IRQF_SHARED, link->devname, link->priv);
|
2009-10-24 21:55:12 +08:00
|
|
|
if (ret)
|
2014-09-10 20:58:59 +08:00
|
|
|
goto failed_preirq;
|
2009-10-24 21:55:12 +08:00
|
|
|
|
2010-07-30 01:27:09 +08:00
|
|
|
ret = pcmcia_enable_device(link);
|
2009-10-24 21:55:12 +08:00
|
|
|
if (ret)
|
|
|
|
goto failed;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-07-24 21:58:54 +08:00
|
|
|
if (snd_pdacf_assign_resources(pdacf, link->resource[0]->start,
|
|
|
|
link->irq) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto failed;
|
|
|
|
|
2006-03-31 23:26:06 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-09-10 20:58:59 +08:00
|
|
|
failed:
|
|
|
|
free_irq(link->irq, link->priv);
|
|
|
|
failed_preirq:
|
2006-03-31 23:21:06 +08:00
|
|
|
pcmcia_disable_device(link);
|
2006-03-31 23:26:06 +08:00
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-01-06 07:27:16 +08:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
static int pdacf_suspend(struct pcmcia_device *link)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 22:07:38 +08:00
|
|
|
struct snd_pdacf *chip = link->priv;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-06 07:27:16 +08:00
|
|
|
snd_printdd(KERN_DEBUG "SUSPEND\n");
|
|
|
|
if (chip) {
|
|
|
|
snd_printdd(KERN_DEBUG "snd_pdacf_suspend calling\n");
|
2012-07-02 21:42:33 +08:00
|
|
|
snd_pdacf_suspend(chip);
|
2006-01-06 07:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
static int pdacf_resume(struct pcmcia_device *link)
|
2006-01-06 07:27:16 +08:00
|
|
|
{
|
|
|
|
struct snd_pdacf *chip = link->priv;
|
|
|
|
|
|
|
|
snd_printdd(KERN_DEBUG "RESUME\n");
|
2006-03-05 18:04:33 +08:00
|
|
|
if (pcmcia_dev_present(link)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (chip) {
|
2006-01-06 07:27:16 +08:00
|
|
|
snd_printdd(KERN_DEBUG "calling snd_pdacf_resume\n");
|
|
|
|
snd_pdacf_resume(chip);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2006-01-06 07:27:16 +08:00
|
|
|
snd_printdd(KERN_DEBUG "resume done!\n");
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-06 07:27:16 +08:00
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Module entry points
|
|
|
|
*/
|
2011-05-07 02:04:55 +08:00
|
|
|
static const struct pcmcia_device_id snd_pdacf_ids[] = {
|
2006-11-29 16:54:51 +08:00
|
|
|
/* this is too general PCMCIA_DEVICE_MANF_CARD(0x015d, 0x4c45), */
|
|
|
|
PCMCIA_DEVICE_PROD_ID12("Core Sound","PDAudio-CF",0x396d19d2,0x71717b49),
|
2005-06-28 07:28:42 +08:00
|
|
|
PCMCIA_DEVICE_NULL
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pcmcia, snd_pdacf_ids);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct pcmcia_driver pdacf_cs_driver = {
|
2005-07-08 08:59:00 +08:00
|
|
|
.owner = THIS_MODULE,
|
2010-08-08 17:36:26 +08:00
|
|
|
.name = "snd-pdaudiocf",
|
2006-03-31 23:26:06 +08:00
|
|
|
.probe = snd_pdacf_probe,
|
2006-01-06 07:27:16 +08:00
|
|
|
.remove = snd_pdacf_detach,
|
2005-06-28 07:28:42 +08:00
|
|
|
.id_table = snd_pdacf_ids,
|
2006-01-06 07:27:16 +08:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.suspend = pdacf_suspend,
|
|
|
|
.resume = pdacf_resume,
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
2013-03-07 02:29:42 +08:00
|
|
|
module_pcmcia_driver(pdacf_cs_driver);
|