From mboxrd@z Thu Jan 1 00:00:00 1970 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 4B5A0C48BC4 for ; Thu, 15 Feb 2024 21:25: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:MIME-Version:References: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=ANISoV39sXRmwGEoQKHCspAOUujdSlxlvgWr52ctxoM=; b=aZJux9U42hfzIL Bz6Mcv2hx+YI8sE5KQLdboyGx9mdjmqVK6Jx1Z60T5FwtDiP9YxfbOBRL33DTaBQbzp/I2B3wKaI+ E3+h3hitU2RsKi2VOfVv5evqASOXVUF2l73Fuo4hSjStqHq4/mzmi2Bu+13/peH28kR3L6b9VesBC LwsG7+BFW2xlSwgDrNk0w0ZZ9lVsi0+m3xIVyOZsJWxkB/Pg8rEh9LVwcPhTuC+cXNPrZYDC1Fmru YhvqXTebolq1L4lt0PnYc0k7D9CeDbMUjsPIkJOP0JiQTwakKBgrtR4x3wgRVuZcNpoQHx6Z+ASC1 OmkkDo/PGJHxRsM9TXJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rajE7-00000000BNj-3NfF; Thu, 15 Feb 2024 21:25:03 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rajE5-00000000BN1-0Ylw for linux-arm-kernel@lists.infradead.org; Thu, 15 Feb 2024 21:25:02 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-412345cca4eso3001715e9.2 for ; Thu, 15 Feb 2024 13:25:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708032299; x=1708637099; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FvMVfjIDJ/BKciHnF5qg5N2Qgvv6oBbQkuHi7gs9joc=; b=KImg5oiYEyAktLe3AHMd+XR+YOu+27gWcz31afwfKyGd9yTVeyNPu6+IvgKKvYdMaQ ADbY/NMvHub16DhwQqcAqOQK1VZKEVtktBnJHt6F8siNqtxMuFP7baakgphRbdgJ1KtD MxhNS27fiKaspzyLa0Vt0gmZiaTwxT2I/++UAWRO7bUaB6rTyctdoRd9mGihbgWTRF4t QiLEy8sJocu2aowB/DkWXGVQ9eTESf4lUr2YRghc2+BJ3eJN4FI8ybBi5iLTdrPKIsWA HBLdZ6lLCGdLtNnDrO9Js9nHuugW4ynlIiUxyuvG8450JuUSXo4FjvTBimtml0vgROsr nMUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708032299; x=1708637099; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FvMVfjIDJ/BKciHnF5qg5N2Qgvv6oBbQkuHi7gs9joc=; b=TSOMWznp099KG7eK/3109jIL/VpWMD2Ch0VINm/pMOAMIsGmET3D32mxrvDssfbeiy Q/ZHsAD49wd4/3lcQn3j4j+k3HmRc3GaBuWybF+HrIEVK3kiHDES1WUJP1ZbPAiVpzZS 3kPDX9Tu3dXnpAqJ8H3AdGv1e8JNodoAh6D2NjmuiR39Lgizvy2w5A3u/PT7jNVFegfz gwnJ7rZS3j4Pe/24Vjpnn/Xu3vvjfhRilw/4MME93xwAd1MX5g0900v4rhSDFNNPZA7J hcsSXPRWmokp0yR0C3IOxYB09sdjUkvFwNzyFIHFMAWqmJWnGyyI+FfP1akgKu8V8bk2 C1xA== X-Forwarded-Encrypted: i=1; AJvYcCVLLbqcjDSTdWVWRK77D91aC1RwkxTC1UvlWwRT95nLvFviGVNWfrXLDojIFIP9YAPSs4p5JYZtfpmb3PAXWOFZdPD4l+sYkz+E+VmzVf2OfOzRkeE= X-Gm-Message-State: AOJu0Yy/LyMKu2IatkNpNmttupTopzadG7jAU0T0UM5hRgwLx7gIzqCS EIdj8HsjETxaKbVoh/KYrTqydSYv3UO9KdK878LNKMgjHdEVyWa7 X-Google-Smtp-Source: AGHT+IEqilO1RVYYgsSObj+hh0eVVdOevsjm66BEoLNbz1nZrrTQmxm341SJB7BSHEKpCwvMF+9d8g== X-Received: by 2002:a05:600c:1f87:b0:411:fc3f:c620 with SMTP id je7-20020a05600c1f8700b00411fc3fc620mr2306045wmb.20.1708032295816; Thu, 15 Feb 2024 13:24:55 -0800 (PST) Received: from jernej-laptop.localnet (86-58-6-171.dynamic.telemach.net. [86.58.6.171]) by smtp.gmail.com with ESMTPSA id i5-20020a05600c290500b00410ebcf8180sm280325wmd.43.2024.02.15.13.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 13:24:55 -0800 (PST) From: Jernej =?utf-8?B?xaBrcmFiZWM=?= To: Vasily Khoruzhick , Yangtao Li , Chen-Yu Tsai , Samuel Holland , Andre Przywara Cc: "Rafael J . Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Martin Botka , Maksim Kiselev , Bob McChesney , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: Re: [PATCH v4 5/7] thermal: sun8i: add SRAM register access code Date: Thu, 15 Feb 2024 22:24:54 +0100 Message-ID: <4543691.LvFx2qVVIh@jernej-laptop> In-Reply-To: <20240209144221.3602382-6-andre.przywara@arm.com> References: <20240209144221.3602382-1-andre.przywara@arm.com> <20240209144221.3602382-6-andre.przywara@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240215_132501_228992_BB9FFC58 X-CRM114-Status: GOOD ( 29.42 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Dne petek, 09. februar 2024 ob 15:42:19 CET je Andre Przywara napisal(a): > The Allwinner H616 SoC needs to clear a bit in one register in the SRAM > controller, to report reasonable temperature values. On reset, bit 16 in > register 0x3000000 is set, which leads to the driver reporting > temperatures around 200C. Clearing this bit brings the values down to the > expected range. The BSP code does a one-time write in U-Boot, with a > comment just mentioning the effect on the THS, but offering no further > explanation. > > To not rely on firmware to set things up for us, add code that queries > the SRAM controller device via a DT phandle link, then clear just this > single bit. > > Signed-off-by: Andre Przywara > --- > drivers/thermal/sun8i_thermal.c | 50 +++++++++++++++++++++++++++++++++ > 1 file changed, 50 insertions(+) > > diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c > index c919b0fd5e169..8a9d2bdc71ece 100644 > --- a/drivers/thermal/sun8i_thermal.c > +++ b/drivers/thermal/sun8i_thermal.c > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -66,6 +67,7 @@ struct tsensor { > struct ths_thermal_chip { > bool has_mod_clk; > bool has_bus_clk_reset; > + bool needs_sram; > int sensor_num; > int offset; > int scale; > @@ -83,6 +85,7 @@ struct ths_device { > const struct ths_thermal_chip *chip; > struct device *dev; > struct regmap *regmap; > + struct regmap_field *sram_regmap_field; > struct reset_control *reset; > struct clk *bus_clk; > struct clk *mod_clk; > @@ -337,6 +340,34 @@ static void sun8i_ths_reset_control_assert(void *data) > reset_control_assert(data); > } > > +static struct regmap *sun8i_ths_get_sram_regmap(struct device_node *node) > +{ > + struct device_node *sram_node; > + struct platform_device *sram_pdev; > + struct regmap *regmap = NULL; > + > + sram_node = of_parse_phandle(node, "allwinner,sram", 0); > + if (!sram_node) > + return ERR_PTR(-ENODEV); > + > + sram_pdev = of_find_device_by_node(sram_node); > + if (!sram_pdev) { > + /* platform device might not be probed yet */ > + regmap = ERR_PTR(-EPROBE_DEFER); > + goto out_put_node; > + } > + > + /* If no regmap is found then the other device driver is at fault */ > + regmap = dev_get_regmap(&sram_pdev->dev, NULL); > + if (!regmap) > + regmap = ERR_PTR(-EINVAL); > + > + platform_device_put(sram_pdev); > +out_put_node: > + of_node_put(sram_node); > + return regmap; > +} > + > static int sun8i_ths_resource_init(struct ths_device *tmdev) > { > struct device *dev = tmdev->dev; > @@ -381,6 +412,21 @@ static int sun8i_ths_resource_init(struct ths_device *tmdev) > if (ret) > return ret; > > + if (tmdev->chip->needs_sram) { > + const struct reg_field sun8i_sram_reg_field = > + REG_FIELD(0x0, 16, 16); What about global static constant for a field? Many drivers do so and code would be simpler. Best regards, Jernej > + struct regmap *regmap; > + > + regmap = sun8i_ths_get_sram_regmap(dev->of_node); > + if (IS_ERR(regmap)) > + return PTR_ERR(regmap); > + tmdev->sram_regmap_field = devm_regmap_field_alloc(dev, > + regmap, > + sun8i_sram_reg_field); > + if (IS_ERR(tmdev->sram_regmap_field)) > + return PTR_ERR(tmdev->sram_regmap_field); > + } > + > ret = sun8i_ths_calibrate(tmdev); > if (ret) > return ret; > @@ -427,6 +473,10 @@ static int sun50i_h6_thermal_init(struct ths_device *tmdev) > { > int val; > > + /* The H616 needs to have a bit in the SRAM control register cleared. */ > + if (tmdev->sram_regmap_field) > + regmap_field_write(tmdev->sram_regmap_field, 0); > + > /* > * The manual recommends an overall sample frequency of 50 KHz (20us, > * 480 cycles at 24 MHz), which provides plenty of time for both the > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel