Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2010-2020 CS Group |
| 4 | * Charles Frey <charles.frey@c-s.fr> |
| 5 | * Florent Trinh Thai <florent.trinh-thai@c-s.fr> |
| 6 | * Christophe Leroy <christophe.leroy@c-s.fr> |
| 7 | * |
| 8 | * Board specific routines for the CMPC885 board |
| 9 | */ |
| 10 | |
| 11 | #include <env.h> |
| 12 | #include <common.h> |
| 13 | #include <mpc8xx.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <dm.h> |
| 16 | #include <stdio.h> |
| 17 | #include <stdarg.h> |
| 18 | #include <watchdog.h> |
| 19 | #include <serial.h> |
| 20 | #include <hang.h> |
| 21 | #include <flash.h> |
| 22 | #include <init.h> |
| 23 | #include <fdt_support.h> |
| 24 | #include <linux/delay.h> |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 25 | #include <spi.h> |
| 26 | |
Christophe Leroy | 2a45fb6 | 2023-04-04 12:42:15 +0200 | [diff] [blame] | 27 | #include "../common/common.h" |
| 28 | |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
| 31 | #define BOARD_CMPC885 "cmpc885" |
| 32 | #define BOARD_MCR3000_2G "mcr3k_2g" |
Christophe Leroy | 9646af3 | 2023-01-30 09:07:38 +0100 | [diff] [blame] | 33 | #define BOARD_VGOIP "vgoip" |
| 34 | #define BOARD_MIAE "miae" |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 35 | |
| 36 | #define TYPE_MCR 0x22 |
Christophe Leroy | 9646af3 | 2023-01-30 09:07:38 +0100 | [diff] [blame] | 37 | #define TYPE_MIAE 0x23 |
| 38 | |
| 39 | #define FAR_CASRSA 2 |
| 40 | #define FAR_VGOIP 4 |
| 41 | #define FAV_CLA 7 |
| 42 | #define FAV_SRSA 8 |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 43 | |
| 44 | #define ADDR_CPLD_R_RESET ((unsigned short __iomem *)CONFIG_CPLD_BASE) |
| 45 | #define ADDR_CPLD_R_ETAT ((unsigned short __iomem *)(CONFIG_CPLD_BASE + 2)) |
| 46 | #define ADDR_CPLD_R_TYPE ((unsigned char __iomem *)(CONFIG_CPLD_BASE + 3)) |
| 47 | |
| 48 | #define ADDR_FPGA_R_BASE ((unsigned char __iomem *)CONFIG_FPGA_BASE) |
| 49 | #define ADDR_FPGA_R_ALARMES_IN ((unsigned char __iomem *)CONFIG_FPGA_BASE + 0x31) |
Christophe Leroy | 9646af3 | 2023-01-30 09:07:38 +0100 | [diff] [blame] | 50 | #define ADDR_FPGA_R_FAV ((unsigned char __iomem *)CONFIG_FPGA_BASE + 0x44) |
| 51 | |
| 52 | #define PATH_PHY2 "/soc@ff000000/mdio@e00/ethernet-phy@2" |
| 53 | #define PATH_PHY3 "/soc@ff000000/mdio@e00/ethernet-phy@3" |
| 54 | #define PATH_ETH1 "/soc@ff000000/ethernet@1e00" |
| 55 | #define FIBER_PHY PATH_PHY2 |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 56 | |
| 57 | #define FPGA_R_ACQ_AL_FAV 0x04 |
| 58 | #define R_ETAT_PRES_BASE 0x0040 |
| 59 | |
| 60 | #define R_RESET_STATUS 0x0400 |
| 61 | #define R_RST_STATUS 0x0004 |
| 62 | |
| 63 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 64 | { |
Christophe Leroy | 9646af3 | 2023-01-30 09:07:38 +0100 | [diff] [blame] | 65 | u8 fav_id, far_id; |
| 66 | |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 67 | const char *sync = "receive"; |
| 68 | |
| 69 | ft_cpu_setup(blob, bd); |
| 70 | |
| 71 | /* BRG */ |
Christophe Leroy | 9646af3 | 2023-01-30 09:07:38 +0100 | [diff] [blame] | 72 | do_fixup_by_path_u32(blob, "/soc/cpm", "brg-frequency", bd->bi_busfreq, 1); |
| 73 | |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 74 | /* MAC addr */ |
| 75 | fdt_fixup_ethernet(blob); |
| 76 | |
| 77 | /* Bus Frequency for CPM */ |
| 78 | do_fixup_by_path_u32(blob, "/soc", "bus-frequency", bd->bi_busfreq, 1); |
| 79 | |
| 80 | /* E1 interface - Set data rate */ |
| 81 | do_fixup_by_path_u32(blob, "/localbus/e1", "data-rate", 2, 1); |
| 82 | |
| 83 | /* E1 interface - Set channel phase to 0 */ |
| 84 | do_fixup_by_path_u32(blob, "/localbus/e1", "channel-phase", 0, 1); |
| 85 | |
| 86 | /* E1 interface - rising edge sync pulse transmit */ |
Christophe Leroy | 9646af3 | 2023-01-30 09:07:38 +0100 | [diff] [blame] | 87 | do_fixup_by_path(blob, "/localbus/e1", "rising-edge-sync-pulse", sync, strlen(sync), 1); |
| 88 | |
| 89 | /* MIAE only */ |
| 90 | if (!(in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) || in_8(ADDR_FPGA_R_BASE) != TYPE_MIAE) |
| 91 | return 0; |
| 92 | |
| 93 | far_id = in_8(ADDR_FPGA_R_BASE + 0x43) >> 5; |
| 94 | ft_cleanup(blob, (u32)far_id, "far-id", "cs,mia-far"); |
| 95 | |
| 96 | /* |
| 97 | * special case, with CASRSA (far_id: 2) |
| 98 | * FAV-SRSA register itself as FAV-CLA |
| 99 | */ |
| 100 | fav_id = in_8(ADDR_FPGA_R_BASE + 0x44) >> 5; |
| 101 | |
| 102 | if (far_id == FAR_CASRSA && fav_id == FAV_CLA) |
| 103 | fav_id = FAV_SRSA; |
| 104 | |
| 105 | ft_cleanup(blob, (u32)fav_id, "fav-id", "cs,mia-fav"); |
| 106 | |
| 107 | if (far_id == FAR_CASRSA) { |
| 108 | /* switch to phy3 with gpio, we'll only use phy3 */ |
| 109 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 110 | cpm8xx_t __iomem *cp = (cpm8xx_t __iomem *)&immr->im_cpm; |
| 111 | |
| 112 | setbits_be32(&cp->cp_pedat, 0x00002000); |
| 113 | } |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | int checkboard(void) |
| 119 | { |
| 120 | serial_puts("Board: "); |
| 121 | |
| 122 | /* Is a motherboard present ? */ |
| 123 | if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) { |
| 124 | switch (in_8(ADDR_FPGA_R_BASE)) { |
Christophe Leroy | 9646af3 | 2023-01-30 09:07:38 +0100 | [diff] [blame] | 125 | int far_id; |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 126 | case TYPE_MCR: |
| 127 | printf("MCR3000_2G (CS GROUP)\n"); |
| 128 | break; |
Christophe Leroy | 9646af3 | 2023-01-30 09:07:38 +0100 | [diff] [blame] | 129 | case TYPE_MIAE: |
| 130 | far_id = in_8(ADDR_FPGA_R_BASE + 0x43) >> 5; |
| 131 | |
| 132 | if (far_id == FAR_VGOIP) |
| 133 | printf("VGoIP (CS GROUP)\n"); |
| 134 | else |
| 135 | printf("MIAE (CS GROUP)\n"); |
| 136 | |
| 137 | break; |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 138 | default: |
| 139 | printf("Unknown\n"); |
| 140 | for (;;) |
| 141 | ; |
| 142 | break; |
| 143 | } |
| 144 | } else { |
| 145 | printf("CMPC885 (CS GROUP)\n"); |
| 146 | } |
| 147 | return 0; |
| 148 | } |
| 149 | |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 150 | #define MAX_SPI_BYTES 0x20 |
| 151 | |
Christophe Leroy | eefb461 | 2023-04-05 16:05:36 +0200 | [diff] [blame^] | 152 | #define EE_OFF_MAC1 0x10 |
| 153 | #define EE_OFF_MAC2 0x16 |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 154 | |
| 155 | /* Reads MAC addresses from SPI EEPROM */ |
| 156 | static int setup_mac(void) |
| 157 | { |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 158 | uchar din[MAX_SPI_BYTES]; |
Christophe Leroy | eefb461 | 2023-04-05 16:05:36 +0200 | [diff] [blame^] | 159 | int ret; |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 160 | unsigned long ident = 0x08005120; |
| 161 | |
Christophe Leroy | eefb461 | 2023-04-05 16:05:36 +0200 | [diff] [blame^] | 162 | ret = read_eeprom(din, sizeof(din)); |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 163 | if (ret) |
| 164 | return ret; |
| 165 | |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 166 | if (memcmp(din + EE_OFF_MAC1, &ident, sizeof(ident)) == 0) |
| 167 | eth_env_set_enetaddr("ethaddr", din + EE_OFF_MAC1); |
| 168 | |
| 169 | if (memcmp(din + EE_OFF_MAC2, &ident, sizeof(ident)) == 0) |
| 170 | eth_env_set_enetaddr("eth1addr", din + EE_OFF_MAC2); |
| 171 | |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | int misc_init_r(void) |
| 176 | { |
Christophe Leroy | 9646af3 | 2023-01-30 09:07:38 +0100 | [diff] [blame] | 177 | u8 val, tmp, far_id; |
| 178 | int count = 3; |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 179 | |
| 180 | val = in_8(ADDR_FPGA_R_BASE); |
| 181 | |
| 182 | /* Verify mother board presence */ |
| 183 | if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) { |
| 184 | /* identify the type of mother board */ |
| 185 | switch (val) { |
| 186 | case TYPE_MCR: |
| 187 | /* if at boot alarm button is pressed, delay boot */ |
| 188 | if ((in_8(ADDR_FPGA_R_ALARMES_IN) & FPGA_R_ACQ_AL_FAV) == 0) |
| 189 | env_set("bootdelay", "60"); |
| 190 | |
| 191 | env_set("config", BOARD_MCR3000_2G); |
| 192 | env_set("hostname", BOARD_MCR3000_2G); |
| 193 | break; |
Christophe Leroy | 9646af3 | 2023-01-30 09:07:38 +0100 | [diff] [blame] | 194 | |
| 195 | case TYPE_MIAE: |
| 196 | do { |
| 197 | tmp = in_8(ADDR_FPGA_R_BASE + 0x41); |
| 198 | count--; |
| 199 | mdelay(10); /* 10msec wait */ |
| 200 | } while (count && tmp != in_8(ADDR_FPGA_R_BASE + 0x41)); |
| 201 | |
| 202 | if (!count) { |
| 203 | printf("Cannot read the reset factory switch position\n"); |
| 204 | hang(); |
| 205 | } |
| 206 | |
| 207 | if (tmp & 0x1) |
| 208 | env_set_default("Factory settings switch ON", 0); |
| 209 | |
| 210 | env_set("config", BOARD_MIAE); |
| 211 | far_id = in_8(ADDR_FPGA_R_BASE + 0x43) >> 5; |
| 212 | |
| 213 | if (far_id == FAR_VGOIP) |
| 214 | env_set("hostname", BOARD_VGOIP); |
| 215 | else |
| 216 | env_set("hostname", BOARD_MIAE); |
| 217 | break; |
| 218 | |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 219 | default: |
| 220 | env_set("config", BOARD_CMPC885); |
| 221 | env_set("hostname", BOARD_CMPC885); |
| 222 | break; |
| 223 | } |
| 224 | } else { |
| 225 | printf("no mother board detected"); |
| 226 | env_set("config", BOARD_CMPC885); |
| 227 | env_set("hostname", BOARD_CMPC885); |
| 228 | } |
| 229 | |
| 230 | if (setup_mac()) |
| 231 | printf("Error retrieving mac addresses\n"); |
| 232 | |
| 233 | /* Protection ON by default */ |
| 234 | flash_protect(FLAG_PROTECT_SET, CFG_SYS_FLASH_BASE, 0xffffffff, &flash_info[0]); |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | static void iop_setup_mcr(void) |
| 240 | { |
| 241 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 242 | iop8xx_t __iomem *iop = &immr->im_ioport; |
| 243 | cpm8xx_t __iomem *cp = &immr->im_cpm; |
| 244 | |
| 245 | /* Wait reset on FPGA_F */ |
| 246 | udelay(100); |
| 247 | |
| 248 | /* We must initialize data before changing direction */ |
| 249 | setbits_be16(&iop->iop_pcdat, 0x088E); |
| 250 | setbits_be16(&iop->iop_pddat, 0x0001); |
| 251 | setbits_be32(&cp->cp_pbdat, 0x00029510); |
| 252 | setbits_be32(&cp->cp_pedat, 0x00000002); |
| 253 | |
| 254 | /* |
| 255 | * PAPAR[13] = 0 [0x0004] -> GPIO: () |
| 256 | * PAPAR[12] = 0 [0x0008] -> GPIO: () |
| 257 | * PAPAR[9] = 1 [0x0040] -> GPIO: (PCM_IN_12_MPC) |
| 258 | * PAPAR[8] = 1 [0x0080] -> GPIO: (PCM_OUT_12_MPC) |
| 259 | * PAPAR[7] = 1 [0x0100] -> GPIO: (TDM_BCLK_MPC) |
| 260 | * PAPAR[6] = 1 [0x0200] -> GPIO: (CLK2) |
| 261 | */ |
| 262 | clrsetbits_be16(&iop->iop_papar, 0x03CC, 0x03C0); |
| 263 | |
| 264 | /* |
| 265 | * PBODR[16] = 1 [0x00008000] -> GPIO: (PROG_FPGA_MEZZ) |
| 266 | */ |
| 267 | setbits_be16(&cp->cp_pbodr, 0x00008000); |
| 268 | |
| 269 | /* |
| 270 | * PBDIR[27] = 1 [0x00000010] -> GPIO: (WR_TEMP2) |
| 271 | * PBDIR[26] = 1 [0x00000020] -> GPIO: (BRG02) |
| 272 | * PBDIR[23] = 1 [0x00000100] -> GPIO: (CS_TEMP2) |
| 273 | * PBDIR[18] = 1 [0x00002000] -> GPIO: (RTS2) |
| 274 | * PBDIR[16] = 1 [0x00008000] -> GPIO: (PROG_FPGA_MEZZ) |
| 275 | * PBDIR[15] = 1 [0x00010000] -> GPIO: (BRG03) |
| 276 | * PBDIR[14] = 1 [0x00020000] -> GPIO: (CS_TEMP) |
| 277 | */ |
| 278 | setbits_be32(&cp->cp_pbdir, 0x0003A130); |
| 279 | |
| 280 | /* |
| 281 | * PBPAR[20] = 1 [0x00000800] -> GPIO: (SMRXD2) |
| 282 | * PBPAR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ) |
| 283 | * PBPAR[16] = 0 [0x00008000] -> GPIO: (PROG_FPGA_MEZZ) |
| 284 | */ |
| 285 | clrsetbits_be32(&cp->cp_pbpar, 0x0000C800, 0x00000800); |
| 286 | |
| 287 | /* |
| 288 | * PCPAR[14] = 0 [0x0002] -> GPIO: (CS_POT2) |
| 289 | */ |
| 290 | clrbits_be16(&iop->iop_pcpar, 0x0002); |
| 291 | |
| 292 | /* |
| 293 | * PDPAR[14] = 1 [0x0002] -> GPIO: (TDM_FS_MPC) |
| 294 | * PDPAR[11] = 1 [0x0010] -> GPIO: (RXD3) |
| 295 | * PDPAR[10] = 1 [0x0020] -> GPIO: (TXD3) |
| 296 | * PDPAR[9] = 1 [0x0040] -> GPIO: (TXD4) |
| 297 | * PDPAR[7] = 1 [0x0100] -> GPIO: (RTS3) |
| 298 | * PDPAR[5] = 1 [0x0400] -> GPIO: (CLK8) |
| 299 | * PDPAR[3] = 1 [0x1000] -> GPIO: (CLK7) |
| 300 | */ |
| 301 | setbits_be16(&iop->iop_pdpar, 0x1572); |
| 302 | |
| 303 | /* |
| 304 | * PEPAR[27] = 1 [0x00000010] -> GPIO: (R2_RXER) |
| 305 | * PEPAR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV) |
| 306 | * PEPAR[25] = 1 [0x00000040] -> GPIO: (RXD4) |
| 307 | * PEPAR[24] = 1 [0x00000080] -> GPIO: (BRG01) |
| 308 | * PEPAR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO) |
| 309 | * PEPAR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1) |
| 310 | * PEPAR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0) |
| 311 | * PEPAR[20] = 1 [0x00000800] -> GPIO: (SMTXD2) |
| 312 | * PEPAR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN) |
| 313 | * PEPAR[17] = 1 [0x00004000] -> GPIO: (CLK5) |
| 314 | * PEPAR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK) |
| 315 | * PEPAR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1) |
| 316 | * PEPAR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0) |
| 317 | */ |
| 318 | clrsetbits_be32(&cp->cp_pepar, 0x0003DFF0, 0x0003DEF0); |
| 319 | |
| 320 | /* |
| 321 | * PADIR[9] = 1 [0x0040] -> GPIO: (PCM_IN_12_MPC) |
| 322 | * PADIR[8] = 1 [0x0080] -> GPIO: (PCM_OUT_12_MPC) |
| 323 | * PADIR[5] = 1 [0x0400] -> GPIO: () |
| 324 | */ |
| 325 | setbits_be16(&iop->iop_padir, 0x04C0); |
| 326 | |
| 327 | /* |
| 328 | * PCDIR[15] = 1 [0x0001] -> GPIO: (WP_EEPROM2) |
| 329 | * PCDIR[14] = 1 [0x0002] -> GPIO: (CS_POT2) |
| 330 | * PCDIR[13] = 1 [0x0004] -> GPIO: (CS_POT1) |
| 331 | * PCDIR[12] = 1 [0x0008] -> GPIO: (CS_EEPROM2) |
| 332 | * PCDIR[8] = 1 [0x0080] -> GPIO: (CS_CODEC_FAV) |
| 333 | * PCDIR[4] = 1 [0x0800] -> GPIO: (CS_CODEC_RADIO) |
| 334 | */ |
| 335 | setbits_be16(&iop->iop_pcdir, 0x088F); |
| 336 | |
| 337 | /* |
| 338 | * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4) |
| 339 | * PDDIR[6] = 0 [0x0200] -> GPIO: (INIT_FPGA_RADIO) |
| 340 | * PDDIR[2] = x [0x2000] -> Reserved |
| 341 | * PDDIR[1] = 0 [0x4000] -> ODR for PD10 : (TXD3) |
| 342 | * PDDIR[0] = 0 [0x8000] -> ODR for PD8 : (R_MDC) |
| 343 | */ |
| 344 | clrsetbits_be16(&iop->iop_pddir, 0xC240, 0x0040); |
| 345 | |
| 346 | /* |
| 347 | * PEDIR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE) |
| 348 | * PEDIR[27] = 1 [0x00000010] -> GPIO: (R2_RXER) |
| 349 | * PEDIR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV) |
| 350 | * PEDIR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO) |
| 351 | * PEDIR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1) |
| 352 | * PEDIR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0) |
| 353 | * PEDIR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN) |
| 354 | * PEDIR[18] = 1 [0x00002000] -> GPIO: (PROG_FPGA_RADIO) |
| 355 | * PEDIR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK) |
| 356 | * PEDIR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1) |
| 357 | * PEDIR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0) |
| 358 | */ |
| 359 | clrsetbits_be32(&cp->cp_pedir, 0x0003B732, 0x0003B632); |
| 360 | |
| 361 | /* |
| 362 | * PAODR[10] = 1 [0x0020] -> GPIO: (INIT_FPGA_F) |
| 363 | */ |
| 364 | setbits_be16(&iop->iop_paodr, 0x0020); // set_bit |
| 365 | |
| 366 | /* |
| 367 | * PEODR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE) |
| 368 | * PEODR[18] = 1 [0x00002000] -> GPIO: (FPGA_RADIO) |
| 369 | */ |
| 370 | setbits_be32(&cp->cp_peodr, 0x00002002); |
| 371 | |
| 372 | /* |
| 373 | * PESO[24] = 1 [0x00000080] -> GPIO: (BRG01) |
| 374 | * PESO[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO) |
| 375 | * PESO[20] = 1 [0x00000800] -> GPIO: (SMTXD2) |
| 376 | * PESO[19] = 1 [0x00001000] -> GPIO: (R2_TXEN) |
| 377 | * PESO[15] = 1 [0x00010000] -> GPIO: (R2_TXD1) |
| 378 | * PESO[14] = 1 [0x00020000] -> GPIO: (R2_TXD0) |
| 379 | */ |
| 380 | clrsetbits_be32(&cp->cp_peso, 0x00031980, 0x00031880); |
| 381 | |
| 382 | /* Disable CS for device */ |
| 383 | /* PROGFPGA down */ |
| 384 | clrbits_be32(&cp->cp_pbdat, 0x00008000); |
| 385 | |
| 386 | /* PROGFPGA down */ |
| 387 | clrbits_be32(&cp->cp_pedat, 0x00002000); |
| 388 | udelay(1); /* Wait more than 300ns */ |
| 389 | |
| 390 | /* |
| 391 | * We do not set the PROG signal of the C4E1 because |
| 392 | * there is a conflic with the CS of the EEPROM. |
| 393 | * I don't know why there is not the same problem |
| 394 | * with the FPGA_R |
| 395 | */ |
| 396 | |
| 397 | /* PROGFPGA up */ |
| 398 | setbits_be32(&cp->cp_pedat, 0x00002000); |
| 399 | } |
| 400 | |
| 401 | static void iop_setup_cmpc885(void) |
| 402 | { |
| 403 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 404 | iop8xx_t __iomem *iop = &immr->im_ioport; |
| 405 | cpm8xx_t __iomem *cp = &immr->im_cpm; |
| 406 | |
| 407 | /* We must initialize data before changing direction */ |
| 408 | out_be16(&iop->iop_pcdat, 0x0000); |
| 409 | out_be16(&iop->iop_pddat, 0x0001); |
| 410 | |
| 411 | out_be32(&cp->cp_pbdat, 0x00021400); |
| 412 | out_be32(&cp->cp_pedat, 0x00000000); |
| 413 | |
| 414 | /* |
| 415 | * PAPAR[13] = 0 [0x0004] -> GPIO: () |
| 416 | * PAPAR[12] = 0 [0x0008] -> GPIO: () |
| 417 | * PAPAR[9] = 0 [0x0040] -> GPIO: () |
| 418 | * PAPAR[8] = 0 [0x0080] -> GPIO: () |
| 419 | * PAPAR[7] = 0 [0x0100] -> GPIO: () |
| 420 | * PAPAR[6] = 0 [0x0200] -> GPIO: () |
| 421 | */ |
| 422 | clrbits_be16(&iop->iop_papar, 0x03CC); |
| 423 | |
| 424 | /* |
| 425 | * PBPAR[20] = 0 [0x00000800] -> GPIO: () |
| 426 | * PBPAR[17] = 0 [0x00004000] -> GPIO: () |
| 427 | * PBPAR[16] = 0 [0x00008000] -> GPIO: () |
| 428 | */ |
| 429 | clrbits_be32(&cp->cp_pbpar, 0x0000C800); |
| 430 | |
| 431 | /* |
| 432 | * PCPAR[14] = 0 [0x0002] -> GPIO: () |
| 433 | */ |
| 434 | clrbits_be16(&iop->iop_pcpar, 0x0002); |
| 435 | |
| 436 | /* |
| 437 | * PDPAR[14] = 0 [0x0002] -> GPIO: () |
| 438 | * PDPAR[11] = 0 [0x0010] -> GPIO: () |
| 439 | * PDPAR[10] = 0 [0x0020] -> GPIO: () |
| 440 | * PDPAR[9] = 0 [0x0040] -> GPIO: () |
| 441 | * PDPAR[7] = 0 [0x0100] -> GPIO: () |
| 442 | * PDPAR[5] = 0 [0x0400] -> GPIO: () |
| 443 | * PDPAR[3] = 0 [0x1000] -> GPIO: () |
| 444 | */ |
| 445 | clrbits_be16(&iop->iop_pdpar, 0x1572); |
| 446 | |
| 447 | /* |
| 448 | * PEPAR[27] = 0 [0x00000010] -> GPIO: () |
| 449 | * PEPAR[26] = 0 [0x00000020] -> GPIO: () |
| 450 | * PEPAR[25] = 0 [0x00000040] -> GPIO: () |
| 451 | * PEPAR[24] = 0 [0x00000080] -> GPIO: () |
| 452 | * PEPAR[23] = 0 [0x00000100] -> GPIO: () |
| 453 | * PEPAR[22] = 0 [0x00000200] -> GPIO: () |
| 454 | * PEPAR[21] = 0 [0x00000400] -> GPIO: () |
| 455 | * PEPAR[20] = 0 [0x00000800] -> GPIO: () |
| 456 | * PEPAR[19] = 0 [0x00001000] -> GPIO: () |
| 457 | * PEPAR[17] = 0 [0x00004000] -> GPIO: () |
| 458 | * PEPAR[16] = 0 [0x00008000] -> GPIO: () |
| 459 | * PEPAR[15] = 0 [0x00010000] -> GPIO: () |
| 460 | * PEPAR[14] = 0 [0x00020000] -> GPIO: () |
| 461 | */ |
| 462 | clrbits_be32(&cp->cp_pepar, 0x0003DFF0); |
| 463 | |
| 464 | /* |
| 465 | * PADIR[9] = 0 [0x0040] -> GPIO: () |
| 466 | * PADIR[8] = 0 [0x0080] -> GPIO: () |
| 467 | * PADIR[5] = 0 [0x0400] -> GPIO: () |
| 468 | */ |
| 469 | clrbits_be16(&iop->iop_padir, 0x04C0); |
| 470 | |
| 471 | /* |
| 472 | * In/Out or per. Function 0/1 |
| 473 | * PBDIR[27] = 0 [0x00000010] -> GPIO: () |
| 474 | * PBDIR[26] = 0 [0x00000020] -> GPIO: () |
| 475 | * PBDIR[23] = 0 [0x00000100] -> GPIO: () |
| 476 | * PBDIR[17] = 0 [0x00004000] -> GPIO: () |
| 477 | * PBDIR[16] = 0 [0x00008000] -> GPIO: () |
| 478 | */ |
| 479 | clrbits_be32(&cp->cp_pbdir, 0x0000C130); |
| 480 | |
| 481 | /* |
| 482 | * PCDIR[15] = 0 [0x0001] -> GPIO: () |
| 483 | * PCDIR[14] = 0 [0x0002] -> GPIO: () |
| 484 | * PCDIR[13] = 0 [0x0004] -> GPIO: () |
| 485 | * PCDIR[12] = 0 [0x0008] -> GPIO: () |
| 486 | * PCDIR[8] = 0 [0x0080] -> GPIO: () |
| 487 | * PCDIR[4] = 0 [0x0800] -> GPIO: () |
| 488 | */ |
| 489 | clrbits_be16(&iop->iop_pcdir, 0x088F); |
| 490 | |
| 491 | /* |
| 492 | * PDDIR[9] = 0 [0x0040] -> GPIO: () |
| 493 | * PDDIR[6] = 0 [0x0200] -> GPIO: () |
| 494 | * PDDIR[2] = x [0x2000] -> Reserved |
| 495 | * PDDIR[1] = 0 [0x4000] -> ODR for PD10 : () |
| 496 | * PDDIR[0] = 0 [0x8000] -> ODR for PD8 : (R_MDC) |
| 497 | */ |
| 498 | clrbits_be16(&iop->iop_pddir, 0xC240); |
| 499 | |
| 500 | /* |
| 501 | * PEDIR[30] = 0 [0x00000002] -> GPIO: () |
| 502 | * PEDIR[27] = 0 [0x00000010] -> GPIO: () |
| 503 | * PEDIR[26] = 0 [0x00000020] -> GPIO: () |
| 504 | * PEDIR[23] = 0 [0x00000100] -> GPIO: () |
| 505 | * PEDIR[22] = 0 [0x00000200] -> GPIO: () |
| 506 | * PEDIR[21] = 0 [0x00000400] -> GPIO: () |
| 507 | * PEDIR[19] = 0 [0x00001000] -> GPIO: () |
| 508 | * PEDIR[18] = 0 [0x00002000] -> GPIO: () |
| 509 | * PEDIR[16] = 0 [0x00008000] -> GPIO: () |
| 510 | * PEDIR[15] = 0 [0x00010000] -> GPIO: () |
| 511 | * PEDIR[14] = 0 [0x00020000] -> GPIO: () |
| 512 | */ |
| 513 | clrbits_be32(&cp->cp_pedir, 0x0003B732); |
| 514 | |
| 515 | /* |
| 516 | * PAODR[10] = 0 [0x0020] -> GPIO: () |
| 517 | */ |
| 518 | clrbits_be16(&iop->iop_paodr, 0x0020); |
| 519 | |
| 520 | /* |
| 521 | * PBODR[16] = 0 [0x00008000] -> GPIO: () |
| 522 | */ |
| 523 | clrbits_be16(&cp->cp_pbodr, 0x00008000); |
| 524 | |
| 525 | /* |
| 526 | * PEODR[30] = 0 [0x00000002] -> GPIO: () |
| 527 | * PEODR[18] = 0 [0x00002000] -> GPIO: () |
| 528 | */ |
| 529 | clrbits_be32(&cp->cp_peodr, 0x00002002); |
| 530 | |
| 531 | /* |
| 532 | * PESO[24] = 0 [0x00000080] -> GPIO: () |
| 533 | * PESO[23] = 0 [0x00000100] -> GPIO: () |
| 534 | * PESO[20] = 0 [0x00000800] -> GPIO: () |
| 535 | * PESO[19] = 0 [0x00001000] -> GPIO: () |
| 536 | * PESO[15] = 0 [0x00010000] -> GPIO: () |
| 537 | * PESO[14] = 0 [0x00020000] -> GPIO: () |
| 538 | */ |
| 539 | clrbits_be32(&cp->cp_peso, 0x00031980); |
| 540 | } |
| 541 | |
Christophe Leroy | 9646af3 | 2023-01-30 09:07:38 +0100 | [diff] [blame] | 542 | static void iop_setup_miae(void) |
| 543 | { |
| 544 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 545 | iop8xx_t __iomem *iop = &immr->im_ioport; |
| 546 | cpm8xx_t __iomem *cp = &immr->im_cpm; |
| 547 | |
| 548 | /* Wait reset on FPGA_F */ |
| 549 | udelay(100); |
| 550 | |
| 551 | /* Set the front panel LED color to red */ |
| 552 | clrbits_8(ADDR_FPGA_R_FAV, 0x02); |
| 553 | |
| 554 | /* We must initialize data before changing direction */ |
| 555 | setbits_be16(&iop->iop_pcdat, 0x0888); |
| 556 | setbits_be16(&iop->iop_pddat, 0x0201); |
| 557 | setbits_be32(&cp->cp_pbdat, 0x00021510); |
| 558 | setbits_be32(&cp->cp_pedat, 0x00000002); |
| 559 | |
| 560 | /* |
| 561 | * PAPAR[13] = 1 [0x0004] -> GPIO: (RXD2) |
| 562 | * PAPAR[12] = 1 [0x0008] -> GPIO: (TXD2) |
| 563 | * PAPAR[9] = 1 [0x0040] -> GPIO: (TDM1O) |
| 564 | * PAPAR[8] = 1 [0x0080] -> GPIO: (TDM1I) |
| 565 | * PAPAR[7] = 1 [0x0100] -> GPIO: (TDM_BCLK_MPC) |
| 566 | * PAPAR[6] = 1 [0x0200] -> GPIO: (CLK2) |
| 567 | */ |
| 568 | setbits_be16(&iop->iop_papar, 0x03CC); |
| 569 | |
| 570 | /* |
| 571 | * PBODR[16] = 0 [0x00008000] -> GPIO: (L1ST4) |
| 572 | */ |
| 573 | clrbits_be16(&cp->cp_pbodr, 0x00008000); |
| 574 | |
| 575 | /* |
| 576 | * PBDIR[27] = 1 [0x00000010] -> GPIO: (WR_TEMP2) |
| 577 | * PBDIR[26] = 1 [0x00000020] -> GPIO: (BRG02) |
| 578 | * PBDIR[23] = 1 [0x00000100] -> GPIO: (CS_TEMP2) |
| 579 | * PBDIR[18] = 1 [0x00002000] -> GPIO: (RTS2) |
| 580 | * PBDIR[16] = 0 [0x00008000] -> GPIO: (L1ST4) |
| 581 | * PBDIR[15] = 1 [0x00010000] -> GPIO: (BRG03) |
| 582 | * PBDIR[14] = 1 [0x00020000] -> GPIO: (CS_TEMP) |
| 583 | */ |
| 584 | clrsetbits_be32(&cp->cp_pbdir, 0x0003A130, 0x00032130); |
| 585 | |
| 586 | /* |
| 587 | * PBPAR[20] = 1 [0x00000800] -> GPIO: (SMRXD2) |
| 588 | * PBPAR[17] = 1 [0x00004000] -> GPIO: (L1ST3) |
| 589 | * PBPAR[16] = 1 [0x00008000] -> GPIO: (L1ST4) |
| 590 | */ |
| 591 | setbits_be32(&cp->cp_pbpar, 0x0000C800); |
| 592 | |
| 593 | /* |
| 594 | * PCPAR[14] = 1 [0x0002] -> GPIO: (L1ST2) |
| 595 | */ |
| 596 | setbits_be16(&iop->iop_pcpar, 0x0002); |
| 597 | |
| 598 | /* |
| 599 | * PDPAR[14] = 1 [0x0002] -> GPIO: (TDM_FS_MPC) |
| 600 | * PDPAR[11] = 1 [0x0010] -> GPIO: (RXD3) |
| 601 | * PDPAR[10] = 1 [0x0020] -> GPIO: (TXD3) |
| 602 | * PDPAR[9] = 1 [0x0040] -> GPIO: (TXD4) |
| 603 | * PDPAR[7] = 1 [0x0100] -> GPIO: (RTS3) |
| 604 | * PDPAR[5] = 1 [0x0400] -> GPIO: (CLK8) |
| 605 | * PDPAR[3] = 1 [0x1000] -> GPIO: (CLK7) |
| 606 | */ |
| 607 | setbits_be16(&iop->iop_pdpar, 0x1572); |
| 608 | |
| 609 | /* |
| 610 | * PEPAR[27] = 1 [0x00000010] -> GPIO: (R2_RXER) |
| 611 | * PEPAR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV) |
| 612 | * PEPAR[25] = 1 [0x00000040] -> GPIO: (RXD4) |
| 613 | * PEPAR[24] = 1 [0x00000080] -> GPIO: (BRG01) |
| 614 | * PEPAR[23] = 1 [0x00000100] -> GPIO: (L1ST1) |
| 615 | * PEPAR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1) |
| 616 | * PEPAR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0) |
| 617 | * PEPAR[20] = 1 [0x00000800] -> GPIO: (SMTXD2) |
| 618 | * PEPAR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN) |
| 619 | * PEPAR[17] = 1 [0x00004000] -> GPIO: (CLK5) |
| 620 | * PEPAR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK) |
| 621 | * PEPAR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1) |
| 622 | * PEPAR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0) |
| 623 | */ |
| 624 | setbits_be32(&cp->cp_pepar, 0x0003DFF0); |
| 625 | |
| 626 | /* |
| 627 | * PADIR[9] = 1 [0x0040] -> GPIO: (TDM1O) |
| 628 | * PADIR[8] = 1 [0x0080] -> GPIO: (TDM1I) |
| 629 | * PADIR[5] = 0 [0x0400] -> GPIO: () |
| 630 | */ |
| 631 | clrsetbits_be16(&iop->iop_padir, 0x04C0, 0x00C0); |
| 632 | |
| 633 | /* |
| 634 | * PCDIR[15] = 1 [0x0001] -> GPIO: (WP_EEPROM2) |
| 635 | * PCDIR[14] = 1 [0x0002] -> GPIO: (L1ST2) |
| 636 | * PCDIR[13] = 0 [0x0004] -> GPIO: () |
| 637 | * PCDIR[12] = 1 [0x0008] -> GPIO: (CS_EEPROM2) |
| 638 | * PCDIR[8] = 1 [0x0080] -> GPIO: (CS_CODEC_2) |
| 639 | * PCDIR[4] = 1 [0x0800] -> GPIO: (CS_CODEC_1) |
| 640 | */ |
| 641 | clrsetbits_be16(&iop->iop_pcdir, 0x088F, 0x088B); |
| 642 | |
| 643 | /* |
| 644 | * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4) |
| 645 | * PDDIR[6] = 1 [0x0200] -> GPIO: (CS_CODEC_3) |
| 646 | */ |
| 647 | setbits_be16(&iop->iop_pddir, 0x0240); |
| 648 | |
| 649 | /* |
| 650 | * PEDIR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE) |
| 651 | * PEDIR[27] = 1 [0x00000010] -> GPIO: (R2_RXER) |
| 652 | * PEDIR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV) |
| 653 | * PEDIR[23] = 1 [0x00000100] -> GPIO: (L1ST1) |
| 654 | * PEDIR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1) |
| 655 | * PEDIR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0) |
| 656 | * PEDIR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN) |
| 657 | * PEDIR[18] = 1 [0x00002000] -> GPIO: (PE18) |
| 658 | * PEDIR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK) |
| 659 | * PEDIR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1) |
| 660 | * PEDIR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0) |
| 661 | */ |
| 662 | setbits_be32(&cp->cp_pedir, 0x0003B732); |
| 663 | |
| 664 | /* |
| 665 | * PAODR[10] = 1 [0x0020] -> GPIO: (INIT_FPGA_F) |
| 666 | */ |
| 667 | setbits_be16(&iop->iop_paodr, 0x0020); |
| 668 | |
| 669 | /* |
| 670 | * PEODR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE) |
| 671 | * PEODR[18] = 0 [0x00002000] -> GPIO: (PE18) |
| 672 | */ |
| 673 | clrsetbits_be32(&cp->cp_peodr, 0x00002002, 0x00000002); |
| 674 | |
| 675 | /* |
| 676 | * PESO[24] = 1 [0x00000080] -> GPIO: (BRG01) |
| 677 | * PESO[23] = 1 [0x00000100] -> GPIO: (L1ST1) |
| 678 | * PESO[20] = 1 [0x00000800] -> GPIO: (SMTXD2) |
| 679 | * PESO[19] = 1 [0x00001000] -> GPIO: (R2_TXEN) |
| 680 | * PESO[15] = 1 [0x00010000] -> GPIO: (R2_TXD1) |
| 681 | * PESO[14] = 1 [0x00020000] -> GPIO: (R2_TXD0) |
| 682 | */ |
| 683 | setbits_be32(&cp->cp_peso, 0x00031980); |
| 684 | } |
| 685 | |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 686 | int board_early_init_f(void) |
| 687 | { |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | /* Specific board initialization */ |
| 692 | int board_early_init_r(void) |
| 693 | { |
| 694 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 695 | iop8xx_t __iomem *iop = &immr->im_ioport; |
| 696 | cpm8xx_t __iomem *cp = &immr->im_cpm; |
| 697 | |
| 698 | /* MPC885 Port settings common to all boards */ |
| 699 | setbits_be16(&iop->iop_padat, 0x0000); |
| 700 | |
| 701 | /* Port A (MPC885 reference manual - 34.2) */ |
| 702 | /* |
| 703 | * In/Out or per. Function 0/1 |
| 704 | * PADIR[15] = 0 [0x0001] -> GPIO: (USB_RXD) |
| 705 | * PADIR[14] = 0 [0x0002] -> GPIO: (USB_OE) |
| 706 | * PADIR[13] = 0 [0x0004] -> GPIO: () |
| 707 | * PADIR[12] = 0 [0x0008] -> GPIO: () |
| 708 | * PADIR[11] = 1 [0x0010] -> GPIO: (R1_TXD0) |
| 709 | * PADIR[10] = 0 [0x0020] -> GPIO: () |
| 710 | * PADIR[7] = 0 [0x0100] -> GPIO: () |
| 711 | * PADIR[6] = 0 [0x0200] -> GPIO: () |
| 712 | * PADIR[4] = 1 [0x0800] -> GPIO: (R1_TXD1) |
| 713 | * PADIR[3] = 0 [0x1000] -> GPIO: (R1_RXER) |
| 714 | * PADIR[2] = 0 [0x2000] -> GPIO: (R1_CRS_DV) |
| 715 | * PADIR[1] = 0 [0x4000] -> GPIO: (R1_RXD0) |
| 716 | * PADIR[0] = 0 [0x8000] -> GPIO: (R1_RXD1) |
| 717 | */ |
| 718 | clrsetbits_be16(&iop->iop_padir, 0xFB3F, 0x0810); |
| 719 | |
| 720 | /* |
| 721 | * Open drain or active output |
| 722 | * PAODR[15] = x [0x0001] |
| 723 | * PAODR[14] = 0 [0x0002] |
| 724 | * PAODR[13] = x [0x0004] |
| 725 | * PAODR[12] = 0 [0x0008] |
| 726 | * PAODR[11] = 0 [0x0010] |
| 727 | * PAODR[9] = 0 [0x0040] |
| 728 | * PAODR[8] = 0 [0x0080] |
| 729 | * PAODR[7] = 0 [0x0100] |
| 730 | */ |
| 731 | clrbits_be16(&iop->iop_paodr, 0x01DF); |
| 732 | |
| 733 | /* |
| 734 | * GPIO or per. Function |
| 735 | * PAPAR[15] = 1 [0x0001] -> GPIO: (USB_RXD) |
| 736 | * PAPAR[14] = 1 [0x0002] -> GPIO: (USB_OE) |
| 737 | * PAPAR[11] = 1 [0x0010] -> GPIO: (R1_TXD0) |
| 738 | * PAPAR[10] = 0 [0x0020] -> GPIO: (INIT_FPGA_F) |
| 739 | * PAPAR[5] = 0 [0x0400] -> GPIO: () |
| 740 | * PAPAR[4] = 1 [0x0800] -> GPIO: (R1_TXD1) |
| 741 | * PAPAR[3] = 1 [0x1000] -> GPIO: (R1_RXER) |
| 742 | * PAPAR[2] = 1 [0x2000] -> GPIO: (R1_CRS_DV) |
| 743 | * PAPAR[1] = 1 [0x4000] -> GPIO: (R1_RXD0) |
| 744 | * PAPAR[0] = 1 [0x8000] -> GPIO: (R1_RXD1) |
| 745 | */ |
| 746 | clrsetbits_be16(&iop->iop_papar, 0xFC33, 0xF813); |
| 747 | |
| 748 | /* Port B (MPC885 reference manual - 34.3) */ |
| 749 | /* |
| 750 | * In/Out or per. Function 0/1 |
| 751 | * PBDIR[31] = 0 [0x00000001] -> GPIO: (R1_REF_CLK) |
| 752 | * PBDIR[30] = 1 [0x00000002] -> GPIO: (CLK) |
| 753 | * PBDIR[29] = 1 [0x00000004] -> GPIO: (MOSI) |
| 754 | * PBDIR[28] = 1 [0x00000008] -> GPIO: (MISO) |
| 755 | * PBDIR[25] = 0 [0x00000040] -> GPIO: (SMTXD1) |
| 756 | * PBDIR[24] = 0 [0x00000080] -> GPIO: (SMRXD1) |
| 757 | * PBDIR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ) |
| 758 | * PBDIR[21] = 1 [0x00000400] -> GPIO: (CS_EEPROM) |
| 759 | * PBDIR[20] = 0 [0x00000800] -> GPIO: (SMRXD2) |
| 760 | * PBDIR[19] = 1 [0x00001000] -> GPIO: (WR_TEMP) |
| 761 | * PBDIR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ) |
| 762 | */ |
| 763 | clrsetbits_be32(&cp->cp_pbdir, 0x00005ECF, 0x0000140E); |
| 764 | |
| 765 | /* |
| 766 | * Open drain or active output |
| 767 | * PBODR[31] = 0 [0x00000001] -> GPIO: (R1_REF_CLK) |
| 768 | * PBODR[30] = 0 [0x00000002] -> GPIO: (CLK) |
| 769 | * PBODR[29] = 0 [0x00000004] -> GPIO: (MOSI) |
| 770 | * PBODR[28] = 0 [0x00000008] -> GPIO: (MISO) |
| 771 | * PBODR[27] = 0 [0x00000010] -> GPIO: (WR_TEMP2) |
| 772 | * PBODR[26] = 0 [0x00000020] -> GPIO: (BRG02) |
| 773 | * PBODR[25] = 0 [0x00000040] -> GPIO: (SMTXD1) |
| 774 | * PBODR[24] = 0 [0x00000080] -> GPIO: (SMRXD1) |
| 775 | * PBODR[23] = 0 [0x00000100] -> GPIO: (CS_TEMP2) |
| 776 | * PBODR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ) |
| 777 | * PBODR[21] = 0 [0x00000400] -> GPIO: (CS_EEPROM) |
| 778 | * PBODR[20] = 0 [0x00000800] -> GPIO: (SMRXD2) |
| 779 | * PBODR[19] = 0 [0x00001000] -> GPIO: (WR_TEMP) |
| 780 | * PBODR[18] = 0 [0x00002000] -> GPIO: (RTS2) |
| 781 | * PBODR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ) |
| 782 | */ |
| 783 | clrbits_be16(&cp->cp_pbodr, 0x00007FFF); |
| 784 | |
| 785 | /* |
| 786 | * GPIO or per. Function |
| 787 | * PBPAR[31] = 1 [0x00000001] -> GPIO: (R1_REF_CLK) |
| 788 | * PBPAR[30] = 1 [0x00000002] -> GPIO: (CLK) |
| 789 | * PBPAR[29] = 1 [0x00000004] -> GPIO: (MOSI) |
| 790 | * PBPAR[28] = 1 [0x00000008] -> GPIO: (MISO) |
| 791 | * PBPAR[27] = 0 [0x00000010] -> GPIO: (WR_TEMP2) |
| 792 | * PBPAR[26] = 0 [0x00000020] -> GPIO: (BRG02) |
| 793 | * PBPAR[25] = 1 [0x00000040] -> GPIO: (SMTXD1) |
| 794 | * PBPAR[24] = 1 [0x00000080] -> GPIO: (SMRXD1) |
| 795 | * PBPAR[23] = 0 [0x00000100] -> GPIO: (CS_TEMP2) |
| 796 | * PBPAR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ) |
| 797 | * PBPAR[21] = 0 [0x00000400] -> GPIO: (CS_EEPROM) |
| 798 | * PBPAR[19] = 0 [0x00001000] -> GPIO: (WR_TEMP) |
| 799 | * PBPAR[18] = 0 [0x00002000] -> GPIO: (RTS2) |
| 800 | * PBPAR[15] = 0 [0x00010000] -> GPIO: (BRG03) |
| 801 | * PBPAR[14] = 0 [0x00020000] -> GPIO: (CS_TEMP) |
| 802 | */ |
| 803 | clrsetbits_be32(&cp->cp_pbpar, 0x000337FF, 0x000000CF); |
| 804 | |
| 805 | /* Port C (MPC885 Reference Manual - 34.4) */ |
| 806 | /* |
| 807 | * In/Out or per. Function 0/1 |
| 808 | * PCDIR[11] = 0 [0x0010] -> GPIO: (USB_RXP) |
| 809 | * PCDIR[10] = 0 [0x0020] -> GPIO: (USB_RXN) |
| 810 | * PCDIR[9] = 0 [0x0040] -> GPIO: (CTS2) |
| 811 | * PCDIR[7] = 1 [0x0100] -> GPIO: (USB_TXP) |
| 812 | * PCDIR[6] = 1 [0x0200] -> GPIO: (USB_TXN) |
| 813 | * PCDIR[5] = 0 [0x0400] -> GPIO: (CTS3) |
| 814 | */ |
| 815 | clrsetbits_be16(&iop->iop_pcdir, 0x0770, 0x0300); |
| 816 | |
| 817 | /* |
| 818 | * GPIO or per. Function |
| 819 | * PCPAR[15] = 0 [0x0001] -> GPIO: (WP_EEPROM2) |
| 820 | * PCPAR[13] = 0 [0x0004] -> GPIO: (CS_POT1) |
| 821 | * PCPAR[12] = 0 [0x0008] -> GPIO: (CS_EEPROM2) |
| 822 | * PCPAR[11] = 0 [0x0010] -> GPIO: (USB_RXP) |
| 823 | * PCPAR[10] = 0 [0x0020] -> GPIO: (USB_RXN) |
| 824 | * PCPAR[9] = 0 [0x0040] -> GPIO: (CTS2) |
| 825 | * PCPAR[8] = 0 [0x0080] -> GPIO: (CS_CODEC_FAV) |
| 826 | * PCPAR[7] = 1 [0x0100] -> GPIO: (USB_TXP) |
| 827 | * PCPAR[6] = 1 [0x0200] -> GPIO: (USB_TXN) |
| 828 | * PCPAR[5] = 0 [0x0400] -> GPIO: (CTS3) |
| 829 | * PCPAR[4] = 0 [0x0800] -> GPIO: (CS_CODEC_RADIO) |
| 830 | */ |
| 831 | clrsetbits_be16(&iop->iop_pcpar, 0x0FFD, 0x0300); |
| 832 | |
| 833 | /* |
| 834 | * Special Option register |
| 835 | * PCSO[15] = 0 [0x0001] -> GPIO: (WP_EEPROM2) |
| 836 | * PCSO[14] = 0 [0x0002] -> GPIO: (CS_POT2) |
| 837 | * PCSO[13] = x [0x0004] -> Reserved |
| 838 | * PCSO[12] = x [0x0008] -> Reserved |
| 839 | * PCSO[11] = 1 [0x0010] -> GPIO: (USB_RXP) |
| 840 | * PCSO[10] = 1 [0x0020] -> GPIO: (USB_RXN) |
| 841 | * PCSO[9] = 1 [0x0040] -> GPIO: (CTS2) |
| 842 | * PCSO[8] = 0 [0x0080] -> GPIO: (CS_CODEC_FAV) |
| 843 | * PCSO[7] = 0 [0x0100] -> GPIO: (USB_TXP) |
| 844 | * PCSO[6] = 0 [0x0200] -> GPIO: (USB_TXN) |
| 845 | * PCSO[5] = 1 [0x0400] -> GPIO: (CTS3) |
| 846 | * PCSO[4] = 0 [0x0800] -> GPIO: (CS_CODEC_RADIO) |
| 847 | */ |
| 848 | clrsetbits_be16(&iop->iop_pcso, 0x0FF3, 0x0470); |
| 849 | |
| 850 | /* |
| 851 | * Interrupt or IO |
| 852 | * PCINT[15] = 0 [0x0001] -> GPIO: () |
| 853 | * PCINT[14] = 0 [0x0002] -> GPIO: () |
| 854 | * PCINT[13] = 0 [0x0004] -> GPIO: () |
| 855 | * PCINT[12] = 0 [0x0008] -> GPIO: () |
| 856 | * PCINT[11] = 0 [0x0010] -> GPIO: (USB_RXP) |
| 857 | * PCINT[10] = 0 [0x0020] -> GPIO: (USB_RXN) |
| 858 | * PCINT[9] = 0 [0x0040] -> GPIO: () |
| 859 | * PCINT[8] = 0 [0x0080] -> GPIO: () |
| 860 | * PCINT[7] = 0 [0x0100] -> GPIO: (USB_TXP) |
| 861 | * PCINT[6] = 0 [0x0200] -> GPIO: (USB_TXN) |
| 862 | * PCINT[5] = 0 [0x0400] -> GPIO: () |
| 863 | * PCINT[4] = 0 [0x0800] -> GPIO: () |
| 864 | */ |
| 865 | clrbits_be16(&iop->iop_pcint, 0x0FFF); |
| 866 | |
| 867 | /* Port D (MPC885 Reference Manual - 34.5) */ |
| 868 | /* |
| 869 | * In/Out or per. Function 0/1 |
| 870 | * PDDIR[15] = 1 [0x0001] -> GPIO: (CS_NAND) |
| 871 | * PDDIR[14] = 0 [0x0002] -> GPIO: (TDM_FS_MPC) |
| 872 | * PDDIR[13] = 1 [0x0004] -> GPIO: (ALE_NAND) |
| 873 | * PDDIR[12] = 1 [0x0008] -> GPIO: (CLE_NAND) |
| 874 | * PDDIR[11] = 0 [0x0010] -> GPIO: (RXD3) |
| 875 | * PDDIR[10] = 0 [0x0020] -> GPIO: (TXD3) |
| 876 | * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4) |
| 877 | * PDDIR[8] = 0 [0x0080] -> GPIO: (R_MDC) |
| 878 | * PDDIR[7] = 0 [0x0100] -> GPIO: (RTS3) |
| 879 | * PDDIR[5] = 0 [0x0400] -> GPIO: (CLK8) |
| 880 | * PDDIR[4] = 0 [0x0800] -> GPIO: (CLK4) |
| 881 | * PDDIR[3] = 0 [0x1000] -> GPIO: (CLK7) |
| 882 | */ |
| 883 | clrsetbits_be16(&iop->iop_pddir, 0x1DFF, 0x004D); |
| 884 | |
| 885 | /* |
| 886 | * GPIO or per. Function |
| 887 | * PDPAR[15] = 0 [0x0001] -> GPIO: (CS_NAND) |
| 888 | * PDPAR[13] = 0 [0x0004] -> GPIO: (ALE_NAND) |
| 889 | * PDPAR[12] = 0 [0x0008] -> GPIO: (CLE_NAND) |
| 890 | * PDPAR[8] = 1 [0x0080] -> GPIO: (R_MDC) |
| 891 | * PDPAR[6] = 0 [0x0200] -> GPIO: (INIT_FPGA_RADIO) |
| 892 | * PDPAR[4] = 1 [0x0800] -> GPIO: (CLK4) |
| 893 | */ |
| 894 | clrsetbits_be16(&iop->iop_pdpar, 0x0A8D, 0x0880); |
| 895 | |
| 896 | /* Port E (MPC885 Reference Manual - 34.6) */ |
| 897 | /* |
| 898 | * In/Out or per. Function 0/1 |
| 899 | * PEDIR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE) |
| 900 | * PEDIR[29] = 1 [0x00000004] -> GPIO: (USB_SPEED) |
| 901 | * PEDIR[28] = 1 [0x00000008] -> GPIO: (USB_SUSPEND) |
| 902 | * PEDIR[25] = 0 [0x00000040] -> GPIO: (RXD4) |
| 903 | * PEDIR[24] = 0 [0x00000080] -> GPIO: (BRG01) |
| 904 | * PEDIR[20] = 0 [0x00000800] -> GPIO: (SMTXD2) |
| 905 | * PEDIR[17] = 0 [0x00004000] -> GPIO: (CLK5) |
| 906 | */ |
| 907 | clrsetbits_be32(&cp->cp_pedir, 0x000048CD, 0x0000000C); |
| 908 | |
| 909 | /* |
| 910 | * open drain or active output |
| 911 | * PEODR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE) |
| 912 | * PEODR[29] = 0 [0x00000004] -> GPIO: (USB_SPEED) |
| 913 | * PEODR[28] = 1 [0x00000008] -> GPIO: (USB_SUSPEND) |
| 914 | * PEODR[27] = 0 [0x00000010] -> GPIO: (R2_RXER) |
| 915 | * PEODR[26] = 0 [0x00000020] -> GPIO: (R2_CRS_DV) |
| 916 | * PEODR[25] = 0 [0x00000040] -> GPIO: (RXD4) |
| 917 | * PEODR[24] = 0 [0x00000080] -> GPIO: (BRG01) |
| 918 | * PEODR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO) |
| 919 | * PEODR[22] = 0 [0x00000200] -> GPIO: (R2_RXD1) |
| 920 | * PEODR[21] = 0 [0x00000400] -> GPIO: (R2_RXD0) |
| 921 | * PEODR[20] = 0 [0x00000800] -> GPIO: (SMTXD2) |
| 922 | * PEODR[19] = 0 [0x00001000] -> GPIO: (R2_TXEN) |
| 923 | * PEODR[17] = 0 [0x00004000] -> GPIO: (CLK5) |
| 924 | * PEODR[16] = 0 [0x00008000] -> GPIO: (R2_REF_CLK) |
| 925 | */ |
| 926 | clrsetbits_be32(&cp->cp_peodr, 0x0000DFFD, 0x00000008); |
| 927 | |
| 928 | /* |
| 929 | * GPIO or per. Function |
| 930 | * PEPAR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE) |
| 931 | * PEPAR[30] = 0 [0x00000002] -> GPIO: (PROG_FPGA_FIRMWARE) |
| 932 | * PEPAR[29] = 0 [0x00000004] -> GPIO: (USB_SPEED) |
| 933 | * PEPAR[28] = 0 [0x00000008] -> GPIO: (USB_SUSPEND) |
| 934 | * PEPAR[18] = 0 [0x00002000] -> GPIO: (PROG_FPGA_RADIO) |
| 935 | */ |
| 936 | clrbits_be32(&cp->cp_pepar, 0x0000200F); |
| 937 | |
| 938 | /* |
| 939 | * Special Option register |
| 940 | * PESO[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE) |
| 941 | * PESO[30] = 0 [0x00000002] -> GPIO: (PROG_FPGA_FIRMWARE) |
| 942 | * PESO[29] = 0 [0x00000004] -> GPIO: (USB_SPEED) |
| 943 | * PESO[28] = 0 [0x00000008] -> GPIO: (USB_SUSPEND) |
| 944 | * PESO[27] = 0 [0x00000010] -> GPIO: (R2_RXER) |
| 945 | * PESO[26] = 0 [0x00000020] -> GPIO: (R2_CRS_DV) |
| 946 | * PESO[25] = 0 [0x00000040] -> GPIO: (RXD4) |
| 947 | * PESO[22] = 0 [0x00000200] -> GPIO: (R2_RXD1) |
| 948 | * PESO[21] = 0 [0x00000400] -> GPIO: (R2_RXD0) |
| 949 | * PESO[18] = 0 [0x00002000] -> GPIO: (PROG_FPGA_RADIO) |
| 950 | * PESO[17] = 0 [0x00004000] -> GPIO: (CLK5) |
| 951 | * PESO[16] = 0 [0x00008000] -> GPIO: (R2_REF_CLK) |
| 952 | */ |
| 953 | clrbits_be32(&cp->cp_peso, 0x0000E67F); |
| 954 | |
| 955 | /* Is a motherboard present ? */ |
| 956 | if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) { |
| 957 | /* Initialize signal PROG_FPGA_FIRMWARE */ |
| 958 | out_be32(&cp->cp_pedat, 0x00000002); |
| 959 | out_be32(&cp->cp_peodr, 0x00000002); |
| 960 | out_be32(&cp->cp_pedir, 0x00000002); |
| 961 | |
| 962 | /* Check if fpga firmware is loaded */ |
| 963 | if (!(in_be32(&cp->cp_pedat) & 0x00000001)) { |
| 964 | printf("Reloading FPGA firmware.\n"); |
| 965 | |
| 966 | /* Load fpga firmware */ |
| 967 | /* Activate PROG_FPGA_FIRMWARE for 1 usec */ |
| 968 | clrbits_be32(&cp->cp_pedat, 0x00000002); |
| 969 | udelay(1); |
| 970 | setbits_be32(&cp->cp_pedat, 0x00000002); |
| 971 | |
| 972 | /* Wait 200 msec and check DONE_FPGA_FIRMWARE */ |
| 973 | mdelay(200); |
| 974 | if (!(in_be32(&cp->cp_pedat) & 0x00000001)) { |
| 975 | for (;;) { |
| 976 | printf("error loading firmware.\n"); |
| 977 | mdelay(500); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | /* Send a reset signal and wait for 20 msec */ |
| 982 | clrbits_be16(ADDR_CPLD_R_RESET, R_RST_STATUS); |
| 983 | mdelay(20); |
| 984 | setbits_be16(ADDR_CPLD_R_RESET, R_RST_STATUS); |
| 985 | } |
| 986 | |
| 987 | /* Wait 300 msec and check the reset state */ |
| 988 | mdelay(300); |
| 989 | if (!(in_be16(ADDR_CPLD_R_RESET) & R_RESET_STATUS)) { |
| 990 | for (;;) { |
| 991 | printf("Could not reset FPGA.\n"); |
| 992 | mdelay(500); |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | /* is FPGA firmware loaded ? */ |
| 997 | if (!(in_be32(&cp->cp_pedat) & 0x00000001)) { |
| 998 | printf("Reloading FPGA firmware\n"); |
| 999 | |
| 1000 | /* Load FPGA firmware */ |
| 1001 | /* Activate PROG_FPGA_FIRMWARE for 1 usec */ |
| 1002 | clrbits_be32(&cp->cp_pedat, 0x00000002); |
| 1003 | udelay(1); |
| 1004 | setbits_be32(&cp->cp_pedat, 0x00000002); |
| 1005 | |
| 1006 | /* Wait 200ms before checking DONE_FPGA_FIRMWARE */ |
| 1007 | mdelay(200); |
| 1008 | } |
| 1009 | |
| 1010 | /* Identify the type of mother board */ |
| 1011 | switch (in_8(ADDR_FPGA_R_BASE)) { |
| 1012 | case TYPE_MCR: |
| 1013 | iop_setup_mcr(); |
| 1014 | break; |
| 1015 | |
Christophe Leroy | 9646af3 | 2023-01-30 09:07:38 +0100 | [diff] [blame] | 1016 | case TYPE_MIAE: |
| 1017 | iop_setup_miae(); |
| 1018 | break; |
| 1019 | |
Christophe Leroy | 1fc46f5 | 2022-10-14 12:54:50 +0200 | [diff] [blame] | 1020 | default: |
| 1021 | break; |
| 1022 | } |
| 1023 | /* CMPC885 board alone */ |
| 1024 | } else { |
| 1025 | iop_setup_cmpc885(); |
| 1026 | } |
| 1027 | |
| 1028 | return 0; |
| 1029 | } |