Skip to content

Commit 3ab20d1

Browse files
committed
Cleanup.
1 parent 8cabdc8 commit 3ab20d1

File tree

1 file changed

+23
-40
lines changed

1 file changed

+23
-40
lines changed

drivers/platform/surface/surface_fan.c

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
#include <linux/acpi.h>
9-
109
#include <linux/hwmon.h>
1110
#include <linux/kernel.h>
1211
#include <linux/module.h>
@@ -21,16 +20,13 @@
2120
// It both sets up as a cooling device through the thermal cooling device as
2221
// well as a hwmon fan for monitoring.
2322

24-
// Min fan speed is 2000, max is roughly 7140.
25-
26-
// https://docs.kernel.org/driver-api/surface_aggregator/client.html
27-
// https://docs.kernel.org/driver-api/thermal/sysfs-api.html
28-
// https://docs.kernel.org/hwmon/sysfs-interface.html
29-
3023
// This driver can change the fan speed, but only while the onboard controller
3124
// is not overriding it. At about 40 degrees celsius that takes over and over
3225
// writes whatever setpoint was given.
3326

27+
#define SURFACE_FAN_MIN_SPEED 2000
28+
#define SURFACE_FAN_MAX_SPEED 8000
29+
3430
struct fan_data {
3531
struct device *dev;
3632
struct ssam_controller *ctrl;
@@ -63,32 +59,31 @@ static const struct acpi_device_id surface_fan_match[] = {
6359
MODULE_DEVICE_TABLE(acpi, surface_fan_match);
6460

6561

66-
6762
// Thermal cooling device
68-
static int surface_fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
63+
static int surface_fan_set_cur_state(struct thermal_cooling_device *cdev,
64+
unsigned long state)
6965
{
7066
__le16 value;
7167
struct fan_data *d = cdev->devdata;
7268
value = cpu_to_le16(clamp(state, 0lu, (1lu << 16)));
73-
printk(KERN_INFO "surface_fan_set_cur_state: %lu\n", state);
7469
return __ssam_fan_set(d->ctrl, &value);
7570
}
7671

77-
static int surface_fan_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state)
72+
static int surface_fan_get_cur_state(struct thermal_cooling_device *cdev,
73+
unsigned long *state)
7874
{
7975
int res;
80-
printk(KERN_INFO "surface_fan_get_cur_state.\n");
8176
struct fan_data *d = cdev->devdata;
8277
__le16 value = 0;
8378
res = __ssam_fan_get(d->ctrl, &value);
8479
*state = le16_to_cpu(value);
8580
return res;
8681
}
8782

88-
static int surface_fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state)
83+
static int surface_fan_get_max_state(struct thermal_cooling_device *cdev,
84+
unsigned long *state)
8985
{
90-
printk(KERN_INFO "surface_fan_get_max_state.\n");
91-
*state = 7200; // My fan tops out at like 7140.
86+
*state = SURFACE_FAN_MAX_SPEED;
9287
return 0;
9388
}
9489

@@ -100,8 +95,9 @@ static const struct thermal_cooling_device_ops surface_fan_cooling_ops = {
10095

10196

10297
// hwmon
103-
umode_t surface_fan_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type,
104-
u32 attr, int channel) {
98+
umode_t surface_fan_hwmon_is_visible(const void *drvdata,
99+
enum hwmon_sensor_types type,
100+
u32 attr, int channel) {
105101
switch (type) {
106102
case hwmon_fan:
107103
switch (attr) {
@@ -121,8 +117,9 @@ umode_t surface_fan_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_type
121117
return 0;
122118
}
123119

124-
static int surface_fan_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
125-
long *val)
120+
static int surface_fan_hwmon_read(struct device *dev,
121+
enum hwmon_sensor_types type,
122+
u32 attr, int channel, long *val)
126123
{
127124
struct fan_data *data = dev_get_drvdata(dev);
128125
__le16 value;
@@ -139,10 +136,10 @@ static int surface_fan_hwmon_read(struct device *dev, enum hwmon_sensor_types ty
139136
*val = le16_to_cpu(value);
140137
return 0;
141138
case hwmon_fan_min:
142-
*val = 2000;
139+
*val = SURFACE_FAN_MIN_SPEED;
143140
return 0;
144141
case hwmon_fan_max:
145-
*val = 7200;
142+
*val = SURFACE_FAN_MAX_SPEED;
146143
return 0;
147144
case hwmon_fan_target:
148145
// No known way to retrieve the current setpoint.
@@ -160,8 +157,8 @@ static int surface_fan_hwmon_read(struct device *dev, enum hwmon_sensor_types ty
160157

161158

162159
static int surface_fan_hwmon_write(struct device *dev,
163-
enum hwmon_sensor_types type,
164-
u32 attr, int channel, long val)
160+
enum hwmon_sensor_types type,
161+
u32 attr, int channel, long val)
165162
{
166163
__le16 value;
167164
struct fan_data *data = dev_get_drvdata(dev);
@@ -214,10 +211,6 @@ static int surface_fan_probe(struct platform_device *pdev)
214211
__le16 value;
215212
int status;
216213

217-
218-
printk(KERN_INFO "probing register.\n");
219-
dev_dbg(&pdev->dev, "probing\n");
220-
221214
ctrl = ssam_client_bind(&pdev->dev);
222215
if (IS_ERR(ctrl))
223216
return PTR_ERR(ctrl) == -ENODEV ? -EPROBE_DEFER : PTR_ERR(ctrl);
@@ -226,7 +219,6 @@ static int surface_fan_probe(struct platform_device *pdev)
226219
// speed.
227220
status = __ssam_fan_get(ctrl, &value);
228221
if (status) {
229-
dev_err(&pdev->dev, "Failed to probe fan speed: %d\n", status);
230222
return -ENODEV;
231223
}
232224

@@ -237,15 +229,14 @@ static int surface_fan_probe(struct platform_device *pdev)
237229
cdev = thermal_cooling_device_register("Fan",
238230
data, &surface_fan_cooling_ops);
239231
if (IS_ERR(cdev))
240-
return PTR_ERR(cdev) == -ENODEV ? -EPROBE_DEFER : PTR_ERR(cdev);
232+
return PTR_ERR(cdev);
241233

242234

243235
hdev = devm_hwmon_device_register_with_info(&pdev->dev, "fan", data,
244236
&surface_fan_chip_info,
245237
NULL);
246238
if (IS_ERR(hdev)) {
247-
printk(KERN_INFO "hdev dregistration fail register.\n");
248-
return PTR_ERR(hdev) == -ENODEV ? -EPROBE_DEFER : PTR_ERR(hdev);
239+
return PTR_ERR(hdev);
249240
}
250241

251242
data->dev = &pdev->dev;
@@ -258,15 +249,13 @@ static int surface_fan_probe(struct platform_device *pdev)
258249
acpi_fan->driver_data = data;
259250
platform_set_drvdata(pdev, data);
260251

261-
printk(KERN_INFO "Yay.\n");
262252
return 0;
263253
}
264254

265255
static int surface_fan_remove(struct platform_device *pdev)
266256
{
267257
struct fan_data *d = platform_get_drvdata(pdev);
268258
thermal_cooling_device_unregister(d->cdev);
269-
dev_dbg(&pdev->dev, "remove\n");
270259
return 0;
271260
}
272261

@@ -283,22 +272,16 @@ static struct platform_driver surface_fan = {
283272

284273
static int __init surface_fan_init(void)
285274
{
286-
int ret;
287-
printk(KERN_INFO "Trying register.\n");
288-
ret = platform_driver_register(&surface_fan);
289-
printk(KERN_INFO "Ret: %d.\n", ret);
290-
return ret;
275+
return platform_driver_register(&surface_fan);
291276
}
292277
module_init(surface_fan_init);
293278

294279
static void __exit surface_fan_exit(void)
295280
{
296-
printk(KERN_INFO "Bye: .\n");
297281
platform_driver_unregister(&surface_fan);
298282
}
299283
module_exit(surface_fan_exit);
300284

301285
MODULE_AUTHOR("Ivor Wanders <ivor@iwanders.net>");
302286
MODULE_DESCRIPTION("Fan Driver for Surface System Aggregator Module");
303-
304287
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)