mirror of
				https://review.coreboot.org/flashrom.git
				synced 2025-11-04 07:00:39 +01:00 
			
		
		
		
	bitbang_spi.c: Reorder functions with primitives at the top
Reshuffle file with no semantic changes, this avoids unnecessary prototypes for static member functions as to be an easier implementation to parse. BUG=none TEST=builds Change-Id: Ided41c6c64376e0cddeb17b936773a86c36d5f72 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/47664 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Sam McNally <sammc@google.com>
This commit is contained in:
		
				
					committed by
					
						
						Edward O'Callaghan
					
				
			
			
				
	
			
			
			
						parent
						
							b2b4507657
						
					
				
				
					commit
					36e5bd3c21
				
			@@ -64,57 +64,6 @@ static int bitbang_spi_set_sck_get_miso(const struct bitbang_spi_master * const
 | 
				
			|||||||
	return master->get_miso();
 | 
						return master->get_miso();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int bitbang_spi_send_command(const struct flashctx *flash,
 | 
					 | 
				
			||||||
				    unsigned int writecnt, unsigned int readcnt,
 | 
					 | 
				
			||||||
				    const unsigned char *writearr,
 | 
					 | 
				
			||||||
				    unsigned char *readarr);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const struct spi_master spi_master_bitbang = {
 | 
					 | 
				
			||||||
	.features	= SPI_MASTER_4BA,
 | 
					 | 
				
			||||||
	.max_data_read	= MAX_DATA_READ_UNLIMITED,
 | 
					 | 
				
			||||||
	.max_data_write	= MAX_DATA_WRITE_UNLIMITED,
 | 
					 | 
				
			||||||
	.command	= bitbang_spi_send_command,
 | 
					 | 
				
			||||||
	.multicommand	= default_spi_send_multicommand,
 | 
					 | 
				
			||||||
	.read		= default_spi_read,
 | 
					 | 
				
			||||||
	.write_256	= default_spi_write_256,
 | 
					 | 
				
			||||||
	.write_aai	= default_spi_write_aai,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if 0 // until it is needed
 | 
					 | 
				
			||||||
static int bitbang_spi_shutdown(const struct bitbang_spi_master *master)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	/* FIXME: Run bitbang_spi_release_bus here or per command? */
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int register_spi_bitbang_master(const struct bitbang_spi_master *master)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct spi_master mst = spi_master_bitbang;
 | 
					 | 
				
			||||||
	/* If someone forgot to initialize a bitbang function, we catch it here. */
 | 
					 | 
				
			||||||
	if (!master || !master->set_cs ||
 | 
					 | 
				
			||||||
	    !master->set_sck || !master->set_mosi || !master->get_miso ||
 | 
					 | 
				
			||||||
	    (master->request_bus && !master->release_bus) ||
 | 
					 | 
				
			||||||
	    (!master->request_bus && master->release_bus)) {
 | 
					 | 
				
			||||||
		msg_perr("Incomplete SPI bitbang master setting!\n"
 | 
					 | 
				
			||||||
			 "Please report a bug at flashrom@flashrom.org\n");
 | 
					 | 
				
			||||||
		return ERROR_FLASHROM_BUG;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	mst.data = master;
 | 
					 | 
				
			||||||
	register_spi_master(&mst);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Only mess with the bus if we're sure nobody else uses it. */
 | 
					 | 
				
			||||||
	bitbang_spi_request_bus(master);
 | 
					 | 
				
			||||||
	bitbang_spi_set_cs(master, 1);
 | 
					 | 
				
			||||||
	bitbang_spi_set_sck_set_mosi(master, 0, 0);
 | 
					 | 
				
			||||||
	/* FIXME: Release SPI bus here and request it again for each command or
 | 
					 | 
				
			||||||
	 * don't release it now and only release it on programmer shutdown?
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	bitbang_spi_release_bus(master);
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static uint8_t bitbang_spi_read_byte(const struct bitbang_spi_master *master)
 | 
					static uint8_t bitbang_spi_read_byte(const struct bitbang_spi_master *master)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint8_t ret = 0;
 | 
						uint8_t ret = 0;
 | 
				
			||||||
@@ -173,3 +122,49 @@ static int bitbang_spi_send_command(const struct flashctx *flash,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const struct spi_master spi_master_bitbang = {
 | 
				
			||||||
 | 
						.features	= SPI_MASTER_4BA,
 | 
				
			||||||
 | 
						.max_data_read	= MAX_DATA_READ_UNLIMITED,
 | 
				
			||||||
 | 
						.max_data_write	= MAX_DATA_WRITE_UNLIMITED,
 | 
				
			||||||
 | 
						.command	= bitbang_spi_send_command,
 | 
				
			||||||
 | 
						.multicommand	= default_spi_send_multicommand,
 | 
				
			||||||
 | 
						.read		= default_spi_read,
 | 
				
			||||||
 | 
						.write_256	= default_spi_write_256,
 | 
				
			||||||
 | 
						.write_aai	= default_spi_write_aai,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if 0 // until it is needed
 | 
				
			||||||
 | 
					static int bitbang_spi_shutdown(const struct bitbang_spi_master *master)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						/* FIXME: Run bitbang_spi_release_bus here or per command? */
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int register_spi_bitbang_master(const struct bitbang_spi_master *master)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct spi_master mst = spi_master_bitbang;
 | 
				
			||||||
 | 
						/* If someone forgot to initialize a bitbang function, we catch it here. */
 | 
				
			||||||
 | 
						if (!master || !master->set_cs ||
 | 
				
			||||||
 | 
						    !master->set_sck || !master->set_mosi || !master->get_miso ||
 | 
				
			||||||
 | 
						    (master->request_bus && !master->release_bus) ||
 | 
				
			||||||
 | 
						    (!master->request_bus && master->release_bus)) {
 | 
				
			||||||
 | 
							msg_perr("Incomplete SPI bitbang master setting!\n"
 | 
				
			||||||
 | 
								 "Please report a bug at flashrom@flashrom.org\n");
 | 
				
			||||||
 | 
							return ERROR_FLASHROM_BUG;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mst.data = master;
 | 
				
			||||||
 | 
						register_spi_master(&mst);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Only mess with the bus if we're sure nobody else uses it. */
 | 
				
			||||||
 | 
						bitbang_spi_request_bus(master);
 | 
				
			||||||
 | 
						bitbang_spi_set_cs(master, 1);
 | 
				
			||||||
 | 
						bitbang_spi_set_sck_set_mosi(master, 0, 0);
 | 
				
			||||||
 | 
						/* FIXME: Release SPI bus here and request it again for each command or
 | 
				
			||||||
 | 
						 * don't release it now and only release it on programmer shutdown?
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						bitbang_spi_release_bus(master);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user