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