aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2008-05-29 07:40:00 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2008-07-10 09:26:40 -0400
commitb82a82d0a90af74847ae3e873a241dedf3786fd5 (patch)
treee00019c018a1a5790d4a31a4c5ef4e41501bbf0d
parentfa6e1cb66e2f9d2d4703e7bd7dd50839bb10e4c3 (diff)
ymfpci: treat firmware data as const
Standardise both in-kernel and loaded firmware to be stored as little-endian instead of host-endian. Signed-off-by: David Woodhouse <dwmw2@infradead.org>
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index 29b3056c5109..6298b29c66bb 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -26,6 +26,7 @@
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/vmalloc.h> 28#include <linux/vmalloc.h>
29#include <linux/mutex.h>
29 30
30#include <sound/core.h> 31#include <sound/core.h>
31#include <sound/control.h> 32#include <sound/control.h>
@@ -2009,11 +2010,34 @@ static struct firmware snd_ymfpci_controller_1e_microcode = {
2009 .size = YDSXG_CTRLLENGTH, 2010 .size = YDSXG_CTRLLENGTH,
2010 .data = (u8 *)CntrlInst1E, 2011 .data = (u8 *)CntrlInst1E,
2011}; 2012};
2013
2014#ifdef __BIG_ENDIAN
2015static int microcode_swapped;
2016static DEFINE_MUTEX(microcode_swap);
2017
2018static void snd_ymfpci_convert_to_le(const struct firmware *fw)
2019{
2020 int i;
2021 u32 *data = (u32 *)fw->data;
2022
2023 for (i = 0; i < fw->size / 4; ++i)
2024 cpu_to_le32s(&data[i]);
2025}
2012#endif 2026#endif
2013 2027
2014#ifdef CONFIG_SND_YMFPCI_FIRMWARE_IN_KERNEL
2015static int snd_ymfpci_request_firmware(struct snd_ymfpci *chip) 2028static int snd_ymfpci_request_firmware(struct snd_ymfpci *chip)
2016{ 2029{
2030#ifdef __BIG_ENDIAN
2031 mutex_lock(&microcode_swap);
2032 if (!microcode_swapped) {
2033 snd_ymfpci_convert_to_le(&snd_ymfpci_dsp_microcode);
2034 snd_ymfpci_convert_to_le(&snd_ymfpci_controller_1e_microcode);
2035 snd_ymfpci_convert_to_le(&snd_ymfpci_controller_microcode);
2036 microcode_swapped = 1;
2037 }
2038 mutex_unlock(&microcode_swap);
2039#endif
2040
2017 chip->dsp_microcode = &snd_ymfpci_dsp_microcode; 2041 chip->dsp_microcode = &snd_ymfpci_dsp_microcode;
2018 if (chip->device_id == PCI_DEVICE_ID_YAMAHA_724F || 2042 if (chip->device_id == PCI_DEVICE_ID_YAMAHA_724F ||
2019 chip->device_id == PCI_DEVICE_ID_YAMAHA_740C || 2043 chip->device_id == PCI_DEVICE_ID_YAMAHA_740C ||
@@ -2029,19 +2053,6 @@ static int snd_ymfpci_request_firmware(struct snd_ymfpci *chip)
2029 2053
2030#else /* use fw_loader */ 2054#else /* use fw_loader */
2031 2055
2032#ifdef __LITTLE_ENDIAN
2033static inline void snd_ymfpci_convert_from_le(const struct firmware *fw) { }
2034#else
2035static void snd_ymfpci_convert_from_le(const struct firmware *fw)
2036{
2037 int i;
2038 u32 *data = (u32 *)fw->data;
2039
2040 for (i = 0; i < fw->size / 4; ++i)
2041 le32_to_cpus(&data[i]);
2042}
2043#endif
2044
2045static int snd_ymfpci_request_firmware(struct snd_ymfpci *chip) 2056static int snd_ymfpci_request_firmware(struct snd_ymfpci *chip)
2046{ 2057{
2047 int err, is_1e; 2058 int err, is_1e;
@@ -2050,9 +2061,7 @@ static int snd_ymfpci_request_firmware(struct snd_ymfpci *chip)
2050 err = request_firmware(&chip->dsp_microcode, "yamaha/ds1_dsp.fw", 2061 err = request_firmware(&chip->dsp_microcode, "yamaha/ds1_dsp.fw",
2051 &chip->pci->dev); 2062 &chip->pci->dev);
2052 if (err >= 0) { 2063 if (err >= 0) {
2053 if (chip->dsp_microcode->size == YDSXG_DSPLENGTH) 2064 if (chip->dsp_microcode->size != YDSXG_DSPLENGTH) {
2054 snd_ymfpci_convert_from_le(chip->dsp_microcode);
2055 else {
2056 snd_printk(KERN_ERR "DSP microcode has wrong size\n"); 2065 snd_printk(KERN_ERR "DSP microcode has wrong size\n");
2057 err = -EINVAL; 2066 err = -EINVAL;
2058 } 2067 }
@@ -2067,9 +2076,7 @@ static int snd_ymfpci_request_firmware(struct snd_ymfpci *chip)
2067 err = request_firmware(&chip->controller_microcode, name, 2076 err = request_firmware(&chip->controller_microcode, name,
2068 &chip->pci->dev); 2077 &chip->pci->dev);
2069 if (err >= 0) { 2078 if (err >= 0) {
2070 if (chip->controller_microcode->size == YDSXG_CTRLLENGTH) 2079 if (chip->controller_microcode->size != YDSXG_CTRLLENGTH) {
2071 snd_ymfpci_convert_from_le(chip->controller_microcode);
2072 else {
2073 snd_printk(KERN_ERR "controller microcode" 2080 snd_printk(KERN_ERR "controller microcode"
2074 " has wrong size\n"); 2081 " has wrong size\n");
2075 err = -EINVAL; 2082 err = -EINVAL;
@@ -2090,7 +2097,7 @@ static void snd_ymfpci_download_image(struct snd_ymfpci *chip)
2090{ 2097{
2091 int i; 2098 int i;
2092 u16 ctrl; 2099 u16 ctrl;
2093 u32 *inst; 2100 const __le32 *inst;
2094 2101
2095 snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0x00000000); 2102 snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0x00000000);
2096 snd_ymfpci_disable_dsp(chip); 2103 snd_ymfpci_disable_dsp(chip);
@@ -2105,14 +2112,16 @@ static void snd_ymfpci_download_image(struct snd_ymfpci *chip)
2105 snd_ymfpci_writew(chip, YDSXGR_GLOBALCTRL, ctrl & ~0x0007); 2112 snd_ymfpci_writew(chip, YDSXGR_GLOBALCTRL, ctrl & ~0x0007);
2106 2113
2107 /* setup DSP instruction code */ 2114 /* setup DSP instruction code */
2108 inst = (u32 *)chip->dsp_microcode->data; 2115 inst = (const __le32 *)chip->dsp_microcode->data;
2109 for (i = 0; i < YDSXG_DSPLENGTH / 4; i++) 2116 for (i = 0; i < YDSXG_DSPLENGTH / 4; i++)
2110 snd_ymfpci_writel(chip, YDSXGR_DSPINSTRAM + (i << 2), inst[i]); 2117 snd_ymfpci_writel(chip, YDSXGR_DSPINSTRAM + (i << 2),
2118 le32_to_cpu(inst[i]));
2111 2119
2112 /* setup control instruction code */ 2120 /* setup control instruction code */
2113 inst = (u32 *)chip->controller_microcode->data; 2121 inst = (const __le32 *)chip->controller_microcode->data;
2114 for (i = 0; i < YDSXG_CTRLLENGTH / 4; i++) 2122 for (i = 0; i < YDSXG_CTRLLENGTH / 4; i++)
2115 snd_ymfpci_writel(chip, YDSXGR_CTRLINSTRAM + (i << 2), inst[i]); 2123 snd_ymfpci_writel(chip, YDSXGR_CTRLINSTRAM + (i << 2),
2124 le32_to_cpu(inst[i]));
2116 2125
2117 snd_ymfpci_enable_dsp(chip); 2126 snd_ymfpci_enable_dsp(chip);
2118} 2127}