cs5535audio_pm.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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/slab.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"
  31. static void snd_cs5535audio_stop_hardware(struct cs5535audio *cs5535au)
  32. {
  33. /*
  34. we depend on snd_ac97_suspend to tell the
  35. AC97 codec to shutdown. the amd spec suggests
  36. that the LNK_SHUTDOWN be done at the same time
  37. that the codec power-down is issued. instead,
  38. we do it just after rather than at the same
  39. time. excluding codec specific build_ops->suspend
  40. ac97 powerdown hits:
  41. 0x8000 EAPD
  42. 0x4000 Headphone amplifier
  43. 0x0300 ADC & DAC
  44. 0x0400 Analog Mixer powerdown (Vref on)
  45. I am not sure if this is the best that we can do.
  46. The remainder to be investigated are:
  47. - analog mixer (vref off) 0x0800
  48. - AC-link powerdown 0x1000
  49. - codec internal clock 0x2000
  50. */
  51. /* set LNK_SHUTDOWN to shutdown AC link */
  52. cs_writel(cs5535au, ACC_CODEC_CNTL, ACC_CODEC_CNTL_LNK_SHUTDOWN);
  53. }
  54. int snd_cs5535audio_suspend(struct pci_dev *pci, pm_message_t state)
  55. {
  56. struct snd_card *card = pci_get_drvdata(pci);
  57. struct cs5535audio *cs5535au = card->private_data;
  58. int i;
  59. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  60. snd_pcm_suspend_all(cs5535au->pcm);
  61. snd_ac97_suspend(cs5535au->ac97);
  62. for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) {
  63. struct cs5535audio_dma *dma = &cs5535au->dmas[i];
  64. if (dma && dma->substream)
  65. dma->saved_prd = dma->ops->read_prd(cs5535au);
  66. }
  67. /* save important regs, then disable aclink in hw */
  68. snd_cs5535audio_stop_hardware(cs5535au);
  69. if (pci_save_state(pci)) {
  70. printk(KERN_ERR "cs5535audio: pci_save_state failed!\n");
  71. return -EIO;
  72. }
  73. pci_disable_device(pci);
  74. pci_set_power_state(pci, pci_choose_state(pci, state));
  75. return 0;
  76. }
  77. int snd_cs5535audio_resume(struct pci_dev *pci)
  78. {
  79. struct snd_card *card = pci_get_drvdata(pci);
  80. struct cs5535audio *cs5535au = card->private_data;
  81. u32 tmp;
  82. int timeout;
  83. int i;
  84. pci_set_power_state(pci, PCI_D0);
  85. if (pci_restore_state(pci) < 0) {
  86. printk(KERN_ERR "cs5535audio: pci_restore_state failed, "
  87. "disabling device\n");
  88. snd_card_disconnect(card);
  89. return -EIO;
  90. }
  91. if (pci_enable_device(pci) < 0) {
  92. printk(KERN_ERR "cs5535audio: pci_enable_device failed, "
  93. "disabling device\n");
  94. snd_card_disconnect(card);
  95. return -EIO;
  96. }
  97. pci_set_master(pci);
  98. /* set LNK_WRM_RST to reset AC link */
  99. cs_writel(cs5535au, ACC_CODEC_CNTL, ACC_CODEC_CNTL_LNK_WRM_RST);
  100. timeout = 50;
  101. do {
  102. tmp = cs_readl(cs5535au, ACC_CODEC_STATUS);
  103. if (tmp & PRM_RDY_STS)
  104. break;
  105. udelay(1);
  106. } while (--timeout);
  107. if (!timeout)
  108. snd_printk(KERN_ERR "Failure getting AC Link ready\n");
  109. /* set up rate regs, dma. actual initiation is done in trig */
  110. for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) {
  111. struct cs5535audio_dma *dma = &cs5535au->dmas[i];
  112. if (dma && dma->substream) {
  113. dma->substream->ops->prepare(dma->substream);
  114. dma->ops->setup_prd(cs5535au, dma->saved_prd);
  115. }
  116. }
  117. /* we depend on ac97 to perform the codec power up */
  118. snd_ac97_resume(cs5535au->ac97);
  119. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  120. return 0;
  121. }