sacsng.c 24 KB

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