ams-delta.c 17 KB

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