diff options
author | Stephen Warren <swarren@nvidia.com> | 2011-12-02 17:08:38 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-12-03 06:19:08 -0500 |
commit | c0eb27cf84ffd79347907f07ae33061ba0034c41 (patch) | |
tree | e16f7811f2978b732ddbc0c7d983881c36a6ac0d | |
parent | 672b0c6a37d3bf951a449cff9f6c98b7dfc47a16 (diff) |
ASoC: WM8903: Create default platform data structure
When no platform data is supplied, point pdata at a default platform
structure. This enables two future changes:
a) Defines the default platform data values in a single place.
b) There is always a valid pdata pointer, so some conditional code can
be simplified by a later patch.
Based on work by John Bonesio, but significantly reworked since then.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r-- | sound/soc/codecs/wm8903.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c index a75688b5a568..e6ecede576dc 100644 --- a/sound/soc/codecs/wm8903.c +++ b/sound/soc/codecs/wm8903.c | |||
@@ -114,6 +114,7 @@ static const struct reg_default wm8903_reg_defaults[] = { | |||
114 | }; | 114 | }; |
115 | 115 | ||
116 | struct wm8903_priv { | 116 | struct wm8903_priv { |
117 | struct wm8903_platform_data *pdata; | ||
117 | struct snd_soc_codec *codec; | 118 | struct snd_soc_codec *codec; |
118 | struct regmap *regmap; | 119 | struct regmap *regmap; |
119 | 120 | ||
@@ -1834,7 +1835,7 @@ static struct gpio_chip wm8903_template_chip = { | |||
1834 | static void wm8903_init_gpio(struct snd_soc_codec *codec) | 1835 | static void wm8903_init_gpio(struct snd_soc_codec *codec) |
1835 | { | 1836 | { |
1836 | struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); | 1837 | struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); |
1837 | struct wm8903_platform_data *pdata = dev_get_platdata(codec->dev); | 1838 | struct wm8903_platform_data *pdata = wm8903->pdata; |
1838 | int ret; | 1839 | int ret; |
1839 | 1840 | ||
1840 | wm8903->gpio_chip = wm8903_template_chip; | 1841 | wm8903->gpio_chip = wm8903_template_chip; |
@@ -1872,8 +1873,8 @@ static void wm8903_free_gpio(struct snd_soc_codec *codec) | |||
1872 | 1873 | ||
1873 | static int wm8903_probe(struct snd_soc_codec *codec) | 1874 | static int wm8903_probe(struct snd_soc_codec *codec) |
1874 | { | 1875 | { |
1875 | struct wm8903_platform_data *pdata = dev_get_platdata(codec->dev); | ||
1876 | struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); | 1876 | struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); |
1877 | struct wm8903_platform_data *pdata = wm8903->pdata; | ||
1877 | int ret, i; | 1878 | int ret, i; |
1878 | int trigger, irq_pol; | 1879 | int trigger, irq_pol; |
1879 | u16 val; | 1880 | u16 val; |
@@ -2039,6 +2040,7 @@ static const struct regmap_config wm8903_regmap = { | |||
2039 | static __devinit int wm8903_i2c_probe(struct i2c_client *i2c, | 2040 | static __devinit int wm8903_i2c_probe(struct i2c_client *i2c, |
2040 | const struct i2c_device_id *id) | 2041 | const struct i2c_device_id *id) |
2041 | { | 2042 | { |
2043 | struct wm8903_platform_data *pdata = dev_get_platdata(&i2c->dev); | ||
2042 | struct wm8903_priv *wm8903; | 2044 | struct wm8903_priv *wm8903; |
2043 | unsigned int val; | 2045 | unsigned int val; |
2044 | int ret; | 2046 | int ret; |
@@ -2059,6 +2061,19 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c, | |||
2059 | i2c_set_clientdata(i2c, wm8903); | 2061 | i2c_set_clientdata(i2c, wm8903); |
2060 | wm8903->irq = i2c->irq; | 2062 | wm8903->irq = i2c->irq; |
2061 | 2063 | ||
2064 | /* If no platform data was supplied, create storage for defaults */ | ||
2065 | if (pdata) { | ||
2066 | wm8903->pdata = pdata; | ||
2067 | } else { | ||
2068 | wm8903->pdata = devm_kzalloc(&i2c->dev, | ||
2069 | sizeof(struct wm8903_platform_data), | ||
2070 | GFP_KERNEL); | ||
2071 | if (wm8903->pdata == NULL) { | ||
2072 | dev_err(&i2c->dev, "Failed to allocate pdata\n"); | ||
2073 | return -ENOMEM; | ||
2074 | } | ||
2075 | } | ||
2076 | |||
2062 | ret = regmap_read(wm8903->regmap, WM8903_SW_RESET_AND_ID, &val); | 2077 | ret = regmap_read(wm8903->regmap, WM8903_SW_RESET_AND_ID, &val); |
2063 | if (ret != 0) { | 2078 | if (ret != 0) { |
2064 | dev_err(&i2c->dev, "Failed to read chip ID: %d\n", ret); | 2079 | dev_err(&i2c->dev, "Failed to read chip ID: %d\n", ret); |