blob: b669dec594ffa2d7ac732650d0b3be31fa85b0c5 [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>
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010017struct cpg_mssr_info {
18 const struct cpg_core_clk *core_clk;
19 unsigned int core_clk_size;
20 const struct mssr_mod_clk *mod_clk;
21 unsigned int mod_clk_size;
22 const struct mstp_stop_table *mstp_table;
23 unsigned int mstp_table_size;
24 const char *reset_node;
25 const char *extalr_node;
Marek Vasutf63b2952018-01-08 16:38:51 +010026 const char *extal_usb_node;
Marek Vasutb9234192018-01-08 16:05:28 +010027 unsigned int mod_clk_base;
28 unsigned int clk_extal_id;
29 unsigned int clk_extalr_id;
Marek Vasutf63b2952018-01-08 16:38:51 +010030 unsigned int clk_extal_usb_id;
31 unsigned int pll0_div;
Marek Vasut28f90042018-01-16 19:23:17 +010032 const void *(*get_pll_config)(const u32 cpg_mode);
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010033};
34
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010035/*
36 * Definitions of CPG Core Clocks
37 *
38 * These include:
39 * - Clock outputs exported to DT
40 * - External input clocks
41 * - Internal CPG clocks
42 */
43struct cpg_core_clk {
44 /* Common */
45 const char *name;
46 unsigned int id;
47 unsigned int type;
48 /* Depending on type */
49 unsigned int parent; /* Core Clocks only */
50 unsigned int div;
51 unsigned int mult;
52 unsigned int offset;
53};
54
55enum clk_types {
56 /* Generic */
57 CLK_TYPE_IN, /* External Clock Input */
58 CLK_TYPE_FF, /* Fixed Factor Clock */
Marek Vasut32ae81e2018-01-18 00:05:28 +010059 CLK_TYPE_DIV6P1, /* DIV6 Clock with 1 parent clock */
60 CLK_TYPE_DIV6_RO, /* DIV6 Clock read only with extra divisor */
Marek Vasut78414832019-03-04 21:38:10 +010061 CLK_TYPE_FR, /* Fixed Rate Clock */
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010062
63 /* Custom definitions start here */
64 CLK_TYPE_CUSTOM,
65};
66
67#define DEF_TYPE(_name, _id, _type...) \
68 { .name = _name, .id = _id, .type = _type }
69#define DEF_BASE(_name, _id, _type, _parent...) \
70 DEF_TYPE(_name, _id, _type, .parent = _parent)
71
72#define DEF_INPUT(_name, _id) \
73 DEF_TYPE(_name, _id, CLK_TYPE_IN)
74#define DEF_FIXED(_name, _id, _parent, _div, _mult) \
75 DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
Marek Vasut32ae81e2018-01-18 00:05:28 +010076#define DEF_DIV6P1(_name, _id, _parent, _offset) \
77 DEF_BASE(_name, _id, CLK_TYPE_DIV6P1, _parent, .offset = _offset)
78#define DEF_DIV6_RO(_name, _id, _parent, _offset, _div) \
79 DEF_BASE(_name, _id, CLK_TYPE_DIV6_RO, _parent, .offset = _offset, .div = _div, .mult = 1)
Marek Vasut78414832019-03-04 21:38:10 +010080#define DEF_RATE(_name, _id, _rate) \
81 DEF_TYPE(_name, _id, CLK_TYPE_FR, .mult = _rate)
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010082
83/*
84 * Definitions of Module Clocks
85 */
86struct mssr_mod_clk {
87 const char *name;
88 unsigned int id;
89 unsigned int parent; /* Add MOD_CLK_BASE for Module Clocks */
90};
91
92/* Convert from sparse base-100 to packed index space */
93#define MOD_CLK_PACK(x) ((x) - ((x) / 100) * (100 - 32))
94
95#define MOD_CLK_ID(x) (MOD_CLK_BASE + MOD_CLK_PACK(x))
96
97#define DEF_MOD(_name, _mod, _parent...) \
98 { .name = _name, .id = MOD_CLK_ID(_mod), .parent = _parent }
99
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100100struct mstp_stop_table {
Marek Vasut2eb56a12018-01-15 00:58:35 +0100101 u32 sdis;
102 u32 sen;
103 u32 rdis;
104 u32 ren;
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100105};
106
107#define TSTR0 0x04
108#define TSTR0_STR0 BIT(0)
109
Marek Vasute11008b2018-01-15 16:44:39 +0100110bool renesas_clk_is_mod(struct clk *clk);
111int renesas_clk_get_mod(struct clk *clk, struct cpg_mssr_info *info,
112 const struct mssr_mod_clk **mssr);
113int renesas_clk_get_core(struct clk *clk, struct cpg_mssr_info *info,
114 const struct cpg_core_clk **core);
115int renesas_clk_get_parent(struct clk *clk, struct cpg_mssr_info *info,
116 struct clk *parent);
117int renesas_clk_endisable(struct clk *clk, void __iomem *base, bool enable);
118int renesas_clk_remove(void __iomem *base, struct cpg_mssr_info *info);
119
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100120#endif /* __DRIVERS_CLK_RENESAS_CPG_MSSR__ */