kernel: Add support spi-nor, Eon EN25QH32
[openwrt/openwrt.git] / target / linux / generic / pending-4.4 / 042-0001-mtd-bcm47xxsflash-use-ioremap_cache-instead-of-KSEG0.patch
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
5 KSEG0ADDR()
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
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.
13
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.
18
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.
22
23 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
24 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
25 ---
26
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
30 return -ENOTSUPP;
31 }
32
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
39 @@ -2,6 +2,7 @@
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)
49 return -EINVAL;
50
51 - memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(b47s->window + from),
52 - len);
53 + memcpy_fromio(buf, b47s->window + from, len);
54 *retlen = len;
55
56 return len;
57 @@ -275,15 +275,33 @@ static void bcm47xxsflash_bcma_cc_write(
58
59 static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
60 {
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;
66 int err;
67
68 - b47s = devm_kzalloc(&pdev->dev, sizeof(*b47s), GFP_KERNEL);
69 + b47s = devm_kzalloc(dev, sizeof(*b47s), GFP_KERNEL);
70 if (!b47s)
71 return -ENOMEM;
72 sflash->priv = b47s;
73
74 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
75 + if (!res) {
76 + dev_err(dev, "invalid resource\n");
77 + return -EINVAL;
78 + }
79 + if (!devm_request_mem_region(dev, res->start, resource_size(res),
80 + res->name)) {
81 + dev_err(dev, "can't request region for resource %pR\n", res);
82 + return -EBUSY;
83 + }
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);
87 + return -ENOMEM;
88 + }
89 +
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
94 break;
95 }
96
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);
103 if (err) {
104 pr_err("Failed to register MTD device: %d\n", err);
105 + iounmap(b47s->window);
106 return err;
107 }
108
109 @@ -321,6 +339,7 @@ static int bcm47xxsflash_bcma_remove(str
110 struct bcm47xxsflash *b47s = sflash->priv;
111
112 mtd_device_unregister(&b47s->mtd);
113 + iounmap(b47s->window);
114
115 return 0;
116 }
117 --- a/drivers/mtd/devices/bcm47xxsflash.h
118 +++ b/drivers/mtd/devices/bcm47xxsflash.h
119 @@ -65,7 +65,8 @@ struct bcm47xxsflash {
120
121 enum bcm47xxsflash_type type;
122
123 - u32 window;
124 + void __iomem *window;
125 +
126 u32 blocksize;
127 u16 numblocks;
128 u32 size;
129 --- a/include/linux/bcma/bcma_driver_chipcommon.h
130 +++ b/include/linux/bcma/bcma_driver_chipcommon.h
131 @@ -588,7 +588,6 @@ struct bcma_pflash {
132 #ifdef CONFIG_BCMA_SFLASH
133 struct bcma_sflash {
134 bool present;
135 - u32 window;
136 u32 blocksize;
137 u16 numblocks;
138 u32 size;