0014-arch-mips-cleanup-cevt-rt3352.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. From e6ed424c36458aff8738fb1fbb0141196678058a Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Mon, 7 Dec 2015 17:17:23 +0100
  4. Subject: [PATCH 14/53] arch: mips: cleanup cevt-rt3352
  5. Signed-off-by: John Crispin <blogic@openwrt.org>
  6. ---
  7. arch/mips/ralink/cevt-rt3352.c | 85 ++++++++++++++++++++++++++--------------
  8. 1 file changed, 56 insertions(+), 29 deletions(-)
  9. --- a/arch/mips/ralink/cevt-rt3352.c
  10. +++ b/arch/mips/ralink/cevt-rt3352.c
  11. @@ -52,7 +52,7 @@ static inline void mt7620_freq_scaling(s
  12. sdev->freq_scale = status;
  13. - pr_info("%s: %s autosleep mode\n", systick.dev.name,
  14. + pr_info("%s: %s autosleep mode\n", sdev->dev.name,
  15. (status) ? ("enable") : ("disable"));
  16. if (status)
  17. rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) | SLEEP_EN, CLK_LUT_CFG);
  18. @@ -60,18 +60,33 @@ static inline void mt7620_freq_scaling(s
  19. rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) & ~SLEEP_EN, CLK_LUT_CFG);
  20. }
  21. +static inline unsigned int read_count(struct systick_device *sdev)
  22. +{
  23. + return ioread32(sdev->membase + SYSTICK_COUNT);
  24. +}
  25. +
  26. +static inline unsigned int read_compare(struct systick_device *sdev)
  27. +{
  28. + return ioread32(sdev->membase + SYSTICK_COMPARE);
  29. +}
  30. +
  31. +static inline void write_compare(struct systick_device *sdev, unsigned int val)
  32. +{
  33. + iowrite32(val, sdev->membase + SYSTICK_COMPARE);
  34. +}
  35. +
  36. static int systick_next_event(unsigned long delta,
  37. struct clock_event_device *evt)
  38. {
  39. struct systick_device *sdev;
  40. - u32 count;
  41. + int res;
  42. sdev = container_of(evt, struct systick_device, dev);
  43. - count = ioread32(sdev->membase + SYSTICK_COUNT);
  44. - count = (count + delta) % SYSTICK_FREQ;
  45. - iowrite32(count, sdev->membase + SYSTICK_COMPARE);
  46. + delta += read_count(sdev);
  47. + write_compare(sdev, delta);
  48. + res = ((int)(read_count(sdev) - delta) >= 0) ? -ETIME : 0;
  49. - return 0;
  50. + return res;
  51. }
  52. static void systick_event_handler(struct clock_event_device *dev)
  53. @@ -81,20 +96,25 @@ static void systick_event_handler(struct
  54. static irqreturn_t systick_interrupt(int irq, void *dev_id)
  55. {
  56. - struct clock_event_device *dev = (struct clock_event_device *) dev_id;
  57. + int ret = 0;
  58. + struct clock_event_device *cdev;
  59. + struct systick_device *sdev;
  60. - dev->event_handler(dev);
  61. + if (read_c0_cause() & STATUSF_IP7) {
  62. + cdev = (struct clock_event_device *) dev_id;
  63. + sdev = container_of(cdev, struct systick_device, dev);
  64. +
  65. + /* Clear Count/Compare Interrupt */
  66. + write_compare(sdev, read_compare(sdev));
  67. + cdev->event_handler(cdev);
  68. + ret = 1;
  69. + }
  70. - return IRQ_HANDLED;
  71. + return IRQ_RETVAL(ret);
  72. }
  73. static struct systick_device systick = {
  74. .dev = {
  75. - /*
  76. - * cevt-r4k uses 300, make sure systick
  77. - * gets used if available
  78. - */
  79. - .rating = 310,
  80. .features = CLOCK_EVT_FEAT_ONESHOT,
  81. .set_next_event = systick_next_event,
  82. .set_state_shutdown = systick_shutdown,
  83. @@ -116,9 +136,9 @@ static int systick_shutdown(struct clock
  84. sdev = container_of(evt, struct systick_device, dev);
  85. if (sdev->irq_requested)
  86. - free_irq(systick.dev.irq, &systick_irqaction);
  87. + remove_irq(systick.dev.irq, &systick_irqaction);
  88. sdev->irq_requested = 0;
  89. - iowrite32(0, systick.membase + SYSTICK_CONFIG);
  90. + iowrite32(CFG_CNT_EN, systick.membase + SYSTICK_CONFIG);
  91. if (systick_freq_scaling)
  92. systick_freq_scaling(sdev, 0);
  93. @@ -145,38 +165,45 @@ static int systick_set_oneshot(struct cl
  94. }
  95. static const struct of_device_id systick_match[] = {
  96. - { .compatible = "ralink,mt7620-systick", .data = mt7620_freq_scaling},
  97. + { .compatible = "ralink,mt7620a-systick", .data = mt7620_freq_scaling},
  98. {},
  99. };
  100. static void __init ralink_systick_init(struct device_node *np)
  101. {
  102. const struct of_device_id *match;
  103. + int rating = 200;
  104. systick.membase = of_iomap(np, 0);
  105. if (!systick.membase)
  106. return;
  107. match = of_match_node(systick_match, np);
  108. - if (match)
  109. + if (match) {
  110. systick_freq_scaling = match->data;
  111. + /*
  112. + * cevt-r4k uses 300, make sure systick
  113. + * gets used if available
  114. + */
  115. + rating = 310;
  116. + }
  117. - systick_irqaction.name = np->name;
  118. - systick.dev.name = np->name;
  119. - clockevents_calc_mult_shift(&systick.dev, SYSTICK_FREQ, 60);
  120. - systick.dev.max_delta_ns = clockevent_delta2ns(0x7fff, &systick.dev);
  121. - systick.dev.min_delta_ns = clockevent_delta2ns(0x3, &systick.dev);
  122. + /* enable counter than register clock source */
  123. + iowrite32(CFG_CNT_EN, systick.membase + SYSTICK_CONFIG);
  124. + clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name,
  125. + SYSTICK_FREQ, rating, 16, clocksource_mmio_readl_up);
  126. +
  127. + /* register clock event */
  128. systick.dev.irq = irq_of_parse_and_map(np, 0);
  129. if (!systick.dev.irq) {
  130. pr_err("%s: request_irq failed", np->name);
  131. return;
  132. }
  133. -
  134. - clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name,
  135. - SYSTICK_FREQ, 301, 16, clocksource_mmio_readl_up);
  136. -
  137. - clockevents_register_device(&systick.dev);
  138. -
  139. + systick_irqaction.name = np->name;
  140. + systick.dev.name = np->name;
  141. + systick.dev.rating = rating;
  142. + systick.dev.cpumask = cpumask_of(0);
  143. + clockevents_config_and_register(&systick.dev, SYSTICK_FREQ, 0x3, 0x7fff);
  144. pr_info("%s: running - mult: %d, shift: %d\n",
  145. np->name, systick.dev.mult, systick.dev.shift);
  146. }