From: "Jernej Škrabec" <jernej.skrabec@gmail.com>
To: Vasily Khoruzhick <anarsoul@gmail.com>,
Yangtao Li <tiny.windzz@gmail.com>, Chen-Yu Tsai <wens@csie.org>,
Samuel Holland <samuel@sholland.org>,
Andre Przywara <andre.przywara@arm.com>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Zhang Rui <rui.zhang@intel.com>,
Lukasz Luba <lukasz.luba@arm.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Martin Botka <martin.botka@somainline.org>,
Maksim Kiselev <bigunclemax@gmail.com>,
Bob McChesney <bob@electricworry.net>,
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 [thread overview]
Message-ID: <4543691.LvFx2qVVIh@jernej-laptop> (raw)
In-Reply-To: <20240209144221.3602382-6-andre.przywara@arm.com>
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 <andre.przywara@arm.com>
> ---
> 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 <linux/module.h>
> #include <linux/nvmem-consumer.h>
> #include <linux/of.h>
> +#include <linux/of_platform.h>
> #include <linux/platform_device.h>
> #include <linux/regmap.h>
> #include <linux/reset.h>
> @@ -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
>
next prev parent reply other threads:[~2024-02-15 21:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-09 14:42 [PATCH v4 0/7] add support for H616 thermal system Andre Przywara
2024-02-09 14:42 ` [PATCH v4 1/7] soc: sunxi: sram: export register 0 for THS on H616 Andre Przywara
2024-02-14 20:29 ` Jernej Škrabec
2024-02-15 1:28 ` Andre Przywara
2024-02-15 21:18 ` Jernej Škrabec
2024-02-09 14:42 ` [PATCH v4 2/7] dt-bindings: thermal: sun8i: Add H616 THS controller Andre Przywara
2024-02-11 16:31 ` Krzysztof Kozlowski
2024-02-09 14:42 ` [PATCH v4 3/7] thermal: sun8i: explain unknown H6 register value Andre Przywara
2024-02-14 20:31 ` Jernej Škrabec
2024-02-09 14:42 ` [PATCH v4 4/7] thermal: sun8i: extend H6 calibration to support 4 sensors Andre Przywara
2024-02-14 20:35 ` Jernej Škrabec
2024-02-09 14:42 ` [PATCH v4 5/7] thermal: sun8i: add SRAM register access code Andre Przywara
2024-02-15 21:24 ` Jernej Škrabec [this message]
2024-02-09 14:42 ` [PATCH v4 6/7] thermal: sun8i: add support for H616 THS controller Andre Przywara
2024-02-09 14:42 ` [PATCH v4 7/7] arm64: dts: allwinner: h616: Add thermal sensor and zones Andre Przywara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4543691.LvFx2qVVIh@jernej-laptop \
--to=jernej.skrabec@gmail.com \
--cc=anarsoul@gmail.com \
--cc=andre.przywara@arm.com \
--cc=bigunclemax@gmail.com \
--cc=bob@electricworry.net \
--cc=conor+dt@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=lukasz.luba@arm.com \
--cc=martin.botka@somainline.org \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
--cc=rui.zhang@intel.com \
--cc=samuel@sholland.org \
--cc=tiny.windzz@gmail.com \
--cc=wens@csie.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).