blob: 6ad9c9443b5db7558c9a01bf45066a83bc81dba6 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Richard Purdiedbc6b6a2006-10-06 18:38:03 +02002/*
3 * ac97.c -- ALSA Soc AC97 codec support
4 *
5 * Copyright 2005 Wolfson Microelectronics PLC.
Liam Girdwoodd3311242008-10-12 13:17:36 +01006 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
Richard Purdiedbc6b6a2006-10-06 18:38:03 +02007 *
Richard Purdiedbc6b6a2006-10-06 18:38:03 +02008 * Generic AC97 support.
9 */
10
11#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020013#include <linux/kernel.h>
14#include <linux/device.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040015#include <linux/module.h>
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020016#include <sound/core.h>
17#include <sound/pcm.h>
18#include <sound/ac97_codec.h>
19#include <sound/initval.h>
20#include <sound/soc.h>
21
Mark Brownd2a369c2013-08-19 12:18:07 +010022static const struct snd_soc_dapm_widget ac97_widgets[] = {
23 SND_SOC_DAPM_INPUT("RX"),
24 SND_SOC_DAPM_OUTPUT("TX"),
25};
26
27static const struct snd_soc_dapm_route ac97_routes[] = {
28 { "AC97 Capture", NULL, "RX" },
29 { "TX", NULL, "AC97 Playback" },
30};
31
Mark Browndee89c42008-11-18 22:11:38 +000032static int ac97_prepare(struct snd_pcm_substream *substream,
33 struct snd_soc_dai *dai)
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020034{
Kuninori Morimotoc95869e2018-01-29 02:58:25 +000035 struct snd_soc_component *component = dai->component;
36 struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020037
38 int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
39 AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +010040 return snd_ac97_set_rate(ac97, reg, substream->runtime->rate);
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020041}
42
Lars-Peter Clausen85e76522011-11-23 11:40:40 +010043static const struct snd_soc_dai_ops ac97_dai_ops = {
Eric Miao6335d0552009-03-03 09:41:00 +080044 .prepare = ac97_prepare,
45};
46
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000047static struct snd_soc_dai_driver ac97_dai = {
48 .name = "ac97-hifi",
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020049 .playback = {
50 .stream_name = "AC97 Playback",
51 .channels_min = 1,
Liam Girdwood5a8ec342007-02-02 17:16:41 +010052 .channels_max = 2,
Maciej S. Szmigierodf82ca72015-05-10 00:09:57 +020053 .rates = SNDRV_PCM_RATE_KNOT,
Mark Brown33f503c2009-05-02 12:24:55 +010054 .formats = SND_SOC_STD_AC97_FMTS,},
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020055 .capture = {
56 .stream_name = "AC97 Capture",
57 .channels_min = 1,
Liam Girdwood5a8ec342007-02-02 17:16:41 +010058 .channels_max = 2,
Maciej S. Szmigierodf82ca72015-05-10 00:09:57 +020059 .rates = SNDRV_PCM_RATE_KNOT,
Mark Brown33f503c2009-05-02 12:24:55 +010060 .formats = SND_SOC_STD_AC97_FMTS,},
Eric Miao6335d0552009-03-03 09:41:00 +080061 .ops = &ac97_dai_ops,
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020062};
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020063
Kuninori Morimotoc95869e2018-01-29 02:58:25 +000064static int ac97_soc_probe(struct snd_soc_component *component)
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020065{
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +010066 struct snd_ac97 *ac97;
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020067 struct snd_ac97_bus *ac97_bus;
68 struct snd_ac97_template ac97_template;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000069 int ret;
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020070
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020071 /* add codec as bus device for standard ac97 */
Kuninori Morimotoc95869e2018-01-29 02:58:25 +000072 ret = snd_ac97_bus(component->card->snd_card, 0, soc_ac97_ops,
Lars-Peter Clausen00200102014-07-17 22:01:07 +020073 NULL, &ac97_bus);
Mark Brown24c053e2008-04-23 15:26:45 +020074 if (ret < 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000075 return ret;
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020076
77 memset(&ac97_template, 0, sizeof(struct snd_ac97_template));
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +010078 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &ac97);
Mark Brown24c053e2008-04-23 15:26:45 +020079 if (ret < 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000080 return ret;
Graham Gowerfb48e3c2010-03-25 10:52:12 +103081
Kuninori Morimotoc95869e2018-01-29 02:58:25 +000082 snd_soc_component_set_drvdata(component, ac97);
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +010083
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020084 return 0;
Richard Purdiedbc6b6a2006-10-06 18:38:03 +020085}
86
Manuel Lauss3f775982008-07-03 09:33:10 +020087#ifdef CONFIG_PM
Kuninori Morimotoc95869e2018-01-29 02:58:25 +000088static int ac97_soc_suspend(struct snd_soc_component *component)
Manuel Lauss3f775982008-07-03 09:33:10 +020089{
Kuninori Morimotoc95869e2018-01-29 02:58:25 +000090 struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +010091
92 snd_ac97_suspend(ac97);
Manuel Lauss3f775982008-07-03 09:33:10 +020093
94 return 0;
95}
96
Kuninori Morimotoc95869e2018-01-29 02:58:25 +000097static int ac97_soc_resume(struct snd_soc_component *component)
Manuel Lauss3f775982008-07-03 09:33:10 +020098{
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +010099
Kuninori Morimotoc95869e2018-01-29 02:58:25 +0000100 struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
Lars-Peter Clausen358a8bb2014-11-10 22:41:53 +0100101
102 snd_ac97_resume(ac97);
Manuel Lauss3f775982008-07-03 09:33:10 +0200103
104 return 0;
105}
106#else
107#define ac97_soc_suspend NULL
108#define ac97_soc_resume NULL
109#endif
110
Kuninori Morimotoc95869e2018-01-29 02:58:25 +0000111static const struct snd_soc_component_driver soc_component_dev_ac97 = {
112 .probe = ac97_soc_probe,
113 .suspend = ac97_soc_suspend,
114 .resume = ac97_soc_resume,
115 .dapm_widgets = ac97_widgets,
116 .num_dapm_widgets = ARRAY_SIZE(ac97_widgets),
117 .dapm_routes = ac97_routes,
118 .num_dapm_routes = ARRAY_SIZE(ac97_routes),
119 .idle_bias_on = 1,
120 .use_pmdown_time = 1,
121 .endianness = 1,
122 .non_legacy_dai_naming = 1,
Richard Purdiedbc6b6a2006-10-06 18:38:03 +0200123};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000124
Bill Pemberton7a79e942012-12-07 09:26:37 -0500125static int ac97_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000126{
Kuninori Morimotoc95869e2018-01-29 02:58:25 +0000127 return devm_snd_soc_register_component(&pdev->dev,
128 &soc_component_dev_ac97, &ac97_dai, 1);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000129}
130
Bill Pemberton7a79e942012-12-07 09:26:37 -0500131static int ac97_remove(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000132{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000133 return 0;
134}
135
136static struct platform_driver ac97_codec_driver = {
137 .driver = {
Mark Brown591796b2010-09-23 19:43:07 +0100138 .name = "ac97-codec",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000139 },
140
141 .probe = ac97_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -0500142 .remove = ac97_remove,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000143};
144
Mark Brown5bbcc3c2011-11-23 22:52:08 +0000145module_platform_driver(ac97_codec_driver);
Richard Purdiedbc6b6a2006-10-06 18:38:03 +0200146
147MODULE_DESCRIPTION("Soc Generic AC97 driver");
148MODULE_AUTHOR("Liam Girdwood");
149MODULE_LICENSE("GPL");
Mika Westerberg0afe6b92010-10-13 11:30:33 +0300150MODULE_ALIAS("platform:ac97-codec");