cs5535audio_pm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Power management for audio on multifunction CS5535 companion device
  3. * Copyright (C) Jaya Kumar
  4. *
  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.
  9. *
  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.
  14. *
  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
  18. *
  19. */
  20. #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"
  30. static void snd_cs5535audio_stop_hardware(struct cs5535audio *cs5535au)
  31. {
  32. /*
  33. we depend on snd_ac97_suspend to tell the
  34. AC97 codec to shutdown. the amd spec suggests
  35. that the LNK_SHUTDOWN be done at the same time
  36. that the codec power-down is issued. instead,
  37. we do it just after rather than at the same
  38. time. excluding codec specific build_ops->suspend
  39. ac97 powerdown hits:
  40. 0x8000 EAPD
  41. 0x4000 Headphone amplifier
  42. 0x0300 ADC & DAC
  43. 0x0400 Analog Mixer powerdown (Vref on)
  44. I am not sure if this is the best that we can do.
  45. The remainder to be investigated are:
  46. - analog mixer (vref off) 0x0800
  47. - AC-link powerdown 0x1000
  48. - codec internal clock 0x2000
  49. */
  50. /* set LNK_SHUTDOWN to shutdown AC link */
  51. cs_writel(cs5535au, ACC_CODEC_CNTL, ACC_CODEC_CNTL_LNK_SHUTDOWN);
  52. }
  53. static int snd_cs5535audio_suspend(struct device *dev)
  54. {
  55. struct snd_card *card = dev_get_drvdata(dev);
  56. struct cs5535audio *cs5535au = card->private_data;
  57. int i;
  58. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  59. snd_pcm_suspend_all(cs5535au->pcm);
  60. snd_ac97_suspend(cs5535au->ac97);
  61. for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) {
  62. struct cs5535audio_dma *dma = &cs5535au->dmas[i];
  63. if (dma && dma->substream)
  64. dma->saved_prd = dma->ops->read_prd(cs5535au);
  65. }
  66. /* save important regs, then disable aclink in hw */
  67. snd_cs5535audio_stop_hardware(cs5535au);
  68. return 0;
  69. }
  70. static int snd_cs5535audio_resume(struct device *dev)
  71. {
  72. struct snd_card *card = dev_get_drvdata(dev);
  73. struct cs5535audio *cs5535au = card->private_data;
  74. u32 tmp;
  75. int timeout;
  76. int i;
  77. /* set LNK_WRM_RST to reset AC link */
  78. cs_writel(cs5535au, ACC_CODEC_CNTL, ACC_CODEC_CNTL_LNK_WRM_RST);
  79. timeout = 50;
  80. do {
  81. tmp = cs_readl(cs5535au, ACC_CODEC_STATUS);
  82. if (tmp & PRM_RDY_STS)
  83. break;
  84. udelay(1);
  85. } while (--timeout);
  86. if (!timeout)
  87. dev_err(cs5535au->card->dev, "Failure getting AC Link ready\n");
  88. /* set up rate regs, dma. actual initiation is done in trig */
  89. for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) {
  90. struct cs5535audio_dma *dma = &cs5535au->dmas[i];
  91. if (dma && dma->substream) {
  92. dma->substream->ops->prepare(dma->substream);
  93. dma->ops->setup_prd(cs5535au, dma->saved_prd);
  94. }
  95. }
  96. /* we depend on ac97 to perform the codec power up */
  97. snd_ac97_resume(cs5535au->ac97);
  98. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  99. return 0;
  100. }
  101. SIMPLE_DEV_PM_OPS(snd_cs5535audio_pm, snd_cs5535audio_suspend, snd_cs5535audio_resume);