~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: 02361ba41101b395473ce2874abcccf40f3f1588 (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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2016  Nexell Co., Ltd.
 *
 * Author: junghyun, kim <jhkim@nexell.co.kr>
 */

#include <linux/types.h>
#include <linux/io.h>

#include "s5pxx18_soc_disptop_clk.h"
#include "s5pxx18_soc_disptop.h"

static struct {
	struct nx_disptop_clkgen_register_set *__g_pregister;
} __g_module_variables[NUMBER_OF_DISPTOP_CLKGEN_MODULE] = {
	{ NULL,},
};

int nx_disp_top_clkgen_initialize(void)
{
	static int binit;
	u32 i;

	if (binit == 0) {
		for (i = 0; i < NUMBER_OF_DISPTOP_CLKGEN_MODULE; i++)
			__g_module_variables[i].__g_pregister = NULL;
		binit = 1;
	}
	return 1;
}

u32 nx_disp_top_clkgen_get_number_of_module(void)
{
	return NUMBER_OF_DISPTOP_CLKGEN_MODULE;
}

u32 nx_disp_top_clkgen_get_physical_address(u32 module_index)
{
	static const u32 physical_addr[] =
		PHY_BASEADDR_DISPTOP_CLKGEN_LIST;

	return (u32)physical_addr[module_index];
}

u32 nx_disp_top_clkgen_get_size_of_register_set(void)
{
	return sizeof(struct nx_disptop_clkgen_register_set);
}

void nx_disp_top_clkgen_set_base_address(u32 module_index, void *base_address)
{
	__g_module_variables[module_index].__g_pregister =
	    (struct nx_disptop_clkgen_register_set *)base_address;
}

void *nx_disp_top_clkgen_get_base_address(u32 module_index)
{
	return (void *)__g_module_variables[module_index].__g_pregister;
}

void nx_disp_top_clkgen_set_clock_bclk_mode(u32 module_index,
					    enum nx_bclkmode mode)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	register u32 regvalue;
	u32 clkmode = 0;

	pregister = __g_module_variables[module_index].__g_pregister;
	switch (mode) {
	case nx_bclkmode_disable:
		clkmode = 0;
	case nx_bclkmode_dynamic:
		clkmode = 2;
		break;
	case nx_bclkmode_always:
		clkmode = 3;
		break;
	default:
		break;
	}

	regvalue = pregister->clkenb;
	regvalue &= ~3ul;
	regvalue |= (clkmode & 0x03);

	writel(regvalue, &pregister->clkenb);
}

enum nx_bclkmode nx_disp_top_clkgen_get_clock_bclk_mode(u32 module_index)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	u32 mode = 0;

	pregister = __g_module_variables[module_index].__g_pregister;
	mode = (pregister->clkenb & 3ul);

	switch (mode) {
	case 0:
		return nx_bclkmode_disable;
	case 2:
		return nx_bclkmode_dynamic;
	case 3:
		return nx_bclkmode_always;
	default:
		break;
	}
	return nx_bclkmode_disable;
}

void nx_disp_top_clkgen_set_clock_pclk_mode(u32 module_index,
					    enum nx_pclkmode mode)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	register u32 regvalue;
	const u32 pclkmode_pos = 3;
	u32 clkmode = 0;

	pregister = __g_module_variables[module_index].__g_pregister;
	switch (mode) {
	case nx_pclkmode_dynamic:
		clkmode = 0;
		break;
	case nx_pclkmode_always:
		clkmode = 1;
		break;
	default:
		break;
	}

	regvalue = pregister->clkenb;
	regvalue &= ~(1ul << pclkmode_pos);
	regvalue |= (clkmode & 0x01) << pclkmode_pos;

	writel(regvalue, &pregister->clkenb);
}

enum nx_pclkmode nx_disp_top_clkgen_get_clock_pclk_mode(u32 module_index)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	const u32 pclkmode_pos = 3;

	pregister = __g_module_variables[module_index].__g_pregister;

	if (pregister->clkenb & (1ul << pclkmode_pos))
		return nx_pclkmode_always;

	return nx_pclkmode_dynamic;
}

void nx_disp_top_clkgen_set_clock_source(u32 module_index, u32 index,
					 u32 clk_src)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	register u32 read_value;

	const u32 clksrcsel_pos = 2;
	const u32 clksrcsel_mask = 0x07 << clksrcsel_pos;

	pregister = __g_module_variables[module_index].__g_pregister;

	read_value = pregister->CLKGEN[index << 1];
	read_value &= ~clksrcsel_mask;
	read_value |= clk_src << clksrcsel_pos;

	writel(read_value, &pregister->CLKGEN[index << 1]);
}

u32 nx_disp_top_clkgen_get_clock_source(u32 module_index, u32 index)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	const u32 clksrcsel_pos = 2;
	const u32 clksrcsel_mask = 0x07 << clksrcsel_pos;

	pregister = __g_module_variables[module_index].__g_pregister;

	return (pregister->CLKGEN[index << 1] &
		clksrcsel_mask) >> clksrcsel_pos;
}

void nx_disp_top_clkgen_set_clock_divisor(u32 module_index, u32 index,
					  u32 divisor)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	const u32 clkdiv_pos = 5;
	const u32 clkdiv_mask = 0xff << clkdiv_pos;
	register u32 read_value;

	pregister = __g_module_variables[module_index].__g_pregister;

	read_value = pregister->CLKGEN[index << 1];
	read_value &= ~clkdiv_mask;
	read_value |= (divisor - 1) << clkdiv_pos;
	writel(read_value, &pregister->CLKGEN[index << 1]);
}

u32 nx_disp_top_clkgen_get_clock_divisor(u32 module_index, u32 index)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	const u32 clkdiv_pos = 5;
	const u32 clkdiv_mask = 0xff << clkdiv_pos;

	pregister = __g_module_variables[module_index].__g_pregister;

	return ((pregister->CLKGEN[index << 1] &
		 clkdiv_mask) >> clkdiv_pos) + 1;
}

void nx_disp_top_clkgen_set_clock_divisor_enable(u32 module_index, int enable)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	register u32 read_value;
	const u32 clkgenenb_pos = 2;
	const u32 clkgenenb_mask = 1ul << clkgenenb_pos;

	pregister = __g_module_variables[module_index].__g_pregister;

	read_value = pregister->clkenb;
	read_value &= ~clkgenenb_mask;
	read_value |= (u32)enable << clkgenenb_pos;

	writel(read_value, &pregister->clkenb);
}

int nx_disp_top_clkgen_get_clock_divisor_enable(u32 module_index)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	const u32 clkgenenb_pos = 2;
	const u32 clkgenenb_mask = 1ul << clkgenenb_pos;

	pregister = __g_module_variables[module_index].__g_pregister;

	return (int)((pregister->clkenb &
		      clkgenenb_mask) >> clkgenenb_pos);
}

void nx_disp_top_clkgen_set_clock_out_inv(u32 module_index, u32 index,
					  int out_clk_inv)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	register u32 read_value;
	const u32 outclkinv_pos = 1;
	const u32 outclkinv_mask = 1ul << outclkinv_pos;

	pregister = __g_module_variables[module_index].__g_pregister;

	read_value = pregister->CLKGEN[index << 1];
	read_value &= ~outclkinv_mask;
	read_value |= out_clk_inv << outclkinv_pos;

	writel(read_value, &pregister->CLKGEN[index << 1]);
}

int nx_disp_top_clkgen_get_clock_out_inv(u32 module_index, u32 index)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	const u32 outclkinv_pos = 1;
	const u32 outclkinv_mask = 1ul << outclkinv_pos;

	pregister = __g_module_variables[module_index].__g_pregister;

	return (int)((pregister->CLKGEN[index << 1] &
		      outclkinv_mask) >> outclkinv_pos);
}

int nx_disp_top_clkgen_set_input_inv(u32 module_index,
				     u32 index, int in_clk_inv)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	register u32 read_value;
	const u32 inclkinv_pos = 4 + index;
	const u32 inclkinv_mask = 1ul << inclkinv_pos;

	pregister = __g_module_variables[module_index].__g_pregister;

	read_value = pregister->clkenb;
	read_value &= ~inclkinv_mask;
	read_value |= in_clk_inv << inclkinv_pos;

	writel(read_value, &pregister->clkenb);
	return true;
}

int nx_disp_top_clkgen_get_input_inv(u32 module_index, u32 index)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	const u32 inclkinv_pos = 4 + index;
	const u32 inclkinv_mask = 1ul << inclkinv_pos;

	pregister = __g_module_variables[module_index].__g_pregister;

	return (int)((pregister->clkenb &
		      inclkinv_mask) >> inclkinv_pos);
}

void nx_disp_top_clkgen_set_clock_out_select(u32 module_index, u32 index,
					     int bbypass)
{
	register struct nx_disptop_clkgen_register_set *pregister;
	register u32 read_value;

	pregister = __g_module_variables[module_index].__g_pregister;

	read_value = pregister->CLKGEN[index << 1];
	read_value = read_value & (~0x01);
	read_value = read_value | bbypass;

	writel(read_value, &pregister->CLKGEN[index << 1]);
}