]> git.ipfire.org Git - people/ms/u-boot.git/blame - drivers/misc/fsl_law.c
rename CFG_ macros to CONFIG_SYS
[people/ms/u-boot.git] / drivers / misc / fsl_law.c
CommitLineData
83d40dfd
KG
1/*
2 * Copyright 2008 Freescale Semiconductor, Inc.
3 *
4 * (C) Copyright 2000
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <common.h>
27#include <asm/fsl_law.h>
28#include <asm/io.h>
29
f060054d
KG
30DECLARE_GLOBAL_DATA_PTR;
31
83d40dfd 32#define LAWAR_EN 0x80000000
f060054d
KG
33/* number of LAWs in the hw implementation */
34#if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
35 defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555)
36#define FSL_HW_NUM_LAWS 8
37#elif defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544) || \
38 defined(CONFIG_MPC8568) || \
39 defined(CONFIG_MPC8641) || defined(CONFIG_MPC8610)
40#define FSL_HW_NUM_LAWS 10
ef50d6c0 41#elif defined(CONFIG_MPC8536) || defined(CONFIG_MPC8572)
f060054d
KG
42#define FSL_HW_NUM_LAWS 12
43#else
44#error FSL_HW_NUM_LAWS not defined for this platform
45#endif
83d40dfd
KG
46
47void set_law(u8 idx, phys_addr_t addr, enum law_size sz, enum law_trgt_if id)
48{
6d0f6bcf 49 volatile u32 *base = (volatile u32 *)(CONFIG_SYS_IMMR + 0xc08);
83d40dfd
KG
50 volatile u32 *lawbar = base + 8 * idx;
51 volatile u32 *lawar = base + 8 * idx + 2;
52
f060054d
KG
53 gd->used_laws |= (1 << idx);
54
83d40dfd
KG
55 out_be32(lawbar, addr >> 12);
56 out_be32(lawar, LAWAR_EN | ((u32)id << 20) | (u32)sz);
57
58 return ;
59}
60
f060054d
KG
61int set_next_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id)
62{
63 u32 idx = ffz(gd->used_laws);
64
65 if (idx >= FSL_HW_NUM_LAWS)
66 return -1;
67
68 set_law(idx, addr, sz, id);
ba04f701
KG
69
70 return idx;
71}
72
73int set_last_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id)
74{
75 u32 idx;
76
77 /* we have no LAWs free */
78 if (gd->used_laws == -1)
79 return -1;
80
81 /* grab the last free law */
82 idx = __ilog2(~(gd->used_laws));
83
84 if (idx >= FSL_HW_NUM_LAWS)
85 return -1;
86
87 set_law(idx, addr, sz, id);
f060054d
KG
88
89 return idx;
90}
91
83d40dfd
KG
92void disable_law(u8 idx)
93{
6d0f6bcf 94 volatile u32 *base = (volatile u32 *)(CONFIG_SYS_IMMR + 0xc08);
83d40dfd
KG
95 volatile u32 *lawbar = base + 8 * idx;
96 volatile u32 *lawar = base + 8 * idx + 2;
97
f060054d
KG
98 gd->used_laws &= ~(1 << idx);
99
83d40dfd
KG
100 out_be32(lawar, 0);
101 out_be32(lawbar, 0);
102
103 return;
104}
105
ddcebcb6
BB
106void print_laws(void)
107{
6d0f6bcf 108 volatile u32 *base = (volatile u32 *)(CONFIG_SYS_IMMR + 0xc08);
ddcebcb6
BB
109 volatile u32 *lawbar = base;
110 volatile u32 *lawar = base + 2;
111 int i;
112
113 printf("\nLocal Access Window Configuration\n");
114 for(i = 0; i < FSL_HW_NUM_LAWS; i++) {
115 printf("\tLAWBAR%d : 0x%08x, LAWAR%d : 0x%08x\n",
116 i, in_be32(lawbar), i, in_be32(lawar));
117 lawbar += 8;
118 lawar += 8;
119 }
120
121 return;
122}
123
f784e32b
KG
124/* use up to 2 LAWs for DDR, used the last available LAWs */
125int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id)
126{
127 u64 start_align, law_sz;
128 int law_sz_enc;
129
130 if (start == 0)
131 start_align = 1ull << (LAW_SIZE_32G + 1);
132 else
133 start_align = 1ull << (ffs64(start) - 1);
134 law_sz = min(start_align, sz);
135 law_sz_enc = __ilog2_u64(law_sz) - 1;
136
137 if (set_last_law(start, law_sz_enc, id) < 0)
138 return -1;
139
140 /* do we still have anything to map */
141 sz = sz - law_sz;
142 if (sz) {
143 start += law_sz;
144
145 start_align = 1ull << (ffs64(start) - 1);
146 law_sz = min(start_align, sz);
147 law_sz_enc = __ilog2_u64(law_sz) - 1;
148
149 if (set_last_law(start, law_sz_enc, id) < 0)
150 return -1;
151 } else {
152 return 0;
153 }
154
155 /* do we still have anything to map */
156 sz = sz - law_sz;
157 if (sz)
158 return 1;
159
160 return 0;
161}
162
83d40dfd
KG
163void init_laws(void)
164{
165 int i;
83d40dfd 166
f060054d 167 gd->used_laws = ~((1 << FSL_HW_NUM_LAWS) - 1);
83d40dfd 168
f060054d
KG
169 for (i = 0; i < num_law_entries; i++) {
170 if (law_table[i].index == -1)
171 set_next_law(law_table[i].addr, law_table[i].size,
172 law_table[i].trgt_id);
173 else
174 set_law(law_table[i].index, law_table[i].addr,
175 law_table[i].size, law_table[i].trgt_id);
83d40dfd
KG
176 }
177
178 return ;
179}