2 * Copyright (C) 2016 Maxime Ripard
3 * Maxime Ripard <maxime.ripard@free-electrons.com>
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.
11 #include <linux/delay.h>
13 #include <linux/reset-controller.h>
15 #include "ccu_reset.h"
17 static int ccu_reset_assert(struct reset_controller_dev *rcdev,
20 struct ccu_reset *ccu = rcdev_to_ccu_reset(rcdev);
21 const struct ccu_reset_map *map = &ccu->reset_map[id];
25 spin_lock_irqsave(ccu->lock, flags);
27 reg = readl(ccu->base + map->reg);
28 writel(reg & ~map->bit, ccu->base + map->reg);
30 spin_unlock_irqrestore(ccu->lock, flags);
35 static int ccu_reset_deassert(struct reset_controller_dev *rcdev,
38 struct ccu_reset *ccu = rcdev_to_ccu_reset(rcdev);
39 const struct ccu_reset_map *map = &ccu->reset_map[id];
43 spin_lock_irqsave(ccu->lock, flags);
45 reg = readl(ccu->base + map->reg);
46 writel(reg | map->bit, ccu->base + map->reg);
48 spin_unlock_irqrestore(ccu->lock, flags);
53 static int ccu_reset_reset(struct reset_controller_dev *rcdev,
56 ccu_reset_assert(rcdev, id);
58 ccu_reset_deassert(rcdev, id);
63 static int ccu_reset_status(struct reset_controller_dev *rcdev,
66 struct ccu_reset *ccu = rcdev_to_ccu_reset(rcdev);
67 const struct ccu_reset_map *map = &ccu->reset_map[id];
70 * The reset control API expects 0 if reset is not asserted,
71 * which is the opposite of what our hardware uses.
73 return !(map->bit & readl(ccu->base + map->reg));
76 const struct reset_control_ops ccu_reset_ops = {
77 .assert = ccu_reset_assert,
78 .deassert = ccu_reset_deassert,
79 .reset = ccu_reset_reset,
80 .status = ccu_reset_status,