51 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
54 #include <linux/module.h>
55 #include <linux/kernel.h>
56 #include <linux/stddef.h>
57 #include <linux/errno.h>
72 static void cycx_bootcfg(
struct cycx_hw *
hw);
78 static int get_option_index(
const long *optlist,
long optval);
81 #define wait_cyc(addr) cycx_exec(addr + CMD_OFFSET)
86 static const char fullname[] =
"Cyclom 2X Support Module";
94 static const long cyc2x_dpmbase_options[] = {
96 0xA0000, 0xA4000, 0xA8000, 0xAC000, 0xB0000, 0xB4000, 0xB8000,
97 0xBC000, 0xC0000, 0xC4000, 0xC8000, 0xCC000, 0xD0000, 0xD4000,
98 0xD8000, 0xDC000, 0xE0000, 0xE4000, 0xE8000, 0xEC000
101 static const long cycx_2x_irq_options[] = { 7, 3, 5, 9, 10, 11, 12, 15 };
112 static int __init cycx_drv_init(
void)
122 static void cycx_drv_cleanup(
void)
142 if (!get_option_index(cycx_2x_irq_options, hw->
irq)) {
149 pr_err(
"you must specify the dpm address!\n");
151 }
else if (!get_option_index(cyc2x_dpmbase_options, dpmbase)) {
152 pr_err(
"memory address 0x%lX is invalid!\n", dpmbase);
159 if (!detect_cyc2x(hw->
dpmbase)) {
160 pr_err(
"adapter Cyclom 2X not found at address 0x%lX!\n",
165 pr_info(
"found Cyclom 2X card at address 0x%lX\n", dpmbase);
168 err = load_cyc2x(hw, cfm, len);
184 static void cycx_inten(
struct cycx_hw *
hw)
205 while (
readw(addr)) {
250 for (; tries < 3 ; tries++) {
269 for (i = 0 ; i <
cnt ; i++) {
271 writeb(*buffer++, pt_code++);
278 static int buffer_load(
void __iomem *addr,
u8 *buffer,
u32 cnt)
287 static void cycx_start(
void __iomem *addr)
290 writeb(0xea, addr + 0x30);
291 writeb(0x00, addr + 0x31);
292 writeb(0xc4, addr + 0x32);
293 writeb(0x00, addr + 0x33);
294 writeb(0x00, addr + 0x34);
310 reset_load(addr, code, len);
331 writew(0x4000, pt_boot_cmd + 2 *
sizeof(
u16));
338 if (buffer_load(addr, code + i,
349 static int cycx_code_boot(
void __iomem *addr,
u8 *code,
u32 len)
361 writew(0x0000, pt_boot_cmd +
sizeof(
u16));
362 writew(0xc400, pt_boot_cmd + 2 *
sizeof(
u16));
369 if (buffer_load(addr, code + i,
396 pr_err(
"load_cyc2x: not Cyclom-2X firmware!\n");
404 pr_err(
"%s: firmware format %u rejected! Expecting %u.\n",
417 pr_err(
"%s: firmware corrupted!\n", __func__);
418 pr_err(
" cdsize = 0x%x (expected 0x%lx)\n",
421 pr_err(
" chksum = 0x%x (expected 0x%x)\n",
428 #ifdef FIRMWARE_DEBUG
429 pr_info(
"%s: image sizes\n", __func__);
435 data_image = reset_image + img_hdr->
reset_size;
436 code_image = data_image + img_hdr->
data_size;
440 pr_info(
"loading firmware %s (ID=%u)...\n",
441 cfm->
descr[0] ? cfm->
descr :
"unknown firmware",
444 for (i = 0 ; i < 5 ; i++) {
446 if (!reset_cyc2x(hw->
dpmbase)) {
447 pr_err(
"dpm problem or board not found\n");
457 for (j = 0 ; j < 3 ; j++)
458 if (!
readw(pt_cycld))
464 pr_err(
"reset not started\n");
470 pr_err(
"cannot load data file\n");
476 pr_err(
"cannot load code file\n");
503 static void cycx_bootcfg(
struct cycx_hw *hw)
515 static int detect_cyc2x(
void __iomem *addr)
519 return memory_exists(addr);
525 static int get_option_index(
const long *optlist,
long optval)
529 for (; i <= optlist[0]; ++
i)
530 if (optlist[i] == optval)
537 static int reset_cyc2x(
void __iomem *addr)
544 return memory_exists(addr);
553 for (; len; --len, ++
buf)
554 for (mask = 0x80;
mask; mask >>= 1) {
555 flag = (crc & 0x8000);
557 crc |= ((*buf &
mask) ? 1 : 0);