mtd: bcm47xxsflash: use ioremap_cache() instead of KSEG0ADDR()
authorBrian Norris <computersforpeace@gmail.com>
Fri, 26 Feb 2016 10:50:28 +0000 (11:50 +0100)
committerBrian Norris <computersforpeace@gmail.com>
Mon, 4 Apr 2016 07:07:57 +0000 (00:07 -0700)
Using KSEG0ADDR makes code highly MIPS dependent and not portable.
Thanks to the fix a68f376 ("MIPS: io.h: Define `ioremap_cache'") we can
use ioremap_cache which is generic and supported on MIPS as well now.

KSEG0ADDR was translating 0x1c000000 into 0x9c000000. With ioremap_cache
we use MIPS's __ioremap (and then remap_area_pages). This results in
different address (e.g. 0xc0080000) but it still should be cached as
expected and it was successfully tested with BCM47186B0.

Other than that drivers/bcma/driver_chipcommon_sflash.c nicely setups a
struct resource for access window, but we wren't using it. Use it now
and drop duplicated info.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
drivers/bcma/driver_chipcommon_sflash.c
drivers/mtd/devices/bcm47xxsflash.c
drivers/mtd/devices/bcm47xxsflash.h
include/linux/bcma/bcma_driver_chipcommon.h

index 04d706ca5f439be4576c8f78afb4b10a66b5dd3e..35b13a08ca3e6a4f21cd602ecf3d9ab9c328f9f0 100644 (file)
@@ -146,7 +146,6 @@ int bcma_sflash_init(struct bcma_drv_cc *cc)
                return -ENOTSUPP;
        }
 
-       sflash->window = BCMA_SOC_FLASH2;
        sflash->blocksize = e->blocksize;
        sflash->numblocks = e->numblocks;
        sflash->size = sflash->blocksize * sflash->numblocks;
index 347bb83db8642a15320ed65771ca4e58d89da2b1..1c65c15b31a1aaed713363d5430c917754b13f13 100644 (file)
@@ -2,6 +2,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
+#include <linux/ioport.h>
 #include <linux/mtd/mtd.h>
 #include <linux/platform_device.h>
 #include <linux/bcma/bcma.h>
@@ -109,8 +110,7 @@ static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len,
        if ((from + len) > mtd->size)
                return -EINVAL;
 
-       memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(b47s->window + from),
-                     len);
+       memcpy_fromio(buf, b47s->window + from, len);
        *retlen = len;
 
        return len;
@@ -275,15 +275,33 @@ static void bcm47xxsflash_bcma_cc_write(struct bcm47xxsflash *b47s, u16 offset,
 
 static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
 {
-       struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
+       struct device *dev = &pdev->dev;
+       struct bcma_sflash *sflash = dev_get_platdata(dev);
        struct bcm47xxsflash *b47s;
+       struct resource *res;
        int err;
 
-       b47s = devm_kzalloc(&pdev->dev, sizeof(*b47s), GFP_KERNEL);
+       b47s = devm_kzalloc(dev, sizeof(*b47s), GFP_KERNEL);
        if (!b47s)
                return -ENOMEM;
        sflash->priv = b47s;
 
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               dev_err(dev, "invalid resource\n");
+               return -EINVAL;
+       }
+       if (!devm_request_mem_region(dev, res->start, resource_size(res),
+                                    res->name)) {
+               dev_err(dev, "can't request region for resource %pR\n", res);
+               return -EBUSY;
+       }
+       b47s->window = ioremap_cache(res->start, resource_size(res));
+       if (!b47s->window) {
+               dev_err(dev, "ioremap failed for resource %pR\n", res);
+               return -ENOMEM;
+       }
+
        b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
        b47s->cc_read = bcm47xxsflash_bcma_cc_read;
        b47s->cc_write = bcm47xxsflash_bcma_cc_write;
@@ -297,7 +315,6 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
                break;
        }
 
-       b47s->window = sflash->window;
        b47s->blocksize = sflash->blocksize;
        b47s->numblocks = sflash->numblocks;
        b47s->size = sflash->size;
@@ -306,6 +323,7 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
        err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0);
        if (err) {
                pr_err("Failed to register MTD device: %d\n", err);
+               iounmap(b47s->window);
                return err;
        }
 
@@ -321,6 +339,7 @@ static int bcm47xxsflash_bcma_remove(struct platform_device *pdev)
        struct bcm47xxsflash *b47s = sflash->priv;
 
        mtd_device_unregister(&b47s->mtd);
+       iounmap(b47s->window);
 
        return 0;
 }
index fe93daf4f4894a35f2d7b8a65363d1d163d09ffc..1564b62b412e3c071f5f3062e2e992296d531f91 100644 (file)
@@ -65,7 +65,8 @@ struct bcm47xxsflash {
 
        enum bcm47xxsflash_type type;
 
-       u32 window;
+       void __iomem *window;
+
        u32 blocksize;
        u16 numblocks;
        u32 size;
index 846513c73606bd96997015eb115f55fc59e3e39d..a5ac2cad5cb77424ff699429c006e34a0c7da784 100644 (file)
@@ -587,7 +587,6 @@ struct mtd_info;
 
 struct bcma_sflash {
        bool present;
-       u32 window;
        u32 blocksize;
        u16 numblocks;
        u32 size;
This page took 0.027894 seconds and 5 git commands to generate.