summaryrefslogtreecommitdiff
path: root/src/soc
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@chromium.org>2016-12-01 01:02:44 -0800
committerFurquan Shaikh <furquan@google.com>2016-12-05 03:28:06 +0100
commit36b81af9e8ecea2bf58aae9a421720ed10f61b82 (patch)
tree05e7329c67bf009531c12052db105ac55ce015b8 /src/soc
parent0dba0254ea31eca41fdef88783f1dd192ac6fa56 (diff)
downloadcoreboot-36b81af9e8ecea2bf58aae9a421720ed10f61b82.tar.xz
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 <furquan@chromium.org> Reviewed-on: https://review.coreboot.org/17683 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/soc')
-rw-r--r--src/soc/broadcom/cygnus/spi.c18
-rw-r--r--src/soc/imgtec/pistachio/spi.c46
-rw-r--r--src/soc/intel/apollolake/spi.c9
-rw-r--r--src/soc/intel/baytrail/spi.c13
-rw-r--r--src/soc/intel/braswell/spi.c13
-rw-r--r--src/soc/intel/broadwell/spi.c13
-rw-r--r--src/soc/intel/fsp_baytrail/spi.c13
-rw-r--r--src/soc/intel/fsp_broadwell_de/spi.c13
-rw-r--r--src/soc/intel/skylake/flash_controller.c9
-rw-r--r--src/soc/marvell/armada38x/spi.c8
-rw-r--r--src/soc/marvell/bg4cd/spi.c4
-rw-r--r--src/soc/mediatek/mt8173/spi.c22
-rw-r--r--src/soc/nvidia/tegra124/spi.c9
-rw-r--r--src/soc/nvidia/tegra210/spi.c9
-rw-r--r--src/soc/qualcomm/ipq40xx/include/soc/spi.h5
-rw-r--r--src/soc/qualcomm/ipq40xx/spi.c34
-rw-r--r--src/soc/qualcomm/ipq806x/include/soc/spi.h5
-rw-r--r--src/soc/qualcomm/ipq806x/spi.c32
-rw-r--r--src/soc/rockchip/common/spi.c20
-rw-r--r--src/soc/samsung/exynos5420/spi.c13
20 files changed, 150 insertions, 158 deletions
diff --git a/src/soc/broadcom/cygnus/spi.c b/src/soc/broadcom/cygnus/spi.c
index 13b69765b2..810f2c266c 100644
--- a/src/soc/broadcom/cygnus/spi.c
+++ b/src/soc/broadcom/cygnus/spi.c
@@ -76,9 +76,6 @@
/* QSPI private data */
struct qspi_priv {
- /* Slave entry */
- struct spi_slave slave;
-
/* Specified SPI parameters */
unsigned int max_hz;
unsigned int spi_mode;
@@ -94,16 +91,19 @@ struct qspi_priv {
static struct qspi_priv qspi_slave;
-/* Macro to get the private data */
-#define to_qspi_slave(s) container_of(s, struct qspi_priv, slave)
+static struct qspi_priv *to_qspi_slave(const struct spi_slave *slave)
+{
+ return &qspi_slave;
+}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
struct qspi_priv *priv = &qspi_slave;
unsigned int spbr;
- priv->slave.bus = bus;
- priv->slave.cs = cs;
+ slave->bus = bus;
+ slave->cs = cs;
+
priv->max_hz = QSPI_MAX_HZ;
priv->spi_mode = QSPI_MODE;
priv->reg = (void *)(IPROC_QSPI_BASE);
@@ -129,7 +129,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
(8 << 2) | /* 8 bits per word */
(priv->spi_mode & 3)); /* mode: CPOL / CPHA */
- return &priv->slave;
+ return 0;
}
static int mspi_enable(struct qspi_priv *priv)
diff --git a/src/soc/imgtec/pistachio/spi.c b/src/soc/imgtec/pistachio/spi.c
index 307aec9ec8..86c452a55a 100644
--- a/src/soc/imgtec/pistachio/spi.c
+++ b/src/soc/imgtec/pistachio/spi.c
@@ -30,7 +30,6 @@
#define IMGTEC_SPI_MAX_TRANSFER_SIZE ((1 << 16) - 1)
struct img_spi_slave {
- struct spi_slave slave;
/* SPIM instance device parameters */
struct spim_device_parameters device_parameters;
/* SPIM instance base address */
@@ -59,13 +58,20 @@ static int wait_status(u32 reg, u32 shift)
return SPIM_OK;
}
+static struct img_spi_slave *get_img_slave(const struct spi_slave *slave)
+{
+ return img_spi_slaves + slave->bus * SPIM_NUM_PORTS_PER_BLOCK +
+ slave->cs;
+}
+
/* Transmitter function. Fills TX FIFO with data before enabling SPIM */
static int transmitdata(const struct spi_slave *slave, u8 *buffer, u32 size)
{
u32 blocksize, base, write_data;
int ret;
+ struct img_spi_slave *img_slave = get_img_slave(slave);
- base = container_of(slave, struct img_spi_slave, slave)->base;
+ base = img_slave->base;
while (size) {
/* Wait until FIFO empty */
write32(base + SPFI_INT_CLEAR_REG_OFFSET, SPFI_SDE_MASK);
@@ -101,8 +107,9 @@ static int receivedata(const struct spi_slave *slave, u8 *buffer, u32 size)
{
u32 read_data, base;
int ret;
+ struct img_spi_slave *img_slave = get_img_slave(slave);
- base = container_of(slave, struct img_spi_slave, slave)->base;
+ base = img_slave->base;
/*
* Do 32bit reads first. Clear status GDEX32BIT here so that the first
* status reg. read gets the actual bit state
@@ -145,10 +152,10 @@ static void setparams(const struct spi_slave *slave, u32 port,
struct spim_device_parameters *params)
{
u32 spim_parameters, port_state, base;
+ struct img_spi_slave *img_slave = get_img_slave(slave);
+ base = img_slave->base;
spim_parameters = 0;
-
- base = container_of(slave, struct img_spi_slave, slave)->base;
port_state = read32(base + SPFI_PORT_STATE_REG_OFFSET);
port_state &= ~((SPIM_PORT0_MASK>>port)|SPFI_PORT_SELECT_MASK);
port_state |= params->cs_idle_level<<(SPIM_CS0_IDLE_SHIFT-port);
@@ -250,7 +257,9 @@ static u32 control_reg_setup(struct spim_buffer *first,
static int check_buffers(const struct spi_slave *slave, struct spim_buffer *first,
struct spim_buffer *second){
- if (!(container_of(slave, struct img_spi_slave, slave)->initialised))
+ struct img_spi_slave *img_slave = get_img_slave(slave);
+
+ if (!(img_slave->initialised))
return -SPIM_API_NOT_INITIALISED;
/*
* First operation must always be defined
@@ -331,8 +340,9 @@ static int spim_io(const struct spi_slave *slave, struct spim_buffer *first,
u32 reg, base;
int i, trans_count, ret;
struct spim_buffer *transaction[2];
+ struct img_spi_slave *img_slave = get_img_slave(slave);
- base = container_of(slave, struct img_spi_slave, slave)->base;
+ base = img_slave->base;
ret = check_buffers(slave, first, second);
if (ret)
@@ -412,11 +422,9 @@ void spi_init(void)
}
/* Set up communications parameters for a SPI slave. */
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
-
struct img_spi_slave *img_slave = NULL;
- struct spi_slave *slave;
struct spim_device_parameters *device_parameters;
u32 base;
@@ -430,21 +438,21 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
default:
printk(BIOS_ERR, "%s: Error: unsupported bus.\n",
__func__);
- return NULL;
+ return -1;
}
if (cs > SPIM_DEVICE4) {
printk(BIOS_ERR, "%s: Error: unsupported chipselect.\n",
__func__);
- return NULL;
+ return -1;
}
- img_slave = img_spi_slaves + bus * SPIM_NUM_PORTS_PER_BLOCK + cs;
- slave = &(img_slave->slave);
+ slave->bus = bus;
+ slave->cs = cs;
+
+ img_slave = get_img_slave(slave);
device_parameters = &(img_slave->device_parameters);
img_slave->base = base;
- slave->bus = bus;
- slave->cs = cs;
device_parameters->bitrate = 64;
device_parameters->cs_setup = 0;
@@ -455,7 +463,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
device_parameters->data_idle_level = 0;
img_slave->initialised = IMG_FALSE;
- return slave;
+ return 0;
}
/* Claim the bus and prepare it for communication */
@@ -469,7 +477,7 @@ int spi_claim_bus(const struct spi_slave *slave)
__func__);
return -SPIM_API_NOT_INITIALISED;
}
- img_slave = container_of(slave, struct img_spi_slave, slave);
+ img_slave = get_img_slave(slave);
if (img_slave->initialised)
return SPIM_OK;
/* Check device parameters */
@@ -499,7 +507,7 @@ void spi_release_bus(const struct spi_slave *slave)
__func__);
return;
}
- img_slave = container_of(slave, struct img_spi_slave, slave);
+ img_slave = get_img_slave(slave);
img_slave->initialised = IMG_FALSE;
/* Soft reset peripheral internals */
write32(img_slave->base + SPFI_CONTROL_REG_OFFSET,
diff --git a/src/soc/intel/apollolake/spi.c b/src/soc/intel/apollolake/spi.c
index 6e873f45c8..ca56702dcf 100644
--- a/src/soc/intel/apollolake/spi.c
+++ b/src/soc/intel/apollolake/spi.c
@@ -344,7 +344,6 @@ static int nuclear_spi_status(const struct spi_flash *flash, uint8_t *reg)
return ret;
}
-static struct spi_slave boot_spi CAR_GLOBAL;
static struct spi_flash boot_flash CAR_GLOBAL;
/*
@@ -391,20 +390,18 @@ struct spi_flash *spi_flash_programmer_probe(struct spi_slave *spi, int force)
return flash;
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
BOILERPLATE_CREATE_CTX(ctx);
/* This is special hardware. We expect bus 0 and CS line 0 here. */
if ((bus != 0) || (cs != 0))
- return NULL;
-
- struct spi_slave *slave = car_get_var_ptr(&boot_spi);
+ return -1;
slave->bus = bus;
slave->cs = cs;
- return slave;
+ return 0;
}
int spi_read_status(uint8_t *status)
diff --git a/src/soc/intel/baytrail/spi.c b/src/soc/intel/baytrail/spi.c
index 13f88067eb..b4f95aa832 100644
--- a/src/soc/intel/baytrail/spi.c
+++ b/src/soc/intel/baytrail/spi.c
@@ -260,20 +260,11 @@ static void ich_set_bbar(uint32_t minaddr)
writel_(ichspi_bbar, cntlr.bbar);
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
- ich_spi_slave *slave = malloc(sizeof(*slave));
-
- if (!slave) {
- printk(BIOS_DEBUG, "ICH SPI: Bad allocation\n");
- return NULL;
- }
-
- memset(slave, 0, sizeof(*slave));
-
slave->bus = bus;
slave->cs = cs;
- return slave;
+ return 0;
}
static ich9_spi_regs *spi_regs(void)
diff --git a/src/soc/intel/braswell/spi.c b/src/soc/intel/braswell/spi.c
index 34e031b1cd..4236e6ff50 100644
--- a/src/soc/intel/braswell/spi.c
+++ b/src/soc/intel/braswell/spi.c
@@ -229,20 +229,11 @@ static void read_reg(void *src, void *value, uint32_t size)
}
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
- ich_spi_slave *slave = malloc(sizeof(*slave));
-
- if (!slave) {
- printk(BIOS_ERR, "ICH SPI: Bad allocation\n");
- return NULL;
- }
-
- memset(slave, 0, sizeof(*slave));
-
slave->bus = bus;
slave->cs = cs;
- return slave;
+ return 0;
}
static ich9_spi_regs *spi_regs(void)
diff --git a/src/soc/intel/broadwell/spi.c b/src/soc/intel/broadwell/spi.c
index 6aa7dd33a8..5220970532 100644
--- a/src/soc/intel/broadwell/spi.c
+++ b/src/soc/intel/broadwell/spi.c
@@ -259,20 +259,11 @@ static void ich_set_bbar(uint32_t minaddr)
writel_(ichspi_bbar, cntlr.bbar);
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
- ich_spi_slave *slave = malloc(sizeof(*slave));
-
- if (!slave) {
- printk(BIOS_DEBUG, "ICH SPI: Bad allocation\n");
- return NULL;
- }
-
- memset(slave, 0, sizeof(*slave));
-
slave->bus = bus;
slave->cs = cs;
- return slave;
+ return 0;
}
void spi_init(void)
diff --git a/src/soc/intel/fsp_baytrail/spi.c b/src/soc/intel/fsp_baytrail/spi.c
index 232366c63b..06b160c8b5 100644
--- a/src/soc/intel/fsp_baytrail/spi.c
+++ b/src/soc/intel/fsp_baytrail/spi.c
@@ -249,20 +249,11 @@ static void read_reg(const void *src, void *value, uint32_t size)
}
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
- ich_spi_slave *slave = malloc(sizeof(*slave));
-
- if (!slave) {
- printk(BIOS_DEBUG, "ICH SPI: Bad allocation\n");
- return NULL;
- }
-
- memset(slave, 0, sizeof(*slave));
-
slave->bus = bus;
slave->cs = cs;
- return slave;
+ return 0;
}
static ich9_spi_regs *spi_regs(void)
diff --git a/src/soc/intel/fsp_broadwell_de/spi.c b/src/soc/intel/fsp_broadwell_de/spi.c
index c38fbce7b7..8af56860fa 100644
--- a/src/soc/intel/fsp_broadwell_de/spi.c
+++ b/src/soc/intel/fsp_broadwell_de/spi.c
@@ -259,20 +259,11 @@ static void ich_set_bbar(uint32_t minaddr)
writel_(ichspi_bbar, cntlr.bbar);
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave * slave)
{
- ich_spi_slave *slave = malloc(sizeof(*slave));
-
- if (!slave) {
- printk(BIOS_DEBUG, "ICH SPI: Bad allocation\n");
- return NULL;
- }
-
- memset(slave, 0, sizeof(*slave));
-
slave->bus = bus;
slave->cs = cs;
- return slave;
+ return 0;
}
void spi_init(void)
diff --git a/src/soc/intel/skylake/flash_controller.c b/src/soc/intel/skylake/flash_controller.c
index 8aee796218..734d9d3532 100644
--- a/src/soc/intel/skylake/flash_controller.c
+++ b/src/soc/intel/skylake/flash_controller.c
@@ -342,7 +342,6 @@ int pch_hwseq_read_status(const struct spi_flash *flash, u8 *reg)
return 0;
}
-static struct spi_slave boot_spi CAR_GLOBAL;
static struct spi_flash boot_flash CAR_GLOBAL;
struct spi_flash *spi_flash_programmer_probe(struct spi_slave *spi, int force)
@@ -370,18 +369,16 @@ struct spi_flash *spi_flash_programmer_probe(struct spi_slave *spi, int force)
return flash;
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
/* This is special hardware. We expect bus 0 and CS line 0 here. */
if ((bus != 0) || (cs != 0))
- return NULL;
-
- struct spi_slave *slave = car_get_var_ptr(&boot_spi);
+ return -1;
slave->bus = bus;
slave->cs = cs;
- return slave;
+ return 0;
}
int spi_flash_get_fpr_info(struct fpr_info *info)
diff --git a/src/soc/marvell/armada38x/spi.c b/src/soc/marvell/armada38x/spi.c
index af0a279133..8f9686793f 100644
--- a/src/soc/marvell/armada38x/spi.c
+++ b/src/soc/marvell/armada38x/spi.c
@@ -153,8 +153,6 @@ static MV_SPI_TYPE_INFO spi_types[] = { {.en16_bit = MV_TRUE,
param define end
*******************************************************************************/
-static struct spi_slave s_spi;
-
static int mv_spi_baud_rate_set(unsigned char spi_id,
unsigned int serial_baud_rate);
static void mv_spi_cs_deassert(unsigned char spi_id);
@@ -444,14 +442,12 @@ static int mrvl_spi_xfer(const struct spi_slave *slave,
return 0;
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
- struct spi_slave *slave = &s_spi;
-
slave->bus = bus;
slave->cs = cs;
mv_spi_sys_init(bus, cs, CONFIG_SF_DEFAULT_SPEED);
- return slave;
+ return 0;
}
int spi_claim_bus(const struct spi_slave *slave)
diff --git a/src/soc/marvell/bg4cd/spi.c b/src/soc/marvell/bg4cd/spi.c
index 9a999b049c..54161bcf33 100644
--- a/src/soc/marvell/bg4cd/spi.c
+++ b/src/soc/marvell/bg4cd/spi.c
@@ -15,9 +15,9 @@
#include <stddef.h>
#include <spi-generic.h>
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
- return NULL;
+ return -1;
}
int spi_claim_bus(const struct spi_slave *slave)
diff --git a/src/soc/mediatek/mt8173/spi.c b/src/soc/mediatek/mt8173/spi.c
index f60de6c32b..d6bcc0bd0a 100644
--- a/src/soc/mediatek/mt8173/spi.c
+++ b/src/soc/mediatek/mt8173/spi.c
@@ -47,9 +47,6 @@ enum {
static struct mtk_spi_bus spi_bus[1] = {
{
- .slave = {
- .bus = 0,
- },
.regs = (void *)SPI_BASE,
.state = MTK_SPI_IDLE,
}
@@ -57,7 +54,8 @@ static struct mtk_spi_bus spi_bus[1] = {
static inline struct mtk_spi_bus *to_mtk_spi(const struct spi_slave *slave)
{
- return container_of(slave, struct mtk_spi_bus, slave);
+ assert(slave->bus < ARRAY_SIZE(spi_bus));
+ return &spi_bus[slave->bus];
}
static void spi_sw_reset(struct mtk_spi_regs *regs)
@@ -162,24 +160,26 @@ static void mtk_spi_dump_data(const char *name, const uint8_t *data,
#endif
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
struct mtk_spi_bus *eslave;
- static struct spi_slave slave;
switch (bus) {
case CONFIG_EC_GOOGLE_CHROMEEC_SPI_BUS:
- eslave = &spi_bus[bus];
+ slave->bus = bus;
+ slave->cs = cs;
+ eslave = to_mtk_spi(slave);
assert(read32(&eslave->regs->spi_cfg0_reg) != 0);
spi_sw_reset(eslave->regs);
- return &eslave->slave;
+ return 0;
case CONFIG_BOOT_DEVICE_SPI_FLASH_BUS:
- slave.bus = bus;
- slave.cs = cs;
- return &slave;
+ slave->bus = bus;
+ slave->cs = cs;
+ return 0;
default:
die ("wrong bus number.\n");
};
+ return -1;
}
int spi_claim_bus(const struct spi_slave *slave)
diff --git a/src/soc/nvidia/tegra124/spi.c b/src/soc/nvidia/tegra124/spi.c
index 2ad4aa1f85..0cb48657d6 100644
--- a/src/soc/nvidia/tegra124/spi.c
+++ b/src/soc/nvidia/tegra124/spi.c
@@ -798,11 +798,14 @@ int spi_xfer(const struct spi_slave *slave, const void *dout,
return ret;
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
struct tegra_spi_channel *channel = to_tegra_spi(bus);
if (!channel)
- return NULL;
+ return -1;
- return &channel->slave;
+ slave->bus = channel->slave.bus;
+ slave->cs = channel->slave.cs;
+
+ return 0;
}
diff --git a/src/soc/nvidia/tegra210/spi.c b/src/soc/nvidia/tegra210/spi.c
index 7efefc44fe..3a2dd17230 100644
--- a/src/soc/nvidia/tegra210/spi.c
+++ b/src/soc/nvidia/tegra210/spi.c
@@ -834,11 +834,14 @@ int spi_xfer(const struct spi_slave *slave, const void *dout,
return ret;
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
struct tegra_spi_channel *channel = to_tegra_spi(bus);
if (!channel)
- return NULL;
+ return -1;
- return &channel->slave;
+ slave->cs = channel->slave.cs;
+ slave->bus = channel->slave.bus;
+
+ return 0;
}
diff --git a/src/soc/qualcomm/ipq40xx/include/soc/spi.h b/src/soc/qualcomm/ipq40xx/include/soc/spi.h
index 8ef1fbf69d..b91e6ca28f 100644
--- a/src/soc/qualcomm/ipq40xx/include/soc/spi.h
+++ b/src/soc/qualcomm/ipq40xx/include/soc/spi.h
@@ -186,9 +186,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 /* _IPQ40XX_SPI_H_ */
diff --git a/src/soc/qualcomm/ipq40xx/spi.c b/src/soc/qualcomm/ipq40xx/spi.c
index 871f24b254..cda3bea7e6 100644
--- a/src/soc/qualcomm/ipq40xx/spi.c
+++ b/src/soc/qualcomm/ipq40xx/spi.c
@@ -207,7 +207,26 @@ void spi_init(void)
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;
@@ -218,16 +237,17 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
printk(BIOS_ERR,
"SPI error: unsupported bus %d (Supported busses 0, 1 and 2) "
"or chipselect\n", bus);
- return NULL;
+ return -1;
}
for (i = 0; i < ARRAY_SIZE(spi_slave_pool); i++) {
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):
@@ -238,11 +258,11 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
ds->mode = SPI_MODE3;
ds->allocated = 1;
- return &ds->slave;
+ return 0;
}
printk(BIOS_ERR, "SPI error: all %d pools busy\n", i);
- return NULL;
+ return -1;
}
/*
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;
}
/*
diff --git a/src/soc/rockchip/common/spi.c b/src/soc/rockchip/common/spi.c
index 8f45679dfc..85597f2b79 100644
--- a/src/soc/rockchip/common/spi.c
+++ b/src/soc/rockchip/common/spi.c
@@ -27,7 +27,6 @@
#include <timer.h>
struct rockchip_spi_slave {
- struct spi_slave slave;
struct rockchip_spi *regs;
};
@@ -37,30 +36,24 @@ struct rockchip_spi_slave {
static struct rockchip_spi_slave rockchip_spi_slaves[] = {
{
- .slave = { .bus = 0, },
.regs = (void *)SPI0_BASE,
},
{
- .slave = { .bus = 1, },
.regs = (void *)SPI1_BASE,
},
{
- .slave = { .bus = 2, },
.regs = (void *)SPI2_BASE,
},
#ifdef SPI3_BASE
{
- .slave = { .bus = 3, },
.regs = (void *)SPI3_BASE,
},
#ifdef SPI4_BASE
{
- .slave = { .bus = 4, },
.regs = (void *)SPI4_BASE,
},
#ifdef SPI5_BASE
{
- .slave = { .bus = 5, },
.regs = (void *)SPI5_BASE,
},
#endif
@@ -70,13 +63,18 @@ static struct rockchip_spi_slave rockchip_spi_slaves[] = {
static struct rockchip_spi_slave *to_rockchip_spi(const struct spi_slave *slave)
{
- return container_of(slave, struct rockchip_spi_slave, slave);
+ assert(slave->bus < ARRAY_SIZE(rockchip_spi_slaves));
+ return &rockchip_spi_slaves[slave->bus];
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
- assert(bus >= 0 && bus < ARRAY_SIZE(rockchip_spi_slaves));
- return &(rockchip_spi_slaves[bus].slave);
+ assert(bus < ARRAY_SIZE(rockchip_spi_slaves));
+
+ slave->bus = bus;
+ slave->cs = cs;
+
+ return 0;
}
static void spi_cs_activate(const struct spi_slave *slave)
diff --git a/src/soc/samsung/exynos5420/spi.c b/src/soc/samsung/exynos5420/spi.c
index c2faeb5198..5dbe024f71 100644
--- a/src/soc/samsung/exynos5420/spi.c
+++ b/src/soc/samsung/exynos5420/spi.c
@@ -60,7 +60,7 @@ static struct exynos_spi_slave exynos_spi_slaves[3] = {
static inline struct exynos_spi_slave *to_exynos_spi(const struct spi_slave *slave)
{
- return container_of(slave, struct exynos_spi_slave, slave);
+ return &exynos_spi_slaves[slave->bus];
}
static void spi_sw_reset(struct exynos_spi *regs, int word)
@@ -117,15 +117,20 @@ static void exynos_spi_init(struct exynos_spi *regs)
spi_sw_reset(regs, 1);
}
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs)
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
ASSERT(bus >= 0 && bus < 3);
- struct exynos_spi_slave *eslave = &exynos_spi_slaves[bus];
+ struct exynos_spi_slave *eslave;
+
+ slave->bus = bus;
+ slave->cs = cs;
+
+ eslave = to_exynos_spi(slave);
if (!eslave->initialized) {
exynos_spi_init(eslave->regs);
eslave->initialized = 1;
}
- return &eslave->slave;
+ return 0;
}
int spi_claim_bus(const struct spi_slave *slave)