sc520_timer.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * (C) Copyright 2002
  3. * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /* stuff specific for the sc520, but independent of implementation */
  24. #include <common.h>
  25. #include <asm/interrupt.h>
  26. #include <asm/ic/sc520.h>
  27. void reset_timer(void)
  28. {
  29. write_mmcr_word(SC520_GPTMR0CNT, 0);
  30. write_mmcr_word(SC520_GPTMR0CTL, 0x6001);
  31. }
  32. ulong get_timer(ulong base)
  33. {
  34. /* fixme: 30 or 33 */
  35. return read_mmcr_word(SC520_GPTMR0CNT) / 33;
  36. }
  37. void set_timer(ulong t)
  38. {
  39. /* FixMe: use two cascade coupled timers */
  40. write_mmcr_word(SC520_GPTMR0CTL, 0x4001);
  41. write_mmcr_word(SC520_GPTMR0CNT, t*33);
  42. write_mmcr_word(SC520_GPTMR0CTL, 0x6001);
  43. }
  44. void udelay(unsigned long usec)
  45. {
  46. int m=0;
  47. long u;
  48. read_mmcr_word(SC520_SWTMRMILLI);
  49. read_mmcr_word(SC520_SWTMRMICRO);
  50. #if 0
  51. /* do not enable this line, udelay is used in the serial driver -> recursion */
  52. printf("udelay: %ld m.u %d.%d tm.tu %d.%d\n", usec, m, u, tm, tu);
  53. #endif
  54. while (1) {
  55. m += read_mmcr_word(SC520_SWTMRMILLI);
  56. u = read_mmcr_word(SC520_SWTMRMICRO) + (m * 1000);
  57. if (usec <= u) {
  58. break;
  59. }
  60. }
  61. }