b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 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 | udelay(rst->reset_map[id].udelay ?: 1); /* use 1 us as default */ |
| 20 | rcdev->ops->deassert(rcdev, id); |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | static int qcom_reset_set_assert(struct reset_controller_dev *rcdev, |
| 25 | unsigned long id, bool assert) |
| 26 | { |
| 27 | struct qcom_reset_controller *rst; |
| 28 | const struct qcom_reset_map *map; |
| 29 | u32 mask; |
| 30 | |
| 31 | rst = to_qcom_reset_controller(rcdev); |
| 32 | map = &rst->reset_map[id]; |
| 33 | mask = map->bitmask ? map->bitmask : BIT(map->bit); |
| 34 | |
| 35 | regmap_update_bits(rst->regmap, map->reg, mask, assert ? mask : 0); |
| 36 | |
| 37 | /* Read back the register to ensure write completion, ignore the value */ |
| 38 | regmap_read(rst->regmap, map->reg, &mask); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static int qcom_reset_assert(struct reset_controller_dev *rcdev, unsigned long id) |
| 44 | { |
| 45 | return qcom_reset_set_assert(rcdev, id, true); |
| 46 | } |
| 47 | |
| 48 | static int qcom_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) |
| 49 | { |
| 50 | return qcom_reset_set_assert(rcdev, id, false); |
| 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); |