[PATCH 09/20] ALSA: Cleanup WM8753 driver after switch to i2c driver model

Jonas Bonn jonas.bonn at gmail.com
Wed Oct 1 21:47:21 CEST 2008


Mainly this concerns device registration.  Registration should be handled
at the machine level and not in the driver itself.  This patch drops
registration at the driver level.

As registration allows for specifying an i2c device address, the setup
data is not needed to be passed to the driver.

Signed-off-by: Jonas Bonn <jonas.bonn at gmail.com>
---
 sound/soc/codecs/wm8753.c          |   60 ++++++-----------------------------
 sound/soc/s3c24xx/neo1973_wm8753.c |    6 ---
 2 files changed, 11 insertions(+), 55 deletions(-)

diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index 48d0aec..933b40d 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -1648,17 +1648,20 @@ static int wm8753_i2c_probe(struct i2c_client *i2c,
 	struct snd_soc_codec *codec = socdev->codec;
 	int ret;
 
+	/* codec->control_data must be set before call to wm8753_init */
 	i2c_set_clientdata(i2c, codec);
 	codec->control_data = i2c;
 
 	ret = wm8753_init(socdev);
-	if (ret < 0)
+	if (ret < 0) {
 		pr_err("failed to initialise WM8753\n");
+		codec->control_data = NULL;
+	}
 
 	return ret;
 }
 
-static int wm8753_i2c_remove(struct i2c_client *client)
+static int __devexit wm8753_i2c_remove(struct i2c_client *client)
 {
 	struct snd_soc_codec *codec = i2c_get_clientdata(client);
 	kfree(codec->reg_cache);
@@ -1679,60 +1682,20 @@ static struct i2c_driver wm8753_i2c_driver = {
 	.probe =    wm8753_i2c_probe,
 	.remove =   wm8753_i2c_remove,
 	.id_table = wm8753_i2c_id,
+	.class =    I2C_CLASS_SOUND
 };
 
-static int wm8753_add_i2c_device(struct platform_device *pdev,
-				 const struct wm8753_setup_data *setup)
-{
-	struct i2c_board_info info;
-	struct i2c_adapter *adapter;
-	struct i2c_client *client;
-	int ret;
-
-	ret = i2c_add_driver(&wm8753_i2c_driver);
-	if (ret != 0) {
-		dev_err(&pdev->dev, "can't add i2c driver\n");
-		return ret;
-	}
-
-	memset(&info, 0, sizeof(struct i2c_board_info));
-	info.addr = setup->i2c_address;
-	strlcpy(info.type, "wm8753", I2C_NAME_SIZE);
-
-	adapter = i2c_get_adapter(setup->i2c_bus);
-	if (!adapter) {
-		dev_err(&pdev->dev, "can't get i2c adapter %d\n",
-			setup->i2c_bus);
-		goto err_driver;
-	}
-
-	client = i2c_new_device(adapter, &info);
-	i2c_put_adapter(adapter);
-	if (!client) {
-		dev_err(&pdev->dev, "can't add i2c device at 0x%x\n",
-			(unsigned int)info.addr);
-		goto err_driver;
-	}
-
-	return 0;
-
-err_driver:
-	i2c_del_driver(&wm8753_i2c_driver);
-	return -ENODEV;
-}
 #endif
 
 static int wm8753_probe(struct platform_device *pdev)
 {
 	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-	struct wm8753_setup_data *setup;
 	struct snd_soc_codec *codec;
 	struct wm8753_priv *wm8753;
 	int ret = 0;
 
-	pr_info("WM8753 Audio Codec %s", WM8753_VERSION);
+	pr_info("WM8753 Audio Codec %s\n", WM8753_VERSION);
 
-	setup = socdev->codec_data;
 	codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
 	if (codec == NULL)
 		return -ENOMEM;
@@ -1752,10 +1715,10 @@ static int wm8753_probe(struct platform_device *pdev)
 	INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work);
 
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
-	if (setup->i2c_address) {
-		codec->hw_write = (hw_write_t)i2c_master_send;
-		ret = wm8753_add_i2c_device(pdev, setup);
-	}
+	codec->hw_write = (hw_write_t)i2c_master_send;
+	ret = i2c_add_driver(&wm8753_i2c_driver);
+	if (ret != 0)
+		printk(KERN_ERR "can't add i2c driver");
 #else
 		/* Add other interfaces here */
 #endif
@@ -1798,7 +1761,6 @@ static int wm8753_remove(struct platform_device *pdev)
 	snd_soc_free_pcms(socdev);
 	snd_soc_dapm_free(socdev);
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
-	i2c_unregister_device(codec->control_data);
 	i2c_del_driver(&wm8753_i2c_driver);
 #endif
 	kfree(codec->private_data);
diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c
index 85a395b..3537f53 100644
--- a/sound/soc/s3c24xx/neo1973_wm8753.c
+++ b/sound/soc/s3c24xx/neo1973_wm8753.c
@@ -584,16 +584,10 @@ static struct snd_soc_machine neo1973 = {
 	.num_links = ARRAY_SIZE(neo1973_dai),
 };
 
-static struct wm8753_setup_data neo1973_wm8753_setup = {
-	.i2c_bus = 0,
-	.i2c_address = 0x1a,
-};
-
 static struct snd_soc_device neo1973_snd_devdata = {
 	.machine = &neo1973,
 	.platform = &s3c24xx_soc_platform,
 	.codec_dev = &soc_codec_dev_wm8753,
-	.codec_data = &neo1973_wm8753_setup,
 };
 
 static int lm4857_i2c_probe(struct i2c_client *client,
-- 
1.5.4.3




More information about the openmoko-kernel mailing list