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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame^] | 14 | #include <linux/slab.h> |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 15 | #include <linux/module.h> |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 16 | #include <linux/kernel.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <sound/core.h> |
| 19 | #include <sound/pcm.h> |
| 20 | #include <sound/ac97_codec.h> |
| 21 | #include <sound/initval.h> |
| 22 | #include <sound/soc.h> |
| 23 | |
| 24 | #include "ad73311.h" |
| 25 | |
| 26 | struct snd_soc_dai ad73311_dai = { |
| 27 | .name = "AD73311", |
| 28 | .playback = { |
| 29 | .stream_name = "Playback", |
| 30 | .channels_min = 1, |
| 31 | .channels_max = 1, |
| 32 | .rates = SNDRV_PCM_RATE_8000, |
| 33 | .formats = SNDRV_PCM_FMTBIT_S16_LE, }, |
| 34 | .capture = { |
| 35 | .stream_name = "Capture", |
| 36 | .channels_min = 1, |
| 37 | .channels_max = 1, |
| 38 | .rates = SNDRV_PCM_RATE_8000, |
| 39 | .formats = SNDRV_PCM_FMTBIT_S16_LE, }, |
| 40 | }; |
| 41 | EXPORT_SYMBOL_GPL(ad73311_dai); |
| 42 | |
| 43 | static int ad73311_soc_probe(struct platform_device *pdev) |
| 44 | { |
| 45 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 46 | struct snd_soc_codec *codec; |
| 47 | int ret = 0; |
| 48 | |
| 49 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
| 50 | if (codec == NULL) |
| 51 | return -ENOMEM; |
| 52 | mutex_init(&codec->mutex); |
| 53 | codec->name = "AD73311"; |
| 54 | codec->owner = THIS_MODULE; |
| 55 | codec->dai = &ad73311_dai; |
| 56 | codec->num_dai = 1; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 57 | socdev->card->codec = codec; |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 58 | INIT_LIST_HEAD(&codec->dapm_widgets); |
| 59 | INIT_LIST_HEAD(&codec->dapm_paths); |
| 60 | |
| 61 | /* register pcms */ |
| 62 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
| 63 | if (ret < 0) { |
| 64 | printk(KERN_ERR "ad73311: failed to create pcms\n"); |
| 65 | goto pcm_err; |
| 66 | } |
| 67 | |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 68 | return ret; |
| 69 | |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 70 | pcm_err: |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 71 | kfree(socdev->card->codec); |
| 72 | socdev->card->codec = NULL; |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | static int ad73311_soc_remove(struct platform_device *pdev) |
| 77 | { |
| 78 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 79 | struct snd_soc_codec *codec = socdev->card->codec; |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 80 | |
| 81 | if (codec == NULL) |
| 82 | return 0; |
| 83 | snd_soc_free_pcms(socdev); |
| 84 | kfree(codec); |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | struct snd_soc_codec_device soc_codec_dev_ad73311 = { |
| 89 | .probe = ad73311_soc_probe, |
| 90 | .remove = ad73311_soc_remove, |
| 91 | }; |
| 92 | EXPORT_SYMBOL_GPL(soc_codec_dev_ad73311); |
| 93 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 94 | static int __init ad73311_init(void) |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 95 | { |
| 96 | return snd_soc_register_dai(&ad73311_dai); |
| 97 | } |
| 98 | module_init(ad73311_init); |
| 99 | |
| 100 | static void __exit ad73311_exit(void) |
| 101 | { |
| 102 | snd_soc_unregister_dai(&ad73311_dai); |
| 103 | } |
| 104 | module_exit(ad73311_exit); |
| 105 | |
Cliff Cai | 0e77e78 | 2008-09-27 16:57:26 +0800 | [diff] [blame] | 106 | MODULE_DESCRIPTION("ASoC ad73311 driver"); |
| 107 | MODULE_AUTHOR("Cliff Cai "); |
| 108 | MODULE_LICENSE("GPL"); |