blob: e5eca8a1abe484a6c5abb30f72e51164b762eaae [file] [log] [blame]
Amit Nischal7ef6f112018-05-07 16:20:18 +05301/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (c) 2013, 2018, The Linux Foundation. All rights reserved. */
Stephen Boydbcd61c02014-01-15 10:47:25 -08003
4#ifndef __QCOM_CLK_RCG_H__
5#define __QCOM_CLK_RCG_H__
6
7#include <linux/clk-provider.h>
8#include "clk-regmap.h"
9
Taniya Dasda172d22018-06-23 19:49:25 +053010#define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) }
11
Stephen Boydbcd61c02014-01-15 10:47:25 -080012struct freq_tbl {
13 unsigned long freq;
14 u8 src;
15 u8 pre_div;
16 u16 m;
17 u16 n;
18};
19
20/**
21 * struct mn - M/N:D counter
22 * @mnctr_en_bit: bit to enable mn counter
23 * @mnctr_reset_bit: bit to assert mn counter reset
24 * @mnctr_mode_shift: lowest bit of mn counter mode field
25 * @n_val_shift: lowest bit of n value field
26 * @m_val_shift: lowest bit of m value field
27 * @width: number of bits in m/n/d values
28 * @reset_in_cc: true if the mnctr_reset_bit is in the CC register
29 */
30struct mn {
31 u8 mnctr_en_bit;
32 u8 mnctr_reset_bit;
33 u8 mnctr_mode_shift;
34#define MNCTR_MODE_DUAL 0x2
35#define MNCTR_MODE_MASK 0x3
36 u8 n_val_shift;
37 u8 m_val_shift;
38 u8 width;
39 bool reset_in_cc;
40};
41
42/**
43 * struct pre_div - pre-divider
44 * @pre_div_shift: lowest bit of pre divider field
45 * @pre_div_width: number of bits in predivider
46 */
47struct pre_div {
48 u8 pre_div_shift;
49 u8 pre_div_width;
50};
51
52/**
53 * struct src_sel - source selector
54 * @src_sel_shift: lowest bit of source selection field
55 * @parent_map: map from software's parent index to hardware's src_sel field
56 */
57struct src_sel {
58 u8 src_sel_shift;
59#define SRC_SEL_MASK 0x7
Georgi Djakov293d2e972015-03-20 18:30:26 +020060 const struct parent_map *parent_map;
Stephen Boydbcd61c02014-01-15 10:47:25 -080061};
62
63/**
64 * struct clk_rcg - root clock generator
65 *
66 * @ns_reg: NS register
67 * @md_reg: MD register
68 * @mn: mn counter
69 * @p: pre divider
70 * @s: source selector
71 * @freq_tbl: frequency table
72 * @clkr: regmap clock handle
73 * @lock: register lock
74 *
75 */
76struct clk_rcg {
77 u32 ns_reg;
78 u32 md_reg;
79
80 struct mn mn;
81 struct pre_div p;
82 struct src_sel s;
83
84 const struct freq_tbl *freq_tbl;
85
86 struct clk_regmap clkr;
87};
88
89extern const struct clk_ops clk_rcg_ops;
Stephen Boyd404c1ff2014-07-11 12:55:27 -070090extern const struct clk_ops clk_rcg_bypass_ops;
Archit Tanejad8aa2be2015-10-14 18:24:44 +053091extern const struct clk_ops clk_rcg_bypass2_ops;
92extern const struct clk_ops clk_rcg_pixel_ops;
93extern const struct clk_ops clk_rcg_esc_ops;
Stephen Boyd9d3745d2015-03-06 15:41:53 -080094extern const struct clk_ops clk_rcg_lcc_ops;
Stephen Boydbcd61c02014-01-15 10:47:25 -080095
96#define to_clk_rcg(_hw) container_of(to_clk_regmap(_hw), struct clk_rcg, clkr)
97
98/**
99 * struct clk_dyn_rcg - root clock generator with glitch free mux
100 *
101 * @mux_sel_bit: bit to switch glitch free mux
Stephen Boyd229fd4a2014-04-28 15:59:16 -0700102 * @ns_reg: NS0 and NS1 register
Stephen Boydbcd61c02014-01-15 10:47:25 -0800103 * @md_reg: MD0 and MD1 register
Stephen Boyd229fd4a2014-04-28 15:59:16 -0700104 * @bank_reg: register to XOR @mux_sel_bit into to switch glitch free mux
Stephen Boydbcd61c02014-01-15 10:47:25 -0800105 * @mn: mn counter (banked)
106 * @s: source selector (banked)
107 * @freq_tbl: frequency table
108 * @clkr: regmap clock handle
109 * @lock: register lock
110 *
111 */
112struct clk_dyn_rcg {
Stephen Boyd229fd4a2014-04-28 15:59:16 -0700113 u32 ns_reg[2];
Stephen Boydbcd61c02014-01-15 10:47:25 -0800114 u32 md_reg[2];
Stephen Boyd229fd4a2014-04-28 15:59:16 -0700115 u32 bank_reg;
Stephen Boydbcd61c02014-01-15 10:47:25 -0800116
117 u8 mux_sel_bit;
118
119 struct mn mn[2];
120 struct pre_div p[2];
121 struct src_sel s[2];
122
123 const struct freq_tbl *freq_tbl;
124
125 struct clk_regmap clkr;
126};
127
128extern const struct clk_ops clk_dyn_rcg_ops;
129
130#define to_clk_dyn_rcg(_hw) \
131 container_of(to_clk_regmap(_hw), struct clk_dyn_rcg, clkr)
132
133/**
134 * struct clk_rcg2 - root clock generator
135 *
136 * @cmd_rcgr: corresponds to *_CMD_RCGR
137 * @mnd_width: number of bits in m/n/d values
138 * @hid_width: number of bits in half integer divider
Amit Nischal7ef6f112018-05-07 16:20:18 +0530139 * @safe_src_index: safe src index value
Stephen Boydbcd61c02014-01-15 10:47:25 -0800140 * @parent_map: map from software's parent index to hardware's src_sel field
141 * @freq_tbl: frequency table
142 * @clkr: regmap clock handle
Stephen Boydbcd61c02014-01-15 10:47:25 -0800143 *
144 */
145struct clk_rcg2 {
146 u32 cmd_rcgr;
147 u8 mnd_width;
148 u8 hid_width;
Amit Nischal7ef6f112018-05-07 16:20:18 +0530149 u8 safe_src_index;
Georgi Djakov293d2e972015-03-20 18:30:26 +0200150 const struct parent_map *parent_map;
Stephen Boydbcd61c02014-01-15 10:47:25 -0800151 const struct freq_tbl *freq_tbl;
152 struct clk_regmap clkr;
153};
154
155#define to_clk_rcg2(_hw) container_of(to_clk_regmap(_hw), struct clk_rcg2, clkr)
156
157extern const struct clk_ops clk_rcg2_ops;
Rajendra Nayak081ba802016-11-21 12:07:11 +0530158extern const struct clk_ops clk_rcg2_floor_ops;
Stephen Boyd99cbd062014-05-16 16:07:11 -0700159extern const struct clk_ops clk_edp_pixel_ops;
160extern const struct clk_ops clk_byte_ops;
Stephen Boyd8ee9c7d2015-04-09 23:02:02 -0700161extern const struct clk_ops clk_byte2_ops;
Stephen Boyd99cbd062014-05-16 16:07:11 -0700162extern const struct clk_ops clk_pixel_ops;
Stephen Boyd55213e12015-11-30 17:31:41 -0800163extern const struct clk_ops clk_gfx3d_ops;
Amit Nischal7ef6f112018-05-07 16:20:18 +0530164extern const struct clk_ops clk_rcg2_shared_ops;
Stephen Boydbcd61c02014-01-15 10:47:25 -0800165
Taniya Dascc4f6942018-08-11 07:23:55 +0530166struct clk_rcg_dfs_data {
167 struct clk_rcg2 *rcg;
168 struct clk_init_data *init;
169};
170
171#define DEFINE_RCG_DFS(r) \
172 { .rcg = &r##_src, .init = &r##_init }
173
174extern int qcom_cc_register_rcg_dfs(struct regmap *regmap,
175 const struct clk_rcg_dfs_data *rcgs,
176 size_t len);
Stephen Boydbcd61c02014-01-15 10:47:25 -0800177#endif