ASoC: Make WM8978 I2C usage unconditional
Subsystems (3)
PATCH 1/7 ASoC: Make WM8978 I2C usage unconditional
The driver only supports I2C.
Signed-off-by Mark Brown <[email protected]>
--- sound/soc/codecs/wm8978.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
sound/soc/codecs/wm8978.c +0 -6
@@ -1001,7 +1001,6 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8978 = { .reg_cache_default = wm8978_reg, }; -#if defined(CONFIG_I2C ) || defined(CONFIG_I2C_MODULE )static __devinit int wm8978_i2c_probe (struct i2c_client *i2c,const struct i2c_device_id *id) {
@@ -1043,27 +1042,22 @@ static struct i2c_driver wm8978_i2c_driver = { .remove = __devexit_p(wm8978_i2c_remove), .id_table = wm8978_i2c_id, }; -#endif static int __init wm8978_modinit (void ) {int ret =0 ; -#if defined(CONFIG_I2C ) || defined(CONFIG_I2C_MODULE ) ret =i2c_add_driver (&wm8978_i2c_driver);if (ret !=0 ) {printk (KERN_ERR "Failed to register WM8978 I2C driver: %d\n" , ret); } -#endif return ret; }module_init (wm8978_modinit); static void __exit wm8978_exit(void) { -#if defined(CONFIG_I2C ) || defined(CONFIG_I2C_MODULE )i2c_del_driver (&wm8978_i2c_driver); -#endif }module_exit (wm8978_exit);
Signature · 1 line
1.7.7.3
PATCH 2/7 ASoC: Remove unused control type from wm8978 driver
Signed-off-by Mark Brown <[email protected]>
--- sound/soc/codecs/wm8978.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
sound/soc/codecs/wm8978.c +0 -1
@@ -50,7 +50,6 @@ static const u16 wm8978_reg[WM8978_CACHEREGNUM] = {/* codec private data */ struct wm8978_priv { -enum snd_soc_control_type control_type;unsigned int f_pllout;unsigned int f_mclk;unsigned int f_256fs;
Signature · 1 line
1.7.7.3
PATCH 3/7 ASoC: Convert wm8978 to table based DAPM and control init
In reply to Mark BrownSigned-off-by Mark Brown <[email protected]>
--- sound/soc/codecs/wm8978.c | 25 ++++++++----------------- 1 files changed, 8 insertions(+), 17 deletions(-)
sound/soc/codecs/wm8978.c +8 -17
@@ -302,7 +302,7 @@ static const struct snd_soc_dapm_widget wm8978_dapm_widgets[] = { SND_SOC_DAPM_OUTPUT("RSPK"), }; -static const struct snd_soc_dapm_route audio_map[] = { +static const struct snd_soc_dapm_route wm8978_dapm_routes[] = {/* Output mixer */ {"Right Output Mixer" ,"PCM Playback Switch" ,"Right DAC" }, {"Right Output Mixer" ,"Aux Playback Switch" ,"RAUX" },
@@ -351,18 +351,6 @@ static const struct snd_soc_dapm_route audio_map[] = { {"Left Input Mixer", "MicP Switch", "LMICP"}, }; -static int wm8978_add_widgets (struct snd_soc_codec *codec) -{ -struct snd_soc_dapm_context *dapm = &codec->dapm; - -snd_soc_dapm_new_controls (dapm, wm8978_dapm_widgets, -ARRAY_SIZE (wm8978_dapm_widgets)); -/* set up the WM8978 audio map */ -snd_soc_dapm_add_routes (dapm, audio_map,ARRAY_SIZE (audio_map)); - -return 0 ; -} -/* PLL divisors */ struct wm8978_pll_div { u32 k;
@@ -975,10 +963,6 @@ static int wm8978_probe(struct snd_soc_codec *codec)wm8978_set_bias_level (codec,SND_SOC_BIAS_STANDBY ); -snd_soc_add_controls (codec, wm8978_snd_controls, -ARRAY_SIZE (wm8978_snd_controls)); -wm8978_add_widgets (codec); -return 0 ; }
@@ -998,6 +982,13 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8978 = { .reg_cache_size = ARRAY_SIZE(wm8978_reg), .reg_word_size = sizeof(u16), .reg_cache_default = wm8978_reg, + + .controls = wm8978_snd_controls, + .num_controls = ARRAY_SIZE(wm8978_snd_controls), + .dapm_widgets = wm8978_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(wm8978_dapm_widgets), + .dapm_routes = wm8978_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(wm8978_dapm_routes), }; static __devinit int wm8978_i2c_probe(struct i2c_client *i2c,
Signature · 1 line
1.7.7.3
PATCH 4/7 ASoC: Convert wm8978 to devm_kzalloc()
In reply to Mark BrownSigned-off-by Mark Brown <[email protected]>
--- sound/soc/codecs/wm8978.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
sound/soc/codecs/wm8978.c +4 -4
@@ -997,7 +997,8 @@ static __devinit int wm8978_i2c_probe(struct i2c_client *i2c,struct wm8978_priv *wm8978;int ret; - wm8978 =kzalloc (sizeof (struct wm8978_priv ),GFP_KERNEL ); + wm8978 =devm_kzalloc (&i2c->dev,sizeof (struct wm8978_priv ), +GFP_KERNEL );if (wm8978 ==NULL )return -ENOMEM ;
@@ -1005,15 +1006,14 @@ static __devinit int wm8978_i2c_probe(struct i2c_client *i2c, ret =snd_soc_register_codec (&i2c->dev, &soc_codec_dev_wm8978, &wm8978_dai,1 ); -if (ret <0 ) -kfree (wm8978); +return ret; } static __devexit int wm8978_i2c_remove(struct i2c_client *client) {snd_soc_unregister_codec (&client->dev); -kfree (i2c_get_clientdata (client)); +return 0 ; }
Signature · 1 line
1.7.7.3
PATCH 5/7 ASoC: Use standard cache sync for WM8978
In reply to Mark BrownSaves a bit of code and supports further refactoring.
Signed-off-by Mark Brown <[email protected]>
--- sound/soc/codecs/wm8978.c | 9 +-------- 1 files changed, 1 insertions(+), 8 deletions(-)
sound/soc/codecs/wm8978.c +1 -8
@@ -891,16 +891,9 @@ static int wm8978_suspend(struct snd_soc_codec *codec)static int wm8978_resume (struct snd_soc_codec *codec) {struct wm8978_priv *wm8978 =snd_soc_codec_get_drvdata (codec); -int i; -u16 *cache = codec->reg_cache;/* Sync reg_cache with the hardware */ -for (i =0 ; i <ARRAY_SIZE (wm8978_reg); i++) { -if (i ==WM8978_RESET ) -continue ; -if (cache[i] != wm8978_reg[i]) -snd_soc_write (codec, i, cache[i]); - } +snd_soc_cache_sync (codec);wm8978_set_bias_level (codec,SND_SOC_BIAS_STANDBY );
Signature · 1 line
1.7.7.3
PATCH 6/7 ASoC: Convert wm8978 to direct regmap API usage
In reply to Mark BrownHelps push the register cache code down out of ASoC and improves resume times by using the more efficient regmap cache sync code.
Signed-off-by Mark Brown <[email protected]>
--- sound/soc/codecs/wm8978.c | 116 ++++++++++++++++++++++++++++++++++++--------- sound/soc/codecs/wm8978.h | 2 + 2 files changed, 96 insertions(+), 22 deletions(-)
sound/soc/codecs/wm8978.c +94 -22
@@ -18,6 +18,7 @@#include <linux/delay.h> #include <linux/pm.h> #include <linux/i2c.h> +#include <linux/regmap.h> #include <linux/slab.h> #include <sound/core.h> #include <sound/pcm.h>
@@ -29,27 +30,74 @@#include "wm8978.h" -/* wm8978 register cache. Note that register 0 is not included in the cache. */ -static const u16 wm8978_reg[WM8978_CACHEREGNUM ] = { -0x0000 ,0x0000 ,0x0000 ,0x0000 ,/* 0x00...0x03 */ -0x0050 ,0x0000 ,0x0140 ,0x0000 ,/* 0x04...0x07 */ -0x0000 ,0x0000 ,0x0000 ,0x00ff ,/* 0x08...0x0b */ -0x00ff ,0x0000 ,0x0100 ,0x00ff ,/* 0x0c...0x0f */ -0x00ff ,0x0000 ,0x012c ,0x002c ,/* 0x10...0x13 */ -0x002c ,0x002c ,0x002c ,0x0000 ,/* 0x14...0x17 */ -0x0032 ,0x0000 ,0x0000 ,0x0000 ,/* 0x18...0x1b */ -0x0000 ,0x0000 ,0x0000 ,0x0000 ,/* 0x1c...0x1f */ -0x0038 ,0x000b ,0x0032 ,0x0000 ,/* 0x20...0x23 */ -0x0008 ,0x000c ,0x0093 ,0x00e9 ,/* 0x24...0x27 */ -0x0000 ,0x0000 ,0x0000 ,0x0000 ,/* 0x28...0x2b */ -0x0033 ,0x0010 ,0x0010 ,0x0100 ,/* 0x2c...0x2f */ -0x0100 ,0x0002 ,0x0001 ,0x0001 ,/* 0x30...0x33 */ -0x0039 ,0x0039 ,0x0039 ,0x0039 ,/* 0x34...0x37 */ -0x0001 ,0x0001 ,/* 0x38...0x3b */ +static const struct reg_default wm8978_reg_defaults[] = { + {1 ,0x0000 }, + {2 ,0x0000 }, + {3 ,0x0000 }, + {4 ,0x0050 }, + {5 ,0x0000 }, + {6 ,0x0140 }, + {7 ,0x0000 }, + {8 ,0x0000 }, + {9 ,0x0000 }, + {10 ,0x0000 }, + {11 ,0x00ff }, + {12 ,0x00ff }, + {13 ,0x0000 }, + {14 ,0x0100 }, + {15 ,0x00ff }, + {16 ,0x00ff }, + {17 ,0x0000 }, + {18 ,0x012c }, + {19 ,0x002c }, + {20 ,0x002c }, + {21 ,0x002c }, + {22 ,0x002c }, + {23 ,0x0000 }, + {24 ,0x0032 }, + {25 ,0x0000 }, + {26 ,0x0000 }, + {27 ,0x0000 }, + {28 ,0x0000 }, + {29 ,0x0000 }, + {30 ,0x0000 }, + {31 ,0x0000 }, + {32 ,0x0038 }, + {33 ,0x000b }, + {34 ,0x0032 }, + {35 ,0x0000 }, + {36 ,0x0008 }, + {37 ,0x000c }, + {38 ,0x0093 }, + {39 ,0x00e9 }, + {40 ,0x0000 }, + {41 ,0x0000 }, + {42 ,0x0000 }, + {43 ,0x0000 }, + {44 ,0x0033 }, + {45 ,0x0010 }, + {46 ,0x0010 }, + {47 ,0x0100 }, + {48 ,0x0100 }, + {49 ,0x0002 }, + {50 ,0x0001 }, + {51 ,0x0001 }, + {52 ,0x0039 }, + {53 ,0x0039 }, + {54 ,0x0039 }, + {55 ,0x0039 }, + {56 ,0x0001 }, + {57 ,0x0001 }, }; +static bool wm8978_volatile (struct device *dev,unsigned int reg) +{ +return reg ==WM8978_RESET ; +} +/* codec private data */ struct wm8978_priv { +struct regmap *regmap;unsigned int f_pllout;unsigned int f_mclk;unsigned int f_256fs;
@@ -881,10 +929,14 @@ static struct snd_soc_dai_driver wm8978_dai = {static int wm8978_suspend (struct snd_soc_codec *codec) { +struct wm8978_priv *wm8978 =snd_soc_codec_get_drvdata (codec); +wm8978_set_bias_level (codec,SND_SOC_BIAS_OFF );/* Also switch PLL off */ snd_soc_write (codec,WM8978_POWER_MANAGEMENT_1 ,0 ); +regcache_mark_dirty (wm8978->regmap); +return 0 ; }
@@ -893,7 +945,7 @@ static int wm8978_resume(struct snd_soc_codec *codec)struct wm8978_priv *wm8978 =snd_soc_codec_get_drvdata (codec);/* Sync reg_cache with the hardware */ -snd_soc_cache_sync (codec); +regcache_sync (wm8978->regmap);wm8978_set_bias_level (codec,SND_SOC_BIAS_STANDBY );
@@ -933,7 +985,8 @@ static int wm8978_probe(struct snd_soc_codec *codec)* default hardware setting */ wm8978->sysclk =WM8978_PLL ; - ret =snd_soc_codec_set_cache_io (codec,7 ,9 ,SND_SOC_I2C ); + codec->control_data = wm8978->regmap; + ret =snd_soc_codec_set_cache_io (codec,7 ,9 ,SND_SOC_REGMAP );if (ret <0 ) {dev_err (codec->dev,"Failed to set cache I/O: %d\n" , ret);return ret;
@@ -972,9 +1025,6 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8978 = { .suspend = wm8978_suspend, .resume = wm8978_resume, .set_bias_level = wm8978_set_bias_level, - .reg_cache_size = ARRAY_SIZE(wm8978_reg), - .reg_word_size = sizeof(u16), - .reg_cache_default = wm8978_reg, .controls = wm8978_snd_controls, .num_controls = ARRAY_SIZE(wm8978_snd_controls),
@@ -984,6 +1034,18 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8978 = { .num_dapm_routes = ARRAY_SIZE(wm8978_dapm_routes), }; +static const struct regmap_config wm8978_regmap_config = { + .reg_bits =7 , + .val_bits =9 , + + .max_register =WM8978_MAX_REGISTER , + .volatile_reg = wm8978_volatile, + + .cache_type =REGCACHE_RBTREE , + .reg_defaults = wm8978_reg_defaults, + .num_reg_defaults =ARRAY_SIZE (wm8978_reg_defaults), +}; +static __devinit int wm8978_i2c_probe (struct i2c_client *i2c,const struct i2c_device_id *id) {
@@ -995,6 +1057,13 @@ static __devinit int wm8978_i2c_probe(struct i2c_client *i2c,if (wm8978 ==NULL )return -ENOMEM ; + wm8978->regmap =regmap_init_i2c (i2c, &wm8978_regmap_config); +if (IS_ERR (wm8978->regmap)) { + ret =PTR_ERR (wm8978->regmap); +dev_err (&i2c->dev,"Failed to allocate regmap: %d\n" , ret); +return ret; + } +i2c_set_clientdata (i2c, wm8978); ret = snd_soc_register_codec(&i2c->dev,
@@ -1005,7 +1074,10 @@ static __devinit int wm8978_i2c_probe(struct i2c_client *i2c, static __devexit int wm8978_i2c_remove(struct i2c_client *client) { +struct wm8978_priv *wm8978 =i2c_get_clientdata (client); +snd_soc_unregister_codec (&client->dev); +regmap_exit (wm8978->regmap);return 0 ; }
sound/soc/codecs/wm8978.h +2 -0
@@ -67,6 +67,8 @@#define WM8978_OUT3_MIXER_CONTROL 0x38#define WM8978_OUT4_MIXER_CONTROL 0x39 +#define WM8978_MAX_REGISTER 0x39 +#define WM8978_CACHEREGNUM 58/* Clock divider Id's */
Signature · 1 line
1.7.7.3
PATCH 7/7 ASoC: Push wm8978 reset down into the I2C probe
In reply to Mark BrownEnsures that we get control of the CODEC earlier and don't try to probe the card at all if register I/O isn't working.
Signed-off-by Mark Brown <[email protected]>
--- sound/soc/codecs/wm8978.c | 22 +++++++++++++++------- 1 files changed, 15 insertions(+), 7 deletions(-)
sound/soc/codecs/wm8978.c +15 -7
@@ -1000,13 +1000,6 @@ static int wm8978_probe(struct snd_soc_codec *codec)for (i =0 ; i <ARRAY_SIZE (update_reg); i++)snd_soc_update_bits (codec, update_reg[i],0x100 ,0x100 ); -/* Reset the codec */ - ret =snd_soc_write (codec,WM8978_RESET ,0 ); -if (ret <0 ) { -dev_err (codec->dev,"Failed to issue reset\n" ); -return ret; - } -wm8978_set_bias_level (codec,SND_SOC_BIAS_STANDBY );return 0 ;
@@ -1066,9 +1059,24 @@ static __devinit int wm8978_i2c_probe(struct i2c_client *i2c,i2c_set_clientdata (i2c, wm8978); +/* Reset the codec */ + ret =regmap_write (wm8978->regmap,WM8978_RESET ,0 ); +if (ret !=0 ) { +dev_err (&i2c->dev,"Failed to issue reset: %d\n" , ret); + goto err; + } + ret =snd_soc_register_codec (&i2c->dev, &soc_codec_dev_wm8978, &wm8978_dai,1 ); +if (ret !=0 ) { +dev_err (&i2c->dev,"Failed to register CODEC: %d\n" , ret); + goto err; + } +return 0 ; + +err: +regmap_exit (wm8978->regmap);return ret; }
Signature · 1 line
1.7.7.3