xref: /linux/drivers/clk/actions/owl-reset.c (revision a4eb44a6435d6d8f9e642407a4a06f65eb90ca04)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 //
3 // Actions Semi Owl SoCs Reset Management Unit driver
4 //
5 // Copyright (c) 2018 Linaro Ltd.
6 // Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
7 
8 #include <linux/delay.h>
9 #include <linux/regmap.h>
10 #include <linux/reset-controller.h>
11 
12 #include "owl-reset.h"
13 
14 static int owl_reset_assert(struct reset_controller_dev *rcdev,
15 			    unsigned long id)
16 {
17 	struct owl_reset *reset = to_owl_reset(rcdev);
18 	const struct owl_reset_map *map = &reset->reset_map[id];
19 
20 	return regmap_update_bits(reset->regmap, map->reg, map->bit, 0);
21 }
22 
23 static int owl_reset_deassert(struct reset_controller_dev *rcdev,
24 			      unsigned long id)
25 {
26 	struct owl_reset *reset = to_owl_reset(rcdev);
27 	const struct owl_reset_map *map = &reset->reset_map[id];
28 
29 	return regmap_update_bits(reset->regmap, map->reg, map->bit, map->bit);
30 }
31 
32 static int owl_reset_reset(struct reset_controller_dev *rcdev,
33 			   unsigned long id)
34 {
35 	owl_reset_assert(rcdev, id);
36 	udelay(1);
37 	owl_reset_deassert(rcdev, id);
38 
39 	return 0;
40 }
41 
42 static int owl_reset_status(struct reset_controller_dev *rcdev,
43 			    unsigned long id)
44 {
45 	struct owl_reset *reset = to_owl_reset(rcdev);
46 	const struct owl_reset_map *map = &reset->reset_map[id];
47 	u32 reg;
48 	int ret;
49 
50 	ret = regmap_read(reset->regmap, map->reg, &reg);
51 	if (ret)
52 		return ret;
53 
54 	/*
55 	 * The reset control API expects 0 if reset is not asserted,
56 	 * which is the opposite of what our hardware uses.
57 	 */
58 	return !(map->bit & reg);
59 }
60 
61 const struct reset_control_ops owl_reset_ops = {
62 	.assert		= owl_reset_assert,
63 	.deassert	= owl_reset_deassert,
64 	.reset		= owl_reset_reset,
65 	.status		= owl_reset_status,
66 };
67