neo1973_wm8753.c 18 KB

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