Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Copyright 2013 Emilio López
0004  *
0005  * Emilio López <emilio@elopez.com.ar>
0006  */
0007 
0008 #include <linux/clk-provider.h>
0009 #include <linux/of.h>
0010 #include <linux/of_address.h>
0011 #include <linux/slab.h>
0012 
0013 #define SUNXI_OSC24M_GATE   0
0014 
0015 static DEFINE_SPINLOCK(hosc_lock);
0016 
0017 static void __init sun4i_osc_clk_setup(struct device_node *node)
0018 {
0019     struct clk *clk;
0020     struct clk_fixed_rate *fixed;
0021     struct clk_gate *gate;
0022     const char *clk_name = node->name;
0023     u32 rate;
0024 
0025     if (of_property_read_u32(node, "clock-frequency", &rate))
0026         return;
0027 
0028     /* allocate fixed-rate and gate clock structs */
0029     fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
0030     if (!fixed)
0031         return;
0032     gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
0033     if (!gate)
0034         goto err_free_fixed;
0035 
0036     of_property_read_string(node, "clock-output-names", &clk_name);
0037 
0038     /* set up gate and fixed rate properties */
0039     gate->reg = of_iomap(node, 0);
0040     gate->bit_idx = SUNXI_OSC24M_GATE;
0041     gate->lock = &hosc_lock;
0042     fixed->fixed_rate = rate;
0043 
0044     clk = clk_register_composite(NULL, clk_name,
0045             NULL, 0,
0046             NULL, NULL,
0047             &fixed->hw, &clk_fixed_rate_ops,
0048             &gate->hw, &clk_gate_ops, 0);
0049 
0050     if (IS_ERR(clk))
0051         goto err_free_gate;
0052 
0053     of_clk_add_provider(node, of_clk_src_simple_get, clk);
0054 
0055     return;
0056 
0057 err_free_gate:
0058     kfree(gate);
0059 err_free_fixed:
0060     kfree(fixed);
0061 }
0062 CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-a10-osc-clk", sun4i_osc_clk_setup);