neo1973_wm8753.c 19 KB

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