18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 28c2ecf20Sopenharmony_ci// 38c2ecf20Sopenharmony_ci// OWL divider clock driver 48c2ecf20Sopenharmony_ci// 58c2ecf20Sopenharmony_ci// Copyright (c) 2014 Actions Semi Inc. 68c2ecf20Sopenharmony_ci// Author: David Liu <liuwei@actions-semi.com> 78c2ecf20Sopenharmony_ci// 88c2ecf20Sopenharmony_ci// Copyright (c) 2018 Linaro Ltd. 98c2ecf20Sopenharmony_ci// Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifndef _OWL_DIVIDER_H_ 128c2ecf20Sopenharmony_ci#define _OWL_DIVIDER_H_ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include "owl-common.h" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistruct owl_divider_hw { 178c2ecf20Sopenharmony_ci u32 reg; 188c2ecf20Sopenharmony_ci u8 shift; 198c2ecf20Sopenharmony_ci u8 width; 208c2ecf20Sopenharmony_ci u8 div_flags; 218c2ecf20Sopenharmony_ci struct clk_div_table *table; 228c2ecf20Sopenharmony_ci}; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistruct owl_divider { 258c2ecf20Sopenharmony_ci struct owl_divider_hw div_hw; 268c2ecf20Sopenharmony_ci struct owl_clk_common common; 278c2ecf20Sopenharmony_ci}; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define OWL_DIVIDER_HW(_reg, _shift, _width, _div_flags, _table) \ 308c2ecf20Sopenharmony_ci { \ 318c2ecf20Sopenharmony_ci .reg = _reg, \ 328c2ecf20Sopenharmony_ci .shift = _shift, \ 338c2ecf20Sopenharmony_ci .width = _width, \ 348c2ecf20Sopenharmony_ci .div_flags = _div_flags, \ 358c2ecf20Sopenharmony_ci .table = _table, \ 368c2ecf20Sopenharmony_ci } 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define OWL_DIVIDER(_struct, _name, _parent, _reg, \ 398c2ecf20Sopenharmony_ci _shift, _width, _table, _div_flags, _flags) \ 408c2ecf20Sopenharmony_ci struct owl_divider _struct = { \ 418c2ecf20Sopenharmony_ci .div_hw = OWL_DIVIDER_HW(_reg, _shift, _width, \ 428c2ecf20Sopenharmony_ci _div_flags, _table), \ 438c2ecf20Sopenharmony_ci .common = { \ 448c2ecf20Sopenharmony_ci .regmap = NULL, \ 458c2ecf20Sopenharmony_ci .hw.init = CLK_HW_INIT(_name, \ 468c2ecf20Sopenharmony_ci _parent, \ 478c2ecf20Sopenharmony_ci &owl_divider_ops, \ 488c2ecf20Sopenharmony_ci _flags), \ 498c2ecf20Sopenharmony_ci }, \ 508c2ecf20Sopenharmony_ci } 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic inline struct owl_divider *hw_to_owl_divider(const struct clk_hw *hw) 538c2ecf20Sopenharmony_ci{ 548c2ecf20Sopenharmony_ci struct owl_clk_common *common = hw_to_owl_clk_common(hw); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci return container_of(common, struct owl_divider, common); 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cilong owl_divider_helper_round_rate(struct owl_clk_common *common, 608c2ecf20Sopenharmony_ci const struct owl_divider_hw *div_hw, 618c2ecf20Sopenharmony_ci unsigned long rate, 628c2ecf20Sopenharmony_ci unsigned long *parent_rate); 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ciunsigned long owl_divider_helper_recalc_rate(struct owl_clk_common *common, 658c2ecf20Sopenharmony_ci const struct owl_divider_hw *div_hw, 668c2ecf20Sopenharmony_ci unsigned long parent_rate); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciint owl_divider_helper_set_rate(const struct owl_clk_common *common, 698c2ecf20Sopenharmony_ci const struct owl_divider_hw *div_hw, 708c2ecf20Sopenharmony_ci unsigned long rate, 718c2ecf20Sopenharmony_ci unsigned long parent_rate); 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ciextern const struct clk_ops owl_divider_ops; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#endif /* _OWL_DIVIDER_H_ */ 76