WIP FPC-III support
[linux/fpc-iii.git] / drivers / clk / sunxi-ng / ccu_reset.c
blob483100e45df387a517ae38fd21bff73ea9a132e5
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2016 Maxime Ripard
4 * Maxime Ripard <maxime.ripard@free-electrons.com>
5 */
7 #include <linux/delay.h>
8 #include <linux/io.h>
9 #include <linux/reset-controller.h>
11 #include "ccu_reset.h"
13 static int ccu_reset_assert(struct reset_controller_dev *rcdev,
14 unsigned long id)
16 struct ccu_reset *ccu = rcdev_to_ccu_reset(rcdev);
17 const struct ccu_reset_map *map = &ccu->reset_map[id];
18 unsigned long flags;
19 u32 reg;
21 spin_lock_irqsave(ccu->lock, flags);
23 reg = readl(ccu->base + map->reg);
24 writel(reg & ~map->bit, ccu->base + map->reg);
26 spin_unlock_irqrestore(ccu->lock, flags);
28 return 0;
31 static int ccu_reset_deassert(struct reset_controller_dev *rcdev,
32 unsigned long id)
34 struct ccu_reset *ccu = rcdev_to_ccu_reset(rcdev);
35 const struct ccu_reset_map *map = &ccu->reset_map[id];
36 unsigned long flags;
37 u32 reg;
39 spin_lock_irqsave(ccu->lock, flags);
41 reg = readl(ccu->base + map->reg);
42 writel(reg | map->bit, ccu->base + map->reg);
44 spin_unlock_irqrestore(ccu->lock, flags);
46 return 0;
49 static int ccu_reset_reset(struct reset_controller_dev *rcdev,
50 unsigned long id)
52 ccu_reset_assert(rcdev, id);
53 udelay(10);
54 ccu_reset_deassert(rcdev, id);
56 return 0;
59 static int ccu_reset_status(struct reset_controller_dev *rcdev,
60 unsigned long id)
62 struct ccu_reset *ccu = rcdev_to_ccu_reset(rcdev);
63 const struct ccu_reset_map *map = &ccu->reset_map[id];
66 * The reset control API expects 0 if reset is not asserted,
67 * which is the opposite of what our hardware uses.
69 return !(map->bit & readl(ccu->base + map->reg));
72 const struct reset_control_ops ccu_reset_ops = {
73 .assert = ccu_reset_assert,
74 .deassert = ccu_reset_deassert,
75 .reset = ccu_reset_reset,
76 .status = ccu_reset_status,