Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 1 | /* |
| 2 | * ad73311.c -- ALSA Soc AD73311 codec support |
| 3 | * |
| 4 | * Copyright: Analog Device Inc. |
| 5 | * Author: Cliff Cai <cliff.cai@analog.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <sound/core.h> |
| 18 | #include <sound/pcm.h> |
| 19 | #include <sound/ac97_codec.h> |
| 20 | #include <sound/initval.h> |
| 21 | #include <sound/soc.h> |
| 22 | |
| 23 | #include "ad73311.h" |
| 24 | |
| 25 | struct snd_soc_dai ad73311_dai = { |
| 26 | .name = "AD73311", |
| 27 | .playback = { |
| 28 | .stream_name = "Playback", |
| 29 | .channels_min = 1, |
| 30 | .channels_max = 1, |
| 31 | .rates = SNDRV_PCM_RATE_8000, |
| 32 | .formats = SNDRV_PCM_FMTBIT_S16_LE, }, |
| 33 | .capture = { |
| 34 | .stream_name = "Capture", |
| 35 | .channels_min = 1, |
| 36 | .channels_max = 1, |
| 37 | .rates = SNDRV_PCM_RATE_8000, |
| 38 | .formats = SNDRV_PCM_FMTBIT_S16_LE, }, |
| 39 | }; |
| 40 | EXPORT_SYMBOL_GPL(ad73311_dai); |
| 41 | |
| 42 | static int ad73311_soc_probe(struct platform_device *pdev) |
| 43 | { |
| 44 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 45 | struct snd_soc_codec *codec; |
| 46 | int ret = 0; |
| 47 | |
| 48 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
| 49 | if (codec == NULL) |
| 50 | return -ENOMEM; |
| 51 | mutex_init(&codec->mutex); |
| 52 | codec->name = "AD73311"; |
| 53 | codec->owner = THIS_MODULE; |
| 54 | codec->dai = &ad73311_dai; |
| 55 | codec->num_dai = 1; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame^] | 56 | socdev->card->codec = codec; |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 57 | INIT_LIST_HEAD(&codec->dapm_widgets); |
| 58 | INIT_LIST_HEAD(&codec->dapm_paths); |
| 59 | |
| 60 | /* register pcms */ |
| 61 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
| 62 | if (ret < 0) { |
| 63 | printk(KERN_ERR "ad73311: failed to create pcms\n"); |
| 64 | goto pcm_err; |
| 65 | } |
| 66 | |
Mark Brown | 968a602 | 2008-11-28 11:49:07 +0000 | [diff] [blame] | 67 | ret = snd_soc_init_card(socdev); |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 68 | if (ret < 0) { |
| 69 | printk(KERN_ERR "ad73311: failed to register card\n"); |
| 70 | goto register_err; |
| 71 | } |
| 72 | |
| 73 | return ret; |
| 74 | |
| 75 | register_err: |
| 76 | snd_soc_free_pcms(socdev); |
| 77 | pcm_err: |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame^] | 78 | kfree(socdev->card->codec); |
| 79 | socdev->card->codec = NULL; |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | static int ad73311_soc_remove(struct platform_device *pdev) |
| 84 | { |
| 85 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame^] | 86 | struct snd_soc_codec *codec = socdev->card->codec; |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 87 | |
| 88 | if (codec == NULL) |
| 89 | return 0; |
| 90 | snd_soc_free_pcms(socdev); |
| 91 | kfree(codec); |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | struct snd_soc_codec_device soc_codec_dev_ad73311 = { |
| 96 | .probe = ad73311_soc_probe, |
| 97 | .remove = ad73311_soc_remove, |
| 98 | }; |
| 99 | EXPORT_SYMBOL_GPL(soc_codec_dev_ad73311); |
| 100 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 101 | static int __init ad73311_init(void) |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 102 | { |
| 103 | return snd_soc_register_dai(&ad73311_dai); |
| 104 | } |
| 105 | module_init(ad73311_init); |
| 106 | |
| 107 | static void __exit ad73311_exit(void) |
| 108 | { |
| 109 | snd_soc_unregister_dai(&ad73311_dai); |
| 110 | } |
| 111 | module_exit(ad73311_exit); |
| 112 | |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 113 | MODULE_DESCRIPTION("ASoC ad73311 driver"); |
| 114 | MODULE_AUTHOR("Cliff Cai "); |
| 115 | MODULE_LICENSE("GPL"); |