diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c index 506e9edf5c85af..89d74a1eff4f26 100644 --- a/drivers/mtd/devices/phram.c +++ b/drivers/mtd/devices/phram.c @@ -34,6 +34,7 @@ struct phram_mtd_list { struct mtd_info mtd; struct list_head list; + bool cached; }; static LIST_HEAD(phram_list); @@ -96,6 +97,7 @@ static int register_device(struct platform_device *pdev, const char *name, phys_addr_t start, size_t len, uint32_t erasesize) { struct device_node *np = pdev ? pdev->dev.of_node : NULL; + bool cached = np ? !of_property_read_bool(np, "no-map") : false; struct phram_mtd_list *new; int ret = -ENOMEM; @@ -103,8 +105,13 @@ static int register_device(struct platform_device *pdev, const char *name, if (!new) goto out0; + new->cached = cached; + ret = -EIO; - new->mtd.priv = ioremap(start, len); + if (cached) + new->mtd.priv = memremap(start, len, MEMREMAP_WB); + else + new->mtd.priv = ioremap(start, len); if (!new->mtd.priv) { pr_err("ioremap failed\n"); goto out1; @@ -140,7 +147,7 @@ static int register_device(struct platform_device *pdev, const char *name, return 0; out2: - iounmap(new->mtd.priv); + cached ? memunmap(new->mtd.priv) : iounmap(new->mtd.priv); out1: kfree(new); out0: @@ -362,7 +369,7 @@ static int phram_remove(struct platform_device *pdev) struct phram_mtd_list *phram = platform_get_drvdata(pdev); mtd_device_unregister(&phram->mtd); - iounmap(phram->mtd.priv); + phram->cached ? memunmap(phram->mtd.priv) : iounmap(phram->mtd.priv); kfree(phram); return 0;