41 #include <linux/module.h>
42 #include <linux/kernel.h>
49 #define CMD_BUSY_TIMEOUT (100)
50 #define CMD_INIT_TIMEOUT (50000)
51 #define CMD_COMPL_TIMEOUT (20000)
52 #define ALLOC_COMPL_TIMEOUT (1000)
59 #define HERMES_AUX_ENABLE 0x8000
60 #define HERMES_AUX_DISABLE 0x4000
61 #define HERMES_AUX_ENABLED 0xC000
62 #define HERMES_AUX_DISABLED 0x0000
64 #define HERMES_AUX_PW0 0xFE01
65 #define HERMES_AUX_PW1 0xDC23
66 #define HERMES_AUX_PW2 0xBA45
69 #define HERMES_PROGRAM_DISABLE (0x0000 | HERMES_CMD_DOWNLD)
70 #define HERMES_PROGRAM_ENABLE_VOLATILE (0x0100 | HERMES_CMD_DOWNLD)
71 #define HERMES_PROGRAM_ENABLE_NON_VOLATILE (0x0200 | HERMES_CMD_DOWNLD)
72 #define HERMES_PROGRAM_NON_VOLATILE (0x0300 | HERMES_CMD_DOWNLD)
78 #define DMSG(stuff...) do {printk(KERN_DEBUG "hermes @ %p: " , hw->iobase); \
79 printk(stuff); } while (0)
85 #define DEBUG(lvl, stuff...) if ((lvl) <= HERMES_DEBUG) DMSG(stuff)
89 #define DEBUG(lvl, stuff...) do { } while (0)
93 static const struct hermes_ops hermes_ops_local;
119 if (reg & HERMES_CMD_BUSY)
135 static int hermes_doicmd_wait(
struct hermes *hw,
u16 cmd,
143 err = hermes_issue_cmd(hw, cmd, parm0, parm1, parm2);
157 if (!hermes_present(hw)) {
158 DEBUG(0,
"hermes @ 0x%x: Card removed during reset.\n",
164 if (!(reg & HERMES_EV_CMD)) {
166 "Timeout waiting for card to reset (reg=0x%04x)!\n",
195 hw->
ops = &hermes_ops_local;
199 static int hermes_init(
struct hermes *hw)
218 while (k && (reg & HERMES_CMD_BUSY)) {
253 static int hermes_docmd_wait(
struct hermes *hw,
u16 cmd,
u16 parm0,
261 err = hermes_issue_cmd(hw, cmd, parm0, 0, 0);
263 if (!hermes_present(hw)) {
266 "Card removed while issuing command "
267 "0x%04x.\n", hw->
iobase, cmd);
272 "Error %d issuing command 0x%04x.\n",
279 while ((!(reg & HERMES_EV_CMD)) && k) {
285 if (!hermes_present(hw)) {
287 "while waiting for command 0x%04x completion.\n",
293 if (!(reg & HERMES_EV_CMD)) {
295 "command 0x%04x completion.\n", hw->
iobase, cmd);
338 if (!hermes_present(hw)) {
340 "Card removed waiting for frame allocation.\n",
345 if (!(reg & HERMES_EV_ALLOC)) {
347 "Timeout waiting for frame allocation\n",
386 if (reg & HERMES_OFFSET_BUSY)
404 "reg=0x%x id=0x%x offset=0x%x\n", hw->
iobase, bap,
405 (reg & HERMES_OFFSET_BUSY) ?
"timeout" :
"error",
408 if (reg & HERMES_OFFSET_BUSY)
426 static int hermes_bap_pread(
struct hermes *hw,
int bap,
void *
buf,
int len,
432 if ((len < 0) || (len % 2))
435 err = hermes_bap_seek(hw, bap,
id, offset);
440 hermes_read_words(hw, dreg, buf, len / 2);
454 static int hermes_bap_pwrite(
struct hermes *hw,
int bap,
const void *buf,
455 int len,
u16 id,
u16 offset)
463 err = hermes_bap_seek(hw, bap,
id, offset);
468 hermes_write_bytes(hw, dreg, buf, len);
482 static int hermes_read_ltv(
struct hermes *hw,
int bap,
u16 rid,
497 err = hermes_bap_seek(hw, bap, rid, 0);
513 "rid (0x%04x) does not match type (0x%04x)\n",
514 hw->
iobase, __func__, rid, rtype);
517 "Truncating LTV record from %d to %d bytes. "
518 "(rid=0x%04x, len=0x%04x)\n", hw->
iobase,
521 nwords =
min((
unsigned)rlength - 1, bufsize / 2);
522 hermes_read_words(hw, dreg, buf, nwords);
527 static int hermes_write_ltv(
struct hermes *hw,
int bap,
u16 rid,
537 err = hermes_bap_seek(hw, bap, rid, 0);
546 hermes_write_bytes(hw, dreg, value, count << 1);
579 for (i = 0; i < 20; i++) {
611 err = hw->
ops->init_cmd_wait(hw,
617 err = hw->
ops->init_cmd_wait(hw,
623 err = hermes_aux_control(hw, 1);
624 pr_debug(
"AUX enable returned %d\n", err);
629 pr_debug(
"Enabling volatile, EP 0x%08x\n", offset);
630 err = hw->
ops->init_cmd_wait(hw,
636 pr_debug(
"PROGRAM_ENABLE returned %d\n", err);
655 pr_debug(
"PROGRAM_DISABLE returned %d, "
656 "r0 0x%04x, r1 0x%04x, r2 0x%04x\n",
663 err = hermes_aux_control(hw, 0);
664 pr_debug(
"AUX disable returned %d\n", err);
673 return rc ? rc :
err;
676 static int hermes_program_bytes(
struct hermes *hw,
const char *
data,
682 hermes_aux_setaddr(hw, addr);
710 data_len = pda_len - 4;
715 ret = hermes_aux_control(hw, 1);
716 pr_debug(
"AUX enable returned %d\n", ret);
721 hermes_aux_setaddr(hw, pda_addr);
725 ret = hermes_aux_control(hw, 0);
726 pr_debug(
"AUX disable returned %d\n", ret);
730 pr_debug(
"Actual PDA length %d, Max allowed %d\n",
732 if (pda_size > pda_len)
738 static void hermes_lock_irqsave(
spinlock_t *lock,
744 static void hermes_unlock_irqrestore(
spinlock_t *lock,
747 spin_unlock_irqrestore(lock, *
flags);
757 spin_unlock_irq(lock);
761 static const struct hermes_ops hermes_ops_local = {
763 .cmd_wait = hermes_docmd_wait,
764 .init_cmd_wait = hermes_doicmd_wait,
765 .allocate = hermes_allocate,
766 .read_ltv = hermes_read_ltv,
767 .write_ltv = hermes_write_ltv,
768 .bap_pread = hermes_bap_pread,
769 .bap_pwrite = hermes_bap_pwrite,
773 .program = hermes_program_bytes,
774 .lock_irqsave = hermes_lock_irqsave,
775 .unlock_irqrestore = hermes_unlock_irqrestore,
776 .lock_irq = hermes_lock_irq,
777 .unlock_irq = hermes_unlock_irq,