Skip to content

Commit 6dc9734

Browse files
committed
ASoC: wm_adsp: Make DSP name configurable by codec driver
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]> (cherry picked from commit 605391d) Modified from upstream to deal with the VPU and HALO code. Removed suffix and dsp_ao members of struct wm_adsp, and the wm_adsp_arch_text() and wm_adsp_arch_text() functions. These are all replaced by the simple generic naming method. Change-Id: I4cf5a369a580bec9b6173933f8080f26c04f2309 Signed-off-by: Richard Fitzgerald <[email protected]>
1 parent a45822e commit 6dc9734

File tree

2 files changed

+72
-80
lines changed

2 files changed

+72
-80
lines changed

sound/soc/codecs/wm_adsp.c

Lines changed: 69 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* published by the Free Software Foundation.
1111
*/
1212

13+
#include <linux/ctype.h>
1314
#include <linux/module.h>
1415
#include <linux/moduleparam.h>
1516
#include <linux/init.h>
@@ -35,20 +36,15 @@
3536
#include "wm_adsp.h"
3637

3738
#define adsp_crit(_dsp, fmt, ...) \
38-
dev_crit(_dsp->dev, "%s%d: " fmt, wm_adsp_arch_text(_dsp->type), \
39-
_dsp->num, ##__VA_ARGS__)
39+
dev_crit(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__)
4040
#define adsp_err(_dsp, fmt, ...) \
41-
dev_err(_dsp->dev, "%s%d: " fmt, wm_adsp_arch_text(_dsp->type), \
42-
_dsp->num, ##__VA_ARGS__)
41+
dev_err(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__)
4342
#define adsp_warn(_dsp, fmt, ...) \
44-
dev_warn(_dsp->dev, "%s%d: " fmt, wm_adsp_arch_text(_dsp->type), \
45-
_dsp->num, ##__VA_ARGS__)
43+
dev_warn(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__)
4644
#define adsp_info(_dsp, fmt, ...) \
47-
dev_info(_dsp->dev, "%s%d: " fmt, wm_adsp_arch_text(_dsp->type), \
48-
_dsp->num, ##__VA_ARGS__)
45+
dev_info(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__)
4946
#define adsp_dbg(_dsp, fmt, ...) \
50-
dev_dbg(_dsp->dev, "%s%d: " fmt, wm_adsp_arch_text(_dsp->type), \
51-
_dsp->num, ##__VA_ARGS__)
47+
dev_dbg(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__)
5248

5349
#define ADSP1_CONTROL_1 0x00
5450
#define ADSP1_CONTROL_2 0x02
@@ -527,34 +523,6 @@ static const char *wm_adsp_fw_text[WM_ADSP_NUM_FW] = {
527523
[WM_ADSP_FW_MISC] = "Misc",
528524
};
529525

530-
static const char *wm_adsp_arch_text_lower(unsigned int type)
531-
{
532-
switch (type) {
533-
case WMFW_ADSP1:
534-
case WMFW_ADSP2:
535-
case WMFW_HALO:
536-
return "dsp";
537-
case WMFW_VPU:
538-
return "vpu";
539-
default:
540-
return NULL;
541-
}
542-
}
543-
544-
static const char *wm_adsp_arch_text(unsigned int type)
545-
{
546-
switch (type) {
547-
case WMFW_ADSP1:
548-
case WMFW_ADSP2:
549-
case WMFW_HALO:
550-
return "DSP";
551-
case WMFW_VPU:
552-
return "VPU";
553-
default:
554-
return NULL;
555-
}
556-
}
557-
558526
struct wm_adsp_system_config_xm_hdr {
559527
__be32 sys_enable;
560528
__be32 fw_id;
@@ -898,21 +866,14 @@ static void wm_adsp2_init_debugfs(struct wm_adsp *dsp,
898866
struct snd_soc_codec *codec)
899867
{
900868
struct dentry *root = NULL;
901-
char *root_name;
902869
int i;
903870

904871
if (!codec->component.debugfs_root) {
905872
adsp_err(dsp, "No codec debugfs root\n");
906873
goto err;
907874
}
908875

909-
root_name = kmalloc(PAGE_SIZE, GFP_KERNEL);
910-
if (!root_name)
911-
goto err;
912-
913-
snprintf(root_name, PAGE_SIZE, "dsp%d", dsp->num);
914-
root = debugfs_create_dir(root_name, codec->component.debugfs_root);
915-
kfree(root_name);
876+
root = debugfs_create_dir(dsp->name, codec->component.debugfs_root);
916877

917878
if (!root)
918879
goto err;
@@ -1673,21 +1634,13 @@ static int wm_adsp_create_control(struct wm_adsp *dsp,
16731634
switch (dsp->fw_ver) {
16741635
case 0:
16751636
case 1:
1676-
snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "DSP%d %s %x",
1677-
dsp->num, region_name, alg_region->alg);
1637+
snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s %s %x",
1638+
dsp->name, region_name, alg_region->alg);
16781639
subname = NULL; /* don't append subname */
16791640
break;
1680-
case 2:
1681-
ret = snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN,
1682-
"DSP%d%s%c %.12s %x", dsp->num,
1683-
dsp->suffix, *region_name,
1684-
fw_txt, alg_region->alg);
1685-
break;
16861641
default:
16871642
ret = snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN,
1688-
"%s%d%s %.12s %x",
1689-
wm_adsp_arch_text(dsp->type),
1690-
dsp->num, dsp->suffix,
1643+
"%s%c %.12s %x", dsp->name, *region_name,
16911644
fw_txt, alg_region->alg);
16921645
break;
16931646
}
@@ -2033,11 +1986,8 @@ static int wm_adsp_load(struct wm_adsp *dsp)
20331986
goto out;
20341987
}
20351988

2036-
snprintf(file, PAGE_SIZE, "%s-%s%d-%s.wmfw",
2037-
dsp->part,
2038-
wm_adsp_arch_text_lower(dsp->type),
2039-
dsp->num,
2040-
fw_txt);
1989+
snprintf(file, PAGE_SIZE, "%s-%s-%s.wmfw", dsp->part, dsp->fwf_name,
1990+
fw_txt);
20411991
file[PAGE_SIZE - 1] = '\0';
20421992

20431993
ret = request_firmware(&firmware, file, dsp->dev);
@@ -2877,6 +2827,7 @@ static int wm_adsp_load_coeff(struct wm_adsp *dsp)
28772827
const struct wm_adsp_region *mem;
28782828
struct wm_adsp_alg_region *alg_region;
28792829
const char *region_name;
2830+
const char *fw_txt;
28802831
int ret, pos, blocks, type, offset, reg;
28812832
char *file;
28822833
struct wm_adsp_buf *buf;
@@ -2887,16 +2838,15 @@ static int wm_adsp_load_coeff(struct wm_adsp *dsp)
28872838

28882839
switch (dsp->type) {
28892840
case WMFW_VPU:
2890-
snprintf(file, PAGE_SIZE, "%s-vpu%d-%s.bin",
2891-
dsp->part, dsp->num,
2892-
wm_vpu_fw[dsp->fw].file);
2841+
fw_txt = wm_vpu_fw[dsp->fw].file;
28932842
break;
28942843
default:
2895-
snprintf(file, PAGE_SIZE, "%s-dsp%d-%s.bin",
2896-
dsp->part, dsp->num,
2897-
wm_adsp_fw[dsp->fw].file);
2844+
fw_txt = wm_adsp_fw[dsp->fw].file;
2845+
break;
28982846
}
28992847

2848+
snprintf(file, PAGE_SIZE, "%s-%s-%s.bin", dsp->part, dsp->fwf_name,
2849+
fw_txt);
29002850
file[PAGE_SIZE - 1] = '\0';
29012851

29022852
ret = request_firmware(&firmware, file, dsp->dev);
@@ -3071,8 +3021,38 @@ static int wm_adsp_load_coeff(struct wm_adsp *dsp)
30713021
return ret;
30723022
}
30733023

3024+
static int wm_adsp_create_name(struct wm_adsp *dsp)
3025+
{
3026+
char *p;
3027+
3028+
if (!dsp->name) {
3029+
dsp->name = devm_kasprintf(dsp->dev, GFP_KERNEL, "DSP%d",
3030+
dsp->num);
3031+
if (!dsp->name)
3032+
return -ENOMEM;
3033+
}
3034+
3035+
if (!dsp->fwf_name) {
3036+
p = devm_kstrdup(dsp->dev, dsp->name, GFP_KERNEL);
3037+
if (!p)
3038+
return -ENOMEM;
3039+
3040+
dsp->fwf_name = p;
3041+
for (; *p != 0; ++p)
3042+
*p = tolower(*p);
3043+
}
3044+
3045+
return 0;
3046+
}
3047+
30743048
int wm_adsp1_init(struct wm_adsp *dsp)
30753049
{
3050+
int ret;
3051+
3052+
ret = wm_adsp_create_name(dsp);
3053+
if (ret)
3054+
return ret;
3055+
30763056
INIT_LIST_HEAD(&dsp->alg_regions);
30773057

30783058
mutex_init(&dsp->pwr_lock);
@@ -3564,8 +3544,7 @@ int wm_adsp2_preloader_put(struct snd_kcontrol *kcontrol,
35643544
struct wm_adsp *dsp = &dsps[mc->shift-1];
35653545
char preload[32];
35663546

3567-
snprintf(preload, ARRAY_SIZE(preload), "DSP%u%s Preload", mc->shift,
3568-
dsp->suffix);
3547+
snprintf(preload, ARRAY_SIZE(preload), "%s Preload", dsp->name);
35693548

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

@@ -3915,12 +3894,7 @@ int wm_adsp2_codec_probe(struct wm_adsp *dsp, struct snd_soc_codec *codec)
39153894
{
39163895
char preload[32];
39173896

3918-
if (!dsp->suffix)
3919-
dsp->suffix = "";
3920-
3921-
snprintf(preload, ARRAY_SIZE(preload), "DSP%d%s Preload", dsp->num,
3922-
dsp->suffix);
3923-
3897+
snprintf(preload, ARRAY_SIZE(preload), "%s Preload", dsp->name);
39243898
snd_soc_component_disable_pin(&codec->component, preload);
39253899

39263900
wm_adsp2_init_debugfs(dsp, codec);
@@ -3943,6 +3917,10 @@ int wm_adsp2_init(struct wm_adsp *dsp)
39433917
{
39443918
int ret;
39453919

3920+
ret = wm_adsp_create_name(dsp);
3921+
if (ret)
3922+
return ret;
3923+
39463924
switch (dsp->rev) {
39473925
case 0:
39483926
/*
@@ -3973,6 +3951,12 @@ EXPORT_SYMBOL_GPL(wm_adsp2_init);
39733951

39743952
int wm_halo_init(struct wm_adsp *dsp, struct mutex *rate_lock)
39753953
{
3954+
int ret;
3955+
3956+
ret = wm_adsp_create_name(dsp);
3957+
if (ret)
3958+
return ret;
3959+
39763960
INIT_LIST_HEAD(&dsp->alg_regions);
39773961
INIT_LIST_HEAD(&dsp->ctl_list);
39783962
INIT_WORK(&dsp->boot_work, wm_halo_boot_work);
@@ -3989,12 +3973,20 @@ int wm_halo_init(struct wm_adsp *dsp, struct mutex *rate_lock)
39893973
}
39903974
EXPORT_SYMBOL_GPL(wm_halo_init);
39913975

3992-
void wm_vpu_init(struct wm_adsp *vpu)
3976+
int wm_vpu_init(struct wm_adsp *vpu)
39933977
{
3978+
int ret;
3979+
3980+
ret = wm_adsp_create_name(vpu);
3981+
if (ret)
3982+
return ret;
3983+
39943984
INIT_LIST_HEAD(&vpu->alg_regions);
39953985
INIT_LIST_HEAD(&vpu->ctl_list);
39963986
INIT_WORK(&vpu->boot_work, wm_vpu_boot_work);
39973987
mutex_init(&vpu->pwr_lock);
3988+
3989+
return 0;
39983990
}
39993991
EXPORT_SYMBOL_GPL(wm_vpu_init);
40003992

sound/soc/codecs/wm_adsp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ struct wm_adsp_compr_buf;
5757

5858
struct wm_adsp {
5959
const char *part;
60+
const char *name;
61+
const char *fwf_name;
6062
int rev;
6163
int num;
6264
int type;
63-
bool ao_dsp;
64-
const char *suffix;
6565
struct device *dev;
6666
struct regmap *regmap;
6767
struct snd_soc_codec *codec;
@@ -156,7 +156,7 @@ int wm_adsp2_codec_probe(struct wm_adsp *dsp, struct snd_soc_codec *codec);
156156
int wm_adsp2_codec_remove(struct wm_adsp *dsp, struct snd_soc_codec *codec);
157157
void wm_adsp_queue_boot_work(struct wm_adsp *dsp);
158158
int wm_vpu_setup_algs(struct wm_adsp *vpu);
159-
void wm_vpu_init(struct wm_adsp *vpu);
159+
int wm_vpu_init(struct wm_adsp *vpu);
160160
int wm_halo_init(struct wm_adsp *dsp, struct mutex *rate_lock);
161161
int wm_adsp1_event(struct snd_soc_dapm_widget *w,
162162
struct snd_kcontrol *kcontrol, int event);

0 commit comments

Comments
 (0)