sacsng.c 26 KB

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