^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2014 Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef __PISTACHIO_CLK_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define __PISTACHIO_CLK_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/clk-provider.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) struct pistachio_gate {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) unsigned long reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) unsigned int shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) const char *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define GATE(_id, _name, _pname, _reg, _shift) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) .id = _id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) .reg = _reg, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) .shift = _shift, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) .name = _name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .parent = _pname, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct pistachio_mux {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) unsigned long reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) unsigned int shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) unsigned int num_parents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) const char **parents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define PNAME(x) static const char *x[] __initconst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define MUX(_id, _name, _pnames, _reg, _shift) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .id = _id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .reg = _reg, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .shift = _shift, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .name = _name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .parents = _pnames, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .num_parents = ARRAY_SIZE(_pnames) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct pistachio_div {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned long reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) unsigned int width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) unsigned int div_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) const char *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define DIV(_id, _name, _pname, _reg, _width) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .id = _id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .reg = _reg, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .width = _width, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .div_flags = 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .name = _name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) .parent = _pname, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define DIV_F(_id, _name, _pname, _reg, _width, _div_flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .id = _id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) .reg = _reg, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) .width = _width, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) .div_flags = _div_flags, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) .name = _name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .parent = _pname, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct pistachio_fixed_factor {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) unsigned int div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) const char *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define FIXED_FACTOR(_id, _name, _pname, _div) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .id = _id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .div = _div, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .name = _name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .parent = _pname, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct pistachio_pll_rate_table {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) unsigned long long fref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) unsigned long long fout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned long long refdiv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) unsigned long long fbdiv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) unsigned long long postdiv1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) unsigned long long postdiv2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) unsigned long long frac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) enum pistachio_pll_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) PLL_GF40LP_LAINT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) PLL_GF40LP_FRAC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct pistachio_pll {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) unsigned long reg_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) enum pistachio_pll_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct pistachio_pll_rate_table *rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) unsigned int nr_rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) const char *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define PLL(_id, _name, _pname, _type, _reg, _rates) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .id = _id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .reg_base = _reg, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .type = _type, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .rates = _rates, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .nr_rates = ARRAY_SIZE(_rates), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .name = _name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) .parent = _pname, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #define PLL_FIXED(_id, _name, _pname, _type, _reg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .id = _id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .reg_base = _reg, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .type = _type, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .rates = NULL, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .nr_rates = 0, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .name = _name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .parent = _pname, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct pistachio_clk_provider {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct device_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct clk_onecell_data clk_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) extern struct pistachio_clk_provider *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) pistachio_clk_alloc_provider(struct device_node *node, unsigned int num_clks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) extern void pistachio_clk_register_provider(struct pistachio_clk_provider *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) extern void pistachio_clk_register_gate(struct pistachio_clk_provider *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct pistachio_gate *gate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) unsigned int num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) extern void pistachio_clk_register_mux(struct pistachio_clk_provider *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct pistachio_mux *mux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) unsigned int num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) extern void pistachio_clk_register_div(struct pistachio_clk_provider *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct pistachio_div *div,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) unsigned int num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) extern void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) pistachio_clk_register_fixed_factor(struct pistachio_clk_provider *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct pistachio_fixed_factor *ff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) unsigned int num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) extern void pistachio_clk_register_pll(struct pistachio_clk_provider *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct pistachio_pll *pll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) unsigned int num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) extern void pistachio_clk_force_enable(struct pistachio_clk_provider *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) unsigned int *clk_ids, unsigned int num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) #endif