Commit c039dd27 authored by Jarkko Nikula's avatar Jarkko Nikula Committed by Mark Brown

spi: pxa2xx: Cleanup register access macros

Currently SSP registers are accessed by having an own read and write macros
for each register. For instance read_SSSR(iobase) and write_SSSR(iobase).

In my opinion this hurts readability and requires new macros to be defined
for each new added register. Let's define and use instead common
pxa2xx_spi_read() and pxa2xx_spi_write() accessors.
Signed-off-by: default avatarJarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 8e8dd9fb
...@@ -111,23 +111,24 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data, ...@@ -111,23 +111,24 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data,
* by using ->dma_running. * by using ->dma_running.
*/ */
if (atomic_dec_and_test(&drv_data->dma_running)) { if (atomic_dec_and_test(&drv_data->dma_running)) {
void __iomem *reg = drv_data->ioaddr;
/* /*
* If the other CPU is still handling the ROR interrupt we * If the other CPU is still handling the ROR interrupt we
* might not know about the error yet. So we re-check the * might not know about the error yet. So we re-check the
* ROR bit here before we clear the status register. * ROR bit here before we clear the status register.
*/ */
if (!error) { if (!error) {
u32 status = read_SSSR(reg) & drv_data->mask_sr; u32 status = pxa2xx_spi_read(drv_data, SSSR)
& drv_data->mask_sr;
error = status & SSSR_ROR; error = status & SSSR_ROR;
} }
/* Clear status & disable interrupts */ /* Clear status & disable interrupts */
write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg); pxa2xx_spi_write(drv_data, SSCR1,
pxa2xx_spi_read(drv_data, SSCR1)
& ~drv_data->dma_cr1);
write_SSSR_CS(drv_data, drv_data->clear_sr); write_SSSR_CS(drv_data, drv_data->clear_sr);
if (!pxa25x_ssp_comp(drv_data)) if (!pxa25x_ssp_comp(drv_data))
write_SSTO(0, reg); pxa2xx_spi_write(drv_data, SSTO, 0);
if (!error) { if (!error) {
pxa2xx_spi_unmap_dma_buffers(drv_data); pxa2xx_spi_unmap_dma_buffers(drv_data);
...@@ -139,7 +140,9 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data, ...@@ -139,7 +140,9 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data,
msg->state = pxa2xx_spi_next_transfer(drv_data); msg->state = pxa2xx_spi_next_transfer(drv_data);
} else { } else {
/* In case we got an error we disable the SSP now */ /* In case we got an error we disable the SSP now */
write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg); pxa2xx_spi_write(drv_data, SSCR0,
pxa2xx_spi_read(drv_data, SSCR0)
& ~SSCR0_SSE);
msg->state = ERROR_STATE; msg->state = ERROR_STATE;
} }
...@@ -247,7 +250,7 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data) ...@@ -247,7 +250,7 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data)
{ {
u32 status; u32 status;
status = read_SSSR(drv_data->ioaddr) & drv_data->mask_sr; status = pxa2xx_spi_read(drv_data, SSSR) & drv_data->mask_sr;
if (status & SSSR_ROR) { if (status & SSSR_ROR) {
dev_err(&drv_data->pdev->dev, "FIFO overrun\n"); dev_err(&drv_data->pdev->dev, "FIFO overrun\n");
......
...@@ -122,7 +122,7 @@ static int wait_ssp_rx_stall(struct driver_data *drv_data) ...@@ -122,7 +122,7 @@ static int wait_ssp_rx_stall(struct driver_data *drv_data)
{ {
unsigned long limit = loops_per_jiffy << 1; unsigned long limit = loops_per_jiffy << 1;
while ((read_SSSR(drv_data->ioaddr) & SSSR_BSY) && --limit) while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY) && --limit)
cpu_relax(); cpu_relax();
return limit; return limit;
...@@ -141,17 +141,18 @@ static int wait_dma_channel_stop(int channel) ...@@ -141,17 +141,18 @@ static int wait_dma_channel_stop(int channel)
static void pxa2xx_spi_dma_error_stop(struct driver_data *drv_data, static void pxa2xx_spi_dma_error_stop(struct driver_data *drv_data,
const char *msg) const char *msg)
{ {
void __iomem *reg = drv_data->ioaddr;
/* Stop and reset */ /* Stop and reset */
DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL; DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL; DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
write_SSSR_CS(drv_data, drv_data->clear_sr); write_SSSR_CS(drv_data, drv_data->clear_sr);
write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg); pxa2xx_spi_write(drv_data, SSCR1,
pxa2xx_spi_read(drv_data, SSCR1)
& ~drv_data->dma_cr1);
if (!pxa25x_ssp_comp(drv_data)) if (!pxa25x_ssp_comp(drv_data))
write_SSTO(0, reg); pxa2xx_spi_write(drv_data, SSTO, 0);
pxa2xx_spi_flush(drv_data); pxa2xx_spi_flush(drv_data);
write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg); pxa2xx_spi_write(drv_data, SSCR0,
pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
pxa2xx_spi_unmap_dma_buffers(drv_data); pxa2xx_spi_unmap_dma_buffers(drv_data);
...@@ -163,11 +164,12 @@ static void pxa2xx_spi_dma_error_stop(struct driver_data *drv_data, ...@@ -163,11 +164,12 @@ static void pxa2xx_spi_dma_error_stop(struct driver_data *drv_data,
static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data) static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data)
{ {
void __iomem *reg = drv_data->ioaddr;
struct spi_message *msg = drv_data->cur_msg; struct spi_message *msg = drv_data->cur_msg;
/* Clear and disable interrupts on SSP and DMA channels*/ /* Clear and disable interrupts on SSP and DMA channels*/
write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg); pxa2xx_spi_write(drv_data, SSCR1,
pxa2xx_spi_read(drv_data, SSCR1)
& ~drv_data->dma_cr1);
write_SSSR_CS(drv_data, drv_data->clear_sr); write_SSSR_CS(drv_data, drv_data->clear_sr);
DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL; DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL; DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
...@@ -240,9 +242,8 @@ void pxa2xx_spi_dma_handler(int channel, void *data) ...@@ -240,9 +242,8 @@ void pxa2xx_spi_dma_handler(int channel, void *data)
irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data) irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data)
{ {
u32 irq_status; u32 irq_status;
void __iomem *reg = drv_data->ioaddr;
irq_status = read_SSSR(reg) & drv_data->mask_sr; irq_status = pxa2xx_spi_read(drv_data, SSSR) & drv_data->mask_sr;
if (irq_status & SSSR_ROR) { if (irq_status & SSSR_ROR) {
pxa2xx_spi_dma_error_stop(drv_data, pxa2xx_spi_dma_error_stop(drv_data,
"dma_transfer: fifo overrun"); "dma_transfer: fifo overrun");
...@@ -252,7 +253,7 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data) ...@@ -252,7 +253,7 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data)
/* Check for false positive timeout */ /* Check for false positive timeout */
if ((irq_status & SSSR_TINT) if ((irq_status & SSSR_TINT)
&& (DCSR(drv_data->tx_channel) & DCSR_RUN)) { && (DCSR(drv_data->tx_channel) & DCSR_RUN)) {
write_SSSR(SSSR_TINT, reg); pxa2xx_spi_write(drv_data, SSSR, SSSR_TINT);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -261,7 +262,7 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data) ...@@ -261,7 +262,7 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data)
/* Clear and disable timeout interrupt, do the rest in /* Clear and disable timeout interrupt, do the rest in
* dma_transfer_complete */ * dma_transfer_complete */
if (!pxa25x_ssp_comp(drv_data)) if (!pxa25x_ssp_comp(drv_data))
write_SSTO(0, reg); pxa2xx_spi_write(drv_data, SSTO, 0);
/* finish this transfer, start the next */ /* finish this transfer, start the next */
pxa2xx_spi_dma_transfer_complete(drv_data); pxa2xx_spi_dma_transfer_complete(drv_data);
......
This diff is collapsed.
...@@ -115,23 +115,17 @@ struct chip_data { ...@@ -115,23 +115,17 @@ struct chip_data {
void (*cs_control)(u32 command); void (*cs_control)(u32 command);
}; };
#define DEFINE_SSP_REG(reg, off) \ static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data,
static inline u32 read_##reg(void const __iomem *p) \ unsigned reg)
{ return __raw_readl(p + (off)); } \ {
\ return __raw_readl(drv_data->ioaddr + reg);
static inline void write_##reg(u32 v, void __iomem *p) \ }
{ __raw_writel(v, p + (off)); }
static inline void pxa2xx_spi_write(const struct driver_data *drv_data,
DEFINE_SSP_REG(SSCR0, 0x00) unsigned reg, u32 val)
DEFINE_SSP_REG(SSCR1, 0x04) {
DEFINE_SSP_REG(SSSR, 0x08) __raw_writel(val, drv_data->ioaddr + reg);
DEFINE_SSP_REG(SSITR, 0x0c) }
DEFINE_SSP_REG(SSDR, 0x10)
DEFINE_SSP_REG(DDS_RATE, 0x28) /* DDS Clock Rate */
DEFINE_SSP_REG(SSTO, 0x28)
DEFINE_SSP_REG(SSPSP, 0x2c)
DEFINE_SSP_REG(SSITF, SSITF)
DEFINE_SSP_REG(SSIRF, SSIRF)
#define START_STATE ((void *)0) #define START_STATE ((void *)0)
#define RUNNING_STATE ((void *)1) #define RUNNING_STATE ((void *)1)
...@@ -155,13 +149,11 @@ static inline int pxa25x_ssp_comp(struct driver_data *drv_data) ...@@ -155,13 +149,11 @@ static inline int pxa25x_ssp_comp(struct driver_data *drv_data)
static inline void write_SSSR_CS(struct driver_data *drv_data, u32 val) static inline void write_SSSR_CS(struct driver_data *drv_data, u32 val)
{ {
void __iomem *reg = drv_data->ioaddr;
if (drv_data->ssp_type == CE4100_SSP || if (drv_data->ssp_type == CE4100_SSP ||
drv_data->ssp_type == QUARK_X1000_SSP) drv_data->ssp_type == QUARK_X1000_SSP)
val |= read_SSSR(reg) & SSSR_ALT_FRM_MASK; val |= pxa2xx_spi_read(drv_data, SSSR) & SSSR_ALT_FRM_MASK;
write_SSSR(val, reg); pxa2xx_spi_write(drv_data, SSSR, val);
} }
extern int pxa2xx_spi_flush(struct driver_data *drv_data); extern int pxa2xx_spi_flush(struct driver_data *drv_data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment