summaryrefstree
path: root/kernel/drivers/vision/dsp/hardware/exynos9830/dsp-hw-clk.c
blob: 8cdc4500594746078d89831ce3ad775d95417ea3 (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
// SPDX-License-Identifier: GPL-2.0
/*
 * Samsung Exynos SoC series dsp driver
 *
 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
 *              http://www.samsung.com/
 */

#include "dsp-log.h"
#include "hardware/dsp-system.h"
#include "hardware/dsp-clk.h"

static struct dsp_clk_format clk_array[] = {
	{ NULL, "dnc_bus" },
	{ NULL, "dnc_busm" }, // 1
	{ NULL, "dnc" }, // 2
	{ NULL, "dspc" },
	{ NULL, "out_dnc_bus" },
	{ NULL, "out_dnc_busp" },
	{ NULL, "dsp_bus0" },
	{ NULL, "dsp0" }, // 7
	{ NULL, "out_dsp_bus0" },
	{ NULL, "out_dsp_busp0" },
	{ NULL, "dsp_bus1" },
	{ NULL, "dsp1" }, // 11
	{ NULL, "out_dsp_bus1" },
	{ NULL, "out_dsp_busp1" },
	{ NULL, "dsp_bus2" },
	{ NULL, "dsp2" }, // 15
	{ NULL, "out_dsp_bus2" },
	{ NULL, "out_dsp_busp2" },
};

void dsp_clk_dump(struct dsp_clk *clk)
{
	long count;
	const char *name;
	unsigned long freq;

	dsp_enter();
	for (count = 0; count < ARRAY_SIZE(clk_array); ++count) {
		/* Only output each core and DMA */
		if ((count != 1) && (count != 2) && (count != 7) &&
				(count != 11) && (count != 15))
			continue;

		name = clk_array[count].name;
		freq = clk_get_rate(clk_array[count].clk);
		dsp_dbg("%15s(%02ld) : %3lu.%06lu MHz\n",
				name, count, freq / 1000000, freq % 1000000);
	}

	dsp_leave();
}

void dsp_clk_user_dump(struct dsp_clk *clk, struct seq_file *file)
{
	long count;
	const char *name;
	unsigned long freq;

	dsp_enter();
	for (count = 0; count < ARRAY_SIZE(clk_array); ++count) {
		name = clk_array[count].name;
		freq = clk_get_rate(clk_array[count].clk);
		seq_printf(file, "%15s(%ld) : %3lu.%06lu MHz\n",
				name, count, freq / 1000000, freq % 1000000);
	}

	dsp_leave();
}

int dsp_clk_enable(struct dsp_clk *clk)
{
	int ret;
	long count;

	dsp_enter();
	for (count = 0; count < ARRAY_SIZE(clk_array); ++count) {
		ret = clk_prepare_enable(clk_array[count].clk);
		if (ret) {
			dsp_err("Failed to enable [%s(%ld/%lu)]clk(%d)\n",
					clk_array[count].name, count,
					ARRAY_SIZE(clk_array), ret);
			goto p_err;
		}
	}

	dsp_clk_dump(clk);
	dsp_leave();
	return 0;
p_err:
	for (count -= 1; count >= 0; --count)
		clk_disable_unprepare(clk_array[count].clk);

	return ret;
}

int dsp_clk_disable(struct dsp_clk *clk)
{
	long count;

	dsp_enter();
	for (count = 0; count < ARRAY_SIZE(clk_array); ++count)
		clk_disable_unprepare(clk_array[count].clk);

	dsp_leave();
	return 0;
}

int dsp_clk_open(struct dsp_clk *clk)
{
	dsp_enter();
	dsp_leave();
	return 0;
}

int dsp_clk_close(struct dsp_clk *clk)
{
	dsp_enter();
	dsp_leave();
	return 0;
}

int dsp_clk_probe(struct dsp_system *sys)
{
	int ret;
	struct dsp_clk *clk;
	long count;

	dsp_enter();
	clk = &sys->clk;
	clk->dev = sys->dev;
	clk->array = clk_array;

	for (count = 0; count < ARRAY_SIZE(clk_array); ++count) {
		clk_array[count].clk = devm_clk_get(clk->dev,
				clk_array[count].name);
		if (IS_ERR(clk_array[count].clk)) {
			ret = IS_ERR(clk_array[count].clk);
			dsp_err("Failed to get [%s(%ld/%lu)]clk(%d)\n",
					clk_array[count].name, count,
					ARRAY_SIZE(clk_array), ret);
			goto p_err;
		}
	}

	dsp_leave();
	return 0;
p_err:
	return ret;
}

void dsp_clk_remove(struct dsp_clk *clk)
{
	dsp_enter();
	dsp_leave();
}