sc520_timer.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 sc520_timer_isr(void)
  28. {
  29. /* Ack the GP Timer Interrupt */
  30. sc520_mmcr->gptmrsta = 0x02;
  31. }
  32. int timer_init(void)
  33. {
  34. /* Map GP Timer 1 to Master PIC IR0 */
  35. sc520_mmcr->gp_tmr_int_map[1] = 0x01;
  36. /* Disable GP Timers 1 & 2 - Allow configuration writes */
  37. sc520_mmcr->gptmr1ctl = 0x4000;
  38. sc520_mmcr->gptmr2ctl = 0x4000;
  39. /* Reset GP Timers 1 & 2 */
  40. sc520_mmcr->gptmr1cnt = 0x0000;
  41. sc520_mmcr->gptmr2cnt = 0x0000;
  42. /* Setup GP Timer 2 as a 100kHz (10us) prescaler */
  43. sc520_mmcr->gptmr2maxcmpa = 83;
  44. sc520_mmcr->gptmr2ctl = 0xc001;
  45. /* Setup GP Timer 1 as a 1000 Hz (1ms) interrupt generator */
  46. sc520_mmcr->gptmr1maxcmpa = 100;
  47. sc520_mmcr->gptmr1ctl = 0xe009;
  48. /* Register the SC520 specific timer interrupt handler */
  49. register_timer_isr (sc520_timer_isr);
  50. /* Install interrupt handler for GP Timer 1 */
  51. irq_install_handler (0, timer_isr, NULL);
  52. unmask_irq (0);
  53. /* Clear the GP Timer 1 status register to get the show rolling*/
  54. sc520_mmcr->gptmrsta = 0x02;
  55. return 0;
  56. }
  57. void udelay(unsigned long usec)
  58. {
  59. int m = 0;
  60. long u;
  61. long temp;
  62. temp = sc520_mmcr->swtmrmilli;
  63. temp = sc520_mmcr->swtmrmicro;
  64. do {
  65. m += sc520_mmcr->swtmrmilli;
  66. u = sc520_mmcr->swtmrmicro + (m * 1000);
  67. } while (u < usec);
  68. }