The claim function assigns sram to cpu which when called from the emac
driver causes exactly the issue the call is supposed to prevent: emac
does not work because it does not have sram available.

Add additional parameter to the sunxi_sram_claim to determine if the
sram is claimed for cpu or device.

Signed-off-by: Michal Suchanek <[email protected]>
---
 drivers/net/ethernet/allwinner/sun4i-emac.c |  2 +-
 drivers/soc/sunxi/sunxi_sram.c              | 11 ++++++++---
 include/linux/soc/sunxi/sunxi_sram.h        |  2 +-
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/allwinner/sun4i-emac.c 
b/drivers/net/ethernet/allwinner/sun4i-emac.c
index 0d309a0..11e8dee 100644
--- a/drivers/net/ethernet/allwinner/sun4i-emac.c
+++ b/drivers/net/ethernet/allwinner/sun4i-emac.c
@@ -859,7 +859,7 @@ static int emac_probe(struct platform_device *pdev)
 
        clk_prepare_enable(db->clk);
 
-       ret = sunxi_sram_claim(SUNXI_SRAM_EMAC, "emac");
+       ret = sunxi_sram_claim(SUNXI_SRAM_EMAC, "emac", 1);
        if (ret)
                dev_warn(&pdev->dev, "Couldn't map SRAM to device\n");
 
diff --git a/drivers/soc/sunxi/sunxi_sram.c b/drivers/soc/sunxi/sunxi_sram.c
index 3d03e89..6e73f38 100644
--- a/drivers/soc/sunxi/sunxi_sram.c
+++ b/drivers/soc/sunxi/sunxi_sram.c
@@ -109,7 +109,7 @@ static const struct file_operations sunxi_sram_fops = {
        .release = single_release,
 };
 
-int sunxi_sram_claim(enum sunxi_sram_type type, const char *function)
+int sunxi_sram_claim(enum sunxi_sram_type type, const char *function, int 
device)
 {
        struct sunxi_sram_desc *sram;
        struct sunxi_sram_func *func;
@@ -135,14 +135,19 @@ int sunxi_sram_claim(enum sunxi_sram_type type, const 
char *function)
 
                sram->claimed = true;
                spin_unlock(&sram_lock);
-               dev_info(&pdev->dev, "Claiming sram %s.\n", sram->name );
+               dev_info(&pdev->dev, "Claiming sram %s for %s.\n", sram->name,
+                      device ? "device" : "cpu");
 
                for (func = sram->func; func->func; func++) {
                        if (strcmp(function, func->func))
                                continue;
 
                        val = readl(base + sram->reg);
-                       val &= ~GENMASK(sram->offset + sram->width,
+                       if (device)
+                               val |= GENMASK(sram->offset + sram->width,
+                                       sram->offset);
+                       else
+                               val &= ~GENMASK(sram->offset + sram->width,
                                        sram->offset);
                        writel(val | func->val, base + sram->reg);
 
diff --git a/include/linux/soc/sunxi/sunxi_sram.h 
b/include/linux/soc/sunxi/sunxi_sram.h
index 351c31a..94d5597 100644
--- a/include/linux/soc/sunxi/sunxi_sram.h
+++ b/include/linux/soc/sunxi/sunxi_sram.h
@@ -18,7 +18,7 @@ enum sunxi_sram_type {
        SUNXI_SRAM_EMAC,
 };
 
-int sunxi_sram_claim(enum sunxi_sram_type type, const char *function);
+int sunxi_sram_claim(enum sunxi_sram_type type, const char *function, int 
for_device);
 int sunxi_sram_release(enum sunxi_sram_type type);
 
 #endif /* _SUNXI_SRAM_H_ */
-- 
2.1.4

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to