time.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/timer64.h>
  22. static u32 sched_clock_multiplier;
  23. #define SCHED_CLOCK_SHIFT 16
  24. static cycle_t tsc_read(struct clocksource *cs)
  25. {
  26. return get_cycles();
  27. }
  28. static struct clocksource clocksource_tsc = {
  29. .name = "timestamp",
  30. .rating = 300,
  31. .read = tsc_read,
  32. .mask = CLOCKSOURCE_MASK(64),
  33. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  34. };
  35. /*
  36. * scheduler clock - returns current time in nanoseconds.
  37. */
  38. u64 sched_clock(void)
  39. {
  40. u64 tsc = get_cycles();
  41. return (tsc * sched_clock_multiplier) >> SCHED_CLOCK_SHIFT;
  42. }
  43. void time_init(void)
  44. {
  45. u64 tmp = (u64)NSEC_PER_SEC << SCHED_CLOCK_SHIFT;
  46. do_div(tmp, c6x_core_freq);
  47. sched_clock_multiplier = tmp;
  48. clocksource_register_hz(&clocksource_tsc, c6x_core_freq);
  49. /* write anything into TSCL to enable counting */
  50. set_creg(TSCL, 0);
  51. /* probe for timer64 event timer */
  52. timer64_init();
  53. }