machine.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ===================
  2. ASoC Machine Driver
  3. ===================
  4. The ASoC machine (or board) driver is the code that glues together all the
  5. component drivers (e.g. codecs, platforms and DAIs). It also describes the
  6. relationships between each component which include audio paths, GPIOs,
  7. interrupts, clocking, jacks and voltage regulators.
  8. The machine driver can contain codec and platform specific code. It registers
  9. the audio subsystem with the kernel as a platform device and is represented by
  10. the following struct:-
  11. ::
  12. /* SoC machine */
  13. struct snd_soc_card {
  14. char *name;
  15. ...
  16. int (*probe)(struct platform_device *pdev);
  17. int (*remove)(struct platform_device *pdev);
  18. /* the pre and post PM functions are used to do any PM work before and
  19. * after the codec and DAIs do any PM work. */
  20. int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
  21. int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
  22. int (*resume_pre)(struct platform_device *pdev);
  23. int (*resume_post)(struct platform_device *pdev);
  24. ...
  25. /* CPU <--> Codec DAI links */
  26. struct snd_soc_dai_link *dai_link;
  27. int num_links;
  28. ...
  29. };
  30. probe()/remove()
  31. ----------------
  32. probe/remove are optional. Do any machine specific probe here.
  33. suspend()/resume()
  34. ------------------
  35. The machine driver has pre and post versions of suspend and resume to take care
  36. of any machine audio tasks that have to be done before or after the codec, DAIs
  37. and DMA is suspended and resumed. Optional.
  38. Machine DAI Configuration
  39. -------------------------
  40. The machine DAI configuration glues all the codec and CPU DAIs together. It can
  41. also be used to set up the DAI system clock and for any machine related DAI
  42. initialisation e.g. the machine audio map can be connected to the codec audio
  43. map, unconnected codec pins can be set as such.
  44. struct snd_soc_dai_link is used to set up each DAI in your machine. e.g.
  45. ::
  46. /* corgi digital audio interface glue - connects codec <--> CPU */
  47. static struct snd_soc_dai_link corgi_dai = {
  48. .name = "WM8731",
  49. .stream_name = "WM8731",
  50. .cpu_dai_name = "pxa-is2-dai",
  51. .codec_dai_name = "wm8731-hifi",
  52. .platform_name = "pxa-pcm-audio",
  53. .codec_name = "wm8713-codec.0-001a",
  54. .init = corgi_wm8731_init,
  55. .ops = &corgi_ops,
  56. };
  57. In the above struct, dai’s are registered using names but you can pass
  58. either dai name or device tree node but not both. Also, names used here
  59. for cpu/codec/platform dais should be globally unique.
  60. Additionally below example macro can be used to register cpu, codec and
  61. platform dai::
  62. SND_SOC_DAILINK_DEFS(wm2200_cpu_dsp,
  63. DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
  64. DAILINK_COMP_ARRAY(COMP_CODEC("spi0.0", "wm0010-sdi1")),
  65. DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
  66. struct snd_soc_card then sets up the machine with its DAIs. e.g.
  67. ::
  68. /* corgi audio machine driver */
  69. static struct snd_soc_card snd_soc_corgi = {
  70. .name = "Corgi",
  71. .dai_link = &corgi_dai,
  72. .num_links = 1,
  73. };
  74. Following this, ``devm_snd_soc_register_card`` can be used to register
  75. the sound card. During the registration, the individual components
  76. such as the codec, CPU, and platform are probed. If all these components
  77. are successfully probed, the sound card gets registered.
  78. Machine Power Map
  79. -----------------
  80. The machine driver can optionally extend the codec power map and to become an
  81. audio power map of the audio subsystem. This allows for automatic power up/down
  82. of speaker/HP amplifiers, etc. Codec pins can be connected to the machines jack
  83. sockets in the machine init function.
  84. Machine Controls
  85. ----------------
  86. Machine specific audio mixer controls can be added in the DAI init function.
  87. Clocking Controls
  88. -----------------
  89. As previously noted, clock configuration is handled within the machine driver.
  90. For details on the clock APIs that the machine driver can utilize for
  91. setup, please refer to Documentation/sound/soc/clocking.rst. However, the
  92. callback needs to be registered by the CPU/Codec/Platform drivers to configure
  93. the clocks that is needed for the corresponding device operation.