Commit 74e89507 authored by Jaroslav Kysela's avatar Jaroslav Kysela

[ALSA] Clean up power-management

Documentation,SA11xx UDA1341 driver,Control Midlevel,ALSA Core
ES18xx driver,OPL3SA2 driver,AD1848 driver,CS4231 driver,ATIIXP driver
ATIIXP-modem driver,CS4281 driver,ES1938 driver,ES1968 driver
Intel8x0 driver,Intel8x0-modem driver,Maestro3 driver,VIA82xx driver
VIA82xx-modem driver,ALI5451 driver,CS46xx driver,NM256 driver
Trident driver,YMFPCI driver,Sound Core PDAudioCF driver
PPC PMAC driver
Clean up for PM code.
snd_power_change() is called in the common routines instead of driver's callback.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent c35adcff
......@@ -5153,7 +5153,7 @@ struct _snd_pcm_runtime {
<listitem><para>Call <function>snd_pcm_suspend_all()</function> to suspend the running PCM streams.</para></listitem>
<listitem><para>Save the register values if necessary.</para></listitem>
<listitem><para>Stop the hardware if necessary.</para></listitem>
<listitem><para>Set the power-state as D3hot by calling <function>snd_power_change_state()</function>.</para></listitem>
<listitem><para>Disable the PCI device by calling <function>pci_disable_device()</function>.</para></listitem>
</orderedlist>
</para>
......@@ -5174,7 +5174,7 @@ struct _snd_pcm_runtime {
/* (4) */
snd_mychip_stop_hardware(chip);
/* (5) */
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
pci_disable_device(chip->pci);
return 0;
}
]]>
......@@ -5194,8 +5194,6 @@ struct _snd_pcm_runtime {
<listitem><para>Resume the mixer, e.g. calling
<function>snd_ac97_resume()</function>.</para></listitem>
<listitem><para>Restart the hardware (if any).</para></listitem>
<listitem><para>Set the power-state as D0 by calling
<function>snd_power_change_state()</function>.</para></listitem>
</orderedlist>
</para>
......@@ -5219,8 +5217,6 @@ struct _snd_pcm_runtime {
snd_ac97_resume(chip->ac97);
/* (6) */
snd_mychip_restart_chip(chip);
/* (7) */
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
]]>
......
......@@ -21,7 +21,7 @@
* merged HAL layer (patches from Brian)
*/
/* $Id: sa11xx-uda1341.c,v 1.18 2004/07/20 15:54:09 cladisch Exp $ */
/* $Id: sa11xx-uda1341.c,v 1.19 2004/12/15 15:26:10 tiwai Exp $ */
/***************************************************************************************************
*
......@@ -875,7 +875,6 @@ static int snd_sa11xx_uda1341_suspend(snd_card_t *card, unsigned int state)
#endif
l3_command(chip->uda1341, CMD_SUSPEND, NULL);
sa11xx_uda1341_audio_shutdown(chip);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -891,7 +890,6 @@ static int snd_sa11xx_uda1341_resume(snd_card_t *card, unsigned int state)
#else
//FIXME
#endif
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* COMFIG_PM */
......
......@@ -1020,18 +1020,23 @@ static int snd_ctl_set_power_state(snd_card_t *card, unsigned int power_state)
{
switch (power_state) {
case SNDRV_CTL_POWER_D0:
case SNDRV_CTL_POWER_D1:
case SNDRV_CTL_POWER_D2:
if (card->power_state != power_state)
if (card->power_state != power_state) {
/* FIXME: pass the correct state value */
card->pm_resume(card, 0);
snd_power_change_state(card, power_state);
}
break;
case SNDRV_CTL_POWER_D3hot:
case SNDRV_CTL_POWER_D3cold:
if (card->power_state != power_state)
if (card->power_state != power_state) {
/* FIXME: pass the correct state value */
card->pm_suspend(card, 0);
snd_power_change_state(card, power_state);
}
break;
case SNDRV_CTL_POWER_D1:
case SNDRV_CTL_POWER_D2:
case SNDRV_CTL_POWER_D3cold:
/* not supported yet */
default:
return -EINVAL;
}
......
......@@ -741,12 +741,18 @@ static int snd_generic_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *
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;
}
return 0;
......@@ -789,6 +795,7 @@ int snd_card_pci_suspend(struct pci_dev *dev, u32 state)
/* FIXME: correct state value? */
err = card->pm_suspend(card, 0);
pci_save_state(dev);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return err;
}
......@@ -802,7 +809,9 @@ int snd_card_pci_resume(struct pci_dev *dev)
/* restore the PCI config space */
pci_restore_state(dev);
/* FIXME: correct state value? */
return card->pm_resume(card, 0);
card->pm_resume(card, 0);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif
......
......@@ -648,16 +648,12 @@ static int snd_ad1848_suspend(snd_card_t *card, unsigned int state)
{
ad1848_t *chip = card->pm_private_data;
if (card->power_state == SNDRV_CTL_POWER_D3hot)
return 0;
snd_pcm_suspend_all(chip->pcm);
/* FIXME: save registers? */
if (chip->thinkpad_flag)
snd_ad1848_thinkpad_twiddle(chip, 0);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -665,15 +661,11 @@ static int snd_ad1848_resume(snd_card_t *card, unsigned int state)
{
ad1848_t *chip = card->pm_private_data;
if (card->power_state == SNDRV_CTL_POWER_D0)
return 0;
if (chip->thinkpad_flag)
snd_ad1848_thinkpad_twiddle(chip, 1);
/* FIXME: restore registers? */
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -1397,20 +1397,16 @@ static void snd_cs4231_resume(cs4231_t *chip)
static int snd_cs4231_pm_suspend(snd_card_t *card, unsigned int state)
{
cs4231_t *chip = card->pm_private_data;
if (chip->suspend) {
if (chip->suspend)
chip->suspend(chip);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
}
return 0;
}
static int snd_cs4231_pm_resume(snd_card_t *card, unsigned int state)
{
cs4231_t *chip = card->pm_private_data;
if (chip->resume) {
if (chip->resume)
chip->resume(chip);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
}
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -1624,7 +1624,6 @@ static int snd_es18xx_suspend(snd_card_t *card, unsigned int state)
snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg);
snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_SUS);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -1635,7 +1634,6 @@ static int snd_es18xx_resume(snd_card_t *card, unsigned int state)
/* restore PM register, we won't wake till (not 0x07) i/o activity though */
snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -539,7 +539,6 @@ static int snd_opl3sa2_suspend(snd_card_t *card, unsigned int state)
/* power down */
snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D3);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -563,7 +562,6 @@ static int snd_opl3sa2_resume(snd_card_t *card, unsigned int state)
/* restore cs4231 */
chip->cs4231_resume(chip->cs4231);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -1933,7 +1933,6 @@ static int ali_suspend(snd_card_t *card, unsigned int state)
spin_unlock_irq(&chip->reg_lock);
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -1971,7 +1970,6 @@ static int ali_resume(snd_card_t *card, unsigned int state)
spin_unlock_irq(&chip->reg_lock);
snd_ac97_resume(chip->ac97);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
......
......@@ -1409,7 +1409,6 @@ static int snd_atiixp_suspend(snd_card_t *card, unsigned int state)
pci_set_power_state(chip->pci, 3);
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -1429,7 +1428,6 @@ static int snd_atiixp_resume(snd_card_t *card, unsigned int state)
if (chip->ac97[i])
snd_ac97_resume(chip->ac97[i]);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -1131,7 +1131,6 @@ static int snd_atiixp_suspend(snd_card_t *card, unsigned int state)
pci_set_power_state(chip->pci, 3);
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -1151,7 +1150,6 @@ static int snd_atiixp_resume(snd_card_t *card, unsigned int state)
if (chip->ac97[i])
snd_ac97_resume(chip->ac97[i]);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -2079,7 +2079,6 @@ static int cs4281_suspend(snd_card_t *card, unsigned int state)
snd_cs4281_pokeBA0(chip, BA0_CLKCR1, ulCLK);
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -2112,7 +2111,6 @@ static int cs4281_resume(snd_card_t *card, unsigned int state)
ulCLK &= ~CLKCR1_CKRA;
snd_cs4281_pokeBA0(chip, BA0_CLKCR1, ulCLK);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -3725,7 +3725,6 @@ static int snd_cs46xx_suspend(snd_card_t *card, unsigned int state)
chip->active_ctrl(chip, -chip->amplifier);
chip->amplifier = amp_saved; /* restore the status */
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -3762,7 +3761,6 @@ static int snd_cs46xx_resume(snd_card_t *card, unsigned int state)
else
chip->active_ctrl(chip, -1); /* disable CLKRUN */
chip->amplifier = amp_saved;
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -1395,7 +1395,6 @@ static int es1938_suspend(snd_card_t *card, unsigned int state)
outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -1415,7 +1414,6 @@ static int es1938_resume(snd_card_t *card, unsigned int state)
snd_es1938_write(chip, *s, *d);
}
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -2415,7 +2415,6 @@ static int es1968_suspend(snd_card_t *card, unsigned int state)
snd_es1968_bob_stop(chip);
snd_es1968_set_acpi(chip, ACPI_D3);
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -2446,7 +2445,6 @@ static int es1968_resume(snd_card_t *card, unsigned int state)
if (chip->bobclient)
snd_es1968_bob_start(chip);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -2314,7 +2314,6 @@ static int intel8x0_suspend(snd_card_t *card, unsigned int state)
if (chip->ac97[i])
snd_ac97_suspend(chip->ac97[i]);
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -2347,7 +2346,6 @@ static int intel8x0_resume(snd_card_t *card, unsigned int state)
}
}
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -1093,7 +1093,6 @@ static int intel8x0m_suspend(snd_card_t *card, unsigned int state)
if (chip->ac97)
snd_ac97_suspend(chip->ac97);
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -1106,7 +1105,6 @@ static int intel8x0m_resume(snd_card_t *card, unsigned int state)
if (chip->ac97)
snd_ac97_resume(chip->ac97);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -2424,7 +2424,6 @@ static int m3_suspend(snd_card_t *card, unsigned int state)
snd_m3_outw(chip, 0xffff, 0x56);
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -2467,7 +2466,6 @@ static int m3_resume(snd_card_t *card, unsigned int state)
snd_m3_enable_ints(chip);
snd_m3_amp_enable(chip, 1);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -1275,7 +1275,6 @@ static int nm256_suspend(snd_card_t *card, unsigned int state)
snd_ac97_suspend(chip->ac97);
chip->coeffs_current = 0;
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -1290,7 +1289,6 @@ static int nm256_resume(snd_card_t *card, unsigned int state)
/* restore ac97 */
snd_ac97_resume(chip->ac97);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -3946,7 +3946,6 @@ static int snd_trident_suspend(snd_card_t *card, unsigned int state)
break;
}
pci_disable_device(trident->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -3981,7 +3980,6 @@ static int snd_trident_resume(snd_card_t *card, unsigned int state)
snd_trident_enable_eso(trident);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
trident->in_suspend = 0;
return 0;
}
......
......@@ -332,6 +332,7 @@ struct via_dev {
struct snd_via_sg_table *idx_table;
/* for recovery from the unexpected pointer */
unsigned int lastpos;
unsigned int fragsize;
unsigned int bufsize;
unsigned int bufsize2;
};
......@@ -478,6 +479,7 @@ static int build_via_table(viadev_t *dev, snd_pcm_substream_t *substream,
dev->tbl_entries = idx;
dev->bufsize = periods * fragsize;
dev->bufsize2 = dev->bufsize / 2;
dev->fragsize = fragsize;
return 0;
}
......@@ -706,29 +708,34 @@ static int snd_via82xx_pcm_trigger(snd_pcm_substream_t * substream, int cmd)
static inline unsigned int calc_linear_pos(viadev_t *viadev, unsigned int idx, unsigned int count)
{
unsigned int size, res;
unsigned int size, base, res;
size = viadev->idx_table[idx].size;
res = viadev->idx_table[idx].offset + size - count;
base = viadev->idx_table[idx].offset;
res = base + size - count;
/* check the validity of the calculated position */
if (size < count) {
snd_printd(KERN_ERR "invalid via82xx_cur_ptr (size = %d, count = %d)\n", (int)size, (int)count);
res = viadev->lastpos;
} else if (check_invalid_pos(viadev, res)) {
} else {
if (! count) {
/* Some mobos report count = 0 on the DMA boundary,
* i.e. count = size indeed.
* Let's check whether this step is above the expected size.
*/
int delta = res - viadev->lastpos;
if (delta < 0)
delta += viadev->bufsize;
if ((unsigned int)delta > viadev->fragsize)
res = base;
}
if (check_invalid_pos(viadev, res)) {
#ifdef POINTER_DEBUG
printk("fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n", idx, viadev->tbl_entries, viadev->lastpos, viadev->bufsize2, viadev->idx_table[idx].offset, viadev->idx_table[idx].size, count);
printk(KERN_DEBUG "fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n", idx, viadev->tbl_entries, viadev->lastpos, viadev->bufsize2, viadev->idx_table[idx].offset, viadev->idx_table[idx].size, count);
#endif
if (count && size < count) {
snd_printd(KERN_ERR "invalid via82xx_cur_ptr, using last valid pointer\n");
res = viadev->lastpos;
} else {
if (! count)
/* bogus count 0 on the DMA boundary? */
res = viadev->idx_table[idx].offset;
else
/* count register returns full size when end of buffer is reached */
res = viadev->idx_table[idx].offset + size;
/* count register returns full size when end of buffer is reached */
res = base + size;
if (check_invalid_pos(viadev, res)) {
snd_printd(KERN_ERR "invalid via82xx_cur_ptr (2), using last valid pointer\n");
res = viadev->lastpos;
......@@ -778,12 +785,20 @@ static snd_pcm_uframes_t snd_via8233_pcm_pointer(snd_pcm_substream_t *substream)
via82xx_t *chip = snd_pcm_substream_chip(substream);
viadev_t *viadev = (viadev_t *)substream->runtime->private_data;
unsigned int idx, count, res;
int timeout = 5000;
snd_assert(viadev->tbl_entries, return 0);
if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE))
return 0;
spin_lock(&chip->reg_lock);
count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT));
do {
count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT));
/* some mobos read 0 count */
if ((count & 0xffffff) || ! viadev->running)
break;
} while (--timeout);
if (! timeout)
snd_printd(KERN_ERR "zero position is read\n");
idx = count >> 24;
if (idx >= viadev->tbl_entries) {
#ifdef POINTER_DEBUG
......@@ -1908,7 +1923,6 @@ static int snd_via82xx_suspend(snd_card_t *card, unsigned int state)
pci_set_power_state(chip->pci, 3);
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -1943,7 +1957,6 @@ static int snd_via82xx_resume(snd_card_t *card, unsigned int state)
for (i = 0; i < chip->num_devs; i++)
snd_via82xx_channel_reset(chip, &chip->devs[i]);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -1054,7 +1054,6 @@ static int snd_via82xx_suspend(snd_card_t *card, unsigned int state)
snd_ac97_suspend(chip->ac97);
pci_set_power_state(chip->pci, 3);
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -1074,7 +1073,6 @@ static int snd_via82xx_resume(snd_card_t *card, unsigned int state)
for (i = 0; i < chip->num_devs; i++)
snd_via82xx_channel_reset(chip, &chip->devs[i]);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -2153,7 +2153,6 @@ static int snd_ymfpci_suspend(snd_card_t *card, unsigned int state)
snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0);
snd_ymfpci_disable_dsp(chip);
pci_disable_device(chip->pci);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -2181,7 +2180,6 @@ static int snd_ymfpci_resume(snd_card_t *card, unsigned int state)
chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT);
spin_unlock_irq(&chip->reg_lock);
}
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif /* CONFIG_PM */
......
......@@ -267,7 +267,6 @@ int snd_pdacf_suspend(snd_card_t *card, unsigned int state)
outw(val, chip->port + PDAUDIOCF_REG_IER);
chip->chip_status |= PDAUDIOCF_STAT_IS_SUSPENDED; /* ignore interrupts from now */
snd_pdacf_powerdown(chip);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -287,7 +286,6 @@ int snd_pdacf_resume(snd_card_t *card, unsigned int state)
(snd_ak4117_external_rate(chip->ak4117) <= 0 || !check_signal(chip)))
mdelay(1);
chip->chip_status &= ~PDAUDIOCF_STAT_IS_SUSPENDED;
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif
......@@ -1248,7 +1248,6 @@ static int snd_pmac_suspend(snd_card_t *card, unsigned int state)
if (chip->rx_irq >= 0)
disable_irq(chip->rx_irq);
snd_pmac_sound_feature(chip, 0);
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
......@@ -1275,7 +1274,6 @@ static int snd_pmac_resume(snd_card_t *card, unsigned int state)
if (chip->rx_irq >= 0)
enable_irq(chip->rx_irq);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
......
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