]> git.sur5r.net Git - u-boot/blob - arch/powerpc/cpu/mpc85xx/liodn.c
powerpc/85xx: Add support for setting up RAID engine liodns on P5020
[u-boot] / arch / powerpc / cpu / mpc85xx / liodn.c
1 /*
2  * Copyright 2008-2011 Freescale Semiconductor, Inc.
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
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.
11  *
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.
16  *
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,
20  * MA 02111-1307 USA
21  */
22
23 #include <common.h>
24 #include <libfdt.h>
25 #include <fdt_support.h>
26
27 #include <asm/immap_85xx.h>
28 #include <asm/io.h>
29 #include <asm/processor.h>
30 #include <asm/fsl_portals.h>
31 #include <asm/fsl_liodn.h>
32
33 int get_dpaa_liodn(enum fsl_dpaa_dev dpaa_dev, u32 *liodns, int liodn_offset)
34 {
35         liodns[0] = liodn_bases[dpaa_dev].id[0] + liodn_offset;
36
37         if (liodn_bases[dpaa_dev].num_ids == 2)
38                 liodns[1] = liodn_bases[dpaa_dev].id[1] + liodn_offset;
39
40         return liodn_bases[dpaa_dev].num_ids;
41 }
42
43 static void set_liodn(struct liodn_id_table *tbl, int size)
44 {
45         int i;
46
47         for (i = 0; i < size; i++) {
48                 u32 liodn;
49                 if (tbl[i].num_ids == 2) {
50                         liodn = (tbl[i].id[0] << 16) | tbl[i].id[1];
51                 } else {
52                         liodn = tbl[i].id[0];
53                 }
54
55                 out_be32((volatile u32 *)(tbl[i].reg_offset), liodn);
56         }
57 }
58
59 static void setup_sec_liodn_base(void)
60 {
61         ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
62         u32 base;
63
64         if (!IS_E_PROCESSOR(get_svr()))
65                 return;
66
67         /* QILCR[QSLOM] */
68         out_be32(&sec->qilcr_ms, 0x3ff<<16);
69
70         base = (liodn_bases[FSL_HW_PORTAL_SEC].id[0] << 16) |
71                 liodn_bases[FSL_HW_PORTAL_SEC].id[1];
72
73         out_be32(&sec->qilcr_ls, base);
74 }
75
76 #ifdef CONFIG_SYS_DPAA_FMAN
77 static void setup_fman_liodn_base(enum fsl_dpaa_dev dev,
78                                   struct liodn_id_table *tbl, int size)
79 {
80         int i;
81         ccsr_fman_t *fm;
82         u32 base;
83
84         switch(dev) {
85         case FSL_HW_PORTAL_FMAN1:
86                 fm = (void *)CONFIG_SYS_FSL_FM1_ADDR;
87                 break;
88
89 #if (CONFIG_SYS_NUM_FMAN == 2)
90         case FSL_HW_PORTAL_FMAN2:
91                 fm = (void *)CONFIG_SYS_FSL_FM2_ADDR;
92                 break;
93 #endif
94         default:
95                 printf("Error: Invalid device type to %s\n", __FUNCTION__);
96                 return ;
97         }
98
99         base = (liodn_bases[dev].id[0] << 16) | liodn_bases[dev].id[0];
100
101         /* setup all bases the same */
102         for (i = 0; i < 32; i++) {
103                 out_be32(&fm->fm_dma.fmdmplr[i], base);
104         }
105
106         /* update tbl to ... */
107         for (i = 0; i < size; i++)
108                 tbl[i].id[0] += liodn_bases[dev].id[0];
109 }
110 #endif
111
112 static void setup_pme_liodn_base(void)
113 {
114 #ifdef CONFIG_SYS_DPAA_PME
115         ccsr_pme_t *pme = (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
116         u32 base = (liodn_bases[FSL_HW_PORTAL_PME].id[0] << 16) |
117                         liodn_bases[FSL_HW_PORTAL_PME].id[1];
118
119         out_be32(&pme->liodnbr, base);
120 #endif
121 }
122
123 #ifdef CONFIG_SYS_FSL_RAID_ENGINE
124 static void setup_raide_liodn_base(void)
125 {
126         struct ccsr_raide *raide = (void *)CONFIG_SYS_FSL_RAID_ENGINE_ADDR;
127
128         /* setup raid engine liodn base for data/desc ; both set to 47 */
129         u32 base = (liodn_bases[FSL_HW_PORTAL_RAID_ENGINE].id[0] << 16) |
130                         liodn_bases[FSL_HW_PORTAL_RAID_ENGINE].id[0];
131
132         out_be32(&raide->liodnbr, base);
133 }
134 #endif
135
136 void set_liodns(void)
137 {
138         /* setup general liodn offsets */
139         set_liodn(liodn_tbl, liodn_tbl_sz);
140
141         /* setup SEC block liodn bases & offsets if we have one */
142         if (IS_E_PROCESSOR(get_svr())) {
143                 set_liodn(sec_liodn_tbl, sec_liodn_tbl_sz);
144                 setup_sec_liodn_base();
145         }
146
147         /* setup FMAN block(s) liodn bases & offsets if we have one */
148 #ifdef CONFIG_SYS_DPAA_FMAN
149         set_liodn(fman1_liodn_tbl, fman1_liodn_tbl_sz);
150         setup_fman_liodn_base(FSL_HW_PORTAL_FMAN1, fman1_liodn_tbl,
151                                 fman1_liodn_tbl_sz);
152
153 #if (CONFIG_SYS_NUM_FMAN == 2)
154         set_liodn(fman2_liodn_tbl, fman2_liodn_tbl_sz);
155         setup_fman_liodn_base(FSL_HW_PORTAL_FMAN2, fman2_liodn_tbl,
156                                 fman2_liodn_tbl_sz);
157 #endif
158 #endif
159         /* setup PME liodn base */
160         setup_pme_liodn_base();
161
162 #ifdef CONFIG_SYS_FSL_RAID_ENGINE
163         /* raid engine ccr addr code for liodn */
164         set_liodn(raide_liodn_tbl, raide_liodn_tbl_sz);
165         setup_raide_liodn_base();
166 #endif
167 }
168
169 static void fdt_fixup_liodn_tbl(void *blob, struct liodn_id_table *tbl, int sz)
170 {
171         int i;
172
173         for (i = 0; i < sz; i++) {
174                 int off;
175
176                 if (tbl[i].compat == NULL)
177                         continue;
178
179                 off = fdt_node_offset_by_compat_reg(blob,
180                                 tbl[i].compat, tbl[i].compat_offset);
181                 if (off >= 0) {
182                         off = fdt_setprop(blob, off, "fsl,liodn",
183                                 &tbl[i].id[0],
184                                 sizeof(u32) * tbl[i].num_ids);
185                         if (off > 0)
186                                 printf("WARNING unable to set fsl,liodn for "
187                                         "%s: %s\n",
188                                         tbl[i].compat, fdt_strerror(off));
189                 } else {
190                         debug("WARNING: could not set fsl,liodn for %s: %s.\n",
191                                         tbl[i].compat, fdt_strerror(off));
192                 }
193         }
194 }
195
196 void fdt_fixup_liodn(void *blob)
197 {
198         fdt_fixup_liodn_tbl(blob, liodn_tbl, liodn_tbl_sz);
199 #ifdef CONFIG_SYS_DPAA_FMAN
200         fdt_fixup_liodn_tbl(blob, fman1_liodn_tbl, fman1_liodn_tbl_sz);
201 #if (CONFIG_SYS_NUM_FMAN == 2)
202         fdt_fixup_liodn_tbl(blob, fman2_liodn_tbl, fman2_liodn_tbl_sz);
203 #endif
204 #endif
205         fdt_fixup_liodn_tbl(blob, sec_liodn_tbl, sec_liodn_tbl_sz);
206
207 #ifdef CONFIG_SYS_FSL_RAID_ENGINE
208         fdt_fixup_liodn_tbl(blob, raide_liodn_tbl, raide_liodn_tbl_sz);
209 #endif
210 }