Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1168040pxf; Fri, 12 Mar 2021 03:40:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJynCfJr1rD2sNNwokqx2Yn2j7ccro9k5FXnhFHedTJ7D4t2PgC5NY5vENHHIFsG4nkL/crC X-Received: by 2002:aa7:c398:: with SMTP id k24mr13579685edq.61.1615549247297; Fri, 12 Mar 2021 03:40:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615549247; cv=none; d=google.com; s=arc-20160816; b=LVajMLYPQPCOHXBCRkmFa8MxIEgmlzSTDBJT8aqZLA7inu7k5+xx0m0XIfayW+WpfS AQKH08EjR1WZMOEIIG6OxN2X0x5aHbCYGzTaxxr3uTn4+c4/4h0lPlPkSLcYwR0T8OkJ C+/C28+pUsMH+IbDteNqtudXqjQGQXKmXx1/IC3do8JR1VSmHX5hqu76mMf2LHOdJEzZ CvAcchYZahivQvR/K6UJJzBkPCUGONpD9rOSgj2Y/4aXP/6Ch6G7m8SeAj8kWXqmCZZK 3GFUcwAmuGPDKAWm0DLeHZW0Zua0qEqWnUUIQHO/m+I94KsM109K/Ttq93Nk5k8JJ/lE quTw== 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=Ne7UOuBSyQ6LTl/s0Ivg0uTIwKZuUegYCxV2TVHsepI=; b=D8QzFXNiQu+TyR+Atz4tKb1Y3OLCp4h0KB5GsfG3ZiiEPsrOrvbum5wvK5CIFFuJfa 5zwZsD/MUZVLBhl5miTX4nXynkYAzJaZzo8yWl6foMglbHZcjQV39gzIcHIq2qLC7/uf vsbUaLaUjeIHi+QpslwZ6C6p0irO2/EuBEdPJo0QUoA9QUW+0d9vl0IN6f1qM+D33od8 4OBChu2n+efS2CYItfadql/qphwlCtFWN0QyfdxbKx0qiDM90hzJX3ci6izh+gKtTHZn Ny7paPSl0ERci5TN0SeF/gAoyDzMbOt1GlBe0bYH0LoOJZDQbfXKG5dA4pMNn2ADbOX5 sxvQ== 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 c8si3903776edy.116.2021.03.12.03.40.24; Fri, 12 Mar 2021 03:40:47 -0800 (PST) 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 S231906AbhCLGf2 (ORCPT + 99 others); Fri, 12 Mar 2021 01:35:28 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:51394 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231765AbhCLGfP (ORCPT ); Fri, 12 Mar 2021 01:35:15 -0500 X-UUID: 51bdb82c8a9f43aab5225e746b882b3c-20210312 X-UUID: 51bdb82c8a9f43aab5225e746b882b3c-20210312 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 213615173; Fri, 12 Mar 2021 14:35:07 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs05n2.mediatek.inc (172.21.101.140) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 12 Mar 2021 14:35:06 +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; Fri, 12 Mar 2021 14:35:05 +0800 From: Zhiyong Tao To: , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH] pinctrl: add lock in mtk_rmw function. Date: Fri, 12 Mar 2021 14:35:02 +0800 Message-ID: <20210312063502.3685-2-zhiyong.tao@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210312063502.3685-1-zhiyong.tao@mediatek.com> References: <20210312063502.3685-1-zhiyong.tao@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain 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-mtk-common-v2.c | 4 ++++ drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h | 2 ++ drivers/pinctrl/mediatek/pinctrl-paris.c | 2 ++ 3 files changed, 8 insertions(+) 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