1 // SPDX-License-Identifier: GPL-2.0-only
3 * PRCC clock implementation for ux500 platform.
5 * Copyright (C) 2012 ST-Ericsson SA
6 * Author: Ulf Hansson <ulf.hansson@linaro.org>
9 #include <linux/clk-provider.h>
10 #include <linux/slab.h>
12 #include <linux/err.h>
13 #include <linux/types.h>
17 #define PRCC_PCKEN 0x000
18 #define PRCC_PCKDIS 0x004
19 #define PRCC_KCKEN 0x008
20 #define PRCC_KCKDIS 0x00C
21 #define PRCC_PCKSR 0x010
22 #define PRCC_KCKSR 0x014
24 #define to_clk_prcc(_hw) container_of(_hw, struct clk_prcc, hw)
33 /* PRCC clock operations. */
35 static int clk_prcc_pclk_enable(struct clk_hw
*hw
)
37 struct clk_prcc
*clk
= to_clk_prcc(hw
);
39 writel(clk
->cg_sel
, (clk
->base
+ PRCC_PCKEN
));
40 while (!(readl(clk
->base
+ PRCC_PCKSR
) & clk
->cg_sel
))
47 static void clk_prcc_pclk_disable(struct clk_hw
*hw
)
49 struct clk_prcc
*clk
= to_clk_prcc(hw
);
51 writel(clk
->cg_sel
, (clk
->base
+ PRCC_PCKDIS
));
55 static int clk_prcc_kclk_enable(struct clk_hw
*hw
)
57 struct clk_prcc
*clk
= to_clk_prcc(hw
);
59 writel(clk
->cg_sel
, (clk
->base
+ PRCC_KCKEN
));
60 while (!(readl(clk
->base
+ PRCC_KCKSR
) & clk
->cg_sel
))
67 static void clk_prcc_kclk_disable(struct clk_hw
*hw
)
69 struct clk_prcc
*clk
= to_clk_prcc(hw
);
71 writel(clk
->cg_sel
, (clk
->base
+ PRCC_KCKDIS
));
75 static int clk_prcc_is_enabled(struct clk_hw
*hw
)
77 struct clk_prcc
*clk
= to_clk_prcc(hw
);
78 return clk
->is_enabled
;
81 static const struct clk_ops clk_prcc_pclk_ops
= {
82 .enable
= clk_prcc_pclk_enable
,
83 .disable
= clk_prcc_pclk_disable
,
84 .is_enabled
= clk_prcc_is_enabled
,
87 static const struct clk_ops clk_prcc_kclk_ops
= {
88 .enable
= clk_prcc_kclk_enable
,
89 .disable
= clk_prcc_kclk_disable
,
90 .is_enabled
= clk_prcc_is_enabled
,
93 static struct clk
*clk_reg_prcc(const char *name
,
94 const char *parent_name
,
95 resource_size_t phy_base
,
98 const struct clk_ops
*clk_prcc_ops
)
100 struct clk_prcc
*clk
;
101 struct clk_init_data clk_prcc_init
;
105 pr_err("clk_prcc: %s invalid arguments passed\n", __func__
);
106 return ERR_PTR(-EINVAL
);
109 clk
= kzalloc(sizeof(*clk
), GFP_KERNEL
);
111 return ERR_PTR(-ENOMEM
);
113 clk
->base
= ioremap(phy_base
, SZ_4K
);
117 clk
->cg_sel
= cg_sel
;
120 clk_prcc_init
.name
= name
;
121 clk_prcc_init
.ops
= clk_prcc_ops
;
122 clk_prcc_init
.flags
= flags
;
123 clk_prcc_init
.parent_names
= (parent_name
? &parent_name
: NULL
);
124 clk_prcc_init
.num_parents
= (parent_name
? 1 : 0);
125 clk
->hw
.init
= &clk_prcc_init
;
127 clk_reg
= clk_register(NULL
, &clk
->hw
);
128 if (IS_ERR_OR_NULL(clk_reg
))
137 pr_err("clk_prcc: %s failed to register clk\n", __func__
);
138 return ERR_PTR(-ENOMEM
);
141 struct clk
*clk_reg_prcc_pclk(const char *name
,
142 const char *parent_name
,
143 resource_size_t phy_base
,
147 return clk_reg_prcc(name
, parent_name
, phy_base
, cg_sel
, flags
,
151 struct clk
*clk_reg_prcc_kclk(const char *name
,
152 const char *parent_name
,
153 resource_size_t phy_base
,
157 return clk_reg_prcc(name
, parent_name
, phy_base
, cg_sel
, flags
,