blob: 3c3b128c4c326ef5d9407dcb8c2a9250d32e9ad4 [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);
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010040};
41
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010042/*
43 * Definitions of CPG Core Clocks
44 *
45 * These include:
46 * - Clock outputs exported to DT
47 * - External input clocks
48 * - Internal CPG clocks
49 */
50struct cpg_core_clk {
51 /* Common */
52 const char *name;
53 unsigned int id;
54 unsigned int type;
55 /* Depending on type */
56 unsigned int parent; /* Core Clocks only */
57 unsigned int div;
58 unsigned int mult;
59 unsigned int offset;
60};
61
62enum clk_types {
63 /* Generic */
64 CLK_TYPE_IN, /* External Clock Input */
65 CLK_TYPE_FF, /* Fixed Factor Clock */
Marek Vasut32ae81e2018-01-18 00:05:28 +010066 CLK_TYPE_DIV6P1, /* DIV6 Clock with 1 parent clock */
67 CLK_TYPE_DIV6_RO, /* DIV6 Clock read only with extra divisor */
Marek Vasut78414832019-03-04 21:38:10 +010068 CLK_TYPE_FR, /* Fixed Rate Clock */
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010069
70 /* Custom definitions start here */
71 CLK_TYPE_CUSTOM,
72};
73
74#define DEF_TYPE(_name, _id, _type...) \
75 { .name = _name, .id = _id, .type = _type }
76#define DEF_BASE(_name, _id, _type, _parent...) \
77 DEF_TYPE(_name, _id, _type, .parent = _parent)
78
79#define DEF_INPUT(_name, _id) \
80 DEF_TYPE(_name, _id, CLK_TYPE_IN)
81#define DEF_FIXED(_name, _id, _parent, _div, _mult) \
82 DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
Marek Vasut32ae81e2018-01-18 00:05:28 +010083#define DEF_DIV6P1(_name, _id, _parent, _offset) \
84 DEF_BASE(_name, _id, CLK_TYPE_DIV6P1, _parent, .offset = _offset)
85#define DEF_DIV6_RO(_name, _id, _parent, _offset, _div) \
86 DEF_BASE(_name, _id, CLK_TYPE_DIV6_RO, _parent, .offset = _offset, .div = _div, .mult = 1)
Marek Vasut78414832019-03-04 21:38:10 +010087#define DEF_RATE(_name, _id, _rate) \
88 DEF_TYPE(_name, _id, CLK_TYPE_FR, .mult = _rate)
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010089
90/*
91 * Definitions of Module Clocks
92 */
93struct mssr_mod_clk {
94 const char *name;
95 unsigned int id;
96 unsigned int parent; /* Add MOD_CLK_BASE for Module Clocks */
97};
98
99/* Convert from sparse base-100 to packed index space */
100#define MOD_CLK_PACK(x) ((x) - ((x) / 100) * (100 - 32))
101
102#define MOD_CLK_ID(x) (MOD_CLK_BASE + MOD_CLK_PACK(x))
103
104#define DEF_MOD(_name, _mod, _parent...) \
105 { .name = _name, .id = MOD_CLK_ID(_mod), .parent = _parent }
106
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100107struct mstp_stop_table {
Marek Vasut2eb56a12018-01-15 00:58:35 +0100108 u32 sdis;
109 u32 sen;
110 u32 rdis;
111 u32 ren;
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100112};
113
114#define TSTR0 0x04
115#define TSTR0_STR0 BIT(0)
116
Marek Vasute11008b2018-01-15 16:44:39 +0100117bool renesas_clk_is_mod(struct clk *clk);
118int renesas_clk_get_mod(struct clk *clk, struct cpg_mssr_info *info,
119 const struct mssr_mod_clk **mssr);
120int renesas_clk_get_core(struct clk *clk, struct cpg_mssr_info *info,
121 const struct cpg_core_clk **core);
122int renesas_clk_get_parent(struct clk *clk, struct cpg_mssr_info *info,
123 struct clk *parent);
Hai Pham5460ee02020-05-22 10:39:04 +0700124int renesas_clk_endisable(struct clk *clk, void __iomem *base,
125 struct cpg_mssr_info *info, bool enable);
Marek Vasute11008b2018-01-15 16:44:39 +0100126int renesas_clk_remove(void __iomem *base, struct cpg_mssr_info *info);
127
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100128#endif /* __DRIVERS_CLK_RENESAS_CPG_MSSR__ */