1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2012 Freescale Semiconductor, Inc.
6 #include <linux/clk-provider.h>
8 #include <linux/slab.h>
12 * struct clk_div - mxs integer divider clock
13 * @divider: the parent class
14 * @ops: pointer to clk_ops of parent class
15 * @reg: register address
16 * @busy: busy bit shift
18 * The mxs divider clock is a subclass of basic clk_divider with an
22 struct clk_divider divider
;
23 const struct clk_ops
*ops
;
28 static inline struct clk_div
*to_clk_div(struct clk_hw
*hw
)
30 struct clk_divider
*divider
= to_clk_divider(hw
);
32 return container_of(divider
, struct clk_div
, divider
);
35 static unsigned long clk_div_recalc_rate(struct clk_hw
*hw
,
36 unsigned long parent_rate
)
38 struct clk_div
*div
= to_clk_div(hw
);
40 return div
->ops
->recalc_rate(&div
->divider
.hw
, parent_rate
);
43 static long clk_div_round_rate(struct clk_hw
*hw
, unsigned long rate
,
46 struct clk_div
*div
= to_clk_div(hw
);
48 return div
->ops
->round_rate(&div
->divider
.hw
, rate
, prate
);
51 static int clk_div_set_rate(struct clk_hw
*hw
, unsigned long rate
,
52 unsigned long parent_rate
)
54 struct clk_div
*div
= to_clk_div(hw
);
57 ret
= div
->ops
->set_rate(&div
->divider
.hw
, rate
, parent_rate
);
59 ret
= mxs_clk_wait(div
->reg
, div
->busy
);
64 static const struct clk_ops clk_div_ops
= {
65 .recalc_rate
= clk_div_recalc_rate
,
66 .round_rate
= clk_div_round_rate
,
67 .set_rate
= clk_div_set_rate
,
70 struct clk
*mxs_clk_div(const char *name
, const char *parent_name
,
71 void __iomem
*reg
, u8 shift
, u8 width
, u8 busy
)
75 struct clk_init_data init
;
77 div
= kzalloc(sizeof(*div
), GFP_KERNEL
);
79 return ERR_PTR(-ENOMEM
);
82 init
.ops
= &clk_div_ops
;
83 init
.flags
= CLK_SET_RATE_PARENT
;
84 init
.parent_names
= (parent_name
? &parent_name
: NULL
);
85 init
.num_parents
= (parent_name
? 1 : 0);
90 div
->divider
.reg
= reg
;
91 div
->divider
.shift
= shift
;
92 div
->divider
.width
= width
;
93 div
->divider
.flags
= CLK_DIVIDER_ONE_BASED
;
94 div
->divider
.lock
= &mxs_lock
;
95 div
->divider
.hw
.init
= &init
;
96 div
->ops
= &clk_divider_ops
;
98 clk
= clk_register(NULL
, &div
->divider
.hw
);