sof_nuvoton_common.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * This file defines data structures and functions used in Machine
  4. * Driver for Intel platforms with Nuvoton Codecs.
  5. *
  6. * Copyright 2023 Intel Corporation.
  7. */
  8. #include <linux/module.h>
  9. #include <sound/sof.h>
  10. #include "sof_nuvoton_common.h"
  11. /*
  12. * Nuvoton NAU8318
  13. */
  14. static const struct snd_kcontrol_new nau8318_kcontrols[] = {
  15. SOC_DAPM_PIN_SWITCH("Spk"),
  16. };
  17. static const struct snd_soc_dapm_widget nau8318_widgets[] = {
  18. SND_SOC_DAPM_SPK("Spk", NULL),
  19. };
  20. static const struct snd_soc_dapm_route nau8318_routes[] = {
  21. { "Spk", NULL, "Speaker" },
  22. };
  23. static struct snd_soc_dai_link_component nau8318_components[] = {
  24. {
  25. .name = NAU8318_DEV0_NAME,
  26. .dai_name = NAU8318_CODEC_DAI,
  27. }
  28. };
  29. static int nau8318_init(struct snd_soc_pcm_runtime *rtd)
  30. {
  31. struct snd_soc_card *card = rtd->card;
  32. int ret;
  33. ret = snd_soc_dapm_new_controls(&card->dapm, nau8318_widgets,
  34. ARRAY_SIZE(nau8318_widgets));
  35. if (ret) {
  36. dev_err(rtd->dev, "fail to add nau8318 widgets, ret %d\n", ret);
  37. return ret;
  38. }
  39. ret = snd_soc_add_card_controls(card, nau8318_kcontrols,
  40. ARRAY_SIZE(nau8318_kcontrols));
  41. if (ret) {
  42. dev_err(rtd->dev, "fail to add nau8318 kcontrols, ret %d\n", ret);
  43. return ret;
  44. }
  45. ret = snd_soc_dapm_add_routes(&card->dapm, nau8318_routes,
  46. ARRAY_SIZE(nau8318_routes));
  47. if (ret) {
  48. dev_err(rtd->dev, "fail to add nau8318 routes, ret %d\n", ret);
  49. return ret;
  50. }
  51. return ret;
  52. }
  53. void nau8318_set_dai_link(struct snd_soc_dai_link *link)
  54. {
  55. link->codecs = nau8318_components;
  56. link->num_codecs = ARRAY_SIZE(nau8318_components);
  57. link->init = nau8318_init;
  58. }
  59. EXPORT_SYMBOL_NS(nau8318_set_dai_link, SND_SOC_INTEL_SOF_NUVOTON_COMMON);
  60. MODULE_DESCRIPTION("ASoC Intel SOF Nuvoton helpers");
  61. MODULE_LICENSE("GPL");