summaryrefstree
path: root/kernel/drivers/bts/cal_bts8895.c
blob: c09a5459a041d26860e7ebe4cb7ab4faaa163183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/* arch/arm/mach-exynos/cal_bts.c
 *
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
 *              http://www.samsung.com/
 *
 * EXYNOS - BTS CAL code.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include "cal_bts8895.h"
#include <linux/soc/samsung/exynos-soc.h>

#define LOG(x, ...)					\
({							\
	seq_printf(buf, x, ##__VA_ARGS__);		\
})

/* for BTS V3.0 Register */

#define TREX_CON				0x000
#define TREX_TIMEOUT				0x010
#define TREX_BLOCK_IDMASK			0x018
#define TREX_BLOCK_IDVALUE			0x01C
#define TREX_RCON				0x020
#define TREX_WCON				0x040
#define TREX_RBLOCK_UPPER			0x024
#define TREX_WBLOCK_UPPER			0x044
#define TREX_RBLOCK_UPPER_NORMAL		0x028
#define TREX_WBLOCK_UPPER_NORMAL		0x048
#define TREX_RBLOCK_UPPER_FULL			0x02C
#define TREX_WBLOCK_UPPER_FULL			0x04C
#define TREX_RBLOCK_UPPER_BUSY			0x030
#define TREX_WBLOCK_UPPER_BUSY			0x050
#define TREX_RBLOCK_UPPER_MAX			0x034
#define TREX_WBLOCK_UPPER_MAX			0x054

/* trex qos register */

#define SCI_CTRL				0x0000
#define VC_NUM0					0x0050
#define VC_NUM1					0x0054
#define VC_NUM2					0x0058
#define VC_NUM3					0x005C
#define TH_IMM_R_0				0x0100
#define TH_IMM_R_1				0x0104
#define TH_IMM_R_2				0x0108
#define TH_IMM_R_3				0x010C
#define TH_IMM_R_4				0x0110
#define TH_IMM_R_5				0x0114
#define TH_IMM_R_6				0x0118
#define TH_IMM_R_7				0x011C
#define TH_IMM_R_8				0x0120
#define TH_IMM_R_9				0x0124
#define TH_IMM_R_10				0x0128
#define TH_IMM_R_11				0x012C
#define TH_IMM_R_12				0x0130
#define TH_IMM_R_13				0x0134
#define TH_IMM_W_0				0x0180
#define TH_IMM_W_1				0x0184
#define TH_IMM_W_2				0x0188
#define TH_IMM_W_3				0x018C
#define TH_IMM_W_4				0x0190
#define TH_IMM_W_5				0x0194
#define TH_IMM_W_6				0x0198
#define TH_IMM_W_7				0x019C
#define TH_IMM_W_8				0x01A0
#define TH_IMM_W_9				0x01A4
#define TH_IMM_W_10				0x01A8
#define TH_IMM_W_11				0x01AC
#define TH_IMM_W_12				0x01B0
#define TH_IMM_W_13				0x01B4
#define TH_HIGH_R_0				0x0200
#define TH_HIGH_R_1				0x0204
#define TH_HIGH_R_2				0x0208
#define TH_HIGH_R_3				0x020C
#define TH_HIGH_R_4				0x0210
#define TH_HIGH_R_5				0x0214
#define TH_HIGH_R_6				0x0218
#define TH_HIGH_R_7				0x021C
#define TH_HIGH_R_8				0x0220
#define TH_HIGH_R_9				0x0224
#define TH_HIGH_R_10				0x0228
#define TH_HIGH_R_11				0x022C
#define TH_HIGH_R_12				0x0230
#define TH_HIGH_R_13				0x0234
#define TH_HIGH_W_0				0x0280
#define TH_HIGH_W_1				0x0284
#define TH_HIGH_W_2				0x0288
#define TH_HIGH_W_3				0x028C
#define TH_HIGH_W_4				0x0290
#define TH_HIGH_W_5				0x0294
#define TH_HIGH_W_6				0x0298
#define TH_HIGH_W_7				0x029C
#define TH_HIGH_W_8				0x02A0
#define TH_HIGH_W_9				0x02A4
#define TH_HIGH_W_10				0x02A8
#define TH_HIGH_W_11				0x02AC
#define TH_HIGH_W_12				0x02B0
#define TH_HIGH_W_13				0x02B4

#define QMAX_THRESHOLD_R			0x0050
#define QMAX_THRESHOLD_W			0x0054

#define SCI_CCMCMDTOKENS0			0x00fc
#define SCI_CCMCMDTOKENS1			0x0110
#define SCI_CCMTOKENRELEASECTL			0x0104

#define SCI_CRP0_CON				0x0204
#define SCI_CRP1_CON				0x022C
#define SCI_CRP2_CON				0x0254

#define SMC_SCHEDCTL_BUNDLE_CTRL4		0x0258

static unsigned int set_mo(unsigned int mo)
{
	if (mo > BTS_MAX_MO || !mo)
		mo = BTS_MAX_MO;
	return mo;
}

void bts_setqos(void __iomem *base, struct bts_status *stat)
{
	unsigned int tmp_reg = 0;
	bool block_en = false;

	if (!base)
		return;

	if (stat->disable) {
		__raw_writel(0x4000, base + TREX_RCON);
		__raw_writel(0x4000, base + TREX_WCON);
		__raw_writel(0x0, base + TREX_CON);
		return;
	}
	__raw_writel(set_mo(stat->rmo), base + TREX_RBLOCK_UPPER);
	__raw_writel(set_mo(stat->wmo), base + TREX_WBLOCK_UPPER);
	if (stat->max_rmo || stat->max_wmo || stat->busy_rmo || stat->busy_wmo)
		block_en = true;
	__raw_writel(set_mo(stat->max_rmo),
		     base + TREX_RBLOCK_UPPER_MAX);
	__raw_writel(set_mo(stat->max_wmo),
		     base + TREX_WBLOCK_UPPER_MAX);
	__raw_writel(set_mo(stat->full_rmo),
		     base + TREX_RBLOCK_UPPER_FULL);
	__raw_writel(set_mo(stat->full_wmo),
		     base + TREX_WBLOCK_UPPER_FULL);
	__raw_writel(set_mo(stat->busy_rmo),
		     base + TREX_RBLOCK_UPPER_BUSY);
	__raw_writel(set_mo(stat->busy_wmo),
		     base + TREX_WBLOCK_UPPER_BUSY);
	if (stat->timeout_en) {
		if (stat->timeout_r > 0xff)
			stat->timeout_r = 0xff;
		if (stat->timeout_w > 0xff)
			stat->timeout_w = 0xff;
		__raw_writel(stat->timeout_w | (stat->timeout_r << 16),
			     base + TREX_TIMEOUT);
	} else {
		__raw_writel(0xff | (0xff << 16),
			     base + TREX_TIMEOUT);
	}
	/* override QoS value */
	tmp_reg |= (1 & !stat->bypass_en) << 8;
	tmp_reg |= (stat->priority & 0xf) << 12;
	/* enable Blocking logic */
	tmp_reg |= (1 & block_en) << 0;
	__raw_writel(tmp_reg, base + TREX_RCON);
	__raw_writel(tmp_reg, base + TREX_WCON);

	__raw_writel(((1 & stat->timeout_en) << 20) | 0x1, base + TREX_CON);
}

void bts_showqos(void __iomem *base, struct seq_file *buf)
{
	if (!base)
		return;
	LOG("CON0x%08X qos(%d,%d)0x%Xr%Xw TO(%d)0x%04Xr%04Xw"
	    "MO(%d,%d)0x%04xr%04xwQbusy0x%04xr%04xwQfull0x%04xr%04xw"
	    "Qmax0x%04xr%04xw\n",
	    __raw_readl(base + TREX_CON),
	    (__raw_readl(base + TREX_RCON) >> 8) & 0x1,
	    (__raw_readl(base + TREX_WCON) >> 8) & 0x1,
	    (__raw_readl(base + TREX_RCON) >> 12) & 0xf,
	    (__raw_readl(base + TREX_WCON) >> 12) & 0xf,
	    (__raw_readl(base + TREX_CON) >> 20) & 0x1,
	    (__raw_readl(base + TREX_TIMEOUT)) & 0xff,
	    (__raw_readl(base + TREX_TIMEOUT) >> 16) & 0xff,
	    __raw_readl(base + TREX_RCON) & 0x1,
	    __raw_readl(base + TREX_WCON) & 0x1,
	    __raw_readl(base + TREX_RBLOCK_UPPER),
	    __raw_readl(base + TREX_WBLOCK_UPPER),
	    __raw_readl(base + TREX_RBLOCK_UPPER_BUSY),
	    __raw_readl(base + TREX_WBLOCK_UPPER_BUSY),
	    __raw_readl(base + TREX_RBLOCK_UPPER_FULL),
	    __raw_readl(base + TREX_WBLOCK_UPPER_FULL),
	    __raw_readl(base + TREX_RBLOCK_UPPER_MAX),
	    __raw_readl(base + TREX_WBLOCK_UPPER_MAX));
}

void bts_trex_init(void __iomem *base)
{
	if (!base)
		return;

	/* high [27:24] mid [19:16] threshold */
	__raw_writel(0x0B050000, base + SCI_CTRL);
	/* disp [5:0] cam [11:6] ISPLP [11:10] SRDZ [13:12] */
	__raw_writel(0x00000A95, base + VC_NUM0);
	__raw_writel(0x0A95C000, base + VC_NUM1);
	__raw_writel(0xC0000000, base + VC_NUM2);
	__raw_writel(0x00000300, base + VC_NUM3);

	__raw_writel(0x0c101010, base + TH_IMM_R_0);
	__raw_writel(0x10100c0c, base + TH_IMM_R_1);
	__raw_writel(0x0c101010, base + TH_IMM_R_6);
	__raw_writel(0x10100c0c, base + TH_IMM_R_7);
	__raw_writel(0x0006000c, base + TH_IMM_W_0);
	__raw_writel(0x10100606, base + TH_IMM_W_1);
	__raw_writel(0x0006000c, base + TH_IMM_W_6);
	__raw_writel(0x10100606, base + TH_IMM_W_7);
	__raw_writel(0x04101010, base + TH_HIGH_R_0);
	__raw_writel(0x10100404, base + TH_HIGH_R_1);
	__raw_writel(0x04101010, base + TH_HIGH_R_6);
	__raw_writel(0x10100404, base + TH_HIGH_R_7);
	__raw_writel(0x02101010, base + TH_HIGH_W_0);
	__raw_writel(0x10100202, base + TH_HIGH_W_1);
	__raw_writel(0x02101010, base + TH_HIGH_W_6);
	__raw_writel(0x10100202, base + TH_HIGH_W_7);
}

void bts_set_qmax(void __iomem *base, unsigned int rmo, unsigned int wmo)
{
	__raw_writel(set_mo(rmo), base + QMAX_THRESHOLD_R);
	__raw_writel(set_mo(wmo), base + QMAX_THRESHOLD_W);

}

void bts_set_tq(void __iomem *base, unsigned int tq)
{
	unsigned int tmp_reg = 0;
	if (tq > 3)
		tq = 0;
	tmp_reg = __raw_readl(base + SCI_CRP0_CON);
	tmp_reg &= ~(0x7 << 20);
	tmp_reg |= tq << 20;
	__raw_writel(tmp_reg, base + SCI_CRP0_CON);
	tmp_reg = __raw_readl(base + SCI_CRP1_CON);
	tmp_reg &= ~(0x7 << 20);
	tmp_reg |= tq << 20;
	__raw_writel(tmp_reg, base + SCI_CRP1_CON);
	tmp_reg = __raw_readl(base + SCI_CRP2_CON);
	tmp_reg &= ~(0x7 << 20);
	tmp_reg |= tq << 20;
	__raw_writel(tmp_reg, base + SCI_CRP2_CON);
}

void bts_set_qbusy(void __iomem *base, unsigned int qbusy)
{
	unsigned int tmp_reg = 0;
	if (qbusy > 0x3f)
		qbusy = 0x3f;
	tmp_reg = __raw_readl(base + SMC_SCHEDCTL_BUNDLE_CTRL4);
	tmp_reg &= ~(0x3f << 16);
	tmp_reg &= ~(0x3f << 24);
	tmp_reg |= qbusy << 16;
	tmp_reg |= qbusy << 24;
	__raw_writel(tmp_reg, base + SMC_SCHEDCTL_BUNDLE_CTRL4);
}

void bts_set_qfull(void __iomem *base, unsigned int qfull_low,
		   unsigned int qfull_high)
{
	unsigned int tmp_reg = 0;
	if (qfull_low > 0x3f)
		qfull_low = 0x3f;
	if (qfull_high < qfull_low)
		qfull_high = qfull_low;
	else if (qfull_high > 0x3f)
		qfull_high = 0x3f;
	tmp_reg = __raw_readl(base + SCI_CCMTOKENRELEASECTL);
	tmp_reg &= ~(0x3f << 6);
	tmp_reg &= ~(0x3f << 12);
	tmp_reg |= qfull_high << 6;
	tmp_reg |= qfull_low << 12;
	__raw_writel(tmp_reg, base + SCI_CCMTOKENRELEASECTL);
}