From patchwork Tue Dec 17 15:16:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13911993 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2085.outbound.protection.outlook.com [40.107.243.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97F281F7086; Tue, 17 Dec 2024 15:17:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448629; cv=fail; b=oyz3fRryYDx+2Kyz2oZit18HSMpiASq4lEbUFP8ZW6vHb9RKI96fcMk704VPeeMEaezUcEfqq35YtaM/v2TWioz3g3TBpg+ZFNyQEGbc7rQvBjUaKn4cPsfL9H1mKVlhRSkjuHbWo2bn+NBiujfAA6bJL6xI8K/hE2Yo2m46FP8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448629; c=relaxed/simple; bh=xPQQRauXJ+OUMUt4XlY8sMsQQbF7JDx2sIM8JsZhB28=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kHCM770OOwJDTY159k4pmQiCVH2Py7h3io0s+np3vtUSywros86ZXRDxdMu0U8kCvDBUmTBv5UJMXGQ8bZyMQWXT67ugnq86bowvvu3IGgXm1xXvF2Rs4MZpvGyfdAmVYJ0NkieI3fYH1269kFsI5RNM8AW+3/KxGK7p+y/ZkxQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=FFi8yAp8; arc=fail smtp.client-ip=40.107.243.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="FFi8yAp8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ayAf8O98cgnkWRO+2ylolMMNCsPsxuHzfVSifdM1B123dc8VgOYsxVl45j50DiBTHkjWDbKQr94iBDE/H4l6KHfb69oTwTKOElNGZ2aJOEP2Cgi0whKZmfjCb6Pl+Z7eegpxtS3gT3d/zQwJhqDpktSCeaunNOiTuSyRUfL9kNaFC1PbADEubfyaZV1jfu9XC10RoJ0SW3TVAzQuT7MIHl1m2RwKrcUeN51ZgiWAAVVybXmwjvHu7hLl629dEBPF1fXQV84EbFWpnanRekrnbGhirDX2JgElcMf52fkNmrYxAUKvEz8OEcihwWJzw8X1Yq/aVaxBwpyR7ig98k4Mjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Fed0ZNVC0K7E9V3PlXtqUsro1XQm/h9zmwr7m4uxb6g=; b=cqZqvvF06JHE5UftiOXUnjB61sYY+KVnnMRFxIRgbarvzCbMeRhabWz5hilAYWBlmugW4G2SRlG0YyN5H3Klm228Q/SNosg+seESKQjFvl4ogy95XyWOSu4zZIV3YJmcYo4M3UP6oEQBmYx7L+PZ3j6nqZlKKe3Iz9A1z8WVJuEu6u0iUg+QVuN31xeUpcBAflMazWuvyZeR+lmABLhBXl4+EfEz48nB8E6lL8pWEO3iRQxM4ZiLRPJynl118b2qRG/fG2DsdNhx9Cr+We5voynPm8HdMOwjJLBkAf3dCbc4TRNkkCWkggluTWC1IhQzP/HWaC0mIcn+1D89MGRqQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Fed0ZNVC0K7E9V3PlXtqUsro1XQm/h9zmwr7m4uxb6g=; b=FFi8yAp8JSB45NhfRygDfxVmgtsasODDBhy8AVMLdCdFki63m5FMS7/iOgUCxLnWVdo+B68cmX9Qw8t4PYgYqGDpbRWQEaJi/44ZKqboKmAs5EjH5DMAad50fGIEXenFAQsK4QyxthdPBbO4MgByijOq5SdVRhWAMEgpYD0zV/U= Received: from MW4PR04CA0356.namprd04.prod.outlook.com (2603:10b6:303:8a::31) by MN2PR12MB4174.namprd12.prod.outlook.com (2603:10b6:208:15f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.22; Tue, 17 Dec 2024 15:17:02 +0000 Received: from CO1PEPF000042AC.namprd03.prod.outlook.com (2603:10b6:303:8a:cafe::75) by MW4PR04CA0356.outlook.office365.com (2603:10b6:303:8a::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.21 via Frontend Transport; Tue, 17 Dec 2024 15:17:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000042AC.mail.protection.outlook.com (10.167.243.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8251.15 via Frontend Transport; Tue, 17 Dec 2024 15:17:02 +0000 Received: from airavat.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 17 Dec 2024 09:16:58 -0600 From: Shyam Sundar S K To: Hans de Goede , , Mario Limonciello , Basavaraj Natikar , Jiri Kosina , "Benjamin Tissoires" , Akshata MukundShetty , Patil Rajesh Reddy CC: , , Subject: [PATCH v2 1/2] HID: amd_sfh: Add support to export device operating states Date: Tue, 17 Dec 2024 20:46:26 +0530 Message-ID: <20241217151627.757477-2-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241217151627.757477-1-Shyam-sundar.S-k@amd.com> References: <20241217151627.757477-1-Shyam-sundar.S-k@amd.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042AC:EE_|MN2PR12MB4174:EE_ X-MS-Office365-Filtering-Correlation-Id: 46b1792a-3145-4672-3faa-08dd1eaddc23 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: kS9TWWs8UzuJ/nCAIPURIH+itZ9ds02iLKI6eLTRy3zobTKab5BpCEFBcba7ZNvl/XjsvKliBQjRnuS/Tu3RrcGFHFoh/NfHz581eUqkqI4etLgd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kN8jTBMMhqyo1pt6MBccC1oYCj+VuYL4hlo+G0ZTz57kUju+K4CLx8bTiA7TVdc/qSf115eHTu4ILkkixWqkvebWzotDlRmvrtQZqu8SQpG16gkbgCveVkYrzUhBE4NZrq0C7EP5POMIJiqlvfwl4012vzL/XfkpRfa5BHcXloVU9567MeUI3av3Ey18F2bmOnJFLu7Mgjaq3lHrP9+Wf9CL9hkKmaVoOy6TV3Px0oK1QFHa+/V3r6Kji68F2OdQFKN3dYJk+hWXFZATR6/5mhrGXFZD2ueW3nTrp4eERleVhXo7UvIBCqO3eTc4Ik= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2024 15:17:02.6388 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 46b1792a-3145-4672-3faa-08dd1eaddc23 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000042AC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4174 From: Basavaraj Natikar Add support to export device operating states, such as laptop placement, platform types and propagate this data to AMD PMF driver for use in actions. To retrieve the device operating states data, SRA sensor support need to be enabled in AMD SFH driver. So add support to enable the SRA sensor. Also, remove explicit assignments to sensor_index enum. Co-developed-by: Akshata MukundShetty Signed-off-by: Akshata MukundShetty Signed-off-by: Basavaraj Natikar Signed-off-by: Shyam Sundar S K --- drivers/hid/amd-sfh-hid/amd_sfh_common.h | 1 + drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c | 22 +++++++++++ .../amd-sfh-hid/sfh1_1/amd_sfh_interface.c | 38 +++++++++++++++++++ .../amd-sfh-hid/sfh1_1/amd_sfh_interface.h | 24 +++++++++++- include/linux/amd-pmf-io.h | 15 ++++++++ 5 files changed, 98 insertions(+), 2 deletions(-) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_common.h b/drivers/hid/amd-sfh-hid/amd_sfh_common.h index e5620d7db569..799b8686a88a 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_common.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_common.h @@ -43,6 +43,7 @@ struct amd_mp2_sensor_info { struct sfh_dev_status { bool is_hpd_present; bool is_als_present; + bool is_sra_present; }; struct amd_mp2_dev { diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c index db36d87d5634..03c028f1aab4 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c @@ -30,6 +30,7 @@ static int amd_sfh_get_sensor_num(struct amd_mp2_dev *mp2, u8 *sensor_id) case ACCEL_IDX: case GYRO_IDX: case MAG_IDX: + case SRA_IDX: case ALS_IDX: case HPD_IDX: if (BIT(i) & slist->sl.sensors) @@ -58,6 +59,8 @@ static const char *get_sensor_name(int idx) return "gyroscope"; case MAG_IDX: return "magnetometer"; + case SRA_IDX: + return "SRA"; case ALS_IDX: return "ALS"; case HPD_IDX: @@ -130,6 +133,23 @@ static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev *privdata) for (i = 0; i < cl_data->num_hid_devices; i++) { cl_data->sensor_sts[i] = SENSOR_DISABLED; + + if (cl_data->num_hid_devices == 1 && cl_data->sensor_idx[0] == SRA_IDX) + break; + + if (cl_data->sensor_idx[i] == SRA_IDX) { + info.sensor_idx = cl_data->sensor_idx[i]; + writel(0, privdata->mmio + amd_get_p2c_val(privdata, 0)); + mp2_ops->start(privdata, info); + status = amd_sfh_wait_for_response + (privdata, cl_data->sensor_idx[i], ENABLE_SENSOR); + + cl_data->sensor_sts[i] = (status == 0) ? SENSOR_ENABLED : SENSOR_DISABLED; + if (cl_data->sensor_sts[i] == SENSOR_ENABLED) + privdata->dev_en.is_sra_present = true; + continue; + } + cl_data->sensor_requested_cnt[i] = 0; cl_data->cur_hid_dev = i; cl_idx = cl_data->sensor_idx[i]; @@ -181,6 +201,8 @@ static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev *privdata) } for (i = 0; i < cl_data->num_hid_devices; i++) { + if (cl_data->sensor_idx[i] == SRA_IDX) + continue; cl_data->cur_hid_dev = i; if (cl_data->sensor_sts[i] == SENSOR_ENABLED) { cl_data->is_any_sensor_enabled = true; diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c index 4676f060da26..ffb98b4c36cb 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c @@ -87,6 +87,41 @@ void sfh_interface_init(struct amd_mp2_dev *mp2) emp2 = mp2; } +static int amd_sfh_mode_info(u32 *platform_type, u32 *laptop_placement) +{ + struct sfh_op_mode mode; + + if (!platform_type || !laptop_placement) + return -EINVAL; + + if (!emp2 || !emp2->dev_en.is_sra_present) + return -ENODEV; + + mode.val = readl(emp2->mmio + amd_get_c2p_val(emp2, 3)); + + *platform_type = mode.op_mode.devicemode; + + if (mode.op_mode.ontablestate == 1) { + *laptop_placement = ON_TABLE; + } else if (mode.op_mode.ontablestate == 2) { + *laptop_placement = ON_LAP_MOTION; + } else if (mode.op_mode.inbagstate == 1) { + *laptop_placement = IN_BAG; + } else if (mode.op_mode.outbagstate == 1) { + *laptop_placement = OUT_OF_BAG; + } else if (mode.op_mode.ontablestate == 0 || mode.op_mode.inbagstate == 0 || + mode.op_mode.outbagstate == 0) { + *laptop_placement = LP_UNKNOWN; + pr_warn_once("Unknown laptop placement\n"); + } else if (mode.op_mode.ontablestate == 3 || mode.op_mode.inbagstate == 3 || + mode.op_mode.outbagstate == 3) { + *laptop_placement = LP_UNDEFINED; + pr_warn_once("Undefined laptop placement\n"); + } + + return 0; +} + static int amd_sfh_hpd_info(u8 *user_present) { struct hpd_status hpdstatus; @@ -131,6 +166,9 @@ int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op) return amd_sfh_hpd_info(&sfh_info->user_present); case MT_ALS: return amd_sfh_als_info(&sfh_info->ambient_light); + case MT_SRA: + return amd_sfh_mode_info(&sfh_info->platform_type, + &sfh_info->laptop_placement); } } return -EINVAL; diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h index 2c211d28764d..665c99ad779f 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h @@ -22,8 +22,9 @@ enum sensor_index { ACCEL_IDX, GYRO_IDX, MAG_IDX, - ALS_IDX = 4, - HPD_IDX = 5, + SRA_IDX, + ALS_IDX, + HPD_IDX, MAX_IDX = 15, }; @@ -164,6 +165,25 @@ struct hpd_status { }; }; +struct sfh_op_mode { + union { + u32 val; + struct { + u32 mode : 3; + u32 lidstatus : 1; + u32 angle : 10; + u32 inbagstatedbg : 2; + u32 ontablestate : 2; + u32 inbagstate : 2; + u32 outbagstate : 2; + u32 inbagmlcstate : 1; + u32 powerstate : 2; + u32 data : 3; + u32 devicemode : 4; + } op_mode; + }; +}; + void sfh_interface_init(struct amd_mp2_dev *mp2); void sfh_deinit_emp2(void); void amd_sfh1_1_set_desc_ops(struct amd_mp2_ops *mp2_ops); diff --git a/include/linux/amd-pmf-io.h b/include/linux/amd-pmf-io.h index b4f818205216..6fa510f419c0 100644 --- a/include/linux/amd-pmf-io.h +++ b/include/linux/amd-pmf-io.h @@ -18,10 +18,12 @@ * enum sfh_message_type - Query the SFH message type * @MT_HPD: Message ID to know the Human presence info from MP2 FW * @MT_ALS: Message ID to know the Ambient light info from MP2 FW + * @MT_SRA: Message ID to know the SRA data from MP2 FW */ enum sfh_message_type { MT_HPD, MT_ALS, + MT_SRA, }; /** @@ -40,10 +42,23 @@ enum sfh_hpd_info { * struct amd_sfh_info - get HPD sensor info from MP2 FW * @ambient_light: Populates the ambient light information * @user_present: Populates the user presence information + * @platform_type: Operating modes (clamshell, flat, tent, etc.) + * @laptop_placement: Device states (ontable, onlap, outbag) */ struct amd_sfh_info { u32 ambient_light; u8 user_present; + u32 platform_type; + u32 laptop_placement; +}; + +enum laptop_placement { + LP_UNKNOWN = 0, + ON_TABLE, + ON_LAP_MOTION, + IN_BAG, + OUT_OF_BAG, + LP_UNDEFINED, }; int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op); From patchwork Tue Dec 17 15:16:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13911994 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2053.outbound.protection.outlook.com [40.107.220.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E0D21F709A; Tue, 17 Dec 2024 15:17:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448630; cv=fail; b=GaR1yPX9/iaRJtd8mC4ZTVZZ7CL0MAR1pDQLqKAf5ZqF5gfWbPNZ1eoy47aAC51OautSIx4/XFBmImPgyw1/FEGenx9Q67l5Ob7RSs8lbXXJRQQ4a9ki0aksj4fZ9aUztJUx1xlvvKbBkXDAkAqH6brwbf25jZXtGaDJXEgHfOU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734448630; c=relaxed/simple; bh=vofImAf+DtdTfunecXKiW3RAtwxWH+LbtcqrGKaaJRs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rKZgmAJ+TH5q5FISgSVGta2i4eZUmiuWAXThnNPP6KVkpmqdpnZXW7T+qPFPQrofW0pDv80vdj7BrOK29mueucOnKlE2ZIZzS37ylAHIIaEULno9eeAyTnedvI6iZb6iS0gDBcQInLoUJpSMqYyYbmEM8tMJr9eVMrptVBaoi4s= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=EcaExXOp; arc=fail smtp.client-ip=40.107.220.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="EcaExXOp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MuLu9EXoJCrPaaHgPvHDV4WK+iHnLVLEBW1H/DHJ0LBP3HTX1Hv/SlvRV56xHHl0fFb/tTAJLd7BIUf+nwVy5wmhCqUSyHsbuBn2al3cYfoIHT4MmnFxKndIwek9eq8VMbvhaBTv5b8/wfOKAvjbo/rSqO5I+HZCBY2Z4Z/GCiXunJ1JNgLzgvC14DXx0GSWPT+ISj0TPwMG+GkZEKa77+s8HibY9txRvg2axFiJwBxqRa64K3GHKeTbYOkFEzLZHflWUq6tBDjN0Mr8iBC7WfML2nBdKqpjQejRvxpVjf4ai+4ngVlbnABDYQw90dRwzid5ZfbwZXJSsCTSgcPy2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=A5pI2FYy46+8kFgbOoJSXgbgN+wH1IURNFhZetL+HeA=; b=XdWL/9WkCRnkKZbyAVpWm1N+ONPYKyxoGq5ZQwdKJhfLN0d3OvabtWI5BBMK9fuXp5RU3puwLvpOMi+yHQWPabjqJXJanw0TKP6gr7kzl40HmpMKFCv+gQQdf0VwYwmv1fBfUZfNPCEu+zml9MC9fycNRHIcAt9tlHRaeey9nWIjnBvSP8nz0Ei+SjvnSDn0zJPqiy6sI0/vNEaCNmnYZhBe26Kq/iRcR4FQFg7rSxy0ajtHbyHh0M8UW/oyqj8kclKlOgezUnoD0DSbkZOIhXyGesDsJRlz59ifBEceuwXt7UpOhl4Y3Y1t8aIGCAaCBBuuyQRaWjCxVj5pNihBrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=A5pI2FYy46+8kFgbOoJSXgbgN+wH1IURNFhZetL+HeA=; b=EcaExXOpsEmvNjUtsYqsA/Th9UVxzKu7yR88malO/5JZHp9xr0feWuugEnzUBSJloanAsU9TEvn6AZqVMQPTtd3VjCK+N9fOhexMuqjSNdC0QfYpg6icAtl6a13ognmvWeb6cEzzNpB9akLu8ERreBRSceQzU7jrpvhgMpZtkFA= Received: from MW4PR04CA0356.namprd04.prod.outlook.com (2603:10b6:303:8a::31) by MN6PR12MB8471.namprd12.prod.outlook.com (2603:10b6:208:473::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.21; Tue, 17 Dec 2024 15:17:06 +0000 Received: from CO1PEPF000042AC.namprd03.prod.outlook.com (2603:10b6:303:8a:cafe::75) by MW4PR04CA0356.outlook.office365.com (2603:10b6:303:8a::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.21 via Frontend Transport; Tue, 17 Dec 2024 15:17:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000042AC.mail.protection.outlook.com (10.167.243.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8251.15 via Frontend Transport; Tue, 17 Dec 2024 15:17:05 +0000 Received: from airavat.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 17 Dec 2024 09:17:02 -0600 From: Shyam Sundar S K To: Hans de Goede , , Mario Limonciello , Basavaraj Natikar , Jiri Kosina , "Benjamin Tissoires" , Akshata MukundShetty , Patil Rajesh Reddy CC: , , , Patil Rajesh Reddy Subject: [PATCH v2 2/2] platform/x86/amd/pmf: Get SRA sensor data from AMD SFH driver Date: Tue, 17 Dec 2024 20:46:27 +0530 Message-ID: <20241217151627.757477-3-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241217151627.757477-1-Shyam-sundar.S-k@amd.com> References: <20241217151627.757477-1-Shyam-sundar.S-k@amd.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042AC:EE_|MN6PR12MB8471:EE_ X-MS-Office365-Filtering-Correlation-Id: de6d0bab-398d-4766-15d0-08dd1eadde1f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: fzSSxFfFyzSB76t5e7+cOg6Du6+Twp6IkvHTQRbNfT+MOprhNfcXXip/WuN+iUbAKTLhq5M+WBGh9PDqLIBjJWV8l1Tn6Qny8Nr4pxD3ShFMwAkbzWyrdZYoFy2kcNUEWgIz5m5192AFPe20hAIV3N4gI76cI3fbknItYbZBQX1J4hjnWeu47PMIvtgtNYCJCLzmmNq11a+K0+cymJuHWFukLwWoPeSJRMAZKCI0avg5vr6a4ZDfxLSQv6hgMFg/Tdh+dG0lloTWmPvhwj2HToLihmZ2HDf7kF0F8YuqUOMUaW8hBl0hG4+2GzwjrWg1muCp4TUddAXyHVXqhW1s9SUUVzhyvz+/3L/wlukNLAngXuFg08pQdeDU9fOe2MHlskNmTKoU4XaEpeC83l7vEe7WmITCl6w7VgPe40YKlm80cSbiJvvF6BB9b7reOv3yZjZC524cXDqA3/Tkp/GeAu/VS8VHeF+8THqjxKWROVoBrQlNH/avaSHR7gnHO9OZIm77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omainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2024 15:17:05.9670 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: de6d0bab-398d-4766-15d0-08dd1eadde1f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000042AC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8471 The AMD SFH driver includes APIs to export SRA sensor data. This data is utilized by the AMD PMF driver to transmit SRA data to the PMF TA, enabling the AMD PMF driver to implement the output actions specified by the PMF TA. Co-developed-by: Patil Rajesh Reddy Signed-off-by: Patil Rajesh Reddy Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/pmf.h | 18 ++++++++++- drivers/platform/x86/amd/pmf/spc.c | 51 ++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 255c5ad2300e..492a64958fcf 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -628,6 +628,20 @@ enum apmf_preq_smartpc { NOTIFY_CUSTOM_BIOS_INPUT2, }; +enum platform_type { + PTYPE_UNKNOWN = 0, + LID_CLOSE, + CLAMSHELL, + FLAT, + TENT, + STAND, + TABLET, + BOOK, + PRESENTATION, + PULL_FWD, + PTYPE_INVALID = 0Xf, +}; + /* Command ids for TA communication */ enum ta_pmf_command { TA_PMF_COMMAND_POLICY_BUILDER_INITIALIZE, @@ -680,7 +694,9 @@ struct ta_pmf_condition_info { u32 device_state; u32 socket_power; u32 skin_temperature; - u32 rsvd3[5]; + u32 rsvd3[2]; + u32 platform_type; + u32 rsvd3_1[2]; u32 ambient_light; u32 length; u32 avg_c0residency; diff --git a/drivers/platform/x86/amd/pmf/spc.c b/drivers/platform/x86/amd/pmf/spc.c index 05bed8206365..f34f3130c330 100644 --- a/drivers/platform/x86/amd/pmf/spc.c +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -16,6 +16,46 @@ #include "pmf.h" #ifdef CONFIG_AMD_PMF_DEBUG +static const char *platform_type_as_str(u16 platform_type) +{ + switch (platform_type) { + case CLAMSHELL: + return "CLAMSHELL"; + case FLAT: + return "FLAT"; + case TENT: + return "TENT"; + case STAND: + return "STAND"; + case TABLET: + return "TABLET"; + case BOOK: + return "BOOK"; + case PRESENTATION: + return "PRESENTATION"; + case PULL_FWD: + return "PULL_FWD"; + default: + return "UNKNOWN"; + } +} + +static const char *laptop_placement_as_str(u16 device_state) +{ + switch (device_state) { + case ON_TABLE: + return "ON_TABLE"; + case ON_LAP_MOTION: + return "ON_LAP_MOTION"; + case IN_BAG: + return "IN_BAG"; + case OUT_OF_BAG: + return "OUT_OF_BAG"; + default: + return "UNKNOWN"; + } +} + static const char *ta_slider_as_str(unsigned int state) { switch (state) { @@ -47,6 +87,9 @@ void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table * dev_dbg(dev->dev, "LID State: %s\n", in->ev_info.lid_state ? "close" : "open"); dev_dbg(dev->dev, "User Presence: %s\n", in->ev_info.user_present ? "Present" : "Away"); dev_dbg(dev->dev, "Ambient Light: %d\n", in->ev_info.ambient_light); + dev_dbg(dev->dev, "Platform type: %s\n", platform_type_as_str(in->ev_info.platform_type)); + dev_dbg(dev->dev, "Laptop placement: %s\n", + laptop_placement_as_str(in->ev_info.device_state)); dev_dbg(dev->dev, "Custom BIOS input1: %u\n", in->ev_info.bios_input1); dev_dbg(dev->dev, "Custom BIOS input2: %u\n", in->ev_info.bios_input2); dev_dbg(dev->dev, "==== TA inputs END ====\n"); @@ -213,6 +256,14 @@ static void amd_pmf_get_sensor_info(struct amd_pmf_dev *dev, struct ta_pmf_enact } else { dev_dbg(dev->dev, "HPD is not enabled/detected\n"); } + + /* Get SRA (Secondary Accelerometer) data */ + if (!amd_get_sfh_info(&sfh_info, MT_SRA)) { + in->ev_info.platform_type = sfh_info.platform_type; + in->ev_info.device_state = sfh_info.laptop_placement; + } else { + dev_dbg(dev->dev, "SRA is not enabled/detected\n"); + } } void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in)