s6105-ipcam.c 6.7 KB

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