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 */ 410d2602d7SGeert Uytterhoeven CLK_TYPE_FR, /* Fixed Rate Clock */ 42b3a33077SSimon Horman 43b3a33077SSimon Horman /* Custom definitions start here */ 44b3a33077SSimon Horman CLK_TYPE_CUSTOM, 45b3a33077SSimon Horman }; 46b3a33077SSimon Horman 47b3a33077SSimon Horman #define DEF_TYPE(_name, _id, _type...) \ 48b3a33077SSimon Horman { .name = _name, .id = _id, .type = _type } 49b3a33077SSimon Horman #define DEF_BASE(_name, _id, _type, _parent...) \ 50b3a33077SSimon Horman DEF_TYPE(_name, _id, _type, .parent = _parent) 51b3a33077SSimon Horman 52b3a33077SSimon Horman #define DEF_INPUT(_name, _id) \ 53b3a33077SSimon Horman DEF_TYPE(_name, _id, CLK_TYPE_IN) 54b3a33077SSimon Horman #define DEF_FIXED(_name, _id, _parent, _div, _mult) \ 55b3a33077SSimon Horman DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult) 56b3a33077SSimon Horman #define DEF_DIV6P1(_name, _id, _parent, _offset) \ 57b3a33077SSimon Horman DEF_BASE(_name, _id, CLK_TYPE_DIV6P1, _parent, .offset = _offset) 585d3927f6SWolfram Sang #define DEF_DIV6_RO(_name, _id, _parent, _offset, _div) \ 595d3927f6SWolfram Sang DEF_BASE(_name, _id, CLK_TYPE_DIV6_RO, _parent, .offset = _offset, .div = _div, .mult = 1) 600d2602d7SGeert Uytterhoeven #define DEF_RATE(_name, _id, _rate) \ 610d2602d7SGeert Uytterhoeven DEF_TYPE(_name, _id, CLK_TYPE_FR, .mult = _rate) 62b3a33077SSimon Horman 63b3a33077SSimon Horman /* 64b3a33077SSimon Horman * Definitions of Module Clocks 65b3a33077SSimon Horman */ 66b3a33077SSimon Horman 67b3a33077SSimon Horman struct mssr_mod_clk { 68b3a33077SSimon Horman const char *name; 69b3a33077SSimon Horman unsigned int id; 70b3a33077SSimon Horman unsigned int parent; /* Add MOD_CLK_BASE for Module Clocks */ 71b3a33077SSimon Horman }; 72b3a33077SSimon Horman 73b3a33077SSimon Horman /* Convert from sparse base-100 to packed index space */ 74b3a33077SSimon Horman #define MOD_CLK_PACK(x) ((x) - ((x) / 100) * (100 - 32)) 75b3a33077SSimon Horman 76b3a33077SSimon Horman #define MOD_CLK_ID(x) (MOD_CLK_BASE + MOD_CLK_PACK(x)) 77b3a33077SSimon Horman 78b3a33077SSimon Horman #define DEF_MOD(_name, _mod, _parent...) \ 79b3a33077SSimon Horman { .name = _name, .id = MOD_CLK_ID(_mod), .parent = _parent } 80b3a33077SSimon Horman 81*fde35c9cSChris Brandt /* Convert from sparse base-10 to packed index space */ 82*fde35c9cSChris Brandt #define MOD_CLK_PACK_10(x) ((x / 10) * 32 + (x % 10)) 83*fde35c9cSChris Brandt 84*fde35c9cSChris Brandt #define MOD_CLK_ID_10(x) (MOD_CLK_BASE + MOD_CLK_PACK_10(x)) 85*fde35c9cSChris Brandt 86*fde35c9cSChris Brandt #define DEF_MOD_STB(_name, _mod, _parent...) \ 87*fde35c9cSChris Brandt { .name = _name, .id = MOD_CLK_ID_10(_mod), .parent = _parent } 88b3a33077SSimon Horman 89b3a33077SSimon Horman struct device_node; 90b3a33077SSimon Horman 91b3a33077SSimon Horman /** 92b3a33077SSimon Horman * SoC-specific CPG/MSSR Description 93b3a33077SSimon Horman * 94b3a33077SSimon Horman * @core_clks: Array of Core Clock definitions 95b3a33077SSimon Horman * @num_core_clks: Number of entries in core_clks[] 96b3a33077SSimon Horman * @last_dt_core_clk: ID of the last Core Clock exported to DT 97b3a33077SSimon Horman * @num_total_core_clks: Total number of Core Clocks (exported + internal) 98b3a33077SSimon Horman * 99b3a33077SSimon Horman * @mod_clks: Array of Module Clock definitions 100b3a33077SSimon Horman * @num_mod_clks: Number of entries in mod_clks[] 101b3a33077SSimon Horman * @num_hw_mod_clks: Number of Module Clocks supported by the hardware 102b3a33077SSimon Horman * 103b3a33077SSimon Horman * @crit_mod_clks: Array with Module Clock IDs of critical clocks that 104b3a33077SSimon Horman * should not be disabled without a knowledgeable driver 105b3a33077SSimon Horman * @num_crit_mod_clks: Number of entries in crit_mod_clks[] 106b3a33077SSimon Horman * 107b3a33077SSimon Horman * @core_pm_clks: Array with IDs of Core Clocks that are suitable for Power 108b3a33077SSimon Horman * Management, in addition to Module Clocks 109b3a33077SSimon Horman * @num_core_pm_clks: Number of entries in core_pm_clks[] 110b3a33077SSimon Horman * 111b3a33077SSimon Horman * @init: Optional callback to perform SoC-specific initialization 112b3a33077SSimon Horman * @cpg_clk_register: Optional callback to handle special Core Clock types 113*fde35c9cSChris Brandt * 114*fde35c9cSChris Brandt * @stbyctrl: This device has Standby Control Registers which are 8-bits 115*fde35c9cSChris Brandt * wide, no status registers (MSTPSR) and have different address 116*fde35c9cSChris Brandt * offsets. 117b3a33077SSimon Horman */ 118b3a33077SSimon Horman 119b3a33077SSimon Horman struct cpg_mssr_info { 120b3a33077SSimon Horman /* Core Clocks */ 121b3a33077SSimon Horman const struct cpg_core_clk *core_clks; 122b3a33077SSimon Horman unsigned int num_core_clks; 123b3a33077SSimon Horman unsigned int last_dt_core_clk; 124b3a33077SSimon Horman unsigned int num_total_core_clks; 125*fde35c9cSChris Brandt bool stbyctrl; 126b3a33077SSimon Horman 127b3a33077SSimon Horman /* Module Clocks */ 128b3a33077SSimon Horman const struct mssr_mod_clk *mod_clks; 129b3a33077SSimon Horman unsigned int num_mod_clks; 130b3a33077SSimon Horman unsigned int num_hw_mod_clks; 131b3a33077SSimon Horman 132b3a33077SSimon Horman /* Critical Module Clocks that should not be disabled */ 133b3a33077SSimon Horman const unsigned int *crit_mod_clks; 134b3a33077SSimon Horman unsigned int num_crit_mod_clks; 135b3a33077SSimon Horman 136b3a33077SSimon Horman /* Core Clocks suitable for PM, in addition to the Module Clocks */ 137b3a33077SSimon Horman const unsigned int *core_pm_clks; 138b3a33077SSimon Horman unsigned int num_core_pm_clks; 139b3a33077SSimon Horman 140b3a33077SSimon Horman /* Callbacks */ 141b3a33077SSimon Horman int (*init)(struct device *dev); 142b3a33077SSimon Horman struct clk *(*cpg_clk_register)(struct device *dev, 143b3a33077SSimon Horman const struct cpg_core_clk *core, 144b3a33077SSimon Horman const struct cpg_mssr_info *info, 1451f4023cdSGeert Uytterhoeven struct clk **clks, void __iomem *base, 1461f4023cdSGeert Uytterhoeven struct raw_notifier_head *notifiers); 147b3a33077SSimon Horman }; 148b3a33077SSimon Horman 149*fde35c9cSChris Brandt extern const struct cpg_mssr_info r7s9210_cpg_mssr_info; 150c0b2d75dSSergei Shtylyov extern const struct cpg_mssr_info r8a7743_cpg_mssr_info; 1519127d54bSSergei Shtylyov extern const struct cpg_mssr_info r8a7745_cpg_mssr_info; 1525bf2fbbeSBiju Das extern const struct cpg_mssr_info r8a77470_cpg_mssr_info; 153331a53e0SBiju Das extern const struct cpg_mssr_info r8a774a1_cpg_mssr_info; 154d4e59f10SGeert Uytterhoeven extern const struct cpg_mssr_info r8a7790_cpg_mssr_info; 1556449ab81SGeert Uytterhoeven extern const struct cpg_mssr_info r8a7791_cpg_mssr_info; 156fd3c2f38SGeert Uytterhoeven extern const struct cpg_mssr_info r8a7792_cpg_mssr_info; 1572d75588aSGeert Uytterhoeven extern const struct cpg_mssr_info r8a7794_cpg_mssr_info; 158b3a33077SSimon Horman extern const struct cpg_mssr_info r8a7795_cpg_mssr_info; 159e4e2d7c3SGeert Uytterhoeven extern const struct cpg_mssr_info r8a7796_cpg_mssr_info; 1607ce36da9SJacopo Mondi extern const struct cpg_mssr_info r8a77965_cpg_mssr_info; 1618d46e28fSSergei Shtylyov extern const struct cpg_mssr_info r8a77970_cpg_mssr_info; 162ce15783cSSergei Shtylyov extern const struct cpg_mssr_info r8a77980_cpg_mssr_info; 1633570a2afSYoshihiro Shimoda extern const struct cpg_mssr_info r8a77990_cpg_mssr_info; 164d71e851dSGeert Uytterhoeven extern const struct cpg_mssr_info r8a77995_cpg_mssr_info; 16548d0341eSGeert Uytterhoeven 16648d0341eSGeert Uytterhoeven 16748d0341eSGeert Uytterhoeven /* 16848d0341eSGeert Uytterhoeven * Helpers for fixing up clock tables depending on SoC revision 16948d0341eSGeert Uytterhoeven */ 17048d0341eSGeert Uytterhoeven 17148d0341eSGeert Uytterhoeven struct mssr_mod_reparent { 17248d0341eSGeert Uytterhoeven unsigned int clk, parent; 17348d0341eSGeert Uytterhoeven }; 17448d0341eSGeert Uytterhoeven 17548d0341eSGeert Uytterhoeven 17648d0341eSGeert Uytterhoeven extern void cpg_core_nullify_range(struct cpg_core_clk *core_clks, 17748d0341eSGeert Uytterhoeven unsigned int num_core_clks, 17848d0341eSGeert Uytterhoeven unsigned int first_clk, 17948d0341eSGeert Uytterhoeven unsigned int last_clk); 18048d0341eSGeert Uytterhoeven extern void mssr_mod_nullify(struct mssr_mod_clk *mod_clks, 18148d0341eSGeert Uytterhoeven unsigned int num_mod_clks, 18248d0341eSGeert Uytterhoeven const unsigned int *clks, unsigned int n); 18348d0341eSGeert Uytterhoeven extern void mssr_mod_reparent(struct mssr_mod_clk *mod_clks, 18448d0341eSGeert Uytterhoeven unsigned int num_mod_clks, 18548d0341eSGeert Uytterhoeven const struct mssr_mod_reparent *clks, 18648d0341eSGeert Uytterhoeven unsigned int n); 187b3a33077SSimon Horman #endif 188