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>
19 #include <linux/of_address.h>
20 #include <linux/slab.h>
22 static DEFINE_SPINLOCK(mod1_lock
);
24 #define SUN4I_MOD1_ENABLE 31
25 #define SUN4I_MOD1_MUX 16
26 #define SUN4I_MOD1_MUX_WIDTH 2
27 #define SUN4I_MOD1_MAX_PARENTS 4
29 static void __init
sun4i_mod1_clk_setup(struct device_node
*node
)
33 struct clk_gate
*gate
;
34 const char *parents
[4];
35 const char *clk_name
= node
->name
;
39 reg
= of_io_request_and_map(node
, 0, of_node_full_name(node
));
43 mux
= kzalloc(sizeof(*mux
), GFP_KERNEL
);
47 gate
= kzalloc(sizeof(*gate
), GFP_KERNEL
);
51 of_property_read_string(node
, "clock-output-names", &clk_name
);
52 i
= of_clk_parent_fill(node
, parents
, SUN4I_MOD1_MAX_PARENTS
);
55 gate
->bit_idx
= SUN4I_MOD1_ENABLE
;
56 gate
->lock
= &mod1_lock
;
58 mux
->shift
= SUN4I_MOD1_MUX
;
59 mux
->mask
= BIT(SUN4I_MOD1_MUX_WIDTH
) - 1;
60 mux
->lock
= &mod1_lock
;
62 clk
= clk_register_composite(NULL
, clk_name
, parents
, i
,
63 &mux
->hw
, &clk_mux_ops
,
65 &gate
->hw
, &clk_gate_ops
, CLK_SET_RATE_PARENT
);
69 of_clk_add_provider(node
, of_clk_src_simple_get
, clk
);
80 CLK_OF_DECLARE(sun4i_mod1
, "allwinner,sun4i-a10-mod1-clk",
81 sun4i_mod1_clk_setup
);