blob: 92421b15ee44dabaa462c6dd0cec3ffd7532b367 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Marek Vasut4eb4e6e2018-01-08 14:01:40 +01002/*
3 * Renesas RCar Gen3 CPG MSSR driver
4 *
5 * Copyright (C) 2017-2018 Marek Vasut <marek.vasut@gmail.com>
6 *
7 * Based on the following driver from Linux kernel:
8 * r8a7796 Clock Pulse Generator / Module Standby and Software Reset
9 *
10 * Copyright (C) 2016 Glider bvba
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010011 */
12
13#ifndef __DRIVERS_CLK_RENESAS_CPG_MSSR__
14#define __DRIVERS_CLK_RENESAS_CPG_MSSR__
15
Simon Glass4dcacfc2020-05-10 11:40:13 -060016#include <linux/bitops.h>
Hai Pham016a4c22020-11-05 21:32:38 +070017
18enum clk_reg_layout {
19 CLK_REG_LAYOUT_RCAR_GEN2_AND_GEN3 = 0,
20};
21
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010022struct cpg_mssr_info {
23 const struct cpg_core_clk *core_clk;
24 unsigned int core_clk_size;
Hai Pham016a4c22020-11-05 21:32:38 +070025 enum clk_reg_layout reg_layout;
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010026 const struct mssr_mod_clk *mod_clk;
27 unsigned int mod_clk_size;
28 const struct mstp_stop_table *mstp_table;
29 unsigned int mstp_table_size;
30 const char *reset_node;
Marek Vasut814217e2021-04-25 21:53:05 +020031 unsigned int reset_modemr_offset;
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010032 const char *extalr_node;
Marek Vasutf63b2952018-01-08 16:38:51 +010033 const char *extal_usb_node;
Marek Vasutb9234192018-01-08 16:05:28 +010034 unsigned int mod_clk_base;
35 unsigned int clk_extal_id;
36 unsigned int clk_extalr_id;
Marek Vasutf63b2952018-01-08 16:38:51 +010037 unsigned int clk_extal_usb_id;
38 unsigned int pll0_div;
Marek Vasut28f90042018-01-16 19:23:17 +010039 const void *(*get_pll_config)(const u32 cpg_mode);
Hai Pham94803462020-11-05 22:30:37 +070040 const u16 *status_regs;
41 const u16 *control_regs;
42 const u16 *reset_regs;
43 const u16 *reset_clear_regs;
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010044};
45
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010046/*
47 * Definitions of CPG Core Clocks
48 *
49 * These include:
50 * - Clock outputs exported to DT
51 * - External input clocks
52 * - Internal CPG clocks
53 */
54struct cpg_core_clk {
55 /* Common */
56 const char *name;
57 unsigned int id;
58 unsigned int type;
59 /* Depending on type */
60 unsigned int parent; /* Core Clocks only */
61 unsigned int div;
62 unsigned int mult;
63 unsigned int offset;
64};
65
66enum clk_types {
67 /* Generic */
68 CLK_TYPE_IN, /* External Clock Input */
69 CLK_TYPE_FF, /* Fixed Factor Clock */
Marek Vasut32ae81e2018-01-18 00:05:28 +010070 CLK_TYPE_DIV6P1, /* DIV6 Clock with 1 parent clock */
71 CLK_TYPE_DIV6_RO, /* DIV6 Clock read only with extra divisor */
Marek Vasut78414832019-03-04 21:38:10 +010072 CLK_TYPE_FR, /* Fixed Rate Clock */
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010073
74 /* Custom definitions start here */
75 CLK_TYPE_CUSTOM,
76};
77
78#define DEF_TYPE(_name, _id, _type...) \
79 { .name = _name, .id = _id, .type = _type }
80#define DEF_BASE(_name, _id, _type, _parent...) \
81 DEF_TYPE(_name, _id, _type, .parent = _parent)
82
83#define DEF_INPUT(_name, _id) \
84 DEF_TYPE(_name, _id, CLK_TYPE_IN)
85#define DEF_FIXED(_name, _id, _parent, _div, _mult) \
86 DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
Marek Vasut32ae81e2018-01-18 00:05:28 +010087#define DEF_DIV6P1(_name, _id, _parent, _offset) \
88 DEF_BASE(_name, _id, CLK_TYPE_DIV6P1, _parent, .offset = _offset)
89#define DEF_DIV6_RO(_name, _id, _parent, _offset, _div) \
90 DEF_BASE(_name, _id, CLK_TYPE_DIV6_RO, _parent, .offset = _offset, .div = _div, .mult = 1)
Marek Vasut78414832019-03-04 21:38:10 +010091#define DEF_RATE(_name, _id, _rate) \
92 DEF_TYPE(_name, _id, CLK_TYPE_FR, .mult = _rate)
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010093
94/*
95 * Definitions of Module Clocks
96 */
97struct mssr_mod_clk {
98 const char *name;
99 unsigned int id;
100 unsigned int parent; /* Add MOD_CLK_BASE for Module Clocks */
101};
102
103/* Convert from sparse base-100 to packed index space */
104#define MOD_CLK_PACK(x) ((x) - ((x) / 100) * (100 - 32))
105
106#define MOD_CLK_ID(x) (MOD_CLK_BASE + MOD_CLK_PACK(x))
107
108#define DEF_MOD(_name, _mod, _parent...) \
109 { .name = _name, .id = MOD_CLK_ID(_mod), .parent = _parent }
110
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100111struct mstp_stop_table {
Marek Vasut2eb56a12018-01-15 00:58:35 +0100112 u32 sdis;
113 u32 sen;
114 u32 rdis;
115 u32 ren;
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100116};
117
118#define TSTR0 0x04
119#define TSTR0_STR0 BIT(0)
120
Marek Vasute11008b2018-01-15 16:44:39 +0100121bool renesas_clk_is_mod(struct clk *clk);
122int renesas_clk_get_mod(struct clk *clk, struct cpg_mssr_info *info,
123 const struct mssr_mod_clk **mssr);
124int renesas_clk_get_core(struct clk *clk, struct cpg_mssr_info *info,
125 const struct cpg_core_clk **core);
126int renesas_clk_get_parent(struct clk *clk, struct cpg_mssr_info *info,
127 struct clk *parent);
Hai Pham5460ee02020-05-22 10:39:04 +0700128int renesas_clk_endisable(struct clk *clk, void __iomem *base,
129 struct cpg_mssr_info *info, bool enable);
Marek Vasute11008b2018-01-15 16:44:39 +0100130int renesas_clk_remove(void __iomem *base, struct cpg_mssr_info *info);
131
Hai Pham94803462020-11-05 22:30:37 +0700132/*
133 * Module Standby and Software Reset register offets.
134 *
135 * If the registers exist, these are valid for SH-Mobile, R-Mobile,
136 * R-Car Gen2, R-Car Gen3, and RZ/G1.
137 * These are NOT valid for R-Car Gen1 and RZ/A1!
138 */
139
140/*
141 * Module Stop Status Register offsets
142 */
143
144static const u16 mstpsr[] = {
145 0x030, 0x038, 0x040, 0x048, 0x04C, 0x03C, 0x1C0, 0x1C4,
146 0x9A0, 0x9A4, 0x9A8, 0x9AC,
147};
148
149/*
150 * System Module Stop Control Register offsets
151 */
152
153static const u16 smstpcr[] = {
154 0x130, 0x134, 0x138, 0x13C, 0x140, 0x144, 0x148, 0x14C,
155 0x990, 0x994, 0x998, 0x99C,
156};
157
158/*
159 * Software Reset Register offsets
160 */
161
162static const u16 srcr[] = {
163 0x0A0, 0x0A8, 0x0B0, 0x0B8, 0x0BC, 0x0C4, 0x1C8, 0x1CC,
164 0x920, 0x924, 0x928, 0x92C,
165};
166
167/* Realtime Module Stop Control Register offsets */
168#define RMSTPCR(i) ((i) < 8 ? smstpcr[i] - 0x20 : smstpcr[i] - 0x10)
169
170/* Modem Module Stop Control Register offsets (r8a73a4) */
171#define MMSTPCR(i) (smstpcr[i] + 0x20)
172
173/* Software Reset Clearing Register offsets */
174
175static const u16 srstclr[] = {
176 0x940, 0x944, 0x948, 0x94C, 0x950, 0x954, 0x958, 0x95C,
177 0x960, 0x964, 0x968, 0x96C,
178};
179
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100180#endif /* __DRIVERS_CLK_RENESAS_CPG_MSSR__ */