Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / clk / actions / owl-reset.c
blob203f8f34a8d41dc0f2a0bb466d040ed30353f473
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>
8 #include <linux/delay.h>
9 #include <linux/regmap.h>
10 #include <linux/reset-controller.h>
12 #include "owl-reset.h"
14 static int owl_reset_assert(struct reset_controller_dev *rcdev,
15 unsigned long id)
17 struct owl_reset *reset = to_owl_reset(rcdev);
18 const struct owl_reset_map *map = &reset->reset_map[id];
20 return regmap_update_bits(reset->regmap, map->reg, map->bit, 0);
23 static int owl_reset_deassert(struct reset_controller_dev *rcdev,
24 unsigned long id)
26 struct owl_reset *reset = to_owl_reset(rcdev);
27 const struct owl_reset_map *map = &reset->reset_map[id];
29 return regmap_update_bits(reset->regmap, map->reg, map->bit, map->bit);
32 static int owl_reset_reset(struct reset_controller_dev *rcdev,
33 unsigned long id)
35 owl_reset_assert(rcdev, id);
36 udelay(1);
37 owl_reset_deassert(rcdev, id);
39 return 0;
42 static int owl_reset_status(struct reset_controller_dev *rcdev,
43 unsigned long id)
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;
50 ret = regmap_read(reset->regmap, map->reg, &reg);
51 if (ret)
52 return ret;
55 * The reset control API expects 0 if reset is not asserted,
56 * which is the opposite of what our hardware uses.
58 return !(map->bit & reg);
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,