xref: /openbmc/linux/drivers/clk/qcom/reset.c (revision 5ee9cd065836e5934710ca35653bce7905add20b)
19c92ab61SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2b36ba30cSStephen Boyd /*
3b36ba30cSStephen Boyd  * Copyright (c) 2013, The Linux Foundation. All rights reserved.
4b36ba30cSStephen Boyd  */
5b36ba30cSStephen Boyd 
6b36ba30cSStephen Boyd #include <linux/bitops.h>
7b36ba30cSStephen Boyd #include <linux/export.h>
8b36ba30cSStephen Boyd #include <linux/regmap.h>
9b36ba30cSStephen Boyd #include <linux/reset-controller.h>
10b36ba30cSStephen Boyd #include <linux/delay.h>
11b36ba30cSStephen Boyd 
12b36ba30cSStephen Boyd #include "reset.h"
13b36ba30cSStephen Boyd 
qcom_reset(struct reset_controller_dev * rcdev,unsigned long id)14b36ba30cSStephen Boyd static int qcom_reset(struct reset_controller_dev *rcdev, unsigned long id)
15b36ba30cSStephen Boyd {
162cb8a39bSStephan Gerhold 	struct qcom_reset_controller *rst = to_qcom_reset_controller(rcdev);
172cb8a39bSStephan Gerhold 
18b36ba30cSStephen Boyd 	rcdev->ops->assert(rcdev, id);
19181b66eeSKonrad Dybcio 	fsleep(rst->reset_map[id].udelay ?: 1); /* use 1 us as default */
20181b66eeSKonrad Dybcio 
21b36ba30cSStephen Boyd 	rcdev->ops->deassert(rcdev, id);
22b36ba30cSStephen Boyd 	return 0;
23b36ba30cSStephen Boyd }
24b36ba30cSStephen Boyd 
qcom_reset_set_assert(struct reset_controller_dev * rcdev,unsigned long id,bool assert)25cbb27876SKonrad Dybcio static int qcom_reset_set_assert(struct reset_controller_dev *rcdev,
26cbb27876SKonrad Dybcio 				 unsigned long id, bool assert)
27b36ba30cSStephen Boyd {
28b36ba30cSStephen Boyd 	struct qcom_reset_controller *rst;
29b36ba30cSStephen Boyd 	const struct qcom_reset_map *map;
30b36ba30cSStephen Boyd 	u32 mask;
31b36ba30cSStephen Boyd 
32b36ba30cSStephen Boyd 	rst = to_qcom_reset_controller(rcdev);
33b36ba30cSStephen Boyd 	map = &rst->reset_map[id];
344a521089SRobert Marko 	mask = map->bitmask ? map->bitmask : BIT(map->bit);
35b36ba30cSStephen Boyd 
36*cfa7009cSKonrad Dybcio 	regmap_update_bits(rst->regmap, map->reg, mask, assert ? mask : 0);
37*cfa7009cSKonrad Dybcio 
38*cfa7009cSKonrad Dybcio 	/* Read back the register to ensure write completion, ignore the value */
39*cfa7009cSKonrad Dybcio 	regmap_read(rst->regmap, map->reg, &mask);
40*cfa7009cSKonrad Dybcio 
41*cfa7009cSKonrad Dybcio 	return 0;
42b36ba30cSStephen Boyd }
43b36ba30cSStephen Boyd 
qcom_reset_assert(struct reset_controller_dev * rcdev,unsigned long id)44cbb27876SKonrad Dybcio static int qcom_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
45b36ba30cSStephen Boyd {
46cbb27876SKonrad Dybcio 	return qcom_reset_set_assert(rcdev, id, true);
47cbb27876SKonrad Dybcio }
48b36ba30cSStephen Boyd 
qcom_reset_deassert(struct reset_controller_dev * rcdev,unsigned long id)49cbb27876SKonrad Dybcio static int qcom_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
50cbb27876SKonrad Dybcio {
51cbb27876SKonrad Dybcio 	return qcom_reset_set_assert(rcdev, id, false);
52b36ba30cSStephen Boyd }
53b36ba30cSStephen Boyd 
54add479eeSPhilipp Zabel const struct reset_control_ops qcom_reset_ops = {
55b36ba30cSStephen Boyd 	.reset = qcom_reset,
56b36ba30cSStephen Boyd 	.assert = qcom_reset_assert,
57b36ba30cSStephen Boyd 	.deassert = qcom_reset_deassert,
58b36ba30cSStephen Boyd };
59b36ba30cSStephen Boyd EXPORT_SYMBOL_GPL(qcom_reset_ops);
60