Commit 5292bcd3 authored by Jiri Slaby's avatar Jiri Slaby Committed by Linus Torvalds

Char: moxa, merge c2xx and c320 firmware loading

Signed-off-by: default avatarJiri Slaby <jirislaby@gmail.com>
Tested-by: default avatarOyvind Aabling <Oyvind.Aabling@uni-c.dk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 03718234
...@@ -368,92 +368,40 @@ static int moxa_load_320b(struct moxa_board_conf *brd, const u8 *ptr, ...@@ -368,92 +368,40 @@ static int moxa_load_320b(struct moxa_board_conf *brd, const u8 *ptr,
return 0; return 0;
} }
static int moxa_load_c218(struct moxa_board_conf *brd, const void *ptr, static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
size_t len) size_t len)
{ {
void __iomem *baseAddr = brd->basemem; void __iomem *baseAddr = brd->basemem;
const u16 *uptr = ptr; const u16 *uptr = ptr;
size_t wlen, len2, j; size_t wlen, len2, j;
unsigned int i, retry; unsigned long key, loadbuf, loadlen, checksum, checksum_ok;
unsigned int i, retry, c320;
u16 usum, keycode; u16 usum, keycode;
if (brd->boardType == MOXA_BOARD_CP204J) c320 = brd->boardType == MOXA_BOARD_C320_PCI ||
keycode = CP204J_KeyCode; brd->boardType == MOXA_BOARD_C320_ISA;
else keycode = (brd->boardType == MOXA_BOARD_CP204J) ? CP204J_KeyCode :
keycode = C218_KeyCode; C218_KeyCode;
usum = 0;
wlen = len >> 1;
for (i = 0; i < wlen; i++)
usum += le16_to_cpu(uptr[i]);
retry = 0;
do {
wlen = len >> 1;
j = 0;
while (wlen) {
len2 = (wlen > 2048) ? 2048 : wlen;
wlen -= len2;
memcpy_toio(baseAddr + C218_LoadBuf, ptr + j,
len2 << 1);
j += len2 << 1;
writew(len2, baseAddr + C218DLoad_len);
writew(0, baseAddr + C218_key);
for (i = 0; i < 100; i++) {
if (readw(baseAddr + C218_key) == keycode)
break;
msleep(10);
}
if (readw(baseAddr + C218_key) != keycode)
return -EIO;
}
writew(0, baseAddr + C218DLoad_len);
writew(usum, baseAddr + C218check_sum);
writew(0, baseAddr + C218_key);
for (i = 0; i < 100; i++) {
if (readw(baseAddr + C218_key) == keycode)
break;
msleep(10);
}
retry++;
} while ((readb(baseAddr + C218chksum_ok) != 1) && (retry < 3));
if (readb(baseAddr + C218chksum_ok) != 1)
return -EIO;
writew(0, baseAddr + C218_key); switch (brd->boardType) {
for (i = 0; i < 100; i++) { case MOXA_BOARD_CP204J:
if (readw(baseAddr + Magic_no) == Magic_code) case MOXA_BOARD_C218_ISA:
case MOXA_BOARD_C218_PCI:
key = C218_key;
loadbuf = C218_LoadBuf;
loadlen = C218DLoad_len;
checksum = C218check_sum;
checksum_ok = C218chksum_ok;
break; break;
msleep(10); default:
} key = C320_key;
if (readw(baseAddr + Magic_no) != Magic_code) keycode = C320_KeyCode;
return -EIO; loadbuf = C320_LoadBuf;
loadlen = C320DLoad_len;
writew(1, baseAddr + Disable_IRQ); checksum = C320check_sum;
writew(0, baseAddr + Magic_no); checksum_ok = C320chksum_ok;
for (i = 0; i < 100; i++) {
if (readw(baseAddr + Magic_no) == Magic_code)
break; break;
msleep(10);
} }
if (readw(baseAddr + Magic_no) != Magic_code)
return -EIO;
moxaCard = 1;
brd->intNdx = baseAddr + IRQindex;
brd->intPend = baseAddr + IRQpending;
brd->intTable = baseAddr + IRQtable;
return 0;
}
static int moxa_load_c320(struct moxa_board_conf *brd, const void *ptr,
size_t len)
{
void __iomem *baseAddr = brd->basemem;
const u16 *uptr = ptr;
size_t wlen, len2, j;
unsigned int i, retry;
u16 usum;
usum = 0; usum = 0;
wlen = len >> 1; wlen = len >> 1;
...@@ -466,33 +414,33 @@ static int moxa_load_c320(struct moxa_board_conf *brd, const void *ptr, ...@@ -466,33 +414,33 @@ static int moxa_load_c320(struct moxa_board_conf *brd, const void *ptr,
while (wlen) { while (wlen) {
len2 = (wlen > 2048) ? 2048 : wlen; len2 = (wlen > 2048) ? 2048 : wlen;
wlen -= len2; wlen -= len2;
memcpy_toio(baseAddr + C320_LoadBuf, ptr + j, memcpy_toio(baseAddr + loadbuf, ptr + j, len2 << 1);
len2 << 1);
j += len2 << 1; j += len2 << 1;
writew(len2, baseAddr + C320DLoad_len);
writew(0, baseAddr + C320_key); writew(len2, baseAddr + loadlen);
for (i = 0; i < 10; i++) { writew(0, baseAddr + key);
if (readw(baseAddr + C320_key) == C320_KeyCode) for (i = 0; i < 100; i++) {
if (readw(baseAddr + key) == keycode)
break; break;
msleep(10); msleep(10);
} }
if (readw(baseAddr + C320_key) != C320_KeyCode) if (readw(baseAddr + key) != keycode)
return -EIO; return -EIO;
} }
writew(0, baseAddr + C320DLoad_len); writew(0, baseAddr + loadlen);
writew(usum, baseAddr + C320check_sum); writew(usum, baseAddr + checksum);
writew(0, baseAddr + C320_key); writew(0, baseAddr + key);
for (i = 0; i < 10; i++) { for (i = 0; i < 100; i++) {
if (readw(baseAddr + C320_key) == C320_KeyCode) if (readw(baseAddr + key) == keycode)
break; break;
msleep(10); msleep(10);
} }
retry++; retry++;
} while ((readb(baseAddr + C320chksum_ok) != 1) && (retry < 3)); } while ((readb(baseAddr + checksum_ok) != 1) && (retry < 3));
if (readb(baseAddr + C320chksum_ok) != 1) if (readb(baseAddr + checksum_ok) != 1)
return -EIO; return -EIO;
writew(0, baseAddr + C320_key); writew(0, baseAddr + key);
for (i = 0; i < 600; i++) { for (i = 0; i < 600; i++) {
if (readw(baseAddr + Magic_no) == Magic_code) if (readw(baseAddr + Magic_no) == Magic_code)
break; break;
...@@ -501,6 +449,7 @@ static int moxa_load_c320(struct moxa_board_conf *brd, const void *ptr, ...@@ -501,6 +449,7 @@ static int moxa_load_c320(struct moxa_board_conf *brd, const void *ptr,
if (readw(baseAddr + Magic_no) != Magic_code) if (readw(baseAddr + Magic_no) != Magic_code)
return -EIO; return -EIO;
if (c320) {
if (brd->busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */ if (brd->busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */
writew(0x3800, baseAddr + TMS320_PORT1); writew(0x3800, baseAddr + TMS320_PORT1);
writew(0x3900, baseAddr + TMS320_PORT2); writew(0x3900, baseAddr + TMS320_PORT2);
...@@ -510,6 +459,7 @@ static int moxa_load_c320(struct moxa_board_conf *brd, const void *ptr, ...@@ -510,6 +459,7 @@ static int moxa_load_c320(struct moxa_board_conf *brd, const void *ptr,
writew(0x3400, baseAddr + TMS320_PORT2); writew(0x3400, baseAddr + TMS320_PORT2);
writew(19999, baseAddr + TMS320_CLOCK); writew(19999, baseAddr + TMS320_CLOCK);
} }
}
writew(1, baseAddr + Disable_IRQ); writew(1, baseAddr + Disable_IRQ);
writew(0, baseAddr + Magic_no); writew(0, baseAddr + Magic_no);
for (i = 0; i < 500; i++) { for (i = 0; i < 500; i++) {
...@@ -520,6 +470,7 @@ static int moxa_load_c320(struct moxa_board_conf *brd, const void *ptr, ...@@ -520,6 +470,7 @@ static int moxa_load_c320(struct moxa_board_conf *brd, const void *ptr,
if (readw(baseAddr + Magic_no) != Magic_code) if (readw(baseAddr + Magic_no) != Magic_code)
return -EIO; return -EIO;
if (c320) {
j = readw(baseAddr + Module_cnt); j = readw(baseAddr + Module_cnt);
if (j <= 0) if (j <= 0)
return -EIO; return -EIO;
...@@ -533,6 +484,7 @@ static int moxa_load_c320(struct moxa_board_conf *brd, const void *ptr, ...@@ -533,6 +484,7 @@ static int moxa_load_c320(struct moxa_board_conf *brd, const void *ptr,
} }
if (readw(baseAddr + Magic_no) != Magic_code) if (readw(baseAddr + Magic_no) != Magic_code)
return -EIO; return -EIO;
}
moxaCard = 1; moxaCard = 1;
brd->intNdx = baseAddr + IRQindex; brd->intNdx = baseAddr + IRQindex;
brd->intPend = baseAddr + IRQpending; brd->intPend = baseAddr + IRQpending;
...@@ -549,17 +501,18 @@ static int moxa_load_code(struct moxa_board_conf *brd, const void *ptr, ...@@ -549,17 +501,18 @@ static int moxa_load_code(struct moxa_board_conf *brd, const void *ptr,
int retval, i; int retval, i;
if (len % 2) { if (len % 2) {
printk(KERN_ERR "moxa: C2XX bios length is not even\n"); printk(KERN_ERR "moxa: bios length is not even\n");
return -EINVAL; return -EINVAL;
} }
retval = moxa_real_load_code(brd, ptr, len); /* may change numPorts */
if (retval)
return retval;
switch (brd->boardType) { switch (brd->boardType) {
case MOXA_BOARD_C218_ISA: case MOXA_BOARD_C218_ISA:
case MOXA_BOARD_C218_PCI: case MOXA_BOARD_C218_PCI:
case MOXA_BOARD_CP204J: case MOXA_BOARD_CP204J:
retval = moxa_load_c218(brd, ptr, len);
if (retval)
return retval;
port = brd->ports; port = brd->ports;
for (i = 0; i < brd->numPorts; i++, port++) { for (i = 0; i < brd->numPorts; i++, port++) {
port->chkPort = 1; port->chkPort = 1;
...@@ -579,9 +532,6 @@ static int moxa_load_code(struct moxa_board_conf *brd, const void *ptr, ...@@ -579,9 +532,6 @@ static int moxa_load_code(struct moxa_board_conf *brd, const void *ptr,
} }
break; break;
default: default:
retval = moxa_load_c320(brd, ptr, len); /* fills in numPorts */
if (retval)
return retval;
port = brd->ports; port = brd->ports;
for (i = 0; i < brd->numPorts; i++, port++) { for (i = 0; i < brd->numPorts; i++, port++) {
port->chkPort = 1; port->chkPort = 1;
......
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