Merge branches 'clk-assigned-rates', 'clk-renesas' and 'clk-scmi' into clk-next
* clk-assigned-rates: clk: clk-conf: support assigned-clock-rates-u64 * clk-renesas: (34 commits) clk: renesas: r9a09g057: Add clock and reset entries for GTM/RIIC/SDHI/WDT clk: renesas: rzv2h: Add support for dynamic switching divider clocks clk: renesas: r9a08g045: Add clocks, resets and power domains for USB dt-bindings: clock: renesas,cpg-clocks: Add top-level constraints clk: renesas: r8a779h0: Add CANFD clock clk: renesas: Add RZ/V2H(P) CPG driver clk: renesas: Add family-specific clock driver for RZ/V2H(P) dt-bindings: clock: renesas: Document RZ/V2H(P) SoC CPG clk: renesas: r8a779h0: Add PWM clock dt-bindings: clock: renesas,cpg-mssr: Document RZ/G2M v3.0 (r8a774a3) clock clk: renesas: rcar-gen4: Remove unused default PLL2/3/4/6 configs clk: renesas: rcar-gen4: Remove unused fixed PLL clock types clk: renesas: rcar-gen4: Remove unused variable PLL2 clock type clk: renesas: r8a779h0: Model PLL1/2/3/4/6 as fractional PLLs clk: renesas: r8a779g0: Model PLL1/3/4/6 as fractional PLLs clk: renesas: r8a779f0: Model PLL1/2/3/6 as fractional PLLs clk: renesas: r8a779a0: Use defines for PLL control registers clk: renesas: rcar-gen4: Add support for fractional 9.24 PLLs clk: renesas: rcar-gen4: Add support for fixed variable PLLs clk: renesas: rcar-gen4: Add support for variable fractional PLLs ... * clk-scmi: clk: scmi: add is_prepared hookpull/963/head
commit
c7183ff52f
|
|
@ -32,12 +32,16 @@ properties:
|
|||
reg:
|
||||
maxItems: 1
|
||||
|
||||
clocks: true
|
||||
clocks:
|
||||
minItems: 1
|
||||
maxItems: 3
|
||||
|
||||
'#clock-cells':
|
||||
const: 1
|
||||
|
||||
clock-output-names: true
|
||||
clock-output-names:
|
||||
minItems: 3
|
||||
maxItems: 17
|
||||
|
||||
renesas,mode:
|
||||
description: Board-specific settings of the MD_CK* bits on R-Mobile A1
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ properties:
|
|||
- renesas,r8a7745-cpg-mssr # RZ/G1E
|
||||
- renesas,r8a77470-cpg-mssr # RZ/G1C
|
||||
- renesas,r8a774a1-cpg-mssr # RZ/G2M
|
||||
- renesas,r8a774a3-cpg-mssr # RZ/G2M v3.0
|
||||
- renesas,r8a774b1-cpg-mssr # RZ/G2N
|
||||
- renesas,r8a774c0-cpg-mssr # RZ/G2E
|
||||
- renesas,r8a774e1-cpg-mssr # RZ/G2H
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
|
||||
%YAML 1.2
|
||||
---
|
||||
$id: http://devicetree.org/schemas/clock/renesas,rzv2h-cpg.yaml#
|
||||
$schema: http://devicetree.org/meta-schemas/core.yaml#
|
||||
|
||||
title: Renesas RZ/V2H(P) Clock Pulse Generator (CPG)
|
||||
|
||||
maintainers:
|
||||
- Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
|
||||
|
||||
description:
|
||||
On Renesas RZ/V2H(P) SoCs, the CPG (Clock Pulse Generator) handles generation
|
||||
and control of clock signals for the IP modules, generation and control of resets,
|
||||
and control over booting, low power consumption and power supply domains.
|
||||
|
||||
properties:
|
||||
compatible:
|
||||
const: renesas,r9a09g057-cpg
|
||||
|
||||
reg:
|
||||
maxItems: 1
|
||||
|
||||
clocks:
|
||||
items:
|
||||
- description: AUDIO_EXTAL clock input
|
||||
- description: RTXIN clock input
|
||||
- description: QEXTAL clock input
|
||||
|
||||
clock-names:
|
||||
items:
|
||||
- const: audio_extal
|
||||
- const: rtxin
|
||||
- const: qextal
|
||||
|
||||
'#clock-cells':
|
||||
description: |
|
||||
- For CPG core clocks, the two clock specifier cells must be "CPG_CORE"
|
||||
and a core clock reference, as defined in
|
||||
<dt-bindings/clock/renesas,r9a09g057-cpg.h>,
|
||||
- For module clocks, the two clock specifier cells must be "CPG_MOD" and
|
||||
a module number. The module number is calculated as the CLKON register
|
||||
offset index multiplied by 16, plus the actual bit in the register
|
||||
used to turn the CLK ON. For example, for CGC_GIC_0_GICCLK, the
|
||||
calculation is (1 * 16 + 3) = 0x13.
|
||||
const: 2
|
||||
|
||||
'#power-domain-cells':
|
||||
const: 0
|
||||
|
||||
'#reset-cells':
|
||||
description:
|
||||
The single reset specifier cell must be the reset number. The reset number
|
||||
is calculated as the reset register offset index multiplied by 16, plus the
|
||||
actual bit in the register used to reset the specific IP block. For example,
|
||||
for SYS_0_PRESETN, the calculation is (3 * 16 + 0) = 0x30.
|
||||
const: 1
|
||||
|
||||
required:
|
||||
- compatible
|
||||
- reg
|
||||
- clocks
|
||||
- clock-names
|
||||
- '#clock-cells'
|
||||
- '#power-domain-cells'
|
||||
- '#reset-cells'
|
||||
|
||||
additionalProperties: false
|
||||
|
||||
examples:
|
||||
- |
|
||||
clock-controller@10420000 {
|
||||
compatible = "renesas,r9a09g057-cpg";
|
||||
reg = <0x10420000 0x10000>;
|
||||
clocks = <&audio_extal_clk>, <&rtxin_clk>, <&qextal_clk>;
|
||||
clock-names = "audio_extal", "rtxin", "qextal";
|
||||
#clock-cells = <2>;
|
||||
#power-domain-cells = <0>;
|
||||
#reset-cells = <1>;
|
||||
};
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
#include <linux/device.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/printk.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
static int __set_clk_parents(struct device_node *node, bool clk_supplier)
|
||||
{
|
||||
|
|
@ -81,11 +82,44 @@ err:
|
|||
static int __set_clk_rates(struct device_node *node, bool clk_supplier)
|
||||
{
|
||||
struct of_phandle_args clkspec;
|
||||
int rc, index = 0;
|
||||
int rc, count, count_64, index;
|
||||
struct clk *clk;
|
||||
u32 rate;
|
||||
u64 *rates_64 __free(kfree) = NULL;
|
||||
u32 *rates __free(kfree) = NULL;
|
||||
|
||||
count = of_property_count_u32_elems(node, "assigned-clock-rates");
|
||||
count_64 = of_property_count_u64_elems(node, "assigned-clock-rates-u64");
|
||||
if (count_64 > 0) {
|
||||
count = count_64;
|
||||
rates_64 = kcalloc(count, sizeof(*rates_64), GFP_KERNEL);
|
||||
if (!rates_64)
|
||||
return -ENOMEM;
|
||||
|
||||
rc = of_property_read_u64_array(node,
|
||||
"assigned-clock-rates-u64",
|
||||
rates_64, count);
|
||||
} else if (count > 0) {
|
||||
rates = kcalloc(count, sizeof(*rates), GFP_KERNEL);
|
||||
if (!rates)
|
||||
return -ENOMEM;
|
||||
|
||||
rc = of_property_read_u32_array(node, "assigned-clock-rates",
|
||||
rates, count);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
for (index = 0; index < count; index++) {
|
||||
unsigned long rate;
|
||||
|
||||
if (rates_64)
|
||||
rate = rates_64[index];
|
||||
else
|
||||
rate = rates[index];
|
||||
|
||||
of_property_for_each_u32(node, "assigned-clock-rates", rate) {
|
||||
if (rate) {
|
||||
rc = of_parse_phandle_with_args(node, "assigned-clocks",
|
||||
"#clock-cells", index, &clkspec);
|
||||
|
|
@ -112,12 +146,11 @@ static int __set_clk_rates(struct device_node *node, bool clk_supplier)
|
|||
|
||||
rc = clk_set_rate(clk, rate);
|
||||
if (rc < 0)
|
||||
pr_err("clk: couldn't set %s clk rate to %u (%d), current rate: %lu\n",
|
||||
pr_err("clk: couldn't set %s clk rate to %lu (%d), current rate: %lu\n",
|
||||
__clk_get_name(clk), rate, rc,
|
||||
clk_get_rate(clk));
|
||||
clk_put(clk);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,13 +156,13 @@ static void scmi_clk_atomic_disable(struct clk_hw *hw)
|
|||
scmi_proto_clk_ops->disable(clk->ph, clk->id, ATOMIC);
|
||||
}
|
||||
|
||||
static int scmi_clk_atomic_is_enabled(struct clk_hw *hw)
|
||||
static int __scmi_clk_is_enabled(struct clk_hw *hw, bool atomic)
|
||||
{
|
||||
int ret;
|
||||
bool enabled = false;
|
||||
struct scmi_clk *clk = to_scmi_clk(hw);
|
||||
|
||||
ret = scmi_proto_clk_ops->state_get(clk->ph, clk->id, &enabled, ATOMIC);
|
||||
ret = scmi_proto_clk_ops->state_get(clk->ph, clk->id, &enabled, atomic);
|
||||
if (ret)
|
||||
dev_warn(clk->dev,
|
||||
"Failed to get state for clock ID %d\n", clk->id);
|
||||
|
|
@ -170,6 +170,16 @@ static int scmi_clk_atomic_is_enabled(struct clk_hw *hw)
|
|||
return !!enabled;
|
||||
}
|
||||
|
||||
static int scmi_clk_atomic_is_enabled(struct clk_hw *hw)
|
||||
{
|
||||
return __scmi_clk_is_enabled(hw, ATOMIC);
|
||||
}
|
||||
|
||||
static int scmi_clk_is_enabled(struct clk_hw *hw)
|
||||
{
|
||||
return __scmi_clk_is_enabled(hw, NOT_ATOMIC);
|
||||
}
|
||||
|
||||
static int scmi_clk_get_duty_cycle(struct clk_hw *hw, struct clk_duty *duty)
|
||||
{
|
||||
int ret;
|
||||
|
|
@ -285,6 +295,8 @@ scmi_clk_ops_alloc(struct device *dev, unsigned long feats_key)
|
|||
|
||||
if (feats_key & BIT(SCMI_CLK_ATOMIC_SUPPORTED))
|
||||
ops->is_enabled = scmi_clk_atomic_is_enabled;
|
||||
else
|
||||
ops->is_prepared = scmi_clk_is_enabled;
|
||||
|
||||
/* Rate ops */
|
||||
ops->recalc_rate = scmi_clk_recalc_rate;
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ config CLK_RENESAS
|
|||
select CLK_R9A07G054 if ARCH_R9A07G054
|
||||
select CLK_R9A08G045 if ARCH_R9A08G045
|
||||
select CLK_R9A09G011 if ARCH_R9A09G011
|
||||
select CLK_R9A09G057 if ARCH_R9A09G057
|
||||
select CLK_SH73A0 if ARCH_SH73A0
|
||||
|
||||
if CLK_RENESAS
|
||||
|
|
@ -193,6 +194,10 @@ config CLK_R9A09G011
|
|||
bool "RZ/V2M clock support" if COMPILE_TEST
|
||||
select CLK_RZG2L
|
||||
|
||||
config CLK_R9A09G057
|
||||
bool "RZ/V2H(P) clock support" if COMPILE_TEST
|
||||
select CLK_RZV2H
|
||||
|
||||
config CLK_SH73A0
|
||||
bool "SH-Mobile AG5 clock support" if COMPILE_TEST
|
||||
select CLK_RENESAS_CPG_MSTP
|
||||
|
|
@ -228,6 +233,10 @@ config CLK_RZG2L
|
|||
bool "RZ/{G2L,G2UL,G3S,V2L} family clock support" if COMPILE_TEST
|
||||
select RESET_CONTROLLER
|
||||
|
||||
config CLK_RZV2H
|
||||
bool "RZ/V2H(P) family clock support" if COMPILE_TEST
|
||||
select RESET_CONTROLLER
|
||||
|
||||
# Generic
|
||||
config CLK_RENESAS_CPG_MSSR
|
||||
bool "CPG/MSSR clock support" if COMPILE_TEST
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ obj-$(CONFIG_CLK_R9A07G044) += r9a07g044-cpg.o
|
|||
obj-$(CONFIG_CLK_R9A07G054) += r9a07g044-cpg.o
|
||||
obj-$(CONFIG_CLK_R9A08G045) += r9a08g045-cpg.o
|
||||
obj-$(CONFIG_CLK_R9A09G011) += r9a09g011-cpg.o
|
||||
obj-$(CONFIG_CLK_R9A09G057) += r9a09g057-cpg.o
|
||||
obj-$(CONFIG_CLK_SH73A0) += clk-sh73a0.o
|
||||
|
||||
# Family
|
||||
|
|
@ -46,6 +47,7 @@ obj-$(CONFIG_CLK_RCAR_GEN3_CPG) += rcar-gen3-cpg.o
|
|||
obj-$(CONFIG_CLK_RCAR_GEN4_CPG) += rcar-gen4-cpg.o
|
||||
obj-$(CONFIG_CLK_RCAR_USB2_CLOCK_SEL) += rcar-usb2-clock-sel.o
|
||||
obj-$(CONFIG_CLK_RZG2L) += rzg2l-cpg.o
|
||||
obj-$(CONFIG_CLK_RZV2H) += rzv2h-cpg.o
|
||||
|
||||
# Generic
|
||||
obj-$(CONFIG_CLK_RENESAS_CPG_MSSR) += renesas-cpg-mssr.o
|
||||
|
|
|
|||
|
|
@ -61,6 +61,11 @@ enum clk_ids {
|
|||
DEF_BASE(_name, _id, CLK_TYPE_GEN4_PLL2X_3X, CLK_MAIN, \
|
||||
.offset = _offset)
|
||||
|
||||
#define CPG_PLL20CR 0x0834 /* PLL20 Control Register */
|
||||
#define CPG_PLL21CR 0x0838 /* PLL21 Control Register */
|
||||
#define CPG_PLL30CR 0x083c /* PLL30 Control Register */
|
||||
#define CPG_PLL31CR 0x0840 /* PLL31 Control Register */
|
||||
|
||||
static const struct cpg_core_clk r8a779a0_core_clks[] __initconst = {
|
||||
/* External Clock Inputs */
|
||||
DEF_INPUT("extal", CLK_EXTAL),
|
||||
|
|
@ -70,10 +75,10 @@ static const struct cpg_core_clk r8a779a0_core_clks[] __initconst = {
|
|||
DEF_BASE(".main", CLK_MAIN, CLK_TYPE_GEN4_MAIN, CLK_EXTAL),
|
||||
DEF_BASE(".pll1", CLK_PLL1, CLK_TYPE_GEN4_PLL1, CLK_MAIN),
|
||||
DEF_BASE(".pll5", CLK_PLL5, CLK_TYPE_GEN4_PLL5, CLK_MAIN),
|
||||
DEF_PLL(".pll20", CLK_PLL20, 0x0834),
|
||||
DEF_PLL(".pll21", CLK_PLL21, 0x0838),
|
||||
DEF_PLL(".pll30", CLK_PLL30, 0x083c),
|
||||
DEF_PLL(".pll31", CLK_PLL31, 0x0840),
|
||||
DEF_PLL(".pll20", CLK_PLL20, CPG_PLL20CR),
|
||||
DEF_PLL(".pll21", CLK_PLL21, CPG_PLL21CR),
|
||||
DEF_PLL(".pll30", CLK_PLL30, CPG_PLL30CR),
|
||||
DEF_PLL(".pll31", CLK_PLL31, CPG_PLL31CR),
|
||||
|
||||
DEF_FIXED(".pll1_div2", CLK_PLL1_DIV2, CLK_PLL1, 2, 1),
|
||||
DEF_FIXED(".pll20_div2", CLK_PLL20_DIV2, CLK_PLL20, 2, 1),
|
||||
|
|
@ -116,17 +121,17 @@ static const struct cpg_core_clk r8a779a0_core_clks[] __initconst = {
|
|||
DEF_FIXED("cp", R8A779A0_CLK_CP, CLK_EXTAL, 2, 1),
|
||||
DEF_FIXED("cl16mck", R8A779A0_CLK_CL16MCK, CLK_PLL1_DIV2, 64, 1),
|
||||
|
||||
DEF_GEN4_SDH("sd0h", R8A779A0_CLK_SD0H, CLK_SDSRC, 0x870),
|
||||
DEF_GEN4_SD("sd0", R8A779A0_CLK_SD0, R8A779A0_CLK_SD0H, 0x870),
|
||||
DEF_GEN4_SDH("sd0h", R8A779A0_CLK_SD0H, CLK_SDSRC, CPG_SD0CKCR),
|
||||
DEF_GEN4_SD("sd0", R8A779A0_CLK_SD0, R8A779A0_CLK_SD0H, CPG_SD0CKCR),
|
||||
|
||||
DEF_BASE("rpc", R8A779A0_CLK_RPC, CLK_TYPE_GEN4_RPC, CLK_RPCSRC),
|
||||
DEF_BASE("rpcd2", R8A779A0_CLK_RPCD2, CLK_TYPE_GEN4_RPCD2,
|
||||
R8A779A0_CLK_RPC),
|
||||
|
||||
DEF_DIV6P1("mso", R8A779A0_CLK_MSO, CLK_PLL5_DIV4, 0x87c),
|
||||
DEF_DIV6P1("canfd", R8A779A0_CLK_CANFD, CLK_PLL5_DIV4, 0x878),
|
||||
DEF_DIV6P1("csi0", R8A779A0_CLK_CSI0, CLK_PLL5_DIV4, 0x880),
|
||||
DEF_DIV6P1("dsi", R8A779A0_CLK_DSI, CLK_PLL5_DIV4, 0x884),
|
||||
DEF_DIV6P1("mso", R8A779A0_CLK_MSO, CLK_PLL5_DIV4, CPG_MSOCKCR),
|
||||
DEF_DIV6P1("canfd", R8A779A0_CLK_CANFD, CLK_PLL5_DIV4, CPG_CANFDCKCR),
|
||||
DEF_DIV6P1("csi0", R8A779A0_CLK_CSI0, CLK_PLL5_DIV4, CPG_CSICKCR),
|
||||
DEF_DIV6P1("dsi", R8A779A0_CLK_DSI, CLK_PLL5_DIV4, CPG_DSIEXTCKCR),
|
||||
|
||||
DEF_GEN4_OSC("osc", R8A779A0_CLK_OSC, CLK_EXTAL, 8),
|
||||
DEF_GEN4_MDSEL("r", R8A779A0_CLK_R, 29, CLK_EXTALR, 1, CLK_OCO, 1),
|
||||
|
|
@ -253,12 +258,12 @@ static const unsigned int r8a779a0_crit_mod_clks[] __initconst = {
|
|||
*/
|
||||
#define CPG_PLL_CONFIG_INDEX(md) ((((md) & BIT(14)) >> 13) | \
|
||||
(((md) & BIT(13)) >> 13))
|
||||
static const struct rcar_gen4_cpg_pll_config cpg_pll_configs[4] = {
|
||||
/* EXTAL div PLL1 mult/div PLL2 mult/div PLL3 mult/div PLL4 mult/div PLL5 mult/div PLL6 mult/div OSC prediv */
|
||||
{ 1, 128, 1, 0, 0, 0, 0, 144, 1, 192, 1, 0, 0, 16, },
|
||||
{ 1, 106, 1, 0, 0, 0, 0, 120, 1, 160, 1, 0, 0, 19, },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
|
||||
{ 2, 128, 1, 0, 0, 0, 0, 144, 1, 192, 1, 0, 0, 32, },
|
||||
static const struct rcar_gen4_cpg_pll_config cpg_pll_configs[4] __initconst = {
|
||||
/* EXTAL div PLL1 mult/div PLL5 mult/div OSC prediv */
|
||||
{ 1, 128, 1, 192, 1, 16, },
|
||||
{ 1, 106, 1, 160, 1, 19, },
|
||||
{ 0, 0, 0, 0, 0, 0, },
|
||||
{ 2, 128, 1, 192, 1, 32, },
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -57,12 +57,12 @@ static const struct cpg_core_clk r8a779f0_core_clks[] __initconst = {
|
|||
DEF_INPUT("extalr", CLK_EXTALR),
|
||||
|
||||
/* Internal Core Clocks */
|
||||
DEF_BASE(".main", CLK_MAIN, CLK_TYPE_GEN4_MAIN, CLK_EXTAL),
|
||||
DEF_BASE(".pll1", CLK_PLL1, CLK_TYPE_GEN4_PLL1, CLK_MAIN),
|
||||
DEF_BASE(".pll2", CLK_PLL2, CLK_TYPE_GEN4_PLL2, CLK_MAIN),
|
||||
DEF_BASE(".pll3", CLK_PLL3, CLK_TYPE_GEN4_PLL3, CLK_MAIN),
|
||||
DEF_BASE(".pll5", CLK_PLL5, CLK_TYPE_GEN4_PLL5, CLK_MAIN),
|
||||
DEF_BASE(".pll6", CLK_PLL6, CLK_TYPE_GEN4_PLL6, CLK_MAIN),
|
||||
DEF_BASE(".main", CLK_MAIN, CLK_TYPE_GEN4_MAIN, CLK_EXTAL),
|
||||
DEF_GEN4_PLL_F9_24(".pll1", 1, CLK_PLL1, CLK_MAIN),
|
||||
DEF_GEN4_PLL_V9_24(".pll2", 2, CLK_PLL2, CLK_MAIN),
|
||||
DEF_GEN4_PLL_V9_24(".pll3", 3, CLK_PLL3, CLK_MAIN),
|
||||
DEF_BASE(".pll5", CLK_PLL5, CLK_TYPE_GEN4_PLL5, CLK_MAIN),
|
||||
DEF_GEN4_PLL_V9_24(".pll6", 6, CLK_PLL6, CLK_MAIN),
|
||||
|
||||
DEF_FIXED(".pll1_div2", CLK_PLL1_DIV2, CLK_PLL1, 2, 1),
|
||||
DEF_FIXED(".pll2_div2", CLK_PLL2_DIV2, CLK_PLL2, 2, 1),
|
||||
|
|
@ -115,13 +115,13 @@ static const struct cpg_core_clk r8a779f0_core_clks[] __initconst = {
|
|||
DEF_FIXED("sasyncperd2",R8A779F0_CLK_SASYNCPERD2, CLK_SASYNCPER,2, 1),
|
||||
DEF_FIXED("sasyncperd4",R8A779F0_CLK_SASYNCPERD4, CLK_SASYNCPER,4, 1),
|
||||
|
||||
DEF_GEN4_SDH("sd0h", R8A779F0_CLK_SD0H, CLK_SDSRC, 0x870),
|
||||
DEF_GEN4_SD("sd0", R8A779F0_CLK_SD0, R8A779F0_CLK_SD0H, 0x870),
|
||||
DEF_GEN4_SDH("sd0h", R8A779F0_CLK_SD0H, CLK_SDSRC, CPG_SD0CKCR),
|
||||
DEF_GEN4_SD("sd0", R8A779F0_CLK_SD0, R8A779F0_CLK_SD0H, CPG_SD0CKCR),
|
||||
|
||||
DEF_BASE("rpc", R8A779F0_CLK_RPC, CLK_TYPE_GEN4_RPC, CLK_RPCSRC),
|
||||
DEF_BASE("rpcd2", R8A779F0_CLK_RPCD2, CLK_TYPE_GEN4_RPCD2, R8A779F0_CLK_RPC),
|
||||
|
||||
DEF_DIV6P1("mso", R8A779F0_CLK_MSO, CLK_PLL5_DIV4, 0x87c),
|
||||
DEF_DIV6P1("mso", R8A779F0_CLK_MSO, CLK_PLL5_DIV4, CPG_MSOCKCR),
|
||||
|
||||
DEF_GEN4_OSC("osc", R8A779F0_CLK_OSC, CLK_EXTAL, 8),
|
||||
DEF_GEN4_MDSEL("r", R8A779F0_CLK_R, 29, CLK_EXTALR, 1, CLK_OCO, 1),
|
||||
|
|
@ -187,12 +187,12 @@ static const unsigned int r8a779f0_crit_mod_clks[] __initconst = {
|
|||
#define CPG_PLL_CONFIG_INDEX(md) ((((md) & BIT(14)) >> 13) | \
|
||||
(((md) & BIT(13)) >> 13))
|
||||
|
||||
static const struct rcar_gen4_cpg_pll_config cpg_pll_configs[4] = {
|
||||
/* EXTAL div PLL1 mult/div PLL2 mult/div PLL3 mult/div PLL4 mult/div PLL5 mult/div PLL6 mult/div OSC prediv */
|
||||
{ 1, 200, 1, 150, 1, 200, 1, 0, 0, 200, 1, 134, 1, 15, },
|
||||
{ 1, 160, 1, 120, 1, 160, 1, 0, 0, 160, 1, 106, 1, 19, },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
|
||||
{ 2, 160, 1, 120, 1, 160, 1, 0, 0, 160, 1, 106, 1, 38, },
|
||||
static const struct rcar_gen4_cpg_pll_config cpg_pll_configs[4] __initconst = {
|
||||
/* EXTAL div PLL1 mult/div PLL5 mult/div OSC prediv */
|
||||
{ 1, 200, 1, 200, 1, 15, },
|
||||
{ 1, 160, 1, 160, 1, 19, },
|
||||
{ 0, 0, 0, 0, 0, 0, },
|
||||
{ 2, 160, 1, 160, 1, 38, },
|
||||
};
|
||||
|
||||
static int __init r8a779f0_cpg_mssr_init(struct device *dev)
|
||||
|
|
|
|||
|
|
@ -66,13 +66,13 @@ static const struct cpg_core_clk r8a779g0_core_clks[] __initconst = {
|
|||
DEF_INPUT("extalr", CLK_EXTALR),
|
||||
|
||||
/* Internal Core Clocks */
|
||||
DEF_BASE(".main", CLK_MAIN, CLK_TYPE_GEN4_MAIN, CLK_EXTAL),
|
||||
DEF_BASE(".pll1", CLK_PLL1, CLK_TYPE_GEN4_PLL1, CLK_MAIN),
|
||||
DEF_BASE(".pll2", CLK_PLL2, CLK_TYPE_GEN4_PLL2_VAR, CLK_MAIN),
|
||||
DEF_BASE(".pll3", CLK_PLL3, CLK_TYPE_GEN4_PLL3, CLK_MAIN),
|
||||
DEF_BASE(".pll4", CLK_PLL4, CLK_TYPE_GEN4_PLL4, CLK_MAIN),
|
||||
DEF_BASE(".pll5", CLK_PLL5, CLK_TYPE_GEN4_PLL5, CLK_MAIN),
|
||||
DEF_BASE(".pll6", CLK_PLL6, CLK_TYPE_GEN4_PLL6, CLK_MAIN),
|
||||
DEF_BASE(".main", CLK_MAIN, CLK_TYPE_GEN4_MAIN, CLK_EXTAL),
|
||||
DEF_GEN4_PLL_F8_25(".pll1", 1, CLK_PLL1, CLK_MAIN),
|
||||
DEF_GEN4_PLL_V8_25(".pll2", 2, CLK_PLL2, CLK_MAIN),
|
||||
DEF_GEN4_PLL_V8_25(".pll3", 3, CLK_PLL3, CLK_MAIN),
|
||||
DEF_GEN4_PLL_V8_25(".pll4", 4, CLK_PLL4, CLK_MAIN),
|
||||
DEF_BASE(".pll5", CLK_PLL5, CLK_TYPE_GEN4_PLL5, CLK_MAIN),
|
||||
DEF_GEN4_PLL_V8_25(".pll6", 6, CLK_PLL6, CLK_MAIN),
|
||||
|
||||
DEF_FIXED(".pll1_div2", CLK_PLL1_DIV2, CLK_PLL1, 2, 1),
|
||||
DEF_FIXED(".pll2_div2", CLK_PLL2_DIV2, CLK_PLL2, 2, 1),
|
||||
|
|
@ -146,14 +146,14 @@ static const struct cpg_core_clk r8a779g0_core_clks[] __initconst = {
|
|||
DEF_FIXED("viobusd2", R8A779G0_CLK_VIOBUSD2, CLK_VIO, 2, 1),
|
||||
DEF_FIXED("vcbus", R8A779G0_CLK_VCBUS, CLK_VC, 1, 1),
|
||||
DEF_FIXED("vcbusd2", R8A779G0_CLK_VCBUSD2, CLK_VC, 2, 1),
|
||||
DEF_DIV6P1("canfd", R8A779G0_CLK_CANFD, CLK_PLL5_DIV4, 0x878),
|
||||
DEF_DIV6P1("csi", R8A779G0_CLK_CSI, CLK_PLL5_DIV4, 0x880),
|
||||
DEF_DIV6P1("canfd", R8A779G0_CLK_CANFD, CLK_PLL5_DIV4, CPG_CANFDCKCR),
|
||||
DEF_DIV6P1("csi", R8A779G0_CLK_CSI, CLK_PLL5_DIV4, CPG_CSICKCR),
|
||||
DEF_FIXED("dsiref", R8A779G0_CLK_DSIREF, CLK_PLL5_DIV4, 48, 1),
|
||||
DEF_DIV6P1("dsiext", R8A779G0_CLK_DSIEXT, CLK_PLL5_DIV4, 0x884),
|
||||
DEF_DIV6P1("dsiext", R8A779G0_CLK_DSIEXT, CLK_PLL5_DIV4, CPG_DSIEXTCKCR),
|
||||
|
||||
DEF_GEN4_SDH("sd0h", R8A779G0_CLK_SD0H, CLK_SDSRC, 0x870),
|
||||
DEF_GEN4_SD("sd0", R8A779G0_CLK_SD0, R8A779G0_CLK_SD0H, 0x870),
|
||||
DEF_DIV6P1("mso", R8A779G0_CLK_MSO, CLK_PLL5_DIV4, 0x87c),
|
||||
DEF_GEN4_SDH("sd0h", R8A779G0_CLK_SD0H, CLK_SDSRC, CPG_SD0CKCR),
|
||||
DEF_GEN4_SD("sd0", R8A779G0_CLK_SD0, R8A779G0_CLK_SD0H, CPG_SD0CKCR),
|
||||
DEF_DIV6P1("mso", R8A779G0_CLK_MSO, CLK_PLL5_DIV4, CPG_MSOCKCR),
|
||||
|
||||
DEF_BASE("rpc", R8A779G0_CLK_RPC, CLK_TYPE_GEN4_RPC, CLK_RPCSRC),
|
||||
DEF_BASE("rpcd2", R8A779G0_CLK_RPCD2, CLK_TYPE_GEN4_RPCD2, R8A779G0_CLK_RPC),
|
||||
|
|
@ -258,12 +258,12 @@ static const struct mssr_mod_clk r8a779g0_mod_clks[] __initconst = {
|
|||
#define CPG_PLL_CONFIG_INDEX(md) ((((md) & BIT(14)) >> 13) | \
|
||||
(((md) & BIT(13)) >> 13))
|
||||
|
||||
static const struct rcar_gen4_cpg_pll_config cpg_pll_configs[4] = {
|
||||
/* EXTAL div PLL1 mult/div PLL2 mult/div PLL3 mult/div PLL4 mult/div PLL5 mult/div PLL6 mult/div OSC prediv */
|
||||
{ 1, 192, 1, 204, 1, 192, 1, 144, 1, 192, 1, 168, 1, 16, },
|
||||
{ 1, 160, 1, 170, 1, 160, 1, 120, 1, 160, 1, 140, 1, 19, },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
|
||||
{ 2, 192, 1, 204, 1, 192, 1, 144, 1, 192, 1, 168, 1, 32, },
|
||||
static const struct rcar_gen4_cpg_pll_config cpg_pll_configs[4] __initconst = {
|
||||
/* EXTAL div PLL1 mult/div PLL5 mult/div OSC prediv */
|
||||
{ 1, 192, 1, 192, 1, 16, },
|
||||
{ 1, 160, 1, 160, 1, 19, },
|
||||
{ 0, 0, 0, 0, 0, 0, },
|
||||
{ 2, 192, 1, 192, 1, 32, },
|
||||
};
|
||||
|
||||
static int __init r8a779g0_cpg_mssr_init(struct device *dev)
|
||||
|
|
|
|||
|
|
@ -63,19 +63,19 @@ enum clk_ids {
|
|||
MOD_CLK_BASE
|
||||
};
|
||||
|
||||
static const struct cpg_core_clk r8a779h0_core_clks[] = {
|
||||
static const struct cpg_core_clk r8a779h0_core_clks[] __initconst = {
|
||||
/* External Clock Inputs */
|
||||
DEF_INPUT("extal", CLK_EXTAL),
|
||||
DEF_INPUT("extalr", CLK_EXTALR),
|
||||
|
||||
/* Internal Core Clocks */
|
||||
DEF_BASE(".main", CLK_MAIN, CLK_TYPE_GEN4_MAIN, CLK_EXTAL),
|
||||
DEF_BASE(".pll1", CLK_PLL1, CLK_TYPE_GEN4_PLL1, CLK_MAIN),
|
||||
DEF_BASE(".pll2", CLK_PLL2, CLK_TYPE_GEN4_PLL2, CLK_MAIN),
|
||||
DEF_BASE(".pll3", CLK_PLL3, CLK_TYPE_GEN4_PLL3, CLK_MAIN),
|
||||
DEF_BASE(".pll4", CLK_PLL4, CLK_TYPE_GEN4_PLL4, CLK_MAIN),
|
||||
DEF_GEN4_PLL_F8_25(".pll1", 1, CLK_PLL1, CLK_MAIN),
|
||||
DEF_GEN4_PLL_V8_25(".pll2", 2, CLK_PLL2, CLK_MAIN),
|
||||
DEF_GEN4_PLL_V8_25(".pll3", 3, CLK_PLL3, CLK_MAIN),
|
||||
DEF_GEN4_PLL_V8_25(".pll4", 4, CLK_PLL4, CLK_MAIN),
|
||||
DEF_BASE(".pll5", CLK_PLL5, CLK_TYPE_GEN4_PLL5, CLK_MAIN),
|
||||
DEF_BASE(".pll6", CLK_PLL6, CLK_TYPE_GEN4_PLL6, CLK_MAIN),
|
||||
DEF_GEN4_PLL_V8_25(".pll6", 6, CLK_PLL6, CLK_MAIN),
|
||||
|
||||
DEF_FIXED(".pll1_div2", CLK_PLL1_DIV2, CLK_PLL1, 2, 1),
|
||||
DEF_FIXED(".pll2_div2", CLK_PLL2_DIV2, CLK_PLL2, 2, 1),
|
||||
|
|
@ -156,14 +156,14 @@ static const struct cpg_core_clk r8a779h0_core_clks[] = {
|
|||
DEF_FIXED("viobusd2", R8A779H0_CLK_VIOBUSD2, CLK_VIOSRC, 2, 1),
|
||||
DEF_FIXED("vcbusd1", R8A779H0_CLK_VCBUSD1, CLK_VCSRC, 1, 1),
|
||||
DEF_FIXED("vcbusd2", R8A779H0_CLK_VCBUSD2, CLK_VCSRC, 2, 1),
|
||||
DEF_DIV6P1("canfd", R8A779H0_CLK_CANFD, CLK_PLL5_DIV4, 0x878),
|
||||
DEF_DIV6P1("csi", R8A779H0_CLK_CSI, CLK_PLL5_DIV4, 0x880),
|
||||
DEF_DIV6P1("canfd", R8A779H0_CLK_CANFD, CLK_PLL5_DIV4, CPG_CANFDCKCR),
|
||||
DEF_DIV6P1("csi", R8A779H0_CLK_CSI, CLK_PLL5_DIV4, CPG_CSICKCR),
|
||||
DEF_FIXED("dsiref", R8A779H0_CLK_DSIREF, CLK_PLL5_DIV4, 48, 1),
|
||||
DEF_DIV6P1("dsiext", R8A779H0_CLK_DSIEXT, CLK_PLL5_DIV4, 0x884),
|
||||
DEF_DIV6P1("mso", R8A779H0_CLK_MSO, CLK_PLL5_DIV4, 0x87c),
|
||||
DEF_DIV6P1("dsiext", R8A779H0_CLK_DSIEXT, CLK_PLL5_DIV4, CPG_DSIEXTCKCR),
|
||||
DEF_DIV6P1("mso", R8A779H0_CLK_MSO, CLK_PLL5_DIV4, CPG_MSOCKCR),
|
||||
|
||||
DEF_GEN4_SDH("sd0h", R8A779H0_CLK_SD0H, CLK_SDSRC, 0x870),
|
||||
DEF_GEN4_SD("sd0", R8A779H0_CLK_SD0, R8A779H0_CLK_SD0H, 0x870),
|
||||
DEF_GEN4_SDH("sd0h", R8A779H0_CLK_SD0H, CLK_SDSRC, CPG_SD0CKCR),
|
||||
DEF_GEN4_SD("sd0", R8A779H0_CLK_SD0, R8A779H0_CLK_SD0H, CPG_SD0CKCR),
|
||||
|
||||
DEF_BASE("rpc", R8A779H0_CLK_RPC, CLK_TYPE_GEN4_RPC, CLK_RPCSRC),
|
||||
DEF_BASE("rpcd2", R8A779H0_CLK_RPCD2, CLK_TYPE_GEN4_RPCD2, R8A779H0_CLK_RPC),
|
||||
|
|
@ -172,10 +172,11 @@ static const struct cpg_core_clk r8a779h0_core_clks[] = {
|
|||
DEF_GEN4_MDSEL("r", R8A779H0_CLK_R, 29, CLK_EXTALR, 1, CLK_OCO, 1),
|
||||
};
|
||||
|
||||
static const struct mssr_mod_clk r8a779h0_mod_clks[] = {
|
||||
static const struct mssr_mod_clk r8a779h0_mod_clks[] __initconst = {
|
||||
DEF_MOD("avb0:rgmii0", 211, R8A779H0_CLK_S0D8_HSC),
|
||||
DEF_MOD("avb1:rgmii1", 212, R8A779H0_CLK_S0D8_HSC),
|
||||
DEF_MOD("avb2:rgmii2", 213, R8A779H0_CLK_S0D8_HSC),
|
||||
DEF_MOD("canfd0", 328, R8A779H0_CLK_SASYNCPERD2),
|
||||
DEF_MOD("csi40", 331, R8A779H0_CLK_CSI),
|
||||
DEF_MOD("csi41", 400, R8A779H0_CLK_CSI),
|
||||
DEF_MOD("hscif0", 514, R8A779H0_CLK_SASYNCPERD1),
|
||||
|
|
@ -195,6 +196,8 @@ static const struct mssr_mod_clk r8a779h0_mod_clks[] = {
|
|||
DEF_MOD("msi3", 621, R8A779H0_CLK_MSO),
|
||||
DEF_MOD("msi4", 622, R8A779H0_CLK_MSO),
|
||||
DEF_MOD("msi5", 623, R8A779H0_CLK_MSO),
|
||||
DEF_MOD("pcie0", 624, R8A779H0_CLK_S0D2_HSC),
|
||||
DEF_MOD("pwm", 628, R8A779H0_CLK_SASYNCPERD4),
|
||||
DEF_MOD("rpc-if", 629, R8A779H0_CLK_RPCD2),
|
||||
DEF_MOD("scif0", 702, R8A779H0_CLK_SASYNCPERD4),
|
||||
DEF_MOD("scif1", 703, R8A779H0_CLK_SASYNCPERD4),
|
||||
|
|
@ -252,12 +255,12 @@ static const struct mssr_mod_clk r8a779h0_mod_clks[] = {
|
|||
#define CPG_PLL_CONFIG_INDEX(md) ((((md) & BIT(14)) >> 13) | \
|
||||
(((md) & BIT(13)) >> 13))
|
||||
|
||||
static const struct rcar_gen4_cpg_pll_config cpg_pll_configs[4] = {
|
||||
/* EXTAL div PLL1 mult/div PLL2 mult/div PLL3 mult/div PLL4 mult/div PLL5 mult/div PLL6 mult/div OSC prediv */
|
||||
{ 1, 192, 1, 240, 1, 192, 1, 240, 1, 192, 1, 168, 1, 16, },
|
||||
{ 1, 160, 1, 200, 1, 160, 1, 200, 1, 160, 1, 140, 1, 19, },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
|
||||
{ 2, 192, 1, 240, 1, 192, 1, 240, 1, 192, 1, 168, 1, 32, },
|
||||
static const struct rcar_gen4_cpg_pll_config cpg_pll_configs[4] __initconst = {
|
||||
/* EXTAL div PLL1 mult/div PLL5 mult/div OSC prediv */
|
||||
{ 1, 192, 1, 192, 1, 16, },
|
||||
{ 1, 160, 1, 160, 1, 19, },
|
||||
{ 0, 0, 0, 0, 0, 0, },
|
||||
{ 2, 192, 1, 192, 1, 32, },
|
||||
};
|
||||
|
||||
static int __init r8a779h0_cpg_mssr_init(struct device *dev)
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ enum clk_ids {
|
|||
CLK_PLL5,
|
||||
CLK_PLL5_500,
|
||||
CLK_PLL5_250,
|
||||
CLK_PLL5_FOUTPOSTDIV,
|
||||
CLK_DSI_DIV,
|
||||
#endif
|
||||
CLK_PLL6,
|
||||
CLK_PLL6_250,
|
||||
|
|
@ -120,6 +122,7 @@ static const struct cpg_core_clk r9a07g043_core_clks[] __initconst = {
|
|||
DEF_FIXED(".pll5", CLK_PLL5, CLK_EXTAL, 125, 1),
|
||||
DEF_FIXED(".pll5_500", CLK_PLL5_500, CLK_PLL5, 1, 6),
|
||||
DEF_FIXED(".pll5_250", CLK_PLL5_250, CLK_PLL5_500, 1, 2),
|
||||
DEF_PLL5_FOUTPOSTDIV(".pll5_foutpostdiv", CLK_PLL5_FOUTPOSTDIV, CLK_EXTAL),
|
||||
#endif
|
||||
DEF_FIXED(".pll6", CLK_PLL6, CLK_EXTAL, 125, 6),
|
||||
DEF_FIXED(".pll6_250", CLK_PLL6_250, CLK_PLL6, 1, 2),
|
||||
|
|
@ -146,6 +149,8 @@ static const struct cpg_core_clk r9a07g043_core_clks[] __initconst = {
|
|||
#ifdef CONFIG_ARM64
|
||||
DEF_FIXED("M2", R9A07G043_CLK_M2, CLK_PLL3_533, 1, 2),
|
||||
DEF_FIXED("M2_DIV2", CLK_M2_DIV2, R9A07G043_CLK_M2, 1, 2),
|
||||
DEF_DSI_DIV("DSI_DIV", CLK_DSI_DIV, CLK_PLL5_FOUTPOSTDIV, CLK_SET_RATE_PARENT),
|
||||
DEF_FIXED("M3", R9A07G043_CLK_M3, CLK_DSI_DIV, 1, 1),
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
@ -209,6 +214,12 @@ static const struct rzg2l_mod_clk r9a07g043_mod_clks[] = {
|
|||
0x564, 2),
|
||||
DEF_MOD("cru_aclk", R9A07G043_CRU_ACLK, R9A07G043_CLK_M0,
|
||||
0x564, 3),
|
||||
DEF_COUPLED("lcdc_clk_a", R9A07G043_LCDC_CLK_A, R9A07G043_CLK_M0,
|
||||
0x56c, 0),
|
||||
DEF_COUPLED("lcdc_clk_p", R9A07G043_LCDC_CLK_P, R9A07G043_CLK_ZT,
|
||||
0x56c, 0),
|
||||
DEF_MOD("lcdc_clk_d", R9A07G043_LCDC_CLK_D, R9A07G043_CLK_M3,
|
||||
0x56c, 1),
|
||||
#endif
|
||||
DEF_MOD("ssi0_pclk", R9A07G043_SSI0_PCLK2, R9A07G043_CLK_P0,
|
||||
0x570, 0),
|
||||
|
|
@ -309,6 +320,7 @@ static const struct rzg2l_reset r9a07g043_resets[] = {
|
|||
DEF_RST(R9A07G043_CRU_CMN_RSTB, 0x864, 0),
|
||||
DEF_RST(R9A07G043_CRU_PRESETN, 0x864, 1),
|
||||
DEF_RST(R9A07G043_CRU_ARESETN, 0x864, 2),
|
||||
DEF_RST(R9A07G043_LCDC_RESET_N, 0x86c, 0),
|
||||
#endif
|
||||
DEF_RST(R9A07G043_SSI0_RST_M2_REG, 0x870, 0),
|
||||
DEF_RST(R9A07G043_SSI1_RST_M2_REG, 0x870, 1),
|
||||
|
|
|
|||
|
|
@ -193,6 +193,7 @@ static const struct rzg2l_mod_clk r9a08g045_mod_clks[] = {
|
|||
DEF_MOD("ia55_pclk", R9A08G045_IA55_PCLK, R9A08G045_CLK_P2, 0x518, 0),
|
||||
DEF_MOD("ia55_clk", R9A08G045_IA55_CLK, R9A08G045_CLK_P1, 0x518, 1),
|
||||
DEF_MOD("dmac_aclk", R9A08G045_DMAC_ACLK, R9A08G045_CLK_P3, 0x52c, 0),
|
||||
DEF_MOD("dmac_pclk", R9A08G045_DMAC_PCLK, CLK_P3_DIV2, 0x52c, 1),
|
||||
DEF_MOD("wdt0_pclk", R9A08G045_WDT0_PCLK, R9A08G045_CLK_P0, 0x548, 0),
|
||||
DEF_MOD("wdt0_clk", R9A08G045_WDT0_CLK, R9A08G045_OSCCLK, 0x548, 1),
|
||||
DEF_MOD("sdhi0_imclk", R9A08G045_SDHI0_IMCLK, CLK_SD0_DIV4, 0x554, 0),
|
||||
|
|
@ -207,6 +208,10 @@ static const struct rzg2l_mod_clk r9a08g045_mod_clks[] = {
|
|||
DEF_MOD("sdhi2_imclk2", R9A08G045_SDHI2_IMCLK2, CLK_SD2_DIV4, 0x554, 9),
|
||||
DEF_MOD("sdhi2_clk_hs", R9A08G045_SDHI2_CLK_HS, R9A08G045_CLK_SD2, 0x554, 10),
|
||||
DEF_MOD("sdhi2_aclk", R9A08G045_SDHI2_ACLK, R9A08G045_CLK_P1, 0x554, 11),
|
||||
DEF_MOD("usb0_host", R9A08G045_USB_U2H0_HCLK, R9A08G045_CLK_P1, 0x578, 0),
|
||||
DEF_MOD("usb1_host", R9A08G045_USB_U2H1_HCLK, R9A08G045_CLK_P1, 0x578, 1),
|
||||
DEF_MOD("usb0_func", R9A08G045_USB_U2P_EXR_CPUCLK, R9A08G045_CLK_P1, 0x578, 2),
|
||||
DEF_MOD("usb_pclk", R9A08G045_USB_PCLK, R9A08G045_CLK_P1, 0x578, 3),
|
||||
DEF_COUPLED("eth0_axi", R9A08G045_ETH0_CLK_AXI, R9A08G045_CLK_M0, 0x57c, 0),
|
||||
DEF_COUPLED("eth0_chi", R9A08G045_ETH0_CLK_CHI, R9A08G045_CLK_ZT, 0x57c, 0),
|
||||
DEF_MOD("eth0_refclk", R9A08G045_ETH0_REFCLK, R9A08G045_CLK_HP, 0x57c, 8),
|
||||
|
|
@ -226,10 +231,16 @@ static const struct rzg2l_reset r9a08g045_resets[] = {
|
|||
DEF_RST(R9A08G045_GIC600_GICRESET_N, 0x814, 0),
|
||||
DEF_RST(R9A08G045_GIC600_DBG_GICRESET_N, 0x814, 1),
|
||||
DEF_RST(R9A08G045_IA55_RESETN, 0x818, 0),
|
||||
DEF_RST(R9A08G045_DMAC_ARESETN, 0x82c, 0),
|
||||
DEF_RST(R9A08G045_DMAC_RST_ASYNC, 0x82c, 1),
|
||||
DEF_RST(R9A08G045_WDT0_PRESETN, 0x848, 0),
|
||||
DEF_RST(R9A08G045_SDHI0_IXRST, 0x854, 0),
|
||||
DEF_RST(R9A08G045_SDHI1_IXRST, 0x854, 1),
|
||||
DEF_RST(R9A08G045_SDHI2_IXRST, 0x854, 2),
|
||||
DEF_RST(R9A08G045_USB_U2H0_HRESETN, 0x878, 0),
|
||||
DEF_RST(R9A08G045_USB_U2H1_HRESETN, 0x878, 1),
|
||||
DEF_RST(R9A08G045_USB_U2P_EXL_SYSRST, 0x878, 2),
|
||||
DEF_RST(R9A08G045_USB_PRESETN, 0x878, 3),
|
||||
DEF_RST(R9A08G045_ETH0_RST_HW_N, 0x87c, 0),
|
||||
DEF_RST(R9A08G045_ETH1_RST_HW_N, 0x87c, 1),
|
||||
DEF_RST(R9A08G045_I2C0_MRST, 0x880, 0),
|
||||
|
|
@ -277,6 +288,15 @@ static const struct rzg2l_cpg_pm_domain_init_data r9a08g045_pm_domains[] = {
|
|||
DEF_PD("sdhi2", R9A08G045_PD_SDHI2,
|
||||
DEF_REG_CONF(CPG_BUS_PERI_COM_MSTOP, BIT(11)),
|
||||
RZG2L_PD_F_NONE),
|
||||
DEF_PD("usb0", R9A08G045_PD_USB0,
|
||||
DEF_REG_CONF(CPG_BUS_PERI_COM_MSTOP, GENMASK(6, 5)),
|
||||
RZG2L_PD_F_NONE),
|
||||
DEF_PD("usb1", R9A08G045_PD_USB1,
|
||||
DEF_REG_CONF(CPG_BUS_PERI_COM_MSTOP, BIT(7)),
|
||||
RZG2L_PD_F_NONE),
|
||||
DEF_PD("usb-phy", R9A08G045_PD_USB_PHY,
|
||||
DEF_REG_CONF(CPG_BUS_PERI_COM_MSTOP, BIT(4)),
|
||||
RZG2L_PD_F_NONE),
|
||||
DEF_PD("eth0", R9A08G045_PD_ETHER0,
|
||||
DEF_REG_CONF(CPG_BUS_PERI_COM_MSTOP, BIT(2)),
|
||||
RZG2L_PD_F_NONE),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,164 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Renesas RZ/V2H(P) CPG driver
|
||||
*
|
||||
* Copyright (C) 2024 Renesas Electronics Corp.
|
||||
*/
|
||||
|
||||
#include <linux/clk-provider.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h>
|
||||
|
||||
#include <dt-bindings/clock/renesas,r9a09g057-cpg.h>
|
||||
|
||||
#include "rzv2h-cpg.h"
|
||||
|
||||
enum clk_ids {
|
||||
/* Core Clock Outputs exported to DT */
|
||||
LAST_DT_CORE_CLK = R9A09G057_IOTOP_0_SHCLK,
|
||||
|
||||
/* External Input Clocks */
|
||||
CLK_AUDIO_EXTAL,
|
||||
CLK_RTXIN,
|
||||
CLK_QEXTAL,
|
||||
|
||||
/* PLL Clocks */
|
||||
CLK_PLLCM33,
|
||||
CLK_PLLCLN,
|
||||
CLK_PLLDTY,
|
||||
CLK_PLLCA55,
|
||||
|
||||
/* Internal Core Clocks */
|
||||
CLK_PLLCM33_DIV16,
|
||||
CLK_PLLCLN_DIV2,
|
||||
CLK_PLLCLN_DIV8,
|
||||
CLK_PLLCLN_DIV16,
|
||||
CLK_PLLDTY_ACPU,
|
||||
CLK_PLLDTY_ACPU_DIV4,
|
||||
|
||||
/* Module Clocks */
|
||||
MOD_CLK_BASE,
|
||||
};
|
||||
|
||||
static const struct clk_div_table dtable_2_64[] = {
|
||||
{0, 2},
|
||||
{1, 4},
|
||||
{2, 8},
|
||||
{3, 16},
|
||||
{4, 64},
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static const struct cpg_core_clk r9a09g057_core_clks[] __initconst = {
|
||||
/* External Clock Inputs */
|
||||
DEF_INPUT("audio_extal", CLK_AUDIO_EXTAL),
|
||||
DEF_INPUT("rtxin", CLK_RTXIN),
|
||||
DEF_INPUT("qextal", CLK_QEXTAL),
|
||||
|
||||
/* PLL Clocks */
|
||||
DEF_FIXED(".pllcm33", CLK_PLLCM33, CLK_QEXTAL, 200, 3),
|
||||
DEF_FIXED(".pllcln", CLK_PLLCLN, CLK_QEXTAL, 200, 3),
|
||||
DEF_FIXED(".plldty", CLK_PLLDTY, CLK_QEXTAL, 200, 3),
|
||||
DEF_PLL(".pllca55", CLK_PLLCA55, CLK_QEXTAL, PLL_CONF(0x64)),
|
||||
|
||||
/* Internal Core Clocks */
|
||||
DEF_FIXED(".pllcm33_div16", CLK_PLLCM33_DIV16, CLK_PLLCM33, 1, 16),
|
||||
|
||||
DEF_FIXED(".pllcln_div2", CLK_PLLCLN_DIV2, CLK_PLLCLN, 1, 2),
|
||||
DEF_FIXED(".pllcln_div8", CLK_PLLCLN_DIV8, CLK_PLLCLN, 1, 8),
|
||||
DEF_FIXED(".pllcln_div16", CLK_PLLCLN_DIV16, CLK_PLLCLN, 1, 16),
|
||||
|
||||
DEF_DDIV(".plldty_acpu", CLK_PLLDTY_ACPU, CLK_PLLDTY, CDDIV0_DIVCTL2, dtable_2_64),
|
||||
DEF_FIXED(".plldty_acpu_div4", CLK_PLLDTY_ACPU_DIV4, CLK_PLLDTY_ACPU, 1, 4),
|
||||
|
||||
/* Core Clocks */
|
||||
DEF_FIXED("sys_0_pclk", R9A09G057_SYS_0_PCLK, CLK_QEXTAL, 1, 1),
|
||||
DEF_FIXED("iotop_0_shclk", R9A09G057_IOTOP_0_SHCLK, CLK_PLLCM33_DIV16, 1, 1),
|
||||
};
|
||||
|
||||
static const struct rzv2h_mod_clk r9a09g057_mod_clks[] __initconst = {
|
||||
DEF_MOD("gtm_0_pclk", CLK_PLLCM33_DIV16, 4, 3, 2, 3),
|
||||
DEF_MOD("gtm_1_pclk", CLK_PLLCM33_DIV16, 4, 4, 2, 4),
|
||||
DEF_MOD("gtm_2_pclk", CLK_PLLCLN_DIV16, 4, 5, 2, 5),
|
||||
DEF_MOD("gtm_3_pclk", CLK_PLLCLN_DIV16, 4, 6, 2, 6),
|
||||
DEF_MOD("gtm_4_pclk", CLK_PLLCLN_DIV16, 4, 7, 2, 7),
|
||||
DEF_MOD("gtm_5_pclk", CLK_PLLCLN_DIV16, 4, 8, 2, 8),
|
||||
DEF_MOD("gtm_6_pclk", CLK_PLLCLN_DIV16, 4, 9, 2, 9),
|
||||
DEF_MOD("gtm_7_pclk", CLK_PLLCLN_DIV16, 4, 10, 2, 10),
|
||||
DEF_MOD("wdt_0_clkp", CLK_PLLCM33_DIV16, 4, 11, 2, 11),
|
||||
DEF_MOD("wdt_0_clk_loco", CLK_QEXTAL, 4, 12, 2, 12),
|
||||
DEF_MOD("wdt_1_clkp", CLK_PLLCLN_DIV16, 4, 13, 2, 13),
|
||||
DEF_MOD("wdt_1_clk_loco", CLK_QEXTAL, 4, 14, 2, 14),
|
||||
DEF_MOD("wdt_2_clkp", CLK_PLLCLN_DIV16, 4, 15, 2, 15),
|
||||
DEF_MOD("wdt_2_clk_loco", CLK_QEXTAL, 5, 0, 2, 16),
|
||||
DEF_MOD("wdt_3_clkp", CLK_PLLCLN_DIV16, 5, 1, 2, 17),
|
||||
DEF_MOD("wdt_3_clk_loco", CLK_QEXTAL, 5, 2, 2, 18),
|
||||
DEF_MOD("scif_0_clk_pck", CLK_PLLCM33_DIV16, 8, 15, 4, 15),
|
||||
DEF_MOD("riic_8_ckm", CLK_PLLCM33_DIV16, 9, 3, 4, 19),
|
||||
DEF_MOD("riic_0_ckm", CLK_PLLCLN_DIV16, 9, 4, 4, 20),
|
||||
DEF_MOD("riic_1_ckm", CLK_PLLCLN_DIV16, 9, 5, 4, 21),
|
||||
DEF_MOD("riic_2_ckm", CLK_PLLCLN_DIV16, 9, 6, 4, 22),
|
||||
DEF_MOD("riic_3_ckm", CLK_PLLCLN_DIV16, 9, 7, 4, 23),
|
||||
DEF_MOD("riic_4_ckm", CLK_PLLCLN_DIV16, 9, 8, 4, 24),
|
||||
DEF_MOD("riic_5_ckm", CLK_PLLCLN_DIV16, 9, 9, 4, 25),
|
||||
DEF_MOD("riic_6_ckm", CLK_PLLCLN_DIV16, 9, 10, 4, 26),
|
||||
DEF_MOD("riic_7_ckm", CLK_PLLCLN_DIV16, 9, 11, 4, 27),
|
||||
DEF_MOD("sdhi_0_imclk", CLK_PLLCLN_DIV8, 10, 3, 5, 3),
|
||||
DEF_MOD("sdhi_0_imclk2", CLK_PLLCLN_DIV8, 10, 4, 5, 4),
|
||||
DEF_MOD("sdhi_0_clk_hs", CLK_PLLCLN_DIV2, 10, 5, 5, 5),
|
||||
DEF_MOD("sdhi_0_aclk", CLK_PLLDTY_ACPU_DIV4, 10, 6, 5, 6),
|
||||
DEF_MOD("sdhi_1_imclk", CLK_PLLCLN_DIV8, 10, 7, 5, 7),
|
||||
DEF_MOD("sdhi_1_imclk2", CLK_PLLCLN_DIV8, 10, 8, 5, 8),
|
||||
DEF_MOD("sdhi_1_clk_hs", CLK_PLLCLN_DIV2, 10, 9, 5, 9),
|
||||
DEF_MOD("sdhi_1_aclk", CLK_PLLDTY_ACPU_DIV4, 10, 10, 5, 10),
|
||||
DEF_MOD("sdhi_2_imclk", CLK_PLLCLN_DIV8, 10, 11, 5, 11),
|
||||
DEF_MOD("sdhi_2_imclk2", CLK_PLLCLN_DIV8, 10, 12, 5, 12),
|
||||
DEF_MOD("sdhi_2_clk_hs", CLK_PLLCLN_DIV2, 10, 13, 5, 13),
|
||||
DEF_MOD("sdhi_2_aclk", CLK_PLLDTY_ACPU_DIV4, 10, 14, 5, 14),
|
||||
};
|
||||
|
||||
static const struct rzv2h_reset r9a09g057_resets[] __initconst = {
|
||||
DEF_RST(6, 13, 2, 30), /* GTM_0_PRESETZ */
|
||||
DEF_RST(6, 14, 2, 31), /* GTM_1_PRESETZ */
|
||||
DEF_RST(6, 15, 3, 0), /* GTM_2_PRESETZ */
|
||||
DEF_RST(7, 0, 3, 1), /* GTM_3_PRESETZ */
|
||||
DEF_RST(7, 1, 3, 2), /* GTM_4_PRESETZ */
|
||||
DEF_RST(7, 2, 3, 3), /* GTM_5_PRESETZ */
|
||||
DEF_RST(7, 3, 3, 4), /* GTM_6_PRESETZ */
|
||||
DEF_RST(7, 4, 3, 5), /* GTM_7_PRESETZ */
|
||||
DEF_RST(7, 5, 3, 6), /* WDT_0_RESET */
|
||||
DEF_RST(7, 6, 3, 7), /* WDT_1_RESET */
|
||||
DEF_RST(7, 7, 3, 8), /* WDT_2_RESET */
|
||||
DEF_RST(7, 8, 3, 9), /* WDT_3_RESET */
|
||||
DEF_RST(9, 5, 4, 6), /* SCIF_0_RST_SYSTEM_N */
|
||||
DEF_RST(9, 8, 4, 9), /* RIIC_0_MRST */
|
||||
DEF_RST(9, 9, 4, 10), /* RIIC_1_MRST */
|
||||
DEF_RST(9, 10, 4, 11), /* RIIC_2_MRST */
|
||||
DEF_RST(9, 11, 4, 12), /* RIIC_3_MRST */
|
||||
DEF_RST(9, 12, 4, 13), /* RIIC_4_MRST */
|
||||
DEF_RST(9, 13, 4, 14), /* RIIC_5_MRST */
|
||||
DEF_RST(9, 14, 4, 15), /* RIIC_6_MRST */
|
||||
DEF_RST(9, 15, 4, 16), /* RIIC_7_MRST */
|
||||
DEF_RST(10, 0, 4, 17), /* RIIC_8_MRST */
|
||||
DEF_RST(10, 7, 4, 24), /* SDHI_0_IXRST */
|
||||
DEF_RST(10, 8, 4, 25), /* SDHI_1_IXRST */
|
||||
DEF_RST(10, 9, 4, 26), /* SDHI_2_IXRST */
|
||||
};
|
||||
|
||||
const struct rzv2h_cpg_info r9a09g057_cpg_info __initconst = {
|
||||
/* Core Clocks */
|
||||
.core_clks = r9a09g057_core_clks,
|
||||
.num_core_clks = ARRAY_SIZE(r9a09g057_core_clks),
|
||||
.last_dt_core_clk = LAST_DT_CORE_CLK,
|
||||
.num_total_core_clks = MOD_CLK_BASE,
|
||||
|
||||
/* Module Clocks */
|
||||
.mod_clks = r9a09g057_mod_clks,
|
||||
.num_mod_clks = ARRAY_SIZE(r9a09g057_mod_clks),
|
||||
.num_hw_mod_clks = 25 * 16,
|
||||
|
||||
/* Resets */
|
||||
.resets = r9a09g057_resets,
|
||||
.num_resets = ARRAY_SIZE(r9a09g057_resets),
|
||||
};
|
||||
|
|
@ -45,7 +45,6 @@ static u32 cpg_mode __initdata;
|
|||
#define CPG_PLL6CR1 0x8d8
|
||||
|
||||
#define CPG_PLLxCR0_KICK BIT(31)
|
||||
#define CPG_PLLxCR0_NI GENMASK(27, 20) /* Integer mult. factor */
|
||||
#define CPG_PLLxCR0_SSMODE GENMASK(18, 16) /* PLL mode */
|
||||
#define CPG_PLLxCR0_SSMODE_FM BIT(18) /* Fractional Multiplication */
|
||||
#define CPG_PLLxCR0_SSMODE_DITH BIT(17) /* Frequency Dithering */
|
||||
|
|
@ -53,35 +52,57 @@ static u32 cpg_mode __initdata;
|
|||
#define CPG_PLLxCR0_SSFREQ GENMASK(14, 8) /* SSCG Modulation Frequency */
|
||||
#define CPG_PLLxCR0_SSDEPT GENMASK(6, 0) /* SSCG Modulation Depth */
|
||||
|
||||
#define SSMODE_FM BIT(2) /* Fractional Multiplication */
|
||||
#define SSMODE_DITHER BIT(1) /* Frequency Dithering */
|
||||
#define SSMODE_CENTER BIT(0) /* Center (vs. Down) Spread Dithering */
|
||||
/* Fractional 8.25 PLL */
|
||||
#define CPG_PLLxCR0_NI8 GENMASK(27, 20) /* Integer mult. factor */
|
||||
#define CPG_PLLxCR1_NF25 GENMASK(24, 0) /* Fractional mult. factor */
|
||||
|
||||
/* Fractional 9.24 PLL */
|
||||
#define CPG_PLLxCR0_NI9 GENMASK(28, 20) /* Integer mult. factor */
|
||||
#define CPG_PLLxCR1_NF24 GENMASK(23, 0) /* Fractional mult. factor */
|
||||
|
||||
#define CPG_PLLxCR_STC GENMASK(30, 24) /* R_Car V3U PLLxCR */
|
||||
|
||||
#define CPG_RPCCKCR 0x874 /* RPC Clock Freq. Control Register */
|
||||
|
||||
#define CPG_SD0CKCR1 0x8a4 /* SD-IF0 Clock Freq. Control Reg. 1 */
|
||||
|
||||
#define CPG_SD0CKCR1_SDSRC_SEL GENMASK(30, 29) /* SDSRC clock freq. select */
|
||||
|
||||
/* PLL Clocks */
|
||||
struct cpg_pll_clk {
|
||||
struct clk_hw hw;
|
||||
void __iomem *pllcr0_reg;
|
||||
void __iomem *pllcr1_reg;
|
||||
void __iomem *pllecr_reg;
|
||||
u32 pllecr_pllst_mask;
|
||||
};
|
||||
|
||||
#define to_pll_clk(_hw) container_of(_hw, struct cpg_pll_clk, hw)
|
||||
|
||||
static unsigned long cpg_pll_clk_recalc_rate(struct clk_hw *hw,
|
||||
unsigned long parent_rate)
|
||||
static unsigned long cpg_pll_8_25_clk_recalc_rate(struct clk_hw *hw,
|
||||
unsigned long parent_rate)
|
||||
{
|
||||
struct cpg_pll_clk *pll_clk = to_pll_clk(hw);
|
||||
unsigned int mult;
|
||||
u32 cr0 = readl(pll_clk->pllcr0_reg);
|
||||
unsigned int ni, nf;
|
||||
unsigned long rate;
|
||||
|
||||
mult = FIELD_GET(CPG_PLLxCR0_NI, readl(pll_clk->pllcr0_reg)) + 1;
|
||||
ni = (FIELD_GET(CPG_PLLxCR0_NI8, cr0) + 1) * 2;
|
||||
rate = parent_rate * ni;
|
||||
if (cr0 & CPG_PLLxCR0_SSMODE_FM) {
|
||||
nf = FIELD_GET(CPG_PLLxCR1_NF25, readl(pll_clk->pllcr1_reg));
|
||||
rate += mul_u64_u32_shr(parent_rate, nf, 24);
|
||||
}
|
||||
|
||||
return parent_rate * mult * 2;
|
||||
return rate;
|
||||
}
|
||||
|
||||
static int cpg_pll_clk_determine_rate(struct clk_hw *hw,
|
||||
struct clk_rate_request *req)
|
||||
static int cpg_pll_8_25_clk_determine_rate(struct clk_hw *hw,
|
||||
struct clk_rate_request *req)
|
||||
{
|
||||
unsigned int min_mult, max_mult, mult;
|
||||
struct cpg_pll_clk *pll_clk = to_pll_clk(hw);
|
||||
unsigned int min_mult, max_mult, ni, nf;
|
||||
u32 cr0 = readl(pll_clk->pllcr0_reg);
|
||||
unsigned long prate;
|
||||
|
||||
prate = req->best_parent_rate * 2;
|
||||
|
|
@ -90,28 +111,58 @@ static int cpg_pll_clk_determine_rate(struct clk_hw *hw,
|
|||
if (max_mult < min_mult)
|
||||
return -EINVAL;
|
||||
|
||||
mult = DIV_ROUND_CLOSEST_ULL(req->rate, prate);
|
||||
mult = clamp(mult, min_mult, max_mult);
|
||||
if (cr0 & CPG_PLLxCR0_SSMODE_FM) {
|
||||
ni = div64_ul(req->rate, prate);
|
||||
if (ni < min_mult) {
|
||||
ni = min_mult;
|
||||
nf = 0;
|
||||
} else {
|
||||
ni = min(ni, max_mult);
|
||||
nf = div64_ul((u64)(req->rate - prate * ni) << 24,
|
||||
req->best_parent_rate);
|
||||
}
|
||||
} else {
|
||||
ni = DIV_ROUND_CLOSEST_ULL(req->rate, prate);
|
||||
ni = clamp(ni, min_mult, max_mult);
|
||||
nf = 0;
|
||||
}
|
||||
req->rate = prate * ni + mul_u64_u32_shr(req->best_parent_rate, nf, 24);
|
||||
|
||||
req->rate = prate * mult;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpg_pll_clk_set_rate(struct clk_hw *hw, unsigned long rate,
|
||||
unsigned long parent_rate)
|
||||
static int cpg_pll_8_25_clk_set_rate(struct clk_hw *hw, unsigned long rate,
|
||||
unsigned long parent_rate)
|
||||
{
|
||||
struct cpg_pll_clk *pll_clk = to_pll_clk(hw);
|
||||
unsigned int mult;
|
||||
unsigned long prate = parent_rate * 2;
|
||||
u32 cr0 = readl(pll_clk->pllcr0_reg);
|
||||
unsigned int ni, nf;
|
||||
u32 val;
|
||||
|
||||
mult = DIV_ROUND_CLOSEST_ULL(rate, parent_rate * 2);
|
||||
mult = clamp(mult, 1U, 256U);
|
||||
if (cr0 & CPG_PLLxCR0_SSMODE_FM) {
|
||||
ni = div64_ul(rate, prate);
|
||||
if (ni < 1) {
|
||||
ni = 1;
|
||||
nf = 0;
|
||||
} else {
|
||||
ni = min(ni, 256U);
|
||||
nf = div64_ul((u64)(rate - prate * ni) << 24,
|
||||
parent_rate);
|
||||
}
|
||||
} else {
|
||||
ni = DIV_ROUND_CLOSEST_ULL(rate, prate);
|
||||
ni = clamp(ni, 1U, 256U);
|
||||
}
|
||||
|
||||
if (readl(pll_clk->pllcr0_reg) & CPG_PLLxCR0_KICK)
|
||||
return -EBUSY;
|
||||
|
||||
cpg_reg_modify(pll_clk->pllcr0_reg, CPG_PLLxCR0_NI,
|
||||
FIELD_PREP(CPG_PLLxCR0_NI, mult - 1));
|
||||
cpg_reg_modify(pll_clk->pllcr0_reg, CPG_PLLxCR0_NI8,
|
||||
FIELD_PREP(CPG_PLLxCR0_NI8, ni - 1));
|
||||
if (cr0 & CPG_PLLxCR0_SSMODE_FM)
|
||||
cpg_reg_modify(pll_clk->pllcr1_reg, CPG_PLLxCR1_NF25,
|
||||
FIELD_PREP(CPG_PLLxCR1_NF25, nf));
|
||||
|
||||
/*
|
||||
* Set KICK bit in PLLxCR0 to update hardware setting and wait for
|
||||
|
|
@ -132,22 +183,55 @@ static int cpg_pll_clk_set_rate(struct clk_hw *hw, unsigned long rate,
|
|||
val & pll_clk->pllecr_pllst_mask, 0, 1000);
|
||||
}
|
||||
|
||||
static const struct clk_ops cpg_pll_clk_ops = {
|
||||
.recalc_rate = cpg_pll_clk_recalc_rate,
|
||||
.determine_rate = cpg_pll_clk_determine_rate,
|
||||
.set_rate = cpg_pll_clk_set_rate,
|
||||
static const struct clk_ops cpg_pll_f8_25_clk_ops = {
|
||||
.recalc_rate = cpg_pll_8_25_clk_recalc_rate,
|
||||
};
|
||||
|
||||
static const struct clk_ops cpg_pll_v8_25_clk_ops = {
|
||||
.recalc_rate = cpg_pll_8_25_clk_recalc_rate,
|
||||
.determine_rate = cpg_pll_8_25_clk_determine_rate,
|
||||
.set_rate = cpg_pll_8_25_clk_set_rate,
|
||||
};
|
||||
|
||||
static unsigned long cpg_pll_9_24_clk_recalc_rate(struct clk_hw *hw,
|
||||
unsigned long parent_rate)
|
||||
{
|
||||
struct cpg_pll_clk *pll_clk = to_pll_clk(hw);
|
||||
u32 cr0 = readl(pll_clk->pllcr0_reg);
|
||||
unsigned int ni, nf;
|
||||
unsigned long rate;
|
||||
|
||||
ni = FIELD_GET(CPG_PLLxCR0_NI9, cr0) + 1;
|
||||
rate = parent_rate * ni;
|
||||
if (cr0 & CPG_PLLxCR0_SSMODE_FM) {
|
||||
nf = FIELD_GET(CPG_PLLxCR1_NF24, readl(pll_clk->pllcr1_reg));
|
||||
rate += mul_u64_u32_shr(parent_rate, nf, 24);
|
||||
} else {
|
||||
rate *= 2;
|
||||
}
|
||||
|
||||
return rate;
|
||||
}
|
||||
|
||||
static const struct clk_ops cpg_pll_f9_24_clk_ops = {
|
||||
.recalc_rate = cpg_pll_9_24_clk_recalc_rate,
|
||||
};
|
||||
|
||||
static struct clk * __init cpg_pll_clk_register(const char *name,
|
||||
const char *parent_name,
|
||||
void __iomem *base,
|
||||
unsigned int cr0_offset,
|
||||
unsigned int cr1_offset,
|
||||
unsigned int index)
|
||||
|
||||
unsigned int index,
|
||||
const struct clk_ops *ops)
|
||||
{
|
||||
struct cpg_pll_clk *pll_clk;
|
||||
static const struct { u16 cr0, cr1; } pll_cr_offsets[] __initconst = {
|
||||
[1 - 1] = { CPG_PLL1CR0, CPG_PLL1CR1 },
|
||||
[2 - 1] = { CPG_PLL2CR0, CPG_PLL2CR1 },
|
||||
[3 - 1] = { CPG_PLL3CR0, CPG_PLL3CR1 },
|
||||
[4 - 1] = { CPG_PLL4CR0, CPG_PLL4CR1 },
|
||||
[6 - 1] = { CPG_PLL6CR0, CPG_PLL6CR1 },
|
||||
};
|
||||
struct clk_init_data init = {};
|
||||
struct cpg_pll_clk *pll_clk;
|
||||
struct clk *clk;
|
||||
|
||||
pll_clk = kzalloc(sizeof(*pll_clk), GFP_KERNEL);
|
||||
|
|
@ -155,25 +239,23 @@ static struct clk * __init cpg_pll_clk_register(const char *name,
|
|||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
init.name = name;
|
||||
init.ops = &cpg_pll_clk_ops;
|
||||
init.ops = ops;
|
||||
init.parent_names = &parent_name;
|
||||
init.num_parents = 1;
|
||||
|
||||
pll_clk->hw.init = &init;
|
||||
pll_clk->pllcr0_reg = base + cr0_offset;
|
||||
pll_clk->pllcr0_reg = base + pll_cr_offsets[index - 1].cr0;
|
||||
pll_clk->pllcr1_reg = base + pll_cr_offsets[index - 1].cr1;
|
||||
pll_clk->pllecr_reg = base + CPG_PLLECR;
|
||||
pll_clk->pllecr_pllst_mask = CPG_PLLECR_PLLST(index);
|
||||
|
||||
/* Disable Fractional Multiplication and Frequency Dithering */
|
||||
writel(0, base + cr1_offset);
|
||||
cpg_reg_modify(pll_clk->pllcr0_reg, CPG_PLLxCR0_SSMODE, 0);
|
||||
|
||||
clk = clk_register(NULL, &pll_clk->hw);
|
||||
if (IS_ERR(clk))
|
||||
kfree(pll_clk);
|
||||
|
||||
return clk;
|
||||
}
|
||||
|
||||
/*
|
||||
* Z0 Clock & Z1 Clock
|
||||
*/
|
||||
|
|
@ -358,51 +440,41 @@ struct clk * __init rcar_gen4_cpg_clk_register(struct device *dev,
|
|||
div = cpg_pll_config->pll1_div;
|
||||
break;
|
||||
|
||||
case CLK_TYPE_GEN4_PLL2_VAR:
|
||||
/*
|
||||
* PLL2 is implemented as a custom clock, to change the
|
||||
* multiplier when cpufreq changes between normal and boost
|
||||
* modes.
|
||||
*/
|
||||
return cpg_pll_clk_register(core->name, __clk_get_name(parent),
|
||||
base, CPG_PLL2CR0, CPG_PLL2CR1, 2);
|
||||
|
||||
case CLK_TYPE_GEN4_PLL2:
|
||||
mult = cpg_pll_config->pll2_mult;
|
||||
div = cpg_pll_config->pll2_div;
|
||||
break;
|
||||
|
||||
case CLK_TYPE_GEN4_PLL3:
|
||||
mult = cpg_pll_config->pll3_mult;
|
||||
div = cpg_pll_config->pll3_div;
|
||||
break;
|
||||
|
||||
case CLK_TYPE_GEN4_PLL4:
|
||||
mult = cpg_pll_config->pll4_mult;
|
||||
div = cpg_pll_config->pll4_div;
|
||||
break;
|
||||
|
||||
case CLK_TYPE_GEN4_PLL5:
|
||||
mult = cpg_pll_config->pll5_mult;
|
||||
div = cpg_pll_config->pll5_div;
|
||||
break;
|
||||
|
||||
case CLK_TYPE_GEN4_PLL6:
|
||||
mult = cpg_pll_config->pll6_mult;
|
||||
div = cpg_pll_config->pll6_div;
|
||||
break;
|
||||
|
||||
case CLK_TYPE_GEN4_PLL2X_3X:
|
||||
value = readl(base + core->offset);
|
||||
mult = (((value >> 24) & 0x7f) + 1) * 2;
|
||||
mult = (FIELD_GET(CPG_PLLxCR_STC, value) + 1) * 2;
|
||||
break;
|
||||
|
||||
case CLK_TYPE_GEN4_PLL_F8_25:
|
||||
return cpg_pll_clk_register(core->name, __clk_get_name(parent),
|
||||
base, core->offset,
|
||||
&cpg_pll_f8_25_clk_ops);
|
||||
|
||||
case CLK_TYPE_GEN4_PLL_V8_25:
|
||||
return cpg_pll_clk_register(core->name, __clk_get_name(parent),
|
||||
base, core->offset,
|
||||
&cpg_pll_v8_25_clk_ops);
|
||||
|
||||
case CLK_TYPE_GEN4_PLL_V9_24:
|
||||
/* Variable fractional 9.24 is not yet supported, using fixed */
|
||||
fallthrough;
|
||||
case CLK_TYPE_GEN4_PLL_F9_24:
|
||||
return cpg_pll_clk_register(core->name, __clk_get_name(parent),
|
||||
base, core->offset,
|
||||
&cpg_pll_f9_24_clk_ops);
|
||||
|
||||
case CLK_TYPE_GEN4_Z:
|
||||
return cpg_z_clk_register(core->name, __clk_get_name(parent),
|
||||
base, core->div, core->offset);
|
||||
|
||||
case CLK_TYPE_GEN4_SDSRC:
|
||||
div = ((readl(base + SD0CKCR1) >> 29) & 0x03) + 4;
|
||||
value = readl(base + CPG_SD0CKCR1);
|
||||
div = FIELD_GET(CPG_SD0CKCR1_SDSRC_SEL, value) + 4;
|
||||
break;
|
||||
|
||||
case CLK_TYPE_GEN4_SDH:
|
||||
|
|
|
|||
|
|
@ -12,13 +12,12 @@
|
|||
enum rcar_gen4_clk_types {
|
||||
CLK_TYPE_GEN4_MAIN = CLK_TYPE_CUSTOM,
|
||||
CLK_TYPE_GEN4_PLL1,
|
||||
CLK_TYPE_GEN4_PLL2,
|
||||
CLK_TYPE_GEN4_PLL2_VAR,
|
||||
CLK_TYPE_GEN4_PLL2X_3X, /* r8a779a0 only */
|
||||
CLK_TYPE_GEN4_PLL3,
|
||||
CLK_TYPE_GEN4_PLL4,
|
||||
CLK_TYPE_GEN4_PLL5,
|
||||
CLK_TYPE_GEN4_PLL6,
|
||||
CLK_TYPE_GEN4_PLL_F8_25, /* Fixed fractional 8.25 PLL */
|
||||
CLK_TYPE_GEN4_PLL_V8_25, /* Variable fractional 8.25 PLL */
|
||||
CLK_TYPE_GEN4_PLL_F9_24, /* Fixed fractional 9.24 PLL */
|
||||
CLK_TYPE_GEN4_PLL_V9_24, /* Variable fractional 9.24 PLL */
|
||||
CLK_TYPE_GEN4_SDSRC,
|
||||
CLK_TYPE_GEN4_SDH,
|
||||
CLK_TYPE_GEN4_SD,
|
||||
|
|
@ -47,6 +46,18 @@ enum rcar_gen4_clk_types {
|
|||
#define DEF_GEN4_OSC(_name, _id, _parent, _div) \
|
||||
DEF_BASE(_name, _id, CLK_TYPE_GEN4_OSC, _parent, .div = _div)
|
||||
|
||||
#define DEF_GEN4_PLL_F8_25(_name, _idx, _id, _parent) \
|
||||
DEF_BASE(_name, _id, CLK_TYPE_GEN4_PLL_F8_25, _parent, .offset = _idx)
|
||||
|
||||
#define DEF_GEN4_PLL_V8_25(_name, _idx, _id, _parent) \
|
||||
DEF_BASE(_name, _id, CLK_TYPE_GEN4_PLL_V8_25, _parent, .offset = _idx)
|
||||
|
||||
#define DEF_GEN4_PLL_F9_24(_name, _idx, _id, _parent) \
|
||||
DEF_BASE(_name, _id, CLK_TYPE_GEN4_PLL_F9_24, _parent, .offset = _idx)
|
||||
|
||||
#define DEF_GEN4_PLL_V9_24(_name, _idx, _id, _parent) \
|
||||
DEF_BASE(_name, _id, CLK_TYPE_GEN4_PLL_V9_24, _parent, .offset = _idx)
|
||||
|
||||
#define DEF_GEN4_Z(_name, _id, _type, _parent, _div, _offset) \
|
||||
DEF_BASE(_name, _id, _type, _parent, .div = _div, .offset = _offset)
|
||||
|
||||
|
|
@ -54,21 +65,16 @@ struct rcar_gen4_cpg_pll_config {
|
|||
u8 extal_div;
|
||||
u8 pll1_mult;
|
||||
u8 pll1_div;
|
||||
u8 pll2_mult;
|
||||
u8 pll2_div;
|
||||
u8 pll3_mult;
|
||||
u8 pll3_div;
|
||||
u8 pll4_mult;
|
||||
u8 pll4_div;
|
||||
u8 pll5_mult;
|
||||
u8 pll5_div;
|
||||
u8 pll6_mult;
|
||||
u8 pll6_div;
|
||||
u8 osc_prediv;
|
||||
};
|
||||
|
||||
#define CPG_RPCCKCR 0x874
|
||||
#define SD0CKCR1 0x8a4
|
||||
#define CPG_SD0CKCR 0x870 /* SD-IF0 Clock Frequency Control Register */
|
||||
#define CPG_CANFDCKCR 0x878 /* CAN-FD Clock Frequency Control Register */
|
||||
#define CPG_MSOCKCR 0x87c /* MSIOF Clock Frequency Control Register */
|
||||
#define CPG_CSICKCR 0x880 /* CSI Clock Frequency Control Register */
|
||||
#define CPG_DSIEXTCKCR 0x884 /* DSI Clock Frequency Control Register */
|
||||
|
||||
struct clk *rcar_gen4_cpg_clk_register(struct device *dev,
|
||||
const struct cpg_core_clk *core, const struct cpg_mssr_info *info,
|
||||
|
|
|
|||
|
|
@ -339,8 +339,7 @@ static const struct clk_ops rzg3s_div_clk_ops = {
|
|||
};
|
||||
|
||||
static struct clk * __init
|
||||
rzg3s_cpg_div_clk_register(const struct cpg_core_clk *core, struct clk **clks,
|
||||
void __iomem *base, struct rzg2l_cpg_priv *priv)
|
||||
rzg3s_cpg_div_clk_register(const struct cpg_core_clk *core, struct rzg2l_cpg_priv *priv)
|
||||
{
|
||||
struct div_hw_data *div_hw_data;
|
||||
struct clk_init_data init = {};
|
||||
|
|
@ -351,7 +350,7 @@ rzg3s_cpg_div_clk_register(const struct cpg_core_clk *core, struct clk **clks,
|
|||
u32 max = 0;
|
||||
int ret;
|
||||
|
||||
parent = clks[core->parent & 0xffff];
|
||||
parent = priv->clks[core->parent];
|
||||
if (IS_ERR(parent))
|
||||
return ERR_CAST(parent);
|
||||
|
||||
|
|
@ -400,16 +399,15 @@ rzg3s_cpg_div_clk_register(const struct cpg_core_clk *core, struct clk **clks,
|
|||
|
||||
static struct clk * __init
|
||||
rzg2l_cpg_div_clk_register(const struct cpg_core_clk *core,
|
||||
struct clk **clks,
|
||||
void __iomem *base,
|
||||
struct rzg2l_cpg_priv *priv)
|
||||
{
|
||||
void __iomem *base = priv->base;
|
||||
struct device *dev = priv->dev;
|
||||
const struct clk *parent;
|
||||
const char *parent_name;
|
||||
struct clk_hw *clk_hw;
|
||||
|
||||
parent = clks[core->parent & 0xffff];
|
||||
parent = priv->clks[core->parent];
|
||||
if (IS_ERR(parent))
|
||||
return ERR_CAST(parent);
|
||||
|
||||
|
|
@ -440,7 +438,6 @@ rzg2l_cpg_div_clk_register(const struct cpg_core_clk *core,
|
|||
|
||||
static struct clk * __init
|
||||
rzg2l_cpg_mux_clk_register(const struct cpg_core_clk *core,
|
||||
void __iomem *base,
|
||||
struct rzg2l_cpg_priv *priv)
|
||||
{
|
||||
const struct clk_hw *clk_hw;
|
||||
|
|
@ -448,7 +445,7 @@ rzg2l_cpg_mux_clk_register(const struct cpg_core_clk *core,
|
|||
clk_hw = devm_clk_hw_register_mux(priv->dev, core->name,
|
||||
core->parent_names, core->num_parents,
|
||||
core->flag,
|
||||
base + GET_REG_OFFSET(core->conf),
|
||||
priv->base + GET_REG_OFFSET(core->conf),
|
||||
GET_SHIFT(core->conf),
|
||||
GET_WIDTH(core->conf),
|
||||
core->mux_flags, &priv->rmw_lock);
|
||||
|
|
@ -508,7 +505,6 @@ static const struct clk_ops rzg2l_cpg_sd_clk_mux_ops = {
|
|||
|
||||
static struct clk * __init
|
||||
rzg2l_cpg_sd_mux_clk_register(const struct cpg_core_clk *core,
|
||||
void __iomem *base,
|
||||
struct rzg2l_cpg_priv *priv)
|
||||
{
|
||||
struct sd_mux_hw_data *sd_mux_hw_data;
|
||||
|
|
@ -652,7 +648,6 @@ static const struct clk_ops rzg2l_cpg_dsi_div_ops = {
|
|||
|
||||
static struct clk * __init
|
||||
rzg2l_cpg_dsi_div_clk_register(const struct cpg_core_clk *core,
|
||||
struct clk **clks,
|
||||
struct rzg2l_cpg_priv *priv)
|
||||
{
|
||||
struct dsi_div_hw_data *clk_hw_data;
|
||||
|
|
@ -662,7 +657,7 @@ rzg2l_cpg_dsi_div_clk_register(const struct cpg_core_clk *core,
|
|||
struct clk_hw *clk_hw;
|
||||
int ret;
|
||||
|
||||
parent = clks[core->parent & 0xffff];
|
||||
parent = priv->clks[core->parent];
|
||||
if (IS_ERR(parent))
|
||||
return ERR_CAST(parent);
|
||||
|
||||
|
|
@ -900,7 +895,6 @@ static const struct clk_ops rzg2l_cpg_sipll5_ops = {
|
|||
|
||||
static struct clk * __init
|
||||
rzg2l_cpg_sipll5_register(const struct cpg_core_clk *core,
|
||||
struct clk **clks,
|
||||
struct rzg2l_cpg_priv *priv)
|
||||
{
|
||||
const struct clk *parent;
|
||||
|
|
@ -910,7 +904,7 @@ rzg2l_cpg_sipll5_register(const struct cpg_core_clk *core,
|
|||
struct clk_hw *clk_hw;
|
||||
int ret;
|
||||
|
||||
parent = clks[core->parent & 0xffff];
|
||||
parent = priv->clks[core->parent];
|
||||
if (IS_ERR(parent))
|
||||
return ERR_CAST(parent);
|
||||
|
||||
|
|
@ -1013,8 +1007,6 @@ static const struct clk_ops rzg3s_cpg_pll_ops = {
|
|||
|
||||
static struct clk * __init
|
||||
rzg2l_cpg_pll_clk_register(const struct cpg_core_clk *core,
|
||||
struct clk **clks,
|
||||
void __iomem *base,
|
||||
struct rzg2l_cpg_priv *priv,
|
||||
const struct clk_ops *ops)
|
||||
{
|
||||
|
|
@ -1023,8 +1015,9 @@ rzg2l_cpg_pll_clk_register(const struct cpg_core_clk *core,
|
|||
struct clk_init_data init;
|
||||
const char *parent_name;
|
||||
struct pll_clk *pll_clk;
|
||||
int ret;
|
||||
|
||||
parent = clks[core->parent & 0xffff];
|
||||
parent = priv->clks[core->parent];
|
||||
if (IS_ERR(parent))
|
||||
return ERR_CAST(parent);
|
||||
|
||||
|
|
@ -1041,11 +1034,15 @@ rzg2l_cpg_pll_clk_register(const struct cpg_core_clk *core,
|
|||
|
||||
pll_clk->hw.init = &init;
|
||||
pll_clk->conf = core->conf;
|
||||
pll_clk->base = base;
|
||||
pll_clk->base = priv->base;
|
||||
pll_clk->priv = priv;
|
||||
pll_clk->type = core->type;
|
||||
|
||||
return clk_register(NULL, &pll_clk->hw);
|
||||
ret = devm_clk_hw_register(dev, &pll_clk->hw);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
|
||||
return pll_clk->hw.clk;
|
||||
}
|
||||
|
||||
static struct clk
|
||||
|
|
@ -1102,6 +1099,7 @@ rzg2l_cpg_register_core_clk(const struct cpg_core_clk *core,
|
|||
struct device *dev = priv->dev;
|
||||
unsigned int id = core->id, div = core->div;
|
||||
const char *parent_name;
|
||||
struct clk_hw *clk_hw;
|
||||
|
||||
WARN_DEBUG(id >= priv->num_core_clks);
|
||||
WARN_DEBUG(PTR_ERR(priv->clks[id]) != -ENOENT);
|
||||
|
|
@ -1124,39 +1122,40 @@ rzg2l_cpg_register_core_clk(const struct cpg_core_clk *core,
|
|||
}
|
||||
|
||||
parent_name = __clk_get_name(parent);
|
||||
clk = clk_register_fixed_factor(NULL, core->name,
|
||||
parent_name, CLK_SET_RATE_PARENT,
|
||||
core->mult, div);
|
||||
clk_hw = devm_clk_hw_register_fixed_factor(dev, core->name, parent_name,
|
||||
CLK_SET_RATE_PARENT,
|
||||
core->mult, div);
|
||||
if (IS_ERR(clk_hw))
|
||||
clk = ERR_CAST(clk_hw);
|
||||
else
|
||||
clk = clk_hw->clk;
|
||||
break;
|
||||
case CLK_TYPE_SAM_PLL:
|
||||
clk = rzg2l_cpg_pll_clk_register(core, priv->clks, priv->base, priv,
|
||||
&rzg2l_cpg_pll_ops);
|
||||
clk = rzg2l_cpg_pll_clk_register(core, priv, &rzg2l_cpg_pll_ops);
|
||||
break;
|
||||
case CLK_TYPE_G3S_PLL:
|
||||
clk = rzg2l_cpg_pll_clk_register(core, priv->clks, priv->base, priv,
|
||||
&rzg3s_cpg_pll_ops);
|
||||
clk = rzg2l_cpg_pll_clk_register(core, priv, &rzg3s_cpg_pll_ops);
|
||||
break;
|
||||
case CLK_TYPE_SIPLL5:
|
||||
clk = rzg2l_cpg_sipll5_register(core, priv->clks, priv);
|
||||
clk = rzg2l_cpg_sipll5_register(core, priv);
|
||||
break;
|
||||
case CLK_TYPE_DIV:
|
||||
clk = rzg2l_cpg_div_clk_register(core, priv->clks,
|
||||
priv->base, priv);
|
||||
clk = rzg2l_cpg_div_clk_register(core, priv);
|
||||
break;
|
||||
case CLK_TYPE_G3S_DIV:
|
||||
clk = rzg3s_cpg_div_clk_register(core, priv->clks, priv->base, priv);
|
||||
clk = rzg3s_cpg_div_clk_register(core, priv);
|
||||
break;
|
||||
case CLK_TYPE_MUX:
|
||||
clk = rzg2l_cpg_mux_clk_register(core, priv->base, priv);
|
||||
clk = rzg2l_cpg_mux_clk_register(core, priv);
|
||||
break;
|
||||
case CLK_TYPE_SD_MUX:
|
||||
clk = rzg2l_cpg_sd_mux_clk_register(core, priv->base, priv);
|
||||
clk = rzg2l_cpg_sd_mux_clk_register(core, priv);
|
||||
break;
|
||||
case CLK_TYPE_PLL5_4_MUX:
|
||||
clk = rzg2l_cpg_pll5_4_mux_clk_register(core, priv);
|
||||
break;
|
||||
case CLK_TYPE_DSI_DIV:
|
||||
clk = rzg2l_cpg_dsi_div_clk_register(core, priv->clks, priv);
|
||||
clk = rzg2l_cpg_dsi_div_clk_register(core, priv);
|
||||
break;
|
||||
default:
|
||||
goto fail;
|
||||
|
|
@ -1337,6 +1336,7 @@ rzg2l_cpg_register_mod_clk(const struct rzg2l_mod_clk *mod,
|
|||
struct clk *parent, *clk;
|
||||
const char *parent_name;
|
||||
unsigned int i;
|
||||
int ret;
|
||||
|
||||
WARN_DEBUG(id < priv->num_core_clks);
|
||||
WARN_DEBUG(id >= priv->num_core_clks + priv->num_mod_clks);
|
||||
|
|
@ -1380,10 +1380,13 @@ rzg2l_cpg_register_mod_clk(const struct rzg2l_mod_clk *mod,
|
|||
clock->priv = priv;
|
||||
clock->hw.init = &init;
|
||||
|
||||
clk = clk_register(NULL, &clock->hw);
|
||||
if (IS_ERR(clk))
|
||||
ret = devm_clk_hw_register(dev, &clock->hw);
|
||||
if (ret) {
|
||||
clk = ERR_PTR(ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
clk = clock->hw.clk;
|
||||
dev_dbg(dev, "Module clock %pC at %lu Hz\n", clk, clk_get_rate(clk));
|
||||
priv->clks[id] = clk;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,853 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Renesas RZ/V2H(P) Clock Pulse Generator
|
||||
*
|
||||
* Copyright (C) 2024 Renesas Electronics Corp.
|
||||
*
|
||||
* Based on rzg2l-cpg.c
|
||||
*
|
||||
* Copyright (C) 2015 Glider bvba
|
||||
* Copyright (C) 2013 Ideas On Board SPRL
|
||||
* Copyright (C) 2015 Renesas Electronics Corp.
|
||||
*/
|
||||
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/clk-provider.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/iopoll.h>
|
||||
#include <linux/mod_devicetable.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/pm_clock.h>
|
||||
#include <linux/pm_domain.h>
|
||||
#include <linux/reset-controller.h>
|
||||
|
||||
#include <dt-bindings/clock/renesas-cpg-mssr.h>
|
||||
|
||||
#include "rzv2h-cpg.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define WARN_DEBUG(x) WARN_ON(x)
|
||||
#else
|
||||
#define WARN_DEBUG(x) do { } while (0)
|
||||
#endif
|
||||
|
||||
#define GET_CLK_ON_OFFSET(x) (0x600 + ((x) * 4))
|
||||
#define GET_CLK_MON_OFFSET(x) (0x800 + ((x) * 4))
|
||||
#define GET_RST_OFFSET(x) (0x900 + ((x) * 4))
|
||||
#define GET_RST_MON_OFFSET(x) (0xA00 + ((x) * 4))
|
||||
|
||||
#define KDIV(val) ((s16)FIELD_GET(GENMASK(31, 16), (val)))
|
||||
#define MDIV(val) FIELD_GET(GENMASK(15, 6), (val))
|
||||
#define PDIV(val) FIELD_GET(GENMASK(5, 0), (val))
|
||||
#define SDIV(val) FIELD_GET(GENMASK(2, 0), (val))
|
||||
|
||||
#define DDIV_DIVCTL_WEN(shift) BIT((shift) + 16)
|
||||
|
||||
#define GET_MOD_CLK_ID(base, index, bit) \
|
||||
((base) + ((((index) * (16))) + (bit)))
|
||||
|
||||
#define CPG_CLKSTATUS0 (0x700)
|
||||
|
||||
/**
|
||||
* struct rzv2h_cpg_priv - Clock Pulse Generator Private Data
|
||||
*
|
||||
* @dev: CPG device
|
||||
* @base: CPG register block base address
|
||||
* @rmw_lock: protects register accesses
|
||||
* @clks: Array containing all Core and Module Clocks
|
||||
* @num_core_clks: Number of Core Clocks in clks[]
|
||||
* @num_mod_clks: Number of Module Clocks in clks[]
|
||||
* @resets: Array of resets
|
||||
* @num_resets: Number of Module Resets in info->resets[]
|
||||
* @last_dt_core_clk: ID of the last Core Clock exported to DT
|
||||
* @rcdev: Reset controller entity
|
||||
*/
|
||||
struct rzv2h_cpg_priv {
|
||||
struct device *dev;
|
||||
void __iomem *base;
|
||||
spinlock_t rmw_lock;
|
||||
|
||||
struct clk **clks;
|
||||
unsigned int num_core_clks;
|
||||
unsigned int num_mod_clks;
|
||||
struct rzv2h_reset *resets;
|
||||
unsigned int num_resets;
|
||||
unsigned int last_dt_core_clk;
|
||||
|
||||
struct reset_controller_dev rcdev;
|
||||
};
|
||||
|
||||
#define rcdev_to_priv(x) container_of(x, struct rzv2h_cpg_priv, rcdev)
|
||||
|
||||
struct pll_clk {
|
||||
struct rzv2h_cpg_priv *priv;
|
||||
void __iomem *base;
|
||||
struct clk_hw hw;
|
||||
unsigned int conf;
|
||||
unsigned int type;
|
||||
};
|
||||
|
||||
#define to_pll(_hw) container_of(_hw, struct pll_clk, hw)
|
||||
|
||||
/**
|
||||
* struct mod_clock - Module clock
|
||||
*
|
||||
* @priv: CPG private data
|
||||
* @hw: handle between common and hardware-specific interfaces
|
||||
* @on_index: register offset
|
||||
* @on_bit: ON/MON bit
|
||||
* @mon_index: monitor register offset
|
||||
* @mon_bit: montor bit
|
||||
*/
|
||||
struct mod_clock {
|
||||
struct rzv2h_cpg_priv *priv;
|
||||
struct clk_hw hw;
|
||||
u8 on_index;
|
||||
u8 on_bit;
|
||||
s8 mon_index;
|
||||
u8 mon_bit;
|
||||
};
|
||||
|
||||
#define to_mod_clock(_hw) container_of(_hw, struct mod_clock, hw)
|
||||
|
||||
/**
|
||||
* struct ddiv_clk - DDIV clock
|
||||
*
|
||||
* @priv: CPG private data
|
||||
* @div: divider clk
|
||||
* @mon: monitor bit in CPG_CLKSTATUS0 register
|
||||
*/
|
||||
struct ddiv_clk {
|
||||
struct rzv2h_cpg_priv *priv;
|
||||
struct clk_divider div;
|
||||
u8 mon;
|
||||
};
|
||||
|
||||
#define to_ddiv_clock(_div) container_of(_div, struct ddiv_clk, div)
|
||||
|
||||
static unsigned long rzv2h_cpg_pll_clk_recalc_rate(struct clk_hw *hw,
|
||||
unsigned long parent_rate)
|
||||
{
|
||||
struct pll_clk *pll_clk = to_pll(hw);
|
||||
struct rzv2h_cpg_priv *priv = pll_clk->priv;
|
||||
unsigned int clk1, clk2;
|
||||
u64 rate;
|
||||
|
||||
if (!PLL_CLK_ACCESS(pll_clk->conf))
|
||||
return 0;
|
||||
|
||||
clk1 = readl(priv->base + PLL_CLK1_OFFSET(pll_clk->conf));
|
||||
clk2 = readl(priv->base + PLL_CLK2_OFFSET(pll_clk->conf));
|
||||
|
||||
rate = mul_u64_u32_shr(parent_rate, (MDIV(clk1) << 16) + KDIV(clk1),
|
||||
16 + SDIV(clk2));
|
||||
|
||||
return DIV_ROUND_CLOSEST_ULL(rate, PDIV(clk1));
|
||||
}
|
||||
|
||||
static const struct clk_ops rzv2h_cpg_pll_ops = {
|
||||
.recalc_rate = rzv2h_cpg_pll_clk_recalc_rate,
|
||||
};
|
||||
|
||||
static struct clk * __init
|
||||
rzv2h_cpg_pll_clk_register(const struct cpg_core_clk *core,
|
||||
struct rzv2h_cpg_priv *priv,
|
||||
const struct clk_ops *ops)
|
||||
{
|
||||
void __iomem *base = priv->base;
|
||||
struct device *dev = priv->dev;
|
||||
struct clk_init_data init;
|
||||
const struct clk *parent;
|
||||
const char *parent_name;
|
||||
struct pll_clk *pll_clk;
|
||||
int ret;
|
||||
|
||||
parent = priv->clks[core->parent];
|
||||
if (IS_ERR(parent))
|
||||
return ERR_CAST(parent);
|
||||
|
||||
pll_clk = devm_kzalloc(dev, sizeof(*pll_clk), GFP_KERNEL);
|
||||
if (!pll_clk)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
parent_name = __clk_get_name(parent);
|
||||
init.name = core->name;
|
||||
init.ops = ops;
|
||||
init.flags = 0;
|
||||
init.parent_names = &parent_name;
|
||||
init.num_parents = 1;
|
||||
|
||||
pll_clk->hw.init = &init;
|
||||
pll_clk->conf = core->cfg.conf;
|
||||
pll_clk->base = base;
|
||||
pll_clk->priv = priv;
|
||||
pll_clk->type = core->type;
|
||||
|
||||
ret = devm_clk_hw_register(dev, &pll_clk->hw);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
|
||||
return pll_clk->hw.clk;
|
||||
}
|
||||
|
||||
static unsigned long rzv2h_ddiv_recalc_rate(struct clk_hw *hw,
|
||||
unsigned long parent_rate)
|
||||
{
|
||||
struct clk_divider *divider = to_clk_divider(hw);
|
||||
unsigned int val;
|
||||
|
||||
val = readl(divider->reg) >> divider->shift;
|
||||
val &= clk_div_mask(divider->width);
|
||||
|
||||
return divider_recalc_rate(hw, parent_rate, val, divider->table,
|
||||
divider->flags, divider->width);
|
||||
}
|
||||
|
||||
static long rzv2h_ddiv_round_rate(struct clk_hw *hw, unsigned long rate,
|
||||
unsigned long *prate)
|
||||
{
|
||||
struct clk_divider *divider = to_clk_divider(hw);
|
||||
|
||||
return divider_round_rate(hw, rate, prate, divider->table,
|
||||
divider->width, divider->flags);
|
||||
}
|
||||
|
||||
static int rzv2h_ddiv_determine_rate(struct clk_hw *hw,
|
||||
struct clk_rate_request *req)
|
||||
{
|
||||
struct clk_divider *divider = to_clk_divider(hw);
|
||||
|
||||
return divider_determine_rate(hw, req, divider->table, divider->width,
|
||||
divider->flags);
|
||||
}
|
||||
|
||||
static inline int rzv2h_cpg_wait_ddiv_clk_update_done(void __iomem *base, u8 mon)
|
||||
{
|
||||
u32 bitmask = BIT(mon);
|
||||
u32 val;
|
||||
|
||||
return readl_poll_timeout_atomic(base + CPG_CLKSTATUS0, val, !(val & bitmask), 10, 200);
|
||||
}
|
||||
|
||||
static int rzv2h_ddiv_set_rate(struct clk_hw *hw, unsigned long rate,
|
||||
unsigned long parent_rate)
|
||||
{
|
||||
struct clk_divider *divider = to_clk_divider(hw);
|
||||
struct ddiv_clk *ddiv = to_ddiv_clock(divider);
|
||||
struct rzv2h_cpg_priv *priv = ddiv->priv;
|
||||
unsigned long flags = 0;
|
||||
int value;
|
||||
u32 val;
|
||||
int ret;
|
||||
|
||||
value = divider_get_val(rate, parent_rate, divider->table,
|
||||
divider->width, divider->flags);
|
||||
if (value < 0)
|
||||
return value;
|
||||
|
||||
spin_lock_irqsave(divider->lock, flags);
|
||||
|
||||
ret = rzv2h_cpg_wait_ddiv_clk_update_done(priv->base, ddiv->mon);
|
||||
if (ret)
|
||||
goto ddiv_timeout;
|
||||
|
||||
val = readl(divider->reg) | DDIV_DIVCTL_WEN(divider->shift);
|
||||
val &= ~(clk_div_mask(divider->width) << divider->shift);
|
||||
val |= (u32)value << divider->shift;
|
||||
writel(val, divider->reg);
|
||||
|
||||
ret = rzv2h_cpg_wait_ddiv_clk_update_done(priv->base, ddiv->mon);
|
||||
if (ret)
|
||||
goto ddiv_timeout;
|
||||
|
||||
spin_unlock_irqrestore(divider->lock, flags);
|
||||
|
||||
return 0;
|
||||
|
||||
ddiv_timeout:
|
||||
spin_unlock_irqrestore(divider->lock, flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct clk_ops rzv2h_ddiv_clk_divider_ops = {
|
||||
.recalc_rate = rzv2h_ddiv_recalc_rate,
|
||||
.round_rate = rzv2h_ddiv_round_rate,
|
||||
.determine_rate = rzv2h_ddiv_determine_rate,
|
||||
.set_rate = rzv2h_ddiv_set_rate,
|
||||
};
|
||||
|
||||
static struct clk * __init
|
||||
rzv2h_cpg_ddiv_clk_register(const struct cpg_core_clk *core,
|
||||
struct rzv2h_cpg_priv *priv)
|
||||
{
|
||||
struct ddiv cfg_ddiv = core->cfg.ddiv;
|
||||
struct clk_init_data init = {};
|
||||
struct device *dev = priv->dev;
|
||||
u8 shift = cfg_ddiv.shift;
|
||||
u8 width = cfg_ddiv.width;
|
||||
const struct clk *parent;
|
||||
const char *parent_name;
|
||||
struct clk_divider *div;
|
||||
struct ddiv_clk *ddiv;
|
||||
int ret;
|
||||
|
||||
parent = priv->clks[core->parent];
|
||||
if (IS_ERR(parent))
|
||||
return ERR_CAST(parent);
|
||||
|
||||
parent_name = __clk_get_name(parent);
|
||||
|
||||
if ((shift + width) > 16)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
ddiv = devm_kzalloc(priv->dev, sizeof(*ddiv), GFP_KERNEL);
|
||||
if (!ddiv)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
init.name = core->name;
|
||||
init.ops = &rzv2h_ddiv_clk_divider_ops;
|
||||
init.parent_names = &parent_name;
|
||||
init.num_parents = 1;
|
||||
|
||||
ddiv->priv = priv;
|
||||
ddiv->mon = cfg_ddiv.monbit;
|
||||
div = &ddiv->div;
|
||||
div->reg = priv->base + cfg_ddiv.offset;
|
||||
div->shift = shift;
|
||||
div->width = width;
|
||||
div->flags = core->flag;
|
||||
div->lock = &priv->rmw_lock;
|
||||
div->hw.init = &init;
|
||||
div->table = core->dtable;
|
||||
|
||||
ret = devm_clk_hw_register(dev, &div->hw);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
|
||||
return div->hw.clk;
|
||||
}
|
||||
|
||||
static struct clk
|
||||
*rzv2h_cpg_clk_src_twocell_get(struct of_phandle_args *clkspec,
|
||||
void *data)
|
||||
{
|
||||
unsigned int clkidx = clkspec->args[1];
|
||||
struct rzv2h_cpg_priv *priv = data;
|
||||
struct device *dev = priv->dev;
|
||||
const char *type;
|
||||
struct clk *clk;
|
||||
|
||||
switch (clkspec->args[0]) {
|
||||
case CPG_CORE:
|
||||
type = "core";
|
||||
if (clkidx > priv->last_dt_core_clk) {
|
||||
dev_err(dev, "Invalid %s clock index %u\n", type, clkidx);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
clk = priv->clks[clkidx];
|
||||
break;
|
||||
|
||||
case CPG_MOD:
|
||||
type = "module";
|
||||
if (clkidx >= priv->num_mod_clks) {
|
||||
dev_err(dev, "Invalid %s clock index %u\n", type, clkidx);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
clk = priv->clks[priv->num_core_clks + clkidx];
|
||||
break;
|
||||
|
||||
default:
|
||||
dev_err(dev, "Invalid CPG clock type %u\n", clkspec->args[0]);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
if (IS_ERR(clk))
|
||||
dev_err(dev, "Cannot get %s clock %u: %ld", type, clkidx,
|
||||
PTR_ERR(clk));
|
||||
else
|
||||
dev_dbg(dev, "clock (%u, %u) is %pC at %lu Hz\n",
|
||||
clkspec->args[0], clkspec->args[1], clk,
|
||||
clk_get_rate(clk));
|
||||
return clk;
|
||||
}
|
||||
|
||||
static void __init
|
||||
rzv2h_cpg_register_core_clk(const struct cpg_core_clk *core,
|
||||
struct rzv2h_cpg_priv *priv)
|
||||
{
|
||||
struct clk *clk = ERR_PTR(-EOPNOTSUPP), *parent;
|
||||
unsigned int id = core->id, div = core->div;
|
||||
struct device *dev = priv->dev;
|
||||
const char *parent_name;
|
||||
struct clk_hw *clk_hw;
|
||||
|
||||
WARN_DEBUG(id >= priv->num_core_clks);
|
||||
WARN_DEBUG(PTR_ERR(priv->clks[id]) != -ENOENT);
|
||||
|
||||
switch (core->type) {
|
||||
case CLK_TYPE_IN:
|
||||
clk = of_clk_get_by_name(priv->dev->of_node, core->name);
|
||||
break;
|
||||
case CLK_TYPE_FF:
|
||||
WARN_DEBUG(core->parent >= priv->num_core_clks);
|
||||
parent = priv->clks[core->parent];
|
||||
if (IS_ERR(parent)) {
|
||||
clk = parent;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
parent_name = __clk_get_name(parent);
|
||||
clk_hw = devm_clk_hw_register_fixed_factor(dev, core->name,
|
||||
parent_name, CLK_SET_RATE_PARENT,
|
||||
core->mult, div);
|
||||
if (IS_ERR(clk_hw))
|
||||
clk = ERR_CAST(clk_hw);
|
||||
else
|
||||
clk = clk_hw->clk;
|
||||
break;
|
||||
case CLK_TYPE_PLL:
|
||||
clk = rzv2h_cpg_pll_clk_register(core, priv, &rzv2h_cpg_pll_ops);
|
||||
break;
|
||||
case CLK_TYPE_DDIV:
|
||||
clk = rzv2h_cpg_ddiv_clk_register(core, priv);
|
||||
break;
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (IS_ERR_OR_NULL(clk))
|
||||
goto fail;
|
||||
|
||||
dev_dbg(dev, "Core clock %pC at %lu Hz\n", clk, clk_get_rate(clk));
|
||||
priv->clks[id] = clk;
|
||||
return;
|
||||
|
||||
fail:
|
||||
dev_err(dev, "Failed to register core clock %s: %ld\n",
|
||||
core->name, PTR_ERR(clk));
|
||||
}
|
||||
|
||||
static int rzv2h_mod_clock_endisable(struct clk_hw *hw, bool enable)
|
||||
{
|
||||
struct mod_clock *clock = to_mod_clock(hw);
|
||||
unsigned int reg = GET_CLK_ON_OFFSET(clock->on_index);
|
||||
struct rzv2h_cpg_priv *priv = clock->priv;
|
||||
u32 bitmask = BIT(clock->on_bit);
|
||||
struct device *dev = priv->dev;
|
||||
u32 value;
|
||||
int error;
|
||||
|
||||
dev_dbg(dev, "CLK_ON 0x%x/%pC %s\n", reg, hw->clk,
|
||||
enable ? "ON" : "OFF");
|
||||
|
||||
value = bitmask << 16;
|
||||
if (enable)
|
||||
value |= bitmask;
|
||||
|
||||
writel(value, priv->base + reg);
|
||||
|
||||
if (!enable || clock->mon_index < 0)
|
||||
return 0;
|
||||
|
||||
reg = GET_CLK_MON_OFFSET(clock->mon_index);
|
||||
bitmask = BIT(clock->mon_bit);
|
||||
error = readl_poll_timeout_atomic(priv->base + reg, value,
|
||||
value & bitmask, 0, 10);
|
||||
if (error)
|
||||
dev_err(dev, "Failed to enable CLK_ON %p\n",
|
||||
priv->base + reg);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static int rzv2h_mod_clock_enable(struct clk_hw *hw)
|
||||
{
|
||||
return rzv2h_mod_clock_endisable(hw, true);
|
||||
}
|
||||
|
||||
static void rzv2h_mod_clock_disable(struct clk_hw *hw)
|
||||
{
|
||||
rzv2h_mod_clock_endisable(hw, false);
|
||||
}
|
||||
|
||||
static int rzv2h_mod_clock_is_enabled(struct clk_hw *hw)
|
||||
{
|
||||
struct mod_clock *clock = to_mod_clock(hw);
|
||||
struct rzv2h_cpg_priv *priv = clock->priv;
|
||||
u32 bitmask;
|
||||
u32 offset;
|
||||
|
||||
if (clock->mon_index >= 0) {
|
||||
offset = GET_CLK_MON_OFFSET(clock->mon_index);
|
||||
bitmask = BIT(clock->mon_bit);
|
||||
} else {
|
||||
offset = GET_CLK_ON_OFFSET(clock->on_index);
|
||||
bitmask = BIT(clock->on_bit);
|
||||
}
|
||||
|
||||
return readl(priv->base + offset) & bitmask;
|
||||
}
|
||||
|
||||
static const struct clk_ops rzv2h_mod_clock_ops = {
|
||||
.enable = rzv2h_mod_clock_enable,
|
||||
.disable = rzv2h_mod_clock_disable,
|
||||
.is_enabled = rzv2h_mod_clock_is_enabled,
|
||||
};
|
||||
|
||||
static void __init
|
||||
rzv2h_cpg_register_mod_clk(const struct rzv2h_mod_clk *mod,
|
||||
struct rzv2h_cpg_priv *priv)
|
||||
{
|
||||
struct mod_clock *clock = NULL;
|
||||
struct device *dev = priv->dev;
|
||||
struct clk_init_data init;
|
||||
struct clk *parent, *clk;
|
||||
const char *parent_name;
|
||||
unsigned int id;
|
||||
int ret;
|
||||
|
||||
id = GET_MOD_CLK_ID(priv->num_core_clks, mod->on_index, mod->on_bit);
|
||||
WARN_DEBUG(id >= priv->num_core_clks + priv->num_mod_clks);
|
||||
WARN_DEBUG(mod->parent >= priv->num_core_clks + priv->num_mod_clks);
|
||||
WARN_DEBUG(PTR_ERR(priv->clks[id]) != -ENOENT);
|
||||
|
||||
parent = priv->clks[mod->parent];
|
||||
if (IS_ERR(parent)) {
|
||||
clk = parent;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
clock = devm_kzalloc(dev, sizeof(*clock), GFP_KERNEL);
|
||||
if (!clock) {
|
||||
clk = ERR_PTR(-ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
init.name = mod->name;
|
||||
init.ops = &rzv2h_mod_clock_ops;
|
||||
init.flags = CLK_SET_RATE_PARENT;
|
||||
if (mod->critical)
|
||||
init.flags |= CLK_IS_CRITICAL;
|
||||
|
||||
parent_name = __clk_get_name(parent);
|
||||
init.parent_names = &parent_name;
|
||||
init.num_parents = 1;
|
||||
|
||||
clock->on_index = mod->on_index;
|
||||
clock->on_bit = mod->on_bit;
|
||||
clock->mon_index = mod->mon_index;
|
||||
clock->mon_bit = mod->mon_bit;
|
||||
clock->priv = priv;
|
||||
clock->hw.init = &init;
|
||||
|
||||
ret = devm_clk_hw_register(dev, &clock->hw);
|
||||
if (ret) {
|
||||
clk = ERR_PTR(ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
priv->clks[id] = clock->hw.clk;
|
||||
|
||||
return;
|
||||
|
||||
fail:
|
||||
dev_err(dev, "Failed to register module clock %s: %ld\n",
|
||||
mod->name, PTR_ERR(clk));
|
||||
}
|
||||
|
||||
static int rzv2h_cpg_assert(struct reset_controller_dev *rcdev,
|
||||
unsigned long id)
|
||||
{
|
||||
struct rzv2h_cpg_priv *priv = rcdev_to_priv(rcdev);
|
||||
unsigned int reg = GET_RST_OFFSET(priv->resets[id].reset_index);
|
||||
u32 mask = BIT(priv->resets[id].reset_bit);
|
||||
u8 monbit = priv->resets[id].mon_bit;
|
||||
u32 value = mask << 16;
|
||||
|
||||
dev_dbg(rcdev->dev, "assert id:%ld offset:0x%x\n", id, reg);
|
||||
|
||||
writel(value, priv->base + reg);
|
||||
|
||||
reg = GET_RST_MON_OFFSET(priv->resets[id].mon_index);
|
||||
mask = BIT(monbit);
|
||||
|
||||
return readl_poll_timeout_atomic(priv->base + reg, value,
|
||||
value & mask, 10, 200);
|
||||
}
|
||||
|
||||
static int rzv2h_cpg_deassert(struct reset_controller_dev *rcdev,
|
||||
unsigned long id)
|
||||
{
|
||||
struct rzv2h_cpg_priv *priv = rcdev_to_priv(rcdev);
|
||||
unsigned int reg = GET_RST_OFFSET(priv->resets[id].reset_index);
|
||||
u32 mask = BIT(priv->resets[id].reset_bit);
|
||||
u8 monbit = priv->resets[id].mon_bit;
|
||||
u32 value = (mask << 16) | mask;
|
||||
|
||||
dev_dbg(rcdev->dev, "deassert id:%ld offset:0x%x\n", id, reg);
|
||||
|
||||
writel(value, priv->base + reg);
|
||||
|
||||
reg = GET_RST_MON_OFFSET(priv->resets[id].mon_index);
|
||||
mask = BIT(monbit);
|
||||
|
||||
return readl_poll_timeout_atomic(priv->base + reg, value,
|
||||
!(value & mask), 10, 200);
|
||||
}
|
||||
|
||||
static int rzv2h_cpg_reset(struct reset_controller_dev *rcdev,
|
||||
unsigned long id)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = rzv2h_cpg_assert(rcdev, id);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return rzv2h_cpg_deassert(rcdev, id);
|
||||
}
|
||||
|
||||
static int rzv2h_cpg_status(struct reset_controller_dev *rcdev,
|
||||
unsigned long id)
|
||||
{
|
||||
struct rzv2h_cpg_priv *priv = rcdev_to_priv(rcdev);
|
||||
unsigned int reg = GET_RST_MON_OFFSET(priv->resets[id].mon_index);
|
||||
u8 monbit = priv->resets[id].mon_bit;
|
||||
|
||||
return !!(readl(priv->base + reg) & BIT(monbit));
|
||||
}
|
||||
|
||||
static const struct reset_control_ops rzv2h_cpg_reset_ops = {
|
||||
.reset = rzv2h_cpg_reset,
|
||||
.assert = rzv2h_cpg_assert,
|
||||
.deassert = rzv2h_cpg_deassert,
|
||||
.status = rzv2h_cpg_status,
|
||||
};
|
||||
|
||||
static int rzv2h_cpg_reset_xlate(struct reset_controller_dev *rcdev,
|
||||
const struct of_phandle_args *reset_spec)
|
||||
{
|
||||
struct rzv2h_cpg_priv *priv = rcdev_to_priv(rcdev);
|
||||
unsigned int id = reset_spec->args[0];
|
||||
u8 rst_index = id / 16;
|
||||
u8 rst_bit = id % 16;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < rcdev->nr_resets; i++) {
|
||||
if (rst_index == priv->resets[i].reset_index &&
|
||||
rst_bit == priv->resets[i].reset_bit)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int rzv2h_cpg_reset_controller_register(struct rzv2h_cpg_priv *priv)
|
||||
{
|
||||
priv->rcdev.ops = &rzv2h_cpg_reset_ops;
|
||||
priv->rcdev.of_node = priv->dev->of_node;
|
||||
priv->rcdev.dev = priv->dev;
|
||||
priv->rcdev.of_reset_n_cells = 1;
|
||||
priv->rcdev.of_xlate = rzv2h_cpg_reset_xlate;
|
||||
priv->rcdev.nr_resets = priv->num_resets;
|
||||
|
||||
return devm_reset_controller_register(priv->dev, &priv->rcdev);
|
||||
}
|
||||
|
||||
/**
|
||||
* struct rzv2h_cpg_pd - RZ/V2H power domain data structure
|
||||
* @priv: pointer to CPG private data structure
|
||||
* @genpd: generic PM domain
|
||||
*/
|
||||
struct rzv2h_cpg_pd {
|
||||
struct rzv2h_cpg_priv *priv;
|
||||
struct generic_pm_domain genpd;
|
||||
};
|
||||
|
||||
static int rzv2h_cpg_attach_dev(struct generic_pm_domain *domain, struct device *dev)
|
||||
{
|
||||
struct device_node *np = dev->of_node;
|
||||
struct of_phandle_args clkspec;
|
||||
bool once = true;
|
||||
struct clk *clk;
|
||||
int error;
|
||||
int i = 0;
|
||||
|
||||
while (!of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
|
||||
&clkspec)) {
|
||||
if (once) {
|
||||
once = false;
|
||||
error = pm_clk_create(dev);
|
||||
if (error) {
|
||||
of_node_put(clkspec.np);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
clk = of_clk_get_from_provider(&clkspec);
|
||||
of_node_put(clkspec.np);
|
||||
if (IS_ERR(clk)) {
|
||||
error = PTR_ERR(clk);
|
||||
goto fail_destroy;
|
||||
}
|
||||
|
||||
error = pm_clk_add_clk(dev, clk);
|
||||
if (error) {
|
||||
dev_err(dev, "pm_clk_add_clk failed %d\n",
|
||||
error);
|
||||
goto fail_put;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
fail_put:
|
||||
clk_put(clk);
|
||||
|
||||
fail_destroy:
|
||||
pm_clk_destroy(dev);
|
||||
err:
|
||||
return error;
|
||||
}
|
||||
|
||||
static void rzv2h_cpg_detach_dev(struct generic_pm_domain *unused, struct device *dev)
|
||||
{
|
||||
if (!pm_clk_no_clocks(dev))
|
||||
pm_clk_destroy(dev);
|
||||
}
|
||||
|
||||
static void rzv2h_cpg_genpd_remove_simple(void *data)
|
||||
{
|
||||
pm_genpd_remove(data);
|
||||
}
|
||||
|
||||
static int __init rzv2h_cpg_add_pm_domains(struct rzv2h_cpg_priv *priv)
|
||||
{
|
||||
struct device *dev = priv->dev;
|
||||
struct device_node *np = dev->of_node;
|
||||
struct rzv2h_cpg_pd *pd;
|
||||
int ret;
|
||||
|
||||
pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
|
||||
if (!pd)
|
||||
return -ENOMEM;
|
||||
|
||||
pd->genpd.name = np->name;
|
||||
pd->priv = priv;
|
||||
pd->genpd.flags |= GENPD_FLAG_ALWAYS_ON | GENPD_FLAG_PM_CLK | GENPD_FLAG_ACTIVE_WAKEUP;
|
||||
pd->genpd.attach_dev = rzv2h_cpg_attach_dev;
|
||||
pd->genpd.detach_dev = rzv2h_cpg_detach_dev;
|
||||
ret = pm_genpd_init(&pd->genpd, &pm_domain_always_on_gov, false);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = devm_add_action_or_reset(dev, rzv2h_cpg_genpd_remove_simple, &pd->genpd);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return of_genpd_add_provider_simple(np, &pd->genpd);
|
||||
}
|
||||
|
||||
static void rzv2h_cpg_del_clk_provider(void *data)
|
||||
{
|
||||
of_clk_del_provider(data);
|
||||
}
|
||||
|
||||
static int __init rzv2h_cpg_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct device_node *np = dev->of_node;
|
||||
const struct rzv2h_cpg_info *info;
|
||||
struct rzv2h_cpg_priv *priv;
|
||||
unsigned int nclks, i;
|
||||
struct clk **clks;
|
||||
int error;
|
||||
|
||||
info = of_device_get_match_data(dev);
|
||||
|
||||
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return -ENOMEM;
|
||||
|
||||
spin_lock_init(&priv->rmw_lock);
|
||||
|
||||
priv->dev = dev;
|
||||
|
||||
priv->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(priv->base))
|
||||
return PTR_ERR(priv->base);
|
||||
|
||||
nclks = info->num_total_core_clks + info->num_hw_mod_clks;
|
||||
clks = devm_kmalloc_array(dev, nclks, sizeof(*clks), GFP_KERNEL);
|
||||
if (!clks)
|
||||
return -ENOMEM;
|
||||
|
||||
priv->resets = devm_kmemdup(dev, info->resets, sizeof(*info->resets) *
|
||||
info->num_resets, GFP_KERNEL);
|
||||
if (!priv->resets)
|
||||
return -ENOMEM;
|
||||
|
||||
dev_set_drvdata(dev, priv);
|
||||
priv->clks = clks;
|
||||
priv->num_core_clks = info->num_total_core_clks;
|
||||
priv->num_mod_clks = info->num_hw_mod_clks;
|
||||
priv->last_dt_core_clk = info->last_dt_core_clk;
|
||||
priv->num_resets = info->num_resets;
|
||||
|
||||
for (i = 0; i < nclks; i++)
|
||||
clks[i] = ERR_PTR(-ENOENT);
|
||||
|
||||
for (i = 0; i < info->num_core_clks; i++)
|
||||
rzv2h_cpg_register_core_clk(&info->core_clks[i], priv);
|
||||
|
||||
for (i = 0; i < info->num_mod_clks; i++)
|
||||
rzv2h_cpg_register_mod_clk(&info->mod_clks[i], priv);
|
||||
|
||||
error = of_clk_add_provider(np, rzv2h_cpg_clk_src_twocell_get, priv);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
error = devm_add_action_or_reset(dev, rzv2h_cpg_del_clk_provider, np);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
error = rzv2h_cpg_add_pm_domains(priv);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
error = rzv2h_cpg_reset_controller_register(priv);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct of_device_id rzv2h_cpg_match[] = {
|
||||
#ifdef CONFIG_CLK_R9A09G057
|
||||
{
|
||||
.compatible = "renesas,r9a09g057-cpg",
|
||||
.data = &r9a09g057_cpg_info,
|
||||
},
|
||||
#endif
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
|
||||
static struct platform_driver rzv2h_cpg_driver = {
|
||||
.driver = {
|
||||
.name = "rzv2h-cpg",
|
||||
.of_match_table = rzv2h_cpg_match,
|
||||
},
|
||||
};
|
||||
|
||||
static int __init rzv2h_cpg_init(void)
|
||||
{
|
||||
return platform_driver_probe(&rzv2h_cpg_driver, rzv2h_cpg_probe);
|
||||
}
|
||||
|
||||
subsys_initcall(rzv2h_cpg_init);
|
||||
|
||||
MODULE_DESCRIPTION("Renesas RZ/V2H CPG Driver");
|
||||
|
|
@ -0,0 +1,190 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Renesas RZ/V2H(P) Clock Pulse Generator
|
||||
*
|
||||
* Copyright (C) 2024 Renesas Electronics Corp.
|
||||
*/
|
||||
|
||||
#ifndef __RENESAS_RZV2H_CPG_H__
|
||||
#define __RENESAS_RZV2H_CPG_H__
|
||||
|
||||
/**
|
||||
* struct ddiv - Structure for dynamic switching divider
|
||||
*
|
||||
* @offset: register offset
|
||||
* @shift: position of the divider bit
|
||||
* @width: width of the divider
|
||||
* @monbit: monitor bit in CPG_CLKSTATUS0 register
|
||||
*/
|
||||
struct ddiv {
|
||||
unsigned int offset:11;
|
||||
unsigned int shift:4;
|
||||
unsigned int width:4;
|
||||
unsigned int monbit:5;
|
||||
};
|
||||
|
||||
#define DDIV_PACK(_offset, _shift, _width, _monbit) \
|
||||
((struct ddiv){ \
|
||||
.offset = _offset, \
|
||||
.shift = _shift, \
|
||||
.width = _width, \
|
||||
.monbit = _monbit \
|
||||
})
|
||||
|
||||
#define CPG_CDDIV0 (0x400)
|
||||
|
||||
#define CDDIV0_DIVCTL2 DDIV_PACK(CPG_CDDIV0, 8, 3, 2)
|
||||
|
||||
/**
|
||||
* Definitions of CPG Core Clocks
|
||||
*
|
||||
* These include:
|
||||
* - Clock outputs exported to DT
|
||||
* - External input clocks
|
||||
* - Internal CPG clocks
|
||||
*/
|
||||
struct cpg_core_clk {
|
||||
const char *name;
|
||||
unsigned int id;
|
||||
unsigned int parent;
|
||||
unsigned int div;
|
||||
unsigned int mult;
|
||||
unsigned int type;
|
||||
union {
|
||||
unsigned int conf;
|
||||
struct ddiv ddiv;
|
||||
} cfg;
|
||||
const struct clk_div_table *dtable;
|
||||
u32 flag;
|
||||
};
|
||||
|
||||
enum clk_types {
|
||||
/* Generic */
|
||||
CLK_TYPE_IN, /* External Clock Input */
|
||||
CLK_TYPE_FF, /* Fixed Factor Clock */
|
||||
CLK_TYPE_PLL,
|
||||
CLK_TYPE_DDIV, /* Dynamic Switching Divider */
|
||||
};
|
||||
|
||||
/* BIT(31) indicates if CLK1/2 are accessible or not */
|
||||
#define PLL_CONF(n) (BIT(31) | ((n) & ~GENMASK(31, 16)))
|
||||
#define PLL_CLK_ACCESS(n) ((n) & BIT(31) ? 1 : 0)
|
||||
#define PLL_CLK1_OFFSET(n) ((n) & ~GENMASK(31, 16))
|
||||
#define PLL_CLK2_OFFSET(n) (((n) & ~GENMASK(31, 16)) + (0x4))
|
||||
|
||||
#define DEF_TYPE(_name, _id, _type...) \
|
||||
{ .name = _name, .id = _id, .type = _type }
|
||||
#define DEF_BASE(_name, _id, _type, _parent...) \
|
||||
DEF_TYPE(_name, _id, _type, .parent = _parent)
|
||||
#define DEF_PLL(_name, _id, _parent, _conf) \
|
||||
DEF_TYPE(_name, _id, CLK_TYPE_PLL, .parent = _parent, .cfg.conf = _conf)
|
||||
#define DEF_INPUT(_name, _id) \
|
||||
DEF_TYPE(_name, _id, CLK_TYPE_IN)
|
||||
#define DEF_FIXED(_name, _id, _parent, _mult, _div) \
|
||||
DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
|
||||
#define DEF_DDIV(_name, _id, _parent, _ddiv_packed, _dtable) \
|
||||
DEF_TYPE(_name, _id, CLK_TYPE_DDIV, \
|
||||
.cfg.ddiv = _ddiv_packed, \
|
||||
.parent = _parent, \
|
||||
.dtable = _dtable, \
|
||||
.flag = CLK_DIVIDER_HIWORD_MASK)
|
||||
|
||||
/**
|
||||
* struct rzv2h_mod_clk - Module Clocks definitions
|
||||
*
|
||||
* @name: handle between common and hardware-specific interfaces
|
||||
* @parent: id of parent clock
|
||||
* @critical: flag to indicate the clock is critical
|
||||
* @on_index: control register index
|
||||
* @on_bit: ON bit
|
||||
* @mon_index: monitor register index
|
||||
* @mon_bit: monitor bit
|
||||
*/
|
||||
struct rzv2h_mod_clk {
|
||||
const char *name;
|
||||
u16 parent;
|
||||
bool critical;
|
||||
u8 on_index;
|
||||
u8 on_bit;
|
||||
s8 mon_index;
|
||||
u8 mon_bit;
|
||||
};
|
||||
|
||||
#define DEF_MOD_BASE(_name, _parent, _critical, _onindex, _onbit, _monindex, _monbit) \
|
||||
{ \
|
||||
.name = (_name), \
|
||||
.parent = (_parent), \
|
||||
.critical = (_critical), \
|
||||
.on_index = (_onindex), \
|
||||
.on_bit = (_onbit), \
|
||||
.mon_index = (_monindex), \
|
||||
.mon_bit = (_monbit), \
|
||||
}
|
||||
|
||||
#define DEF_MOD(_name, _parent, _onindex, _onbit, _monindex, _monbit) \
|
||||
DEF_MOD_BASE(_name, _parent, false, _onindex, _onbit, _monindex, _monbit)
|
||||
|
||||
#define DEF_MOD_CRITICAL(_name, _parent, _onindex, _onbit, _monindex, _monbit) \
|
||||
DEF_MOD_BASE(_name, _parent, true, _onindex, _onbit, _monindex, _monbit)
|
||||
|
||||
/**
|
||||
* struct rzv2h_reset - Reset definitions
|
||||
*
|
||||
* @reset_index: reset register index
|
||||
* @reset_bit: reset bit
|
||||
* @mon_index: monitor register index
|
||||
* @mon_bit: monitor bit
|
||||
*/
|
||||
struct rzv2h_reset {
|
||||
u8 reset_index;
|
||||
u8 reset_bit;
|
||||
u8 mon_index;
|
||||
u8 mon_bit;
|
||||
};
|
||||
|
||||
#define DEF_RST_BASE(_resindex, _resbit, _monindex, _monbit) \
|
||||
{ \
|
||||
.reset_index = (_resindex), \
|
||||
.reset_bit = (_resbit), \
|
||||
.mon_index = (_monindex), \
|
||||
.mon_bit = (_monbit), \
|
||||
}
|
||||
|
||||
#define DEF_RST(_resindex, _resbit, _monindex, _monbit) \
|
||||
DEF_RST_BASE(_resindex, _resbit, _monindex, _monbit)
|
||||
|
||||
/**
|
||||
* struct rzv2h_cpg_info - SoC-specific CPG Description
|
||||
*
|
||||
* @core_clks: Array of Core Clock definitions
|
||||
* @num_core_clks: Number of entries in core_clks[]
|
||||
* @last_dt_core_clk: ID of the last Core Clock exported to DT
|
||||
* @num_total_core_clks: Total number of Core Clocks (exported + internal)
|
||||
*
|
||||
* @mod_clks: Array of Module Clock definitions
|
||||
* @num_mod_clks: Number of entries in mod_clks[]
|
||||
* @num_hw_mod_clks: Number of Module Clocks supported by the hardware
|
||||
*
|
||||
* @resets: Array of Module Reset definitions
|
||||
* @num_resets: Number of entries in resets[]
|
||||
*/
|
||||
struct rzv2h_cpg_info {
|
||||
/* Core Clocks */
|
||||
const struct cpg_core_clk *core_clks;
|
||||
unsigned int num_core_clks;
|
||||
unsigned int last_dt_core_clk;
|
||||
unsigned int num_total_core_clks;
|
||||
|
||||
/* Module Clocks */
|
||||
const struct rzv2h_mod_clk *mod_clks;
|
||||
unsigned int num_mod_clks;
|
||||
unsigned int num_hw_mod_clks;
|
||||
|
||||
/* Resets */
|
||||
const struct rzv2h_reset *resets;
|
||||
unsigned int num_resets;
|
||||
};
|
||||
|
||||
extern const struct rzv2h_cpg_info r9a09g057_cpg_info;
|
||||
|
||||
#endif /* __RENESAS_RZV2H_CPG_H__ */
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
|
||||
*
|
||||
* Copyright (C) 2024 Renesas Electronics Corp.
|
||||
*/
|
||||
#ifndef __DT_BINDINGS_CLOCK_RENESAS_R9A09G057_CPG_H__
|
||||
#define __DT_BINDINGS_CLOCK_RENESAS_R9A09G057_CPG_H__
|
||||
|
||||
#include <dt-bindings/clock/renesas-cpg-mssr.h>
|
||||
|
||||
/* Core Clock list */
|
||||
#define R9A09G057_SYS_0_PCLK 0
|
||||
#define R9A09G057_CA55_0_CORE_CLK0 1
|
||||
#define R9A09G057_CA55_0_CORE_CLK1 2
|
||||
#define R9A09G057_CA55_0_CORE_CLK2 3
|
||||
#define R9A09G057_CA55_0_CORE_CLK3 4
|
||||
#define R9A09G057_CA55_0_PERIPHCLK 5
|
||||
#define R9A09G057_CM33_CLK0 6
|
||||
#define R9A09G057_CST_0_SWCLKTCK 7
|
||||
#define R9A09G057_IOTOP_0_SHCLK 8
|
||||
|
||||
#endif /* __DT_BINDINGS_CLOCK_RENESAS_R9A09G057_CPG_H__ */
|
||||
Loading…
Reference in New Issue