forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/platform/x86/acerhdf.c
....@@ -1,10 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * acerhdf - A driver which monitors the temperature
34 * of the aspire one netbook, turns on/off the fan
45 * as soon as the upper/lower threshold is reached.
56 *
6
- * (C) 2009 - Peter Feuerer peter (a) piie.net
7
- * http://piie.net
7
+ * (C) 2009 - Peter Kaestle peter (a) piie.net
8
+ * https://piie.net
89 * 2009 Borislav Petkov bp (a) alien8.de
910 *
1011 * Inspired by and many thanks to:
....@@ -15,20 +16,6 @@
1516 * o lkml - Matthew Garrett
1617 * - Borislav Petkov
1718 * - Andreas Mohr
18
- *
19
- * This program is free software; you can redistribute it and/or modify
20
- * it under the terms of the GNU General Public License as published by
21
- * the Free Software Foundation; either version 2 of the License, or
22
- * (at your option) any later version.
23
- *
24
- * This program is distributed in the hope that it will be useful,
25
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
- * GNU General Public License for more details.
28
- *
29
- * You should have received a copy of the GNU General Public License
30
- * along with this program; if not, write to the Free Software
31
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3219 */
3320
3421 #define pr_fmt(fmt) "acerhdf: " fmt
....@@ -86,6 +73,7 @@
8673 static unsigned int fanon = 60000;
8774 static unsigned int fanoff = 53000;
8875 static unsigned int verbose;
76
+static unsigned int list_supported;
8977 static unsigned int fanstate = ACERHDF_FAN_AUTO;
9078 static char force_bios[16];
9179 static char force_product[16];
....@@ -104,10 +92,12 @@
10492 MODULE_PARM_DESC(fanoff, "Turn the fan off below this temperature");
10593 module_param(verbose, uint, 0600);
10694 MODULE_PARM_DESC(verbose, "Enable verbose dmesg output");
95
+module_param(list_supported, uint, 0600);
96
+MODULE_PARM_DESC(list_supported, "List supported models and BIOS versions");
10797 module_param_string(force_bios, force_bios, 16, 0);
108
-MODULE_PARM_DESC(force_bios, "Force BIOS version and omit BIOS check");
98
+MODULE_PARM_DESC(force_bios, "Pretend system has this known supported BIOS version");
10999 module_param_string(force_product, force_product, 16, 0);
110
-MODULE_PARM_DESC(force_product, "Force BIOS product and omit BIOS check");
100
+MODULE_PARM_DESC(force_product, "Pretend system is this known supported model");
111101
112102 /*
113103 * cmd_off: to switch the fan completely off and check if the fan is off
....@@ -130,7 +120,7 @@
130120 .moff = 0xff,
131121 };
132122
133
-/* BIOS settings */
123
+/* BIOS settings - only used during probe */
134124 struct bios_settings {
135125 const char *vendor;
136126 const char *product;
....@@ -141,8 +131,18 @@
141131 int mcmd_enable;
142132 };
143133
134
+/* This could be a daughter struct in the above, but not worth the redirect */
135
+struct ctrl_settings {
136
+ u8 fanreg;
137
+ u8 tempreg;
138
+ struct fancmd cmd;
139
+ int mcmd_enable;
140
+};
141
+
142
+static struct ctrl_settings ctrl_cfg __read_mostly;
143
+
144144 /* Register addresses and values for different BIOS versions */
145
-static const struct bios_settings bios_tbl[] = {
145
+static const struct bios_settings bios_tbl[] __initconst = {
146146 /* AOA110 */
147147 {"Acer", "AOA110", "v0.3109", 0x55, 0x58, {0x1f, 0x00}, 0},
148148 {"Acer", "AOA110", "v0.3114", 0x55, 0x58, {0x1f, 0x00}, 0},
....@@ -224,6 +224,8 @@
224224 {"Acer", "Aspire 5739G", "V1.3311", 0x55, 0x58, {0x20, 0x00}, 0},
225225 /* Acer TravelMate 7730 */
226226 {"Acer", "TravelMate 7730G", "v0.3509", 0x55, 0x58, {0xaf, 0x00}, 0},
227
+ /* Acer Aspire 7551 */
228
+ {"Acer", "Aspire 7551", "V1.18", 0x93, 0xa8, {0x14, 0x04}, 1},
227229 /* Acer TravelMate TM8573T */
228230 {"Acer", "TM8573T", "V1.13", 0x93, 0xa8, {0x14, 0x04}, 1},
229231 /* Gateway */
....@@ -257,8 +259,6 @@
257259 {"", "", "", 0, 0, {0, 0}, 0}
258260 };
259261
260
-static const struct bios_settings *bios_cfg __read_mostly;
261
-
262262 /*
263263 * this struct is used to instruct thermal layer to use bang_bang instead of
264264 * default governor for acerhdf
....@@ -271,7 +271,7 @@
271271 {
272272 u8 read_temp;
273273
274
- if (ec_read(bios_cfg->tempreg, &read_temp))
274
+ if (ec_read(ctrl_cfg.tempreg, &read_temp))
275275 return -EINVAL;
276276
277277 *temp = read_temp * 1000;
....@@ -283,10 +283,10 @@
283283 {
284284 u8 fan;
285285
286
- if (ec_read(bios_cfg->fanreg, &fan))
286
+ if (ec_read(ctrl_cfg.fanreg, &fan))
287287 return -EINVAL;
288288
289
- if (fan != bios_cfg->cmd.cmd_off)
289
+ if (fan != ctrl_cfg.cmd.cmd_off)
290290 *state = ACERHDF_FAN_AUTO;
291291 else
292292 *state = ACERHDF_FAN_OFF;
....@@ -307,13 +307,13 @@
307307 state = ACERHDF_FAN_AUTO;
308308 }
309309
310
- cmd = (state == ACERHDF_FAN_OFF) ? bios_cfg->cmd.cmd_off
311
- : bios_cfg->cmd.cmd_auto;
310
+ cmd = (state == ACERHDF_FAN_OFF) ? ctrl_cfg.cmd.cmd_off
311
+ : ctrl_cfg.cmd.cmd_auto;
312312 fanstate = state;
313313
314
- ec_write(bios_cfg->fanreg, cmd);
314
+ ec_write(ctrl_cfg.fanreg, cmd);
315315
316
- if (bios_cfg->mcmd_enable && state == ACERHDF_FAN_OFF) {
316
+ if (ctrl_cfg.mcmd_enable && state == ACERHDF_FAN_OFF) {
317317 if (verbose)
318318 pr_notice("turning off fan manually\n");
319319 ec_write(mcmd.mreg, mcmd.moff);
....@@ -397,29 +397,14 @@
397397 {
398398 acerhdf_change_fanstate(ACERHDF_FAN_AUTO);
399399 kernelmode = 0;
400
- if (thz_dev)
401
- thz_dev->polling_delay = 0;
400
+
402401 pr_notice("kernel mode fan control OFF\n");
403402 }
404403 static inline void acerhdf_enable_kernelmode(void)
405404 {
406405 kernelmode = 1;
407406
408
- thz_dev->polling_delay = interval*1000;
409
- thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED);
410407 pr_notice("kernel mode fan control ON\n");
411
-}
412
-
413
-static int acerhdf_get_mode(struct thermal_zone_device *thermal,
414
- enum thermal_device_mode *mode)
415
-{
416
- if (verbose)
417
- pr_notice("kernel mode fan control %d\n", kernelmode);
418
-
419
- *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED
420
- : THERMAL_DEVICE_DISABLED;
421
-
422
- return 0;
423408 }
424409
425410 /*
....@@ -428,8 +413,8 @@
428413 * the temperature and the fan.
429414 * disabled: the BIOS takes control of the fan.
430415 */
431
-static int acerhdf_set_mode(struct thermal_zone_device *thermal,
432
- enum thermal_device_mode mode)
416
+static int acerhdf_change_mode(struct thermal_zone_device *thermal,
417
+ enum thermal_device_mode mode)
433418 {
434419 if (mode == THERMAL_DEVICE_DISABLED && kernelmode)
435420 acerhdf_revert_to_bios_mode();
....@@ -488,8 +473,7 @@
488473 .bind = acerhdf_bind,
489474 .unbind = acerhdf_unbind,
490475 .get_temp = acerhdf_get_ec_temp,
491
- .get_mode = acerhdf_get_mode,
492
- .set_mode = acerhdf_set_mode,
476
+ .change_mode = acerhdf_change_mode,
493477 .get_trip_type = acerhdf_get_trip_type,
494478 .get_trip_hyst = acerhdf_get_trip_hyst,
495479 .get_trip_temp = acerhdf_get_trip_temp,
....@@ -616,10 +600,11 @@
616600 }
617601
618602 /* check hardware */
619
-static int acerhdf_check_hardware(void)
603
+static int __init acerhdf_check_hardware(void)
620604 {
621605 char const *vendor, *version, *product;
622606 const struct bios_settings *bt = NULL;
607
+ int found = 0;
623608
624609 /* get BIOS data */
625610 vendor = dmi_get_system_info(DMI_SYS_VENDOR);
....@@ -632,6 +617,17 @@
632617 }
633618
634619 pr_info("Acer Aspire One Fan driver, v.%s\n", DRV_VER);
620
+
621
+ if (list_supported) {
622
+ pr_info("List of supported Manufacturer/Model/BIOS:\n");
623
+ pr_info("---------------------------------------------------\n");
624
+ for (bt = bios_tbl; bt->vendor[0]; bt++) {
625
+ pr_info("%-13s | %-17s | %-10s\n", bt->vendor,
626
+ bt->product, bt->version);
627
+ }
628
+ pr_info("---------------------------------------------------\n");
629
+ return -ECANCELED;
630
+ }
635631
636632 if (force_bios[0]) {
637633 version = force_bios;
....@@ -658,16 +654,22 @@
658654 if (str_starts_with(vendor, bt->vendor) &&
659655 str_starts_with(product, bt->product) &&
660656 str_starts_with(version, bt->version)) {
661
- bios_cfg = bt;
657
+ found = 1;
662658 break;
663659 }
664660 }
665661
666
- if (!bios_cfg) {
662
+ if (!found) {
667663 pr_err("unknown (unsupported) BIOS version %s/%s/%s, please report, aborting!\n",
668664 vendor, product, version);
669665 return -EINVAL;
670666 }
667
+
668
+ /* Copy control settings from BIOS table before we free it. */
669
+ ctrl_cfg.fanreg = bt->fanreg;
670
+ ctrl_cfg.tempreg = bt->tempreg;
671
+ memcpy(&ctrl_cfg.cmd, &bt->cmd, sizeof(struct fancmd));
672
+ ctrl_cfg.mcmd_enable = bt->mcmd_enable;
671673
672674 /*
673675 * if started with kernel mode off, prevent the kernel from switching
....@@ -675,13 +677,13 @@
675677 */
676678 if (!kernelmode) {
677679 pr_notice("Fan control off, to enable do:\n");
678
- pr_notice("echo -n \"enabled\" > /sys/class/thermal/thermal_zone0/mode\n");
680
+ pr_notice("echo -n \"enabled\" > /sys/class/thermal/thermal_zoneN/mode # N=0,1,2...\n");
679681 }
680682
681683 return 0;
682684 }
683685
684
-static int acerhdf_register_platform(void)
686
+static int __init acerhdf_register_platform(void)
685687 {
686688 int err = 0;
687689
....@@ -713,8 +715,10 @@
713715 platform_driver_unregister(&acerhdf_driver);
714716 }
715717
716
-static int acerhdf_register_thermal(void)
718
+static int __init acerhdf_register_thermal(void)
717719 {
720
+ int ret;
721
+
718722 cl_dev = thermal_cooling_device_register("acerhdf-fan", NULL,
719723 &acerhdf_cooling_ops);
720724
....@@ -727,6 +731,13 @@
727731 (kernelmode) ? interval*1000 : 0);
728732 if (IS_ERR(thz_dev))
729733 return -EINVAL;
734
+
735
+ if (kernelmode)
736
+ ret = thermal_zone_device_enable(thz_dev);
737
+ else
738
+ ret = thermal_zone_device_disable(thz_dev);
739
+ if (ret)
740
+ return ret;
730741
731742 if (strcmp(thz_dev->governor->name,
732743 acerhdf_zone_params.governor_name)) {
....@@ -785,7 +796,7 @@
785796 }
786797
787798 MODULE_LICENSE("GPL");
788
-MODULE_AUTHOR("Peter Feuerer");
799
+MODULE_AUTHOR("Peter Kaestle");
789800 MODULE_DESCRIPTION("Aspire One temperature and fan driver");
790801 MODULE_ALIAS("dmi:*:*Acer*:pnAOA*:");
791802 MODULE_ALIAS("dmi:*:*Acer*:pnAO751h*:");
....@@ -799,6 +810,7 @@
799810 MODULE_ALIAS("dmi:*:*Acer*:pnAspire*One*753:");
800811 MODULE_ALIAS("dmi:*:*Acer*:pnAspire*5315:");
801812 MODULE_ALIAS("dmi:*:*Acer*:TravelMate*7730G:");
813
+MODULE_ALIAS("dmi:*:*Acer*:pnAspire*7551:");
802814 MODULE_ALIAS("dmi:*:*Acer*:TM8573T:");
803815 MODULE_ALIAS("dmi:*:*Gateway*:pnAOA*:");
804816 MODULE_ALIAS("dmi:*:*Gateway*:pnLT31*:");
....@@ -808,7 +820,7 @@
808820 MODULE_ALIAS("dmi:*:*Packard*Bell*:pnENBFT*:");
809821 MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTMA*:");
810822 MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTVR46*:");
811
-MODULE_ALIAS("dmi:*:*Acer*:pnExtensa 5420*:");
823
+MODULE_ALIAS("dmi:*:*Acer*:pnExtensa*5420*:");
812824
813825 module_init(acerhdf_init);
814826 module_exit(acerhdf_exit);