drivers/spi/spi_flash: assume spi_flash read callback exists
spi_flash_erase() and spi_flash_write() already assume their respective callbacks are supplied in the spi_flash_ops object. Make the same assumption in spi_flash_read(). In order to do this the spi_flash_ops objects from the drivers need to reference the the previously used fallback read command, spi_flash_read_chunked(). This function is made global and renamed to spi_flash_cmd_read() for consistency. By doing this further dead code elimination can be achieved when the spi flash drivers aren't included in the build. A Hatch Chrome OS build achieves a further text segment reduction of 0.5KiB in verstage, romstage, and ramstage. Change-Id: I7fee55e6ffc1983657c3adde025a0e8c9d12ca23 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/38366 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Furquan Shaikh <furquan@google.com>
This commit is contained in:
		| @@ -149,6 +149,7 @@ static const struct adesto_spi_flash_params adesto_spi_flash_table[] = { | ||||
| }; | ||||
|  | ||||
| static const struct spi_flash_ops spi_flash_ops = { | ||||
| 	.read = spi_flash_cmd_read, | ||||
| 	.write = spi_flash_cmd_write_page_program, | ||||
| 	.erase = spi_flash_cmd_erase, | ||||
| }; | ||||
|   | ||||
| @@ -120,6 +120,7 @@ static const struct amic_spi_flash_params amic_spi_flash_table[] = { | ||||
| }; | ||||
|  | ||||
| static const struct spi_flash_ops spi_flash_ops = { | ||||
| 	.read = spi_flash_cmd_read, | ||||
| 	.write = spi_flash_cmd_write_page_program, | ||||
| 	.erase = spi_flash_cmd_erase, | ||||
| }; | ||||
|   | ||||
| @@ -104,6 +104,7 @@ static const struct atmel_spi_flash_params atmel_spi_flash_table[] = { | ||||
| }; | ||||
|  | ||||
| static const struct spi_flash_ops spi_flash_ops = { | ||||
| 	.read = spi_flash_cmd_read, | ||||
| 	.write = spi_flash_cmd_write_page_program, | ||||
| 	.erase = spi_flash_cmd_erase, | ||||
| }; | ||||
|   | ||||
| @@ -236,6 +236,7 @@ static const struct eon_spi_flash_params eon_spi_flash_table[] = { | ||||
| }; | ||||
|  | ||||
| static const struct spi_flash_ops spi_flash_ops = { | ||||
| 	.read = spi_flash_cmd_read, | ||||
| 	.write = spi_flash_cmd_write_page_program, | ||||
| 	.erase = spi_flash_cmd_erase, | ||||
| 	.status = spi_flash_cmd_status, | ||||
|   | ||||
| @@ -165,6 +165,7 @@ static const struct gigadevice_spi_flash_params gigadevice_spi_flash_table[] = { | ||||
| }; | ||||
|  | ||||
| static const struct spi_flash_ops spi_flash_ops = { | ||||
| 	.read = spi_flash_cmd_read, | ||||
| 	.write = spi_flash_cmd_write_page_program, | ||||
| 	.erase = spi_flash_cmd_erase, | ||||
| 	.status = spi_flash_cmd_status, | ||||
|   | ||||
| @@ -201,6 +201,7 @@ static const struct macronix_spi_flash_params macronix_spi_flash_table[] = { | ||||
| }; | ||||
|  | ||||
| static const struct spi_flash_ops spi_flash_ops = { | ||||
| 	.read = spi_flash_cmd_read, | ||||
| 	.write = spi_flash_cmd_write_page_program, | ||||
| 	.erase = spi_flash_cmd_erase, | ||||
| 	.status = spi_flash_cmd_status, | ||||
|   | ||||
| @@ -219,6 +219,7 @@ static const struct spansion_spi_flash_params spansion_spi_flash_table[] = { | ||||
| }; | ||||
|  | ||||
| static const struct spi_flash_ops spi_flash_ops = { | ||||
| 	.read = spi_flash_cmd_read, | ||||
| 	.write = spi_flash_cmd_write_page_program, | ||||
| 	.erase = spi_flash_cmd_erase, | ||||
| 	.status = spi_flash_cmd_status, | ||||
|   | ||||
| @@ -127,7 +127,7 @@ int spi_flash_cmd_write(const struct spi_slave *spi, const u8 *cmd, | ||||
|  | ||||
| /* Perform the read operation honoring spi controller fifo size, reissuing | ||||
|  * the read command until the full request completed. */ | ||||
| static int spi_flash_read_chunked(const struct spi_flash *flash, u32 offset, | ||||
| int spi_flash_cmd_read(const struct spi_flash *flash, u32 offset, | ||||
| 				  size_t len, void *buf) | ||||
| { | ||||
| 	u8 cmd[5]; | ||||
| @@ -465,10 +465,7 @@ int spi_flash_probe(unsigned int bus, unsigned int cs, struct spi_flash *flash) | ||||
| int spi_flash_read(const struct spi_flash *flash, u32 offset, size_t len, | ||||
| 		void *buf) | ||||
| { | ||||
| 	if (flash->ops->read) | ||||
| 		return flash->ops->read(flash, offset, len, buf); | ||||
|  | ||||
| 	return spi_flash_read_chunked(flash, offset, len, buf); | ||||
| 	return flash->ops->read(flash, offset, len, buf); | ||||
| } | ||||
|  | ||||
| int spi_flash_write(const struct spi_flash *flash, u32 offset, size_t len, | ||||
|   | ||||
| @@ -66,6 +66,9 @@ int spi_flash_cmd_status(const struct spi_flash *flash, u8 *reg); | ||||
| int spi_flash_cmd_write_page_program(const struct spi_flash *flash, u32 offset, | ||||
| 				size_t len, const void *buf); | ||||
|  | ||||
| /* Read len bytes into buf at offset. */ | ||||
| int spi_flash_cmd_read(const struct spi_flash *flash, u32 offset, size_t len, void *buf); | ||||
|  | ||||
| /* Manufacturer-specific probe functions */ | ||||
| int spi_flash_probe_spansion(const struct spi_slave *spi, u8 *idcode, | ||||
| 			     struct spi_flash *flash); | ||||
|   | ||||
| @@ -55,12 +55,14 @@ static int sst_write_ai(const struct spi_flash *flash, u32 offset, size_t len, | ||||
| 			const void *buf); | ||||
|  | ||||
| static const struct spi_flash_ops spi_flash_ops_write_ai = { | ||||
| 	.read = spi_flash_cmd_read, | ||||
| 	.write = sst_write_ai, | ||||
| 	.erase = spi_flash_cmd_erase, | ||||
| 	.status = spi_flash_cmd_status, | ||||
| }; | ||||
|  | ||||
| static const struct spi_flash_ops spi_flash_ops_write_256 = { | ||||
| 	.read = spi_flash_cmd_read, | ||||
| 	.write = spi_flash_cmd_write_page_program, | ||||
| 	.erase = spi_flash_cmd_erase, | ||||
| 	.status = spi_flash_cmd_status, | ||||
|   | ||||
| @@ -285,6 +285,7 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = { | ||||
| }; | ||||
|  | ||||
| static const struct spi_flash_ops spi_flash_ops = { | ||||
| 	.read = spi_flash_cmd_read, | ||||
| 	.write = spi_flash_cmd_write_page_program, | ||||
| 	.erase = spi_flash_cmd_erase, | ||||
| }; | ||||
|   | ||||
| @@ -611,6 +611,7 @@ winbond_set_write_protection(const struct spi_flash *flash, | ||||
| } | ||||
|  | ||||
| static const struct spi_flash_ops spi_flash_ops = { | ||||
| 	.read = spi_flash_cmd_read, | ||||
| 	.write = spi_flash_cmd_write_page_program, | ||||
| 	.erase = spi_flash_cmd_erase, | ||||
| 	.status = spi_flash_cmd_status, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user