neo1973_wm8753.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * neo1973_wm8753.c -- SoC audio for Neo1973
  3. *
  4. * Copyright 2007 Wolfson Microelectronics PLC.
  5. * Author: Graeme Gregory
  6. * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * Revision history
  14. * 20th Jan 2007 Initial version.
  15. * 05th Feb 2007 Rename all to Neo1973
  16. *
  17. */
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/timer.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/i2c.h>
  24. #include <sound/driver.h>
  25. #include <sound/core.h>
  26. #include <sound/pcm.h>
  27. #include <sound/soc.h>
  28. #include <sound/soc-dapm.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/hardware/scoop.h>
  31. #include <asm/arch/regs-iis.h>
  32. #include <asm/arch/regs-clock.h>
  33. #include <asm/arch/regs-gpio.h>
  34. #include <asm/hardware.h>
  35. #include <asm/arch/audio.h>
  36. #include <asm/io.h>
  37. #include <asm/arch/spi-gpio.h>
  38. #include "../codecs/wm8753.h"
  39. #include "lm4857.h"
  40. #include "s3c24xx-pcm.h"
  41. #include "s3c24xx-i2s.h"
  42. /* define the scenarios */
  43. #define NEO_AUDIO_OFF 0
  44. #define NEO_GSM_CALL_AUDIO_HANDSET 1
  45. #define NEO_GSM_CALL_AUDIO_HEADSET 2
  46. #define NEO_GSM_CALL_AUDIO_BLUETOOTH 3
  47. #define NEO_STEREO_TO_SPEAKERS 4
  48. #define NEO_STEREO_TO_HEADPHONES 5
  49. #define NEO_CAPTURE_HANDSET 6
  50. #define NEO_CAPTURE_HEADSET 7
  51. #define NEO_CAPTURE_BLUETOOTH 8
  52. static struct snd_soc_machine neo1973;
  53. static struct i2c_client *i2c;
  54. static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
  55. struct snd_pcm_hw_params *params)
  56. {
  57. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  58. struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
  59. struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
  60. unsigned int pll_out = 0, bclk = 0;
  61. int ret = 0;
  62. unsigned long iis_clkrate;
  63. iis_clkrate = s3c24xx_i2s_get_clockrate();
  64. switch (params_rate(params)) {
  65. case 8000:
  66. case 16000:
  67. pll_out = 12288000;
  68. break;
  69. case 48000:
  70. bclk = WM8753_BCLK_DIV_4;
  71. pll_out = 12288000;
  72. break;
  73. case 96000:
  74. bclk = WM8753_BCLK_DIV_2;
  75. pll_out = 12288000;
  76. break;
  77. case 11025:
  78. bclk = WM8753_BCLK_DIV_16;
  79. pll_out = 11289600;
  80. break;
  81. case 22050:
  82. bclk = WM8753_BCLK_DIV_8;
  83. pll_out = 11289600;
  84. break;
  85. case 44100:
  86. bclk = WM8753_BCLK_DIV_4;
  87. pll_out = 11289600;
  88. break;
  89. case 88200:
  90. bclk = WM8753_BCLK_DIV_2;
  91. pll_out = 11289600;
  92. break;
  93. }
  94. /* set codec DAI configuration */
  95. ret = codec_dai->dai_ops.set_fmt(codec_dai,
  96. SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  97. SND_SOC_DAIFMT_CBM_CFM);
  98. if (ret < 0)
  99. return ret;
  100. /* set cpu DAI configuration */
  101. ret = cpu_dai->dai_ops.set_fmt(cpu_dai,
  102. SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  103. SND_SOC_DAIFMT_CBM_CFM);
  104. if (ret < 0)
  105. return ret;
  106. /* set the codec system clock for DAC and ADC */
  107. ret = codec_dai->dai_ops.set_sysclk(codec_dai, WM8753_MCLK, pll_out,
  108. SND_SOC_CLOCK_IN);
  109. if (ret < 0)
  110. return ret;
  111. /* set MCLK division for sample rate */
  112. ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
  113. S3C2410_IISMOD_32FS );
  114. if (ret < 0)
  115. return ret;
  116. /* set codec BCLK division for sample rate */
  117. ret = codec_dai->dai_ops.set_clkdiv(codec_dai, WM8753_BCLKDIV, bclk);
  118. if (ret < 0)
  119. return ret;
  120. /* set prescaler division for sample rate */
  121. ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
  122. S3C24XX_PRESCALE(4,4));
  123. if (ret < 0)
  124. return ret;
  125. /* codec PLL input is PCLK/4 */
  126. ret = codec_dai->dai_ops.set_pll(codec_dai, WM8753_PLL1,
  127. iis_clkrate / 4, pll_out);
  128. if (ret < 0)
  129. return ret;
  130. return 0;
  131. }
  132. static int neo1973_hifi_hw_free(struct snd_pcm_substream *substream)
  133. {
  134. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  135. struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
  136. /* disable the PLL */
  137. return codec_dai->dai_ops.set_pll(codec_dai, WM8753_PLL1, 0, 0);
  138. }
  139. /*
  140. * Neo1973 WM8753 HiFi DAI opserations.
  141. */
  142. static struct snd_soc_ops neo1973_hifi_ops = {
  143. .hw_params = neo1973_hifi_hw_params,
  144. .hw_free = neo1973_hifi_hw_free,
  145. };
  146. static int neo1973_voice_hw_params(struct snd_pcm_substream *substream,
  147. struct snd_pcm_hw_params *params)
  148. {
  149. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  150. struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
  151. unsigned int pcmdiv = 0;
  152. int ret = 0;
  153. unsigned long iis_clkrate;
  154. iis_clkrate = s3c24xx_i2s_get_clockrate();
  155. if (params_rate(params) != 8000)
  156. return -EINVAL;
  157. if (params_channels(params) != 1)
  158. return -EINVAL;
  159. pcmdiv = WM8753_PCM_DIV_6; /* 2.048 MHz */
  160. /* todo: gg check mode (DSP_B) against CSR datasheet */
  161. /* set codec DAI configuration */
  162. ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B |
  163. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
  164. if (ret < 0)
  165. return ret;
  166. /* set the codec system clock for DAC and ADC */
  167. ret = codec_dai->dai_ops.set_sysclk(codec_dai, WM8753_PCMCLK, 12288000,
  168. SND_SOC_CLOCK_IN);
  169. if (ret < 0)
  170. return ret;
  171. /* set codec PCM division for sample rate */
  172. ret = codec_dai->dai_ops.set_clkdiv(codec_dai, WM8753_PCMDIV, pcmdiv);
  173. if (ret < 0)
  174. return ret;
  175. /* configue and enable PLL for 12.288MHz output */
  176. ret = codec_dai->dai_ops.set_pll(codec_dai, WM8753_PLL2,
  177. iis_clkrate / 4, 12288000);
  178. if (ret < 0)
  179. return ret;
  180. return 0;
  181. }
  182. static int neo1973_voice_hw_free(struct snd_pcm_substream *substream)
  183. {
  184. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  185. struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
  186. /* disable the PLL */
  187. return codec_dai->dai_ops.set_pll(codec_dai, WM8753_PLL2, 0, 0);
  188. }
  189. static struct snd_soc_ops neo1973_voice_ops = {
  190. .hw_params = neo1973_voice_hw_params,
  191. .hw_free = neo1973_voice_hw_free,
  192. };
  193. static int neo1973_scenario = 0;
  194. static int neo1973_get_scenario(struct snd_kcontrol *kcontrol,
  195. struct snd_ctl_elem_value *ucontrol)
  196. {
  197. ucontrol->value.integer.value[0] = neo1973_scenario;
  198. return 0;
  199. }
  200. static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario)
  201. {
  202. switch(neo1973_scenario) {
  203. case NEO_AUDIO_OFF:
  204. snd_soc_dapm_set_endpoint(codec, "Audio Out", 0);
  205. snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
  206. snd_soc_dapm_set_endpoint(codec, "GSM Line In", 0);
  207. snd_soc_dapm_set_endpoint(codec, "Headset Mic", 0);
  208. snd_soc_dapm_set_endpoint(codec, "Call Mic", 0);
  209. break;
  210. case NEO_GSM_CALL_AUDIO_HANDSET:
  211. snd_soc_dapm_set_endpoint(codec, "Audio Out", 1);
  212. snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 1);
  213. snd_soc_dapm_set_endpoint(codec, "GSM Line In", 1);
  214. snd_soc_dapm_set_endpoint(codec, "Headset Mic", 0);
  215. snd_soc_dapm_set_endpoint(codec, "Call Mic", 1);
  216. break;
  217. case NEO_GSM_CALL_AUDIO_HEADSET:
  218. snd_soc_dapm_set_endpoint(codec, "Audio Out", 1);
  219. snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 1);
  220. snd_soc_dapm_set_endpoint(codec, "GSM Line In", 1);
  221. snd_soc_dapm_set_endpoint(codec, "Headset Mic", 1);
  222. snd_soc_dapm_set_endpoint(codec, "Call Mic", 0);
  223. break;
  224. case NEO_GSM_CALL_AUDIO_BLUETOOTH:
  225. snd_soc_dapm_set_endpoint(codec, "Audio Out", 0);
  226. snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 1);
  227. snd_soc_dapm_set_endpoint(codec, "GSM Line In", 1);
  228. snd_soc_dapm_set_endpoint(codec, "Headset Mic", 0);
  229. snd_soc_dapm_set_endpoint(codec, "Call Mic", 0);
  230. break;
  231. case NEO_STEREO_TO_SPEAKERS:
  232. snd_soc_dapm_set_endpoint(codec, "Audio Out", 1);
  233. snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
  234. snd_soc_dapm_set_endpoint(codec, "GSM Line In", 0);
  235. snd_soc_dapm_set_endpoint(codec, "Headset Mic", 0);
  236. snd_soc_dapm_set_endpoint(codec, "Call Mic", 0);
  237. break;
  238. case NEO_STEREO_TO_HEADPHONES:
  239. snd_soc_dapm_set_endpoint(codec, "Audio Out", 1);
  240. snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
  241. snd_soc_dapm_set_endpoint(codec, "GSM Line In", 0);
  242. snd_soc_dapm_set_endpoint(codec, "Headset Mic", 0);
  243. snd_soc_dapm_set_endpoint(codec, "Call Mic", 0);
  244. break;
  245. case NEO_CAPTURE_HANDSET:
  246. snd_soc_dapm_set_endpoint(codec, "Audio Out", 0);
  247. snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
  248. snd_soc_dapm_set_endpoint(codec, "GSM Line In", 0);
  249. snd_soc_dapm_set_endpoint(codec, "Headset Mic", 0);
  250. snd_soc_dapm_set_endpoint(codec, "Call Mic", 1);
  251. break;
  252. case NEO_CAPTURE_HEADSET:
  253. snd_soc_dapm_set_endpoint(codec, "Audio Out", 0);
  254. snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
  255. snd_soc_dapm_set_endpoint(codec, "GSM Line In", 0);
  256. snd_soc_dapm_set_endpoint(codec, "Headset Mic", 1);
  257. snd_soc_dapm_set_endpoint(codec, "Call Mic", 0);
  258. break;
  259. case NEO_CAPTURE_BLUETOOTH:
  260. snd_soc_dapm_set_endpoint(codec, "Audio Out", 0);
  261. snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
  262. snd_soc_dapm_set_endpoint(codec, "GSM Line In", 0);
  263. snd_soc_dapm_set_endpoint(codec, "Headset Mic", 0);
  264. snd_soc_dapm_set_endpoint(codec, "Call Mic", 0);
  265. break;
  266. default:
  267. snd_soc_dapm_set_endpoint(codec, "Audio Out", 0);
  268. snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
  269. snd_soc_dapm_set_endpoint(codec, "GSM Line In", 0);
  270. snd_soc_dapm_set_endpoint(codec, "Headset Mic", 0);
  271. snd_soc_dapm_set_endpoint(codec, "Call Mic", 0);
  272. }
  273. snd_soc_dapm_sync_endpoints(codec);
  274. return 0;
  275. }
  276. static int neo1973_set_scenario(struct snd_kcontrol *kcontrol,
  277. struct snd_ctl_elem_value *ucontrol)
  278. {
  279. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  280. if (neo1973_scenario == ucontrol->value.integer.value[0])
  281. return 0;
  282. neo1973_scenario = ucontrol->value.integer.value[0];
  283. set_scenario_endpoints(codec, neo1973_scenario);
  284. return 1;
  285. }
  286. static u8 lm4857_regs[4] = {0x00, 0x40, 0x80, 0xC0};
  287. static void lm4857_write_regs(void)
  288. {
  289. if (i2c_master_send(i2c, lm4857_regs, 4) != 4)
  290. printk(KERN_ERR "lm4857: i2c write failed\n");
  291. }
  292. static int lm4857_get_reg(struct snd_kcontrol *kcontrol,
  293. struct snd_ctl_elem_value *ucontrol)
  294. {
  295. int reg=kcontrol->private_value & 0xFF;
  296. int shift = (kcontrol->private_value >> 8) & 0x0F;
  297. int mask = (kcontrol->private_value >> 16) & 0xFF;
  298. ucontrol->value.integer.value[0] = (lm4857_regs[reg] >> shift) & mask;
  299. return 0;
  300. }
  301. static int lm4857_set_reg(struct snd_kcontrol *kcontrol,
  302. struct snd_ctl_elem_value *ucontrol)
  303. {
  304. int reg = kcontrol->private_value & 0xFF;
  305. int shift = (kcontrol->private_value >> 8) & 0x0F;
  306. int mask = (kcontrol->private_value >> 16) & 0xFF;
  307. if (((lm4857_regs[reg] >> shift ) & mask) ==
  308. ucontrol->value.integer.value[0])
  309. return 0;
  310. lm4857_regs[reg] &= ~ (mask << shift);
  311. lm4857_regs[reg] |= ucontrol->value.integer.value[0] << shift;
  312. lm4857_write_regs();
  313. return 1;
  314. }
  315. static int lm4857_get_mode(struct snd_kcontrol *kcontrol,
  316. struct snd_ctl_elem_value *ucontrol)
  317. {
  318. u8 value = lm4857_regs[LM4857_CTRL] & 0x0F;
  319. if (value)
  320. value -= 5;
  321. ucontrol->value.integer.value[0] = value;
  322. return 0;
  323. }
  324. static int lm4857_set_mode(struct snd_kcontrol *kcontrol,
  325. struct snd_ctl_elem_value *ucontrol)
  326. {
  327. u8 value = ucontrol->value.integer.value[0];
  328. if (value)
  329. value += 5;
  330. if ((lm4857_regs[LM4857_CTRL] & 0x0F) == value)
  331. return 0;
  332. lm4857_regs[LM4857_CTRL] &= 0xF0;
  333. lm4857_regs[LM4857_CTRL] |= value;
  334. lm4857_write_regs();
  335. return 1;
  336. }
  337. static const struct snd_soc_dapm_widget wm8753_dapm_widgets[] = {
  338. SND_SOC_DAPM_LINE("Audio Out", NULL),
  339. SND_SOC_DAPM_LINE("GSM Line Out", NULL),
  340. SND_SOC_DAPM_LINE("GSM Line In", NULL),
  341. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  342. SND_SOC_DAPM_MIC("Call Mic", NULL),
  343. };
  344. /* example machine audio_mapnections */
  345. static const char* audio_map[][3] = {
  346. /* Connections to the lm4857 amp */
  347. {"Audio Out", NULL, "LOUT1"},
  348. {"Audio Out", NULL, "ROUT1"},
  349. /* Connections to the GSM Module */
  350. {"GSM Line Out", NULL, "MONO1"},
  351. {"GSM Line Out", NULL, "MONO2"},
  352. {"RXP", NULL, "GSM Line In"},
  353. {"RXN", NULL, "GSM Line In"},
  354. /* Connections to Headset */
  355. {"MIC1", NULL, "Mic Bias"},
  356. {"Mic Bias", NULL, "Headset Mic"},
  357. /* Call Mic */
  358. {"MIC2", NULL, "Mic Bias"},
  359. {"MIC2N", NULL, "Mic Bias"},
  360. {"Mic Bias", NULL, "Call Mic"},
  361. /* Connect the ALC pins */
  362. {"ACIN", NULL, "ACOP"},
  363. {NULL, NULL, NULL},
  364. };
  365. static const char *lm4857_mode[] = {
  366. "Off",
  367. "Call Speaker",
  368. "Stereo Speakers",
  369. "Stereo Speakers + Headphones",
  370. "Headphones"
  371. };
  372. static const struct soc_enum lm4857_mode_enum[] = {
  373. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lm4857_mode), lm4857_mode),
  374. };
  375. static const char *neo_scenarios[] = {
  376. "Off",
  377. "GSM Handset",
  378. "GSM Headset",
  379. "GSM Bluetooth",
  380. "Speakers",
  381. "Headphones",
  382. "Capture Handset",
  383. "Capture Headset",
  384. "Capture Bluetooth"
  385. };
  386. static const struct soc_enum neo_scenario_enum[] = {
  387. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(neo_scenarios),neo_scenarios),
  388. };
  389. static const struct snd_kcontrol_new wm8753_neo1973_controls[] = {
  390. SOC_SINGLE_EXT("Amp Left Playback Volume", LM4857_LVOL, 0, 31, 0,
  391. lm4857_get_reg, lm4857_set_reg),
  392. SOC_SINGLE_EXT("Amp Right Playback Volume", LM4857_RVOL, 0, 31, 0,
  393. lm4857_get_reg, lm4857_set_reg),
  394. SOC_SINGLE_EXT("Amp Mono Playback Volume", LM4857_MVOL, 0, 31, 0,
  395. lm4857_get_reg, lm4857_set_reg),
  396. SOC_ENUM_EXT("Amp Mode", lm4857_mode_enum[0],
  397. lm4857_get_mode, lm4857_set_mode),
  398. SOC_ENUM_EXT("Neo Mode", neo_scenario_enum[0],
  399. neo1973_get_scenario, neo1973_set_scenario),
  400. SOC_SINGLE_EXT("Amp Spk 3D Playback Switch", LM4857_LVOL, 5, 1, 0,
  401. lm4857_get_reg, lm4857_set_reg),
  402. SOC_SINGLE_EXT("Amp HP 3d Playback Switch", LM4857_RVOL, 5, 1, 0,
  403. lm4857_get_reg, lm4857_set_reg),
  404. SOC_SINGLE_EXT("Amp Fast Wakeup Playback Switch", LM4857_CTRL, 5, 1, 0,
  405. lm4857_get_reg, lm4857_set_reg),
  406. SOC_SINGLE_EXT("Amp Earpiece 6dB Playback Switch", LM4857_CTRL, 4, 1, 0,
  407. lm4857_get_reg, lm4857_set_reg),
  408. };
  409. /*
  410. * This is an example machine initialisation for a wm8753 connected to a
  411. * neo1973 II. It is missing logic to detect hp/mic insertions and logic
  412. * to re-route the audio in such an event.
  413. */
  414. static int neo1973_wm8753_init(struct snd_soc_codec *codec)
  415. {
  416. int i, err;
  417. /* set up NC codec pins */
  418. snd_soc_dapm_set_endpoint(codec, "LOUT2", 0);
  419. snd_soc_dapm_set_endpoint(codec, "ROUT2", 0);
  420. snd_soc_dapm_set_endpoint(codec, "OUT3", 0);
  421. snd_soc_dapm_set_endpoint(codec, "OUT4", 0);
  422. snd_soc_dapm_set_endpoint(codec, "LINE1", 0);
  423. snd_soc_dapm_set_endpoint(codec, "LINE2", 0);
  424. /* set endpoints to default mode */
  425. set_scenario_endpoints(codec, NEO_AUDIO_OFF);
  426. /* Add neo1973 specific widgets */
  427. for (i = 0; i < ARRAY_SIZE(wm8753_dapm_widgets); i++)
  428. snd_soc_dapm_new_control(codec, &wm8753_dapm_widgets[i]);
  429. /* add neo1973 specific controls */
  430. for (i = 0; i < ARRAY_SIZE(wm8753_neo1973_controls); i++) {
  431. err = snd_ctl_add(codec->card,
  432. snd_soc_cnew(&wm8753_neo1973_controls[i],
  433. codec, NULL));
  434. if (err < 0)
  435. return err;
  436. }
  437. /* set up neo1973 specific audio path audio_mapnects */
  438. for (i = 0; audio_map[i][0] != NULL; i++) {
  439. snd_soc_dapm_connect_input(codec, audio_map[i][0],
  440. audio_map[i][1], audio_map[i][2]);
  441. }
  442. snd_soc_dapm_sync_endpoints(codec);
  443. return 0;
  444. }
  445. /*
  446. * BT Codec DAI
  447. */
  448. static struct snd_soc_cpu_dai bt_dai =
  449. { .name = "Bluetooth",
  450. .id = 0,
  451. .type = SND_SOC_DAI_PCM,
  452. .playback = {
  453. .channels_min = 1,
  454. .channels_max = 1,
  455. .rates = SNDRV_PCM_RATE_8000,
  456. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  457. .capture = {
  458. .channels_min = 1,
  459. .channels_max = 1,
  460. .rates = SNDRV_PCM_RATE_8000,
  461. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  462. };
  463. static struct snd_soc_dai_link neo1973_dai[] = {
  464. { /* Hifi Playback - for similatious use with voice below */
  465. .name = "WM8753",
  466. .stream_name = "WM8753 HiFi",
  467. .cpu_dai = &s3c24xx_i2s_dai,
  468. .codec_dai = &wm8753_dai[WM8753_DAI_HIFI],
  469. .init = neo1973_wm8753_init,
  470. .ops = &neo1973_hifi_ops,
  471. },
  472. { /* Voice via BT */
  473. .name = "Bluetooth",
  474. .stream_name = "Voice",
  475. .cpu_dai = &bt_dai,
  476. .codec_dai = &wm8753_dai[WM8753_DAI_VOICE],
  477. .ops = &neo1973_voice_ops,
  478. },
  479. };
  480. static struct snd_soc_machine neo1973 = {
  481. .name = "neo1973",
  482. .dai_link = neo1973_dai,
  483. .num_links = ARRAY_SIZE(neo1973_dai),
  484. };
  485. static struct wm8753_setup_data neo1973_wm8753_setup = {
  486. .i2c_address = 0x1a,
  487. };
  488. static struct snd_soc_device neo1973_snd_devdata = {
  489. .machine = &neo1973,
  490. .platform = &s3c24xx_soc_platform,
  491. .codec_dev = &soc_codec_dev_wm8753,
  492. .codec_data = &neo1973_wm8753_setup,
  493. };
  494. static struct i2c_client client_template;
  495. static unsigned short normal_i2c[] = { 0x7C, I2C_CLIENT_END };
  496. /* Magic definition of all other variables and things */
  497. I2C_CLIENT_INSMOD;
  498. static int lm4857_amp_probe(struct i2c_adapter *adap, int addr, int kind)
  499. {
  500. int ret;
  501. client_template.adapter = adap;
  502. client_template.addr = addr;
  503. i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
  504. if (i2c == NULL)
  505. return -ENOMEM;
  506. ret = i2c_attach_client(i2c);
  507. if (ret < 0) {
  508. printk(KERN_ERR "LM4857 failed to attach at addr %x\n", addr);
  509. goto exit_err;
  510. }
  511. lm4857_write_regs();
  512. return ret;
  513. exit_err:
  514. kfree(i2c);
  515. return ret;
  516. }
  517. static int lm4857_i2c_detach(struct i2c_client *client)
  518. {
  519. i2c_detach_client(client);
  520. kfree(client);
  521. return 0;
  522. }
  523. static int lm4857_i2c_attach(struct i2c_adapter *adap)
  524. {
  525. return i2c_probe(adap, &addr_data, lm4857_amp_probe);
  526. }
  527. /* corgi i2c codec control layer */
  528. static struct i2c_driver lm4857_i2c_driver = {
  529. .driver = {
  530. .name = "LM4857 I2C Amp",
  531. .owner = THIS_MODULE,
  532. },
  533. .id = I2C_DRIVERID_LM4857,
  534. .attach_adapter = lm4857_i2c_attach,
  535. .detach_client = lm4857_i2c_detach,
  536. .command = NULL,
  537. };
  538. static struct i2c_client client_template = {
  539. .name = "LM4857",
  540. .driver = &lm4857_i2c_driver,
  541. };
  542. static struct platform_device *neo1973_snd_device;
  543. static int __init neo1973_init(void)
  544. {
  545. int ret;
  546. neo1973_snd_device = platform_device_alloc("soc-audio", -1);
  547. if (!neo1973_snd_device)
  548. return -ENOMEM;
  549. platform_set_drvdata(neo1973_snd_device, &neo1973_snd_devdata);
  550. neo1973_snd_devdata.dev = &neo1973_snd_device->dev;
  551. ret = platform_device_add(neo1973_snd_device);
  552. if (ret)
  553. platform_device_put(neo1973_snd_device);
  554. ret = i2c_add_driver(&lm4857_i2c_driver);
  555. if (ret != 0)
  556. printk(KERN_ERR "can't add i2c driver");
  557. return ret;
  558. }
  559. static void __exit neo1973_exit(void)
  560. {
  561. platform_device_unregister(neo1973_snd_device);
  562. }
  563. module_init(neo1973_init);
  564. module_exit(neo1973_exit);
  565. /* Module information */
  566. MODULE_AUTHOR("Graeme Gregory, graeme.gregory@wolfsonmicro.com, www.wolfsonmicro.com");
  567. MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973");
  568. MODULE_LICENSE("GPL");