Patchwork Convert SPI write status register to multicommand

login
register
about
Submitter Carl-Daniel Hailfinger
Date 2009-07-14 10:06:26
Message ID <4A5C58A2.1080501@gmx.net>
Download mbox | patch
Permalink /patch/33/
State Accepted
Commit r658
Headers show

Comments

Carl-Daniel Hailfinger - 2009-07-14 10:06:26
Convert SPI write status register to multicommand infrastructure.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Carl-Daniel Hailfinger - 2009-07-22 15:51:24
On 14.07.2009 12:06, Carl-Daniel Hailfinger wrote:
> Convert SPI write status register to multicommand infrastructure.
>
> Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
>   

This kills one of the two remaining special cases for broken hardware.
Anyone up for an ack?

Regards,
Carl-Daniel
Stefan Reinauer - 2009-07-22 17:35:52
On 7/22/09 5:51 PM, Carl-Daniel Hailfinger wrote:
> On 14.07.2009 12:06, Carl-Daniel Hailfinger wrote:
>   
>> Convert SPI write status register to multicommand infrastructure.
>>
>> Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
>>   
>>     
> This kills one of the two remaining special cases for broken hardware.
> Anyone up for an ack?
>   

Go ahead.

Acked-by: Stefan Reinauer <stepan@coresystems.de>
Carl-Daniel Hailfinger - 2009-07-22 20:10:05
On 22.07.2009 19:35, Stefan Reinauer wrote:
> On 7/22/09 5:51 PM, Carl-Daniel Hailfinger wrote:
>   
>> On 14.07.2009 12:06, Carl-Daniel Hailfinger wrote:
>>   
>>     
>>> Convert SPI write status register to multicommand infrastructure.
>>>
>>> Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
>>>   
>>>     
>>>       
>> This kills one of the two remaining special cases for broken hardware.  
>>     
>
> Acked-by: Stefan Reinauer <stepan@coresystems.de>
>   

Thanks, r658.

Regards,
Carl-Daniel

Patch

Index: flashrom-spi_multicommand_statusreg/spi.c
===================================================================
--- flashrom-spi_multicommand_statusreg/spi.c	(Revision 652)
+++ flashrom-spi_multicommand_statusreg/spi.c	(Arbeitskopie)
@@ -690,21 +690,7 @@ 
 	result = spi_send_command(sizeof(cmd), JEDEC_EWSR_INSIZE, cmd, NULL);
 
 	if (result)
-		printf_debug("%s failed", __func__);
-	if (result == SPI_INVALID_OPCODE) {
-		switch (spi_controller) {
-		case SPI_CONTROLLER_ICH7:
-		case SPI_CONTROLLER_ICH9:
-		case SPI_CONTROLLER_VIA:
-			printf_debug(" due to SPI master limitation, ignoring"
-				     " and hoping it will be run as PREOP\n");
-			return 0;
-		default:
-			break;
-		}
-	}
-	if (result)
-		printf_debug("\n");
+		printf_debug("%s failed\n", __func__);
 
 	return result;
 }
@@ -715,11 +701,30 @@ 
  */
 int spi_write_status_register(int status)
 {
-	const unsigned char cmd[JEDEC_WRSR_OUTSIZE] =
-	    { JEDEC_WRSR, (unsigned char)status };
+	int result;
+	struct spi_command spicommands[] = {
+	{
+		.writecnt	= JEDEC_EWSR_OUTSIZE,
+		.writearr	= (const unsigned char[]){ JEDEC_EWSR },
+		.readcnt	= 0,
+		.readarr	= NULL,
+	}, {
+		.writecnt	= JEDEC_WRSR_OUTSIZE,
+		.writearr	= (const unsigned char[]){ JEDEC_WRSR, (unsigned char) status },
+		.readcnt	= 0,
+		.readarr	= NULL,
+	}, {
+		.writecnt	= 0,
+		.writearr	= NULL,
+		.readcnt	= 0,
+		.readarr	= NULL,
+	}};
 
-	/* Send WRSR (Write Status Register) */
-	return spi_send_command(sizeof(cmd), 0, cmd, NULL);
+	result = spi_send_multicommand(spicommands);
+	if (result) {
+		printf_debug("%s failed during command execution\n", __func__);
+	}
+	return result;
 }
 
 int spi_byte_program(int addr, uint8_t byte)
@@ -746,7 +751,6 @@ 
 	result = spi_send_multicommand(spicommands);
 	if (result) {
 		printf_debug("%s failed during command execution\n", __func__);
-		return result;
 	}
 	return result;
 }
@@ -793,7 +797,6 @@ 
 	result = spi_send_multicommand(spicommands);
 	if (result) {
 		printf_debug("%s failed during command execution\n", __func__);
-		return result;
 	}
 	return result;
 }
@@ -807,11 +810,6 @@ 
 	/* If there is block protection in effect, unprotect it first. */
 	if ((status & 0x3c) != 0) {
 		printf_debug("Some block protection in effect, disabling\n");
-		result = spi_write_status_enable();
-		if (result) {
-			printf_debug("spi_write_status_enable failed\n");
-			return result;
-		}
 		result = spi_write_status_register(status & ~0x3c);
 		if (result) {
 			printf_debug("spi_write_status_register failed\n");