ams-delta.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * ams-delta.c -- SoC audio for Amstrad E3 (Delta) videophone
  3. *
  4. * Copyright (C) 2009 Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
  5. *
  6. * Initially based on sound/soc/omap/osk5912.x
  7. * Copyright (C) 2008 Mistral Solutions
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. #include <linux/gpio.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/tty.h>
  27. #include <linux/module.h>
  28. #include <sound/soc.h>
  29. #include <sound/jack.h>
  30. #include <asm/mach-types.h>
  31. #include <plat/board-ams-delta.h>
  32. #include <plat/mcbsp.h>
  33. #include "omap-mcbsp.h"
  34. #include "omap-pcm.h"
  35. #include "../codecs/cx20442.h"
  36. /* Board specific DAPM widgets */
  37. static const struct snd_soc_dapm_widget ams_delta_dapm_widgets[] = {
  38. /* Handset */
  39. SND_SOC_DAPM_MIC("Mouthpiece", NULL),
  40. SND_SOC_DAPM_HP("Earpiece", NULL),
  41. /* Handsfree/Speakerphone */
  42. SND_SOC_DAPM_MIC("Microphone", NULL),
  43. SND_SOC_DAPM_SPK("Speaker", NULL),
  44. };
  45. /* How they are connected to codec pins */
  46. static const struct snd_soc_dapm_route ams_delta_audio_map[] = {
  47. {"TELIN", NULL, "Mouthpiece"},
  48. {"Earpiece", NULL, "TELOUT"},
  49. {"MIC", NULL, "Microphone"},
  50. {"Speaker", NULL, "SPKOUT"},
  51. };
  52. /*
  53. * Controls, functional after the modem line discipline is activated.
  54. */
  55. /* Virtual switch: audio input/output constellations */
  56. static const char *ams_delta_audio_mode[] =
  57. {"Mixed", "Handset", "Handsfree", "Speakerphone"};
  58. /* Selection <-> pin translation */
  59. #define AMS_DELTA_MOUTHPIECE 0
  60. #define AMS_DELTA_EARPIECE 1
  61. #define AMS_DELTA_MICROPHONE 2
  62. #define AMS_DELTA_SPEAKER 3
  63. #define AMS_DELTA_AGC 4
  64. #define AMS_DELTA_MIXED ((1 << AMS_DELTA_EARPIECE) | \
  65. (1 << AMS_DELTA_MICROPHONE))
  66. #define AMS_DELTA_HANDSET ((1 << AMS_DELTA_MOUTHPIECE) | \
  67. (1 << AMS_DELTA_EARPIECE))
  68. #define AMS_DELTA_HANDSFREE ((1 << AMS_DELTA_MICROPHONE) | \
  69. (1 << AMS_DELTA_SPEAKER))
  70. #define AMS_DELTA_SPEAKERPHONE (AMS_DELTA_HANDSFREE | (1 << AMS_DELTA_AGC))
  71. static const unsigned short ams_delta_audio_mode_pins[] = {
  72. AMS_DELTA_MIXED,
  73. AMS_DELTA_HANDSET,
  74. AMS_DELTA_HANDSFREE,
  75. AMS_DELTA_SPEAKERPHONE,
  76. };
  77. static unsigned short ams_delta_audio_agc;
  78. static int ams_delta_set_audio_mode(struct snd_kcontrol *kcontrol,
  79. struct snd_ctl_elem_value *ucontrol)
  80. {
  81. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  82. struct snd_soc_dapm_context *dapm = &codec->dapm;
  83. struct soc_enum *control = (struct soc_enum *)kcontrol->private_value;
  84. unsigned short pins;
  85. int pin, changed = 0;
  86. /* Refuse any mode changes if we are not able to control the codec. */
  87. if (!codec->hw_write)
  88. return -EUNATCH;
  89. if (ucontrol->value.enumerated.item[0] >= control->max)
  90. return -EINVAL;
  91. mutex_lock(&codec->mutex);
  92. /* Translate selection to bitmap */
  93. pins = ams_delta_audio_mode_pins[ucontrol->value.enumerated.item[0]];
  94. /* Setup pins after corresponding bits if changed */
  95. pin = !!(pins & (1 << AMS_DELTA_MOUTHPIECE));
  96. if (pin != snd_soc_dapm_get_pin_status(dapm, "Mouthpiece")) {
  97. changed = 1;
  98. if (pin)
  99. snd_soc_dapm_enable_pin(dapm, "Mouthpiece");
  100. else
  101. snd_soc_dapm_disable_pin(dapm, "Mouthpiece");
  102. }
  103. pin = !!(pins & (1 << AMS_DELTA_EARPIECE));
  104. if (pin != snd_soc_dapm_get_pin_status(dapm, "Earpiece")) {
  105. changed = 1;
  106. if (pin)
  107. snd_soc_dapm_enable_pin(dapm, "Earpiece");
  108. else
  109. snd_soc_dapm_disable_pin(dapm, "Earpiece");
  110. }
  111. pin = !!(pins & (1 << AMS_DELTA_MICROPHONE));
  112. if (pin != snd_soc_dapm_get_pin_status(dapm, "Microphone")) {
  113. changed = 1;
  114. if (pin)
  115. snd_soc_dapm_enable_pin(dapm, "Microphone");
  116. else
  117. snd_soc_dapm_disable_pin(dapm, "Microphone");
  118. }
  119. pin = !!(pins & (1 << AMS_DELTA_SPEAKER));
  120. if (pin != snd_soc_dapm_get_pin_status(dapm, "Speaker")) {
  121. changed = 1;
  122. if (pin)
  123. snd_soc_dapm_enable_pin(dapm, "Speaker");
  124. else
  125. snd_soc_dapm_disable_pin(dapm, "Speaker");
  126. }
  127. pin = !!(pins & (1 << AMS_DELTA_AGC));
  128. if (pin != ams_delta_audio_agc) {
  129. ams_delta_audio_agc = pin;
  130. changed = 1;
  131. if (pin)
  132. snd_soc_dapm_enable_pin(dapm, "AGCIN");
  133. else
  134. snd_soc_dapm_disable_pin(dapm, "AGCIN");
  135. }
  136. if (changed)
  137. snd_soc_dapm_sync(dapm);
  138. mutex_unlock(&codec->mutex);
  139. return changed;
  140. }
  141. static int ams_delta_get_audio_mode(struct snd_kcontrol *kcontrol,
  142. struct snd_ctl_elem_value *ucontrol)
  143. {
  144. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  145. struct snd_soc_dapm_context *dapm = &codec->dapm;
  146. unsigned short pins, mode;
  147. pins = ((snd_soc_dapm_get_pin_status(dapm, "Mouthpiece") <<
  148. AMS_DELTA_MOUTHPIECE) |
  149. (snd_soc_dapm_get_pin_status(dapm, "Earpiece") <<
  150. AMS_DELTA_EARPIECE));
  151. if (pins)
  152. pins |= (snd_soc_dapm_get_pin_status(dapm, "Microphone") <<
  153. AMS_DELTA_MICROPHONE);
  154. else
  155. pins = ((snd_soc_dapm_get_pin_status(dapm, "Microphone") <<
  156. AMS_DELTA_MICROPHONE) |
  157. (snd_soc_dapm_get_pin_status(dapm, "Speaker") <<
  158. AMS_DELTA_SPEAKER) |
  159. (ams_delta_audio_agc << AMS_DELTA_AGC));
  160. for (mode = 0; mode < ARRAY_SIZE(ams_delta_audio_mode); mode++)
  161. if (pins == ams_delta_audio_mode_pins[mode])
  162. break;
  163. if (mode >= ARRAY_SIZE(ams_delta_audio_mode))
  164. return -EINVAL;
  165. ucontrol->value.enumerated.item[0] = mode;
  166. return 0;
  167. }
  168. static const struct soc_enum ams_delta_audio_enum[] = {
  169. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(ams_delta_audio_mode),
  170. ams_delta_audio_mode),
  171. };
  172. static const struct snd_kcontrol_new ams_delta_audio_controls[] = {
  173. SOC_ENUM_EXT("Audio Mode", ams_delta_audio_enum[0],
  174. ams_delta_get_audio_mode, ams_delta_set_audio_mode),
  175. };
  176. /* Hook switch */
  177. static struct snd_soc_jack ams_delta_hook_switch;
  178. static struct snd_soc_jack_gpio ams_delta_hook_switch_gpios[] = {
  179. {
  180. .gpio = 4,
  181. .name = "hook_switch",
  182. .report = SND_JACK_HEADSET,
  183. .invert = 1,
  184. .debounce_time = 150,
  185. }
  186. };
  187. /* After we are able to control the codec over the modem,
  188. * the hook switch can be used for dynamic DAPM reconfiguration. */
  189. static struct snd_soc_jack_pin ams_delta_hook_switch_pins[] = {
  190. /* Handset */
  191. {
  192. .pin = "Mouthpiece",
  193. .mask = SND_JACK_MICROPHONE,
  194. },
  195. {
  196. .pin = "Earpiece",
  197. .mask = SND_JACK_HEADPHONE,
  198. },
  199. /* Handsfree */
  200. {
  201. .pin = "Microphone",
  202. .mask = SND_JACK_MICROPHONE,
  203. .invert = 1,
  204. },
  205. {
  206. .pin = "Speaker",
  207. .mask = SND_JACK_HEADPHONE,
  208. .invert = 1,
  209. },
  210. };
  211. /*
  212. * Modem line discipline, required for making above controls functional.
  213. * Activated from userspace with ldattach, possibly invoked from udev rule.
  214. */
  215. /* To actually apply any modem controlled configuration changes to the codec,
  216. * we must connect codec DAI pins to the modem for a moment. Be careful not
  217. * to interfere with our digital mute function that shares the same hardware. */
  218. static struct timer_list cx81801_timer;
  219. static bool cx81801_cmd_pending;
  220. static bool ams_delta_muted;
  221. static DEFINE_SPINLOCK(ams_delta_lock);
  222. static void cx81801_timeout(unsigned long data)
  223. {
  224. int muted;
  225. spin_lock(&ams_delta_lock);
  226. cx81801_cmd_pending = 0;
  227. muted = ams_delta_muted;
  228. spin_unlock(&ams_delta_lock);
  229. /* Reconnect the codec DAI back from the modem to the CPU DAI
  230. * only if digital mute still off */
  231. if (!muted)
  232. ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_CODEC, 0);
  233. }
  234. /*
  235. * Used for passing a codec structure pointer
  236. * from the board initialization code to the tty line discipline.
  237. */
  238. static struct snd_soc_codec *cx20442_codec;
  239. /* Line discipline .open() */
  240. static int cx81801_open(struct tty_struct *tty)
  241. {
  242. int ret;
  243. if (!cx20442_codec)
  244. return -ENODEV;
  245. /*
  246. * Pass the codec structure pointer for use by other ldisc callbacks,
  247. * both the card and the codec specific parts.
  248. */
  249. tty->disc_data = cx20442_codec;
  250. ret = v253_ops.open(tty);
  251. if (ret < 0)
  252. tty->disc_data = NULL;
  253. return ret;
  254. }
  255. /* Line discipline .close() */
  256. static void cx81801_close(struct tty_struct *tty)
  257. {
  258. struct snd_soc_codec *codec = tty->disc_data;
  259. struct snd_soc_dapm_context *dapm = &codec->dapm;
  260. del_timer_sync(&cx81801_timer);
  261. /* Prevent the hook switch from further changing the DAPM pins */
  262. INIT_LIST_HEAD(&ams_delta_hook_switch.pins);
  263. if (!codec)
  264. return;
  265. v253_ops.close(tty);
  266. /* Revert back to default audio input/output constellation */
  267. snd_soc_dapm_disable_pin(dapm, "Mouthpiece");
  268. snd_soc_dapm_enable_pin(dapm, "Earpiece");
  269. snd_soc_dapm_enable_pin(dapm, "Microphone");
  270. snd_soc_dapm_disable_pin(dapm, "Speaker");
  271. snd_soc_dapm_disable_pin(dapm, "AGCIN");
  272. snd_soc_dapm_sync(dapm);
  273. }
  274. /* Line discipline .hangup() */
  275. static int cx81801_hangup(struct tty_struct *tty)
  276. {
  277. cx81801_close(tty);
  278. return 0;
  279. }
  280. /* Line discipline .receive_buf() */
  281. static void cx81801_receive(struct tty_struct *tty,
  282. const unsigned char *cp, char *fp, int count)
  283. {
  284. struct snd_soc_codec *codec = tty->disc_data;
  285. const unsigned char *c;
  286. int apply, ret;
  287. if (!codec)
  288. return;
  289. if (!codec->hw_write) {
  290. /* First modem response, complete setup procedure */
  291. /* Initialize timer used for config pulse generation */
  292. setup_timer(&cx81801_timer, cx81801_timeout, 0);
  293. v253_ops.receive_buf(tty, cp, fp, count);
  294. /* Link hook switch to DAPM pins */
  295. ret = snd_soc_jack_add_pins(&ams_delta_hook_switch,
  296. ARRAY_SIZE(ams_delta_hook_switch_pins),
  297. ams_delta_hook_switch_pins);
  298. if (ret)
  299. dev_warn(codec->dev,
  300. "Failed to link hook switch to DAPM pins, "
  301. "will continue with hook switch unlinked.\n");
  302. return;
  303. }
  304. v253_ops.receive_buf(tty, cp, fp, count);
  305. for (c = &cp[count - 1]; c >= cp; c--) {
  306. if (*c != '\r')
  307. continue;
  308. /* Complete modem response received, apply config to codec */
  309. spin_lock_bh(&ams_delta_lock);
  310. mod_timer(&cx81801_timer, jiffies + msecs_to_jiffies(150));
  311. apply = !ams_delta_muted && !cx81801_cmd_pending;
  312. cx81801_cmd_pending = 1;
  313. spin_unlock_bh(&ams_delta_lock);
  314. /* Apply config pulse by connecting the codec to the modem
  315. * if not already done */
  316. if (apply)
  317. ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_CODEC,
  318. AMS_DELTA_LATCH2_MODEM_CODEC);
  319. break;
  320. }
  321. }
  322. /* Line discipline .write_wakeup() */
  323. static void cx81801_wakeup(struct tty_struct *tty)
  324. {
  325. v253_ops.write_wakeup(tty);
  326. }
  327. static struct tty_ldisc_ops cx81801_ops = {
  328. .magic = TTY_LDISC_MAGIC,
  329. .name = "cx81801",
  330. .owner = THIS_MODULE,
  331. .open = cx81801_open,
  332. .close = cx81801_close,
  333. .hangup = cx81801_hangup,
  334. .receive_buf = cx81801_receive,
  335. .write_wakeup = cx81801_wakeup,
  336. };
  337. /*
  338. * Even if not very useful, the sound card can still work without any of the
  339. * above functonality activated. You can still control its audio input/output
  340. * constellation and speakerphone gain from userspace by issuing AT commands
  341. * over the modem port.
  342. */
  343. static int ams_delta_hw_params(struct snd_pcm_substream *substream,
  344. struct snd_pcm_hw_params *params)
  345. {
  346. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  347. /* Set cpu DAI configuration */
  348. return snd_soc_dai_set_fmt(rtd->cpu_dai,
  349. SND_SOC_DAIFMT_DSP_A |
  350. SND_SOC_DAIFMT_NB_NF |
  351. SND_SOC_DAIFMT_CBM_CFM);
  352. }
  353. static struct snd_soc_ops ams_delta_ops = {
  354. .hw_params = ams_delta_hw_params,
  355. };
  356. /* Board specific codec bias level control */
  357. static int ams_delta_set_bias_level(struct snd_soc_card *card,
  358. struct snd_soc_dapm_context *dapm,
  359. enum snd_soc_bias_level level)
  360. {
  361. switch (level) {
  362. case SND_SOC_BIAS_ON:
  363. case SND_SOC_BIAS_PREPARE:
  364. case SND_SOC_BIAS_STANDBY:
  365. if (card->dapm.bias_level == SND_SOC_BIAS_OFF)
  366. ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_NRESET,
  367. AMS_DELTA_LATCH2_MODEM_NRESET);
  368. break;
  369. case SND_SOC_BIAS_OFF:
  370. if (card->dapm.bias_level != SND_SOC_BIAS_OFF)
  371. ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_NRESET,
  372. 0);
  373. }
  374. card->dapm.bias_level = level;
  375. return 0;
  376. }
  377. /* Digital mute implemented using modem/CPU multiplexer.
  378. * Shares hardware with codec config pulse generation */
  379. static bool ams_delta_muted = 1;
  380. static int ams_delta_digital_mute(struct snd_soc_dai *dai, int mute)
  381. {
  382. int apply;
  383. if (ams_delta_muted == mute)
  384. return 0;
  385. spin_lock_bh(&ams_delta_lock);
  386. ams_delta_muted = mute;
  387. apply = !cx81801_cmd_pending;
  388. spin_unlock_bh(&ams_delta_lock);
  389. if (apply)
  390. ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_CODEC,
  391. mute ? AMS_DELTA_LATCH2_MODEM_CODEC : 0);
  392. return 0;
  393. }
  394. /* Our codec DAI probably doesn't have its own .ops structure */
  395. static const struct snd_soc_dai_ops ams_delta_dai_ops = {
  396. .digital_mute = ams_delta_digital_mute,
  397. };
  398. /* Will be used if the codec ever has its own digital_mute function */
  399. static int ams_delta_startup(struct snd_pcm_substream *substream)
  400. {
  401. return ams_delta_digital_mute(NULL, 0);
  402. }
  403. static void ams_delta_shutdown(struct snd_pcm_substream *substream)
  404. {
  405. ams_delta_digital_mute(NULL, 1);
  406. }
  407. /*
  408. * Card initialization
  409. */
  410. static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd)
  411. {
  412. struct snd_soc_codec *codec = rtd->codec;
  413. struct snd_soc_dapm_context *dapm = &codec->dapm;
  414. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  415. struct snd_soc_card *card = rtd->card;
  416. int ret;
  417. /* Codec is ready, now add/activate board specific controls */
  418. /* Store a pointer to the codec structure for tty ldisc use */
  419. cx20442_codec = codec;
  420. /* Set up digital mute if not provided by the codec */
  421. if (!codec_dai->driver->ops) {
  422. codec_dai->driver->ops = &ams_delta_dai_ops;
  423. } else {
  424. ams_delta_ops.startup = ams_delta_startup;
  425. ams_delta_ops.shutdown = ams_delta_shutdown;
  426. }
  427. /* Set codec bias level */
  428. ams_delta_set_bias_level(card, dapm, SND_SOC_BIAS_STANDBY);
  429. /* Add hook switch - can be used to control the codec from userspace
  430. * even if line discipline fails */
  431. ret = snd_soc_jack_new(rtd->codec, "hook_switch",
  432. SND_JACK_HEADSET, &ams_delta_hook_switch);
  433. if (ret)
  434. dev_warn(card->dev,
  435. "Failed to allocate resources for hook switch, "
  436. "will continue without one.\n");
  437. else {
  438. ret = snd_soc_jack_add_gpios(&ams_delta_hook_switch,
  439. ARRAY_SIZE(ams_delta_hook_switch_gpios),
  440. ams_delta_hook_switch_gpios);
  441. if (ret)
  442. dev_warn(card->dev,
  443. "Failed to set up hook switch GPIO line, "
  444. "will continue with hook switch inactive.\n");
  445. }
  446. /* Register optional line discipline for over the modem control */
  447. ret = tty_register_ldisc(N_V253, &cx81801_ops);
  448. if (ret) {
  449. dev_warn(card->dev,
  450. "Failed to register line discipline, "
  451. "will continue without any controls.\n");
  452. return 0;
  453. }
  454. /* Add board specific DAPM widgets and routes */
  455. ret = snd_soc_dapm_new_controls(dapm, ams_delta_dapm_widgets,
  456. ARRAY_SIZE(ams_delta_dapm_widgets));
  457. if (ret) {
  458. dev_warn(card->dev,
  459. "Failed to register DAPM controls, "
  460. "will continue without any.\n");
  461. return 0;
  462. }
  463. ret = snd_soc_dapm_add_routes(dapm, ams_delta_audio_map,
  464. ARRAY_SIZE(ams_delta_audio_map));
  465. if (ret) {
  466. dev_warn(card->dev,
  467. "Failed to set up DAPM routes, "
  468. "will continue with codec default map.\n");
  469. return 0;
  470. }
  471. /* Set up initial pin constellation */
  472. snd_soc_dapm_disable_pin(dapm, "Mouthpiece");
  473. snd_soc_dapm_enable_pin(dapm, "Earpiece");
  474. snd_soc_dapm_enable_pin(dapm, "Microphone");
  475. snd_soc_dapm_disable_pin(dapm, "Speaker");
  476. snd_soc_dapm_disable_pin(dapm, "AGCIN");
  477. snd_soc_dapm_disable_pin(dapm, "AGCOUT");
  478. /* Add virtual switch */
  479. ret = snd_soc_add_codec_controls(codec, ams_delta_audio_controls,
  480. ARRAY_SIZE(ams_delta_audio_controls));
  481. if (ret)
  482. dev_warn(card->dev,
  483. "Failed to register audio mode control, "
  484. "will continue without it.\n");
  485. return 0;
  486. }
  487. /* DAI glue - connects codec <--> CPU */
  488. static struct snd_soc_dai_link ams_delta_dai_link = {
  489. .name = "CX20442",
  490. .stream_name = "CX20442",
  491. .cpu_dai_name = "omap-mcbsp.1",
  492. .codec_dai_name = "cx20442-voice",
  493. .init = ams_delta_cx20442_init,
  494. .platform_name = "omap-pcm-audio",
  495. .codec_name = "cx20442-codec",
  496. .ops = &ams_delta_ops,
  497. };
  498. /* Audio card driver */
  499. static struct snd_soc_card ams_delta_audio_card = {
  500. .name = "AMS_DELTA",
  501. .owner = THIS_MODULE,
  502. .dai_link = &ams_delta_dai_link,
  503. .num_links = 1,
  504. .set_bias_level = ams_delta_set_bias_level,
  505. };
  506. /* Module init/exit */
  507. static struct platform_device *ams_delta_audio_platform_device;
  508. static struct platform_device *cx20442_platform_device;
  509. static int __init ams_delta_module_init(void)
  510. {
  511. int ret;
  512. if (!(machine_is_ams_delta()))
  513. return -ENODEV;
  514. ams_delta_audio_platform_device =
  515. platform_device_alloc("soc-audio", -1);
  516. if (!ams_delta_audio_platform_device)
  517. return -ENOMEM;
  518. platform_set_drvdata(ams_delta_audio_platform_device,
  519. &ams_delta_audio_card);
  520. ret = platform_device_add(ams_delta_audio_platform_device);
  521. if (ret)
  522. goto err;
  523. /*
  524. * Codec platform device could be registered from elsewhere (board?),
  525. * but I do it here as it makes sense only if used with the card.
  526. */
  527. cx20442_platform_device =
  528. platform_device_register_simple("cx20442-codec", -1, NULL, 0);
  529. return 0;
  530. err:
  531. platform_device_put(ams_delta_audio_platform_device);
  532. return ret;
  533. }
  534. module_init(ams_delta_module_init);
  535. static void __exit ams_delta_module_exit(void)
  536. {
  537. if (tty_unregister_ldisc(N_V253) != 0)
  538. dev_warn(&ams_delta_audio_platform_device->dev,
  539. "failed to unregister V253 line discipline\n");
  540. snd_soc_jack_free_gpios(&ams_delta_hook_switch,
  541. ARRAY_SIZE(ams_delta_hook_switch_gpios),
  542. ams_delta_hook_switch_gpios);
  543. /* Keep modem power on */
  544. ams_delta_set_bias_level(&ams_delta_audio_card,
  545. &ams_delta_audio_card.rtd[0].codec->dapm,
  546. SND_SOC_BIAS_STANDBY);
  547. platform_device_unregister(cx20442_platform_device);
  548. platform_device_unregister(ams_delta_audio_platform_device);
  549. }
  550. module_exit(ams_delta_module_exit);
  551. MODULE_AUTHOR("Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>");
  552. MODULE_DESCRIPTION("ALSA SoC driver for Amstrad E3 (Delta) videophone");
  553. MODULE_LICENSE("GPL");