1 // SPDX-License-Identifier: GPL-2.0
3 * H8/300 divide clock driver
5 * Copyright 2015 Yoshinori Sato <ysato@users.sourceforge.jp>
8 #include <linux/clk-provider.h>
12 #include <linux/of_address.h>
14 static DEFINE_SPINLOCK(clklock
);
16 static void __init
h8300_div_clk_setup(struct device_node
*node
)
18 unsigned int num_parents
;
20 const char *clk_name
= node
->name
;
21 const char *parent_name
;
22 void __iomem
*divcr
= NULL
;
26 num_parents
= of_clk_get_parent_count(node
);
28 pr_err("%s: no parent found\n", clk_name
);
32 divcr
= of_iomap(node
, 0);
34 pr_err("%s: failed to map divide register\n", clk_name
);
37 offset
= (unsigned long)divcr
& 3;
38 offset
= (3 - offset
) * 8;
39 divcr
= (void __iomem
*)((unsigned long)divcr
& ~3);
41 parent_name
= of_clk_get_parent_name(node
, 0);
42 of_property_read_u32(node
, "renesas,width", &width
);
43 hw
= clk_hw_register_divider(NULL
, clk_name
, parent_name
,
44 CLK_SET_RATE_GATE
, divcr
, offset
, width
,
45 CLK_DIVIDER_POWER_OF_TWO
, &clklock
);
47 of_clk_add_hw_provider(node
, of_clk_hw_simple_get
, hw
);
50 pr_err("%s: failed to register %s div clock (%ld)\n",
51 __func__
, clk_name
, PTR_ERR(hw
));
57 CLK_OF_DECLARE(h8300_div_clk
, "renesas,h8300-div-clock", h8300_div_clk_setup
);