simple-card.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * ASoC simple sound card support
  3. *
  4. * Copyright (C) 2012 Renesas Solutions Corp.
  5. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/platform_device.h>
  12. #include <linux/module.h>
  13. #include <sound/simple_card.h>
  14. #define asoc_simple_get_card_info(p) \
  15. container_of(p->dai_link, struct asoc_simple_card_info, snd_link)
  16. static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
  17. struct asoc_simple_dai *set,
  18. unsigned int daifmt)
  19. {
  20. int ret = 0;
  21. daifmt |= set->fmt;
  22. if (!ret && daifmt)
  23. ret = snd_soc_dai_set_fmt(dai, daifmt);
  24. if (ret == -ENOTSUPP) {
  25. dev_dbg(dai->dev, "ASoC: set_fmt is not supported\n");
  26. ret = 0;
  27. }
  28. if (!ret && set->sysclk)
  29. ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0);
  30. return ret;
  31. }
  32. static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
  33. {
  34. struct asoc_simple_card_info *info = asoc_simple_get_card_info(rtd);
  35. struct snd_soc_dai *codec = rtd->codec_dai;
  36. struct snd_soc_dai *cpu = rtd->cpu_dai;
  37. unsigned int daifmt = info->daifmt;
  38. int ret;
  39. ret = __asoc_simple_card_dai_init(codec, &info->codec_dai, daifmt);
  40. if (ret < 0)
  41. return ret;
  42. ret = __asoc_simple_card_dai_init(cpu, &info->cpu_dai, daifmt);
  43. if (ret < 0)
  44. return ret;
  45. return 0;
  46. }
  47. static int asoc_simple_card_probe(struct platform_device *pdev)
  48. {
  49. struct asoc_simple_card_info *cinfo = pdev->dev.platform_data;
  50. struct device *dev = &pdev->dev;
  51. if (!cinfo) {
  52. dev_err(dev, "no info for asoc-simple-card\n");
  53. return -EINVAL;
  54. }
  55. if (!cinfo->name ||
  56. !cinfo->card ||
  57. !cinfo->codec ||
  58. !cinfo->platform ||
  59. !cinfo->cpu_dai.name ||
  60. !cinfo->codec_dai.name) {
  61. dev_err(dev, "insufficient asoc_simple_card_info settings\n");
  62. return -EINVAL;
  63. }
  64. /*
  65. * init snd_soc_dai_link
  66. */
  67. cinfo->snd_link.name = cinfo->name;
  68. cinfo->snd_link.stream_name = cinfo->name;
  69. cinfo->snd_link.cpu_dai_name = cinfo->cpu_dai.name;
  70. cinfo->snd_link.platform_name = cinfo->platform;
  71. cinfo->snd_link.codec_name = cinfo->codec;
  72. cinfo->snd_link.codec_dai_name = cinfo->codec_dai.name;
  73. cinfo->snd_link.init = asoc_simple_card_dai_init;
  74. /*
  75. * init snd_soc_card
  76. */
  77. cinfo->snd_card.name = cinfo->card;
  78. cinfo->snd_card.owner = THIS_MODULE;
  79. cinfo->snd_card.dai_link = &cinfo->snd_link;
  80. cinfo->snd_card.num_links = 1;
  81. cinfo->snd_card.dev = &pdev->dev;
  82. return snd_soc_register_card(&cinfo->snd_card);
  83. }
  84. static int asoc_simple_card_remove(struct platform_device *pdev)
  85. {
  86. struct asoc_simple_card_info *cinfo = pdev->dev.platform_data;
  87. return snd_soc_unregister_card(&cinfo->snd_card);
  88. }
  89. static struct platform_driver asoc_simple_card = {
  90. .driver = {
  91. .name = "asoc-simple-card",
  92. .owner = THIS_MODULE,
  93. },
  94. .probe = asoc_simple_card_probe,
  95. .remove = asoc_simple_card_remove,
  96. };
  97. module_platform_driver(asoc_simple_card);
  98. MODULE_ALIAS("platform:asoc-simple-card");
  99. MODULE_LICENSE("GPL");
  100. MODULE_DESCRIPTION("ASoC Simple Sound Card");
  101. MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");