ASoC: Begin to factor out register cache I/O functions
Subsystems (4)
PATCH 1/8 ASoC: Begin to factor out register cache I/O functions
A lot of CODECs share the same register data formats and therefore replicate the code to manage access to and caching of the register map. In order to reduce code duplication centralised versions of this code will be introduced with drivers able to configure the use of the common code by calling the new snd_soc_codec_set_cache_io() API call during startup.
As an initial user the 7 bit address/9 bit data format used by many Wolfson devices is supported for write only CODECs and the drivers with straightforward register cache implementations are converted to use it.
--- include/sound/soc.h | 2 + sound/soc/Makefile | 2 +- sound/soc/codecs/wm8510.c | 141 +++++++++++--------------------- sound/soc/codecs/wm8728.c | 78 +++++------------- sound/soc/codecs/wm8731.c | 108 +++++++------------------ sound/soc/codecs/wm8750.c | 121 ++++++++++------------------ sound/soc/codecs/wm8960.c | 194 +++++++++++++++++---------------------------- sound/soc/codecs/wm8971.c | 121 ++++++++++------------------ sound/soc/codecs/wm8988.c | 105 ++++++++----------------- sound/soc/soc-cache.c | 105 ++++++++++++++++++++++++ 10 files changed, 400 insertions(+), 577 deletions(-) create mode 100644 sound/soc/soc-cache.c
include/sound/soc.h +2 -0
@@ -192,6 +192,8 @@ void snd_soc_unregister_platform(struct snd_soc_platform *platform);int snd_soc_register_codec (struct snd_soc_codec *codec);void snd_soc_unregister_codec (struct snd_soc_codec *codec);int snd_soc_codec_volatile_register (struct snd_soc_codec *codec,int reg); +int snd_soc_codec_set_cache_io (struct snd_soc_codec *codec, +int addr_bits,int data_bits);#ifdef CONFIG_PM int snd_soc_suspend_device (struct device *dev);
sound/soc/Makefile +1 -1
@@ -1,4 +1,4 @@ -snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o +snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o obj-$(CONFIG_SND_SOC) += snd-soc-core.o obj-$(CONFIG_SND_SOC) += codecs/
sound/soc/codecs/wm8510.c +49 -92
257 lines not on this page · raw message
sound/soc/codecs/wm8728.c +22 -56
152 lines not on this page · raw message
sound/soc/codecs/wm8731.c +29 -79
199 lines not on this page · raw message
sound/soc/codecs/wm8750.c +43 -78
202 lines not on this page · raw message
sound/soc/codecs/wm8960.c +72 -122
326 lines not on this page · raw message
sound/soc/codecs/wm8971.c +44 -77
210 lines not on this page · raw message
sound/soc/codecs/wm8988.c +33 -72
195 lines not on this page · raw message
sound/soc/soc-cache.c new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
1.6.3.3
PATCH 2/8 ASoC: Remove unused AK4535 hardware read functionality
Nothing uses it and the existing hw_read operation needs to be refectored so it's easier to remove it rather than work with it. Support can be re-added if the code requires volatile registers.
--- sound/soc/codecs/ak4535.c | 16 ---------------- 1 files changed, 0 insertions(+), 16 deletions(-)
sound/soc/codecs/ak4535.c +0 -16
@@ -59,21 +59,6 @@ static inline unsigned int ak4535_read_reg_cache(struct snd_soc_codec *codec,return cache[reg]; } -static inline unsigned int ak4535_read (struct snd_soc_codec *codec, -unsigned int reg) -{ -u8 data; - data = reg; - -if (codec->hw_write (codec->control_data, &data,1 ) !=1 ) -return -EIO ; - -if (codec->hw_read (codec->control_data, &data,1 ) !=1 ) -return -EIO ; - -return data; -}; -/* * write ak4535 register cache */
@@ -635,7 +620,6 @@ static int ak4535_probe(struct platform_device *pdev)#if defined(CONFIG_I2C ) || defined(CONFIG_I2C_MODULE )if (setup->i2c_address) { codec->hw_write = (hw_write_t )i2c_master_send; - codec->hw_read = (hw_read_t )i2c_master_recv; ret =ak4535_add_i2c_device (pdev, setup); }#endif
Signature · 1 line
1.6.3.3
PATCH 3/8 ASoC: Remove use of hw_read from TLV320AIC3x driver
The TLV320AIC3x driver is currently the only user of the CODEC hw_read operation and is jumping through some hoops in order to do so. In order to support future refactoring to make the hw_read operation more usable unwrap the usage in this driver to avoid its use.
--- sound/soc/codecs/tlv320aic3x.c | 11 ++--------- 1 files changed, 2 insertions(+), 9 deletions(-)
sound/soc/codecs/tlv320aic3x.c +2 -9
@@ -145,8 +145,8 @@ static int aic3x_read(struct snd_soc_codec *codec, unsigned int reg, u8 *value) { *value = reg &0xff ; -if (codec->hw_read (codec->control_data, value,1 ) !=1 ) -return -EIO ; + + value[0 ] =i2c_smbus_read_byte_data (codec->control_data, value[0 ]);aic3x_write_reg_cache (codec, reg, *value);return 0 ;
@@ -1316,12 +1316,6 @@ static struct i2c_driver aic3x_i2c_driver = { .id_table = aic3x_i2c_id, }; -static int aic3x_i2c_read (struct i2c_client *client,u8 *value,int len) -{ - value[0 ] =i2c_smbus_read_byte_data (client, value[0 ]); -return (len ==1 ); -} -static int aic3x_add_i2c_device (struct platform_device *pdev,const struct aic3x_setup_data *setup) {
@@ -1394,7 +1388,6 @@ static int aic3x_probe(struct platform_device *pdev)#if defined(CONFIG_I2C ) || defined(CONFIG_I2C_MODULE )if (setup->i2c_address) { codec->hw_write = (hw_write_t ) i2c_master_send; - codec->hw_read = (hw_read_t ) aic3x_i2c_read; ret =aic3x_add_i2c_device (pdev, setup); }#else
Signature · 1 line
1.6.3.3
PATCH 4/8 ASoC: Factor out WM8580 register cache code
Note the slightly tricky cache usage in the volume update function due to the requirement for a separate write for the VU bit.
--- sound/soc/codecs/wm8580.c | 148 ++++++++++++-------------------------------- 1 files changed, 41 insertions(+), 107 deletions(-)
sound/soc/codecs/wm8580.c +41 -107
@@ -205,73 +205,6 @@ struct wm8580_priv {struct pll_state b; }; -/* -* read wm8580 register cache -*/ -static inline unsigned int wm8580_read_reg_cache (struct snd_soc_codec *codec, -unsigned int reg) -{ -u16 *cache = codec->reg_cache; -BUG_ON (reg >=ARRAY_SIZE (wm8580_reg)); -return cache[reg]; -} - -/* -* write wm8580 register cache -*/ -static inline void wm8580_write_reg_cache (struct snd_soc_codec *codec, -unsigned int reg,unsigned int value) -{ -u16 *cache = codec->reg_cache; - - cache[reg] = value; -} - -/* -* write to the WM8580 register space -*/ -static int wm8580_write (struct snd_soc_codec *codec,unsigned int reg, -unsigned int value) -{ -u8 data[2 ]; - -BUG_ON (reg >=ARRAY_SIZE (wm8580_reg)); - -/* Registers are 9 bits wide */ - value &=0x1ff ; - -switch (reg) { -case WM8580_RESET : -/* Uncached */ -break ; -default : -if (value ==wm8580_read_reg_cache (codec, reg)) -return 0 ; - } - -/* data is -* D15..D9 WM8580 register offset -* D8...D0 register data -*/ - data[0 ] = (reg <<1 ) | ((value >>8 ) &0x0001 ); - data[1 ] = value &0x00ff ; - -wm8580_write_reg_cache (codec, reg, value); -if (codec->hw_write (codec->control_data, data,2 ) ==2 ) -return 0 ; -else -return -EIO ; -} - -static inline unsigned int wm8580_read (struct snd_soc_codec *codec, -unsigned int reg) -{ -switch (reg) { -default : -return wm8580_read_reg_cache (codec, reg); - } -} - static const DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1); static int wm8580_out_vu(struct snd_kcontrol *kcontrol,
@@ -280,25 +213,22 @@ static int wm8580_out_vu(struct snd_kcontrol *kcontrol,struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;struct snd_soc_codec *codec =snd_kcontrol_chip (kcontrol); +u16 *reg_cache = codec->reg_cache;unsigned int reg = mc->reg;unsigned int reg2 = mc->rreg;int ret; -u16 val;/* Clear the register cache so we write without VU set */ -wm8580_write_reg_cache (codec, reg,0 ); -wm8580_write_reg_cache (codec, reg2,0 ); + reg_cache[reg] =0 ; + reg_cache[reg2] =0 ; ret =snd_soc_put_volsw_2r (kcontrol, ucontrol);if (ret <0 )return ret;/* Now write again with the volume update bit set */ - val =wm8580_read_reg_cache (codec, reg); -wm8580_write (codec, reg, val |0x0100 ); - - val =wm8580_read_reg_cache (codec, reg2); -wm8580_write (codec, reg2, val |0x0100 ); +snd_soc_update_bits (codec, reg,0x100 ,0x100 ); +snd_soc_update_bits (codec, reg2,0x100 ,0x100 );return 0 ; }
@@ -521,27 +451,27 @@ static int wm8580_set_dai_pll(struct snd_soc_dai *codec_dai,/* Always disable the PLL - it is not safe to leave it running * while reprogramming it. */ - reg =wm8580_read (codec,WM8580_PWRDN2 ); -wm8580_write (codec,WM8580_PWRDN2 , reg | pwr_mask); + reg =snd_soc_read (codec,WM8580_PWRDN2 ); +snd_soc_write (codec,WM8580_PWRDN2 , reg | pwr_mask);if (!freq_in || !freq_out)return 0 ; -wm8580_write (codec,WM8580_PLLA1 + offset, pll_div.k &0x1ff ); -wm8580_write (codec,WM8580_PLLA2 + offset, (pll_div.k >>9 ) &0xff ); -wm8580_write (codec,WM8580_PLLA3 + offset, +snd_soc_write (codec,WM8580_PLLA1 + offset, pll_div.k &0x1ff ); +snd_soc_write (codec,WM8580_PLLA2 + offset, (pll_div.k >>9 ) &0xff ); +snd_soc_write (codec,WM8580_PLLA3 + offset, (pll_div.k >>18 &0xf ) | (pll_div.n <<4 )); - reg =wm8580_read (codec,WM8580_PLLA4 + offset); + reg =snd_soc_read (codec,WM8580_PLLA4 + offset); reg &= ~0x3f ; reg |= pll_div.prescale | pll_div.postscale <<1 | pll_div.freqmode <<3 ; -wm8580_write (codec,WM8580_PLLA4 + offset, reg); +snd_soc_write (codec,WM8580_PLLA4 + offset, reg);/* All done, turn it on */ - reg =wm8580_read (codec,WM8580_PWRDN2 ); -wm8580_write (codec,WM8580_PWRDN2 , reg & ~pwr_mask); + reg =snd_soc_read (codec,WM8580_PWRDN2 ); +snd_soc_write (codec,WM8580_PWRDN2 , reg & ~pwr_mask);return 0 ; }
@@ -556,7 +486,7 @@ static int wm8580_paif_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; -u16 paifb =wm8580_read (codec,WM8580_PAIF3 + dai->id); +u16 paifb =snd_soc_read (codec,WM8580_PAIF3 + dai->id); paifb &= ~WM8580_AIF_LENGTH_MASK ;/* bit size */
@@ -576,7 +506,7 @@ static int wm8580_paif_hw_params(struct snd_pcm_substream *substream,return -EINVAL ; } -wm8580_write (codec,WM8580_PAIF3 + dai->id, paifb); +snd_soc_write (codec,WM8580_PAIF3 + dai->id, paifb);return 0 ; }
@@ -588,8 +518,8 @@ static int wm8580_set_paif_dai_fmt(struct snd_soc_dai *codec_dai,unsigned int aifb;int can_invert_lrclk; - aifa =wm8580_read (codec,WM8580_PAIF1 + codec_dai->id); - aifb =wm8580_read (codec,WM8580_PAIF3 + codec_dai->id); + aifa =snd_soc_read (codec,WM8580_PAIF1 + codec_dai->id); + aifb =snd_soc_read (codec,WM8580_PAIF3 + codec_dai->id); aifb &= ~(WM8580_AIF_FMT_MASK |WM8580_AIF_LRP |WM8580_AIF_BCP );
@@ -655,8 +585,8 @@ static int wm8580_set_paif_dai_fmt(struct snd_soc_dai *codec_dai,return -EINVAL ; } -wm8580_write (codec,WM8580_PAIF1 + codec_dai->id, aifa); -wm8580_write (codec,WM8580_PAIF3 + codec_dai->id, aifb); +snd_soc_write (codec,WM8580_PAIF1 + codec_dai->id, aifa); +snd_soc_write (codec,WM8580_PAIF3 + codec_dai->id, aifb);return 0 ; }
@@ -669,7 +599,7 @@ static int wm8580_set_dai_clkdiv(struct snd_soc_dai *codec_dai,switch (div_id) {case WM8580_MCLK : - reg =wm8580_read (codec,WM8580_PLLB4 ); + reg =snd_soc_read (codec,WM8580_PLLB4 ); reg &= ~WM8580_PLLB4_MCLKOUTSRC_MASK ;switch (div) {
@@ -691,11 +621,11 @@ static int wm8580_set_dai_clkdiv(struct snd_soc_dai *codec_dai,default :return -EINVAL ; } -wm8580_write (codec,WM8580_PLLB4 , reg); +snd_soc_write (codec,WM8580_PLLB4 , reg);break ;case WM8580_DAC_CLKSEL : - reg =wm8580_read (codec,WM8580_CLKSEL ); + reg =snd_soc_read (codec,WM8580_CLKSEL ); reg &= ~WM8580_CLKSEL_DAC_CLKSEL_MASK ;switch (div) {
@@ -713,11 +643,11 @@ static int wm8580_set_dai_clkdiv(struct snd_soc_dai *codec_dai,default :return -EINVAL ; } -wm8580_write (codec,WM8580_CLKSEL , reg); +snd_soc_write (codec,WM8580_CLKSEL , reg);break ;case WM8580_CLKOUTSRC : - reg =wm8580_read (codec,WM8580_PLLB4 ); + reg =snd_soc_read (codec,WM8580_PLLB4 ); reg &= ~WM8580_PLLB4_CLKOUTSRC_MASK ;switch (div) {
@@ -739,7 +669,7 @@ static int wm8580_set_dai_clkdiv(struct snd_soc_dai *codec_dai,default :return -EINVAL ; } -wm8580_write (codec,WM8580_PLLB4 , reg); +snd_soc_write (codec,WM8580_PLLB4 , reg);break ;default :
@@ -754,14 +684,14 @@ static int wm8580_digital_mute(struct snd_soc_dai *codec_dai, int mute)struct snd_soc_codec *codec = codec_dai->codec;unsigned int reg; - reg =wm8580_read (codec,WM8580_DAC_CONTROL5 ); + reg =snd_soc_read (codec,WM8580_DAC_CONTROL5 );if (mute) reg |=WM8580_DAC_CONTROL5_MUTEALL ;else reg &= ~WM8580_DAC_CONTROL5_MUTEALL ; -wm8580_write (codec,WM8580_DAC_CONTROL5 , reg); +snd_soc_write (codec,WM8580_DAC_CONTROL5 , reg);return 0 ; }
@@ -778,20 +708,20 @@ static int wm8580_set_bias_level(struct snd_soc_codec *codec,case SND_SOC_BIAS_STANDBY :if (codec->bias_level ==SND_SOC_BIAS_OFF ) {/* Power up and get individual control of the DACs */ - reg =wm8580_read (codec,WM8580_PWRDN1 ); + reg =snd_soc_read (codec,WM8580_PWRDN1 ); reg &= ~(WM8580_PWRDN1_PWDN |WM8580_PWRDN1_ALLDACPD ); -wm8580_write (codec,WM8580_PWRDN1 , reg); +snd_soc_write (codec,WM8580_PWRDN1 , reg);/* Make VMID high impedence */ - reg =wm8580_read (codec,WM8580_ADC_CONTROL1 ); + reg =snd_soc_read (codec,WM8580_ADC_CONTROL1 ); reg &= ~0x100 ; -wm8580_write (codec,WM8580_ADC_CONTROL1 , reg); +snd_soc_write (codec,WM8580_ADC_CONTROL1 , reg); }break ;case SND_SOC_BIAS_OFF : - reg =wm8580_read (codec,WM8580_PWRDN1 ); -wm8580_write (codec,WM8580_PWRDN1 , reg |WM8580_PWRDN1_PWDN ); + reg =snd_soc_read (codec,WM8580_PWRDN1 ); +snd_soc_write (codec,WM8580_PWRDN1 , reg |WM8580_PWRDN1_PWDN );break ; } codec->bias_level = level;
@@ -920,8 +850,6 @@ static int wm8580_register(struct wm8580_priv *wm8580) codec->private_data = wm8580; codec->name ="WM8580" ; codec->owner =THIS_MODULE ; - codec->read = wm8580_read_reg_cache; - codec->write = wm8580_write; codec->bias_level =SND_SOC_BIAS_OFF ; codec->set_bias_level = wm8580_set_bias_level; codec->dai = wm8580_dai;
@@ -931,6 +859,12 @@ static int wm8580_register(struct wm8580_priv *wm8580)memcpy (codec->reg_cache, wm8580_reg,sizeof (wm8580_reg)); + ret =snd_soc_codec_set_cache_io (codec,7 ,9 ); +if (ret <0 ) { +dev_err (codec->dev,"Failed to set cache I/O: %d\n" , ret); + goto err; + } +for (i =0 ; i <ARRAY_SIZE (wm8580->supplies); i++) wm8580->supplies[i].supply = wm8580_supply_names[i];
@@ -949,7 +883,7 @@ static int wm8580_register(struct wm8580_priv *wm8580) }/* Get the codec into a known state */ - ret =wm8580_write (codec,WM8580_RESET ,0 ); + ret =snd_soc_write (codec,WM8580_RESET ,0 );if (ret !=0 ) {dev_err (codec->dev,"Failed to reset codec: %d\n" , ret); goto err_regulator_enable;
Signature · 1 line
1.6.3.3
PATCH 5/8 ASoC: Add I/O control bus information to factored out cache setup
While writes tend to be able to use a fairly bus independant format to do the writes reads are all bus specific. To allow us to factor out this code include the bus type as a parameter when setting up the cache.
Initially just use this to factor out hw_write_t for I2C.
--- include/sound/soc.h | 9 ++++++++- sound/soc/codecs/wm8510.c | 10 +++++----- sound/soc/codecs/wm8580.c | 8 ++++---- sound/soc/codecs/wm8728.c | 10 +++++----- sound/soc/codecs/wm8731.c | 10 +++++----- sound/soc/codecs/wm8750.c | 10 +++++----- sound/soc/codecs/wm8960.c | 8 ++++---- sound/soc/codecs/wm8971.c | 8 ++++---- sound/soc/codecs/wm8988.c | 10 +++++----- sound/soc/soc-cache.c | 19 ++++++++++++++++++- 10 files changed, 63 insertions(+), 39 deletions(-)
include/sound/soc.h +8 -1
@@ -187,13 +187,20 @@ typedef int (*hw_read_t)(void *,char* ,int);extern struct snd_ac97_bus_ops soc_ac97_ops; +enum snd_soc_control_type { +SND_SOC_CUSTOM , +SND_SOC_I2C , +SND_SOC_SPI , +}; +int snd_soc_register_platform (struct snd_soc_platform *platform);void snd_soc_unregister_platform (struct snd_soc_platform *platform);int snd_soc_register_codec (struct snd_soc_codec *codec);void snd_soc_unregister_codec (struct snd_soc_codec *codec);int snd_soc_codec_volatile_register (struct snd_soc_codec *codec,int reg);int snd_soc_codec_set_cache_io (struct snd_soc_codec *codec, -int addr_bits,int data_bits); +int addr_bits,int data_bits, +enum snd_soc_control_type control);#ifdef CONFIG_PM int snd_soc_suspend_device (struct device *dev);
sound/soc/codecs/wm8510.c +5 -5
@@ -564,7 +564,8 @@ static int wm8510_resume(struct platform_device *pdev)* initialise the WM8510 driver * register the mixer and dsp interfaces with the kernel */ -static int wm8510_init (struct snd_soc_device *socdev) +static int wm8510_init (struct snd_soc_device *socdev, +enum snd_soc_control_type control) {struct snd_soc_codec *codec = socdev->card->codec;int ret =0 ;
@@ -580,7 +581,7 @@ static int wm8510_init(struct snd_soc_device *socdev)if (codec->reg_cache ==NULL )return -ENOMEM ; - ret =snd_soc_codec_set_cache_io (codec,7 ,9 ); + ret =snd_soc_codec_set_cache_io (codec,7 ,9 , control);if (ret <0 ) {printk (KERN_ERR "wm8510: failed to set cache I/O: %d\n" , ret);
@@ -635,7 +636,7 @@ static int wm8510_i2c_probe(struct i2c_client *i2c,i2c_set_clientdata (i2c, codec); codec->control_data = i2c; - ret =wm8510_init (socdev); + ret =wm8510_init (socdev,SND_SOC_I2C );if (ret <0 )pr_err ("failed to initialise WM8510\n" );
@@ -715,7 +716,7 @@ static int __devinit wm8510_spi_probe(struct spi_device *spi) codec->control_data = spi; - ret =wm8510_init (socdev); + ret =wm8510_init (socdev,SND_SOC_SPI );if (ret <0 )dev_err (&spi->dev,"failed to initialise WM8510\n" );
@@ -784,7 +785,6 @@ static int wm8510_probe(struct platform_device *pdev) wm8510_socdev = socdev;#if defined(CONFIG_I2C ) || defined(CONFIG_I2C_MODULE )if (setup->i2c_address) { - codec->hw_write = (hw_write_t )i2c_master_send; ret =wm8510_add_i2c_device (pdev, setup); }#endif
sound/soc/codecs/wm8580.c +4 -4
@@ -832,7 +832,8 @@ struct snd_soc_codec_device soc_codec_dev_wm8580 = { };EXPORT_SYMBOL_GPL (soc_codec_dev_wm8580); -static int wm8580_register (struct wm8580_priv *wm8580) +static int wm8580_register (struct wm8580_priv *wm8580, +enum snd_soc_control_type control) {int ret, i;struct snd_soc_codec *codec = &wm8580->codec;
@@ -859,7 +860,7 @@ static int wm8580_register(struct wm8580_priv *wm8580)memcpy (codec->reg_cache, wm8580_reg,sizeof (wm8580_reg)); - ret =snd_soc_codec_set_cache_io (codec,7 ,9 ); + ret =snd_soc_codec_set_cache_io (codec,7 ,9 , control);if (ret <0 ) {dev_err (codec->dev,"Failed to set cache I/O: %d\n" , ret); goto err;
@@ -944,14 +945,13 @@ static int wm8580_i2c_probe(struct i2c_client *i2c,return -ENOMEM ; codec = &wm8580->codec; - codec->hw_write = (hw_write_t )i2c_master_send;i2c_set_clientdata (i2c, wm8580); codec->control_data = i2c; codec->dev = &i2c->dev; -return wm8580_register (wm8580); +return wm8580_register (wm8580,SND_SOC_I2C ); }static int wm8580_i2c_remove (struct i2c_client *client)
sound/soc/codecs/wm8728.c +5 -5
@@ -248,7 +248,8 @@ static int wm8728_resume(struct platform_device *pdev)* initialise the WM8728 driver * register the mixer and dsp interfaces with the kernel */ -static int wm8728_init (struct snd_soc_device *socdev) +static int wm8728_init (struct snd_soc_device *socdev, +enum snd_soc_control_type control) {struct snd_soc_codec *codec = socdev->card->codec;int ret =0 ;
@@ -266,7 +267,7 @@ static int wm8728_init(struct snd_soc_device *socdev)if (codec->reg_cache ==NULL )return -ENOMEM ; - ret =snd_soc_codec_set_cache_io (codec,7 ,9 ); + ret =snd_soc_codec_set_cache_io (codec,7 ,9 , control);if (ret <0 ) {printk (KERN_ERR "wm8728: failed to configure cache I/O: %d\n" , ret);
@@ -323,7 +324,7 @@ static int wm8728_i2c_probe(struct i2c_client *i2c,i2c_set_clientdata (i2c, codec); codec->control_data = i2c; - ret =wm8728_init (socdev); + ret =wm8728_init (socdev,SND_SOC_I2C );if (ret <0 )pr_err ("failed to initialise WM8728\n" );
@@ -403,7 +404,7 @@ static int __devinit wm8728_spi_probe(struct spi_device *spi) codec->control_data = spi; - ret =wm8728_init (socdev); + ret =wm8728_init (socdev,SND_SOC_SPI );if (ret <0 )dev_err (&spi->dev,"failed to initialise WM8728\n" );
@@ -472,7 +473,6 @@ static int wm8728_probe(struct platform_device *pdev)#if defined(CONFIG_I2C ) || defined(CONFIG_I2C_MODULE )if (setup->i2c_address) { - codec->hw_write = (hw_write_t )i2c_master_send; ret =wm8728_add_i2c_device (pdev, setup); }#endif
sound/soc/codecs/wm8731.c +5 -5
@@ -504,7 +504,8 @@ struct snd_soc_codec_device soc_codec_dev_wm8731 = { };EXPORT_SYMBOL_GPL (soc_codec_dev_wm8731); -static int wm8731_register (struct wm8731_priv *wm8731) +static int wm8731_register (struct wm8731_priv *wm8731, +enum snd_soc_control_type control) {int ret;struct snd_soc_codec *codec = &wm8731->codec;
@@ -531,7 +532,7 @@ static int wm8731_register(struct wm8731_priv *wm8731)memcpy (codec->reg_cache, wm8731_reg,sizeof (wm8731_reg)); - ret =snd_soc_codec_set_cache_io (codec,7 ,9 ); + ret =snd_soc_codec_set_cache_io (codec,7 ,9 , control);if (ret <0 ) {dev_err (codec->dev,"Failed to set cache I/O: %d\n" , ret); goto err;
@@ -630,7 +631,7 @@ static int __devinit wm8731_spi_probe(struct spi_device *spi)dev_set_drvdata (&spi->dev, wm8731); -return wm8731_register (wm8731); +return wm8731_register (wm8731,SND_SOC_SPI ); } static int __devexit wm8731_spi_remove(struct spi_device *spi)
@@ -682,14 +683,13 @@ static __devinit int wm8731_i2c_probe(struct i2c_client *i2c,return -ENOMEM ; codec = &wm8731->codec; - codec->hw_write = (hw_write_t )i2c_master_send;i2c_set_clientdata (i2c, wm8731); codec->control_data = i2c; codec->dev = &i2c->dev; -return wm8731_register (wm8731); +return wm8731_register (wm8731,SND_SOC_I2C ); } static __devexit int wm8731_i2c_remove(struct i2c_client *client)
sound/soc/codecs/wm8750.c +5 -5
@@ -711,7 +711,8 @@ static int wm8750_resume(struct platform_device *pdev)* initialise the WM8750 driver * register the mixer and dsp interfaces with the kernel */ -static int wm8750_init (struct snd_soc_device *socdev) +static int wm8750_init (struct snd_soc_device *socdev, +enum snd_soc_control_type control) {struct snd_soc_codec *codec = socdev->card->codec;int reg, ret =0 ;
@@ -726,7 +727,7 @@ static int wm8750_init(struct snd_soc_device *socdev)if (codec->reg_cache ==NULL )return -ENOMEM ; - ret =snd_soc_codec_set_cache_io (codec,7 ,9 ); + ret =snd_soc_codec_set_cache_io (codec,7 ,9 , control);if (ret <0 ) {printk (KERN_ERR "wm8750: failed to set cache I/O: %d\n" , ret); goto err;
@@ -809,7 +810,7 @@ static int wm8750_i2c_probe(struct i2c_client *i2c,i2c_set_clientdata (i2c, codec); codec->control_data = i2c; - ret =wm8750_init (socdev); + ret =wm8750_init (socdev,SND_SOC_I2C );if (ret <0 )pr_err ("failed to initialise WM8750\n" );
@@ -889,7 +890,7 @@ static int __devinit wm8750_spi_probe(struct spi_device *spi) codec->control_data = spi; - ret =wm8750_init (socdev); + ret =wm8750_init (socdev,SND_SOC_SPI );if (ret <0 )dev_err (&spi->dev,"failed to initialise WM8750\n" );
@@ -967,7 +968,6 @@ static int wm8750_probe(struct platform_device *pdev)#if defined(CONFIG_I2C ) || defined(CONFIG_I2C_MODULE )if (setup->i2c_address) { - codec->hw_write = (hw_write_t )i2c_master_send; ret =wm8750_add_i2c_device (pdev, setup); }#endif
sound/soc/codecs/wm8960.c +4 -4
@@ -747,7 +747,8 @@ struct snd_soc_codec_device soc_codec_dev_wm8960 = { };EXPORT_SYMBOL_GPL (soc_codec_dev_wm8960); -static int wm8960_register (struct wm8960_priv *wm8960) +static int wm8960_register (struct wm8960_priv *wm8960, +enum snd_soc_control_type control) {struct wm8960_data *pdata = wm8960->codec.dev->platform_data;struct snd_soc_codec *codec = &wm8960->codec;
@@ -785,7 +786,7 @@ static int wm8960_register(struct wm8960_priv *wm8960)memcpy (codec->reg_cache, wm8960_reg,sizeof (wm8960_reg)); - ret =snd_soc_codec_set_cache_io (codec,7 ,9 ); + ret =snd_soc_codec_set_cache_io (codec,7 ,9 , control);if (ret <0 ) {dev_err (codec->dev,"Failed to set cache I/O: %d\n" , ret); goto err;
@@ -866,14 +867,13 @@ static __devinit int wm8960_i2c_probe(struct i2c_client *i2c,return -ENOMEM ; codec = &wm8960->codec; - codec->hw_write = (hw_write_t )i2c_master_send;i2c_set_clientdata (i2c, wm8960); codec->control_data = i2c; codec->dev = &i2c->dev; -return wm8960_register (wm8960); +return wm8960_register (wm8960,SND_SOC_I2C ); } static __devexit int wm8960_i2c_remove(struct i2c_client *client)
sound/soc/codecs/wm8971.c +4 -4
@@ -640,7 +640,8 @@ static int wm8971_resume(struct platform_device *pdev)return 0 ; } -static int wm8971_init (struct snd_soc_device *socdev) +static int wm8971_init (struct snd_soc_device *socdev, +enum snd_soc_control_type control) {struct snd_soc_codec *codec = socdev->card->codec;int reg, ret =0 ;
@@ -656,7 +657,7 @@ static int wm8971_init(struct snd_soc_device *socdev)if (codec->reg_cache ==NULL )return -ENOMEM ; - ret =snd_soc_codec_set_cache_io (codec,7 ,9 ); + ret =snd_soc_codec_set_cache_io (codec,7 ,9 , control);if (ret <0 ) {printk (KERN_ERR "wm8971: failed to set cache I/O: %d\n" , ret); goto err;
@@ -734,7 +735,7 @@ static int wm8971_i2c_probe(struct i2c_client *i2c, codec->control_data = i2c; - ret =wm8971_init (socdev); + ret =wm8971_init (socdev,SND_SOC_I2C );if (ret <0 )pr_err ("failed to initialise WM8971\n" );
@@ -844,7 +845,6 @@ static int wm8971_probe(struct platform_device *pdev)#if defined (CONFIG_I2C ) || defined (CONFIG_I2C_MODULE )if (setup->i2c_address) { - codec->hw_write = (hw_write_t )i2c_master_send; ret =wm8971_add_i2c_device (pdev, setup); }#endif
sound/soc/codecs/wm8988.c +5 -5
@@ -825,7 +825,8 @@ struct snd_soc_codec_device soc_codec_dev_wm8988 = { };EXPORT_SYMBOL_GPL (soc_codec_dev_wm8988); -static int wm8988_register (struct wm8988_priv *wm8988) +static int wm8988_register (struct wm8988_priv *wm8988, +enum snd_soc_control_type control) {struct snd_soc_codec *codec = &wm8988->codec;int ret;
@@ -854,7 +855,7 @@ static int wm8988_register(struct wm8988_priv *wm8988)memcpy (codec->reg_cache, wm8988_reg,sizeof (wm8988_reg)); - ret =snd_soc_codec_set_cache_io (codec,7 ,9 ); + ret =snd_soc_codec_set_cache_io (codec,7 ,9 , control);if (ret <0 ) {dev_err (codec->dev,"Failed to set cache I/O: %d\n" , ret); goto err;
@@ -927,14 +928,13 @@ static int wm8988_i2c_probe(struct i2c_client *i2c,return -ENOMEM ; codec = &wm8988->codec; - codec->hw_write = (hw_write_t )i2c_master_send;i2c_set_clientdata (i2c, wm8988); codec->control_data = i2c; codec->dev = &i2c->dev; -return wm8988_register (wm8988); +return wm8988_register (wm8988,SND_SOC_I2C ); }static int wm8988_i2c_remove (struct i2c_client *client)
@@ -1019,7 +1019,7 @@ static int __devinit wm8988_spi_probe(struct spi_device *spi) spi->dev.driver_data = wm8988; -return wm8988_register (wm8988); +return wm8988_register (wm8988,SND_SOC_SPI ); } static int __devexit wm8988_spi_remove(struct spi_device *spi)
sound/soc/soc-cache.c +18 -1
@@ -11,6 +11,7 @@* option) any later version. */ +#include <linux/i2c.h> #include <sound/soc.h> static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec,
@@ -62,6 +63,7 @@ static struct {* @type: Type of cache. * @addr_bits: Number of bits of register address data. * @data_bits: Number of bits of data per register. +* @control: Control bus used. * * Register formats are frequently shared between many I2C and SPI * devices. In order to promote code reuse the ASoC core provides
@@ -75,7 +77,8 @@ static struct {* volatile registers. */ int snd_soc_codec_set_cache_io (struct snd_soc_codec *codec, -int addr_bits,int data_bits) +int addr_bits,int data_bits, +enum snd_soc_control_type control) {int i;
@@ -100,6 +103,20 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, codec->write = io_types[i].write; codec->read = io_types[i].read; +switch (control) { +case SND_SOC_CUSTOM : +break ; + +case SND_SOC_I2C : +#if defined(CONFIG_I2C ) || defined(CONFIG_I2C_MODULE ) + codec->hw_write = (hw_write_t )i2c_master_send; +#endif +break ; + +case SND_SOC_SPI : +break ; + } +return 0 ; }EXPORT_SYMBOL_GPL (snd_soc_codec_set_cache_io);
Signature · 1 line
1.6.3.3
PATCH 6/8 ASoC: Factor out I2C 8 bit address 16 bit data I/O
As part of this refactoring the type of the CODEC hw_read operation is changed to match the regular read operation.
--- include/sound/soc.h | 2 +- sound/soc/soc-cache.c | 79 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 9 deletions(-)
include/sound/soc.h +1 -1
@@ -373,7 +373,7 @@ struct snd_soc_codec { size_t, unsigned int);int (*volatile_register)(unsigned int );hw_write_t hw_write; -hw_read_t hw_read; +unsigned int (*hw_read)(struct snd_soc_codec *,unsigned int );void *reg_cache;short reg_cache_size;short reg_cache_step;
sound/soc/soc-cache.c +71 -8
104 lines not on this page · raw message
Signature · 1 line
1.6.3.3
PATCH 7/8 ASoC: Factor out I/O for Wolfson 8 bit data 16 bit register CODECs
--- sound/soc/codecs/wm8523.c | 98 +++----------- sound/soc/codecs/wm8900.c | 319 ++++++++++++++++---------------------------- sound/soc/codecs/wm8903.c | 244 ++++++++++++---------------------- sound/soc/codecs/wm8940.c | 143 ++++++++------------- sound/soc/codecs/wm8961.c | 231 ++++++++++++--------------------- sound/soc/codecs/wm8990.c | 194 +++++++++++----------------- sound/soc/codecs/wm9081.c | 229 ++++++++++++-------------------- 7 files changed, 521 insertions(+), 937 deletions(-)
sound/soc/codecs/wm8523.c +21 -77
@@ -62,7 +62,7 @@ static const u16 wm8523_reg[WM8523_REGISTER_COUNT] = { 0x0000, /* R8 - ZERO_DETECT */ }; -static int wm8523_volatile (unsigned int reg) +static int wm8523_volatile_register (unsigned int reg) {switch (reg) {case WM8523_DEVICE_ID :
@@ -73,71 +73,9 @@ static int wm8523_volatile(unsigned int reg) } } -static int wm8523_write (struct snd_soc_codec *codec,unsigned int reg, -unsigned int value) -{ -struct wm8523_priv *wm8523 = codec->private_data; -u8 data[3 ]; - -BUG_ON (reg >WM8523_MAX_REGISTER ); - - data[0 ] = reg; - data[1 ] = (value >>8 ) &0x00ff ; - data[2 ] = value &0x00ff ; - -if (!wm8523_volatile (reg)) - wm8523->reg_cache[reg] = value; -if (codec->hw_write (codec->control_data, data,3 ) ==3 ) -return 0 ; -else -return -EIO ; -} -static int wm8523_reset (struct snd_soc_codec *codec) { -return wm8523_write (codec,WM8523_DEVICE_ID ,0 ); -} - -static unsigned int wm8523_read_hw (struct snd_soc_codec *codec,u8 reg) -{ -struct i2c_msg xfer[2 ]; -u16 data; -int ret; -struct i2c_client *i2c = codec->control_data; - -/* Write register */ - xfer[0 ].addr = i2c->addr; - xfer[0 ].flags =0 ; - xfer[0 ].len =1 ; - xfer[0 ].buf = ® - -/* Read data */ - xfer[1 ].addr = i2c->addr; - xfer[1 ].flags =I2C_M_RD ; - xfer[1 ].len =2 ; - xfer[1 ].buf = (u8 *)&data; - - ret =i2c_transfer (i2c->adapter, xfer,2 ); -if (ret !=2 ) { -dev_err (codec->dev,"Failed to read 0x%x: %d\n" , reg, ret); -return 0 ; - } - -return (data >>8 ) | ((data &0xff ) <<8 ); -} - - -static unsigned int wm8523_read (struct snd_soc_codec *codec, -unsigned int reg) -{ -u16 *reg_cache = codec->reg_cache; - -BUG_ON (reg >WM8523_MAX_REGISTER ); - -if (wm8523_volatile (reg)) -return wm8523_read_hw (codec, reg); -else -return reg_cache[reg]; +return snd_soc_write (codec,WM8523_DEVICE_ID ,0 ); } static const DECLARE_TLV_DB_SCALE(dac_tlv, -10000, 25, 0);
@@ -228,8 +166,8 @@ static int wm8523_hw_params(struct snd_pcm_substream *substream,struct snd_soc_codec *codec = socdev->card->codec;struct wm8523_priv *wm8523 = codec->private_data;int i; -u16 aifctrl1 =wm8523_read (codec,WM8523_AIF_CTRL1 ); -u16 aifctrl2 =wm8523_read (codec,WM8523_AIF_CTRL2 ); +u16 aifctrl1 =snd_soc_read (codec,WM8523_AIF_CTRL1 ); +u16 aifctrl2 =snd_soc_read (codec,WM8523_AIF_CTRL2 );/* Find a supported LRCLK ratio */ for (i =0 ; i <ARRAY_SIZE (lrclk_ratios); i++) {
@@ -263,8 +201,8 @@ static int wm8523_hw_params(struct snd_pcm_substream *substream,break ; } -wm8523_write (codec,WM8523_AIF_CTRL1 , aifctrl1); -wm8523_write (codec,WM8523_AIF_CTRL2 , aifctrl2); +snd_soc_write (codec,WM8523_AIF_CTRL1 , aifctrl1); +snd_soc_write (codec,WM8523_AIF_CTRL2 , aifctrl2);return 0 ; }
@@ -322,7 +260,7 @@ static int wm8523_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) {struct snd_soc_codec *codec = codec_dai->codec; -u16 aifctrl1 =wm8523_read (codec,WM8523_AIF_CTRL1 ); +u16 aifctrl1 =snd_soc_read (codec,WM8523_AIF_CTRL1 ); aifctrl1 &= ~(WM8523_BCLK_INV_MASK |WM8523_LRCLK_INV_MASK |WM8523_FMT_MASK |WM8523_AIF_MSTR_MASK );
@@ -372,7 +310,7 @@ static int wm8523_set_dai_fmt(struct snd_soc_dai *codec_dai,return -EINVAL ; } -wm8523_write (codec,WM8523_AIF_CTRL1 , aifctrl1); +snd_soc_write (codec,WM8523_AIF_CTRL1 , aifctrl1);return 0 ; }
@@ -411,7 +349,7 @@ static int wm8523_set_bias_level(struct snd_soc_codec *codec,/* Sync back default/cached values */ for (i =WM8523_AIF_CTRL1 ; i <WM8523_MAX_REGISTER ; i++) -wm8523_write (codec, i, wm8523->reg_cache[i]); +snd_soc_write (codec, i, wm8523->reg_cache[i]);msleep (100 );
@@ -543,7 +481,8 @@ struct snd_soc_codec_device soc_codec_dev_wm8523 = { };EXPORT_SYMBOL_GPL (soc_codec_dev_wm8523); -static int wm8523_register (struct wm8523_priv *wm8523) +static int wm8523_register (struct wm8523_priv *wm8523, +enum snd_soc_control_type control) {int ret;struct snd_soc_codec *codec = &wm8523->codec;
@@ -561,14 +500,13 @@ static int wm8523_register(struct wm8523_priv *wm8523) codec->private_data = wm8523; codec->name ="WM8523" ; codec->owner =THIS_MODULE ; - codec->read = wm8523_read; - codec->write = wm8523_write; codec->bias_level =SND_SOC_BIAS_OFF ; codec->set_bias_level = wm8523_set_bias_level; codec->dai = &wm8523_dai; codec->num_dai =1 ; codec->reg_cache_size =WM8523_REGISTER_COUNT ; codec->reg_cache = &wm8523->reg_cache; + codec->volatile_register = wm8523_volatile_register; wm8523->rate_constraint.list = &wm8523->rate_constraint_list[0 ]; wm8523->rate_constraint.count =
@@ -576,6 +514,12 @@ static int wm8523_register(struct wm8523_priv *wm8523)memcpy (codec->reg_cache, wm8523_reg,sizeof (wm8523_reg)); + ret =snd_soc_codec_set_cache_io (codec,8 ,16 , control); +if (ret !=0 ) { +dev_err (codec->dev,"Failed to set cache I/O: %d\n" , ret); + goto err; + } +for (i =0 ; i <ARRAY_SIZE (wm8523->supplies); i++) wm8523->supplies[i].supply = wm8523_supply_names[i];
@@ -593,7 +537,7 @@ static int wm8523_register(struct wm8523_priv *wm8523) goto err_get; } - ret =wm8523_read (codec,WM8523_DEVICE_ID ); + ret =snd_soc_read (codec,WM8523_DEVICE_ID );if (ret <0 ) {dev_err (codec->dev,"Failed to read ID register\n" ); goto err_enable;
@@ -604,7 +548,7 @@ static int wm8523_register(struct wm8523_priv *wm8523) goto err_enable; } - ret =wm8523_read (codec,WM8523_REVISION ); + ret =snd_soc_read (codec,WM8523_REVISION );if (ret <0 ) {dev_err (codec->dev,"Failed to read revision register\n" ); goto err_enable;
@@ -684,7 +628,7 @@ static __devinit int wm8523_i2c_probe(struct i2c_client *i2c, codec->dev = &i2c->dev; -return wm8523_register (wm8523); +return wm8523_register (wm8523,SND_SOC_I2C ); } static __devexit int wm8523_i2c_remove(struct i2c_client *client)
sound/soc/codecs/wm8900.c +116 -203
568 lines not on this page · raw message
sound/soc/codecs/wm8903.c +86 -158
466 lines not on this page · raw message
sound/soc/codecs/wm8940.c +52 -91
296 lines not on this page · raw message
sound/soc/codecs/wm8961.c +85 -146
498 lines not on this page · raw message
sound/soc/codecs/wm8990.c +76 -118
406 lines not on this page · raw message
sound/soc/codecs/wm9081.c +85 -144
483 lines not on this page · raw message
Signature · 1 line
1.6.3.3
PATCH 8/8 ASoC: Factor out 7 bit register 9 bit data SPI write
This converts all the Wolfson drivers using this format (the only devices that do) except WM8753 to use it.
--- sound/soc/codecs/wm8510.c | 25 ------------------------- sound/soc/codecs/wm8728.c | 25 ------------------------- sound/soc/codecs/wm8731.c | 25 ------------------------- sound/soc/codecs/wm8750.c | 25 ------------------------- sound/soc/codecs/wm8988.c | 25 ------------------------- sound/soc/soc-cache.c | 39 ++++++++++++++++++++++++++++++++++++--- 6 files changed, 36 insertions(+), 128 deletions(-)
sound/soc/codecs/wm8510.c +0 -25
@@ -737,30 +737,6 @@ static struct spi_driver wm8510_spi_driver = { .probe = wm8510_spi_probe, .remove = __devexit_p(wm8510_spi_remove), }; - -static int wm8510_spi_write (struct spi_device *spi,const char *data,int len) -{ -struct spi_transfer t; -struct spi_message m; -u8 msg[2 ]; - -if (len <=0 ) -return 0 ; - - msg[0 ] = data[0 ]; - msg[1 ] = data[1 ]; - -spi_message_init (&m); -memset (&t,0 , (sizeof t)); - - t.tx_buf = &msg[0 ]; - t.len = len; - -spi_message_add_tail (&t, &m); -spi_sync (spi, &m); - -return len; -}#endif /* CONFIG_SPI_MASTER */ static int wm8510_probe (struct platform_device *pdev)
@@ -790,7 +766,6 @@ static int wm8510_probe(struct platform_device *pdev)#endif #if defined(CONFIG_SPI_MASTER )if (setup->spi) { - codec->hw_write = (hw_write_t )wm8510_spi_write; ret =spi_register_driver (&wm8510_spi_driver);if (ret !=0 )printk (KERN_ERR "can't add spi driver" );
sound/soc/codecs/wm8728.c +0 -25
@@ -425,30 +425,6 @@ static struct spi_driver wm8728_spi_driver = { .probe = wm8728_spi_probe, .remove = __devexit_p(wm8728_spi_remove), }; - -static int wm8728_spi_write (struct spi_device *spi,const char *data,int len) -{ -struct spi_transfer t; -struct spi_message m; -u8 msg[2 ]; - -if (len <=0 ) -return 0 ; - - msg[0 ] = data[0 ]; - msg[1 ] = data[1 ]; - -spi_message_init (&m); -memset (&t,0 , (sizeof t)); - - t.tx_buf = &msg[0 ]; - t.len = len; - -spi_message_add_tail (&t, &m); -spi_sync (spi, &m); - -return len; -}#endif /* CONFIG_SPI_MASTER */ static int wm8728_probe (struct platform_device *pdev)
@@ -478,7 +454,6 @@ static int wm8728_probe(struct platform_device *pdev)#endif #if defined(CONFIG_SPI_MASTER )if (setup->spi) { - codec->hw_write = (hw_write_t )wm8728_spi_write; ret =spi_register_driver (&wm8728_spi_driver);if (ret !=0 )printk (KERN_ERR "can't add spi driver" );
sound/soc/codecs/wm8731.c +0 -25
@@ -591,30 +591,6 @@ static void wm8731_unregister(struct wm8731_priv *wm8731) }#if defined(CONFIG_SPI_MASTER ) -static int wm8731_spi_write (struct spi_device *spi,const char *data,int len) -{ -struct spi_transfer t; -struct spi_message m; -u8 msg[2 ]; - -if (len <=0 ) -return 0 ; - - msg[0 ] = data[0 ]; - msg[1 ] = data[1 ]; - -spi_message_init (&m); -memset (&t,0 , (sizeof t)); - - t.tx_buf = &msg[0 ]; - t.len = len; - -spi_message_add_tail (&t, &m); -spi_sync (spi, &m); - -return len; -} -static int __devinit wm8731_spi_probe (struct spi_device *spi) {struct snd_soc_codec *codec;
@@ -626,7 +602,6 @@ static int __devinit wm8731_spi_probe(struct spi_device *spi) codec = &wm8731->codec; codec->control_data = spi; - codec->hw_write = (hw_write_t )wm8731_spi_write; codec->dev = &spi->dev;dev_set_drvdata (&spi->dev, wm8731);
sound/soc/codecs/wm8750.c +0 -25
@@ -911,30 +911,6 @@ static struct spi_driver wm8750_spi_driver = { .probe = wm8750_spi_probe, .remove = __devexit_p(wm8750_spi_remove), }; - -static int wm8750_spi_write (struct spi_device *spi,const char *data,int len) -{ -struct spi_transfer t; -struct spi_message m; -u8 msg[2 ]; - -if (len <=0 ) -return 0 ; - - msg[0 ] = data[0 ]; - msg[1 ] = data[1 ]; - -spi_message_init (&m); -memset (&t,0 , (sizeof t)); - - t.tx_buf = &msg[0 ]; - t.len = len; - -spi_message_add_tail (&t, &m); -spi_sync (spi, &m); - -return len; -}#endif static int wm8750_probe (struct platform_device *pdev)
@@ -973,7 +949,6 @@ static int wm8750_probe(struct platform_device *pdev)#endif #if defined(CONFIG_SPI_MASTER )if (setup->spi) { - codec->hw_write = (hw_write_t )wm8750_spi_write; ret =spi_register_driver (&wm8750_spi_driver);if (ret !=0 )printk (KERN_ERR "can't add spi driver" );
sound/soc/codecs/wm8988.c +0 -25
@@ -979,30 +979,6 @@ static struct i2c_driver wm8988_i2c_driver = {#endif #if defined(CONFIG_SPI_MASTER ) -static int wm8988_spi_write (struct spi_device *spi,const char *data,int len) -{ -struct spi_transfer t; -struct spi_message m; -u8 msg[2 ]; - -if (len <=0 ) -return 0 ; - - msg[0 ] = data[0 ]; - msg[1 ] = data[1 ]; - -spi_message_init (&m); -memset (&t,0 , (sizeof t)); - - t.tx_buf = &msg[0 ]; - t.len = len; - -spi_message_add_tail (&t, &m); -spi_sync (spi, &m); - -return len; -} -static int __devinit wm8988_spi_probe (struct spi_device *spi) {struct wm8988_priv *wm8988;
@@ -1013,7 +989,6 @@ static int __devinit wm8988_spi_probe(struct spi_device *spi)return -ENOMEM ; codec = &wm8988->codec; - codec->hw_write = (hw_write_t )wm8988_spi_write; codec->control_data = spi; codec->dev = &spi->dev;
sound/soc/soc-cache.c +36 -3
@@ -12,6 +12,7 @@*/ #include <linux/i2c.h> +#include <linux/spi/spi.h> #include <sound/soc.h> static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec,
@@ -46,6 +47,36 @@ static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg,return -EIO ; } +#if defined(CONFIG_SPI_MASTER ) +static int snd_soc_7_9_spi_write (void *control_data,const char *data, +int len) +{ +struct spi_device *spi = control_data; +struct spi_transfer t; +struct spi_message m; +u8 msg[2 ]; + +if (len <=0 ) +return 0 ; + + msg[0 ] = data[0 ]; + msg[1 ] = data[1 ]; + +spi_message_init (&m); +memset (&t,0 , (sizeof t)); + + t.tx_buf = &msg[0 ]; + t.len = len; + +spi_message_add_tail (&t, &m); +spi_sync (spi, &m); + +return len; +} +#else +#define snd_soc_7_9_spi_write NULL +#endif +static int snd_soc_8_16_write (struct snd_soc_codec *codec,unsigned int reg,unsigned int value) {
@@ -115,12 +146,12 @@ static struct {int addr_bits;int data_bits;int (*write)(struct snd_soc_codec *codec,unsigned int ,unsigned int ); +int (*spi_write)(void *,const char *,int );unsigned int (*read)(struct snd_soc_codec *,unsigned int );unsigned int (*i2c_read)(struct snd_soc_codec *,unsigned int ); } io_types[] = { - { 7, 9, snd_soc_7_9_write, snd_soc_7_9_read }, - { 8, 16, - snd_soc_8_16_write, snd_soc_8_16_read, + { 7, 9, snd_soc_7_9_write, snd_soc_7_9_spi_write, snd_soc_7_9_read }, + { 8, 16, snd_soc_8_16_write, NULL, snd_soc_8_16_read, snd_soc_8_16_read_i2c }, };
@@ -177,6 +208,8 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,break ;case SND_SOC_SPI : +if (io_types[i].spi_write) + codec->hw_write = io_types[i].spi_write;break ; }
Signature · 1 line
1.6.3.3