sc520_timer.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * (C) Copyright 2008-2011
  3. * Graeme Russ, <graeme.russ@gmail.com>
  4. *
  5. * (C) Copyright 2002
  6. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <asm/io.h>
  28. #include <asm/interrupt.h>
  29. #include <asm/arch/sc520.h>
  30. void sc520_timer_isr(void)
  31. {
  32. /* Ack the GP Timer Interrupt */
  33. writeb(0x02, &sc520_mmcr->gptmrsta);
  34. }
  35. int timer_init(void)
  36. {
  37. /* Register the SC520 specific timer interrupt handler */
  38. register_timer_isr(sc520_timer_isr);
  39. /* Install interrupt handler for GP Timer 1 */
  40. irq_install_handler (0, timer_isr, NULL);
  41. /* Map GP Timer 1 to Master PIC IR0 */
  42. writeb(0x01, &sc520_mmcr->gp_tmr_int_map[1]);
  43. /* Disable GP Timers 1 & 2 - Allow configuration writes */
  44. writew(0x4000, &sc520_mmcr->gptmr1ctl);
  45. writew(0x4000, &sc520_mmcr->gptmr2ctl);
  46. /* Reset GP Timers 1 & 2 */
  47. writew(0x0000, &sc520_mmcr->gptmr1cnt);
  48. writew(0x0000, &sc520_mmcr->gptmr2cnt);
  49. /* Setup GP Timer 2 as a 100kHz (10us) prescaler */
  50. writew(83, &sc520_mmcr->gptmr2maxcmpa);
  51. writew(0xc001, &sc520_mmcr->gptmr2ctl);
  52. /* Setup GP Timer 1 as a 1000 Hz (1ms) interrupt generator */
  53. writew(100, &sc520_mmcr->gptmr1maxcmpa);
  54. writew(0xe009, &sc520_mmcr->gptmr1ctl);
  55. unmask_irq(0);
  56. /* Clear the GP Timer 1 status register to get the show rolling*/
  57. writeb(0x02, &sc520_mmcr->gptmrsta);
  58. return 0;
  59. }
  60. /* Allow boards to override udelay implementation */
  61. void __udelay(unsigned long usec)
  62. __attribute__((weak, alias("sc520_udelay")));
  63. void sc520_udelay(unsigned long usec)
  64. {
  65. int m = 0;
  66. long u;
  67. readw(&sc520_mmcr->swtmrmilli);
  68. readw(&sc520_mmcr->swtmrmicro);
  69. do {
  70. m += readw(&sc520_mmcr->swtmrmilli);
  71. u = readw(&sc520_mmcr->swtmrmicro) + (m * 1000);
  72. } while (u < usec);
  73. }