cs5535audio_pm.c 2.8 KB

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