public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Kumar Gala <galak@kernel.crashing.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 04/14] FSL DDR: Provide a generic fsl_ddr_sdram_set_lawbar()
Date: Tue, 12 Aug 2008 11:06:12 -0500	[thread overview]
Message-ID: <1218557182-1328-4-git-send-email-galak@kernel.crashing.org> (raw)
In-Reply-To: <1218557182-1328-3-git-send-email-galak@kernel.crashing.org>

Make fsl_ddr_sdram_set_lawbar() a weak function to allow board code to
override if desired.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
---
 drivers/misc/fsl_law.c |   87 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/fsl_law.c b/drivers/misc/fsl_law.c
index 48ece4f..37af297 100644
--- a/drivers/misc/fsl_law.c
+++ b/drivers/misc/fsl_law.c
@@ -121,6 +121,93 @@ void print_laws(void)
 	return;
 }
 
+#if defined(CONFIG_FSL_DDR1) || \
+    defined(CONFIG_FSL_DDR2) || \
+    defined(CONFIG_FSL_DDR3)
+#include <../cpu/mpc8xxx/fsl_ddr_sdram.h>
+
+/* use up to 2 LAWs for DDR, used the last available LAWs */
+int __set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id)
+{
+	u64 start_align, law_sz;
+	int law_sz_enc;
+
+	if (start == 0)
+		start_align = 1ull << (LAW_SIZE_32G + 1);
+	else
+		start_align = 1ull << (ffs64(start) - 1);
+	law_sz = min(start_align, sz);
+	law_sz_enc = __ilog2_u64(law_sz) - 1;
+
+	if (set_last_law(start, law_sz_enc, id) < 0)
+		return -1;
+
+	/* do we still have anything to map */
+	sz = sz - law_sz;
+	if (sz) {
+		start += law_sz;
+
+		start_align = 1ull << (ffs64(start) - 1);
+		law_sz = min(start_align, sz);
+		law_sz_enc = __ilog2_u64(law_sz) - 1;
+
+		if (set_last_law(start, law_sz_enc, id) < 0)
+			return -1;
+	} else {
+		return 0;
+	}
+
+	/* do we still have anything to map */
+	sz = sz - law_sz;
+	if (sz)
+		return 1;
+
+	return 0;
+}
+
+void
+__fsl_ddr_sdram_set_lawbar(const common_timing_params_t *memctl_common_params,
+			   unsigned int memctl_interleaved,
+			   unsigned int ctrl_num)
+{
+	/*
+	 * If no DIMMs on this controller, do not proceed any further.
+	 */
+	if (!memctl_common_params->ndimms_present) {
+		return;
+	}
+
+	if (ctrl_num == 0) {
+		/*
+		 * Set up LAW for DDR controller 1 space.
+		 */
+		unsigned int lawbar1_target_id = memctl_interleaved
+			? LAW_TRGT_IF_DDR_INTRLV : LAW_TRGT_IF_DDR_1;
+
+		if (__set_ddr_laws(memctl_common_params->base_address,
+				memctl_common_params->total_mem,
+				lawbar1_target_id) < 0) {
+			printf("ERROR\n");
+			return ;
+		}
+	} else if (ctrl_num == 1) {
+		if (__set_ddr_laws(memctl_common_params->base_address,
+				memctl_common_params->total_mem,
+				LAW_TRGT_IF_DDR_2) < 0) {
+			printf("ERROR\n");
+			return ;
+		}
+	} else {
+		printf("unexpected controller number %u in fsl_ddr_sdram_set_lawbar()\n", ctrl_num);
+	}
+}
+
+__attribute__((weak, alias("__fsl_ddr_sdram_set_lawbar"))) void
+fsl_ddr_sdram_set_lawbar(const common_timing_params_t *memctl_common_params,
+			 unsigned int memctl_interleaved,
+			 unsigned int ctrl_num);
+#endif
+
 void init_laws(void)
 {
 	int i;
-- 
1.5.5.1

  reply	other threads:[~2008-08-12 16:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-12 16:06 [U-Boot] [PATCH 01/14] Add proper SPD definitions for DDR1/2/3 Kumar Gala
2008-08-12 16:06 ` [U-Boot] [PATCH 02/14] FSL DDR: Rewrite the FSL mpc8xxx DDR controller setup code Kumar Gala
2008-08-12 16:06   ` [U-Boot] [PATCH 03/14] FSL DDR: Add interactive DDR config support Kumar Gala
2008-08-12 16:06     ` Kumar Gala [this message]
2008-08-12 16:06       ` [U-Boot] [PATCH 05/14] FSL DDR: Add e500 TLB helper for DDR code Kumar Gala
2008-08-12 16:06         ` [U-Boot] [PATCH 06/14] FSL DDR: Convert MPC8641HPCN to new " Kumar Gala
2008-08-12 16:06           ` [U-Boot] [PATCH 07/14] FSL DDR: Convert MPC8610HPCD " Kumar Gala
2008-08-12 16:06             ` [U-Boot] [PATCH 08/14] FSL DDR: Convert MPC8544DS " Kumar Gala
2008-08-12 16:06               ` [U-Boot] [PATCH 09/14] FSL DDR: Convert MPC8540ADS " Kumar Gala
2008-08-12 16:06                 ` [U-Boot] [PATCH 10/14] FSL DDR: Convert MPC8560ADS " Kumar Gala
2008-08-12 16:06                   ` [U-Boot] [PATCH 11/14] FSL DDR: Convert MPC8555ADS " Kumar Gala
2008-08-12 16:06                     ` [U-Boot] [PATCH 12/14] FSL DDR: Convert MPC8541CDS " Kumar Gala
2008-08-12 16:06                       ` [U-Boot] [PATCH 13/14] FSL DDR: Convert MPC8568MDS " Kumar Gala
2008-08-12 16:06                         ` [U-Boot] [PATCH 14/14] FSL DDR: Convert MPC8548CDS " Kumar Gala
2008-08-12 19:55                           ` Wolfgang Denk
2008-08-12 19:56                           ` Wolfgang Denk
2008-08-12 19:52     ` [U-Boot] [PATCH 03/14] FSL DDR: Add interactive DDR config support Wolfgang Denk
2008-08-12 19:05   ` [U-Boot] [PATCH 02/14] FSL DDR: Rewrite the FSL mpc8xxx DDR controller setup code Wolfgang Denk
2008-08-12 19:49 ` [U-Boot] [PATCH 01/14] Add proper SPD definitions for DDR1/2/3 Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1218557182-1328-4-git-send-email-galak@kernel.crashing.org \
    --to=galak@kernel.crashing.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox