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-
7549static 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-
306247static 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-
369291err :
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
439365err_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