uapi/if_ether.h: move __UAPI_DEF_ETHHDR libc define
[linux/fpc-iii.git] / drivers / clk / mediatek / reset.c
blobd3551d5efef241e04aaabd6a8f372f22c486a5b1
1 /*
2 * Copyright (c) 2014 MediaTek Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
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.
14 #include <linux/mfd/syscon.h>
15 #include <linux/module.h>
16 #include <linux/of.h>
17 #include <linux/platform_device.h>
18 #include <linux/regmap.h>
19 #include <linux/reset-controller.h>
20 #include <linux/slab.h>
22 #include "clk-mtk.h"
24 struct mtk_reset {
25 struct regmap *regmap;
26 int regofs;
27 struct reset_controller_dev rcdev;
30 static int mtk_reset_assert(struct reset_controller_dev *rcdev,
31 unsigned long id)
33 struct mtk_reset *data = container_of(rcdev, struct mtk_reset, rcdev);
35 return regmap_update_bits(data->regmap, data->regofs + ((id / 32) << 2),
36 BIT(id % 32), ~0);
39 static int mtk_reset_deassert(struct reset_controller_dev *rcdev,
40 unsigned long id)
42 struct mtk_reset *data = container_of(rcdev, struct mtk_reset, rcdev);
44 return regmap_update_bits(data->regmap, data->regofs + ((id / 32) << 2),
45 BIT(id % 32), 0);
48 static int mtk_reset(struct reset_controller_dev *rcdev,
49 unsigned long id)
51 int ret;
53 ret = mtk_reset_assert(rcdev, id);
54 if (ret)
55 return ret;
57 return mtk_reset_deassert(rcdev, id);
60 static const struct reset_control_ops mtk_reset_ops = {
61 .assert = mtk_reset_assert,
62 .deassert = mtk_reset_deassert,
63 .reset = mtk_reset,
66 void mtk_register_reset_controller(struct device_node *np,
67 unsigned int num_regs, int regofs)
69 struct mtk_reset *data;
70 int ret;
71 struct regmap *regmap;
73 regmap = syscon_node_to_regmap(np);
74 if (IS_ERR(regmap)) {
75 pr_err("Cannot find regmap for %pOF: %ld\n", np,
76 PTR_ERR(regmap));
77 return;
80 data = kzalloc(sizeof(*data), GFP_KERNEL);
81 if (!data)
82 return;
84 data->regmap = regmap;
85 data->regofs = regofs;
86 data->rcdev.owner = THIS_MODULE;
87 data->rcdev.nr_resets = num_regs * 32;
88 data->rcdev.ops = &mtk_reset_ops;
89 data->rcdev.of_node = np;
91 ret = reset_controller_register(&data->rcdev);
92 if (ret) {
93 pr_err("could not register reset controller: %d\n", ret);
94 kfree(data);
95 return;