1b3a33077SSimon Horman /* 2b3a33077SSimon Horman * Renesas Clock Pulse Generator / Module Standby and Software Reset 3b3a33077SSimon Horman * 4b3a33077SSimon Horman * Copyright (C) 2015 Glider bvba 5b3a33077SSimon Horman * 6b3a33077SSimon Horman * This program is free software; you can redistribute it and/or modify 7b3a33077SSimon Horman * it under the terms of the GNU General Public License as published by 8b3a33077SSimon Horman * the Free Software Foundation; version 2 of the License. 9b3a33077SSimon Horman */ 10b3a33077SSimon Horman 11b3a33077SSimon Horman #ifndef __CLK_RENESAS_CPG_MSSR_H__ 12b3a33077SSimon Horman #define __CLK_RENESAS_CPG_MSSR_H__ 13b3a33077SSimon Horman 14b3a33077SSimon Horman /* 15b3a33077SSimon Horman * Definitions of CPG Core Clocks 16b3a33077SSimon Horman * 17b3a33077SSimon Horman * These include: 18b3a33077SSimon Horman * - Clock outputs exported to DT 19b3a33077SSimon Horman * - External input clocks 20b3a33077SSimon Horman * - Internal CPG clocks 21b3a33077SSimon Horman */ 22b3a33077SSimon Horman 23b3a33077SSimon Horman struct cpg_core_clk { 24b3a33077SSimon Horman /* Common */ 25b3a33077SSimon Horman const char *name; 26b3a33077SSimon Horman unsigned int id; 27b3a33077SSimon Horman unsigned int type; 28b3a33077SSimon Horman /* Depending on type */ 29b3a33077SSimon Horman unsigned int parent; /* Core Clocks only */ 30b3a33077SSimon Horman unsigned int div; 31b3a33077SSimon Horman unsigned int mult; 32b3a33077SSimon Horman unsigned int offset; 33b3a33077SSimon Horman }; 34b3a33077SSimon Horman 35b3a33077SSimon Horman enum clk_types { 36b3a33077SSimon Horman /* Generic */ 37b3a33077SSimon Horman CLK_TYPE_IN, /* External Clock Input */ 38b3a33077SSimon Horman CLK_TYPE_FF, /* Fixed Factor Clock */ 39b3a33077SSimon Horman CLK_TYPE_DIV6P1, /* DIV6 Clock with 1 parent clock */ 405d3927f6SWolfram Sang CLK_TYPE_DIV6_RO, /* DIV6 Clock read only with extra divisor */ 41b3a33077SSimon Horman 42b3a33077SSimon Horman /* Custom definitions start here */ 43b3a33077SSimon Horman CLK_TYPE_CUSTOM, 44b3a33077SSimon Horman }; 45b3a33077SSimon Horman 46b3a33077SSimon Horman #define DEF_TYPE(_name, _id, _type...) \ 47b3a33077SSimon Horman { .name = _name, .id = _id, .type = _type } 48b3a33077SSimon Horman #define DEF_BASE(_name, _id, _type, _parent...) \ 49b3a33077SSimon Horman DEF_TYPE(_name, _id, _type, .parent = _parent) 50b3a33077SSimon Horman 51b3a33077SSimon Horman #define DEF_INPUT(_name, _id) \ 52b3a33077SSimon Horman DEF_TYPE(_name, _id, CLK_TYPE_IN) 53b3a33077SSimon Horman #define DEF_FIXED(_name, _id, _parent, _div, _mult) \ 54b3a33077SSimon Horman DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult) 55b3a33077SSimon Horman #define DEF_DIV6P1(_name, _id, _parent, _offset) \ 56b3a33077SSimon Horman DEF_BASE(_name, _id, CLK_TYPE_DIV6P1, _parent, .offset = _offset) 575d3927f6SWolfram Sang #define DEF_DIV6_RO(_name, _id, _parent, _offset, _div) \ 585d3927f6SWolfram Sang DEF_BASE(_name, _id, CLK_TYPE_DIV6_RO, _parent, .offset = _offset, .div = _div, .mult = 1) 59b3a33077SSimon Horman 60b3a33077SSimon Horman /* 61b3a33077SSimon Horman * Definitions of Module Clocks 62b3a33077SSimon Horman */ 63b3a33077SSimon Horman 64b3a33077SSimon Horman struct mssr_mod_clk { 65b3a33077SSimon Horman const char *name; 66b3a33077SSimon Horman unsigned int id; 67b3a33077SSimon Horman unsigned int parent; /* Add MOD_CLK_BASE for Module Clocks */ 68b3a33077SSimon Horman }; 69b3a33077SSimon Horman 70b3a33077SSimon Horman /* Convert from sparse base-100 to packed index space */ 71b3a33077SSimon Horman #define MOD_CLK_PACK(x) ((x) - ((x) / 100) * (100 - 32)) 72b3a33077SSimon Horman 73b3a33077SSimon Horman #define MOD_CLK_ID(x) (MOD_CLK_BASE + MOD_CLK_PACK(x)) 74b3a33077SSimon Horman 75b3a33077SSimon Horman #define DEF_MOD(_name, _mod, _parent...) \ 76b3a33077SSimon Horman { .name = _name, .id = MOD_CLK_ID(_mod), .parent = _parent } 77b3a33077SSimon Horman 78b3a33077SSimon Horman 79b3a33077SSimon Horman struct device_node; 80b3a33077SSimon Horman 81b3a33077SSimon Horman /** 82b3a33077SSimon Horman * SoC-specific CPG/MSSR Description 83b3a33077SSimon Horman * 84b3a33077SSimon Horman * @core_clks: Array of Core Clock definitions 85b3a33077SSimon Horman * @num_core_clks: Number of entries in core_clks[] 86b3a33077SSimon Horman * @last_dt_core_clk: ID of the last Core Clock exported to DT 87b3a33077SSimon Horman * @num_total_core_clks: Total number of Core Clocks (exported + internal) 88b3a33077SSimon Horman * 89b3a33077SSimon Horman * @mod_clks: Array of Module Clock definitions 90b3a33077SSimon Horman * @num_mod_clks: Number of entries in mod_clks[] 91b3a33077SSimon Horman * @num_hw_mod_clks: Number of Module Clocks supported by the hardware 92b3a33077SSimon Horman * 93b3a33077SSimon Horman * @crit_mod_clks: Array with Module Clock IDs of critical clocks that 94b3a33077SSimon Horman * should not be disabled without a knowledgeable driver 95b3a33077SSimon Horman * @num_crit_mod_clks: Number of entries in crit_mod_clks[] 96b3a33077SSimon Horman * 97b3a33077SSimon Horman * @core_pm_clks: Array with IDs of Core Clocks that are suitable for Power 98b3a33077SSimon Horman * Management, in addition to Module Clocks 99b3a33077SSimon Horman * @num_core_pm_clks: Number of entries in core_pm_clks[] 100b3a33077SSimon Horman * 101b3a33077SSimon Horman * @init: Optional callback to perform SoC-specific initialization 102b3a33077SSimon Horman * @cpg_clk_register: Optional callback to handle special Core Clock types 103b3a33077SSimon Horman */ 104b3a33077SSimon Horman 105b3a33077SSimon Horman struct cpg_mssr_info { 106b3a33077SSimon Horman /* Core Clocks */ 107b3a33077SSimon Horman const struct cpg_core_clk *core_clks; 108b3a33077SSimon Horman unsigned int num_core_clks; 109b3a33077SSimon Horman unsigned int last_dt_core_clk; 110b3a33077SSimon Horman unsigned int num_total_core_clks; 111b3a33077SSimon Horman 112b3a33077SSimon Horman /* Module Clocks */ 113b3a33077SSimon Horman const struct mssr_mod_clk *mod_clks; 114b3a33077SSimon Horman unsigned int num_mod_clks; 115b3a33077SSimon Horman unsigned int num_hw_mod_clks; 116b3a33077SSimon Horman 117b3a33077SSimon Horman /* Critical Module Clocks that should not be disabled */ 118b3a33077SSimon Horman const unsigned int *crit_mod_clks; 119b3a33077SSimon Horman unsigned int num_crit_mod_clks; 120b3a33077SSimon Horman 121b3a33077SSimon Horman /* Core Clocks suitable for PM, in addition to the Module Clocks */ 122b3a33077SSimon Horman const unsigned int *core_pm_clks; 123b3a33077SSimon Horman unsigned int num_core_pm_clks; 124b3a33077SSimon Horman 125b3a33077SSimon Horman /* Callbacks */ 126b3a33077SSimon Horman int (*init)(struct device *dev); 127b3a33077SSimon Horman struct clk *(*cpg_clk_register)(struct device *dev, 128b3a33077SSimon Horman const struct cpg_core_clk *core, 129b3a33077SSimon Horman const struct cpg_mssr_info *info, 1301f4023cdSGeert Uytterhoeven struct clk **clks, void __iomem *base, 1311f4023cdSGeert Uytterhoeven struct raw_notifier_head *notifiers); 132b3a33077SSimon Horman }; 133b3a33077SSimon Horman 134c0b2d75dSSergei Shtylyov extern const struct cpg_mssr_info r8a7743_cpg_mssr_info; 1359127d54bSSergei Shtylyov extern const struct cpg_mssr_info r8a7745_cpg_mssr_info; 1365bf2fbbeSBiju Das extern const struct cpg_mssr_info r8a77470_cpg_mssr_info; 137d4e59f10SGeert Uytterhoeven extern const struct cpg_mssr_info r8a7790_cpg_mssr_info; 1386449ab81SGeert Uytterhoeven extern const struct cpg_mssr_info r8a7791_cpg_mssr_info; 139fd3c2f38SGeert Uytterhoeven extern const struct cpg_mssr_info r8a7792_cpg_mssr_info; 1402d75588aSGeert Uytterhoeven extern const struct cpg_mssr_info r8a7794_cpg_mssr_info; 141b3a33077SSimon Horman extern const struct cpg_mssr_info r8a7795_cpg_mssr_info; 142e4e2d7c3SGeert Uytterhoeven extern const struct cpg_mssr_info r8a7796_cpg_mssr_info; 1437ce36da9SJacopo Mondi extern const struct cpg_mssr_info r8a77965_cpg_mssr_info; 1448d46e28fSSergei Shtylyov extern const struct cpg_mssr_info r8a77970_cpg_mssr_info; 145ce15783cSSergei Shtylyov extern const struct cpg_mssr_info r8a77980_cpg_mssr_info; 146*3570a2afSYoshihiro Shimoda extern const struct cpg_mssr_info r8a77990_cpg_mssr_info; 147d71e851dSGeert Uytterhoeven extern const struct cpg_mssr_info r8a77995_cpg_mssr_info; 14848d0341eSGeert Uytterhoeven 14948d0341eSGeert Uytterhoeven 15048d0341eSGeert Uytterhoeven /* 15148d0341eSGeert Uytterhoeven * Helpers for fixing up clock tables depending on SoC revision 15248d0341eSGeert Uytterhoeven */ 15348d0341eSGeert Uytterhoeven 15448d0341eSGeert Uytterhoeven struct mssr_mod_reparent { 15548d0341eSGeert Uytterhoeven unsigned int clk, parent; 15648d0341eSGeert Uytterhoeven }; 15748d0341eSGeert Uytterhoeven 15848d0341eSGeert Uytterhoeven 15948d0341eSGeert Uytterhoeven extern void cpg_core_nullify_range(struct cpg_core_clk *core_clks, 16048d0341eSGeert Uytterhoeven unsigned int num_core_clks, 16148d0341eSGeert Uytterhoeven unsigned int first_clk, 16248d0341eSGeert Uytterhoeven unsigned int last_clk); 16348d0341eSGeert Uytterhoeven extern void mssr_mod_nullify(struct mssr_mod_clk *mod_clks, 16448d0341eSGeert Uytterhoeven unsigned int num_mod_clks, 16548d0341eSGeert Uytterhoeven const unsigned int *clks, unsigned int n); 16648d0341eSGeert Uytterhoeven extern void mssr_mod_reparent(struct mssr_mod_clk *mod_clks, 16748d0341eSGeert Uytterhoeven unsigned int num_mod_clks, 16848d0341eSGeert Uytterhoeven const struct mssr_mod_reparent *clks, 16948d0341eSGeert Uytterhoeven unsigned int n); 170b3a33077SSimon Horman #endif 171