From 36b81af9e8ecea2bf58aae9a421720ed10f61b82 Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Thu, 1 Dec 2016 01:02:44 -0800 Subject: spi: Pass pointer to spi_slave structure in spi_setup_slave For spi_setup_slave, instead of making the platform driver return a pointer to spi_slave structure, pass in a structure pointer that can be filled in by the driver as required. This removes the need for platform drivers to maintain a slave structure in data/CAR section. BUG=chrome-os-partner:59832 BRANCH=None TEST=Compiles successfully Change-Id: Ia15a4f88ef4dcfdf616bb1c22261e7cb642a7573 Signed-off-by: Furquan Shaikh Reviewed-on: https://review.coreboot.org/17683 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- src/soc/qualcomm/ipq806x/include/soc/spi.h | 5 ----- src/soc/qualcomm/ipq806x/spi.c | 32 ++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 11 deletions(-) (limited to 'src/soc/qualcomm/ipq806x') diff --git a/src/soc/qualcomm/ipq806x/include/soc/spi.h b/src/soc/qualcomm/ipq806x/include/soc/spi.h index 5dedcdafba..98a15b8c30 100644 --- a/src/soc/qualcomm/ipq806x/include/soc/spi.h +++ b/src/soc/qualcomm/ipq806x/include/soc/spi.h @@ -271,9 +271,4 @@ struct ipq_spi_slave { int allocated; }; -static inline struct ipq_spi_slave *to_ipq_spi(const struct spi_slave *slave) -{ - return container_of(slave, struct ipq_spi_slave, slave); -} - #endif /* _IPQ806X_SPI_H_ */ diff --git a/src/soc/qualcomm/ipq806x/spi.c b/src/soc/qualcomm/ipq806x/spi.c index d1af7201fa..81dc508cd7 100644 --- a/src/soc/qualcomm/ipq806x/spi.c +++ b/src/soc/qualcomm/ipq806x/spi.c @@ -499,7 +499,26 @@ void spi_init() memset(spi_slave_pool, 0, sizeof(spi_slave_pool)); } -struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs) +static struct ipq_spi_slave *to_ipq_spi(const struct spi_slave *slave) +{ + struct ipq_spi_slave *ds; + size_t i; + + for (i = 0; i < ARRAY_SIZE(spi_slave_pool); i++) { + ds = spi_slave_pool + i; + + if (!ds->allocated) + continue; + + if ((ds->slave.bus == slave->bus) && + (ds->slave.cs == slave->cs)) + return ds; + } + + return NULL; +} + +int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave) { struct ipq_spi_slave *ds = NULL; int i; @@ -521,9 +540,10 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs) if (spi_slave_pool[i].allocated) continue; ds = spi_slave_pool + i; - ds->slave.bus = bus; - ds->slave.cs = cs; - ds->regs = &spi_reg[bus]; + + ds->slave.bus = slave->bus = bus; + ds->slave.cs = slave->cs = cs; + ds->regs = &spi_reg[bus]; /* * TODO(vbendeb): @@ -534,11 +554,11 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs) ds->mode = GSBI_SPI_MODE_0; ds->allocated = 1; - return &ds->slave; + return 0; } printk(BIOS_ERR, "SPI error: all %d pools busy\n", i); - return NULL; + return -1; } /* -- cgit v1.2.3