0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/clk-provider.h>
0011 #include <linux/io.h>
0012 #include <linux/of.h>
0013 #include <linux/of_address.h>
0014 #include <linux/slab.h>
0015
0016 static DEFINE_SPINLOCK(gmac_lock);
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 #define SUN7I_A20_GMAC_GPIT 2
0044 #define SUN7I_A20_GMAC_MASK 0x3
0045 #define SUN7I_A20_GMAC_PARENTS 2
0046
0047 static u32 sun7i_a20_gmac_mux_table[SUN7I_A20_GMAC_PARENTS] = {
0048 0x00,
0049 0x02,
0050 };
0051
0052 static void __init sun7i_a20_gmac_clk_setup(struct device_node *node)
0053 {
0054 struct clk *clk;
0055 struct clk_mux *mux;
0056 struct clk_gate *gate;
0057 const char *clk_name = node->name;
0058 const char *parents[SUN7I_A20_GMAC_PARENTS];
0059 void __iomem *reg;
0060
0061 if (of_property_read_string(node, "clock-output-names", &clk_name))
0062 return;
0063
0064
0065 mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL);
0066 if (!mux)
0067 return;
0068
0069 gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
0070 if (!gate)
0071 goto free_mux;
0072
0073
0074 if (of_clk_parent_fill(node, parents, 2) != 2)
0075 goto free_gate;
0076
0077 reg = of_iomap(node, 0);
0078 if (!reg)
0079 goto free_gate;
0080
0081
0082 gate->reg = reg;
0083 gate->bit_idx = SUN7I_A20_GMAC_GPIT;
0084 gate->lock = &gmac_lock;
0085 mux->reg = reg;
0086 mux->mask = SUN7I_A20_GMAC_MASK;
0087 mux->table = sun7i_a20_gmac_mux_table;
0088 mux->lock = &gmac_lock;
0089
0090 clk = clk_register_composite(NULL, clk_name,
0091 parents, SUN7I_A20_GMAC_PARENTS,
0092 &mux->hw, &clk_mux_ops,
0093 NULL, NULL,
0094 &gate->hw, &clk_gate_ops,
0095 0);
0096
0097 if (IS_ERR(clk))
0098 goto iounmap_reg;
0099
0100 of_clk_add_provider(node, of_clk_src_simple_get, clk);
0101
0102 return;
0103
0104 iounmap_reg:
0105 iounmap(reg);
0106 free_gate:
0107 kfree(gate);
0108 free_mux:
0109 kfree(mux);
0110 }
0111 CLK_OF_DECLARE(sun7i_a20_gmac, "allwinner,sun7i-a20-gmac-clk",
0112 sun7i_a20_gmac_clk_setup);