aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2017-08-08 16:51:26 -0400
committerMark Brown <broonie@kernel.org>2017-08-09 12:52:54 -0400
commit8447e4781f033f56cb18c2ec0301ea5d207877fc (patch)
tree20b0ad775c4627f94e599848785b2c900a54385c
parent1232978a0dff2d361c3d43cd74e46200c9933466 (diff)
spi: spi-ep93xx: use 32-bit read/write for all registers
All the EP93xx SSP registers are 32-bit. Since most of the upper bits are unused, this driver tries to be tricky and uses 8 or 16-bit I/O to access the registers. This really just adds a bit of confusion. Simplify the I/O by using 32-bit read/write's for all of the registers. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> [chris: use u32 instead of unsigned int] Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/spi/spi-ep93xx.c83
1 files changed, 38 insertions, 45 deletions
diff --git a/drivers/spi/spi-ep93xx.c b/drivers/spi/spi-ep93xx.c
index 49c42a6c2be1..0bd792020471 100644
--- a/drivers/spi/spi-ep93xx.c
+++ b/drivers/spi/spi-ep93xx.c
@@ -113,47 +113,47 @@ struct ep93xx_spi {
113 113
114static int ep93xx_spi_enable(const struct ep93xx_spi *espi) 114static int ep93xx_spi_enable(const struct ep93xx_spi *espi)
115{ 115{
116 u8 regval; 116 u32 val;
117 int err; 117 int err;
118 118
119 err = clk_enable(espi->clk); 119 err = clk_enable(espi->clk);
120 if (err) 120 if (err)
121 return err; 121 return err;
122 122
123 regval = readb(espi->mmio + SSPCR1); 123 val = readl(espi->mmio + SSPCR1);
124 regval |= SSPCR1_SSE; 124 val |= SSPCR1_SSE;
125 writeb(regval, espi->mmio + SSPCR1); 125 writel(val, espi->mmio + SSPCR1);
126 126
127 return 0; 127 return 0;
128} 128}
129 129
130static void ep93xx_spi_disable(const struct ep93xx_spi *espi) 130static void ep93xx_spi_disable(const struct ep93xx_spi *espi)
131{ 131{
132 u8 regval; 132 u32 val;
133 133
134 regval = readb(espi->mmio + SSPCR1); 134 val = readl(espi->mmio + SSPCR1);
135 regval &= ~SSPCR1_SSE; 135 val &= ~SSPCR1_SSE;
136 writeb(regval, espi->mmio + SSPCR1); 136 writel(val, espi->mmio + SSPCR1);
137 137
138 clk_disable(espi->clk); 138 clk_disable(espi->clk);
139} 139}
140 140
141static void ep93xx_spi_enable_interrupts(const struct ep93xx_spi *espi) 141static void ep93xx_spi_enable_interrupts(const struct ep93xx_spi *espi)
142{ 142{
143 u8 regval; 143 u32 val;
144 144
145 regval = readb(espi->mmio + SSPCR1); 145 val = readl(espi->mmio + SSPCR1);
146 regval |= (SSPCR1_RORIE | SSPCR1_TIE | SSPCR1_RIE); 146 val |= (SSPCR1_RORIE | SSPCR1_TIE | SSPCR1_RIE);
147 writeb(regval, espi->mmio + SSPCR1); 147 writel(val, espi->mmio + SSPCR1);
148} 148}
149 149
150static void ep93xx_spi_disable_interrupts(const struct ep93xx_spi *espi) 150static void ep93xx_spi_disable_interrupts(const struct ep93xx_spi *espi)
151{ 151{
152 u8 regval; 152 u32 val;
153 153
154 regval = readb(espi->mmio + SSPCR1); 154 val = readl(espi->mmio + SSPCR1);
155 regval &= ~(SSPCR1_RORIE | SSPCR1_TIE | SSPCR1_RIE); 155 val &= ~(SSPCR1_RORIE | SSPCR1_TIE | SSPCR1_RIE);
156 writeb(regval, espi->mmio + SSPCR1); 156 writel(val, espi->mmio + SSPCR1);
157} 157}
158 158
159/** 159/**
@@ -230,47 +230,41 @@ static int ep93xx_spi_chip_setup(const struct ep93xx_spi *espi,
230 spi->mode, div_cpsr, div_scr, dss); 230 spi->mode, div_cpsr, div_scr, dss);
231 dev_dbg(&espi->pdev->dev, "setup: cr0 %#x\n", cr0); 231 dev_dbg(&espi->pdev->dev, "setup: cr0 %#x\n", cr0);
232 232
233 writeb(div_cpsr, espi->mmio + SSPCPSR); 233 writel(div_cpsr, espi->mmio + SSPCPSR);
234 writew(cr0, espi->mmio + SSPCR0); 234 writel(cr0, espi->mmio + SSPCR0);
235 235
236 return 0; 236 return 0;
237} 237}
238 238
239static void ep93xx_do_write(struct ep93xx_spi *espi, struct spi_transfer *t) 239static void ep93xx_do_write(struct ep93xx_spi *espi, struct spi_transfer *t)
240{ 240{
241 if (t->bits_per_word > 8) { 241 u32 val = 0;
242 u16 tx_val = 0;
243 242
243 if (t->bits_per_word > 8) {
244 if (t->tx_buf) 244 if (t->tx_buf)
245 tx_val = ((u16 *)t->tx_buf)[espi->tx]; 245 val = ((u16 *)t->tx_buf)[espi->tx];
246 writew(tx_val, espi->mmio + SSPDR); 246 espi->tx += 2;
247 espi->tx += sizeof(tx_val);
248 } else { 247 } else {
249 u8 tx_val = 0;
250
251 if (t->tx_buf) 248 if (t->tx_buf)
252 tx_val = ((u8 *)t->tx_buf)[espi->tx]; 249 val = ((u8 *)t->tx_buf)[espi->tx];
253 writeb(tx_val, espi->mmio + SSPDR); 250 espi->tx += 1;
254 espi->tx += sizeof(tx_val);
255 } 251 }
252 writel(val, espi->mmio + SSPDR);
256} 253}
257 254
258static void ep93xx_do_read(struct ep93xx_spi *espi, struct spi_transfer *t) 255static void ep93xx_do_read(struct ep93xx_spi *espi, struct spi_transfer *t)
259{ 256{
260 if (t->bits_per_word > 8) { 257 u32 val;
261 u16 rx_val;
262 258
263 rx_val = readw(espi->mmio + SSPDR); 259 val = readl(espi->mmio + SSPDR);
260 if (t->bits_per_word > 8) {
264 if (t->rx_buf) 261 if (t->rx_buf)
265 ((u16 *)t->rx_buf)[espi->rx] = rx_val; 262 ((u16 *)t->rx_buf)[espi->rx] = val;
266 espi->rx += sizeof(rx_val); 263 espi->rx += 2;
267 } else { 264 } else {
268 u8 rx_val;
269
270 rx_val = readb(espi->mmio + SSPDR);
271 if (t->rx_buf) 265 if (t->rx_buf)
272 ((u8 *)t->rx_buf)[espi->rx] = rx_val; 266 ((u8 *)t->rx_buf)[espi->rx] = val;
273 espi->rx += sizeof(rx_val); 267 espi->rx += 1;
274 } 268 }
275} 269}
276 270
@@ -291,7 +285,7 @@ static int ep93xx_spi_read_write(struct ep93xx_spi *espi)
291 struct spi_transfer *t = msg->state; 285 struct spi_transfer *t = msg->state;
292 286
293 /* read as long as RX FIFO has frames in it */ 287 /* read as long as RX FIFO has frames in it */
294 while ((readb(espi->mmio + SSPSR) & SSPSR_RNE)) { 288 while ((readl(espi->mmio + SSPSR) & SSPSR_RNE)) {
295 ep93xx_do_read(espi, t); 289 ep93xx_do_read(espi, t);
296 espi->fifo_level--; 290 espi->fifo_level--;
297 } 291 }
@@ -593,14 +587,14 @@ static void ep93xx_spi_process_message(struct ep93xx_spi *espi,
593 * Just to be sure: flush any data from RX FIFO. 587 * Just to be sure: flush any data from RX FIFO.
594 */ 588 */
595 timeout = jiffies + msecs_to_jiffies(SPI_TIMEOUT); 589 timeout = jiffies + msecs_to_jiffies(SPI_TIMEOUT);
596 while (readw(espi->mmio + SSPSR) & SSPSR_RNE) { 590 while (readl(espi->mmio + SSPSR) & SSPSR_RNE) {
597 if (time_after(jiffies, timeout)) { 591 if (time_after(jiffies, timeout)) {
598 dev_warn(&espi->pdev->dev, 592 dev_warn(&espi->pdev->dev,
599 "timeout while flushing RX FIFO\n"); 593 "timeout while flushing RX FIFO\n");
600 msg->status = -ETIMEDOUT; 594 msg->status = -ETIMEDOUT;
601 return; 595 return;
602 } 596 }
603 readw(espi->mmio + SSPDR); 597 readl(espi->mmio + SSPDR);
604 } 598 }
605 599
606 /* 600 /*
@@ -649,15 +643,14 @@ static int ep93xx_spi_transfer_one_message(struct spi_master *master,
649static irqreturn_t ep93xx_spi_interrupt(int irq, void *dev_id) 643static irqreturn_t ep93xx_spi_interrupt(int irq, void *dev_id)
650{ 644{
651 struct ep93xx_spi *espi = dev_id; 645 struct ep93xx_spi *espi = dev_id;
652 u8 irq_status = readb(espi->mmio + SSPIIR);
653 646
654 /* 647 /*
655 * If we got ROR (receive overrun) interrupt we know that something is 648 * If we got ROR (receive overrun) interrupt we know that something is
656 * wrong. Just abort the message. 649 * wrong. Just abort the message.
657 */ 650 */
658 if (unlikely(irq_status & SSPIIR_RORIS)) { 651 if (readl(espi->mmio + SSPIIR) & SSPIIR_RORIS) {
659 /* clear the overrun interrupt */ 652 /* clear the overrun interrupt */
660 writeb(0, espi->mmio + SSPICR); 653 writel(0, espi->mmio + SSPICR);
661 dev_warn(&espi->pdev->dev, 654 dev_warn(&espi->pdev->dev,
662 "receive overrun, aborting the message\n"); 655 "receive overrun, aborting the message\n");
663 espi->current_msg->status = -EIO; 656 espi->current_msg->status = -EIO;
@@ -857,7 +850,7 @@ static int ep93xx_spi_probe(struct platform_device *pdev)
857 dev_warn(&pdev->dev, "DMA setup failed. Falling back to PIO\n"); 850 dev_warn(&pdev->dev, "DMA setup failed. Falling back to PIO\n");
858 851
859 /* make sure that the hardware is disabled */ 852 /* make sure that the hardware is disabled */
860 writeb(0, espi->mmio + SSPCR1); 853 writel(0, espi->mmio + SSPCR1);
861 854
862 error = devm_spi_register_master(&pdev->dev, master); 855 error = devm_spi_register_master(&pdev->dev, master);
863 if (error) { 856 if (error) {