clk: sunxi-ng: Move all clock types to a library
[sfrench/cifs-2.6.git] / drivers / clk / sunxi-ng / ccu_reset.c
1 /*
2  * Copyright (C) 2016 Maxime Ripard
3  * Maxime Ripard <maxime.ripard@free-electrons.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  */
10
11 #include <linux/io.h>
12 #include <linux/reset-controller.h>
13
14 #include "ccu_reset.h"
15
16 static int ccu_reset_assert(struct reset_controller_dev *rcdev,
17                             unsigned long id)
18 {
19         struct ccu_reset *ccu = rcdev_to_ccu_reset(rcdev);
20         const struct ccu_reset_map *map = &ccu->reset_map[id];
21         unsigned long flags;
22         u32 reg;
23
24         spin_lock_irqsave(ccu->lock, flags);
25
26         reg = readl(ccu->base + map->reg);
27         writel(reg & ~map->bit, ccu->base + map->reg);
28
29         spin_unlock_irqrestore(ccu->lock, flags);
30
31         return 0;
32 }
33
34 static int ccu_reset_deassert(struct reset_controller_dev *rcdev,
35                               unsigned long id)
36 {
37         struct ccu_reset *ccu = rcdev_to_ccu_reset(rcdev);
38         const struct ccu_reset_map *map = &ccu->reset_map[id];
39         unsigned long flags;
40         u32 reg;
41
42         spin_lock_irqsave(ccu->lock, flags);
43
44         reg = readl(ccu->base + map->reg);
45         writel(reg | map->bit, ccu->base + map->reg);
46
47         spin_unlock_irqrestore(ccu->lock, flags);
48
49         return 0;
50 }
51
52 const struct reset_control_ops ccu_reset_ops = {
53         .assert         = ccu_reset_assert,
54         .deassert       = ccu_reset_deassert,
55 };