1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2016 Maxime Ripard
4 * Maxime Ripard <maxime.ripard@free-electrons.com>
7 #include <linux/delay.h>
9 #include <linux/reset-controller.h>
11 #include "ccu_reset.h"
13 static int ccu_reset_assert(struct reset_controller_dev
*rcdev
,
16 struct ccu_reset
*ccu
= rcdev_to_ccu_reset(rcdev
);
17 const struct ccu_reset_map
*map
= &ccu
->reset_map
[id
];
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
);
31 static int ccu_reset_deassert(struct reset_controller_dev
*rcdev
,
34 struct ccu_reset
*ccu
= rcdev_to_ccu_reset(rcdev
);
35 const struct ccu_reset_map
*map
= &ccu
->reset_map
[id
];
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
);
49 static int ccu_reset_reset(struct reset_controller_dev
*rcdev
,
52 ccu_reset_assert(rcdev
, id
);
54 ccu_reset_deassert(rcdev
, id
);
59 static int ccu_reset_status(struct reset_controller_dev
*rcdev
,
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
,