Skip to content

Commit

Permalink
ALSA: Echoaudio - Add firmware cache #1
Browse files Browse the repository at this point in the history
Changes the way the firmware is passed through functions.

When CONFIG_PM is enabled the firmware cannot be released because the
driver will need it again to resume the card. 
With this patch the firmware is passed as an index of the struct
firmware card_fw[] in place of a pointer. That same index is then used
to locate the firmware in the firmware cache.

Signed-off-by: Giuliano Pochini <pochini@shiny.it>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Giuliano Pochini authored and Takashi Iwai committed Feb 15, 2010
1 parent a540e13 commit 19b5006
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 65 deletions.
2 changes: 1 addition & 1 deletion sound/pci/echoaudio/darla20_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
chip->device_id = device_id;
chip->subdevice_id = subdevice_id;
chip->bad_board = TRUE;
chip->dsp_code_to_load = &card_fw[FW_DARLA20_DSP];
chip->dsp_code_to_load = FW_DARLA20_DSP;
chip->spdif_status = GD_SPDIF_STATUS_UNDEF;
chip->clock_state = GD_CLOCK_UNDEF;
/* Since this card has no ASIC, mark it as loaded so everything
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/echoaudio/darla24_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
chip->device_id = device_id;
chip->subdevice_id = subdevice_id;
chip->bad_board = TRUE;
chip->dsp_code_to_load = &card_fw[FW_DARLA24_DSP];
chip->dsp_code_to_load = FW_DARLA24_DSP;
/* Since this card has no ASIC, mark it as loaded so everything
works OK */
chip->asic_loaded = TRUE;
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/echoaudio/echo3g_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
chip->subdevice_id = subdevice_id;
chip->bad_board = TRUE;
chip->has_midi = TRUE;
chip->dsp_code_to_load = &card_fw[FW_ECHO3G_DSP];
chip->dsp_code_to_load = FW_ECHO3G_DSP;

/* Load the DSP code and the ASIC on the PCI card and get
what type of external box is attached */
Expand Down
8 changes: 7 additions & 1 deletion sound/pci/echoaudio/echoaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,24 @@ MODULE_PARM_DESC(enable, "Enable " ECHOCARD_NAME " soundcard.");
static unsigned int channels_list[10] = {1, 2, 4, 6, 8, 10, 12, 14, 16, 999999};
static const DECLARE_TLV_DB_SCALE(db_scale_output_gain, -12800, 100, 1);



static int get_firmware(const struct firmware **fw_entry,
const struct firmware *frm, struct echoaudio *chip)
struct echoaudio *chip, const short fw_index)
{
int err;
char name[30];
const struct firmware *frm = &card_fw[fw_index];

DE_ACT(("firmware requested: %s\n", frm->data));
snprintf(name, sizeof(name), "ea/%s", frm->data);
if ((err = request_firmware(fw_entry, name, pci_device(chip))) < 0)
snd_printk(KERN_ERR "get_firmware(): Firmware not available (%d)\n", err);
return err;
}



static void free_firmware(const struct firmware *fw_entry)
{
release_firmware(fw_entry);
Expand Down
6 changes: 3 additions & 3 deletions sound/pci/echoaudio/echoaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ struct echoaudio {
u16 device_id, subdevice_id;
u16 *dsp_code; /* Current DSP code loaded,
* NULL if nothing loaded */
const struct firmware *dsp_code_to_load;/* DSP code to load */
const struct firmware *asic_code; /* Current ASIC code */
short dsp_code_to_load; /* DSP code to load */
short asic_code; /* Current ASIC code */
u32 comm_page_phys; /* Physical address of the
* memory seen by DSP */
volatile u32 __iomem *dsp_registers; /* DSP's register base */
Expand All @@ -464,7 +464,7 @@ static int load_firmware(struct echoaudio *chip);
static int wait_handshake(struct echoaudio *chip);
static int send_vector(struct echoaudio *chip, u32 command);
static int get_firmware(const struct firmware **fw_entry,
const struct firmware *frm, struct echoaudio *chip);
struct echoaudio *chip, const short fw_index);
static void free_firmware(const struct firmware *fw_entry);

#ifdef ECHOCARD_HAS_MIDI
Expand Down
5 changes: 2 additions & 3 deletions sound/pci/echoaudio/echoaudio_3g.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,11 @@ static int load_asic(struct echoaudio *chip)
/* Give the DSP a few milliseconds to settle down */
mdelay(2);

err = load_asic_generic(chip, DSP_FNC_LOAD_3G_ASIC,
&card_fw[FW_3G_ASIC]);
err = load_asic_generic(chip, DSP_FNC_LOAD_3G_ASIC, FW_3G_ASIC);
if (err < 0)
return err;

chip->asic_code = &card_fw[FW_3G_ASIC];
chip->asic_code = FW_3G_ASIC;

/* Now give the new ASIC some time to set up */
msleep(1000);
Expand Down
12 changes: 7 additions & 5 deletions sound/pci/echoaudio/echoaudio_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ static inline int check_asic_status(struct echoaudio *chip)
#ifdef ECHOCARD_HAS_ASIC

/* Load ASIC code - done after the DSP is loaded */
static int load_asic_generic(struct echoaudio *chip, u32 cmd,
const struct firmware *asic)
static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic)
{
const struct firmware *fw;
int err;
u32 i, size;
u8 *code;

if ((err = get_firmware(&fw, asic, chip)) < 0) {
err = get_firmware(&fw, chip, asic);
if (err < 0) {
snd_printk(KERN_WARNING "Firmware not found !\n");
return err;
}
Expand Down Expand Up @@ -245,7 +245,8 @@ static int install_resident_loader(struct echoaudio *chip)
return 0;
}

if ((i = get_firmware(&fw, &card_fw[FW_361_LOADER], chip)) < 0) {
i = get_firmware(&fw, chip, FW_361_LOADER);
if (i < 0) {
snd_printk(KERN_WARNING "Firmware not found !\n");
return i;
}
Expand Down Expand Up @@ -485,7 +486,8 @@ static int load_firmware(struct echoaudio *chip)
chip->dsp_code = NULL;
}

if ((err = get_firmware(&fw, chip->dsp_code_to_load, chip)) < 0)
err = get_firmware(&fw, chip, chip->dsp_code_to_load);
if (err < 0)
return err;
err = load_dsp(chip, (u16 *)fw->data);
free_firmware(fw);
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/echoaudio/gina20_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
chip->device_id = device_id;
chip->subdevice_id = subdevice_id;
chip->bad_board = TRUE;
chip->dsp_code_to_load = &card_fw[FW_GINA20_DSP];
chip->dsp_code_to_load = FW_GINA20_DSP;
chip->spdif_status = GD_SPDIF_STATUS_UNDEF;
chip->clock_state = GD_CLOCK_UNDEF;
/* Since this card has no ASIC, mark it as loaded so everything
Expand Down
18 changes: 9 additions & 9 deletions sound/pci/echoaudio/gina24_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ static int write_control_reg(struct echoaudio *chip, u32 value, char force);
static int set_input_clock(struct echoaudio *chip, u16 clock);
static int set_professional_spdif(struct echoaudio *chip, char prof);
static int set_digital_mode(struct echoaudio *chip, u8 mode);
static int load_asic_generic(struct echoaudio *chip, u32 cmd,
const struct firmware *asic);
static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic);
static int check_asic_status(struct echoaudio *chip);


Expand Down Expand Up @@ -64,13 +63,13 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)

/* Gina24 comes in both '301 and '361 flavors */
if (chip->device_id == DEVICE_ID_56361) {
chip->dsp_code_to_load = &card_fw[FW_GINA24_361_DSP];
chip->dsp_code_to_load = FW_GINA24_361_DSP;
chip->digital_modes =
ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA |
ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL |
ECHOCAPS_HAS_DIGITAL_MODE_ADAT;
} else {
chip->dsp_code_to_load = &card_fw[FW_GINA24_301_DSP];
chip->dsp_code_to_load = FW_GINA24_301_DSP;
chip->digital_modes =
ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA |
ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL |
Expand Down Expand Up @@ -125,7 +124,7 @@ static int load_asic(struct echoaudio *chip)
{
u32 control_reg;
int err;
const struct firmware *fw;
short asic;

if (chip->asic_loaded)
return 1;
Expand All @@ -135,14 +134,15 @@ static int load_asic(struct echoaudio *chip)

/* Pick the correct ASIC for '301 or '361 Gina24 */
if (chip->device_id == DEVICE_ID_56361)
fw = &card_fw[FW_GINA24_361_ASIC];
asic = FW_GINA24_361_ASIC;
else
fw = &card_fw[FW_GINA24_301_ASIC];
asic = FW_GINA24_301_ASIC;

if ((err = load_asic_generic(chip, DSP_FNC_LOAD_GINA24_ASIC, fw)) < 0)
err = load_asic_generic(chip, DSP_FNC_LOAD_GINA24_ASIC, asic);
if (err < 0)
return err;

chip->asic_code = fw;
chip->asic_code = asic;

/* Now give the new ASIC a little time to set up */
mdelay(10);
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/echoaudio/indigo_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
chip->device_id = device_id;
chip->subdevice_id = subdevice_id;
chip->bad_board = TRUE;
chip->dsp_code_to_load = &card_fw[FW_INDIGO_DSP];
chip->dsp_code_to_load = FW_INDIGO_DSP;
/* Since this card has no ASIC, mark it as loaded so everything
works OK */
chip->asic_loaded = TRUE;
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/echoaudio/indigodj_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
chip->device_id = device_id;
chip->subdevice_id = subdevice_id;
chip->bad_board = TRUE;
chip->dsp_code_to_load = &card_fw[FW_INDIGO_DJ_DSP];
chip->dsp_code_to_load = FW_INDIGO_DJ_DSP;
/* Since this card has no ASIC, mark it as loaded so everything
works OK */
chip->asic_loaded = TRUE;
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/echoaudio/indigodjx_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
chip->device_id = device_id;
chip->subdevice_id = subdevice_id;
chip->bad_board = TRUE;
chip->dsp_code_to_load = &card_fw[FW_INDIGO_DJX_DSP];
chip->dsp_code_to_load = FW_INDIGO_DJX_DSP;
/* Since this card has no ASIC, mark it as loaded so everything
works OK */
chip->asic_loaded = TRUE;
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/echoaudio/indigoio_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
chip->device_id = device_id;
chip->subdevice_id = subdevice_id;
chip->bad_board = TRUE;
chip->dsp_code_to_load = &card_fw[FW_INDIGO_IO_DSP];
chip->dsp_code_to_load = FW_INDIGO_IO_DSP;
/* Since this card has no ASIC, mark it as loaded so everything
works OK */
chip->asic_loaded = TRUE;
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/echoaudio/indigoiox_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
chip->device_id = device_id;
chip->subdevice_id = subdevice_id;
chip->bad_board = TRUE;
chip->dsp_code_to_load = &card_fw[FW_INDIGO_IOX_DSP];
chip->dsp_code_to_load = FW_INDIGO_IOX_DSP;
/* Since this card has no ASIC, mark it as loaded so everything
works OK */
chip->asic_loaded = TRUE;
Expand Down
7 changes: 3 additions & 4 deletions sound/pci/echoaudio/layla20_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@

static int read_dsp(struct echoaudio *chip, u32 *data);
static int set_professional_spdif(struct echoaudio *chip, char prof);
static int load_asic_generic(struct echoaudio *chip, u32 cmd,
const struct firmware *asic);
static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic);
static int check_asic_status(struct echoaudio *chip);
static int update_flags(struct echoaudio *chip);

Expand All @@ -54,7 +53,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
chip->subdevice_id = subdevice_id;
chip->bad_board = TRUE;
chip->has_midi = TRUE;
chip->dsp_code_to_load = &card_fw[FW_LAYLA20_DSP];
chip->dsp_code_to_load = FW_LAYLA20_DSP;
chip->input_clock_types =
ECHO_CLOCK_BIT_INTERNAL | ECHO_CLOCK_BIT_SPDIF |
ECHO_CLOCK_BIT_WORD | ECHO_CLOCK_BIT_SUPER;
Expand Down Expand Up @@ -144,7 +143,7 @@ static int load_asic(struct echoaudio *chip)
return 0;

err = load_asic_generic(chip, DSP_FNC_LOAD_LAYLA_ASIC,
&card_fw[FW_LAYLA20_ASIC]);
FW_LAYLA20_ASIC);
if (err < 0)
return err;

Expand Down
19 changes: 9 additions & 10 deletions sound/pci/echoaudio/layla24_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ static int write_control_reg(struct echoaudio *chip, u32 value, char force);
static int set_input_clock(struct echoaudio *chip, u16 clock);
static int set_professional_spdif(struct echoaudio *chip, char prof);
static int set_digital_mode(struct echoaudio *chip, u8 mode);
static int load_asic_generic(struct echoaudio *chip, u32 cmd,
const struct firmware *asic);
static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic);
static int check_asic_status(struct echoaudio *chip);


Expand All @@ -54,7 +53,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
chip->subdevice_id = subdevice_id;
chip->bad_board = TRUE;
chip->has_midi = TRUE;
chip->dsp_code_to_load = &card_fw[FW_LAYLA24_DSP];
chip->dsp_code_to_load = FW_LAYLA24_DSP;
chip->input_clock_types =
ECHO_CLOCK_BIT_INTERNAL | ECHO_CLOCK_BIT_SPDIF |
ECHO_CLOCK_BIT_WORD | ECHO_CLOCK_BIT_ADAT;
Expand Down Expand Up @@ -123,18 +122,18 @@ static int load_asic(struct echoaudio *chip)

/* Load the ASIC for the PCI card */
err = load_asic_generic(chip, DSP_FNC_LOAD_LAYLA24_PCI_CARD_ASIC,
&card_fw[FW_LAYLA24_1_ASIC]);
FW_LAYLA24_1_ASIC);
if (err < 0)
return err;

chip->asic_code = &card_fw[FW_LAYLA24_2S_ASIC];
chip->asic_code = FW_LAYLA24_2S_ASIC;

/* Now give the new ASIC a little time to set up */
mdelay(10);

/* Do the external one */
err = load_asic_generic(chip, DSP_FNC_LOAD_LAYLA24_EXTERNAL_ASIC,
&card_fw[FW_LAYLA24_2S_ASIC]);
FW_LAYLA24_2S_ASIC);
if (err < 0)
return FALSE;

Expand Down Expand Up @@ -299,7 +298,7 @@ static int set_input_clock(struct echoaudio *chip, u16 clock)
/* Depending on what digital mode you want, Layla24 needs different ASICs
loaded. This function checks the ASIC needed for the new mode and sees
if it matches the one already loaded. */
static int switch_asic(struct echoaudio *chip, const struct firmware *asic)
static int switch_asic(struct echoaudio *chip, short asic)
{
s8 *monitors;

Expand Down Expand Up @@ -335,7 +334,7 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
{
u32 control_reg;
int err, incompatible_clock;
const struct firmware *asic;
short asic;

/* Set clock to "internal" if it's not compatible with the new mode */
incompatible_clock = FALSE;
Expand All @@ -344,12 +343,12 @@ static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
case DIGITAL_MODE_SPDIF_RCA:
if (chip->input_clock == ECHO_CLOCK_ADAT)
incompatible_clock = TRUE;
asic = &card_fw[FW_LAYLA24_2S_ASIC];
asic = FW_LAYLA24_2S_ASIC;
break;
case DIGITAL_MODE_ADAT:
if (chip->input_clock == ECHO_CLOCK_SPDIF)
incompatible_clock = TRUE;
asic = &card_fw[FW_LAYLA24_2A_ASIC];
asic = FW_LAYLA24_2A_ASIC;
break;
default:
DE_ACT(("Digital mode not supported: %d\n", mode));
Expand Down
2 changes: 1 addition & 1 deletion sound/pci/echoaudio/mia_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
chip->device_id = device_id;
chip->subdevice_id = subdevice_id;
chip->bad_board = TRUE;
chip->dsp_code_to_load = &card_fw[FW_MIA_DSP];
chip->dsp_code_to_load = FW_MIA_DSP;
/* Since this card has no ASIC, mark it as loaded so everything
works OK */
chip->asic_loaded = TRUE;
Expand Down
Loading

0 comments on commit 19b5006

Please sign in to comment.