Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 1 | /* |
Kumar Gala | 6b3a8d0 | 2011-09-10 10:44:13 -0500 | [diff] [blame] | 2 | * Copyright 2008-2011 Freescale Semiconductor, Inc. |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 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 | |
Kumar Gala | 1a0c642 | 2011-10-14 00:01:23 -0500 | [diff] [blame^] | 43 | static void set_srio_liodn(struct srio_liodn_id_table *tbl, int size) |
| 44 | { |
| 45 | int i; |
| 46 | |
| 47 | for (i = 0; i < size; i++) { |
| 48 | unsigned long reg_off = tbl[i].reg_offset[0]; |
| 49 | out_be32((u32 *)reg_off, tbl[i].id[0]); |
| 50 | |
| 51 | if (tbl[i].num_ids == 2) { |
| 52 | reg_off = tbl[i].reg_offset[1]; |
| 53 | out_be32((u32 *)reg_off, tbl[i].id[1]); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 58 | static void set_liodn(struct liodn_id_table *tbl, int size) |
| 59 | { |
| 60 | int i; |
| 61 | |
| 62 | for (i = 0; i < size; i++) { |
| 63 | u32 liodn; |
| 64 | if (tbl[i].num_ids == 2) { |
| 65 | liodn = (tbl[i].id[0] << 16) | tbl[i].id[1]; |
| 66 | } else { |
| 67 | liodn = tbl[i].id[0]; |
| 68 | } |
| 69 | |
| 70 | out_be32((volatile u32 *)(tbl[i].reg_offset), liodn); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | static void setup_sec_liodn_base(void) |
| 75 | { |
| 76 | ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR; |
| 77 | u32 base; |
| 78 | |
| 79 | if (!IS_E_PROCESSOR(get_svr())) |
| 80 | return; |
| 81 | |
| 82 | /* QILCR[QSLOM] */ |
| 83 | out_be32(&sec->qilcr_ms, 0x3ff<<16); |
| 84 | |
| 85 | base = (liodn_bases[FSL_HW_PORTAL_SEC].id[0] << 16) | |
| 86 | liodn_bases[FSL_HW_PORTAL_SEC].id[1]; |
| 87 | |
| 88 | out_be32(&sec->qilcr_ls, base); |
| 89 | } |
| 90 | |
| 91 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 92 | static void setup_fman_liodn_base(enum fsl_dpaa_dev dev, |
| 93 | struct liodn_id_table *tbl, int size) |
| 94 | { |
| 95 | int i; |
| 96 | ccsr_fman_t *fm; |
| 97 | u32 base; |
| 98 | |
| 99 | switch(dev) { |
| 100 | case FSL_HW_PORTAL_FMAN1: |
| 101 | fm = (void *)CONFIG_SYS_FSL_FM1_ADDR; |
| 102 | break; |
| 103 | |
| 104 | #if (CONFIG_SYS_NUM_FMAN == 2) |
| 105 | case FSL_HW_PORTAL_FMAN2: |
| 106 | fm = (void *)CONFIG_SYS_FSL_FM2_ADDR; |
| 107 | break; |
| 108 | #endif |
| 109 | default: |
| 110 | printf("Error: Invalid device type to %s\n", __FUNCTION__); |
| 111 | return ; |
| 112 | } |
| 113 | |
| 114 | base = (liodn_bases[dev].id[0] << 16) | liodn_bases[dev].id[0]; |
| 115 | |
| 116 | /* setup all bases the same */ |
| 117 | for (i = 0; i < 32; i++) { |
| 118 | out_be32(&fm->fm_dma.fmdmplr[i], base); |
| 119 | } |
| 120 | |
| 121 | /* update tbl to ... */ |
| 122 | for (i = 0; i < size; i++) |
| 123 | tbl[i].id[0] += liodn_bases[dev].id[0]; |
| 124 | } |
| 125 | #endif |
| 126 | |
| 127 | static void setup_pme_liodn_base(void) |
| 128 | { |
| 129 | #ifdef CONFIG_SYS_DPAA_PME |
| 130 | ccsr_pme_t *pme = (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR; |
| 131 | u32 base = (liodn_bases[FSL_HW_PORTAL_PME].id[0] << 16) | |
| 132 | liodn_bases[FSL_HW_PORTAL_PME].id[1]; |
| 133 | |
| 134 | out_be32(&pme->liodnbr, base); |
| 135 | #endif |
| 136 | } |
| 137 | |
Kumar Gala | 6b3a8d0 | 2011-09-10 10:44:13 -0500 | [diff] [blame] | 138 | #ifdef CONFIG_SYS_FSL_RAID_ENGINE |
| 139 | static void setup_raide_liodn_base(void) |
| 140 | { |
| 141 | struct ccsr_raide *raide = (void *)CONFIG_SYS_FSL_RAID_ENGINE_ADDR; |
| 142 | |
| 143 | /* setup raid engine liodn base for data/desc ; both set to 47 */ |
| 144 | u32 base = (liodn_bases[FSL_HW_PORTAL_RAID_ENGINE].id[0] << 16) | |
| 145 | liodn_bases[FSL_HW_PORTAL_RAID_ENGINE].id[0]; |
| 146 | |
| 147 | out_be32(&raide->liodnbr, base); |
| 148 | } |
| 149 | #endif |
| 150 | |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 151 | void set_liodns(void) |
| 152 | { |
| 153 | /* setup general liodn offsets */ |
| 154 | set_liodn(liodn_tbl, liodn_tbl_sz); |
| 155 | |
Kumar Gala | 1a0c642 | 2011-10-14 00:01:23 -0500 | [diff] [blame^] | 156 | /* setup SRIO port liodns */ |
| 157 | set_srio_liodn(srio_liodn_tbl, srio_liodn_tbl_sz); |
| 158 | |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 159 | /* setup SEC block liodn bases & offsets if we have one */ |
| 160 | if (IS_E_PROCESSOR(get_svr())) { |
| 161 | set_liodn(sec_liodn_tbl, sec_liodn_tbl_sz); |
| 162 | setup_sec_liodn_base(); |
| 163 | } |
| 164 | |
| 165 | /* setup FMAN block(s) liodn bases & offsets if we have one */ |
| 166 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 167 | set_liodn(fman1_liodn_tbl, fman1_liodn_tbl_sz); |
| 168 | setup_fman_liodn_base(FSL_HW_PORTAL_FMAN1, fman1_liodn_tbl, |
| 169 | fman1_liodn_tbl_sz); |
| 170 | |
| 171 | #if (CONFIG_SYS_NUM_FMAN == 2) |
| 172 | set_liodn(fman2_liodn_tbl, fman2_liodn_tbl_sz); |
| 173 | setup_fman_liodn_base(FSL_HW_PORTAL_FMAN2, fman2_liodn_tbl, |
| 174 | fman2_liodn_tbl_sz); |
| 175 | #endif |
| 176 | #endif |
| 177 | /* setup PME liodn base */ |
| 178 | setup_pme_liodn_base(); |
Kumar Gala | 6b3a8d0 | 2011-09-10 10:44:13 -0500 | [diff] [blame] | 179 | |
| 180 | #ifdef CONFIG_SYS_FSL_RAID_ENGINE |
| 181 | /* raid engine ccr addr code for liodn */ |
| 182 | set_liodn(raide_liodn_tbl, raide_liodn_tbl_sz); |
| 183 | setup_raide_liodn_base(); |
| 184 | #endif |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | static void fdt_fixup_liodn_tbl(void *blob, struct liodn_id_table *tbl, int sz) |
| 188 | { |
| 189 | int i; |
| 190 | |
| 191 | for (i = 0; i < sz; i++) { |
| 192 | int off; |
| 193 | |
| 194 | if (tbl[i].compat == NULL) |
| 195 | continue; |
| 196 | |
| 197 | off = fdt_node_offset_by_compat_reg(blob, |
| 198 | tbl[i].compat, tbl[i].compat_offset); |
| 199 | if (off >= 0) { |
| 200 | off = fdt_setprop(blob, off, "fsl,liodn", |
| 201 | &tbl[i].id[0], |
| 202 | sizeof(u32) * tbl[i].num_ids); |
| 203 | if (off > 0) |
| 204 | printf("WARNING unable to set fsl,liodn for " |
| 205 | "%s: %s\n", |
| 206 | tbl[i].compat, fdt_strerror(off)); |
| 207 | } else { |
| 208 | debug("WARNING: could not set fsl,liodn for %s: %s.\n", |
| 209 | tbl[i].compat, fdt_strerror(off)); |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | void fdt_fixup_liodn(void *blob) |
| 215 | { |
| 216 | fdt_fixup_liodn_tbl(blob, liodn_tbl, liodn_tbl_sz); |
| 217 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 218 | fdt_fixup_liodn_tbl(blob, fman1_liodn_tbl, fman1_liodn_tbl_sz); |
| 219 | #if (CONFIG_SYS_NUM_FMAN == 2) |
| 220 | fdt_fixup_liodn_tbl(blob, fman2_liodn_tbl, fman2_liodn_tbl_sz); |
| 221 | #endif |
| 222 | #endif |
| 223 | fdt_fixup_liodn_tbl(blob, sec_liodn_tbl, sec_liodn_tbl_sz); |
Kumar Gala | 6b3a8d0 | 2011-09-10 10:44:13 -0500 | [diff] [blame] | 224 | |
| 225 | #ifdef CONFIG_SYS_FSL_RAID_ENGINE |
| 226 | fdt_fixup_liodn_tbl(blob, raide_liodn_tbl, raide_liodn_tbl_sz); |
| 227 | #endif |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 228 | } |