e45e32804d2c75aa5e5a1bf11be76e3d422b140b
[releases.git] / reset.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2013, The Linux Foundation. All rights reserved.
4  */
5
6 #include <linux/bitops.h>
7 #include <linux/export.h>
8 #include <linux/regmap.h>
9 #include <linux/reset-controller.h>
10 #include <linux/delay.h>
11
12 #include "reset.h"
13
14 static int qcom_reset(struct reset_controller_dev *rcdev, unsigned long id)
15 {
16         struct qcom_reset_controller *rst = to_qcom_reset_controller(rcdev);
17
18         rcdev->ops->assert(rcdev, id);
19         fsleep(rst->reset_map[id].udelay ?: 1); /* use 1 us as default */
20
21         rcdev->ops->deassert(rcdev, id);
22         return 0;
23 }
24
25 static int
26 qcom_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
27 {
28         struct qcom_reset_controller *rst;
29         const struct qcom_reset_map *map;
30         u32 mask;
31
32         rst = to_qcom_reset_controller(rcdev);
33         map = &rst->reset_map[id];
34         mask = map->bitmask ? map->bitmask : BIT(map->bit);
35
36         return regmap_update_bits(rst->regmap, map->reg, mask, mask);
37 }
38
39 static int
40 qcom_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
41 {
42         struct qcom_reset_controller *rst;
43         const struct qcom_reset_map *map;
44         u32 mask;
45
46         rst = to_qcom_reset_controller(rcdev);
47         map = &rst->reset_map[id];
48         mask = map->bitmask ? map->bitmask : BIT(map->bit);
49
50         return regmap_update_bits(rst->regmap, map->reg, mask, 0);
51 }
52
53 const struct reset_control_ops qcom_reset_ops = {
54         .reset = qcom_reset,
55         .assert = qcom_reset_assert,
56         .deassert = qcom_reset_deassert,
57 };
58 EXPORT_SYMBOL_GPL(qcom_reset_ops);