linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/6] Add device tree support for on-chip SRAM
@ 2012-09-07 12:43 Philipp Zabel
  2012-09-07 12:43 ` [PATCH v4 1/6] genalloc: add a global pool list, allow to find pools by phys address Philipp Zabel
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Philipp Zabel @ 2012-09-07 12:43 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss

These patches add support to configure on-chip SRAM via device-tree
node and to obtain the resulting genalloc pool from a phandle pointing
at the node.
This allows drivers to allocate SRAM with the genalloc API without
hard-coding the genalloc pool address.

The on-chip SRAM on i.MX53 and i.MX6q is registered via device tree and
changed to use the simple generic SRAM driver:

		ocram: ocram@00900000 {
			compatible = "fsl,imx-ocram", "sram";
			reg = <0x00900000 0x3f000>;
 		};

A driver that needs to allocate SRAM buffers, like the video processing
unit on i.MX53, can retrieve the genalloc pool from a phandle in the
device tree using of_get_named_gen_pool(node, "iram", 0) from patch 1:

		vpu@63ff4000 {
			/* ... */
			iram = <&ocram>;
 		};

Changes since v3:
 - Added devicetree binding documentation
 - Register platform driver early with postcore_initcall
 - Added optional SRAM clock support.

regards
Philipp

---
 Documentation/devicetree/bindings/misc/sram.txt |   17 ++++
 arch/arm/boot/dts/imx53.dtsi                    |    5 +
 arch/arm/boot/dts/imx6q.dtsi                    |    5 +
 arch/arm/mach-imx/clk-imx6q.c                   |    1 +
 arch/arm/plat-mxc/Kconfig                       |    4 -
 arch/arm/plat-mxc/Makefile                      |    1 -
 arch/arm/plat-mxc/include/mach/iram.h           |   41 --------
 arch/arm/plat-mxc/iram_alloc.c                  |   73 --------------
 drivers/misc/Kconfig                            |    9 ++
 drivers/misc/Makefile                           |    1 +
 drivers/misc/sram.c                             |  121 +++++++++++++++++++++++
 include/linux/genalloc.h                        |   14 +++
 lib/genalloc.c                                  |   67 +++++++++++++
 13 files changed, 240 insertions(+), 119 deletions(-)


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

* [PATCH v4 1/6] genalloc: add a global pool list, allow to find pools by phys address
  2012-09-07 12:43 [PATCH v4 0/6] Add device tree support for on-chip SRAM Philipp Zabel
@ 2012-09-07 12:43 ` Philipp Zabel
  2012-09-07 12:43 ` [PATCH v4 2/6] misc: Generic on-chip SRAM allocation driver Philipp Zabel
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Philipp Zabel @ 2012-09-07 12:43 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

This patch keeps all created pools in a global list and adds two
functions that allow to retrieve the gen_pool pointer from a known
physical address and from a device tree node.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Shawn Guo <shawn.guo@linaro.org>
---
 include/linux/genalloc.h |   14 ++++++++++
 lib/genalloc.c           |   67 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)

diff --git a/include/linux/genalloc.h b/include/linux/genalloc.h
index 5e98eeb..d498c43 100644
--- a/include/linux/genalloc.h
+++ b/include/linux/genalloc.h
@@ -33,6 +33,7 @@
  *  General purpose special memory pool descriptor.
  */
 struct gen_pool {
+	struct list_head next_pool;	/* pool in global list */
 	spinlock_t lock;
 	struct list_head chunks;	/* list of chunks in this pool */
 	int min_alloc_order;		/* minimum allocation order */
@@ -78,4 +79,17 @@ extern void gen_pool_for_each_chunk(struct gen_pool *,
 	void (*)(struct gen_pool *, struct gen_pool_chunk *, void *), void *);
 extern size_t gen_pool_avail(struct gen_pool *);
 extern size_t gen_pool_size(struct gen_pool *);
+extern struct gen_pool *gen_pool_find_by_phys(phys_addr_t phys);
+
+struct device_node;
+#ifdef CONFIG_OF
+extern struct gen_pool *of_get_named_gen_pool(struct device_node *np,
+	const char *propname, int index);
+#else
+inline struct gen_pool *of_get_named_gen_pool(struct device_node *np,
+	const char *propname, int index)
+{
+	return NULL;
+}
+#endif
 #endif /* __GENALLOC_H__ */
diff --git a/lib/genalloc.c b/lib/genalloc.c
index 6bc04aa..90699ac 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -34,6 +34,11 @@
 #include <linux/rculist.h>
 #include <linux/interrupt.h>
 #include <linux/genalloc.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+
+static LIST_HEAD(pools);
+static DEFINE_SPINLOCK(list_lock);
 
 static int set_bits_ll(unsigned long *addr, unsigned long mask_to_set)
 {
@@ -152,6 +157,9 @@ struct gen_pool *gen_pool_create(int min_alloc_order, int nid)
 		spin_lock_init(&pool->lock);
 		INIT_LIST_HEAD(&pool->chunks);
 		pool->min_alloc_order = min_alloc_order;
+		spin_lock(&list_lock);
+		list_add_rcu(&pool->next_pool, &pools);
+		spin_unlock(&list_lock);
 	}
 	return pool;
 }
@@ -234,6 +242,9 @@ void gen_pool_destroy(struct gen_pool *pool)
 	int order = pool->min_alloc_order;
 	int bit, end_bit;
 
+	spin_lock(&list_lock);
+	list_del_rcu(&pool->next_pool);
+	spin_unlock(&list_lock);
 	list_for_each_safe(_chunk, _next_chunk, &pool->chunks) {
 		chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk);
 		list_del(&chunk->next_chunk);
@@ -400,3 +411,59 @@ size_t gen_pool_size(struct gen_pool *pool)
 	return size;
 }
 EXPORT_SYMBOL_GPL(gen_pool_size);
+
+/**
+ * gen_pool_find_by_phys - find a pool by physical start address
+ * @phys: physical address as added with gen_pool_add_virt
+ *
+ * Returns the pool that contains the chunk starting at phys,
+ * or NULL if not found.
+ */
+struct gen_pool *gen_pool_find_by_phys(phys_addr_t phys)
+{
+	struct gen_pool *pool, *found = NULL;
+	struct gen_pool_chunk *chunk;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(pool, &pools, next_pool) {
+		list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) {
+			if (phys == chunk->phys_addr) {
+				found = pool;
+				break;
+			}
+		}
+	}
+	rcu_read_unlock();
+
+	return found;
+}
+EXPORT_SYMBOL_GPL(gen_pool_find_by_phys);
+
+#ifdef CONFIG_OF
+/**
+ * of_get_named_gen_pool - find a pool by phandle property
+ * @np: device node
+ * @propname: property name containing phandle(s)
+ * @index: index into the phandle array
+ *
+ * Returns the pool that contains the chunk starting at the physical
+ * address of the device tree node pointed at by the phandle property,
+ * or NULL if not found.
+ */
+struct gen_pool *of_get_named_gen_pool(struct device_node *np,
+	const char *propname, int index)
+{
+	struct device_node *np_pool;
+	struct resource res;
+	int ret;
+
+	np_pool = of_parse_phandle(np, propname, index);
+	if (!np_pool)
+		return NULL;
+	ret = of_address_to_resource(np_pool, 0, &res);
+	if (ret < 0)
+		return NULL;
+	return gen_pool_find_by_phys((phys_addr_t) res.start);
+}
+EXPORT_SYMBOL_GPL(of_get_named_gen_pool);
+#endif /* CONFIG_OF */
-- 
1.7.10.4


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

* [PATCH v4 2/6] misc: Generic on-chip SRAM allocation driver
  2012-09-07 12:43 [PATCH v4 0/6] Add device tree support for on-chip SRAM Philipp Zabel
  2012-09-07 12:43 ` [PATCH v4 1/6] genalloc: add a global pool list, allow to find pools by phys address Philipp Zabel
@ 2012-09-07 12:43 ` Philipp Zabel
  2012-10-04 15:25   ` Matt Porter
  2012-09-07 12:43 ` [PATCH v4 3/6] ARM: dts: add sram for imx53 and imx6q Philipp Zabel
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Philipp Zabel @ 2012-09-07 12:43 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

This driver requests and remaps a memory region as configured in the
device tree. It serves memory from this region via the genalloc API.

Other drivers can retrieve the genalloc pool from a phandle pointing
to this drivers' device node in the device tree.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Shawn Guo <shawn.guo@linaro.org>
---
Changes since v3:
 - Added devicetree binding documentation
 - Register platform driver with postcore_initcall
---
 Documentation/devicetree/bindings/misc/sram.txt |   17 ++++
 drivers/misc/Kconfig                            |    9 ++
 drivers/misc/Makefile                           |    1 +
 drivers/misc/sram.c                             |  111 +++++++++++++++++++++++
 4 files changed, 138 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/sram.txt
 create mode 100644 drivers/misc/sram.c

diff --git a/Documentation/devicetree/bindings/misc/sram.txt b/Documentation/devicetree/bindings/misc/sram.txt
new file mode 100644
index 0000000..8bb26fc
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/sram.txt
@@ -0,0 +1,17 @@
+Generic on-chip SRAM
+
+Simple IO memory regions to be managed by the genalloc API.
+
+Required properties:
+
+- compatible : sram
+
+- reg : SRAM iomem address range
+
+Example:
+
+sram: sram@5c000000 {
+	compatible = "sram";
+	reg = <0x5c000000 0x40000>; /* 256 KiB SRAM at address 0x5c000000 */
+};
+
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 98a442d..9a3395f 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -509,6 +509,15 @@ config USB_SWITCH_FSA9480
 	  stereo and mono audio, video, microphone and UART data to use
 	  a common connector port.
 
+config SRAM
+	bool "Generic on-chip SRAM driver"
+	depends on HAS_IOMEM
+	select GENERIC_ALLOCATOR
+	help
+	  This driver allows to declare a memory region to be managed
+	  by the genalloc API. It is supposed to be used for small
+	  on-chip SRAM areas found on many ARM SoCs.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index b88df7a..ccc759a 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -50,3 +50,4 @@ obj-y				+= carma/
 obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
 obj-$(CONFIG_ALTERA_STAPL)	+=altera-stapl/
 obj-$(CONFIG_INTEL_MEI)		+= mei/
+obj-$(CONFIG_SRAM)		+= sram.o
diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
new file mode 100644
index 0000000..7a363f2
--- /dev/null
+++ b/drivers/misc/sram.c
@@ -0,0 +1,111 @@
+/*
+ * Generic on-chip SRAM allocation driver
+ *
+ * Copyright (C) 2012 Philipp Zabel, Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/spinlock.h>
+#include <linux/genalloc.h>
+
+struct sram_dev {
+	struct gen_pool *pool;
+};
+
+static int __devinit sram_probe(struct platform_device *pdev)
+{
+	void __iomem *virt_base;
+	struct sram_dev *sram;
+	struct resource *res;
+	unsigned long size;
+	int ret;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
+	size = resource_size(res);
+
+	virt_base = devm_request_and_ioremap(&pdev->dev, res);
+	if (!virt_base)
+		return -EADDRNOTAVAIL;
+
+	sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
+	if (!sram)
+		return -ENOMEM;
+
+	sram->pool = gen_pool_create(PAGE_SHIFT, -1);
+	if (!sram->pool)
+		return -ENOMEM;
+
+	ret = gen_pool_add_virt(sram->pool, (unsigned long)virt_base,
+				res->start, size, -1);
+	if (ret < 0) {
+		gen_pool_destroy(sram->pool);
+		return ret;
+	}
+
+	platform_set_drvdata(pdev, sram);
+
+	dev_dbg(&pdev->dev, "SRAM pool: %ld KiB @ 0x%p\n", size / 1024, virt_base);
+
+	return 0;
+}
+
+static int __devexit sram_remove(struct platform_device *pdev)
+{
+	struct sram_dev *sram = platform_get_drvdata(pdev);
+
+	if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool))
+		dev_dbg(&pdev->dev, "removed while SRAM allocated\n");
+
+	gen_pool_destroy(sram->pool);
+
+	return 0;
+}
+
+#ifdef CONFIG_OF
+static struct of_device_id sram_dt_ids[] = {
+	{ .compatible = "sram" },
+	{ /* sentinel */ }
+};
+#endif
+
+static struct platform_driver sram_driver = {
+	.driver = {
+		.name = "sram",
+		.of_match_table = of_match_ptr(sram_dt_ids),
+	},
+	.probe = sram_probe,
+	.remove = __devexit_p(sram_remove),
+};
+
+int __init sram_init(void)
+{
+	return platform_driver_register(&sram_driver);
+}
+
+postcore_initcall(sram_init);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Philipp Zabel, Pengutronix");
+MODULE_DESCRIPTION("Generic SRAM allocator driver");
-- 
1.7.10.4


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

* [PATCH v4 3/6] ARM: dts: add sram for imx53 and imx6q
  2012-09-07 12:43 [PATCH v4 0/6] Add device tree support for on-chip SRAM Philipp Zabel
  2012-09-07 12:43 ` [PATCH v4 1/6] genalloc: add a global pool list, allow to find pools by phys address Philipp Zabel
  2012-09-07 12:43 ` [PATCH v4 2/6] misc: Generic on-chip SRAM allocation driver Philipp Zabel
@ 2012-09-07 12:43 ` Philipp Zabel
  2012-09-07 12:43 ` [PATCH v4 4/6] ARM i.MX: remove IRAM_ALLOC facility Philipp Zabel
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Philipp Zabel @ 2012-09-07 12:43 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Shawn Guo <shawn.guo@linaro.org>
---
 arch/arm/boot/dts/imx53.dtsi |    5 +++++
 arch/arm/boot/dts/imx6q.dtsi |    5 +++++
 2 files changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/imx53.dtsi b/arch/arm/boot/dts/imx53.dtsi
index cd37165..2767a92 100644
--- a/arch/arm/boot/dts/imx53.dtsi
+++ b/arch/arm/boot/dts/imx53.dtsi
@@ -337,5 +337,10 @@
 				status = "disabled";
 			};
 		};
+
+		ocram: ocram@f8000000 {
+			compatible = "fsl,imx-ocram", "sram";
+			reg = <0xf8000000 0x20000>;
+		};
 	};
 };
diff --git a/arch/arm/boot/dts/imx6q.dtsi b/arch/arm/boot/dts/imx6q.dtsi
index fd57079..1e463c4 100644
--- a/arch/arm/boot/dts/imx6q.dtsi
+++ b/arch/arm/boot/dts/imx6q.dtsi
@@ -111,6 +111,11 @@
 		       status = "disabled";
 		};
 
+		ocram: ocram@00900000 {
+			compatible = "fsl,imx-ocram", "sram";
+			reg = <0x00900000 0x3f000>;
+		};
+
 		timer@00a00600 {
 			compatible = "arm,cortex-a9-twd-timer";
 			reg = <0x00a00600 0x20>;
-- 
1.7.10.4


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

* [PATCH v4 4/6] ARM i.MX: remove IRAM_ALLOC facility
  2012-09-07 12:43 [PATCH v4 0/6] Add device tree support for on-chip SRAM Philipp Zabel
                   ` (2 preceding siblings ...)
  2012-09-07 12:43 ` [PATCH v4 3/6] ARM: dts: add sram for imx53 and imx6q Philipp Zabel
@ 2012-09-07 12:43 ` Philipp Zabel
  2012-09-07 12:43 ` [PATCH v4 5/6] misc: sram: Add optional clock Philipp Zabel
  2012-09-07 12:43 ` [PATCH v4 6/6] ARM i.MX6q: Add ocram clkdev entry Philipp Zabel
  5 siblings, 0 replies; 9+ messages in thread
From: Philipp Zabel @ 2012-09-07 12:43 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

A generic on-chip SRAM allocator driver can be used instead.
Users of the iram_alloc/free API should convert to the genalloc API:

-	virt = iram_alloc(SIZE, &phys);
+	gen_pool_alloc(iram_pool, SIZE);
+	phys = gen_pool_virt_to_phys(iram_pool, virt);
 	/* ... */
-	iram_free(virt, SIZE);
+	gen_pool_free(iram_pool, virt, SIZE);

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Shawn Guo <shawn.guo@linaro.org>
---
 arch/arm/plat-mxc/Kconfig             |    4 --
 arch/arm/plat-mxc/Makefile            |    1 -
 arch/arm/plat-mxc/include/mach/iram.h |   41 ------------------
 arch/arm/plat-mxc/iram_alloc.c        |   73 ---------------------------------
 4 files changed, 119 deletions(-)
 delete mode 100644 arch/arm/plat-mxc/include/mach/iram.h
 delete mode 100644 arch/arm/plat-mxc/iram_alloc.c

diff --git a/arch/arm/plat-mxc/Kconfig b/arch/arm/plat-mxc/Kconfig
index baf9064..8e63f10 100644
--- a/arch/arm/plat-mxc/Kconfig
+++ b/arch/arm/plat-mxc/Kconfig
@@ -82,8 +82,4 @@ config IMX_HAVE_IOMUX_V1
 config ARCH_MXC_IOMUX_V3
 	bool
 
-config IRAM_ALLOC
-	bool
-	select GENERIC_ALLOCATOR
-
 endif
diff --git a/arch/arm/plat-mxc/Makefile b/arch/arm/plat-mxc/Makefile
index 6ac7200..bdf370f 100644
--- a/arch/arm/plat-mxc/Makefile
+++ b/arch/arm/plat-mxc/Makefile
@@ -10,7 +10,6 @@ obj-$(CONFIG_MXC_AVIC) += avic.o
 
 obj-$(CONFIG_IMX_HAVE_IOMUX_V1) += iomux-v1.o
 obj-$(CONFIG_ARCH_MXC_IOMUX_V3) += iomux-v3.o
-obj-$(CONFIG_IRAM_ALLOC) += iram_alloc.o
 obj-$(CONFIG_MXC_ULPI) += ulpi.o
 obj-$(CONFIG_MXC_USE_EPIT) += epit.o
 obj-$(CONFIG_MXC_DEBUG_BOARD) += 3ds_debugboard.o
diff --git a/arch/arm/plat-mxc/include/mach/iram.h b/arch/arm/plat-mxc/include/mach/iram.h
deleted file mode 100644
index 022690c..0000000
--- a/arch/arm/plat-mxc/include/mach/iram.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-#include <linux/errno.h>
-
-#ifdef CONFIG_IRAM_ALLOC
-
-int __init iram_init(unsigned long base, unsigned long size);
-void __iomem *iram_alloc(unsigned int size, unsigned long *dma_addr);
-void iram_free(unsigned long dma_addr, unsigned int size);
-
-#else
-
-static inline int __init iram_init(unsigned long base, unsigned long size)
-{
-	return -ENOMEM;
-}
-
-static inline void __iomem *iram_alloc(unsigned int size, unsigned long *dma_addr)
-{
-	return NULL;
-}
-
-static inline void iram_free(unsigned long base, unsigned long size) {}
-
-#endif
diff --git a/arch/arm/plat-mxc/iram_alloc.c b/arch/arm/plat-mxc/iram_alloc.c
deleted file mode 100644
index 074c386..0000000
--- a/arch/arm/plat-mxc/iram_alloc.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-
-#include <linux/kernel.h>
-#include <linux/io.h>
-#include <linux/module.h>
-#include <linux/spinlock.h>
-#include <linux/genalloc.h>
-#include <mach/iram.h>
-
-static unsigned long iram_phys_base;
-static void __iomem *iram_virt_base;
-static struct gen_pool *iram_pool;
-
-static inline void __iomem *iram_phys_to_virt(unsigned long p)
-{
-	return iram_virt_base + (p - iram_phys_base);
-}
-
-void __iomem *iram_alloc(unsigned int size, unsigned long *dma_addr)
-{
-	if (!iram_pool)
-		return NULL;
-
-	*dma_addr = gen_pool_alloc(iram_pool, size);
-	pr_debug("iram alloc - %dB@0x%lX\n", size, *dma_addr);
-	if (!*dma_addr)
-		return NULL;
-	return iram_phys_to_virt(*dma_addr);
-}
-EXPORT_SYMBOL(iram_alloc);
-
-void iram_free(unsigned long addr, unsigned int size)
-{
-	if (!iram_pool)
-		return;
-
-	gen_pool_free(iram_pool, addr, size);
-}
-EXPORT_SYMBOL(iram_free);
-
-int __init iram_init(unsigned long base, unsigned long size)
-{
-	iram_phys_base = base;
-
-	iram_pool = gen_pool_create(PAGE_SHIFT, -1);
-	if (!iram_pool)
-		return -ENOMEM;
-
-	gen_pool_add(iram_pool, base, size, -1);
-	iram_virt_base = ioremap(iram_phys_base, size);
-	if (!iram_virt_base)
-		return -EIO;
-
-	pr_debug("i.MX IRAM pool: %ld KB@0x%p\n", size / 1024, iram_virt_base);
-	return 0;
-}
-- 
1.7.10.4


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

* [PATCH v4 5/6] misc: sram: Add optional clock
  2012-09-07 12:43 [PATCH v4 0/6] Add device tree support for on-chip SRAM Philipp Zabel
                   ` (3 preceding siblings ...)
  2012-09-07 12:43 ` [PATCH v4 4/6] ARM i.MX: remove IRAM_ALLOC facility Philipp Zabel
@ 2012-09-07 12:43 ` Philipp Zabel
  2012-09-07 12:43 ` [PATCH v4 6/6] ARM i.MX6q: Add ocram clkdev entry Philipp Zabel
  5 siblings, 0 replies; 9+ messages in thread
From: Philipp Zabel @ 2012-09-07 12:43 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

On some platforms the SRAM needs a clock to be enabled explicitly.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/misc/sram.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
index 7a363f2..0cc2e75 100644
--- a/drivers/misc/sram.c
+++ b/drivers/misc/sram.c
@@ -21,6 +21,8 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/clk.h>
+#include <linux/err.h>
 #include <linux/io.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
@@ -29,6 +31,7 @@
 
 struct sram_dev {
 	struct gen_pool *pool;
+	struct clk *clk;
 };
 
 static int __devinit sram_probe(struct platform_device *pdev)
@@ -53,6 +56,10 @@ static int __devinit sram_probe(struct platform_device *pdev)
 	if (!sram)
 		return -ENOMEM;
 
+	sram->clk = devm_clk_get(&pdev->dev, NULL);
+	if (!IS_ERR(sram->clk))
+		clk_prepare_enable(sram->clk);
+
 	sram->pool = gen_pool_create(PAGE_SHIFT, -1);
 	if (!sram->pool)
 		return -ENOMEM;
@@ -80,6 +87,9 @@ static int __devexit sram_remove(struct platform_device *pdev)
 
 	gen_pool_destroy(sram->pool);
 
+	if (!IS_ERR(sram->clk))
+		clk_disable_unprepare(sram->clk);
+
 	return 0;
 }
 
-- 
1.7.10.4


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

* [PATCH v4 6/6] ARM i.MX6q: Add ocram clkdev entry
  2012-09-07 12:43 [PATCH v4 0/6] Add device tree support for on-chip SRAM Philipp Zabel
                   ` (4 preceding siblings ...)
  2012-09-07 12:43 ` [PATCH v4 5/6] misc: sram: Add optional clock Philipp Zabel
@ 2012-09-07 12:43 ` Philipp Zabel
  5 siblings, 0 replies; 9+ messages in thread
From: Philipp Zabel @ 2012-09-07 12:43 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss
  Cc: Philipp Zabel

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 arch/arm/mach-imx/clk-imx6q.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-imx/clk-imx6q.c b/arch/arm/mach-imx/clk-imx6q.c
index 4233d9e..5912966 100644
--- a/arch/arm/mach-imx/clk-imx6q.c
+++ b/arch/arm/mach-imx/clk-imx6q.c
@@ -439,6 +439,7 @@ int __init mx6q_clocks_init(void)
 	clk_register_clkdev(clk[cko1_sel], "cko1_sel", NULL);
 	clk_register_clkdev(clk[ahb], "ahb", NULL);
 	clk_register_clkdev(clk[cko1], "cko1", NULL);
+	clk_register_clkdev(clk[ocram], NULL, "900000.ocram");
 
 	for (i = 0; i < ARRAY_SIZE(clks_init_on); i++)
 		clk_prepare_enable(clk[clks_init_on[i]]);
-- 
1.7.10.4


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

* Re: [PATCH v4 2/6] misc: Generic on-chip SRAM allocation driver
  2012-09-07 12:43 ` [PATCH v4 2/6] misc: Generic on-chip SRAM allocation driver Philipp Zabel
@ 2012-10-04 15:25   ` Matt Porter
  2012-10-05  8:40     ` Philipp Zabel
  0 siblings, 1 reply; 9+ messages in thread
From: Matt Porter @ 2012-10-04 15:25 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss

On Fri, Sep 07, 2012 at 02:43:44PM +0200, Philipp Zabel wrote:
> This driver requests and remaps a memory region as configured in the
> device tree. It serves memory from this region via the genalloc API.
> 
> Other drivers can retrieve the genalloc pool from a phandle pointing
> to this drivers' device node in the device tree.

<snip>

> +	sram->pool = gen_pool_create(PAGE_SHIFT, -1);
> +	if (!sram->pool)
> +		return -ENOMEM;

As mentioned in the uio_pruss/genalloc discussion, removing the
hardcoded minimum allocation order will allow this to be used for
a number of other cases. The most notable is moving mach-davinci/
off of its own genalloc-based SRAM arch driver. Some of the davinci
SoCs have very small SRAMs and need the ability to allocate a smaller
chunk.

Here's a build-tested patch to add this option:

>From 6eced8c31eba2f86e72e854cf404d8f58fbeba85 Mon Sep 17 00:00:00 2001
From: Matt Porter <mporter@ti.com>
Date: Thu, 4 Oct 2012 11:08:02 -0400
Subject: [PATCH] misc: sram: add support for configurable allocation order

Adds support for setting the genalloc pool's minimum allocation
order via DT or platform data. The allocation order is optional
for both the DT property and platform data case. If it is not
present then the order defaults to PAGE_SHIFT to preserve the
current behavior.

Signed-off-by: Matt Porter <mporter@ti.com>
---
 Documentation/devicetree/bindings/misc/sram.txt |   12 ++++++++++-
 drivers/misc/sram.c                             |   14 ++++++++++++-
 include/linux/platform_data/sram.h              |   25 +++++++++++++++++++++++
 3 files changed, 49 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/platform_data/sram.h

diff --git a/Documentation/devicetree/bindings/misc/sram.txt b/Documentation/devicetree/bindings/misc/sram.txt
index b64136c..b1705ec 100644
--- a/Documentation/devicetree/bindings/misc/sram.txt
+++ b/Documentation/devicetree/bindings/misc/sram.txt
@@ -8,10 +8,20 @@ Required properties:
 
 - reg : SRAM iomem address range
 
-Example:
+Optional properties:
+
+- alloc-order : Minimum allocation order for the SRAM pool
+
+Examples:
+
+sram: sram@5c000000 {
+	compatible = "sram";
+	reg = <0x5c000000 0x40000>; /* 256 KiB SRAM at address 0x5c000000 */
+};
 
 sram: sram@5c000000 {
 	compatible = "sram";
 	reg = <0x5c000000 0x40000>; /* 256 KiB SRAM at address 0x5c000000 */
+	alloc-order = <9>; /* Minimum 512 byte allocation */
 };
 
diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
index 7a363f2..3bf8ed3 100644
--- a/drivers/misc/sram.c
+++ b/drivers/misc/sram.c
@@ -26,6 +26,7 @@
 #include <linux/platform_device.h>
 #include <linux/spinlock.h>
 #include <linux/genalloc.h>
+#include <linux/platform_data/sram.h>
 
 struct sram_dev {
 	struct gen_pool *pool;
@@ -37,6 +38,7 @@ static int __devinit sram_probe(struct platform_device *pdev)
 	struct sram_dev *sram;
 	struct resource *res;
 	unsigned long size;
+	u32 alloc_order = PAGE_SHIFT;
 	int ret;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -53,7 +55,17 @@ static int __devinit sram_probe(struct platform_device *pdev)
 	if (!sram)
 		return -ENOMEM;
 
-	sram->pool = gen_pool_create(PAGE_SHIFT, -1);
+	if (pdev->dev.of_node)
+		of_property_read_u32(pdev->dev.of_node,
+				     "alloc-order", &alloc_order);
+	else
+		if (pdev->dev.platform_data) {
+			struct sram_pdata *pdata = pdev->dev.platform_data;
+			if (pdata->alloc_order)
+				alloc_order = pdata->alloc_order;
+		}
+
+	sram->pool = gen_pool_create(alloc_order, -1);
 	if (!sram->pool)
 		return -ENOMEM;
 
diff --git a/include/linux/platform_data/sram.h b/include/linux/platform_data/sram.h
new file mode 100644
index 0000000..e17bdaa
--- /dev/null
+++ b/include/linux/platform_data/sram.h
@@ -0,0 +1,25 @@
+/*
+ * include/linux/platform_data/sram.h
+ *
+ * Platform data for generic sram driver
+ *
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _SRAM_H_
+#define _SRAM_H_
+
+struct sram_pdata {
+	unsigned alloc_order;	/* Optional: driver defaults to PAGE_SHIFT */
+};
+
+#endif /* _SRAM_H_ */
-- 
1.7.9.5


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

* Re: [PATCH v4 2/6] misc: Generic on-chip SRAM allocation driver
  2012-10-04 15:25   ` Matt Porter
@ 2012-10-05  8:40     ` Philipp Zabel
  0 siblings, 0 replies; 9+ messages in thread
From: Philipp Zabel @ 2012-10-05  8:40 UTC (permalink / raw)
  To: Matt Porter
  Cc: linux-kernel, linux-arm-kernel, Grant Likely, Rob Herring,
	Paul Gortmaker, Shawn Guo, Richard Zhao, Huang Shijie,
	Dong Aisheng, kernel, devicetree-discuss

Am Donnerstag, den 04.10.2012, 11:25 -0400 schrieb Matt Porter:
> On Fri, Sep 07, 2012 at 02:43:44PM +0200, Philipp Zabel wrote:
> > This driver requests and remaps a memory region as configured in the
> > device tree. It serves memory from this region via the genalloc API.
> > 
> > Other drivers can retrieve the genalloc pool from a phandle pointing
> > to this drivers' device node in the device tree.
> 
> <snip>
> 
> > +	sram->pool = gen_pool_create(PAGE_SHIFT, -1);
> > +	if (!sram->pool)
> > +		return -ENOMEM;
> 
> As mentioned in the uio_pruss/genalloc discussion, removing the
> hardcoded minimum allocation order will allow this to be used for
> a number of other cases. The most notable is moving mach-davinci/
> off of its own genalloc-based SRAM arch driver. Some of the davinci
> SoCs have very small SRAMs and need the ability to allocate a smaller
> chunk.
> 
> Here's a build-tested patch to add this option:

Thank you,

> From 6eced8c31eba2f86e72e854cf404d8f58fbeba85 Mon Sep 17 00:00:00 2001
> From: Matt Porter <mporter@ti.com>
> Date: Thu, 4 Oct 2012 11:08:02 -0400
> Subject: [PATCH] misc: sram: add support for configurable allocation order
> 
> Adds support for setting the genalloc pool's minimum allocation
> order via DT or platform data. The allocation order is optional
> for both the DT property and platform data case. If it is not
> present then the order defaults to PAGE_SHIFT to preserve the
> current behavior.
> 
> Signed-off-by: Matt Porter <mporter@ti.com>

Tested-by: Philipp Zabel <p.zabel@pengutronix.de>

> ---
>  Documentation/devicetree/bindings/misc/sram.txt |   12 ++++++++++-
>  drivers/misc/sram.c                             |   14 ++++++++++++-
>  include/linux/platform_data/sram.h              |   25 +++++++++++++++++++++++
>  3 files changed, 49 insertions(+), 2 deletions(-)
>  create mode 100644 include/linux/platform_data/sram.h
> 
> diff --git a/Documentation/devicetree/bindings/misc/sram.txt b/Documentation/devicetree/bindings/misc/sram.txt
> index b64136c..b1705ec 100644
> --- a/Documentation/devicetree/bindings/misc/sram.txt
> +++ b/Documentation/devicetree/bindings/misc/sram.txt
> @@ -8,10 +8,20 @@ Required properties:
>  
>  - reg : SRAM iomem address range
>  
> -Example:
> +Optional properties:
> +
> +- alloc-order : Minimum allocation order for the SRAM pool
> +
> +Examples:
> +
> +sram: sram@5c000000 {
> +	compatible = "sram";
> +	reg = <0x5c000000 0x40000>; /* 256 KiB SRAM at address 0x5c000000 */
> +};
>  
>  sram: sram@5c000000 {
>  	compatible = "sram";
>  	reg = <0x5c000000 0x40000>; /* 256 KiB SRAM at address 0x5c000000 */
> +	alloc-order = <9>; /* Minimum 512 byte allocation */
>  };
>  
> diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
> index 7a363f2..3bf8ed3 100644
> --- a/drivers/misc/sram.c
> +++ b/drivers/misc/sram.c
> @@ -26,6 +26,7 @@
>  #include <linux/platform_device.h>
>  #include <linux/spinlock.h>
>  #include <linux/genalloc.h>
> +#include <linux/platform_data/sram.h>
>  
>  struct sram_dev {
>  	struct gen_pool *pool;
> @@ -37,6 +38,7 @@ static int __devinit sram_probe(struct platform_device *pdev)
>  	struct sram_dev *sram;
>  	struct resource *res;
>  	unsigned long size;
> +	u32 alloc_order = PAGE_SHIFT;
>  	int ret;
>  
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -53,7 +55,17 @@ static int __devinit sram_probe(struct platform_device *pdev)
>  	if (!sram)
>  		return -ENOMEM;
>  
> -	sram->pool = gen_pool_create(PAGE_SHIFT, -1);
> +	if (pdev->dev.of_node)
> +		of_property_read_u32(pdev->dev.of_node,
> +				     "alloc-order", &alloc_order);
> +	else
> +		if (pdev->dev.platform_data) {
> +			struct sram_pdata *pdata = pdev->dev.platform_data;
> +			if (pdata->alloc_order)
> +				alloc_order = pdata->alloc_order;
> +		}
> +
> +	sram->pool = gen_pool_create(alloc_order, -1);
>  	if (!sram->pool)
>  		return -ENOMEM;
>  
> diff --git a/include/linux/platform_data/sram.h b/include/linux/platform_data/sram.h
> new file mode 100644
> index 0000000..e17bdaa
> --- /dev/null
> +++ b/include/linux/platform_data/sram.h
> @@ -0,0 +1,25 @@
> +/*
> + * include/linux/platform_data/sram.h
> + *
> + * Platform data for generic sram driver
> + *
> + * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation version 2.
> + *
> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
> + * kind, whether express or implied; without even the implied warranty
> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#ifndef _SRAM_H_
> +#define _SRAM_H_
> +
> +struct sram_pdata {
> +	unsigned alloc_order;	/* Optional: driver defaults to PAGE_SHIFT */
> +};
> +
> +#endif /* _SRAM_H_ */



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

end of thread, other threads:[~2012-10-05  8:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-07 12:43 [PATCH v4 0/6] Add device tree support for on-chip SRAM Philipp Zabel
2012-09-07 12:43 ` [PATCH v4 1/6] genalloc: add a global pool list, allow to find pools by phys address Philipp Zabel
2012-09-07 12:43 ` [PATCH v4 2/6] misc: Generic on-chip SRAM allocation driver Philipp Zabel
2012-10-04 15:25   ` Matt Porter
2012-10-05  8:40     ` Philipp Zabel
2012-09-07 12:43 ` [PATCH v4 3/6] ARM: dts: add sram for imx53 and imx6q Philipp Zabel
2012-09-07 12:43 ` [PATCH v4 4/6] ARM i.MX: remove IRAM_ALLOC facility Philipp Zabel
2012-09-07 12:43 ` [PATCH v4 5/6] misc: sram: Add optional clock Philipp Zabel
2012-09-07 12:43 ` [PATCH v4 6/6] ARM i.MX6q: Add ocram clkdev entry Philipp Zabel

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).