summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sound/soc.h10
-rw-r--r--sound/soc/soc-ac97.c118
-rw-r--r--sound/soc/soc-core.c4
3 files changed, 14 insertions, 118 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 5b4dec693ca5..206cc8d6eefa 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -507,15 +507,7 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
507 struct platform_device *pdev); 507 struct platform_device *pdev);
508 508
509extern struct snd_ac97_bus_ops *soc_ac97_ops; 509extern struct snd_ac97_bus_ops *soc_ac97_ops;
510
511int snd_soc_ac97_register_dai_links(struct snd_soc_card *card);
512#else 510#else
513
514static inline int snd_soc_ac97_register_dai_links(struct snd_soc_card *card)
515{
516 return 0;
517}
518
519static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops, 511static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
520 struct platform_device *pdev) 512 struct platform_device *pdev)
521{ 513{
@@ -808,8 +800,6 @@ struct snd_soc_codec {
808 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */ 800 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
809 unsigned int cache_bypass:1; /* Suppress access to the cache */ 801 unsigned int cache_bypass:1; /* Suppress access to the cache */
810 unsigned int suspended:1; /* Codec is in suspend PM state */ 802 unsigned int suspended:1; /* Codec is in suspend PM state */
811 unsigned int ac97_registered:1; /* Codec has been AC97 registered */
812 unsigned int ac97_created:1; /* Codec has been created by SoC */
813 unsigned int cache_init:1; /* codec cache has been initialized */ 803 unsigned int cache_init:1; /* codec cache has been initialized */
814 u32 cache_sync; /* Cache needs to be synced to hardware */ 804 u32 cache_sync; /* Cache needs to be synced to hardware */
815 805
diff --git a/sound/soc/soc-ac97.c b/sound/soc/soc-ac97.c
index f2ed77b5169a..920d76c43827 100644
--- a/sound/soc/soc-ac97.c
+++ b/sound/soc/soc-ac97.c
@@ -42,80 +42,6 @@ static struct snd_ac97_bus soc_ac97_bus = {
42 .ops = NULL, /* Gets initialized in snd_soc_set_ac97_ops() */ 42 .ops = NULL, /* Gets initialized in snd_soc_set_ac97_ops() */
43}; 43};
44 44
45/* register ac97 codec to bus */
46static int soc_register_ac97_codec(struct snd_soc_codec *codec,
47 struct snd_soc_dai *codec_dai)
48{
49 int ret;
50
51 /* Only instantiate AC97 if not already done by the adaptor
52 * for the generic AC97 subsystem.
53 */
54 if (!codec_dai->driver->ac97_control || codec->ac97_registered)
55 return 0;
56
57 /*
58 * It is possible that the AC97 device is already registered to
59 * the device subsystem. This happens when the device is created
60 * via snd_ac97_mixer(). Currently only SoC codec that does so
61 * is the generic AC97 glue but others migh emerge.
62 *
63 * In those cases we don't try to register the device again.
64 */
65 if (!codec->ac97_created)
66 return 0;
67
68 codec->ac97->dev.bus = &ac97_bus_type;
69 codec->ac97->dev.parent = codec->component.card->dev;
70
71 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
72 codec->component.card->snd_card->number, 0,
73 codec->component.name);
74 ret = device_add(&codec->ac97->dev);
75 if (ret < 0) {
76 dev_err(codec->dev, "ASoC: AC97 device register failed: %d\n",
77 ret);
78 return ret;
79 }
80 codec->ac97_registered = 1;
81
82 return 0;
83}
84
85static void soc_unregister_ac97_codec(struct snd_soc_codec *codec)
86{
87 if (!codec->ac97_registered)
88 return;
89 device_del(&codec->ac97->dev);
90 codec->ac97_registered = 0;
91}
92
93static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
94{
95 int i, ret;
96
97 for (i = 0; i < rtd->num_codecs; i++) {
98 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
99
100 ret = soc_register_ac97_codec(codec_dai->codec, codec_dai);
101 if (ret) {
102 while (--i >= 0)
103 soc_unregister_ac97_codec(codec_dai->codec);
104 return ret;
105 }
106 }
107
108 return 0;
109}
110
111static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
112{
113 int i;
114
115 for (i = 0; i < rtd->num_codecs; i++)
116 soc_unregister_ac97_codec(rtd->codec_dais[i]->codec);
117}
118
119static void soc_ac97_device_release(struct device *dev) 45static void soc_ac97_device_release(struct device *dev)
120{ 46{
121 kfree(to_ac97_t(dev)); 47 kfree(to_ac97_t(dev));
@@ -129,22 +55,28 @@ static void soc_ac97_device_release(struct device *dev)
129 */ 55 */
130int snd_soc_new_ac97_codec(struct snd_soc_codec *codec) 56int snd_soc_new_ac97_codec(struct snd_soc_codec *codec)
131{ 57{
58 int ret;
59
132 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL); 60 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
133 if (codec->ac97 == NULL) 61 if (codec->ac97 == NULL)
134 return -ENOMEM; 62 return -ENOMEM;
135 63
136 codec->ac97->bus = &soc_ac97_bus; 64 codec->ac97->bus = &soc_ac97_bus;
137 codec->ac97->num = 0; 65 codec->ac97->num = 0;
66
67 codec->ac97->dev.bus = &ac97_bus_type;
68 codec->ac97->dev.parent = codec->component.card->dev;
138 codec->ac97->dev.release = soc_ac97_device_release; 69 codec->ac97->dev.release = soc_ac97_device_release;
139 70
140 /* 71 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
141 * Mark the AC97 device to be created by us. This way we ensure that the 72 codec->component.card->snd_card->number, 0,
142 * device will be registered with the device subsystem later on. 73 codec->component.name);
143 */ 74
144 codec->ac97_created = 1; 75 ret = device_register(&codec->ac97->dev);
145 device_initialize(&codec->ac97->dev); 76 if (ret)
77 put_device(&codec->ac97->dev);
146 78
147 return 0; 79 return ret;
148} 80}
149EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); 81EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
150 82
@@ -156,11 +88,10 @@ EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
156 */ 88 */
157void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) 89void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
158{ 90{
159 soc_unregister_ac97_codec(codec); 91 device_del(&codec->ac97->dev);
160 codec->ac97->bus = NULL; 92 codec->ac97->bus = NULL;
161 put_device(&codec->ac97->dev); 93 put_device(&codec->ac97->dev);
162 codec->ac97 = NULL; 94 codec->ac97 = NULL;
163 codec->ac97_created = 0;
164} 95}
165EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); 96EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
166 97
@@ -321,24 +252,3 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
321 return 0; 252 return 0;
322} 253}
323EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops_of_reset); 254EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops_of_reset);
324
325int snd_soc_ac97_register_dai_links(struct snd_soc_card *card)
326{
327 int i;
328 int ret;
329
330 /* register any AC97 codecs */
331 for (i = 0; i < card->num_rtd; i++) {
332 ret = soc_register_ac97_dai_link(&card->rtd[i]);
333 if (ret < 0)
334 goto err;
335 }
336
337 return 0;
338err:
339 dev_err(card->dev,
340 "ASoC: failed to register AC97: %d\n", ret);
341 while (--i >= 0)
342 soc_unregister_ac97_dai_link(&card->rtd[i]);
343 return ret;
344}
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index d883b4ad03ac..fba6e28e18d3 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1671,10 +1671,6 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
1671 goto probe_aux_dev_err; 1671 goto probe_aux_dev_err;
1672 } 1672 }
1673 1673
1674 ret = snd_soc_ac97_register_dai_links(card);
1675 if (ret < 0)
1676 goto probe_aux_dev_err;
1677
1678 card->instantiated = 1; 1674 card->instantiated = 1;
1679 snd_soc_dapm_sync(&card->dapm); 1675 snd_soc_dapm_sync(&card->dapm);
1680 mutex_unlock(&card->mutex); 1676 mutex_unlock(&card->mutex);