Commit ba03e483 authored by Boris Brezillon's avatar Boris Brezillon Committed by Miquel Raynal

mtd: rawnand: cs553x: Stop using chip->legacy.IO_ADDR_{R, W}

Now that we have our own controller struct we can keep the MMIO pointer
in there and use instead of using the chip->legacy.IO_ADDR_{R,W} fields.
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20200501090650.1138200-3-boris.brezillon@collabora.com
parent c9e1817f
...@@ -92,51 +92,66 @@ ...@@ -92,51 +92,66 @@
struct cs553x_nand_controller { struct cs553x_nand_controller {
struct nand_controller base; struct nand_controller base;
struct nand_chip chip; struct nand_chip chip;
void __iomem *mmio;
}; };
static struct cs553x_nand_controller *
to_cs553x(struct nand_controller *controller)
{
return container_of(controller, struct cs553x_nand_controller, base);
}
static void cs553x_read_buf(struct nand_chip *this, u_char *buf, int len) static void cs553x_read_buf(struct nand_chip *this, u_char *buf, int len)
{ {
struct cs553x_nand_controller *cs553x = to_cs553x(this->controller);
while (unlikely(len > 0x800)) { while (unlikely(len > 0x800)) {
memcpy_fromio(buf, this->legacy.IO_ADDR_R, 0x800); memcpy_fromio(buf, cs553x->mmio, 0x800);
buf += 0x800; buf += 0x800;
len -= 0x800; len -= 0x800;
} }
memcpy_fromio(buf, this->legacy.IO_ADDR_R, len); memcpy_fromio(buf, cs553x->mmio, len);
} }
static void cs553x_write_buf(struct nand_chip *this, const u_char *buf, int len) static void cs553x_write_buf(struct nand_chip *this, const u_char *buf, int len)
{ {
struct cs553x_nand_controller *cs553x = to_cs553x(this->controller);
while (unlikely(len > 0x800)) { while (unlikely(len > 0x800)) {
memcpy_toio(this->legacy.IO_ADDR_R, buf, 0x800); memcpy_toio(cs553x->mmio, buf, 0x800);
buf += 0x800; buf += 0x800;
len -= 0x800; len -= 0x800;
} }
memcpy_toio(this->legacy.IO_ADDR_R, buf, len); memcpy_toio(cs553x->mmio, buf, len);
} }
static unsigned char cs553x_read_byte(struct nand_chip *this) static unsigned char cs553x_read_byte(struct nand_chip *this)
{ {
return readb(this->legacy.IO_ADDR_R); struct cs553x_nand_controller *cs553x = to_cs553x(this->controller);
return readb(cs553x->mmio);
} }
static void cs553x_write_byte(struct nand_chip *this, u_char byte) static void cs553x_write_byte(struct nand_chip *this, u_char byte)
{ {
struct cs553x_nand_controller *cs553x = to_cs553x(this->controller);
int i = 100000; int i = 100000;
while (i && readb(this->legacy.IO_ADDR_R + MM_NAND_STS) & CS_NAND_CTLR_BUSY) { while (i && readb(cs553x->mmio + MM_NAND_STS) & CS_NAND_CTLR_BUSY) {
udelay(1); udelay(1);
i--; i--;
} }
writeb(byte, this->legacy.IO_ADDR_W + 0x801); writeb(byte, cs553x->mmio + 0x801);
} }
static void cs553x_hwcontrol(struct nand_chip *this, int cmd, static void cs553x_hwcontrol(struct nand_chip *this, int cmd,
unsigned int ctrl) unsigned int ctrl)
{ {
void __iomem *mmio_base = this->legacy.IO_ADDR_R; struct cs553x_nand_controller *cs553x = to_cs553x(this->controller);
if (ctrl & NAND_CTRL_CHANGE) { if (ctrl & NAND_CTRL_CHANGE) {
unsigned char ctl = (ctrl & ~NAND_CTRL_CHANGE ) ^ 0x01; unsigned char ctl = (ctrl & ~NAND_CTRL_CHANGE ) ^ 0x01;
writeb(ctl, mmio_base + MM_NAND_CTL); writeb(ctl, cs553x->mmio + MM_NAND_CTL);
} }
if (cmd != NAND_CMD_NONE) if (cmd != NAND_CMD_NONE)
cs553x_write_byte(this, cmd); cs553x_write_byte(this, cmd);
...@@ -144,26 +159,26 @@ static void cs553x_hwcontrol(struct nand_chip *this, int cmd, ...@@ -144,26 +159,26 @@ static void cs553x_hwcontrol(struct nand_chip *this, int cmd,
static int cs553x_device_ready(struct nand_chip *this) static int cs553x_device_ready(struct nand_chip *this)
{ {
void __iomem *mmio_base = this->legacy.IO_ADDR_R; struct cs553x_nand_controller *cs553x = to_cs553x(this->controller);
unsigned char foo = readb(mmio_base + MM_NAND_STS); unsigned char foo = readb(cs553x->mmio + MM_NAND_STS);
return (foo & CS_NAND_STS_FLASH_RDY) && !(foo & CS_NAND_CTLR_BUSY); return (foo & CS_NAND_STS_FLASH_RDY) && !(foo & CS_NAND_CTLR_BUSY);
} }
static void cs_enable_hwecc(struct nand_chip *this, int mode) static void cs_enable_hwecc(struct nand_chip *this, int mode)
{ {
void __iomem *mmio_base = this->legacy.IO_ADDR_R; struct cs553x_nand_controller *cs553x = to_cs553x(this->controller);
writeb(0x07, mmio_base + MM_NAND_ECC_CTL); writeb(0x07, cs553x->mmio + MM_NAND_ECC_CTL);
} }
static int cs_calculate_ecc(struct nand_chip *this, const u_char *dat, static int cs_calculate_ecc(struct nand_chip *this, const u_char *dat,
u_char *ecc_code) u_char *ecc_code)
{ {
struct cs553x_nand_controller *cs553x = to_cs553x(this->controller);
uint32_t ecc; uint32_t ecc;
void __iomem *mmio_base = this->legacy.IO_ADDR_R;
ecc = readl(mmio_base + MM_NAND_STS); ecc = readl(cs553x->mmio + MM_NAND_STS);
ecc_code[1] = ecc >> 8; ecc_code[1] = ecc >> 8;
ecc_code[0] = ecc >> 16; ecc_code[0] = ecc >> 16;
...@@ -204,8 +219,8 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr) ...@@ -204,8 +219,8 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr)
new_mtd->owner = THIS_MODULE; new_mtd->owner = THIS_MODULE;
/* map physical address */ /* map physical address */
this->legacy.IO_ADDR_R = this->legacy.IO_ADDR_W = ioremap(adr, 4096); controller->mmio = ioremap(adr, 4096);
if (!this->legacy.IO_ADDR_R) { if (!controller->mmio) {
pr_warn("ioremap cs553x NAND @0x%08lx failed\n", adr); pr_warn("ioremap cs553x NAND @0x%08lx failed\n", adr);
err = -EIO; err = -EIO;
goto out_mtd; goto out_mtd;
...@@ -247,7 +262,7 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr) ...@@ -247,7 +262,7 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr)
out_free: out_free:
kfree(new_mtd->name); kfree(new_mtd->name);
out_ior: out_ior:
iounmap(this->legacy.IO_ADDR_R); iounmap(controller->mmio);
out_mtd: out_mtd:
kfree(controller); kfree(controller);
out: out:
...@@ -322,7 +337,6 @@ static void __exit cs553x_cleanup(void) ...@@ -322,7 +337,6 @@ static void __exit cs553x_cleanup(void)
int i; int i;
for (i = 0; i < NR_CS553X_CONTROLLERS; i++) { for (i = 0; i < NR_CS553X_CONTROLLERS; i++) {
void __iomem *mmio_base;
struct cs553x_nand_controller *controller = controllers[i]; struct cs553x_nand_controller *controller = controllers[i];
struct nand_chip *this = &controller->chip; struct nand_chip *this = &controller->chip;
struct mtd_info *mtd = nand_to_mtd(this); struct mtd_info *mtd = nand_to_mtd(this);
...@@ -330,16 +344,13 @@ static void __exit cs553x_cleanup(void) ...@@ -330,16 +344,13 @@ static void __exit cs553x_cleanup(void)
if (!mtd) if (!mtd)
continue; continue;
this = mtd_to_nand(mtd);
mmio_base = this->legacy.IO_ADDR_R;
/* Release resources, unregister device */ /* Release resources, unregister device */
nand_release(this); nand_release(this);
kfree(mtd->name); kfree(mtd->name);
controllers[i] = NULL; controllers[i] = NULL;
/* unmap physical address */ /* unmap physical address */
iounmap(mmio_base); iounmap(controller->mmio);
/* Free the MTD device structure */ /* Free the MTD device structure */
kfree(controller); kfree(controller);
......
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