exynos_ppmu.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. EXPORT_SYMBOL(busfreq_mon_reset);
  63. void exynos_read_ppmu(struct busfreq_ppmu_data *ppmu_data)
  64. {
  65. int i, j;
  66. for (i = 0; i < ppmu_data->ppmu_end; i++) {
  67. void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base;
  68. exynos_ppmu_stop(ppmu_base);
  69. /* Update local data from PPMU */
  70. ppmu_data->ppmu[i].ccnt = __raw_readl(ppmu_base + PPMU_CCNT);
  71. for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) {
  72. if (ppmu_data->ppmu[i].event[j] == 0)
  73. ppmu_data->ppmu[i].count[j] = 0;
  74. else
  75. ppmu_data->ppmu[i].count[j] =
  76. exynos_ppmu_read(ppmu_base, j);
  77. }
  78. }
  79. busfreq_mon_reset(ppmu_data);
  80. }
  81. EXPORT_SYMBOL(exynos_read_ppmu);
  82. int exynos_get_busier_ppmu(struct busfreq_ppmu_data *ppmu_data)
  83. {
  84. unsigned int count = 0;
  85. int i, j, busy = 0;
  86. for (i = 0; i < ppmu_data->ppmu_end; i++) {
  87. for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) {
  88. if (ppmu_data->ppmu[i].count[j] > count) {
  89. count = ppmu_data->ppmu[i].count[j];
  90. busy = i;
  91. }
  92. }
  93. }
  94. return busy;
  95. }
  96. EXPORT_SYMBOL(exynos_get_busier_ppmu);