ASoC: sigmadsp: Refuse to load firmware files with a non-supported version
Subsystems (3)
Lars-Peter Clausen
maintainerPATCH 1/6 ASoC: sigmadsp: Refuse to load firmware files with a non-supported version
Make sure to check the version field of the firmware header to make sure to not accidentally try to parse a firmware file with a different layout. Trying to do so can result in loading invalid firmware code to the device.
--- sound/soc/codecs/sigmadsp.c | 7 +++++++ 1 file changed, 7 insertions(+)
sound/soc/codecs/sigmadsp.c +7 -0
@@ -159,6 +159,13 @@ int _process_sigma_firmware(struct device *dev, goto done; } +if (ssfw_head->version !=1 ) { +dev_err (dev, +"Failed to load firmware: Invalid version %d. Supported firmware versions: 1\n" , + ssfw_head->version); + goto done; + } + crc =crc32 (0 , fw->data +sizeof (*ssfw_head), fw->size -sizeof (*ssfw_head));pr_debug ("%s: crc=%x\n" , __func__, crc);
Signature · 1 line
1.8.0
Lars-Peter Clausen
maintainerPATCH 2/6 ASoC: adau17x1: Mark DSP parameter memory as readable and precious
To be able to read back data from the DSP parameter memory the register range needs to be marked as readable. At the same time we do not want them to e.g. appear in debugfs output so mark them as precious as well.
--- sound/soc/codecs/adau1761.c | 1 + sound/soc/codecs/adau1781.c | 1 + sound/soc/codecs/adau17x1.c | 14 ++++++++++++++ sound/soc/codecs/adau17x1.h | 1 + 4 files changed, 17 insertions(+)
sound/soc/codecs/adau1761.c +1 -0
@@ -799,6 +799,7 @@ const struct regmap_config adau1761_regmap_config = { .num_reg_defaults = ARRAY_SIZE(adau1761_reg_defaults), .readable_reg = adau1761_readable_register, .volatile_reg = adau17x1_volatile_register, + .precious_reg = adau17x1_precious_register, .cache_type = REGCACHE_RBTREE, };EXPORT_SYMBOL_GPL (adau1761_regmap_config);
sound/soc/codecs/adau1781.c +1 -0
@@ -488,6 +488,7 @@ const struct regmap_config adau1781_regmap_config = { .num_reg_defaults = ARRAY_SIZE(adau1781_reg_defaults), .readable_reg = adau1781_readable_register, .volatile_reg = adau17x1_volatile_register, + .precious_reg = adau17x1_precious_register, .cache_type = REGCACHE_RBTREE, };EXPORT_SYMBOL_GPL (adau1781_regmap_config);
sound/soc/codecs/adau17x1.c +14 -0
@@ -688,8 +688,22 @@ int adau17x1_set_micbias_voltage(struct snd_soc_codec *codec, }EXPORT_SYMBOL_GPL (adau17x1_set_micbias_voltage); +bool adau17x1_precious_register (struct device *dev,unsigned int reg) +{ +/* SigmaDSP parameter memory */ +if (reg <0x400 ) +return true; + +return false; +} +EXPORT_SYMBOL_GPL (adau17x1_precious_register); +bool adau17x1_readable_register (struct device *dev,unsigned int reg) { +/* SigmaDSP parameter memory */ +if (reg <0x400 ) +return true; +switch (reg) {case ADAU17X1_CLOCK_CONTROL :case ADAU17X1_PLL_CONTROL :
sound/soc/codecs/adau17x1.h +1 -0
@@ -52,6 +52,7 @@ int adau17x1_set_micbias_voltage(struct snd_soc_codec *codec, enum adau17x1_micbias_voltage micbias);bool adau17x1_readable_register (struct device *dev,unsigned int reg);bool adau17x1_volatile_register (struct device *dev,unsigned int reg); +bool adau17x1_precious_register (struct device *dev,unsigned int reg);int adau17x1_resume (struct snd_soc_codec *codec);extern const struct snd_soc_dai_ops adau17x1_dai_ops;
Signature · 1 line
1.8.0
Lars-Peter Clausen
maintainerRe: [PATCH 2/6] ASoC: adau17x1: Mark DSP parameter memory as readable and precious
Quoted 5 lines · Lars-Peter Clausen
To be able to read back data from the DSP parameter memory the register range needs to be marked as readable. At the same time we do not want them to e.g. appear in debugfs output so mark them as precious as well.
Signed-off-by Lars-Peter Clausen <[email protected]>
It looks like this one was lost, shall I resend?
Thanks,
- Lars
Mark Brown
maintainerRe: [PATCH 2/6] ASoC: adau17x1: Mark DSP parameter memory as readable and precious
Quoted 1 line · Lars-Peter Clausen
It looks like this one was lost, shall I resend?
Yes.
Lars-Peter Clausen
maintainerPATCH 3/6 ASoC: sigmadsp: Drop support support SIGMA_ACTION_DELAY
In reply to Lars-Peter ClausenThe official firmware generation tool never emitted any SIGMA_ACTION_DELAY instructions. Keeping support for it with the new restructured loader that also supports v2 will be difficult, so drop support for it.
--- sound/soc/codecs/sigmadsp.c | 8 -------- 1 file changed, 8 deletions(-)
sound/soc/codecs/sigmadsp.c +0 -8
@@ -7,7 +7,6 @@*/ #include <linux/crc32.h> -#include <linux/delay.h> #include <linux/firmware.h> #include <linux/kernel.h> #include <linux/i2c.h>
@@ -28,9 +27,6 @@ enum {SIGMA_ACTION_WRITEXBYTES =0 ,SIGMA_ACTION_WRITESINGLE ,SIGMA_ACTION_WRITESAFELOAD , -SIGMA_ACTION_DELAY , -SIGMA_ACTION_PLLWAIT , -SIGMA_ACTION_NOOP , SIGMA_ACTION_END, };
@@ -79,10 +75,6 @@ process_sigma_action(struct sigma_firmware *ssfw, struct sigma_action *sa)if (ret <0 )return -EINVAL ;break ; -case SIGMA_ACTION_DELAY : -udelay (len); - len =0 ; -break ;case SIGMA_ACTION_END :return 0 ;default :
Signature · 1 line
1.8.0
Lars-Peter Clausen
maintainerPATCH 4/6 ASoC: sigmadsp: Restructure in preparation for fw v2 support
In reply to Lars-Peter ClausenThe v2 file format of the SigmaDSP takes a more declarative style compared to the imperative style of the v1 format. In addition some features that are supported with v2 require the driver to keep state around for the firmware. This requires a bit of restructuring of both the firmware loader itself and the drivers making use of the firmware loader.
Instead of loading and executing the firmware in place when the DSP is configured the firmware is now loaded at driver probe time. This is required since the new firmware format will in addition to the firmware data itself contain meta information describing the firmware and its requirements and capabilities. Those will for example be used to restrict the supported samplerates advertised by the driver to userspace to the list of samplerates supported for the firmware.
This only does the restructuring required by the v2 format, but does not yet add support for the new format itself.
--- sound/soc/codecs/adau1701.c | 33 ++++- sound/soc/codecs/adau1761.c | 21 ++- sound/soc/codecs/adau1781.c | 30 ++--- sound/soc/codecs/adau17x1.c | 54 +++++++- sound/soc/codecs/adau17x1.h | 9 +- sound/soc/codecs/sigmadsp-i2c.c | 52 ++++++-- sound/soc/codecs/sigmadsp-regmap.c | 38 ++++-- sound/soc/codecs/sigmadsp.c | 255 +++++++++++++++++++++++++++++++------ sound/soc/codecs/sigmadsp.h | 53 +++++--- 9 files changed, 424 insertions(+), 121 deletions(-)
sound/soc/codecs/adau1701.c +28 -5
@@ -103,6 +103,8 @@ struct adau1701 {unsigned int sysclk;struct regmap *regmap;u8 pin_config[12 ]; + +struct sigmadsp *sigmadsp; };static const struct snd_kcontrol_new adau1701_controls[] = {
@@ -238,12 +240,14 @@ static int adau1701_reg_read(void *context, unsigned int reg,return 0 ; } -static int adau1701_reset (struct snd_soc_codec *codec,unsigned int clkdiv) +static int adau1701_reset (struct snd_soc_codec *codec,unsigned int clkdiv, +unsigned int rate) {struct adau1701 *adau1701 =snd_soc_codec_get_drvdata (codec); -struct i2c_client *client =to_i2c_client (codec->dev);int ret; +sigmadsp_reset (adau1701->sigmadsp); +if (clkdiv !=ADAU1707_CLKDIV_UNSET &&gpio_is_valid (adau1701->gpio_pll_mode[0 ]) &&gpio_is_valid (adau1701->gpio_pll_mode[1 ])) {
@@ -284,7 +288,7 @@ static int adau1701_reset(struct snd_soc_codec *codec, unsigned int clkdiv)* know the correct PLL setup */ if (clkdiv !=ADAU1707_CLKDIV_UNSET ) { - ret =process_sigma_firmware (client,ADAU1701_FIRMWARE ); + ret =sigmadsp_setup (adau1701->sigmadsp, rate);if (ret) {dev_warn (codec->dev,"Failed to load firmware\n" );return ret;
@@ -385,7 +389,7 @@ static int adau1701_hw_params(struct snd_pcm_substream *substream,* firmware upload. */ if (clkdiv != adau1701->pll_clkdiv) { - ret =adau1701_reset (codec, clkdiv); + ret =adau1701_reset (codec, clkdiv,params_rate (params));if (ret <0 )return ret; }
@@ -554,6 +558,14 @@ static int adau1701_set_sysclk(struct snd_soc_codec *codec, int clk_id,return 0 ; } +static int adau1701_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct adau1701 *adau1701 =snd_soc_codec_get_drvdata (dai->codec); + +return sigmadsp_restrict_params (adau1701->sigmadsp, substream); +} +#define ADAU1701_RATES (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | \ SNDRV_PCM_RATE_192000)
@@ -564,6 +576,7 @@ static const struct snd_soc_dai_ops adau1701_dai_ops = { .set_fmt = adau1701_set_dai_fmt, .hw_params = adau1701_hw_params, .digital_mute = adau1701_digital_mute, + .startup = adau1701_startup, };static struct snd_soc_dai_driver adau1701_dai = {
@@ -600,6 +613,10 @@ static int adau1701_probe(struct snd_soc_codec *codec)unsigned int val;struct adau1701 *adau1701 =snd_soc_codec_get_drvdata (codec); + ret =sigmadsp_attach (adau1701->sigmadsp, &codec->component); +if (ret) +return ret; +/* * Let the pll_clkdiv variable default to something that won't happen * at runtime. That way, we can postpone the firmware download from
@@ -609,7 +626,7 @@ static int adau1701_probe(struct snd_soc_codec *codec) adau1701->pll_clkdiv =ADAU1707_CLKDIV_UNSET ;/* initalize with pre-configured pll mode settings */ - ret =adau1701_reset (codec, adau1701->pll_clkdiv); + ret =adau1701_reset (codec, adau1701->pll_clkdiv,0 );if (ret <0 )return ret;
@@ -722,6 +739,12 @@ static int adau1701_i2c_probe(struct i2c_client *client, adau1701->gpio_pll_mode[1 ] = gpio_pll_mode[1 ];i2c_set_clientdata (client, adau1701); + + adau1701->sigmadsp =devm_sigmadsp_init_i2c (client,NULL , +ADAU1701_FIRMWARE ); +if (IS_ERR (adau1701->sigmadsp)) +return PTR_ERR (adau1701->sigmadsp); + ret =snd_soc_register_codec (&client->dev, &adau1701_codec_drv, &adau1701_dai,1 );return ret;
sound/soc/codecs/adau1761.c +10 -11
@@ -703,11 +703,6 @@ static int adau1761_codec_probe(struct snd_soc_codec *codec) ARRAY_SIZE(adau1761_dapm_routes));if (ret)return ret; - - ret =adau17x1_load_firmware (adau, codec->dev, -ADAU1761_FIRMWARE ); -if (ret) -dev_warn (codec->dev,"Failed to firmware\n" ); } ret =adau17x1_add_routes (codec);
@@ -776,16 +771,20 @@ int adau1761_probe(struct device *dev, struct regmap *regmap, enum adau17x1_type type, void (*switch_mode)(struct device *dev)) {struct snd_soc_dai_driver *dai_drv; +const char *firmware_name;int ret; - ret =adau17x1_probe (dev, regmap, type, switch_mode); -if (ret) -return ret; - -if (type ==ADAU1361 ) +if (type ==ADAU1361 ) { dai_drv = &adau1361_dai_driver; -else + firmware_name =NULL ; + }else { dai_drv = &adau1761_dai_driver; + firmware_name =ADAU1761_FIRMWARE ; + } + + ret =adau17x1_probe (dev, regmap, type, switch_mode, firmware_name); +if (ret) +return ret;return snd_soc_register_codec (dev, &adau1761_codec_driver, dai_drv,1 ); }
sound/soc/codecs/adau1781.c +13 -17
@@ -385,7 +385,6 @@ static int adau1781_codec_probe(struct snd_soc_codec *codec) {struct adau1781_platform_data *pdata =dev_get_platdata (codec->dev);struct adau *adau =snd_soc_codec_get_drvdata (codec); -const char *firmware;int ret; ret =adau17x1_add_widgets (codec);
@@ -422,25 +421,10 @@ static int adau1781_codec_probe(struct snd_soc_codec *codec)return ret; } -switch (adau->type) { -case ADAU1381 : - firmware =ADAU1381_FIRMWARE ; -break ; -case ADAU1781 : - firmware =ADAU1781_FIRMWARE ; -break ; -default : -return -EINVAL ; - } - ret =adau17x1_add_routes (codec);if (ret <0 )return ret; - ret =adau17x1_load_firmware (adau, codec->dev, firmware); -if (ret) -dev_warn (codec->dev,"Failed to load firmware\n" ); -return 0 ; }
@@ -496,9 +480,21 @@ EXPORT_SYMBOL_GPL(adau1781_regmap_config);int adau1781_probe (struct device *dev,struct regmap *regmap,enum adau17x1_type type,void (*switch_mode)(struct device *dev)) { +const char *firmware_name;int ret; - ret =adau17x1_probe (dev, regmap, type, switch_mode); +switch (type) { +case ADAU1381 : + firmware_name =ADAU1381_FIRMWARE ; +break ; +case ADAU1781 : + firmware_name =ADAU1781_FIRMWARE ; +break ; +default : +return -EINVAL ; + } + + ret =adau17x1_probe (dev, regmap, type, switch_mode, firmware_name);if (ret)return ret;
sound/soc/codecs/adau17x1.c +48 -6
115 lines not on this page · raw message
sound/soc/codecs/adau17x1.h +6 -3
@@ -4,6 +4,8 @@#include <linux/regmap.h> #include <linux/platform_data/adau17x1.h> +#include "sigmadsp.h" +enum adau17x1_type {ADAU1361 ,ADAU1761 ,
@@ -42,12 +44,14 @@ struct adau {bool dsp_bypass[2 ];struct regmap *regmap; +struct sigmadsp *sigmadsp; };int adau17x1_add_widgets (struct snd_soc_codec *codec);int adau17x1_add_routes (struct snd_soc_codec *codec);int adau17x1_probe (struct device *dev,struct regmap *regmap, -enum adau17x1_type type,void (*switch_mode)(struct device *dev)); +enum adau17x1_type type,void (*switch_mode)(struct device *dev), +const char *firmware_name);int adau17x1_set_micbias_voltage (struct snd_soc_codec *codec,enum adau17x1_micbias_voltage micbias);bool adau17x1_readable_register (struct device *dev,unsigned int reg);
@@ -57,8 +61,7 @@ int adau17x1_resume(struct snd_soc_codec *codec);extern const struct snd_soc_dai_ops adau17x1_dai_ops; -int adau17x1_load_firmware (struct adau *adau,struct device *dev, -const char *firmware); +int adau17x1_setup_firmware (struct adau *adau,unsigned int rate);bool adau17x1_has_dsp (struct adau *adau);#define ADAU17X1_CLOCK_CONTROL 0x4000
sound/soc/codecs/sigmadsp-i2c.c +41 -11
70 lines not on this page · raw message
sound/soc/codecs/sigmadsp-regmap.c +27 -11
@@ -12,24 +12,40 @@#include "sigmadsp.h" -static int sigma_action_write_regmap (void *control_data, -const struct sigma_action *sa,size_t len) +static int sigmadsp_write_regmap (void *control_data, +unsigned int addr,const uint8_t data[],size_t len) { -return regmap_raw_write (control_data,be16_to_cpu (sa->addr), - sa->payload, len -2 ); +return regmap_raw_write (control_data, addr, + data, len); } -int process_sigma_firmware_regmap (struct device *dev,struct regmap *regmap, -const char *name) +/** +* devm_sigmadsp_init_i2c() - Initialize SigmaDSP instance +* @dev: The parent device +* @regmap: Regmap instance to use +* @ops: The sigmadsp_ops to use for this instance +* @firmware_name: Name of the firmware file to load +* +* Allocates a SigmaDSP instance and loads the specified firmware file. +* +* Returns a pointer to a struct sigmadsp on success, or a PTR_ERR() on error. +*/ +struct sigmadsp *devm_sigmadsp_init_regmap (struct device *dev, +struct regmap *regmap,const struct sigmadsp_ops *ops, +const char *firmware_name) { -struct sigma_firmware ssfw; +struct sigmadsp *sigmadsp; + + sigmadsp =devm_sigmadsp_init (dev, ops, firmware_name); +if (IS_ERR (sigmadsp)) +return sigmadsp; - ssfw.control_data = regmap; - ssfw.write = sigma_action_write_regmap; + sigmadsp->control_data = regmap; + sigmadsp->write = sigmadsp_write_regmap; -return _process_sigma_firmware (dev, &ssfw, name); +return sigmadsp; } -EXPORT_SYMBOL (process_sigma_firmware_regmap); +EXPORT_SYMBOL_GPL (devm_sigmadsp_init_regmap);MODULE_AUTHOR ("Lars-Peter Clausen <[email protected]>" );MODULE_DESCRIPTION ("SigmaDSP regmap firmware loader" );
sound/soc/codecs/sigmadsp.c +215 -40
353 lines not on this page · raw message
sound/soc/codecs/sigmadsp.h +36 -17
67 lines not on this page · raw message
Signature · 1 line
1.8.0
Lars-Peter Clausen
maintainerPATCH 5/6 ASoC: sigmadsp: Add support for fw v2
In reply to Lars-Peter ClausenThis patch adds support for the v2 version of the SigmaDSP firmware file format. The new format has support for having different program and parameter settings for different samplerates. In addition it stores metadata describing the firmware. This metadata includes the set of supported samplerates which will be used to restrict the samplerates that can be selected by userspace. Also included is information about the modifiable parameters. Those will be exposed as ALSA controls so they can be changed at runtime.
The new format is based on a binary type-length-value structure that makes it both forward and backwards compatible.
--- sound/soc/codecs/sigmadsp-i2c.c | 29 +++ sound/soc/codecs/sigmadsp-regmap.c | 8 + sound/soc/codecs/sigmadsp.c | 463 ++++++++++++++++++++++++++++++++++++- sound/soc/codecs/sigmadsp.h | 6 + 4 files changed, 504 insertions(+), 2 deletions(-)
sound/soc/codecs/sigmadsp-i2c.c +29 -0
@@ -34,6 +34,34 @@ static int sigmadsp_write_i2c(void *control_data,return ret; } +static int sigmadsp_read_i2c (void *control_data, +unsigned int addr,uint8_t data[],size_t len) +{ +struct i2c_client *client = control_data; +struct i2c_msg msgs[2 ]; +uint8_t buf[2 ]; +int ret; + +put_unaligned_be16 (addr, buf); + + msgs[0 ].addr = client->addr; + msgs[0 ].len =sizeof (buf); + msgs[0 ].buf = buf; + msgs[0 ].flags =0 ; + + msgs[1 ].addr = client->addr; + msgs[1 ].len = len; + msgs[1 ].buf = data; + msgs[1 ].flags =I2C_M_RD ; + + ret =i2c_transfer (client->adapter, msgs,ARRAY_SIZE (msgs)); +if (ret <0 ) +return ret; +else if (ret !=ARRAY_SIZE (msgs)) +return -EIO ; +return 0 ; +} +/** * devm_sigmadsp_init_i2c() - Initialize SigmaDSP instance * @client: The parent I2C device
@@ -55,6 +83,7 @@ struct sigmadsp *devm_sigmadsp_init_i2c(struct i2c_client *client, sigmadsp->control_data = client; sigmadsp->write = sigmadsp_write_i2c; + sigmadsp->read = sigmadsp_read_i2c;return sigmadsp; }
sound/soc/codecs/sigmadsp-regmap.c +8 -0
@@ -19,6 +19,13 @@ static int sigmadsp_write_regmap(void *control_data, data, len); } +static int sigmadsp_read_regmap (void *control_data, +unsigned int addr,uint8_t data[],size_t len) +{ +return regmap_raw_read (control_data, addr, + data, len); +} +/** * devm_sigmadsp_init_i2c() - Initialize SigmaDSP instance * @dev: The parent device
@@ -42,6 +49,7 @@ struct sigmadsp *devm_sigmadsp_init_regmap(struct device *dev, sigmadsp->control_data = regmap; sigmadsp->write = sigmadsp_write_regmap; + sigmadsp->read = sigmadsp_read_regmap;return sigmadsp; }
sound/soc/codecs/sigmadsp.c +461 -2
559 lines not on this page · raw message
sound/soc/codecs/sigmadsp.h +6 -0
@@ -27,14 +27,20 @@ struct sigmadsp_ops {struct sigmadsp {const struct sigmadsp_ops *ops; +struct list_head ctrl_list;struct list_head data_list; +struct snd_pcm_hw_constraint_list rate_constraints; +unsigned int current_samplerate;struct snd_soc_component *component;struct device *dev; +struct mutex lock; +void *control_data;int (*write)(void *,unsigned int ,const uint8_t *,size_t ); +int (*read)(void *,unsigned int ,uint8_t *,size_t ); }; struct sigmadsp *devm_sigmadsp_init(struct device *dev,
Signature · 1 line
1.8.0
Lars-Peter Clausen
maintainerPATCH 6/6 ASoC: adau1701: Implement sigmadsp safeload
In reply to Lars-Peter ClausenThe safeload feature allows to load up to 5 parameter memory registers atomically. This is helpful for switching between e.g. filter settings without causing any glitches.
--- sound/soc/codecs/adau1701.c | 57 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-)
sound/soc/codecs/adau1701.c +55 -2
@@ -22,9 +22,14 @@#include <sound/pcm_params.h> #include <sound/soc.h> +#include <asm/unaligned.h> +#include "sigmadsp.h" #include "adau1701.h" +#define ADAU1701_SAFELOAD_DATA (i) (0x0810 + (i)) +#define ADAU1701_SAFELOAD_ADDR (i) (0x0815 + (i)) +#define ADAU1701_DSPCTRL 0x081c#define ADAU1701_SEROCTL 0x081e#define ADAU1701_SERICTL 0x081f
@@ -42,6 +47,7 @@#define ADAU1701_DSPCTRL_CR (1 << 2)#define ADAU1701_DSPCTRL_DAM (1 << 3)#define ADAU1701_DSPCTRL_ADM (1 << 4) +#define ADAU1701_DSPCTRL_IST (1 << 5)#define ADAU1701_DSPCTRL_SR_48 0x00#define ADAU1701_DSPCTRL_SR_96 0x01#define ADAU1701_DSPCTRL_SR_192 0x02
@@ -102,6 +108,7 @@ struct adau1701 {unsigned int pll_clkdiv;unsigned int sysclk;struct regmap *regmap; +struct i2c_client *client;u8 pin_config[12 ];struct sigmadsp *sigmadsp;
@@ -161,6 +168,7 @@ static bool adau1701_volatile_reg(struct device *dev, unsigned int reg) {switch (reg) {case ADAU1701_DACSET : +case ADAU1701_DSPCTRL :return true;default :return false;
@@ -240,6 +248,50 @@ static int adau1701_reg_read(void *context, unsigned int reg,return 0 ; } +static int adau1701_safeload (struct sigmadsp *sigmadsp,unsigned int addr, +const uint8_t bytes[],size_t len) +{ +struct i2c_client *client =to_i2c_client (sigmadsp->dev); +struct adau1701 *adau1701 =i2c_get_clientdata (client); +unsigned int val; +unsigned int i; +uint8_t buf[10 ]; +int ret; + + ret =regmap_read (adau1701->regmap,ADAU1701_DSPCTRL , &val); +if (ret) +return ret; + +if (val &ADAU1701_DSPCTRL_IST ) +msleep (50 ); + +for (i =0 ; i < len /4 ; i++) { +put_unaligned_le16 (ADAU1701_SAFELOAD_DATA (i), buf); + buf[2 ] =0x00 ; +memcpy (buf +3 , bytes + i *4 ,4 ); + ret =i2c_master_send (client, buf,7 ); +if (ret <0 ) +return ret; +else if (ret !=7 ) +return -EIO ; + +put_unaligned_le16 (ADAU1701_SAFELOAD_ADDR (i), buf); +put_unaligned_le16 (addr + i, buf +2 ); + ret =i2c_master_send (client, buf,4 ); +if (ret <0 ) +return ret; +else if (ret !=4 ) +return -EIO ; + } + +return regmap_update_bits (adau1701->regmap,ADAU1701_DSPCTRL , +ADAU1701_DSPCTRL_IST ,ADAU1701_DSPCTRL_IST ); +} + +static const struct sigmadsp_ops adau1701_sigmadsp_ops = { + .safeload = adau1701_safeload, +}; +static int adau1701_reset (struct snd_soc_codec *codec,unsigned int clkdiv,unsigned int rate) {
@@ -684,6 +736,7 @@ static int adau1701_i2c_probe(struct i2c_client *client,if (!adau1701)return -ENOMEM ; + adau1701->client = client; adau1701->regmap =devm_regmap_init (dev,NULL , client, &adau1701_regmap);if (IS_ERR (adau1701->regmap))
@@ -740,8 +793,8 @@ static int adau1701_i2c_probe(struct i2c_client *client,i2c_set_clientdata (client, adau1701); - adau1701->sigmadsp =devm_sigmadsp_init_i2c (client,NULL , -ADAU1701_FIRMWARE ); + adau1701->sigmadsp =devm_sigmadsp_init_i2c (client, + &adau1701_sigmadsp_ops,ADAU1701_FIRMWARE );if (IS_ERR (adau1701->sigmadsp))return PTR_ERR (adau1701->sigmadsp);
Signature · 1 line
1.8.0
Quoted 3 lines · Lars-Peter Clausen
Make sure to check the version field of the firmware header to make sure to not accidentally try to parse a firmware file with a different layout. Trying to do so can result in loading invalid firmware code to the device.
Applied all, thanks.