integratorap.c 17 KB

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