blob: 0735228579803b99b2a0c6e3872feee158387799 [file] [log] [blame]
Tero Kristo0aa29302021-06-11 11:45:13 +03001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * (C) Copyright 2020 - Texas Instruments Incorporated - http://www.ti.com
4 * Tero Kristo <t-kristo@ti.com>
5 */
6
7#ifndef __K3_CLK_H__
8#define __K3_CLK_H__
9
Tero Kristob4a72a92021-06-11 11:45:14 +030010#include <asm/io.h>
11#include <linux/bitops.h>
Tero Kristo0aa29302021-06-11 11:45:13 +030012#include <linux/clk-provider.h>
Tero Kristob4a72a92021-06-11 11:45:14 +030013#include <linux/types.h>
14#include <stdint.h>
15
16struct dev_clk {
17 int dev_id;
18 int clk_id;
19 const char *clk_name;
20};
21
22#define DEV_CLK(_dev_id, _clk_id, _clk_name) { .dev_id = _dev_id, \
23 .clk_id = _clk_id, .clk_name = _clk_name, }
24
25#define CLK_TYPE_MUX 0x01
26#define CLK_TYPE_DIV 0x02
27#define CLK_TYPE_PLL 0x03
28#define CLK_TYPE_HFOSC 0x04
29#define CLK_TYPE_POSTDIV 0x05
30#define CLK_TYPE_MUX_PLLCTRL 0x06
31#define CLK_TYPE_FIXED_RATE 0x07
32
33struct pll_data {
34 u32 reg;
35 const char *name;
36 const char *parent;
37 u32 flags;
38};
39
40struct mux_data {
41 u32 reg;
42 const char *name;
43 const char * const *parents;
44 int num_parents;
45 u32 flags;
46 int shift;
47 int width;
48};
49
50struct div_data {
51 u32 reg;
52 const char *name;
53 const char *parent;
54 u32 flags;
55 int shift;
56 int width;
57};
58
59struct hfosc_data {
60 const char *name;
61 u32 flags;
62};
63
64struct fixed_rate_data {
65 const char *name;
66 u64 rate;
67 u32 flags;
68};
69
70struct postdiv_data {
71 const char *name;
72 const char *parent;
73 int width;
74 u32 flags;
75};
76
77struct mux_pllctrl_data {
78 u32 reg;
79 const char *name;
80 const char * const *parents;
81 int num_parents;
82 u32 flags;
83};
84
85struct clk_data {
86 int type;
87 u32 default_freq;
88 union {
89 struct pll_data pll;
90 struct mux_data mux;
91 struct div_data div;
92 struct hfosc_data hfosc;
93 struct postdiv_data postdiv;
94 struct mux_pllctrl_data mux_pllctrl;
95 struct fixed_rate_data fixed_rate;
96 } clk;
97};
98
99#define CLK_MUX(_name, _parents, _num_parents, _reg, _shift, _width, _flags) \
100 { \
101 .type = CLK_TYPE_MUX, \
102 .clk.mux = { .name = _name, .parents = _parents, \
103 .reg = _reg, \
104 .num_parents = _num_parents, .shift = _shift, \
105 .width = _width, .flags = _flags } \
106 }
107
108#define CLK_DIV(_name, _parent, _reg, _shift, _width, _flags) \
109 { \
110 .type = CLK_TYPE_DIV, \
111 .clk.div = {.name = _name, .parent = _parent, .reg = _reg, .shift = _shift, .width = _width, .flags = _flags } \
112 }
113
114#define CLK_DIV_DEFFREQ(_name, _parent, _reg, _shift, _width, _flags, _freq) \
115 { \
116 .type = CLK_TYPE_DIV, \
117 .default_freq = _freq, \
118 .clk.div = { \
119 .name = _name, .parent = _parent, \
120 .reg = _reg, .shift = _shift, \
121 .width = _width, .flags = _flags } \
122 }
123
124#define CLK_PLL(_name, _parent, _reg, _flags) \
125 { \
126 .type = CLK_TYPE_PLL, \
127 .clk.pll = {.name = _name, .parent = _parent, .reg = _reg, .flags = _flags } \
128 }
129
130#define CLK_PLL_DEFFREQ(_name, _parent, _reg, _flags, _freq) \
131 { \
132 .type = CLK_TYPE_PLL, \
133 .default_freq = _freq, \
134 .clk.pll = { .name = _name, .parent = _parent, \
135 .reg = _reg, .flags = _flags } \
136 }
137
138#define CLK_HFOSC(_name, _flags) \
139 { \
140 .type = CLK_TYPE_HFOSC, \
141 .clk.hfosc = { .name = _name, .flags = _flags } \
142 }
143
144#define CLK_FIXED_RATE(_name, _rate, _flags) \
145 { \
146 .type = CLK_TYPE_FIXED_RATE, \
147 .clk.fixed_rate = { .name = _name, .rate = _rate, .flags = _flags } \
148 }
149
150#define CLK_POSTDIV(_name, _parent, _width, _flags) \
151 { \
152 .type = CLK_TYPE_POSTDIV, \
153 .clk.postdiv = {.name = _name, .parent = _parent, .width = _width, .flags = _flags } \
154 }
155
156#define CLK_MUX_PLLCTRL(_name, _parents, _num_parents, _reg, _flags) \
157 { \
158 .type = CLK_TYPE_MUX, \
159 .clk.mux_pllctrl = { .name = _name, .parents = _parents,\
160 .num_parents = _num_parents, .flags = _flags } \
161 }
162
163struct ti_k3_clk_platdata {
164 const struct clk_data *clk_list;
165 int clk_list_cnt;
166 const struct dev_clk *soc_dev_clk_data;
167 int soc_dev_clk_data_cnt;
168};
169
170extern const struct ti_k3_clk_platdata j721e_clk_platdata;
171extern const struct ti_k3_clk_platdata j7200_clk_platdata;
Tero Kristo0aa29302021-06-11 11:45:13 +0300172
173struct clk *clk_register_ti_pll(const char *name, const char *parent_name,
174 void __iomem *reg);
175
176#endif /* __K3_CLK_H__ */