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 <linux/i2c.h>
  17. #include <sound/core.h>
  18. #include <sound/pcm.h>
  19. #include <sound/soc.h>
  20. #include <variant/dmac.h>
  21. #include "s6000-pcm.h"
  22. #include "s6000-i2s.h"
  23. #define S6105_CAM_CODEC_CLOCK 12288000
  24. static int s6105_hw_params(struct snd_pcm_substream *substream,
  25. struct snd_pcm_hw_params *params)
  26. {
  27. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  28. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  29. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  30. int ret = 0;
  31. /* set codec DAI configuration */
  32. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  33. SND_SOC_DAIFMT_CBM_CFM);
  34. if (ret < 0)
  35. return ret;
  36. /* set cpu DAI configuration */
  37. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM |
  38. SND_SOC_DAIFMT_NB_NF);
  39. if (ret < 0)
  40. return ret;
  41. /* set the codec system clock */
  42. ret = snd_soc_dai_set_sysclk(codec_dai, 0, S6105_CAM_CODEC_CLOCK,
  43. SND_SOC_CLOCK_OUT);
  44. if (ret < 0)
  45. return ret;
  46. return 0;
  47. }
  48. static struct snd_soc_ops s6105_ops = {
  49. .hw_params = s6105_hw_params,
  50. };
  51. /* s6105 machine dapm widgets */
  52. static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
  53. SND_SOC_DAPM_LINE("Audio Out Differential", NULL),
  54. SND_SOC_DAPM_LINE("Audio Out Stereo", NULL),
  55. SND_SOC_DAPM_LINE("Audio In", NULL),
  56. };
  57. /* s6105 machine audio_mapnections to the codec pins */
  58. static const struct snd_soc_dapm_route audio_map[] = {
  59. /* Audio Out connected to HPLOUT, HPLCOM, HPROUT */
  60. {"Audio Out Differential", NULL, "HPLOUT"},
  61. {"Audio Out Differential", NULL, "HPLCOM"},
  62. {"Audio Out Stereo", NULL, "HPLOUT"},
  63. {"Audio Out Stereo", NULL, "HPROUT"},
  64. /* Audio In connected to LINE1L, LINE1R */
  65. {"LINE1L", NULL, "Audio In"},
  66. {"LINE1R", NULL, "Audio In"},
  67. };
  68. static int output_type_info(struct snd_kcontrol *kcontrol,
  69. struct snd_ctl_elem_info *uinfo)
  70. {
  71. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  72. uinfo->count = 1;
  73. uinfo->value.enumerated.items = 2;
  74. if (uinfo->value.enumerated.item) {
  75. uinfo->value.enumerated.item = 1;
  76. strcpy(uinfo->value.enumerated.name, "HPLOUT/HPROUT");
  77. } else {
  78. strcpy(uinfo->value.enumerated.name, "HPLOUT/HPLCOM");
  79. }
  80. return 0;
  81. }
  82. static int output_type_get(struct snd_kcontrol *kcontrol,
  83. struct snd_ctl_elem_value *ucontrol)
  84. {
  85. ucontrol->value.enumerated.item[0] = kcontrol->private_value;
  86. return 0;
  87. }
  88. static int output_type_put(struct snd_kcontrol *kcontrol,
  89. struct snd_ctl_elem_value *ucontrol)
  90. {
  91. struct snd_soc_codec *codec = kcontrol->private_data;
  92. struct snd_soc_dapm_context *dapm = &codec->dapm;
  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(dapm, val ? differential : stereo);
  100. snd_soc_dapm_sync(dapm);
  101. snd_soc_dapm_enable_pin(dapm, val ? stereo : differential);
  102. snd_soc_dapm_sync(dapm);
  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_pcm_runtime *rtd)
  117. {
  118. struct snd_soc_codec *codec = rtd->codec;
  119. struct snd_soc_dapm_context *dapm = &codec->dapm;
  120. /* Add s6105 specific widgets */
  121. snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
  122. ARRAY_SIZE(aic3x_dapm_widgets));
  123. /* Set up s6105 specific audio path audio_map */
  124. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  125. /* not present */
  126. snd_soc_dapm_nc_pin(dapm, "MONO_LOUT");
  127. snd_soc_dapm_nc_pin(dapm, "LINE2L");
  128. snd_soc_dapm_nc_pin(dapm, "LINE2R");
  129. /* not connected */
  130. snd_soc_dapm_nc_pin(dapm, "MIC3L"); /* LINE2L on this chip */
  131. snd_soc_dapm_nc_pin(dapm, "MIC3R"); /* LINE2R on this chip */
  132. snd_soc_dapm_nc_pin(dapm, "LLOUT");
  133. snd_soc_dapm_nc_pin(dapm, "RLOUT");
  134. snd_soc_dapm_nc_pin(dapm, "HPRCOM");
  135. /* always connected */
  136. snd_soc_dapm_enable_pin(dapm, "Audio In");
  137. /* must correspond to audio_out_mux.private_value initializer */
  138. snd_soc_dapm_disable_pin(dapm, "Audio Out Differential");
  139. snd_soc_dapm_sync(dapm);
  140. snd_soc_dapm_enable_pin(dapm, "Audio Out Stereo");
  141. snd_soc_dapm_sync(dapm);
  142. snd_ctl_add(codec->card->snd_card, snd_ctl_new1(&audio_out_mux, codec));
  143. return 0;
  144. }
  145. /* s6105 digital audio interface glue - connects codec <--> CPU */
  146. static struct snd_soc_dai_link s6105_dai = {
  147. .name = "TLV320AIC31",
  148. .stream_name = "AIC31",
  149. .cpu_dai_name = "s6000-i2s",
  150. .codec_dai_name = "tlv320aic3x-hifi",
  151. .platform_name = "s6000-pcm-audio",
  152. .codec_name = "tlv320aic3x-codec.0-001a",
  153. .init = s6105_aic3x_init,
  154. .ops = &s6105_ops,
  155. };
  156. /* s6105 audio machine driver */
  157. static struct snd_soc_card snd_soc_card_s6105 = {
  158. .name = "Stretch IP Camera",
  159. .dai_link = &s6105_dai,
  160. .num_links = 1,
  161. };
  162. static struct s6000_snd_platform_data __initdata s6105_snd_data = {
  163. .wide = 0,
  164. .channel_in = 0,
  165. .channel_out = 1,
  166. .lines_in = 1,
  167. .lines_out = 1,
  168. .same_rate = 1,
  169. };
  170. static struct platform_device *s6105_snd_device;
  171. /* temporary i2c device creation until this can be moved into the machine
  172. * support file.
  173. */
  174. static struct i2c_board_info i2c_device[] = {
  175. { I2C_BOARD_INFO("tlv320aic33", 0x18), }
  176. };
  177. static int __init s6105_init(void)
  178. {
  179. int ret;
  180. i2c_register_board_info(0, i2c_device, ARRAY_SIZE(i2c_device));
  181. s6105_snd_device = platform_device_alloc("soc-audio", -1);
  182. if (!s6105_snd_device)
  183. return -ENOMEM;
  184. platform_set_drvdata(s6105_snd_device, &snd_soc_card_s6105);
  185. platform_device_add_data(s6105_snd_device, &s6105_snd_data,
  186. sizeof(s6105_snd_data));
  187. ret = platform_device_add(s6105_snd_device);
  188. if (ret)
  189. platform_device_put(s6105_snd_device);
  190. return ret;
  191. }
  192. static void __exit s6105_exit(void)
  193. {
  194. platform_device_unregister(s6105_snd_device);
  195. }
  196. module_init(s6105_init);
  197. module_exit(s6105_exit);
  198. MODULE_AUTHOR("Daniel Gloeckner");
  199. MODULE_DESCRIPTION("Stretch s6105 IP camera ASoC driver");
  200. MODULE_LICENSE("GPL");