868589fdde150f3e9f728844a1d87ae7880d5995
1 /************************************************************************************
2 * FILE PURPOSE: C6474 Device Specific functions
3 ************************************************************************************
4 * FILE NAME: c6474.c
5 *
6 * DESCRIPTION: Implements the device specific functions for the IBL
7 *
8 * @file c6474.c
9 *
10 * @brief
11 * This file implements the device specific functions for the IBL
12 *
13 ************************************************************************************/
14 #include "ibl.h"
15 #include "device.h"
16 #include "pllapi.h"
17 #include "emif31api.h"
18 #include "pscapi.h"
19 #include "gpio.h"
20 #include <string.h>
22 extern cregister unsigned int DNUM;
25 /**
26 * @brief The default boot configuration table is filled in
27 *
28 * @details
29 * A default ibl configuraiton table is provided when one is not found
30 * preloaded.
31 */
32 void deviceLoadDefaultIblTable (void)
33 {
34 uint32 macA, macB;
36 #if 0 /* This is really the default. Switching to a direct tftp boot until I have a bootp server
37 * on a private lan for test */
38 ibl.ethConfig[0].ethPriority = ibl_LOWEST_PRIORITY;
39 ibl.ethConfig[0].port = 0;
40 ibl.ethConfig[0].doBootp = TRUE;
41 ibl.ethConfig[0].bootFormat = ibl_BOOT_FORMAT_AUTO;
43 memset (&ibl.ethConfig[0].ethInfo, 0, sizeof(ibl.ethConfig[0].ethInfo));
44 #endif
46 /* This is the temporary code */
47 ibl.ethConfig[0].ethPriority = ibl_LOWEST_PRIORITY;
48 ibl.ethConfig[0].port = 0;
49 ibl.ethConfig[0].doBootp = FALSE;
50 ibl.ethConfig[0].useBootpServerIp = FALSE;
51 ibl.ethConfig[0].useBootpFileName = FALSE;
52 ibl.ethConfig[0].bootFormat = ibl_BOOT_FORMAT_NAME;
54 memset (&ibl.ethConfig[0].ethInfo, 0, sizeof(ibl.ethConfig[0].ethInfo));
56 ibl.ethConfig[0].ethInfo.ipAddr[0] = 10;
57 ibl.ethConfig[0].ethInfo.ipAddr[1] = 218;
58 ibl.ethConfig[0].ethInfo.ipAddr[2] = 109;
59 ibl.ethConfig[0].ethInfo.ipAddr[3] = 21;
61 ibl.ethConfig[0].ethInfo.serverIp[0] = 10;
62 ibl.ethConfig[0].ethInfo.serverIp[1] = 218;
63 ibl.ethConfig[0].ethInfo.serverIp[2] = 109;
64 ibl.ethConfig[0].ethInfo.serverIp[3] = 196;
66 ibl.ethConfig[0].ethInfo.gatewayIp[0] = 10;
67 ibl.ethConfig[0].ethInfo.gatewayIp[1] = 218;
68 ibl.ethConfig[0].ethInfo.gatewayIp[2] = 109;
69 ibl.ethConfig[0].ethInfo.gatewayIp[3] = 1;
71 /* Leave hw address as 0 */
73 strcpy (ibl.ethConfig[0].ethInfo.fileName, "test2_little.out");
75 ibl.ethConfig[0].blob.startAddress = 0x00200000; /* Base address of SL2 */
76 ibl.ethConfig[0].blob.sizeBytes = 0x000c0000; /* All of SL2 */
77 ibl.ethConfig[0].blob.branchAddress = 0x00200000; /* Base of SL2 */
81 macA = *((uint32 *)0x2a80700);
82 macB = *((uint32 *)0x2a80704);
84 ibl.ethConfig[0].ethInfo.hwAddress[0] = (macA >> 24) & 0xff;
85 ibl.ethConfig[0].ethInfo.hwAddress[1] = (macA >> 16) & 0xff;
86 ibl.ethConfig[0].ethInfo.hwAddress[2] = (macA >> 8) & 0xff;
87 ibl.ethConfig[0].ethInfo.hwAddress[3] = (macA >> 0) & 0xff;
88 ibl.ethConfig[0].ethInfo.hwAddress[4] = (macB >> 24) & 0xff;
89 ibl.ethConfig[0].ethInfo.hwAddress[5] = (macB >> 16) & 0xff;
92 ibl.ethConfig[1].ethPriority = ibl_DEVICE_NOBOOT;
95 /* MDIO configuration */
96 ibl.mdioConfig.nMdioOps = 8;
97 ibl.mdioConfig.mdioClkDiv = 0x20;
98 ibl.mdioConfig.interDelay = 1400; /* ~2ms at 700 MHz */
100 ibl.mdioConfig.mdio[0] = (1 << 30) | (27 << 21) | (24 << 16) | 0x848b;
101 ibl.mdioConfig.mdio[1] = (1 << 30) | (20 << 21) | (24 << 16) | 0x0ce0;
102 ibl.mdioConfig.mdio[2] = (1 << 30) | (24 << 21) | (24 << 16) | 0x4101;
103 ibl.mdioConfig.mdio[3] = (1 << 30) | ( 0 << 21) | (24 << 16) | 0x9140;
105 ibl.mdioConfig.mdio[4] = (1 << 30) | (27 << 21) | (25 << 16) | 0x848b;
106 ibl.mdioConfig.mdio[5] = (1 << 30) | (20 << 21) | (25 << 16) | 0x0ce0;
107 ibl.mdioConfig.mdio[6] = (1 << 30) | (24 << 21) | (25 << 16) | 0x4101;
108 ibl.mdioConfig.mdio[7] = (1 << 30) | ( 0 << 21) | (25 << 16) | 0x9140;
111 /* Main Pll configuration */
112 ibl.pllConfig[ibl_MAIN_PLL].doEnable = TRUE;
113 ibl.pllConfig[ibl_MAIN_PLL].prediv = 1;
114 ibl.pllConfig[ibl_MAIN_PLL].mult = 28;
115 ibl.pllConfig[ibl_MAIN_PLL].postdiv = 1;
117 ibl.pllConfig[ibl_MAIN_PLL].pllOutFreqMhz = 500;
119 /* The DDR PLL. The multipliers/dividers are fixed, so are really dont cares */
120 ibl.pllConfig[ibl_DDR_PLL].doEnable = TRUE;
122 /* The network PLL. The multipliers/dividers are fixed */
123 ibl.pllConfig[ibl_NET_PLL].doEnable = TRUE;
125 /* EMIF configuration */
126 ibl.ddrConfig.uEmif.emif3p1.sdcfg = 0x00538832; /* timing, 32bit wide */
127 ibl.ddrConfig.uEmif.emif3p1.sdrfc = 0x0000073B; /* Refresh 533Mhz */
128 ibl.ddrConfig.uEmif.emif3p1.sdtim1 = 0x47245BD2; /* Timing 1 */
129 ibl.ddrConfig.uEmif.emif3p1.sdtim2 = 0x0125DC44; /* Timing 2 */
130 ibl.ddrConfig.uEmif.emif3p1.dmcctl = 0x50001906; /* PHY read latency for CAS 5 is 5 + 2 - 1 */
133 /* NAND configuration for the MT29F1G08 flash */
134 ibl.nandConfig.nandPriority = ibl_HIGHEST_PRIORITY;
135 ibl.nandConfig.bootFormat = ibl_BOOT_FORMAT_COFF;
137 ibl.nandConfig.nandInfo.busWidthBits = 8;
138 ibl.nandConfig.nandInfo.pageSizeBytes = 2048;
139 ibl.nandConfig.nandInfo.pageEccBytes = 64;
140 ibl.nandConfig.nandInfo.pagesPerBlock = 64;
141 ibl.nandConfig.nandInfo.totalBlocks = 1024;
143 ibl.nandConfig.nandInfo.addressBytes = 4;
144 ibl.nandConfig.nandInfo.lsbFirst = TRUE;
145 ibl.nandConfig.nandInfo.blockOffset = 22;
146 ibl.nandConfig.nandInfo.pageOffset = 16;
147 ibl.nandConfig.nandInfo.columnOffset = 0;
149 ibl.nandConfig.nandInfo.resetCommand = 0xff;
150 ibl.nandConfig.nandInfo.readCommandPre = 0;
151 ibl.nandConfig.nandInfo.readCommandPost = 0x30;
152 ibl.nandConfig.nandInfo.postCommand = TRUE;
155 }
157 /**
158 * @brief Determine if an address is local
159 *
160 * @details
161 * Examines an input address to determine if it is a local address
162 */
163 bool address_is_local (Uint32 addr)
164 {
165 /* L2 */
166 if ((addr >= 0x00800000) && (addr < 0x00898000))
167 return (TRUE);
169 /* L1P */
170 if ((addr >= 0x00e00000) && (addr < 0x00e08000))
171 return (TRUE);
173 /* L2D */
174 if ((addr >= 0x00f00000) && (addr < 0x00f08000))
175 return (TRUE);
177 return (FALSE);
179 }
182 /**
183 * @brief Convert a local l1d, l1p or l2 address to a global address
184 *
185 * @details
186 * The global address is formed. If the address is not local then
187 * the input address is returned
188 */
189 Uint32 deviceLocalAddrToGlobal (Uint32 addr)
190 {
192 if (address_is_local (addr))
193 addr = (1 << 28) | (DNUM << 24) | addr;
195 return (addr);
197 }
200 /**
201 * @brief Configure the PLLs
202 *
203 * @details
204 * Only the main PLL can be configured here. The DDR pll is enabled by default,
205 * and the network PLL is enabled through serdes configuration.
206 * the multiplier and dividers.
207 */
208 void devicePllConfig (void)
209 {
210 if (ibl.pllConfig[ibl_MAIN_PLL].doEnable == TRUE)
211 hwPllSetPll (MAIN_PLL,
212 ibl.pllConfig[ibl_MAIN_PLL].prediv,
213 ibl.pllConfig[ibl_MAIN_PLL].mult,
214 ibl.pllConfig[ibl_MAIN_PLL].postdiv);
216 }
218 /**
219 * @brief
220 * Enable the DDR
221 *
222 * @details
223 * The DDR controller on the c6474 is an emif 3.1. The controller is
224 * initialized directly with the supplied values
225 */
226 void deviceDdrConfig (void)
227 {
228 if (ibl.ddrConfig.configDdr != 0)
229 hwEmif3p1Enable (&ibl.ddrConfig.uEmif.emif3p1);
231 }
234 /**
235 * @brief Power up a peripheral
236 *
237 * @details
238 * Boot peripherals are powered up
239 */
240 int32 devicePowerPeriph (int32 modNum)
241 {
242 /* If the input value is < 0 there is nothing to power up */
243 if (modNum < 0)
244 return (0);
247 if (modNum >= TARGET_PWR_MAX_MOD)
248 return (-1);
250 return ((int32)pscEnableModule(modNum));
252 }
255 /**
256 * @brief Enable the pass through version of the nand controller
257 *
258 * @details On the evm the nand controller is enabled by setting
259 * gpio 14 high
260 */
261 int32 deviceConfigureForNand(void)
262 {
263 hwGpioSetDirection(NAND_MODE_GPIO, GPIO_OUT);
264 hwGpioSetOutput(NAND_MODE_GPIO);
265 return (0);
267 }
270 /**
271 * @brief
272 * The e-fuse mac address is loaded
273 */
274 void deviceLoadDefaultEthAddress (uint8 *maddr)
275 {
276 uint32 macA, macB;
278 /* Read the e-fuse mac address */
279 macA = *((uint32 *)0x2880834);
280 macB = *((uint32 *)0x2880838);
282 maddr[0] = (macB >> 8) & 0xff;
283 maddr[1] = (macB >> 0) & 0xff;
284 maddr[2] = (macA >> 24) & 0xff;
285 maddr[3] = (macA >> 16) & 0xff;
286 maddr[4] = (macA >> 8) & 0xff;
287 maddr[5] = (macA >> 0) & 0xff;
288 }