interrupts.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2000-2002
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * (C) Copyright 2003
  7. * Gleb Natapov <gnatapov@mrv.com>
  8. */
  9. #include <common.h>
  10. #include <irq_func.h>
  11. #include <asm/processor.h>
  12. #include <watchdog.h>
  13. #ifdef CONFIG_LED_STATUS
  14. #include <status_led.h>
  15. #endif
  16. #ifndef CONFIG_MPC83XX_TIMER
  17. #ifndef CONFIG_SYS_WATCHDOG_FREQ
  18. #define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
  19. #endif
  20. static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
  21. static __inline__ unsigned long get_dec (void)
  22. {
  23. unsigned long val;
  24. asm volatile ("mfdec %0":"=r" (val):);
  25. return val;
  26. }
  27. static __inline__ void set_dec (unsigned long val)
  28. {
  29. if (val)
  30. asm volatile ("mtdec %0"::"r" (val));
  31. }
  32. #endif /* !CONFIG_MPC83XX_TIMER */
  33. void enable_interrupts(void)
  34. {
  35. set_msr (get_msr () | MSR_EE);
  36. }
  37. /* returns flag if MSR_EE was set before */
  38. int disable_interrupts(void)
  39. {
  40. ulong msr = get_msr ();
  41. set_msr (msr & ~MSR_EE);
  42. return ((msr & MSR_EE) != 0);
  43. }
  44. #ifndef CONFIG_MPC83XX_TIMER
  45. int interrupt_init(void)
  46. {
  47. /* call cpu specific function from $(CPU)/interrupts.c */
  48. interrupt_init_cpu (&decrementer_count);
  49. set_dec (decrementer_count);
  50. set_msr (get_msr () | MSR_EE);
  51. return (0);
  52. }
  53. static volatile ulong timestamp = 0;
  54. void timer_interrupt(struct pt_regs *regs)
  55. {
  56. /* call cpu specific function from $(CPU)/interrupts.c */
  57. timer_interrupt_cpu (regs);
  58. /* Restore Decrementer Count */
  59. set_dec (decrementer_count);
  60. timestamp++;
  61. #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
  62. if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
  63. WATCHDOG_RESET ();
  64. #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
  65. #ifdef CONFIG_LED_STATUS
  66. status_led_tick(timestamp);
  67. #endif /* CONFIG_LED_STATUS */
  68. }
  69. ulong get_timer (ulong base)
  70. {
  71. return (timestamp - base);
  72. }
  73. #endif /* !CONFIG_MPC83XX_TIMER */