summaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorHoang Pham <hopham@nvidia.com>2017-06-11 05:10:27 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-06-01 07:10:27 -0400
commitc9b265a519a1afabd5faca58ab2363c0df336e44 (patch)
treee46ecd2f28dadcefa0004e808c7f22bf2b13622c /include/linux
parentb72a24f17895f466112373d564cdf6a52f81a02f (diff)
tegra: central_actmon: refactor driver
- Convert module platform actmon common driver into actmon core driver - Convert dependent drivers into SoCs module platform actmon drivers - This allows for the kernel to support multiple SoCs without a namespace clash avoiding need for different compile time options and no need to change actmon core driver for future chips Reviewed-on: http://git-master/r/1268709 (cherry picked from commit 7198bd1f18319d867f541f63cc282ac90a290e8f) Change-Id: I9ff5966c090b8faf3c6f2cc5c6a0308b864b9f7e Reviewed-on: https://git-master.nvidia.com/r/1499976 Reviewed-by: Timo Alho <talho@nvidia.com> Tested-by: Timo Alho <talho@nvidia.com> Signed-off-by: Hoang Pham <hopham@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1730873 GVS: Gerrit_Virtual_Submit Reviewed-by: Sachin Nikam <snikam@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/platform/tegra/actmon_common.h192
1 files changed, 192 insertions, 0 deletions
diff --git a/include/linux/platform/tegra/actmon_common.h b/include/linux/platform/tegra/actmon_common.h
new file mode 100644
index 000000000..b3a76d0b8
--- /dev/null
+++ b/include/linux/platform/tegra/actmon_common.h
@@ -0,0 +1,192 @@
1/*
2 * Copyright (C) 2016-2018, NVIDIA Corporation. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14#ifndef ACTMON_COMMON_H
15
16#include <asm/io.h>
17
18/* START: These device register offsets have common value across socs */
19#define ACTMON_CMN_DEV_CTRL 0x00
20#define ACTMON_CMN_DEV_CTRL_ENB (0x1 << 31)
21#define ACTMON_CMN_DEV_CTRL_UP_WMARK_NUM_SHIFT 26
22#define ACTMON_CMN_DEV_CTRL_UP_WMARK_NUM_MASK (0x7 << 26)
23#define ACTMON_CMN_DEV_CTRL_DOWN_WMARK_NUM_SHIFT 21
24#define ACTMON_CMN_DEV_CTRL_DOWN_WMARK_NUM_MASK (0x7 << 21)
25
26/* Common dev interrupt status bits across socs */
27#define ACTMON_CMN_DEV_INTR_UP_WMARK (0x1 << 31)
28#define ACTMON_CMN_DEV_INTR_DOWN_WMARK (0x1 << 30)
29/* END: common device regs across socs */
30
31#define ACTMON_DEFAULT_AVG_WINDOW_LOG2 7
32#define ACTMON_DEFAULT_AVG_BAND 6 /* 1/10 of % */
33#define ACTMON_DEFAULT_SAMPLING_PERIOD 7
34
35#define DEFAULT_SUSPEND_FREQ 204000
36#define DEFAULT_BOOST_UP_COEF 200
37#define DEFAULT_BOOST_DOWN_COEF 50
38#define DEFAULT_BOOST_UP_THRESHOLD 30
39#define DEFAULT_BOOST_DOWN_THRESHOLD 20
40#define DEFAULT_UP_WMARK_WINDOW 3
41#define DEFAULT_DOWN_WMARK_WINDOW 2
42#define DEFAULT_EWMA_COEF_K 6
43#define DEFAULT_COUNT_WEIGHT 0x53
44#define FREQ_SAMPLER 1
45#define LOAD_SAMPLER 0
46#define DEFAULT_ACTMON_TYPE FREQ_SAMPLER
47/* Maximum frequency EMC is running at when sourced from PLLP. This is
48 * really a short-cut, but it is true for all Tegra3 platforms
49 */
50#define EMC_PLLP_FREQ_MAX 204000
51
52enum actmon_devices {
53 MC_ALL, /* Should match with device sequence in dt */
54 MAX_DEVICES,
55};
56
57enum actmon_type {
58 ACTMON_LOAD_SAMPLER,
59 ACTMON_FREQ_SAMPLER,
60};
61
62enum actmon_state {
63 ACTMON_UNINITIALIZED = -1,
64 ACTMON_OFF = 0,
65 ACTMON_ON = 1,
66 ACTMON_SUSPENDED = 2,
67};
68struct actmon_dev;
69struct actmon_drv_data;
70struct dev_reg_ops {
71 void (*set_init_avg)(u32 value, void __iomem *base);
72 void (*set_avg_up_wm)(u32 value, void __iomem *base);
73 void (*set_avg_dn_wm)(u32 value, void __iomem *base);
74 void (*set_dev_up_wm)(u32 value, void __iomem *base);
75 void (*set_dev_dn_wm)(u32 value, void __iomem *base);
76 void (*enb_dev_wm)(u32 *value);
77 void (*disb_dev_up_wm)(u32 *value);
78 void (*disb_dev_dn_wm)(u32 *value);
79 void (*set_intr_st)(u32 value, void __iomem *base);
80 void (*init_dev_cntrl)(struct actmon_dev *, void __iomem *base);
81 void (*enb_dev_intr)(u32 value, void __iomem *base);
82 void (*enb_dev_intr_all)(void __iomem *base);
83 void (*set_cnt_wt)(u32 value, void __iomem *base);
84 u32 (*get_intr_st)(void __iomem *base);
85 u32 (*get_dev_intr_enb)(void __iomem *base);
86 u32 (*get_dev_intr)(void __iomem *base);
87 u32 (*get_raw_cnt)(void __iomem *base);
88 u32 (*get_avg_cnt)(void __iomem *base);
89 u32 (*get_cum_cnt)(void __iomem *base);
90};
91
92/* Units:
93 * - frequency in kHz
94 * - coefficients, and thresholds in %
95 * - sampling period in ms
96 * - window in sample periods (value = setting + 1)
97 */
98struct actmon_dev {
99 struct device_node *dn;
100 u32 reg_offs;
101 u32 glb_status_irq_mask;
102 const char *dev_name;
103 const char *con_id;
104 void *clnt;
105
106 unsigned long max_freq;
107 unsigned long target_freq;
108 unsigned long cur_freq;
109 unsigned long suspend_freq;
110
111 unsigned long avg_actv_freq;
112 unsigned long avg_band_freq;
113 unsigned int avg_sustain_coef;
114 u32 avg_count;
115 u32 avg_dependency_threshold;
116
117 unsigned long boost_freq;
118 unsigned long boost_freq_step;
119 unsigned int boost_up_coef;
120 unsigned int boost_down_coef;
121 unsigned int boost_up_threshold;
122 unsigned int boost_down_threshold;
123
124 u8 up_wmark_window;
125 u8 down_wmark_window;
126 u8 avg_window_log2;
127 u32 count_weight;
128
129 enum actmon_type type;
130 enum actmon_state state;
131 enum actmon_state saved_state;
132
133 struct dev_reg_ops ops;
134 void (*actmon_dev_set_rate)(struct actmon_dev *, unsigned long);
135 unsigned long (*actmon_dev_get_rate)(struct actmon_dev *);
136 unsigned long (*actmon_dev_post_change_rate)(struct actmon_dev *,
137 void *v);
138 void (*actmon_dev_clk_enable)(struct actmon_dev *);
139 spinlock_t lock;
140 struct notifier_block rate_change_nb;
141 struct kobj_attribute avgact_attr;
142};
143
144struct actmon_reg_ops {
145 void (*set_sample_prd)(u32 value, void __iomem *base);
146 void (*set_glb_intr)(u32 value, void __iomem *base);
147 u32 (*get_glb_intr_st)(void __iomem *base);
148};
149struct actmon_drv_data {
150 void __iomem *base;
151 struct platform_device *pdev;
152 int virq;
153 struct clk *actmon_clk;
154 u8 sample_period;
155 unsigned long freq;
156 struct reset_control *actmon_rst;
157 struct actmon_dev devices[MAX_DEVICES];
158 int (*actmon_dev_platform_init)(struct actmon_dev *adev,
159 struct platform_device *pdev);
160 int (*clock_init)(struct platform_device *pdev);
161 int (*clock_deinit)(struct platform_device *pdev);
162 int (*reset_init)(struct platform_device *pdev);
163 int (*reset_deinit)(struct platform_device *pdev);
164 void (*dev_free_resource)(struct actmon_dev *adev,
165 struct platform_device *pdev);
166 struct actmon_reg_ops ops;
167#ifdef CONFIG_DEBUG_FS
168 struct dentry *dfs_root;
169#endif
170 struct kobject *actmon_kobj;
171};
172
173static inline void actmon_wmb(void)
174{
175 dsb(sy);
176}
177
178static inline u32 actmon_dev_readl(void __iomem *base,
179 u32 offset)
180{
181 return __raw_readl(base + offset);
182}
183
184static inline void actmon_dev_writel(void __iomem *base, u32
185 offset, u32 val)
186{
187 __raw_writel(val, base + offset);
188}
189
190int tegra_actmon_register(struct actmon_drv_data *actmon);
191int tegra_actmon_remove(struct platform_device *pdev);
192#endif /* ACTMON_COMMON_H */