18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2016 Maxime Ripard. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef _CCU_GATE_H_ 78c2ecf20Sopenharmony_ci#define _CCU_GATE_H_ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/clk-provider.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include "ccu_common.h" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistruct ccu_gate { 148c2ecf20Sopenharmony_ci u32 enable; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci struct ccu_common common; 178c2ecf20Sopenharmony_ci}; 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define SUNXI_CCU_GATE(_struct, _name, _parent, _reg, _gate, _flags) \ 208c2ecf20Sopenharmony_ci struct ccu_gate _struct = { \ 218c2ecf20Sopenharmony_ci .enable = _gate, \ 228c2ecf20Sopenharmony_ci .common = { \ 238c2ecf20Sopenharmony_ci .reg = _reg, \ 248c2ecf20Sopenharmony_ci .hw.init = CLK_HW_INIT(_name, \ 258c2ecf20Sopenharmony_ci _parent, \ 268c2ecf20Sopenharmony_ci &ccu_gate_ops, \ 278c2ecf20Sopenharmony_ci _flags), \ 288c2ecf20Sopenharmony_ci } \ 298c2ecf20Sopenharmony_ci } 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define SUNXI_CCU_GATE_HW(_struct, _name, _parent, _reg, _gate, _flags) \ 328c2ecf20Sopenharmony_ci struct ccu_gate _struct = { \ 338c2ecf20Sopenharmony_ci .enable = _gate, \ 348c2ecf20Sopenharmony_ci .common = { \ 358c2ecf20Sopenharmony_ci .reg = _reg, \ 368c2ecf20Sopenharmony_ci .hw.init = CLK_HW_INIT_HW(_name, \ 378c2ecf20Sopenharmony_ci _parent, \ 388c2ecf20Sopenharmony_ci &ccu_gate_ops, \ 398c2ecf20Sopenharmony_ci _flags), \ 408c2ecf20Sopenharmony_ci } \ 418c2ecf20Sopenharmony_ci } 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define SUNXI_CCU_GATE_FW(_struct, _name, _parent, _reg, _gate, _flags) \ 448c2ecf20Sopenharmony_ci struct ccu_gate _struct = { \ 458c2ecf20Sopenharmony_ci .enable = _gate, \ 468c2ecf20Sopenharmony_ci .common = { \ 478c2ecf20Sopenharmony_ci .reg = _reg, \ 488c2ecf20Sopenharmony_ci .hw.init = CLK_HW_INIT_FW_NAME(_name, \ 498c2ecf20Sopenharmony_ci _parent, \ 508c2ecf20Sopenharmony_ci &ccu_gate_ops, \ 518c2ecf20Sopenharmony_ci _flags), \ 528c2ecf20Sopenharmony_ci } \ 538c2ecf20Sopenharmony_ci } 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/* 568c2ecf20Sopenharmony_ci * The following two macros allow the re-use of the data structure 578c2ecf20Sopenharmony_ci * holding the parent info. 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_ci#define SUNXI_CCU_GATE_HWS(_struct, _name, _parent, _reg, _gate, _flags) \ 608c2ecf20Sopenharmony_ci struct ccu_gate _struct = { \ 618c2ecf20Sopenharmony_ci .enable = _gate, \ 628c2ecf20Sopenharmony_ci .common = { \ 638c2ecf20Sopenharmony_ci .reg = _reg, \ 648c2ecf20Sopenharmony_ci .hw.init = CLK_HW_INIT_HWS(_name, \ 658c2ecf20Sopenharmony_ci _parent, \ 668c2ecf20Sopenharmony_ci &ccu_gate_ops, \ 678c2ecf20Sopenharmony_ci _flags), \ 688c2ecf20Sopenharmony_ci } \ 698c2ecf20Sopenharmony_ci } 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define SUNXI_CCU_GATE_DATA(_struct, _name, _data, _reg, _gate, _flags) \ 728c2ecf20Sopenharmony_ci struct ccu_gate _struct = { \ 738c2ecf20Sopenharmony_ci .enable = _gate, \ 748c2ecf20Sopenharmony_ci .common = { \ 758c2ecf20Sopenharmony_ci .reg = _reg, \ 768c2ecf20Sopenharmony_ci .hw.init = \ 778c2ecf20Sopenharmony_ci CLK_HW_INIT_PARENTS_DATA(_name, \ 788c2ecf20Sopenharmony_ci _data, \ 798c2ecf20Sopenharmony_ci &ccu_gate_ops, \ 808c2ecf20Sopenharmony_ci _flags), \ 818c2ecf20Sopenharmony_ci } \ 828c2ecf20Sopenharmony_ci } 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistatic inline struct ccu_gate *hw_to_ccu_gate(struct clk_hw *hw) 858c2ecf20Sopenharmony_ci{ 868c2ecf20Sopenharmony_ci struct ccu_common *common = hw_to_ccu_common(hw); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci return container_of(common, struct ccu_gate, common); 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_civoid ccu_gate_helper_disable(struct ccu_common *common, u32 gate); 928c2ecf20Sopenharmony_ciint ccu_gate_helper_enable(struct ccu_common *common, u32 gate); 938c2ecf20Sopenharmony_ciint ccu_gate_helper_is_enabled(struct ccu_common *common, u32 gate); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ciextern const struct clk_ops ccu_gate_ops; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#endif /* _CCU_GATE_H_ */ 98