Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 2 | /* |
| 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 Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #ifndef __DRIVERS_CLK_RENESAS_CPG_MSSR__ |
| 14 | #define __DRIVERS_CLK_RENESAS_CPG_MSSR__ |
| 15 | |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 16 | #include <linux/bitops.h> |
Hai Pham | 016a4c2 | 2020-11-05 21:32:38 +0700 | [diff] [blame^] | 17 | |
| 18 | enum clk_reg_layout { |
| 19 | CLK_REG_LAYOUT_RCAR_GEN2_AND_GEN3 = 0, |
| 20 | }; |
| 21 | |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 22 | struct cpg_mssr_info { |
| 23 | const struct cpg_core_clk *core_clk; |
| 24 | unsigned int core_clk_size; |
Hai Pham | 016a4c2 | 2020-11-05 21:32:38 +0700 | [diff] [blame^] | 25 | enum clk_reg_layout reg_layout; |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 26 | 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 Vasut | 814217e | 2021-04-25 21:53:05 +0200 | [diff] [blame] | 31 | unsigned int reset_modemr_offset; |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 32 | const char *extalr_node; |
Marek Vasut | f63b295 | 2018-01-08 16:38:51 +0100 | [diff] [blame] | 33 | const char *extal_usb_node; |
Marek Vasut | b923419 | 2018-01-08 16:05:28 +0100 | [diff] [blame] | 34 | unsigned int mod_clk_base; |
| 35 | unsigned int clk_extal_id; |
| 36 | unsigned int clk_extalr_id; |
Marek Vasut | f63b295 | 2018-01-08 16:38:51 +0100 | [diff] [blame] | 37 | unsigned int clk_extal_usb_id; |
| 38 | unsigned int pll0_div; |
Marek Vasut | 28f9004 | 2018-01-16 19:23:17 +0100 | [diff] [blame] | 39 | const void *(*get_pll_config)(const u32 cpg_mode); |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 40 | }; |
| 41 | |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 42 | /* |
| 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 | */ |
| 50 | struct 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 | |
| 62 | enum clk_types { |
| 63 | /* Generic */ |
| 64 | CLK_TYPE_IN, /* External Clock Input */ |
| 65 | CLK_TYPE_FF, /* Fixed Factor Clock */ |
Marek Vasut | 32ae81e | 2018-01-18 00:05:28 +0100 | [diff] [blame] | 66 | CLK_TYPE_DIV6P1, /* DIV6 Clock with 1 parent clock */ |
| 67 | CLK_TYPE_DIV6_RO, /* DIV6 Clock read only with extra divisor */ |
Marek Vasut | 7841483 | 2019-03-04 21:38:10 +0100 | [diff] [blame] | 68 | CLK_TYPE_FR, /* Fixed Rate Clock */ |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 69 | |
| 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 Vasut | 32ae81e | 2018-01-18 00:05:28 +0100 | [diff] [blame] | 83 | #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 Vasut | 7841483 | 2019-03-04 21:38:10 +0100 | [diff] [blame] | 87 | #define DEF_RATE(_name, _id, _rate) \ |
| 88 | DEF_TYPE(_name, _id, CLK_TYPE_FR, .mult = _rate) |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * Definitions of Module Clocks |
| 92 | */ |
| 93 | struct 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 Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 107 | struct mstp_stop_table { |
Marek Vasut | 2eb56a1 | 2018-01-15 00:58:35 +0100 | [diff] [blame] | 108 | u32 sdis; |
| 109 | u32 sen; |
| 110 | u32 rdis; |
| 111 | u32 ren; |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | #define TSTR0 0x04 |
| 115 | #define TSTR0_STR0 BIT(0) |
| 116 | |
Marek Vasut | e11008b | 2018-01-15 16:44:39 +0100 | [diff] [blame] | 117 | bool renesas_clk_is_mod(struct clk *clk); |
| 118 | int renesas_clk_get_mod(struct clk *clk, struct cpg_mssr_info *info, |
| 119 | const struct mssr_mod_clk **mssr); |
| 120 | int renesas_clk_get_core(struct clk *clk, struct cpg_mssr_info *info, |
| 121 | const struct cpg_core_clk **core); |
| 122 | int renesas_clk_get_parent(struct clk *clk, struct cpg_mssr_info *info, |
| 123 | struct clk *parent); |
Hai Pham | 5460ee0 | 2020-05-22 10:39:04 +0700 | [diff] [blame] | 124 | int renesas_clk_endisable(struct clk *clk, void __iomem *base, |
| 125 | struct cpg_mssr_info *info, bool enable); |
Marek Vasut | e11008b | 2018-01-15 16:44:39 +0100 | [diff] [blame] | 126 | int renesas_clk_remove(void __iomem *base, struct cpg_mssr_info *info); |
| 127 | |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 128 | #endif /* __DRIVERS_CLK_RENESAS_CPG_MSSR__ */ |