]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - drivers/clk/h8300/clk-div.c
Merge tag 'tegra-for-4.3-cleanup' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-eoan-kernel.git] / drivers / clk / h8300 / clk-div.c
1 /*
2 * H8/300 divide clock driver
3 *
4 * Copyright 2015 Yoshinori Sato <ysato@users.sourceforge.jp>
5 */
6
7 #include <linux/clk.h>
8 #include <linux/clkdev.h>
9 #include <linux/clk-provider.h>
10 #include <linux/err.h>
11 #include <linux/of.h>
12 #include <linux/of_address.h>
13
14 static DEFINE_SPINLOCK(clklock);
15
16 static void __init h8300_div_clk_setup(struct device_node *node)
17 {
18 unsigned int num_parents;
19 struct clk *clk;
20 const char *clk_name = node->name;
21 const char *parent_name;
22 void __iomem *divcr = NULL;
23 int width;
24
25 num_parents = of_clk_get_parent_count(node);
26 if (num_parents < 1) {
27 pr_err("%s: no parent found", clk_name);
28 return;
29 }
30
31 divcr = of_iomap(node, 0);
32 if (divcr == NULL) {
33 pr_err("%s: failed to map divide register", clk_name);
34 goto error;
35 }
36
37 parent_name = of_clk_get_parent_name(node, 0);
38 of_property_read_u32(node, "renesas,width", &width);
39 clk = clk_register_divider(NULL, clk_name, parent_name,
40 CLK_SET_RATE_GATE, divcr, 0, width,
41 CLK_DIVIDER_POWER_OF_TWO, &clklock);
42 if (!IS_ERR(clk)) {
43 of_clk_add_provider(node, of_clk_src_simple_get, clk);
44 return;
45 }
46 pr_err("%s: failed to register %s div clock (%ld)\n",
47 __func__, clk_name, PTR_ERR(clk));
48 error:
49 if (divcr)
50 iounmap(divcr);
51 }
52
53 CLK_OF_DECLARE(h8300_div_clk, "renesas,h8300-div-clock", h8300_div_clk_setup);