exynos_ppmu.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com/
  4. *
  5. * EXYNOS - PPMU support
  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/types.h>
  13. #include <linux/io.h>
  14. #include "exynos_ppmu.h"
  15. void exynos_ppmu_reset(void __iomem *ppmu_base)
  16. {
  17. __raw_writel(PPMU_CYCLE_RESET | PPMU_COUNTER_RESET, ppmu_base);
  18. __raw_writel(PPMU_ENABLE_CYCLE |
  19. PPMU_ENABLE_COUNT0 |
  20. PPMU_ENABLE_COUNT1 |
  21. PPMU_ENABLE_COUNT2 |
  22. PPMU_ENABLE_COUNT3,
  23. ppmu_base + PPMU_CNTENS);
  24. }
  25. void exynos_ppmu_setevent(void __iomem *ppmu_base, unsigned int ch,
  26. unsigned int evt)
  27. {
  28. __raw_writel(evt, ppmu_base + PPMU_BEVTSEL(ch));
  29. }
  30. void exynos_ppmu_start(void __iomem *ppmu_base)
  31. {
  32. __raw_writel(PPMU_ENABLE, ppmu_base);
  33. }
  34. void exynos_ppmu_stop(void __iomem *ppmu_base)
  35. {
  36. __raw_writel(PPMU_DISABLE, ppmu_base);
  37. }
  38. unsigned int exynos_ppmu_read(void __iomem *ppmu_base, unsigned int ch)
  39. {
  40. unsigned int total;
  41. if (ch == PPMU_PMNCNT3)
  42. total = ((__raw_readl(ppmu_base + PMCNT_OFFSET(ch)) << 8) |
  43. __raw_readl(ppmu_base + PMCNT_OFFSET(ch + 1)));
  44. else
  45. total = __raw_readl(ppmu_base + PMCNT_OFFSET(ch));
  46. return total;
  47. }
  48. void busfreq_mon_reset(struct busfreq_ppmu_data *ppmu_data)
  49. {
  50. unsigned int i;
  51. for (i = 0; i < ppmu_data->ppmu_end; i++) {
  52. void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base;
  53. /* Reset the performance and cycle counters */
  54. exynos_ppmu_reset(ppmu_base);
  55. /* Setup count registers to monitor read/write transactions */
  56. ppmu_data->ppmu[i].event[PPMU_PMNCNT3] = RDWR_DATA_COUNT;
  57. exynos_ppmu_setevent(ppmu_base, PPMU_PMNCNT3,
  58. ppmu_data->ppmu[i].event[PPMU_PMNCNT3]);
  59. exynos_ppmu_start(ppmu_base);
  60. }
  61. }
  62. void exynos_read_ppmu(struct busfreq_ppmu_data *ppmu_data)
  63. {
  64. int i, j;
  65. for (i = 0; i < ppmu_data->ppmu_end; i++) {
  66. void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base;
  67. exynos_ppmu_stop(ppmu_base);
  68. /* Update local data from PPMU */
  69. ppmu_data->ppmu[i].ccnt = __raw_readl(ppmu_base + PPMU_CCNT);
  70. for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) {
  71. if (ppmu_data->ppmu[i].event[j] == 0)
  72. ppmu_data->ppmu[i].count[j] = 0;
  73. else
  74. ppmu_data->ppmu[i].count[j] =
  75. exynos_ppmu_read(ppmu_base, j);
  76. }
  77. }
  78. busfreq_mon_reset(ppmu_data);
  79. }
  80. int exynos_get_busier_ppmu(struct busfreq_ppmu_data *ppmu_data)
  81. {
  82. unsigned int count = 0;
  83. int i, j, busy = 0;
  84. for (i = 0; i < ppmu_data->ppmu_end; i++) {
  85. for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) {
  86. if (ppmu_data->ppmu[i].count[j] > count) {
  87. count = ppmu_data->ppmu[i].count[j];
  88. busy = i;
  89. }
  90. }
  91. }
  92. return busy;
  93. }