summaryrefslogtreecommitdiff
path: root/bsp/spacemit/dm/clk/ccu_ddn.h
blob: c0f5a7f755b78d3de3b7bf379b6700cbf698921d (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
/*
 * Copyright (c) 2006-2024, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-5-1       GuEe-GUI     first version
 */

#ifndef __CCU_DDN_H__
#define __CCU_DDN_H__

#include "ccu.h"

struct ccu_ddn_tbl
{
    rt_uint32_t num;
    rt_uint32_t den;
};

struct ccu_ddn_info
{
    rt_uint32_t factor;
    rt_uint32_t num_mask;
    rt_uint32_t den_mask;
    rt_uint32_t num_shift;
    rt_uint32_t den_shift;
};

struct ccu_ddn_config
{
    rt_uint32_t tbl_size;
    struct ccu_ddn_tbl *tbl;
    struct ccu_ddn_info *info;
};

struct ccu_ddn
{
    struct ccu_common common;
    struct ccu_ddn_config ddn;
    rt_uint32_t gate;
};

#define PLL_DDN_TBL(_num, _den) \
{                   \
    .num = (_num),  \
    .den = (_den),  \
}

#define _SPACEMIT_CCU_DDN_CONFIG(_info, _table, _size) \
{                                           \
    .info = (struct ccu_ddn_info *)_info,   \
    .tbl = (struct ccu_ddn_tbl *)_table,    \
    .tbl_size = _size,                      \
}

#define SPACEMIT_CCU_DDN(_struct, _name, _parent, _info, _table, \
                        _size, _base_type, _reg_ctrl, _flags) \
struct ccu_ddn _struct =                \
{                                       \
    .ddn = _SPACEMIT_CCU_DDN_CONFIG(_info, _table, _size), \
    .common =                           \
    {                                   \
        .reg_ctrl = _reg_ctrl,          \
        .base_type = _base_type,        \
        .cell.name = _name,             \
        .cell.parent_name = _parent,    \
        .cell.parents_nr = 1,           \
        .cell.ops = &ccu_ddn_ops,       \
        .cell.flags = _flags,           \
    },                                  \
}

#define SPACEMIT_CCU_DDN_GATE(_struct, _name, _parent, _info, _table, _size, \
                              _base_type, _reg_ddn, _reg_gate, _gate_mask, _flags) \
struct ccu_ddn _struct =                \
{                                       \
    .gate   = _gate_mask,               \
    .ddn    = _SPACEMIT_CCU_DDN_CONFIG(_info, _table, _size), \
    .common =                           \
    {                                   \
        .reg_ctrl = _reg_ddn,           \
        .reg_sel = _reg_gate,           \
        .base_type = _base_type,        \
        .cell.name = _name,             \
        .cell.parent_name = _parent,    \
        .cell.parents_nr = 1,           \
        .cell.ops = &ccu_ddn_ops,       \
        .cell.flags = _flags,           \
    }                                   \
}

extern const struct rt_clk_ops ccu_ddn_ops;

rt_inline struct ccu_ddn *cell_to_ccu_ddn(struct rt_clk_cell *cell)
{
    struct ccu_common *common = cell_to_ccu_common(cell);

    return rt_container_of(common, struct ccu_ddn, common);
}

#endif /* __CCU_DDN_H__ */