summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2015-02-21 00:17:47 +0800
committerJagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>2015-03-30 01:42:49 +0530
commitbb1662760eb0ec2eb88253cb95e2d423b2c2bb44 (patch)
treedb48e3747b87ee8959134966506e70083fb560ff
parent46122960f0e7bac8cbb97bcccf8dc788c3a0beeb (diff)
downloadu-boot-imx-bb1662760eb0ec2eb88253cb95e2d423b2c2bb44.zip
u-boot-imx-bb1662760eb0ec2eb88253cb95e2d423b2c2bb44.tar.gz
u-boot-imx-bb1662760eb0ec2eb88253cb95e2d423b2c2bb44.tar.bz2
spi: cf_spi: Use to_cf_spi_slave to resolve cfslave from slave
Don't assume slave is always the first member of struct cf_spi_slave. Use container_of instead of casting first structure member. Signed-off-by: Axel Lin <axel.lin@ingics.com> Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
-rw-r--r--drivers/spi/cf_spi.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/spi/cf_spi.c b/drivers/spi/cf_spi.c
index 879a809..7453538 100644
--- a/drivers/spi/cf_spi.c
+++ b/drivers/spi/cf_spi.c
@@ -46,6 +46,11 @@ DECLARE_GLOBAL_DATA_PTR;
#define SPI_MODE_MOD 0x00200000
#define SPI_DBLRATE 0x00100000
+static inline struct cf_spi_slave *to_cf_spi_slave(struct spi_slave *slave)
+{
+ return container_of(slave, struct cf_spi_slave, slave);
+}
+
void cfspi_init(void)
{
volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
@@ -105,7 +110,7 @@ u16 cfspi_rx(void)
int cfspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
void *din, ulong flags)
{
- struct cf_spi_slave *cfslave = (struct cf_spi_slave *)slave;
+ struct cf_spi_slave *cfslave = to_cf_spi_slave(slave);
u16 *spi_rd16 = NULL, *spi_wr16 = NULL;
u8 *spi_rd = NULL, *spi_wr = NULL;
static u32 ctrl = 0;
@@ -326,7 +331,9 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
void spi_free_slave(struct spi_slave *slave)
{
- free(slave);
+ struct cf_spi_slave *cfslave = to_cf_spi_slave(slave);
+
+ free(cfslave);
}
int spi_claim_bus(struct spi_slave *slave)