0006-MIPS-ralink-add-cpu-frequency-scaling.patch 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. From bd30f19a006fb52bac80c6463c49dd2f4159f4ac Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Sun, 28 Jul 2013 16:26:41 +0200
  4. Subject: [PATCH 06/53] MIPS: ralink: add cpu frequency scaling
  5. This feature will break udelay() and cause the delay loop to have longer delays
  6. when the frequency is scaled causing a performance hit.
  7. Signed-off-by: John Crispin <blogic@openwrt.org>
  8. ---
  9. arch/mips/ralink/cevt-rt3352.c | 38 ++++++++++++++++++++++++++++++++++++++
  10. 1 file changed, 38 insertions(+)
  11. --- a/arch/mips/ralink/cevt-rt3352.c
  12. +++ b/arch/mips/ralink/cevt-rt3352.c
  13. @@ -29,6 +29,10 @@
  14. /* enable the counter */
  15. #define CFG_CNT_EN 0x1
  16. +/* mt7620 frequency scaling defines */
  17. +#define CLK_LUT_CFG 0x40
  18. +#define SLEEP_EN BIT(31)
  19. +
  20. struct systick_device {
  21. void __iomem *membase;
  22. struct clock_event_device dev;
  23. @@ -36,9 +40,26 @@ struct systick_device {
  24. int freq_scale;
  25. };
  26. +static void (*systick_freq_scaling)(struct systick_device *sdev, int status);
  27. +
  28. static int systick_set_oneshot(struct clock_event_device *evt);
  29. static int systick_shutdown(struct clock_event_device *evt);
  30. +static inline void mt7620_freq_scaling(struct systick_device *sdev, int status)
  31. +{
  32. + if (sdev->freq_scale == status)
  33. + return;
  34. +
  35. + sdev->freq_scale = status;
  36. +
  37. + pr_info("%s: %s autosleep mode\n", systick.dev.name,
  38. + (status) ? ("enable") : ("disable"));
  39. + if (status)
  40. + rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) | SLEEP_EN, CLK_LUT_CFG);
  41. + else
  42. + rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) & ~SLEEP_EN, CLK_LUT_CFG);
  43. +}
  44. +
  45. static int systick_next_event(unsigned long delta,
  46. struct clock_event_device *evt)
  47. {
  48. @@ -99,6 +120,9 @@ static int systick_shutdown(struct clock
  49. sdev->irq_requested = 0;
  50. iowrite32(0, systick.membase + SYSTICK_CONFIG);
  51. + if (systick_freq_scaling)
  52. + systick_freq_scaling(sdev, 0);
  53. +
  54. return 0;
  55. }
  56. @@ -114,15 +138,29 @@ static int systick_set_oneshot(struct cl
  57. iowrite32(CFG_EXT_STK_EN | CFG_CNT_EN,
  58. systick.membase + SYSTICK_CONFIG);
  59. + if (systick_freq_scaling)
  60. + systick_freq_scaling(sdev, 1);
  61. +
  62. return 0;
  63. }
  64. +static const struct of_device_id systick_match[] = {
  65. + { .compatible = "ralink,mt7620-systick", .data = mt7620_freq_scaling},
  66. + {},
  67. +};
  68. +
  69. static void __init ralink_systick_init(struct device_node *np)
  70. {
  71. + const struct of_device_id *match;
  72. +
  73. systick.membase = of_iomap(np, 0);
  74. if (!systick.membase)
  75. return;
  76. + match = of_match_node(systick_match, np);
  77. + if (match)
  78. + systick_freq_scaling = match->data;
  79. +
  80. systick_irqaction.name = np->name;
  81. systick.dev.name = np->name;
  82. clockevents_calc_mult_shift(&systick.dev, SYSTICK_FREQ, 60);