Skip to content

Commit

Permalink
ASoC: wm_adsp: Make DSP name configurable by codec driver
Browse files Browse the repository at this point in the history
Instead of harcoding that a core must always be called "DSPn"
add a name member to struct wm_adsp so that the owning codec
driver can provide a custom name. This allows for re-use of
the wm_adsp driver with parts where the processing cores are
named differently.

If no name is provided the default DSPn name is used.

Signed-off-by: Richard Fitzgerald <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
rfvirgil authored and broonie committed Aug 8, 2018
1 parent 35ef57a commit 605391d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
69 changes: 48 additions & 21 deletions sound/soc/codecs/wm_adsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* published by the Free Software Foundation.
*/

#include <linux/ctype.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
Expand All @@ -35,15 +36,15 @@
#include "wm_adsp.h"

#define adsp_crit(_dsp, fmt, ...) \
dev_crit(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__)
dev_crit(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__)
#define adsp_err(_dsp, fmt, ...) \
dev_err(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__)
dev_err(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__)
#define adsp_warn(_dsp, fmt, ...) \
dev_warn(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__)
dev_warn(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__)
#define adsp_info(_dsp, fmt, ...) \
dev_info(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__)
dev_info(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__)
#define adsp_dbg(_dsp, fmt, ...) \
dev_dbg(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__)
dev_dbg(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__)

#define ADSP1_CONTROL_1 0x00
#define ADSP1_CONTROL_2 0x02
Expand Down Expand Up @@ -608,21 +609,14 @@ static void wm_adsp2_init_debugfs(struct wm_adsp *dsp,
struct snd_soc_component *component)
{
struct dentry *root = NULL;
char *root_name;
int i;

if (!component->debugfs_root) {
adsp_err(dsp, "No codec debugfs root\n");
goto err;
}

root_name = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!root_name)
goto err;

snprintf(root_name, PAGE_SIZE, "dsp%d", dsp->num);
root = debugfs_create_dir(root_name, component->debugfs_root);
kfree(root_name);
root = debugfs_create_dir(dsp->name, component->debugfs_root);

if (!root)
goto err;
Expand Down Expand Up @@ -1315,12 +1309,12 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
switch (dsp->fw_ver) {
case 0:
case 1:
snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "DSP%d %s %x",
dsp->num, region_name, alg_region->alg);
snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s %s %x",
dsp->name, region_name, alg_region->alg);
break;
default:
ret = snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN,
"DSP%d%c %.12s %x", dsp->num, *region_name,
"%s%c %.12s %x", dsp->name, *region_name,
wm_adsp_fw_text[dsp->fw], alg_region->alg);

/* Truncate the subname from the start if it is too long */
Expand Down Expand Up @@ -1648,7 +1642,7 @@ static int wm_adsp_load(struct wm_adsp *dsp)
if (file == NULL)
return -ENOMEM;

snprintf(file, PAGE_SIZE, "%s-dsp%d-%s.wmfw", dsp->part, dsp->num,
snprintf(file, PAGE_SIZE, "%s-%s-%s.wmfw", dsp->part, dsp->fwf_name,
wm_adsp_fw[dsp->fw].file);
file[PAGE_SIZE - 1] = '\0';

Expand Down Expand Up @@ -2226,7 +2220,7 @@ static int wm_adsp_load_coeff(struct wm_adsp *dsp)
if (file == NULL)
return -ENOMEM;

snprintf(file, PAGE_SIZE, "%s-dsp%d-%s.bin", dsp->part, dsp->num,
snprintf(file, PAGE_SIZE, "%s-%s-%s.bin", dsp->part, dsp->fwf_name,
wm_adsp_fw[dsp->fw].file);
file[PAGE_SIZE - 1] = '\0';

Expand Down Expand Up @@ -2398,8 +2392,38 @@ static int wm_adsp_load_coeff(struct wm_adsp *dsp)
return ret;
}

static int wm_adsp_create_name(struct wm_adsp *dsp)
{
char *p;

if (!dsp->name) {
dsp->name = devm_kasprintf(dsp->dev, GFP_KERNEL, "DSP%d",
dsp->num);
if (!dsp->name)
return -ENOMEM;
}

if (!dsp->fwf_name) {
p = devm_kstrdup(dsp->dev, dsp->name, GFP_KERNEL);
if (!p)
return -ENOMEM;

dsp->fwf_name = p;
for (; *p != 0; ++p)
*p = tolower(*p);
}

return 0;
}

int wm_adsp1_init(struct wm_adsp *dsp)
{
int ret;

ret = wm_adsp_create_name(dsp);
if (ret)
return ret;

INIT_LIST_HEAD(&dsp->alg_regions);

mutex_init(&dsp->pwr_lock);
Expand Down Expand Up @@ -2672,7 +2696,7 @@ int wm_adsp2_preloader_put(struct snd_kcontrol *kcontrol,
struct wm_adsp *dsp = &dsps[mc->shift - 1];
char preload[32];

snprintf(preload, ARRAY_SIZE(preload), "DSP%u Preload", mc->shift);
snprintf(preload, ARRAY_SIZE(preload), "%s Preload", dsp->name);

dsp->preloaded = ucontrol->value.integer.value[0];

Expand Down Expand Up @@ -2867,8 +2891,7 @@ int wm_adsp2_component_probe(struct wm_adsp *dsp, struct snd_soc_component *comp
{
char preload[32];

snprintf(preload, ARRAY_SIZE(preload), "DSP%d Preload", dsp->num);

snprintf(preload, ARRAY_SIZE(preload), "%s Preload", dsp->name);
snd_soc_component_disable_pin(component, preload);

wm_adsp2_init_debugfs(dsp, component);
Expand All @@ -2891,6 +2914,10 @@ int wm_adsp2_init(struct wm_adsp *dsp)
{
int ret;

ret = wm_adsp_create_name(dsp);
if (ret)
return ret;

switch (dsp->rev) {
case 0:
/*
Expand Down
2 changes: 2 additions & 0 deletions sound/soc/codecs/wm_adsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ struct wm_adsp_compr_buf;

struct wm_adsp {
const char *part;
const char *name;
const char *fwf_name;
int rev;
int num;
int type;
Expand Down

0 comments on commit 605391d

Please sign in to comment.