1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2024 Jari Sihvola <jsihv@gmx.com> 5 */ 6 7 #ifndef _JH7110_CLK_H_ 8 #define _JH7110_CLK_H_ 9 10 #include <dev/clk/clk.h> 11 12 #define JH7110_CLK_HAS_GATE 0x01 13 #define JH7110_CLK_HAS_MUX 0x02 14 #define JH7110_CLK_HAS_DIV 0x04 15 #define JH7110_CLK_HAS_INV 0x08 16 17 #define AONCRG_RESET_SELECTOR 0x38 18 #define AONCRG_RESET_STATUS 0x3c 19 #define STGCRG_RESET_SELECTOR 0x74 20 #define STGCRG_RESET_STATUS 0x78 21 #define SYSCRG_RESET_SELECTOR 0x2f8 22 #define SYSCRG_RESET_STATUS 0x308 23 24 struct jh7110_clkgen_softc { 25 struct mtx mtx; 26 struct clkdom *clkdom; 27 struct resource *mem_res; 28 uint32_t reset_status_offset; 29 uint32_t reset_selector_offset; 30 }; 31 32 struct jh7110_clk_def { 33 struct clknode_init_def clkdef; 34 uint32_t offset; 35 uint32_t flags; 36 uint64_t d_max; 37 }; 38 39 #define JH7110_CLK(_idx, _name, _pn, _d_max, _flags) \ 40 { \ 41 .clkdef.id = _idx, \ 42 .clkdef.name = _name, \ 43 .clkdef.parent_names = _pn, \ 44 .clkdef.parent_cnt = nitems(_pn), \ 45 .clkdef.flags = CLK_NODE_STATIC_STRINGS, \ 46 .flags = _flags, \ 47 .d_max = _d_max, \ 48 } 49 50 #define JH7110_GATE(_idx, _name, _pn) \ 51 JH7110_CLK(_idx, _name, _pn, 0, JH7110_CLK_HAS_GATE) 52 #define JH7110_MUX(_idx, _name, _pn) \ 53 JH7110_CLK(_idx, _name, _pn, 0, JH7110_CLK_HAS_MUX) 54 #define JH7110_DIV(_idx, _name, _pn, _d_max) \ 55 JH7110_CLK(_idx, _name, _pn, _d_max, JH7110_CLK_HAS_DIV) 56 #define JH7110_GATEMUX(_idx, _name, _pn) \ 57 JH7110_CLK(_idx, _name, _pn, 0, JH7110_CLK_HAS_GATE | \ 58 JH7110_CLK_HAS_MUX) 59 #define JH7110_GATEDIV(_idx, _name, _pn, _d_max) \ 60 JH7110_CLK(_idx, _name, _pn, _d_max, JH7110_CLK_HAS_GATE | \ 61 JH7110_CLK_HAS_DIV) 62 #define JH7110_INV(_idx, _name, _pn) \ 63 JH7110_CLK(_idx, _name, _pn, 0, JH7110_CLK_HAS_INV) 64 65 int jh7110_clk_register(struct clkdom *clkdom, 66 const struct jh7110_clk_def *clkdef); 67 int jh7110_ofw_map(struct clkdom *clkdom, uint32_t ncells, phandle_t *cells, 68 struct clknode **clk); 69 int jh7110_reset_is_asserted(device_t dev, intptr_t id, bool *reset); 70 int jh7110_reset_assert(device_t dev, intptr_t id, bool assert); 71 72 #endif /* _JH7110_CLK_H_ */ 73