2 * Copyright 2008-2011 Freescale Semiconductor, Inc.
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 #include <fdt_support.h>
27 #include <asm/immap_85xx.h>
29 #include <asm/processor.h>
30 #include <asm/fsl_portals.h>
31 #include <asm/fsl_liodn.h>
33 int get_dpaa_liodn(enum fsl_dpaa_dev dpaa_dev, u32 *liodns, int liodn_offset)
35 liodns[0] = liodn_bases[dpaa_dev].id[0] + liodn_offset;
37 if (liodn_bases[dpaa_dev].num_ids == 2)
38 liodns[1] = liodn_bases[dpaa_dev].id[1] + liodn_offset;
40 return liodn_bases[dpaa_dev].num_ids;
43 #ifdef CONFIG_SYS_SRIO
44 static void set_srio_liodn(struct srio_liodn_id_table *tbl, int size)
48 for (i = 0; i < size; i++) {
49 unsigned long reg_off = tbl[i].reg_offset[0];
50 out_be32((u32 *)reg_off, tbl[i].id[0]);
52 if (tbl[i].num_ids == 2) {
53 reg_off = tbl[i].reg_offset[1];
54 out_be32((u32 *)reg_off, tbl[i].id[1]);
60 static void set_liodn(struct liodn_id_table *tbl, int size)
64 for (i = 0; i < size; i++) {
66 if (tbl[i].num_ids == 2) {
67 liodn = (tbl[i].id[0] << 16) | tbl[i].id[1];
72 out_be32((volatile u32 *)(tbl[i].reg_offset), liodn);
76 static void setup_sec_liodn_base(void)
78 ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
81 if (!IS_E_PROCESSOR(get_svr()))
85 out_be32(&sec->qilcr_ms, 0x3ff<<16);
87 base = (liodn_bases[FSL_HW_PORTAL_SEC].id[0] << 16) |
88 liodn_bases[FSL_HW_PORTAL_SEC].id[1];
90 out_be32(&sec->qilcr_ls, base);
93 #ifdef CONFIG_SYS_DPAA_FMAN
94 static void setup_fman_liodn_base(enum fsl_dpaa_dev dev,
95 struct liodn_id_table *tbl, int size)
102 case FSL_HW_PORTAL_FMAN1:
103 fm = (void *)CONFIG_SYS_FSL_FM1_ADDR;
106 #if (CONFIG_SYS_NUM_FMAN == 2)
107 case FSL_HW_PORTAL_FMAN2:
108 fm = (void *)CONFIG_SYS_FSL_FM2_ADDR;
112 printf("Error: Invalid device type to %s\n", __FUNCTION__);
116 base = (liodn_bases[dev].id[0] << 16) | liodn_bases[dev].id[0];
118 /* setup all bases the same */
119 for (i = 0; i < 32; i++) {
120 out_be32(&fm->fm_dma.fmdmplr[i], base);
123 /* update tbl to ... */
124 for (i = 0; i < size; i++)
125 tbl[i].id[0] += liodn_bases[dev].id[0];
129 static void setup_pme_liodn_base(void)
131 #ifdef CONFIG_SYS_DPAA_PME
132 ccsr_pme_t *pme = (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
133 u32 base = (liodn_bases[FSL_HW_PORTAL_PME].id[0] << 16) |
134 liodn_bases[FSL_HW_PORTAL_PME].id[1];
136 out_be32(&pme->liodnbr, base);
140 #ifdef CONFIG_SYS_FSL_RAID_ENGINE
141 static void setup_raide_liodn_base(void)
143 struct ccsr_raide *raide = (void *)CONFIG_SYS_FSL_RAID_ENGINE_ADDR;
145 /* setup raid engine liodn base for data/desc ; both set to 47 */
146 u32 base = (liodn_bases[FSL_HW_PORTAL_RAID_ENGINE].id[0] << 16) |
147 liodn_bases[FSL_HW_PORTAL_RAID_ENGINE].id[0];
149 out_be32(&raide->liodnbr, base);
153 #ifdef CONFIG_SYS_DPAA_RMAN
154 static void set_rman_liodn(struct liodn_id_table *tbl, int size)
157 struct ccsr_rman *rman = (void *)CONFIG_SYS_FSL_CORENET_RMAN_ADDR;
159 for (i = 0; i < size; i++) {
160 /* write the RMan block number */
161 out_be32(&rman->mmitar, i);
162 /* write the liodn offset corresponding to the block */
163 out_be32((u32 *)(tbl[i].reg_offset), tbl[i].id[0]);
167 static void setup_rman_liodn_base(struct liodn_id_table *tbl, int size)
170 struct ccsr_rman *rman = (void *)CONFIG_SYS_FSL_CORENET_RMAN_ADDR;
171 u32 base = liodn_bases[FSL_HW_PORTAL_RMAN].id[0];
173 out_be32(&rman->mmliodnbr, base);
175 /* update liodn offset */
176 for (i = 0; i < size; i++)
177 tbl[i].id[0] += base;
181 void set_liodns(void)
183 /* setup general liodn offsets */
184 set_liodn(liodn_tbl, liodn_tbl_sz);
186 #ifdef CONFIG_SYS_SRIO
187 /* setup SRIO port liodns */
188 set_srio_liodn(srio_liodn_tbl, srio_liodn_tbl_sz);
191 /* setup SEC block liodn bases & offsets if we have one */
192 if (IS_E_PROCESSOR(get_svr())) {
193 set_liodn(sec_liodn_tbl, sec_liodn_tbl_sz);
194 setup_sec_liodn_base();
197 /* setup FMAN block(s) liodn bases & offsets if we have one */
198 #ifdef CONFIG_SYS_DPAA_FMAN
199 set_liodn(fman1_liodn_tbl, fman1_liodn_tbl_sz);
200 setup_fman_liodn_base(FSL_HW_PORTAL_FMAN1, fman1_liodn_tbl,
203 #if (CONFIG_SYS_NUM_FMAN == 2)
204 set_liodn(fman2_liodn_tbl, fman2_liodn_tbl_sz);
205 setup_fman_liodn_base(FSL_HW_PORTAL_FMAN2, fman2_liodn_tbl,
209 /* setup PME liodn base */
210 setup_pme_liodn_base();
212 #ifdef CONFIG_SYS_FSL_RAID_ENGINE
213 /* raid engine ccr addr code for liodn */
214 set_liodn(raide_liodn_tbl, raide_liodn_tbl_sz);
215 setup_raide_liodn_base();
218 #ifdef CONFIG_SYS_DPAA_RMAN
219 /* setup RMan liodn offsets */
220 set_rman_liodn(rman_liodn_tbl, rman_liodn_tbl_sz);
221 /* setup RMan liodn base */
222 setup_rman_liodn_base(rman_liodn_tbl, rman_liodn_tbl_sz);
226 #ifdef CONFIG_SYS_SRIO
227 static void fdt_fixup_srio_liodn(void *blob, struct srio_liodn_id_table *tbl)
231 /* search for srio node, if doesn't exist just return - nothing todo */
232 srio_off = fdt_node_offset_by_compatible(blob, -1, "fsl,srio");
236 for (i = 0; i < srio_liodn_tbl_sz; i++) {
237 int off, portid = tbl[i].portid;
239 off = fdt_node_offset_by_prop_value(blob, srio_off,
240 "cell-index", &portid, 4);
242 off = fdt_setprop(blob, off, "fsl,liodn",
244 sizeof(u32) * tbl[i].num_ids);
246 printf("WARNING unable to set fsl,liodn for "
247 "fsl,srio port %d: %s\n",
248 portid, fdt_strerror(off));
250 debug("WARNING: couldn't set fsl,liodn for srio: %s.\n",
257 static void fdt_fixup_liodn_tbl(void *blob, struct liodn_id_table *tbl, int sz)
261 for (i = 0; i < sz; i++) {
264 if (tbl[i].compat == NULL)
267 off = fdt_node_offset_by_compat_reg(blob,
268 tbl[i].compat, tbl[i].compat_offset);
270 off = fdt_setprop(blob, off, "fsl,liodn",
272 sizeof(u32) * tbl[i].num_ids);
274 printf("WARNING unable to set fsl,liodn for "
276 tbl[i].compat, fdt_strerror(off));
278 debug("WARNING: could not set fsl,liodn for %s: %s.\n",
279 tbl[i].compat, fdt_strerror(off));
284 void fdt_fixup_liodn(void *blob)
286 #ifdef CONFIG_SYS_SRIO
287 fdt_fixup_srio_liodn(blob, srio_liodn_tbl);
290 fdt_fixup_liodn_tbl(blob, liodn_tbl, liodn_tbl_sz);
291 #ifdef CONFIG_SYS_DPAA_FMAN
292 fdt_fixup_liodn_tbl(blob, fman1_liodn_tbl, fman1_liodn_tbl_sz);
293 #if (CONFIG_SYS_NUM_FMAN == 2)
294 fdt_fixup_liodn_tbl(blob, fman2_liodn_tbl, fman2_liodn_tbl_sz);
297 fdt_fixup_liodn_tbl(blob, sec_liodn_tbl, sec_liodn_tbl_sz);
299 #ifdef CONFIG_SYS_FSL_RAID_ENGINE
300 fdt_fixup_liodn_tbl(blob, raide_liodn_tbl, raide_liodn_tbl_sz);
303 #ifdef CONFIG_SYS_DPAA_RMAN
304 fdt_fixup_liodn_tbl(blob, rman_liodn_tbl, rman_liodn_tbl_sz);