cyclone.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include <linux/clocksource.h>
  2. #include <linux/string.h>
  3. #include <linux/errno.h>
  4. #include <linux/timex.h>
  5. #include <linux/init.h>
  6. #include <asm/pgtable.h>
  7. #include <asm/io.h>
  8. #include <asm/mach_timer.h>
  9. #define CYCLONE_CBAR_ADDR 0xFEB00CD0 /* base address ptr */
  10. #define CYCLONE_PMCC_OFFSET 0x51A0 /* offset to control register */
  11. #define CYCLONE_MPCS_OFFSET 0x51A8 /* offset to select register */
  12. #define CYCLONE_MPMC_OFFSET 0x51D0 /* offset to count register */
  13. #define CYCLONE_TIMER_FREQ 99780000 /* 100Mhz, but not really */
  14. #define CYCLONE_TIMER_MASK CLOCKSOURCE_MASK(32) /* 32 bit mask */
  15. int use_cyclone = 0;
  16. static void __iomem *cyclone_ptr;
  17. static cycle_t read_cyclone(struct clocksource *cs)
  18. {
  19. return (cycle_t)readl(cyclone_ptr);
  20. }
  21. static struct clocksource clocksource_cyclone = {
  22. .name = "cyclone",
  23. .rating = 250,
  24. .read = read_cyclone,
  25. .mask = CYCLONE_TIMER_MASK,
  26. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  27. };
  28. static int __init init_cyclone_clocksource(void)
  29. {
  30. unsigned long base; /* saved value from CBAR */
  31. unsigned long offset;
  32. u32 __iomem* volatile cyclone_timer; /* Cyclone MPMC0 register */
  33. u32 __iomem* reg;
  34. int i;
  35. /* make sure we're on a summit box: */
  36. if (!use_cyclone)
  37. return -ENODEV;
  38. printk(KERN_INFO "Summit chipset: Starting Cyclone Counter.\n");
  39. /* find base address: */
  40. offset = CYCLONE_CBAR_ADDR;
  41. reg = ioremap_nocache(offset, sizeof(reg));
  42. if (!reg) {
  43. printk(KERN_ERR "Summit chipset: Could not find valid CBAR register.\n");
  44. return -ENODEV;
  45. }
  46. /* even on 64bit systems, this is only 32bits: */
  47. base = readl(reg);
  48. if (!base) {
  49. printk(KERN_ERR "Summit chipset: Could not find valid CBAR value.\n");
  50. return -ENODEV;
  51. }
  52. iounmap(reg);
  53. /* setup PMCC: */
  54. offset = base + CYCLONE_PMCC_OFFSET;
  55. reg = ioremap_nocache(offset, sizeof(reg));
  56. if (!reg) {
  57. printk(KERN_ERR "Summit chipset: Could not find valid PMCC register.\n");
  58. return -ENODEV;
  59. }
  60. writel(0x00000001,reg);
  61. iounmap(reg);
  62. /* setup MPCS: */
  63. offset = base + CYCLONE_MPCS_OFFSET;
  64. reg = ioremap_nocache(offset, sizeof(reg));
  65. if (!reg) {
  66. printk(KERN_ERR "Summit chipset: Could not find valid MPCS register.\n");
  67. return -ENODEV;
  68. }
  69. writel(0x00000001,reg);
  70. iounmap(reg);
  71. /* map in cyclone_timer: */
  72. offset = base + CYCLONE_MPMC_OFFSET;
  73. cyclone_timer = ioremap_nocache(offset, sizeof(u64));
  74. if (!cyclone_timer) {
  75. printk(KERN_ERR "Summit chipset: Could not find valid MPMC register.\n");
  76. return -ENODEV;
  77. }
  78. /* quick test to make sure its ticking: */
  79. for (i = 0; i < 3; i++){
  80. u32 old = readl(cyclone_timer);
  81. int stall = 100;
  82. while (stall--)
  83. barrier();
  84. if (readl(cyclone_timer) == old) {
  85. printk(KERN_ERR "Summit chipset: Counter not counting! DISABLED\n");
  86. iounmap(cyclone_timer);
  87. cyclone_timer = NULL;
  88. return -ENODEV;
  89. }
  90. }
  91. cyclone_ptr = cyclone_timer;
  92. return clocksource_register_hz(&clocksource_cyclone,
  93. CYCLONE_TIMER_FREQ);
  94. }
  95. arch_initcall(init_cyclone_clocksource);