Merge tag 'asoc-v3.15' into asoc-linus
[deliverable/linux.git] / sound / soc / omap / ams-delta.c
CommitLineData
6d7f68a1
JK
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
25#include <linux/gpio.h>
26#include <linux/spinlock.h>
27#include <linux/tty.h>
da155d5b 28#include <linux/module.h>
6d7f68a1 29
ce6120cc 30#include <sound/soc.h>
6d7f68a1
JK
31#include <sound/jack.h>
32
33#include <asm/mach-types.h>
34
e27e35ec 35#include <mach/board-ams-delta.h>
2203747c 36#include <linux/platform_data/asoc-ti-mcbsp.h>
6d7f68a1
JK
37
38#include "omap-mcbsp.h"
6d7f68a1
JK
39#include "../codecs/cx20442.h"
40
41
42/* Board specific DAPM widgets */
02624621 43static const struct snd_soc_dapm_widget ams_delta_dapm_widgets[] = {
6d7f68a1
JK
44 /* Handset */
45 SND_SOC_DAPM_MIC("Mouthpiece", NULL),
46 SND_SOC_DAPM_HP("Earpiece", NULL),
47 /* Handsfree/Speakerphone */
48 SND_SOC_DAPM_MIC("Microphone", NULL),
49 SND_SOC_DAPM_SPK("Speaker", NULL),
50};
51
52/* How they are connected to codec pins */
53static const struct snd_soc_dapm_route ams_delta_audio_map[] = {
54 {"TELIN", NULL, "Mouthpiece"},
55 {"Earpiece", NULL, "TELOUT"},
56
57 {"MIC", NULL, "Microphone"},
58 {"Speaker", NULL, "SPKOUT"},
59};
60
61/*
62 * Controls, functional after the modem line discipline is activated.
63 */
64
65/* Virtual switch: audio input/output constellations */
66static const char *ams_delta_audio_mode[] =
67 {"Mixed", "Handset", "Handsfree", "Speakerphone"};
68
69/* Selection <-> pin translation */
70#define AMS_DELTA_MOUTHPIECE 0
71#define AMS_DELTA_EARPIECE 1
72#define AMS_DELTA_MICROPHONE 2
73#define AMS_DELTA_SPEAKER 3
74#define AMS_DELTA_AGC 4
75
76#define AMS_DELTA_MIXED ((1 << AMS_DELTA_EARPIECE) | \
77 (1 << AMS_DELTA_MICROPHONE))
78#define AMS_DELTA_HANDSET ((1 << AMS_DELTA_MOUTHPIECE) | \
79 (1 << AMS_DELTA_EARPIECE))
80#define AMS_DELTA_HANDSFREE ((1 << AMS_DELTA_MICROPHONE) | \
81 (1 << AMS_DELTA_SPEAKER))
82#define AMS_DELTA_SPEAKERPHONE (AMS_DELTA_HANDSFREE | (1 << AMS_DELTA_AGC))
83
02624621 84static const unsigned short ams_delta_audio_mode_pins[] = {
6d7f68a1
JK
85 AMS_DELTA_MIXED,
86 AMS_DELTA_HANDSET,
87 AMS_DELTA_HANDSFREE,
88 AMS_DELTA_SPEAKERPHONE,
89};
90
91static unsigned short ams_delta_audio_agc;
92
93static int ams_delta_set_audio_mode(struct snd_kcontrol *kcontrol,
94 struct snd_ctl_elem_value *ucontrol)
95{
96 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
ce6120cc 97 struct snd_soc_dapm_context *dapm = &codec->dapm;
6d7f68a1
JK
98 struct soc_enum *control = (struct soc_enum *)kcontrol->private_value;
99 unsigned short pins;
100 int pin, changed = 0;
101
102 /* Refuse any mode changes if we are not able to control the codec. */
f0fba2ad 103 if (!codec->hw_write)
6d7f68a1
JK
104 return -EUNATCH;
105
9a8d38db 106 if (ucontrol->value.enumerated.item[0] >= control->items)
6d7f68a1
JK
107 return -EINVAL;
108
03510ca0 109 snd_soc_dapm_mutex_lock(dapm);
6d7f68a1
JK
110
111 /* Translate selection to bitmap */
112 pins = ams_delta_audio_mode_pins[ucontrol->value.enumerated.item[0]];
113
114 /* Setup pins after corresponding bits if changed */
115 pin = !!(pins & (1 << AMS_DELTA_MOUTHPIECE));
03510ca0 116
ce6120cc 117 if (pin != snd_soc_dapm_get_pin_status(dapm, "Mouthpiece")) {
6d7f68a1
JK
118 changed = 1;
119 if (pin)
03510ca0 120 snd_soc_dapm_enable_pin_unlocked(dapm, "Mouthpiece");
6d7f68a1 121 else
03510ca0 122 snd_soc_dapm_disable_pin_unlocked(dapm, "Mouthpiece");
6d7f68a1
JK
123 }
124 pin = !!(pins & (1 << AMS_DELTA_EARPIECE));
ce6120cc 125 if (pin != snd_soc_dapm_get_pin_status(dapm, "Earpiece")) {
6d7f68a1
JK
126 changed = 1;
127 if (pin)
03510ca0 128 snd_soc_dapm_enable_pin_unlocked(dapm, "Earpiece");
6d7f68a1 129 else
03510ca0 130 snd_soc_dapm_disable_pin_unlocked(dapm, "Earpiece");
6d7f68a1
JK
131 }
132 pin = !!(pins & (1 << AMS_DELTA_MICROPHONE));
ce6120cc 133 if (pin != snd_soc_dapm_get_pin_status(dapm, "Microphone")) {
6d7f68a1
JK
134 changed = 1;
135 if (pin)
03510ca0 136 snd_soc_dapm_enable_pin_unlocked(dapm, "Microphone");
6d7f68a1 137 else
03510ca0 138 snd_soc_dapm_disable_pin_unlocked(dapm, "Microphone");
6d7f68a1
JK
139 }
140 pin = !!(pins & (1 << AMS_DELTA_SPEAKER));
ce6120cc 141 if (pin != snd_soc_dapm_get_pin_status(dapm, "Speaker")) {
6d7f68a1
JK
142 changed = 1;
143 if (pin)
03510ca0 144 snd_soc_dapm_enable_pin_unlocked(dapm, "Speaker");
6d7f68a1 145 else
03510ca0 146 snd_soc_dapm_disable_pin_unlocked(dapm, "Speaker");
6d7f68a1
JK
147 }
148 pin = !!(pins & (1 << AMS_DELTA_AGC));
149 if (pin != ams_delta_audio_agc) {
150 ams_delta_audio_agc = pin;
151 changed = 1;
152 if (pin)
03510ca0 153 snd_soc_dapm_enable_pin_unlocked(dapm, "AGCIN");
6d7f68a1 154 else
03510ca0 155 snd_soc_dapm_disable_pin_unlocked(dapm, "AGCIN");
6d7f68a1 156 }
03510ca0 157
6d7f68a1 158 if (changed)
03510ca0 159 snd_soc_dapm_sync_unlocked(dapm);
6d7f68a1 160
03510ca0 161 snd_soc_dapm_mutex_unlock(dapm);
6d7f68a1
JK
162
163 return changed;
164}
165
166static int ams_delta_get_audio_mode(struct snd_kcontrol *kcontrol,
167 struct snd_ctl_elem_value *ucontrol)
168{
169 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
ce6120cc 170 struct snd_soc_dapm_context *dapm = &codec->dapm;
6d7f68a1
JK
171 unsigned short pins, mode;
172
ce6120cc 173 pins = ((snd_soc_dapm_get_pin_status(dapm, "Mouthpiece") <<
6d7f68a1 174 AMS_DELTA_MOUTHPIECE) |
ce6120cc 175 (snd_soc_dapm_get_pin_status(dapm, "Earpiece") <<
6d7f68a1
JK
176 AMS_DELTA_EARPIECE));
177 if (pins)
ce6120cc 178 pins |= (snd_soc_dapm_get_pin_status(dapm, "Microphone") <<
6d7f68a1
JK
179 AMS_DELTA_MICROPHONE);
180 else
ce6120cc 181 pins = ((snd_soc_dapm_get_pin_status(dapm, "Microphone") <<
6d7f68a1 182 AMS_DELTA_MICROPHONE) |
ce6120cc 183 (snd_soc_dapm_get_pin_status(dapm, "Speaker") <<
6d7f68a1
JK
184 AMS_DELTA_SPEAKER) |
185 (ams_delta_audio_agc << AMS_DELTA_AGC));
186
187 for (mode = 0; mode < ARRAY_SIZE(ams_delta_audio_mode); mode++)
188 if (pins == ams_delta_audio_mode_pins[mode])
189 break;
190
191 if (mode >= ARRAY_SIZE(ams_delta_audio_mode))
192 return -EINVAL;
193
194 ucontrol->value.enumerated.item[0] = mode;
195
196 return 0;
197}
198
7cb5e1bb
TI
199static const SOC_ENUM_SINGLE_EXT_DECL(ams_delta_audio_enum,
200 ams_delta_audio_mode);
6d7f68a1
JK
201
202static const struct snd_kcontrol_new ams_delta_audio_controls[] = {
7cb5e1bb 203 SOC_ENUM_EXT("Audio Mode", ams_delta_audio_enum,
6d7f68a1
JK
204 ams_delta_get_audio_mode, ams_delta_set_audio_mode),
205};
206
207/* Hook switch */
208static struct snd_soc_jack ams_delta_hook_switch;
209static struct snd_soc_jack_gpio ams_delta_hook_switch_gpios[] = {
210 {
211 .gpio = 4,
212 .name = "hook_switch",
213 .report = SND_JACK_HEADSET,
214 .invert = 1,
215 .debounce_time = 150,
216 }
217};
218
219/* After we are able to control the codec over the modem,
220 * the hook switch can be used for dynamic DAPM reconfiguration. */
221static struct snd_soc_jack_pin ams_delta_hook_switch_pins[] = {
222 /* Handset */
223 {
224 .pin = "Mouthpiece",
225 .mask = SND_JACK_MICROPHONE,
226 },
227 {
228 .pin = "Earpiece",
229 .mask = SND_JACK_HEADPHONE,
230 },
231 /* Handsfree */
232 {
233 .pin = "Microphone",
234 .mask = SND_JACK_MICROPHONE,
235 .invert = 1,
236 },
237 {
238 .pin = "Speaker",
239 .mask = SND_JACK_HEADPHONE,
240 .invert = 1,
241 },
242};
243
244
245/*
246 * Modem line discipline, required for making above controls functional.
247 * Activated from userspace with ldattach, possibly invoked from udev rule.
248 */
249
250/* To actually apply any modem controlled configuration changes to the codec,
25985edc 251 * we must connect codec DAI pins to the modem for a moment. Be careful not
6d7f68a1
JK
252 * to interfere with our digital mute function that shares the same hardware. */
253static struct timer_list cx81801_timer;
254static bool cx81801_cmd_pending;
255static bool ams_delta_muted;
256static DEFINE_SPINLOCK(ams_delta_lock);
257
258static void cx81801_timeout(unsigned long data)
259{
260 int muted;
261
262 spin_lock(&ams_delta_lock);
263 cx81801_cmd_pending = 0;
264 muted = ams_delta_muted;
265 spin_unlock(&ams_delta_lock);
266
267 /* Reconnect the codec DAI back from the modem to the CPU DAI
268 * only if digital mute still off */
269 if (!muted)
270 ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_CODEC, 0);
271}
272
f0fba2ad
LG
273/*
274 * Used for passing a codec structure pointer
275 * from the board initialization code to the tty line discipline.
276 */
277static struct snd_soc_codec *cx20442_codec;
278
6d7f68a1
JK
279/* Line discipline .open() */
280static int cx81801_open(struct tty_struct *tty)
281{
f0fba2ad
LG
282 int ret;
283
284 if (!cx20442_codec)
285 return -ENODEV;
286
287 /*
288 * Pass the codec structure pointer for use by other ldisc callbacks,
289 * both the card and the codec specific parts.
290 */
291 tty->disc_data = cx20442_codec;
292
293 ret = v253_ops.open(tty);
294
295 if (ret < 0)
296 tty->disc_data = NULL;
297
298 return ret;
6d7f68a1
JK
299}
300
301/* Line discipline .close() */
302static void cx81801_close(struct tty_struct *tty)
303{
304 struct snd_soc_codec *codec = tty->disc_data;
ce6120cc 305 struct snd_soc_dapm_context *dapm = &codec->dapm;
6d7f68a1
JK
306
307 del_timer_sync(&cx81801_timer);
308
6d7f68a1
JK
309 /* Prevent the hook switch from further changing the DAPM pins */
310 INIT_LIST_HEAD(&ams_delta_hook_switch.pins);
311
f0fba2ad
LG
312 if (!codec)
313 return;
314
315 v253_ops.close(tty);
316
6d7f68a1 317 /* Revert back to default audio input/output constellation */
03510ca0
CK
318 snd_soc_dapm_mutex_lock(dapm);
319
320 snd_soc_dapm_disable_pin_unlocked(dapm, "Mouthpiece");
321 snd_soc_dapm_enable_pin_unlocked(dapm, "Earpiece");
322 snd_soc_dapm_enable_pin_unlocked(dapm, "Microphone");
323 snd_soc_dapm_disable_pin_unlocked(dapm, "Speaker");
324 snd_soc_dapm_disable_pin_unlocked(dapm, "AGCIN");
325
326 snd_soc_dapm_sync_unlocked(dapm);
327
328 snd_soc_dapm_mutex_unlock(codec);
6d7f68a1
JK
329}
330
331/* Line discipline .hangup() */
332static int cx81801_hangup(struct tty_struct *tty)
333{
334 cx81801_close(tty);
335 return 0;
336}
337
dbc6221b 338/* Line discipline .receive_buf() */
6d7f68a1
JK
339static void cx81801_receive(struct tty_struct *tty,
340 const unsigned char *cp, char *fp, int count)
341{
342 struct snd_soc_codec *codec = tty->disc_data;
343 const unsigned char *c;
344 int apply, ret;
345
f0fba2ad
LG
346 if (!codec)
347 return;
348
349 if (!codec->hw_write) {
6d7f68a1
JK
350 /* First modem response, complete setup procedure */
351
352 /* Initialize timer used for config pulse generation */
353 setup_timer(&cx81801_timer, cx81801_timeout, 0);
354
355 v253_ops.receive_buf(tty, cp, fp, count);
356
357 /* Link hook switch to DAPM pins */
358 ret = snd_soc_jack_add_pins(&ams_delta_hook_switch,
359 ARRAY_SIZE(ams_delta_hook_switch_pins),
360 ams_delta_hook_switch_pins);
361 if (ret)
f0fba2ad 362 dev_warn(codec->dev,
6d7f68a1
JK
363 "Failed to link hook switch to DAPM pins, "
364 "will continue with hook switch unlinked.\n");
365
366 return;
367 }
368
369 v253_ops.receive_buf(tty, cp, fp, count);
370
371 for (c = &cp[count - 1]; c >= cp; c--) {
372 if (*c != '\r')
373 continue;
374 /* Complete modem response received, apply config to codec */
375
376 spin_lock_bh(&ams_delta_lock);
377 mod_timer(&cx81801_timer, jiffies + msecs_to_jiffies(150));
378 apply = !ams_delta_muted && !cx81801_cmd_pending;
379 cx81801_cmd_pending = 1;
380 spin_unlock_bh(&ams_delta_lock);
381
382 /* Apply config pulse by connecting the codec to the modem
383 * if not already done */
384 if (apply)
385 ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_CODEC,
386 AMS_DELTA_LATCH2_MODEM_CODEC);
387 break;
388 }
389}
390
391/* Line discipline .write_wakeup() */
392static void cx81801_wakeup(struct tty_struct *tty)
393{
394 v253_ops.write_wakeup(tty);
395}
396
397static struct tty_ldisc_ops cx81801_ops = {
398 .magic = TTY_LDISC_MAGIC,
399 .name = "cx81801",
400 .owner = THIS_MODULE,
401 .open = cx81801_open,
402 .close = cx81801_close,
403 .hangup = cx81801_hangup,
404 .receive_buf = cx81801_receive,
405 .write_wakeup = cx81801_wakeup,
406};
407
408
409/*
25985edc 410 * Even if not very useful, the sound card can still work without any of the
6d7f68a1 411 * above functonality activated. You can still control its audio input/output
25985edc 412 * constellation and speakerphone gain from userspace by issuing AT commands
6d7f68a1
JK
413 * over the modem port.
414 */
415
416static int ams_delta_hw_params(struct snd_pcm_substream *substream,
417 struct snd_pcm_hw_params *params)
418{
419 struct snd_soc_pcm_runtime *rtd = substream->private_data;
420
421 /* Set cpu DAI configuration */
f0fba2ad 422 return snd_soc_dai_set_fmt(rtd->cpu_dai,
6d7f68a1
JK
423 SND_SOC_DAIFMT_DSP_A |
424 SND_SOC_DAIFMT_NB_NF |
425 SND_SOC_DAIFMT_CBM_CFM);
426}
427
428static struct snd_soc_ops ams_delta_ops = {
429 .hw_params = ams_delta_hw_params,
430};
431
432
6d7f68a1
JK
433/* Digital mute implemented using modem/CPU multiplexer.
434 * Shares hardware with codec config pulse generation */
435static bool ams_delta_muted = 1;
436
437static int ams_delta_digital_mute(struct snd_soc_dai *dai, int mute)
438{
439 int apply;
440
441 if (ams_delta_muted == mute)
442 return 0;
443
444 spin_lock_bh(&ams_delta_lock);
445 ams_delta_muted = mute;
446 apply = !cx81801_cmd_pending;
447 spin_unlock_bh(&ams_delta_lock);
448
449 if (apply)
450 ams_delta_latch2_write(AMS_DELTA_LATCH2_MODEM_CODEC,
451 mute ? AMS_DELTA_LATCH2_MODEM_CODEC : 0);
452 return 0;
453}
454
455/* Our codec DAI probably doesn't have its own .ops structure */
85e7652d 456static const struct snd_soc_dai_ops ams_delta_dai_ops = {
6d7f68a1
JK
457 .digital_mute = ams_delta_digital_mute,
458};
459
460/* Will be used if the codec ever has its own digital_mute function */
461static int ams_delta_startup(struct snd_pcm_substream *substream)
462{
463 return ams_delta_digital_mute(NULL, 0);
464}
465
466static void ams_delta_shutdown(struct snd_pcm_substream *substream)
467{
468 ams_delta_digital_mute(NULL, 1);
469}
470
471
472/*
473 * Card initialization
474 */
475
f0fba2ad 476static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd)
6d7f68a1 477{
f0fba2ad 478 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 479 struct snd_soc_dapm_context *dapm = &codec->dapm;
f0fba2ad
LG
480 struct snd_soc_dai *codec_dai = rtd->codec_dai;
481 struct snd_soc_card *card = rtd->card;
6d7f68a1
JK
482 int ret;
483 /* Codec is ready, now add/activate board specific controls */
484
f0fba2ad
LG
485 /* Store a pointer to the codec structure for tty ldisc use */
486 cx20442_codec = codec;
487
6d7f68a1 488 /* Set up digital mute if not provided by the codec */
f0fba2ad
LG
489 if (!codec_dai->driver->ops) {
490 codec_dai->driver->ops = &ams_delta_dai_ops;
6d7f68a1
JK
491 } else {
492 ams_delta_ops.startup = ams_delta_startup;
493 ams_delta_ops.shutdown = ams_delta_shutdown;
494 }
495
6d7f68a1
JK
496 /* Add hook switch - can be used to control the codec from userspace
497 * even if line discipline fails */
f0fba2ad 498 ret = snd_soc_jack_new(rtd->codec, "hook_switch",
6d7f68a1
JK
499 SND_JACK_HEADSET, &ams_delta_hook_switch);
500 if (ret)
501 dev_warn(card->dev,
502 "Failed to allocate resources for hook switch, "
503 "will continue without one.\n");
504 else {
505 ret = snd_soc_jack_add_gpios(&ams_delta_hook_switch,
506 ARRAY_SIZE(ams_delta_hook_switch_gpios),
507 ams_delta_hook_switch_gpios);
508 if (ret)
509 dev_warn(card->dev,
510 "Failed to set up hook switch GPIO line, "
511 "will continue with hook switch inactive.\n");
512 }
513
514 /* Register optional line discipline for over the modem control */
b7b8f9bf 515 ret = tty_register_ldisc(N_V253, &cx81801_ops);
6d7f68a1
JK
516 if (ret) {
517 dev_warn(card->dev,
518 "Failed to register line discipline, "
519 "will continue without any controls.\n");
520 return 0;
521 }
522
523 /* Add board specific DAPM widgets and routes */
ce6120cc 524 ret = snd_soc_dapm_new_controls(dapm, ams_delta_dapm_widgets,
6d7f68a1
JK
525 ARRAY_SIZE(ams_delta_dapm_widgets));
526 if (ret) {
527 dev_warn(card->dev,
528 "Failed to register DAPM controls, "
529 "will continue without any.\n");
530 return 0;
531 }
532
ce6120cc 533 ret = snd_soc_dapm_add_routes(dapm, ams_delta_audio_map,
6d7f68a1
JK
534 ARRAY_SIZE(ams_delta_audio_map));
535 if (ret) {
536 dev_warn(card->dev,
537 "Failed to set up DAPM routes, "
538 "will continue with codec default map.\n");
539 return 0;
540 }
541
542 /* Set up initial pin constellation */
ce6120cc
LG
543 snd_soc_dapm_disable_pin(dapm, "Mouthpiece");
544 snd_soc_dapm_enable_pin(dapm, "Earpiece");
545 snd_soc_dapm_enable_pin(dapm, "Microphone");
546 snd_soc_dapm_disable_pin(dapm, "Speaker");
547 snd_soc_dapm_disable_pin(dapm, "AGCIN");
548 snd_soc_dapm_disable_pin(dapm, "AGCOUT");
6d7f68a1
JK
549
550 /* Add virtual switch */
022658be 551 ret = snd_soc_add_codec_controls(codec, ams_delta_audio_controls,
6d7f68a1
JK
552 ARRAY_SIZE(ams_delta_audio_controls));
553 if (ret)
554 dev_warn(card->dev,
555 "Failed to register audio mode control, "
556 "will continue without it.\n");
557
558 return 0;
559}
560
561/* DAI glue - connects codec <--> CPU */
562static struct snd_soc_dai_link ams_delta_dai_link = {
563 .name = "CX20442",
564 .stream_name = "CX20442",
45656b44 565 .cpu_dai_name = "omap-mcbsp.1",
5394637a 566 .codec_dai_name = "cx20442-voice",
6d7f68a1 567 .init = ams_delta_cx20442_init,
f0fba2ad
LG
568 .platform_name = "omap-pcm-audio",
569 .codec_name = "cx20442-codec",
6d7f68a1
JK
570 .ops = &ams_delta_ops,
571};
572
573/* Audio card driver */
574static struct snd_soc_card ams_delta_audio_card = {
575 .name = "AMS_DELTA",
b425b884 576 .owner = THIS_MODULE,
6d7f68a1
JK
577 .dai_link = &ams_delta_dai_link,
578 .num_links = 1,
6d7f68a1
JK
579};
580
6d7f68a1 581/* Module init/exit */
7ff60006 582static int ams_delta_probe(struct platform_device *pdev)
6d7f68a1 583{
b764de2d 584 struct snd_soc_card *card = &ams_delta_audio_card;
6d7f68a1
JK
585 int ret;
586
b764de2d 587 card->dev = &pdev->dev;
6d7f68a1 588
b764de2d
JK
589 ret = snd_soc_register_card(card);
590 if (ret) {
591 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
592 card->dev = NULL;
593 return ret;
594 }
6d7f68a1 595 return 0;
6d7f68a1 596}
6d7f68a1 597
7ff60006 598static int ams_delta_remove(struct platform_device *pdev)
6d7f68a1 599{
b764de2d
JK
600 struct snd_soc_card *card = platform_get_drvdata(pdev);
601
b7b8f9bf 602 if (tty_unregister_ldisc(N_V253) != 0)
b764de2d 603 dev_warn(&pdev->dev,
b7b8f9bf 604 "failed to unregister V253 line discipline\n");
6d7f68a1
JK
605
606 snd_soc_jack_free_gpios(&ams_delta_hook_switch,
607 ARRAY_SIZE(ams_delta_hook_switch_gpios),
608 ams_delta_hook_switch_gpios);
609
b764de2d
JK
610 snd_soc_unregister_card(card);
611 card->dev = NULL;
612 return 0;
6d7f68a1 613}
b764de2d
JK
614
615#define DRV_NAME "ams-delta-audio"
616
617static struct platform_driver ams_delta_driver = {
618 .driver = {
619 .name = DRV_NAME,
620 .owner = THIS_MODULE,
621 },
622 .probe = ams_delta_probe,
7ff60006 623 .remove = ams_delta_remove,
b764de2d
JK
624};
625
626module_platform_driver(ams_delta_driver);
6d7f68a1
JK
627
628MODULE_AUTHOR("Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>");
629MODULE_DESCRIPTION("ALSA SoC driver for Amstrad E3 (Delta) videophone");
630MODULE_LICENSE("GPL");
b764de2d 631MODULE_ALIAS("platform:" DRV_NAME);
This page took 0.418102 seconds and 5 git commands to generate.