Commit efac16ca authored by Jaroslav Kysela's avatar Jaroslav Kysela

[ALSA] Remove pm_register/pm_unregister

SA11xx UDA1341 driver,ALSA Core,ISA
Removed pm_register() and pm_unregister().
Use platform_device for suspend/resume, instead.

The current implemention is still a hack.  The whole ISA drivers should
be rewritten with a proper bus definition.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 41a3b69f
......@@ -169,11 +169,13 @@ struct _snd_card {
#ifdef CONFIG_PM
int (*pm_suspend)(snd_card_t *card, unsigned int state);
int (*pm_resume)(snd_card_t *card, unsigned int state);
struct pm_dev *pm_dev; /* for ISA */
void *pm_private_data;
unsigned int power_state; /* power state */
struct semaphore power_lock; /* power lock */
wait_queue_head_t power_sleep;
#ifdef CONFIG_SND_GENERIC_PM
struct snd_generic_device *pm_dev; /* for ISA */
#endif
#endif
#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
......@@ -209,33 +211,31 @@ int snd_card_set_pm_callback(snd_card_t *card,
int (*suspend)(snd_card_t *, unsigned int),
int (*resume)(snd_card_t *, unsigned int),
void *private_data);
int snd_card_set_dev_pm_callback(snd_card_t *card, int type,
int (*suspend)(snd_card_t *, unsigned int),
int (*resume)(snd_card_t *, unsigned int),
void *private_data);
int snd_card_set_generic_pm_callback(snd_card_t *card,
int (*suspend)(snd_card_t *, unsigned int),
int (*resume)(snd_card_t *, unsigned int),
void *private_data);
#define snd_card_set_isa_pm_callback(card,suspend,resume,data) \
snd_card_set_dev_pm_callback(card, PM_ISA_DEV, suspend, resume, data)
#ifdef CONFIG_PCI
#ifndef SND_PCI_PM_CALLBACKS
snd_card_set_generic_pm_callback(card, suspend, resume, data)
struct pci_dev;
int snd_card_pci_suspend(struct pci_dev *dev, u32 state);
int snd_card_pci_resume(struct pci_dev *dev);
#define SND_PCI_PM_CALLBACKS \
.suspend = snd_card_pci_suspend, .resume = snd_card_pci_resume
#endif
#endif
#else
#else /* ! CONFIG_PM */
#define snd_power_lock(card) do { (void)(card); } while (0)
#define snd_power_unlock(card) do { (void)(card); } while (0)
static inline int snd_power_wait(snd_card_t *card, unsigned int state, struct file *file) { return 0; }
#define snd_power_get_state(card) SNDRV_CTL_POWER_D0
#define snd_power_change_state(card, state) do { (void)(card); } while (0)
#define snd_card_set_pm_callback(card,suspend,resume,data)
#define snd_card_set_dev_pm_callback(card,suspend,resume,data)
#define snd_card_set_generic_pm_callback(card,suspend,resume,data)
#define snd_card_set_isa_pm_callback(card,suspend,resume,data)
#ifdef CONFIG_PCI
#define SND_PCI_PM_CALLBACKS
#endif
#endif
#endif /* CONFIG_PM */
/* device.c */
......
......@@ -21,7 +21,7 @@
* merged HAL layer (patches from Brian)
*/
/* $Id: sa11xx-uda1341.c,v 1.19 2004/12/15 15:26:10 tiwai Exp $ */
/* $Id: sa11xx-uda1341.c,v 1.20 2005/01/28 14:49:59 tiwai Exp $ */
/***************************************************************************************************
*
......@@ -938,7 +938,7 @@ static int __init sa11xx_uda1341_init(void)
if ((err = snd_card_sa11xx_uda1341_pcm(sa11xx_uda1341, 0)) < 0)
goto nodev;
snd_card_set_dev_pm_callback(card, PM_SYS_DEV,
snd_card_set_generic_pm_callback(card,
snd_sa11xx_uda1341_suspend, snd_sa11_uda1341_resume,
sa11xx_uda1341);
......
......@@ -123,3 +123,5 @@ config SND_DEBUG_DETECT
Say Y here to enable extra-verbose log messages printed when
detecting devices.
config SND_GENERIC_PM
bool
......@@ -229,6 +229,10 @@ int snd_card_disconnect(snd_card_t * card)
return 0;
}
#if defined(CONFIG_PM) && defined(CONFIG_SND_GENERIC_PM)
static void snd_generic_device_unregister(struct snd_generic_device *dev);
#endif
/**
* snd_card_free - frees given soundcard structure
* @card: soundcard structure
......@@ -252,9 +256,9 @@ int snd_card_free(snd_card_t * card)
#ifdef CONFIG_PM
wake_up(&card->power_sleep);
#ifdef CONFIG_ISA
#ifdef CONFIG_SND_GENERIC_PM
if (card->pm_dev) {
pm_unregister(card->pm_dev);
snd_generic_device_unregister(card->pm_dev);
card->pm_dev = NULL;
}
#endif
......@@ -729,53 +733,131 @@ int snd_card_set_pm_callback(snd_card_t *card,
return 0;
}
static int snd_generic_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
#ifdef CONFIG_SND_GENERIC_PM
/*
* use platform_device for generic power-management without a proper bus
* (e.g. ISA)
*/
struct snd_generic_device {
struct platform_device pdev;
snd_card_t *card;
};
#define get_snd_generic_card(dev) container_of(to_platform_device(dev), struct snd_generic_device, pdev)->card
#define SND_GENERIC_NAME "snd_generic_pm"
static int snd_generic_suspend(struct device *dev, u32 state, u32 level);
static int snd_generic_resume(struct device *dev, u32 level);
static struct device_driver snd_generic_driver = {
.name = SND_GENERIC_NAME,
.bus = &platform_bus_type,
.suspend = snd_generic_suspend,
.resume = snd_generic_resume,
};
static int generic_driver_registered;
static void generic_driver_unregister(void)
{
if (generic_driver_registered) {
generic_driver_registered--;
if (! generic_driver_registered)
driver_unregister(&snd_generic_driver);
}
}
static struct snd_generic_device *snd_generic_device_register(snd_card_t *card)
{
snd_card_t *card = dev->data;
struct snd_generic_device *dev;
switch (rqst) {
case PM_SUSPEND:
if (card->power_state == SNDRV_CTL_POWER_D3hot)
break;
/* FIXME: the correct state value? */
card->pm_suspend(card, 0);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
break;
case PM_RESUME:
if (card->power_state == SNDRV_CTL_POWER_D0)
break;
/* FIXME: the correct state value? */
card->pm_resume(card, 0);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
break;
if (! generic_driver_registered) {
if (driver_register(&snd_generic_driver) < 0)
return NULL;
}
generic_driver_registered++;
dev = kcalloc(1, sizeof(*dev), GFP_KERNEL);
if (! dev) {
generic_driver_unregister();
return NULL;
}
dev->pdev.name = SND_GENERIC_NAME;
dev->pdev.id = card->number;
dev->card = card;
if (platform_device_register(&dev->pdev) < 0) {
kfree(dev);
generic_driver_unregister();
return NULL;
}
return dev;
}
static void snd_generic_device_unregister(struct snd_generic_device *dev)
{
platform_device_unregister(&dev->pdev);
kfree(dev);
generic_driver_unregister();
}
/* suspend/resume callbacks for snd_generic platform device */
static int snd_generic_suspend(struct device *dev, u32 state, u32 level)
{
snd_card_t *card;
if (level != SUSPEND_DISABLE)
return 0;
card = get_snd_generic_card(dev);
if (card->power_state == SNDRV_CTL_POWER_D3hot)
return 0;
/* FIXME: the correct state value? */
card->pm_suspend(card, 0);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
static int snd_generic_resume(struct device *dev, u32 level)
{
snd_card_t *card;
if (level != RESUME_ENABLE)
return 0;
card = get_snd_generic_card(dev);
if (card->power_state == SNDRV_CTL_POWER_D0)
return 0;
/* FIXME: the correct state value? */
card->pm_resume(card, 0);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
/**
* snd_card_set_dev_pm_callback - set the generic power-management callbacks
* snd_card_set_generic_pm_callback - set the generic power-management callbacks
* @card: soundcard structure
* @type: PM device type (PM_XXX)
* @suspend: suspend callback function
* @resume: resume callback function
* @private_data: private data to pass to the callback functions
*
* Registers the power-management and sets the lowlevel callbacks for
* the given card with the given PM type. These callbacks are called
* from the ALSA's common PM handler and from the control API.
* the given card. These callbacks are called from the ALSA's common
* PM handler and from the control API.
*/
int snd_card_set_dev_pm_callback(snd_card_t *card, int type,
int snd_card_set_generic_pm_callback(snd_card_t *card,
int (*suspend)(snd_card_t *, unsigned int),
int (*resume)(snd_card_t *, unsigned int),
void *private_data)
{
card->pm_dev = pm_register(type, 0, snd_generic_pm_callback);
card->pm_dev = snd_generic_device_register(card);
if (! card->pm_dev)
return -ENOMEM;
card->pm_dev->data = card;
snd_card_set_pm_callback(card, suspend, resume, private_data);
return 0;
}
#endif /* CONFIG_SND_GENERIC_PM */
#ifdef CONFIG_PCI
int snd_card_pci_suspend(struct pci_dev *dev, u32 state)
......
......@@ -420,7 +420,9 @@ EXPORT_SYMBOL(snd_card_file_remove);
#ifdef CONFIG_PM
EXPORT_SYMBOL(snd_power_wait);
EXPORT_SYMBOL(snd_card_set_pm_callback);
EXPORT_SYMBOL(snd_card_set_dev_pm_callback);
#if defined(CONFIG_PM) && defined(CONFIG_SND_GENERIC_PM)
EXPORT_SYMBOL(snd_card_set_generic_pm_callback);
#endif
#ifdef CONFIG_PCI
EXPORT_SYMBOL(snd_card_pci_suspend);
EXPORT_SYMBOL(snd_card_pci_resume);
......
......@@ -20,6 +20,7 @@ config SND_AD1848
tristate "Generic AD1848/CS4248 driver"
depends on SND
select SND_PCM
select SND_GENERIC_PM
help
Say Y here to include support for AD1848 (Analog Devices) or
CS4248 (Cirrus Logic - Crystal Semiconductors) chips.
......@@ -35,6 +36,7 @@ config SND_CS4231
depends on SND
select SND_MPU401_UART
select SND_PCM
select SND_GENERIC_PM
help
Say Y here to include support for CS4231 chips from Cirrus
Logic - Crystal Semiconductors.
......@@ -48,6 +50,7 @@ config SND_CS4232
select SND_OPL3_LIB
select SND_MPU401_UART
select SND_PCM
select SND_GENERIC_PM
help
Say Y here to include support for CS4232 chips from Cirrus
Logic - Crystal Semiconductors.
......@@ -61,6 +64,7 @@ config SND_CS4236
select SND_OPL3_LIB
select SND_MPU401_UART
select SND_PCM
select SND_GENERIC_PM
help
Say Y to include support for CS4235,CS4236,CS4237B,CS4238B,
CS4239 chips from Cirrus Logic - Crystal Semiconductors.
......@@ -98,6 +102,7 @@ config SND_ES18XX
select SND_OPL3_LIB
select SND_MPU401_UART
select SND_PCM
select SND_GENERIC_PM
help
Say Y here to include support for ESS AudioDrive ES18xx chips.
......@@ -332,6 +337,7 @@ config SND_OPL3SA2
select SND_OPL3_LIB
select SND_MPU401_UART
select SND_PCM
select SND_GENERIC_PM
help
Say Y here to include support for Yamaha OPL3-SA2 and OPL3-SA3
chips.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment