blob: 90fb73a9d9b2ebc3be60d1d7612eecb361fe022d [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Jaya Kumar9ac25592006-04-28 14:34:49 +02002/*
3 * Power management for audio on multifunction CS5535 companion device
4 * Copyright (C) Jaya Kumar
Jaya Kumar9ac25592006-04-28 14:34:49 +02005 */
6
7#include <linux/init.h>
Jaya Kumar9ac25592006-04-28 14:34:49 +02008#include <linux/pci.h>
9#include <linux/delay.h>
Jaya Kumar9ac25592006-04-28 14:34:49 +020010#include <sound/core.h>
11#include <sound/control.h>
12#include <sound/initval.h>
13#include <sound/asoundef.h>
14#include <sound/pcm.h>
15#include <sound/ac97_codec.h>
16#include "cs5535audio.h"
17
18static void snd_cs5535audio_stop_hardware(struct cs5535audio *cs5535au)
19{
20 /*
21 we depend on snd_ac97_suspend to tell the
22 AC97 codec to shutdown. the amd spec suggests
23 that the LNK_SHUTDOWN be done at the same time
24 that the codec power-down is issued. instead,
25 we do it just after rather than at the same
26 time. excluding codec specific build_ops->suspend
27 ac97 powerdown hits:
28 0x8000 EAPD
29 0x4000 Headphone amplifier
30 0x0300 ADC & DAC
31 0x0400 Analog Mixer powerdown (Vref on)
32 I am not sure if this is the best that we can do.
33 The remainder to be investigated are:
34 - analog mixer (vref off) 0x0800
35 - AC-link powerdown 0x1000
36 - codec internal clock 0x2000
37 */
38
39 /* set LNK_SHUTDOWN to shutdown AC link */
40 cs_writel(cs5535au, ACC_CODEC_CNTL, ACC_CODEC_CNTL_LNK_SHUTDOWN);
41
42}
43
Jérémy Lefaurefe4cb862016-12-16 19:25:27 -050044static int __maybe_unused snd_cs5535audio_suspend(struct device *dev)
Jaya Kumar9ac25592006-04-28 14:34:49 +020045{
Takashi Iwai68cb2b52012-07-02 15:20:37 +020046 struct snd_card *card = dev_get_drvdata(dev);
Jaya Kumar9ac25592006-04-28 14:34:49 +020047 struct cs5535audio *cs5535au = card->private_data;
48 int i;
49
50 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
Jaya Kumar9ac25592006-04-28 14:34:49 +020051 snd_ac97_suspend(cs5535au->ac97);
Andres Salomon222fa0b2007-09-03 15:42:16 +020052 for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) {
53 struct cs5535audio_dma *dma = &cs5535au->dmas[i];
54 if (dma && dma->substream)
55 dma->saved_prd = dma->ops->read_prd(cs5535au);
56 }
Jaya Kumar9ac25592006-04-28 14:34:49 +020057 /* save important regs, then disable aclink in hw */
58 snd_cs5535audio_stop_hardware(cs5535au);
Jaya Kumar9ac25592006-04-28 14:34:49 +020059 return 0;
60}
61
Jérémy Lefaurefe4cb862016-12-16 19:25:27 -050062static int __maybe_unused snd_cs5535audio_resume(struct device *dev)
Jaya Kumar9ac25592006-04-28 14:34:49 +020063{
Takashi Iwai68cb2b52012-07-02 15:20:37 +020064 struct snd_card *card = dev_get_drvdata(dev);
Jaya Kumar9ac25592006-04-28 14:34:49 +020065 struct cs5535audio *cs5535au = card->private_data;
66 u32 tmp;
67 int timeout;
68 int i;
69
Jaya Kumar9ac25592006-04-28 14:34:49 +020070 /* set LNK_WRM_RST to reset AC link */
71 cs_writel(cs5535au, ACC_CODEC_CNTL, ACC_CODEC_CNTL_LNK_WRM_RST);
72
73 timeout = 50;
74 do {
75 tmp = cs_readl(cs5535au, ACC_CODEC_STATUS);
76 if (tmp & PRM_RDY_STS)
77 break;
78 udelay(1);
79 } while (--timeout);
80
81 if (!timeout)
Takashi Iwai00980aa2014-02-25 16:10:25 +010082 dev_err(cs5535au->card->dev, "Failure getting AC Link ready\n");
Jaya Kumar9ac25592006-04-28 14:34:49 +020083
Jaya Kumar9ac25592006-04-28 14:34:49 +020084 /* set up rate regs, dma. actual initiation is done in trig */
85 for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) {
86 struct cs5535audio_dma *dma = &cs5535au->dmas[i];
Andres Salomon222fa0b2007-09-03 15:42:16 +020087 if (dma && dma->substream) {
Jaya Kumar9ac25592006-04-28 14:34:49 +020088 dma->substream->ops->prepare(dma->substream);
89 dma->ops->setup_prd(cs5535au, dma->saved_prd);
90 }
91 }
Andres Salomon222fa0b2007-09-03 15:42:16 +020092
93 /* we depend on ac97 to perform the codec power up */
94 snd_ac97_resume(cs5535au->ac97);
Jaya Kumar9ac25592006-04-28 14:34:49 +020095 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
96
97 return 0;
98}
99
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200100SIMPLE_DEV_PM_OPS(snd_cs5535audio_pm, snd_cs5535audio_suspend, snd_cs5535audio_resume);