From: "Nuno Sá" <nuno.sa@analog.com>
To: <linux-hwmon@vger.kernel.org>, <devicetree@vger.kernel.org>
Cc: Guenter Roeck <linux@roeck-us.net>,
Rob Herring <robh+dt@kernel.org>,
Jean Delvare <jdelvare@suse.com>
Subject: [RFC PATCH 2/6] hwmon: axi-fan-control: add tacho devicetree properties
Date: Thu, 8 Jul 2021 14:01:07 +0200 [thread overview]
Message-ID: <20210708120111.519444-3-nuno.sa@analog.com> (raw)
In-Reply-To: <20210708120111.519444-1-nuno.sa@analog.com>
This core is capable to run without any user interaction and when it
does, it uses some predefined values in order to evaluate the tacho
signal from the FAN. These values depend on the attached FAN, so that
the core now exposes registers to change them accordingly. The values
are:
* adi,tacho-25-us: Expected tacho signal when the PWM is 25%;
* adi,tacho-50-us: Expected tacho signal when the PWM is 50%;
* adi,tacho-75-us: Expected tacho signal when the PWM is 75%;
* adi,tacho-100-us: Expected tacho signal when the PWM is 100%.
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/hwmon/axi-fan-control.c | 34 +++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/hwmon/axi-fan-control.c b/drivers/hwmon/axi-fan-control.c
index 901d1588234d..aa5a922f684d 100644
--- a/drivers/hwmon/axi-fan-control.c
+++ b/drivers/hwmon/axi-fan-control.c
@@ -23,6 +23,14 @@
#define ADI_REG_PWM_PERIOD 0x00c0
#define ADI_REG_TACH_MEASUR 0x00c4
#define ADI_REG_TEMPERATURE 0x00c8
+#define ADI_REG_TACH_25 0x0140
+#define ADI_REG_TACH_50 0x0144
+#define ADI_REG_TACH_75 0x0148
+#define ADI_REG_TACH_100 0x014c
+#define ADI_REG_TACH_25_TOL 0x0150
+#define ADI_REG_TACH_50_TOL 0x0154
+#define ADI_REG_TACH_75_TOL 0x0158
+#define ADI_REG_TACH_100_TOL 0x015c
#define ADI_REG_IRQ_MASK 0x0040
#define ADI_REG_IRQ_PENDING 0x0044
@@ -328,6 +336,7 @@ static int axi_fan_control_init(struct axi_fan_control_data *ctl,
const struct device_node *np)
{
int ret;
+ u32 tacho_val;
/* get fan pulses per revolution */
ret = of_property_read_u32(np, "pulses-per-revolution", &ctl->ppr);
@@ -337,6 +346,31 @@ static int axi_fan_control_init(struct axi_fan_control_data *ctl,
/* 1, 2 and 4 are the typical and accepted values */
if (ctl->ppr != 1 && ctl->ppr != 2 && ctl->ppr != 4)
return -EINVAL;
+
+ if (!of_property_read_u32(np, "adi,tacho-25-us", &tacho_val)) {
+ tacho_val = DIV_ROUND_CLOSEST_ULL((u64)tacho_val * ctl->clk_rate, 1000000);
+ axi_iowrite(tacho_val, ADI_REG_TACH_25, ctl);
+ axi_iowrite(DIV_ROUND_CLOSEST(tacho_val * 25, 100), ADI_REG_TACH_25_TOL, ctl);
+ }
+
+ if (!of_property_read_u32(np, "adi,tacho-50-us", &tacho_val)) {
+ tacho_val = DIV_ROUND_CLOSEST_ULL((u64)tacho_val * ctl->clk_rate, 1000000);
+ axi_iowrite(tacho_val, ADI_REG_TACH_50, ctl);
+ axi_iowrite(DIV_ROUND_CLOSEST(tacho_val * 25, 100), ADI_REG_TACH_50_TOL, ctl);
+ }
+
+ if (!of_property_read_u32(np, "adi,tacho-75-us", &tacho_val)) {
+ tacho_val = DIV_ROUND_CLOSEST_ULL((u64)tacho_val * ctl->clk_rate, 1000000);
+ axi_iowrite(tacho_val, ADI_REG_TACH_75, ctl);
+ axi_iowrite(DIV_ROUND_CLOSEST(tacho_val * 25, 100), ADI_REG_TACH_75_TOL, ctl);
+ }
+
+ if (!of_property_read_u32(np, "adi,tacho-100-us", &tacho_val)) {
+ tacho_val = DIV_ROUND_CLOSEST_ULL((u64)tacho_val * ctl->clk_rate, 1000000);
+ axi_iowrite(tacho_val, ADI_REG_TACH_100, ctl);
+ axi_iowrite(DIV_ROUND_CLOSEST(tacho_val * 25, 100), ADI_REG_TACH_100_TOL, ctl);
+ }
+
/*
* Enable all IRQs
*/
--
2.32.0
next prev parent reply other threads:[~2021-07-08 11:58 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-08 12:01 [RFC PATCH 0/6] AXI FAN new features and improvements Nuno Sá
2021-07-08 12:01 ` [RFC PATCH 1/6] hwmon: axi-fan-control: make sure the clock is enabled Nuno Sá
2021-07-17 17:24 ` Guenter Roeck
2021-07-19 7:27 ` Sa, Nuno
2021-07-08 12:01 ` Nuno Sá [this message]
2021-07-08 12:01 ` [RFC PATCH 3/6] dt-bindings: axi-fan-control: add tacho properties Nuno Sá
2021-07-12 17:26 ` Rob Herring
2021-07-15 10:26 ` Sa, Nuno
2021-07-15 20:39 ` Guenter Roeck
2021-07-16 7:44 ` Sa, Nuno
2021-07-16 15:03 ` Guenter Roeck
2021-07-19 7:46 ` Sa, Nuno
2021-07-21 15:00 ` Guenter Roeck
2021-07-22 13:00 ` Sa, Nuno
2021-07-22 15:23 ` Guenter Roeck
2021-07-08 12:01 ` [RFC PATCH 4/6] hwmon: axi-fan-control: handle irqs in natural order Nuno Sá
2021-07-08 12:01 ` [RFC PATCH 5/6] hwmon: axi-fan-control: clear the fan fault irq at startup Nuno Sá
2021-07-08 12:01 ` [RFC PATCH 6/6] hwmon: axi-fan-control: support temperature vs pwm points Nuno Sá
2021-07-17 17:22 ` Guenter Roeck
2021-07-19 7:23 ` Sa, Nuno
2021-07-27 8:42 ` [RFC PATCH 0/6] AXI FAN new features and improvements Sa, Nuno
2021-07-28 18:38 ` Guenter Roeck
2021-08-02 8:04 ` Sa, Nuno
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=20210708120111.519444-3-nuno.sa@analog.com \
--to=nuno.sa@analog.com \
--cc=devicetree@vger.kernel.org \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=robh+dt@kernel.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 NNTP newsgroup(s).