* [PATCH RFC] arm/imx: provide command to add ram device with autodetected size
@ 2012-07-26 9:53 Uwe Kleine-König
2012-07-26 10:17 ` Juergen Beisert
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2012-07-26 9:53 UTC (permalink / raw)
To: barebox
The amount of available ram is determined by the ESDCTL register, so
better don't hardcode the value.
This commit provides a command that can be used instead of
arm_add_mem_device and convertes pcm043 (on which this patch was tested)
to it.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,
maybe better move the new function into a new file
arch/arm/mach-imx/esdctl.c and the prototype into <mach/esdctl.h>?
Also imx_add_ram1() is still missing. I will implement that when we
agree the patch's idea is useful.
Best regards
Uwe
arch/arm/boards/pcm043/pcm043.c | 2 +-
arch/arm/mach-imx/devices.c | 34 ++++++++++++++++++++++++++++++
arch/arm/mach-imx/include/mach/devices.h | 1 +
arch/arm/mach-imx/include/mach/esdctl.h | 1 +
4 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/arch/arm/boards/pcm043/pcm043.c b/arch/arm/boards/pcm043/pcm043.c
index 152b47c..b1bf8ef 100644
--- a/arch/arm/boards/pcm043/pcm043.c
+++ b/arch/arm/boards/pcm043/pcm043.c
@@ -103,7 +103,7 @@ static struct imx_ipu_fb_platform_data ipu_fb_data = {
static int pcm043_mem_init(void)
{
- arm_add_mem_device("ram0", IMX_SDRAM_CS0, SZ_128M);
+ imx_add_ram0();
return 0;
}
diff --git a/arch/arm/mach-imx/devices.c b/arch/arm/mach-imx/devices.c
index 6cd50f3..ca98a80 100644
--- a/arch/arm/mach-imx/devices.c
+++ b/arch/arm/mach-imx/devices.c
@@ -1,6 +1,10 @@
#include <common.h>
#include <driver.h>
#include <mach/devices.h>
+#include <mach/esdctl.h>
+#include <mach/imx-regs.h>
+#include <asm/io.h>
+#include <asm/memory.h>
static inline struct device_d *imx_add_device(char *name, int id, void *base, int size, void *pdata)
{
@@ -52,3 +56,33 @@ struct device_d *imx_add_esdhc(void *base, int id, struct esdhc_platform_data *p
{
return imx_add_device("imx-esdhc", id, base, 0x1000, pdata);
}
+
+static void imx_add_ram(const char* name, resource_size_t base,
+ void __iomem *esdctladdr)
+{
+ u32 esdctl = readl(esdctladdr);
+ /*
+ * with the fields ROW, COL and DSIZ all zero we have 11 rows, 8 cols
+ * and 2 bytes bus width on 4 banks.
+ */
+ resource_size_t size = 4 << (11 + 8 + 1);
+
+ if (!(esdctl & ESDCTL0_SDE))
+ /* SDRAM controller disabled, so no RAM here */
+ return;
+
+ /* calculate memory size: 4 banks * 2^#rows * 2^#cols * bytes/word */
+ size <<= (esdctl & ESDCTL0_ROW_MASK) >> 24;
+ size <<= (esdctl & ESDCTL0_COL_MASK) >> 20;
+
+ if ((esdctl & ESDCTL0_DSIZ_MASK) == ESDCTL0_DSIZ_31_0)
+ /* 4 bytes bus width */
+ size <<= 1;
+
+ arm_add_mem_device(name, base, size);
+}
+
+void imx_add_ram0(void)
+{
+ imx_add_ram("ram0", (resource_size_t)IMX_SDRAM_CS0, (void __iomem *)ESDCTL0);
+}
diff --git a/arch/arm/mach-imx/include/mach/devices.h b/arch/arm/mach-imx/include/mach/devices.h
index f0f730a..317ad17 100644
--- a/arch/arm/mach-imx/include/mach/devices.h
+++ b/arch/arm/mach-imx/include/mach/devices.h
@@ -17,3 +17,4 @@ struct device_d *imx_add_ipufb(void *base, struct imx_ipu_fb_platform_data *pdat
struct device_d *imx_add_mmc(void *base, int id, void *pdata);
struct device_d *imx_add_esdhc(void *base, int id, struct esdhc_platform_data *pdata);
+void imx_add_ram0(void);
diff --git a/arch/arm/mach-imx/include/mach/esdctl.h b/arch/arm/mach-imx/include/mach/esdctl.h
index 10c8b9b..91d4141 100644
--- a/arch/arm/mach-imx/include/mach/esdctl.h
+++ b/arch/arm/mach-imx/include/mach/esdctl.h
@@ -26,6 +26,7 @@
#define ESDCTL0_DSIZ_31_16 (0 << 16)
#define ESDCTL0_DSIZ_15_0 (1 << 16)
#define ESDCTL0_DSIZ_31_0 (2 << 16)
+#define ESDCTL0_DSIZ_MASK (3 << 16)
#define ESDCTL0_REF1 (1 << 13)
#define ESDCTL0_REF2 (2 << 13)
#define ESDCTL0_REF4 (3 << 13)
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RFC] arm/imx: provide command to add ram device with autodetected size
2012-07-26 9:53 [PATCH RFC] arm/imx: provide command to add ram device with autodetected size Uwe Kleine-König
@ 2012-07-26 10:17 ` Juergen Beisert
2012-07-27 8:14 ` Sascha Hauer
2012-08-02 16:32 ` [PATCH v2] " Uwe Kleine-König
2 siblings, 0 replies; 5+ messages in thread
From: Juergen Beisert @ 2012-07-26 10:17 UTC (permalink / raw)
To: barebox; +Cc: Uwe Kleine-König
Uwe Kleine-König wrote:
> The amount of available ram is determined by the ESDCTL register, so
> better don't hardcode the value.
>
> This commit provides a command that can be used instead of
> arm_add_mem_device and convertes pcm043 (on which this patch was tested)
> to it.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
>
> maybe better move the new function into a new file
> arch/arm/mach-imx/esdctl.c and the prototype into <mach/esdctl.h>?
>
> Also imx_add_ram1() is still missing. I will implement that when we
> agree the patch's idea is useful.
It is a really good idea. I is useful for all my Samsung targets, too.
Maybe it should be a generic feature, because *most* of the supported SoCs are
able to detect the available RAM size in such a way.
jbe
--
Pengutronix e.K. | Juergen Beisert |
Linux Solutions for Science and Industry | http://www.pengutronix.de/ |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RFC] arm/imx: provide command to add ram device with autodetected size
2012-07-26 9:53 [PATCH RFC] arm/imx: provide command to add ram device with autodetected size Uwe Kleine-König
2012-07-26 10:17 ` Juergen Beisert
@ 2012-07-27 8:14 ` Sascha Hauer
2012-08-02 16:32 ` [PATCH v2] " Uwe Kleine-König
2 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-07-27 8:14 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: barebox
On Thu, Jul 26, 2012 at 11:53:40AM +0200, Uwe Kleine-König wrote:
> The amount of available ram is determined by the ESDCTL register, so
> better don't hardcode the value.
>
> This commit provides a command that can be used instead of
> arm_add_mem_device and convertes pcm043 (on which this patch was tested)
> to it.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
>
> maybe better move the new function into a new file
> arch/arm/mach-imx/esdctl.c and the prototype into <mach/esdctl.h>?
>
> Also imx_add_ram1() is still missing. I will implement that when we
> agree the patch's idea is useful.
I agree it's useful
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] arm/imx: provide command to add ram device with autodetected size
2012-07-26 9:53 [PATCH RFC] arm/imx: provide command to add ram device with autodetected size Uwe Kleine-König
2012-07-26 10:17 ` Juergen Beisert
2012-07-27 8:14 ` Sascha Hauer
@ 2012-08-02 16:32 ` Uwe Kleine-König
2012-08-03 13:26 ` Sascha Hauer
2 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2012-08-02 16:32 UTC (permalink / raw)
To: barebox
The amount of available ram is determined by the ESDCTL register, so
better don't hardcode the value.
This commit provides a command that can be used instead of
arm_add_mem_device and convertes pcm043 (on which this patch was tested)
to it.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
changes since implicit v1:
- support 2nd sdram chip select
- move implementation to arch/arm/mach-imx/esdctl.c
arch/arm/boards/pcm043/pcm043.c | 3 ++-
arch/arm/mach-imx/Makefile | 2 +-
arch/arm/mach-imx/esdctl.c | 45 +++++++++++++++++++++++++++++++
arch/arm/mach-imx/include/mach/esdctl.h | 3 +++
4 files changed, 51 insertions(+), 2 deletions(-)
create mode 100644 arch/arm/mach-imx/esdctl.c
diff --git a/arch/arm/boards/pcm043/pcm043.c b/arch/arm/boards/pcm043/pcm043.c
index 65e0586..3a309c4 100644
--- a/arch/arm/boards/pcm043/pcm043.c
+++ b/arch/arm/boards/pcm043/pcm043.c
@@ -46,6 +46,7 @@
#include <mach/imx-pll.h>
#include <mach/iomux-mx35.h>
#include <mach/devices-imx35.h>
+#include <mach/esdctl.h>
static struct fec_platform_data fec_info = {
.xcv_type = MII100,
@@ -103,7 +104,7 @@ static struct imx_ipu_fb_platform_data ipu_fb_data = {
static int pcm043_mem_init(void)
{
- arm_add_mem_device("ram0", IMX_SDRAM_CS0, SZ_128M);
+ imx_add_ram0();
return 0;
}
diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 03e2421..cc6fa5e 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -1,4 +1,4 @@
-obj-y += clocksource.o gpio.o
+obj-y += clocksource.o gpio.o esdctl.o
obj-$(CONFIG_ARCH_IMX1) += speed-imx1.o imx1.o iomux-v1.o
obj-$(CONFIG_ARCH_IMX25) += speed-imx25.o imx25.o iomux-v3.o
obj-$(CONFIG_ARCH_IMX21) += speed-imx21.o imx21.o iomux-v1.o
diff --git a/arch/arm/mach-imx/esdctl.c b/arch/arm/mach-imx/esdctl.c
new file mode 100644
index 0000000..8695c12
--- /dev/null
+++ b/arch/arm/mach-imx/esdctl.c
@@ -0,0 +1,45 @@
+#include <mach/esdctl.h>
+#include <mach/imx-regs.h>
+#include <asm/io.h>
+#include <asm/memory.h>
+
+static void imx_add_ram(const char* name, resource_size_t base,
+ void __iomem *esdctladdr)
+{
+ u32 esdctl = readl(esdctladdr);
+ /*
+ * with the fields ROW, COL and DSIZ all zero we have 11 rows, 8 cols
+ * and 2 bytes bus width on 4 banks.
+ */
+ resource_size_t size = 4 << (11 + 8 + 1);
+
+ if (!(esdctl & ESDCTL0_SDE))
+ /* SDRAM controller disabled, so no RAM here */
+ return;
+
+ /* calculate memory size: 4 banks * 2^#rows * 2^#cols * bytes/word */
+ size <<= (esdctl & ESDCTL0_ROW_MASK) >> 24;
+ size <<= (esdctl & ESDCTL0_COL_MASK) >> 20;
+
+ if ((esdctl & ESDCTL0_DSIZ_MASK) == ESDCTL0_DSIZ_31_0)
+ /* 4 bytes bus width */
+ size <<= 1;
+
+ arm_add_mem_device(name, base, size);
+}
+
+void imx_add_ram0(void)
+{
+ imx_add_ram("ram0", (resource_size_t)IMX_SDRAM_CS0, (void __iomem *)ESDCTL0);
+}
+
+void imx_add_ram1(void)
+{
+ imx_add_ram("ram1", (resource_size_t)IMX_SDRAM_CS1, (void __iomem *)ESDCTL1);
+}
+
+void imx_add_ram_auto(void)
+{
+ imx_add_ram0();
+ imx_add_ram1();
+}
diff --git a/arch/arm/mach-imx/include/mach/esdctl.h b/arch/arm/mach-imx/include/mach/esdctl.h
index 10c8b9b..688f799 100644
--- a/arch/arm/mach-imx/include/mach/esdctl.h
+++ b/arch/arm/mach-imx/include/mach/esdctl.h
@@ -26,6 +26,7 @@
#define ESDCTL0_DSIZ_31_16 (0 << 16)
#define ESDCTL0_DSIZ_15_0 (1 << 16)
#define ESDCTL0_DSIZ_31_0 (2 << 16)
+#define ESDCTL0_DSIZ_MASK (3 << 16)
#define ESDCTL0_REF1 (1 << 13)
#define ESDCTL0_REF2 (2 << 13)
#define ESDCTL0_REF4 (3 << 13)
@@ -124,3 +125,5 @@
//#define ESDCFGx_tRC_14 0x0000000e // 15 seems to not exist
#define ESDCFGx_tRC_16 0x0000000f
+void imx_add_ram0(void);
+void imx_add_ram1(void);
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] arm/imx: provide command to add ram device with autodetected size
2012-08-02 16:32 ` [PATCH v2] " Uwe Kleine-König
@ 2012-08-03 13:26 ` Sascha Hauer
0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-08-03 13:26 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: barebox
On Thu, Aug 02, 2012 at 06:32:42PM +0200, Uwe Kleine-König wrote:
> The amount of available ram is determined by the ESDCTL register, so
> better don't hardcode the value.
>
> This commit provides a command that can be used instead of
> arm_add_mem_device and convertes pcm043 (on which this patch was tested)
> to it.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> changes since implicit v1:
> - support 2nd sdram chip select
> - move implementation to arch/arm/mach-imx/esdctl.c
>
> arch/arm/boards/pcm043/pcm043.c | 3 ++-
> arch/arm/mach-imx/Makefile | 2 +-
> arch/arm/mach-imx/esdctl.c | 45 +++++++++++++++++++++++++++++++
> arch/arm/mach-imx/include/mach/esdctl.h | 3 +++
> 4 files changed, 51 insertions(+), 2 deletions(-)
> create mode 100644 arch/arm/mach-imx/esdctl.c
>
> diff --git a/arch/arm/boards/pcm043/pcm043.c b/arch/arm/boards/pcm043/pcm043.c
> index 65e0586..3a309c4 100644
> --- a/arch/arm/boards/pcm043/pcm043.c
> +++ b/arch/arm/boards/pcm043/pcm043.c
> @@ -46,6 +46,7 @@
> #include <mach/imx-pll.h>
> #include <mach/iomux-mx35.h>
> #include <mach/devices-imx35.h>
> +#include <mach/esdctl.h>
>
> static struct fec_platform_data fec_info = {
> .xcv_type = MII100,
> @@ -103,7 +104,7 @@ static struct imx_ipu_fb_platform_data ipu_fb_data = {
>
> static int pcm043_mem_init(void)
> {
> - arm_add_mem_device("ram0", IMX_SDRAM_CS0, SZ_128M);
> + imx_add_ram0();
>
> return 0;
> }
> diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
> index 03e2421..cc6fa5e 100644
> --- a/arch/arm/mach-imx/Makefile
> +++ b/arch/arm/mach-imx/Makefile
> @@ -1,4 +1,4 @@
> -obj-y += clocksource.o gpio.o
> +obj-y += clocksource.o gpio.o esdctl.o
for i in arch/arm/configs/*; do make $(basename $i); make; done
Probably this will break on several i.MX SoCs missing IMX_SDRAM_CS0 and
friends.
> +void imx_add_ram_auto(void)
> +{
> + imx_add_ram0();
> + imx_add_ram1();
> +}
> diff --git a/arch/arm/mach-imx/include/mach/esdctl.h b/arch/arm/mach-imx/include/mach/esdctl.h
> index 10c8b9b..688f799 100644
> --- a/arch/arm/mach-imx/include/mach/esdctl.h
> +++ b/arch/arm/mach-imx/include/mach/esdctl.h
> @@ -26,6 +26,7 @@
> #define ESDCTL0_DSIZ_31_16 (0 << 16)
> #define ESDCTL0_DSIZ_15_0 (1 << 16)
> #define ESDCTL0_DSIZ_31_0 (2 << 16)
> +#define ESDCTL0_DSIZ_MASK (3 << 16)
> #define ESDCTL0_REF1 (1 << 13)
> #define ESDCTL0_REF2 (2 << 13)
> #define ESDCTL0_REF4 (3 << 13)
> @@ -124,3 +125,5 @@
> //#define ESDCFGx_tRC_14 0x0000000e // 15 seems to not exist
> #define ESDCFGx_tRC_16 0x0000000f
>
> +void imx_add_ram0(void);
> +void imx_add_ram1(void);
The prototype for imx_add_ram_auto() is missing here.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-08-03 13:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-26 9:53 [PATCH RFC] arm/imx: provide command to add ram device with autodetected size Uwe Kleine-König
2012-07-26 10:17 ` Juergen Beisert
2012-07-27 8:14 ` Sascha Hauer
2012-08-02 16:32 ` [PATCH v2] " Uwe Kleine-König
2012-08-03 13:26 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox