1 From 5651d6aaf489d1db48c253cf884b40214e91c2c5 Mon Sep 17 00:00:00 2001
2 From: Brian Norris <computersforpeace@gmail.com>
3 Date: Fri, 26 Feb 2016 11:50:28 +0100
4 Subject: [PATCH] mtd: bcm47xxsflash: use ioremap_cache() instead of
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 Using KSEG0ADDR makes code highly MIPS dependent and not portable.
11 Thanks to the fix a68f376 ("MIPS: io.h: Define `ioremap_cache'") we can
12 use ioremap_cache which is generic and supported on MIPS as well now.
14 KSEG0ADDR was translating 0x1c000000 into 0x9c000000. With ioremap_cache
15 we use MIPS's __ioremap (and then remap_area_pages). This results in
16 different address (e.g. 0xc0080000) but it still should be cached as
17 expected and it was successfully tested with BCM47186B0.
19 Other than that drivers/bcma/driver_chipcommon_sflash.c nicely setups a
20 struct resource for access window, but we wren't using it. Use it now
21 and drop duplicated info.
23 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
24 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
27 --- a/drivers/bcma/driver_chipcommon_sflash.c
28 +++ b/drivers/bcma/driver_chipcommon_sflash.c
29 @@ -146,7 +146,6 @@ int bcma_sflash_init(struct bcma_drv_cc
33 - sflash->window = BCMA_SOC_FLASH2;
34 sflash->blocksize = e->blocksize;
35 sflash->numblocks = e->numblocks;
36 sflash->size = sflash->blocksize * sflash->numblocks;
37 --- a/drivers/mtd/devices/bcm47xxsflash.c
38 +++ b/drivers/mtd/devices/bcm47xxsflash.c
40 #include <linux/module.h>
41 #include <linux/slab.h>
42 #include <linux/delay.h>
43 +#include <linux/ioport.h>
44 #include <linux/mtd/mtd.h>
45 #include <linux/platform_device.h>
46 #include <linux/bcma/bcma.h>
47 @@ -109,8 +110,7 @@ static int bcm47xxsflash_read(struct mtd
48 if ((from + len) > mtd->size)
51 - memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(b47s->window + from),
53 + memcpy_fromio(buf, b47s->window + from, len);
57 @@ -275,15 +275,33 @@ static void bcm47xxsflash_bcma_cc_write(
59 static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
61 - struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
62 + struct device *dev = &pdev->dev;
63 + struct bcma_sflash *sflash = dev_get_platdata(dev);
64 struct bcm47xxsflash *b47s;
65 + struct resource *res;
68 - b47s = devm_kzalloc(&pdev->dev, sizeof(*b47s), GFP_KERNEL);
69 + b47s = devm_kzalloc(dev, sizeof(*b47s), GFP_KERNEL);
74 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
76 + dev_err(dev, "invalid resource\n");
79 + if (!devm_request_mem_region(dev, res->start, resource_size(res),
81 + dev_err(dev, "can't request region for resource %pR\n", res);
84 + b47s->window = ioremap_cache(res->start, resource_size(res));
85 + if (!b47s->window) {
86 + dev_err(dev, "ioremap failed for resource %pR\n", res);
90 b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
91 b47s->cc_read = bcm47xxsflash_bcma_cc_read;
92 b47s->cc_write = bcm47xxsflash_bcma_cc_write;
93 @@ -297,7 +315,6 @@ static int bcm47xxsflash_bcma_probe(stru
97 - b47s->window = sflash->window;
98 b47s->blocksize = sflash->blocksize;
99 b47s->numblocks = sflash->numblocks;
100 b47s->size = sflash->size;
101 @@ -306,6 +323,7 @@ static int bcm47xxsflash_bcma_probe(stru
102 err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0);
104 pr_err("Failed to register MTD device: %d\n", err);
105 + iounmap(b47s->window);
109 @@ -321,6 +339,7 @@ static int bcm47xxsflash_bcma_remove(str
110 struct bcm47xxsflash *b47s = sflash->priv;
112 mtd_device_unregister(&b47s->mtd);
113 + iounmap(b47s->window);
117 --- a/drivers/mtd/devices/bcm47xxsflash.h
118 +++ b/drivers/mtd/devices/bcm47xxsflash.h
119 @@ -65,7 +65,8 @@ struct bcm47xxsflash {
121 enum bcm47xxsflash_type type;
124 + void __iomem *window;
129 --- a/include/linux/bcma/bcma_driver_chipcommon.h
130 +++ b/include/linux/bcma/bcma_driver_chipcommon.h
131 @@ -585,7 +585,6 @@ struct bcma_pflash {
132 #ifdef CONFIG_BCMA_SFLASH