neo1973_wm8753.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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. static const struct snd_soc_dapm_route dapm_routes[] = {
  361. /* Connections to the lm4857 amp */
  362. {"Audio Out", NULL, "LOUT1"},
  363. {"Audio Out", NULL, "ROUT1"},
  364. /* Connections to the GSM Module */
  365. {"GSM Line Out", NULL, "MONO1"},
  366. {"GSM Line Out", NULL, "MONO2"},
  367. {"RXP", NULL, "GSM Line In"},
  368. {"RXN", NULL, "GSM Line In"},
  369. /* Connections to Headset */
  370. {"MIC1", NULL, "Mic Bias"},
  371. {"Mic Bias", NULL, "Headset Mic"},
  372. /* Call Mic */
  373. {"MIC2", NULL, "Mic Bias"},
  374. {"MIC2N", NULL, "Mic Bias"},
  375. {"Mic Bias", NULL, "Call Mic"},
  376. /* Connect the ALC pins */
  377. {"ACIN", NULL, "ACOP"},
  378. };
  379. static const char *lm4857_mode[] = {
  380. "Off",
  381. "Call Speaker",
  382. "Stereo Speakers",
  383. "Stereo Speakers + Headphones",
  384. "Headphones"
  385. };
  386. static const struct soc_enum lm4857_mode_enum[] = {
  387. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lm4857_mode), lm4857_mode),
  388. };
  389. static const char *neo_scenarios[] = {
  390. "Off",
  391. "GSM Handset",
  392. "GSM Headset",
  393. "GSM Bluetooth",
  394. "Speakers",
  395. "Headphones",
  396. "Capture Handset",
  397. "Capture Headset",
  398. "Capture Bluetooth"
  399. };
  400. static const struct soc_enum neo_scenario_enum[] = {
  401. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(neo_scenarios), neo_scenarios),
  402. };
  403. static const struct snd_kcontrol_new wm8753_neo1973_controls[] = {
  404. SOC_SINGLE_EXT("Amp Left Playback Volume", LM4857_LVOL, 0, 31, 0,
  405. lm4857_get_reg, lm4857_set_reg),
  406. SOC_SINGLE_EXT("Amp Right Playback Volume", LM4857_RVOL, 0, 31, 0,
  407. lm4857_get_reg, lm4857_set_reg),
  408. SOC_SINGLE_EXT("Amp Mono Playback Volume", LM4857_MVOL, 0, 31, 0,
  409. lm4857_get_reg, lm4857_set_reg),
  410. SOC_ENUM_EXT("Amp Mode", lm4857_mode_enum[0],
  411. lm4857_get_mode, lm4857_set_mode),
  412. SOC_ENUM_EXT("Neo Mode", neo_scenario_enum[0],
  413. neo1973_get_scenario, neo1973_set_scenario),
  414. SOC_SINGLE_EXT("Amp Spk 3D Playback Switch", LM4857_LVOL, 5, 1, 0,
  415. lm4857_get_reg, lm4857_set_reg),
  416. SOC_SINGLE_EXT("Amp HP 3d Playback Switch", LM4857_RVOL, 5, 1, 0,
  417. lm4857_get_reg, lm4857_set_reg),
  418. SOC_SINGLE_EXT("Amp Fast Wakeup Playback Switch", LM4857_CTRL, 5, 1, 0,
  419. lm4857_get_reg, lm4857_set_reg),
  420. SOC_SINGLE_EXT("Amp Earpiece 6dB Playback Switch", LM4857_CTRL, 4, 1, 0,
  421. lm4857_get_reg, lm4857_set_reg),
  422. };
  423. /*
  424. * This is an example machine initialisation for a wm8753 connected to a
  425. * neo1973 II. It is missing logic to detect hp/mic insertions and logic
  426. * to re-route the audio in such an event.
  427. */
  428. static int neo1973_wm8753_init(struct snd_soc_codec *codec)
  429. {
  430. int i, err;
  431. DBG("Entered %s\n", __func__);
  432. /* set up NC codec pins */
  433. snd_soc_dapm_set_endpoint(codec, "LOUT2", 0);
  434. snd_soc_dapm_set_endpoint(codec, "ROUT2", 0);
  435. snd_soc_dapm_set_endpoint(codec, "OUT3", 0);
  436. snd_soc_dapm_set_endpoint(codec, "OUT4", 0);
  437. snd_soc_dapm_set_endpoint(codec, "LINE1", 0);
  438. snd_soc_dapm_set_endpoint(codec, "LINE2", 0);
  439. /* set endpoints to default mode */
  440. set_scenario_endpoints(codec, NEO_AUDIO_OFF);
  441. /* Add neo1973 specific widgets */
  442. snd_soc_dapm_new_controls(codec, wm8753_dapm_widgets,
  443. ARRAY_SIZE(wm8753_dapm_widgets));
  444. /* add neo1973 specific controls */
  445. for (i = 0; i < ARRAY_SIZE(wm8753_neo1973_controls); i++) {
  446. err = snd_ctl_add(codec->card,
  447. snd_soc_cnew(&wm8753_neo1973_controls[i],
  448. codec, NULL));
  449. if (err < 0)
  450. return err;
  451. }
  452. /* set up neo1973 specific audio routes */
  453. err = snd_soc_dapm_add_routes(codec, dapm_routes,
  454. ARRAY_SIZE(dapm_routes));
  455. snd_soc_dapm_sync_endpoints(codec);
  456. return 0;
  457. }
  458. /*
  459. * BT Codec DAI
  460. */
  461. static struct snd_soc_cpu_dai bt_dai = {
  462. .name = "Bluetooth",
  463. .id = 0,
  464. .type = SND_SOC_DAI_PCM,
  465. .playback = {
  466. .channels_min = 1,
  467. .channels_max = 1,
  468. .rates = SNDRV_PCM_RATE_8000,
  469. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  470. .capture = {
  471. .channels_min = 1,
  472. .channels_max = 1,
  473. .rates = SNDRV_PCM_RATE_8000,
  474. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  475. };
  476. static struct snd_soc_dai_link neo1973_dai[] = {
  477. { /* Hifi Playback - for similatious use with voice below */
  478. .name = "WM8753",
  479. .stream_name = "WM8753 HiFi",
  480. .cpu_dai = &s3c24xx_i2s_dai,
  481. .codec_dai = &wm8753_dai[WM8753_DAI_HIFI],
  482. .init = neo1973_wm8753_init,
  483. .ops = &neo1973_hifi_ops,
  484. },
  485. { /* Voice via BT */
  486. .name = "Bluetooth",
  487. .stream_name = "Voice",
  488. .cpu_dai = &bt_dai,
  489. .codec_dai = &wm8753_dai[WM8753_DAI_VOICE],
  490. .ops = &neo1973_voice_ops,
  491. },
  492. };
  493. static struct snd_soc_machine neo1973 = {
  494. .name = "neo1973",
  495. .dai_link = neo1973_dai,
  496. .num_links = ARRAY_SIZE(neo1973_dai),
  497. };
  498. static struct wm8753_setup_data neo1973_wm8753_setup = {
  499. .i2c_address = 0x1a,
  500. };
  501. static struct snd_soc_device neo1973_snd_devdata = {
  502. .machine = &neo1973,
  503. .platform = &s3c24xx_soc_platform,
  504. .codec_dev = &soc_codec_dev_wm8753,
  505. .codec_data = &neo1973_wm8753_setup,
  506. };
  507. static struct i2c_client client_template;
  508. static const unsigned short normal_i2c[] = { 0x7C, I2C_CLIENT_END };
  509. /* Magic definition of all other variables and things */
  510. I2C_CLIENT_INSMOD;
  511. static int lm4857_amp_probe(struct i2c_adapter *adap, int addr, int kind)
  512. {
  513. int ret;
  514. DBG("Entered %s\n", __func__);
  515. client_template.adapter = adap;
  516. client_template.addr = addr;
  517. i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
  518. if (i2c == NULL)
  519. return -ENOMEM;
  520. ret = i2c_attach_client(i2c);
  521. if (ret < 0) {
  522. printk(KERN_ERR "LM4857 failed to attach at addr %x\n", addr);
  523. goto exit_err;
  524. }
  525. lm4857_write_regs();
  526. return ret;
  527. exit_err:
  528. kfree(i2c);
  529. return ret;
  530. }
  531. static int lm4857_i2c_detach(struct i2c_client *client)
  532. {
  533. DBG("Entered %s\n", __func__);
  534. i2c_detach_client(client);
  535. kfree(client);
  536. return 0;
  537. }
  538. static int lm4857_i2c_attach(struct i2c_adapter *adap)
  539. {
  540. DBG("Entered %s\n", __func__);
  541. return i2c_probe(adap, &addr_data, lm4857_amp_probe);
  542. }
  543. static u8 lm4857_state;
  544. static int lm4857_suspend(struct i2c_client *dev, pm_message_t state)
  545. {
  546. DBG("Entered %s\n", __func__);
  547. dev_dbg(&dev->dev, "lm4857_suspend\n");
  548. lm4857_state = lm4857_regs[LM4857_CTRL] & 0xf;
  549. if (lm4857_state) {
  550. lm4857_regs[LM4857_CTRL] &= 0xf0;
  551. lm4857_write_regs();
  552. }
  553. return 0;
  554. }
  555. static int lm4857_resume(struct i2c_client *dev)
  556. {
  557. DBG("Entered %s\n", __func__);
  558. if (lm4857_state) {
  559. lm4857_regs[LM4857_CTRL] |= (lm4857_state & 0x0f);
  560. lm4857_write_regs();
  561. }
  562. return 0;
  563. }
  564. static void lm4857_shutdown(struct i2c_client *dev)
  565. {
  566. DBG("Entered %s\n", __func__);
  567. dev_dbg(&dev->dev, "lm4857_shutdown\n");
  568. lm4857_regs[LM4857_CTRL] &= 0xf0;
  569. lm4857_write_regs();
  570. }
  571. /* corgi i2c codec control layer */
  572. static struct i2c_driver lm4857_i2c_driver = {
  573. .driver = {
  574. .name = "LM4857 I2C Amp",
  575. .owner = THIS_MODULE,
  576. },
  577. .id = I2C_DRIVERID_LM4857,
  578. .suspend = lm4857_suspend,
  579. .resume = lm4857_resume,
  580. .shutdown = lm4857_shutdown,
  581. .attach_adapter = lm4857_i2c_attach,
  582. .detach_client = lm4857_i2c_detach,
  583. .command = NULL,
  584. };
  585. static struct i2c_client client_template = {
  586. .name = "LM4857",
  587. .driver = &lm4857_i2c_driver,
  588. };
  589. static struct platform_device *neo1973_snd_device;
  590. static int __init neo1973_init(void)
  591. {
  592. int ret;
  593. DBG("Entered %s\n", __func__);
  594. neo1973_snd_device = platform_device_alloc("soc-audio", -1);
  595. if (!neo1973_snd_device)
  596. return -ENOMEM;
  597. platform_set_drvdata(neo1973_snd_device, &neo1973_snd_devdata);
  598. neo1973_snd_devdata.dev = &neo1973_snd_device->dev;
  599. ret = platform_device_add(neo1973_snd_device);
  600. if (ret)
  601. platform_device_put(neo1973_snd_device);
  602. ret = i2c_add_driver(&lm4857_i2c_driver);
  603. if (ret != 0)
  604. printk(KERN_ERR "can't add i2c driver");
  605. return ret;
  606. }
  607. static void __exit neo1973_exit(void)
  608. {
  609. DBG("Entered %s\n", __func__);
  610. i2c_del_driver(&lm4857_i2c_driver);
  611. platform_device_unregister(neo1973_snd_device);
  612. }
  613. module_init(neo1973_init);
  614. module_exit(neo1973_exit);
  615. /* Module information */
  616. MODULE_AUTHOR("Graeme Gregory, graeme@openmoko.org, www.openmoko.org");
  617. MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973");
  618. MODULE_LICENSE("GPL");