of course this requires the general spi support in serprog.
example output of all 5 patches (+ changing serial to Serial; damnit): ./flashrom -p serprog:dev=/dev/ttyU2flasher:115200,sck=1234 -V -c W25Q32 flashrom v0.9.3-r1349 on Linux 2.6.35-28-generic (x86_64), built with libpci 3.1.7, GCC 4.4.5, little endian flashrom is free software, get the source code at http://www.flashrom.org Calibrating delay loop... OS timer resolution is 1 usecs, 1193M loops per second, 10 myus = 10 us, 100 myus = 100 us, 1000 myus = 997 us, 10000 myus = 9997 us, 4 myus = 4 us, OK. Initializing serprog programmer serprog: connected - attempting to synchronize . serprog: Synchronized serprog: Interface version ok. serprog: Bus support: parallel=off, LPC=off, FWH=off, SPI=on serprog: Maximum write-n length is 16777215 serprog: Maximum read-n length is 16777215 serprog: Requested to set SPI clock frequency to 1234 kHz. It was actually set to 1000 kHz serprog: Programmer name is "atmegaXXu2 " serprog: Serial buffer size is 65535 Probing for Winbond W25Q32, 4096 kB: probe_spi_rdid_generic: id1 0xef, id2 0x4016 Chip status register is 00 Found chip "Winbond W25Q32" (4096 kB, SPI) on serprog. No operations were specified. do we want full stops at all those debug messages? i would say yes, but there are (almost) none. -- Kind regards/Mit freundlichen Grüßen, Stefan Tauner
>From a1222fd1930f670cab933d26ae24f4b868c1217f Mon Sep 17 00:00:00 2001 In-Reply-To: <[email protected]> References: <[email protected]> From: Stefan Tauner <[email protected]> Date: Tue, 21 Jun 2011 23:14:59 +0200 Subject: [PATCH 5/5] serprog: add support for setting the SPI frequency Signed-off-by: Stefan Tauner <[email protected]> --- serprog-protocol.txt | 8 ++++++++ serprog.c | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/serprog-protocol.txt b/serprog-protocol.txt index 9a09287..ddceb2b 100644 --- a/serprog-protocol.txt +++ b/serprog-protocol.txt @@ -33,6 +33,7 @@ COMMAND Description Parameters Return Value 0x12 Set used bustype 8-bit flags (as with 0x05) ACK / NAK 0x13 Perform SPI operation 24-bit slen + 24-bit rlen ACK + rlen bytes of data / NAK + slen bytes of data +0x14 Set SPI clock frequency 16-bit requested frequency ACK + 16-bit set frequency / NAK 0x?? unimplemented command - invalid. @@ -73,6 +74,12 @@ Additional information of the above commands: Maximum slen is Q_WRNMAXLEN result after Q_BUSTYPE returns only SPI or S_BUSTYPE == SPI is used. Same for rlen and Q_RDNMAXLEN. This operation is immediate, meaning it doesnt use the operation buffer. + 0x14 (S_SPI_SCK): + Set the SPI clock frequency. + The requested frequency should be mapped by the programmer software + to a supported frequency lower than the one requested. If there is + no lower frequency available the lowest possible should be used. + The value chosen is sent back in the reply with an ACK. About mandatory commands: The only truly mandatory commands for any device are 0x00, 0x01, 0x02 and 0x10, but one can't really do anything with these commands. @@ -107,3 +114,4 @@ This define listing should help C coders - (it's here to be the single source fo #define S_CMD_Q_RDNMAXLEN 0x11 /* Query read-n maximum length */ #define S_CMD_S_BUSTYPE 0x12 /* Set used bustype(s). */ #define S_CMD_O_SPIOP 0x13 /* Perform SPI operation. */ +#define S_CMD_S_SPI_SCK 0x14 /* Set SPI clock frequency */ diff --git a/serprog.c b/serprog.c index 30b4c12..82a61b8 100644 --- a/serprog.c +++ b/serprog.c @@ -69,6 +69,7 @@ static int serprog_shutdown(void *data); #define S_CMD_Q_RDNMAXLEN 0x11 /* Query read-n maximum length */ #define S_CMD_S_BUSTYPE 0x12 /* Set used bustype(s). */ #define S_CMD_O_SPIOP 0x13 /* Perform SPI operation. */ +#define S_CMD_S_SPI_SCK 0x14 /* Set SPI clock frequency */ static uint16_t sp_device_serbuf_size = 16; static uint16_t sp_device_opbuf_size = 300; @@ -431,6 +432,7 @@ int serprog_init(void) /* Check for the minimum operational set of commands. */ if (buses_supported & CHIP_BUSTYPE_SPI) { uint8_t bt = CHIP_BUSTYPE_SPI; + char *f_spi; if (sp_check_commandavail(S_CMD_O_SPIOP) == 0) { msg_perr("Error: SPI operation not supported while the " "bustype is SPI\n"); @@ -461,6 +463,26 @@ int serprog_init(void) spi_programmer_serprog.max_data_read = v; msg_pdbg(MSGHEADER "Maximum read-n length is %d\n", v); } + f_spi = extract_programmer_param("sck"); + if (f_spi && strlen(f_spi)) { + uint8_t buf[2]; + uint16_t tmp = atoi(f_spi); + buf[0] = tmp & 0xFF; + buf[1] = tmp >> 8; + if (sp_check_commandavail(S_CMD_S_SPI_SCK) == 0) + msg_pdbg(MSGHEADER "Setting SPI clock rate is " + "not supported!\n"); + else if (sp_docommand(S_CMD_S_SPI_SCK, 2, buf, 2, buf) + == 0) { + tmp = buf[0] | (buf[1]<<8); + msg_pdbg(MSGHEADER "Requested to set SPI clock " + "frequency to %s kHz. It was actually " + "set to %d kHz\n", f_spi, tmp); + } else + msg_pdbg(MSGHEADER "Setting SPI clock rate " + "failed!\n"); + } + free(f_spi); bt = buses_supported; sp_docommand(S_CMD_S_BUSTYPE, 1, &bt, 0, NULL); register_spi_programmer(&spi_programmer_serprog); -- 1.7.1
_______________________________________________ flashrom mailing list [email protected] http://www.flashrom.org/mailman/listinfo/flashrom
