diff --git a/ichspi.c b/ichspi.c index a6bf154..aa0b23b 100644 --- a/ichspi.c +++ b/ichspi.c @@ -36,17 +36,6 @@ #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 */ @@ -227,7 +216,7 @@ static int generate_opcodes(OPCODES * op) uint32_t opmenu[2]; if (op == NULL) { - printf_debug("\n%s: null OPCODES pointer!\n", __func__); + msg_pdbg("\n%s: null OPCODES pointer!\n", __func__); return -1; } @@ -246,7 +235,7 @@ static int generate_opcodes(OPCODES * op) opmenu[1] = REGREAD32(ICH9_REG_OPMENU + 4); break; default: - printf_debug("%s: unsupported chipset\n", __func__); + msg_pdbg("%s: unsupported chipset\n", __func__); return -1; } @@ -312,7 +301,7 @@ int program_opcodes(OPCODES * op) opmenu[1] |= ((uint32_t) op->opcode[a].opcode) << ((a - 4) * 8); } - printf_debug("\n%s: preop=%04x optype=%04x opmenu=%08x%08x\n", __func__, preop, optype, opmenu[0], opmenu[1]); + msg_pdbg("\n%s: preop=%04x optype=%04x opmenu=%08x%08x\n", __func__, preop, optype, opmenu[0], opmenu[1]); switch (spi_controller) { case SPI_CONTROLLER_ICH7: case SPI_CONTROLLER_VIA: @@ -328,7 +317,7 @@ int program_opcodes(OPCODES * op) REGWRITE32(ICH9_REG_OPMENU + 4, opmenu[1]); break; default: - printf_debug("%s: unsupported chipset\n", __func__); + msg_pdbg("%s: unsupported chipset\n", __func__); return -1; } @@ -349,22 +338,22 @@ int ich_init_opcodes(void) return 0; if (ichspi_lock) { - printf_debug("Generating OPCODES... "); + msg_pdbg("Generating OPCODES... "); curopcodes_done = &O_EXISTING; rc = generate_opcodes(curopcodes_done); } else { - printf_debug("Programming OPCODES... "); + msg_pdbg("Programming OPCODES... "); curopcodes_done = &O_ST_M25P; rc = program_opcodes(curopcodes_done); } if (rc) { curopcodes = NULL; - printf_debug("failed\n"); + msg_pdbg("failed\n"); return 1; } else { curopcodes = curopcodes_done; - printf_debug("done\n"); + msg_pdbg("done\n"); return 0; } } @@ -436,7 +425,7 @@ static int ich7_run_opcode(OPCODE op, uint32_t offset, opmenu >>= 8; } if (opcode_index == 8) { - printf_debug("Opcode %x not found.\n", op.opcode); + msg_pdbg("Opcode %x not found.\n", op.opcode); return 1; } temp16 |= ((uint16_t) (opcode_index & 0x07)) << 4; @@ -464,11 +453,11 @@ static int ich7_run_opcode(OPCODE op, uint32_t offset, programmer_delay(10); } if (!timeout) { - printf_debug("timeout\n"); + msg_pdbg("timeout\n"); } if ((REGREAD16(ICH7_REG_SPIS) & SPIS_FCERR) != 0) { - printf_debug("Transaction error!\n"); + msg_pdbg("Transaction error!\n"); return 1; } @@ -553,7 +542,7 @@ static int ich9_run_opcode(OPCODE op, uint32_t offset, opmenu >>= 8; } if (opcode_index == 8) { - printf_debug("Opcode %x not found.\n", op.opcode); + msg_pdbg("Opcode %x not found.\n", op.opcode); return 1; } temp32 |= ((uint32_t) (opcode_index & 0x07)) << (8 + 4); @@ -581,11 +570,11 @@ static int ich9_run_opcode(OPCODE op, uint32_t offset, programmer_delay(10); } if (!timeout) { - printf_debug("timeout\n"); + msg_pdbg("timeout\n"); } if ((REGREAD32(ICH9_REG_SSFS) & SSFS_FCERR) != 0) { - printf_debug("Transaction error!\n"); + msg_pdbg("Transaction error!\n"); return 1; } @@ -621,7 +610,7 @@ static int run_opcode(OPCODE op, uint32_t offset, return SPI_INVALID_LENGTH; return ich9_run_opcode(op, offset, datalength, data); default: - printf_debug("%s: unsupported chipset\n", __func__); + msg_pdbg("%s: unsupported chipset\n", __func__); } /* If we ever get here, something really weird happened */ @@ -635,14 +624,14 @@ static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes, uint32_t remaining = page_size; int towrite; - msg_comm_debug("ich_spi_write_page: offset=%d, number=%d, buf=%p\n", + msg_pspew("ich_spi_write_page: offset=%d, number=%d, buf=%p\n", offset, page_size, bytes); for (; remaining > 0; remaining -= towrite) { towrite = min(remaining, maxdata); if (spi_nbyte_program(offset + (page_size - remaining), &bytes[page_size - remaining], towrite)) { - printf_debug("Error writing"); + msg_pdbg("Error writing"); return 1; } } @@ -670,14 +659,14 @@ int ich_spi_write_256(struct flashchip *flash, uint8_t * buf) spi_disable_blockprotect(); /* Erase first */ - printf("Erasing flash before programming... "); + msg_pinfo("Erasing flash before programming... "); if (erase_flash(flash)) { - fprintf(stderr, "ERASE FAILED!\n"); + msg_perr("ERASE FAILED!\n"); return -1; } - printf("done.\n"); + msg_pinfo("done.\n"); - printf("Programming page: \n"); + msg_pinfo("Programming page: \n"); for (i = 0; i < total_size / erase_size; i++) { if (spi_controller == SPI_CONTROLLER_VIA) maxdata = 16; @@ -689,7 +678,7 @@ int ich_spi_write_256(struct flashchip *flash, uint8_t * buf) } } - printf("\n"); + msg_pinfo("\n"); return rc; } @@ -716,7 +705,7 @@ int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt, /* unknown / not programmed command */ if (opcode_index == -1) { - printf_debug("Invalid OPCODE 0x%02x\n", cmd); + msg_pdbg("Invalid OPCODE 0x%02x\n", cmd); return SPI_INVALID_OPCODE; } @@ -743,7 +732,7 @@ int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt, result = run_opcode(*opcode, addr, count, data); if (result) { - printf_debug("run OPCODE 0x%02x failed\n", opcode->opcode); + msg_pdbg("run OPCODE 0x%02x failed\n", opcode->opcode); } return result;