Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / clk / qcom / reset.c
blobd96c96a9089f40b3a111067434d4d19632505a16
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
4 */
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>
12 #include "reset.h"
14 static int qcom_reset(struct reset_controller_dev *rcdev, unsigned long id)
16 struct qcom_reset_controller *rst = to_qcom_reset_controller(rcdev);
18 rcdev->ops->assert(rcdev, id);
19 fsleep(rst->reset_map[id].udelay ?: 1); /* use 1 us as default */
21 rcdev->ops->deassert(rcdev, id);
22 return 0;
25 static int qcom_reset_set_assert(struct reset_controller_dev *rcdev,
26 unsigned long id, bool assert)
28 struct qcom_reset_controller *rst;
29 const struct qcom_reset_map *map;
30 u32 mask;
32 rst = to_qcom_reset_controller(rcdev);
33 map = &rst->reset_map[id];
34 mask = map->bitmask ? map->bitmask : BIT(map->bit);
36 regmap_update_bits(rst->regmap, map->reg, mask, assert ? mask : 0);
38 /* Read back the register to ensure write completion, ignore the value */
39 regmap_read(rst->regmap, map->reg, &mask);
41 return 0;
44 static int qcom_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
46 return qcom_reset_set_assert(rcdev, id, true);
49 static int qcom_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
51 return qcom_reset_set_assert(rcdev, id, false);
54 const struct reset_control_ops qcom_reset_ops = {
55 .reset = qcom_reset,
56 .assert = qcom_reset_assert,
57 .deassert = qcom_reset_deassert,
59 EXPORT_SYMBOL_GPL(qcom_reset_ops);