Stephen Boyd | b36ba30 | 2014-01-15 10:47:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This software is licensed under the terms of the GNU General Public |
| 5 | * License version 2, as published by the Free Software Foundation, and |
| 6 | * may be copied, distributed, and modified under those terms. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/bitops.h> |
| 15 | #include <linux/export.h> |
| 16 | #include <linux/regmap.h> |
| 17 | #include <linux/reset-controller.h> |
| 18 | #include <linux/delay.h> |
| 19 | |
| 20 | #include "reset.h" |
| 21 | |
| 22 | static int qcom_reset(struct reset_controller_dev *rcdev, unsigned long id) |
| 23 | { |
| 24 | rcdev->ops->assert(rcdev, id); |
| 25 | udelay(1); |
| 26 | rcdev->ops->deassert(rcdev, id); |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | static int |
| 31 | qcom_reset_assert(struct reset_controller_dev *rcdev, unsigned long id) |
| 32 | { |
| 33 | struct qcom_reset_controller *rst; |
| 34 | const struct qcom_reset_map *map; |
| 35 | u32 mask; |
| 36 | |
| 37 | rst = to_qcom_reset_controller(rcdev); |
| 38 | map = &rst->reset_map[id]; |
| 39 | mask = BIT(map->bit); |
| 40 | |
| 41 | return regmap_update_bits(rst->regmap, map->reg, mask, mask); |
| 42 | } |
| 43 | |
| 44 | static int |
| 45 | qcom_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) |
| 46 | { |
| 47 | struct qcom_reset_controller *rst; |
| 48 | const struct qcom_reset_map *map; |
| 49 | u32 mask; |
| 50 | |
| 51 | rst = to_qcom_reset_controller(rcdev); |
| 52 | map = &rst->reset_map[id]; |
| 53 | mask = BIT(map->bit); |
| 54 | |
| 55 | return regmap_update_bits(rst->regmap, map->reg, mask, 0); |
| 56 | } |
| 57 | |
| 58 | struct reset_control_ops qcom_reset_ops = { |
| 59 | .reset = qcom_reset, |
| 60 | .assert = qcom_reset_assert, |
| 61 | .deassert = qcom_reset_deassert, |
| 62 | }; |
| 63 | EXPORT_SYMBOL_GPL(qcom_reset_ops); |