From patchwork Wed Oct 25 13:30:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Majewski X-Patchwork-Id: 13436129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 546A9C25B47 for ; Wed, 25 Oct 2023 13:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:References:MIME-Version:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tM4f5cb5cWFe3wTD8NrLrxQAduCF5tx1U8xn5q0y0gE=; b=u7uZSH7wU7qrB9 Ec0Iff8y/74W6PvdBhM8ztCzhXsQNIJGXLx9Mjjzil73+yuowEMoczfXkJa4fLwvTdeWpY5NPiRFl inqaND817xD6r47eYtwVf27s0cCBAoifnb8/fd18YNr5RDij2hizmPoAfBLSTI1MJZbQC88LIr10O RpS1kdDbk98qE/MSj+zIt3kRZO3lNwE06U6nBZ/icDM5zANp26RSCqhReVHY8vPkun20XXe/bIh4i H52zaxm+GWVYPQ8jrFZp9tcq9+lRnmt6J+x6Fzv2C3y0EC7MADur17YPtOfm1JLLbNXdy92+vS2HJ 6nZ9//BmJKhtcEfYZW1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qvdz5-00CPXd-1W; Wed, 25 Oct 2023 13:31:43 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qvdyO-00CPEA-21 for linux-arm-kernel@lists.infradead.org; Wed, 25 Oct 2023 13:31:02 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20231025133059euoutp017b652319a648705a8b6d03148b58ba80~RXOHMrM1o0138801388euoutp01J for ; Wed, 25 Oct 2023 13:30:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20231025133059euoutp017b652319a648705a8b6d03148b58ba80~RXOHMrM1o0138801388euoutp01J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698240659; bh=HFjJa1RguNICip8Nann+GThTo5GBNLI3URdePUvmffE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AZnpX9HH0dxpg/Fb8UgwEWRPgmQ2/XFHTfdBBGsTgwk/IGA05MOVeX4anW/ntKrOS y5NL14fIFSkUIHFN1mhdFKpdoLQIt0e7FO5qogoVfAePkIHerm1z09VKAt6lKhS6Ug /BiPplyYdRRNeom3fvKbIFxZh3QF/iacHMqWqcFo= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231025133058eucas1p2ae0d7e96fc3ee9387e28f79996425503~RXOGmIoDt2604026040eucas1p2z; Wed, 25 Oct 2023 13:30:58 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 01.1B.37758.29819356; Wed, 25 Oct 2023 14:30:58 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20231025133058eucas1p149f79722039a90e6e61172ae323b813a~RXOGQN_Qm1623116231eucas1p1O; Wed, 25 Oct 2023 13:30:58 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231025133058eusmtrp2bd86726330a5eef4a72f334cb7034e18~RXOGPR-CE1214112141eusmtrp2S; Wed, 25 Oct 2023 13:30:58 +0000 (GMT) X-AuditID: cbfec7f5-7ffff7000002937e-73-653918925873 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id EF.26.25043.29819356; Wed, 25 Oct 2023 14:30:58 +0100 (BST) Received: from AMDC4515.eu.corp.samsungelectronics.net (unknown [106.120.51.28]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231025133057eusmtip2debfa402ef1f59ea66a6f1930eb75707~RXOFRU8VK1376613766eusmtip2l; Wed, 25 Oct 2023 13:30:57 +0000 (GMT) From: Mateusz Majewski To: linux-pm@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Mateusz Majewski , Bartlomiej Zolnierkiewicz , Krzysztof Kozlowski , "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Alim Akhtar , Liam Girdwood , Mark Brown , Marek Szyprowski , Lukasz Luba Subject: [PATCH v4 7/8] thermal: exynos: split initialization of TMU and the thermal zone Date: Wed, 25 Oct 2023 15:30:26 +0200 Message-ID: <20231025133027.524152-8-m.majewski2@samsung.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231025133027.524152-1-m.majewski2@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrGKsWRmVeSWpSXmKPExsWy7djPc7qTJCxTDdp7NCwezNvGZnF4foXF 1IdP2Cy+b7nOZDHvs6zF3tdb2S2+Xelgstj0+BqrxeVdc9gsPvceYbSYcX4fk8XCphZ2i4nH JjNbrD1yl91i7pepzBZPHvaxOQh4rJm3htFj56y77B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qTJCxTDTrfcFg8mLeNzeLw/AqL qQ+fsFl833KdyWLeZ1mLva+3slt8u9LBZLHp8TVWi8u75rBZfO49wmgx4/w+JouFTS3sFhOP TWa2WHvkLrvF3C9TmS2ePOxjcxDwWDNvDaPHzll32T0W73nJ5LFpVSebx51re9g8Ni+p9+jb sorR4/MmuQCOKD2bovzSklSFjPziElulaEMLIz1DSws9IxNLPUNj81grI1MlfTublNSczLLU In27BL2M9a8bGAvuqFd0vLdpYFym0MXIySEhYCLx+tkW1i5GLg4hgaWMEhMeTWGHSEhLHP4C YwtL/LnWxQZR1MwkMXv2GhaQBJuAgcSDN8vYQRIiAp2MEl2bzzGBJJgF/jNLfJ0JtkJYIFLi wqyrjCA2i4CqxPYNs9lAbF4BW4kjE4+zQWyQl9iz6DtYL6eAnUTv8etgcSGgmgkdD9kh6gUl Ts58wgIxX16ieets5gmMArOQpGYhSS1gZFrFKJJaWpybnltspFecmFtcmpeul5yfu4kRGIfb jv3csoNx5auPeocYmTgYDzFKcDArifBG+likCvGmJFZWpRblxxeV5qQWH2I0Bbp7IrOUaHI+ MBHklcQbmhmYGpqYWRqYWpoZK4nzehZ0JAoJpCeWpGanphakFsH0MXFwSjUwLVP4tGe2ZvCf 3W+8BWb/7zROvGjqrrOFPWrHlonVx/s/PZ71zf2cGJsK70X7S49ebi3k3O7P6zwlWzCg+1/9 WXt+9p7+H0VcNbcZbPc9eLs+SmXKvPmnExKPvxbP5NM2FSp3OeYa98i5+l3h7OvmD2obrfju fNe977Wq8Ynd/BLx9sY9T4RXcy1ZXT//chNjXc8yd9cNL6wtfzGkP0thttea7dbDYvnc3+tT /PKJSZwNB7/GLi1tLXh77MPuL0cXrE89JRcWplCn/+NkWOnOEi7Oi63pNk9DDavvvW1meCjC cGiRd0TsA4buzWYnlaqXlznv+vHwocPKOzNnXlBf8+Ha9uq7+z7/OWBSsdbAUImlOCPRUIu5 qDgRAGyks51MAwAA X-CMS-MailID: 20231025133058eucas1p149f79722039a90e6e61172ae323b813a X-Msg-Generator: CA X-RootMTR: 20231025133058eucas1p149f79722039a90e6e61172ae323b813a X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231025133058eucas1p149f79722039a90e6e61172ae323b813a References: <20231025133027.524152-1-m.majewski2@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231025_063100_934376_DC8BCED4 X-CRM114-Status: GOOD ( 24.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This will be needed in the future, as the thermal zone subsystem might call our callbacks right after devm_thermal_of_zone_register. Currently we just make get_temp return EAGAIN in such case, but this will not be possible with state-modifying callbacks, for instance set_trips. Reviewed-by: Krzysztof Kozlowski Signed-off-by: Mateusz Majewski --- v3 -> v4: Reordered calls done while leaving exynos_tmu_initialize so that they mirror the calls done while entering this function. v1 -> v2: We take clocks into account; exynos_tmu_initialize needs both clocks, as tmu_initialize might use the base_second registers. However, exynos_thermal_zone_configure only needs clk. drivers/thermal/samsung/exynos_tmu.c | 104 +++++++++++++++------------ 1 file changed, 60 insertions(+), 44 deletions(-) diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c index d918bf6d5359..6b3a7dd05c68 100644 --- a/drivers/thermal/samsung/exynos_tmu.c +++ b/drivers/thermal/samsung/exynos_tmu.c @@ -251,25 +251,8 @@ static void sanitize_temp_error(struct exynos_tmu_data *data, u32 trim_info) static int exynos_tmu_initialize(struct platform_device *pdev) { struct exynos_tmu_data *data = platform_get_drvdata(pdev); - struct thermal_zone_device *tzd = data->tzd; - int num_trips = thermal_zone_get_num_trips(tzd); unsigned int status; - int ret = 0, temp; - - ret = thermal_zone_get_crit_temp(tzd, &temp); - if (ret && data->soc != SOC_ARCH_EXYNOS5433) { /* FIXME */ - dev_err(&pdev->dev, - "No CRITICAL trip point defined in device tree!\n"); - goto out; - } - - if (num_trips > data->ntrip) { - dev_info(&pdev->dev, - "More trip points than supported by this TMU.\n"); - dev_info(&pdev->dev, - "%d trip points should be configured in polling mode.\n", - num_trips - data->ntrip); - } + int ret = 0; mutex_lock(&data->lock); clk_enable(data->clk); @@ -280,32 +263,63 @@ static int exynos_tmu_initialize(struct platform_device *pdev) if (!status) { ret = -EBUSY; } else { - int i, ntrips = - min_t(int, num_trips, data->ntrip); - data->tmu_initialize(pdev); - - /* Write temperature code for rising and falling threshold */ - for (i = 0; i < ntrips; i++) { - - struct thermal_trip trip; - - ret = thermal_zone_get_trip(tzd, i, &trip); - if (ret) - goto err; - - data->tmu_set_trip_temp(data, i, trip.temperature / MCELSIUS); - data->tmu_set_trip_hyst(data, i, trip.temperature / MCELSIUS, - trip.hysteresis / MCELSIUS); - } - data->tmu_clear_irqs(data); } + + if (!IS_ERR(data->clk_sec)) + clk_disable(data->clk_sec); + clk_disable(data->clk); + mutex_unlock(&data->lock); + + return ret; +} + +static int exynos_thermal_zone_configure(struct platform_device *pdev) +{ + struct exynos_tmu_data *data = platform_get_drvdata(pdev); + struct thermal_zone_device *tzd = data->tzd; + int i, num_trips = thermal_zone_get_num_trips(tzd); + int ret = 0, temp; + + ret = thermal_zone_get_crit_temp(tzd, &temp); + + if (ret && data->soc != SOC_ARCH_EXYNOS5433) { /* FIXME */ + dev_err(&pdev->dev, + "No CRITICAL trip point defined in device tree!\n"); + goto out; + } + + mutex_lock(&data->lock); + + if (num_trips > data->ntrip) { + dev_info(&pdev->dev, + "More trip points than supported by this TMU.\n"); + dev_info(&pdev->dev, + "%d trip points should be configured in polling mode.\n", + num_trips - data->ntrip); + } + + clk_enable(data->clk); + + num_trips = min_t(int, num_trips, data->ntrip); + + /* Write temperature code for rising and falling threshold */ + for (i = 0; i < num_trips; i++) { + struct thermal_trip trip; + + ret = thermal_zone_get_trip(tzd, i, &trip); + if (ret) + goto err; + + data->tmu_set_trip_temp(data, i, trip.temperature / MCELSIUS); + data->tmu_set_trip_hyst(data, i, trip.temperature / MCELSIUS, + trip.hysteresis / MCELSIUS); + } + err: clk_disable(data->clk); mutex_unlock(&data->lock); - if (!IS_ERR(data->clk_sec)) - clk_disable(data->clk_sec); out: return ret; } @@ -1044,10 +1058,12 @@ static int exynos_tmu_probe(struct platform_device *pdev) break; } - /* - * data->tzd must be registered before calling exynos_tmu_initialize(), - * requesting irq and calling exynos_tmu_control(). - */ + ret = exynos_tmu_initialize(pdev); + if (ret) { + dev_err(&pdev->dev, "Failed to initialize TMU\n"); + return ret; + } + data->tzd = devm_thermal_of_zone_register(&pdev->dev, 0, data, &exynos_sensor_ops); if (IS_ERR(data->tzd)) { @@ -1058,9 +1074,9 @@ static int exynos_tmu_probe(struct platform_device *pdev) goto err_sclk; } - ret = exynos_tmu_initialize(pdev); + ret = exynos_thermal_zone_configure(pdev); if (ret) { - dev_err(&pdev->dev, "Failed to initialize TMU\n"); + dev_err(&pdev->dev, "Failed to configure the thermal zone\n"); goto err_sclk; }