ams-delta.c 18 KB

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