sacsng.c 25 KB

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