Skip to content

Commit

Permalink
maestro3: treat firmware data as const
Browse files Browse the repository at this point in the history
The maestro3 driver is byte-swapping its firmware to be host-endian in
advance, when it doesn't seem to be necessary -- we could just use
le16_to_cpu() as we load it.

Doing that means that we need to switch the in-tree firmware to be
little-endian too.

Take the least intrusive way of doing this, which is to switch the
existing snd_m3_convert_from_le() function to convert _to_ little-endian
instead, and use it on the in-tree firmware instead of the loaded
firmware. It's a bit suboptimal but doesn't matter much right now
because we're about to remove the special cases for the in-tree version
anyway.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jul 10, 2008
1 parent c63e87e commit fa6e1cb
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions sound/pci/maestro3.c
Original file line number Diff line number Diff line change
Expand Up @@ -2240,18 +2240,16 @@ static const struct firmware assp_minisrc = {
.size = sizeof assp_minisrc_image
};

#else /* CONFIG_SND_MAESTRO3_FIRMWARE_IN_KERNEL */

#ifdef __LITTLE_ENDIAN
static inline void snd_m3_convert_from_le(const struct firmware *fw) { }
static inline void snd_m3_convert_to_le(const struct firmware *fw) { }
#else
static void snd_m3_convert_from_le(const struct firmware *fw)
static void snd_m3_convert_to_le(const struct firmware *fw)
{
int i;
u16 *data = (u16 *)fw->data;

for (i = 0; i < fw->size / 2; ++i)
le16_to_cpus(&data[i]);
cpu_to_le16s(&data[i]);
}
#endif

Expand All @@ -2271,7 +2269,7 @@ static const u16 minisrc_lpf[MINISRC_LPF_LEN] = {
static void snd_m3_assp_init(struct snd_m3 *chip)
{
unsigned int i;
u16 *data;
const u16 *data;

/* zero kernel data */
for (i = 0; i < (REV_B_DATA_MEMORY_UNIT_LENGTH * NUM_UNITS_KERNEL_DATA) / 2; i++)
Expand All @@ -2289,10 +2287,11 @@ static void snd_m3_assp_init(struct snd_m3 *chip)
KDATA_DMA_XFER0);

/* write kernel into code memory.. */
data = (u16 *)chip->assp_kernel_image->data;
data = (const u16 *)chip->assp_kernel_image->data;
for (i = 0 ; i * 2 < chip->assp_kernel_image->size; i++) {
snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE,
REV_B_CODE_MEMORY_BEGIN + i, data[i]);
REV_B_CODE_MEMORY_BEGIN + i,
le16_to_cpu(data[i]));
}

/*
Expand All @@ -2301,10 +2300,10 @@ static void snd_m3_assp_init(struct snd_m3 *chip)
* drop it there. It seems that the minisrc doesn't
* need vectors, so we won't bother with them..
*/
data = (u16 *)chip->assp_minisrc_image->data;
data = (const u16 *)chip->assp_minisrc_image->data;
for (i = 0; i * 2 < chip->assp_minisrc_image->size; i++) {
snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE,
0x400 + i, data[i]);
0x400 + i, le16_to_cpu(data[i]));
}

/*
Expand Down Expand Up @@ -2749,8 +2748,7 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
if (err < 0) {
snd_m3_free(chip);
return err;
} else
snd_m3_convert_from_le(chip->assp_kernel_image);
}
#endif

#ifdef CONFIG_SND_MAESTRO3_FIRMWARE_IN_KERNEL
Expand All @@ -2761,8 +2759,7 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
if (err < 0) {
snd_m3_free(chip);
return err;
} else
snd_m3_convert_from_le(chip->assp_minisrc_image);
}
#endif

if ((err = pci_request_regions(pci, card->driver)) < 0) {
Expand Down Expand Up @@ -2915,6 +2912,10 @@ static struct pci_driver driver = {

static int __init alsa_card_m3_init(void)
{
#ifdef CONFIG_SND_MAESTRO3_FIRMWARE_IN_KERNEL
snd_m3_convert_to_le(&assp_kernel);
snd_m3_convert_to_le(&assp_minisrc);
#endif
return pci_register_driver(&driver);
}

Expand Down

0 comments on commit fa6e1cb

Please sign in to comment.