Skip to content

Commit de66d53

Browse files
cladischJaroslav Kysela
authored andcommitted
[ALSA] sb16: add request_firmware()
Load the CSP programs using request_firmware(), if possible, instead of using the built-in firmware blobs. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
1 parent 219e281 commit de66d53

3 files changed

Lines changed: 68 additions & 8 deletions

File tree

‎include/sound/sb16_csp.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,21 @@ struct snd_sb_csp_info {
114114
#ifdef __KERNEL__
115115
#include "sb.h"
116116
#include "hwdep.h"
117+
#include <linux/firmware.h>
117118

118119
struct snd_sb_csp;
119120

121+
/* indices for the known CSP programs */
122+
enum {
123+
CSP_PROGRAM_MULAW,
124+
CSP_PROGRAM_ALAW,
125+
CSP_PROGRAM_ADPCM_INIT,
126+
CSP_PROGRAM_ADPCM_PLAYBACK,
127+
CSP_PROGRAM_ADPCM_CAPTURE,
128+
129+
CSP_PROGRAM_COUNT
130+
};
131+
120132
/*
121133
* CSP operators
122134
*/
@@ -159,6 +171,8 @@ struct snd_sb_csp {
159171
struct snd_kcontrol *qsound_space;
160172

161173
struct mutex access_mutex; /* locking */
174+
175+
const struct firmware *csp_programs[CSP_PROGRAM_COUNT];
162176
};
163177

164178
int snd_sb_csp_new(struct snd_sb *chip, int device, struct snd_hwdep ** rhwdep);

‎sound/isa/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ config SND_SBAWE
358358
config SND_SB16_CSP
359359
bool "Sound Blaster 16/AWE CSP support"
360360
depends on (SND_SB16 || SND_SBAWE) && (BROKEN || !PPC)
361+
select FW_LOADER
361362
help
362363
Say Y here to include support for the CSP core. This special
363364
coprocessor can do variable tasks like various compression and

‎sound/isa/sb/sb16_csp.c‎

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,13 @@ int snd_sb_csp_new(struct snd_sb *chip, int device, struct snd_hwdep ** rhwdep)
161161
*/
162162
static void snd_sb_csp_free(struct snd_hwdep *hwdep)
163163
{
164+
int i;
164165
struct snd_sb_csp *p = hwdep->private_data;
165166
if (p) {
166167
if (p->running & SNDRV_SB_CSP_ST_RUNNING)
167168
snd_sb_csp_stop(p);
169+
for (i = 0; i < ARRAY_SIZE(p->csp_programs); ++i)
170+
release_firmware(p->csp_programs[i]);
168171
kfree(p);
169172
}
170173
}
@@ -687,8 +690,50 @@ static int snd_sb_csp_load_user(struct snd_sb_csp * p, const unsigned char __use
687690
return err;
688691
}
689692

693+
#define FIRMWARE_IN_THE_KERNEL
694+
695+
#ifdef FIRMWARE_IN_THE_KERNEL
690696
#include "sb16_csp_codecs.h"
691697

698+
static const struct firmware snd_sb_csp_static_programs[] = {
699+
{ .data = mulaw_main, .size = sizeof mulaw_main },
700+
{ .data = alaw_main, .size = sizeof alaw_main },
701+
{ .data = ima_adpcm_init, .size = sizeof ima_adpcm_init },
702+
{ .data = ima_adpcm_playback, .size = sizeof ima_adpcm_playback },
703+
{ .data = ima_adpcm_capture, .size = sizeof ima_adpcm_capture },
704+
};
705+
#endif
706+
707+
static int snd_sb_csp_firmware_load(struct snd_sb_csp *p, int index, int flags)
708+
{
709+
static const char *const names[] = {
710+
"sb16/mulaw_main.csp",
711+
"sb16/alaw_main.csp",
712+
"sb16/ima_adpcm_init.csp",
713+
"sb16/ima_adpcm_playback.csp",
714+
"sb16/ima_adpcm_capture.csp",
715+
};
716+
const struct firmware *program;
717+
int err;
718+
719+
BUILD_BUG_ON(ARRAY_SIZE(names) != CSP_PROGRAM_COUNT);
720+
program = p->csp_programs[index];
721+
if (!program) {
722+
err = request_firmware(&program, names[index],
723+
p->chip->card->dev);
724+
if (err >= 0)
725+
p->csp_programs[index] = program;
726+
else {
727+
#ifdef FIRMWARE_IN_THE_KERNEL
728+
program = &snd_sb_csp_static_programs[index];
729+
#else
730+
return err;
731+
#endif
732+
}
733+
}
734+
return snd_sb_csp_load(p, program->data, program->size, flags);
735+
}
736+
692737
/*
693738
* autoload hardware codec if necessary
694739
* return 0 if CSP is loaded and ready to run (p->running != 0)
@@ -708,27 +753,27 @@ static int snd_sb_csp_autoload(struct snd_sb_csp * p, int pcm_sfmt, int play_rec
708753
} else {
709754
switch (pcm_sfmt) {
710755
case SNDRV_PCM_FORMAT_MU_LAW:
711-
err = snd_sb_csp_load(p, &mulaw_main[0], sizeof(mulaw_main), 0);
756+
err = snd_sb_csp_firmware_load(p, CSP_PROGRAM_MULAW, 0);
712757
p->acc_format = SNDRV_PCM_FMTBIT_MU_LAW;
713758
p->mode = SNDRV_SB_CSP_MODE_DSP_READ | SNDRV_SB_CSP_MODE_DSP_WRITE;
714759
break;
715760
case SNDRV_PCM_FORMAT_A_LAW:
716-
err = snd_sb_csp_load(p, &alaw_main[0], sizeof(alaw_main), 0);
761+
err = snd_sb_csp_firmware_load(p, CSP_PROGRAM_ALAW, 0);
717762
p->acc_format = SNDRV_PCM_FMTBIT_A_LAW;
718763
p->mode = SNDRV_SB_CSP_MODE_DSP_READ | SNDRV_SB_CSP_MODE_DSP_WRITE;
719764
break;
720765
case SNDRV_PCM_FORMAT_IMA_ADPCM:
721-
err = snd_sb_csp_load(p, &ima_adpcm_init[0], sizeof(ima_adpcm_init),
722-
SNDRV_SB_CSP_LOAD_INITBLOCK);
766+
err = snd_sb_csp_firmware_load(p, CSP_PROGRAM_ADPCM_INIT,
767+
SNDRV_SB_CSP_LOAD_INITBLOCK);
723768
if (err)
724769
break;
725770
if (play_rec_mode == SNDRV_SB_CSP_MODE_DSP_WRITE) {
726-
err = snd_sb_csp_load(p, &ima_adpcm_playback[0],
727-
sizeof(ima_adpcm_playback), 0);
771+
err = snd_sb_csp_firmware_load
772+
(p, CSP_PROGRAM_ADPCM_PLAYBACK, 0);
728773
p->mode = SNDRV_SB_CSP_MODE_DSP_WRITE;
729774
} else {
730-
err = snd_sb_csp_load(p, &ima_adpcm_capture[0],
731-
sizeof(ima_adpcm_capture), 0);
775+
err = snd_sb_csp_firmware_load
776+
(p, CSP_PROGRAM_ADPCM_CAPTURE, 0);
732777
p->mode = SNDRV_SB_CSP_MODE_DSP_READ;
733778
}
734779
p->acc_format = SNDRV_PCM_FMTBIT_IMA_ADPCM;

0 commit comments

Comments
 (0)