1
0

042-0001-mtd-bcm47xxsflash-use-ioremap_cache-instead-of-KSEG0.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. Using KSEG0ADDR makes code highly MIPS dependent and not portable.
  10. Thanks to the fix a68f376 ("MIPS: io.h: Define `ioremap_cache'") we can
  11. use ioremap_cache which is generic and supported on MIPS as well now.
  12. KSEG0ADDR was translating 0x1c000000 into 0x9c000000. With ioremap_cache
  13. we use MIPS's __ioremap (and then remap_area_pages). This results in
  14. different address (e.g. 0xc0080000) but it still should be cached as
  15. expected and it was successfully tested with BCM47186B0.
  16. Other than that drivers/bcma/driver_chipcommon_sflash.c nicely setups a
  17. struct resource for access window, but we wren't using it. Use it now
  18. and drop duplicated info.
  19. Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  20. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  21. ---
  22. --- a/drivers/bcma/driver_chipcommon_sflash.c
  23. +++ b/drivers/bcma/driver_chipcommon_sflash.c
  24. @@ -146,7 +146,6 @@ int bcma_sflash_init(struct bcma_drv_cc
  25. return -ENOTSUPP;
  26. }
  27. - sflash->window = BCMA_SOC_FLASH2;
  28. sflash->blocksize = e->blocksize;
  29. sflash->numblocks = e->numblocks;
  30. sflash->size = sflash->blocksize * sflash->numblocks;
  31. --- a/drivers/mtd/devices/bcm47xxsflash.c
  32. +++ b/drivers/mtd/devices/bcm47xxsflash.c
  33. @@ -2,6 +2,7 @@
  34. #include <linux/module.h>
  35. #include <linux/slab.h>
  36. #include <linux/delay.h>
  37. +#include <linux/ioport.h>
  38. #include <linux/mtd/mtd.h>
  39. #include <linux/platform_device.h>
  40. #include <linux/bcma/bcma.h>
  41. @@ -109,8 +110,7 @@ static int bcm47xxsflash_read(struct mtd
  42. if ((from + len) > mtd->size)
  43. return -EINVAL;
  44. - memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(b47s->window + from),
  45. - len);
  46. + memcpy_fromio(buf, b47s->window + from, len);
  47. *retlen = len;
  48. return len;
  49. @@ -275,15 +275,33 @@ static void bcm47xxsflash_bcma_cc_write(
  50. static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
  51. {
  52. - struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
  53. + struct device *dev = &pdev->dev;
  54. + struct bcma_sflash *sflash = dev_get_platdata(dev);
  55. struct bcm47xxsflash *b47s;
  56. + struct resource *res;
  57. int err;
  58. - b47s = devm_kzalloc(&pdev->dev, sizeof(*b47s), GFP_KERNEL);
  59. + b47s = devm_kzalloc(dev, sizeof(*b47s), GFP_KERNEL);
  60. if (!b47s)
  61. return -ENOMEM;
  62. sflash->priv = b47s;
  63. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  64. + if (!res) {
  65. + dev_err(dev, "invalid resource\n");
  66. + return -EINVAL;
  67. + }
  68. + if (!devm_request_mem_region(dev, res->start, resource_size(res),
  69. + res->name)) {
  70. + dev_err(dev, "can't request region for resource %pR\n", res);
  71. + return -EBUSY;
  72. + }
  73. + b47s->window = ioremap_cache(res->start, resource_size(res));
  74. + if (!b47s->window) {
  75. + dev_err(dev, "ioremap failed for resource %pR\n", res);
  76. + return -ENOMEM;
  77. + }
  78. +
  79. b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
  80. b47s->cc_read = bcm47xxsflash_bcma_cc_read;
  81. b47s->cc_write = bcm47xxsflash_bcma_cc_write;
  82. @@ -297,7 +315,6 @@ static int bcm47xxsflash_bcma_probe(stru
  83. break;
  84. }
  85. - b47s->window = sflash->window;
  86. b47s->blocksize = sflash->blocksize;
  87. b47s->numblocks = sflash->numblocks;
  88. b47s->size = sflash->size;
  89. @@ -306,6 +323,7 @@ static int bcm47xxsflash_bcma_probe(stru
  90. err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0);
  91. if (err) {
  92. pr_err("Failed to register MTD device: %d\n", err);
  93. + iounmap(b47s->window);
  94. return err;
  95. }
  96. @@ -321,6 +339,7 @@ static int bcm47xxsflash_bcma_remove(str
  97. struct bcm47xxsflash *b47s = sflash->priv;
  98. mtd_device_unregister(&b47s->mtd);
  99. + iounmap(b47s->window);
  100. return 0;
  101. }
  102. --- a/drivers/mtd/devices/bcm47xxsflash.h
  103. +++ b/drivers/mtd/devices/bcm47xxsflash.h
  104. @@ -65,7 +65,8 @@ struct bcm47xxsflash {
  105. enum bcm47xxsflash_type type;
  106. - u32 window;
  107. + void __iomem *window;
  108. +
  109. u32 blocksize;
  110. u16 numblocks;
  111. u32 size;
  112. --- a/include/linux/bcma/bcma_driver_chipcommon.h
  113. +++ b/include/linux/bcma/bcma_driver_chipcommon.h
  114. @@ -588,7 +588,6 @@ struct bcma_pflash {
  115. #ifdef CONFIG_BCMA_SFLASH
  116. struct bcma_sflash {
  117. bool present;
  118. - u32 window;
  119. u32 blocksize;
  120. u16 numblocks;
  121. u32 size;