2 * Copyright 2015 Chen-Yu Tsai
4 * Chen-Yu Tsai <wens@csie.org>
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/reset-controller.h>
21 #include <linux/slab.h>
22 #include <linux/spinlock.h>
24 static DEFINE_SPINLOCK(ve_lock
);
26 #define SUN4I_VE_ENABLE 31
27 #define SUN4I_VE_DIVIDER_SHIFT 16
28 #define SUN4I_VE_DIVIDER_WIDTH 3
29 #define SUN4I_VE_RESET 0
32 * sunxi_ve_reset... - reset bit in ve clk registers handling
35 struct ve_reset_data
{
38 struct reset_controller_dev rcdev
;
41 static int sunxi_ve_reset_assert(struct reset_controller_dev
*rcdev
,
44 struct ve_reset_data
*data
= container_of(rcdev
,
50 spin_lock_irqsave(data
->lock
, flags
);
52 reg
= readl(data
->reg
);
53 writel(reg
& ~BIT(SUN4I_VE_RESET
), data
->reg
);
55 spin_unlock_irqrestore(data
->lock
, flags
);
60 static int sunxi_ve_reset_deassert(struct reset_controller_dev
*rcdev
,
63 struct ve_reset_data
*data
= container_of(rcdev
,
69 spin_lock_irqsave(data
->lock
, flags
);
71 reg
= readl(data
->reg
);
72 writel(reg
| BIT(SUN4I_VE_RESET
), data
->reg
);
74 spin_unlock_irqrestore(data
->lock
, flags
);
79 static int sunxi_ve_of_xlate(struct reset_controller_dev
*rcdev
,
80 const struct of_phandle_args
*reset_spec
)
82 if (WARN_ON(reset_spec
->args_count
!= 0))
88 static const struct reset_control_ops sunxi_ve_reset_ops
= {
89 .assert = sunxi_ve_reset_assert
,
90 .deassert
= sunxi_ve_reset_deassert
,
93 static void __init
sun4i_ve_clk_setup(struct device_node
*node
)
96 struct clk_divider
*div
;
97 struct clk_gate
*gate
;
98 struct ve_reset_data
*reset_data
;
100 const char *clk_name
= node
->name
;
104 reg
= of_io_request_and_map(node
, 0, of_node_full_name(node
));
108 div
= kzalloc(sizeof(*div
), GFP_KERNEL
);
112 gate
= kzalloc(sizeof(*gate
), GFP_KERNEL
);
116 of_property_read_string(node
, "clock-output-names", &clk_name
);
117 parent
= of_clk_get_parent_name(node
, 0);
120 gate
->bit_idx
= SUN4I_VE_ENABLE
;
121 gate
->lock
= &ve_lock
;
124 div
->shift
= SUN4I_VE_DIVIDER_SHIFT
;
125 div
->width
= SUN4I_VE_DIVIDER_WIDTH
;
126 div
->lock
= &ve_lock
;
128 clk
= clk_register_composite(NULL
, clk_name
, &parent
, 1,
130 &div
->hw
, &clk_divider_ops
,
131 &gate
->hw
, &clk_gate_ops
,
132 CLK_SET_RATE_PARENT
);
136 err
= of_clk_add_provider(node
, of_clk_src_simple_get
, clk
);
138 goto err_unregister_clk
;
140 reset_data
= kzalloc(sizeof(*reset_data
), GFP_KERNEL
);
142 goto err_del_provider
;
144 reset_data
->reg
= reg
;
145 reset_data
->lock
= &ve_lock
;
146 reset_data
->rcdev
.nr_resets
= 1;
147 reset_data
->rcdev
.ops
= &sunxi_ve_reset_ops
;
148 reset_data
->rcdev
.of_node
= node
;
149 reset_data
->rcdev
.of_xlate
= sunxi_ve_of_xlate
;
150 reset_data
->rcdev
.of_reset_n_cells
= 0;
151 err
= reset_controller_register(&reset_data
->rcdev
);
160 of_clk_del_provider(node
);
170 CLK_OF_DECLARE(sun4i_ve
, "allwinner,sun4i-a10-ve-clk",