neo1973_wm8753.c 18 KB

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