Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2587089ybl; Thu, 9 Jan 2020 15:38:53 -0800 (PST) X-Google-Smtp-Source: APXvYqzaTQEtQUN5DkC3Flk98Z3J3Rh7VOCBNfT/qEQmFmH6UsGbIbzeobDIR1D74wEUOQE7uPUi X-Received: by 2002:aca:72d0:: with SMTP id p199mr7356oic.40.1578613133654; Thu, 09 Jan 2020 15:38:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578613133; cv=none; d=google.com; s=arc-20160816; b=MRbaPSVEwGBPzcmzMPZi1bYmWR6MK/fCEzahwlBQvIlATnu9aVuRnH0xMsKRuv4EQa b+D8NTNZxtnVwBMOSC2xRbpji2GlZnS1yq3fkzQXbwR7iQGd06ePZEs9OkIkrLlMdxgS 1vF0MzBTrjt6Xc+kEUCdFnKXCxcmWpOKYuQdb/82YJxkRh8FhlhTMBqMzbON1kQEcvyU 8ra097YEMm2LZKoYOXYP43pD4pbzgWNJcZ1mxtgxowEjcltEVayNW50GFsBi6HKl9Pcn SFINGJsaxI/4HFm9s0QqomXHMzz4xO66rLkiTpdkpi9sHDajnuaE6xw31a2Tgoyps0pf QTxQ== 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:autocrypt:from:references:cc:to:subject:dkim-signature; bh=OkiBfAyiea+S3QYPk/Iz+JDLkJR3ttkyrtVdPCTuhPU=; b=azsIdh2mNjK7Pwb7NoE0lm167ocEyQAwhe2s+IvpKpBwd0pH8ZTOd+o7PdZK0HmPlL 7pHJ0osNV4GOFtxGHiRhd58LFfQwWPzlTWBVi4+ck/crvv1Lf85ki2duoz2MdNHAzJxc pXAZcGuvsU5T9SO60cfC+H8pC3TpbzZ+NyMENhs2F66OTSui7X7B86mAz6RdQ72EB1SM 3dSlatfSBnNlsjfEyiQSOjISomrFLKvQJy5bP6/nx1k72CQ+n2GXyeOoK5KWITr9LLb9 BZdPv/D0X4+7OSiUEVi+AesBC9JCfqF35PVJCH8+qaGR4vq5YGXpSyFWgNhlppNWg3WQ sJdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=liRSIkRr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id o66si21944oig.193.2020.01.09.15.38.42; Thu, 09 Jan 2020 15:38:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=liRSIkRr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1729488AbgAIXhl (ORCPT + 99 others); Thu, 9 Jan 2020 18:37:41 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:44334 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727876AbgAIXhk (ORCPT ); Thu, 9 Jan 2020 18:37:40 -0500 Received: by mail-wr1-f66.google.com with SMTP id q10so5372wrm.11 for ; Thu, 09 Jan 2020 15:37:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:autocrypt:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=OkiBfAyiea+S3QYPk/Iz+JDLkJR3ttkyrtVdPCTuhPU=; b=liRSIkRr92KeTEDlG3OAm2rxJYDe8R3yhU4n/ZHZ/Xu+iUF1C108LnzEMAbElWR9qY 2+sO7+5psgBa5wVqZ6oFv46a1HPldDhgcy/nbRF+Uc1TchWpufTVJRpTbeepL8MiswEj O3iR99E1MiV7eaN9CTTbG2pmTDvMLmbCbwqUmqbg2rZK4zg3A+aCxI/fqYJ6hUAiXpzK +IeTJSXR4zChB0mdyFO14eqpYZ8b394x04dmFsGasRMusgzyay6dOsKvdbvK+4xxUIcb E3HZtcHrD2gZyhxa0qMmj+LhvjzQ98IzV4K2zXz2W0F5zHXzJkaETm1Z6P2vfdDcuGLq itAA== 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:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=OkiBfAyiea+S3QYPk/Iz+JDLkJR3ttkyrtVdPCTuhPU=; b=MFGxIJ6R85aMjMgh6XQdeZu3zeL0JmgmjZ0/BNnteuH+lxVbg3QXG15b8mpXsfxlJi xcenHNkqn2fVLFoktaIe1kfqkP9DhD9XefkCR6zDhr2jSlvmD3fY2Sh+xPH58iGZYbh/ E2wcYUaAlOfD4I5CgGq6LGXlmKJWSs4IwHzsYV6wo7rsm4BrrxxJIuGEtV68cpxEfYIp PZ7NeysjtXyNva9UelHqE92CSd9sB3en1uWqE0v147/E2k1fkopC+HqVdEksUT3tfa7s 6iYURpGwL6rqukxed7R+ThSOGW2Ak3Z45g32nwdYsJJzjHfw8+5zZdY/nFbsfCkk26/w raZA== X-Gm-Message-State: APjAAAV/b5gI7o9YHeeUfPL32D1doYkUhj27HBHUMc8Yd8j486YOOw0o BiCjtXaq3xQpsEfbMwLmbwrQNQ== X-Received: by 2002:adf:f5cf:: with SMTP id k15mr269443wrp.182.1578613057624; Thu, 09 Jan 2020 15:37:37 -0800 (PST) Received: from ?IPv6:2a01:e34:ed2f:f020:f1d5:61e0:e9d8:1c3d? ([2a01:e34:ed2f:f020:f1d5:61e0:e9d8:1c3d]) by smtp.googlemail.com with ESMTPSA id t5sm124922wrr.35.2020.01.09.15.37.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Jan 2020 15:37:37 -0800 (PST) Subject: Re: [RESEND][PATCH] thermal: mediatek: add suspend/resume callback To: Michael Kao , Zhang Rui , Eduardo Valentin , Rob Herring , Mark Rutland , Matthias Brugger , hsinyi@chromium.org, linux-pm@vger.kernel.org, srv_heupstream@mediatek.com Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Louis Yu References: <20191219092431.8935-1-michael.kao@mediatek.com> <20191219092431.8935-2-michael.kao@mediatek.com> From: Daniel Lezcano Autocrypt: addr=daniel.lezcano@linaro.org; prefer-encrypt=mutual; keydata= xsFNBFv/yykBEADDdW8RZu7iZILSf3zxq5y8YdaeyZjI/MaqgnvG/c3WjFaunoTMspeusiFE sXvtg3ehTOoyD0oFjKkHaia1Zpa1m/gnNdT/WvTveLfGA1gH+yGes2Sr53Ht8hWYZFYMZc8V 2pbSKh8wepq4g8r5YI1XUy9YbcTdj5mVrTklyGWA49NOeJz2QbfytMT3DJmk40LqwK6CCSU0 9Ed8n0a+vevmQoRZJEd3Y1qXn2XHys0F6OHCC+VLENqNNZXdZE9E+b3FFW0lk49oLTzLRNIq 0wHeR1H54RffhLQAor2+4kSSu8mW5qB0n5Eb/zXJZZ/bRiXmT8kNg85UdYhvf03ZAsp3qxcr xMfMsC7m3+ADOtW90rNNLZnRvjhsYNrGIKH8Ub0UKXFXibHbafSuq7RqyRQzt01Ud8CAtq+w P9EftUysLtovGpLSpGDO5zQ++4ZGVygdYFr318aGDqCljKAKZ9hYgRimPBToDedho1S1uE6F 6YiBFnI3ry9+/KUnEP6L8Sfezwy7fp2JUNkUr41QF76nz43tl7oersrLxHzj2dYfWUAZW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ZFGr+GoHwiELqfLEAQ9AhlrHGCKcgVgTOI6NHg== Message-ID: <7e3506e3-a99e-eb01-ee42-5876b542fe38@linaro.org> Date: Fri, 10 Jan 2020 00:37:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20191219092431.8935-2-michael.kao@mediatek.com> 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 19/12/2019 10:24, Michael Kao wrote: > From: Louis Yu > > Add suspend/resume callback to disable/enable Mediatek thermal sensor > respectively. Since thermal power domain is off in suspend, thermal driver > needs re-initialization during resume. > > Signed-off-by: Louis Yu > Signed-off-by: Michael Kao > --- > drivers/thermal/mtk_thermal.c | 134 +++++++++++++++++++++++++++++++--- > 1 file changed, 125 insertions(+), 9 deletions(-) > > diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c > index acf4854cbb8b..2bb8b13591aa 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 > @@ -31,6 +32,8 @@ > > #define APMIXED_SYS_TS_CON1 0x604 > > +#define APMIXED_SYS_TS_CON1_BUFFER_OFF 0x30 > + > /* Thermal Controller Registers */ > #define TEMP_MONCTL0 0x000 > #define TEMP_MONCTL1 0x004 > @@ -38,6 +41,7 @@ > #define TEMP_MONIDET0 0x014 > #define TEMP_MONIDET1 0x018 > #define TEMP_MSRCTL0 0x038 > +#define TEMP_MSRCTL1 0x03c > #define TEMP_AHBPOLL 0x040 > #define TEMP_AHBTO 0x044 > #define TEMP_ADCPNP0 0x048 > @@ -87,6 +91,9 @@ > #define TEMP_ADCVALIDMASK_VALID_HIGH BIT(5) > #define TEMP_ADCVALIDMASK_VALID_POS(bit) (bit) > > +#define TEMP_MSRCTL1_BUS_STA (BIT(0) | BIT(7)) > +#define TEMP_MSRCTL1_SENSING_POINTS_PAUSE 0x10E > + > /* MT8173 thermal sensors */ > #define MT8173_TS1 0 > #define MT8173_TS2 1 > @@ -250,6 +257,10 @@ struct mtk_thermal_data { > struct mtk_thermal { > struct device *dev; > void __iomem *thermal_base; > + void __iomem *apmixed_base; > + void __iomem *auxadc_base; > + u64 apmixed_phys_base; > + u64 auxadc_phys_base; > > struct clk *clk_peri_therm; > struct clk *clk_auxadc; > @@ -746,6 +757,42 @@ static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num, > mtk_thermal_put_bank(bank); > } > > +static int mtk_thermal_disable_sensing(struct mtk_thermal *mt, int num) > +{ > + struct mtk_thermal_bank *bank = &mt->banks[num]; > + u32 val; > + unsigned long timeout; > + void __iomem *addr; > + int ret = 0; > + > + bank->id = num; > + bank->mt = mt; Can you explain why this is done? > + mtk_thermal_get_bank(bank); I'm not comfortable with this call. The underlying code is calling mutex_lock, I suspect it can potentially deadlock the board. Why do you need a mutex? Isn't a spin_lock enough? Please take also the opportunity to rename to lock_bank / unlock_bank. get and put are usually for refcounting. > + val = readl(mt->thermal_base + TEMP_MSRCTL1); > + /* pause periodic temperature measurement for sensing points */ > + writel(val | TEMP_MSRCTL1_SENSING_POINTS_PAUSE, > + mt->thermal_base + TEMP_MSRCTL1); > + > + /* wait until temperature measurement bus idle */ > + timeout = jiffies + HZ; > + addr = mt->thermal_base + TEMP_MSRCTL1; > + > + ret = readl_poll_timeout(addr, val, (val & TEMP_MSRCTL1_BUS_STA) == 0x0, > + 0, timeout); > + if (ret < 0) > + goto out; > + > + /* disable periodic temperature meausrement on sensing points */ s/meausrement/measurement/ > + writel(0x0, mt->thermal_base + TEMP_MONCTL0); > + > +out: > + mtk_thermal_put_bank(bank); > + > + return ret; > +} > + > static u64 of_get_phys_base(struct device_node *np) > { > u64 size64; > @@ -868,7 +915,6 @@ static int mtk_thermal_probe(struct platform_device *pdev) > struct device_node *auxadc, *apmixedsys, *np = pdev->dev.of_node; > struct mtk_thermal *mt; > struct resource *res; > - u64 auxadc_phys_base, apmixed_phys_base; > struct thermal_zone_device *tzdev; > > mt = devm_kzalloc(&pdev->dev, sizeof(*mt), GFP_KERNEL); > @@ -904,11 +950,11 @@ static int mtk_thermal_probe(struct platform_device *pdev) > return -ENODEV; > } > > - auxadc_phys_base = of_get_phys_base(auxadc); > + mt->auxadc_phys_base = of_get_phys_base(auxadc); > > of_node_put(auxadc); > > - if (auxadc_phys_base == OF_BAD_ADDR) { > + if (mt->auxadc_phys_base == OF_BAD_ADDR) { > dev_err(&pdev->dev, "Can't get auxadc phys address\n"); > return -EINVAL; > } > @@ -919,11 +965,12 @@ static int mtk_thermal_probe(struct platform_device *pdev) > return -ENODEV; > } > > - apmixed_phys_base = of_get_phys_base(apmixedsys); > + mt->apmixed_phys_base = of_get_phys_base(apmixedsys); > + mt->apmixed_base = of_iomap(apmixedsys, 0); > > of_node_put(apmixedsys); > > - if (apmixed_phys_base == OF_BAD_ADDR) { > + if (mt->apmixed_phys_base == OF_BAD_ADDR) { > dev_err(&pdev->dev, "Can't get auxadc phys address\n"); > return -EINVAL; > } > @@ -935,19 +982,19 @@ static int mtk_thermal_probe(struct platform_device *pdev) > ret = clk_prepare_enable(mt->clk_auxadc); > if (ret) { > dev_err(&pdev->dev, "Can't enable auxadc clk: %d\n", ret); > - return ret; > + goto err_disable_clk_auxadc; > } > > ret = clk_prepare_enable(mt->clk_peri_therm); > if (ret) { > dev_err(&pdev->dev, "Can't enable peri clk: %d\n", ret); > - goto err_disable_clk_auxadc; > + goto err_disable_clk_peri_therm; > } > > for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++) > for (i = 0; i < mt->conf->num_banks; i++) > - mtk_thermal_init_bank(mt, i, apmixed_phys_base, > - auxadc_phys_base, ctrl_id); > + mtk_thermal_init_bank(mt, i, mt->apmixed_phys_base, > + mt->auxadc_phys_base, ctrl_id); > > platform_set_drvdata(pdev, mt); > > @@ -978,11 +1025,80 @@ static int mtk_thermal_remove(struct platform_device *pdev) > return 0; > } > > +static int __maybe_unused mtk_thermal_suspend(struct device *dev) > +{ > + struct platform_device *pdev = to_platform_device(dev); > + struct mtk_thermal *mt = platform_get_drvdata(pdev); > + int i, ret; > + > + for (i = 0; i < mt->conf->num_banks; i++) { > + ret = mtk_thermal_disable_sensing(mt, i); > + if (ret) > + goto out; > + } > + > + /* disable buffer */ > + writel(readl(mt->apmixed_base + APMIXED_SYS_TS_CON1) | > + APMIXED_SYS_TS_CON1_BUFFER_OFF, > + mt->apmixed_base + APMIXED_SYS_TS_CON1); > + > + clk_disable_unprepare(mt->clk_peri_therm); > + clk_disable_unprepare(mt->clk_auxadc); > + > + return 0; > + > +out: > + dev_err(&pdev->dev, "Failed to wait until bus idle\n"); > + > + return ret; > +} > + > +static int __maybe_unused mtk_thermal_resume(struct device *dev) > +{ > + struct platform_device *pdev = to_platform_device(dev); > + struct mtk_thermal *mt = platform_get_drvdata(pdev); > + int i, ret, ctrl_id; > + > + ret = device_reset(&pdev->dev); > + if (ret) > + return ret; > + > + ret = clk_prepare_enable(mt->clk_auxadc); > + if (ret) { > + dev_err(&pdev->dev, "Can't enable auxadc clk: %d\n", ret); > + goto err_disable_clk_auxadc; > + } > + > + ret = clk_prepare_enable(mt->clk_peri_therm); > + if (ret) { > + dev_err(&pdev->dev, "Can't enable peri clk: %d\n", ret); > + goto err_disable_clk_peri_therm; > + } > + > + for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++) > + for (i = 0; i < mt->conf->num_banks; i++) > + mtk_thermal_init_bank(mt, i, mt->apmixed_phys_base, > + mt->auxadc_phys_base, ctrl_id); > + > + return 0; > + > +err_disable_clk_peri_therm: > + clk_disable_unprepare(mt->clk_peri_therm); > +err_disable_clk_auxadc: > + clk_disable_unprepare(mt->clk_auxadc); > + > + return ret; > +} > + > +static SIMPLE_DEV_PM_OPS(mtk_thermal_pm_ops, > + mtk_thermal_suspend, mtk_thermal_resume); > + > static struct platform_driver mtk_thermal_driver = { > .probe = mtk_thermal_probe, > .remove = mtk_thermal_remove, > .driver = { > .name = "mtk-thermal", > + .pm = &mtk_thermal_pm_ops, > .of_match_table = mtk_thermal_of_match, > }, > }; > -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog