GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / sound / pci / cs5535audio / cs5535audio_pm.c
blob37aa56f961b7fbee32b5330bfebbb11dfe9a56b3
1 /*
2 * Power management for audio on multifunction CS5535 companion device
3 * Copyright (C) Jaya Kumar
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/init.h>
22 #include <linux/pci.h>
23 #include <linux/delay.h>
24 #include <sound/core.h>
25 #include <sound/control.h>
26 #include <sound/initval.h>
27 #include <sound/asoundef.h>
28 #include <sound/pcm.h>
29 #include <sound/ac97_codec.h>
30 #include "cs5535audio.h"
32 static void snd_cs5535audio_stop_hardware(struct cs5535audio *cs5535au)
34 /*
35 we depend on snd_ac97_suspend to tell the
36 AC97 codec to shutdown. the amd spec suggests
37 that the LNK_SHUTDOWN be done at the same time
38 that the codec power-down is issued. instead,
39 we do it just after rather than at the same
40 time. excluding codec specific build_ops->suspend
41 ac97 powerdown hits:
42 0x8000 EAPD
43 0x4000 Headphone amplifier
44 0x0300 ADC & DAC
45 0x0400 Analog Mixer powerdown (Vref on)
46 I am not sure if this is the best that we can do.
47 The remainder to be investigated are:
48 - analog mixer (vref off) 0x0800
49 - AC-link powerdown 0x1000
50 - codec internal clock 0x2000
53 /* set LNK_SHUTDOWN to shutdown AC link */
54 cs_writel(cs5535au, ACC_CODEC_CNTL, ACC_CODEC_CNTL_LNK_SHUTDOWN);
58 int snd_cs5535audio_suspend(struct pci_dev *pci, pm_message_t state)
60 struct snd_card *card = pci_get_drvdata(pci);
61 struct cs5535audio *cs5535au = card->private_data;
62 int i;
64 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
65 snd_pcm_suspend_all(cs5535au->pcm);
66 snd_ac97_suspend(cs5535au->ac97);
67 for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) {
68 struct cs5535audio_dma *dma = &cs5535au->dmas[i];
69 if (dma && dma->substream)
70 dma->saved_prd = dma->ops->read_prd(cs5535au);
72 /* save important regs, then disable aclink in hw */
73 snd_cs5535audio_stop_hardware(cs5535au);
75 if (pci_save_state(pci)) {
76 printk(KERN_ERR "cs5535audio: pci_save_state failed!\n");
77 return -EIO;
79 pci_disable_device(pci);
80 pci_set_power_state(pci, pci_choose_state(pci, state));
81 return 0;
84 int snd_cs5535audio_resume(struct pci_dev *pci)
86 struct snd_card *card = pci_get_drvdata(pci);
87 struct cs5535audio *cs5535au = card->private_data;
88 u32 tmp;
89 int timeout;
90 int i;
92 pci_set_power_state(pci, PCI_D0);
93 if (pci_restore_state(pci) < 0) {
94 printk(KERN_ERR "cs5535audio: pci_restore_state failed, "
95 "disabling device\n");
96 snd_card_disconnect(card);
97 return -EIO;
99 if (pci_enable_device(pci) < 0) {
100 printk(KERN_ERR "cs5535audio: pci_enable_device failed, "
101 "disabling device\n");
102 snd_card_disconnect(card);
103 return -EIO;
105 pci_set_master(pci);
107 /* set LNK_WRM_RST to reset AC link */
108 cs_writel(cs5535au, ACC_CODEC_CNTL, ACC_CODEC_CNTL_LNK_WRM_RST);
110 timeout = 50;
111 do {
112 tmp = cs_readl(cs5535au, ACC_CODEC_STATUS);
113 if (tmp & PRM_RDY_STS)
114 break;
115 udelay(1);
116 } while (--timeout);
118 if (!timeout)
119 snd_printk(KERN_ERR "Failure getting AC Link ready\n");
121 /* set up rate regs, dma. actual initiation is done in trig */
122 for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) {
123 struct cs5535audio_dma *dma = &cs5535au->dmas[i];
124 if (dma && dma->substream) {
125 dma->substream->ops->prepare(dma->substream);
126 dma->ops->setup_prd(cs5535au, dma->saved_prd);
130 /* we depend on ac97 to perform the codec power up */
131 snd_ac97_resume(cs5535au->ac97);
132 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
134 return 0;