blob: 73e024eaa0118c069b84f19eac66c5ac2a3c2468 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jon Loeligerd9b94f22005-07-25 14:05:07 -05002/*
Zhao Chenhuib813cbe2011-08-24 13:20:04 +08003 * Copyright 2004, 2007, 2009-2011 Freescale Semiconductor, Inc.
Jon Loeligerd9b94f22005-07-25 14:05:07 -05004 *
5 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
Jon Loeligerd9b94f22005-07-25 14:05:07 -05006 */
7
8#include <common.h>
Simon Glass4e4bf942022-07-31 12:28:48 -06009#include <display_options.h>
Simon Glass2cf431c2019-11-14 12:57:47 -070010#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -060011#include <net.h>
Jon Loeligerd9b94f22005-07-25 14:05:07 -050012#include <pci.h>
Simon Glass2189d5f2019-11-14 12:57:20 -070013#include <vsprintf.h>
Jon Loeligerd9b94f22005-07-25 14:05:07 -050014#include <asm/processor.h>
Jon Loeligere31d2c12008-03-18 13:51:06 -050015#include <asm/mmu.h>
Jon Loeligerd9b94f22005-07-25 14:05:07 -050016#include <asm/immap_85xx.h>
Kumar Galac8514622009-04-02 13:22:48 -050017#include <asm/fsl_pci.h>
York Sun5614e712013-09-30 09:22:09 -070018#include <fsl_ddr_sdram.h>
Kumar Gala5d27e022010-12-15 04:55:20 -060019#include <asm/fsl_serdes.h>
Andy Fleming09f3e092006-09-13 10:34:18 -050020#include <miiphy.h>
Simon Glassc05ed002020-05-10 11:40:11 -060021#include <linux/delay.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090022#include <linux/libfdt.h>
Kumar Galab90d2542007-11-29 00:11:44 -060023#include <fdt_support.h>
chenhui zhaod3701222011-09-06 16:41:18 +000024#include <tsec.h>
25#include <fsl_mdio.h>
26#include <netdev.h>
Jon Loeligerd9b94f22005-07-25 14:05:07 -050027
28#include "../common/cadmus.h"
29#include "../common/eeprom.h"
Matthew McClintockbf1dfff2006-06-28 10:46:13 -050030#include "../common/via.h"
Jon Loeligerd9b94f22005-07-25 14:05:07 -050031
Jon Loeligerd9b94f22005-07-25 14:05:07 -050032void local_bus_init(void);
Jon Loeligerd9b94f22005-07-25 14:05:07 -050033
Jon Loeligerd9b94f22005-07-25 14:05:07 -050034int checkboard (void)
35{
Tom Rini51552072022-10-28 20:27:12 -040036 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 Loeligerd9b94f22005-07-25 14:05:07 -050038
39 /* PCI slot in USER bits CSR[6:7] by convention. */
40 uint pci_slot = get_pci_slot ();
41
Jon Loeligerd9b94f22005-07-25 14:05:07 -050042 uint cpu_board_rev = get_cpu_board_revision ();
43
chenhui zhaofff80972011-10-13 13:40:59 +080044 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 Loeligerd9b94f22005-07-25 14:05:07 -050048 MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
49 MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
Jon Loeligerd9b94f22005-07-25 14:05:07 -050050 /*
51 * Initialize local bus.
52 */
53 local_bus_init ();
54
Jon Loeligerd9b94f22005-07-25 14:05:07 -050055 /*
56 * Hack TSEC 3 and 4 IO voltages.
57 */
58 gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */
59
Ed Swarthoutf2cff6b2007-07-27 01:50:52 -050060 ecm->eedr = 0xffffffff; /* clear ecm errors */
61 ecm->eeer = 0xffffffff; /* enable ecm errors */
Jon Loeligerd9b94f22005-07-25 14:05:07 -050062 return 0;
63}
64
Jon Loeligerd9b94f22005-07-25 14:05:07 -050065/*
66 * Initialize Local Bus
67 */
68void
69local_bus_init(void)
70{
Tom Rini51552072022-10-28 20:27:12 -040071 volatile ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Becky Brucef51cdaf2010-06-17 11:37:20 -050072 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
Jon Loeligerd9b94f22005-07-25 14:05:07 -050073
74 uint clkdiv;
Jon Loeligerd9b94f22005-07-25 14:05:07 -050075 sys_info_t sysinfo;
76
77 get_sys_info(&sysinfo);
Trent Piephoa5d212a2008-12-03 15:16:34 -080078 clkdiv = (lbc->lcrr & LCRR_CLKDIV) * 2;
Jon Loeligerd9b94f22005-07-25 14:05:07 -050079
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 Swarthoutf2cff6b2007-07-27 01:50:52 -050092
93 lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
94 lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
Jon Loeligerd9b94f22005-07-25 14:05:07 -050095}
96
97/*
98 * Initialize SDRAM memory on the Local Bus.
99 */
Becky Bruce70961ba2010-12-17 17:17:57 -0600100void lbc_sdram_init(void)
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500101{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200102#if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500103
104 uint idx;
Becky Brucef51cdaf2010-06-17 11:37:20 -0500105 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
Tom Rini65cc0e22022-11-16 13:10:41 -0500106 uint *sdram_addr = (uint *)CFG_SYS_LBC_SDRAM_BASE;
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500107 uint lsdmr_common;
108
Becky Bruce7ea38712010-12-17 17:17:59 -0600109 puts("LBC SDRAM: ");
Tom Rini65cc0e22022-11-16 13:10:41 -0500110 print_size(CFG_SYS_LBC_SDRAM_SIZE * 1024 * 1024,
chenhui zhaoa6d0bfa2011-09-06 16:41:14 +0000111 "\n");
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500112
113 /*
114 * Setup SDRAM Base and Option Registers
115 */
Becky Brucef51cdaf2010-06-17 11:37:20 -0500116 set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
117 set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
Tom Rini65cc0e22022-11-16 13:10:41 -0500118 lbc->lbcr = CFG_SYS_LBC_LBCR;
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500119 asm("msync");
120
Tom Rini65cc0e22022-11-16 13:10:41 -0500121 lbc->lsrt = CFG_SYS_LBC_LSRT;
122 lbc->mrtpr = CFG_SYS_LBC_MRTPR;
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500123 asm("msync");
124
125 /*
126 * MPC8548 uses "new" 15-16 style addressing.
127 */
Tom Rini65cc0e22022-11-16 13:10:41 -0500128 lsdmr_common = CFG_SYS_LBC_LSDMR_COMMON;
Kumar Galab0fe93ed2009-03-26 01:34:38 -0500129 lsdmr_common |= LSDMR_BSMA1516;
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500130
131 /*
132 * Issue PRECHARGE ALL command.
133 */
Kumar Galab0fe93ed2009-03-26 01:34:38 -0500134 lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500135 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 Galab0fe93ed2009-03-26 01:34:38 -0500144 lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500145 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 Galab0fe93ed2009-03-26 01:34:38 -0500154 lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500155 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 Galab0fe93ed2009-03-26 01:34:38 -0500163 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500164 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}
171
Tom Rinia34f9712022-08-02 07:33:39 -0400172#ifndef CONFIG_DM_ETH
173static void configure_rgmii(void)
Andy Fleming09f3e092006-09-13 10:34:18 -0500174{
Jon Loeligerf5012822006-10-20 15:54:34 -0500175 unsigned short temp;
Andy Fleming09f3e092006-09-13 10:34:18 -0500176
177 /* Change the resistors for the PHY */
178 /* This is needed to get the RGMII working for the 1.3+
179 * CDS cards */
180 if (get_board_version() == 0x13) {
chenhui zhaod3701222011-09-06 16:41:18 +0000181 miiphy_write(DEFAULT_MII_NAME,
Andy Fleming09f3e092006-09-13 10:34:18 -0500182 TSEC1_PHY_ADDR, 29, 18);
183
chenhui zhaod3701222011-09-06 16:41:18 +0000184 miiphy_read(DEFAULT_MII_NAME,
Andy Fleming09f3e092006-09-13 10:34:18 -0500185 TSEC1_PHY_ADDR, 30, &temp);
186
187 temp = (temp & 0xf03f);
188 temp |= 2 << 9; /* 36 ohm */
189 temp |= 2 << 6; /* 39 ohm */
190
chenhui zhaod3701222011-09-06 16:41:18 +0000191 miiphy_write(DEFAULT_MII_NAME,
Andy Fleming09f3e092006-09-13 10:34:18 -0500192 TSEC1_PHY_ADDR, 30, temp);
193
chenhui zhaod3701222011-09-06 16:41:18 +0000194 miiphy_write(DEFAULT_MII_NAME,
Andy Fleming09f3e092006-09-13 10:34:18 -0500195 TSEC1_PHY_ADDR, 29, 3);
196
chenhui zhaod3701222011-09-06 16:41:18 +0000197 miiphy_write(DEFAULT_MII_NAME,
Andy Fleming09f3e092006-09-13 10:34:18 -0500198 TSEC1_PHY_ADDR, 30, 0x8000);
199 }
200
chenhui zhaod3701222011-09-06 16:41:18 +0000201 return;
Andy Fleming09f3e092006-09-13 10:34:18 -0500202}
Ed Swarthoutf2cff6b2007-07-27 01:50:52 -0500203
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900204int board_eth_init(struct bd_info *bis)
chenhui zhaod3701222011-09-06 16:41:18 +0000205{
Bin Meng1adc0952016-01-11 22:41:15 -0800206#ifdef CONFIG_TSEC_ENET
chenhui zhaod3701222011-09-06 16:41:18 +0000207 struct fsl_pq_mdio_info mdio_info;
208 struct tsec_info_struct tsec_info[4];
209 int num = 0;
210
211#ifdef CONFIG_TSEC1
212 SET_STD_TSEC_INFO(tsec_info[num], 1);
213 num++;
214#endif
215#ifdef CONFIG_TSEC2
216 SET_STD_TSEC_INFO(tsec_info[num], 2);
217 num++;
218#endif
219#ifdef CONFIG_TSEC3
220 /* initialize TSEC3 only if Carrier is 1.3 or above on CDS */
221 if (get_board_version() >= 0x13) {
222 SET_STD_TSEC_INFO(tsec_info[num], 3);
223 tsec_info[num].interface = PHY_INTERFACE_MODE_RGMII_ID;
224 num++;
225 }
226#endif
227#ifdef CONFIG_TSEC4
228 /* initialize TSEC4 only if Carrier is 1.3 or above on CDS */
229 if (get_board_version() >= 0x13) {
230 SET_STD_TSEC_INFO(tsec_info[num], 4);
231 tsec_info[num].interface = PHY_INTERFACE_MODE_RGMII_ID;
232 num++;
233 }
234#endif
235
236 if (!num) {
237 printf("No TSECs initialized\n");
238
239 return 0;
240 }
241
242 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
243 mdio_info.name = DEFAULT_MII_NAME;
244 fsl_pq_mdio_init(bis, &mdio_info);
245
246 tsec_eth_init(bis, tsec_info, num);
247 configure_rgmii();
Bin Meng1adc0952016-01-11 22:41:15 -0800248#endif
chenhui zhaod3701222011-09-06 16:41:18 +0000249
250 return pci_eth_init(bis);
251}
Tom Rinia34f9712022-08-02 07:33:39 -0400252#endif