Skip to content

Commit 322989d

Browse files
mtk-rex-bc-chenbebarino
authored andcommitted
clk: mediatek: reset: Support inuput argument index mode
There is a large number of mediatek infra reset bits, but we do not use all of them. In addition, the proper input argement of reset controller soulde be index. Therefore, to be compatible with previous drivers and usage, we add description variables to store the ids which can mapping to index. To use this mode, we need to put the id in rst_idx_map to map from index to ids. For example, if we want to input index 1 (this index is used to set bank 1 bit 14) for svs, we need to declare the reset controller like this: In drivers: static u16 rst_ofs[] = { 0x120, 0x130, 0x140, 0x150, 0x730, }; static u16 rst_idx_map[] = { 0 * 32 + 0, 1 * 32 + 14, .... }; static const struct mtk_clk_rst_desc clk_rst_desc = { .version = MTK_RST_SET_CLR, .rst_bank_ofs = rst_ofs, .rst_bank_nr = ARRAY_SIZE(rst_ofs), .rst_idx_map = rst_idx_map, .rst_idx_map_nr = ARRAY_SIZE(rst_idx_map), }; In dts: svs: { ... resets = <&infra 1>; ... }; Signed-off-by: Rex-BC Chen <rex-bc.chen@mediatek.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> Link: https://lore.kernel.org/r/20220523093346.28493-9-rex-bc.chen@mediatek.com Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 723e367 commit 322989d

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

drivers/clk/mediatek/reset.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ static const struct reset_control_ops mtk_reset_ops_set_clr = {
9898
.reset = mtk_reset_set_clr,
9999
};
100100

101+
static int reset_xlate(struct reset_controller_dev *rcdev,
102+
const struct of_phandle_args *reset_spec)
103+
{
104+
struct mtk_clk_rst_data *data = to_mtk_clk_rst_data(rcdev);
105+
106+
if (reset_spec->args[0] >= rcdev->nr_resets ||
107+
reset_spec->args[0] >= data->desc->rst_idx_map_nr)
108+
return -EINVAL;
109+
110+
return data->desc->rst_idx_map[reset_spec->args[0]];
111+
}
112+
101113
void mtk_register_reset_controller(struct device_node *np,
102114
const struct mtk_clk_rst_desc *desc)
103115
{
@@ -136,10 +148,17 @@ void mtk_register_reset_controller(struct device_node *np,
136148
data->desc = desc;
137149
data->regmap = regmap;
138150
data->rcdev.owner = THIS_MODULE;
139-
data->rcdev.nr_resets = desc->rst_bank_nr * RST_NR_PER_BANK;
140151
data->rcdev.ops = rcops;
141152
data->rcdev.of_node = np;
142153

154+
if (data->desc->rst_idx_map_nr > 0) {
155+
data->rcdev.of_reset_n_cells = 1;
156+
data->rcdev.nr_resets = desc->rst_idx_map_nr;
157+
data->rcdev.of_xlate = reset_xlate;
158+
} else {
159+
data->rcdev.nr_resets = desc->rst_bank_nr * RST_NR_PER_BANK;
160+
}
161+
143162
ret = reset_controller_register(&data->rcdev);
144163
if (ret) {
145164
pr_err("could not register reset controller: %d\n", ret);

drivers/clk/mediatek/reset.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ enum mtk_reset_version {
2828
* @version: Reset version which is defined in enum mtk_reset_version.
2929
* @rst_bank_ofs: Pointer to an array containing base offsets of the reset register.
3030
* @rst_bank_nr: Quantity of reset bank.
31+
* @rst_idx_map:Pointer to an array containing ids if input argument is index.
32+
* This array is not necessary if our input argument does not mean index.
33+
* @rst_idx_map_nr: Quantity of reset index map.
3134
*/
3235
struct mtk_clk_rst_desc {
3336
enum mtk_reset_version version;
3437
u16 *rst_bank_ofs;
3538
u32 rst_bank_nr;
39+
u16 *rst_idx_map;
40+
u32 rst_idx_map_nr;
3641
};
3742

3843
/**

0 commit comments

Comments
 (0)