Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp836433ybt; Tue, 7 Jul 2020 01:14:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFP4MBibdDVFsmhvcMsiBKOwB0/z74pcFFWon0+Te5xbFJcxd7O8SpX0nBdQn+ofPSjw7i X-Received: by 2002:a17:906:899:: with SMTP id n25mr43850407eje.298.1594109665214; Tue, 07 Jul 2020 01:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594109665; cv=none; d=google.com; s=arc-20160816; b=aQbU0hbd9EOjeY3zanUoeO/Qs7NBxVpAf5KokMWcsL50hzPTsyJb3Ea4rJUI/qJk5I ucK1B7RHOFN6HBwDGSKCMTiGjh4yjYy4moV8nOMV1jo+D+itVwRAxOehBDwpWSyE/KhG yhW+/KXcL0R8QejxKk1Sn6h3Y+uXWtZ+Yh6rFUsWZPfJDVvg9zqe9Kf2LtVhVMtheBzb R2DXDdopSgzBIjgnfTvJfR7X7oez38i5+b+sTHDhs52Xbg0bvUc91eLHCcEXdT2aK62Z BjTmJTxeyXFy43ppcFXZKONtg/CE/VPpUWn5a7W6ka17o2lWaz5RJWqJDAZypWAO4cwK ZHKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=05xI6wJb+pvE4wHQ2qdDsXdX+BPzXeWRcihwoqOjd6U=; b=i41k3tIKtYTbXcSPIFqtL/z09BJZEd80msd/raaYAAdJRgWWTqiRSxQ85mca/XP76e TIXQ1zkD6Xcba68wiLrFtaN0uZnRGlIddtj5FJsS6HGNGJOCR/a8ecIPiePXvAN09yOT eHwnWv5pllQfH4W+44wwf47uPBmw9yPELVKFfmNL5nlYY6cEsn2cK9JFOxghlLABNtZX M8C5Cm6CGk7t98t35U4SvbK2DmzrLIFZyLZiLciTNM9NpfZ++ChP+6TpxVCXnB0rway3 WAP73tK9Eh6f/XAi2B3LERQQTXBxxTXrHDCdACu5ntKpqoClDDAdIYxY2zwlyuofkgyi a5mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="n+PP/J3k"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ca17si13209306ejb.533.2020.07.07.01.13.59; Tue, 07 Jul 2020 01:14:25 -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; dkim=pass header.i=@linaro.org header.s=google header.b="n+PP/J3k"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728201AbgGGINu (ORCPT + 99 others); Tue, 7 Jul 2020 04:13:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbgGGINu (ORCPT ); Tue, 7 Jul 2020 04:13:50 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7153C061755 for ; Tue, 7 Jul 2020 01:13:49 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id w3so33040110wmi.4 for ; Tue, 07 Jul 2020 01:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=05xI6wJb+pvE4wHQ2qdDsXdX+BPzXeWRcihwoqOjd6U=; b=n+PP/J3kqkRrr/c7+eNimD9rRpfjE7IfpEMRiSGV9YCwHelXn8b/BUiPC0odXPJ9Lj Pk35HpivQKzprFoKVnlhMtQZ/GDkd8aQ2PStjrZ1X0Y8ZoWPLy1kVYKyoaIKMsrgAs0e uH9Wk/Q2I7r1qYRQIr9/RC2bKU8JqDbJkxJ2bapjEp6s7RwmUNBw7c8dF7rJ/uk8BADc lSOeTTNRTPrPMqchjvdNy3sQEIcRUaYxvGEhvnAGm4aoCl/Nus1MGTw7140hSpOVEoOb 5Ilm9oHGJ/KAT0yE73lpzAOE0wbO2KlVK9VVnMbdb4ankQFT+e/b/nRaxEwbXYwN6Qrt GjCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=05xI6wJb+pvE4wHQ2qdDsXdX+BPzXeWRcihwoqOjd6U=; b=ln19CSV9/tnOi2ifmIChONnY2bwDqI1cELInyOFs6rO8/bWFw/QqTmTeT47V7S6YR1 1Hb+KUXcY4UMAjWuzFKOTRX0Qhac/5AO/WzP9nyul7SZla7sndCbpeWKJxlRtbrxvBw7 MtFgxZjTwPzrkZxSM2gXcpaSplPfgnul1exziZBVOTyaA6zZ03y3MEr2ZP5sFIgs/l1Y iHTzPLIOOZ8rwRn62krxDgD5D5nC6GpZIxPdqWsepXDu9Gu873wxkSQrGr3Ovi6exuz7 +/j1PWJK85yWKf5NLelyxf75eZmnBYML/UFPtUTWyQ024T/4cM8JOyxF170M6hsPDrL4 ujlA== X-Gm-Message-State: AOAM532Blwvc+CC70++lIwPNgFz/Z9DO9Eh2tEP3pvXkzw4wzxXB1lDX IlR3+/5BLlpnLI5nzUbCNE3vdSwCdBg= X-Received: by 2002:a7b:c0c9:: with SMTP id s9mr2747323wmh.166.1594109627674; Tue, 07 Jul 2020 01:13:47 -0700 (PDT) Received: from ?IPv6:2a01:e34:ed2f:f020:b4ff:29eb:619e:318? ([2a01:e34:ed2f:f020:b4ff:29eb:619e:318]) by smtp.googlemail.com with ESMTPSA id g3sm18887963wrb.59.2020.07.07.01.13.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Jul 2020 01:13:47 -0700 (PDT) Subject: Re: [v4,7/7] thermal: mediatek: use spinlock to protect PTPCORESEL To: Michael Kao Cc: Matthias Brugger , Zhang Rui , Eduardo Valentin , Rob Herring , Mark Rutland , hsinyi@chromium.org, linux-pm@vger.kernel.org, srv_heupstream@mediatek.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org References: <20200323121537.22697-1-michael.kao@mediatek.com> <20200323121537.22697-8-michael.kao@mediatek.com> <1afbf412-fbeb-8abe-66d8-bd7ac4e9dd83@linaro.org> <1591329023.12739.0.camel@mtksdccf07> From: Daniel Lezcano Message-ID: <4c9e9abf-1f87-ae68-3827-22df52adfd19@linaro.org> Date: Tue, 7 Jul 2020 10:13:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <1591329023.12739.0.camel@mtksdccf07> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/06/2020 05:50, Michael Kao wrote: > On Fri, 2020-05-22 at 17:36 +0200, Daniel Lezcano wrote: >> On 23/03/2020 13:15, Michael Kao wrote: >>> From: "michael.kao" >>> >>> The driver of thermal and svs will use the >>> same register for the project which should select >>> bank before reading sensor value. >> >> Here there is a design problem AFAICT. The sensor should not be using >> external locks. >> > The PTPCORESEL is a common register used by svs and thermal. > The thermal need to ensure PTPCORESEL register will not be changed by > svs when thermal switch bank to read raw data of temperature. > So we use svs_lock to make sure there is no conflict between the two > drivers. Why not use regmap ? >>> Signed-off-by: Michael Kao >>> --- >>> drivers/thermal/mtk_thermal.c | 9 ++++----- >>> 1 file changed, 4 insertions(+), 5 deletions(-) >>> >>> diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c >>> index 9eaca432920e..594ad4f0f8cd 100644 >>> --- a/drivers/thermal/mtk_thermal.c >>> +++ b/drivers/thermal/mtk_thermal.c >>> @@ -22,6 +22,7 @@ >>> #include >>> #include >>> #include >>> +#include >>> >>> /* AUXADC Registers */ >>> #define AUXADC_CON1_SET_V 0x008 >>> @@ -262,7 +263,7 @@ struct mtk_thermal { >>> struct clk *clk_peri_therm; >>> struct clk *clk_auxadc; >>> /* lock: for getting and putting banks */ >>> - struct mutex lock; >>> + unsigned long flags; >>> >>> /* Calibration values */ >>> s32 adc_ge; >>> @@ -561,7 +562,7 @@ static void mtk_thermal_get_bank(struct mtk_thermal_bank *bank) >>> u32 val; >>> >>> if (mt->conf->need_switch_bank) { >>> - mutex_lock(&mt->lock); >>> + mt->flags = claim_mtk_svs_lock(); >>> >>> val = readl(mt->thermal_base + PTPCORESEL); >>> val &= ~0xf; >>> @@ -581,7 +582,7 @@ static void mtk_thermal_put_bank(struct mtk_thermal_bank *bank) >>> struct mtk_thermal *mt = bank->mt; >>> >>> if (mt->conf->need_switch_bank) >>> - mutex_unlock(&mt->lock); >>> + release_mtk_svs_lock(mt->flags); >>> } >>> >>> /** >>> @@ -938,8 +939,6 @@ static int mtk_thermal_probe(struct platform_device *pdev) >>> if (ret) >>> return ret; >>> >>> - mutex_init(&mt->lock); >>> - >>> mt->dev = &pdev->dev; >>> >>> auxadc = of_parse_phandle(np, "mediatek,auxadc", 0); >>> >> >> > -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog