diff --git a/buspirate_spi.c b/buspirate_spi.c index 3006aa106..d67bfbc7e 100644 --- a/buspirate_spi.c +++ b/buspirate_spi.c @@ -25,6 +25,17 @@ #include "flash.h" #include "spi.h" +/* Change this to #define if you want lowlevel debugging of commands + * sent to the Bus Pirate. + */ +#undef COMM_DEBUG + +#ifdef COMM_DEBUG +#define msg_comm_debug printf_debug +#else +#define msg_comm_debug(...) do {} while (0) +#endif + /* Change this to #define if you want to test without a serial implementation */ #undef FAKE_COMMUNICATION @@ -47,14 +58,14 @@ int buspirate_sendrecv(unsigned char *buf, unsigned int writecnt, unsigned int r { int i, ret = 0; - printf_debug("%s: write %i, read %i\n", __func__, writecnt, readcnt); + msg_comm_debug("%s: write %i, read %i ", __func__, writecnt, readcnt); if (!writecnt && !readcnt) { fprintf(stderr, "Zero length command!\n"); return 1; } - printf_debug("Sending"); + msg_comm_debug("Sending"); for (i = 0; i < writecnt; i++) - printf_debug(" 0x%02x", buf[i]); + msg_comm_debug(" 0x%02x", buf[i]); #ifdef FAKE_COMMUNICATION /* Placate the caller for now. */ if (readcnt) { @@ -72,10 +83,10 @@ int buspirate_sendrecv(unsigned char *buf, unsigned int writecnt, unsigned int r if (ret) return ret; #endif - printf_debug(", receiving"); + msg_comm_debug(", receiving"); for (i = 0; i < readcnt; i++) - printf_debug(" 0x%02x", buf[i]); - printf_debug("\n"); + msg_comm_debug(" 0x%02x", buf[i]); + msg_comm_debug("\n"); return 0; } diff --git a/ft2232_spi.c b/ft2232_spi.c index d565a6fd3..80c6d4e98 100644 --- a/ft2232_spi.c +++ b/ft2232_spi.c @@ -29,6 +29,17 @@ #include "spi.h" #include +/* Change this to #define if you want lowlevel debugging of commands + * sent to the FT2232 SPI controller. + */ +#undef COMM_DEBUG + +#ifdef COMM_DEBUG +#define msg_comm_debug printf_debug +#else +#define msg_comm_debug(...) do {} while (0) +#endif + /* * The 'H' chips can run internally at either 12MHz or 60MHz. * The non-H chips can only run at 12MHz. @@ -224,7 +235,7 @@ int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, * and deassert CS# all in one shot. If reading, we do three separate * operations. */ - printf_debug("Assert CS#\n"); + msg_comm_debug("Assert CS#\n"); buf[i++] = SET_BITS_LOW; buf[i++] = 0 & ~CS_BIT; /* assertive */ buf[i++] = 0x0b; @@ -266,7 +277,7 @@ int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, } } - printf_debug("De-assert CS#\n"); + msg_comm_debug("De-assert CS#\n"); buf[i++] = SET_BITS_LOW; buf[i++] = CS_BIT; buf[i++] = 0x0b; diff --git a/ichspi.c b/ichspi.c index cd02b9638..a6bf15459 100644 --- a/ichspi.c +++ b/ichspi.c @@ -36,6 +36,17 @@ #include "flash.h" #include "spi.h" +/* Change this to #define if you want lowlevel debugging of commands + * sent to the ICH/VIA SPI controller. + */ +#undef COMM_DEBUG + +#ifdef COMM_DEBUG +#define msg_comm_debug printf_debug +#else +#define msg_comm_debug(...) do {} while (0) +#endif + /* ICH9 controller register definition */ #define ICH9_REG_FADDR 0x08 /* 32 Bits */ #define ICH9_REG_FDATA0 0x10 /* 64 Bytes */ @@ -624,7 +635,7 @@ static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes, uint32_t remaining = page_size; int towrite; - printf_debug("ich_spi_write_page: offset=%d, number=%d, buf=%p\n", + msg_comm_debug("ich_spi_write_page: offset=%d, number=%d, buf=%p\n", offset, page_size, bytes); for (; remaining > 0; remaining -= towrite) { diff --git a/sb600spi.c b/sb600spi.c index 87f1cc1ee..66943ba87 100644 --- a/sb600spi.c +++ b/sb600spi.c @@ -24,6 +24,17 @@ #include "flash.h" #include "spi.h" +/* Change this to #define if you want lowlevel debugging of commands + * sent to the SB600/SB700 SPI controller. + */ +#undef COMM_DEBUG + +#ifdef COMM_DEBUG +#define msg_comm_debug printf_debug +#else +#define msg_comm_debug(...) do {} while (0) +#endif + /* This struct is unused, but helps visualize the SB600 SPI BAR layout. *struct sb600_spi_controller { * unsigned int spi_cntrl0; / * 00h * / @@ -105,7 +116,7 @@ int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt, writecnt--; - printf_debug("%s, cmd=%x, writecnt=%x, readcnt=%x\n", + msg_comm_debug("%s, cmd=%x, writecnt=%x, readcnt=%x\n", __func__, cmd, writecnt, readcnt); if (readcnt > 8) { @@ -135,10 +146,10 @@ int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt, /* Send the write byte to FIFO. */ for (count = 0; count < writecnt; count++, writearr++) { - printf_debug(" [%x]", *writearr); + msg_comm_debug(" [%x]", *writearr); mmio_writeb(*writearr, sb600_spibar + 0xC); } - printf_debug("\n"); + msg_comm_debug("\n"); /* * We should send the data by sequence, which means we need to reset @@ -164,16 +175,16 @@ int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt, /* Skip the bytes we sent. */ for (count = 0; count < writecnt; count++) { cmd = mmio_readb(sb600_spibar + 0xC); - printf_debug("[ %2x]", cmd); + msg_comm_debug("[ %2x]", cmd); } - printf_debug("The FIFO pointer after skipping is %d.\n", + msg_comm_debug("The FIFO pointer after skipping is %d.\n", mmio_readb(sb600_spibar + 0xd) & 0x07); for (count = 0; count < readcnt; count++, readarr++) { *readarr = mmio_readb(sb600_spibar + 0xC); - printf_debug("[%02x]", *readarr); + msg_comm_debug("[%02x]", *readarr); } - printf_debug("\n"); + msg_comm_debug("\n"); return 0; } diff --git a/wbsio_spi.c b/wbsio_spi.c index 6b9425fe4..e6b94ad7a 100644 --- a/wbsio_spi.c +++ b/wbsio_spi.c @@ -2,6 +2,7 @@ * This file is part of the flashrom project. * * Copyright (C) 2008 Peter Stuge + * Copyright (C) 2009,2010 Carl-Daniel Hailfinger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +22,17 @@ #include "flash.h" #include "spi.h" +/* Change this to #define if you want lowlevel debugging of commands + * sent to the Winbond W836xx SPI controller. + */ +#undef COMM_DEBUG + +#ifdef COMM_DEBUG +#define msg_comm_debug printf_debug +#else +#define msg_comm_debug(...) do {} while (0) +#endif + #define WBSIO_PORT1 0x2e #define WBSIO_PORT2 0x4e @@ -62,7 +74,7 @@ int wbsio_check_for_spi(const char *name) if (0 == (wbsio_spibase = wbsio_get_spibase(WBSIO_PORT2))) return 1; - printf_debug("\nwbsio_spibase = 0x%x\n", wbsio_spibase); + msg_comm_debug("\nwbsio_spibase = 0x%x\n", wbsio_spibase); buses_supported |= CHIP_BUSTYPE_SPI; spi_controller = SPI_CONTROLLER_WBSIO; @@ -96,42 +108,42 @@ int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt, int i; uint8_t mode = 0; - printf_debug("%s:", __func__); + msg_comm_debug("%s:", __func__); if (1 == writecnt && 0 == readcnt) { mode = 0x10; } else if (2 == writecnt && 0 == readcnt) { OUTB(writearr[1], wbsio_spibase + 4); - printf_debug(" data=0x%02x", writearr[1]); + msg_comm_debug(" data=0x%02x", writearr[1]); mode = 0x20; } else if (1 == writecnt && 2 == readcnt) { mode = 0x30; } else if (4 == writecnt && 0 == readcnt) { - printf_debug(" addr=0x%02x", (writearr[1] & 0x0f)); + msg_comm_debug(" addr=0x%02x", (writearr[1] & 0x0f)); for (i = 2; i < writecnt; i++) { OUTB(writearr[i], wbsio_spibase + i); - printf_debug("%02x", writearr[i]); + msg_comm_debug("%02x", writearr[i]); } mode = 0x40 | (writearr[1] & 0x0f); } else if (5 == writecnt && 0 == readcnt) { - printf_debug(" addr=0x%02x", (writearr[1] & 0x0f)); + msg_comm_debug(" addr=0x%02x", (writearr[1] & 0x0f)); for (i = 2; i < 4; i++) { OUTB(writearr[i], wbsio_spibase + i); - printf_debug("%02x", writearr[i]); + msg_comm_debug("%02x", writearr[i]); } OUTB(writearr[i], wbsio_spibase + i); - printf_debug(" data=0x%02x", writearr[i]); + msg_comm_debug(" data=0x%02x", writearr[i]); mode = 0x50 | (writearr[1] & 0x0f); } else if (8 == writecnt && 0 == readcnt) { - printf_debug(" addr=0x%02x", (writearr[1] & 0x0f)); + msg_comm_debug(" addr=0x%02x", (writearr[1] & 0x0f)); for (i = 2; i < 4; i++) { OUTB(writearr[i], wbsio_spibase + i); - printf_debug("%02x", writearr[i]); + msg_comm_debug("%02x", writearr[i]); } - printf_debug(" data=0x"); + msg_comm_debug(" data=0x"); for (; i < writecnt; i++) { OUTB(writearr[i], wbsio_spibase + i); - printf_debug("%02x", writearr[i]); + msg_comm_debug("%02x", writearr[i]); } mode = 0x60 | (writearr[1] & 0x0f); } else if (5 == writecnt && 4 == readcnt) { @@ -142,14 +154,14 @@ int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt, */ ; } else if (4 == writecnt && readcnt >= 1 && readcnt <= 4) { - printf_debug(" addr=0x%02x", (writearr[1] & 0x0f)); + msg_comm_debug(" addr=0x%02x", (writearr[1] & 0x0f)); for (i = 2; i < writecnt; i++) { OUTB(writearr[i], wbsio_spibase + i); - printf_debug("%02x", writearr[i]); + msg_comm_debug("%02x", writearr[i]); } mode = ((7 + readcnt) << 4) | (writearr[1] & 0x0f); } - printf_debug(" cmd=%02x mode=%02x\n", writearr[0], mode); + msg_comm_debug(" cmd=%02x mode=%02x\n", writearr[0], mode); if (!mode) { fprintf(stderr, "%s: unsupported command type wr=%d rd=%d\n", @@ -165,12 +177,12 @@ int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt, if (!readcnt) return 0; - printf_debug("%s: returning data =", __func__); + msg_comm_debug("%s: returning data =", __func__); for (i = 0; i < readcnt; i++) { readarr[i] = INB(wbsio_spibase + 4 + i); - printf_debug(" 0x%02x", readarr[i]); + msg_comm_debug(" 0x%02x", readarr[i]); } - printf_debug("\n"); + msg_comm_debug("\n"); return 0; }