^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0+ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // OWL factor clock driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Copyright (c) 2014 Actions Semi Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // Author: David Liu <liuwei@actions-semi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // Copyright (c) 2018 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) // Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #ifndef _OWL_FACTOR_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define _OWL_FACTOR_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "owl-common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct clk_factor_table {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) unsigned int mul;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) unsigned int div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct owl_factor_hw {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) u32 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) u8 shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) u8 width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) u8 fct_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct clk_factor_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct owl_factor {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct owl_factor_hw factor_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct owl_clk_common common;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define OWL_FACTOR_HW(_reg, _shift, _width, _fct_flags, _table) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .reg = _reg, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .shift = _shift, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .width = _width, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .fct_flags = _fct_flags, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .table = _table, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define OWL_FACTOR(_struct, _name, _parent, _reg, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) _shift, _width, _table, _fct_flags, _flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct owl_factor _struct = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .factor_hw = OWL_FACTOR_HW(_reg, _shift, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) _width, _fct_flags, _table), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .common = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .regmap = NULL, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .hw.init = CLK_HW_INIT(_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) _parent, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) &owl_factor_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) _flags), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define div_mask(d) ((1 << ((d)->width)) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static inline struct owl_factor *hw_to_owl_factor(const struct clk_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct owl_clk_common *common = hw_to_owl_clk_common(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return container_of(common, struct owl_factor, common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) long owl_factor_helper_round_rate(struct owl_clk_common *common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) const struct owl_factor_hw *factor_hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) unsigned long rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) unsigned long *parent_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) unsigned long owl_factor_helper_recalc_rate(struct owl_clk_common *common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) const struct owl_factor_hw *factor_hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) unsigned long parent_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int owl_factor_helper_set_rate(const struct owl_clk_common *common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) const struct owl_factor_hw *factor_hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) unsigned long rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned long parent_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) extern const struct clk_ops owl_factor_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #endif /* _OWL_FACTOR_H_ */