s6105-ipcam.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * ASoC driver for Stretch s6105 IP camera platform
  3. *
  4. * Author: Daniel Gloeckner, <dg@emlix.com>
  5. * Copyright: (C) 2009 emlix GmbH <info@emlix.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/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/timer.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/platform_device.h>
  16. #include <sound/core.h>
  17. #include <sound/pcm.h>
  18. #include <sound/soc.h>
  19. #include <sound/soc-dapm.h>
  20. #include <variant/dmac.h>
  21. #include "../codecs/tlv320aic3x.h"
  22. #include "s6000-pcm.h"
  23. #include "s6000-i2s.h"
  24. #define S6105_CAM_CODEC_CLOCK 12288000
  25. static int s6105_hw_params(struct snd_pcm_substream *substream,
  26. struct snd_pcm_hw_params *params)
  27. {
  28. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  29. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  30. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  31. int ret = 0;
  32. /* set codec DAI configuration */
  33. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  34. SND_SOC_DAIFMT_CBM_CFM);
  35. if (ret < 0)
  36. return ret;
  37. /* set cpu DAI configuration */
  38. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM |
  39. SND_SOC_DAIFMT_NB_NF);
  40. if (ret < 0)
  41. return ret;
  42. /* set the codec system clock */
  43. ret = snd_soc_dai_set_sysclk(codec_dai, 0, S6105_CAM_CODEC_CLOCK,
  44. SND_SOC_CLOCK_OUT);
  45. if (ret < 0)
  46. return ret;
  47. return 0;
  48. }
  49. static struct snd_soc_ops s6105_ops = {
  50. .hw_params = s6105_hw_params,
  51. };
  52. /* s6105 machine dapm widgets */
  53. static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
  54. SND_SOC_DAPM_LINE("Audio Out Differential", NULL),
  55. SND_SOC_DAPM_LINE("Audio Out Stereo", NULL),
  56. SND_SOC_DAPM_LINE("Audio In", NULL),
  57. };
  58. /* s6105 machine audio_mapnections to the codec pins */
  59. static const struct snd_soc_dapm_route audio_map[] = {
  60. /* Audio Out connected to HPLOUT, HPLCOM, HPROUT */
  61. {"Audio Out Differential", NULL, "HPLOUT"},
  62. {"Audio Out Differential", NULL, "HPLCOM"},
  63. {"Audio Out Stereo", NULL, "HPLOUT"},
  64. {"Audio Out Stereo", NULL, "HPROUT"},
  65. /* Audio In connected to LINE1L, LINE1R */
  66. {"LINE1L", NULL, "Audio In"},
  67. {"LINE1R", NULL, "Audio In"},
  68. };
  69. static int output_type_info(struct snd_kcontrol *kcontrol,
  70. struct snd_ctl_elem_info *uinfo)
  71. {
  72. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  73. uinfo->count = 1;
  74. uinfo->value.enumerated.items = 2;
  75. if (uinfo->value.enumerated.item) {
  76. uinfo->value.enumerated.item = 1;
  77. strcpy(uinfo->value.enumerated.name, "HPLOUT/HPROUT");
  78. } else {
  79. strcpy(uinfo->value.enumerated.name, "HPLOUT/HPLCOM");
  80. }
  81. return 0;
  82. }
  83. static int output_type_get(struct snd_kcontrol *kcontrol,
  84. struct snd_ctl_elem_value *ucontrol)
  85. {
  86. ucontrol->value.enumerated.item[0] = kcontrol->private_value;
  87. return 0;
  88. }
  89. static int output_type_put(struct snd_kcontrol *kcontrol,
  90. struct snd_ctl_elem_value *ucontrol)
  91. {
  92. struct snd_soc_codec *codec = kcontrol->private_data;
  93. unsigned int val = (ucontrol->value.enumerated.item[0] != 0);
  94. char *differential = "Audio Out Differential";
  95. char *stereo = "Audio Out Stereo";
  96. if (kcontrol->private_value == val)
  97. return 0;
  98. kcontrol->private_value = val;
  99. snd_soc_dapm_disable_pin(codec, val ? differential : stereo);
  100. snd_soc_dapm_sync(codec);
  101. snd_soc_dapm_enable_pin(codec, val ? stereo : differential);
  102. snd_soc_dapm_sync(codec);
  103. return 1;
  104. }
  105. static const struct snd_kcontrol_new audio_out_mux = {
  106. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  107. .name = "Master Output Mux",
  108. .index = 0,
  109. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  110. .info = output_type_info,
  111. .get = output_type_get,
  112. .put = output_type_put,
  113. .private_value = 1 /* default to stereo */
  114. };
  115. /* Logic for a aic3x as connected on the s6105 ip camera ref design */
  116. static int s6105_aic3x_init(struct snd_soc_codec *codec)
  117. {
  118. /* Add s6105 specific widgets */
  119. snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
  120. ARRAY_SIZE(aic3x_dapm_widgets));
  121. /* Set up s6105 specific audio path audio_map */
  122. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  123. /* not present */
  124. snd_soc_dapm_nc_pin(codec, "MONO_LOUT");
  125. snd_soc_dapm_nc_pin(codec, "LINE2L");
  126. snd_soc_dapm_nc_pin(codec, "LINE2R");
  127. /* not connected */
  128. snd_soc_dapm_nc_pin(codec, "MIC3L"); /* LINE2L on this chip */
  129. snd_soc_dapm_nc_pin(codec, "MIC3R"); /* LINE2R on this chip */
  130. snd_soc_dapm_nc_pin(codec, "LLOUT");
  131. snd_soc_dapm_nc_pin(codec, "RLOUT");
  132. snd_soc_dapm_nc_pin(codec, "HPRCOM");
  133. /* always connected */
  134. snd_soc_dapm_enable_pin(codec, "Audio In");
  135. /* must correspond to audio_out_mux.private_value initializer */
  136. snd_soc_dapm_disable_pin(codec, "Audio Out Differential");
  137. snd_soc_dapm_sync(codec);
  138. snd_soc_dapm_enable_pin(codec, "Audio Out Stereo");
  139. snd_soc_dapm_sync(codec);
  140. snd_ctl_add(codec->card, snd_ctl_new1(&audio_out_mux, codec));
  141. return 0;
  142. }
  143. /* s6105 digital audio interface glue - connects codec <--> CPU */
  144. static struct snd_soc_dai_link s6105_dai = {
  145. .name = "TLV320AIC31",
  146. .stream_name = "AIC31",
  147. .cpu_dai = &s6000_i2s_dai,
  148. .codec_dai = &aic3x_dai,
  149. .init = s6105_aic3x_init,
  150. .ops = &s6105_ops,
  151. };
  152. /* s6105 audio machine driver */
  153. static struct snd_soc_card snd_soc_card_s6105 = {
  154. .name = "Stretch IP Camera",
  155. .platform = &s6000_soc_platform,
  156. .dai_link = &s6105_dai,
  157. .num_links = 1,
  158. };
  159. /* s6105 audio private data */
  160. static struct aic3x_setup_data s6105_aic3x_setup = {
  161. .i2c_bus = 0,
  162. .i2c_address = 0x18,
  163. };
  164. /* s6105 audio subsystem */
  165. static struct snd_soc_device s6105_snd_devdata = {
  166. .card = &snd_soc_card_s6105,
  167. .codec_dev = &soc_codec_dev_aic3x,
  168. .codec_data = &s6105_aic3x_setup,
  169. };
  170. static struct s6000_snd_platform_data __initdata s6105_snd_data = {
  171. .wide = 0,
  172. .channel_in = 0,
  173. .channel_out = 1,
  174. .lines_in = 1,
  175. .lines_out = 1,
  176. .same_rate = 1,
  177. };
  178. static struct platform_device *s6105_snd_device;
  179. static int __init s6105_init(void)
  180. {
  181. int ret;
  182. s6105_snd_device = platform_device_alloc("soc-audio", -1);
  183. if (!s6105_snd_device)
  184. return -ENOMEM;
  185. platform_set_drvdata(s6105_snd_device, &s6105_snd_devdata);
  186. s6105_snd_devdata.dev = &s6105_snd_device->dev;
  187. platform_device_add_data(s6105_snd_device, &s6105_snd_data,
  188. sizeof(s6105_snd_data));
  189. ret = platform_device_add(s6105_snd_device);
  190. if (ret)
  191. platform_device_put(s6105_snd_device);
  192. return ret;
  193. }
  194. static void __exit s6105_exit(void)
  195. {
  196. platform_device_unregister(s6105_snd_device);
  197. }
  198. module_init(s6105_init);
  199. module_exit(s6105_exit);
  200. MODULE_AUTHOR("Daniel Gloeckner");
  201. MODULE_DESCRIPTION("Stretch s6105 IP camera ASoC driver");
  202. MODULE_LICENSE("GPL");