blob: 73f014691240083727e7d34f906ab7fe78a5cf6d [file] [log] [blame]
Carlo Caione7a29a862015-06-01 13:13:53 +02001/*
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
32struct parm {
33 u16 reg_off;
34 u8 shift;
35 u8 width;
36};
Michael Turquetteec623f22016-04-28 12:01:42 -070037
Carlo Caione7a29a862015-06-01 13:13:53 +020038struct pll_rate_table {
39 unsigned long rate;
40 u16 m;
41 u16 n;
42 u16 od;
43};
44#define PLL_RATE(_r, _m, _n, _od) \
45 { \
46 .rate = (_r), \
47 .m = (_m), \
48 .n = (_n), \
49 .od = (_od), \
50 } \
51
Michael Turquetteec623f22016-04-28 12:01:42 -070052struct meson_clk_pll {
53 struct clk_hw hw;
54 void __iomem *base;
55 struct parm m;
56 struct parm n;
57 struct parm od;
58 const struct pll_rate_table *rate_table;
59 unsigned int rate_count;
60 spinlock_t *lock;
Carlo Caione7a29a862015-06-01 13:13:53 +020061};
62
Michael Turquetteec623f22016-04-28 12:01:42 -070063#define to_meson_clk_pll(_hw) container_of(_hw, struct meson_clk_pll, hw)
64
Michael Turquette55d42c42016-04-30 12:47:36 -070065struct meson_clk_cpu {
66 struct clk_hw hw;
67 void __iomem *base;
68 u16 reg_off;
69 struct notifier_block clk_nb;
70 const struct clk_div_table *div_table;
71};
72
Michael Turquette55d42c42016-04-30 12:47:36 -070073int meson_clk_cpu_notifier_cb(struct notifier_block *nb, unsigned long event,
74 void *data);
Michael Turquetteec623f22016-04-28 12:01:42 -070075
Michael Turquette1c50da42016-06-06 23:16:17 -070076struct meson_clk_mpll {
77 struct clk_hw hw;
78 void __iomem *base;
79 struct parm sdm;
80 struct parm n2;
81 /* FIXME ssen gate control? */
82 spinlock_t *lock;
83};
84
Michael Turquette73de5c82016-06-07 16:00:55 -070085#define MESON_GATE(_name, _reg, _bit) \
86struct clk_gate gxbb_##_name = { \
87 .reg = (void __iomem *) _reg, \
88 .bit_idx = (_bit), \
89 .lock = &clk_lock, \
90 .hw.init = &(struct clk_init_data) { \
91 .name = #_name, \
92 .ops = &clk_gate_ops, \
93 .parent_names = (const char *[]){ "clk81" }, \
94 .num_parents = 1, \
95 .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED), \
96 }, \
97};
98
Michael Turquetteec623f22016-04-28 12:01:42 -070099/* clk_ops */
100extern const struct clk_ops meson_clk_pll_ro_ops;
101extern const struct clk_ops meson_clk_pll_ops;
Michael Turquette55d42c42016-04-30 12:47:36 -0700102extern const struct clk_ops meson_clk_cpu_ops;
Michael Turquette1c50da42016-06-06 23:16:17 -0700103extern const struct clk_ops meson_clk_mpll_ro_ops;
Carlo Caione7a29a862015-06-01 13:13:53 +0200104
105#endif /* __CLKC_H */