| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2016 Icenowy Zheng <icenowy@aosc.xyz> |
|---|
| 3 | | - * |
|---|
| 4 | | - * This software is licensed under the terms of the GNU General Public |
|---|
| 5 | | - * License version 2, as published by the Free Software Foundation, and |
|---|
| 6 | | - * may be copied, distributed, and modified under those terms. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 9 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | | - * GNU General Public License for more details. |
|---|
| 12 | 4 | */ |
|---|
| 13 | 5 | |
|---|
| 14 | 6 | #include <linux/clk-provider.h> |
|---|
| .. | .. |
|---|
| 25 | 17 | |
|---|
| 26 | 18 | #include "ccu-sun8i-r.h" |
|---|
| 27 | 19 | |
|---|
| 28 | | -static const char * const ar100_parents[] = { "osc32k", "osc24M", |
|---|
| 29 | | - "pll-periph0", "iosc" }; |
|---|
| 30 | | -static const char * const a83t_ar100_parents[] = { "osc16M-d512", "osc24M", |
|---|
| 31 | | - "pll-periph0", "iosc" }; |
|---|
| 20 | +static const struct clk_parent_data ar100_parents[] = { |
|---|
| 21 | + { .fw_name = "losc" }, |
|---|
| 22 | + { .fw_name = "hosc" }, |
|---|
| 23 | + { .fw_name = "pll-periph" }, |
|---|
| 24 | + { .fw_name = "iosc" }, |
|---|
| 25 | +}; |
|---|
| 26 | + |
|---|
| 32 | 27 | static const struct ccu_mux_var_prediv ar100_predivs[] = { |
|---|
| 33 | 28 | { .index = 2, .shift = 8, .width = 5 }, |
|---|
| 34 | 29 | }; |
|---|
| .. | .. |
|---|
| 47 | 42 | .common = { |
|---|
| 48 | 43 | .reg = 0x00, |
|---|
| 49 | 44 | .features = CCU_FEATURE_VARIABLE_PREDIV, |
|---|
| 50 | | - .hw.init = CLK_HW_INIT_PARENTS("ar100", |
|---|
| 51 | | - ar100_parents, |
|---|
| 52 | | - &ccu_div_ops, |
|---|
| 53 | | - 0), |
|---|
| 45 | + .hw.init = CLK_HW_INIT_PARENTS_DATA("ar100", |
|---|
| 46 | + ar100_parents, |
|---|
| 47 | + &ccu_div_ops, |
|---|
| 48 | + 0), |
|---|
| 54 | 49 | }, |
|---|
| 55 | 50 | }; |
|---|
| 56 | 51 | |
|---|
| 57 | | -static struct ccu_div a83t_ar100_clk = { |
|---|
| 58 | | - .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO), |
|---|
| 52 | +static CLK_FIXED_FACTOR_HW(ahb0_clk, "ahb0", &ar100_clk.common.hw, 1, 1, 0); |
|---|
| 59 | 53 | |
|---|
| 60 | | - .mux = { |
|---|
| 61 | | - .shift = 16, |
|---|
| 62 | | - .width = 2, |
|---|
| 54 | +static SUNXI_CCU_M(apb0_clk, "apb0", "ahb0", 0x0c, 0, 2, 0); |
|---|
| 63 | 55 | |
|---|
| 64 | | - .var_predivs = ar100_predivs, |
|---|
| 65 | | - .n_var_predivs = ARRAY_SIZE(ar100_predivs), |
|---|
| 66 | | - }, |
|---|
| 67 | | - |
|---|
| 68 | | - .common = { |
|---|
| 69 | | - .reg = 0x00, |
|---|
| 70 | | - .features = CCU_FEATURE_VARIABLE_PREDIV, |
|---|
| 71 | | - .hw.init = CLK_HW_INIT_PARENTS("ar100", |
|---|
| 72 | | - a83t_ar100_parents, |
|---|
| 73 | | - &ccu_div_ops, |
|---|
| 74 | | - 0), |
|---|
| 75 | | - }, |
|---|
| 76 | | -}; |
|---|
| 77 | | - |
|---|
| 78 | | -static CLK_FIXED_FACTOR(ahb0_clk, "ahb0", "ar100", 1, 1, 0); |
|---|
| 79 | | - |
|---|
| 80 | | -static struct ccu_div apb0_clk = { |
|---|
| 81 | | - .div = _SUNXI_CCU_DIV_FLAGS(0, 2, CLK_DIVIDER_POWER_OF_TWO), |
|---|
| 82 | | - |
|---|
| 83 | | - .common = { |
|---|
| 84 | | - .reg = 0x0c, |
|---|
| 85 | | - .hw.init = CLK_HW_INIT("apb0", |
|---|
| 86 | | - "ahb0", |
|---|
| 87 | | - &ccu_div_ops, |
|---|
| 88 | | - 0), |
|---|
| 89 | | - }, |
|---|
| 90 | | -}; |
|---|
| 91 | | - |
|---|
| 92 | | -static SUNXI_CCU_M(a83t_apb0_clk, "apb0", "ahb0", 0x0c, 0, 2, 0); |
|---|
| 93 | | - |
|---|
| 94 | | -static SUNXI_CCU_GATE(apb0_pio_clk, "apb0-pio", "apb0", |
|---|
| 95 | | - 0x28, BIT(0), 0); |
|---|
| 96 | | -static SUNXI_CCU_GATE(apb0_ir_clk, "apb0-ir", "apb0", |
|---|
| 97 | | - 0x28, BIT(1), 0); |
|---|
| 98 | | -static SUNXI_CCU_GATE(apb0_timer_clk, "apb0-timer", "apb0", |
|---|
| 99 | | - 0x28, BIT(2), 0); |
|---|
| 100 | | -static SUNXI_CCU_GATE(apb0_rsb_clk, "apb0-rsb", "apb0", |
|---|
| 101 | | - 0x28, BIT(3), 0); |
|---|
| 102 | | -static SUNXI_CCU_GATE(apb0_uart_clk, "apb0-uart", "apb0", |
|---|
| 103 | | - 0x28, BIT(4), 0); |
|---|
| 104 | | -static SUNXI_CCU_GATE(apb0_i2c_clk, "apb0-i2c", "apb0", |
|---|
| 105 | | - 0x28, BIT(6), 0); |
|---|
| 106 | | -static SUNXI_CCU_GATE(apb0_twd_clk, "apb0-twd", "apb0", |
|---|
| 107 | | - 0x28, BIT(7), 0); |
|---|
| 56 | +/* |
|---|
| 57 | + * Define the parent as an array that can be reused to save space |
|---|
| 58 | + * instead of having compound literals for each gate. Also have it |
|---|
| 59 | + * non-const so we can change it on the A83T. |
|---|
| 60 | + */ |
|---|
| 61 | +static const struct clk_hw *apb0_gate_parent[] = { &apb0_clk.common.hw }; |
|---|
| 62 | +static SUNXI_CCU_GATE_HWS(apb0_pio_clk, "apb0-pio", |
|---|
| 63 | + apb0_gate_parent, 0x28, BIT(0), 0); |
|---|
| 64 | +static SUNXI_CCU_GATE_HWS(apb0_ir_clk, "apb0-ir", |
|---|
| 65 | + apb0_gate_parent, 0x28, BIT(1), 0); |
|---|
| 66 | +static SUNXI_CCU_GATE_HWS(apb0_timer_clk, "apb0-timer", |
|---|
| 67 | + apb0_gate_parent, 0x28, BIT(2), 0); |
|---|
| 68 | +static SUNXI_CCU_GATE_HWS(apb0_rsb_clk, "apb0-rsb", |
|---|
| 69 | + apb0_gate_parent, 0x28, BIT(3), 0); |
|---|
| 70 | +static SUNXI_CCU_GATE_HWS(apb0_uart_clk, "apb0-uart", |
|---|
| 71 | + apb0_gate_parent, 0x28, BIT(4), 0); |
|---|
| 72 | +static SUNXI_CCU_GATE_HWS(apb0_i2c_clk, "apb0-i2c", |
|---|
| 73 | + apb0_gate_parent, 0x28, BIT(6), 0); |
|---|
| 74 | +static SUNXI_CCU_GATE_HWS(apb0_twd_clk, "apb0-twd", |
|---|
| 75 | + apb0_gate_parent, 0x28, BIT(7), 0); |
|---|
| 108 | 76 | |
|---|
| 109 | 77 | static const char * const r_mod0_default_parents[] = { "osc32k", "osc24M" }; |
|---|
| 110 | 78 | static SUNXI_CCU_MP_WITH_MUX_GATE(ir_clk, "ir", |
|---|
| .. | .. |
|---|
| 115 | 83 | BIT(31), /* gate */ |
|---|
| 116 | 84 | 0); |
|---|
| 117 | 85 | |
|---|
| 118 | | -static const char *const a83t_r_mod0_parents[] = { "osc16M", "osc24M" }; |
|---|
| 86 | +static const struct clk_parent_data a83t_r_mod0_parents[] = { |
|---|
| 87 | + { .fw_name = "iosc" }, |
|---|
| 88 | + { .fw_name = "hosc" }, |
|---|
| 89 | +}; |
|---|
| 119 | 90 | static const struct ccu_mux_fixed_prediv a83t_ir_predivs[] = { |
|---|
| 120 | 91 | { .index = 0, .div = 16 }, |
|---|
| 121 | 92 | }; |
|---|
| .. | .. |
|---|
| 135 | 106 | .common = { |
|---|
| 136 | 107 | .reg = 0x54, |
|---|
| 137 | 108 | .features = CCU_FEATURE_VARIABLE_PREDIV, |
|---|
| 138 | | - .hw.init = CLK_HW_INIT_PARENTS("ir", |
|---|
| 139 | | - a83t_r_mod0_parents, |
|---|
| 140 | | - &ccu_mp_ops, |
|---|
| 141 | | - 0), |
|---|
| 109 | + .hw.init = CLK_HW_INIT_PARENTS_DATA("ir", |
|---|
| 110 | + a83t_r_mod0_parents, |
|---|
| 111 | + &ccu_mp_ops, |
|---|
| 112 | + 0), |
|---|
| 142 | 113 | }, |
|---|
| 143 | 114 | }; |
|---|
| 144 | 115 | |
|---|
| 145 | 116 | static struct ccu_common *sun8i_a83t_r_ccu_clks[] = { |
|---|
| 146 | | - &a83t_ar100_clk.common, |
|---|
| 147 | | - &a83t_apb0_clk.common, |
|---|
| 117 | + &ar100_clk.common, |
|---|
| 118 | + &apb0_clk.common, |
|---|
| 148 | 119 | &apb0_pio_clk.common, |
|---|
| 149 | 120 | &apb0_ir_clk.common, |
|---|
| 150 | 121 | &apb0_timer_clk.common, |
|---|
| .. | .. |
|---|
| 182 | 153 | |
|---|
| 183 | 154 | static struct clk_hw_onecell_data sun8i_a83t_r_hw_clks = { |
|---|
| 184 | 155 | .hws = { |
|---|
| 185 | | - [CLK_AR100] = &a83t_ar100_clk.common.hw, |
|---|
| 156 | + [CLK_AR100] = &ar100_clk.common.hw, |
|---|
| 186 | 157 | [CLK_AHB0] = &ahb0_clk.hw, |
|---|
| 187 | | - [CLK_APB0] = &a83t_apb0_clk.common.hw, |
|---|
| 158 | + [CLK_APB0] = &apb0_clk.common.hw, |
|---|
| 188 | 159 | [CLK_APB0_PIO] = &apb0_pio_clk.common.hw, |
|---|
| 189 | 160 | [CLK_APB0_IR] = &apb0_ir_clk.common.hw, |
|---|
| 190 | 161 | [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw, |
|---|