Commit 27d202ff authored by David Woodhouse's avatar David Woodhouse Committed by David Woodhouse

firmware: convert Ambassador ATM driver to request_firmware()

Since it had various regions to be loaded to separate addresses, and it
wanted to do them in fairly small chunks anyway, switch it to use the
new ihex code. Encode the start address in the first record.
Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
Acked-by: default avatarChas Williams <chas@cmf.nrl.navy.mil>
parent ec6752f5
...@@ -6,9 +6,9 @@ fore_200e-objs := fore200e.o ...@@ -6,9 +6,9 @@ fore_200e-objs := fore200e.o
hostprogs-y := fore200e_mkfirm hostprogs-y := fore200e_mkfirm
# Files generated that shall be removed upon make clean # Files generated that shall be removed upon make clean
clean-files := atmsar11.bin atmsar11.bin1 atmsar11.bin2 pca200e.bin \ clean-files := pca200e.bin pca200e.bin1 pca200e.bin2 pca200e_ecd.bin \
pca200e.bin1 pca200e.bin2 pca200e_ecd.bin pca200e_ecd.bin1 \ pca200e_ecd.bin1 pca200e_ecd.bin2 sba200e_ecd.bin sba200e_ecd.bin1 \
pca200e_ecd.bin2 sba200e_ecd.bin sba200e_ecd.bin1 sba200e_ecd.bin2 sba200e_ecd.bin2
# Firmware generated that shall be removed upon make clean # Firmware generated that shall be removed upon make clean
clean-files += fore200e_pca_fw.c fore200e_sba_fw.c clean-files += fore200e_pca_fw.c fore200e_sba_fw.c
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include <linux/poison.h> #include <linux/poison.h>
#include <linux/bitrev.h> #include <linux/bitrev.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/firmware.h>
#include <linux/ihex.h>
#include <asm/atomic.h> #include <asm/atomic.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -290,29 +292,6 @@ static inline void __init show_version (void) { ...@@ -290,29 +292,6 @@ static inline void __init show_version (void) {
*/ */
/********** microcode **********/
#ifdef AMB_NEW_MICROCODE
#define UCODE(x) UCODE2(atmsar12.x)
#else
#define UCODE(x) UCODE2(atmsar11.x)
#endif
#define UCODE2(x) #x
static u32 __devinitdata ucode_start =
#include UCODE(start)
;
static region __devinitdata ucode_regions[] = {
#include UCODE(regions)
{ 0, 0 }
};
static u32 __devinitdata ucode_data[] = {
#include UCODE(data)
0xdeadbeef
};
static void do_housekeeping (unsigned long arg); static void do_housekeeping (unsigned long arg);
/********** globals **********/ /********** globals **********/
...@@ -1841,45 +1820,34 @@ static int __devinit get_loader_version (loader_block * lb, ...@@ -1841,45 +1820,34 @@ static int __devinit get_loader_version (loader_block * lb,
/* loader: write memory data blocks */ /* loader: write memory data blocks */
static int __devinit loader_write (loader_block * lb, static int __devinit loader_write (loader_block* lb,
const amb_dev * dev, const u32 * data, const amb_dev *dev,
u32 address, unsigned int count) { const struct ihex_binrec *rec) {
unsigned int i;
transfer_block * tb = &lb->payload.transfer; transfer_block * tb = &lb->payload.transfer;
PRINTD (DBG_FLOW|DBG_LOAD, "loader_write"); PRINTD (DBG_FLOW|DBG_LOAD, "loader_write");
if (count > MAX_TRANSFER_DATA) tb->address = rec->addr;
return -EINVAL; tb->count = cpu_to_be32(be16_to_cpu(rec->len) / 4);
tb->address = cpu_to_be32 (address); memcpy(tb->data, rec->data, be16_to_cpu(rec->len));
tb->count = cpu_to_be32 (count);
for (i = 0; i < count; ++i)
tb->data[i] = cpu_to_be32 (data[i]);
return do_loader_command (lb, dev, write_adapter_memory); return do_loader_command (lb, dev, write_adapter_memory);
} }
/* loader: verify memory data blocks */ /* loader: verify memory data blocks */
static int __devinit loader_verify (loader_block * lb, static int __devinit loader_verify (loader_block * lb,
const amb_dev * dev, const u32 * data, const amb_dev *dev,
u32 address, unsigned int count) { const struct ihex_binrec *rec) {
unsigned int i;
transfer_block * tb = &lb->payload.transfer; transfer_block * tb = &lb->payload.transfer;
int res; int res;
PRINTD (DBG_FLOW|DBG_LOAD, "loader_verify"); PRINTD (DBG_FLOW|DBG_LOAD, "loader_verify");
if (count > MAX_TRANSFER_DATA) tb->address = rec->addr;
return -EINVAL; tb->count = cpu_to_be32(be16_to_cpu(rec->len) / 4);
tb->address = cpu_to_be32 (address);
tb->count = cpu_to_be32 (count);
res = do_loader_command (lb, dev, read_adapter_memory); res = do_loader_command (lb, dev, read_adapter_memory);
if (!res) if (!res && memcmp(tb->data, rec->data, be16_to_cpu(rec->len)))
for (i = 0; i < count; ++i)
if (tb->data[i] != cpu_to_be32 (data[i])) {
res = -EINVAL; res = -EINVAL;
break;
}
return res; return res;
} }
...@@ -1962,47 +1930,53 @@ static int amb_reset (amb_dev * dev, int diags) { ...@@ -1962,47 +1930,53 @@ static int amb_reset (amb_dev * dev, int diags) {
/********** transfer and start the microcode **********/ /********** transfer and start the microcode **********/
static int __devinit ucode_init (loader_block * lb, amb_dev * dev) { static int __devinit ucode_init (loader_block * lb, amb_dev * dev) {
unsigned int i = 0; const struct firmware *fw;
unsigned int total = 0; unsigned long start_address;
const u32 * pointer = ucode_data; const struct ihex_binrec *rec;
u32 address;
unsigned int count;
int res; int res;
res = request_ihex_firmware(&fw, "atmsar11.fw", &dev->pci_dev->dev);
if (res) {
PRINTK (KERN_ERR, "Cannot load microcode data");
return res;
}
/* First record contains just the start address */
rec = (const struct ihex_binrec *)fw->data;
if (be16_to_cpu(rec->len) != sizeof(__be32) || be32_to_cpu(rec->addr)) {
PRINTK (KERN_ERR, "Bad microcode data (no start record)");
return -EINVAL;
}
start_address = be32_to_cpup((__be32 *)rec->data);
rec = ihex_next_binrec(rec);
PRINTD (DBG_FLOW|DBG_LOAD, "ucode_init"); PRINTD (DBG_FLOW|DBG_LOAD, "ucode_init");
while (address = ucode_regions[i].start, while (rec) {
count = ucode_regions[i].count) { PRINTD (DBG_LOAD, "starting region (%x, %u)", be32_to_cpu(rec->addr),
PRINTD (DBG_LOAD, "starting region (%x, %u)", address, count); be16_to_cpu(rec->len));
while (count) { if (be16_to_cpu(rec->len) > 4 * MAX_TRANSFER_DATA) {
unsigned int words; PRINTK (KERN_ERR, "Bad microcode data (record too long)");
if (count <= MAX_TRANSFER_DATA) return -EINVAL;
words = count;
else
words = MAX_TRANSFER_DATA;
total += words;
res = loader_write (lb, dev, pointer, address, words);
if (res)
return res;
res = loader_verify (lb, dev, pointer, address, words);
if (res)
return res;
count -= words;
address += sizeof(u32) * words;
pointer += words;
} }
i += 1; if (be16_to_cpu(rec->len) & 3) {
PRINTK (KERN_ERR, "Bad microcode data (odd number of bytes)");
return -EINVAL;
} }
if (*pointer == ATM_POISON) { res = loader_write(lb, dev, rec);
return loader_start (lb, dev, ucode_start); if (res)
} else { break;
// cast needed as there is no %? for pointer differnces
PRINTD (DBG_LOAD|DBG_ERR, res = loader_verify(lb, dev, rec);
"offset=%li, *pointer=%x, address=%x, total=%u", if (res)
(long) (pointer - ucode_data), *pointer, address, total); break;
PRINTK (KERN_ERR, "incorrect microcode data");
return -ENOMEM;
} }
release_firmware(fw);
if (!res)
res = loader_start(lb, dev, start_address);
return res;
} }
/********** give adapter parameters **********/ /********** give adapter parameters **********/
......
...@@ -656,17 +656,6 @@ typedef struct amb_dev amb_dev; ...@@ -656,17 +656,6 @@ typedef struct amb_dev amb_dev;
#define AMB_DEV(atm_dev) ((amb_dev *) (atm_dev)->dev_data) #define AMB_DEV(atm_dev) ((amb_dev *) (atm_dev)->dev_data)
#define AMB_VCC(atm_vcc) ((amb_vcc *) (atm_vcc)->dev_data) #define AMB_VCC(atm_vcc) ((amb_vcc *) (atm_vcc)->dev_data)
/* the microcode */
typedef struct {
u32 start;
unsigned int count;
} region;
static region ucode_regions[];
static u32 ucode_data[];
static u32 ucode_start;
/* rate rounding */ /* rate rounding */
typedef enum { typedef enum {
......
This diff is collapsed.
/*
See copyright and licensing conditions in ambassador.* files.
*/
{ 0x00000080, 993, },
{ 0xa0d0d500, 80, },
{ 0xa0d0f000, 978, },
/*
See copyright and licensing conditions in ambassador.* files.
*/
0xa0d0f000
...@@ -20,6 +20,7 @@ fw-external-y := $(subst ",,$(CONFIG_EXTRA_FIRMWARE)) ...@@ -20,6 +20,7 @@ fw-external-y := $(subst ",,$(CONFIG_EXTRA_FIRMWARE))
# accurate. In the latter case it doesn't matter -- it'll use $(fw-shipped-all). # accurate. In the latter case it doesn't matter -- it'll use $(fw-shipped-all).
# But be aware that the config file might not be included at all. # But be aware that the config file might not be included at all.
fw-shipped-$(CONFIG_ATM_AMBASSADOR) += atmsar11.fw
fw-shipped-$(CONFIG_DVB_TTUSB_BUDGET) += ttusb-budget/dspbootcode.bin fw-shipped-$(CONFIG_DVB_TTUSB_BUDGET) += ttusb-budget/dspbootcode.bin
fw-shipped-$(CONFIG_SMCTR) += tr_smctr.bin fw-shipped-$(CONFIG_SMCTR) += tr_smctr.bin
fw-shipped-$(CONFIG_SND_KORG1212) += korg/k1212.dsp fw-shipped-$(CONFIG_SND_KORG1212) += korg/k1212.dsp
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment