Linux 4.18.10
[linux/fpc-iii.git] / drivers / clk / sunxi / clk-a10-hosc.c
blobdca532431394d3010e801bf6207531e72eac6c26
1 /*
2 * Copyright 2013 Emilio López
4 * Emilio López <emilio@elopez.com.ar>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/clk-provider.h>
18 #include <linux/of.h>
19 #include <linux/of_address.h>
20 #include <linux/slab.h>
22 #define SUNXI_OSC24M_GATE 0
24 static DEFINE_SPINLOCK(hosc_lock);
26 static void __init sun4i_osc_clk_setup(struct device_node *node)
28 struct clk *clk;
29 struct clk_fixed_rate *fixed;
30 struct clk_gate *gate;
31 const char *clk_name = node->name;
32 u32 rate;
34 if (of_property_read_u32(node, "clock-frequency", &rate))
35 return;
37 /* allocate fixed-rate and gate clock structs */
38 fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
39 if (!fixed)
40 return;
41 gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
42 if (!gate)
43 goto err_free_fixed;
45 of_property_read_string(node, "clock-output-names", &clk_name);
47 /* set up gate and fixed rate properties */
48 gate->reg = of_iomap(node, 0);
49 gate->bit_idx = SUNXI_OSC24M_GATE;
50 gate->lock = &hosc_lock;
51 fixed->fixed_rate = rate;
53 clk = clk_register_composite(NULL, clk_name,
54 NULL, 0,
55 NULL, NULL,
56 &fixed->hw, &clk_fixed_rate_ops,
57 &gate->hw, &clk_gate_ops, 0);
59 if (IS_ERR(clk))
60 goto err_free_gate;
62 of_clk_add_provider(node, of_clk_src_simple_get, clk);
64 return;
66 err_free_gate:
67 kfree(gate);
68 err_free_fixed:
69 kfree(fixed);
71 CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-a10-osc-clk", sun4i_osc_clk_setup);