2022-05-23 17:33:28 +08:00
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright ( c ) 2022 MediaTek Inc .
*/
# ifndef __DRV_CLK_MTK_RESET_H
# define __DRV_CLK_MTK_RESET_H
# include <linux/reset-controller.h>
# include <linux/types.h>
2022-05-23 17:33:34 +08:00
# define RST_NR_PER_BANK 32
2022-05-23 17:33:41 +08:00
/* Infra global controller reset set register */
# define INFRA_RST0_SET_OFFSET 0x120
# define INFRA_RST1_SET_OFFSET 0x130
# define INFRA_RST2_SET_OFFSET 0x140
# define INFRA_RST3_SET_OFFSET 0x150
# define INFRA_RST4_SET_OFFSET 0x730
2022-05-23 17:33:32 +08:00
/**
* enum mtk_reset_version - Version of MediaTek clock reset controller .
* @ MTK_RST_SIMPLE : Use the same registers for bit set and clear .
* @ MTK_RST_SET_CLR : Use separate registers for bit set and clear .
* @ MTK_RST_MAX : Total quantity of version for MediaTek clock reset controller .
*/
enum mtk_reset_version {
MTK_RST_SIMPLE = 0 ,
MTK_RST_SET_CLR ,
MTK_RST_MAX ,
} ;
2022-05-23 17:33:33 +08:00
/**
* struct mtk_clk_rst_desc - Description of MediaTek clock reset .
* @ version : Reset version which is defined in enum mtk_reset_version .
2022-05-23 17:33:34 +08:00
* @ rst_bank_ofs : Pointer to an array containing base offsets of the reset register .
2022-05-23 17:33:33 +08:00
* @ rst_bank_nr : Quantity of reset bank .
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>
2022-05-23 17:33:35 +08:00
* @ rst_idx_map : Pointer to an array containing ids if input argument is index .
* This array is not necessary if our input argument does not mean index .
* @ rst_idx_map_nr : Quantity of reset index map .
2022-05-23 17:33:33 +08:00
*/
struct mtk_clk_rst_desc {
enum mtk_reset_version version ;
2022-05-23 17:33:34 +08:00
u16 * rst_bank_ofs ;
2022-05-23 17:33:33 +08:00
u32 rst_bank_nr ;
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>
2022-05-23 17:33:35 +08:00
u16 * rst_idx_map ;
u32 rst_idx_map_nr ;
2022-05-23 17:33:33 +08:00
} ;
/**
* struct mtk_clk_rst_data - Data of MediaTek clock reset controller .
* @ regmap : Pointer to base address of reset register address .
* @ rcdev : Reset controller device .
* @ desc : Pointer to description of the reset controller .
*/
struct mtk_clk_rst_data {
2022-05-23 17:33:28 +08:00
struct regmap * regmap ;
struct reset_controller_dev rcdev ;
2022-05-23 17:33:33 +08:00
const struct mtk_clk_rst_desc * desc ;
2022-05-23 17:33:28 +08:00
} ;
2022-05-23 17:33:32 +08:00
/**
* mtk_register_reset_controller - Register MediaTek clock reset controller
* @ np : Pointer to device node .
2022-05-23 17:33:33 +08:00
* @ desc : Constant pointer to description of clock reset .
2022-05-23 17:33:36 +08:00
*
* Return : 0 on success and errorno otherwise .
2022-05-23 17:33:32 +08:00
*/
2022-05-23 17:33:36 +08:00
int mtk_register_reset_controller ( struct device_node * np ,
const struct mtk_clk_rst_desc * desc ) ;
2022-05-23 17:33:28 +08:00
2022-05-23 17:33:37 +08:00
/**
* mtk_register_reset_controller - Register mediatek clock reset controller with device
* @ np : Pointer to device .
* @ desc : Constant pointer to description of clock reset .
*
* Return : 0 on success and errorno otherwise .
*/
int mtk_register_reset_controller_with_dev ( struct device * dev ,
const struct mtk_clk_rst_desc * desc ) ;
2022-05-23 17:33:28 +08:00
# endif /* __DRV_CLK_MTK_RESET_H */