| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
/* |
| 3 |
* Copyright (c) 2024 SpacemiT Technology Co. Ltd |
| 4 |
* Copyright (c) 2024-2025 Haylen Chu <[email protected]> |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef _CCU_DDN_H_ |
| 8 |
#define _CCU_DDN_H_ |
| 9 |
|
| 10 |
#include <linux/bitops.h> |
| 11 |
#include <linux/clk-provider.h> |
| 12 |
|
| 13 |
#include "ccu_common.h" |
| 14 |
|
| 15 |
struct ccu_ddn { |
| 16 |
struct ccu_common common; |
| 17 |
unsigned int num_mask; |
| 18 |
unsigned int num_shift; |
| 19 |
unsigned int den_mask; |
| 20 |
unsigned int den_shift; |
| 21 |
unsigned int pre_div; |
| 22 |
}; |
| 23 |
|
| 24 |
#define CCU_DDN_INIT(_name, _parent, _flags) \ |
| 25 |
CLK_HW_INIT_HW(#_name, &_parent.common.hw, &spacemit_ccu_ddn_ops, _flags) |
| 26 |
|
| 27 |
#define CCU_DDN_DEFINE(_name, _parent, _reg_ctrl, _num_shift, _num_width, \ |
| 28 |
_den_shift, _den_width, _pre_div, _flags) \ |
| 29 |
static struct ccu_ddn _name = { \ |
| 30 |
.common = { \ |
| 31 |
.reg_ctrl = _reg_ctrl, \ |
| 32 |
.hw.init = CCU_DDN_INIT(_name, _parent, _flags), \ |
| 33 |
}, \ |
| 34 |
.num_mask = GENMASK(_num_shift + _num_width - 1, _num_shift), \ |
| 35 |
.num_shift = _num_shift, \ |
| 36 |
.den_mask = GENMASK(_den_shift + _den_width - 1, _den_shift), \ |
| 37 |
.den_shift = _den_shift, \ |
| 38 |
.pre_div = _pre_div, \ |
| 39 |
} |
| 40 |
|
| 41 |
static inline struct ccu_ddn *hw_to_ccu_ddn(struct clk_hw *hw) |
| 42 |
{ |
| 43 |
struct ccu_common *common = hw_to_ccu_common(hw); |
| 44 |
|
| 45 |
return container_of(common, struct ccu_ddn, common); |
| 46 |
} |
| 47 |
|
| 48 |
extern const struct clk_ops spacemit_ccu_ddn_ops; |
| 49 |
|
| 50 |
#endif |