spi: Clean up SPI driver interface
1. Add new structure spi_ctrlr_buses that allows platform to define a mapping from SPI controller to buses managed by the controller. 2. Provide weak implementations of spi_init and spi_setup_slave that will be used by platforms using the new interface. BUG=chrome-os-partner:59832 BRANCH=None TEST=Compiles successfully Change-Id: Ia6f47941b786299f4d823895898ffb1b36e02f73 Signed-off-by: Furquan Shaikh <furquan@chromium.org> Reviewed-on: https://review.coreboot.org/17561 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
committed by
Martin Roth
parent
2dc8b77d0e
commit
b5d41cb063
@ -41,3 +41,38 @@ int spi_xfer(const struct spi_slave *slave, const void *dout, size_t bytesout,
|
|||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void __attribute__((weak)) spi_init(void)
|
||||||
|
{
|
||||||
|
/* Default weak implementation - do nothing. */
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct spi_ctrlr_buses spi_ctrlr_bus_map[0] __attribute__((weak));
|
||||||
|
const size_t spi_ctrlr_bus_map_count __attribute__((weak));
|
||||||
|
|
||||||
|
int __attribute__((weak)) spi_setup_slave(unsigned int bus, unsigned int cs,
|
||||||
|
struct spi_slave *slave)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
memset(slave, 0, sizeof(*slave));
|
||||||
|
|
||||||
|
for (i = 0; i < spi_ctrlr_bus_map_count; i++) {
|
||||||
|
if ((spi_ctrlr_bus_map[i].bus_start <= bus) &&
|
||||||
|
(spi_ctrlr_bus_map[i].bus_end >= bus)) {
|
||||||
|
slave->ctrlr = spi_ctrlr_bus_map[i].ctrlr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slave->ctrlr == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
slave->bus = bus;
|
||||||
|
slave->cs = cs;
|
||||||
|
|
||||||
|
if (slave->ctrlr->setup)
|
||||||
|
return slave->ctrlr->setup(slave);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -42,14 +42,33 @@ struct spi_slave {
|
|||||||
* claim_bus: Claim SPI bus and prepare for communication.
|
* claim_bus: Claim SPI bus and prepare for communication.
|
||||||
* release_bus: Release SPI bus.
|
* release_bus: Release SPI bus.
|
||||||
* xfer: SPI transfer
|
* xfer: SPI transfer
|
||||||
|
* setup: Setup given SPI device bus.
|
||||||
*/
|
*/
|
||||||
struct spi_ctrlr {
|
struct spi_ctrlr {
|
||||||
int (*claim_bus)(const struct spi_slave *slave);
|
int (*claim_bus)(const struct spi_slave *slave);
|
||||||
void (*release_bus)(const struct spi_slave *slave);
|
void (*release_bus)(const struct spi_slave *slave);
|
||||||
int (*xfer)(const struct spi_slave *slave, const void *dout,
|
int (*xfer)(const struct spi_slave *slave, const void *dout,
|
||||||
size_t bytesout, void *din, size_t bytesin);
|
size_t bytesout, void *din, size_t bytesin);
|
||||||
|
int (*setup)(const struct spi_slave *slave);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------
|
||||||
|
* Structure defining mapping of SPI buses to controller.
|
||||||
|
*
|
||||||
|
* ctrlr: Pointer to controller structure managing the given SPI buses.
|
||||||
|
* bus_start: Start bus number managed by the controller.
|
||||||
|
* bus_end: End bus number manager by the controller.
|
||||||
|
*/
|
||||||
|
struct spi_ctrlr_buses {
|
||||||
|
const struct spi_ctrlr *ctrlr;
|
||||||
|
unsigned int bus_start;
|
||||||
|
unsigned int bus_end;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Mapping of SPI buses to controllers - should be defined by platform. */
|
||||||
|
extern const struct spi_ctrlr_buses spi_ctrlr_bus_map[];
|
||||||
|
extern const size_t spi_ctrlr_bus_map_count;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
* Initialization, must be called once on start up.
|
* Initialization, must be called once on start up.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user