1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2013 Emilio López
5 * Emilio López <emilio@elopez.com.ar>
8 #include <linux/clk-provider.h>
10 #include <linux/of_address.h>
11 #include <linux/slab.h>
13 #define SUNXI_OSC24M_GATE 0
15 static DEFINE_SPINLOCK(hosc_lock
);
17 static void __init
sun4i_osc_clk_setup(struct device_node
*node
)
20 struct clk_fixed_rate
*fixed
;
21 struct clk_gate
*gate
;
22 const char *clk_name
= node
->name
;
25 if (of_property_read_u32(node
, "clock-frequency", &rate
))
28 /* allocate fixed-rate and gate clock structs */
29 fixed
= kzalloc(sizeof(struct clk_fixed_rate
), GFP_KERNEL
);
32 gate
= kzalloc(sizeof(struct clk_gate
), GFP_KERNEL
);
36 of_property_read_string(node
, "clock-output-names", &clk_name
);
38 /* set up gate and fixed rate properties */
39 gate
->reg
= of_iomap(node
, 0);
40 gate
->bit_idx
= SUNXI_OSC24M_GATE
;
41 gate
->lock
= &hosc_lock
;
42 fixed
->fixed_rate
= rate
;
44 clk
= clk_register_composite(NULL
, clk_name
,
47 &fixed
->hw
, &clk_fixed_rate_ops
,
48 &gate
->hw
, &clk_gate_ops
, 0);
53 of_clk_add_provider(node
, of_clk_src_simple_get
, clk
);
62 CLK_OF_DECLARE(sun4i_osc
, "allwinner,sun4i-a10-osc-clk", sun4i_osc_clk_setup
);