1 // SPDX-License-Identifier: GPL-2.0-only
3 * mmp AXI peripharal clock operation source file
5 * Copyright (C) 2012 Marvell
6 * Chao Xie <xiechao.mail@gmail.com>
9 #include <linux/kernel.h>
11 #include <linux/err.h>
12 #include <linux/delay.h>
13 #include <linux/slab.h>
17 #define to_clk_apmu(clk) (container_of(clk, struct clk_apmu, clk))
26 static int clk_apmu_enable(struct clk_hw *hw)
28 struct clk_apmu *apmu = to_clk_apmu(hw);
30 unsigned long flags = 0;
33 spin_lock_irqsave(apmu->lock, flags);
35 data = readl_relaxed(apmu->base) | apmu->enable_mask;
36 writel_relaxed(data, apmu->base);
39 spin_unlock_irqrestore(apmu->lock, flags);
44 static void clk_apmu_disable(struct clk_hw *hw)
46 struct clk_apmu *apmu = to_clk_apmu(hw);
48 unsigned long flags = 0;
51 spin_lock_irqsave(apmu->lock, flags);
53 data = readl_relaxed(apmu->base) & ~apmu->enable_mask;
54 writel_relaxed(data, apmu->base);
57 spin_unlock_irqrestore(apmu->lock, flags);
60 static const struct clk_ops clk_apmu_ops = {
61 .enable = clk_apmu_enable,
62 .disable = clk_apmu_disable,
65 struct clk *mmp_clk_register_apmu(const char *name, const char *parent_name,
66 void __iomem *base, u32 enable_mask, spinlock_t *lock)
68 struct clk_apmu *apmu;
70 struct clk_init_data init;
72 apmu = kzalloc(sizeof(*apmu), GFP_KERNEL);
77 init.ops = &clk_apmu_ops;
78 init.flags = CLK_SET_RATE_PARENT;
79 init.parent_names = (parent_name ? &parent_name : NULL);
80 init.num_parents = (parent_name ? 1 : 0);
83 apmu->enable_mask = enable_mask;
85 apmu->hw.init = &init;
87 clk = clk_register(NULL, &apmu->hw);