| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright 2011-2012 Calxeda, Inc. |
|---|
| 3 | 4 | * Copyright (C) 2012-2013 Altera Corporation <www.altera.com> |
|---|
| 4 | 5 | * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 7 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | | - * (at your option) any later version. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | 6 | * Based from clk-highbank.c |
|---|
| 16 | | - * |
|---|
| 17 | 7 | */ |
|---|
| 18 | 8 | #include <linux/slab.h> |
|---|
| 19 | 9 | #include <linux/clk-provider.h> |
|---|
| .. | .. |
|---|
| 40 | 30 | { |
|---|
| 41 | 31 | u32 l4_src; |
|---|
| 42 | 32 | u32 perpll_src; |
|---|
| 33 | + const char *name = clk_hw_get_name(hwclk); |
|---|
| 43 | 34 | |
|---|
| 44 | | - if (streq(hwclk->init->name, SOCFPGA_L4_MP_CLK)) { |
|---|
| 35 | + if (streq(name, SOCFPGA_L4_MP_CLK)) { |
|---|
| 45 | 36 | l4_src = readl(clk_mgr_base_addr + CLKMGR_L4SRC); |
|---|
| 46 | 37 | return l4_src &= 0x1; |
|---|
| 47 | 38 | } |
|---|
| 48 | | - if (streq(hwclk->init->name, SOCFPGA_L4_SP_CLK)) { |
|---|
| 39 | + if (streq(name, SOCFPGA_L4_SP_CLK)) { |
|---|
| 49 | 40 | l4_src = readl(clk_mgr_base_addr + CLKMGR_L4SRC); |
|---|
| 50 | 41 | return !!(l4_src & 2); |
|---|
| 51 | 42 | } |
|---|
| 52 | 43 | |
|---|
| 53 | 44 | perpll_src = readl(clk_mgr_base_addr + CLKMGR_PERPLL_SRC); |
|---|
| 54 | | - if (streq(hwclk->init->name, SOCFPGA_MMC_CLK)) |
|---|
| 45 | + if (streq(name, SOCFPGA_MMC_CLK)) |
|---|
| 55 | 46 | return perpll_src &= 0x3; |
|---|
| 56 | | - if (streq(hwclk->init->name, SOCFPGA_NAND_CLK) || |
|---|
| 57 | | - streq(hwclk->init->name, SOCFPGA_NAND_X_CLK)) |
|---|
| 58 | | - return (perpll_src >> 2) & 3; |
|---|
| 47 | + if (streq(name, SOCFPGA_NAND_CLK) || |
|---|
| 48 | + streq(name, SOCFPGA_NAND_X_CLK)) |
|---|
| 49 | + return (perpll_src >> 2) & 3; |
|---|
| 59 | 50 | |
|---|
| 60 | 51 | /* QSPI clock */ |
|---|
| 61 | 52 | return (perpll_src >> 4) & 3; |
|---|
| .. | .. |
|---|
| 65 | 56 | static int socfpga_clk_set_parent(struct clk_hw *hwclk, u8 parent) |
|---|
| 66 | 57 | { |
|---|
| 67 | 58 | u32 src_reg; |
|---|
| 59 | + const char *name = clk_hw_get_name(hwclk); |
|---|
| 68 | 60 | |
|---|
| 69 | | - if (streq(hwclk->init->name, SOCFPGA_L4_MP_CLK)) { |
|---|
| 61 | + if (streq(name, SOCFPGA_L4_MP_CLK)) { |
|---|
| 70 | 62 | src_reg = readl(clk_mgr_base_addr + CLKMGR_L4SRC); |
|---|
| 71 | 63 | src_reg &= ~0x1; |
|---|
| 72 | 64 | src_reg |= parent; |
|---|
| 73 | 65 | writel(src_reg, clk_mgr_base_addr + CLKMGR_L4SRC); |
|---|
| 74 | | - } else if (streq(hwclk->init->name, SOCFPGA_L4_SP_CLK)) { |
|---|
| 66 | + } else if (streq(name, SOCFPGA_L4_SP_CLK)) { |
|---|
| 75 | 67 | src_reg = readl(clk_mgr_base_addr + CLKMGR_L4SRC); |
|---|
| 76 | 68 | src_reg &= ~0x2; |
|---|
| 77 | 69 | src_reg |= (parent << 1); |
|---|
| 78 | 70 | writel(src_reg, clk_mgr_base_addr + CLKMGR_L4SRC); |
|---|
| 79 | 71 | } else { |
|---|
| 80 | 72 | src_reg = readl(clk_mgr_base_addr + CLKMGR_PERPLL_SRC); |
|---|
| 81 | | - if (streq(hwclk->init->name, SOCFPGA_MMC_CLK)) { |
|---|
| 73 | + if (streq(name, SOCFPGA_MMC_CLK)) { |
|---|
| 82 | 74 | src_reg &= ~0x3; |
|---|
| 83 | 75 | src_reg |= parent; |
|---|
| 84 | | - } else if (streq(hwclk->init->name, SOCFPGA_NAND_CLK) || |
|---|
| 85 | | - streq(hwclk->init->name, SOCFPGA_NAND_X_CLK)) { |
|---|
| 76 | + } else if (streq(name, SOCFPGA_NAND_CLK) || |
|---|
| 77 | + streq(name, SOCFPGA_NAND_X_CLK)) { |
|---|
| 86 | 78 | src_reg &= ~0xC; |
|---|
| 87 | 79 | src_reg |= (parent << 2); |
|---|
| 88 | 80 | } else {/* QSPI clock */ |
|---|
| .. | .. |
|---|
| 176 | 168 | .set_parent = socfpga_clk_set_parent, |
|---|
| 177 | 169 | }; |
|---|
| 178 | 170 | |
|---|
| 179 | | -static void __init __socfpga_gate_init(struct device_node *node, |
|---|
| 180 | | - const struct clk_ops *ops) |
|---|
| 171 | +void __init socfpga_gate_init(struct device_node *node) |
|---|
| 181 | 172 | { |
|---|
| 182 | 173 | u32 clk_gate[2]; |
|---|
| 183 | 174 | u32 div_reg[3]; |
|---|
| .. | .. |
|---|
| 187 | 178 | struct socfpga_gate_clk *socfpga_clk; |
|---|
| 188 | 179 | const char *clk_name = node->name; |
|---|
| 189 | 180 | const char *parent_name[SOCFPGA_MAX_PARENTS]; |
|---|
| 190 | | - struct clk_init_data init = {}; |
|---|
| 181 | + struct clk_init_data init; |
|---|
| 182 | + struct clk_ops *ops; |
|---|
| 191 | 183 | int rc; |
|---|
| 192 | 184 | |
|---|
| 193 | 185 | socfpga_clk = kzalloc(sizeof(*socfpga_clk), GFP_KERNEL); |
|---|
| 194 | 186 | if (WARN_ON(!socfpga_clk)) |
|---|
| 187 | + return; |
|---|
| 188 | + |
|---|
| 189 | + ops = kmemdup(&gateclk_ops, sizeof(gateclk_ops), GFP_KERNEL); |
|---|
| 190 | + if (WARN_ON(!ops)) |
|---|
| 195 | 191 | return; |
|---|
| 196 | 192 | |
|---|
| 197 | 193 | rc = of_property_read_u32_array(node, "clk-gate", clk_gate, 2); |
|---|
| .. | .. |
|---|
| 202 | 198 | socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0]; |
|---|
| 203 | 199 | socfpga_clk->hw.bit_idx = clk_gate[1]; |
|---|
| 204 | 200 | |
|---|
| 205 | | - gateclk_ops.enable = clk_gate_ops.enable; |
|---|
| 206 | | - gateclk_ops.disable = clk_gate_ops.disable; |
|---|
| 201 | + ops->enable = clk_gate_ops.enable; |
|---|
| 202 | + ops->disable = clk_gate_ops.disable; |
|---|
| 207 | 203 | } |
|---|
| 208 | 204 | |
|---|
| 209 | 205 | rc = of_property_read_u32(node, "fixed-divider", &fixed_div); |
|---|
| .. | .. |
|---|
| 234 | 230 | init.flags = 0; |
|---|
| 235 | 231 | |
|---|
| 236 | 232 | init.num_parents = of_clk_parent_fill(node, parent_name, SOCFPGA_MAX_PARENTS); |
|---|
| 233 | + if (init.num_parents < 2) { |
|---|
| 234 | + ops->get_parent = NULL; |
|---|
| 235 | + ops->set_parent = NULL; |
|---|
| 236 | + } |
|---|
| 237 | + |
|---|
| 237 | 238 | init.parent_names = parent_name; |
|---|
| 238 | 239 | socfpga_clk->hw.hw.init = &init; |
|---|
| 239 | 240 | |
|---|
| .. | .. |
|---|
| 245 | 246 | rc = of_clk_add_provider(node, of_clk_src_simple_get, clk); |
|---|
| 246 | 247 | if (WARN_ON(rc)) |
|---|
| 247 | 248 | return; |
|---|
| 248 | | -} |
|---|
| 249 | | - |
|---|
| 250 | | -void __init socfpga_gate_init(struct device_node *node) |
|---|
| 251 | | -{ |
|---|
| 252 | | - __socfpga_gate_init(node, &gateclk_ops); |
|---|
| 253 | 249 | } |
|---|