Skip to content

Commit

Permalink
ASoC: Add indirection for CODEC private data
Browse files Browse the repository at this point in the history
One of the features of the multi CODEC work is that it embeds a struct
device in the CODEC to provide diagnostics via a sysfs class rather than
via the device tree, at which point it's much better to use the struct
device private data rather than having two places to store it. Provide
an accessor function to allow this change to be made more easily, and
update all the CODEC drivers are updated.

To ensure use of the accessor the private data structure member is
renamed, meaning that if code developed with older an older core that
still uses private_data is merged it will fail to build.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
  • Loading branch information
Mark Brown committed Apr 17, 2010
1 parent 890c681 commit b2c812e
Show file tree
Hide file tree
Showing 43 changed files with 258 additions and 247 deletions.
13 changes: 12 additions & 1 deletion include/sound/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ struct snd_soc_codec {
struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
unsigned int active;
unsigned int pcm_devs;
void *private_data;
void *drvdata;

/* codec IO */
void *control_data; /* codec control (i2c/3wire) data */
Expand Down Expand Up @@ -597,6 +597,17 @@ static inline unsigned int snd_soc_write(struct snd_soc_codec *codec,
return codec->write(codec, reg, val);
}

static inline void snd_soc_codec_set_drvdata(struct snd_soc_codec *codec,
void *data)
{
codec->drvdata = data;
}

static inline void *snd_soc_codec_get_drvdata(struct snd_soc_codec *codec)
{
return codec->drvdata;
}

#include <sound/soc-dai.h>

#endif
2 changes: 1 addition & 1 deletion sound/soc/codecs/ad1836.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ static int ad1836_register(struct ad1836_priv *ad1836)
mutex_init(&codec->mutex);
INIT_LIST_HEAD(&codec->dapm_widgets);
INIT_LIST_HEAD(&codec->dapm_paths);
codec->private_data = ad1836;
snd_soc_codec_set_drvdata(codec, ad1836);
codec->reg_cache = ad1836->reg_cache;
codec->reg_cache_size = AD1836_NUM_REGS;
codec->name = "AD1836";
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/ad193x.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static int ad193x_bus_probe(struct device *dev, void *ctrl_data, int bus_type)
mutex_init(&codec->mutex);
codec->control_data = ctrl_data;
codec->dev = dev;
codec->private_data = ad193x;
snd_soc_codec_set_drvdata(codec, ad193x);
codec->reg_cache = ad193x->reg_cache;
codec->reg_cache_size = AD193X_NUM_REGS;
codec->name = "AD193X";
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/ak4104.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static int ak4104_spi_probe(struct spi_device *spi)
codec->owner = THIS_MODULE;
codec->dai = &ak4104_dai;
codec->num_dai = 1;
codec->private_data = ak4104;
snd_soc_codec_set_drvdata(codec, ak4104);
codec->control_data = spi;
codec->reg_cache = ak4104->reg_cache;
codec->reg_cache_size = AK4104_NUM_REGS;
Expand Down
10 changes: 5 additions & 5 deletions sound/soc/codecs/ak4535.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static int ak4535_set_dai_sysclk(struct snd_soc_dai *codec_dai,
int clk_id, unsigned int freq, int dir)
{
struct snd_soc_codec *codec = codec_dai->codec;
struct ak4535_priv *ak4535 = codec->private_data;
struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);

ak4535->sysclk = freq;
return 0;
Expand All @@ -314,7 +314,7 @@ static int ak4535_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_device *socdev = rtd->socdev;
struct snd_soc_codec *codec = socdev->card->codec;
struct ak4535_priv *ak4535 = codec->private_data;
struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
u8 mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2) & ~(0x3 << 5);
int rate = params_rate(params), fs = 256;

Expand Down Expand Up @@ -599,7 +599,7 @@ static int ak4535_probe(struct platform_device *pdev)
return -ENOMEM;
}

codec->private_data = ak4535;
snd_soc_codec_set_drvdata(codec, ak4535);
socdev->card->codec = codec;
mutex_init(&codec->mutex);
INIT_LIST_HEAD(&codec->dapm_widgets);
Expand All @@ -616,7 +616,7 @@ static int ak4535_probe(struct platform_device *pdev)
#endif

if (ret != 0) {
kfree(codec->private_data);
kfree(snd_soc_codec_get_drvdata(codec));
kfree(codec);
}
return ret;
Expand All @@ -638,7 +638,7 @@ static int ak4535_remove(struct platform_device *pdev)
i2c_unregister_device(codec->control_data);
i2c_del_driver(&ak4535_i2c_driver);
#endif
kfree(codec->private_data);
kfree(snd_soc_codec_get_drvdata(codec));
kfree(codec);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/ak4642.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ static int ak4642_init(struct ak4642_priv *ak4642)
INIT_LIST_HEAD(&codec->dapm_widgets);
INIT_LIST_HEAD(&codec->dapm_paths);

codec->private_data = ak4642;
snd_soc_codec_set_drvdata(codec, ak4642);
codec->name = "AK4642";
codec->owner = THIS_MODULE;
codec->read = ak4642_read_reg_cache;
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/ak4671.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ static int ak4671_register(struct ak4671_priv *ak4671,
INIT_LIST_HEAD(&codec->dapm_widgets);
INIT_LIST_HEAD(&codec->dapm_paths);

codec->private_data = ak4671;
snd_soc_codec_set_drvdata(codec, ak4671);
codec->name = "AK4671";
codec->owner = THIS_MODULE;
codec->bias_level = SND_SOC_BIAS_OFF;
Expand Down
20 changes: 10 additions & 10 deletions sound/soc/codecs/cs4270.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai,
int clk_id, unsigned int freq, int dir)
{
struct snd_soc_codec *codec = codec_dai->codec;
struct cs4270_private *cs4270 = codec->private_data;
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
unsigned int rates = 0;
unsigned int rate_min = -1;
unsigned int rate_max = 0;
Expand Down Expand Up @@ -269,7 +269,7 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai,
unsigned int format)
{
struct snd_soc_codec *codec = codec_dai->codec;
struct cs4270_private *cs4270 = codec->private_data;
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
int ret = 0;

/* set DAI format */
Expand Down Expand Up @@ -411,7 +411,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_device *socdev = rtd->socdev;
struct snd_soc_codec *codec = socdev->card->codec;
struct cs4270_private *cs4270 = codec->private_data;
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
int ret;
unsigned int i;
unsigned int rate;
Expand Down Expand Up @@ -490,7 +490,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
static int cs4270_dai_mute(struct snd_soc_dai *dai, int mute)
{
struct snd_soc_codec *codec = dai->codec;
struct cs4270_private *cs4270 = codec->private_data;
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
int reg6;

reg6 = snd_soc_read(codec, CS4270_MUTE);
Expand Down Expand Up @@ -523,7 +523,7 @@ static int cs4270_soc_put_mute(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
struct cs4270_private *cs4270 = codec->private_data;
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
int left = !ucontrol->value.integer.value[0];
int right = !ucontrol->value.integer.value[1];

Expand Down Expand Up @@ -599,7 +599,7 @@ static int cs4270_probe(struct platform_device *pdev)
{
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
struct snd_soc_codec *codec = cs4270_codec;
struct cs4270_private *cs4270 = codec->private_data;
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
int i, ret;

/* Connect the codec to the socdev. snd_soc_new_pcms() needs this. */
Expand Down Expand Up @@ -656,7 +656,7 @@ static int cs4270_remove(struct platform_device *pdev)
{
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
struct snd_soc_codec *codec = cs4270_codec;
struct cs4270_private *cs4270 = codec->private_data;
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);

snd_soc_free_pcms(socdev);
regulator_bulk_disable(ARRAY_SIZE(cs4270->supplies), cs4270->supplies);
Expand Down Expand Up @@ -729,7 +729,7 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client,
codec->owner = THIS_MODULE;
codec->dai = &cs4270_dai;
codec->num_dai = 1;
codec->private_data = cs4270;
snd_soc_codec_set_drvdata(codec, cs4270);
codec->control_data = i2c_client;
codec->read = cs4270_read_reg_cache;
codec->write = cs4270_i2c_write;
Expand Down Expand Up @@ -842,7 +842,7 @@ MODULE_DEVICE_TABLE(i2c, cs4270_id);
static int cs4270_soc_suspend(struct platform_device *pdev, pm_message_t mesg)
{
struct snd_soc_codec *codec = cs4270_codec;
struct cs4270_private *cs4270 = codec->private_data;
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
int reg, ret;

reg = snd_soc_read(codec, CS4270_PWRCTL) | CS4270_PWRCTL_PDN_ALL;
Expand All @@ -862,7 +862,7 @@ static int cs4270_soc_suspend(struct platform_device *pdev, pm_message_t mesg)
static int cs4270_soc_resume(struct platform_device *pdev)
{
struct snd_soc_codec *codec = cs4270_codec;
struct cs4270_private *cs4270 = codec->private_data;
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
struct i2c_client *i2c_client = codec->control_data;
int reg;

Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/cx20442.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ static int cx20442_register(struct cx20442_priv *cx20442)

codec->name = "CX20442";
codec->owner = THIS_MODULE;
codec->private_data = cx20442;
snd_soc_codec_set_drvdata(codec, cx20442);

codec->dai = &cx20442_dai;
codec->num_dai = 1;
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/da7210.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ static int da7210_init(struct da7210_priv *da7210)
INIT_LIST_HEAD(&codec->dapm_widgets);
INIT_LIST_HEAD(&codec->dapm_paths);

codec->private_data = da7210;
snd_soc_codec_set_drvdata(codec, da7210);
codec->name = "DA7210";
codec->owner = THIS_MODULE;
codec->read = da7210_read;
Expand Down
12 changes: 6 additions & 6 deletions sound/soc/codecs/ssm2602.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ static int ssm2602_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_device *socdev = rtd->socdev;
struct snd_soc_codec *codec = socdev->card->codec;
struct ssm2602_priv *ssm2602 = codec->private_data;
struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
struct i2c_client *i2c = codec->control_data;
u16 iface = ssm2602_read_reg_cache(codec, SSM2602_IFACE) & 0xfff3;
int i = get_coeff(ssm2602->sysclk, params_rate(params));
Expand Down Expand Up @@ -322,7 +322,7 @@ static int ssm2602_startup(struct snd_pcm_substream *substream,
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_device *socdev = rtd->socdev;
struct snd_soc_codec *codec = socdev->card->codec;
struct ssm2602_priv *ssm2602 = codec->private_data;
struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
struct i2c_client *i2c = codec->control_data;
struct snd_pcm_runtime *master_runtime;

Expand Down Expand Up @@ -373,7 +373,7 @@ static void ssm2602_shutdown(struct snd_pcm_substream *substream,
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_device *socdev = rtd->socdev;
struct snd_soc_codec *codec = socdev->card->codec;
struct ssm2602_priv *ssm2602 = codec->private_data;
struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);

/* deactivate */
if (!codec->active)
Expand Down Expand Up @@ -401,7 +401,7 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai,
int clk_id, unsigned int freq, int dir)
{
struct snd_soc_codec *codec = codec_dai->codec;
struct ssm2602_priv *ssm2602 = codec->private_data;
struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
switch (freq) {
case 11289600:
case 12000000:
Expand Down Expand Up @@ -726,7 +726,7 @@ static int ssm2602_probe(struct platform_device *pdev)
return -ENOMEM;
}

codec->private_data = ssm2602;
snd_soc_codec_set_drvdata(codec, ssm2602);
socdev->card->codec = codec;
mutex_init(&codec->mutex);
INIT_LIST_HEAD(&codec->dapm_widgets);
Expand Down Expand Up @@ -759,7 +759,7 @@ static int ssm2602_remove(struct platform_device *pdev)
i2c_unregister_device(codec->control_data);
i2c_del_driver(&ssm2602_i2c_driver);
#endif
kfree(codec->private_data);
kfree(snd_soc_codec_get_drvdata(codec));
kfree(codec);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/stac9766.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ static int stac9766_codec_probe(struct platform_device *pdev)
pcm_err:
snd_soc_free_ac97_codec(codec);
codec_err:
kfree(codec->private_data);
kfree(snd_soc_codec_get_drvdata(codec));
cache_err:
kfree(socdev->card->codec);
socdev->card->codec = NULL;
Expand Down
10 changes: 5 additions & 5 deletions sound/soc/codecs/tlv320aic3x.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_device *socdev = rtd->socdev;
struct snd_soc_codec *codec = socdev->card->codec;
struct aic3x_priv *aic3x = codec->private_data;
struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
u16 d, pll_d = 1;
Expand Down Expand Up @@ -930,7 +930,7 @@ static int aic3x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
int clk_id, unsigned int freq, int dir)
{
struct snd_soc_codec *codec = codec_dai->codec;
struct aic3x_priv *aic3x = codec->private_data;
struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);

aic3x->sysclk = freq;
return 0;
Expand All @@ -940,7 +940,7 @@ static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
unsigned int fmt)
{
struct snd_soc_codec *codec = codec_dai->codec;
struct aic3x_priv *aic3x = codec->private_data;
struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
u8 iface_areg, iface_breg;
int delay = 0;

Expand Down Expand Up @@ -994,7 +994,7 @@ static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
static int aic3x_set_bias_level(struct snd_soc_codec *codec,
enum snd_soc_bias_level level)
{
struct aic3x_priv *aic3x = codec->private_data;
struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
u8 reg;

switch (level) {
Expand Down Expand Up @@ -1338,7 +1338,7 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,

codec = &aic3x->codec;
codec->dev = &i2c->dev;
codec->private_data = aic3x;
snd_soc_codec_set_drvdata(codec, aic3x);
codec->control_data = i2c;
codec->hw_write = (hw_write_t) i2c_master_send;

Expand Down
Loading

0 comments on commit b2c812e

Please sign in to comment.