Title: [9200] trunk/sound/soc: [!no_src_qa!]sound:soc:ad73311: fix module circular dependency loop.
Revision
9200
Author
lliubbo
Date
2010-10-11 04:53:23 -0400 (Mon, 11 Oct 2010)

Log Message

[!no_src_qa!]sound:soc:ad73311: fix module circular dependency loop.

Current ad73311 driver can't work as modules because of the circular
dependency
loop.

This commit implemented the codec->hw_write() function so as to skip the
dependency and keep the board-specific code in bf5xx-ad73311.c.

Modified Paths

Diff

Modified: trunk/sound/soc/blackfin/bf5xx-ad73311.c (9199 => 9200)


--- trunk/sound/soc/blackfin/bf5xx-ad73311.c	2010-10-10 09:45:38 UTC (rev 9199)
+++ trunk/sound/soc/blackfin/bf5xx-ad73311.c	2010-10-11 08:53:23 UTC (rev 9200)
@@ -52,19 +52,6 @@
 #include "bf5xx-i2s-pcm.h"
 #include "bf5xx-i2s.h"
 
-/*
- * Defaults for amixer-settable parameters, adds to fixed values in
- * snd_ad73311_configure
- * TODO: later not as global variable
- */
-struct ad73311_ctrls ad73311 = {
-	.ogain  = 2,
-	.igain  = 2,
-	.rfseen = 1,
-	.srate  = 0,
-};
-EXPORT_SYMBOL(ad73311);
-
 #if CONFIG_SND_BF5XX_SPORT_NUM == 0
 #define bfin_write_SPORT_TCR1	bfin_write_SPORT0_TCR1
 #define bfin_read_SPORT_TCR1	bfin_read_SPORT0_TCR1
@@ -83,7 +70,53 @@
 #define GPIO_RESET CONFIG_SND_BFIN_AD73311_RESET
 
 static struct snd_soc_card bf5xx_ad73311;
+static int bf5xx_probe(struct platform_device *pdev);
 
+static int bf5xx_ad73311_hw_params(struct snd_pcm_substream *substream,
+	struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
+	int ret = 0;
+
+	pr_debug("%s rate %d format %x\n", __func__, params_rate(params),
+		params_format(params));
+
+	/* set cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A |
+		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+
+static struct snd_soc_ops bf5xx_ad73311_ops = {
+	.hw_params = bf5xx_ad73311_hw_params,
+};
+
+static struct snd_soc_dai_link bf5xx_ad73311_dai = {
+	.name = "ad73311",
+	.stream_name = "AD73311",
+	.cpu_dai = &bf5xx_i2s_dai,
+	.codec_dai = &ad73311_dai,
+	.ops = &bf5xx_ad73311_ops,
+};
+
+static struct snd_soc_card bf5xx_ad73311 = {
+	.name = "bf5xx_ad73311",
+	.platform = &bf5xx_i2s_soc_platform,
+	.probe = bf5xx_probe,
+	.dai_link = &bf5xx_ad73311_dai,
+	.num_links = 1,
+};
+
+static struct snd_soc_device bf5xx_ad73311_snd_devdata = {
+	.card = &bf5xx_ad73311,
+	.codec_dev = &soc_codec_dev_ad73311,
+};
+
 static int snd_ad73311_reset(void)
 {
 	gpio_set_value(GPIO_RESET, 0);
@@ -172,11 +205,11 @@
 	return 0;
 }
 
-int ad73311_reg_config(void)
+static int bf5xx_ad73311_reg_write(void *control_data, const char *data,
+				 int len)
 {
 	return snd_ad73311_configure();
 }
-EXPORT_SYMBOL(ad73311_reg_config);
 
 static int bf5xx_probe(struct platform_device *pdev)
 {
@@ -196,6 +229,8 @@
 	gpio_direction_output(GPIO_SE, 0);
 	gpio_direction_output(GPIO_RESET, 0);
 
+	if (ad73311_codec != NULL)
+		ad73311_codec->hw_write = bf5xx_ad73311_reg_write;
 	err = snd_ad73311_configure();
 	if (err < 0)
 		return -EFAULT;
@@ -203,51 +238,6 @@
 	return 0;
 }
 
-static int bf5xx_ad73311_hw_params(struct snd_pcm_substream *substream,
-	struct snd_pcm_hw_params *params)
-{
-	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
-	int ret = 0;
-
-	pr_debug("%s rate %d format %x\n", __func__, params_rate(params),
-		params_format(params));
-
-	/* set cpu DAI configuration */
-	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A |
-		SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
-	if (ret < 0)
-		return ret;
-
-	return 0;
-}
-
-
-static struct snd_soc_ops bf5xx_ad73311_ops = {
-	.hw_params = bf5xx_ad73311_hw_params,
-};
-
-static struct snd_soc_dai_link bf5xx_ad73311_dai = {
-	.name = "ad73311",
-	.stream_name = "AD73311",
-	.cpu_dai = &bf5xx_i2s_dai,
-	.codec_dai = &ad73311_dai,
-	.ops = &bf5xx_ad73311_ops,
-};
-
-static struct snd_soc_card bf5xx_ad73311 = {
-	.name = "bf5xx_ad73311",
-	.platform = &bf5xx_i2s_soc_platform,
-	.probe = bf5xx_probe,
-	.dai_link = &bf5xx_ad73311_dai,
-	.num_links = 1,
-};
-
-static struct snd_soc_device bf5xx_ad73311_snd_devdata = {
-	.card = &bf5xx_ad73311,
-	.codec_dev = &soc_codec_dev_ad73311,
-};
-
 static struct platform_device *bf5xx_ad73311_snd_device;
 
 static int __init bf5xx_ad73311_init(void)

Modified: trunk/sound/soc/codecs/ad73311.c (9199 => 9200)


--- trunk/sound/soc/codecs/ad73311.c	2010-10-10 09:45:38 UTC (rev 9199)
+++ trunk/sound/soc/codecs/ad73311.c	2010-10-11 08:53:23 UTC (rev 9200)
@@ -34,12 +34,26 @@
 					SNDRV_PCM_RATE_32000 | \
 					SNDRV_PCM_RATE_64000)
 
+struct snd_soc_codec *ad73311_codec;
+EXPORT_SYMBOL(ad73311_codec);
+
+struct ad73311_ctrls ad73311 = {
+	.ogain  = 2,
+	.igain  = 2,
+	.rfseen = 1,
+	.srate  = 0,
+};
+EXPORT_SYMBOL(ad73311);
+
 static int ad73311_ogain_put(struct snd_kcontrol *kcontrol,
 				struct snd_ctl_elem_value *uvalue)
 {
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
 	if (ad73311.ogain != (7 - uvalue->value.integer.value[0])) {
 		ad73311.ogain = 7 - uvalue->value.integer.value[0];
-		return ad73311_reg_config();
+		return codec->hw_write(codec->control_data, (char *)&ad73311,
+						sizeof(struct ad73311_ctrls));
 	}
 	return 0;
 }
@@ -54,9 +68,11 @@
 static int ad73311_igain_put(struct snd_kcontrol *kcontrol,
 				struct snd_ctl_elem_value *uvalue)
 {
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
 	if (ad73311.igain != uvalue->value.integer.value[0]) {
 		ad73311.igain =  uvalue->value.integer.value[0];
-		return ad73311_reg_config();
+		return codec->hw_write(codec->control_data, (char *)&ad73311,
+						sizeof(struct ad73311_ctrls));
 	}
 	return 0;
 }
@@ -71,9 +87,11 @@
 static int ad73311_rfseen_put(struct snd_kcontrol *kcontrol,
 				struct snd_ctl_elem_value *uvalue)
 {
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
 	if (ad73311.rfseen != uvalue->value.integer.value[0]) {
 		ad73311.rfseen = uvalue->value.integer.value[0];
-		return ad73311_reg_config();
+		return codec->hw_write(codec->control_data, (char *)&ad73311,
+						sizeof(struct ad73311_ctrls));
 	}
 	return 0;
 
@@ -90,6 +108,7 @@
 				struct snd_ctl_elem_value *uvalue)
 {
 	int tmpvar = 0;
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
 	if (ad73311.srate != uvalue->value.integer.value[0]) {
 		ad73311.srate = uvalue->value.integer.value[0];
 		switch (ad73311.srate) {
@@ -108,7 +127,8 @@
 		}
 		ad73311_dai.playback.rates = tmpvar;
 		ad73311_dai.capture.rates = tmpvar;
-		return ad73311_reg_config();
+		return codec->hw_write(codec->control_data, (char *)&ad73311,
+						sizeof(struct ad73311_ctrls));
 	}
 	return 0;
 
@@ -148,12 +168,9 @@
 static int ad73311_soc_probe(struct platform_device *pdev)
 {
 	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-	struct snd_soc_codec *codec;
+	struct snd_soc_codec *codec = ad73311_codec;
 	int ret = 0;
 
-	codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
-	if (codec == NULL)
-		return -ENOMEM;
 	mutex_init(&codec->mutex);
 	codec->name = DRV_NAME;
 	codec->dev = &pdev->dev;
@@ -178,7 +195,6 @@
 	return ret;
 
 pcm_err:
-	kfree(socdev->card->codec);
 	socdev->card->codec = NULL;
 	return ret;
 }
@@ -186,12 +202,7 @@
 static int ad73311_soc_remove(struct platform_device *pdev)
 {
 	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-	struct snd_soc_codec *codec = socdev->card->codec;
-
-	if (codec == NULL)
-		return 0;
 	snd_soc_free_pcms(socdev);
-	kfree(codec);
 	return 0;
 }
 
@@ -203,13 +214,23 @@
 
 static int __init ad73311_init(void)
 {
+	struct snd_soc_codec *codec;
+
+	codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
+	if (codec == NULL)
+		return -ENOMEM;
+	ad73311_codec = codec;
 	return snd_soc_register_dai(&ad73311_dai);
 }
 module_init(ad73311_init);
 
 static void __exit ad73311_exit(void)
 {
+	struct snd_soc_codec *codec = ad73311_codec;
+
 	snd_soc_unregister_dai(&ad73311_dai);
+	ad73311_codec = NULL;
+	kfree(codec);
 }
 module_exit(ad73311_exit);
 

Modified: trunk/sound/soc/codecs/ad73311.h (9199 => 9200)


--- trunk/sound/soc/codecs/ad73311.h	2010-10-10 09:45:38 UTC (rev 9199)
+++ trunk/sound/soc/codecs/ad73311.h	2010-10-11 08:53:23 UTC (rev 9200)
@@ -151,5 +151,5 @@
 extern struct snd_soc_dai ad73311_dai;
 extern struct snd_soc_codec_device soc_codec_dev_ad73311;
 extern struct ad73311_ctrls ad73311;
-extern int ad73311_reg_config(void);
+extern struct snd_soc_codec *ad73311_codec;
 #endif
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits

Reply via email to