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
|
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-3-08 GuEe-GUI the first version
*/
#include "clk-rk-muxgrf.h"
static rt_err_t rockchip_muxgrf_set_parent_common(struct rt_clk_cell *cell, struct rt_syscon *grf,
rt_uint8_t index)
{
rt_uint32_t mask, val;
struct rockchip_clk_cell *rk_cell = cell_to_rockchip_clk_cell(cell);
mask = RT_GENMASK(rk_cell->mux_width + rk_cell->mux_shift - 1, rk_cell->mux_shift);
val = index;
val <<= rk_cell->mux_shift;
if (rk_cell->mux_flags & CLK_MUX_HIWORD_MASK)
{
return rt_syscon_write(grf, rk_cell->muxdiv_offset, val | (mask << 16));
}
return rt_syscon_update_bits(grf, rk_cell->muxdiv_offset, mask, val);
}
static rt_uint8_t rockchip_muxgrf_get_parent_common(struct rt_clk_cell *cell, struct rt_syscon *grf)
{
rt_uint32_t mask, val;
struct rockchip_clk_cell *rk_cell = cell_to_rockchip_clk_cell(cell);
mask = RT_GENMASK(rk_cell->mux_width - 1, 0);
rt_syscon_read(grf, rk_cell->muxdiv_offset, &val);
val >>= rk_cell->mux_shift;
val &= mask;
return val;
}
static rt_err_t rockchip_muxgrf_set_parent(struct rt_clk_cell *cell, rt_uint8_t index)
{
struct rockchip_clk_cell *rk_cell = cell_to_rockchip_clk_cell(cell);
return rockchip_muxgrf_set_parent_common(cell, rk_cell->provider->grf, index);
}
static rt_uint8_t rockchip_muxgrf_get_parent(struct rt_clk_cell *cell)
{
struct rockchip_clk_cell *rk_cell = cell_to_rockchip_clk_cell(cell);
return rockchip_muxgrf_get_parent_common(cell, rk_cell->provider->grf);
}
const struct rt_clk_ops rockchip_muxgrf_clk_ops =
{
.set_parent = rockchip_muxgrf_set_parent,
.get_parent = rockchip_muxgrf_get_parent,
};
static rt_err_t rockchip_muxpmugrf_set_parent(struct rt_clk_cell *cell, rt_uint8_t index)
{
struct rockchip_clk_cell *rk_cell = cell_to_rockchip_clk_cell(cell);
return rockchip_muxgrf_set_parent_common(cell, rk_cell->provider->pmugrf, index);
}
static rt_uint8_t rockchip_muxpmugrf_get_parent(struct rt_clk_cell *cell)
{
struct rockchip_clk_cell *rk_cell = cell_to_rockchip_clk_cell(cell);
return rockchip_muxgrf_get_parent_common(cell, rk_cell->provider->pmugrf);
}
const struct rt_clk_ops rockchip_muxpmugrf_clk_ops =
{
.set_parent = rockchip_muxpmugrf_set_parent,
.get_parent = rockchip_muxpmugrf_get_parent,
};
|