Commit 42a46434 authored by Zhiyong Tao's avatar Zhiyong Tao Committed by Linus Walleij

pinctrl: add lock in mtk_rmw function.

When multiple threads operate on the same register resource
which include multiple pin, It will make the register resource
wrong to control. So we add lock to avoid the case.
Signed-off-by: default avatarZhiyong Tao <zhiyong.tao@mediatek.com>
Link: https://lore.kernel.org/r/20210321033150.15380-2-zhiyong.tao@mediatek.comSigned-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 1517dad8
...@@ -619,6 +619,8 @@ int mtk_moore_pinctrl_probe(struct platform_device *pdev, ...@@ -619,6 +619,8 @@ int mtk_moore_pinctrl_probe(struct platform_device *pdev,
hw->nbase = hw->soc->nbase_names; hw->nbase = hw->soc->nbase_names;
mutex_init(&hw->lock);
/* Copy from internal struct mtk_pin_desc to register to the core */ /* Copy from internal struct mtk_pin_desc to register to the core */
pins = devm_kmalloc_array(&pdev->dev, hw->soc->npins, sizeof(*pins), pins = devm_kmalloc_array(&pdev->dev, hw->soc->npins, sizeof(*pins),
GFP_KERNEL); GFP_KERNEL);
......
...@@ -58,10 +58,14 @@ void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set) ...@@ -58,10 +58,14 @@ void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set)
{ {
u32 val; u32 val;
mutex_lock(&pctl->lock);
val = mtk_r32(pctl, i, reg); val = mtk_r32(pctl, i, reg);
val &= ~mask; val &= ~mask;
val |= set; val |= set;
mtk_w32(pctl, i, reg, val); mtk_w32(pctl, i, reg, val);
mutex_unlock(&pctl->lock);
} }
static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw,
......
...@@ -251,6 +251,8 @@ struct mtk_pinctrl { ...@@ -251,6 +251,8 @@ struct mtk_pinctrl {
struct mtk_eint *eint; struct mtk_eint *eint;
struct mtk_pinctrl_group *groups; struct mtk_pinctrl_group *groups;
const char **grp_names; const char **grp_names;
/* lock pin's register resource to avoid multiple threads issue*/
struct mutex lock;
}; };
void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set); void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set);
......
...@@ -970,6 +970,8 @@ int mtk_paris_pinctrl_probe(struct platform_device *pdev, ...@@ -970,6 +970,8 @@ int mtk_paris_pinctrl_probe(struct platform_device *pdev,
hw->nbase = hw->soc->nbase_names; hw->nbase = hw->soc->nbase_names;
mutex_init(&hw->lock);
err = mtk_pctrl_build_state(pdev); err = mtk_pctrl_build_state(pdev);
if (err) { if (err) {
dev_err(&pdev->dev, "build state failed: %d\n", err); dev_err(&pdev->dev, "build state failed: %d\n", err);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment