Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 2 | /* |
Zhao Chenhui | 2436cb1 | 2011-08-24 13:20:04 +0800 | [diff] [blame] | 3 | * Copyright 2004, 2007, 2009-2011 Freescale Semiconductor, Inc. |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 4 | * |
| 5 | * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com> |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 1ab1692 | 2022-07-31 12:28:48 -0600 | [diff] [blame] | 9 | #include <display_options.h> |
Simon Glass | 18afe10 | 2019-11-14 12:57:47 -0700 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 11 | #include <net.h> |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 12 | #include <pci.h> |
Simon Glass | f5c208d | 2019-11-14 12:57:20 -0700 | [diff] [blame] | 13 | #include <vsprintf.h> |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 14 | #include <asm/processor.h> |
Jon Loeliger | c378bae | 2008-03-18 13:51:06 -0500 | [diff] [blame] | 15 | #include <asm/mmu.h> |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 16 | #include <asm/immap_85xx.h> |
Kumar Gala | 9bbd643 | 2009-04-02 13:22:48 -0500 | [diff] [blame] | 17 | #include <asm/fsl_pci.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 18 | #include <fsl_ddr_sdram.h> |
Kumar Gala | 3d02038 | 2010-12-15 04:55:20 -0600 | [diff] [blame] | 19 | #include <asm/fsl_serdes.h> |
Andy Fleming | 239e75f | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 20 | #include <miiphy.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 21 | #include <linux/delay.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 22 | #include <linux/libfdt.h> |
Kumar Gala | d28ced3 | 2007-11-29 00:11:44 -0600 | [diff] [blame] | 23 | #include <fdt_support.h> |
chenhui zhao | d1077b6 | 2011-09-06 16:41:18 +0000 | [diff] [blame] | 24 | #include <tsec.h> |
| 25 | #include <fsl_mdio.h> |
| 26 | #include <netdev.h> |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 27 | |
| 28 | #include "../common/cadmus.h" |
| 29 | #include "../common/eeprom.h" |
Matthew McClintock | aa6dd06 | 2006-06-28 10:46:13 -0500 | [diff] [blame] | 30 | #include "../common/via.h" |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 31 | |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 32 | void local_bus_init(void); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 33 | |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 34 | int checkboard (void) |
| 35 | { |
Tom Rini | d5c3bf2 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 36 | volatile ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR); |
| 37 | volatile ccsr_local_ecm_t *ecm = (void *)(CFG_SYS_MPC85xx_ECM_ADDR); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 38 | |
| 39 | /* PCI slot in USER bits CSR[6:7] by convention. */ |
| 40 | uint pci_slot = get_pci_slot (); |
| 41 | |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 42 | uint cpu_board_rev = get_cpu_board_revision (); |
| 43 | |
chenhui zhao | e97171e | 2011-10-13 13:40:59 +0800 | [diff] [blame] | 44 | puts("Board: MPC8548CDS"); |
| 45 | printf(" Carrier Rev: 0x%02x, PCI Slot %d\n", |
| 46 | get_board_version(), pci_slot); |
| 47 | printf(" Daughtercard Rev: %d.%d (0x%04x)\n", |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 48 | MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev), |
| 49 | MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 50 | /* |
| 51 | * Initialize local bus. |
| 52 | */ |
| 53 | local_bus_init (); |
| 54 | |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 55 | /* |
| 56 | * Hack TSEC 3 and 4 IO voltages. |
| 57 | */ |
| 58 | gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */ |
| 59 | |
Ed Swarthout | 95ae0a0 | 2007-07-27 01:50:52 -0500 | [diff] [blame] | 60 | ecm->eedr = 0xffffffff; /* clear ecm errors */ |
| 61 | ecm->eeer = 0xffffffff; /* enable ecm errors */ |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 65 | /* |
| 66 | * Initialize Local Bus |
| 67 | */ |
| 68 | void |
| 69 | local_bus_init(void) |
| 70 | { |
Tom Rini | d5c3bf2 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 71 | volatile ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR); |
Becky Bruce | 0d4cee1 | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 72 | volatile fsl_lbc_t *lbc = LBC_BASE_ADDR; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 73 | |
| 74 | uint clkdiv; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 75 | sys_info_t sysinfo; |
| 76 | |
| 77 | get_sys_info(&sysinfo); |
Trent Piepho | 1b560ac | 2008-12-03 15:16:34 -0800 | [diff] [blame] | 78 | clkdiv = (lbc->lcrr & LCRR_CLKDIV) * 2; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 79 | |
| 80 | gur->lbiuiplldcr1 = 0x00078080; |
| 81 | if (clkdiv == 16) { |
| 82 | gur->lbiuiplldcr0 = 0x7c0f1bf0; |
| 83 | } else if (clkdiv == 8) { |
| 84 | gur->lbiuiplldcr0 = 0x6c0f1bf0; |
| 85 | } else if (clkdiv == 4) { |
| 86 | gur->lbiuiplldcr0 = 0x5c0f1bf0; |
| 87 | } |
| 88 | |
| 89 | lbc->lcrr |= 0x00030000; |
| 90 | |
| 91 | asm("sync;isync;msync"); |
Ed Swarthout | 95ae0a0 | 2007-07-27 01:50:52 -0500 | [diff] [blame] | 92 | |
| 93 | lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */ |
| 94 | lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */ |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Initialize SDRAM memory on the Local Bus. |
| 99 | */ |
Becky Bruce | b88d3d0 | 2010-12-17 17:17:57 -0600 | [diff] [blame] | 100 | void lbc_sdram_init(void) |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 101 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 102 | #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM) |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 103 | |
| 104 | uint idx; |
Becky Bruce | 0d4cee1 | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 105 | volatile fsl_lbc_t *lbc = LBC_BASE_ADDR; |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 106 | uint *sdram_addr = (uint *)CFG_SYS_LBC_SDRAM_BASE; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 107 | uint lsdmr_common; |
| 108 | |
Becky Bruce | 2d8ecac | 2010-12-17 17:17:59 -0600 | [diff] [blame] | 109 | puts("LBC SDRAM: "); |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 110 | print_size(CFG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, |
chenhui zhao | 33b53e4 | 2011-09-06 16:41:14 +0000 | [diff] [blame] | 111 | "\n"); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * Setup SDRAM Base and Option Registers |
| 115 | */ |
Becky Bruce | 0d4cee1 | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 116 | set_lbc_or(2, CONFIG_SYS_OR2_PRELIM); |
| 117 | set_lbc_br(2, CONFIG_SYS_BR2_PRELIM); |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 118 | lbc->lbcr = CFG_SYS_LBC_LBCR; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 119 | asm("msync"); |
| 120 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 121 | lbc->lsrt = CFG_SYS_LBC_LSRT; |
| 122 | lbc->mrtpr = CFG_SYS_LBC_MRTPR; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 123 | asm("msync"); |
| 124 | |
| 125 | /* |
| 126 | * MPC8548 uses "new" 15-16 style addressing. |
| 127 | */ |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 128 | lsdmr_common = CFG_SYS_LBC_LSDMR_COMMON; |
Kumar Gala | 727c6a6 | 2009-03-26 01:34:38 -0500 | [diff] [blame] | 129 | lsdmr_common |= LSDMR_BSMA1516; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * Issue PRECHARGE ALL command. |
| 133 | */ |
Kumar Gala | 727c6a6 | 2009-03-26 01:34:38 -0500 | [diff] [blame] | 134 | lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 135 | asm("sync;msync"); |
| 136 | *sdram_addr = 0xff; |
| 137 | ppcDcbf((unsigned long) sdram_addr); |
| 138 | udelay(100); |
| 139 | |
| 140 | /* |
| 141 | * Issue 8 AUTO REFRESH commands. |
| 142 | */ |
| 143 | for (idx = 0; idx < 8; idx++) { |
Kumar Gala | 727c6a6 | 2009-03-26 01:34:38 -0500 | [diff] [blame] | 144 | lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 145 | asm("sync;msync"); |
| 146 | *sdram_addr = 0xff; |
| 147 | ppcDcbf((unsigned long) sdram_addr); |
| 148 | udelay(100); |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | * Issue 8 MODE-set command. |
| 153 | */ |
Kumar Gala | 727c6a6 | 2009-03-26 01:34:38 -0500 | [diff] [blame] | 154 | lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 155 | asm("sync;msync"); |
| 156 | *sdram_addr = 0xff; |
| 157 | ppcDcbf((unsigned long) sdram_addr); |
| 158 | udelay(100); |
| 159 | |
| 160 | /* |
| 161 | * Issue NORMAL OP command. |
| 162 | */ |
Kumar Gala | 727c6a6 | 2009-03-26 01:34:38 -0500 | [diff] [blame] | 163 | lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 164 | asm("sync;msync"); |
| 165 | *sdram_addr = 0xff; |
| 166 | ppcDcbf((unsigned long) sdram_addr); |
| 167 | udelay(200); /* Overkill. Must wait > 200 bus cycles */ |
| 168 | |
| 169 | #endif /* enable SDRAM init */ |
| 170 | } |