platform/x86: panasonic-laptop: Add platform_profile support
Subsystems (3)
RFC PATCH v4 1/1 platform/x86: panasonic-laptop: Add platform_profile support
Expose firmware thermal and power management policies via the platform_profile interface.
Supported and tested models:
- CF-RZ6 (2016)
- CF-SV8 (2019)
- CF-QV9 (2020)
- CF-SR4 (2024)
Firmware fan operating mode and the TDP limit switch are mapped onto the Linux platform_profile ABI.
This implementation queries the firmware for every get(). CUSTOM is returned when the current state is not recognized. The set() callback writes the values regardless of what the current fan mode and TDP limit is.
- Introduce as separate platform_driver
- Used DEFINE for driver and platform_profile device name
- DMI quirks restrict support to tested models
- When raising TDP, fan mode is switched first
- When limiting TDP, TDP limit is applied first
- ACPI handle for the EC device was used as the EC path varies slightly between models.
- This device is optional: keep hotkey and everything already loaded if profile driver fails for any reason.
- Common fan/power settings are shared by a quirk_default struct to avoid duplication of similar structs.
---
v4:
- Consolidated separate quirk structs for the RZ6, QV9 and SV8 into a quirk_default struct.
v3: https://lore.kernel.org/platform-driver-x86/[email protected]/
- Removed sysfs.h import
- Refactored platform profile probe function to use a different pattern (check warn_on, continue on double unset, then set)
v2: https://lore.kernel.org/platform-driver-x86/[email protected]/
- Refactored code to use its own platform_driver
- Removed DEFINE_FREE and its corresponding __free as its addition
in this module is inappropriate
- Removed pr_fmt line as its addition to this patch is inappropriate
- Added DMI check during __init to prevent attempt of platform profile
device loading on unsupported hardware
- Fixed use of enums as truth values by adding explicit comparisons
- Added *profile_pdev to keep track of new platform_driver
- Removed extra spaces in the quirk definitions
- Added helper function for calling EC methods for simplicity
- Use ARRAY_SIZE() for for loops and added include for array_size.h
- Refactored pcc_profile to be a pointer in platform profile set
function
- Use WARN_ON() when a malformed quirk is detected in the platform
profile probe function
- Avoid use of status as variable name if not acpi_status
- Added Kconfig line for ACPI_PLATFORM_PROFILE
- Removed bool .use_platform_profiles from the quirks struct as it is
no longer needed as a result of the platform_driver being separate.
- Moved DMI quirk matching in probe function before devm_kzalloc of
driver struct
v1: https://lore.kernel.org/platform-driver-x86/[email protected]/
This RFC patch adds support for mapping firmware thermal and CPU power operating policy to platform_profile for Panasonic Let's Note laptops. This originally started as a hwmon and thermal patch, but further analysis had revealed that these are firmware power and thermal policies as opposed to fan control.
Panasonic firmware exposes firmware operating policy through two methods:
- Fan cooling policy (active/passive)
- Processor TDP limit (capped/uncapped)
At boot, firmware defaults to an active cooling policy with the CPU TDP capped. Vendor drivers / DPTF normally unlocks this on Windows.
These 2 methods map to 4 possible distinct states. Only states that correspond to the platform_profile ABI are mapped and exposed as choices. Unmapped states will be returned as "custom" by the driver.
I have tested the following models:
- CF-RZ6 (2016)
- CF-SV8 (2019)
- CF-QV9 (2020)
- CF-SR4 (2024)
State to platform_profile mapping:
Profile | Fan Mode | TDP
+--------------------------------+-----------+------------+ PLATFORM_PROFILE_COOL (SR4 only)| Active | Locked PLATFORM_PROFILE_BALANCED | Active | Locked PLATFORM_PROFILE_QUIET | Passive | Locked PLATFORM_PROFILE_PERFORMANCE | Active | Unlocked CUSTOM (unmapped on all) | Passive | Unlocked
Across all of them, the fan and TDP modes are toggled by the same ACPI methods. However, there is a slight variation in its interpretation based on testing results.
These methods are normally called by the DPTF/IPF _OSC handshake. Depending on the capability bits, the firmware will alter its thermal and power policy.
\_SB.IETM Implementation A:
- CF-RZ6 (2016)
- CF-SV8 (2019)
\_SB.IETM Implementation B:
- CF-QV9 (2020)
- CF-SR4 (2024)
Models belonging to the same group share what appears to be identical AML code for the _OSC.
This patch only exposes the ability to read and set these firmware toggles. The get() callback queries current firmware state and returns the mapped platform_profile. The set() callback sets the target state regardless of current state.
Proposed mappings in this patch are defined in the quirks struct. Activation of platform_profile is gated by DMI checks.
For every model except the SR4, only balanced and performance profiles are defined. This is because the aggressive fan paired with the locked TDP on the SR4 more appropriately correspond to the cool profile.
Test results for the proposed mappings are below.
Test results:
================
(CPU PkgWatt: peak / sustained)
(Sysbench CPU: all available threads)
CF-RZ6: (i5-7Y57, Startup default: Balanced)
Platform Profile | CPU PkgWatt | Sysbench CPU | Stress Temp (CPU)
+-----------------+-----------------+----------------+-------------------+ BALANCED | 10.0W / 9.0W | 19712 | 57C PERFORMANCE | 18.9W / 14.9W | 29132 | 72C
CF-SV8: (i5-8365U, Startup default: Balanced)
Platform Profile | CPU PkgWatt | Sysbench CPU | Stress Temp (CPU)
+-----------------+------------------+----------------+-------------------+ BALANCED | 9.9W / 9.9W | 44695 | 58C PERFORMANCE | 29.0W / 19.9W | 71747 | 81C
CF-QV9: (i5-10310U, Startup default: Balanced)
Platform Profile | CPU PkgWatt | Sysbench CPU | Stress Temp (CPU)
+-----------------+------------------+----------------+-------------------+ BALANCED | 10.0W / 9.9W | 46545 | 59C PERFORMANCE | 18.9W / 14.9W | 57416 | 70C
CF-SR4: (i5-1345U, Startup default: Cool)
Platform Profile | CPU PkgWatt | Sysbench CPU | Stress Temp (CPU)
+-----------------+------------------+----------------+-------------------+ COOL | 12.0W / 12.0W | 177139 | 66C QUIET | 12.0W / 12.0W | 176315 | 73C-75C PERFORMANCE | 29.6W / 21.3W | 247602 | 98C-100C
CF-SR4 Notes:
- QUIET: downclock/throttle at 75C, no increase in package_throttle_count
- PERFORMANCE: stable boost clock, package_throttle_count increase
Other notes:
===============
Additional notes about thermald:
During testing, I have observed that running thermald for the first time since boot will trigger an _OSC negotiation that will unlock CPU TDP for new models (IETM Implementation B). Once thermald is running, exits or runs again, these bits were not observed to change again during testing.
Running thermald on older models (IETM Implementation A) does not touch the fan curve or TDP mode setting.
Suspend: observed to not alter the values set prior to suspend
drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/panasonic-laptop.c | 373 +++++++++++++++++++++++- 2 files changed, 373 insertions(+), 1 deletion(-)
drivers/platform/x86/Kconfig +1 -0
@@ -820,6 +820,7 @@ config PANASONIC_LAPTOP depends on ACPI_VIDEO=n || ACPI_VIDEO depends on SERIO_I8042 || SERIO_I8042 = n select INPUT_SPARSEKMAP + select ACPI_PLATFORM_PROFILE help This driver adds support for access to backlight control and hotkeys on Panasonic Let's Note laptops.
drivers/platform/x86/panasonic-laptop.c +372 -1
407 lines not on this page · raw message
Signature · 1 line
2.55.0
Hi Alex,
Thanks for v4 and for settling the mapping — cool/quiet/performance it is.
I applied this v4 to the v7.3 driver source and built it out-of-tree against Debian's 7.2.9 headers (the unit currently runs 7.2.9, not 7.3; the driver code is v4 verbatim). The 8-line CF-SV1-2 DMI entry is applied on top; without it the profile device does not bind on this model. BIOS V2.00L24, i5-1145G7.
$ cat /sys/firmware/acpi/platform_profile_choices cool quiet performance
target CEFM EPLE read back cool 0x0 0x1 cool quiet 0x1 0x1 quiet performance 0x0 0x0 performance
The passive+unlocked combination (SEFM 1 + SEPL 0, written straight to the EC) reads back as custom; the ABI itself rejects custom (EINVAL) and max-power (EOPNOTSUPP). The values are the same through the legacy /sys/firmware/acpi/... interface and the class device, and writing through either frontend works.
Suspend/resume: this unit only offers s2idle (no deep S3). quiet and cool both survived an s2idle cycle with CEFM/EPLE unchanged, and a profile write after resume still reached the EC. No errors in dmesg on load or on profile changes.
Evidence (choices, round-trip, custom, resume logs):
https://github.com/numuly/cf-sv1-2-platform-profile-evidence/tree/v4-test-20261026/driver
The CF-SV1-2 DMI entry follows as a separate patch, as you suggested.
Thanks,
Wu
Wu Zhipeng
Tested-byRe-sending the tag as its own trailer so tooling picks it up:
PATCH 1/1 platform/x86: panasonic-laptop: Add CF-SV1-2 platform_profile entry
In reply to Alex YeoThe CF-SV1-2 exposes the same CEFM/EPLE fan/TDP policy pair as the CF-SR4, with the same boolean mapping (cool = active + locked, quiet = passive + locked, performance = active + unlocked), so reuse quirk_cf_sr4 and add only a DMI entry. The remaining combination (passive + unlocked) is reported as CUSTOM by get().
Measured on the unit (BIOS V2.00L24, i5-1145G7, EPP=performance, turbo on, no userspace fan governor): the TDP toggle is the power lever (~10 W locked vs ~26 W unlocked) and the fan toggle is a temperature lever at essentially equal package power (active+locked 9.96 W / 50 C, passive+locked 9.95 W / 60 C, active+unlocked 26.32 W / 84 C).
Notes for this model, because they do not generalise: the SEFM curve bytes behind the boolean differ from CF-SR4 (0x00 cool / 0x05 quiet / 0x02 in S0i3), EPLE/SEPL select an IETM table PL rather than a fixed TDP cap, _FST[1] is a fan setpoint and not RPM, a nonzero TFN1._FSL override masks a profile change until released, and the EC boots at CEFM=0 / EPLE=1 (active + locked / COOL).
Alex Yeo confirmed the cool/quiet/performance mapping for this model on 2026-10-26.
---
Applies on top of RFC v4 ([email protected]); the pre-image is the v4 post-image.
drivers/platform/x86/panasonic-laptop.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/platform/x86/panasonic-laptop.c +8 -0
@@ -329,6 +329,14 @@ static const struct dmi_system_id pcc_profile_quirks[] = { }, .driver_data = &quirk_cf_sr4, }, + { + .ident = "Panasonic Corporation CFSV1-2", + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Panasonic Corporation" ), + DMI_MATCH(DMI_PRODUCT_NAME, "CFSV1-2"), + }, + .driver_data = &quirk_cf_sr4, + }, { .ident ="Panasonic Corporation CFQV9-1" , .matches = {
Signature · 1 line
2.47.3
Ilpo Järvinen
maintainerQuoted 9 lines · Alex Yeo
Expose firmware thermal and power management policies via the
platform_profileinterface.Supported and tested models:
- CF-RZ6 (2016)
- CF-SV8 (2019)
- CF-QV9 (2020)
- CF-SR4 (2024)
Quoted 4 lines
Firmware fan operating mode and the TDP limit switch are mapped onto the Linux
platform_profileABI.This implementation queries the firmware for every
get().
Avoid "This patch/implementation/series ..." openings in changelog. Start with:
Query the firmware ...
Quoted 9 lines
CUSTOM is returned when the current state is not recognized. The
set()callback writes the values regardless of what the current fan mode and TDP limit is.- Introduce as separate
platform_driver- Used DEFINE for driver and
platform_profiledevice name
- DMI quirks restrict support to tested models
Drop these 2.
Quoted 9 lines
- When raising TDP, fan mode is switched first
- When limiting TDP, TDP limit is applied first
- ACPI handle for the EC device was used as the EC path varies slightly between models.- This device is optional: keep hotkey and everything already loaded if profile driver fails for any reason.
- Common fan/power settings are shared by aquirk_defaultstruct to avoid duplication of similar structs.
These two are overly verbose in the current form so try to shorten them.
Write all these on the list without bullets points into normal text.
We generally don't describe algorithms as bullet points, using LLMs will easily get you wrong when it comes to this so you need to pay attention.
Quoted 5 lines
Signed-off-by Alex Yeo <[email protected]>---
v4:
- Consolidated separate quirk structs for the RZ6, QV9 and SV8 into aquirk_defaultstruct.
Can you send v5 as a proper series. As the other patch was posted into the same thread, my tool picks it and not this one.
And why is this still RFC?
Quoted 584 lines
v3: https://lore.kernel.org/platform-driver-x86/[email protected]/
- Removedsysfs.himport
- Refactored platform profile probe function to use a different pattern (checkwarn_on, continue on double unset, then set)v2: https://lore.kernel.org/platform-driver-x86/[email protected]/
- Refactored code to use its ownplatform_driver
- RemovedDEFINE_FREEand its corresponding__freeas its addition
in this module is inappropriate
- Removedpr_fmtline as its addition to this patch is inappropriate
- Added DMI check during__initto prevent attempt of platform profile
device loading on unsupported hardware
- Fixed use of enums as truth values by adding explicit comparisons
- Added*profile_pdevto keep track of newplatform_driver
- Removed extra spaces in the quirk definitions
- Added helper function for calling EC methods for simplicity
- UseARRAY_SIZE()for for loops and added include forarray_size.h
- Refactoredpcc_profileto be a pointer in platform profile set
function
- UseWARN_ON()when a malformed quirk is detected in the platform
profile probe function
- Avoid use of status as variable name if notacpi_status
- AddedKconfigline forACPI_PLATFORM_PROFILE
- Removed bool .use_platform_profiles from the quirks struct as it is
no longer needed as a result of theplatform_driverbeing separate.
- Moved DMI quirk matching in probe function beforedevm_kzallocof
driver structv1: https://lore.kernel.org/platform-driver-x86/[email protected]/
This RFC patch adds support for mapping firmware thermal and CPU power operating policy to
platform_profilefor Panasonic Let's Note laptops. This originally started as a hwmon and thermal patch, but further analysis had revealed that these are firmware power and thermal policies as opposed to fan control.Panasonic firmware exposes firmware operating policy through two methods:
- Fan cooling policy (active/passive)
- Processor TDP limit (capped/uncapped)At boot, firmware defaults to an active cooling policy with the CPU TDP capped. Vendor drivers / DPTF normally unlocks this on Windows.
These 2 methods map to 4 possible distinct states. Only states that correspond to the
platform_profileABI are mapped and exposed as choices. Unmapped states will be returned as "custom" by the driver.I have tested the following models:
- CF-RZ6 (2016)
- CF-SV8 (2019)
- CF-QV9 (2020)
- CF-SR4 (2024)State to
platform_profilemapping:Profile | Fan Mode | TDP
+--------------------------------+-----------+------------+ PLATFORM_PROFILE_COOL (SR4 only)| Active | Locked PLATFORM_PROFILE_BALANCED | Active | Locked PLATFORM_PROFILE_QUIET | Passive | Locked PLATFORM_PROFILE_PERFORMANCE | Active | Unlocked CUSTOM (unmapped on all) | Passive | UnlockedAcross all of them, the fan and TDP modes are toggled by the same ACPI methods. However, there is a slight variation in its interpretation based on testing results.
These methods are normally called by the DPTF/IPF
_OSChandshake. Depending on the capability bits, the firmware will alter its thermal and power policy.\_SB.IETM Implementation A:
- CF-RZ6 (2016)
- CF-SV8 (2019)\_SB.IETM Implementation B:
- CF-QV9 (2020)
- CF-SR4 (2024)Models belonging to the same group share what appears to be identical AML code for the
_OSC.This patch only exposes the ability to read and set these firmware toggles. The
get()callback queries current firmware state and returns the mappedplatform_profile. Theset()callback sets the target state regardless of current state.Proposed mappings in this patch are defined in the quirks struct. Activation of
platform_profileis gated by DMI checks.For every model except the SR4, only balanced and performance profiles are defined. This is because the aggressive fan paired with the locked TDP on the SR4 more appropriately correspond to the cool profile.
Test results for the proposed mappings are below.
Test results:
================
(CPU PkgWatt: peak / sustained)
(Sysbench CPU: all available threads)CF-RZ6: (i5-7Y57, Startup default: Balanced)
Platform Profile | CPU PkgWatt | Sysbench CPU | Stress Temp (CPU)
+-----------------+-----------------+----------------+-------------------+ BALANCED | 10.0W / 9.0W | 19712 | 57C PERFORMANCE | 18.9W / 14.9W | 29132 | 72CCF-SV8: (i5-8365U, Startup default: Balanced)
Platform Profile | CPU PkgWatt | Sysbench CPU | Stress Temp (CPU)
+-----------------+------------------+----------------+-------------------+ BALANCED | 9.9W / 9.9W | 44695 | 58C PERFORMANCE | 29.0W / 19.9W | 71747 | 81CCF-QV9: (i5-10310U, Startup default: Balanced)
Platform Profile | CPU PkgWatt | Sysbench CPU | Stress Temp (CPU)
+-----------------+------------------+----------------+-------------------+ BALANCED | 10.0W / 9.9W | 46545 | 59C PERFORMANCE | 18.9W / 14.9W | 57416 | 70CCF-SR4: (i5-1345U, Startup default: Cool)
Platform Profile | CPU PkgWatt | Sysbench CPU | Stress Temp (CPU)
+-----------------+------------------+----------------+-------------------+ COOL | 12.0W / 12.0W | 177139 | 66C QUIET | 12.0W / 12.0W | 176315 | 73C-75C PERFORMANCE | 29.6W / 21.3W | 247602 | 98C-100CCF-SR4 Notes:
- QUIET: downclock/throttle at 75C, no increase inpackage_throttle_count
- PERFORMANCE: stable boost clock,package_throttle_countincreaseOther notes:
===============Additional notes about thermald:
During testing, I have observed that running thermald for the first time since boot will trigger an_OSCnegotiation that will unlock CPU TDP for new models (IETM Implementation B). Once thermald is running, exits or runs again, these bits were not observed to change again during testing.Running thermald on older models (IETM Implementation A) does not touch the fan curve or TDP mode setting.
Suspend: observed to not alter the values set prior to suspend
drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/panasonic-laptop.c | 373 +++++++++++++++++++++++- 2 files changed, 373 insertions(+), 1 deletion(-)drivers/platform/x86/Kconfig +1
-0@@ -820,6 +820,7 @@ config PANASONIC_LAPTOP depends on ACPI_VIDEO=n || ACPI_VIDEO depends on SERIO_I8042 || SERIO_I8042 = n select INPUT_SPARSEKMAP + select ACPI_PLATFORM_PROFILE help This driver adds support for access to backlight control and hotkeys on Panasonic Let's Note laptops.drivers/platform/x86/panasonic-laptop.c +372
-1@@ -120,9 +120,13 @@*/ #include <linux/acpi.h> +#include <linux/array_size.h> #include <linux/backlight.h> #include <linux/bits.h> #include <linux/ctype.h> +#include <linux/dmi.h> +#include <linux/err.h> +#include <linux/errno.h> #include <linux/i8042.h> #include <linux/init.h> #include <linux/input.h> @@ -130,6 +134,8 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/platform_device.h> +#include <linux/platform_profile.h> +#include <linux/printk.h> #include <linux/seq_file.h> #include <linux/serio.h> #include <linux/slab.h> @@ -158,10 +164,37 @@ MODULE_LICENSE("GPL");#define ECO_MODE_OFF 0x00#define ECO_MODE_ON 0x80 +#define PCC_ACPI_FAN_ACTIVE_MODE 0x00 +#define PCC_ACPI_FAN_PASSIVE_MODE 0x01 +#define PCC_ACPI_TDP_LIMIT_ON 0x01 +#define PCC_ACPI_TDP_LIMIT_OFF 0x00 +#define ACPI_PCC_DRIVER_NAME "Panasonic Laptop Support" +#define PROFILE_PCC_DRIVER_NAME "panasonic-platform-profile"#define ACPI_PCC_INPUT_PHYS "panasonic/hkey0" +enum pcc_profile_fan_mode { +PCC_FAN_MODE_UNSET =0 , +PCC_FAN_MODE_ACTIVE , +PCC_FAN_MODE_PASSIVE , +}; + +enum pcc_profile_tdp_mode { +PCC_TDP_MODE_UNSET =0 , +PCC_TDP_MODE_LOCKED , +PCC_TDP_MODE_UNLOCKED , +}; + +struct pcc_platform_profile { +enum pcc_profile_fan_mode fan_mode; +enum pcc_profile_tdp_mode tdp_mode; +}; + +struct pcc_profile_quirk { +struct pcc_platform_profile platform_profiles[PLATFORM_PROFILE_LAST ]; +}; +/* LCD_TYPEs: 0 = Normal, 1 = Semi-transparent ECO_MODEs: 0x03 = off, 0x83 = on */ @@ -251,6 +284,78 @@ struct pcc_acpi { u32 sinf[] __counted_by(num_sifr); }; +struct pcc_profile { +acpi_handle ec_handle; +const struct pcc_profile_quirk *quirks; +struct device *platform_profile_dev; +}; + +static struct pcc_profile_quirk quirk_default = { + .platform_profiles = { + [PLATFORM_PROFILE_BALANCED ] = { + .fan_mode =PCC_FAN_MODE_ACTIVE , + .tdp_mode =PCC_TDP_MODE_LOCKED , + }, + [PLATFORM_PROFILE_PERFORMANCE ] = { + .fan_mode =PCC_FAN_MODE_ACTIVE , + .tdp_mode =PCC_TDP_MODE_UNLOCKED , + }, + }, +}; + +static struct pcc_profile_quirk quirk_cf_sr4 = { + .platform_profiles = { + [PLATFORM_PROFILE_QUIET ] = { + .fan_mode =PCC_FAN_MODE_PASSIVE , + .tdp_mode =PCC_TDP_MODE_LOCKED , + }, + [PLATFORM_PROFILE_COOL ] = { + .fan_mode =PCC_FAN_MODE_ACTIVE , + .tdp_mode =PCC_TDP_MODE_LOCKED , + }, + [PLATFORM_PROFILE_PERFORMANCE ] = { + .fan_mode =PCC_FAN_MODE_ACTIVE , + .tdp_mode =PCC_TDP_MODE_UNLOCKED , + }, + }, +}; + +static const struct dmi_system_id pcc_profile_quirks[] = { + { + .ident ="Panasonic Connect Co., Ltd. CFSR4-1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Panasonic Connect Co., Ltd." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"CFSR4-1" ), + }, + .driver_data = &quirk_cf_sr4, + }, + { + .ident ="Panasonic Corporation CFQV9-1" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Panasonic Corporation" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"CFQV9-1" ), + }, + .driver_data = &quirk_default, + }, + { + .ident ="Panasonic Corporation CFSV8-2" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Panasonic Corporation" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"CFSV8-2" ), + }, + .driver_data = &quirk_default, + }, + { + .ident ="Panasonic Corporation CFRZ6-2" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Panasonic Corporation" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"CFRZ6-2" ), + }, + .driver_data = &quirk_default, + }, + {}, +}; +/* * On some Panasonic models the volume up / down / mute keys send duplicate * keypress events over the PS/2 kbd interface, filter these out. @@ -1143,4 +1248,270 @@ static void acpi_pcc_hotkey_remove(struct platform_device *pdev)kfree (pcc); } -module_platform_driver (acpi_pcc_driver); +static int pcc_profile_fan_mode_get (struct pcc_profile *pcc,enum pcc_profile_fan_mode *fan_mode) +{ +unsigned long long state; +acpi_status status; + + status =acpi_evaluate_integer (pcc->ec_handle,"CEFM" ,NULL , &state); +if (ACPI_FAILURE (status)) { +pr_err ("cannot get fan mode via CEFM\n" ); +return -EIO ; + } + +if (state ==PCC_ACPI_FAN_ACTIVE_MODE ) + *fan_mode =PCC_FAN_MODE_ACTIVE ; +else if (state ==PCC_ACPI_FAN_PASSIVE_MODE ) + *fan_mode =PCC_FAN_MODE_PASSIVE ; +else +return -EINVAL ; + +return 0 ; +} + +static int pcc_profile_tdp_mode_get (struct pcc_profile *pcc,enum pcc_profile_tdp_mode *tdp_mode) +{ +unsigned long long state; +acpi_status status; + + status =acpi_evaluate_integer (pcc->ec_handle,"EPLE" ,NULL , + &state); +if (ACPI_FAILURE (status)) { +pr_err ("cannot read power limit using EPLE\n" ); +return -EIO ; + } + +if (state ==PCC_ACPI_TDP_LIMIT_ON ) + *tdp_mode =PCC_TDP_MODE_LOCKED ; +else if (state ==PCC_ACPI_TDP_LIMIT_OFF ) + *tdp_mode =PCC_TDP_MODE_UNLOCKED ; +else +return -EINVAL ; + +return 0 ; +} + +static int pcc_profile_ec_execute (struct pcc_profile *pcc,char *method,u64 arg) +{ +acpi_status status; + + status =acpi_execute_simple_method (pcc->ec_handle, method, arg); +if (ACPI_FAILURE (status)) { +pr_err ("failed to execute EC method %s\n" , method); +return -EIO ; + } + +return 0 ; +} + +static int pcc_profile_fan_mode_set (struct pcc_profile *pcc,enum pcc_profile_fan_mode fan_mode) +{ +switch (fan_mode) { +case PCC_FAN_MODE_ACTIVE : +return pcc_profile_ec_execute (pcc,"SEFM" ,PCC_ACPI_FAN_ACTIVE_MODE ); +case PCC_FAN_MODE_PASSIVE : +return pcc_profile_ec_execute (pcc,"SEFM" ,PCC_ACPI_FAN_PASSIVE_MODE ); +default : +return -EINVAL ; + } +} + +static int pcc_profile_tdp_mode_set (struct pcc_profile *pcc,enum pcc_profile_tdp_mode tdp_mode) +{ +switch (tdp_mode) { +case PCC_TDP_MODE_LOCKED : +return pcc_profile_ec_execute (pcc,"SEPL" ,PCC_ACPI_TDP_LIMIT_ON ); +case PCC_TDP_MODE_UNLOCKED : +return pcc_profile_ec_execute (pcc,"SEPL" ,PCC_ACPI_TDP_LIMIT_OFF ); +default : +return -EINVAL ; + } +} + +static int pcc_profile_platform_profile_get (struct device *dev, +enum platform_profile_option *profile) +{ +struct pcc_profile *pcc =dev_get_drvdata (dev); +enum platform_profile_option pp_opt; +enum pcc_profile_fan_mode fan_mode; +enum pcc_profile_tdp_mode tdp_mode; +int err; + + err =pcc_profile_fan_mode_get (pcc, &fan_mode); +if (err) +return err; + + err =pcc_profile_tdp_mode_get (pcc, &tdp_mode); +if (err) +return err; + +for (pp_opt =0 ; pp_opt <ARRAY_SIZE (pcc->quirks->platform_profiles); pp_opt++) { +const struct pcc_platform_profile *pcc_profile = + &pcc->quirks->platform_profiles[pp_opt]; + +if (tdp_mode == pcc_profile->tdp_mode && + fan_mode == pcc_profile->fan_mode) { + *profile = pp_opt; +return 0 ; + } + } + + *profile =PLATFORM_PROFILE_CUSTOM ; +return 0 ; +} + +static int pcc_profile_platform_profile_set_profile (struct pcc_profile *pcc, +enum pcc_profile_fan_mode fan_mode, +enum pcc_profile_tdp_mode tdp_mode) +{ +int err; + +switch (tdp_mode) { +case PCC_TDP_MODE_UNLOCKED : + err =pcc_profile_fan_mode_set (pcc, fan_mode); +if (err) +return err; + +return pcc_profile_tdp_mode_set (pcc, tdp_mode); +case PCC_TDP_MODE_LOCKED : + err =pcc_profile_tdp_mode_set (pcc, tdp_mode); +if (err) +return err; + +return pcc_profile_fan_mode_set (pcc, fan_mode); +default : +return -EINVAL ; + } +} + +static int pcc_profile_platform_profile_set (struct device *dev, +enum platform_profile_option profile) +{ +struct pcc_profile *pcc =dev_get_drvdata (dev); +const struct pcc_platform_profile *pcc_profile = &pcc->quirks->platform_profiles[profile]; + +return pcc_profile_platform_profile_set_profile (pcc, + pcc_profile->fan_mode, + pcc_profile->tdp_mode); +} + +static int pcc_profile_platform_profile_probe (void *drvdata,unsigned long *choices) +{ +enum platform_profile_option pp_opt; +struct pcc_profile *pcc = drvdata; + +for (pp_opt =0 ; pp_opt <ARRAY_SIZE (pcc->quirks->platform_profiles); pp_opt++) { +const struct pcc_platform_profile *profile = + &pcc->quirks->platform_profiles[pp_opt]; + +/* Both TDP and fan mode should be set */ +if (WARN_ON ((profile->fan_mode !=PCC_FAN_MODE_UNSET ) != + (profile->tdp_mode !=PCC_TDP_MODE_UNSET ))) +return -EINVAL ; + +if (profile->fan_mode ==PCC_FAN_MODE_UNSET && + profile->tdp_mode ==PCC_TDP_MODE_UNSET ) +continue ; + +set_bit (pp_opt, choices); + } + +return 0 ; +} + +static const struct platform_profile_ops pcc_platform_profile_ops = { + .probe = pcc_profile_platform_profile_probe, + .profile_get = pcc_profile_platform_profile_get, + .profile_set = pcc_profile_platform_profile_set, +}; + +static int pcc_profile_driver_probe (struct platform_device *pdev) +{ +const struct dmi_system_id *dmi_id; +struct acpi_device *ec_adev; +struct pcc_profile *pcc; + + dmi_id =dmi_first_match (pcc_profile_quirks); +if (!dmi_id) +return -ENODEV ; + + pcc =devm_kzalloc (&pdev->dev,sizeof (*pcc),GFP_KERNEL ); +if (!pcc) +return -ENOMEM ; + + ec_adev =acpi_dev_get_first_match_dev ("PNP0C09" ,NULL ,-1 ); +if (!ec_adev) +return -ENODEV ; + + pcc->ec_handle = ec_adev->handle; +acpi_dev_put (ec_adev); + + pcc->quirks = dmi_id->driver_data; + + pcc->platform_profile_dev = +devm_platform_profile_register (&pdev->dev, +PROFILE_PCC_DRIVER_NAME , + pcc, + &pcc_platform_profile_ops); +if (IS_ERR (pcc->platform_profile_dev)) { +return dev_err_probe (&pdev->dev, +PTR_ERR (pcc->platform_profile_dev), +"failed to register platform profiles\n" ); + } + +return 0 ; +} + +static struct platform_driver profile_pcc_driver = { + .probe = pcc_profile_driver_probe, + .driver = { + .name =PROFILE_PCC_DRIVER_NAME , + }, +}; + +static struct platform_device *profile_pdev; + +static int __init panasonic_module_init (void ) +{ +int err; + + err =platform_driver_register (&acpi_pcc_driver); +if (err) +return err; + +if (!dmi_check_system (pcc_profile_quirks)) +return 0 ; + + err =platform_driver_register (&profile_pcc_driver); +if (err) { +pr_warn ("failed to register profile driver: %d\n" , err); +return 0 ; + } + + profile_pdev =platform_device_register_simple (PROFILE_PCC_DRIVER_NAME , +PLATFORM_DEVID_NONE , +NULL ,0 ); +if (IS_ERR (profile_pdev)) { + err =PTR_ERR (profile_pdev); +pr_warn ("failed to register profile device: %d\n" , err); + + profile_pdev =NULL ; +platform_driver_unregister (&profile_pcc_driver); +return 0 ; + } + +return 0 ; +} + +static void __exit panasonic_module_exit(void) +{ +if (profile_pdev) { +platform_device_unregister (profile_pdev); +platform_driver_unregister (&profile_pcc_driver); + } + +platform_driver_unregister (&acpi_pcc_driver); +} + +module_init (panasonic_module_init); +module_exit (panasonic_module_exit);
Signature · 1 line
i.