Skip to content

Commit 5651d6a

Browse files
mtd: bcm47xxsflash: use ioremap_cache() instead of KSEG0ADDR()
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>
1 parent fddcca5 commit 5651d6a

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

‎drivers/bcma/driver_chipcommon_sflash.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ int bcma_sflash_init(struct bcma_drv_cc *cc)
146146
return -ENOTSUPP;
147147
}
148148

149-
sflash->window = BCMA_SOC_FLASH2;
150149
sflash->blocksize = e->blocksize;
151150
sflash->numblocks = e->numblocks;
152151
sflash->size = sflash->blocksize * sflash->numblocks;

‎drivers/mtd/devices/bcm47xxsflash.c‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <linux/module.h>
33
#include <linux/slab.h>
44
#include <linux/delay.h>
5+
#include <linux/ioport.h>
56
#include <linux/mtd/mtd.h>
67
#include <linux/platform_device.h>
78
#include <linux/bcma/bcma.h>
@@ -109,8 +110,7 @@ static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len,
109110
if ((from + len) > mtd->size)
110111
return -EINVAL;
111112

112-
memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(b47s->window + from),
113-
len);
113+
memcpy_fromio(buf, b47s->window + from, len);
114114
*retlen = len;
115115

116116
return len;
@@ -275,15 +275,33 @@ static void bcm47xxsflash_bcma_cc_write(struct bcm47xxsflash *b47s, u16 offset,
275275

276276
static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
277277
{
278-
struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
278+
struct device *dev = &pdev->dev;
279+
struct bcma_sflash *sflash = dev_get_platdata(dev);
279280
struct bcm47xxsflash *b47s;
281+
struct resource *res;
280282
int err;
281283

282-
b47s = devm_kzalloc(&pdev->dev, sizeof(*b47s), GFP_KERNEL);
284+
b47s = devm_kzalloc(dev, sizeof(*b47s), GFP_KERNEL);
283285
if (!b47s)
284286
return -ENOMEM;
285287
sflash->priv = b47s;
286288

289+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
290+
if (!res) {
291+
dev_err(dev, "invalid resource\n");
292+
return -EINVAL;
293+
}
294+
if (!devm_request_mem_region(dev, res->start, resource_size(res),
295+
res->name)) {
296+
dev_err(dev, "can't request region for resource %pR\n", res);
297+
return -EBUSY;
298+
}
299+
b47s->window = ioremap_cache(res->start, resource_size(res));
300+
if (!b47s->window) {
301+
dev_err(dev, "ioremap failed for resource %pR\n", res);
302+
return -ENOMEM;
303+
}
304+
287305
b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
288306
b47s->cc_read = bcm47xxsflash_bcma_cc_read;
289307
b47s->cc_write = bcm47xxsflash_bcma_cc_write;
@@ -297,7 +315,6 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
297315
break;
298316
}
299317

300-
b47s->window = sflash->window;
301318
b47s->blocksize = sflash->blocksize;
302319
b47s->numblocks = sflash->numblocks;
303320
b47s->size = sflash->size;
@@ -306,6 +323,7 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
306323
err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0);
307324
if (err) {
308325
pr_err("Failed to register MTD device: %d\n", err);
326+
iounmap(b47s->window);
309327
return err;
310328
}
311329

@@ -321,6 +339,7 @@ static int bcm47xxsflash_bcma_remove(struct platform_device *pdev)
321339
struct bcm47xxsflash *b47s = sflash->priv;
322340

323341
mtd_device_unregister(&b47s->mtd);
342+
iounmap(b47s->window);
324343

325344
return 0;
326345
}

‎drivers/mtd/devices/bcm47xxsflash.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ struct bcm47xxsflash {
6565

6666
enum bcm47xxsflash_type type;
6767

68-
u32 window;
68+
void __iomem *window;
69+
6970
u32 blocksize;
7071
u16 numblocks;
7172
u32 size;

‎include/linux/bcma/bcma_driver_chipcommon.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ struct mtd_info;
587587

588588
struct bcma_sflash {
589589
bool present;
590-
u32 window;
591590
u32 blocksize;
592591
u16 numblocks;
593592
u32 size;

0 commit comments

Comments
 (0)