Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2528729pxf; Sat, 20 Mar 2021 20:40:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxa3w5mCB6N8JlxKbtmt3QVU/7sjozaGiqXlE9VmTp7w+sFxevJAg27dy9mzpdhS8I3xk3g X-Received: by 2002:a17:906:b80c:: with SMTP id dv12mr12506545ejb.110.1616298054291; Sat, 20 Mar 2021 20:40:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616298054; cv=none; d=google.com; s=arc-20160816; b=WI7TeqvawaOKe/cr9z7BQeXJFZUBIHQ0NrICg+ZqnPGVArUhjqvJFQ2qX5XbdzOuBw TzPsTfbKaGMBJHNbcBUJQBMOm4lHdyqwG1eBtzrsvsOtvcSntzyFcWFCD6mfKPcR0NJK RNYAW85kPMjzVUi+77tgir33g71/Xh34Bm0jht8pyxsIGcvVuFR5rE/sRzCPeJeZkX8l amcxzrGzcO9v3cPgusGMAcyCH6l/uJkz6sFJLLXbaSoKN/1Faw8tqSbQgauWHrPFEeoD Pm7VOnd0c5/NORlJhz4Rew1ps5jsXYTMUeyDBXkWG2wZ4c0o1eM/cGGgN/b/rQIKdKbb RPew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=MTgH02cdFYTHf2LmhygX2X1lqI2PYPIlgJ2HMErem6o=; b=zHOAfgzLLXL5629eot0luIcwyYUtH+48zEIkyz7lj6+9vG7xua41rrAarq+H972bM/ CruG5PDsTE8pchvbdWYS7xYr8mIwsf3LdrSQz/ECvW9mVNuS3K6IIBzsmDdp0hu70Jv/ vRtA8gOJzX9dPexd+YOF1TBh++ej34ZkXwYI368yv0DgixQHja7BWjVbXuUhyLTbScsc XfMRS/tNp0J8f/z8OXr6KIUZjgieVxby7/y1+HxweZw9qawsD2K8Go0hkiDB3KoKAE5X bgtySvLgc+kWOJi00s8KE4+Cdi0Ht/dyzYw/oyGx1UPsWkigydKE3hVnGHFYWmyUmD5V LAhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a8si7861159ejt.44.2021.03.20.20.40.30; Sat, 20 Mar 2021 20:40:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229893AbhCUDcw (ORCPT + 99 others); Sat, 20 Mar 2021 23:32:52 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:43907 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229766AbhCUDcX (ORCPT ); Sat, 20 Mar 2021 23:32:23 -0400 X-UUID: 68a4fdba93ae430aa3d84cafde72d6b8-20210321 X-UUID: 68a4fdba93ae430aa3d84cafde72d6b8-20210321 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 99678444; Sun, 21 Mar 2021 11:32:18 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 21 Mar 2021 11:31:55 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sun, 21 Mar 2021 11:31:54 +0800 From: Zhiyong Tao To: , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH] pinctrl: add lock in mtk_rmw function. Date: Sun, 21 Mar 2021 11:31:50 +0800 Message-ID: <20210321033150.15380-2-zhiyong.tao@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210321033150.15380-1-zhiyong.tao@mediatek.com> References: <20210321033150.15380-1-zhiyong.tao@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: EF78D9D04B7ACC28C8390CE98C6ECE40209D1609D7CFD814B5CD4A3CF3C78F032000:8 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: Zhiyong Tao --- drivers/pinctrl/mediatek/pinctrl-moore.c | 2 ++ drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 4 ++++ drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h | 2 ++ drivers/pinctrl/mediatek/pinctrl-paris.c | 2 ++ 4 files changed, 10 insertions(+) diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c index 0fa7de43bc4c..f77921957f15 100644 --- a/drivers/pinctrl/mediatek/pinctrl-moore.c +++ b/drivers/pinctrl/mediatek/pinctrl-moore.c @@ -619,6 +619,8 @@ int mtk_moore_pinctrl_probe(struct platform_device *pdev, hw->nbase = hw->soc->nbase_names; + mutex_init(&hw->lock); + /* Copy from internal struct mtk_pin_desc to register to the core */ pins = devm_kmalloc_array(&pdev->dev, hw->soc->npins, sizeof(*pins), GFP_KERNEL); diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c index 72f17f26acd8..fcf7c3eeee4a 100644 --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c @@ -58,10 +58,14 @@ void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set) { u32 val; + mutex_lock(&pctl->lock); + val = mtk_r32(pctl, i, reg); val &= ~mask; val |= set; mtk_w32(pctl, i, reg, val); + + mutex_unlock(&pctl->lock); } static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h index e2aae285b5fc..65eac708a3b3 100644 --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h @@ -251,6 +251,8 @@ struct mtk_pinctrl { struct mtk_eint *eint; struct mtk_pinctrl_group *groups; 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); diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c index da1f19288aa6..48e823f6d293 100644 --- a/drivers/pinctrl/mediatek/pinctrl-paris.c +++ b/drivers/pinctrl/mediatek/pinctrl-paris.c @@ -970,6 +970,8 @@ int mtk_paris_pinctrl_probe(struct platform_device *pdev, hw->nbase = hw->soc->nbase_names; + mutex_init(&hw->lock); + err = mtk_pctrl_build_state(pdev); if (err) { dev_err(&pdev->dev, "build state failed: %d\n", err); -- 2.18.0