summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/include/openpcd.h1
-rw-r--r--firmware/src/pcd/rc632.c34
2 files changed, 34 insertions, 1 deletions
diff --git a/firmware/include/openpcd.h b/firmware/include/openpcd.h
index 0cceb53..b59a245 100644
--- a/firmware/include/openpcd.h
+++ b/firmware/include/openpcd.h
@@ -61,6 +61,7 @@ enum openpcd_cmd_class {
#define OPENPCD_CMD_READ_VFIFO (0x8|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
#define OPENPCD_CMD_DUMP_REGS (0x9|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
#define OPENPCD_CMD_IRQ (0xa|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
+#define OPENPCD_CMD_WRITE_REG_SET (0xb|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
/* CMD_CLS_SSC */
#define OPENPCD_CMD_SSC_READ (0x1|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_SSC))
diff --git a/firmware/src/pcd/rc632.c b/firmware/src/pcd/rc632.c
index 8513d2a..5287300 100644
--- a/firmware/src/pcd/rc632.c
+++ b/firmware/src/pcd/rc632.c
@@ -185,6 +185,8 @@ struct rc632 {
#define RC632_F_FIFO_TX 0x0001
static struct rc632 rc632;
+#define RC632_WRITE_ADDR(x) ((x << 1) & 0x7e)
+
/* RC632 access primitives */
int rc632_reg_write(struct rfid_asic_handle *hdl,
@@ -194,7 +196,7 @@ int rc632_reg_write(struct rfid_asic_handle *hdl,
DEBUG632("[0x%02x] <= 0x%02x", addr, data);
- addr = (addr << 1) & 0x7e;
+ addr = RC632_WRITE_ADDR(addr);
spi_outbuf[0] = addr;
spi_outbuf[1] = data;
@@ -203,6 +205,32 @@ int rc632_reg_write(struct rfid_asic_handle *hdl,
return spi_transceive(spi_outbuf, 2, spi_inbuf, &rx_len);
}
+#define RC632_REGSET_START 0x10
+#define RC632_REGSET_END 0x3f
+#define RC632_REGSET_MAXSIZE (RC632_REGSET_END-RC632_REGSET_START)
+static char regset_buf[RC632_REGSET_MAXSIZE * 2];
+
+int rc632_reg_write_set(struct rfid_asic_handle *hdl,
+ u_int8_t *regs, int len)
+{
+ u_int8_t i, j = 0;
+ u_int16_t rx_len;
+
+ if (len > RC632_REGSET_MAXSIZE)
+ return -E2BIG;
+
+ for (i = RC632_REGSET_START; i <= RC632_REGSET_END; i++) {
+ /* skip bank registers */
+ if (i % 8 == 0)
+ continue;
+ regset_buf[j++] = RC632_WRITE_ADDR(i);
+ regset_buf[j++] = regs[i - RC632_REGSET_START];
+ }
+
+ rx_len = j;
+ return spi_transceive(regset_buf, j, spi_inbuf, &rx_len);
+}
+
int rc632_fifo_write(struct rfid_asic_handle *hdl,
u_int8_t len, u_int8_t *data, u_int8_t flags)
{
@@ -457,6 +485,10 @@ static int rc632_usb_in(struct req_ctx *rctx)
DEBUGP("WRITE_REG(0x%02x, 0x%02x) ", poh->reg, poh->val);
rc632_reg_write(RAH, poh->reg, poh->val);
break;
+ case OPENPCD_CMD_WRITE_REG_SET:
+ DEBUGP("WRITE_REG_SET(%s) ", hexdump(poh->data, len));
+ rc632_reg_write_set(RAH, poh->data, len);
+ break;
case OPENPCD_CMD_WRITE_FIFO:
DEBUGP("WRITE FIFO(len=%u): %s ", len,
hexdump(poh->data, len));
personal git repositories of Harald Welte. Your mileage may vary