linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] ARM: sunxi: SRAM mapping support
@ 2015-03-20 18:52 Hans de Goede
  2015-03-20 18:52 ` [PATCH 1/5] drivers: soc: sunxi: Introduce SoC driver to map SRAMs Hans de Goede
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Hans de Goede @ 2015-03-20 18:52 UTC (permalink / raw)
  To: linux-arm-kernel

Hi All,

Here is a cleaned up version of Maxime's sunxi SRAM controller driver.

I've been using / testing this together with the sunxi musb support patches
I've been working on, and it works well. I've tested it on sun4i, sun5i and
sun7i. See the per patch commit messages for the (minor) changes which I did
compared to Maxime's RFC.

A note about the changing of the compatible to a sun4i-a10 prefix, I've
looked at the user manual for all 3 generations and the sram controller is
the same for all 3. Register 0x1c00024 (SoC version) is only documented in
the A20 manual, but is present and works indentical in all 3 generations.

Since this is a prereq for my musb work, if there are no objections then I
would like to see this go upstream soon.

Since it only touches sunxi files (and one Makefile), it is probably best if
this all goes upstream through Maxime.

Regards,

Hans

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/5] drivers: soc: sunxi: Introduce SoC driver to map SRAMs
  2015-03-20 18:52 [PATCH 0/5] ARM: sunxi: SRAM mapping support Hans de Goede
@ 2015-03-20 18:52 ` Hans de Goede
  2015-03-24 15:19   ` Maxime Ripard
  2015-03-20 18:52 ` [PATCH 2/5] ARM: dts: sun4i: Add A10 SRAM and SRAM controller Hans de Goede
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Hans de Goede @ 2015-03-20 18:52 UTC (permalink / raw)
  To: linux-arm-kernel

From: Maxime Ripard <maxime.ripard@free-electrons.com>

The Allwinner SoCs have a handful of SRAM that can be either mapped to be
accessible by devices or the CPU.

That mapping is controlled by an SRAM controller, and that mapping might not be
set by the bootloader, for example if the device wasn't used at all, or if
we're using solutions like the U-Boot's Falcon Boot.

We could also imagine changing this at runtime for example to change the
mapping of these SRAMs to use them for suspend/resume or runtime memory rate
change, if that ever happens.

These use cases require some API in the kernel to control that mapping,
exported through a drivers/soc driver.

This driver also implement a debugfs file that shows the SRAM found in the
system, the current mapping and the SRAM that have been claimed by some drivers
in the kernel.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
[hdegoede at redhat.com: Changed compat string to sun4i-a10-sram-controller, as
 the sram controller is identical on sun4i, sun5i & sun7i, added devicetree
 binding documentation, fixed some checkpatch warnings]
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 .../devicetree/bindings/soc/sunxi/sram.txt         |  64 ++++++
 drivers/soc/Kconfig                                |   1 +
 drivers/soc/Makefile                               |   1 +
 drivers/soc/sunxi/Kconfig                          |  12 ++
 drivers/soc/sunxi/Makefile                         |   1 +
 drivers/soc/sunxi/sunxi_sram.c                     | 235 +++++++++++++++++++++
 include/linux/soc/sunxi/sunxi_sram.h               |  24 +++
 7 files changed, 338 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/sunxi/sram.txt
 create mode 100644 drivers/soc/sunxi/Kconfig
 create mode 100644 drivers/soc/sunxi/Makefile
 create mode 100644 drivers/soc/sunxi/sunxi_sram.c
 create mode 100644 include/linux/soc/sunxi/sunxi_sram.h

diff --git a/Documentation/devicetree/bindings/soc/sunxi/sram.txt b/Documentation/devicetree/bindings/soc/sunxi/sram.txt
new file mode 100644
index 0000000..6e1bc80
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/sunxi/sram.txt
@@ -0,0 +1,64 @@
+Allwinnner sun4i / sun5i / sun7i SoC SRAM controllers
+-----------------------------------------------------
+
+Required properties:
+- compatible : "allwinner,sun4i-a10-sram-controller"
+- reg : sram controller register offset + length
+
+SRAM nodes
+----------
+
+Besides a node for the SRAM controller the devicetree must also contain a
+node for each SRAM block controlled by the controller.
+
+Required sram node properties:
+- compatible : "allwinner,sun4i-a10-sram"
+- allwinner,sram-name : should be one of
+  * "A1"
+  * "A2"
+  * "A3-A4"
+  * "D"
+
+Example
+-------
+
+/*
+ * Note we use the address were mmio register start, not where
+ * the SRAM blocks starts, this cannot be changed because doing
+ * doing so would be a devicetree ABI change.
+ */
+soc at 01c00000 {
+	compatible = "simple-bus";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	ranges;
+
+	sram at 00000000 {
+		compatible = "allwinner,sun4i-a10-sram";
+		reg = <0x00000000 0x4000>;
+		allwinner,sram-name = "A1";
+	};
+
+	sram at 00004000 {
+		compatible = "allwinner,sun4i-a10-sram";
+		reg = <0x00004000 0x4000>;
+		allwinner,sram-name = "A2";
+	};
+
+	sram at 00008000 {
+		compatible = "allwinner,sun4i-a10-sram";
+		reg = <0x00008000 0x4000>;
+		allwinner,sram-name = "A3-A4";
+	};
+
+	sram at 00010000 {
+		compatible = "allwinner,sun4i-a10-sram";
+		reg = <0x00010000 0x1000>;
+		allwinner,sram-name = "D";
+	};
+
+	sram-controller at 01c00000 {
+		compatible = "allwinner,sun4i-a10-sram-controller";
+		reg = <0x01c00000 0x30>;
+	};
+};
diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index 76d6bd4..5d0f55d 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -1,6 +1,7 @@
 menu "SOC (System On Chip) specific Drivers"
 
 source "drivers/soc/qcom/Kconfig"
+source "drivers/soc/sunxi/Kconfig"
 source "drivers/soc/ti/Kconfig"
 source "drivers/soc/versatile/Kconfig"
 
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 063113d..170bba3 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -3,6 +3,7 @@
 #
 
 obj-$(CONFIG_ARCH_QCOM)		+= qcom/
+obj-$(CONFIG_ARCH_SUNXI)	+= sunxi/
 obj-$(CONFIG_ARCH_TEGRA)	+= tegra/
 obj-$(CONFIG_SOC_TI)		+= ti/
 obj-$(CONFIG_PLAT_VERSATILE)	+= versatile/
diff --git a/drivers/soc/sunxi/Kconfig b/drivers/soc/sunxi/Kconfig
new file mode 100644
index 0000000..212c634
--- /dev/null
+++ b/drivers/soc/sunxi/Kconfig
@@ -0,0 +1,12 @@
+#
+# Allwinner sunXi SoC drivers
+#
+config SUNXI_SRAM
+        tristate "Allwinner sunXi SRAM Controller"
+        depends on ARCH_SUNXI
+	default y
+        help
+          Say y here to enable the SRAM controller support. This
+          device is responsible on mapping the SRAM in the sunXi SoCs
+          wether to the CPU/DMA, or to the devices.
+
diff --git a/drivers/soc/sunxi/Makefile b/drivers/soc/sunxi/Makefile
new file mode 100644
index 0000000..4cf9dbd
--- /dev/null
+++ b/drivers/soc/sunxi/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_SUNXI_SRAM) +=	sunxi_sram.o
diff --git a/drivers/soc/sunxi/sunxi_sram.c b/drivers/soc/sunxi/sunxi_sram.c
new file mode 100644
index 0000000..5b76fd1
--- /dev/null
+++ b/drivers/soc/sunxi/sunxi_sram.c
@@ -0,0 +1,235 @@
+/*
+ * Allwinner SoCs SRAM Controller Driver
+ *
+ * Copyright (C) 2015 Maxime Ripard
+ *
+ * Author: Maxime Ripard <maxime.ripard@free-electrons.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/debugfs.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+
+#include <linux/soc/sunxi/sunxi_sram.h>
+
+struct sunxi_sram_func {
+	char	*func;
+	u8	val;
+};
+
+struct sunxi_sram_desc {
+	enum sunxi_sram_type	type;
+	char			*name;
+	u8			reg;
+	u8			offset;
+	u8			width;
+	struct sunxi_sram_func	*func;
+	bool			claimed;
+	bool			enabled;
+};
+
+#define SUNXI_SRAM_MAP(_val, _func)				\
+	{							\
+		.func = _func,					\
+		.val = _val,					\
+	}
+
+#define SUNXI_SRAM_DESC(_type, _name, _reg, _off, _width, ...)	\
+	{							\
+		.type = _type,					\
+		.name = _name,					\
+		.reg = _reg,					\
+		.offset = _off,					\
+		.width = _width,				\
+		.func = (struct sunxi_sram_func[]){		\
+			__VA_ARGS__, { } },			\
+	}
+
+struct sunxi_sram_desc sun4i_sram_desc[] = {
+	SUNXI_SRAM_DESC(SUNXI_SRAM_EMAC, "A3-A4", 0x4, 0x4, 1,
+			SUNXI_SRAM_MAP(0, "cpu"),
+			SUNXI_SRAM_MAP(1, "emac")),
+	SUNXI_SRAM_DESC(SUNXI_SRAM_USB_OTG, "D", 0x4, 0x0, 1,
+			SUNXI_SRAM_MAP(0, "cpu"),
+			SUNXI_SRAM_MAP(1, "usb-otg")),
+	{ /* Sentinel */ },
+};
+
+static struct sunxi_sram_desc *sram_list;
+static DEFINE_SPINLOCK(sram_lock);
+static void __iomem *base;
+
+static int sunxi_sram_show(struct seq_file *s, void *data)
+{
+	struct sunxi_sram_desc *sram;
+	struct sunxi_sram_func *func;
+	u32 val;
+
+	seq_puts(s, "Allwinner sunXi SRAM\n");
+	seq_puts(s, "--------------------\n");
+
+
+	for (sram = sram_list; sram->name; sram++) {
+		if (!sram->enabled)
+			continue;
+
+		seq_printf(s, "\n%s\n", sram->name);
+
+		val = readl(base + sram->reg);
+		val >>= sram->offset;
+		val &= sram->width;
+
+		for (func = sram->func; func->func; func++) {
+			seq_printf(s, "\t\t%s%c\n", func->func,
+				   func->val == val ? '*' : ' ');
+		}
+	}
+
+	return 0;
+}
+
+static int sunxi_sram_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, sunxi_sram_show, inode->i_private);
+}
+
+static const struct file_operations sunxi_sram_fops = {
+	.open = sunxi_sram_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
+
+int sunxi_sram_claim(enum sunxi_sram_type type, const char *function)
+{
+	struct sunxi_sram_desc *sram;
+	struct sunxi_sram_func *func;
+	u32 val;
+
+	if (IS_ERR(base))
+		return -EPROBE_DEFER;
+
+	for (sram = sram_list; sram->name; sram++) {
+		if (sram->type != type)
+			continue;
+
+		if (!sram->enabled)
+			return -ENODEV;
+
+		spin_lock(&sram_lock);
+
+		if (sram->claimed) {
+			spin_unlock(&sram_lock);
+			return -EBUSY;
+		}
+
+		sram->claimed = true;
+		spin_unlock(&sram_lock);
+
+		for (func = sram->func; func->func; func++) {
+			if (strcmp(function, func->func))
+				continue;
+
+			val = readl(base + sram->reg);
+			val &= ~GENMASK(sram->offset + sram->width,
+					sram->offset);
+			writel(val | func->val, base + sram->reg);
+
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL(sunxi_sram_claim);
+
+int sunxi_sram_release(enum sunxi_sram_type type)
+{
+	struct sunxi_sram_desc *sram;
+
+	for (sram = sram_list; sram->type; sram++) {
+		if (sram->type != type)
+			continue;
+
+		if (!sram->enabled)
+			return -ENODEV;
+
+		spin_lock(&sram_lock);
+		sram->claimed = false;
+		spin_unlock(&sram_lock);
+
+		return 0;
+	}
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL(sunxi_sram_release);
+
+static const struct of_device_id sunxi_sram_dt_match[] = {
+	{ .compatible = "allwinner,sun4i-a10-sram-controller",
+	  .data = &sun4i_sram_desc },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, sunxi_sram_dt_match);
+
+static int sunxi_sram_probe(struct platform_device *pdev)
+{
+	const struct of_device_id *match;
+	struct sunxi_sram_desc *sram;
+	struct device_node *node;
+	struct resource *res;
+	struct dentry *d;
+	const char *name;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	match = of_match_device(sunxi_sram_dt_match, &pdev->dev);
+	if (!match)
+		return -ENODEV;
+
+	sram_list = (struct sunxi_sram_desc *)match->data;
+
+	for_each_compatible_node(node, NULL, "allwinner,sun4i-a10-sram") {
+		if (of_property_read_string(node, "allwinner,sram-name", &name))
+			continue;
+
+		for (sram = sram_list; sram->name; sram++)
+			if (!strcmp(name, sram->name))
+				break;
+
+		if (!sram->name)
+			continue;
+
+		sram->enabled = true;
+	}
+
+	d = debugfs_create_file("sram", S_IRUGO, NULL, NULL,
+				&sunxi_sram_fops);
+	if (!d)
+		return -ENOMEM;
+
+	return 0;
+}
+
+static struct platform_driver sunxi_sram_driver = {
+	.driver = {
+		.name		= "sunxi-sram",
+		.of_match_table	= sunxi_sram_dt_match,
+	},
+	.probe	= sunxi_sram_probe,
+};
+module_platform_driver(sunxi_sram_driver);
+
+MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
+MODULE_DESCRIPTION("Allwinner sunXi SRAM Controller Driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/soc/sunxi/sunxi_sram.h b/include/linux/soc/sunxi/sunxi_sram.h
new file mode 100644
index 0000000..351c31a
--- /dev/null
+++ b/include/linux/soc/sunxi/sunxi_sram.h
@@ -0,0 +1,24 @@
+/*
+ * Allwinner SoCs SRAM Controller Driver
+ *
+ * Copyright (C) 2015 Maxime Ripard
+ *
+ * Author: Maxime Ripard <maxime.ripard@free-electrons.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef _SUNXI_SRAM_H_
+#define _SUNXI_SRAM_H_
+
+enum sunxi_sram_type {
+	SUNXI_SRAM_USB_OTG,
+	SUNXI_SRAM_EMAC,
+};
+
+int sunxi_sram_claim(enum sunxi_sram_type type, const char *function);
+int sunxi_sram_release(enum sunxi_sram_type type);
+
+#endif /* _SUNXI_SRAM_H_ */
-- 
2.3.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/5] ARM: dts: sun4i: Add A10 SRAM and SRAM controller
  2015-03-20 18:52 [PATCH 0/5] ARM: sunxi: SRAM mapping support Hans de Goede
  2015-03-20 18:52 ` [PATCH 1/5] drivers: soc: sunxi: Introduce SoC driver to map SRAMs Hans de Goede
@ 2015-03-20 18:52 ` Hans de Goede
  2015-03-24 15:20   ` Maxime Ripard
  2015-03-20 18:52 ` [PATCH 3/5] ARM: dts: sun5i: Add A13 and A10s " Hans de Goede
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Hans de Goede @ 2015-03-20 18:52 UTC (permalink / raw)
  To: linux-arm-kernel

The A10 has a few SRAM that can be mapped either to a device or to the CPU,
with the mapping being controlled by a SRAM controller.

Since most of the time these SRAM won't be accessible by the CPU,
we can't use the mmio-sram driver and compatible.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 arch/arm/boot/dts/sun4i-a10.dtsi | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
index b66ebb3..88f57b4 100644
--- a/arch/arm/boot/dts/sun4i-a10.dtsi
+++ b/arch/arm/boot/dts/sun4i-a10.dtsi
@@ -451,12 +451,46 @@
 		};
 	};
 
+	/*
+	 * Note we use the address were mmio registers start, not where the
+	 * SRAM blocks start, this cannot be changed because that would be
+	 * a devicetree ABI change.
+	 */
 	soc at 01c00000 {
 		compatible = "simple-bus";
 		#address-cells = <1>;
 		#size-cells = <1>;
 		ranges;
 
+		sram at 00000000 {
+			compatible = "allwinner,sun4i-a10-sram";
+			reg = <0x00000000 0x4000>;
+			allwinner,sram-name = "A1";
+		};
+
+		sram at 00004000 {
+			compatible = "allwinner,sun4i-a10-sram";
+			reg = <0x00004000 0x4000>;
+			allwinner,sram-name = "A2";
+		};
+
+		sram at 00008000 {
+			compatible = "allwinner,sun4i-a10-sram";
+			reg = <0x00008000 0x4000>;
+			allwinner,sram-name = "A3-A4";
+		};
+
+		sram at 00010000 {
+			compatible = "allwinner,sun4i-a10-sram";
+			reg = <0x00010000 0x1000>;
+			allwinner,sram-name = "D";
+		};
+
+		sram-controller at 01c00000 {
+			compatible = "allwinner,sun4i-a10-sram-controller";
+			reg = <0x01c00000 0x30>;
+		};
+
 		dma: dma-controller at 01c02000 {
 			compatible = "allwinner,sun4i-a10-dma";
 			reg = <0x01c02000 0x1000>;
-- 
2.3.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/5] ARM: dts: sun5i: Add A13 and A10s SRAM and SRAM controller
  2015-03-20 18:52 [PATCH 0/5] ARM: sunxi: SRAM mapping support Hans de Goede
  2015-03-20 18:52 ` [PATCH 1/5] drivers: soc: sunxi: Introduce SoC driver to map SRAMs Hans de Goede
  2015-03-20 18:52 ` [PATCH 2/5] ARM: dts: sun4i: Add A10 SRAM and SRAM controller Hans de Goede
@ 2015-03-20 18:52 ` Hans de Goede
  2015-03-20 18:52 ` [PATCH 4/5] ARM: dts: sun7i: Add A20 " Hans de Goede
  2015-03-20 18:52 ` [PATCH 5/5] net: allwinner: emac: Claim our SRAM Hans de Goede
  4 siblings, 0 replies; 13+ messages in thread
From: Hans de Goede @ 2015-03-20 18:52 UTC (permalink / raw)
  To: linux-arm-kernel

The A13 / A10s has a few SRAM that can be mapped either to a device or to
the CPU, with the mapping being controlled by a SRAM controller.

Since most of the time these SRAM won't be accessible by the CPU,
we can't use the mmio-sram driver and compatible.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 arch/arm/boot/dts/sun5i.dtsi | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/arch/arm/boot/dts/sun5i.dtsi b/arch/arm/boot/dts/sun5i.dtsi
index de48692..eb5bce5 100644
--- a/arch/arm/boot/dts/sun5i.dtsi
+++ b/arch/arm/boot/dts/sun5i.dtsi
@@ -298,12 +298,46 @@
 		};
 	};
 
+	/*
+	 * Note we use the address were mmio registers start, not where the
+	 * SRAM blocks start, this cannot be changed because that would be
+	 * a devicetree ABI change.
+	 */
 	soc at 01c00000 {
 		compatible = "simple-bus";
 		#address-cells = <1>;
 		#size-cells = <1>;
 		ranges;
 
+		sram at 00000000 {
+			compatible = "allwinner,sun4i-a10-sram";
+			reg = <0x00000000 0x4000>;
+			allwinner,sram-name = "A1";
+		};
+
+		sram at 00004000 {
+			compatible = "allwinner,sun4i-a10-sram";
+			reg = <0x00004000 0x4000>;
+			allwinner,sram-name = "A2";
+		};
+
+		sram at 00008000 {
+			compatible = "allwinner,sun4i-a10-sram";
+			reg = <0x00008000 0x4000>;
+			allwinner,sram-name = "A3-A4";
+		};
+
+		sram at 00010000 {
+			compatible = "allwinner,sun4i-a10-sram";
+			reg = <0x00010000 0x1000>;
+			allwinner,sram-name = "D";
+		};
+
+		sram-controller at 01c00000 {
+			compatible = "allwinner,sun4i-a10-sram-controller";
+			reg = <0x01c00000 0x30>;
+		};
+
 		dma: dma-controller at 01c02000 {
 			compatible = "allwinner,sun4i-a10-dma";
 			reg = <0x01c02000 0x1000>;
-- 
2.3.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/5] ARM: dts: sun7i: Add A20 SRAM and SRAM controller
  2015-03-20 18:52 [PATCH 0/5] ARM: sunxi: SRAM mapping support Hans de Goede
                   ` (2 preceding siblings ...)
  2015-03-20 18:52 ` [PATCH 3/5] ARM: dts: sun5i: Add A13 and A10s " Hans de Goede
@ 2015-03-20 18:52 ` Hans de Goede
  2015-03-20 18:52 ` [PATCH 5/5] net: allwinner: emac: Claim our SRAM Hans de Goede
  4 siblings, 0 replies; 13+ messages in thread
From: Hans de Goede @ 2015-03-20 18:52 UTC (permalink / raw)
  To: linux-arm-kernel

From: Maxime Ripard <maxime.ripard@free-electrons.com>

The A20 has a few SRAM that can be mapped either to a device or to the CPU,
with the mapping being controlled by a SRAM controller.

Since most of the time these SRAM won't be accessible by the CPU,
we can't use the mmio-sram driver and compatible.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
[hdegoede at redhat.com: Do not change soc node name, change compatible to
 sun4i-a10-sram-controller to match the driver change]
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 arch/arm/boot/dts/sun7i-a20.dtsi | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 4673c11..7c04a24 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -528,12 +528,46 @@
 		};
 	};
 
+	/*
+	 * Note we use the address were mmio registers start, not where the
+	 * SRAM blocks start, this cannot be changed because that would be
+	 * a devicetree ABI change.
+	 */
 	soc at 01c00000 {
 		compatible = "simple-bus";
 		#address-cells = <1>;
 		#size-cells = <1>;
 		ranges;
 
+		sram at 00000000 {
+			compatible = "allwinner,sun4i-a10-sram";
+			reg = <0x00000000 0x4000>;
+			allwinner,sram-name = "A1";
+		};
+
+		sram at 00004000 {
+			compatible = "allwinner,sun4i-a10-sram";
+			reg = <0x00004000 0x4000>;
+			allwinner,sram-name = "A2";
+		};
+
+		sram at 00008000 {
+			compatible = "allwinner,sun4i-a10-sram";
+			reg = <0x00008000 0x4000>;
+			allwinner,sram-name = "A3-A4";
+		};
+
+		sram at 00010000 {
+			compatible = "allwinner,sun4i-a10-sram";
+			reg = <0x00010000 0x1000>;
+			allwinner,sram-name = "D";
+		};
+
+		sram-controller at 01c00000 {
+			compatible = "allwinner,sun4i-a10-sram-controller";
+			reg = <0x01c00000 0x30>;
+		};
+
 		nmi_intc: interrupt-controller at 01c00030 {
 			compatible = "allwinner,sun7i-a20-sc-nmi";
 			interrupt-controller;
-- 
2.3.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/5] net: allwinner: emac: Claim our SRAM
  2015-03-20 18:52 [PATCH 0/5] ARM: sunxi: SRAM mapping support Hans de Goede
                   ` (3 preceding siblings ...)
  2015-03-20 18:52 ` [PATCH 4/5] ARM: dts: sun7i: Add A20 " Hans de Goede
@ 2015-03-20 18:52 ` Hans de Goede
  2015-03-20 18:53   ` Hans de Goede
  2015-03-24 15:22   ` Maxime Ripard
  4 siblings, 2 replies; 13+ messages in thread
From: Hans de Goede @ 2015-03-20 18:52 UTC (permalink / raw)
  To: linux-arm-kernel

From: Maxime Ripard <maxime.ripard@free-electrons.com>

The SRAM the EMAC is using might not have been mapped accordingly by the
bootloader, preventing the EMAC to work properly.

Ask for that SRAM to be mapped at probe time to make sure that this never
happens.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
[hdegoede at redhat.com: Make sure SUNXI_SRAM gets enabled in Kconfig]
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/net/ethernet/allwinner/sun4i-emac.c | 13 +++++++++++--
 drivers/net/ethernet/stmicro/stmmac/Kconfig |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/allwinner/sun4i-emac.c b/drivers/net/ethernet/allwinner/sun4i-emac.c
index f3470d9..9d0136b 100644
--- a/drivers/net/ethernet/allwinner/sun4i-emac.c
+++ b/drivers/net/ethernet/allwinner/sun4i-emac.c
@@ -29,6 +29,8 @@
 #include <linux/platform_device.h>
 #include <linux/phy.h>
 
+#include <linux/soc/sunxi/sunxi_sram.h>
+
 #include "sun4i-emac.h"
 
 #define DRV_NAME		"sun4i-emac"
@@ -857,11 +859,15 @@ static int emac_probe(struct platform_device *pdev)
 
 	clk_prepare_enable(db->clk);
 
+	ret = sunxi_sram_claim(SUNXI_SRAM_EMAC, "emac");
+	if (ret)
+		dev_warn(&pdev->dev, "Couldn't map SRAM to device\n");
+
 	db->phy_node = of_parse_phandle(np, "phy", 0);
 	if (!db->phy_node) {
 		dev_err(&pdev->dev, "no associated PHY\n");
 		ret = -ENODEV;
-		goto out;
+		goto out_release_sram;
 	}
 
 	/* Read MAC-address from DT */
@@ -893,7 +899,7 @@ static int emac_probe(struct platform_device *pdev)
 	if (ret) {
 		dev_err(&pdev->dev, "Registering netdev failed!\n");
 		ret = -ENODEV;
-		goto out;
+		goto out_release_sram;
 	}
 
 	dev_info(&pdev->dev, "%s: at %p, IRQ %d MAC: %pM\n",
@@ -901,6 +907,8 @@ static int emac_probe(struct platform_device *pdev)
 
 	return 0;
 
+out_release_sram:
+	sunxi_sram_release(SUNXI_SRAM_EMAC);
 out:
 	dev_err(db->dev, "not found (%d).\n", ret);
 
@@ -914,6 +922,7 @@ static int emac_remove(struct platform_device *pdev)
 	struct net_device *ndev = platform_get_drvdata(pdev);
 
 	unregister_netdev(ndev);
+	sunxi_sram_release(SUNXI_SRAM_EMAC);
 	free_netdev(ndev);
 
 	dev_dbg(&pdev->dev, "released and freed device\n");
diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
index 7d3af19..785ca22 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
@@ -16,6 +16,7 @@ if STMMAC_ETH
 config STMMAC_PLATFORM
 	tristate "STMMAC Platform bus support"
 	depends on STMMAC_ETH
+	select SUNXI_SRAM if ARCH_SUNXI
 	default y
 	---help---
 	  This selects the platform specific bus support for the stmmac driver.
-- 
2.3.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/5] net: allwinner: emac: Claim our SRAM
  2015-03-20 18:52 ` [PATCH 5/5] net: allwinner: emac: Claim our SRAM Hans de Goede
@ 2015-03-20 18:53   ` Hans de Goede
  2015-03-24 15:22   ` Maxime Ripard
  1 sibling, 0 replies; 13+ messages in thread
From: Hans de Goede @ 2015-03-20 18:53 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 20-03-15 19:52, Hans de Goede wrote:
> From: Maxime Ripard <maxime.ripard@free-electrons.com>
>
> The SRAM the EMAC is using might not have been mapped accordingly by the
> bootloader, preventing the EMAC to work properly.
>
> Ask for that SRAM to be mapped at probe time to make sure that this never
> happens.
>
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> [hdegoede at redhat.com: Make sure SUNXI_SRAM gets enabled in Kconfig]
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Note this patch is only included for completeness / as an example,
it should probably go upstream through the network-drivers tree
once the rest is merged.

Regards,

Hans

> ---
>   drivers/net/ethernet/allwinner/sun4i-emac.c | 13 +++++++++++--
>   drivers/net/ethernet/stmicro/stmmac/Kconfig |  1 +
>   2 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/allwinner/sun4i-emac.c b/drivers/net/ethernet/allwinner/sun4i-emac.c
> index f3470d9..9d0136b 100644
> --- a/drivers/net/ethernet/allwinner/sun4i-emac.c
> +++ b/drivers/net/ethernet/allwinner/sun4i-emac.c
> @@ -29,6 +29,8 @@
>   #include <linux/platform_device.h>
>   #include <linux/phy.h>
>
> +#include <linux/soc/sunxi/sunxi_sram.h>
> +
>   #include "sun4i-emac.h"
>
>   #define DRV_NAME		"sun4i-emac"
> @@ -857,11 +859,15 @@ static int emac_probe(struct platform_device *pdev)
>
>   	clk_prepare_enable(db->clk);
>
> +	ret = sunxi_sram_claim(SUNXI_SRAM_EMAC, "emac");
> +	if (ret)
> +		dev_warn(&pdev->dev, "Couldn't map SRAM to device\n");
> +
>   	db->phy_node = of_parse_phandle(np, "phy", 0);
>   	if (!db->phy_node) {
>   		dev_err(&pdev->dev, "no associated PHY\n");
>   		ret = -ENODEV;
> -		goto out;
> +		goto out_release_sram;
>   	}
>
>   	/* Read MAC-address from DT */
> @@ -893,7 +899,7 @@ static int emac_probe(struct platform_device *pdev)
>   	if (ret) {
>   		dev_err(&pdev->dev, "Registering netdev failed!\n");
>   		ret = -ENODEV;
> -		goto out;
> +		goto out_release_sram;
>   	}
>
>   	dev_info(&pdev->dev, "%s: at %p, IRQ %d MAC: %pM\n",
> @@ -901,6 +907,8 @@ static int emac_probe(struct platform_device *pdev)
>
>   	return 0;
>
> +out_release_sram:
> +	sunxi_sram_release(SUNXI_SRAM_EMAC);
>   out:
>   	dev_err(db->dev, "not found (%d).\n", ret);
>
> @@ -914,6 +922,7 @@ static int emac_remove(struct platform_device *pdev)
>   	struct net_device *ndev = platform_get_drvdata(pdev);
>
>   	unregister_netdev(ndev);
> +	sunxi_sram_release(SUNXI_SRAM_EMAC);
>   	free_netdev(ndev);
>
>   	dev_dbg(&pdev->dev, "released and freed device\n");
> diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> index 7d3af19..785ca22 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
> +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> @@ -16,6 +16,7 @@ if STMMAC_ETH
>   config STMMAC_PLATFORM
>   	tristate "STMMAC Platform bus support"
>   	depends on STMMAC_ETH
> +	select SUNXI_SRAM if ARCH_SUNXI
>   	default y
>   	---help---
>   	  This selects the platform specific bus support for the stmmac driver.
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/5] drivers: soc: sunxi: Introduce SoC driver to map SRAMs
  2015-03-20 18:52 ` [PATCH 1/5] drivers: soc: sunxi: Introduce SoC driver to map SRAMs Hans de Goede
@ 2015-03-24 15:19   ` Maxime Ripard
  2015-03-26 14:37     ` Hans de Goede
  0 siblings, 1 reply; 13+ messages in thread
From: Maxime Ripard @ 2015-03-24 15:19 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Fri, Mar 20, 2015 at 07:52:45PM +0100, Hans de Goede wrote:
> From: Maxime Ripard <maxime.ripard@free-electrons.com>
> 
> The Allwinner SoCs have a handful of SRAM that can be either mapped to be
> accessible by devices or the CPU.
> 
> That mapping is controlled by an SRAM controller, and that mapping might not be
> set by the bootloader, for example if the device wasn't used at all, or if
> we're using solutions like the U-Boot's Falcon Boot.
> 
> We could also imagine changing this at runtime for example to change the
> mapping of these SRAMs to use them for suspend/resume or runtime memory rate
> change, if that ever happens.
> 
> These use cases require some API in the kernel to control that mapping,
> exported through a drivers/soc driver.
> 
> This driver also implement a debugfs file that shows the SRAM found in the
> system, the current mapping and the SRAM that have been claimed by some drivers
> in the kernel.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> [hdegoede at redhat.com: Changed compat string to sun4i-a10-sram-controller, as
>  the sram controller is identical on sun4i, sun5i & sun7i, added devicetree
>  binding documentation, fixed some checkpatch warnings]
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  .../devicetree/bindings/soc/sunxi/sram.txt         |  64 ++++++
>  drivers/soc/Kconfig                                |   1 +
>  drivers/soc/Makefile                               |   1 +
>  drivers/soc/sunxi/Kconfig                          |  12 ++
>  drivers/soc/sunxi/Makefile                         |   1 +
>  drivers/soc/sunxi/sunxi_sram.c                     | 235 +++++++++++++++++++++
>  include/linux/soc/sunxi/sunxi_sram.h               |  24 +++
>  7 files changed, 338 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/soc/sunxi/sram.txt
>  create mode 100644 drivers/soc/sunxi/Kconfig
>  create mode 100644 drivers/soc/sunxi/Makefile
>  create mode 100644 drivers/soc/sunxi/sunxi_sram.c
>  create mode 100644 include/linux/soc/sunxi/sunxi_sram.h
> 
> diff --git a/Documentation/devicetree/bindings/soc/sunxi/sram.txt b/Documentation/devicetree/bindings/soc/sunxi/sram.txt
> new file mode 100644
> index 0000000..6e1bc80
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/sunxi/sram.txt
> @@ -0,0 +1,64 @@
> +Allwinnner sun4i / sun5i / sun7i SoC SRAM controllers
> +-----------------------------------------------------
> +
> +Required properties:
> +- compatible : "allwinner,sun4i-a10-sram-controller"
> +- reg : sram controller register offset + length
> +
> +SRAM nodes
> +----------
> +
> +Besides a node for the SRAM controller the devicetree must also contain a
> +node for each SRAM block controlled by the controller.
> +
> +Required sram node properties:
> +- compatible : "allwinner,sun4i-a10-sram"
> +- allwinner,sram-name : should be one of
> +  * "A1"
> +  * "A2"
> +  * "A3-A4"
> +  * "D"
> +
> +Example
> +-------
> +
> +/*
> + * Note we use the address were mmio register start, not where
                              ^ where

> + * the SRAM blocks starts, this cannot be changed because doing
                      ^ start

> + * doing so would be a devicetree ABI change.

One doing too many ? :)

> + */
> +soc at 01c00000 {
> +	compatible = "simple-bus";
> +	#address-cells = <1>;
> +	#size-cells = <1>;
> +	ranges;
> +
> +	sram at 00000000 {
> +		compatible = "allwinner,sun4i-a10-sram";
> +		reg = <0x00000000 0x4000>;
> +		allwinner,sram-name = "A1";
> +	};
> +
> +	sram at 00004000 {
> +		compatible = "allwinner,sun4i-a10-sram";
> +		reg = <0x00004000 0x4000>;
> +		allwinner,sram-name = "A2";
> +	};
> +
> +	sram at 00008000 {
> +		compatible = "allwinner,sun4i-a10-sram";
> +		reg = <0x00008000 0x4000>;
> +		allwinner,sram-name = "A3-A4";
> +	};
> +
> +	sram at 00010000 {
> +		compatible = "allwinner,sun4i-a10-sram";
> +		reg = <0x00010000 0x1000>;
> +		allwinner,sram-name = "D";
> +	};
> +
> +	sram-controller at 01c00000 {
> +		compatible = "allwinner,sun4i-a10-sram-controller";
> +		reg = <0x01c00000 0x30>;
> +	};
> +};
> diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
> index 76d6bd4..5d0f55d 100644
> --- a/drivers/soc/Kconfig
> +++ b/drivers/soc/Kconfig
> @@ -1,6 +1,7 @@
>  menu "SOC (System On Chip) specific Drivers"
>  
>  source "drivers/soc/qcom/Kconfig"
> +source "drivers/soc/sunxi/Kconfig"
>  source "drivers/soc/ti/Kconfig"
>  source "drivers/soc/versatile/Kconfig"
>  
> diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
> index 063113d..170bba3 100644
> --- a/drivers/soc/Makefile
> +++ b/drivers/soc/Makefile
> @@ -3,6 +3,7 @@
>  #
>  
>  obj-$(CONFIG_ARCH_QCOM)		+= qcom/
> +obj-$(CONFIG_ARCH_SUNXI)	+= sunxi/
>  obj-$(CONFIG_ARCH_TEGRA)	+= tegra/
>  obj-$(CONFIG_SOC_TI)		+= ti/
>  obj-$(CONFIG_PLAT_VERSATILE)	+= versatile/
> diff --git a/drivers/soc/sunxi/Kconfig b/drivers/soc/sunxi/Kconfig
> new file mode 100644
> index 0000000..212c634
> --- /dev/null
> +++ b/drivers/soc/sunxi/Kconfig
> @@ -0,0 +1,12 @@
> +#
> +# Allwinner sunXi SoC drivers
> +#
> +config SUNXI_SRAM
> +        tristate "Allwinner sunXi SRAM Controller"
> +        depends on ARCH_SUNXI
> +	default y

The indentation is off.

Also, that could probably be turned into an hidden option, with a
default y, so that we are sure that it's always going to be there.

Thanks,
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150324/4891405c/attachment.sig>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 2/5] ARM: dts: sun4i: Add A10 SRAM and SRAM controller
  2015-03-20 18:52 ` [PATCH 2/5] ARM: dts: sun4i: Add A10 SRAM and SRAM controller Hans de Goede
@ 2015-03-24 15:20   ` Maxime Ripard
  2015-03-26 14:42     ` Hans de Goede
  0 siblings, 1 reply; 13+ messages in thread
From: Maxime Ripard @ 2015-03-24 15:20 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Mar 20, 2015 at 07:52:46PM +0100, Hans de Goede wrote:
> The A10 has a few SRAM that can be mapped either to a device or to the CPU,
> with the mapping being controlled by a SRAM controller.
> 
> Since most of the time these SRAM won't be accessible by the CPU,
> we can't use the mmio-sram driver and compatible.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  arch/arm/boot/dts/sun4i-a10.dtsi | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
> index b66ebb3..88f57b4 100644
> --- a/arch/arm/boot/dts/sun4i-a10.dtsi
> +++ b/arch/arm/boot/dts/sun4i-a10.dtsi
> @@ -451,12 +451,46 @@
>  		};
>  	};
>  
> +	/*
> +	 * Note we use the address were mmio registers start, not where the
                                   ^ where

> +	 * SRAM blocks start, this cannot be changed because that would be
> +	 * a devicetree ABI change.
> +	 */
>  	soc at 01c00000 {
>  		compatible = "simple-bus";
>  		#address-cells = <1>;
>  		#size-cells = <1>;
>  		ranges;
>  
> +		sram at 00000000 {
> +			compatible = "allwinner,sun4i-a10-sram";
> +			reg = <0x00000000 0x4000>;
> +			allwinner,sram-name = "A1";
> +		};
> +
> +		sram at 00004000 {
> +			compatible = "allwinner,sun4i-a10-sram";
> +			reg = <0x00004000 0x4000>;
> +			allwinner,sram-name = "A2";
> +		};
> +
> +		sram at 00008000 {
> +			compatible = "allwinner,sun4i-a10-sram";
> +			reg = <0x00008000 0x4000>;
> +			allwinner,sram-name = "A3-A4";
> +		};
> +
> +		sram at 00010000 {
> +			compatible = "allwinner,sun4i-a10-sram";
> +			reg = <0x00010000 0x1000>;
> +			allwinner,sram-name = "D";
> +		};
> +
> +		sram-controller at 01c00000 {
> +			compatible = "allwinner,sun4i-a10-sram-controller";
> +			reg = <0x01c00000 0x30>;
> +		};
> +
>  		dma: dma-controller at 01c02000 {
>  			compatible = "allwinner,sun4i-a10-dma";
>  			reg = <0x01c02000 0x1000>;
> -- 
> 2.3.3
> 

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150324/b7687602/attachment-0001.sig>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 5/5] net: allwinner: emac: Claim our SRAM
  2015-03-20 18:52 ` [PATCH 5/5] net: allwinner: emac: Claim our SRAM Hans de Goede
  2015-03-20 18:53   ` Hans de Goede
@ 2015-03-24 15:22   ` Maxime Ripard
  2015-03-26 14:44     ` Hans de Goede
  1 sibling, 1 reply; 13+ messages in thread
From: Maxime Ripard @ 2015-03-24 15:22 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Mar 20, 2015 at 07:52:49PM +0100, Hans de Goede wrote:
> From: Maxime Ripard <maxime.ripard@free-electrons.com>
> 
> The SRAM the EMAC is using might not have been mapped accordingly by the
> bootloader, preventing the EMAC to work properly.
> 
> Ask for that SRAM to be mapped at probe time to make sure that this never
> happens.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> [hdegoede at redhat.com: Make sure SUNXI_SRAM gets enabled in Kconfig]
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/net/ethernet/allwinner/sun4i-emac.c | 13 +++++++++++--
>  drivers/net/ethernet/stmicro/stmmac/Kconfig |  1 +
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/allwinner/sun4i-emac.c b/drivers/net/ethernet/allwinner/sun4i-emac.c
> index f3470d9..9d0136b 100644
> --- a/drivers/net/ethernet/allwinner/sun4i-emac.c
> +++ b/drivers/net/ethernet/allwinner/sun4i-emac.c
> @@ -29,6 +29,8 @@
>  #include <linux/platform_device.h>
>  #include <linux/phy.h>
>  
> +#include <linux/soc/sunxi/sunxi_sram.h>
> +
>  #include "sun4i-emac.h"
>  
>  #define DRV_NAME		"sun4i-emac"
> @@ -857,11 +859,15 @@ static int emac_probe(struct platform_device *pdev)
>  
>  	clk_prepare_enable(db->clk);
>  
> +	ret = sunxi_sram_claim(SUNXI_SRAM_EMAC, "emac");
> +	if (ret)
> +		dev_warn(&pdev->dev, "Couldn't map SRAM to device\n");
> +
>  	db->phy_node = of_parse_phandle(np, "phy", 0);
>  	if (!db->phy_node) {
>  		dev_err(&pdev->dev, "no associated PHY\n");
>  		ret = -ENODEV;
> -		goto out;
> +		goto out_release_sram;
>  	}
>  
>  	/* Read MAC-address from DT */
> @@ -893,7 +899,7 @@ static int emac_probe(struct platform_device *pdev)
>  	if (ret) {
>  		dev_err(&pdev->dev, "Registering netdev failed!\n");
>  		ret = -ENODEV;
> -		goto out;
> +		goto out_release_sram;
>  	}
>  
>  	dev_info(&pdev->dev, "%s: at %p, IRQ %d MAC: %pM\n",
> @@ -901,6 +907,8 @@ static int emac_probe(struct platform_device *pdev)
>  
>  	return 0;
>  
> +out_release_sram:
> +	sunxi_sram_release(SUNXI_SRAM_EMAC);
>  out:
>  	dev_err(db->dev, "not found (%d).\n", ret);
>  
> @@ -914,6 +922,7 @@ static int emac_remove(struct platform_device *pdev)
>  	struct net_device *ndev = platform_get_drvdata(pdev);
>  
>  	unregister_netdev(ndev);
> +	sunxi_sram_release(SUNXI_SRAM_EMAC);
>  	free_netdev(ndev);
>  
>  	dev_dbg(&pdev->dev, "released and freed device\n");
> diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> index 7d3af19..785ca22 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
> +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> @@ -16,6 +16,7 @@ if STMMAC_ETH
>  config STMMAC_PLATFORM
>  	tristate "STMMAC Platform bus support"
>  	depends on STMMAC_ETH
> +	select SUNXI_SRAM if ARCH_SUNXI
>  	default y
>  	---help---
>  	  This selects the platform specific bus support for the stmmac driver.

Shouldn't that be in emac's Kconfig option instead?

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150324/690d9728/attachment.sig>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/5] drivers: soc: sunxi: Introduce SoC driver to map SRAMs
  2015-03-24 15:19   ` Maxime Ripard
@ 2015-03-26 14:37     ` Hans de Goede
  0 siblings, 0 replies; 13+ messages in thread
From: Hans de Goede @ 2015-03-26 14:37 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 24-03-15 16:19, Maxime Ripard wrote:
> Hi,
>
> On Fri, Mar 20, 2015 at 07:52:45PM +0100, Hans de Goede wrote:
>> From: Maxime Ripard <maxime.ripard@free-electrons.com>
>>
>> The Allwinner SoCs have a handful of SRAM that can be either mapped to be
>> accessible by devices or the CPU.
>>
>> That mapping is controlled by an SRAM controller, and that mapping might not be
>> set by the bootloader, for example if the device wasn't used at all, or if
>> we're using solutions like the U-Boot's Falcon Boot.
>>
>> We could also imagine changing this at runtime for example to change the
>> mapping of these SRAMs to use them for suspend/resume or runtime memory rate
>> change, if that ever happens.
>>
>> These use cases require some API in the kernel to control that mapping,
>> exported through a drivers/soc driver.
>>
>> This driver also implement a debugfs file that shows the SRAM found in the
>> system, the current mapping and the SRAM that have been claimed by some drivers
>> in the kernel.
>>
>> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
>> [hdegoede at redhat.com: Changed compat string to sun4i-a10-sram-controller, as
>>   the sram controller is identical on sun4i, sun5i & sun7i, added devicetree
>>   binding documentation, fixed some checkpatch warnings]
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>   .../devicetree/bindings/soc/sunxi/sram.txt         |  64 ++++++
>>   drivers/soc/Kconfig                                |   1 +
>>   drivers/soc/Makefile                               |   1 +
>>   drivers/soc/sunxi/Kconfig                          |  12 ++
>>   drivers/soc/sunxi/Makefile                         |   1 +
>>   drivers/soc/sunxi/sunxi_sram.c                     | 235 +++++++++++++++++++++
>>   include/linux/soc/sunxi/sunxi_sram.h               |  24 +++
>>   7 files changed, 338 insertions(+)
>>   create mode 100644 Documentation/devicetree/bindings/soc/sunxi/sram.txt
>>   create mode 100644 drivers/soc/sunxi/Kconfig
>>   create mode 100644 drivers/soc/sunxi/Makefile
>>   create mode 100644 drivers/soc/sunxi/sunxi_sram.c
>>   create mode 100644 include/linux/soc/sunxi/sunxi_sram.h
>>
>> diff --git a/Documentation/devicetree/bindings/soc/sunxi/sram.txt b/Documentation/devicetree/bindings/soc/sunxi/sram.txt
>> new file mode 100644
>> index 0000000..6e1bc80
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/soc/sunxi/sram.txt
>> @@ -0,0 +1,64 @@
>> +Allwinnner sun4i / sun5i / sun7i SoC SRAM controllers
>> +-----------------------------------------------------
>> +
>> +Required properties:
>> +- compatible : "allwinner,sun4i-a10-sram-controller"
>> +- reg : sram controller register offset + length
>> +
>> +SRAM nodes
>> +----------
>> +
>> +Besides a node for the SRAM controller the devicetree must also contain a
>> +node for each SRAM block controlled by the controller.
>> +
>> +Required sram node properties:
>> +- compatible : "allwinner,sun4i-a10-sram"
>> +- allwinner,sram-name : should be one of
>> +  * "A1"
>> +  * "A2"
>> +  * "A3-A4"
>> +  * "D"
>> +
>> +Example
>> +-------
>> +
>> +/*
>> + * Note we use the address were mmio register start, not where
>                                ^ where
>
>> + * the SRAM blocks starts, this cannot be changed because doing
>                        ^ start
>
>> + * doing so would be a devicetree ABI change.
>
> One doing too many ? :)

Both fixed.

>> + */
>> +soc at 01c00000 {
>> +	compatible = "simple-bus";
>> +	#address-cells = <1>;
>> +	#size-cells = <1>;
>> +	ranges;
>> +
>> +	sram at 00000000 {
>> +		compatible = "allwinner,sun4i-a10-sram";
>> +		reg = <0x00000000 0x4000>;
>> +		allwinner,sram-name = "A1";
>> +	};
>> +
>> +	sram at 00004000 {
>> +		compatible = "allwinner,sun4i-a10-sram";
>> +		reg = <0x00004000 0x4000>;
>> +		allwinner,sram-name = "A2";
>> +	};
>> +
>> +	sram at 00008000 {
>> +		compatible = "allwinner,sun4i-a10-sram";
>> +		reg = <0x00008000 0x4000>;
>> +		allwinner,sram-name = "A3-A4";
>> +	};
>> +
>> +	sram at 00010000 {
>> +		compatible = "allwinner,sun4i-a10-sram";
>> +		reg = <0x00010000 0x1000>;
>> +		allwinner,sram-name = "D";
>> +	};
>> +
>> +	sram-controller at 01c00000 {
>> +		compatible = "allwinner,sun4i-a10-sram-controller";
>> +		reg = <0x01c00000 0x30>;
>> +	};
>> +};
>> diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
>> index 76d6bd4..5d0f55d 100644
>> --- a/drivers/soc/Kconfig
>> +++ b/drivers/soc/Kconfig
>> @@ -1,6 +1,7 @@
>>   menu "SOC (System On Chip) specific Drivers"
>>
>>   source "drivers/soc/qcom/Kconfig"
>> +source "drivers/soc/sunxi/Kconfig"
>>   source "drivers/soc/ti/Kconfig"
>>   source "drivers/soc/versatile/Kconfig"
>>
>> diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
>> index 063113d..170bba3 100644
>> --- a/drivers/soc/Makefile
>> +++ b/drivers/soc/Makefile
>> @@ -3,6 +3,7 @@
>>   #
>>
>>   obj-$(CONFIG_ARCH_QCOM)		+= qcom/
>> +obj-$(CONFIG_ARCH_SUNXI)	+= sunxi/
>>   obj-$(CONFIG_ARCH_TEGRA)	+= tegra/
>>   obj-$(CONFIG_SOC_TI)		+= ti/
>>   obj-$(CONFIG_PLAT_VERSATILE)	+= versatile/
>> diff --git a/drivers/soc/sunxi/Kconfig b/drivers/soc/sunxi/Kconfig
>> new file mode 100644
>> index 0000000..212c634
>> --- /dev/null
>> +++ b/drivers/soc/sunxi/Kconfig
>> @@ -0,0 +1,12 @@
>> +#
>> +# Allwinner sunXi SoC drivers
>> +#
>> +config SUNXI_SRAM
>> +        tristate "Allwinner sunXi SRAM Controller"
>> +        depends on ARCH_SUNXI
>> +	default y
>
> The indentation is off.

That is because your original patch used 8 spaces instead of tabs,
fixed.

> Also, that could probably be turned into an hidden option, with a
> default y, so that we are sure that it's always going to be there.

Also done / fixed.

Regards,

Hans

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 2/5] ARM: dts: sun4i: Add A10 SRAM and SRAM controller
  2015-03-24 15:20   ` Maxime Ripard
@ 2015-03-26 14:42     ` Hans de Goede
  0 siblings, 0 replies; 13+ messages in thread
From: Hans de Goede @ 2015-03-26 14:42 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 24-03-15 16:20, Maxime Ripard wrote:
> On Fri, Mar 20, 2015 at 07:52:46PM +0100, Hans de Goede wrote:
>> The A10 has a few SRAM that can be mapped either to a device or to the CPU,
>> with the mapping being controlled by a SRAM controller.
>>
>> Since most of the time these SRAM won't be accessible by the CPU,
>> we can't use the mmio-sram driver and compatible.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>   arch/arm/boot/dts/sun4i-a10.dtsi | 34 ++++++++++++++++++++++++++++++++++
>>   1 file changed, 34 insertions(+)
>>
>> diff --git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
>> index b66ebb3..88f57b4 100644
>> --- a/arch/arm/boot/dts/sun4i-a10.dtsi
>> +++ b/arch/arm/boot/dts/sun4i-a10.dtsi
>> @@ -451,12 +451,46 @@
>>   		};
>>   	};
>>
>> +	/*
>> +	 * Note we use the address were mmio registers start, not where the
>                                     ^ where
>

Fixed in patches 2 to 4.

Regards,

Hans


>> +	 * SRAM blocks start, this cannot be changed because that would be
>> +	 * a devicetree ABI change.
>> +	 */
>>   	soc at 01c00000 {
>>   		compatible = "simple-bus";
>>   		#address-cells = <1>;
>>   		#size-cells = <1>;
>>   		ranges;
>>
>> +		sram at 00000000 {
>> +			compatible = "allwinner,sun4i-a10-sram";
>> +			reg = <0x00000000 0x4000>;
>> +			allwinner,sram-name = "A1";
>> +		};
>> +
>> +		sram at 00004000 {
>> +			compatible = "allwinner,sun4i-a10-sram";
>> +			reg = <0x00004000 0x4000>;
>> +			allwinner,sram-name = "A2";
>> +		};
>> +
>> +		sram at 00008000 {
>> +			compatible = "allwinner,sun4i-a10-sram";
>> +			reg = <0x00008000 0x4000>;
>> +			allwinner,sram-name = "A3-A4";
>> +		};
>> +
>> +		sram at 00010000 {
>> +			compatible = "allwinner,sun4i-a10-sram";
>> +			reg = <0x00010000 0x1000>;
>> +			allwinner,sram-name = "D";
>> +		};
>> +
>> +		sram-controller at 01c00000 {
>> +			compatible = "allwinner,sun4i-a10-sram-controller";
>> +			reg = <0x01c00000 0x30>;
>> +		};
>> +
>>   		dma: dma-controller at 01c02000 {
>>   			compatible = "allwinner,sun4i-a10-dma";
>>   			reg = <0x01c02000 0x1000>;
>> --
>> 2.3.3
>>
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 5/5] net: allwinner: emac: Claim our SRAM
  2015-03-24 15:22   ` Maxime Ripard
@ 2015-03-26 14:44     ` Hans de Goede
  0 siblings, 0 replies; 13+ messages in thread
From: Hans de Goede @ 2015-03-26 14:44 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On 24-03-15 16:22, Maxime Ripard wrote:
> On Fri, Mar 20, 2015 at 07:52:49PM +0100, Hans de Goede wrote:
>> From: Maxime Ripard <maxime.ripard@free-electrons.com>
>>
>> The SRAM the EMAC is using might not have been mapped accordingly by the
>> bootloader, preventing the EMAC to work properly.
>>
>> Ask for that SRAM to be mapped at probe time to make sure that this never
>> happens.
>>
>> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
>> [hdegoede at redhat.com: Make sure SUNXI_SRAM gets enabled in Kconfig]
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>   drivers/net/ethernet/allwinner/sun4i-emac.c | 13 +++++++++++--
>>   drivers/net/ethernet/stmicro/stmmac/Kconfig |  1 +
>>   2 files changed, 12 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/allwinner/sun4i-emac.c b/drivers/net/ethernet/allwinner/sun4i-emac.c
>> index f3470d9..9d0136b 100644
>> --- a/drivers/net/ethernet/allwinner/sun4i-emac.c
>> +++ b/drivers/net/ethernet/allwinner/sun4i-emac.c
>> @@ -29,6 +29,8 @@
>>   #include <linux/platform_device.h>
>>   #include <linux/phy.h>
>>
>> +#include <linux/soc/sunxi/sunxi_sram.h>
>> +
>>   #include "sun4i-emac.h"
>>
>>   #define DRV_NAME		"sun4i-emac"
>> @@ -857,11 +859,15 @@ static int emac_probe(struct platform_device *pdev)
>>
>>   	clk_prepare_enable(db->clk);
>>
>> +	ret = sunxi_sram_claim(SUNXI_SRAM_EMAC, "emac");
>> +	if (ret)
>> +		dev_warn(&pdev->dev, "Couldn't map SRAM to device\n");
>> +
>>   	db->phy_node = of_parse_phandle(np, "phy", 0);
>>   	if (!db->phy_node) {
>>   		dev_err(&pdev->dev, "no associated PHY\n");
>>   		ret = -ENODEV;
>> -		goto out;
>> +		goto out_release_sram;
>>   	}
>>
>>   	/* Read MAC-address from DT */
>> @@ -893,7 +899,7 @@ static int emac_probe(struct platform_device *pdev)
>>   	if (ret) {
>>   		dev_err(&pdev->dev, "Registering netdev failed!\n");
>>   		ret = -ENODEV;
>> -		goto out;
>> +		goto out_release_sram;
>>   	}
>>
>>   	dev_info(&pdev->dev, "%s: at %p, IRQ %d MAC: %pM\n",
>> @@ -901,6 +907,8 @@ static int emac_probe(struct platform_device *pdev)
>>
>>   	return 0;
>>
>> +out_release_sram:
>> +	sunxi_sram_release(SUNXI_SRAM_EMAC);
>>   out:
>>   	dev_err(db->dev, "not found (%d).\n", ret);
>>
>> @@ -914,6 +922,7 @@ static int emac_remove(struct platform_device *pdev)
>>   	struct net_device *ndev = platform_get_drvdata(pdev);
>>
>>   	unregister_netdev(ndev);
>> +	sunxi_sram_release(SUNXI_SRAM_EMAC);
>>   	free_netdev(ndev);
>>
>>   	dev_dbg(&pdev->dev, "released and freed device\n");
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
>> index 7d3af19..785ca22 100644
>> --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
>> +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
>> @@ -16,6 +16,7 @@ if STMMAC_ETH
>>   config STMMAC_PLATFORM
>>   	tristate "STMMAC Platform bus support"
>>   	depends on STMMAC_ETH
>> +	select SUNXI_SRAM if ARCH_SUNXI
>>   	default y
>>   	---help---
>>   	  This selects the platform specific bus support for the stmmac driver.
>
> Shouldn't that be in emac's Kconfig option instead?

Erm, yes my bad, or rather now that we've made SUNXI_SRAM a hidden option defaulting
to y, it can simply be dropped. I've done that for v2 of the set which I'm about to
send.

Regards,

Hans

>

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-03-26 14:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-20 18:52 [PATCH 0/5] ARM: sunxi: SRAM mapping support Hans de Goede
2015-03-20 18:52 ` [PATCH 1/5] drivers: soc: sunxi: Introduce SoC driver to map SRAMs Hans de Goede
2015-03-24 15:19   ` Maxime Ripard
2015-03-26 14:37     ` Hans de Goede
2015-03-20 18:52 ` [PATCH 2/5] ARM: dts: sun4i: Add A10 SRAM and SRAM controller Hans de Goede
2015-03-24 15:20   ` Maxime Ripard
2015-03-26 14:42     ` Hans de Goede
2015-03-20 18:52 ` [PATCH 3/5] ARM: dts: sun5i: Add A13 and A10s " Hans de Goede
2015-03-20 18:52 ` [PATCH 4/5] ARM: dts: sun7i: Add A20 " Hans de Goede
2015-03-20 18:52 ` [PATCH 5/5] net: allwinner: emac: Claim our SRAM Hans de Goede
2015-03-20 18:53   ` Hans de Goede
2015-03-24 15:22   ` Maxime Ripard
2015-03-26 14:44     ` Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).