2 * Copyright 2011 Freescale Semiconductor, Inc.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * Version 2 as published by the Free Software Foundation.
10 #include <asm/fsl_law.h>
12 #include <linux/log2.h>
14 int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id)
16 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
17 law83xx_t *ecm = &immap->sysconf.ddrlaw[0];
18 u64 start_align, law_sz;
22 start_align = 1ull << (LAW_SIZE_2G + 1);
24 start_align = 1ull << (__ffs64(start) - 1);
25 law_sz = min(start_align, sz);
26 law_sz_enc = __ilog2_u64(law_sz) - 1;
29 * Set up LAWBAR for all of DDR.
31 ecm->bar = start & 0xfffff000;
32 ecm->ar = (LAWAR_EN | (id << 20) | (LAWAR_SIZE & law_sz_enc));
33 debug("DDR:bar=0x%08x\n", ecm->bar);
34 debug("DDR:ar=0x%08x\n", ecm->ar);
36 /* recalculate size based on what was actually covered by the law */
37 law_sz = 1ull << __ilog2_u64(law_sz);
39 /* do we still have anything to map */
44 start_align = 1ull << (__ffs64(start) - 1);
45 law_sz = min(start_align, sz);
46 law_sz_enc = __ilog2_u64(law_sz) - 1;
47 ecm = &immap->sysconf.ddrlaw[1];
48 ecm->bar = start & 0xfffff000;
49 ecm->ar = (LAWAR_EN | (id << 20) | (LAWAR_SIZE & law_sz_enc));
50 debug("DDR:bar=0x%08x\n", ecm->bar);
51 debug("DDR:ar=0x%08x\n", ecm->ar);
56 /* do we still have anything to map */