spi: altera: Use struct-based register access

Zap the offset-based register access and use the struct-based one
as this is the preferred method.

No functional change, but there are some line-over-80 problems in
the driver, which will be addressed later.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chin Liang See <clsee@altera.com>
Cc: Dinh Nguyen <dinguyen@altera.com>
Cc: Albert Aribaud <albert.u.boot@aribaud.net>
Cc: Pavel Machek <pavel@denx.de>
Acked-by: Pavel Machek <pavel@denx.de>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
This commit is contained in:
Marek Vasut 2014-10-22 21:55:58 +02:00 committed by Jagannadha Sutradharudu Teki
parent 0ce4af99c0
commit eef67029d6
1 changed files with 25 additions and 24 deletions

View File

@ -12,11 +12,14 @@
#include <malloc.h> #include <malloc.h>
#include <spi.h> #include <spi.h>
#define ALTERA_SPI_RXDATA 0 struct altera_spi_regs {
#define ALTERA_SPI_TXDATA 4 u32 rxdata;
#define ALTERA_SPI_STATUS 8 u32 txdata;
#define ALTERA_SPI_CONTROL 12 u32 status;
#define ALTERA_SPI_SLAVE_SEL 20 u32 control;
u32 _reserved;
u32 slave_sel;
};
#define ALTERA_SPI_STATUS_ROE_MSK (0x8) #define ALTERA_SPI_STATUS_ROE_MSK (0x8)
#define ALTERA_SPI_STATUS_TOE_MSK (0x10) #define ALTERA_SPI_STATUS_TOE_MSK (0x10)
@ -39,8 +42,8 @@
static ulong altera_spi_base_list[] = CONFIG_SYS_ALTERA_SPI_LIST; static ulong altera_spi_base_list[] = CONFIG_SYS_ALTERA_SPI_LIST;
struct altera_spi_slave { struct altera_spi_slave {
struct spi_slave slave; struct spi_slave slave;
ulong base; struct altera_spi_regs *regs;
}; };
#define to_altera_spi_slave(s) container_of(s, struct altera_spi_slave, slave) #define to_altera_spi_slave(s) container_of(s, struct altera_spi_slave, slave)
@ -54,16 +57,16 @@ __attribute__((weak))
void spi_cs_activate(struct spi_slave *slave) void spi_cs_activate(struct spi_slave *slave)
{ {
struct altera_spi_slave *altspi = to_altera_spi_slave(slave); struct altera_spi_slave *altspi = to_altera_spi_slave(slave);
writel(1 << slave->cs, altspi->base + ALTERA_SPI_SLAVE_SEL); writel(1 << slave->cs, &altspi->regs->slave_sel);
writel(ALTERA_SPI_CONTROL_SSO_MSK, altspi->base + ALTERA_SPI_CONTROL); writel(ALTERA_SPI_CONTROL_SSO_MSK, &altspi->regs->control);
} }
__attribute__((weak)) __attribute__((weak))
void spi_cs_deactivate(struct spi_slave *slave) void spi_cs_deactivate(struct spi_slave *slave)
{ {
struct altera_spi_slave *altspi = to_altera_spi_slave(slave); struct altera_spi_slave *altspi = to_altera_spi_slave(slave);
writel(0, altspi->base + ALTERA_SPI_CONTROL); writel(0, &altspi->regs->control);
writel(0, altspi->base + ALTERA_SPI_SLAVE_SEL); writel(0, &altspi->regs->slave_sel);
} }
void spi_init(void) void spi_init(void)
@ -87,9 +90,9 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
if (!altspi) if (!altspi)
return NULL; return NULL;
altspi->base = altera_spi_base_list[bus]; altspi->regs = (struct altera_spi_regs *)altera_spi_base_list[bus];
debug("%s: bus:%i cs:%i base:%lx\n", __func__, debug("%s: bus:%i cs:%i base:%p\n", __func__,
bus, cs, altspi->base); bus, cs, altspi->regs);
return &altspi->slave; return &altspi->slave;
} }
@ -105,8 +108,8 @@ int spi_claim_bus(struct spi_slave *slave)
struct altera_spi_slave *altspi = to_altera_spi_slave(slave); struct altera_spi_slave *altspi = to_altera_spi_slave(slave);
debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs); debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs);
writel(0, altspi->base + ALTERA_SPI_CONTROL); writel(0, &altspi->regs->control);
writel(0, altspi->base + ALTERA_SPI_SLAVE_SEL); writel(0, &altspi->regs->slave_sel);
return 0; return 0;
} }
@ -115,7 +118,7 @@ void spi_release_bus(struct spi_slave *slave)
struct altera_spi_slave *altspi = to_altera_spi_slave(slave); struct altera_spi_slave *altspi = to_altera_spi_slave(slave);
debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs); debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs);
writel(0, altspi->base + ALTERA_SPI_SLAVE_SEL); writel(0, &altspi->regs->slave_sel);
} }
#ifndef CONFIG_ALTERA_SPI_IDLE_VAL #ifndef CONFIG_ALTERA_SPI_IDLE_VAL
@ -142,20 +145,18 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
} }
/* empty read buffer */ /* empty read buffer */
if (readl(altspi->base + ALTERA_SPI_STATUS) & if (readl(&altspi->regs->status) & ALTERA_SPI_STATUS_RRDY_MSK)
ALTERA_SPI_STATUS_RRDY_MSK) readl(&altspi->regs->rxdata);
readl(altspi->base + ALTERA_SPI_RXDATA);
if (flags & SPI_XFER_BEGIN) if (flags & SPI_XFER_BEGIN)
spi_cs_activate(slave); spi_cs_activate(slave);
while (bytes--) { while (bytes--) {
uchar d = txp ? *txp++ : CONFIG_ALTERA_SPI_IDLE_VAL; uchar d = txp ? *txp++ : CONFIG_ALTERA_SPI_IDLE_VAL;
debug("%s: tx:%x ", __func__, d); debug("%s: tx:%x ", __func__, d);
writel(d, altspi->base + ALTERA_SPI_TXDATA); writel(d, &altspi->regs->txdata);
while (!(readl(altspi->base + ALTERA_SPI_STATUS) & while (!(readl(&altspi->regs->status) & ALTERA_SPI_STATUS_RRDY_MSK))
ALTERA_SPI_STATUS_RRDY_MSK))
; ;
d = readl(altspi->base + ALTERA_SPI_RXDATA); d = readl(&altspi->regs->rxdata);
if (rxp) if (rxp)
*rxp++ = d; *rxp++ = d;
debug("rx:%x\n", d); debug("rx:%x\n", d);