Skip to content

Commit 00ae053

Browse files
spandruvadarafaeljw
authored andcommitted
ACPI: fan: Separate file for attributes creation
Move the functionality of creation of sysfs attributes under acpi device to a new file fan_attr.c. This cleans up the core fan code, which just use thermal sysfs interface. The original fan.c is renamed to fan_core.c. No functional changes are expected. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 9ddb00a commit 00ae053

4 files changed

Lines changed: 133 additions & 89 deletions

File tree

drivers/acpi/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ obj-$(CONFIG_ACPI_AC) += ac.o
8181
obj-$(CONFIG_ACPI_BUTTON) += button.o
8282
obj-$(CONFIG_ACPI_TINY_POWER_BUTTON) += tiny-power-button.o
8383
obj-$(CONFIG_ACPI_FAN) += fan.o
84+
fan-objs := fan_core.o
85+
fan-objs += fan_attr.o
86+
8487
obj-$(CONFIG_ACPI_VIDEO) += video.o
8588
obj-$(CONFIG_ACPI_TAD) += acpi_tad.o
8689
obj-$(CONFIG_ACPI_PCI_SLOT) += pci_slot.o

drivers/acpi/fan.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,44 @@
66
*
77
* Add new device IDs before the generic ACPI fan one.
88
*/
9+
10+
#ifndef _ACPI_FAN_H_
11+
#define _ACPI_FAN_H_
12+
913
#define ACPI_FAN_DEVICE_IDS \
1014
{"INT3404", }, /* Fan */ \
1115
{"INTC1044", }, /* Fan for Tiger Lake generation */ \
1216
{"INTC1048", }, /* Fan for Alder Lake generation */ \
1317
{"INTC10A2", }, /* Fan for Raptor Lake generation */ \
1418
{"PNP0C0B", } /* Generic ACPI fan */
19+
20+
#define ACPI_FPS_NAME_LEN 20
21+
22+
struct acpi_fan_fps {
23+
u64 control;
24+
u64 trip_point;
25+
u64 speed;
26+
u64 noise_level;
27+
u64 power;
28+
char name[ACPI_FPS_NAME_LEN];
29+
struct device_attribute dev_attr;
30+
};
31+
32+
struct acpi_fan_fif {
33+
u64 revision;
34+
u64 fine_grain_ctrl;
35+
u64 step_size;
36+
u64 low_speed_notification;
37+
};
38+
39+
struct acpi_fan {
40+
bool acpi4;
41+
struct acpi_fan_fif fif;
42+
struct acpi_fan_fps *fps;
43+
int fps_count;
44+
struct thermal_cooling_device *cdev;
45+
};
46+
47+
int acpi_fan_create_attributes(struct acpi_device *device);
48+
void acpi_fan_delete_attributes(struct acpi_device *device);
49+
#endif

drivers/acpi/fan_attr.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* fan_attr.c - Create extra attributes for ACPI Fan driver
4+
*
5+
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6+
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7+
* Copyright (C) 2022 Intel Corporation. All rights reserved.
8+
*/
9+
10+
#include <linux/kernel.h>
11+
#include <linux/module.h>
12+
#include <linux/init.h>
13+
#include <linux/acpi.h>
14+
15+
#include "fan.h"
16+
17+
MODULE_LICENSE("GPL");
18+
19+
static ssize_t show_state(struct device *dev, struct device_attribute *attr, char *buf)
20+
{
21+
struct acpi_fan_fps *fps = container_of(attr, struct acpi_fan_fps, dev_attr);
22+
int count;
23+
24+
if (fps->control == 0xFFFFFFFF || fps->control > 100)
25+
count = scnprintf(buf, PAGE_SIZE, "not-defined:");
26+
else
27+
count = scnprintf(buf, PAGE_SIZE, "%lld:", fps->control);
28+
29+
if (fps->trip_point == 0xFFFFFFFF || fps->trip_point > 9)
30+
count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
31+
else
32+
count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->trip_point);
33+
34+
if (fps->speed == 0xFFFFFFFF)
35+
count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
36+
else
37+
count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->speed);
38+
39+
if (fps->noise_level == 0xFFFFFFFF)
40+
count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
41+
else
42+
count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->noise_level * 100);
43+
44+
if (fps->power == 0xFFFFFFFF)
45+
count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined\n");
46+
else
47+
count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld\n", fps->power);
48+
49+
return count;
50+
}
51+
52+
int acpi_fan_create_attributes(struct acpi_device *device)
53+
{
54+
struct acpi_fan *fan = acpi_driver_data(device);
55+
int i, status = 0;
56+
57+
for (i = 0; i < fan->fps_count; ++i) {
58+
struct acpi_fan_fps *fps = &fan->fps[i];
59+
60+
snprintf(fps->name, ACPI_FPS_NAME_LEN, "state%d", i);
61+
sysfs_attr_init(&fps->dev_attr.attr);
62+
fps->dev_attr.show = show_state;
63+
fps->dev_attr.store = NULL;
64+
fps->dev_attr.attr.name = fps->name;
65+
fps->dev_attr.attr.mode = 0444;
66+
status = sysfs_create_file(&device->dev.kobj, &fps->dev_attr.attr);
67+
if (status) {
68+
int j;
69+
70+
for (j = 0; j < i; ++j)
71+
sysfs_remove_file(&device->dev.kobj, &fan->fps[j].dev_attr.attr);
72+
break;
73+
}
74+
}
75+
76+
return status;
77+
}
78+
79+
void acpi_fan_delete_attributes(struct acpi_device *device)
80+
{
81+
struct acpi_fan *fan = acpi_driver_data(device);
82+
int i;
83+
84+
for (i = 0; i < fan->fps_count; ++i)
85+
sysfs_remove_file(&device->dev.kobj, &fan->fps[i].dev_attr.attr);
86+
}
Lines changed: 9 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
/*
3-
* acpi_fan.c - ACPI Fan Driver ($Revision: 29 $)
3+
* fan_core.c - ACPI Fan core Driver
44
*
55
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
66
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7+
* Copyright (C) 2022 Intel Corporation. All rights reserved.
78
*/
89

910
#include <linux/kernel.h>
@@ -45,33 +46,6 @@ static const struct dev_pm_ops acpi_fan_pm = {
4546
#define FAN_PM_OPS_PTR NULL
4647
#endif
4748

48-
#define ACPI_FPS_NAME_LEN 20
49-
50-
struct acpi_fan_fps {
51-
u64 control;
52-
u64 trip_point;
53-
u64 speed;
54-
u64 noise_level;
55-
u64 power;
56-
char name[ACPI_FPS_NAME_LEN];
57-
struct device_attribute dev_attr;
58-
};
59-
60-
struct acpi_fan_fif {
61-
u64 revision;
62-
u64 fine_grain_ctrl;
63-
u64 step_size;
64-
u64 low_speed_notification;
65-
};
66-
67-
struct acpi_fan {
68-
bool acpi4;
69-
struct acpi_fan_fif fif;
70-
struct acpi_fan_fps *fps;
71-
int fps_count;
72-
struct thermal_cooling_device *cdev;
73-
};
74-
7549
static struct platform_driver acpi_fan_driver = {
7650
.probe = acpi_fan_probe,
7751
.remove = acpi_fan_remove,
@@ -270,39 +244,6 @@ static int acpi_fan_speed_cmp(const void *a, const void *b)
270244
return fps1->speed - fps2->speed;
271245
}
272246

273-
static ssize_t show_state(struct device *dev, struct device_attribute *attr, char *buf)
274-
{
275-
struct acpi_fan_fps *fps = container_of(attr, struct acpi_fan_fps, dev_attr);
276-
int count;
277-
278-
if (fps->control == 0xFFFFFFFF || fps->control > 100)
279-
count = scnprintf(buf, PAGE_SIZE, "not-defined:");
280-
else
281-
count = scnprintf(buf, PAGE_SIZE, "%lld:", fps->control);
282-
283-
if (fps->trip_point == 0xFFFFFFFF || fps->trip_point > 9)
284-
count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
285-
else
286-
count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->trip_point);
287-
288-
if (fps->speed == 0xFFFFFFFF)
289-
count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
290-
else
291-
count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->speed);
292-
293-
if (fps->noise_level == 0xFFFFFFFF)
294-
count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
295-
else
296-
count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->noise_level * 100);
297-
298-
if (fps->power == 0xFFFFFFFF)
299-
count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined\n");
300-
else
301-
count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld\n", fps->power);
302-
303-
return count;
304-
}
305-
306247
static int acpi_fan_get_fps(struct acpi_device *device)
307248
{
308249
struct acpi_fan *fan = acpi_driver_data(device);
@@ -347,25 +288,6 @@ static int acpi_fan_get_fps(struct acpi_device *device)
347288
sort(fan->fps, fan->fps_count, sizeof(*fan->fps),
348289
acpi_fan_speed_cmp, NULL);
349290

350-
for (i = 0; i < fan->fps_count; ++i) {
351-
struct acpi_fan_fps *fps = &fan->fps[i];
352-
353-
snprintf(fps->name, ACPI_FPS_NAME_LEN, "state%d", i);
354-
sysfs_attr_init(&fps->dev_attr.attr);
355-
fps->dev_attr.show = show_state;
356-
fps->dev_attr.store = NULL;
357-
fps->dev_attr.attr.name = fps->name;
358-
fps->dev_attr.attr.mode = 0444;
359-
status = sysfs_create_file(&device->dev.kobj, &fps->dev_attr.attr);
360-
if (status) {
361-
int j;
362-
363-
for (j = 0; j < i; ++j)
364-
sysfs_remove_file(&device->dev.kobj, &fan->fps[j].dev_attr.attr);
365-
break;
366-
}
367-
}
368-
369291
err:
370292
kfree(obj);
371293
return status;
@@ -396,6 +318,10 @@ static int acpi_fan_probe(struct platform_device *pdev)
396318
if (result)
397319
return result;
398320

321+
result = acpi_fan_create_attributes(device);
322+
if (result)
323+
return result;
324+
399325
fan->acpi4 = true;
400326
} else {
401327
result = acpi_device_update_power(device, NULL);
@@ -437,12 +363,8 @@ static int acpi_fan_probe(struct platform_device *pdev)
437363
return 0;
438364

439365
err_end:
440-
if (fan->acpi4) {
441-
int i;
442-
443-
for (i = 0; i < fan->fps_count; ++i)
444-
sysfs_remove_file(&device->dev.kobj, &fan->fps[i].dev_attr.attr);
445-
}
366+
if (fan->acpi4)
367+
acpi_fan_delete_attributes(device);
446368

447369
return result;
448370
}
@@ -453,10 +375,8 @@ static int acpi_fan_remove(struct platform_device *pdev)
453375

454376
if (fan->acpi4) {
455377
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
456-
int i;
457378

458-
for (i = 0; i < fan->fps_count; ++i)
459-
sysfs_remove_file(&device->dev.kobj, &fan->fps[i].dev_attr.attr);
379+
acpi_fan_delete_attributes(device);
460380
}
461381
sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling");
462382
sysfs_remove_link(&fan->cdev->device.kobj, "device");

0 commit comments

Comments
 (0)