sacsng.c 26 KB

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