Commit 4fcbbb67 authored by Mark Brown's avatar Mark Brown

ASoC: Update WM8974 to use standard I2C device probe methods

Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 1a55b3f6
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2006 Wolfson Microelectronics PLC. * Copyright 2006 Wolfson Microelectronics PLC.
* *
* Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com> * Author: Liam Girdwood <linux@wolfsonmicro.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
...@@ -28,13 +28,6 @@ ...@@ -28,13 +28,6 @@
#include "wm8974.h" #include "wm8974.h"
struct snd_soc_codec_device soc_codec_dev_wm8974;
/*
* wm8974 register cache
* We can't read the WM8974 register space when we are
* using 2 wire for device control, so we cache them instead.
*/
static const u16 wm8974_reg[WM8974_CACHEREGNUM] = { static const u16 wm8974_reg[WM8974_CACHEREGNUM] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0050, 0x0000, 0x0140, 0x0000, 0x0050, 0x0000, 0x0140, 0x0000,
...@@ -53,6 +46,13 @@ static const u16 wm8974_reg[WM8974_CACHEREGNUM] = { ...@@ -53,6 +46,13 @@ static const u16 wm8974_reg[WM8974_CACHEREGNUM] = {
0x0000, 0x0000,
}; };
struct wm8974_priv {
struct snd_soc_codec codec;
u16 reg_cache[WM8974_CACHEREGNUM];
};
static struct snd_soc_codec *wm8974_codec;
/* /*
* read wm8974 register cache * read wm8974 register cache
*/ */
...@@ -623,217 +623,182 @@ static int wm8974_resume(struct platform_device *pdev) ...@@ -623,217 +623,182 @@ static int wm8974_resume(struct platform_device *pdev)
return 0; return 0;
} }
/* static int wm8974_probe(struct platform_device *pdev)
* initialise the WM8974 driver
* register the mixer and dsp interfaces with the kernel
*/
static int wm8974_init(struct snd_soc_device *socdev)
{ {
struct snd_soc_codec *codec = socdev->card->codec; struct snd_soc_device *socdev = platform_get_drvdata(pdev);
struct snd_soc_codec *codec;
int ret = 0; int ret = 0;
codec->name = "WM8974"; if (wm8974_codec == NULL) {
codec->owner = THIS_MODULE; dev_err(&pdev->dev, "Codec device not registered\n");
codec->read = wm8974_read_reg_cache; return -ENODEV;
codec->write = wm8974_write; }
codec->set_bias_level = wm8974_set_bias_level;
codec->dai = &wm8974_dai;
codec->num_dai = 1;
codec->reg_cache_size = ARRAY_SIZE(wm8974_reg);
codec->reg_cache = kmemdup(wm8974_reg, sizeof(wm8974_reg), GFP_KERNEL);
if (codec->reg_cache == NULL)
return -ENOMEM;
wm8974_reset(codec); socdev->card->codec = wm8974_codec;
codec = wm8974_codec;
/* register pcms */ /* register pcms */
ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "wm8974: failed to create pcms\n"); dev_err(codec->dev, "failed to create pcms: %d\n", ret);
goto pcm_err; goto pcm_err;
} }
/* power on device */ snd_soc_add_controls(codec, wm8974_snd_controls,
wm8974_set_bias_level(codec, SND_SOC_BIAS_STANDBY); ARRAY_SIZE(wm8974_snd_controls));
wm8974_add_controls(codec);
wm8974_add_widgets(codec); wm8974_add_widgets(codec);
ret = snd_soc_init_card(socdev); ret = snd_soc_init_card(socdev);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "wm8974: failed to register card\n"); dev_err(codec->dev, "failed to register card: %d\n", ret);
goto card_err; goto card_err;
} }
return ret; return ret;
card_err: card_err:
snd_soc_free_pcms(socdev); snd_soc_free_pcms(socdev);
snd_soc_dapm_free(socdev); snd_soc_dapm_free(socdev);
pcm_err: pcm_err:
kfree(codec->reg_cache);
return ret; return ret;
} }
static struct snd_soc_device *wm8974_socdev; /* power down chip */
static int wm8974_remove(struct platform_device *pdev)
#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) {
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
/*
* WM8974 2 wire address is 0x1a
*/
#define I2C_DRIVERID_WM8974 0xfefe /* liam - need a proper id */
static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
/* Magic definition of all other variables and things */ snd_soc_free_pcms(socdev);
I2C_CLIENT_INSMOD; snd_soc_dapm_free(socdev);
static struct i2c_driver wm8974_i2c_driver; return 0;
static struct i2c_client client_template; }
/* If the i2c layer weren't so broken, we could pass this kind of data struct snd_soc_codec_device soc_codec_dev_wm8974 = {
around */ .probe = wm8974_probe,
.remove = wm8974_remove,
.suspend = wm8974_suspend,
.resume = wm8974_resume,
};
EXPORT_SYMBOL_GPL(soc_codec_dev_wm8974);
static int wm8974_codec_probe(struct i2c_adapter *adap, int addr, int kind) static __devinit int wm8974_register(struct wm8974_priv *wm8974)
{ {
struct snd_soc_device *socdev = wm8974_socdev;
struct wm8974_setup_data *setup = socdev->codec_data;
struct snd_soc_codec *codec = socdev->card->codec;
struct i2c_client *i2c;
int ret; int ret;
struct snd_soc_codec *codec = &wm8974->codec;
if (addr != setup->i2c_address) if (wm8974_codec) {
return -ENODEV; dev_err(codec->dev, "Another WM8974 is registered\n");
return -EINVAL;
}
client_template.adapter = adap; mutex_init(&codec->mutex);
client_template.addr = addr; INIT_LIST_HEAD(&codec->dapm_widgets);
INIT_LIST_HEAD(&codec->dapm_paths);
i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); codec->private_data = wm8974;
if (i2c == NULL) { codec->name = "WM8974";
kfree(codec); codec->owner = THIS_MODULE;
return -ENOMEM; codec->read = wm8974_read_reg_cache;
} codec->write = wm8974_write;
i2c_set_clientdata(i2c, codec); codec->bias_level = SND_SOC_BIAS_OFF;
codec->control_data = i2c; codec->set_bias_level = wm8974_set_bias_level;
codec->dai = &wm8974_dai;
codec->num_dai = 1;
codec->reg_cache_size = WM8974_CACHEREGNUM;
codec->reg_cache = &wm8974->reg_cache;
ret = i2c_attach_client(i2c); memcpy(codec->reg_cache, wm8974_reg, sizeof(wm8974_reg));
if (ret < 0) {
pr_err("failed to attach codec at addr %x\n", addr);
goto err;
}
ret = wm8974_init(socdev); ret = wm8974_reset(codec);
if (ret < 0) { if (ret < 0) {
pr_err("failed to initialise WM8974\n"); dev_err(codec->dev, "Failed to issue reset\n");
goto err; return ret;
} }
wm8974_dai.dev = codec->dev;
wm8974_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
wm8974_codec = codec;
ret = snd_soc_register_codec(codec);
if (ret != 0) {
dev_err(codec->dev, "Failed to register codec: %d\n", ret);
return ret; return ret;
}
err: ret = snd_soc_register_dai(&wm8974_dai);
kfree(codec); if (ret != 0) {
kfree(i2c); dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
snd_soc_unregister_codec(codec);
return ret; return ret;
} }
static int wm8974_i2c_detach(struct i2c_client *client)
{
struct snd_soc_codec *codec = i2c_get_clientdata(client);
i2c_detach_client(client);
kfree(codec->reg_cache);
kfree(client);
return 0; return 0;
} }
static int wm8974_i2c_attach(struct i2c_adapter *adap) static __devexit void wm8974_unregister(struct wm8974_priv *wm8974)
{ {
return i2c_probe(adap, &addr_data, wm8974_codec_probe); wm8974_set_bias_level(&wm8974->codec, SND_SOC_BIAS_OFF);
snd_soc_unregister_dai(&wm8974_dai);
snd_soc_unregister_codec(&wm8974->codec);
kfree(wm8974);
wm8974_codec = NULL;
} }
/* corgi i2c codec control layer */ static __devinit int wm8974_i2c_probe(struct i2c_client *i2c,
static struct i2c_driver wm8974_i2c_driver = { const struct i2c_device_id *id)
.driver = {
.name = "WM8974 I2C Codec",
.owner = THIS_MODULE,
},
.id = I2C_DRIVERID_WM8974,
.attach_adapter = wm8974_i2c_attach,
.detach_client = wm8974_i2c_detach,
.command = NULL,
};
static struct i2c_client client_template = {
.name = "WM8974",
.driver = &wm8974_i2c_driver,
};
#endif
static int wm8974_probe(struct platform_device *pdev)
{ {
struct snd_soc_device *socdev = platform_get_drvdata(pdev); struct wm8974_priv *wm8974;
struct wm8974_setup_data *setup;
struct snd_soc_codec *codec; struct snd_soc_codec *codec;
int ret = 0;
setup = socdev->codec_data; wm8974 = kzalloc(sizeof(struct wm8974_priv), GFP_KERNEL);
codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); if (wm8974 == NULL)
if (codec == NULL)
return -ENOMEM; return -ENOMEM;
socdev->card->codec = codec; codec = &wm8974->codec;
mutex_init(&codec->mutex);
INIT_LIST_HEAD(&codec->dapm_widgets);
INIT_LIST_HEAD(&codec->dapm_paths);
wm8974_socdev = socdev;
#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; codec->hw_write = (hw_write_t)i2c_master_send;
ret = i2c_add_driver(&wm8974_i2c_driver);
if (ret != 0)
printk(KERN_ERR "can't add i2c driver");
}
#else
/* Add other interfaces here */
#endif
return ret;
}
/* power down chip */ i2c_set_clientdata(i2c, wm8974);
static int wm8974_remove(struct platform_device *pdev) codec->control_data = i2c;
{
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
struct snd_soc_codec *codec = socdev->card->codec;
if (codec->control_data) codec->dev = &i2c->dev;
wm8974_set_bias_level(codec, SND_SOC_BIAS_OFF);
snd_soc_free_pcms(socdev); return wm8974_register(wm8974);
snd_soc_dapm_free(socdev); }
#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE)
i2c_del_driver(&wm8974_i2c_driver);
#endif
kfree(codec);
static __devexit int wm8974_i2c_remove(struct i2c_client *client)
{
struct wm8974_priv *wm8974 = i2c_get_clientdata(client);
wm8974_unregister(wm8974);
return 0; return 0;
} }
struct snd_soc_codec_device soc_codec_dev_wm8974 = { static const struct i2c_device_id wm8974_i2c_id[] = {
.probe = wm8974_probe, { "wm8974", 0 },
.remove = wm8974_remove, { }
.suspend = wm8974_suspend, };
.resume = wm8974_resume, MODULE_DEVICE_TABLE(i2c, wm8974_i2c_id);
static struct i2c_driver wm8974_i2c_driver = {
.driver = {
.name = "WM8974 I2C Codec",
.owner = THIS_MODULE,
},
.probe = wm8974_i2c_probe,
.remove = __devexit_p(wm8974_i2c_remove),
.id_table = wm8974_i2c_id,
}; };
EXPORT_SYMBOL_GPL(soc_codec_dev_wm8974);
static int __init wm8974_modinit(void) static int __init wm8974_modinit(void)
{ {
return snd_soc_register_dai(&wm8974_dai); return i2c_add_driver(&wm8974_i2c_driver);
} }
module_init(wm8974_modinit); module_init(wm8974_modinit);
static void __exit wm8974_exit(void) static void __exit wm8974_exit(void)
{ {
snd_soc_unregister_dai(&wm8974_dai); i2c_del_driver(&wm8974_i2c_driver);
} }
module_exit(wm8974_exit); module_exit(wm8974_exit);
......
...@@ -93,11 +93,6 @@ ...@@ -93,11 +93,6 @@
#define WM8974_MCLKDIV_8 (6 << 5) #define WM8974_MCLKDIV_8 (6 << 5)
#define WM8974_MCLKDIV_12 (7 << 5) #define WM8974_MCLKDIV_12 (7 << 5)
struct wm8974_setup_data {
unsigned short i2c_address;
};
extern struct snd_soc_dai wm8974_dai; extern struct snd_soc_dai wm8974_dai;
extern struct snd_soc_codec_device soc_codec_dev_wm8974; extern struct snd_soc_codec_device soc_codec_dev_wm8974;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment