wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Custom IDEAS, Inc. <www.cideas.com> |
| 4 | * Gerald Van Baren <vanbaren@cideas.com> |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 25 | #include <common.h> |
Wolfgang Denk | 20a5f78 | 2008-07-03 22:34:08 +0200 | [diff] [blame] | 26 | #include <asm/u-boot.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 27 | #include <ioports.h> |
| 28 | #include <mpc8260.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 29 | #include <i2c.h> |
| 30 | #include <spi.h> |
wdenk | 1f197c6 | 2003-09-15 18:00:00 +0000 | [diff] [blame] | 31 | #include <command.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 32 | |
| 33 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 34 | #include <status_led.h> |
| 35 | #endif |
| 36 | |
wdenk | 1f197c6 | 2003-09-15 18:00:00 +0000 | [diff] [blame] | 37 | #ifdef CONFIG_ETHER_LOOPBACK_TEST |
| 38 | extern void eth_loopback_test(void); |
| 39 | #endif /* CONFIG_ETHER_LOOPBACK_TEST */ |
| 40 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 41 | #include "clkinit.h" |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 42 | #include "ioconfig.h" /* I/O configuration table */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * PBI Page Based Interleaving |
| 46 | * PSDMR_PBI page based interleaving |
| 47 | * 0 bank based interleaving |
| 48 | * External Address Multiplexing (EAMUX) adds a clock to address cycles |
| 49 | * (this can help with marginal board layouts) |
| 50 | * PSDMR_EAMUX adds a clock |
| 51 | * 0 no extra clock |
| 52 | * Buffer Command (BUFCMD) adds a clock to command cycles. |
| 53 | * PSDMR_BUFCMD adds a clock |
| 54 | * 0 no extra clock |
| 55 | */ |
| 56 | #define CONFIG_PBI PSDMR_PBI |
| 57 | #define PESSIMISTIC_SDRAM 0 |
| 58 | #define EAMUX 0 /* EST requires EAMUX */ |
| 59 | #define BUFCMD 0 |
| 60 | |
| 61 | /* |
| 62 | * ADC/DAC Defines: |
| 63 | */ |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 64 | #define INITIAL_SAMPLE_RATE 10016 /* Initial Daq sample rate */ |
| 65 | #define INITIAL_RIGHT_JUST 0 /* Initial DAC right justification */ |
| 66 | #define INITIAL_MCLK_DIVIDE 0 /* Initial MCLK Divide */ |
| 67 | #define INITIAL_SAMPLE_64X 1 /* Initial 64x clocking mode */ |
| 68 | #define INITIAL_SAMPLE_128X 0 /* Initial 128x clocking mode */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 69 | |
| 70 | /* |
| 71 | * ADC Defines: |
| 72 | */ |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 73 | #define I2C_ADC_1_ADDR 0x0E /* I2C Address of the ADC #1 */ |
| 74 | #define I2C_ADC_2_ADDR 0x0F /* I2C Address of the ADC #2 */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 75 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 76 | #define ADC_SDATA1_MASK 0x00020000 /* PA14 - CH12SDATA_PU */ |
| 77 | #define ADC_SDATA2_MASK 0x00010000 /* PA15 - CH34SDATA_PU */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 78 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 79 | #define ADC_VREF_CAP 100 /* VREF capacitor in uF */ |
| 80 | #define ADC_INITIAL_DELAY (10 * ADC_VREF_CAP) /* 10 usec per uF, in usec */ |
| 81 | #define ADC_SDATA_DELAY 100 /* ADC SDATA release delay in usec */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 82 | #define ADC_CAL_DELAY (1000000 / INITIAL_SAMPLE_RATE * 4500) |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 83 | /* Wait at least 4100 LRCLK's */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 84 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 85 | #define ADC_REG1_FRAME_START 0x80 /* Frame start */ |
| 86 | #define ADC_REG1_GROUND_CAL 0x40 /* Ground calibration enable */ |
| 87 | #define ADC_REG1_ANA_MOD_PDOWN 0x20 /* Analog modulator section in power down */ |
| 88 | #define ADC_REG1_DIG_MOD_PDOWN 0x10 /* Digital modulator section in power down */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 89 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 90 | #define ADC_REG2_128x 0x80 /* Oversample at 128x */ |
| 91 | #define ADC_REG2_CAL 0x40 /* System calibration enable */ |
| 92 | #define ADC_REG2_CHANGE_SIGN 0x20 /* Change sign enable */ |
| 93 | #define ADC_REG2_LR_DISABLE 0x10 /* Left/Right output disable */ |
| 94 | #define ADC_REG2_HIGH_PASS_DIS 0x08 /* High pass filter disable */ |
| 95 | #define ADC_REG2_SLAVE_MODE 0x04 /* Slave mode */ |
| 96 | #define ADC_REG2_DFS 0x02 /* Digital format select */ |
| 97 | #define ADC_REG2_MUTE 0x01 /* Mute */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 98 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 99 | #define ADC_REG7_ADDR_ENABLE 0x80 /* Address enable */ |
| 100 | #define ADC_REG7_PEAK_ENABLE 0x40 /* Peak enable */ |
| 101 | #define ADC_REG7_PEAK_UPDATE 0x20 /* Peak update */ |
| 102 | #define ADC_REG7_PEAK_FORMAT 0x10 /* Peak display format */ |
| 103 | #define ADC_REG7_DIG_FILT_PDOWN 0x04 /* Digital filter power down enable */ |
| 104 | #define ADC_REG7_FIR2_IN_EN 0x02 /* External FIR2 input enable */ |
| 105 | #define ADC_REG7_PSYCHO_EN 0x01 /* External pyscho filter input enable */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * DAC Defines: |
| 109 | */ |
| 110 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 111 | #define I2C_DAC_ADDR 0x11 /* I2C Address of the DAC */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 112 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 113 | #define DAC_RST_MASK 0x00008000 /* PA16 - DAC_RST* */ |
| 114 | #define DAC_RESET_DELAY 100 /* DAC reset delay in usec */ |
| 115 | #define DAC_INITIAL_DELAY 5000 /* DAC initialization delay in usec */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 116 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 117 | #define DAC_REG1_AMUTE 0x80 /* Auto-mute */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 118 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 119 | #define DAC_REG1_LEFT_JUST_24_BIT (0 << 4) /* Fmt 0: Left justified 24 bit */ |
| 120 | #define DAC_REG1_I2S_24_BIT (1 << 4) /* Fmt 1: I2S up to 24 bit */ |
| 121 | #define DAC_REG1_RIGHT_JUST_16BIT (2 << 4) /* Fmt 2: Right justified 16 bit */ |
| 122 | #define DAC_REG1_RIGHT_JUST_24BIT (3 << 4) /* Fmt 3: Right justified 24 bit */ |
| 123 | #define DAC_REG1_RIGHT_JUST_20BIT (4 << 4) /* Fmt 4: Right justified 20 bit */ |
| 124 | #define DAC_REG1_RIGHT_JUST_18BIT (5 << 4) /* Fmt 5: Right justified 18 bit */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 125 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 126 | #define DAC_REG1_DEM_NO (0 << 2) /* No De-emphasis */ |
| 127 | #define DAC_REG1_DEM_44KHZ (1 << 2) /* 44.1KHz De-emphasis */ |
| 128 | #define DAC_REG1_DEM_48KHZ (2 << 2) /* 48KHz De-emphasis */ |
| 129 | #define DAC_REG1_DEM_32KHZ (3 << 2) /* 32KHz De-emphasis */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 130 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 131 | #define DAC_REG1_SINGLE 0 /* 4- 50KHz sample rate */ |
| 132 | #define DAC_REG1_DOUBLE 1 /* 50-100KHz sample rate */ |
| 133 | #define DAC_REG1_QUAD 2 /* 100-200KHz sample rate */ |
| 134 | #define DAC_REG1_DSD 3 /* Direct Stream Data, DSD */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 135 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 136 | #define DAC_REG5_INVERT_A 0x80 /* Invert channel A */ |
| 137 | #define DAC_REG5_INVERT_B 0x40 /* Invert channel B */ |
| 138 | #define DAC_REG5_I2C_MODE 0x20 /* Control port (I2C) mode */ |
| 139 | #define DAC_REG5_POWER_DOWN 0x10 /* Power down mode */ |
| 140 | #define DAC_REG5_MUTEC_A_B 0x08 /* Mutec A=B */ |
| 141 | #define DAC_REG5_FREEZE 0x04 /* Freeze */ |
| 142 | #define DAC_REG5_MCLK_DIV 0x02 /* MCLK divide by 2 */ |
| 143 | #define DAC_REG5_RESERVED 0x01 /* Reserved */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * Check Board Identity: |
| 147 | */ |
| 148 | |
| 149 | int checkboard(void) |
| 150 | { |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 151 | printf("SACSng\n"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 152 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 153 | return 0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 156 | phys_size_t initdram(int board_type) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 157 | { |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 158 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
| 159 | volatile memctl8260_t *memctl = &immap->im_memctl; |
| 160 | volatile uchar c = 0; |
| 161 | volatile uchar *ramaddr = (uchar *)(CONFIG_SYS_SDRAM_BASE + 0x8); |
| 162 | uint psdmr = CONFIG_SYS_PSDMR; |
| 163 | int i; |
| 164 | uint psrt = 14; /* for no SPD */ |
| 165 | uint chipselects = 1; /* for no SPD */ |
| 166 | uint sdram_size = CONFIG_SYS_SDRAM0_SIZE * 1024 * 1024; /* for no SPD */ |
| 167 | uint or = CONFIG_SYS_OR2_PRELIM; /* for no SPD */ |
| 168 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 169 | #ifdef SDRAM_SPD_ADDR |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 170 | uint data_width; |
| 171 | uint rows; |
| 172 | uint banks; |
| 173 | uint cols; |
| 174 | uint caslatency; |
| 175 | uint width; |
| 176 | uint rowst; |
| 177 | uint sdam; |
| 178 | uint bsma; |
| 179 | uint sda10; |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 180 | u_char data; |
| 181 | u_char cksum; |
| 182 | int j; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 183 | #endif |
| 184 | |
| 185 | #ifdef SDRAM_SPD_ADDR |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 186 | /* Keep the compiler from complaining about potentially uninitialized vars */ |
| 187 | data_width = chipselects = rows = banks = cols = caslatency = psrt = |
| 188 | 0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 189 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 190 | /* |
| 191 | * Read the SDRAM SPD EEPROM via I2C. |
| 192 | */ |
| 193 | i2c_read(SDRAM_SPD_ADDR, 0, 1, &data, 1); |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 194 | cksum = data; |
| 195 | for (j = 1; j < 64; j++) { /* read only the checksummed bytes */ |
| 196 | /* note: the I2C address autoincrements when alen == 0 */ |
| 197 | i2c_read(SDRAM_SPD_ADDR, 0, 0, &data, 1); |
| 198 | if (j == 5) |
| 199 | chipselects = data & 0x0F; |
| 200 | else if (j == 6) |
| 201 | data_width = data; |
| 202 | else if (j == 7) |
| 203 | data_width |= data << 8; |
| 204 | else if (j == 3) |
| 205 | rows = data & 0x0F; |
| 206 | else if (j == 4) |
| 207 | cols = data & 0x0F; |
| 208 | else if (j == 12) { |
| 209 | /* |
| 210 | * Refresh rate: this assumes the prescaler is set to |
| 211 | * approximately 1uSec per tick. |
| 212 | */ |
| 213 | switch (data & 0x7F) { |
| 214 | default: |
| 215 | case 0: |
| 216 | psrt = 14; /* 15.625uS */ |
| 217 | break; |
| 218 | case 1: |
| 219 | psrt = 2; /* 3.9uS */ |
| 220 | break; |
| 221 | case 2: |
| 222 | psrt = 6; /* 7.8uS */ |
| 223 | break; |
| 224 | case 3: |
| 225 | psrt = 29; /* 31.3uS */ |
| 226 | break; |
| 227 | case 4: |
| 228 | psrt = 60; /* 62.5uS */ |
| 229 | break; |
| 230 | case 5: |
| 231 | psrt = 120; /* 125uS */ |
| 232 | break; |
| 233 | } |
| 234 | } else if (j == 17) |
| 235 | banks = data; |
| 236 | else if (j == 18) { |
| 237 | caslatency = 3; /* default CL */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 238 | #if(PESSIMISTIC_SDRAM) |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 239 | if ((data & 0x04) != 0) |
| 240 | caslatency = 3; |
| 241 | else if ((data & 0x02) != 0) |
| 242 | caslatency = 2; |
| 243 | else if ((data & 0x01) != 0) |
| 244 | caslatency = 1; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 245 | #else |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 246 | if ((data & 0x01) != 0) |
| 247 | caslatency = 1; |
| 248 | else if ((data & 0x02) != 0) |
| 249 | caslatency = 2; |
| 250 | else if ((data & 0x04) != 0) |
| 251 | caslatency = 3; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 252 | #endif |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 253 | else { |
| 254 | printf("WARNING: Unknown CAS latency 0x%02X, using 3\n", data); |
| 255 | } |
| 256 | } else if (j == 63) { |
| 257 | if (data != cksum) { |
| 258 | printf("WARNING: Configuration data checksum failure:" " is 0x%02x, calculated 0x%02x\n", data, cksum); |
| 259 | } |
| 260 | } |
| 261 | cksum += data; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 262 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 263 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 264 | /* We don't trust CL less than 2 (only saw it on an old 16MByte DIMM) */ |
| 265 | if (caslatency < 2) { |
| 266 | printf("WARNING: CL was %d, forcing to 2\n", caslatency); |
| 267 | caslatency = 2; |
| 268 | } |
| 269 | if (rows > 14) { |
| 270 | printf("WARNING: This doesn't look good, rows = %d, should be <= 14\n", |
| 271 | rows); |
| 272 | rows = 14; |
| 273 | } |
| 274 | if (cols > 11) { |
| 275 | printf("WARNING: This doesn't look good, columns = %d, should be <= 11\n", |
| 276 | cols); |
| 277 | cols = 11; |
| 278 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 279 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 280 | if ((data_width != 64) && (data_width != 72)) { |
| 281 | printf("WARNING: SDRAM width unsupported, is %d, expected 64 or 72.\n", |
| 282 | data_width); |
| 283 | } |
| 284 | width = 3; /* 2^3 = 8 bytes = 64 bits wide */ |
| 285 | /* |
| 286 | * Convert banks into log2(banks) |
| 287 | */ |
| 288 | if (banks == 2) |
| 289 | banks = 1; |
| 290 | else if (banks == 4) |
| 291 | banks = 2; |
| 292 | else if (banks == 8) |
| 293 | banks = 3; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 294 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 295 | sdram_size = 1 << (rows + cols + banks + width); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 296 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 297 | #if(CONFIG_PBI == 0) /* bank-based interleaving */ |
| 298 | rowst = ((32 - 6) - (rows + cols + width)) * 2; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 299 | #else |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 300 | rowst = 32 - (rows + banks + cols + width); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 301 | #endif |
| 302 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 303 | or = ~(sdram_size - 1) | /* SDAM address mask */ |
| 304 | ((banks - 1) << 13) | /* banks per device */ |
| 305 | (rowst << 9) | /* rowst */ |
| 306 | ((rows - 9) << 6); /* numr */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 307 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 308 | memctl->memc_or2 = or; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 309 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 310 | /* |
| 311 | * SDAM specifies the number of columns that are multiplexed |
| 312 | * (reference AN2165/D), defined to be (columns - 6) for page |
| 313 | * interleave, (columns - 8) for bank interleave. |
| 314 | * |
| 315 | * BSMA is 14 - max(rows, cols). The bank select lines come |
| 316 | * into play above the highest "address" line going into the |
| 317 | * the SDRAM. |
| 318 | */ |
| 319 | #if(CONFIG_PBI == 0) /* bank-based interleaving */ |
| 320 | sdam = cols - 8; |
| 321 | bsma = ((31 - width) - 14) - ((rows > cols) ? rows : cols); |
| 322 | sda10 = sdam + 2; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 323 | #else |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 324 | sdam = cols - 6; |
| 325 | bsma = ((31 - width) - 14) - ((rows > cols) ? rows : cols); |
| 326 | sda10 = sdam; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 327 | #endif |
| 328 | #if(PESSIMISTIC_SDRAM) |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 329 | psdmr = (CONFIG_PBI | PSDMR_RFEN | PSDMR_RFRC_16_CLK | |
| 330 | PSDMR_PRETOACT_8W | PSDMR_ACTTORW_8W | PSDMR_WRC_4C | |
| 331 | PSDMR_EAMUX | PSDMR_BUFCMD) | caslatency | |
| 332 | ((caslatency - 1) << 6) | /* LDOTOPRE is CL - 1 */ |
| 333 | (sdam << 24) | (bsma << 21) | (sda10 << 18); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 334 | #else |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 335 | psdmr = (CONFIG_PBI | PSDMR_RFEN | PSDMR_RFRC_7_CLK | |
| 336 | PSDMR_PRETOACT_3W | /* 1 for 7E parts (fast PC-133) */ |
| 337 | PSDMR_ACTTORW_2W | /* 1 for 7E parts (fast PC-133) */ |
| 338 | PSDMR_WRC_1C | /* 1 clock + 7nSec */ |
| 339 | EAMUX | BUFCMD) | |
| 340 | caslatency | ((caslatency - 1) << 6) | /* LDOTOPRE is CL - 1 */ |
| 341 | (sdam << 24) | (bsma << 21) | (sda10 << 18); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 342 | #endif |
| 343 | #endif |
| 344 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 345 | /* |
| 346 | * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35): |
| 347 | * |
| 348 | * "At system reset, initialization software must set up the |
| 349 | * programmable parameters in the memory controller banks registers |
| 350 | * (ORx, BRx, P/LSDMR). After all memory parameters are configured, |
| 351 | * system software should execute the following initialization sequence |
| 352 | * for each SDRAM device. |
| 353 | * |
| 354 | * 1. Issue a PRECHARGE-ALL-BANKS command |
| 355 | * 2. Issue eight CBR REFRESH commands |
| 356 | * 3. Issue a MODE-SET command to initialize the mode register |
| 357 | * |
| 358 | * Quote from Micron MT48LC8M16A2 data sheet: |
| 359 | * |
| 360 | * "...the SDRAM requires a 100uS delay prior to issuing any |
| 361 | * command other than a COMMAND INHIBIT or NOP. Starting at some |
| 362 | * point during this 100uS period and continuing at least through |
| 363 | * the end of this period, COMMAND INHIBIT or NOP commands should |
| 364 | * be applied." |
| 365 | * |
| 366 | * "Once the 100uS delay has been satisfied with at least one COMMAND |
| 367 | * INHIBIT or NOP command having been applied, a /PRECHARGE command/ |
| 368 | * should be applied. All banks must then be precharged, thereby |
| 369 | * placing the device in the all banks idle state." |
| 370 | * |
| 371 | * "Once in the idle state, /two/ AUTO REFRESH cycles must be |
| 372 | * performed. After the AUTO REFRESH cycles are complete, the |
| 373 | * SDRAM is ready for mode register programming." |
| 374 | * |
| 375 | * (/emphasis/ mine, gvb) |
| 376 | * |
| 377 | * The way I interpret this, Micron start up sequence is: |
| 378 | * 1. Issue a PRECHARGE-BANK command (initial precharge) |
| 379 | * 2. Issue a PRECHARGE-ALL-BANKS command ("all banks ... precharged") |
| 380 | * 3. Issue two (presumably, doing eight is OK) CBR REFRESH commands |
| 381 | * 4. Issue a MODE-SET command to initialize the mode register |
| 382 | * |
| 383 | * -------- |
| 384 | * |
| 385 | * The initial commands are executed by setting P/LSDMR[OP] and |
| 386 | * accessing the SDRAM with a single-byte transaction." |
| 387 | * |
| 388 | * The appropriate BRx/ORx registers have already been set when we |
| 389 | * get here. The SDRAM can be accessed at the address CONFIG_SYS_SDRAM_BASE. |
| 390 | */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 391 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 392 | memctl->memc_mptpr = CONFIG_SYS_MPTPR; |
| 393 | memctl->memc_psrt = psrt; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 394 | |
| 395 | memctl->memc_psdmr = psdmr | PSDMR_OP_PREA; |
| 396 | *ramaddr = c; |
| 397 | |
| 398 | memctl->memc_psdmr = psdmr | PSDMR_OP_CBRR; |
| 399 | for (i = 0; i < 8; i++) |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 400 | *ramaddr = c; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 401 | |
| 402 | memctl->memc_psdmr = psdmr | PSDMR_OP_MRW; |
| 403 | *ramaddr = c; |
| 404 | |
| 405 | memctl->memc_psdmr = psdmr | PSDMR_OP_NORM | PSDMR_RFEN; |
| 406 | *ramaddr = c; |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 407 | |
| 408 | /* |
| 409 | * Do it a second time for the second set of chips if the DIMM has |
| 410 | * two chip selects (double sided). |
| 411 | */ |
| 412 | if (chipselects > 1) { |
| 413 | ramaddr += sdram_size; |
| 414 | |
| 415 | memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM + sdram_size; |
| 416 | memctl->memc_or3 = or; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 417 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 418 | memctl->memc_psdmr = psdmr | PSDMR_OP_PREA; |
| 419 | *ramaddr = c; |
| 420 | |
| 421 | memctl->memc_psdmr = psdmr | PSDMR_OP_CBRR; |
| 422 | for (i = 0; i < 8; i++) |
| 423 | *ramaddr = c; |
| 424 | |
| 425 | memctl->memc_psdmr = psdmr | PSDMR_OP_MRW; |
| 426 | *ramaddr = c; |
| 427 | |
| 428 | memctl->memc_psdmr = psdmr | PSDMR_OP_NORM | PSDMR_RFEN; |
| 429 | *ramaddr = c; |
| 430 | } |
| 431 | |
| 432 | /* return total ram size */ |
| 433 | return (sdram_size * chipselects); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /*----------------------------------------------------------------------- |
| 437 | * Board Control Functions |
| 438 | */ |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 439 | void board_poweroff(void) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 440 | { |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 441 | while (1); /* hang forever */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | |
| 445 | #ifdef CONFIG_MISC_INIT_R |
| 446 | /* ------------------------------------------------------------------------- */ |
| 447 | int misc_init_r(void) |
| 448 | { |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 449 | /* |
| 450 | * Note: iop is used by the I2C macros, and iopa by the ADC/DAC initialization. |
| 451 | */ |
| 452 | volatile ioport_t *iopa = |
| 453 | ioport_addr((immap_t *)CONFIG_SYS_IMMR, 0 /* port A */ ); |
| 454 | volatile ioport_t *iop = |
| 455 | ioport_addr((immap_t *)CONFIG_SYS_IMMR, I2C_PORT); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 456 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 457 | int reg; /* I2C register value */ |
| 458 | char *ep; /* Environment pointer */ |
| 459 | char str_buf[12]; /* sprintf output buffer */ |
| 460 | int sample_rate; /* ADC/DAC sample rate */ |
| 461 | int sample_64x; /* Use 64/4 clocking for the ADC/DAC */ |
| 462 | int sample_128x; /* Use 128/4 clocking for the ADC/DAC */ |
| 463 | int right_just; /* Is the data to the DAC right justified? */ |
| 464 | int mclk_divide; /* MCLK Divide */ |
| 465 | int quiet; /* Quiet or minimal output mode */ |
wdenk | 1f197c6 | 2003-09-15 18:00:00 +0000 | [diff] [blame] | 466 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 467 | quiet = 0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 468 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 469 | if ((ep = getenv("quiet")) != NULL) |
| 470 | quiet = simple_strtol(ep, NULL, 10); |
| 471 | else |
| 472 | setenv("quiet", "0"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 473 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 474 | /* |
| 475 | * SACSng custom initialization: |
| 476 | * Start the ADC and DAC clocks, since the Crystal parts do not |
| 477 | * work on the I2C bus until the clocks are running. |
| 478 | */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 479 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 480 | sample_rate = INITIAL_SAMPLE_RATE; |
| 481 | if ((ep = getenv("DaqSampleRate")) != NULL) |
| 482 | sample_rate = simple_strtol(ep, NULL, 10); |
| 483 | |
| 484 | sample_64x = INITIAL_SAMPLE_64X; |
| 485 | sample_128x = INITIAL_SAMPLE_128X; |
| 486 | if ((ep = getenv("Daq64xSampling")) != NULL) { |
| 487 | sample_64x = simple_strtol(ep, NULL, 10); |
| 488 | if (sample_64x) |
| 489 | sample_128x = 0; |
| 490 | else |
| 491 | sample_128x = 1; |
| 492 | } else { |
| 493 | if ((ep = getenv("Daq128xSampling")) != NULL) { |
| 494 | sample_128x = simple_strtol(ep, NULL, 10); |
| 495 | if (sample_128x) |
| 496 | sample_64x = 0; |
| 497 | else |
| 498 | sample_64x = 1; |
| 499 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 500 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 501 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 502 | /* |
| 503 | * Stop the clocks and wait for at least 1 LRCLK period |
| 504 | * to make sure the clocking has really stopped. |
| 505 | */ |
| 506 | Daq_Stop_Clocks(); |
| 507 | udelay((1000000 / sample_rate) * NUM_LRCLKS_TO_STABILIZE); |
wdenk | c217f6d | 2002-11-11 02:11:37 +0000 | [diff] [blame] | 508 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 509 | /* |
| 510 | * Initialize the clocks with the new rates |
| 511 | */ |
| 512 | Daq_Init_Clocks(sample_rate, sample_64x); |
| 513 | sample_rate = Daq_Get_SampleRate(); |
wdenk | c217f6d | 2002-11-11 02:11:37 +0000 | [diff] [blame] | 514 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 515 | /* |
| 516 | * Start the clocks and wait for at least 1 LRCLK period |
| 517 | * to make sure the clocking has become stable. |
| 518 | */ |
| 519 | Daq_Start_Clocks(sample_rate); |
| 520 | udelay((1000000 / sample_rate) * NUM_LRCLKS_TO_STABILIZE); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 521 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 522 | sprintf(str_buf, "%d", sample_rate); |
| 523 | setenv("DaqSampleRate", str_buf); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 524 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 525 | if (sample_64x) { |
| 526 | setenv("Daq64xSampling", "1"); |
| 527 | setenv("Daq128xSampling", NULL); |
| 528 | } else { |
| 529 | setenv("Daq64xSampling", NULL); |
| 530 | setenv("Daq128xSampling", "1"); |
| 531 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 532 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 533 | /* |
| 534 | * Display the ADC/DAC clocking information |
| 535 | */ |
| 536 | if (!quiet) |
| 537 | Daq_Display_Clocks(); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 538 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 539 | /* |
| 540 | * Determine the DAC data justification |
| 541 | */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 542 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 543 | right_just = INITIAL_RIGHT_JUST; |
| 544 | if ((ep = getenv("DaqDACRightJustified")) != NULL) |
| 545 | right_just = simple_strtol(ep, NULL, 10); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 546 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 547 | sprintf(str_buf, "%d", right_just); |
| 548 | setenv("DaqDACRightJustified", str_buf); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 549 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 550 | /* |
| 551 | * Determine the DAC MCLK Divide |
| 552 | */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 553 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 554 | mclk_divide = INITIAL_MCLK_DIVIDE; |
| 555 | if ((ep = getenv("DaqDACMClockDivide")) != NULL) |
| 556 | mclk_divide = simple_strtol(ep, NULL, 10); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 557 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 558 | sprintf(str_buf, "%d", mclk_divide); |
| 559 | setenv("DaqDACMClockDivide", str_buf); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 560 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 561 | /* |
| 562 | * Initializing the I2C address in the Crystal A/Ds: |
| 563 | * |
| 564 | * 1) Wait for VREF cap to settle (10uSec per uF) |
| 565 | * 2) Release pullup on SDATA |
| 566 | * 3) Write the I2C address to register 6 |
| 567 | * 4) Enable address matching by setting the MSB in register 7 |
| 568 | */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 569 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 570 | if (!quiet) |
| 571 | printf("Initializing the ADC...\n"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 572 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 573 | udelay(ADC_INITIAL_DELAY); /* 10uSec per uF of VREF cap */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 574 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 575 | iopa->pdat &= ~ADC_SDATA1_MASK; /* release SDATA1 */ |
| 576 | udelay(ADC_SDATA_DELAY); /* arbitrary settling time */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 577 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 578 | i2c_reg_write(0x00, 0x06, I2C_ADC_1_ADDR); /* set address */ |
| 579 | i2c_reg_write(I2C_ADC_1_ADDR, 0x07, /* turn on ADDREN */ |
| 580 | ADC_REG7_ADDR_ENABLE); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 581 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 582 | i2c_reg_write(I2C_ADC_1_ADDR, 0x02, /* 128x, slave mode, !HPEN */ |
| 583 | (sample_64x ? 0 : ADC_REG2_128x) | |
| 584 | ADC_REG2_HIGH_PASS_DIS | ADC_REG2_SLAVE_MODE); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 585 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 586 | reg = i2c_reg_read(I2C_ADC_1_ADDR, 0x06) & 0x7F; |
| 587 | if (reg != I2C_ADC_1_ADDR) { |
| 588 | printf("Init of ADC U10 failed: address is 0x%02X should be 0x%02X\n", |
| 589 | reg, I2C_ADC_1_ADDR); |
| 590 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 591 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 592 | iopa->pdat &= ~ADC_SDATA2_MASK; /* release SDATA2 */ |
| 593 | udelay(ADC_SDATA_DELAY); /* arbitrary settling time */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 594 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 595 | /* set address (do not set ADDREN yet) */ |
| 596 | i2c_reg_write(0x00, 0x06, I2C_ADC_2_ADDR); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 597 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 598 | i2c_reg_write(I2C_ADC_2_ADDR, 0x02, /* 64x, slave mode, !HPEN */ |
| 599 | (sample_64x ? 0 : ADC_REG2_128x) | |
| 600 | ADC_REG2_HIGH_PASS_DIS | ADC_REG2_SLAVE_MODE); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 601 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 602 | reg = i2c_reg_read(I2C_ADC_2_ADDR, 0x06) & 0x7F; |
| 603 | if (reg != I2C_ADC_2_ADDR) { |
| 604 | printf("Init of ADC U15 failed: address is 0x%02X should be 0x%02X\n", |
| 605 | reg, I2C_ADC_2_ADDR); |
| 606 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 607 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 608 | i2c_reg_write(I2C_ADC_1_ADDR, 0x01, /* set FSTART and GNDCAL */ |
| 609 | ADC_REG1_FRAME_START | ADC_REG1_GROUND_CAL); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 610 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 611 | i2c_reg_write(I2C_ADC_1_ADDR, 0x02, /* Start calibration */ |
| 612 | (sample_64x ? 0 : ADC_REG2_128x) | |
| 613 | ADC_REG2_CAL | |
| 614 | ADC_REG2_HIGH_PASS_DIS | ADC_REG2_SLAVE_MODE); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 615 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 616 | udelay(ADC_CAL_DELAY); /* a minimum of 4100 LRCLKs */ |
| 617 | i2c_reg_write(I2C_ADC_1_ADDR, 0x01, 0x00); /* remove GNDCAL */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 618 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 619 | /* |
| 620 | * Now that we have synchronized the ADC's, enable address |
| 621 | * selection on the second ADC as well as the first. |
| 622 | */ |
| 623 | i2c_reg_write(I2C_ADC_2_ADDR, 0x07, ADC_REG7_ADDR_ENABLE); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 624 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 625 | /* |
| 626 | * Initialize the Crystal DAC |
| 627 | * |
| 628 | * Two of the config lines are used for I2C so we have to set them |
| 629 | * to the proper initialization state without inadvertantly |
| 630 | * sending an I2C "start" sequence. When we bring the I2C back to |
| 631 | * the normal state, we send an I2C "stop" sequence. |
| 632 | */ |
| 633 | if (!quiet) |
| 634 | printf("Initializing the DAC...\n"); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 635 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 636 | /* |
| 637 | * Bring the I2C clock and data lines low for initialization |
| 638 | */ |
| 639 | I2C_SCL(0); |
| 640 | I2C_DELAY; |
| 641 | I2C_SDA(0); |
| 642 | I2C_ACTIVE; |
| 643 | I2C_DELAY; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 644 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 645 | /* Reset the DAC */ |
| 646 | iopa->pdat &= ~DAC_RST_MASK; |
| 647 | udelay(DAC_RESET_DELAY); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 648 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 649 | /* Release the DAC reset */ |
| 650 | iopa->pdat |= DAC_RST_MASK; |
| 651 | udelay(DAC_INITIAL_DELAY); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 652 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 653 | /* |
| 654 | * Cause the DAC to: |
| 655 | * Enable control port (I2C mode) |
| 656 | * Going into power down |
| 657 | */ |
| 658 | i2c_reg_write(I2C_DAC_ADDR, 0x05, |
| 659 | DAC_REG5_I2C_MODE | DAC_REG5_POWER_DOWN); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 660 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 661 | /* |
| 662 | * Cause the DAC to: |
| 663 | * Enable control port (I2C mode) |
| 664 | * Going into power down |
| 665 | * . MCLK divide by 1 |
| 666 | * . MCLK divide by 2 |
| 667 | */ |
| 668 | i2c_reg_write(I2C_DAC_ADDR, 0x05, |
| 669 | DAC_REG5_I2C_MODE | |
| 670 | DAC_REG5_POWER_DOWN | |
| 671 | (mclk_divide ? DAC_REG5_MCLK_DIV : 0)); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 672 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 673 | /* |
| 674 | * Cause the DAC to: |
| 675 | * Auto-mute disabled |
| 676 | * . Format 0, left justified 24 bits |
| 677 | * . Format 3, right justified 24 bits |
| 678 | * No de-emphasis |
| 679 | * . Single speed mode |
| 680 | * . Double speed mode |
| 681 | */ |
| 682 | i2c_reg_write(I2C_DAC_ADDR, 0x01, |
| 683 | (right_just ? DAC_REG1_RIGHT_JUST_24BIT : |
| 684 | DAC_REG1_LEFT_JUST_24_BIT) | |
| 685 | DAC_REG1_DEM_NO | |
| 686 | (sample_rate >= |
| 687 | 50000 ? DAC_REG1_DOUBLE : DAC_REG1_SINGLE)); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 688 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 689 | sprintf(str_buf, "%d", |
| 690 | sample_rate >= 50000 ? DAC_REG1_DOUBLE : DAC_REG1_SINGLE); |
| 691 | setenv("DaqDACFunctionalMode", str_buf); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 692 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 693 | /* |
| 694 | * Cause the DAC to: |
| 695 | * Enable control port (I2C mode) |
| 696 | * Remove power down |
| 697 | * . MCLK divide by 1 |
| 698 | * . MCLK divide by 2 |
| 699 | */ |
| 700 | i2c_reg_write(I2C_DAC_ADDR, 0x05, |
| 701 | DAC_REG5_I2C_MODE | |
| 702 | (mclk_divide ? DAC_REG5_MCLK_DIV : 0)); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 703 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 704 | /* |
| 705 | * Create a I2C stop condition: |
| 706 | * low->high on data while clock is high. |
| 707 | */ |
| 708 | I2C_SCL(1); |
| 709 | I2C_DELAY; |
| 710 | I2C_SDA(1); |
| 711 | I2C_DELAY; |
| 712 | I2C_TRISTATE; |
wdenk | 1f197c6 | 2003-09-15 18:00:00 +0000 | [diff] [blame] | 713 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 714 | if (!quiet) |
| 715 | printf("\n"); |
wdenk | 1f197c6 | 2003-09-15 18:00:00 +0000 | [diff] [blame] | 716 | #ifdef CONFIG_ETHER_LOOPBACK_TEST |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 717 | /* |
| 718 | * Run the Ethernet loopback test |
| 719 | */ |
| 720 | eth_loopback_test(); |
wdenk | 1f197c6 | 2003-09-15 18:00:00 +0000 | [diff] [blame] | 721 | #endif /* CONFIG_ETHER_LOOPBACK_TEST */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 722 | |
| 723 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 724 | /* |
| 725 | * Turn off the RED fail LED now that we are up and running. |
| 726 | */ |
| 727 | status_led_set(STATUS_LED_RED, STATUS_LED_OFF); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 728 | #endif |
| 729 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 730 | return 0; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 734 | /* |
| 735 | * Show boot status: flash the LED if something goes wrong, indicating |
| 736 | * that last thing that worked and thus, by implication, what is broken. |
| 737 | * |
| 738 | * This stores the last OK value in RAM so this will not work properly |
| 739 | * before RAM is initialized. Since it is being used for indicating |
| 740 | * boot status (i.e. after RAM is initialized), that is OK. |
| 741 | */ |
| 742 | static void flash_code(uchar number, uchar modulo, uchar digits) |
| 743 | { |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 744 | int j; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 745 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 746 | /* |
| 747 | * Recursively do upper digits. |
| 748 | */ |
| 749 | if (digits > 1) |
| 750 | flash_code(number / modulo, modulo, digits - 1); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 751 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 752 | number = number % modulo; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 753 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 754 | /* |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 755 | * Zero is indicated by one long flash (dash). |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 756 | */ |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 757 | if (number == 0) { |
| 758 | status_led_set(STATUS_LED_BOOT, STATUS_LED_ON); |
| 759 | udelay(1000000); |
| 760 | status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF); |
| 761 | udelay(200000); |
| 762 | } else { |
| 763 | /* |
| 764 | * Non-zero is indicated by short flashes, one per count. |
| 765 | */ |
| 766 | for (j = 0; j < number; j++) { |
| 767 | status_led_set(STATUS_LED_BOOT, STATUS_LED_ON); |
| 768 | udelay(100000); |
| 769 | status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF); |
| 770 | udelay(200000); |
| 771 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 772 | } |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 773 | /* |
| 774 | * Inter-digit pause: we've already waited 200 mSec, wait 1 sec total |
| 775 | */ |
| 776 | udelay(700000); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | static int last_boot_progress; |
| 780 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 781 | void show_boot_progress(int status) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 782 | { |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 783 | int i, j; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 784 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 785 | if (status > 0) { |
| 786 | last_boot_progress = status; |
| 787 | } else { |
| 788 | /* |
| 789 | * If a specific failure code is given, flash this code |
| 790 | * else just use the last success code we've seen |
| 791 | */ |
| 792 | if (status < -1) |
| 793 | last_boot_progress = -status; |
wdenk | 1f197c6 | 2003-09-15 18:00:00 +0000 | [diff] [blame] | 794 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 795 | /* |
| 796 | * Flash this code 5 times |
| 797 | */ |
| 798 | for (j = 0; j < 5; j++) { |
| 799 | /* |
| 800 | * Houston, we have a problem. |
| 801 | * Blink the last OK status which indicates where things failed. |
| 802 | */ |
| 803 | status_led_set(STATUS_LED_RED, STATUS_LED_ON); |
| 804 | flash_code(last_boot_progress, 5, 3); |
wdenk | 1f197c6 | 2003-09-15 18:00:00 +0000 | [diff] [blame] | 805 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 806 | /* |
| 807 | * Delay 5 seconds between repetitions, |
| 808 | * with the fault LED blinking |
| 809 | */ |
| 810 | for (i = 0; i < 5; i++) { |
| 811 | status_led_set(STATUS_LED_RED, |
| 812 | STATUS_LED_OFF); |
| 813 | udelay(500000); |
| 814 | status_led_set(STATUS_LED_RED, STATUS_LED_ON); |
| 815 | udelay(500000); |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | /* |
| 820 | * Reset the board to retry initialization. |
| 821 | */ |
| 822 | do_reset(NULL, 0, 0, NULL); |
| 823 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 824 | } |
| 825 | #endif /* CONFIG_SHOW_BOOT_PROGRESS */ |
| 826 | |
| 827 | |
| 828 | /* |
| 829 | * The following are used to control the SPI chip selects for the SPI command. |
| 830 | */ |
Jon Loeliger | e11c123 | 2007-07-09 18:45:16 -0500 | [diff] [blame] | 831 | #if defined(CONFIG_CMD_SPI) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 832 | |
| 833 | #define SPI_ADC_CS_MASK 0x00000800 |
| 834 | #define SPI_DAC_CS_MASK 0x00001000 |
| 835 | |
Haavard Skinnemoen | d74084a | 2008-05-16 11:10:31 +0200 | [diff] [blame] | 836 | static const u32 cs_mask[] = { |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 837 | SPI_ADC_CS_MASK, |
| 838 | SPI_DAC_CS_MASK, |
Haavard Skinnemoen | d74084a | 2008-05-16 11:10:31 +0200 | [diff] [blame] | 839 | }; |
| 840 | |
| 841 | int spi_cs_is_valid(unsigned int bus, unsigned int cs) |
| 842 | { |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 843 | return bus == 0 && cs < sizeof(cs_mask) / sizeof(cs_mask[0]); |
Haavard Skinnemoen | d74084a | 2008-05-16 11:10:31 +0200 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | void spi_cs_activate(struct spi_slave *slave) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 847 | { |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 848 | volatile ioport_t *iopd = |
| 849 | ioport_addr((immap_t *) CONFIG_SYS_IMMR, 3 /* port D */ ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 850 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 851 | iopd->pdat &= ~cs_mask[slave->cs]; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 852 | } |
| 853 | |
Haavard Skinnemoen | d74084a | 2008-05-16 11:10:31 +0200 | [diff] [blame] | 854 | void spi_cs_deactivate(struct spi_slave *slave) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 855 | { |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 856 | volatile ioport_t *iopd = |
| 857 | ioport_addr((immap_t *) CONFIG_SYS_IMMR, 3 /* port D */ ); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 858 | |
Wolfgang Denk | 20351cc | 2011-11-05 05:13:14 +0000 | [diff] [blame] | 859 | iopd->pdat |= cs_mask[slave->cs]; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 860 | } |
| 861 | |
Jon Loeliger | 761ea74 | 2007-07-10 10:48:22 -0500 | [diff] [blame] | 862 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 863 | |
| 864 | #endif /* CONFIG_MISC_INIT_R */ |