aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/brcm2708/patches-4.14/950-0412-PoE-HAT-driver-cleanup.patch
blob: 58aa53955014370a4647d37d4ce94b6b67afa8e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
From 97a6a1f61eb949892457a739435fd5280fc800f8 Mon Sep 17 00:00:00 2001
From: XECDesign <XECDesign@users.noreply.github.com>
Date: Wed, 29 Aug 2018 15:08:30 +0100
Subject: [PATCH 412/454] 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 <serge@raspberrypi.org>
---
 .../devicetree/bindings/hwmon/rpi-poe-fan.txt | 55 +++++++++++++++++++
 Documentation/hwmon/rpi-poe-fan               | 15 +++++
 .../arm/boot/dts/overlays/rpi-poe-overlay.dts |  2 +-
 drivers/hwmon/Kconfig                         |  5 +-
 drivers/hwmon/rpi-poe-fan.c                   | 39 ++++++-------
 5 files changed, 90 insertions(+), 26 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/rpi-poe-fan.txt
 create mode 100644 Documentation/hwmon/rpi-poe-fan

--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/rpi-poe-fan.txt
@@ -0,0 +1,55 @@
+Bindings for the Raspberry Pi PoE HAT fan
+
+Required properties:
+- compatible	: "raspberrypi,rpi-poe-fan"
+- firmware	: Reference to the RPi firmware device node
+- pwms		: the PWM that is used to control the PWM fan
+- cooling-levels      : PWM duty cycle values in a range from 0 to 255
+			which correspond to thermal cooling states
+
+Example:
+	fan0: rpi-poe-fan@0 {
+		compatible = "raspberrypi,rpi-poe-fan";
+		firmware = <&firmware>;
+		cooling-min-state = <0>;
+		cooling-max-state = <3>;
+		#cooling-cells = <2>;
+		cooling-levels = <0 50 150 255>;
+		status = "okay";
+	};
+
+	thermal-zones {
+		cpu_thermal: cpu-thermal {
+			trips {
+				threshold: trip-point@0 {
+					temperature = <45000>;
+					hysteresis = <5000>;
+					type = "active";
+				};
+				target: trip-point@1 {
+					temperature = <50000>;
+					hysteresis = <2000>;
+					type = "active";
+				};
+				cpu_hot: cpu_hot@0 {
+					temperature = <55000>;
+					hysteresis = <2000>;
+					type = "active";
+				};
+			};
+			cooling-maps {
+				map0 {
+					trip = <&threshold>;
+					cooling-device = <&fan0 0 1>;
+				};
+				map1 {
+					trip = <&target>;
+					cooling-device = <&fan0 1 2>;
+				};
+				map2 {
+					trip = <&cpu_hot>;
+					cooling-device = <&fan0 2 3>;
+				};
+			};
+		};
+	};
--- /dev/null
+++ b/Documentation/hwmon/rpi-poe-fan
@@ -0,0 +1,15 @@
+Kernel driver rpi-poe-fan
+=====================
+
+This driver enables the use of the Raspberry Pi PoE HAT fan.
+
+Author: Serge Schneider <serge@raspberrypi.org>
+
+Description
+-----------
+
+The driver implements a simple interface for driving the Raspberry Pi PoE
+(Power over Ethernet) HAT fan. The driver passes commands to the Raspberry Pi
+firmware through the mailbox property interface. The firmware then forwards
+the commands to the board over I2C on the ID_EEPROM pins. The driver exposes
+the fan to the user space through the hwmon sysfs interface.
--- a/arch/arm/boot/dts/overlays/rpi-poe-overlay.dts
+++ b/arch/arm/boot/dts/overlays/rpi-poe-overlay.dts
@@ -11,7 +11,7 @@
 		target-path = "/";
 		__overlay__ {
 			fan0: rpi-poe-fan@0 {
-				compatible = "rpi-poe-fan";
+				compatible = "raspberrypi,rpi-poe-fan";
 				firmware = <&firmware>;
 				cooling-min-state = <0>;
 				cooling-max-state = <3>;
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1287,11 +1287,12 @@ config SENSORS_PWM_FAN
 	  will be called pwm-fan.
 
 config SENSORS_RPI_POE_FAN
-	tristate "Raspberry Pi POE HAT fan"
+	tristate "Raspberry Pi PoE HAT fan"
 	depends on RASPBERRYPI_FIRMWARE
 	depends on THERMAL || THERMAL=n
 	help
-	  If you say yes here you get support for Raspberry Pi POE HAT fan.
+	  If you say yes here you get support for Raspberry Pi PoE (Power over
+	  Ethernet) HAT fan.
 
 	  This driver can also be built as a module.  If so, the module
 	  will be called rpi-poe-fan.
--- a/drivers/hwmon/rpi-poe-fan.c
+++ b/drivers/hwmon/rpi-poe-fan.c
@@ -1,20 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
- * rpi-poe-fan.c - Hwmon driver for Raspberry Pi POE HAT fan.
+ * rpi-poe-fan.c - Hwmon driver for Raspberry Pi PoE HAT fan.
  *
  * Copyright (C) 2018 Raspberry Pi (Trading) Ltd.
  * Based on pwm-fan.c by Kamil Debski <k.debski@samsung.com>
  *
  * Author: Serge Schneider <serge@raspberrypi.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
  */
 
 #include <linux/hwmon.h>
@@ -46,41 +37,41 @@ struct rpi_poe_fan_ctx {
 	struct notifier_block nb;
 };
 
-struct m_data_s{
+struct fw_tag_data_s{
 	u32 reg;
 	u32 val;
 	u32 ret;
 };
 
 static int write_reg(struct rpi_firmware *fw, u32 reg, u32 *val){
-	struct m_data_s m_data = {
+	struct fw_tag_data_s fw_tag_data = {
 		.reg = reg,
 		.val = *val
 	};
 	int ret;
 	ret = rpi_firmware_property(fw, RPI_FIRMWARE_SET_POE_HAT_VAL,
-				    &m_data, sizeof(m_data));
+				    &fw_tag_data, sizeof(fw_tag_data));
 	if (ret) {
 		return ret;
-	} else if (m_data.ret) {
+	} else if (fw_tag_data.ret) {
 		return -EIO;
 	}
 	return 0;
 }
 
 static int read_reg(struct rpi_firmware *fw, u32 reg, u32 *val){
-	struct m_data_s m_data = {
+	struct fw_tag_data_s fw_tag_data = {
 		.reg = reg,
 	};
 	int ret;
 	ret = rpi_firmware_property(fw, RPI_FIRMWARE_GET_POE_HAT_VAL,
-				    &m_data, sizeof(m_data));
+				    &fw_tag_data, sizeof(fw_tag_data));
 	if (ret) {
 		return ret;
-	} else if (m_data.ret) {
+	} else if (fw_tag_data.ret) {
 		return -EIO;
 	}
-	*val = m_data.val;
+	*val = fw_tag_data.val;
 	return 0;
 }
 
@@ -268,7 +259,8 @@ static int rpi_poe_fan_of_get_cooling_da
 
 	ret = of_property_count_u32_elems(np, "cooling-levels");
 	if (ret <= 0) {
-		dev_err(dev, "Wrong data!\n");
+		dev_err(dev, "cooling-levels property missing or invalid: %d\n",
+			ret);
 		return ret ? : -EINVAL;
 	}
 
@@ -397,10 +389,11 @@ static int rpi_poe_fan_suspend(struct de
 {
 	struct rpi_poe_fan_ctx *ctx = dev_get_drvdata(dev);
 	u32 value = 0;
+	int ret = 0;
 
 	if (ctx->pwm_value != value)
 		ret = write_reg(ctx->fw, POE_CUR_PWM, &value);
-	return 0;
+	return ret;
 }
 
 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_resume);
 
 static const struct of_device_id of_rpi_poe_fan_match[] = {
-	{ .compatible = "rpi-poe-fan", },
+	{ .compatible = "raspberrypi,rpi-poe-fan", },
 	{},
 };
 MODULE_DEVICE_TABLE(of, of_rpi_poe_fan_match);
@@ -439,5 +432,5 @@ module_platform_driver(rpi_poe_fan_drive
 
 MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
 MODULE_ALIAS("platform:rpi-poe-fan");
-MODULE_DESCRIPTION("Raspberry Pi POE HAT fan driver");
+MODULE_DESCRIPTION("Raspberry Pi PoE HAT fan driver");
 MODULE_LICENSE("GPL");