From: "Cédric Le Goater" <clg@kaod.org>
To: openbmc@lists.ozlabs.org
Subject: [PATCH v2 linux dev-4.7 7/7] mtd: spi-nor: aspeed: rework io routines
Date: Wed, 9 Nov 2016 09:15:43 +0100 [thread overview]
Message-ID: <1478679343-25354-8-git-send-email-clg@kaod.org> (raw)
In-Reply-To: <1478679343-25354-1-git-send-email-clg@kaod.org>
The io accessors from pflash are shorter and simpler.
Signed-off-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Joel Stanley <joel@jms.id.au>
---
Changes since v1:
- renamed the routine
drivers/mtd/spi-nor/aspeed-smc.c | 112 +++++++++++++--------------------------
1 file changed, 38 insertions(+), 74 deletions(-)
diff --git a/drivers/mtd/spi-nor/aspeed-smc.c b/drivers/mtd/spi-nor/aspeed-smc.c
index 231d4bda4e97..d3bed34f5aa0 100644
--- a/drivers/mtd/spi-nor/aspeed-smc.c
+++ b/drivers/mtd/spi-nor/aspeed-smc.c
@@ -65,84 +65,48 @@ module_param(dma_timeout, uint, 0644);
* the memory buffer pointer and count via explicit code. The final updates
* to len are optimistically suppressed.
*/
-
-static void aspeed_smc_from_fifo(void *buf, const void __iomem *iop, size_t len)
+static int aspeed_smc_read_from_ahb(void *buf, const void __iomem *src,
+ size_t len)
{
- if (!len)
- return;
-
- /* Expect a 4 byte input port. Otherwise just read bytes. */
- if (unlikely((unsigned long)iop & 3)) {
- while (len--) {
- *(u8 *)buf = readb(iop);
- buf++;
+ if ((((unsigned long) src | (unsigned long) buf | len) & 3) == 0) {
+ while (len > 3) {
+ *(u32 *) buf = readl(src);
+ buf += 4;
+ src += 4;
+ len -= 4;
}
}
- /* Align target to word: first byte then half word */
- if ((unsigned long)buf & 1) {
- *(u8 *)buf = readb(iop);
- buf++;
- len--;
- }
- if (((unsigned long)buf & 2) && (len >= 2)) {
- *(u16 *)buf = readw(iop);
- buf += 2;
- len -= 2;
- }
-
- /* Transfer words, then remaining halfword and remaining byte */
- while (len >= 4) {
- *(u32 *)buf = readl(iop);
- buf += 4;
- len -= 4;
- }
- if (len & 2) {
- *(u16 *)buf = readw(iop);
- buf += 2;
+ while (len--) {
+ *(u8 *) buf = readb(src);
+ buf += 1;
+ src += 1;
}
- if (len & 1)
- *(u8 *)buf = readb(iop);
+ return 0;
}
-static void aspeed_smc_to_fifo(void __iomem *iop, const void *buf, size_t len)
+static int aspeed_smc_write_to_ahb(void __iomem *dst, const void *buf,
+ size_t len)
{
- if (!len)
- return;
-
- /* Expect a 4 byte output port. Otherwise just write bytes. */
- if ((unsigned long)iop & 3) {
- while (len--) {
- writeb(*(u8 *)buf, iop);
- buf++;
+ if ((((unsigned long) dst | (unsigned long) buf | len) & 3) == 0) {
+ while (len > 3) {
+ u32 val = *(u32 *) buf;
+
+ writel(val, dst);
+ buf += 4;
+ dst += 4;
+ len -= 4;
}
- return;
}
- /* Align target to word: first byte then half word */
- if ((unsigned long)buf & 1) {
- writeb(*(u8 *)buf, iop);
- buf++;
- len--;
- }
- if (((unsigned long)buf & 2) && (len >= 2)) {
- writew(*(u16 *)buf, iop);
- buf += 2;
- len -= 2;
- }
+ while (len--) {
+ u8 val = *(u8 *) buf;
- /* Transfer words, then remaining halfword and remaining byte */
- while (len >= 4) {
- writel(*(u32 *)buf, iop);
- buf += 4;
- len -= 4;
+ writeb(val, dst);
+ buf += 1;
+ dst += 1;
}
- if (len & 2) {
- writew(*(u16 *)buf, iop);
- buf += 2;
- }
- if (len & 1)
- writeb(*(u8 *)buf, iop);
+ return 0;
}
enum smc_flash_type {
@@ -518,8 +482,8 @@ static int aspeed_smc_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
mutex_lock(&chip->controller->mutex);
aspeed_smc_start_user(nor);
- aspeed_smc_to_fifo(chip->base, &opcode, 1);
- aspeed_smc_from_fifo(buf, chip->base, len);
+ aspeed_smc_write_to_ahb(chip->base, &opcode, 1);
+ aspeed_smc_read_from_ahb(buf, chip->base, len);
aspeed_smc_stop_user(nor);
mutex_unlock(&chip->controller->mutex);
@@ -535,8 +499,8 @@ static int aspeed_smc_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf,
mutex_lock(&chip->controller->mutex);
aspeed_smc_start_user(nor);
- aspeed_smc_to_fifo(chip->base, &opcode, 1);
- aspeed_smc_to_fifo(chip->base, buf, len);
+ aspeed_smc_write_to_ahb(chip->base, &opcode, 1);
+ aspeed_smc_write_to_ahb(chip->base, buf, len);
aspeed_smc_stop_user(nor);
mutex_unlock(&chip->controller->mutex);
@@ -561,12 +525,12 @@ static void aspeed_smc_send_cmd_addr(struct spi_nor *nor, u8 cmd, u32 addr)
cmdaddr |= (u32)cmd << 24;
temp = cpu_to_be32(cmdaddr);
- aspeed_smc_to_fifo(chip->base, &temp, 4);
+ aspeed_smc_write_to_ahb(chip->base, &temp, 4);
break;
case 4:
temp = cpu_to_be32(addr);
- aspeed_smc_to_fifo(chip->base, &cmd, 1);
- aspeed_smc_to_fifo(chip->base, &temp, 4);
+ aspeed_smc_write_to_ahb(chip->base, &cmd, 1);
+ aspeed_smc_write_to_ahb(chip->base, &temp, 4);
break;
}
}
@@ -593,7 +557,7 @@ static int aspeed_smc_read_user(struct spi_nor *nor, loff_t from, size_t len,
aspeed_smc_start_user(nor);
aspeed_smc_send_cmd_addr(nor, nor->read_opcode, from);
- aspeed_smc_from_fifo(read_buf, chip->base, len);
+ aspeed_smc_read_from_ahb(read_buf, chip->base, len);
aspeed_smc_stop_user(nor);
out:
@@ -626,7 +590,7 @@ static void aspeed_smc_write_user(struct spi_nor *nor, loff_t to, size_t len,
aspeed_smc_start_user(nor);
aspeed_smc_send_cmd_addr(nor, nor->program_opcode, to);
- aspeed_smc_to_fifo(chip->base, write_buf, len);
+ aspeed_smc_write_to_ahb(chip->base, write_buf, len);
aspeed_smc_stop_user(nor);
out:
--
2.7.4
next prev parent reply other threads:[~2016-11-09 8:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-09 8:15 [PATCH v2 linux dev-4.7 0/7] Aspeed SMC improvements Cédric Le Goater
2016-11-09 8:15 ` [PATCH v2 linux dev-4.7 1/7] mtd: spi-nor: aspeed: fix setting of the register control value for writes Cédric Le Goater
2016-11-09 23:05 ` Joel Stanley
2016-11-09 8:15 ` [PATCH v2 linux dev-4.7 2/7] mtd: spi-nor: aspeed: improve 4 bytes mode Cédric Le Goater
2016-11-09 23:07 ` Joel Stanley
2016-11-09 8:15 ` [PATCH v2 linux dev-4.7 3/7] mtd: spi-nor: aspeed: extend the bits definitions Cédric Le Goater
2016-11-09 8:15 ` [PATCH v2 linux dev-4.7 4/7] mtd: spi-nor: aspeed: add some logging Cédric Le Goater
2016-11-09 8:15 ` [PATCH v2 linux dev-4.7 5/7] mtd: spi-nor: aspeed: use smc_read mode when doing DMAs Cédric Le Goater
2016-11-09 8:15 ` [PATCH v2 linux dev-4.7 6/7] mtd: spi-nor: aspeed: prepare for fast read Cédric Le Goater
2016-11-09 8:15 ` Cédric Le Goater [this message]
2016-11-10 0:37 ` [PATCH v2 linux dev-4.7 0/7] Aspeed SMC improvements Joel Stanley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478679343-25354-8-git-send-email-clg@kaod.org \
--to=clg@kaod.org \
--cc=openbmc@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.