Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: mediatek: Add reset controller support

The pericfg and infracfg units also provide reset lines to several
other SoC internal units. This adds a function which can be called
from the pericfg and infracfg initialization functions which will
register the reset controller using reset_controller_register. The
reset controller will provide support for resetting the units
connected to the pericfg and infracfg controller. The units resetted
by this controller can use the standard reset device tree binding
to gain access to the reset lines.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Acked-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

authored by

Sascha Hauer and committed by
Stephen Boyd
d633fb7a 9741b1a6

+108
+1
drivers/clk/mediatek/Makefile
··· 1 1 obj-y += clk-mtk.o clk-pll.o clk-gate.o 2 + obj-$(CONFIG_RESET_CONTROLLER) += reset.o
+10
drivers/clk/mediatek/clk-mtk.h
··· 156 156 const struct mtk_pll_data *plls, int num_plls, 157 157 struct clk_onecell_data *clk_data); 158 158 159 + #ifdef CONFIG_RESET_CONTROLLER 160 + void mtk_register_reset_controller(struct device_node *np, 161 + unsigned int num_regs, int regofs); 162 + #else 163 + static inline void mtk_register_reset_controller(struct device_node *np, 164 + unsigned int num_regs, int regofs) 165 + { 166 + } 167 + #endif 168 + 159 169 #endif /* __DRV_CLK_MTK_H */
+97
drivers/clk/mediatek/reset.c
··· 1 + /* 2 + * Copyright (c) 2014 MediaTek Inc. 3 + * 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. 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/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> 21 + 22 + #include "clk-mtk.h" 23 + 24 + struct mtk_reset { 25 + struct regmap *regmap; 26 + int regofs; 27 + struct reset_controller_dev rcdev; 28 + }; 29 + 30 + static int mtk_reset_assert(struct reset_controller_dev *rcdev, 31 + unsigned long id) 32 + { 33 + struct mtk_reset *data = container_of(rcdev, struct mtk_reset, rcdev); 34 + 35 + return regmap_update_bits(data->regmap, data->regofs + ((id / 32) << 2), 36 + BIT(id % 32), ~0); 37 + } 38 + 39 + static int mtk_reset_deassert(struct reset_controller_dev *rcdev, 40 + unsigned long id) 41 + { 42 + struct mtk_reset *data = container_of(rcdev, struct mtk_reset, rcdev); 43 + 44 + return regmap_update_bits(data->regmap, data->regofs + ((id / 32) << 2), 45 + BIT(id % 32), 0); 46 + } 47 + 48 + static int mtk_reset(struct reset_controller_dev *rcdev, 49 + unsigned long id) 50 + { 51 + int ret; 52 + 53 + ret = mtk_reset_assert(rcdev, id); 54 + if (ret) 55 + return ret; 56 + 57 + return mtk_reset_deassert(rcdev, id); 58 + } 59 + 60 + static struct reset_control_ops mtk_reset_ops = { 61 + .assert = mtk_reset_assert, 62 + .deassert = mtk_reset_deassert, 63 + .reset = mtk_reset, 64 + }; 65 + 66 + void mtk_register_reset_controller(struct device_node *np, 67 + unsigned int num_regs, int regofs) 68 + { 69 + struct mtk_reset *data; 70 + int ret; 71 + struct regmap *regmap; 72 + 73 + regmap = syscon_node_to_regmap(np); 74 + if (IS_ERR(regmap)) { 75 + pr_err("Cannot find regmap for %s: %ld\n", np->full_name, 76 + PTR_ERR(regmap)); 77 + return; 78 + } 79 + 80 + data = kzalloc(sizeof(*data), GFP_KERNEL); 81 + if (!data) 82 + return; 83 + 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; 90 + 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; 96 + } 97 + }