From patchwork Fri Jan 22 08:40:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pi-cheng.chen" X-Patchwork-Id: 60121 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp510059lbb; Fri, 22 Jan 2016 00:40:47 -0800 (PST) X-Received: by 10.98.0.135 with SMTP id 129mr2681731pfa.156.1453452047814; Fri, 22 Jan 2016 00:40:47 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si8159325pfa.220.2016.01.22.00.40.47; Fri, 22 Jan 2016 00:40:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752730AbcAVIkq (ORCPT + 6 others); Fri, 22 Jan 2016 03:40:46 -0500 Received: from mail-pa0-f49.google.com ([209.85.220.49]:36551 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752373AbcAVIkn (ORCPT ); Fri, 22 Jan 2016 03:40:43 -0500 Received: by mail-pa0-f49.google.com with SMTP id yy13so37991235pab.3 for ; Fri, 22 Jan 2016 00:40:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IY7plkvy8IujZqYaRigEv8G8Hrx359dg4v1nLEL3ycE=; b=PljRfXTCp3NT85B4/x/GN4KpKfgZCUn1y5sXYwzdgces/yqBY4VRGNE3OecrnGAJNY 144iCRWbdgVlS5reEwu+bu4CH0Hq390n18LT5f0lZX0DJS71+Eu9v7xrxlxiCDUx8Pky h7HUqQUkvU7IXY7jMNxhRV1vPo57kf8QX4EDE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IY7plkvy8IujZqYaRigEv8G8Hrx359dg4v1nLEL3ycE=; b=OWYvb1nxfYL5eT+/orHFR4EL9yOh9rz/XJLanYDyu2rvglc+p01TZYW7QlukXnriR5 0fCz5t2cLY+gi39Rvwac3bqU6W74XGL2KToIRyNmjE8/zXYyQjfgKqKd7L9PcNrfrRIA M3mnonO9a56+LCgyeKKEWC5+35y+SwYVrFhqxXaZJnvdobOiBcJjaFs9r8SY7ZJoCRIr HTT7PHAwSenyIbmcLlS/bsgvxnYFF32/wrRdX+erW+RsVJHrhrNRpKggNOPOmozVt2lm goV1A6aY9MjOfCNEbBO3aweaOTC0t62U2zykCdVBJn2DXx6Cf9NsAtpOKujUPdoaAFH8 tJrQ== X-Gm-Message-State: AG10YOT5oMb/KpW822ay5AXP1bLdPstGoxUVQC+9xjwd31+mR/ioULIW2i48JvviA4Ke6VHs X-Received: by 10.66.255.97 with SMTP id ap1mr2568012pad.135.1453452042413; Fri, 22 Jan 2016 00:40:42 -0800 (PST) Received: from localhost.localdomain ([124.219.30.17]) by smtp.googlemail.com with ESMTPSA id ty5sm7761114pac.48.2016.01.22.00.40.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Jan 2016 00:40:41 -0800 (PST) From: Pi-Cheng Chen To: Nishanth Menon , Eduardo Valentin , Viresh Kumar , Rob Herring , Sascha Hauer Cc: Kevin Hilman , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [RFC PATCH 1/5] thermal: MT8173: Replace mutex with spinlock Date: Fri, 22 Jan 2016 16:40:25 +0800 Message-Id: <1453452029-20843-2-git-send-email-pi-cheng.chen@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453452029-20843-1-git-send-email-pi-cheng.chen@linaro.org> References: <1453452029-20843-1-git-send-email-pi-cheng.chen@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Currently switching between the block of banked registers of Mediatek thermal controller is synchronized by a mutex. Replace it with spinlock since switching between register banks might happen in interrupt context in SVS driver which will be introduced later. Signed-off-by: Pi-Cheng Chen --- drivers/thermal/mtk_thermal.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c index 3c233b8..f20e784 100644 --- a/drivers/thermal/mtk_thermal.c +++ b/drivers/thermal/mtk_thermal.c @@ -135,7 +135,7 @@ struct mtk_thermal { struct mtk_thermal_bank banks[MT8173_NUM_ZONES]; - struct mutex lock; + spinlock_t lock; /* Calibration values */ s32 adc_ge; @@ -222,19 +222,17 @@ static int raw_to_mcelsius(struct mtk_thermal *mt, int sensno, s32 raw) } /** - * mtk_thermal_get_bank - get bank + * mtk_thermal_switch_bank - switch to bank * @bank: The bank * * The bank registers are banked, we have to select a bank in the * PTPCORESEL register to access it. */ -static void mtk_thermal_get_bank(struct mtk_thermal_bank *bank) +static void mtk_thermal_switch_bank(struct mtk_thermal_bank *bank) { struct mtk_thermal *mt = bank->mt; u32 val; - mutex_lock(&mt->lock); - val = readl(mt->thermal_base + PTPCORESEL); val &= ~0xf; val |= bank->id; @@ -242,19 +240,6 @@ static void mtk_thermal_get_bank(struct mtk_thermal_bank *bank) } /** - * mtk_thermal_put_bank - release bank - * @bank: The bank - * - * release a bank previously taken with mtk_thermal_get_bank, - */ -static void mtk_thermal_put_bank(struct mtk_thermal_bank *bank) -{ - struct mtk_thermal *mt = bank->mt; - - mutex_unlock(&mt->lock); -} - -/** * mtk_thermal_bank_temperature - get the temperature of a bank * @bank: The bank * @@ -297,13 +282,15 @@ static int mtk_read_temp(void *data, int *temperature) for (i = 0; i < MT8173_NUM_ZONES; i++) { struct mtk_thermal_bank *bank = &mt->banks[i]; + unsigned long flags; int t; - mtk_thermal_get_bank(bank); + spin_lock_irqsave(&mt->lock, flags); + mtk_thermal_switch_bank(bank); t = mtk_thermal_bank_temperature(bank); - mtk_thermal_put_bank(bank); + spin_unlock_irqrestore(&mt->lock, flags); if (t > tempmax) tempmax = t; @@ -323,12 +310,14 @@ static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num, { struct mtk_thermal_bank *bank = &mt->banks[num]; const struct mtk_thermal_bank_cfg *cfg = &bank_data[num]; + unsigned long flags; int i; bank->id = num; bank->mt = mt; - mtk_thermal_get_bank(bank); + spin_lock_irqsave(&mt->lock, flags); + mtk_thermal_switch_bank(bank); /* bus clock 66M counting unit is 12 * 15.15ns * 256 = 46.540us */ writel(TEMP_MONCTL1_PERIOD_UNIT(12), mt->thermal_base + TEMP_MONCTL1); @@ -416,7 +405,7 @@ static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num, writel(TEMP_ADCWRITECTRL_ADC_PNP_WRITE | TEMP_ADCWRITECTRL_ADC_MUX_WRITE, mt->thermal_base + TEMP_ADCWRITECTRL); - mtk_thermal_put_bank(bank); + spin_unlock_irqrestore(&mt->lock, flags); } static u64 of_get_phys_base(struct device_node *np) @@ -513,7 +502,7 @@ static int mtk_thermal_probe(struct platform_device *pdev) if (ret) return ret; - mutex_init(&mt->lock); + spin_lock_init(&mt->lock); mt->dev = &pdev->dev;