Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+26 -8
-1
drivers/bcma/driver_chipcommon_sflash.c
··· 146 146 return -ENOTSUPP; 147 147 } 148 148 149 - sflash->window = BCMA_SOC_FLASH2; 150 149 sflash->blocksize = e->blocksize; 151 150 sflash->numblocks = e->numblocks; 152 151 sflash->size = sflash->blocksize * sflash->numblocks;
+24 -5
drivers/mtd/devices/bcm47xxsflash.c
··· 2 2 #include <linux/module.h> 3 3 #include <linux/slab.h> 4 4 #include <linux/delay.h> 5 + #include <linux/ioport.h> 5 6 #include <linux/mtd/mtd.h> 6 7 #include <linux/platform_device.h> 7 8 #include <linux/bcma/bcma.h> ··· 110 109 if ((from + len) > mtd->size) 111 110 return -EINVAL; 112 111 113 - memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(b47s->window + from), 114 - len); 112 + memcpy_fromio(buf, b47s->window + from, len); 115 113 *retlen = len; 116 114 117 115 return len; ··· 275 275 276 276 static int bcm47xxsflash_bcma_probe(struct platform_device *pdev) 277 277 { 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); 279 280 struct bcm47xxsflash *b47s; 281 + struct resource *res; 280 282 int err; 281 283 282 - b47s = devm_kzalloc(&pdev->dev, sizeof(*b47s), GFP_KERNEL); 284 + b47s = devm_kzalloc(dev, sizeof(*b47s), GFP_KERNEL); 283 285 if (!b47s) 284 286 return -ENOMEM; 285 287 sflash->priv = b47s; 288 + 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 + } 286 304 287 305 b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash); 288 306 b47s->cc_read = bcm47xxsflash_bcma_cc_read; ··· 315 297 break; 316 298 } 317 299 318 - b47s->window = sflash->window; 319 300 b47s->blocksize = sflash->blocksize; 320 301 b47s->numblocks = sflash->numblocks; 321 302 b47s->size = sflash->size; ··· 323 306 err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0); 324 307 if (err) { 325 308 pr_err("Failed to register MTD device: %d\n", err); 309 + iounmap(b47s->window); 326 310 return err; 327 311 } 328 312 ··· 339 321 struct bcm47xxsflash *b47s = sflash->priv; 340 322 341 323 mtd_device_unregister(&b47s->mtd); 324 + iounmap(b47s->window); 342 325 343 326 return 0; 344 327 }
+2 -1
drivers/mtd/devices/bcm47xxsflash.h
··· 65 65 66 66 enum bcm47xxsflash_type type; 67 67 68 - u32 window; 68 + void __iomem *window; 69 + 69 70 u32 blocksize; 70 71 u16 numblocks; 71 72 u32 size;
-1
include/linux/bcma/bcma_driver_chipcommon.h
··· 587 587 588 588 struct bcma_sflash { 589 589 bool present; 590 - u32 window; 591 590 u32 blocksize; 592 591 u16 numblocks; 593 592 u32 size;