neo1973_wm8753.c 18 KB

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