integratorap.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * (C) Copyright 2002
  7. * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
  8. *
  9. * (C) Copyright 2003
  10. * Texas Instruments, <www.ti.com>
  11. * Kshitij Gupta <Kshitij@ti.com>
  12. *
  13. * (C) Copyright 2004
  14. * ARM Ltd.
  15. * Philippe Robin, <philippe.robin@arm.com>
  16. *
  17. * See file CREDITS for list of people who contributed to this
  18. * project.
  19. *
  20. * This program is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU General Public License as
  22. * published by the Free Software Foundation; either version 2 of
  23. * the License, or (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, write to the Free Software
  32. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33. * MA 02111-1307 USA
  34. */
  35. #include <common.h>
  36. #ifdef CONFIG_PCI
  37. #include <pci.h>
  38. #endif
  39. #include <netdev.h>
  40. DECLARE_GLOBAL_DATA_PTR;
  41. void flash__init (void);
  42. void ether__init (void);
  43. void peripheral_power_enable (void);
  44. #if defined(CONFIG_SHOW_BOOT_PROGRESS)
  45. void show_boot_progress(int progress)
  46. {
  47. printf("Boot reached stage %d\n", progress);
  48. }
  49. #endif
  50. #define COMP_MODE_ENABLE ((unsigned int)0x0000EAEF)
  51. static inline void delay (unsigned long loops)
  52. {
  53. __asm__ volatile ("1:\n"
  54. "subs %0, %1, #1\n"
  55. "bne 1b":"=r" (loops):"0" (loops));
  56. }
  57. /*
  58. * Miscellaneous platform dependent initialisations
  59. */
  60. int board_init (void)
  61. {
  62. /* arch number of Integrator Board */
  63. gd->bd->bi_arch_number = MACH_TYPE_INTEGRATOR;
  64. /* adress of boot parameters */
  65. gd->bd->bi_boot_params = 0x00000100;
  66. gd->flags = 0;
  67. #ifdef CONFIG_CM_REMAP
  68. extern void cm_remap(void);
  69. cm_remap(); /* remaps writeable memory to 0x00000000 */
  70. #endif
  71. icache_enable ();
  72. flash__init ();
  73. return 0;
  74. }
  75. int misc_init_r (void)
  76. {
  77. #ifdef CONFIG_PCI
  78. pci_init();
  79. #endif
  80. setenv("verify", "n");
  81. return (0);
  82. }
  83. /*
  84. * Initialize PCI Devices, report devices found.
  85. */
  86. #ifdef CONFIG_PCI
  87. #ifndef CONFIG_PCI_PNP
  88. static struct pci_config_table pci_integrator_config_table[] = {
  89. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0f, PCI_ANY_ID,
  90. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  91. PCI_ENET0_MEMADDR,
  92. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
  93. { }
  94. };
  95. #endif
  96. /* V3 access routines */
  97. #define _V3Write16(o,v) (*(volatile unsigned short *)(PCI_V3_BASE + (unsigned int)(o)) = (unsigned short)(v))
  98. #define _V3Read16(o) (*(volatile unsigned short *)(PCI_V3_BASE + (unsigned int)(o)))
  99. #define _V3Write32(o,v) (*(volatile unsigned int *)(PCI_V3_BASE + (unsigned int)(o)) = (unsigned int)(v))
  100. #define _V3Read32(o) (*(volatile unsigned int *)(PCI_V3_BASE + (unsigned int)(o)))
  101. /* Compute address necessary to access PCI config space for the given */
  102. /* bus and device. */
  103. #define PCI_CONFIG_ADDRESS( __bus, __devfn, __offset ) ({ \
  104. unsigned int __address, __devicebit; \
  105. unsigned short __mapaddress; \
  106. unsigned int __dev = PCI_DEV (__devfn); /* FIXME to check!! (slot?) */ \
  107. \
  108. if (__bus == 0) { \
  109. /* local bus segment so need a type 0 config cycle */ \
  110. /* build the PCI configuration "address" with one-hot in A31-A11 */ \
  111. __address = PCI_CONFIG_BASE; \
  112. __address |= ((__devfn & 0x07) << 8); \
  113. __address |= __offset & 0xFF; \
  114. __mapaddress = 0x000A; /* 101=>config cycle, 0=>A1=A0=0 */ \
  115. __devicebit = (1 << (__dev + 11)); \
  116. \
  117. if ((__devicebit & 0xFF000000) != 0) { \
  118. /* high order bits are handled by the MAP register */ \
  119. __mapaddress |= (__devicebit >> 16); \
  120. } else { \
  121. /* low order bits handled directly in the address */ \
  122. __address |= __devicebit; \
  123. } \
  124. } else { /* bus !=0 */ \
  125. /* not the local bus segment so need a type 1 config cycle */ \
  126. /* A31-A24 are don't care (so clear to 0) */ \
  127. __mapaddress = 0x000B; /* 101=>config cycle, 1=>A1&A0 from PCI_CFG */ \
  128. __address = PCI_CONFIG_BASE; \
  129. __address |= ((__bus & 0xFF) << 16); /* bits 23..16 = bus number */ \
  130. __address |= ((__dev & 0x1F) << 11); /* bits 15..11 = device number */ \
  131. __address |= ((__devfn & 0x07) << 8); /* bits 10..8 = function number */ \
  132. __address |= __offset & 0xFF; /* bits 7..0 = register number */ \
  133. } \
  134. _V3Write16 (V3_LB_MAP1, __mapaddress); \
  135. __address; \
  136. })
  137. /* _V3OpenConfigWindow - open V3 configuration window */
  138. #define _V3OpenConfigWindow() { \
  139. /* Set up base0 to see all 512Mbytes of memory space (not */ \
  140. /* prefetchable), this frees up base1 for re-use by configuration*/ \
  141. /* memory */ \
  142. \
  143. _V3Write32 (V3_LB_BASE0, ((INTEGRATOR_PCI_BASE & 0xFFF00000) | \
  144. 0x90 | V3_LB_BASE_M_ENABLE)); \
  145. /* Set up base1 to point into configuration space, note that MAP1 */ \
  146. /* register is set up by pciMakeConfigAddress(). */ \
  147. \
  148. _V3Write32 (V3_LB_BASE1, ((CPU_PCI_CNFG_ADRS & 0xFFF00000) | \
  149. 0x40 | V3_LB_BASE_M_ENABLE)); \
  150. }
  151. /* _V3CloseConfigWindow - close V3 configuration window */
  152. #define _V3CloseConfigWindow() { \
  153. /* Reassign base1 for use by prefetchable PCI memory */ \
  154. _V3Write32 (V3_LB_BASE1, (((INTEGRATOR_PCI_BASE + 0x10000000) & 0xFFF00000) \
  155. | 0x84 | V3_LB_BASE_M_ENABLE)); \
  156. _V3Write16 (V3_LB_MAP1, \
  157. (((INTEGRATOR_PCI_BASE + 0x10000000) & 0xFFF00000) >> 16) | 0x0006); \
  158. \
  159. /* And shrink base0 back to a 256M window (NOTE: MAP0 already correct) */ \
  160. \
  161. _V3Write32 (V3_LB_BASE0, ((INTEGRATOR_PCI_BASE & 0xFFF00000) | \
  162. 0x80 | V3_LB_BASE_M_ENABLE)); \
  163. }
  164. static int pci_integrator_read_byte (struct pci_controller *hose, pci_dev_t dev,
  165. int offset, unsigned char *val)
  166. {
  167. _V3OpenConfigWindow ();
  168. *val = *(volatile unsigned char *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  169. PCI_FUNC (dev),
  170. offset);
  171. _V3CloseConfigWindow ();
  172. return 0;
  173. }
  174. static int pci_integrator_read__word (struct pci_controller *hose,
  175. pci_dev_t dev, int offset,
  176. unsigned short *val)
  177. {
  178. _V3OpenConfigWindow ();
  179. *val = *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  180. PCI_FUNC (dev),
  181. offset);
  182. _V3CloseConfigWindow ();
  183. return 0;
  184. }
  185. static int pci_integrator_read_dword (struct pci_controller *hose,
  186. pci_dev_t dev, int offset,
  187. unsigned int *val)
  188. {
  189. _V3OpenConfigWindow ();
  190. *val = *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  191. PCI_FUNC (dev),
  192. offset);
  193. *val |= (*(volatile unsigned int *)
  194. PCI_CONFIG_ADDRESS (PCI_BUS (dev), PCI_FUNC (dev),
  195. (offset + 2))) << 16;
  196. _V3CloseConfigWindow ();
  197. return 0;
  198. }
  199. static int pci_integrator_write_byte (struct pci_controller *hose,
  200. pci_dev_t dev, int offset,
  201. unsigned char val)
  202. {
  203. _V3OpenConfigWindow ();
  204. *(volatile unsigned char *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  205. PCI_FUNC (dev),
  206. offset) = val;
  207. _V3CloseConfigWindow ();
  208. return 0;
  209. }
  210. static int pci_integrator_write_word (struct pci_controller *hose,
  211. pci_dev_t dev, int offset,
  212. unsigned short val)
  213. {
  214. _V3OpenConfigWindow ();
  215. *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  216. PCI_FUNC (dev),
  217. offset) = val;
  218. _V3CloseConfigWindow ();
  219. return 0;
  220. }
  221. static int pci_integrator_write_dword (struct pci_controller *hose,
  222. pci_dev_t dev, int offset,
  223. unsigned int val)
  224. {
  225. _V3OpenConfigWindow ();
  226. *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  227. PCI_FUNC (dev),
  228. offset) = (val & 0xFFFF);
  229. *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  230. PCI_FUNC (dev),
  231. (offset + 2)) = ((val >> 16) & 0xFFFF);
  232. _V3CloseConfigWindow ();
  233. return 0;
  234. }
  235. /******************************
  236. * PCI initialisation
  237. ******************************/
  238. struct pci_controller integrator_hose = {
  239. #ifndef CONFIG_PCI_PNP
  240. config_table: pci_integrator_config_table,
  241. #endif
  242. };
  243. void pci_init_board (void)
  244. {
  245. volatile int i, j;
  246. struct pci_controller *hose = &integrator_hose;
  247. /* setting this register will take the V3 out of reset */
  248. *(volatile unsigned int *) (INTEGRATOR_SC_PCIENABLE) = 1;
  249. /* wait a few usecs to settle the device and the PCI bus */
  250. for (i = 0; i < 100; i++)
  251. j = i + 1;
  252. /* Now write the Base I/O Address Word to V3_BASE + 0x6C */
  253. *(volatile unsigned short *) (V3_BASE + V3_LB_IO_BASE) =
  254. (unsigned short) (V3_BASE >> 16);
  255. do {
  256. *(volatile unsigned char *) (V3_BASE + V3_MAIL_DATA) = 0xAA;
  257. *(volatile unsigned char *) (V3_BASE + V3_MAIL_DATA + 4) =
  258. 0x55;
  259. } while (*(volatile unsigned char *) (V3_BASE + V3_MAIL_DATA) != 0xAA
  260. || *(volatile unsigned char *) (V3_BASE + V3_MAIL_DATA +
  261. 4) != 0x55);
  262. /* Make sure that V3 register access is not locked, if it is, unlock it */
  263. if ((*(volatile unsigned short *) (V3_BASE + V3_SYSTEM) &
  264. V3_SYSTEM_M_LOCK)
  265. == V3_SYSTEM_M_LOCK)
  266. *(volatile unsigned short *) (V3_BASE + V3_SYSTEM) = 0xA05F;
  267. /* Ensure that the slave accesses from PCI are disabled while we */
  268. /* setup windows */
  269. *(volatile unsigned short *) (V3_BASE + V3_PCI_CMD) &=
  270. ~(V3_COMMAND_M_MEM_EN | V3_COMMAND_M_IO_EN);
  271. /* Clear RST_OUT to 0; keep the PCI bus in reset until we've finished */
  272. *(volatile unsigned short *) (V3_BASE + V3_SYSTEM) &=
  273. ~V3_SYSTEM_M_RST_OUT;
  274. /* Make all accesses from PCI space retry until we're ready for them */
  275. *(volatile unsigned short *) (V3_BASE + V3_PCI_CFG) |=
  276. V3_PCI_CFG_M_RETRY_EN;
  277. /* Set up any V3 PCI Configuration Registers that we absolutely have to */
  278. /* LB_CFG controls Local Bus protocol. */
  279. /* Enable LocalBus byte strobes for READ accesses too. */
  280. /* set bit 7 BE_IMODE and bit 6 BE_OMODE */
  281. *(volatile unsigned short *) (V3_BASE + V3_LB_CFG) |= 0x0C0;
  282. /* PCI_CMD controls overall PCI operation. */
  283. /* Enable PCI bus master. */
  284. *(volatile unsigned short *) (V3_BASE + V3_PCI_CMD) |= 0x04;
  285. /* PCI_MAP0 controls where the PCI to CPU memory window is on Local Bus */
  286. *(volatile unsigned int *) (V3_BASE + V3_PCI_MAP0) =
  287. (INTEGRATOR_BOOT_ROM_BASE) | (V3_PCI_MAP_M_ADR_SIZE_512M |
  288. V3_PCI_MAP_M_REG_EN |
  289. V3_PCI_MAP_M_ENABLE);
  290. /* PCI_BASE0 is the PCI address of the start of the window */
  291. *(volatile unsigned int *) (V3_BASE + V3_PCI_BASE0) =
  292. INTEGRATOR_BOOT_ROM_BASE;
  293. /* PCI_MAP1 is LOCAL address of the start of the window */
  294. *(volatile unsigned int *) (V3_BASE + V3_PCI_MAP1) =
  295. (INTEGRATOR_HDR0_SDRAM_BASE) | (V3_PCI_MAP_M_ADR_SIZE_1024M |
  296. V3_PCI_MAP_M_REG_EN |
  297. V3_PCI_MAP_M_ENABLE);
  298. /* PCI_BASE1 is the PCI address of the start of the window */
  299. *(volatile unsigned int *) (V3_BASE + V3_PCI_BASE1) =
  300. INTEGRATOR_HDR0_SDRAM_BASE;
  301. /* Set up the windows from local bus memory into PCI configuration, */
  302. /* I/O and Memory. */
  303. /* PCI I/O, LB_BASE2 and LB_MAP2 are used exclusively for this. */
  304. *(volatile unsigned short *) (V3_BASE + V3_LB_BASE2) =
  305. ((CPU_PCI_IO_ADRS >> 24) << 8) | V3_LB_BASE_M_ENABLE;
  306. *(volatile unsigned short *) (V3_BASE + V3_LB_MAP2) = 0;
  307. /* PCI Configuration, use LB_BASE1/LB_MAP1. */
  308. /* PCI Memory use LB_BASE0/LB_MAP0 and LB_BASE1/LB_MAP1 */
  309. /* Map first 256Mbytes as non-prefetchable via BASE0/MAP0 */
  310. /* (INTEGRATOR_PCI_BASE == PCI_MEM_BASE) */
  311. *(volatile unsigned int *) (V3_BASE + V3_LB_BASE0) =
  312. INTEGRATOR_PCI_BASE | (0x80 | V3_LB_BASE_M_ENABLE);
  313. *(volatile unsigned short *) (V3_BASE + V3_LB_MAP0) =
  314. ((INTEGRATOR_PCI_BASE >> 20) << 0x4) | 0x0006;
  315. /* Map second 256 Mbytes as prefetchable via BASE1/MAP1 */
  316. *(volatile unsigned int *) (V3_BASE + V3_LB_BASE1) =
  317. INTEGRATOR_PCI_BASE | (0x84 | V3_LB_BASE_M_ENABLE);
  318. *(volatile unsigned short *) (V3_BASE + V3_LB_MAP1) =
  319. (((INTEGRATOR_PCI_BASE + 0x10000000) >> 20) << 4) | 0x0006;
  320. /* Allow accesses to PCI Configuration space */
  321. /* and set up A1, A0 for type 1 config cycles */
  322. *(volatile unsigned short *) (V3_BASE + V3_PCI_CFG) =
  323. ((*(volatile unsigned short *) (V3_BASE + V3_PCI_CFG)) &
  324. ~(V3_PCI_CFG_M_RETRY_EN | V3_PCI_CFG_M_AD_LOW1)) |
  325. V3_PCI_CFG_M_AD_LOW0;
  326. /* now we can allow in PCI MEMORY accesses */
  327. *(volatile unsigned short *) (V3_BASE + V3_PCI_CMD) =
  328. (*(volatile unsigned short *) (V3_BASE + V3_PCI_CMD)) |
  329. V3_COMMAND_M_MEM_EN;
  330. /* Set RST_OUT to take the PCI bus is out of reset, PCI devices can */
  331. /* initialise and lock the V3 system register so that no one else */
  332. /* can play with it */
  333. *(volatile unsigned short *) (V3_BASE + V3_SYSTEM) =
  334. (*(volatile unsigned short *) (V3_BASE + V3_SYSTEM)) |
  335. V3_SYSTEM_M_RST_OUT;
  336. *(volatile unsigned short *) (V3_BASE + V3_SYSTEM) =
  337. (*(volatile unsigned short *) (V3_BASE + V3_SYSTEM)) |
  338. V3_SYSTEM_M_LOCK;
  339. /*
  340. * Register the hose
  341. */
  342. hose->first_busno = 0;
  343. hose->last_busno = 0xff;
  344. /* System memory space */
  345. pci_set_region (hose->regions + 0,
  346. 0x00000000, 0x40000000, 0x01000000,
  347. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
  348. /* PCI Memory - config space */
  349. pci_set_region (hose->regions + 1,
  350. 0x00000000, 0x62000000, 0x01000000, PCI_REGION_MEM);
  351. /* PCI V3 regs */
  352. pci_set_region (hose->regions + 2,
  353. 0x00000000, 0x61000000, 0x00080000, PCI_REGION_MEM);
  354. /* PCI I/O space */
  355. pci_set_region (hose->regions + 3,
  356. 0x00000000, 0x60000000, 0x00010000, PCI_REGION_IO);
  357. pci_set_ops (hose,
  358. pci_integrator_read_byte,
  359. pci_integrator_read__word,
  360. pci_integrator_read_dword,
  361. pci_integrator_write_byte,
  362. pci_integrator_write_word, pci_integrator_write_dword);
  363. hose->region_count = 4;
  364. pci_register_hose (hose);
  365. pciauto_config_init (hose);
  366. pciauto_config_device (hose, 0);
  367. hose->last_busno = pci_hose_scan (hose);
  368. }
  369. #endif
  370. /******************************
  371. Routine:
  372. Description:
  373. ******************************/
  374. void flash__init (void)
  375. {
  376. }
  377. /*************************************************************
  378. Routine:ether__init
  379. Description: take the Ethernet controller out of reset and wait
  380. for the EEPROM load to complete.
  381. *************************************************************/
  382. void ether__init (void)
  383. {
  384. }
  385. /******************************
  386. Routine:
  387. Description:
  388. ******************************/
  389. int dram_init (void)
  390. {
  391. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  392. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  393. #ifdef CONFIG_CM_SPD_DETECT
  394. {
  395. extern void dram_query(void);
  396. unsigned long cm_reg_sdram;
  397. unsigned long sdram_shift;
  398. dram_query(); /* Assembler accesses to CM registers */
  399. /* Queries the SPD values */
  400. /* Obtain the SDRAM size from the CM SDRAM register */
  401. cm_reg_sdram = *(volatile ulong *)(CM_BASE + OS_SDRAM);
  402. /* Register SDRAM size
  403. *
  404. * 0xXXXXXXbbb000bb 16 MB
  405. * 0xXXXXXXbbb001bb 32 MB
  406. * 0xXXXXXXbbb010bb 64 MB
  407. * 0xXXXXXXbbb011bb 128 MB
  408. * 0xXXXXXXbbb100bb 256 MB
  409. *
  410. */
  411. sdram_shift = ((cm_reg_sdram & 0x0000001C)/4)%4;
  412. gd->bd->bi_dram[0].size = 0x01000000 << sdram_shift;
  413. }
  414. #endif /* CM_SPD_DETECT */
  415. return 0;
  416. }
  417. /* The Integrator/AP timer1 is clocked at 24MHz
  418. * can be divided by 16 or 256
  419. * and is a 16-bit counter
  420. */
  421. /* U-Boot expects a 32 bit timer running at CONFIG_SYS_HZ*/
  422. static ulong timestamp; /* U-Boot ticks since startup */
  423. static ulong total_count = 0; /* Total timer count */
  424. static ulong lastdec; /* Timer reading at last call */
  425. static ulong div_clock = 256; /* Divisor applied to the timer clock */
  426. static ulong div_timer = 1; /* Divisor to convert timer reading
  427. * change to U-Boot ticks
  428. */
  429. /* CONFIG_SYS_HZ = CONFIG_SYS_HZ_CLOCK/(div_clock * div_timer) */
  430. #define TIMER_LOAD_VAL 0x0000FFFFL
  431. #define READ_TIMER ((*(volatile ulong *)(CONFIG_SYS_TIMERBASE+4)) & 0x0000FFFFL)
  432. /* all function return values in U-Boot ticks i.e. (1/CONFIG_SYS_HZ) sec
  433. * - unless otherwise stated
  434. */
  435. /* starts a counter
  436. * - the Integrator/AP timer issues an interrupt
  437. * each time it reaches zero
  438. */
  439. int interrupt_init (void)
  440. {
  441. /* Load timer with initial value */
  442. *(volatile ulong *)(CONFIG_SYS_TIMERBASE + 0) = TIMER_LOAD_VAL;
  443. /* Set timer to be
  444. * enabled 1
  445. * free-running 0
  446. * XX 00
  447. * divider 256 10
  448. * XX 00
  449. */
  450. *(volatile ulong *)(CONFIG_SYS_TIMERBASE + 8) = 0x00000088;
  451. total_count = 0;
  452. /* init the timestamp and lastdec value */
  453. reset_timer_masked();
  454. div_timer = CONFIG_SYS_HZ_CLOCK / CONFIG_SYS_HZ;
  455. div_timer /= div_clock;
  456. return (0);
  457. }
  458. /*
  459. * timer without interrupts
  460. */
  461. void reset_timer (void)
  462. {
  463. reset_timer_masked ();
  464. }
  465. ulong get_timer (ulong base_ticks)
  466. {
  467. return get_timer_masked () - base_ticks;
  468. }
  469. void set_timer (ulong ticks)
  470. {
  471. timestamp = ticks;
  472. total_count = ticks * div_timer;
  473. reset_timer_masked();
  474. }
  475. /* delay x useconds */
  476. void udelay (unsigned long usec)
  477. {
  478. ulong tmo, tmp;
  479. /* Convert to U-Boot ticks */
  480. tmo = usec * CONFIG_SYS_HZ;
  481. tmo /= (1000000L);
  482. tmp = get_timer_masked(); /* get current timestamp */
  483. tmo += tmp; /* wake up timestamp */
  484. while (get_timer_masked () < tmo) { /* loop till event */
  485. /*NOP*/;
  486. }
  487. }
  488. void reset_timer_masked (void)
  489. {
  490. /* reset time */
  491. lastdec = READ_TIMER; /* capture current decrementer value */
  492. timestamp = 0; /* start "advancing" time stamp from 0 */
  493. }
  494. /* converts the timer reading to U-Boot ticks */
  495. /* the timestamp is the number of ticks since reset */
  496. /* This routine does not detect wraps unless called regularly
  497. ASSUMES a call at least every 16 seconds to detect every reload */
  498. ulong get_timer_masked (void)
  499. {
  500. ulong now = READ_TIMER; /* current count */
  501. if (now > lastdec) {
  502. /* Must have wrapped */
  503. total_count += lastdec + TIMER_LOAD_VAL + 1 - now;
  504. } else {
  505. total_count += lastdec - now;
  506. }
  507. lastdec = now;
  508. timestamp = total_count/div_timer;
  509. return timestamp;
  510. }
  511. /* waits specified delay value and resets timestamp */
  512. void udelay_masked (unsigned long usec)
  513. {
  514. udelay(usec);
  515. }
  516. /*
  517. * This function is derived from PowerPC code (read timebase as long long).
  518. * On ARM it just returns the timer value.
  519. */
  520. unsigned long long get_ticks(void)
  521. {
  522. return get_timer(0);
  523. }
  524. /*
  525. * Return the timebase clock frequency
  526. * i.e. how often the timer decrements
  527. */
  528. ulong get_tbclk (void)
  529. {
  530. return CONFIG_SYS_HZ_CLOCK/div_clock;
  531. }
  532. int board_eth_init(bd_t *bis)
  533. {
  534. return pci_eth_init(bis);
  535. }