From patchwork Thu Feb 4 20:40:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 12068677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58D40C433DB for ; Thu, 4 Feb 2021 20:41:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 133B164F48 for ; Thu, 4 Feb 2021 20:41:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229518AbhBDUlh (ORCPT ); Thu, 4 Feb 2021 15:41:37 -0500 Received: from mail-40133.protonmail.ch ([185.70.40.133]:50276 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbhBDUkt (ORCPT ); Thu, 4 Feb 2021 15:40:49 -0500 Date: Thu, 04 Feb 2021 20:40:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612471204; bh=BxS3as75xXnioCISJT2J2o20wWm8qoV3qCQ/fC1Aydg=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From; b=nr58ULUCfat3VQWUQDcCGr61HGfME6+POxrNa/K2uGd3wUm7u9wLTaUBCZ5ik9xqS tklfpbSJulGZvRVz56VSiOlOsS7b0B5XS6EjLlYMD3bCPWTwcxqw+oXccce0ljggbx bLZpOGM5rmlnRWOEw3RNXp6Lh8SVjKXGglQiYKw8= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Henrique de Moraes Holschuh , Mark Pearson , Jiaxun Yang From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH 2/2] platform/x86: thinkpad_acpi/ideapad-laptop: extract common DYTC constants/functions Message-ID: <20210204203933.559752-3-pobrn@protonmail.com> In-Reply-To: <20210204203933.559752-1-pobrn@protonmail.com> References: <20210204203933.559752-1-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Extract common DYTC constants/functions into a dedicated header file to avoid code duplication. Rename DYTC_MODE_BALANCE to DYTC_MODE_BALANCED and DYTC_MODE_PERFORM to DYTC_MODE_PERFORMANCE to be consistent with the platform_profile_option enum. Signed-off-by: Barnabás Pőcze create mode 100644 drivers/platform/x86/lenovo/dytc.h diff --git a/drivers/platform/x86/lenovo/dytc.h b/drivers/platform/x86/lenovo/dytc.h new file mode 100644 index 000000000000..9ec341bdef70 --- /dev/null +++ b/drivers/platform/x86/lenovo/dytc.h @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef _LENOVO_DYTC_H_ +#define _LENOVO_DYTC_H_ + +#include + +#define DYTC_CMD_QUERY 0 /* To get DYTC status - enable/revision */ +#define DYTC_CMD_SET 1 /* To enable/disable IC function mode */ +#define DYTC_CMD_GET 2 /* To get current IC function and mode */ +#define DYTC_CMD_RESET 511 /* To reset back to default */ + +#define DYTC_QUERY_ENABLE_BIT 8 /* Bit 8 - 0 = disabled, 1 = enabled */ +#define DYTC_QUERY_SUBREV_BIT 16 /* Bits 16 - 27 - sub revision */ +#define DYTC_QUERY_REV_BIT 28 /* Bits 28 - 31 - revision */ + +#define DYTC_GET_FUNCTION_BIT 8 /* Bits 8 - 11 - function setting */ +#define DYTC_GET_MODE_BIT 12 /* Bits 12 - 15 - mode setting */ +#define DYTC_GET_LAPMODE_BIT 17 /* Bit 17 - set when in lapmode */ + +#define DYTC_SET_FUNCTION_BIT 12 /* Bits 12 - 15 - function setting */ +#define DYTC_SET_MODE_BIT 16 /* Bits 16 - 19 - mode setting */ +#define DYTC_SET_VALID_BIT 20 /* Bit 20 - 1 = on, 0 = off */ + +#define DYTC_FUNCTION_STD 0 /* Function = 0, standard mode */ +#define DYTC_FUNCTION_CQL 1 /* Function = 1, lap mode */ +#define DYTC_FUNCTION_MMC 11 /* Function = 11, desk mode */ + +#define DYTC_MODE_PERFORMANCE 2 /* High power mode aka performance */ +#define DYTC_MODE_LOW_POWER 3 /* Low power mode aka quiet */ +#define DYTC_MODE_BALANCED 15 /* Default mode aka balanced */ + +#define DYTC_SET_COMMAND(function, mode, on) \ + (DYTC_CMD_SET | (function) << DYTC_SET_FUNCTION_BIT | \ + (mode) << DYTC_SET_MODE_BIT | \ + (on) << DYTC_SET_VALID_BIT) + +#define DYTC_DISABLE_CQL DYTC_SET_COMMAND(DYTC_FUNCTION_CQL, DYTC_MODE_BALANCED, 0) + +#define DYTC_ENABLE_CQL DYTC_SET_COMMAND(DYTC_FUNCTION_CQL, DYTC_MODE_BALANCED, 1) + +static int inline convert_dytc_to_profile(int dytcmode, enum platform_profile_option *profile) +{ + switch (dytcmode) { + case DYTC_MODE_LOW_POWER: + *profile = PLATFORM_PROFILE_LOW_POWER; + break; + case DYTC_MODE_BALANCED: + *profile = PLATFORM_PROFILE_BALANCED; + break; + case DYTC_MODE_PERFORMANCE: + *profile = PLATFORM_PROFILE_PERFORMANCE; + break; + default: /* Unknown mode */ + return -EINVAL; + } + + return 0; +} + +static inline int convert_profile_to_dytc(enum platform_profile_option profile, int *dytcmode) +{ + switch (profile) { + case PLATFORM_PROFILE_LOW_POWER: + *dytcmode = DYTC_MODE_LOW_POWER; + break; + case PLATFORM_PROFILE_BALANCED: + *dytcmode = DYTC_MODE_BALANCED; + break; + case PLATFORM_PROFILE_PERFORMANCE: + *dytcmode = DYTC_MODE_PERFORMANCE; + break; + default: /* Unknown profile */ + return -EOPNOTSUPP; + } + + return 0; +} + +#endif /* _LENOVO_DYTC_H_ */ diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c index 6cb5ad4be231..387c8c86b8bb 100644 --- a/drivers/platform/x86/lenovo/ideapad-laptop.c +++ b/drivers/platform/x86/lenovo/ideapad-laptop.c @@ -35,6 +35,8 @@ #include +#include "dytc.h" + #define IDEAPAD_RFKILL_DEV_NUM 3 #if IS_ENABLED(CONFIG_ACPI_WMI) @@ -676,76 +678,6 @@ static const struct attribute_group ideapad_attribute_group = { /* * DYTC Platform profile */ -#define DYTC_CMD_QUERY 0 /* To get DYTC status - enable/revision */ -#define DYTC_CMD_SET 1 /* To enable/disable IC function mode */ -#define DYTC_CMD_GET 2 /* To get current IC function and mode */ -#define DYTC_CMD_RESET 0x1ff /* To reset back to default */ - -#define DYTC_QUERY_ENABLE_BIT 8 /* Bit 8 - 0 = disabled, 1 = enabled */ -#define DYTC_QUERY_SUBREV_BIT 16 /* Bits 16 - 27 - sub revision */ -#define DYTC_QUERY_REV_BIT 28 /* Bits 28 - 31 - revision */ - -#define DYTC_GET_FUNCTION_BIT 8 /* Bits 8-11 - function setting */ -#define DYTC_GET_MODE_BIT 12 /* Bits 12-15 - mode setting */ - -#define DYTC_SET_FUNCTION_BIT 12 /* Bits 12-15 - function setting */ -#define DYTC_SET_MODE_BIT 16 /* Bits 16-19 - mode setting */ -#define DYTC_SET_VALID_BIT 20 /* Bit 20 - 1 = on, 0 = off */ - -#define DYTC_FUNCTION_STD 0 /* Function = 0, standard mode */ -#define DYTC_FUNCTION_CQL 1 /* Function = 1, lap mode */ -#define DYTC_FUNCTION_MMC 11 /* Function = 11, desk mode */ - -#define DYTC_MODE_PERFORM 2 /* High power mode aka performance */ -#define DYTC_MODE_LOW_POWER 3 /* Low power mode aka quiet */ -#define DYTC_MODE_BALANCE 0xF /* Default mode aka balanced */ - -#define DYTC_SET_COMMAND(function, mode, on) \ - (DYTC_CMD_SET | (function) << DYTC_SET_FUNCTION_BIT | \ - (mode) << DYTC_SET_MODE_BIT | \ - (on) << DYTC_SET_VALID_BIT) - -#define DYTC_DISABLE_CQL DYTC_SET_COMMAND(DYTC_FUNCTION_CQL, DYTC_MODE_BALANCE, 0) - -#define DYTC_ENABLE_CQL DYTC_SET_COMMAND(DYTC_FUNCTION_CQL, DYTC_MODE_BALANCE, 1) - -static int convert_dytc_to_profile(int dytcmode, enum platform_profile_option *profile) -{ - switch (dytcmode) { - case DYTC_MODE_LOW_POWER: - *profile = PLATFORM_PROFILE_LOW_POWER; - break; - case DYTC_MODE_BALANCE: - *profile = PLATFORM_PROFILE_BALANCED; - break; - case DYTC_MODE_PERFORM: - *profile = PLATFORM_PROFILE_PERFORMANCE; - break; - default: /* Unknown mode */ - return -EINVAL; - } - - return 0; -} - -static int convert_profile_to_dytc(enum platform_profile_option profile, int *perfmode) -{ - switch (profile) { - case PLATFORM_PROFILE_LOW_POWER: - *perfmode = DYTC_MODE_LOW_POWER; - break; - case PLATFORM_PROFILE_BALANCED: - *perfmode = DYTC_MODE_BALANCE; - break; - case PLATFORM_PROFILE_PERFORMANCE: - *perfmode = DYTC_MODE_PERFORM; - break; - default: /* Unknown profile */ - return -EOPNOTSUPP; - } - - return 0; -} /* * dytc_profile_get: Function to register with platform_profile diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c index b881044b31b0..61990fc9870c 100644 --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c @@ -74,6 +74,8 @@ #include #include +#include "dytc.h" + /* ThinkPad CMOS commands */ #define TP_CMOS_VOLUME_DOWN 0 #define TP_CMOS_VOLUME_UP 1 @@ -9845,9 +9847,6 @@ static struct ibm_struct lcdshadow_driver_data = { * Thinkpad sensor interfaces */ -#define DYTC_CMD_GET 2 /* To get current IC function and mode */ -#define DYTC_GET_LAPMODE_BIT 17 /* Set when in lapmode */ - #define PALMSENSOR_PRESENT_BIT 0 /* Determine if psensor present */ #define PALMSENSOR_ON_BIT 1 /* psensor status */ @@ -9999,79 +9998,11 @@ static struct ibm_struct proxsensor_driver_data = { * DYTC Platform Profile interface */ -#define DYTC_CMD_QUERY 0 /* To get DYTC status - enable/revision */ -#define DYTC_CMD_SET 1 /* To enable/disable IC function mode */ -#define DYTC_CMD_RESET 0x1ff /* To reset back to default */ - -#define DYTC_QUERY_ENABLE_BIT 8 /* Bit 8 - 0 = disabled, 1 = enabled */ -#define DYTC_QUERY_SUBREV_BIT 16 /* Bits 16 - 27 - sub revision */ -#define DYTC_QUERY_REV_BIT 28 /* Bits 28 - 31 - revision */ - -#define DYTC_GET_FUNCTION_BIT 8 /* Bits 8-11 - function setting */ -#define DYTC_GET_MODE_BIT 12 /* Bits 12-15 - mode setting */ - -#define DYTC_SET_FUNCTION_BIT 12 /* Bits 12-15 - function setting */ -#define DYTC_SET_MODE_BIT 16 /* Bits 16-19 - mode setting */ -#define DYTC_SET_VALID_BIT 20 /* Bit 20 - 1 = on, 0 = off */ - -#define DYTC_FUNCTION_STD 0 /* Function = 0, standard mode */ -#define DYTC_FUNCTION_CQL 1 /* Function = 1, lap mode */ -#define DYTC_FUNCTION_MMC 11 /* Function = 11, desk mode */ - -#define DYTC_MODE_PERFORM 2 /* High power mode aka performance */ -#define DYTC_MODE_LOWPOWER 3 /* Low power mode */ -#define DYTC_MODE_BALANCE 0xF /* Default mode aka balanced */ - -#define DYTC_SET_COMMAND(function, mode, on) \ - (DYTC_CMD_SET | (function) << DYTC_SET_FUNCTION_BIT | \ - (mode) << DYTC_SET_MODE_BIT | \ - (on) << DYTC_SET_VALID_BIT) - -#define DYTC_DISABLE_CQL DYTC_SET_COMMAND(DYTC_FUNCTION_CQL, DYTC_MODE_BALANCE, 0) - -#define DYTC_ENABLE_CQL DYTC_SET_COMMAND(DYTC_FUNCTION_CQL, DYTC_MODE_BALANCE, 1) - static bool dytc_profile_available; static enum platform_profile_option dytc_current_profile; static atomic_t dytc_ignore_event = ATOMIC_INIT(0); static DEFINE_MUTEX(dytc_mutex); -static int convert_dytc_to_profile(int dytcmode, enum platform_profile_option *profile) -{ - switch (dytcmode) { - case DYTC_MODE_LOWPOWER: - *profile = PLATFORM_PROFILE_LOW_POWER; - break; - case DYTC_MODE_BALANCE: - *profile = PLATFORM_PROFILE_BALANCED; - break; - case DYTC_MODE_PERFORM: - *profile = PLATFORM_PROFILE_PERFORMANCE; - break; - default: /* Unknown mode */ - return -EINVAL; - } - return 0; -} - -static int convert_profile_to_dytc(enum platform_profile_option profile, int *perfmode) -{ - switch (profile) { - case PLATFORM_PROFILE_LOW_POWER: - *perfmode = DYTC_MODE_LOWPOWER; - break; - case PLATFORM_PROFILE_BALANCED: - *perfmode = DYTC_MODE_BALANCE; - break; - case PLATFORM_PROFILE_PERFORMANCE: - *perfmode = DYTC_MODE_PERFORM; - break; - default: /* Unknown profile */ - return -EOPNOTSUPP; - } - return 0; -} - /* * dytc_profile_get: Function to register with platform_profile * handler. Returns current platform profile.