kernel: bump 4.14 to 4.14.93
[openwrt/staging/chunkeey.git] / target / linux / brcm2708 / patches-4.14 / 950-0412-PoE-HAT-driver-cleanup.patch
1 From 97a6a1f61eb949892457a739435fd5280fc800f8 Mon Sep 17 00:00:00 2001
2 From: XECDesign <XECDesign@users.noreply.github.com>
3 Date: Wed, 29 Aug 2018 15:08:30 +0100
4 Subject: [PATCH 412/454] PoE HAT driver cleanup
5
6 * Fix undeclared variable in rpi_poe_fan_suspend
7 * Add SPDX-License-Identifier
8 * Expand PoE acronym in Kconfig help
9 * Give clearer error message on of_property_count_u32_elems fail
10 * Add documentation
11 * Add vendor to of_device_id compatible string.
12 * Rename m_data_s struct to fw_data_s
13 * Fix typos
14
15 Fixes: #2665
16
17 Signed-off-by: Serge Schneider <serge@raspberrypi.org>
18 ---
19 .../devicetree/bindings/hwmon/rpi-poe-fan.txt | 55 +++++++++++++++++++
20 Documentation/hwmon/rpi-poe-fan | 15 +++++
21 .../arm/boot/dts/overlays/rpi-poe-overlay.dts | 2 +-
22 drivers/hwmon/Kconfig | 5 +-
23 drivers/hwmon/rpi-poe-fan.c | 39 ++++++-------
24 5 files changed, 90 insertions(+), 26 deletions(-)
25 create mode 100644 Documentation/devicetree/bindings/hwmon/rpi-poe-fan.txt
26 create mode 100644 Documentation/hwmon/rpi-poe-fan
27
28 --- /dev/null
29 +++ b/Documentation/devicetree/bindings/hwmon/rpi-poe-fan.txt
30 @@ -0,0 +1,55 @@
31 +Bindings for the Raspberry Pi PoE HAT fan
32 +
33 +Required properties:
34 +- compatible : "raspberrypi,rpi-poe-fan"
35 +- firmware : Reference to the RPi firmware device node
36 +- pwms : the PWM that is used to control the PWM fan
37 +- cooling-levels : PWM duty cycle values in a range from 0 to 255
38 + which correspond to thermal cooling states
39 +
40 +Example:
41 + fan0: rpi-poe-fan@0 {
42 + compatible = "raspberrypi,rpi-poe-fan";
43 + firmware = <&firmware>;
44 + cooling-min-state = <0>;
45 + cooling-max-state = <3>;
46 + #cooling-cells = <2>;
47 + cooling-levels = <0 50 150 255>;
48 + status = "okay";
49 + };
50 +
51 + thermal-zones {
52 + cpu_thermal: cpu-thermal {
53 + trips {
54 + threshold: trip-point@0 {
55 + temperature = <45000>;
56 + hysteresis = <5000>;
57 + type = "active";
58 + };
59 + target: trip-point@1 {
60 + temperature = <50000>;
61 + hysteresis = <2000>;
62 + type = "active";
63 + };
64 + cpu_hot: cpu_hot@0 {
65 + temperature = <55000>;
66 + hysteresis = <2000>;
67 + type = "active";
68 + };
69 + };
70 + cooling-maps {
71 + map0 {
72 + trip = <&threshold>;
73 + cooling-device = <&fan0 0 1>;
74 + };
75 + map1 {
76 + trip = <&target>;
77 + cooling-device = <&fan0 1 2>;
78 + };
79 + map2 {
80 + trip = <&cpu_hot>;
81 + cooling-device = <&fan0 2 3>;
82 + };
83 + };
84 + };
85 + };
86 --- /dev/null
87 +++ b/Documentation/hwmon/rpi-poe-fan
88 @@ -0,0 +1,15 @@
89 +Kernel driver rpi-poe-fan
90 +=====================
91 +
92 +This driver enables the use of the Raspberry Pi PoE HAT fan.
93 +
94 +Author: Serge Schneider <serge@raspberrypi.org>
95 +
96 +Description
97 +-----------
98 +
99 +The driver implements a simple interface for driving the Raspberry Pi PoE
100 +(Power over Ethernet) HAT fan. The driver passes commands to the Raspberry Pi
101 +firmware through the mailbox property interface. The firmware then forwards
102 +the commands to the board over I2C on the ID_EEPROM pins. The driver exposes
103 +the fan to the user space through the hwmon sysfs interface.
104 --- a/arch/arm/boot/dts/overlays/rpi-poe-overlay.dts
105 +++ b/arch/arm/boot/dts/overlays/rpi-poe-overlay.dts
106 @@ -11,7 +11,7 @@
107 target-path = "/";
108 __overlay__ {
109 fan0: rpi-poe-fan@0 {
110 - compatible = "rpi-poe-fan";
111 + compatible = "raspberrypi,rpi-poe-fan";
112 firmware = <&firmware>;
113 cooling-min-state = <0>;
114 cooling-max-state = <3>;
115 --- a/drivers/hwmon/Kconfig
116 +++ b/drivers/hwmon/Kconfig
117 @@ -1287,11 +1287,12 @@ config SENSORS_PWM_FAN
118 will be called pwm-fan.
119
120 config SENSORS_RPI_POE_FAN
121 - tristate "Raspberry Pi POE HAT fan"
122 + tristate "Raspberry Pi PoE HAT fan"
123 depends on RASPBERRYPI_FIRMWARE
124 depends on THERMAL || THERMAL=n
125 help
126 - If you say yes here you get support for Raspberry Pi POE HAT fan.
127 + If you say yes here you get support for Raspberry Pi PoE (Power over
128 + Ethernet) HAT fan.
129
130 This driver can also be built as a module. If so, the module
131 will be called rpi-poe-fan.
132 --- a/drivers/hwmon/rpi-poe-fan.c
133 +++ b/drivers/hwmon/rpi-poe-fan.c
134 @@ -1,20 +1,11 @@
135 +// SPDX-License-Identifier: GPL-2.0
136 /*
137 - * rpi-poe-fan.c - Hwmon driver for Raspberry Pi POE HAT fan.
138 + * rpi-poe-fan.c - Hwmon driver for Raspberry Pi PoE HAT fan.
139 *
140 * Copyright (C) 2018 Raspberry Pi (Trading) Ltd.
141 * Based on pwm-fan.c by Kamil Debski <k.debski@samsung.com>
142 *
143 * Author: Serge Schneider <serge@raspberrypi.org>
144 - *
145 - * This program is free software; you can redistribute it and/or modify
146 - * it under the terms of the GNU General Public License as published by
147 - * the Free Software Foundation; either version 2 of the License, or
148 - * (at your option) any later version.
149 - *
150 - * This program is distributed in the hope that it will be useful,
151 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
152 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
153 - * GNU General Public License for more details.
154 */
155
156 #include <linux/hwmon.h>
157 @@ -46,41 +37,41 @@ struct rpi_poe_fan_ctx {
158 struct notifier_block nb;
159 };
160
161 -struct m_data_s{
162 +struct fw_tag_data_s{
163 u32 reg;
164 u32 val;
165 u32 ret;
166 };
167
168 static int write_reg(struct rpi_firmware *fw, u32 reg, u32 *val){
169 - struct m_data_s m_data = {
170 + struct fw_tag_data_s fw_tag_data = {
171 .reg = reg,
172 .val = *val
173 };
174 int ret;
175 ret = rpi_firmware_property(fw, RPI_FIRMWARE_SET_POE_HAT_VAL,
176 - &m_data, sizeof(m_data));
177 + &fw_tag_data, sizeof(fw_tag_data));
178 if (ret) {
179 return ret;
180 - } else if (m_data.ret) {
181 + } else if (fw_tag_data.ret) {
182 return -EIO;
183 }
184 return 0;
185 }
186
187 static int read_reg(struct rpi_firmware *fw, u32 reg, u32 *val){
188 - struct m_data_s m_data = {
189 + struct fw_tag_data_s fw_tag_data = {
190 .reg = reg,
191 };
192 int ret;
193 ret = rpi_firmware_property(fw, RPI_FIRMWARE_GET_POE_HAT_VAL,
194 - &m_data, sizeof(m_data));
195 + &fw_tag_data, sizeof(fw_tag_data));
196 if (ret) {
197 return ret;
198 - } else if (m_data.ret) {
199 + } else if (fw_tag_data.ret) {
200 return -EIO;
201 }
202 - *val = m_data.val;
203 + *val = fw_tag_data.val;
204 return 0;
205 }
206
207 @@ -268,7 +259,8 @@ static int rpi_poe_fan_of_get_cooling_da
208
209 ret = of_property_count_u32_elems(np, "cooling-levels");
210 if (ret <= 0) {
211 - dev_err(dev, "Wrong data!\n");
212 + dev_err(dev, "cooling-levels property missing or invalid: %d\n",
213 + ret);
214 return ret ? : -EINVAL;
215 }
216
217 @@ -397,10 +389,11 @@ static int rpi_poe_fan_suspend(struct de
218 {
219 struct rpi_poe_fan_ctx *ctx = dev_get_drvdata(dev);
220 u32 value = 0;
221 + int ret = 0;
222
223 if (ctx->pwm_value != value)
224 ret = write_reg(ctx->fw, POE_CUR_PWM, &value);
225 - return 0;
226 + return ret;
227 }
228
229 static int rpi_poe_fan_resume(struct device *dev)
230 @@ -420,7 +413,7 @@ static SIMPLE_DEV_PM_OPS(rpi_poe_fan_pm,
231 rpi_poe_fan_resume);
232
233 static const struct of_device_id of_rpi_poe_fan_match[] = {
234 - { .compatible = "rpi-poe-fan", },
235 + { .compatible = "raspberrypi,rpi-poe-fan", },
236 {},
237 };
238 MODULE_DEVICE_TABLE(of, of_rpi_poe_fan_match);
239 @@ -439,5 +432,5 @@ module_platform_driver(rpi_poe_fan_drive
240
241 MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
242 MODULE_ALIAS("platform:rpi-poe-fan");
243 -MODULE_DESCRIPTION("Raspberry Pi POE HAT fan driver");
244 +MODULE_DESCRIPTION("Raspberry Pi PoE HAT fan driver");
245 MODULE_LICENSE("GPL");