ams-delta.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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 <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 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->hw_write)
  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. /*
  232. * Used for passing a codec structure pointer
  233. * from the board initialization code to the tty line discipline.
  234. */
  235. static struct snd_soc_codec *cx20442_codec;
  236. /* Line discipline .open() */
  237. static int cx81801_open(struct tty_struct *tty)
  238. {
  239. int ret;
  240. if (!cx20442_codec)
  241. return -ENODEV;
  242. /*
  243. * Pass the codec structure pointer for use by other ldisc callbacks,
  244. * both the card and the codec specific parts.
  245. */
  246. tty->disc_data = cx20442_codec;
  247. ret = v253_ops.open(tty);
  248. if (ret < 0)
  249. tty->disc_data = NULL;
  250. return ret;
  251. }
  252. /* Line discipline .close() */
  253. static void cx81801_close(struct tty_struct *tty)
  254. {
  255. struct snd_soc_codec *codec = tty->disc_data;
  256. del_timer_sync(&cx81801_timer);
  257. /* Prevent the hook switch from further changing the DAPM pins */
  258. INIT_LIST_HEAD(&ams_delta_hook_switch.pins);
  259. if (!codec)
  260. return;
  261. v253_ops.close(tty);
  262. /* Revert back to default audio input/output constellation */
  263. snd_soc_dapm_disable_pin(codec, "Mouthpiece");
  264. snd_soc_dapm_enable_pin(codec, "Earpiece");
  265. snd_soc_dapm_enable_pin(codec, "Microphone");
  266. snd_soc_dapm_disable_pin(codec, "Speaker");
  267. snd_soc_dapm_disable_pin(codec, "AGCIN");
  268. snd_soc_dapm_sync(codec);
  269. }
  270. /* Line discipline .hangup() */
  271. static int cx81801_hangup(struct tty_struct *tty)
  272. {
  273. cx81801_close(tty);
  274. return 0;
  275. }
  276. /* Line discipline .recieve_buf() */
  277. static void cx81801_receive(struct tty_struct *tty,
  278. const unsigned char *cp, char *fp, int count)
  279. {
  280. struct snd_soc_codec *codec = tty->disc_data;
  281. const unsigned char *c;
  282. int apply, ret;
  283. if (!codec)
  284. return;
  285. if (!codec->hw_write) {
  286. /* First modem response, complete setup procedure */
  287. /* Initialize timer used for config pulse generation */
  288. setup_timer(&cx81801_timer, cx81801_timeout, 0);
  289. v253_ops.receive_buf(tty, cp, fp, count);
  290. /* Link hook switch to DAPM pins */
  291. ret = snd_soc_jack_add_pins(&ams_delta_hook_switch,
  292. ARRAY_SIZE(ams_delta_hook_switch_pins),
  293. ams_delta_hook_switch_pins);
  294. if (ret)
  295. dev_warn(codec->dev,
  296. "Failed to link hook switch to DAPM pins, "
  297. "will continue with hook switch unlinked.\n");
  298. return;
  299. }
  300. v253_ops.receive_buf(tty, cp, fp, count);
  301. for (c = &cp[count - 1]; c >= cp; c--) {
  302. if (*c != '\r')
  303. continue;
  304. /* Complete modem response received, apply config to codec */
  305. spin_lock_bh(&ams_delta_lock);
  306. mod_timer(&cx81801_timer, jiffies + msecs_to_jiffies(150));
  307. apply = !ams_delta_muted && !cx81801_cmd_pending;
  308. cx81801_cmd_pending = 1;
  309. spin_unlock_bh(&ams_delta_lock);
  310. /* Apply config pulse by connecting the codec to the modem
  311. * if not already done */
  312. if (apply)
  313. ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_CODEC,
  314. AMS_DELTA_LATCH2_MODEM_CODEC);
  315. break;
  316. }
  317. }
  318. /* Line discipline .write_wakeup() */
  319. static void cx81801_wakeup(struct tty_struct *tty)
  320. {
  321. v253_ops.write_wakeup(tty);
  322. }
  323. static struct tty_ldisc_ops cx81801_ops = {
  324. .magic = TTY_LDISC_MAGIC,
  325. .name = "cx81801",
  326. .owner = THIS_MODULE,
  327. .open = cx81801_open,
  328. .close = cx81801_close,
  329. .hangup = cx81801_hangup,
  330. .receive_buf = cx81801_receive,
  331. .write_wakeup = cx81801_wakeup,
  332. };
  333. /*
  334. * Even if not very usefull, the sound card can still work without any of the
  335. * above functonality activated. You can still control its audio input/output
  336. * constellation and speakerphone gain from userspace by issueing AT commands
  337. * over the modem port.
  338. */
  339. static int ams_delta_hw_params(struct snd_pcm_substream *substream,
  340. struct snd_pcm_hw_params *params)
  341. {
  342. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  343. /* Set cpu DAI configuration */
  344. return snd_soc_dai_set_fmt(rtd->cpu_dai,
  345. SND_SOC_DAIFMT_DSP_A |
  346. SND_SOC_DAIFMT_NB_NF |
  347. SND_SOC_DAIFMT_CBM_CFM);
  348. }
  349. static struct snd_soc_ops ams_delta_ops = {
  350. .hw_params = ams_delta_hw_params,
  351. };
  352. /* Board specific codec bias level control */
  353. static int ams_delta_set_bias_level(struct snd_soc_card *card,
  354. enum snd_soc_bias_level level)
  355. {
  356. struct snd_soc_codec *codec = card->rtd->codec;
  357. switch (level) {
  358. case SND_SOC_BIAS_ON:
  359. case SND_SOC_BIAS_PREPARE:
  360. case SND_SOC_BIAS_STANDBY:
  361. if (codec->bias_level == SND_SOC_BIAS_OFF)
  362. ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_NRESET,
  363. AMS_DELTA_LATCH2_MODEM_NRESET);
  364. break;
  365. case SND_SOC_BIAS_OFF:
  366. if (codec->bias_level != SND_SOC_BIAS_OFF)
  367. ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_NRESET,
  368. 0);
  369. }
  370. codec->bias_level = level;
  371. return 0;
  372. }
  373. /* Digital mute implemented using modem/CPU multiplexer.
  374. * Shares hardware with codec config pulse generation */
  375. static bool ams_delta_muted = 1;
  376. static int ams_delta_digital_mute(struct snd_soc_dai *dai, int mute)
  377. {
  378. int apply;
  379. if (ams_delta_muted == mute)
  380. return 0;
  381. spin_lock_bh(&ams_delta_lock);
  382. ams_delta_muted = mute;
  383. apply = !cx81801_cmd_pending;
  384. spin_unlock_bh(&ams_delta_lock);
  385. if (apply)
  386. ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_CODEC,
  387. mute ? AMS_DELTA_LATCH2_MODEM_CODEC : 0);
  388. return 0;
  389. }
  390. /* Our codec DAI probably doesn't have its own .ops structure */
  391. static struct snd_soc_dai_ops ams_delta_dai_ops = {
  392. .digital_mute = ams_delta_digital_mute,
  393. };
  394. /* Will be used if the codec ever has its own digital_mute function */
  395. static int ams_delta_startup(struct snd_pcm_substream *substream)
  396. {
  397. return ams_delta_digital_mute(NULL, 0);
  398. }
  399. static void ams_delta_shutdown(struct snd_pcm_substream *substream)
  400. {
  401. ams_delta_digital_mute(NULL, 1);
  402. }
  403. /*
  404. * Card initialization
  405. */
  406. static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd)
  407. {
  408. struct snd_soc_codec *codec = rtd->codec;
  409. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  410. struct snd_soc_card *card = rtd->card;
  411. int ret;
  412. /* Codec is ready, now add/activate board specific controls */
  413. /* Store a pointer to the codec structure for tty ldisc use */
  414. cx20442_codec = codec;
  415. /* Set up digital mute if not provided by the codec */
  416. if (!codec_dai->driver->ops) {
  417. codec_dai->driver->ops = &ams_delta_dai_ops;
  418. } else if (!codec_dai->driver->ops->digital_mute) {
  419. codec_dai->driver->ops->digital_mute = ams_delta_digital_mute;
  420. } else {
  421. ams_delta_ops.startup = ams_delta_startup;
  422. ams_delta_ops.shutdown = ams_delta_shutdown;
  423. }
  424. /* Set codec bias level */
  425. ams_delta_set_bias_level(card, SND_SOC_BIAS_STANDBY);
  426. /* Add hook switch - can be used to control the codec from userspace
  427. * even if line discipline fails */
  428. ret = snd_soc_jack_new(rtd->codec, "hook_switch",
  429. SND_JACK_HEADSET, &ams_delta_hook_switch);
  430. if (ret)
  431. dev_warn(card->dev,
  432. "Failed to allocate resources for hook switch, "
  433. "will continue without one.\n");
  434. else {
  435. ret = snd_soc_jack_add_gpios(&ams_delta_hook_switch,
  436. ARRAY_SIZE(ams_delta_hook_switch_gpios),
  437. ams_delta_hook_switch_gpios);
  438. if (ret)
  439. dev_warn(card->dev,
  440. "Failed to set up hook switch GPIO line, "
  441. "will continue with hook switch inactive.\n");
  442. }
  443. /* Register optional line discipline for over the modem control */
  444. ret = tty_register_ldisc(N_V253, &cx81801_ops);
  445. if (ret) {
  446. dev_warn(card->dev,
  447. "Failed to register line discipline, "
  448. "will continue without any controls.\n");
  449. return 0;
  450. }
  451. /* Add board specific DAPM widgets and routes */
  452. ret = snd_soc_dapm_new_controls(codec, ams_delta_dapm_widgets,
  453. ARRAY_SIZE(ams_delta_dapm_widgets));
  454. if (ret) {
  455. dev_warn(card->dev,
  456. "Failed to register DAPM controls, "
  457. "will continue without any.\n");
  458. return 0;
  459. }
  460. ret = snd_soc_dapm_add_routes(codec, ams_delta_audio_map,
  461. ARRAY_SIZE(ams_delta_audio_map));
  462. if (ret) {
  463. dev_warn(card->dev,
  464. "Failed to set up DAPM routes, "
  465. "will continue with codec default map.\n");
  466. return 0;
  467. }
  468. /* Set up initial pin constellation */
  469. snd_soc_dapm_disable_pin(codec, "Mouthpiece");
  470. snd_soc_dapm_enable_pin(codec, "Earpiece");
  471. snd_soc_dapm_enable_pin(codec, "Microphone");
  472. snd_soc_dapm_disable_pin(codec, "Speaker");
  473. snd_soc_dapm_disable_pin(codec, "AGCIN");
  474. snd_soc_dapm_disable_pin(codec, "AGCOUT");
  475. snd_soc_dapm_sync(codec);
  476. /* Add virtual switch */
  477. ret = snd_soc_add_controls(codec, ams_delta_audio_controls,
  478. ARRAY_SIZE(ams_delta_audio_controls));
  479. if (ret)
  480. dev_warn(card->dev,
  481. "Failed to register audio mode control, "
  482. "will continue without it.\n");
  483. return 0;
  484. }
  485. /* DAI glue - connects codec <--> CPU */
  486. static struct snd_soc_dai_link ams_delta_dai_link = {
  487. .name = "CX20442",
  488. .stream_name = "CX20442",
  489. .cpu_dai_name ="omap-mcbsp-dai.0",
  490. .codec_dai_name = "cx20442-voice",
  491. .init = ams_delta_cx20442_init,
  492. .platform_name = "omap-pcm-audio",
  493. .codec_name = "cx20442-codec",
  494. .ops = &ams_delta_ops,
  495. };
  496. /* Audio card driver */
  497. static struct snd_soc_card ams_delta_audio_card = {
  498. .name = "AMS_DELTA",
  499. .dai_link = &ams_delta_dai_link,
  500. .num_links = 1,
  501. .set_bias_level = ams_delta_set_bias_level,
  502. };
  503. /* Module init/exit */
  504. static struct platform_device *ams_delta_audio_platform_device;
  505. static struct platform_device *cx20442_platform_device;
  506. static int __init ams_delta_module_init(void)
  507. {
  508. int ret;
  509. if (!(machine_is_ams_delta()))
  510. return -ENODEV;
  511. ams_delta_audio_platform_device =
  512. platform_device_alloc("soc-audio", -1);
  513. if (!ams_delta_audio_platform_device)
  514. return -ENOMEM;
  515. platform_set_drvdata(ams_delta_audio_platform_device,
  516. &ams_delta_audio_card);
  517. ret = platform_device_add(ams_delta_audio_platform_device);
  518. if (ret)
  519. goto err;
  520. /*
  521. * Codec platform device could be registered from elsewhere (board?),
  522. * but I do it here as it makes sense only if used with the card.
  523. */
  524. cx20442_platform_device =
  525. platform_device_register_simple("cx20442-codec", -1, NULL, 0);
  526. return 0;
  527. err:
  528. platform_device_put(ams_delta_audio_platform_device);
  529. return ret;
  530. }
  531. module_init(ams_delta_module_init);
  532. static void __exit ams_delta_module_exit(void)
  533. {
  534. if (tty_unregister_ldisc(N_V253) != 0)
  535. dev_warn(&ams_delta_audio_platform_device->dev,
  536. "failed to unregister V253 line discipline\n");
  537. snd_soc_jack_free_gpios(&ams_delta_hook_switch,
  538. ARRAY_SIZE(ams_delta_hook_switch_gpios),
  539. ams_delta_hook_switch_gpios);
  540. /* Keep modem power on */
  541. ams_delta_set_bias_level(&ams_delta_audio_card, SND_SOC_BIAS_STANDBY);
  542. platform_device_unregister(cx20442_platform_device);
  543. platform_device_unregister(ams_delta_audio_platform_device);
  544. }
  545. module_exit(ams_delta_module_exit);
  546. MODULE_AUTHOR("Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>");
  547. MODULE_DESCRIPTION("ALSA SoC driver for Amstrad E3 (Delta) videophone");
  548. MODULE_LICENSE("GPL");