Path: blob/master/sound/pci/cs5535audio/cs5535audio_pm.c
10817 views
/*1* Power management for audio on multifunction CS5535 companion device2* Copyright (C) Jaya Kumar3*4* This program is free software; you can redistribute it and/or modify5* it under the terms of the GNU General Public License as published by6* the Free Software Foundation; either version 2 of the License, or7* (at your option) any later version.8*9* This program is distributed in the hope that it will be useful,10* but WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12* GNU General Public License for more details.13*14* You should have received a copy of the GNU General Public License15* along with this program; if not, write to the Free Software16* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA17*18*/1920#include <linux/init.h>21#include <linux/pci.h>22#include <linux/delay.h>23#include <sound/core.h>24#include <sound/control.h>25#include <sound/initval.h>26#include <sound/asoundef.h>27#include <sound/pcm.h>28#include <sound/ac97_codec.h>29#include "cs5535audio.h"3031static void snd_cs5535audio_stop_hardware(struct cs5535audio *cs5535au)32{33/*34we depend on snd_ac97_suspend to tell the35AC97 codec to shutdown. the amd spec suggests36that the LNK_SHUTDOWN be done at the same time37that the codec power-down is issued. instead,38we do it just after rather than at the same39time. excluding codec specific build_ops->suspend40ac97 powerdown hits:410x8000 EAPD420x4000 Headphone amplifier430x0300 ADC & DAC440x0400 Analog Mixer powerdown (Vref on)45I am not sure if this is the best that we can do.46The remainder to be investigated are:47- analog mixer (vref off) 0x080048- AC-link powerdown 0x100049- codec internal clock 0x200050*/5152/* set LNK_SHUTDOWN to shutdown AC link */53cs_writel(cs5535au, ACC_CODEC_CNTL, ACC_CODEC_CNTL_LNK_SHUTDOWN);5455}5657int snd_cs5535audio_suspend(struct pci_dev *pci, pm_message_t state)58{59struct snd_card *card = pci_get_drvdata(pci);60struct cs5535audio *cs5535au = card->private_data;61int i;6263snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);64snd_pcm_suspend_all(cs5535au->pcm);65snd_ac97_suspend(cs5535au->ac97);66for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) {67struct cs5535audio_dma *dma = &cs5535au->dmas[i];68if (dma && dma->substream)69dma->saved_prd = dma->ops->read_prd(cs5535au);70}71/* save important regs, then disable aclink in hw */72snd_cs5535audio_stop_hardware(cs5535au);7374if (pci_save_state(pci)) {75printk(KERN_ERR "cs5535audio: pci_save_state failed!\n");76return -EIO;77}78pci_disable_device(pci);79pci_set_power_state(pci, pci_choose_state(pci, state));80return 0;81}8283int snd_cs5535audio_resume(struct pci_dev *pci)84{85struct snd_card *card = pci_get_drvdata(pci);86struct cs5535audio *cs5535au = card->private_data;87u32 tmp;88int timeout;89int i;9091pci_set_power_state(pci, PCI_D0);92pci_restore_state(pci);93if (pci_enable_device(pci) < 0) {94printk(KERN_ERR "cs5535audio: pci_enable_device failed, "95"disabling device\n");96snd_card_disconnect(card);97return -EIO;98}99pci_set_master(pci);100101/* set LNK_WRM_RST to reset AC link */102cs_writel(cs5535au, ACC_CODEC_CNTL, ACC_CODEC_CNTL_LNK_WRM_RST);103104timeout = 50;105do {106tmp = cs_readl(cs5535au, ACC_CODEC_STATUS);107if (tmp & PRM_RDY_STS)108break;109udelay(1);110} while (--timeout);111112if (!timeout)113snd_printk(KERN_ERR "Failure getting AC Link ready\n");114115/* set up rate regs, dma. actual initiation is done in trig */116for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) {117struct cs5535audio_dma *dma = &cs5535au->dmas[i];118if (dma && dma->substream) {119dma->substream->ops->prepare(dma->substream);120dma->ops->setup_prd(cs5535au, dma->saved_prd);121}122}123124/* we depend on ac97 to perform the codec power up */125snd_ac97_resume(cs5535au->ac97);126snd_power_change_state(card, SNDRV_CTL_POWER_D0);127128return 0;129}130131132133