[PATCH 05/11] ALSA: make WM8753 driver a new-style I2C driver
Jonas Bonn
jonas.bonn at gmail.com
Wed Oct 1 16:30:42 CEST 2008
This updates the WM8753 ALSA device driver to use the "new style", driver model
interface.
---
sound/soc/codecs/wm8753.c | 74 ++++++++++++--------------------------------
1 files changed, 20 insertions(+), 54 deletions(-)
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index 52028d9..0b13bad 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -1634,46 +1634,27 @@ static struct snd_soc_device *wm8753_socdev;
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
-/*
- * WM8753 2 wire address is determined by GPIO5
- * state during powerup.
- * low = 0x1a
- * high = 0x1b
- */
-static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
-
-/* Magic definition of all other variables and things */
-I2C_CLIENT_INSMOD;
-
-static struct i2c_driver wm8753_i2c_driver;
-static struct i2c_client client_template;
+static const struct i2c_device_id wm8753_id[] = {
+ {"wm8753", 0},
+ {}
+};
+MODULE_DEVICE_TABLE(i2c, wm8753_id);
-static int wm8753_codec_probe(struct i2c_adapter *adap, int addr, int kind)
+static int wm8753_i2c_probe(struct i2c_client *i2c_client,
+ const struct i2c_device_id *id)
{
struct snd_soc_device *socdev = wm8753_socdev;
struct wm8753_setup_data *setup = socdev->codec_data;
struct snd_soc_codec *codec = socdev->codec;
- struct i2c_client *i2c;
int ret;
- if (addr != setup->i2c_address)
+ /* Is this really useful? */
+ if (i2c_client->addr != setup->i2c_address)
return -ENODEV;
- client_template.adapter = adap;
- client_template.addr = addr;
-
- i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
- if (!i2c)
- return -ENOMEM;
-
- i2c_set_clientdata(i2c, codec);
- codec->control_data = i2c;
-
- ret = i2c_attach_client(i2c);
- if (ret < 0) {
- pr_err("failed to attach codec at addr %x\n", addr);
- goto err;
- }
+ /* codec->control_data must be set before call to wm8753_init */
+ codec->control_data = i2c_client;
+ i2c_set_clientdata(i2c_client, codec);
ret = wm8753_init(socdev);
if (ret < 0) {
@@ -1684,39 +1665,25 @@ static int wm8753_codec_probe(struct i2c_adapter *adap, int addr, int kind)
return ret;
err:
- kfree(i2c);
+ codec->control_data = NULL;
return ret;
}
-static int wm8753_i2c_detach(struct i2c_client *client)
+static int __devexit wm8753_i2c_remove(struct i2c_client *i2c_client)
{
- struct snd_soc_codec *codec = i2c_get_clientdata(client);
- i2c_detach_client(client);
+ struct snd_soc_codec *codec = i2c_get_clientdata(i2c_client);
kfree(codec->reg_cache);
- kfree(client);
return 0;
}
-
-static int wm8753_i2c_attach(struct i2c_adapter *adap)
-{
- return i2c_probe(adap, &addr_data, wm8753_codec_probe);
-}
-
-/* corgi i2c codec control layer */
static struct i2c_driver wm8753_i2c_driver = {
.driver = {
.name = "WM8753 I2C Codec",
.owner = THIS_MODULE,
},
- .id = I2C_DRIVERID_WM8753,
- .attach_adapter = wm8753_i2c_attach,
- .detach_client = wm8753_i2c_detach,
- .command = NULL,
-};
-
-static struct i2c_client client_template = {
- .name = "WM8753",
- .driver = &wm8753_i2c_driver,
+ .id_table = wm8753_id,
+ .probe = wm8753_i2c_probe,
+ .remove = __devexit_p(wm8753_i2c_remove),
+ .class = I2C_CLASS_SOUND
};
#endif
@@ -1728,7 +1695,7 @@ static int wm8753_probe(struct platform_device *pdev)
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);
@@ -1751,7 +1718,6 @@ static int wm8753_probe(struct platform_device *pdev)
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
if (setup->i2c_address) {
- normal_i2c[0] = setup->i2c_address;
codec->hw_write = (hw_write_t)i2c_master_send;
ret = i2c_add_driver(&wm8753_i2c_driver);
if (ret != 0)
--
1.5.4.3
More information about the openmoko-kernel
mailing list