0021-MIPS-ralink-add-cpu-frequency-scaling.patch 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. From e76ecd496c9b074ab21b17f12494d823a407e89a 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 21/57] 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 | 36 ++++++++++++++++++++++++++++++++++++
  10. 1 file changed, 36 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,6 +40,8 @@ struct systick_device {
  24. int freq_scale;
  25. };
  26. +static void (*systick_freq_scaling)(struct systick_device *sdev, int status);
  27. +
  28. static void systick_set_clock_mode(enum clock_event_mode mode,
  29. struct clock_event_device *evt);
  30. @@ -87,6 +93,21 @@ static struct irqaction systick_irqactio
  31. .dev_id = &systick.dev,
  32. };
  33. +static inline void mt7620_freq_scaling(struct systick_device *sdev, int status)
  34. +{
  35. + if (sdev->freq_scale == status)
  36. + return;
  37. +
  38. + sdev->freq_scale = status;
  39. +
  40. + pr_info("%s: %s autosleep mode\n", systick.dev.name,
  41. + (status) ? ("enable") : ("disable"));
  42. + if (status)
  43. + rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) | SLEEP_EN, CLK_LUT_CFG);
  44. + else
  45. + rt_sysc_w32(rt_sysc_r32(CLK_LUT_CFG) & ~SLEEP_EN, CLK_LUT_CFG);
  46. +}
  47. +
  48. static void systick_set_clock_mode(enum clock_event_mode mode,
  49. struct clock_event_device *evt)
  50. {
  51. @@ -101,9 +122,13 @@ static void systick_set_clock_mode(enum
  52. sdev->irq_requested = 1;
  53. iowrite32(CFG_EXT_STK_EN | CFG_CNT_EN,
  54. systick.membase + SYSTICK_CONFIG);
  55. + if (systick_freq_scaling)
  56. + systick_freq_scaling(sdev, 1);
  57. break;
  58. case CLOCK_EVT_MODE_SHUTDOWN:
  59. + if (systick_freq_scaling)
  60. + systick_freq_scaling(sdev, 0);
  61. if (sdev->irq_requested)
  62. free_irq(systick.dev.irq, &systick_irqaction);
  63. sdev->irq_requested = 0;
  64. @@ -116,12 +141,23 @@ static void systick_set_clock_mode(enum
  65. }
  66. }
  67. +static const struct of_device_id systick_match[] = {
  68. + { .compatible = "ralink,mt7620-systick", .data = mt7620_freq_scaling},
  69. + {},
  70. +};
  71. +
  72. static void __init ralink_systick_init(struct device_node *np)
  73. {
  74. + const struct of_device_id *match;
  75. +
  76. systick.membase = of_iomap(np, 0);
  77. if (!systick.membase)
  78. return;
  79. + match = of_match_node(systick_match, np);
  80. + if (match)
  81. + systick_freq_scaling = match->data;
  82. +
  83. systick_irqaction.name = np->name;
  84. systick.dev.name = np->name;
  85. clockevents_calc_mult_shift(&systick.dev, SYSTICK_FREQ, 60);