time.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Port on Texas Instruments TMS320C6x architecture
  3. *
  4. * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
  5. * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/clocksource.h>
  13. #include <linux/errno.h>
  14. #include <linux/sched.h>
  15. #include <linux/param.h>
  16. #include <linux/string.h>
  17. #include <linux/mm.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/timex.h>
  20. #include <linux/profile.h>
  21. #include <asm/special_insns.h>
  22. #include <asm/timer64.h>
  23. static u32 sched_clock_multiplier;
  24. #define SCHED_CLOCK_SHIFT 16
  25. static cycle_t tsc_read(struct clocksource *cs)
  26. {
  27. return get_cycles();
  28. }
  29. static struct clocksource clocksource_tsc = {
  30. .name = "timestamp",
  31. .rating = 300,
  32. .read = tsc_read,
  33. .mask = CLOCKSOURCE_MASK(64),
  34. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  35. };
  36. /*
  37. * scheduler clock - returns current time in nanoseconds.
  38. */
  39. u64 sched_clock(void)
  40. {
  41. u64 tsc = get_cycles();
  42. return (tsc * sched_clock_multiplier) >> SCHED_CLOCK_SHIFT;
  43. }
  44. void __init time_init(void)
  45. {
  46. u64 tmp = (u64)NSEC_PER_SEC << SCHED_CLOCK_SHIFT;
  47. do_div(tmp, c6x_core_freq);
  48. sched_clock_multiplier = tmp;
  49. clocksource_register_hz(&clocksource_tsc, c6x_core_freq);
  50. /* write anything into TSCL to enable counting */
  51. set_creg(TSCL, 0);
  52. /* probe for timer64 event timer */
  53. timer64_init();
  54. }