c2f2d21d0385fa7cc6218f261e08e74e82c90367
[librecmc/librecmc.git] / target / linux / generic / patches-4.4 / 042-0003-mtd-bcm47xxsflash-use-uncached-MMIO-access-for-BCM53.patch
1 From 64ad46379fcf14f437553f654d1adcd3d0e0d7f9 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Mon, 15 Aug 2016 14:21:28 +0200
4 Subject: [PATCH] mtd: bcm47xxsflash: use uncached MMIO access for BCM53573
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 BCM53573 is a new series of Broadcom's SoCs. It's based on ARM and uses
10 this old ChipCommon-based flash access. Early tests resulted in flash
11 corruptions that were tracked down to using cached MMIO for flash read
12 access. Switch to ioremap_nocache conditionally to support BCM53573 and
13 don't break performance on old MIPS devices.
14
15 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
17 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
18 ---
19  drivers/mtd/devices/bcm47xxsflash.c | 24 +++++++++++++++++++-----
20  1 file changed, 19 insertions(+), 5 deletions(-)
21
22 --- a/drivers/mtd/devices/bcm47xxsflash.c
23 +++ b/drivers/mtd/devices/bcm47xxsflash.c
24 @@ -296,16 +296,30 @@ static int bcm47xxsflash_bcma_probe(stru
25                 dev_err(dev, "can't request region for resource %pR\n", res);
26                 return -EBUSY;
27         }
28 -       b47s->window = ioremap_cache(res->start, resource_size(res));
29 -       if (!b47s->window) {
30 -               dev_err(dev, "ioremap failed for resource %pR\n", res);
31 -               return -ENOMEM;
32 -       }
33  
34         b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
35         b47s->cc_read = bcm47xxsflash_bcma_cc_read;
36         b47s->cc_write = bcm47xxsflash_bcma_cc_write;
37  
38 +       /*
39 +        * On old MIPS devices cache was magically invalidated when needed,
40 +        * allowing us to use cached access and gain some performance. Trying
41 +        * the same on ARM based BCM53573 results in flash corruptions, we need
42 +        * to use uncached access for it.
43 +        *
44 +        * It may be arch specific, but right now there is only 1 ARM SoC using
45 +        * this driver, so let's follow Broadcom's reference code and check
46 +        * ChipCommon revision.
47 +        */
48 +       if (b47s->bcma_cc->core->id.rev == 54)
49 +               b47s->window = ioremap_nocache(res->start, resource_size(res));
50 +       else
51 +               b47s->window = ioremap_cache(res->start, resource_size(res));
52 +       if (!b47s->window) {
53 +               dev_err(dev, "ioremap failed for resource %pR\n", res);
54 +               return -ENOMEM;
55 +       }
56 +
57         switch (b47s->bcma_cc->capabilities & BCMA_CC_CAP_FLASHT) {
58         case BCMA_CC_FLASHT_STSER:
59                 b47s->type = BCM47XXSFLASH_TYPE_ST;