Skip to content

Commit 0f937c8

Browse files
XECDesignpelwell
authored andcommitted
PoE HAT driver cleanup
* Fix undeclared variable in rpi_poe_fan_suspend * Add SPDX-License-Identifier * Expand PoE acronym in Kconfig help * Give clearer error message on of_property_count_u32_elems fail * Add documentation * Add vendor to of_device_id compatible string. * Rename m_data_s struct to fw_data_s * Fix typos Fixes: #2665 Signed-off-by: Serge Schneider <[email protected]>
1 parent 55de35d commit 0f937c8

File tree

5 files changed

+90
-26
lines changed

5 files changed

+90
-26
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Bindings for the Raspberry Pi PoE HAT fan
2+
3+
Required properties:
4+
- compatible : "raspberrypi,rpi-poe-fan"
5+
- firmware : Reference to the RPi firmware device node
6+
- pwms : the PWM that is used to control the PWM fan
7+
- cooling-levels : PWM duty cycle values in a range from 0 to 255
8+
which correspond to thermal cooling states
9+
10+
Example:
11+
fan0: rpi-poe-fan@0 {
12+
compatible = "raspberrypi,rpi-poe-fan";
13+
firmware = <&firmware>;
14+
cooling-min-state = <0>;
15+
cooling-max-state = <3>;
16+
#cooling-cells = <2>;
17+
cooling-levels = <0 50 150 255>;
18+
status = "okay";
19+
};
20+
21+
thermal-zones {
22+
cpu_thermal: cpu-thermal {
23+
trips {
24+
threshold: trip-point@0 {
25+
temperature = <45000>;
26+
hysteresis = <5000>;
27+
type = "active";
28+
};
29+
target: trip-point@1 {
30+
temperature = <50000>;
31+
hysteresis = <2000>;
32+
type = "active";
33+
};
34+
cpu_hot: cpu_hot@0 {
35+
temperature = <55000>;
36+
hysteresis = <2000>;
37+
type = "active";
38+
};
39+
};
40+
cooling-maps {
41+
map0 {
42+
trip = <&threshold>;
43+
cooling-device = <&fan0 0 1>;
44+
};
45+
map1 {
46+
trip = <&target>;
47+
cooling-device = <&fan0 1 2>;
48+
};
49+
map2 {
50+
trip = <&cpu_hot>;
51+
cooling-device = <&fan0 2 3>;
52+
};
53+
};
54+
};
55+
};

Documentation/hwmon/rpi-poe-fan

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Kernel driver rpi-poe-fan
2+
=====================
3+
4+
This driver enables the use of the Raspberry Pi PoE HAT fan.
5+
6+
Author: Serge Schneider <[email protected]>
7+
8+
Description
9+
-----------
10+
11+
The driver implements a simple interface for driving the Raspberry Pi PoE
12+
(Power over Ethernet) HAT fan. The driver passes commands to the Raspberry Pi
13+
firmware through the mailbox property interface. The firmware then forwards
14+
the commands to the board over I2C on the ID_EEPROM pins. The driver exposes
15+
the fan to the user space through the hwmon sysfs interface.

arch/arm/boot/dts/overlays/rpi-poe-overlay.dts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
target-path = "/";
1212
__overlay__ {
1313
fan0: rpi-poe-fan@0 {
14-
compatible = "rpi-poe-fan";
14+
compatible = "raspberrypi,rpi-poe-fan";
1515
firmware = <&firmware>;
1616
cooling-min-state = <0>;
1717
cooling-max-state = <3>;

drivers/hwmon/Kconfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,11 +1287,12 @@ config SENSORS_PWM_FAN
12871287
will be called pwm-fan.
12881288

12891289
config SENSORS_RPI_POE_FAN
1290-
tristate "Raspberry Pi POE HAT fan"
1290+
tristate "Raspberry Pi PoE HAT fan"
12911291
depends on RASPBERRYPI_FIRMWARE
12921292
depends on THERMAL || THERMAL=n
12931293
help
1294-
If you say yes here you get support for Raspberry Pi POE HAT fan.
1294+
If you say yes here you get support for Raspberry Pi PoE (Power over
1295+
Ethernet) HAT fan.
12951296

12961297
This driver can also be built as a module. If so, the module
12971298
will be called rpi-poe-fan.

drivers/hwmon/rpi-poe-fan.c

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1+
// SPDX-License-Identifier: GPL-2.0
12
/*
2-
* rpi-poe-fan.c - Hwmon driver for Raspberry Pi POE HAT fan.
3+
* rpi-poe-fan.c - Hwmon driver for Raspberry Pi PoE HAT fan.
34
*
45
* Copyright (C) 2018 Raspberry Pi (Trading) Ltd.
56
* Based on pwm-fan.c by Kamil Debski <[email protected]>
67
*
78
* Author: Serge Schneider <[email protected]>
8-
*
9-
* This program is free software; you can redistribute it and/or modify
10-
* it under the terms of the GNU General Public License as published by
11-
* the Free Software Foundation; either version 2 of the License, or
12-
* (at your option) any later version.
13-
*
14-
* This program is distributed in the hope that it will be useful,
15-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17-
* GNU General Public License for more details.
189
*/
1910

2011
#include <linux/hwmon.h>
@@ -46,41 +37,41 @@ struct rpi_poe_fan_ctx {
4637
struct notifier_block nb;
4738
};
4839

49-
struct m_data_s{
40+
struct fw_tag_data_s{
5041
u32 reg;
5142
u32 val;
5243
u32 ret;
5344
};
5445

5546
static int write_reg(struct rpi_firmware *fw, u32 reg, u32 *val){
56-
struct m_data_s m_data = {
47+
struct fw_tag_data_s fw_tag_data = {
5748
.reg = reg,
5849
.val = *val
5950
};
6051
int ret;
6152
ret = rpi_firmware_property(fw, RPI_FIRMWARE_SET_POE_HAT_VAL,
62-
&m_data, sizeof(m_data));
53+
&fw_tag_data, sizeof(fw_tag_data));
6354
if (ret) {
6455
return ret;
65-
} else if (m_data.ret) {
56+
} else if (fw_tag_data.ret) {
6657
return -EIO;
6758
}
6859
return 0;
6960
}
7061

7162
static int read_reg(struct rpi_firmware *fw, u32 reg, u32 *val){
72-
struct m_data_s m_data = {
63+
struct fw_tag_data_s fw_tag_data = {
7364
.reg = reg,
7465
};
7566
int ret;
7667
ret = rpi_firmware_property(fw, RPI_FIRMWARE_GET_POE_HAT_VAL,
77-
&m_data, sizeof(m_data));
68+
&fw_tag_data, sizeof(fw_tag_data));
7869
if (ret) {
7970
return ret;
80-
} else if (m_data.ret) {
71+
} else if (fw_tag_data.ret) {
8172
return -EIO;
8273
}
83-
*val = m_data.val;
74+
*val = fw_tag_data.val;
8475
return 0;
8576
}
8677

@@ -268,7 +259,8 @@ static int rpi_poe_fan_of_get_cooling_data(struct device *dev,
268259

269260
ret = of_property_count_u32_elems(np, "cooling-levels");
270261
if (ret <= 0) {
271-
dev_err(dev, "Wrong data!\n");
262+
dev_err(dev, "cooling-levels property missing or invalid: %d\n",
263+
ret);
272264
return ret ? : -EINVAL;
273265
}
274266

@@ -397,10 +389,11 @@ static int rpi_poe_fan_suspend(struct device *dev)
397389
{
398390
struct rpi_poe_fan_ctx *ctx = dev_get_drvdata(dev);
399391
u32 value = 0;
392+
int ret = 0;
400393

401394
if (ctx->pwm_value != value)
402395
ret = write_reg(ctx->fw, POE_CUR_PWM, &value);
403-
return 0;
396+
return ret;
404397
}
405398

406399
static int rpi_poe_fan_resume(struct device *dev)
@@ -420,7 +413,7 @@ static SIMPLE_DEV_PM_OPS(rpi_poe_fan_pm, rpi_poe_fan_suspend,
420413
rpi_poe_fan_resume);
421414

422415
static const struct of_device_id of_rpi_poe_fan_match[] = {
423-
{ .compatible = "rpi-poe-fan", },
416+
{ .compatible = "raspberrypi,rpi-poe-fan", },
424417
{},
425418
};
426419
MODULE_DEVICE_TABLE(of, of_rpi_poe_fan_match);
@@ -439,5 +432,5 @@ module_platform_driver(rpi_poe_fan_driver);
439432

440433
MODULE_AUTHOR("Serge Schneider <[email protected]>");
441434
MODULE_ALIAS("platform:rpi-poe-fan");
442-
MODULE_DESCRIPTION("Raspberry Pi POE HAT fan driver");
435+
MODULE_DESCRIPTION("Raspberry Pi PoE HAT fan driver");
443436
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)