neo1973_wm8753.c 19 KB

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