From patchwork Sun Dec 17 13:36:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maksim Kiselev X-Patchwork-Id: 13495868 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 48FF4C3DA6E for ; Sun, 17 Dec 2023 13:54:33 +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:MIME-Version: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:In-Reply-To:References: List-Owner; bh=zxVnUk1WlIdgJP0d+2tc/SHtP+XRQuo1QZidlOH7AkY=; b=OGuYFoXoTjoFLp N7VUNN2NegD5Kzme3NoRQ/Fl7BptO7jXcE42ZLrhBx4K8+jRWhUXlSqynuXGY6FSVikfEhTtbxu+6 79FKjMAyCcFF2GzUwu9LyR4Rg1i5zzaOlF3chcqa4mQHVEyQY7oMYQ22PxJUakw5TOYkb9aGedhOB qLNpyck1/dFPbPbRQwIlABrdIz3qP5jAlV9NzGJQaC7iRHLze65hl1ymqLsjJrcvHCCwaTPpSCt2z BVoka/8WsZIXRClIVB3g5gIukFCnPGDFYNUXseMsZJPUGxsd+cbyQwXYehFtko4mZEZdw7K1o3wqt dNXpwFFuspqUG1b+2mRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rEram-007uIS-0y; Sun, 17 Dec 2023 13:54:04 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rErak-007uI5-0f for linux-arm-kernel@lists.infradead.org; Sun, 17 Dec 2023 13:54:03 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40c68c1990dso25590215e9.0 for ; Sun, 17 Dec 2023 05:54:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702821239; x=1703426039; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7l6SuuWclfbVcOTuZs6JSfev7h3TS/9oDDExwi6b7pM=; b=MkouAAqNFrLGfmfGSSClG68CnkYrc2n+uMJHYfo/h1PhTmtEOAYqlOdB6ewrGdN4YF ttt8AXONBcLeYNZ6hIORLTs5xnY5zrB0D+/qcg9CPR90nteVd7ejPUSJvGd7QLJ7Jk0R /hXo40XquUA6ZkR6fT2Yha3mArI8OkoNndCBn1ma0FO/pC/mDcMDLoTTLBzTv3fCJZ1/ +THisvTyB7+dCMiDAwBmxvIFL58P+5on4r6Hd7KDFKZrc9POA/lhPmFyO+B1IS7OPzyb zdCtcudIJ+0WPTw6dQF2qa+ynPKgt0u3Iz8r8138GtZnAOSpELMZGLVACDOkZIX3DHIM /5gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702821239; x=1703426039; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7l6SuuWclfbVcOTuZs6JSfev7h3TS/9oDDExwi6b7pM=; b=k633hK1X+qtrbyaVOMSSc9+EUBp435nxzDyjJ9Ec3ZDvSbdZ7qYmjfsQ96of1v7tUX u7t5khDgEcKD/DnXpMW1wTCV8uGAyMziGbXW3c0hCMCianYx3Je8QIGpDCw3Dj9v9bJ2 /LNcirisPZBnqIO5tCKUJMsTcHKf6K3UQqBRGAqoXR+nIR8s125q1pJbPxFURj1vmHPq EpEq6u4fxGaVm0Zd3YwxWKNlY+W8xlv9TmpUIybpgGGWjx7yB3lpdShOuphAvxrm41Qi rHv+iWb8gmoNUG6vk3mqbs/xlU2OsJ7CLhdmINeMtCOM5AdVQV/XU+KIol3Ui17igbQz SjBg== X-Gm-Message-State: AOJu0Yx3Hd8lXL1xB2RzqpLe6tOe8khQ+WawohFb1LAcnIDkAQgllLa5 9qVP6JzLNVKKrBmIg9cot18= X-Google-Smtp-Source: AGHT+IEW3JCvQI7Q3hwLZUTOI9M8yh3XX24F2pz+loq7Z2S4XB7vyZmMIT7P0YAlr69z8+T0dBsjDQ== X-Received: by 2002:a05:600c:a45:b0:40d:1773:4c57 with SMTP id c5-20020a05600c0a4500b0040d17734c57mr264600wmq.195.1702821238481; Sun, 17 Dec 2023 05:53:58 -0800 (PST) Received: from wpc.yadro.com (188-169-139-214.dsl.utg.ge. [188.169.139.214]) by smtp.gmail.com with ESMTPSA id i9-20020a05600c354900b003fee6e170f9sm37413770wmq.45.2023.12.17.05.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 05:53:58 -0800 (PST) From: Maksim Kiselev To: Cc: Maksim Kiselev , Martin Botka , Andre Przywara , Vasily Khoruzhick , Yangtao Li , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-pm@vger.kernel.org (open list:ALLWINNER THERMAL DRIVER), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Allwinner sunXi SoC support), linux-sunxi@lists.linux.dev (open list:ARM/Allwinner sunXi SoC support), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v1] thermal: sun8i: extend H6 calibration function to support 4 sensors Date: Sun, 17 Dec 2023 16:36:36 +0300 Message-Id: <20231217133637.54773-1-bigunclemax@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231217_055402_247239_7677C67F X-CRM114-Status: GOOD ( 14.55 ) 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 The H616 SoC resembles the H6 thermal sensor controller, with a few changes like four sensors. Extend sun50i_h6_ths_calibrate() function to support calibration of these sensors. Signed-off-by: Martin Botka Signed-off-by: Andre Przywara Signed-off-by: Maksim Kiselev Reviewed-by: Andre Przywara --- drivers/thermal/sun8i_thermal.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index f989b55a8aa8..9af95b4785be 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -221,16 +221,21 @@ static int sun50i_h6_ths_calibrate(struct ths_device *tmdev, struct device *dev = tmdev->dev; int i, ft_temp; - if (!caldata[0] || callen < 2 + 2 * tmdev->chip->sensor_num) + if (!caldata[0]) return -EINVAL; /* * efuse layout: * - * 0 11 16 32 - * +-------+-------+-------+ - * |temp| |sensor0|sensor1| - * +-------+-------+-------+ + * 0 11 16 27 32 43 48 57 + * +----------+-----------+-----------+-----------+ + * | temp | |sensor0| |sensor1| |sensor2| | + * +----------+-----------+-----------+-----------+ + * ^ ^ ^ + * | | | + * | | sensor3[11:8] + * | sensor3[7:4] + * sensor3[3:0] * * The calibration data on the H6 is the ambient temperature and * sensor values that are filled during the factory test stage. @@ -243,9 +248,16 @@ static int sun50i_h6_ths_calibrate(struct ths_device *tmdev, ft_temp = (caldata[0] & FT_TEMP_MASK) * 100; for (i = 0; i < tmdev->chip->sensor_num; i++) { - int sensor_reg = caldata[i + 1] & TEMP_CALIB_MASK; - int cdata, offset; - int sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg); + int sensor_reg, sensor_temp, cdata, offset; + + if (i == 3) + sensor_reg = (caldata[1] >> 12) + | ((caldata[2] >> 12) << 4) + | ((caldata[3] >> 12) << 8); + else + sensor_reg = caldata[i + 1] & TEMP_CALIB_MASK; + + sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg); /* * Calibration data is CALIBRATE_DEFAULT - (calculated