Commit 2323736d authored by Charles Keepax's avatar Charles Keepax Committed by Mark Brown

ASoC: wm_adsp: Add basic support for rev 1 firmware file format

Revision one of the file format includes new algorithm and coefficient
blocks which provide additional information about the controls exported
by the firmware. This patch updates the processing to handle this
version of the file format. Note that whilst this version of the format
adds support for specifying a name for the control through the firmware
file this has not been used and to keep compatibility with existing
deployments no changes to the firmware control naming are made by this
patch.
Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent b21acc1c
...@@ -229,12 +229,14 @@ struct wm_coeff_ctl_ops { ...@@ -229,12 +229,14 @@ struct wm_coeff_ctl_ops {
struct wm_coeff_ctl { struct wm_coeff_ctl {
const char *name; const char *name;
const char *fw_name;
struct wm_adsp_alg_region alg_region; struct wm_adsp_alg_region alg_region;
struct wm_coeff_ctl_ops ops; struct wm_coeff_ctl_ops ops;
struct wm_adsp *dsp; struct wm_adsp *dsp;
unsigned int enabled:1; unsigned int enabled:1;
struct list_head list; struct list_head list;
void *cache; void *cache;
unsigned int offset;
size_t len; size_t len;
unsigned int set:1; unsigned int set:1;
struct snd_kcontrol *kcontrol; struct snd_kcontrol *kcontrol;
...@@ -388,7 +390,7 @@ static int wm_coeff_write_control(struct wm_coeff_ctl *ctl, ...@@ -388,7 +390,7 @@ static int wm_coeff_write_control(struct wm_coeff_ctl *ctl,
return -EINVAL; return -EINVAL;
} }
reg = ctl->alg_region.base; reg = ctl->alg_region.base + ctl->offset;
reg = wm_adsp_region_to_reg(mem, reg); reg = wm_adsp_region_to_reg(mem, reg);
scratch = kmemdup(buf, ctl->len, GFP_KERNEL | GFP_DMA); scratch = kmemdup(buf, ctl->len, GFP_KERNEL | GFP_DMA);
...@@ -442,7 +444,7 @@ static int wm_coeff_read_control(struct wm_coeff_ctl *ctl, ...@@ -442,7 +444,7 @@ static int wm_coeff_read_control(struct wm_coeff_ctl *ctl,
return -EINVAL; return -EINVAL;
} }
reg = ctl->alg_region.base; reg = ctl->alg_region.base + ctl->offset;
reg = wm_adsp_region_to_reg(mem, reg); reg = wm_adsp_region_to_reg(mem, reg);
scratch = kmalloc(ctl->len, GFP_KERNEL | GFP_DMA); scratch = kmalloc(ctl->len, GFP_KERNEL | GFP_DMA);
...@@ -509,8 +511,6 @@ static int wmfw_add_ctl(struct wm_adsp *dsp, struct wm_coeff_ctl *ctl) ...@@ -509,8 +511,6 @@ static int wmfw_add_ctl(struct wm_adsp *dsp, struct wm_coeff_ctl *ctl)
ctl->kcontrol = snd_soc_card_get_kcontrol(dsp->card, ctl->kcontrol = snd_soc_card_get_kcontrol(dsp->card,
ctl->name); ctl->name);
list_add(&ctl->list, &dsp->ctl_list);
return 0; return 0;
err_kcontrol: err_kcontrol:
...@@ -568,7 +568,8 @@ static void wm_adsp_ctl_work(struct work_struct *work) ...@@ -568,7 +568,8 @@ static void wm_adsp_ctl_work(struct work_struct *work)
static int wm_adsp_create_control(struct wm_adsp *dsp, static int wm_adsp_create_control(struct wm_adsp *dsp,
const struct wm_adsp_alg_region *alg_region, const struct wm_adsp_alg_region *alg_region,
unsigned int len) unsigned int offset, unsigned int len,
const char *subname, unsigned int subname_len)
{ {
struct wm_coeff_ctl *ctl; struct wm_coeff_ctl *ctl;
struct wmfw_ctl_work *ctl_work; struct wmfw_ctl_work *ctl_work;
...@@ -593,6 +594,7 @@ static int wm_adsp_create_control(struct wm_adsp *dsp, ...@@ -593,6 +594,7 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
region_name = "ZM"; region_name = "ZM";
break; break;
default: default:
adsp_err(dsp, "Unknown region type: %d\n", alg_region->type);
return -EINVAL; return -EINVAL;
} }
...@@ -611,6 +613,7 @@ static int wm_adsp_create_control(struct wm_adsp *dsp, ...@@ -611,6 +613,7 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
ctl = kzalloc(sizeof(*ctl), GFP_KERNEL); ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
if (!ctl) if (!ctl)
return -ENOMEM; return -ENOMEM;
ctl->fw_name = wm_adsp_fw_text[dsp->fw];
ctl->alg_region = *alg_region; ctl->alg_region = *alg_region;
ctl->name = kmemdup(name, strlen(name) + 1, GFP_KERNEL); ctl->name = kmemdup(name, strlen(name) + 1, GFP_KERNEL);
if (!ctl->name) { if (!ctl->name) {
...@@ -623,6 +626,7 @@ static int wm_adsp_create_control(struct wm_adsp *dsp, ...@@ -623,6 +626,7 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
ctl->ops.xput = wm_coeff_put; ctl->ops.xput = wm_coeff_put;
ctl->dsp = dsp; ctl->dsp = dsp;
ctl->offset = offset;
if (len > 512) { if (len > 512) {
adsp_warn(dsp, "Truncating control %s from %d\n", adsp_warn(dsp, "Truncating control %s from %d\n",
ctl->name, len); ctl->name, len);
...@@ -635,6 +639,8 @@ static int wm_adsp_create_control(struct wm_adsp *dsp, ...@@ -635,6 +639,8 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
goto err_ctl_name; goto err_ctl_name;
} }
list_add(&ctl->list, &dsp->ctl_list);
ctl_work = kzalloc(sizeof(*ctl_work), GFP_KERNEL); ctl_work = kzalloc(sizeof(*ctl_work), GFP_KERNEL);
if (!ctl_work) { if (!ctl_work) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -658,6 +664,103 @@ static int wm_adsp_create_control(struct wm_adsp *dsp, ...@@ -658,6 +664,103 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
return ret; return ret;
} }
struct wm_coeff_parsed_alg {
int id;
const u8 *name;
int name_len;
int ncoeff;
};
struct wm_coeff_parsed_coeff {
int offset;
int mem_type;
const u8 *name;
int name_len;
int ctl_type;
int flags;
int len;
};
static inline void wm_coeff_parse_alg(struct wm_adsp *dsp, const u8 **data,
struct wm_coeff_parsed_alg *blk)
{
const struct wmfw_adsp_alg_data *raw;
raw = (const struct wmfw_adsp_alg_data *)*data;
*data = raw->data;
blk->id = le32_to_cpu(raw->id);
blk->name = raw->name;
blk->name_len = strlen(raw->name);
blk->ncoeff = le32_to_cpu(raw->ncoeff);
adsp_dbg(dsp, "Algorithm ID: %#x\n", blk->id);
adsp_dbg(dsp, "Algorithm name: %.*s\n", blk->name_len, blk->name);
adsp_dbg(dsp, "# of coefficient descriptors: %#x\n", blk->ncoeff);
}
static inline void wm_coeff_parse_coeff(struct wm_adsp *dsp, const u8 **data,
struct wm_coeff_parsed_coeff *blk)
{
const struct wmfw_adsp_coeff_data *raw;
raw = (const struct wmfw_adsp_coeff_data *)*data;
*data = *data + sizeof(raw->hdr) + le32_to_cpu(raw->hdr.size);
blk->offset = le16_to_cpu(raw->hdr.offset);
blk->mem_type = le16_to_cpu(raw->hdr.type);
blk->name = raw->name;
blk->name_len = strlen(raw->name);
blk->ctl_type = le16_to_cpu(raw->ctl_type);
blk->flags = le16_to_cpu(raw->flags);
blk->len = le32_to_cpu(raw->len);
adsp_dbg(dsp, "\tCoefficient type: %#x\n", blk->mem_type);
adsp_dbg(dsp, "\tCoefficient offset: %#x\n", blk->offset);
adsp_dbg(dsp, "\tCoefficient name: %.*s\n", blk->name_len, blk->name);
adsp_dbg(dsp, "\tCoefficient flags: %#x\n", blk->flags);
adsp_dbg(dsp, "\tALSA control type: %#x\n", blk->ctl_type);
adsp_dbg(dsp, "\tALSA control len: %#x\n", blk->len);
}
static int wm_adsp_parse_coeff(struct wm_adsp *dsp,
const struct wmfw_region *region)
{
struct wm_adsp_alg_region alg_region = {};
struct wm_coeff_parsed_alg alg_blk;
struct wm_coeff_parsed_coeff coeff_blk;
const u8 *data = region->data;
int i, ret;
wm_coeff_parse_alg(dsp, &data, &alg_blk);
for (i = 0; i < alg_blk.ncoeff; i++) {
wm_coeff_parse_coeff(dsp, &data, &coeff_blk);
switch (coeff_blk.ctl_type) {
case SNDRV_CTL_ELEM_TYPE_BYTES:
break;
default:
adsp_err(dsp, "Unknown control type: %d\n",
coeff_blk.ctl_type);
return -EINVAL;
}
alg_region.type = coeff_blk.mem_type;
alg_region.alg = alg_blk.id;
ret = wm_adsp_create_control(dsp, &alg_region,
coeff_blk.offset,
coeff_blk.len,
coeff_blk.name,
coeff_blk.name_len);
if (ret < 0)
adsp_err(dsp, "Failed to create control: %.*s, %d\n",
coeff_blk.name_len, coeff_blk.name, ret);
}
return 0;
}
static int wm_adsp_load(struct wm_adsp *dsp) static int wm_adsp_load(struct wm_adsp *dsp)
{ {
LIST_HEAD(buf_list); LIST_HEAD(buf_list);
...@@ -706,12 +809,18 @@ static int wm_adsp_load(struct wm_adsp *dsp) ...@@ -706,12 +809,18 @@ static int wm_adsp_load(struct wm_adsp *dsp)
goto out_fw; goto out_fw;
} }
if (header->ver != 0) { switch (header->ver) {
case 0:
case 1:
break;
default:
adsp_err(dsp, "%s: unknown file format %d\n", adsp_err(dsp, "%s: unknown file format %d\n",
file, header->ver); file, header->ver);
goto out_fw; goto out_fw;
} }
adsp_info(dsp, "Firmware version: %d\n", header->ver); adsp_info(dsp, "Firmware version: %d\n", header->ver);
dsp->fw_ver = header->ver;
if (header->core != dsp->type) { if (header->core != dsp->type) {
adsp_err(dsp, "%s: invalid core %d != %d\n", adsp_err(dsp, "%s: invalid core %d != %d\n",
...@@ -776,6 +885,12 @@ static int wm_adsp_load(struct wm_adsp *dsp) ...@@ -776,6 +885,12 @@ static int wm_adsp_load(struct wm_adsp *dsp)
text = kzalloc(le32_to_cpu(region->len) + 1, text = kzalloc(le32_to_cpu(region->len) + 1,
GFP_KERNEL); GFP_KERNEL);
break; break;
case WMFW_ALGORITHM_DATA:
region_name = "Algorithm";
ret = wm_adsp_parse_coeff(dsp, region);
if (ret != 0)
goto out_fw;
break;
case WMFW_INFO_TEXT: case WMFW_INFO_TEXT:
region_name = "Information"; region_name = "Information";
text = kzalloc(le32_to_cpu(region->len) + 1, text = kzalloc(le32_to_cpu(region->len) + 1,
...@@ -868,6 +983,20 @@ static int wm_adsp_load(struct wm_adsp *dsp) ...@@ -868,6 +983,20 @@ static int wm_adsp_load(struct wm_adsp *dsp)
return ret; return ret;
} }
static void wm_adsp_ctl_fixup_base(struct wm_adsp *dsp,
const struct wm_adsp_alg_region *alg_region)
{
struct wm_coeff_ctl *ctl;
list_for_each_entry(ctl, &dsp->ctl_list, list) {
if (ctl->fw_name == wm_adsp_fw_text[dsp->fw] &&
alg_region->alg == ctl->alg_region.alg &&
alg_region->type == ctl->alg_region.type) {
ctl->alg_region.base = alg_region->base;
}
}
}
static void *wm_adsp_read_algs(struct wm_adsp *dsp, size_t n_algs, static void *wm_adsp_read_algs(struct wm_adsp *dsp, size_t n_algs,
unsigned int pos, unsigned int len) unsigned int pos, unsigned int len)
{ {
...@@ -928,6 +1057,9 @@ static struct wm_adsp_alg_region *wm_adsp_create_region(struct wm_adsp *dsp, ...@@ -928,6 +1057,9 @@ static struct wm_adsp_alg_region *wm_adsp_create_region(struct wm_adsp *dsp,
list_add_tail(&alg_region->list, &dsp->alg_regions); list_add_tail(&alg_region->list, &dsp->alg_regions);
if (dsp->fw_ver > 0)
wm_adsp_ctl_fixup_base(dsp, alg_region);
return alg_region; return alg_region;
} }
...@@ -995,15 +1127,18 @@ static int wm_adsp1_setup_algs(struct wm_adsp *dsp) ...@@ -995,15 +1127,18 @@ static int wm_adsp1_setup_algs(struct wm_adsp *dsp)
ret = PTR_ERR(alg_region); ret = PTR_ERR(alg_region);
goto out; goto out;
} }
if (dsp->fw_ver == 0) {
if (i + 1 < n_algs) { if (i + 1 < n_algs) {
len = be32_to_cpu(adsp1_alg[i + 1].dm); len = be32_to_cpu(adsp1_alg[i + 1].dm);
len -= be32_to_cpu(adsp1_alg[i].dm); len -= be32_to_cpu(adsp1_alg[i].dm);
len *= 4; len *= 4;
wm_adsp_create_control(dsp, alg_region, len); wm_adsp_create_control(dsp, alg_region, 0,
len, NULL, 0);
} else { } else {
adsp_warn(dsp, "Missing length info for region DM with ID %x\n", adsp_warn(dsp, "Missing length info for region DM with ID %x\n",
be32_to_cpu(adsp1_alg[i].alg.id)); be32_to_cpu(adsp1_alg[i].alg.id));
} }
}
alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_ZM, alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_ZM,
adsp1_alg[i].alg.id, adsp1_alg[i].alg.id,
...@@ -1012,16 +1147,19 @@ static int wm_adsp1_setup_algs(struct wm_adsp *dsp) ...@@ -1012,16 +1147,19 @@ static int wm_adsp1_setup_algs(struct wm_adsp *dsp)
ret = PTR_ERR(alg_region); ret = PTR_ERR(alg_region);
goto out; goto out;
} }
if (dsp->fw_ver == 0) {
if (i + 1 < n_algs) { if (i + 1 < n_algs) {
len = be32_to_cpu(adsp1_alg[i + 1].zm); len = be32_to_cpu(adsp1_alg[i + 1].zm);
len -= be32_to_cpu(adsp1_alg[i].zm); len -= be32_to_cpu(adsp1_alg[i].zm);
len *= 4; len *= 4;
wm_adsp_create_control(dsp, alg_region, len); wm_adsp_create_control(dsp, alg_region, 0,
len, NULL, 0);
} else { } else {
adsp_warn(dsp, "Missing length info for region ZM with ID %x\n", adsp_warn(dsp, "Missing length info for region ZM with ID %x\n",
be32_to_cpu(adsp1_alg[i].alg.id)); be32_to_cpu(adsp1_alg[i].alg.id));
} }
} }
}
out: out:
kfree(adsp1_alg); kfree(adsp1_alg);
...@@ -1099,15 +1237,18 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp) ...@@ -1099,15 +1237,18 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp)
ret = PTR_ERR(alg_region); ret = PTR_ERR(alg_region);
goto out; goto out;
} }
if (dsp->fw_ver == 0) {
if (i + 1 < n_algs) { if (i + 1 < n_algs) {
len = be32_to_cpu(adsp2_alg[i + 1].xm); len = be32_to_cpu(adsp2_alg[i + 1].xm);
len -= be32_to_cpu(adsp2_alg[i].xm); len -= be32_to_cpu(adsp2_alg[i].xm);
len *= 4; len *= 4;
wm_adsp_create_control(dsp, alg_region, len); wm_adsp_create_control(dsp, alg_region, 0,
len, NULL, 0);
} else { } else {
adsp_warn(dsp, "Missing length info for region XM with ID %x\n", adsp_warn(dsp, "Missing length info for region XM with ID %x\n",
be32_to_cpu(adsp2_alg[i].alg.id)); be32_to_cpu(adsp2_alg[i].alg.id));
} }
}
alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_YM, alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_YM,
adsp2_alg[i].alg.id, adsp2_alg[i].alg.id,
...@@ -1116,15 +1257,18 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp) ...@@ -1116,15 +1257,18 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp)
ret = PTR_ERR(alg_region); ret = PTR_ERR(alg_region);
goto out; goto out;
} }
if (dsp->fw_ver == 0) {
if (i + 1 < n_algs) { if (i + 1 < n_algs) {
len = be32_to_cpu(adsp2_alg[i + 1].ym); len = be32_to_cpu(adsp2_alg[i + 1].ym);
len -= be32_to_cpu(adsp2_alg[i].ym); len -= be32_to_cpu(adsp2_alg[i].ym);
len *= 4; len *= 4;
wm_adsp_create_control(dsp, alg_region, len); wm_adsp_create_control(dsp, alg_region, 0,
len, NULL, 0);
} else { } else {
adsp_warn(dsp, "Missing length info for region YM with ID %x\n", adsp_warn(dsp, "Missing length info for region YM with ID %x\n",
be32_to_cpu(adsp2_alg[i].alg.id)); be32_to_cpu(adsp2_alg[i].alg.id));
} }
}
alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_ZM, alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_ZM,
adsp2_alg[i].alg.id, adsp2_alg[i].alg.id,
...@@ -1133,16 +1277,19 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp) ...@@ -1133,16 +1277,19 @@ static int wm_adsp2_setup_algs(struct wm_adsp *dsp)
ret = PTR_ERR(alg_region); ret = PTR_ERR(alg_region);
goto out; goto out;
} }
if (dsp->fw_ver == 0) {
if (i + 1 < n_algs) { if (i + 1 < n_algs) {
len = be32_to_cpu(adsp2_alg[i + 1].zm); len = be32_to_cpu(adsp2_alg[i + 1].zm);
len -= be32_to_cpu(adsp2_alg[i].zm); len -= be32_to_cpu(adsp2_alg[i].zm);
len *= 4; len *= 4;
wm_adsp_create_control(dsp, alg_region, len); wm_adsp_create_control(dsp, alg_region, 0,
len, NULL, 0);
} else { } else {
adsp_warn(dsp, "Missing length info for region ZM with ID %x\n", adsp_warn(dsp, "Missing length info for region ZM with ID %x\n",
be32_to_cpu(adsp2_alg[i].alg.id)); be32_to_cpu(adsp2_alg[i].alg.id));
} }
} }
}
out: out:
kfree(adsp2_alg); kfree(adsp2_alg);
......
...@@ -53,6 +53,7 @@ struct wm_adsp { ...@@ -53,6 +53,7 @@ struct wm_adsp {
int num_mems; int num_mems;
int fw; int fw;
int fw_ver;
bool running; bool running;
struct regulator *dvfs; struct regulator *dvfs;
......
...@@ -15,6 +15,12 @@ ...@@ -15,6 +15,12 @@
#include <linux/types.h> #include <linux/types.h>
#define WMFW_MAX_ALG_NAME 256
#define WMFW_MAX_ALG_DESCR_NAME 256
#define WMFW_MAX_COEFF_NAME 256
#define WMFW_MAX_COEFF_DESCR_NAME 256
struct wmfw_header { struct wmfw_header {
char magic[4]; char magic[4];
__le32 len; __le32 len;
...@@ -90,6 +96,28 @@ struct wmfw_adsp2_alg_hdr { ...@@ -90,6 +96,28 @@ struct wmfw_adsp2_alg_hdr {
__be32 ym; __be32 ym;
} __packed; } __packed;
struct wmfw_adsp_alg_data {
__le32 id;
u8 name[WMFW_MAX_ALG_NAME];
u8 descr[WMFW_MAX_ALG_DESCR_NAME];
__le32 ncoeff;
u8 data[];
} __packed;
struct wmfw_adsp_coeff_data {
struct {
__le16 offset;
__le16 type;
__le32 size;
} hdr;
u8 name[WMFW_MAX_COEFF_NAME];
u8 descr[WMFW_MAX_COEFF_DESCR_NAME];
__le16 ctl_type;
__le16 flags;
__le32 len;
u8 data[];
} __packed;
struct wmfw_coeff_hdr { struct wmfw_coeff_hdr {
u8 magic[4]; u8 magic[4];
__le32 len; __le32 len;
...@@ -118,6 +146,7 @@ struct wmfw_coeff_item { ...@@ -118,6 +146,7 @@ struct wmfw_coeff_item {
#define WMFW_ADSP2 2 #define WMFW_ADSP2 2
#define WMFW_ABSOLUTE 0xf0 #define WMFW_ABSOLUTE 0xf0
#define WMFW_ALGORITHM_DATA 0xf2
#define WMFW_NAME_TEXT 0xfe #define WMFW_NAME_TEXT 0xfe
#define WMFW_INFO_TEXT 0xff #define WMFW_INFO_TEXT 0xff
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment