0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/init.h>
0012 #include <linux/slab.h>
0013 #include <linux/kernel.h>
0014 #include <linux/device.h>
0015 #include <linux/module.h>
0016 #include <sound/core.h>
0017 #include <sound/pcm.h>
0018 #include <sound/ac97_codec.h>
0019 #include <sound/initval.h>
0020 #include <sound/soc.h>
0021
0022 static const struct snd_soc_dapm_widget ac97_widgets[] = {
0023 SND_SOC_DAPM_INPUT("RX"),
0024 SND_SOC_DAPM_OUTPUT("TX"),
0025 };
0026
0027 static const struct snd_soc_dapm_route ac97_routes[] = {
0028 { "AC97 Capture", NULL, "RX" },
0029 { "TX", NULL, "AC97 Playback" },
0030 };
0031
0032 static int ac97_prepare(struct snd_pcm_substream *substream,
0033 struct snd_soc_dai *dai)
0034 {
0035 struct snd_soc_component *component = dai->component;
0036 struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
0037
0038 int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
0039 AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
0040 return snd_ac97_set_rate(ac97, reg, substream->runtime->rate);
0041 }
0042
0043 static const struct snd_soc_dai_ops ac97_dai_ops = {
0044 .prepare = ac97_prepare,
0045 };
0046
0047 static struct snd_soc_dai_driver ac97_dai = {
0048 .name = "ac97-hifi",
0049 .playback = {
0050 .stream_name = "AC97 Playback",
0051 .channels_min = 1,
0052 .channels_max = 2,
0053 .rates = SNDRV_PCM_RATE_KNOT,
0054 .formats = SND_SOC_STD_AC97_FMTS,},
0055 .capture = {
0056 .stream_name = "AC97 Capture",
0057 .channels_min = 1,
0058 .channels_max = 2,
0059 .rates = SNDRV_PCM_RATE_KNOT,
0060 .formats = SND_SOC_STD_AC97_FMTS,},
0061 .ops = &ac97_dai_ops,
0062 };
0063
0064 static int ac97_soc_probe(struct snd_soc_component *component)
0065 {
0066 struct snd_ac97 *ac97;
0067 struct snd_ac97_bus *ac97_bus;
0068 struct snd_ac97_template ac97_template;
0069 int ret;
0070
0071
0072 ret = snd_ac97_bus(component->card->snd_card, 0, soc_ac97_ops,
0073 NULL, &ac97_bus);
0074 if (ret < 0)
0075 return ret;
0076
0077 memset(&ac97_template, 0, sizeof(struct snd_ac97_template));
0078 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &ac97);
0079 if (ret < 0)
0080 return ret;
0081
0082 snd_soc_component_set_drvdata(component, ac97);
0083
0084 return 0;
0085 }
0086
0087 #ifdef CONFIG_PM
0088 static int ac97_soc_suspend(struct snd_soc_component *component)
0089 {
0090 struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
0091
0092 snd_ac97_suspend(ac97);
0093
0094 return 0;
0095 }
0096
0097 static int ac97_soc_resume(struct snd_soc_component *component)
0098 {
0099
0100 struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
0101
0102 snd_ac97_resume(ac97);
0103
0104 return 0;
0105 }
0106 #else
0107 #define ac97_soc_suspend NULL
0108 #define ac97_soc_resume NULL
0109 #endif
0110
0111 static const struct snd_soc_component_driver soc_component_dev_ac97 = {
0112 .probe = ac97_soc_probe,
0113 .suspend = ac97_soc_suspend,
0114 .resume = ac97_soc_resume,
0115 .dapm_widgets = ac97_widgets,
0116 .num_dapm_widgets = ARRAY_SIZE(ac97_widgets),
0117 .dapm_routes = ac97_routes,
0118 .num_dapm_routes = ARRAY_SIZE(ac97_routes),
0119 .idle_bias_on = 1,
0120 .use_pmdown_time = 1,
0121 .endianness = 1,
0122 };
0123
0124 static int ac97_probe(struct platform_device *pdev)
0125 {
0126 return devm_snd_soc_register_component(&pdev->dev,
0127 &soc_component_dev_ac97, &ac97_dai, 1);
0128 }
0129
0130 static int ac97_remove(struct platform_device *pdev)
0131 {
0132 return 0;
0133 }
0134
0135 static struct platform_driver ac97_codec_driver = {
0136 .driver = {
0137 .name = "ac97-codec",
0138 },
0139
0140 .probe = ac97_probe,
0141 .remove = ac97_remove,
0142 };
0143
0144 module_platform_driver(ac97_codec_driver);
0145
0146 MODULE_DESCRIPTION("Soc Generic AC97 driver");
0147 MODULE_AUTHOR("Liam Girdwood");
0148 MODULE_LICENSE("GPL");
0149 MODULE_ALIAS("platform:ac97-codec");