Carlo Caione | 7a29a86 | 2015-06-01 13:13:53 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Endless Mobile, Inc. |
| 3 | * Author: Carlo Caione <carlo@endlessm.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #ifndef __CLKC_H |
| 19 | #define __CLKC_H |
| 20 | |
| 21 | #define PMASK(width) GENMASK(width - 1, 0) |
| 22 | #define SETPMASK(width, shift) GENMASK(shift + width - 1, shift) |
| 23 | #define CLRPMASK(width, shift) (~SETPMASK(width, shift)) |
| 24 | |
| 25 | #define PARM_GET(width, shift, reg) \ |
| 26 | (((reg) & SETPMASK(width, shift)) >> (shift)) |
| 27 | #define PARM_SET(width, shift, reg, val) \ |
| 28 | (((reg) & CLRPMASK(width, shift)) | (val << (shift))) |
| 29 | |
| 30 | #define MESON_PARM_APPLICABLE(p) (!!((p)->width)) |
| 31 | |
| 32 | struct parm { |
| 33 | u16 reg_off; |
| 34 | u8 shift; |
| 35 | u8 width; |
| 36 | }; |
Michael Turquette | ec623f2 | 2016-04-28 12:01:42 -0700 | [diff] [blame^] | 37 | |
| 38 | #define PARM(_r, _s, _w) \ |
| 39 | { \ |
| 40 | .reg_off = (_r), \ |
| 41 | .shift = (_s), \ |
| 42 | .width = (_w), \ |
| 43 | } \ |
Carlo Caione | 7a29a86 | 2015-06-01 13:13:53 +0200 | [diff] [blame] | 44 | |
| 45 | struct pll_rate_table { |
| 46 | unsigned long rate; |
| 47 | u16 m; |
| 48 | u16 n; |
| 49 | u16 od; |
| 50 | }; |
| 51 | #define PLL_RATE(_r, _m, _n, _od) \ |
| 52 | { \ |
| 53 | .rate = (_r), \ |
| 54 | .m = (_m), \ |
| 55 | .n = (_n), \ |
| 56 | .od = (_od), \ |
| 57 | } \ |
| 58 | |
Michael Turquette | ec623f2 | 2016-04-28 12:01:42 -0700 | [diff] [blame^] | 59 | struct meson_clk_pll { |
| 60 | struct clk_hw hw; |
| 61 | void __iomem *base; |
| 62 | struct parm m; |
| 63 | struct parm n; |
| 64 | struct parm od; |
| 65 | const struct pll_rate_table *rate_table; |
| 66 | unsigned int rate_count; |
| 67 | spinlock_t *lock; |
Carlo Caione | 7a29a86 | 2015-06-01 13:13:53 +0200 | [diff] [blame] | 68 | }; |
| 69 | |
Michael Turquette | ec623f2 | 2016-04-28 12:01:42 -0700 | [diff] [blame^] | 70 | #define to_meson_clk_pll(_hw) container_of(_hw, struct meson_clk_pll, hw) |
| 71 | |
Carlo Caione | 7a29a86 | 2015-06-01 13:13:53 +0200 | [diff] [blame] | 72 | struct fixed_fact_conf { |
| 73 | unsigned int div; |
| 74 | unsigned int mult; |
| 75 | struct parm div_parm; |
| 76 | struct parm mult_parm; |
| 77 | }; |
| 78 | |
Carlo Caione | 7a29a86 | 2015-06-01 13:13:53 +0200 | [diff] [blame] | 79 | struct composite_conf { |
| 80 | struct parm mux_parm; |
| 81 | struct parm div_parm; |
| 82 | struct parm gate_parm; |
| 83 | struct clk_div_table *div_table; |
| 84 | u32 *mux_table; |
| 85 | u8 mux_flags; |
| 86 | u8 div_flags; |
| 87 | u8 gate_flags; |
| 88 | }; |
| 89 | |
| 90 | #define PNAME(x) static const char *x[] |
| 91 | |
| 92 | enum clk_type { |
| 93 | CLK_FIXED_FACTOR, |
Carlo Caione | 7a29a86 | 2015-06-01 13:13:53 +0200 | [diff] [blame] | 94 | CLK_COMPOSITE, |
| 95 | CLK_CPU, |
Carlo Caione | 7a29a86 | 2015-06-01 13:13:53 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | struct clk_conf { |
| 99 | u16 reg_off; |
| 100 | enum clk_type clk_type; |
| 101 | unsigned int clk_id; |
| 102 | const char *clk_name; |
| 103 | const char **clks_parent; |
| 104 | int num_parents; |
| 105 | unsigned long flags; |
| 106 | union { |
| 107 | struct fixed_fact_conf fixed_fact; |
Carlo Caione | 7a29a86 | 2015-06-01 13:13:53 +0200 | [diff] [blame] | 108 | const struct composite_conf *composite; |
Carlo Caione | 7a29a86 | 2015-06-01 13:13:53 +0200 | [diff] [blame] | 109 | const struct clk_div_table *div_table; |
| 110 | } conf; |
| 111 | }; |
| 112 | |
Carlo Caione | 7a29a86 | 2015-06-01 13:13:53 +0200 | [diff] [blame] | 113 | #define FIXED_FACTOR_DIV(_ci, _cn, _cp, _f, _d) \ |
| 114 | { \ |
| 115 | .clk_type = CLK_FIXED_FACTOR, \ |
| 116 | .clk_id = (_ci), \ |
| 117 | .clk_name = (_cn), \ |
| 118 | .clks_parent = (_cp), \ |
| 119 | .num_parents = ARRAY_SIZE(_cp), \ |
| 120 | .conf.fixed_fact.div = (_d), \ |
| 121 | } \ |
| 122 | |
| 123 | #define CPU(_ro, _ci, _cn, _cp, _dt) \ |
| 124 | { \ |
| 125 | .reg_off = (_ro), \ |
| 126 | .clk_type = CLK_CPU, \ |
| 127 | .clk_id = (_ci), \ |
| 128 | .clk_name = (_cn), \ |
| 129 | .clks_parent = (_cp), \ |
| 130 | .num_parents = ARRAY_SIZE(_cp), \ |
| 131 | .conf.div_table = (_dt), \ |
| 132 | } \ |
| 133 | |
| 134 | #define COMPOSITE(_ro, _ci, _cn, _cp, _f, _c) \ |
| 135 | { \ |
| 136 | .reg_off = (_ro), \ |
| 137 | .clk_type = CLK_COMPOSITE, \ |
| 138 | .clk_id = (_ci), \ |
| 139 | .clk_name = (_cn), \ |
| 140 | .clks_parent = (_cp), \ |
| 141 | .num_parents = ARRAY_SIZE(_cp), \ |
| 142 | .flags = (_f), \ |
| 143 | .conf.composite = (_c), \ |
| 144 | } \ |
| 145 | |
| 146 | struct clk **meson_clk_init(struct device_node *np, unsigned long nr_clks); |
| 147 | void meson_clk_register_clks(const struct clk_conf *clk_confs, |
| 148 | unsigned int nr_confs, void __iomem *clk_base); |
| 149 | struct clk *meson_clk_register_cpu(const struct clk_conf *clk_conf, |
| 150 | void __iomem *reg_base, spinlock_t *lock); |
Michael Turquette | ec623f2 | 2016-04-28 12:01:42 -0700 | [diff] [blame^] | 151 | |
| 152 | /* shared data */ |
| 153 | extern spinlock_t clk_lock; |
| 154 | |
| 155 | /* clk_ops */ |
| 156 | extern const struct clk_ops meson_clk_pll_ro_ops; |
| 157 | extern const struct clk_ops meson_clk_pll_ops; |
Carlo Caione | 7a29a86 | 2015-06-01 13:13:53 +0200 | [diff] [blame] | 158 | |
| 159 | #endif /* __CLKC_H */ |