From patchwork Thu May 30 11:23:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chatradhi, Naveen Krishna" X-Patchwork-Id: 13680286 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2052.outbound.protection.outlook.com [40.107.100.52]) (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 F2FE3174ED4 for ; Thu, 30 May 2024 11:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717068215; cv=fail; b=em+CSx4s7ABw913DRWQx3KEtc1nHinPhmTaQFpUZ7Bdhtyparn/MUgdWjAhfQ1mmpAwZDDFjM6QDtNadIoAdBN1KA1pDrYZ856FfS08D4W0QNr0O9QFxNeHMX3Gzn1TVF6vU7BUx+tKGktTRh4P6IELojFt/pUBquGwpYVw8V5s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717068215; c=relaxed/simple; bh=eRk089coCR9cSIKiwdJj74PIl8ZuibgdXsixI87G+TY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f+aeF5TdYhdGGabqR+SlcQSavrnPNLzSMBT+vLHKlkVd5SeAQNLUOFGDpMlyNjpHgBgKLBdhwkq86gLlQpAGSpjE6tNYsTFT6OViejdxGAnLvElS8WIcr2J2RC6IUi2N4stzBZ0XZCq6sb3qLqxaXFPqjFWbZwQChV6uSndKw7Q= 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=TUXGAycP; arc=fail smtp.client-ip=40.107.100.52 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="TUXGAycP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K6pBb8M/BWtTgw9qX78vsa816ytgpUEAXJpZJ6bj91HUttkHUBEM5hqXOSHtgHR9qTNfXZTb3brWetPSOS7JtU3l9d7o02O4WA1rxGhkNux6nupCw2fvZGJAuSLLkybaILf/kIfHWeL3UerSKUMfhqSdY53bd0GEZ0GOrO3OOugEg2e032Rcisb2iS7W5ZcXuT6UgVGJGf/xPpOlql1gnrpfzB1f/6gnflJtPqyIG8aipMiD+dCltwW8ArhgPwO6EdOZ6h2RWe/8YLMOHYSSd8j4tWpQVSL2j6GlRKyxvRcwg/fd6MUciwV8U4jHGCnduzBQl3KyTtsftqQvpX9Xww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=XZwSDi93TxiryAvdDZBZd8LhuDo+f6iRycvqmEZJyTQ=; b=LUKlyfJe+hfNmzLQH3p52JhUse/ayglPAXd/Fz5X26dXtHhwyVxJ3o8PrD/r3Uh/wBKBvhO/PAPUdLFMU7ILehnzirPCQYV6iueUUPc4/txBcU0QA6Ou9tFWL7/7GoRAPCpyDe+d44brYt/m2KJeA7ECtNAefM74eH6db2ETkVq4dh/3x/xV4YTOyPRdvVvhVtWa29GKBIMYNspza62LBGVk62i7d1MadeEgV/DpL767wgvofr5PiyXj8BC+Oxy7scu6JPGrbFFMNnoFivyGjX25xjy+jnflX3rwUNKW9wVm/AYTIeiRDvcEEoF6X8EN9NG5LY22Qd6+iaBMwhHHQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=XZwSDi93TxiryAvdDZBZd8LhuDo+f6iRycvqmEZJyTQ=; b=TUXGAycPR1yZZgEVxJ1WkBBsN3pVgHyWzW8tbDqIri3M3mVamWvihIQg3vxF4kKJ4QWjIHwSq1H9VDvS/THg/uuvr2+VPscwnFFMadv3j+ISB4YVCEyqkevqNzeNKoHU5PuhYuvr3UYBJFC0zpEjK3PJbujAWdkz4KwBx/yGaac= Received: from MN2PR08CA0011.namprd08.prod.outlook.com (2603:10b6:208:239::16) by SN7PR12MB6766.namprd12.prod.outlook.com (2603:10b6:806:26a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Thu, 30 May 2024 11:23:29 +0000 Received: from BL6PEPF0001AB73.namprd02.prod.outlook.com (2603:10b6:208:239:cafe::56) by MN2PR08CA0011.outlook.office365.com (2603:10b6:208:239::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.30 via Frontend Transport; Thu, 30 May 2024 11:23:29 +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 BL6PEPF0001AB73.mail.protection.outlook.com (10.167.242.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Thu, 30 May 2024 11:23:29 +0000 Received: from amd.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.35; Thu, 30 May 2024 06:23:26 -0500 From: Naveen Krishna Chatradhi To: , CC: , , , , Akshay Gupta , Akshay Gupta , Naveen Krishna Chatradhi Subject: [PATCH 1/5] hwmon/mfd sbrmi: Move core sbrmi from hwmon to MFD Date: Thu, 30 May 2024 11:23:03 +0000 Message-ID: <20240530112307.3089696-2-naveenkrishna.chatradhi@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240530112307.3089696-1-naveenkrishna.chatradhi@amd.com> References: <20240530112307.3089696-1-naveenkrishna.chatradhi@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@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: BL6PEPF0001AB73:EE_|SN7PR12MB6766:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b26e1ab-939c-4d7c-dc57-08dc809aee9d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|376005|36860700004|1800799015; X-Microsoft-Antispam-Message-Info: 4tfeYUvd5ianPUT7Fg/yUorgodMzjDSXWF56tlBd5Gu+qz99bxA9D/0dJ9R72JbO1vkY9UbMhEEi8SsxLjeYL6SSxsgeuIy76En5LAcFodmTqBhsc9h5BeLKpW87FfV9MnF37rFtf3FvZiKPX8CHtLT0joOOjWkH0dW/ojjHvRRJ60N7yLUvSowcY294TdFUA8qJsnqzVHBaWMoMma0A8IujzvAIth5ZeMwb+CgsNuSFGQeBkLpHOWVz9nvdd89/xx42fjTTI+47kqGNezQAA7SPX0tYKQ5ZdkxQFtW0AgDy+Gb8i4L/ePW6BhDEgcOcmfXOgHRyYhTeduO3xQndCQeMuOob1JMk90ytCaNGekLnJXdn8i8McxUkvgxrGXI7itE9yI7lpn7jJeY/A3lOvul1hdHQoZpMhzoBSyX+9WKCt1vmPp5wambviBMwzjBJw9tY3pxk5kNxnO1F8FYqnzwFc+ovhp7bAULfvVi7VaywXRiDL3Aa3pDo2yAmgH3v/gDSSu0gwLSku24jlPJ7BtOR+eaeDsaiFOG/xfT4if0LChZx48B2eS5Bn4DrzZdaPORWkq+Jf/IinnErNeL3GmlO24pb1PVRLFaalDukbSU3/HI0emcU5TQ+gFu/FJ2E3F+pgp7wheto5dVhXYAc6JpAJsQSWIYm3VPO9IIrtS8ttUYzozyvvh9x/Vxj/6L9EbiJF/yDUalebnsTnV2mXiAHP+P0fuVmXNrlqGR0cBTrLiX0rVhr/riiiSNOjzOqG5jOBVQMz33GbTV9ojLtRk9Brqt2XRNQAmtvSSZwdKlgzJopGpgg7IF7bKbehCVib0DtFtR2n61ZnbI7nyxm85hzyeuSD7uCN4ZklltXukBoyxMbSp3JuIHwyWHfu+t7W8od9MP37sEoYA10dPytZxR5yLICYXbx6UutX/wdSmnHa0fUqKcKMInIR1nBOCTvyvBuG/8kUUbnkksVVeShgUYR6AO4SIm2y1aRqYWhbNFaBTgTQKVitCkY/wTUEbbbdkCvGQv0vaHwrWBvxEN2xjm5+eJDwV3lF9bACrGtK8ZPmkf5P8Nxm/Qd/UHsaqQ7lORMfp7zybtlHxB5Ikz7IGjBBysiSKTRmGY4ZvxY7tUdWxzOyhVI/bpZtp7fvELMLICoU/mknod/ZYRGaZyIytxQMmd0lSUQh261kIC91BYhlimaVlCBMMl3/GyUC6QocGYUOzF1PbvNy5+VrXcKTY2D1EfWCuPYtH6iEnBCM6GojOTb5Zzl2J/81PcYVQez3jk+TuoQ4v8mM8M9pqD0jcXn6Tnv8D049VhqvAMtbS6MDeOxw0LrFVqY/bp7QyrOpI9PL5kD5pH2eJZaxgaCbFVM/QQoGKokjjxmmSGz9xsNfibfLA9HQiG+RAZsKsqC 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:(13230031)(82310400017)(376005)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2024 11:23:29.5940 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1b26e1ab-939c-4d7c-dc57-08dc809aee9d 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: BL6PEPF0001AB73.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6766 From: Akshay Gupta This is done to support other functionality provided by the SBRMI, which does not fit in the hwmon subsystem. - Move the core SBRMI core functionality and I2C device probing to MFD - Modify this module to be probed as a platform device by the MFD cell. Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi Acked-by: Guenter Roeck --- drivers/hwmon/Kconfig | 1 + drivers/hwmon/sbrmi.c | 245 +++---------------------------------- drivers/mfd/Kconfig | 10 +- drivers/mfd/Makefile | 2 + drivers/mfd/sbrmi-core.c | 137 +++++++++++++++++++++ drivers/mfd/sbrmi-i2c.c | 106 ++++++++++++++++ include/linux/mfd/amd-sb.h | 45 +++++++ 7 files changed, 316 insertions(+), 230 deletions(-) create mode 100644 drivers/mfd/sbrmi-core.c create mode 100644 drivers/mfd/sbrmi-i2c.c create mode 100644 include/linux/mfd/amd-sb.h diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index e14ae18a973b..56b73e665424 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1839,6 +1839,7 @@ config SENSORS_SBTSI config SENSORS_SBRMI tristate "Emulated SB-RMI sensor" depends on I2C + depends on MFD_SBRMI_I2C help If you say yes here you get support for emulated RMI sensors on AMD SoCs with APML interface connected to a BMC device. diff --git a/drivers/hwmon/sbrmi.c b/drivers/hwmon/sbrmi.c index d48d8e5460ff..aaeb5050eb0c 100644 --- a/drivers/hwmon/sbrmi.c +++ b/drivers/hwmon/sbrmi.c @@ -3,190 +3,18 @@ * sbrmi.c - hwmon driver for a SB-RMI mailbox * compliant AMD SoC device. * - * Copyright (C) 2020-2021 Advanced Micro Devices, Inc. + * Copyright (C) 2020-2024 Advanced Micro Devices, Inc. */ -#include #include #include -#include -#include +#include #include -#include -#include +#include +#include /* Do not allow setting negative power limit */ #define SBRMI_PWR_MIN 0 -/* Mask for Status Register bit[1] */ -#define SW_ALERT_MASK 0x2 - -/* Software Interrupt for triggering */ -#define START_CMD 0x80 -#define TRIGGER_MAILBOX 0x01 - -/* - * SB-RMI supports soft mailbox service request to MP1 (power management - * firmware) through SBRMI inbound/outbound message registers. - * SB-RMI message IDs - */ -enum sbrmi_msg_id { - SBRMI_READ_PKG_PWR_CONSUMPTION = 0x1, - SBRMI_WRITE_PKG_PWR_LIMIT, - SBRMI_READ_PKG_PWR_LIMIT, - SBRMI_READ_PKG_MAX_PWR_LIMIT, -}; - -/* SB-RMI registers */ -enum sbrmi_reg { - SBRMI_CTRL = 0x01, - SBRMI_STATUS, - SBRMI_OUTBNDMSG0 = 0x30, - SBRMI_OUTBNDMSG1, - SBRMI_OUTBNDMSG2, - SBRMI_OUTBNDMSG3, - SBRMI_OUTBNDMSG4, - SBRMI_OUTBNDMSG5, - SBRMI_OUTBNDMSG6, - SBRMI_OUTBNDMSG7, - SBRMI_INBNDMSG0, - SBRMI_INBNDMSG1, - SBRMI_INBNDMSG2, - SBRMI_INBNDMSG3, - SBRMI_INBNDMSG4, - SBRMI_INBNDMSG5, - SBRMI_INBNDMSG6, - SBRMI_INBNDMSG7, - SBRMI_SW_INTERRUPT, -}; - -/* Each client has this additional data */ -struct sbrmi_data { - struct i2c_client *client; - struct mutex lock; - u32 pwr_limit_max; -}; - -struct sbrmi_mailbox_msg { - u8 cmd; - bool read; - u32 data_in; - u32 data_out; -}; - -static int sbrmi_enable_alert(struct i2c_client *client) -{ - int ctrl; - - /* - * Enable the SB-RMI Software alert status - * by writing 0 to bit 4 of Control register(0x1) - */ - ctrl = i2c_smbus_read_byte_data(client, SBRMI_CTRL); - if (ctrl < 0) - return ctrl; - - if (ctrl & 0x10) { - ctrl &= ~0x10; - return i2c_smbus_write_byte_data(client, - SBRMI_CTRL, ctrl); - } - - return 0; -} - -static int rmi_mailbox_xfer(struct sbrmi_data *data, - struct sbrmi_mailbox_msg *msg) -{ - int i, ret, retry = 10; - int sw_status; - u8 byte; - - mutex_lock(&data->lock); - - /* Indicate firmware a command is to be serviced */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG7, START_CMD); - if (ret < 0) - goto exit_unlock; - - /* Write the command to SBRMI::InBndMsg_inst0 */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG0, msg->cmd); - if (ret < 0) - goto exit_unlock; - - /* - * For both read and write the initiator (BMC) writes - * Command Data In[31:0] to SBRMI::InBndMsg_inst[4:1] - * SBRMI_x3C(MSB):SBRMI_x39(LSB) - */ - for (i = 0; i < 4; i++) { - byte = (msg->data_in >> i * 8) & 0xff; - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG1 + i, byte); - if (ret < 0) - goto exit_unlock; - } - - /* - * Write 0x01 to SBRMI::SoftwareInterrupt to notify firmware to - * perform the requested read or write command - */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); - if (ret < 0) - goto exit_unlock; - - /* - * Firmware will write SBRMI::Status[SwAlertSts]=1 to generate - * an ALERT (if enabled) to initiator (BMC) to indicate completion - * of the requested command - */ - do { - sw_status = i2c_smbus_read_byte_data(data->client, - SBRMI_STATUS); - if (sw_status < 0) { - ret = sw_status; - goto exit_unlock; - } - if (sw_status & SW_ALERT_MASK) - break; - usleep_range(50, 100); - } while (retry--); - - if (retry < 0) { - dev_err(&data->client->dev, - "Firmware fail to indicate command completion\n"); - ret = -EIO; - goto exit_unlock; - } - - /* - * For a read operation, the initiator (BMC) reads the firmware - * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1] - * {SBRMI_x34(MSB):SBRMI_x31(LSB)}. - */ - if (msg->read) { - for (i = 0; i < 4; i++) { - ret = i2c_smbus_read_byte_data(data->client, - SBRMI_OUTBNDMSG1 + i); - if (ret < 0) - goto exit_unlock; - msg->data_out |= ret << i * 8; - } - } - - /* - * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the - * ALERT to initiator - */ - ret = i2c_smbus_write_byte_data(data->client, SBRMI_STATUS, - sw_status | SW_ALERT_MASK); - -exit_unlock: - mutex_unlock(&data->lock); - return ret; -} static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) @@ -282,76 +110,35 @@ static const struct hwmon_chip_info sbrmi_chip_info = { .info = sbrmi_info, }; -static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) +static int sbrmi_probe(struct platform_device *pdev) { - struct sbrmi_mailbox_msg msg = { 0 }; - int ret; - - msg.cmd = SBRMI_READ_PKG_MAX_PWR_LIMIT; - msg.read = true; - ret = rmi_mailbox_xfer(data, &msg); - if (ret < 0) - return ret; - data->pwr_limit_max = msg.data_out; - - return ret; -} - -static int sbrmi_probe(struct i2c_client *client) -{ - struct device *dev = &client->dev; + struct device *dev = &pdev->dev; struct device *hwmon_dev; - struct sbrmi_data *data; - int ret; - - data = devm_kzalloc(dev, sizeof(struct sbrmi_data), GFP_KERNEL); - if (!data) - return -ENOMEM; - - data->client = client; - mutex_init(&data->lock); - - /* Enable alert for SB-RMI sequence */ - ret = sbrmi_enable_alert(client); - if (ret < 0) - return ret; + struct sbrmi_data *data = dev_get_drvdata(pdev->dev.parent); - /* Cache maximum power limit */ - ret = sbrmi_get_max_pwr_limit(data); - if (ret < 0) - return ret; - - hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data, + hwmon_dev = devm_hwmon_device_register_with_info(dev, "sbrmi", data, &sbrmi_chip_info, NULL); - return PTR_ERR_OR_ZERO(hwmon_dev); } -static const struct i2c_device_id sbrmi_id[] = { - {"sbrmi"}, - {} -}; -MODULE_DEVICE_TABLE(i2c, sbrmi_id); - -static const struct of_device_id __maybe_unused sbrmi_of_match[] = { +static const struct platform_device_id sbrmi_id[] = { { - .compatible = "amd,sbrmi", + .name = "sbrmi-hwmon", }, { }, }; -MODULE_DEVICE_TABLE(of, sbrmi_of_match); +MODULE_DEVICE_TABLE(platform, sbrmi_id); -static struct i2c_driver sbrmi_driver = { +static struct platform_driver amd_sbrmi_hwmon_driver = { + .probe = sbrmi_probe, .driver = { - .name = "sbrmi", - .of_match_table = of_match_ptr(sbrmi_of_match), + .name = "amd-sbrmi", }, - .probe = sbrmi_probe, .id_table = sbrmi_id, }; - -module_i2c_driver(sbrmi_driver); +module_platform_driver(amd_sbrmi_hwmon_driver); MODULE_AUTHOR("Akshay Gupta "); +MODULE_AUTHOR("Naveen Krishna Chatradhi "); MODULE_DESCRIPTION("Hwmon driver for AMD SB-RMI emulated sensor"); MODULE_LICENSE("GPL"); diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 266b4f54af60..0411cb29b6df 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -1442,6 +1442,15 @@ config MFD_STMPE Touchscreen: stmpe-ts ADC: stmpe-adc +config MFD_SBRMI_I2C + tristate "APML SBRMI support" + depends on I2C + select MFD_CORE + help + APML RMI core support for AMD out of band management + This driver can also be built as a module. If so, the module will + be called sbrmi. + menu "STMicroelectronics STMPE Interface Drivers" depends on MFD_STMPE @@ -2333,6 +2342,5 @@ config MFD_RSMU_SPI This driver provides common support for accessing the device. Additional drivers must be enabled in order to use the functionality of the device. - endmenu endif diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index c66f07edcd0e..6bc807c2e5ed 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -284,3 +284,5 @@ rsmu-i2c-objs := rsmu_core.o rsmu_i2c.o rsmu-spi-objs := rsmu_core.o rsmu_spi.o obj-$(CONFIG_MFD_RSMU_I2C) += rsmu-i2c.o obj-$(CONFIG_MFD_RSMU_SPI) += rsmu-spi.o +apml_sbrmi-objs := sbrmi-i2c.o sbrmi-core.o +obj-$(CONFIG_MFD_SBRMI_I2C) += apml_sbrmi.o diff --git a/drivers/mfd/sbrmi-core.c b/drivers/mfd/sbrmi-core.c new file mode 100644 index 000000000000..d872b5107b36 --- /dev/null +++ b/drivers/mfd/sbrmi-core.c @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * sbrmi-common.c - file defining SB-RMI protocols + * compliant AMD SoC device. + * + * Copyright (C) 2021-2024 Advanced Micro Devices, Inc. + */ +#include +#include +#include +#include +#include + +/* Mask for Status Register bit[1] */ +#define SW_ALERT_MASK 0x2 + +/* Software Interrupt for triggering */ +#define START_CMD 0x80 +#define TRIGGER_MAILBOX 0x01 + +/* SB-RMI registers */ +enum sbrmi_reg { + SBRMI_CTRL = 0x01, + SBRMI_STATUS, + SBRMI_OUTBNDMSG0 = 0x30, + SBRMI_OUTBNDMSG1, + SBRMI_OUTBNDMSG2, + SBRMI_OUTBNDMSG3, + SBRMI_OUTBNDMSG4, + SBRMI_OUTBNDMSG5, + SBRMI_OUTBNDMSG6, + SBRMI_OUTBNDMSG7, + SBRMI_INBNDMSG0, + SBRMI_INBNDMSG1, + SBRMI_INBNDMSG2, + SBRMI_INBNDMSG3, + SBRMI_INBNDMSG4, + SBRMI_INBNDMSG5, + SBRMI_INBNDMSG6, + SBRMI_INBNDMSG7, + SBRMI_SW_INTERRUPT, +}; + +int rmi_mailbox_xfer(struct sbrmi_data *data, + struct sbrmi_mailbox_msg *msg) +{ + int i, ret, retry = 10; + int sw_status; + u8 byte; + + mutex_lock(&data->lock); + + /* Indicate firmware a command is to be serviced */ + ret = i2c_smbus_write_byte_data(data->client, + SBRMI_INBNDMSG7, START_CMD); + if (ret < 0) + goto exit_unlock; + + /* Write the command to SBRMI::InBndMsg_inst0 */ + ret = i2c_smbus_write_byte_data(data->client, + SBRMI_INBNDMSG0, msg->cmd); + if (ret < 0) + goto exit_unlock; + + /* + * For both read and write the initiator (BMC) writes + * Command Data In[31:0] to SBRMI::InBndMsg_inst[4:1] + * SBRMI_x3C(MSB):SBRMI_x39(LSB) + */ + for (i = 0; i < 4; i++) { + byte = (msg->data_in >> i * 8) & 0xff; + ret = i2c_smbus_write_byte_data(data->client, + SBRMI_INBNDMSG1 + i, byte); + if (ret < 0) + goto exit_unlock; + } + + /* + * Write 0x01 to SBRMI::SoftwareInterrupt to notify firmware to + * perform the requested read or write command + */ + ret = i2c_smbus_write_byte_data(data->client, + SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); + if (ret < 0) + goto exit_unlock; + + /* + * Firmware will write SBRMI::Status[SwAlertSts]=1 to generate + * an ALERT (if enabled) to initiator (BMC) to indicate completion + * of the requested command + */ + do { + sw_status = i2c_smbus_read_byte_data(data->client, + SBRMI_STATUS); + if (sw_status < 0) { + ret = sw_status; + goto exit_unlock; + } + if (sw_status & SW_ALERT_MASK) + break; + usleep_range(50, 100); + } while (retry--); + + if (retry < 0) { + dev_err(&data->client->dev, + "Firmware fail to indicate command completion\n"); + ret = -EIO; + goto exit_unlock; + } + + /* + * For a read operation, the initiator (BMC) reads the firmware + * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1] + * {SBRMI_x34(MSB):SBRMI_x31(LSB)}. + */ + if (msg->read) { + for (i = 0; i < 4; i++) { + ret = i2c_smbus_read_byte_data(data->client, + SBRMI_OUTBNDMSG1 + i); + if (ret < 0) + goto exit_unlock; + msg->data_out |= ret << i * 8; + } + } + + /* + * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the + * ALERT to initiator + */ + ret = i2c_smbus_write_byte_data(data->client, SBRMI_STATUS, + sw_status | SW_ALERT_MASK); + +exit_unlock: + mutex_unlock(&data->lock); + return ret; +} +EXPORT_SYMBOL(rmi_mailbox_xfer); diff --git a/drivers/mfd/sbrmi-i2c.c b/drivers/mfd/sbrmi-i2c.c new file mode 100644 index 000000000000..96215e986740 --- /dev/null +++ b/drivers/mfd/sbrmi-i2c.c @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * sbrmi.c - hwmon driver for a SB-RMI mailbox + * compliant AMD SoC device. + * + * Copyright (C) 2020-2024 Advanced Micro Devices, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define SBRMI_CTRL 0x1 + +static int sbrmi_enable_alert(struct i2c_client *client) +{ + int ctrl; + + /* + * Enable the SB-RMI Software alert status + * by writing 0 to bit 4 of Control register(0x1) + */ + ctrl = i2c_smbus_read_byte_data(client, SBRMI_CTRL); + if (ctrl < 0) + return ctrl; + + if (ctrl & 0x10) { + ctrl &= ~0x10; + return i2c_smbus_write_byte_data(client, + SBRMI_CTRL, ctrl); + } + + return 0; +} + +static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) +{ + struct sbrmi_mailbox_msg msg = { 0 }; + int ret; + + msg.cmd = SBRMI_READ_PKG_MAX_PWR_LIMIT; + msg.read = true; + ret = rmi_mailbox_xfer(data, &msg); + if (ret < 0) + return ret; + data->pwr_limit_max = msg.data_out; + + return ret; +} + +static int sbrmi_i2c_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct sbrmi_data *data; + int ret; + + data = devm_kzalloc(dev, sizeof(struct sbrmi_data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->client = client; + mutex_init(&data->lock); + + /* Enable alert for SB-RMI sequence */ + ret = sbrmi_enable_alert(client); + if (ret < 0) + return ret; + + /* Cache maximum power limit */ + return sbrmi_get_max_pwr_limit(data); +} + +static const struct i2c_device_id sbrmi_id[] = { + {"sbrmi-mfd"}, + {} +}; +MODULE_DEVICE_TABLE(i2c, sbrmi_id); + +static const struct of_device_id __maybe_unused sbrmi_of_match[] = { + { + .compatible = "amd,sbrmi", + }, + { }, +}; +MODULE_DEVICE_TABLE(of, sbrmi_of_match); + +static struct i2c_driver sbrmi_driver = { + .driver = { + .name = "sbrmi-mfd", + .of_match_table = of_match_ptr(sbrmi_of_match), + }, + .probe = sbrmi_i2c_probe, + .id_table = sbrmi_id, +}; + +module_i2c_driver(sbrmi_driver); + +MODULE_AUTHOR("Akshay Gupta "); +MODULE_AUTHOR("Naveen Krishna Chatradhi "); +MODULE_DESCRIPTION("Hwmon driver for AMD SB-RMI emulated sensor"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/mfd/amd-sb.h b/include/linux/mfd/amd-sb.h new file mode 100644 index 000000000000..7805f31fb6ea --- /dev/null +++ b/include/linux/mfd/amd-sb.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2021-2024 Advanced Micro Devices, Inc. + */ + +#ifndef _AMD_SB_H_ +#define _AMD_SB_H_ + +#include +#include +/* + * SB-RMI supports soft mailbox service request to MP1 (power management + * firmware) through SBRMI inbound/outbound message registers. + * SB-RMI message IDs + */ +enum sbrmi_msg_id { + SBRMI_READ_PKG_PWR_CONSUMPTION = 0x1, + SBRMI_WRITE_PKG_PWR_LIMIT, + SBRMI_READ_PKG_PWR_LIMIT, + SBRMI_READ_PKG_MAX_PWR_LIMIT, +}; + +/* Each client has this additional data */ +struct sbrmi_data { + struct i2c_client *client; + struct mutex lock; + u32 pwr_limit_max; +}; + +struct sbrmi_mailbox_msg { + u8 cmd; + bool read; + u32 data_in; + u32 data_out; +}; + +#if IS_ENABLED(CONFIG_MFD_SBRMI_I2C) +int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg); +#else +int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg) +{ + return -EOPNOTSUPP; +} +#endif +#endif /*_AMD_SB_H_*/ From patchwork Thu May 30 11:23:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chatradhi, Naveen Krishna" X-Patchwork-Id: 13680287 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2085.outbound.protection.outlook.com [40.107.92.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 03EF4172BB6 for ; Thu, 30 May 2024 11:23:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717068218; cv=fail; b=Ytxec0cTSJvxx7gN8oy5oBseiE+8KkWbmpN6aeoxJ/y92f1vPU5U9sI0YKmsdb2H+0c/0vUEzzji9KCRfZStcWgYbR5u0N8gV9XIkLSQkdQgMAf37TU4g3puzqS4tBUKqQ6jrvCPGJVkx8y7rQGwqtnfUv/owewKgTKKPXOIGsA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717068218; c=relaxed/simple; bh=YpMnCcz6+6J4+dwcgAGF4/fC3Hxanu3BumLZR6eTSLQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RSDl+Olq52XlBD/GleZg3a5WgXoljDpGvnTjhPT+G7L11I92wG9RDLPRFAdVBhopwNbq5zUqkQjjjA4TJIIObRmgmp6iBiQE9o6mEy6eCG9vJ8VJMOae5yq35EocZZjD84S8cyuTENW5yDP4uCVjbQVJzF992TbCAPJcMZQ4u1s= 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=hAn6EWfc; arc=fail smtp.client-ip=40.107.92.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="hAn6EWfc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T1AIhBS2b9PobIVUhpD94GGtkmJ6nm3cvjbbCKuSDZWNPITm4XxuOIMc2Y+46wSKlwlUs2uuYteJT0QVAmkoBHvZmPnmfwhN5q74ZstGKPUE60zkQvYrnreTg00ufE9Aj2ojKcX4EDW3l4rR8vRXQu2D0cSiaf4qFB/gebRvyxLSn46du45AUAtJZgaIh/EOYawHUaCJx67gPRAcXbfN8zOS5J4SLOw580yBM9b7SNDkrTNpa40vdAJ6U8ECmEQkQByocLINNkjuFiw1iLdnl6lK8rWakA8E3MdOq30QjaW6pQ1WdKaPEpelL87/B1aoUEAropQH2im0Ov0/jV05yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=DnzIYo4FoOolVYVpaH6VSx4ur0ijZvULLeIw/KV+wDE=; b=AMtVHrenb9bMkfKbw1/o6XWfuF/mmupFBbCjrp2pCZM1lvf3n0xXFzggKIlVcEnGRFbt+YjVyGnTSZ69ZoHCPy3a/v7Q/PbdV+TVTkZ5XXjtjZmBvTtm9VgoBfSotb8W4fLWVxzqr1/5GmKz2BLt1CgYM8THHwtQ0e2b39tozEJk3v+O07hIpC/+6PwyxpidwSiqmMOEfBcyYE+Wzn+w5vaC+9PkZvcgu1WlbYw2Ed6u0BJRBuagm3IQTw0nB2wTSZbM+PmOTDMCHc+NxOBv6ViO9/MDiROpqie5iVnVA3vig/2D/EZgocPNzlO97Duxv6iLBKPc7j3zSabEOy6amw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=DnzIYo4FoOolVYVpaH6VSx4ur0ijZvULLeIw/KV+wDE=; b=hAn6EWfczy2ecnqclSu7DDKZQ4uTgGL2YJMbiNdBDzGFwQJKZ+iQio7n5YeQ+mAqOFRhAoQTK9phxMnq3TQF/VKWM4OoD4jUeeB0nUTjTi0ZSHnJN4LPzI9JHyvWk5NFZYka4EIwax6zlSU0qjowLighqGUOznl5YD/ewKS1Zsw= Received: from MN2PR17CA0026.namprd17.prod.outlook.com (2603:10b6:208:15e::39) by PH8PR12MB6986.namprd12.prod.outlook.com (2603:10b6:510:1bd::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.27; Thu, 30 May 2024 11:23:34 +0000 Received: from BL6PEPF0001AB74.namprd02.prod.outlook.com (2603:10b6:208:15e:cafe::25) by MN2PR17CA0026.outlook.office365.com (2603:10b6:208:15e::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.30 via Frontend Transport; Thu, 30 May 2024 11:23:33 +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 BL6PEPF0001AB74.mail.protection.outlook.com (10.167.242.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Thu, 30 May 2024 11:23:33 +0000 Received: from amd.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.35; Thu, 30 May 2024 06:23:30 -0500 From: Naveen Krishna Chatradhi To: , CC: , , , , Akshay Gupta , Akshay Gupta , Naveen Krishna Chatradhi Subject: [PATCH 2/5] mfd: sbrmi: Add mfd cell in the probe Date: Thu, 30 May 2024 11:23:04 +0000 Message-ID: <20240530112307.3089696-3-naveenkrishna.chatradhi@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240530112307.3089696-1-naveenkrishna.chatradhi@amd.com> References: <20240530112307.3089696-1-naveenkrishna.chatradhi@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@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: BL6PEPF0001AB74:EE_|PH8PR12MB6986:EE_ X-MS-Office365-Filtering-Correlation-Id: 22e225c4-1817-40a5-2518-08dc809af124 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|82310400017|1800799015|376005; X-Microsoft-Antispam-Message-Info: USAmwgU0aiSyuwdsYLwKLFnPVBdYWAIOYVAwIxyuMvSTeqKyH0lQsAzn+CMTar4xm8wnKpMjgToNxKfwdIwLSdXJt8QBPkiAia+0OPI0iQVT5BgQwyOiFxR7KTdJfS0DAb54BICzBb2jx7N7qE+gbfX+R7PvPp+MqOGEMaZdd75yrNQnyIQXEGI30OeJaVOhkQFxI2kAxxJDcyfVkNL1AFLkw6f2wkieimMaiKXDuTeOM3shqV0emy/bCQLYjsfBG74yaJMvfelKEUCm40ygtIYRYuJpQzHGk+T4351IMWYLo1oliIcE+2bVjR5I0Q2vJcBy/Lr28ffLkQcIDSQBWkBCJqEK/4iA4AS4jgGdQ9XI2+CTXtxw9yTY5zcupvBS+qUUabdexYAnX039rrNM8/XQCnRE7trjtLZCqwz6zkzWK8fEYqcDx1WqHGPIvwSz7NsoA8XEtaZ9rWuQPpbV+Tr+YIgZgQDLDVXjcNEMJMbAIkIdO8mVtE63+EC8TyCtkhd6EWJ06GkyLcNCne2iYuYassg7xLezTXDtCS1WTu3asYkr/nv29L38KucTk64Rjqp7azBNIdwOSCzg0CUojAr9BjpXeY8KagBF68sIhrJr3O0iHwB9+jYM6NRnaozDi8MBwyLaH5hJgsBJgDyVANNWBqGFC+EOapjTE6g1zX94FNR2H6X0oXfwP1Dgv/6qup0wSF/7LN2IAUFOL1XOoRN4hgkjH8ir+iW5Nob7oZf+v14W/I20GdEyyHZ5ZCfqJ4sUJRiGjLuKhLQvwJEHaWqRVEwYTU7/jOXOMIZiiDb9JvNtVTB5PvSMkd9pIr38azCa7b0S08vpMDaJfC98gcvQFnrjDcnsiKj6yrbx+acCnazgk4x+M9Gn0x7L89J/BW7zDJ8vTnIgHdudLrpUIvbqRGgOQK+0vg5uc6g6R735+aaVfYE4Rk4DBhkc2Y98jsusIBhDZRWWL8B4do3rbweG38dR65efx59FeyFkxDuiMN8wLzkUbK8WnrA1zKhX3pF6wLS0S+eJRfqJNjoP3kN2lIPmALg6x0ZHtT2kMR1hYDLo9GwasEoo7JPAbk4xT/eKLX02F0tGdASJqAcuHA2x0s+nYuoCuqVF6QkrZ81NdGjuaFkR8htbK8zYXKjCLVUQ/n/EGBmaXYKglL1IUOwAqbotfQXMDJ9svnd8fv3sSmpbPrfPyMzdUP76u8KK1Pt1ON0tqrtcESlvsMLwlmbw5YCKuIxXc45FAqMRbtO6m850jjudy+bObjMZmAJzQbyNvSOd7ueBxVHikO2LvzOM+smGNGpClIdyhsSqTc12y/e1o/3h2zepzU2x3ysQ0duV3p3Z0OyJLQLvWUw6PZrRwGRZ/uOSpdheLduEjtYY0JdCO/17ztuNoyPZf7n2 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:(13230031)(36860700004)(82310400017)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2024 11:23:33.8295 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22e225c4-1817-40a5-2518-08dc809af124 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: BL6PEPF0001AB74.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6986 From: Akshay Gupta - AMD provides socket power information from out of band which can be read by sensors. - mfd cell will probe the drivers/hwmon/sbrmi as a platform device and share the sbrmi device data. Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi --- drivers/mfd/sbrmi-i2c.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/mfd/sbrmi-i2c.c b/drivers/mfd/sbrmi-i2c.c index 96215e986740..c19f0b3eb0cd 100644 --- a/drivers/mfd/sbrmi-i2c.c +++ b/drivers/mfd/sbrmi-i2c.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -17,6 +18,10 @@ #define SBRMI_CTRL 0x1 +static struct mfd_cell apml_sbrmi[] = { + { .name = "sbrmi-hwmon" }, +}; + static int sbrmi_enable_alert(struct i2c_client *client) { int ctrl; @@ -72,7 +77,17 @@ static int sbrmi_i2c_probe(struct i2c_client *client) return ret; /* Cache maximum power limit */ - return sbrmi_get_max_pwr_limit(data); + ret = sbrmi_get_max_pwr_limit(data); + if (ret < 0) + return ret; + + dev_set_drvdata(dev, (void *)data); + + ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, apml_sbrmi, + ARRAY_SIZE(apml_sbrmi), NULL, 0, NULL); + if (ret) + dev_err(dev, "Failed to register for sub-devices: %d\n", ret); + return ret; } static const struct i2c_device_id sbrmi_id[] = { From patchwork Thu May 30 11:23:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chatradhi, Naveen Krishna" X-Patchwork-Id: 13680288 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2076.outbound.protection.outlook.com [40.107.94.76]) (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 5F59D172BB6 for ; Thu, 30 May 2024 11:23:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717068224; cv=fail; b=uKQbymBPZ8hIbhVCyhfOZTY18XwatQ48+6FPPau1w6XwyJdm69o+ZZ129i/ktRmZamXNOKlJx0Y+kMTGmBg0Pw6BxMgIVRIdQPR+1UeRw4IMHoz1qu3CkGwbmYoADbgJg2ElO3q54xTIQWNZGxaRapTtJvmj//3HyO5NlchY80o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717068224; c=relaxed/simple; bh=PxySybW7jGzVog/pejsCPcZ9NQ14hsNEb9HoSO5NFVg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gTRNWiOUjj7vsbebTSMWORTp5gBajsh+hSrx55lQTfLmTg8CxxWzfaIo8SoGHZhq3B/MlZHigXPks6wF9n0I+VzYehGY9Fk+gi+xGAgBCvYfiUOyW5KQtc/ufyUAPooOnEbWOMVWqv6F65CR8x6mK5WGmUHlEADkUUJmT5GoygQ= 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=GOVmSwZc; arc=fail smtp.client-ip=40.107.94.76 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="GOVmSwZc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m6gbg4W9rjL0nsCvTfhpuhzD0qpmWY02y0Sd9actuADa6FptH3KxR2lT084oZfUDIFFQdhUpBD7X+/JiLpTeO9TIS3Vw9xyGv9KKKvCVLCP95Zj8QQseX6xWm8PJazJMTqA2GCK5xXlDgHYsTVBEeWxewONr/i74HwYLYCBQIaT5zxou7BjMYWcqo4rcC1qxUI0IP8Z7cYqdhHAILJhj3zs4YqhVZTEhwA79SueVIoE8+nW4NzcJvcoagiR+LlgWf092COYETYluALf8tmGt5KMnsIa66BcJT0N/li52RSOfKdMv4xRzXhtJ/ubsAVekjLIfBd4lWEW46jLPLaIPhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=j/Dq9w3snoL1gbr9sgG9jyujvGJq9GfbkvY6dE48EvI=; b=jst09A2i3GdHTsu2CsvQmJh9IAvuF1/4bAPCh3FXxRC3V762LER/401xHPQHqhQEOFun7AlO4yyKqwlBhonSwL0amU3Ni49q8RNFdjVPBjXEOg5IGb8AuqYhCmPm2/WsZqy7HtfmooS+oSSuEZYfrWHNknbb/V09CsWdgAN28p5H0RhiXptcZaS5ow3ynW0tJjb843hBg3JZmgnIIsW5l3Y4gbbRbGD1GLWShB8bCN7rspYp4pKBwbRScy948s2wNl3Bsmclac3xT6xKk6uOyFRlp+T9kyVz6WiKw+tkPxPd0+05WIo1LVPaXNaECyr3uMoQCPSgGVqXApFI6YLBuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=j/Dq9w3snoL1gbr9sgG9jyujvGJq9GfbkvY6dE48EvI=; b=GOVmSwZc5OnCs25VL2Gca7OGJ8l5WG40C89EN4+Ew0OMQByCyBoS1ZfrYfgM1pHpBpgcCoKxqJvWm3fWJ65f89uXo1GEBra2K1B5H0j7aDsec6YXMiMizqjXde8l1CWX0kYmHcfd96y8uTUZiawQK5bLJqPm51NTWtlVyvvX33o= Received: from MN2PR17CA0035.namprd17.prod.outlook.com (2603:10b6:208:15e::48) by DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22; Thu, 30 May 2024 11:23:38 +0000 Received: from BL6PEPF0001AB74.namprd02.prod.outlook.com (2603:10b6:208:15e:cafe::da) by MN2PR17CA0035.outlook.office365.com (2603:10b6:208:15e::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21 via Frontend Transport; Thu, 30 May 2024 11:23:38 +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 BL6PEPF0001AB74.mail.protection.outlook.com (10.167.242.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Thu, 30 May 2024 11:23:38 +0000 Received: from amd.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.35; Thu, 30 May 2024 06:23:34 -0500 From: Naveen Krishna Chatradhi To: , CC: , , , , Akshay Gupta , Akshay Gupta , Naveen Krishna Chatradhi Subject: [PATCH 3/5] mfd/hwmon sbrmi: Use regmap subsystem Date: Thu, 30 May 2024 11:23:05 +0000 Message-ID: <20240530112307.3089696-4-naveenkrishna.chatradhi@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240530112307.3089696-1-naveenkrishna.chatradhi@amd.com> References: <20240530112307.3089696-1-naveenkrishna.chatradhi@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@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: BL6PEPF0001AB74:EE_|DM6PR12MB4092:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a93da91-a173-463c-1d1b-08dc809af3c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|36860700004|82310400017|376005; X-Microsoft-Antispam-Message-Info: H9x4GeTkCnL0urozHqeGPlJ/tEG4aAviz9bsdb2jnpbu1jx9soJrEDRqURMGE707xYMkZGgaTwOQkaSyILlZgEXCRnTOPFd4XFdBR/+gC2oS8OR1pGGOBSWTjJsr/3b4ffl23DJg3T1ocqi8ZNJcAsyaQnpMMJ4c7uqUAxPpgRdFBc6anmsdJkRQMpDWD81wm2g8owcD1iHBXmrV7WQNt4lUe2i2HEKeO6+zml4AvdI1dH6utUnVZJDrAFaO6iC3PQaE9DEknxlp0K8NeRUd0vGhh0RmIvvViz1SwT4Xo95K1RQWv6mDe3tnHZFjXhh04I7KGtmbX/y19XRpkdtqkZKUs212AsnorA0lZgO30PHqGay6LG2/GYH5tUVCMkI79vcowaCVCh+aqZnpZyGjcVGIEJBqRJQ3nsuUeMclL9X/JrasB7ZjPa22p+7lz0bKGrqeO1q1kN4IWHwmDi88x87HD8ZJVm34YHJdDul62eQxcv7DH63wDrEXzJfvR3y9qA9jBUXNoXhrAXEOyxwxpSMG6zf8Ro7JI/4ikj/QcI5sjGGaFnqVV2k6vgzI0PB96EKm64p0/KQ1EmkIHW3OTdkN0Ao0OQ4fBjRINtNG1CLixdKOOTa43bsHnGalTc8iSU9frwXTRya0mxKoisW4mL1guQquwxYRSGhxSI4zAzsFLbnn+e4PUL4pGzzWfaK/plwmVFC+VCJVvaxp8GvcKqmdiP9DVlmWpDcNiq/GzN8WQQQNrcxYfYoq2TCt4J6KL/MzrmVplcyZygzvKmd19eyeUoXU1kiw7T7Tja+97dstnKfVFUe8I4G81KKHerBaeiBOdnrHaKUwOh4Mp0kBsvRsgcCQBhVcsVaPLGRiKbooeHtwF9jVy9RlZFFJm2aIQCeK3GRVYjV6XuEJMH5z6VL/kXhC8wSTv6qCTAusaQEvxNPyGKVZlWJIfWoyPzv/8pkoJGMDoTVnV2LqJaz6aaeuQ72LgpUz/6RXWa6yqj9Xjexazvd5lAkHlihK2Fa2DJsUe6J/1czhXI2XQ5UzYDaVIVfxLMUbEoAEEuO3OTPJI5EvC4j1mIZWllqFr7IgWjKzygVWQ3PQ0XNoakW50iwR6yk4XvcafGJV0jXfdfEXywmsglTWlBeO0bTvqtuwAW0v0CE5VZUzzuy8mo6TC45D26cTfvYf26smXnI/XEgVDokDQR84eOtnPIiMkc8Xs0oivakdq/9Z110oST+gahGheQUHXrRx8UmH8Sb+VWq58ZODF0ihnLhu5HFAbv/SOjWXbqbyCgjCGgkkoOzN8NgvigsptoRPtTCZ7hxRv3qIJZnSFvLuwbjhiabnrszpZYn0L0lsWRtSfWVms7S/AN+KkXdsFS2s6uCj4ELedqiiNarvSfnFIP1ayMusO95A 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:(13230031)(1800799015)(36860700004)(82310400017)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2024 11:23:38.2202 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a93da91-a173-463c-1d1b-08dc809af3c2 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: BL6PEPF0001AB74.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 From: Akshay Gupta - regmap subsystem provides multiple benefits over direct smbus APIs - The susbsytem can be helpful in following cases - Differnet types of bus (i2c/i3c) - Different Register address size (1byte/2byte) Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi --- drivers/mfd/Kconfig | 2 +- drivers/mfd/sbrmi-core.c | 30 ++++++++++++------------------ drivers/mfd/sbrmi-i2c.c | 25 ++++++++++++++++--------- include/linux/mfd/amd-sb.h | 6 +++--- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 0411cb29b6df..d89513e5a06b 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -1444,8 +1444,8 @@ config MFD_STMPE config MFD_SBRMI_I2C tristate "APML SBRMI support" - depends on I2C select MFD_CORE + select REGMAP_I2C help APML RMI core support for AMD out of band management This driver can also be built as a module. If so, the module will diff --git a/drivers/mfd/sbrmi-core.c b/drivers/mfd/sbrmi-core.c index d872b5107b36..5617b91787ba 100644 --- a/drivers/mfd/sbrmi-core.c +++ b/drivers/mfd/sbrmi-core.c @@ -7,9 +7,9 @@ */ #include #include -#include #include #include +#include /* Mask for Status Register bit[1] */ #define SW_ALERT_MASK 0x2 @@ -44,6 +44,7 @@ enum sbrmi_reg { int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg) { + unsigned int bytes; int i, ret, retry = 10; int sw_status; u8 byte; @@ -51,14 +52,12 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, mutex_lock(&data->lock); /* Indicate firmware a command is to be serviced */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG7, START_CMD); + ret = regmap_write(data->regmap, SBRMI_INBNDMSG7, START_CMD); if (ret < 0) goto exit_unlock; /* Write the command to SBRMI::InBndMsg_inst0 */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG0, msg->cmd); + ret = regmap_write(data->regmap, SBRMI_INBNDMSG0, msg->cmd); if (ret < 0) goto exit_unlock; @@ -69,8 +68,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, */ for (i = 0; i < 4; i++) { byte = (msg->data_in >> i * 8) & 0xff; - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_INBNDMSG1 + i, byte); + ret = regmap_write(data->regmap, SBRMI_INBNDMSG1 + i, byte); if (ret < 0) goto exit_unlock; } @@ -79,8 +77,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * Write 0x01 to SBRMI::SoftwareInterrupt to notify firmware to * perform the requested read or write command */ - ret = i2c_smbus_write_byte_data(data->client, - SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); + ret = regmap_write(data->regmap, SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); if (ret < 0) goto exit_unlock; @@ -90,8 +87,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * of the requested command */ do { - sw_status = i2c_smbus_read_byte_data(data->client, - SBRMI_STATUS); + ret = regmap_read(data->regmap, SBRMI_STATUS, &sw_status); if (sw_status < 0) { ret = sw_status; goto exit_unlock; @@ -102,8 +98,6 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, } while (retry--); if (retry < 0) { - dev_err(&data->client->dev, - "Firmware fail to indicate command completion\n"); ret = -EIO; goto exit_unlock; } @@ -115,11 +109,11 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, */ if (msg->read) { for (i = 0; i < 4; i++) { - ret = i2c_smbus_read_byte_data(data->client, - SBRMI_OUTBNDMSG1 + i); + ret = regmap_read(data->regmap, + SBRMI_OUTBNDMSG1 + i, &bytes); if (ret < 0) goto exit_unlock; - msg->data_out |= ret << i * 8; + msg->data_out |= bytes << i * 8; } } @@ -127,8 +121,8 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the * ALERT to initiator */ - ret = i2c_smbus_write_byte_data(data->client, SBRMI_STATUS, - sw_status | SW_ALERT_MASK); + ret = regmap_write(data->regmap, SBRMI_STATUS, + sw_status | SW_ALERT_MASK); exit_unlock: mutex_unlock(&data->lock); diff --git a/drivers/mfd/sbrmi-i2c.c b/drivers/mfd/sbrmi-i2c.c index c19f0b3eb0cd..bdf15a7a2167 100644 --- a/drivers/mfd/sbrmi-i2c.c +++ b/drivers/mfd/sbrmi-i2c.c @@ -15,6 +15,7 @@ #include #include #include +#include #define SBRMI_CTRL 0x1 @@ -22,22 +23,21 @@ static struct mfd_cell apml_sbrmi[] = { { .name = "sbrmi-hwmon" }, }; -static int sbrmi_enable_alert(struct i2c_client *client) +static int sbrmi_enable_alert(struct sbrmi_data *data) { - int ctrl; + int ctrl, ret; /* * Enable the SB-RMI Software alert status * by writing 0 to bit 4 of Control register(0x1) */ - ctrl = i2c_smbus_read_byte_data(client, SBRMI_CTRL); - if (ctrl < 0) - return ctrl; + ret = regmap_read(data->regmap, SBRMI_CTRL, &ctrl); + if (ret < 0) + return ret; if (ctrl & 0x10) { ctrl &= ~0x10; - return i2c_smbus_write_byte_data(client, - SBRMI_CTRL, ctrl); + return regmap_write(data->regmap, SBRMI_CTRL, ctrl); } return 0; @@ -62,17 +62,24 @@ static int sbrmi_i2c_probe(struct i2c_client *client) { struct device *dev = &client->dev; struct sbrmi_data *data; + struct regmap_config sbrmi_i2c_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + }; int ret; data = devm_kzalloc(dev, sizeof(struct sbrmi_data), GFP_KERNEL); if (!data) return -ENOMEM; - data->client = client; mutex_init(&data->lock); + data->regmap = devm_regmap_init_i2c(client, &sbrmi_i2c_regmap_config); + if (IS_ERR(data->regmap)) + return PTR_ERR(data->regmap); + /* Enable alert for SB-RMI sequence */ - ret = sbrmi_enable_alert(client); + ret = sbrmi_enable_alert(data); if (ret < 0) return ret; diff --git a/include/linux/mfd/amd-sb.h b/include/linux/mfd/amd-sb.h index 7805f31fb6ea..977b8228ffa1 100644 --- a/include/linux/mfd/amd-sb.h +++ b/include/linux/mfd/amd-sb.h @@ -7,7 +7,7 @@ #define _AMD_SB_H_ #include -#include +#include /* * SB-RMI supports soft mailbox service request to MP1 (power management * firmware) through SBRMI inbound/outbound message registers. @@ -22,10 +22,10 @@ enum sbrmi_msg_id { /* Each client has this additional data */ struct sbrmi_data { - struct i2c_client *client; + struct regmap *regmap; struct mutex lock; u32 pwr_limit_max; -}; +} __packed; struct sbrmi_mailbox_msg { u8 cmd; From patchwork Thu May 30 11:23:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chatradhi, Naveen Krishna" X-Patchwork-Id: 13680289 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2076.outbound.protection.outlook.com [40.107.102.76]) (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 725761779BB for ; Thu, 30 May 2024 11:23:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717068228; cv=fail; b=bT4KTpdDS0gSV/EMC7bjfWJps0/K5U0ERuJd0EE3Ykelv5U0ZWQRLeWNN1DEVMjJCrdTDzYLYYhSKUZDoPAKhG+HJb4KijDbOO7BGbzWVanhje0kPE18Dn490/vzYaXzhXJ40FoJGvmE0F7h3utI9e/H6cYq6qXw+NuB9kAdfUk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717068228; c=relaxed/simple; bh=IooU7YoL5cxijcSe2md9Zzt9oHmKjtBJyfcCr5GjoVk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lmWAdZLYpc9R0yEAeaRcp6ahMBxWHYaaV48bKH2d93eJUFXD308QMp0s34sxqxtuqzpTsKOI+9M+S2YSdBhL8nlVCBeuxC4P6qJnwhermt1qSGHBujBmG2yesQm1kysHJ1j2jMMmCf6c1aEnMEFRaMcZwpxNEZibIkl3rBYqeDI= 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=mhMqQimi; arc=fail smtp.client-ip=40.107.102.76 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="mhMqQimi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ACQ929V3irYsF5Je8LQo0EuFjN49kjFpVsKzfyYIU1/fv9PPBDfy326pg7XXrB26X+pu/NOmeWDDD+pHSDPTA/gC4S0wtGq0o84CFSTtUSn8FE6nmTmItVkTwVbNdJi0K6vcT9JnKW0HCv3pEeeSOWB2+sp32Abp6bngzEeKe3EUFhX6UE5YSZCD+QGSxmXNfYD/Si8S2+2JI40P2PzbbijZUqdp0UAMCnTrk103rKRr5cNpN5ORZUXRJP8CKY4/Vx5Pv8R7sUrlm8n2ZXz7RiKnNEizudZZdL74EvXvrJqgBpLVZy4XuNJQ8S1BC/yFi5qdhX9ruTdmfi/GXPLqRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=0KvS8Bsr2ExYANgm33fkcQdR7hTBBMKnk0fOhUBj7+0=; b=BMI2BXMySOQoV9mcJNmh1Us+LlELRnZZcNJqU/G8ZCRtBkTGpdXUKhdsEg3mDbIQAatWLScL4i+tV5R1QZXeFqJey2DUg3NJgGG/OzP8n1wa7SLBWX/3oJW4aDgZ/UAV59lSLxhYprRAh9I9OLf4k5skRroRNmON4v8nNHF/iQKfcU+IBTlBlLmlu6mHT1+2FXuPHgKtxgwj5zM+t3fYpBSWp5xzAZvTmCfR6BNIQs8AvTH9tUAO2l9K0UNho3XtoAKp0kr4HpyxJntYTt1kT/QuQ8kqOP8N4gF3jJmIJXqK/Vn4C0BcezKoxwEv+ftrDRRlxOfIrCP1VGrSdWd9Og== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=0KvS8Bsr2ExYANgm33fkcQdR7hTBBMKnk0fOhUBj7+0=; b=mhMqQimigGju5VXKYhGtcJBGG7+o615w69CZFHb877cOTL+kn2Xd1SmK7N8U3PPioo7yWm/L0X8gL7VKYf1zXDpt2U/9xAcJGAqOtYhOjm8OJlNqbvorw8fpDiGblxU0VeX9FdrTbsceB5HMZIAOrzZ/sVBhqM8XtVrYCJwsfoM= Received: from BN9P222CA0001.NAMP222.PROD.OUTLOOK.COM (2603:10b6:408:10c::6) by BY5PR12MB4257.namprd12.prod.outlook.com (2603:10b6:a03:20f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Thu, 30 May 2024 11:23:43 +0000 Received: from BL6PEPF0001AB76.namprd02.prod.outlook.com (2603:10b6:408:10c:cafe::3a) by BN9P222CA0001.outlook.office365.com (2603:10b6:408:10c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21 via Frontend Transport; Thu, 30 May 2024 11:23:42 +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 BL6PEPF0001AB76.mail.protection.outlook.com (10.167.242.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Thu, 30 May 2024 11:23:42 +0000 Received: from amd.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.35; Thu, 30 May 2024 06:23:39 -0500 From: Naveen Krishna Chatradhi To: , CC: , , , , Akshay Gupta , Akshay Gupta , Naveen Krishna Chatradhi Subject: [PATCH 4/5] mfd: sbrmi: Clear sbrmi status register bit SwAlertSts Date: Thu, 30 May 2024 11:23:06 +0000 Message-ID: <20240530112307.3089696-5-naveenkrishna.chatradhi@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240530112307.3089696-1-naveenkrishna.chatradhi@amd.com> References: <20240530112307.3089696-1-naveenkrishna.chatradhi@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@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: BL6PEPF0001AB76:EE_|BY5PR12MB4257:EE_ X-MS-Office365-Filtering-Correlation-Id: 9a7d236b-1912-47ab-6024-08dc809af65e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|376005|1800799015; X-Microsoft-Antispam-Message-Info: CKNIrbtQUttyhJibDOwQ2m7sVqCBW+yPXVxthEwT5mJ+H/tH/FEpxqO76ROBU4i9wTCH4V+RQXLAmWJJwrNa8RuH9dg4DGXhew+WP/iNUYyu8SLVqPaBkaIlMDanSapCWj/LMviT2KbA+kfUf8RvUJhzznzra1dNc628Rkz1ivn2OKYTke+4FLJx+TJfzcxK4Y7N/jQUeye8+S9IiaJV9ro3Ie3g1iQnJeO6HxQjJ5QSzB/ahYND+f4PEAz0FfVabmbgyb013+BeyZ57Ory49qr1qDwZ/oMxvUMBXcaUcAjhrGWiJCHyfZX+uxD/kJwiNQx7cN1uDcZcCaSk2gcltabrDuWzULJ4XGltzl3zk3st9gSTjeW0kC3/hhcgmBxJbr61llNeR4NwQm9zyrW74XqKIQKI9fHWk+hM5Dm2WKubX09QmmQjo6H24gSGkaCIxBU/+5AasF83+N/Sum+106Wobe2ASohBzPNtqRAfalG6LIzmgTq8kXbn5MFGZ3ZQWMMEo2pXntl3TG6r0H6VvjdW5NIiZnywql33wO8+MyPHPPTBoNsr0EbJjUsA1GRtzPFeiQJ4lGtXxDIQYJqVDwouWs9RjM6V4udU4UKWO4C4umDFGPndH2ZhzuBRgAk8OEIggTs9hsSkNlwwnshDrPxCFoAd29+wZs2O+3NlzwlHDlRBV8ZsrqIHm7jnxFdul9sKYj7yS+267U0NM6S8czUHzWSyJVF/v8/8llMbt9BoNBkTZfTnhzCr+sEHZmQwmznWaxXpk/r1I7+H4S0pZ4IP2VpQv7hWS1vvVo5jSYLsKJScrt5lNPsEfpl6RQoyfRK+C7swtlsOZRuv9m3pkxOPJPAezRe1QYJWPXwYfJEaBIFoiBtU2XopXb4eBEYpp9M2URrR0MaN7ZqQqRdJ+O05xaRcX3LSxl16dR204bXai4Mq5F0BfSoO+mdZt2NGzXjy0p5lOcbc4H0o/Tp1bpcPOux6dYgvxlpe1P58HUO19Po3SZg2pMSTGuUYh5sN/+qQ3m/v07P7vgvvZSEcj+fEl/6JUU+VUzdSDHoBKndG3ot3mLn9FSbGwm23Q5jhHVTGeEaoP8V81llQVBCHzTYj2qvCU0gSLUWe/dQGRD7fKNBMpRn6Fpxnvxq9rXWRWd5z1n5J8aW+yMNhpvaV8WieH8D9jlGPuDzqy8BHZ0SF0kjcQ0ouKBjCHpvB/MXw9v1PSTGwfYS9WKzhLwo3S8II98W3Pqeye76PYiRl1mFzrDs1YbM7xYK7R5Lzbh3deGT7/yYMCwGTUuxFtC2lL1rbRS/fW0fHJW9tdohR4tALxcGGFwzpyQVShd269/0sA/SR1Z43xdN9XXQhzKkK7VSh1mvQE4A+UWeEBS5vWn0= 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:(13230031)(82310400017)(36860700004)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2024 11:23:42.5998 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9a7d236b-1912-47ab-6024-08dc809af65e 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: BL6PEPF0001AB76.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4257 From: Akshay Gupta - SBRMI register status b1' SwAlertSts sets in below conditions - Completion of Mailbox command - syncflood event If the bit is set for syncfllod event, it may be interpretted as mailbox command compleition. This patch clears the bit before start of mailbox protocol. Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi --- drivers/mfd/sbrmi-core.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/mfd/sbrmi-core.c b/drivers/mfd/sbrmi-core.c index 5617b91787ba..d5fbe5676cab 100644 --- a/drivers/mfd/sbrmi-core.c +++ b/drivers/mfd/sbrmi-core.c @@ -41,6 +41,22 @@ enum sbrmi_reg { SBRMI_SW_INTERRUPT, }; +static int sbrmi_clear_status_alert(struct sbrmi_data *data) +{ + int sw_status, ret; + + ret = regmap_read(data->regmap, SBRMI_STATUS, + &sw_status); + if (ret < 0) + return ret; + + if (!(sw_status & SW_ALERT_MASK)) + return 0; + + return regmap_write(data->regmap, SBRMI_STATUS, + SW_ALERT_MASK); +} + int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg) { @@ -51,6 +67,10 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, mutex_lock(&data->lock); + ret = sbrmi_clear_status_alert(data); + if (ret < 0) + goto exit_unlock; + /* Indicate firmware a command is to be serviced */ ret = regmap_write(data->regmap, SBRMI_INBNDMSG7, START_CMD); if (ret < 0) From patchwork Thu May 30 11:23:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chatradhi, Naveen Krishna" X-Patchwork-Id: 13680290 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2088.outbound.protection.outlook.com [40.107.243.88]) (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 6C07F179954 for ; Thu, 30 May 2024 11:23:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717068232; cv=fail; b=gy4UZ7w1d8U4x+AiPKjHf1YBtUWmMw1sFClwSei4u54aTV4GyB6g80OwH/2tMOgylcdC544fDVHB7KsmQibACYDCq6tPRNnA9YNfaCTxLWgEs8olkD/k7U4vhNhlS2Z4/IEnzr4fIIbV6dT1yHL3maQKL/8t+AJrBFNlCULej0c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717068232; c=relaxed/simple; bh=z/osxjlYXfwtbXcb8OeffJzz7nbAiQG/MZc769pMRQo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cHeZjdM+5diarzxvQmXcz1oMUMn9kwCFWa1Tpr+aKuAfB2Mr91al6qs0oMkq01D+0v1oD88P8/7mNZo847HvCnecAOVlLaQsENPnThQ+zIleXYPi4OujBbd+ec5xc/aLQL7j3FRBqAfOUEQ0cvCuIgBAikrDEaSIuTV6c3/Zbno= 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=wfoo9dH2; arc=fail smtp.client-ip=40.107.243.88 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="wfoo9dH2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lp4tgaTbCDth+XvXGX+m0w/Pg1AZfV5ESxJOlPhahOoxfv8w5qTc73btNRG176rveuOk6yYPUOGK+ZN2rBUCFD/7IbQZaXXPe7VMxYljs4b9X/sitKg2o7QPVHafW/1WzEZXdeE3Qw6vLHMIxhSWKS/7zegBhJDfHOkRhODB25ZEjojRjF01bE7ditEE99ArDVGH+DC2xpJUCa12zmWU2U1xkrQzywzAuSrSB34Yn0JFg1ePgqayXyocJIreTzQkdZgN+XbFEIty6SqwSJhoeMkvoxozc5v7wrBpQItNTxy6XuggwTVD3mzJsO71TY6pM/UAMjXpPqfGs4pavbdHjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=yFSMVLo8vax1ObIyYL5DWogRG1eVQR8Y9yzYE7MrGog=; b=jl0kRr/zUeoUCTAvGCN3qNtvbhW9uG4iD57ILocSkVJTFtePV3W90xl0ABe/nwR7oCrCPh/Uc0oU+mMZzLffo3U0YzJsNuxJG0WxwKnYeR00uWHtncBrUlzv0oz05gBOFI2gzlVJWRrLmQjnjmMvat/m0t+klxoqgYmPByPBF4D2nNpBnCpaZwAVkPN/948vmOewzHJOtE/mr3danaSvBRHuVYl7WsbXiot/VxTL7syUYNekZhU5SjfNEjl8iwGsk+9w4b17/VbqN3jQOITZD8JxacoYiEmf/cxiyQoGYQ6xohPHhBWwbkiDGr0/Ldk5k8U0/RZA2AO+6yEUXk6yjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=yFSMVLo8vax1ObIyYL5DWogRG1eVQR8Y9yzYE7MrGog=; b=wfoo9dH23GXqADYRaFlKEjEKqoJ+gkBykW8Xk4qZ/RXH4uJmq988uX8QUjnowJCfhXaiVQY9zVszW++LEFpyAtUnsBDiB7NF50aE0WW8ntABE9lMdLZcMNLpdMmOTrLHYKqM7nb1kstGJKs4Fo5eWth3lrZMswLImFdDS4OEt8w= Received: from MN2PR17CA0036.namprd17.prod.outlook.com (2603:10b6:208:15e::49) by CH0PR12MB8508.namprd12.prod.outlook.com (2603:10b6:610:18c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.30; Thu, 30 May 2024 11:23:47 +0000 Received: from BL6PEPF0001AB74.namprd02.prod.outlook.com (2603:10b6:208:15e:cafe::1) by MN2PR17CA0036.outlook.office365.com (2603:10b6:208:15e::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21 via Frontend Transport; Thu, 30 May 2024 11:23:47 +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 BL6PEPF0001AB74.mail.protection.outlook.com (10.167.242.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Thu, 30 May 2024 11:23:46 +0000 Received: from amd.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.35; Thu, 30 May 2024 06:23:43 -0500 From: Naveen Krishna Chatradhi To: , CC: , , , , Akshay Gupta , Akshay Gupta , Naveen Krishna Chatradhi Subject: [PATCH 5/5] mfd/hwmon: sbrmi: Add support for APML protocols Date: Thu, 30 May 2024 11:23:07 +0000 Message-ID: <20240530112307.3089696-6-naveenkrishna.chatradhi@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240530112307.3089696-1-naveenkrishna.chatradhi@amd.com> References: <20240530112307.3089696-1-naveenkrishna.chatradhi@amd.com> Precedence: bulk X-Mailing-List: linux-hwmon@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: BL6PEPF0001AB74:EE_|CH0PR12MB8508:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e366dd3-ebff-4575-aa87-08dc809af8fb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|36860700004|82310400017|1800799015; X-Microsoft-Antispam-Message-Info: Ufj7l3vdU/Bx9LgcGaE8D8uFznPFTLEgVdOZChY4Pmc7W5J3o3JM3cUKYR1Fz9GIRXetAizg2RkeY2ei6dOC2YjUAdM9+leYRt8CgFY8TA3kIqR2kAbJ40fah+FQg88vYQ4FqcClUxHYHp557Bo2731FaRou1GsmFYwLQw+VDtS6C4w8XtZYbsO2fH6fELH5+mik2no9ZEpywJ8uV/eVYWQJrzlBE00lyRwZWeQBKxhqQ8T1kmXRbDEz6RXtlO6T/7mtPTLZ33FvjjKT8IZkWNHhIGzkOM+Ljm01v4z02kyF8y9W+qSUHteKja3zVKFvBhv93yRNM46YYDXdefjnhmwi/Y3VW20sWZx/B/59RpkAKZU4axI1cRon8+5htN5GAarTTh7iQqyeWAedTheJQamdBCZbLMocix1nRJTzyluSe0dPlBDEXVtSOmfV+zD11uHYWlNxtzEwOymkr+CCG+aTpIx9hDXEt/hnQhjOTxs2X/UOEi8qfhqY+SGNWmmixwmD7CPU5/TmT8FQ/IFQlTkFjAHsD9Vf5nZYo6Ba7C+Bxa20sjYjV0qFQEG/WsfYmL55ANj6/o7f9VsgjM3qt+RiXux8/2uHm59Di0mSp7U7i0ZGVsGD4P8O+JYm6RrnkxuFZllow1xTQMMgjm2D60HRWZbwKWDYxXKekAYj6oewa+HkN7vyshYHFs5hRdBwG/wlrYkVna0ms47zZFjc0OiU76t5bBrIULLrX10TG9AKuIU+Tvq2aJqSQSRgN9U5HEtgg6QQ1i8Zroq6hgYkyg3tCyqb53s/KXto3fhRJIY0vLKR2V7dWuaB3YZHKS+cOUy/wfKaGTrZgAVJKUKhP+7zjxO4e3Nf9xFox8e5Rn8Oiy8H3fMCcX3OUBmjJja9YJ0/GNqcKUVdhSPKu/Pigso3Pi9Cvx3qsNovJRgGSn/zpevXgrkPiUsD7I1bu4jniMsmRHFUfynA8KWmCcOKj7eK0uspjiF2B/VqYXYiVH3BzHLAhUc0oM/erFy31FUy2tERY2cxwhgPK9frhbW/5e3kb0sYINPcO1mtoDVeyl8u3RdxY0NNTUrWJO4i+ezSnnMbaljs9t2662bOCLd0avSvTgXIY6/QLk0IN0zG7lx421l0fKvUl+npApmnGbQXlJKA4y6mpKXyP5yPXM0ktysvkXJXCSNXIT6fmzlZ3V9HId70Wqhlu43gGxYjc6iOfUyi4x34o4pOjBl8EXP1lE5fB63rDtzjSvMD4hpzocOkU4j6x500CswnO3+AJUr35xyq65j7Uaqkhs9opBLkU+aqYivjGQaC90CzBhOvNFX35/uYo9h6Y9DsyhzrjfgM 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:(13230031)(376005)(36860700004)(82310400017)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2024 11:23:46.9860 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e366dd3-ebff-4575-aa87-08dc809af8fb 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: BL6PEPF0001AB74.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB8508 From: Akshay Gupta The present sbrmi module only support reporting power via hwmon. However, AMD data center range of processors support various system management functionality Out-of-band over Advanced Platform Management Link (APML). Register a miscdevice, which creates a device /dev/sbrmiX with an IOCTL interface for the user space to invoke the following protocols. - Mailbox read/write (already defined in sbrmi_mailbox_xfer()) - CPUID read - MCAMSR read Open-sourced and widely used https://github.com/amd/esmi_oob_library will continue to provide user-space programmable API. Signed-off-by: Akshay Gupta Reviewed-by: Naveen Krishna Chatradhi --- drivers/hwmon/sbrmi.c | 43 ++-- drivers/mfd/sbrmi-core.c | 461 +++++++++++++++++++++++++++++----- drivers/mfd/sbrmi-core.h | 36 +++ drivers/mfd/sbrmi-i2c.c | 81 ++++-- include/linux/mfd/amd-sb.h | 32 ++- include/uapi/linux/amd-apml.h | 74 ++++++ 6 files changed, 615 insertions(+), 112 deletions(-) create mode 100644 drivers/mfd/sbrmi-core.h create mode 100644 include/uapi/linux/amd-apml.h diff --git a/drivers/hwmon/sbrmi.c b/drivers/hwmon/sbrmi.c index aaeb5050eb0c..a8bf9aea52f9 100644 --- a/drivers/hwmon/sbrmi.c +++ b/drivers/hwmon/sbrmi.c @@ -19,42 +19,46 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { - struct sbrmi_data *data = dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg = { 0 }; + struct apml_sbrmi_device *rmi_dev = dev_get_drvdata(dev); + struct apml_message msg = { 0 }; int ret; if (type != hwmon_power) return -EINVAL; - msg.read = true; + mutex_lock(&rmi_dev->lock); + msg.data_in.reg_in[RD_FLAG_INDEX] = 1; switch (attr) { case hwmon_power_input: msg.cmd = SBRMI_READ_PKG_PWR_CONSUMPTION; - ret = rmi_mailbox_xfer(data, &msg); + ret = rmi_mailbox_xfer(rmi_dev, &msg); break; case hwmon_power_cap: msg.cmd = SBRMI_READ_PKG_PWR_LIMIT; - ret = rmi_mailbox_xfer(data, &msg); + ret = rmi_mailbox_xfer(rmi_dev, &msg); break; case hwmon_power_cap_max: - msg.data_out = data->pwr_limit_max; ret = 0; + msg.data_out.mb_out[RD_WR_DATA_INDEX] = rmi_dev->pwr_limit_max; break; default: - return -EINVAL; + ret = -EINVAL; } - if (ret < 0) - return ret; + /* hwmon power attributes are in microWatt */ - *val = (long)msg.data_out * 1000; + if (!ret) + *val = (long)msg.data_out.mb_out[RD_WR_DATA_INDEX] * 1000; + + mutex_unlock(&rmi_dev->lock); return ret; } static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long val) { - struct sbrmi_data *data = dev_get_drvdata(dev); - struct sbrmi_mailbox_msg msg = { 0 }; + struct apml_sbrmi_device *rmi_dev = dev_get_drvdata(dev); + struct apml_message msg = { 0 }; + int ret; if (type != hwmon_power && attr != hwmon_power_cap) return -EINVAL; @@ -64,13 +68,16 @@ static int sbrmi_write(struct device *dev, enum hwmon_sensor_types type, */ val /= 1000; - val = clamp_val(val, SBRMI_PWR_MIN, data->pwr_limit_max); + val = clamp_val(val, SBRMI_PWR_MIN, rmi_dev->pwr_limit_max); msg.cmd = SBRMI_WRITE_PKG_PWR_LIMIT; - msg.data_in = val; - msg.read = false; + msg.data_in.mb_in[RD_WR_DATA_INDEX] = val; + msg.data_in.reg_in[RD_FLAG_INDEX] = 0; - return rmi_mailbox_xfer(data, &msg); + mutex_lock(&rmi_dev->lock); + ret = rmi_mailbox_xfer(rmi_dev, &msg); + mutex_unlock(&rmi_dev->lock); + return ret; } static umode_t sbrmi_is_visible(const void *data, @@ -114,9 +121,9 @@ static int sbrmi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device *hwmon_dev; - struct sbrmi_data *data = dev_get_drvdata(pdev->dev.parent); + struct apml_sbrmi_device *rmi_dev = dev_get_drvdata(pdev->dev.parent); - hwmon_dev = devm_hwmon_device_register_with_info(dev, "sbrmi", data, + hwmon_dev = devm_hwmon_device_register_with_info(dev, "sbrmi", rmi_dev, &sbrmi_chip_info, NULL); return PTR_ERR_OR_ZERO(hwmon_dev); } diff --git a/drivers/mfd/sbrmi-core.c b/drivers/mfd/sbrmi-core.c index d5fbe5676cab..05d6c68d78b6 100644 --- a/drivers/mfd/sbrmi-core.c +++ b/drivers/mfd/sbrmi-core.c @@ -7,45 +7,271 @@ */ #include #include +#include #include +#include +#include #include #include +#include "sbrmi-core.h" /* Mask for Status Register bit[1] */ #define SW_ALERT_MASK 0x2 +/* Mask to check H/W Alert status bit */ +#define HW_ALERT_MASK 0x80 /* Software Interrupt for triggering */ #define START_CMD 0x80 #define TRIGGER_MAILBOX 0x01 -/* SB-RMI registers */ -enum sbrmi_reg { - SBRMI_CTRL = 0x01, - SBRMI_STATUS, - SBRMI_OUTBNDMSG0 = 0x30, - SBRMI_OUTBNDMSG1, - SBRMI_OUTBNDMSG2, - SBRMI_OUTBNDMSG3, - SBRMI_OUTBNDMSG4, - SBRMI_OUTBNDMSG5, - SBRMI_OUTBNDMSG6, - SBRMI_OUTBNDMSG7, - SBRMI_INBNDMSG0, - SBRMI_INBNDMSG1, - SBRMI_INBNDMSG2, - SBRMI_INBNDMSG3, - SBRMI_INBNDMSG4, - SBRMI_INBNDMSG5, - SBRMI_INBNDMSG6, - SBRMI_INBNDMSG7, - SBRMI_SW_INTERRUPT, -}; +/* Default message lengths as per APML command protocol */ +/* MSR */ +#define MSR_RD_REG_LEN 0xa +#define MSR_WR_REG_LEN 0x8 +#define MSR_RD_DATA_LEN 0x8 +#define MSR_WR_DATA_LEN 0x7 +/* CPUID */ +#define CPUID_RD_DATA_LEN 0x8 +#define CPUID_WR_DATA_LEN 0x8 +#define CPUID_RD_REG_LEN 0xa +#define CPUID_WR_REG_LEN 0x9 + +/* CPUID MSR Command Ids */ +#define CPUID_MCA_CMD 0x73 +#define RD_CPUID_CMD 0x91 +#define RD_MCA_CMD 0x86 + +/* input for bulk write to CPUID and MSR protocol */ +struct cpu_msr_indata { + u8 wr_len; /* const value */ + u8 rd_len; /* const value */ + u8 proto_cmd; /* const value */ + u8 thread; /* thread number */ + union { + u8 reg_offset[4]; /* input value */ + u32 value; + }; + u8 ext; /* extended function */ +} __packed; + +/* output for bulk read from CPUID and MSR protocol */ +struct cpu_msr_outdata { + u8 num_bytes; /* number of bytes return */ + u8 status; /* Protocol status code */ + union { + u64 value; + u8 reg_data[8]; + }; +} __packed; + +#define prepare_mca_msr_input_message(input, thread_id, data_in) \ + input.rd_len = MSR_RD_DATA_LEN, \ + input.wr_len = MSR_WR_DATA_LEN, \ + input.proto_cmd = RD_MCA_CMD, \ + input.thread = thread_id << 1, \ + input.value = data_in + +#define prepare_cpuid_input_message(input, thread_id, func, ext_func) \ + input.rd_len = CPUID_RD_DATA_LEN, \ + input.wr_len = CPUID_WR_DATA_LEN, \ + input.proto_cmd = RD_CPUID_CMD, \ + input.thread = thread_id << 1, \ + input.value = func, \ + input.ext = ext_func + +static int sbrmi_get_rev(struct apml_sbrmi_device *rmi_dev) +{ + struct apml_message msg = { 0 }; + int ret; + + msg.data_in.reg_in[REG_OFF_INDEX] = SBRMI_REV; + msg.data_in.reg_in[RD_FLAG_INDEX] = 1; + ret = regmap_read(rmi_dev->regmap, + msg.data_in.reg_in[REG_OFF_INDEX], + &msg.data_out.mb_out[RD_WR_DATA_INDEX]); + if (ret < 0) + return ret; + + rmi_dev->rev = msg.data_out.reg_out[RD_WR_DATA_INDEX]; + return 0; +} + +/* + * For Mailbox command software alert status bit is set by firmware + * to indicate command completion + * For RMI Rev 0x20, new h/w status bit is introduced. which is used + * by firmware to indicate completion of commands (0x71, 0x72, 0x73). + * wait for the status bit to be set by the firmware before + * reading the data out. + */ +static int sbrmi_wait_status(struct apml_sbrmi_device *rmi_dev, + int *status, int mask) +{ + int ret, retry = 100; + + do { + ret = regmap_read(rmi_dev->regmap, SBRMI_STATUS, status); + if (ret < 0) + return ret; + + if (*status & mask) + break; + + /* Wait 1~2 second for firmware to return data out */ + if (retry > 95) + usleep_range(50, 100); + else + usleep_range(10000, 20000); + } while (retry--); + + if (retry < 0) + ret = -ETIMEDOUT; + return ret; +} + +/* MCA MSR protocol */ +static int rmi_mca_msr_read(struct apml_sbrmi_device *rmi_dev, + struct apml_message *msg) +{ + struct cpu_msr_outdata output = {0}; + struct cpu_msr_indata input = {0}; + int ret, val = 0; + int hw_status; + u16 thread; + + /* cache the rev value to identify if protocol is supported or not */ + if (!rmi_dev->rev) { + ret = sbrmi_get_rev(rmi_dev); + if (ret < 0) + return ret; + } + /* MCA MSR protocol for REV 0x10 is not supported*/ + if (rmi_dev->rev == 0x10) + return -EOPNOTSUPP; + + thread = msg->data_in.reg_in[THREAD_LOW_INDEX] | + msg->data_in.reg_in[THREAD_HI_INDEX] << 8; + + /* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */ + if (thread > 127) { + thread -= 128; + val = 1; + } + ret = regmap_write(rmi_dev->regmap, SBRMI_THREAD128CS, val); + if (ret < 0) + goto exit_unlock; + + prepare_mca_msr_input_message(input, thread, + msg->data_in.mb_in[RD_WR_DATA_INDEX]); + + ret = regmap_bulk_write(rmi_dev->regmap, CPUID_MCA_CMD, + &input, MSR_WR_REG_LEN); + if (ret < 0) + goto exit_unlock; + + ret = sbrmi_wait_status(rmi_dev, &hw_status, HW_ALERT_MASK); + if (ret < 0) + goto exit_unlock; + + ret = regmap_bulk_read(rmi_dev->regmap, CPUID_MCA_CMD, + &output, MSR_RD_REG_LEN); + if (ret < 0) + goto exit_unlock; + + ret = regmap_write(rmi_dev->regmap, SBRMI_STATUS, + HW_ALERT_MASK); + if (ret < 0) + goto exit_unlock; + + if (output.num_bytes != MSR_RD_REG_LEN - 1) { + ret = -EMSGSIZE; + goto exit_unlock; + } + if (output.status) { + ret = -EPROTOTYPE; + msg->fw_ret_code = output.status; + goto exit_unlock; + } + msg->data_out.cpu_msr_out = output.value; + +exit_unlock: + return ret; +} + +/* Read CPUID function protocol */ +static int rmi_cpuid_read(struct apml_sbrmi_device *rmi_dev, + struct apml_message *msg) +{ + struct cpu_msr_indata input = {0}; + struct cpu_msr_outdata output = {0}; + int val = 0; + int ret, hw_status; + u16 thread; + + /* cache the rev value to identify if protocol is supported or not */ + if (!rmi_dev->rev) { + ret = sbrmi_get_rev(rmi_dev); + if (ret < 0) + return ret; + } + /* CPUID protocol for REV 0x10 is not supported*/ + if (rmi_dev->rev == 0x10) + return -EOPNOTSUPP; + + thread = msg->data_in.reg_in[THREAD_LOW_INDEX] | + msg->data_in.reg_in[THREAD_HI_INDEX] << 8; + + /* Thread > 127, Thread128 CS register, 1'b1 needs to be set to 1 */ + if (thread > 127) { + thread -= 128; + val = 1; + } + ret = regmap_write(rmi_dev->regmap, SBRMI_THREAD128CS, val); + if (ret < 0) + goto exit_unlock; + + prepare_cpuid_input_message(input, thread, + msg->data_in.mb_in[RD_WR_DATA_INDEX], + msg->data_in.reg_in[EXT_FUNC_INDEX]); + + ret = regmap_bulk_write(rmi_dev->regmap, CPUID_MCA_CMD, + &input, CPUID_WR_REG_LEN); + if (ret < 0) + goto exit_unlock; + + ret = sbrmi_wait_status(rmi_dev, &hw_status, HW_ALERT_MASK); + if (ret < 0) + goto exit_unlock; + + ret = regmap_bulk_read(rmi_dev->regmap, CPUID_MCA_CMD, + &output, CPUID_RD_REG_LEN); + if (ret < 0) + goto exit_unlock; + + ret = regmap_write(rmi_dev->regmap, SBRMI_STATUS, + HW_ALERT_MASK); + if (ret < 0) + goto exit_unlock; + + if (output.num_bytes != CPUID_RD_REG_LEN - 1) { + ret = -EMSGSIZE; + goto exit_unlock; + } + if (output.status) { + ret = -EPROTOTYPE; + msg->fw_ret_code = output.status; + goto exit_unlock; + } + msg->data_out.cpu_msr_out = output.value; +exit_unlock: + return ret; +} -static int sbrmi_clear_status_alert(struct sbrmi_data *data) +static int sbrmi_clear_status_alert(struct apml_sbrmi_device *rmi_dev) { int sw_status, ret; - ret = regmap_read(data->regmap, SBRMI_STATUS, + ret = regmap_read(rmi_dev->regmap, SBRMI_STATUS, &sw_status); if (ret < 0) return ret; @@ -53,31 +279,31 @@ static int sbrmi_clear_status_alert(struct sbrmi_data *data) if (!(sw_status & SW_ALERT_MASK)) return 0; - return regmap_write(data->regmap, SBRMI_STATUS, + return regmap_write(rmi_dev->regmap, SBRMI_STATUS, SW_ALERT_MASK); } -int rmi_mailbox_xfer(struct sbrmi_data *data, - struct sbrmi_mailbox_msg *msg) +int rmi_mailbox_xfer(struct apml_sbrmi_device *rmi_dev, + struct apml_message *msg) { - unsigned int bytes; - int i, ret, retry = 10; + unsigned int bytes, ec; + int i, ret; int sw_status; u8 byte; - mutex_lock(&data->lock); + msg->fw_ret_code = 0; - ret = sbrmi_clear_status_alert(data); + ret = sbrmi_clear_status_alert(rmi_dev); if (ret < 0) goto exit_unlock; /* Indicate firmware a command is to be serviced */ - ret = regmap_write(data->regmap, SBRMI_INBNDMSG7, START_CMD); + ret = regmap_write(rmi_dev->regmap, SBRMI_INBNDMSG7, START_CMD); if (ret < 0) goto exit_unlock; /* Write the command to SBRMI::InBndMsg_inst0 */ - ret = regmap_write(data->regmap, SBRMI_INBNDMSG0, msg->cmd); + ret = regmap_write(rmi_dev->regmap, SBRMI_INBNDMSG0, msg->cmd); if (ret < 0) goto exit_unlock; @@ -86,9 +312,9 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * Command Data In[31:0] to SBRMI::InBndMsg_inst[4:1] * SBRMI_x3C(MSB):SBRMI_x39(LSB) */ - for (i = 0; i < 4; i++) { - byte = (msg->data_in >> i * 8) & 0xff; - ret = regmap_write(data->regmap, SBRMI_INBNDMSG1 + i, byte); + for (i = 0; i < MB_DATA_SIZE; i++) { + byte = msg->data_in.reg_in[i]; + ret = regmap_write(rmi_dev->regmap, SBRMI_INBNDMSG1 + i, byte); if (ret < 0) goto exit_unlock; } @@ -97,7 +323,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * Write 0x01 to SBRMI::SoftwareInterrupt to notify firmware to * perform the requested read or write command */ - ret = regmap_write(data->regmap, SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); + ret = regmap_write(rmi_dev->regmap, SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); if (ret < 0) goto exit_unlock; @@ -106,46 +332,159 @@ int rmi_mailbox_xfer(struct sbrmi_data *data, * an ALERT (if enabled) to initiator (BMC) to indicate completion * of the requested command */ - do { - ret = regmap_read(data->regmap, SBRMI_STATUS, &sw_status); - if (sw_status < 0) { - ret = sw_status; - goto exit_unlock; - } - if (sw_status & SW_ALERT_MASK) - break; - usleep_range(50, 100); - } while (retry--); - - if (retry < 0) { - ret = -EIO; + ret = sbrmi_wait_status(rmi_dev, &sw_status, SW_ALERT_MASK); + if (ret < 0) goto exit_unlock; - } + + ret = regmap_read(rmi_dev->regmap, SBRMI_OUTBNDMSG7, &ec); + if (ret || ec) + goto exit_clear_alert; /* * For a read operation, the initiator (BMC) reads the firmware * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1] * {SBRMI_x34(MSB):SBRMI_x31(LSB)}. */ - if (msg->read) { - for (i = 0; i < 4; i++) { - ret = regmap_read(data->regmap, + if (msg->data_in.reg_in[RD_FLAG_INDEX]) { + for (i = 0; i < MB_DATA_SIZE; i++) { + ret = regmap_read(rmi_dev->regmap, SBRMI_OUTBNDMSG1 + i, &bytes); if (ret < 0) - goto exit_unlock; - msg->data_out |= bytes << i * 8; + break; + msg->data_out.reg_out[i] = bytes; } } - +exit_clear_alert: /* * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the * ALERT to initiator */ - ret = regmap_write(data->regmap, SBRMI_STATUS, - sw_status | SW_ALERT_MASK); - + ret = regmap_write(rmi_dev->regmap, SBRMI_STATUS, + SW_ALERT_MASK); + if (ec) { + ret = -EPROTOTYPE; + msg->fw_ret_code = ec; + } exit_unlock: - mutex_unlock(&data->lock); return ret; } EXPORT_SYMBOL(rmi_mailbox_xfer); + +static long sbrmi_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) +{ + int __user *arguser = (int __user *)arg; + struct apml_message msg = { 0 }; + bool read = false; + int ret = -EFAULT; + + struct apml_sbrmi_device *rmi_dev = container_of(fp->private_data, struct apml_sbrmi_device, + sbrmi_misc_dev); + if (!rmi_dev) + return -ENODEV; + + /* + * If device remove/unbind is called do not allow new transaction + */ + if (atomic_read(&rmi_dev->no_new_trans)) + return -EBUSY; + /* Copy the structure from user */ + if (copy_struct_from_user(&msg, sizeof(msg), arguser, + sizeof(struct apml_message))) + return ret; + + /* + * Only one I2C transaction can happen at + * one time. Take lock across so no two protocol is + * invoked at same time, modifying the register value. + */ + mutex_lock(&rmi_dev->lock); + /* Verify device unbind/remove is not invoked */ + if (atomic_read(&rmi_dev->no_new_trans)) { + mutex_unlock(&rmi_dev->lock); + return -EBUSY; + } + + /* Is this a read/monitor/get request */ + if (msg.data_in.reg_in[RD_FLAG_INDEX]) + read = true; + + /* + * Set the in_progress variable to true, to wait for + * completion during unbind/remove of driver + */ + atomic_set(&rmi_dev->in_progress, 1); + + switch (msg.cmd) { + case 0 ... 0x999: + /* Mailbox protocol */ + ret = rmi_mailbox_xfer(rmi_dev, &msg); + break; + case APML_CPUID: + ret = rmi_cpuid_read(rmi_dev, &msg); + break; + case APML_MCA_MSR: + /* MCAMSR protocol */ + ret = rmi_mca_msr_read(rmi_dev, &msg); + break; + case APML_REG: + /* REG R/W */ + if (read) { + ret = regmap_read(rmi_dev->regmap, + msg.data_in.reg_in[REG_OFF_INDEX], + &msg.data_out.mb_out[RD_WR_DATA_INDEX]); + } else { + ret = regmap_write(rmi_dev->regmap, + msg.data_in.reg_in[REG_OFF_INDEX], + msg.data_in.reg_in[REG_VAL_INDEX]); + } + break; + default: + break; + } + + /* Send complete only if device is unbinded/remove */ + if (atomic_read(&rmi_dev->no_new_trans)) + complete(&rmi_dev->misc_fops_done); + + atomic_set(&rmi_dev->in_progress, 0); + mutex_unlock(&rmi_dev->lock); + + /* Copy results back to user only for get/monitor commands and firmware failures */ + if ((read && !ret) || ret == -EPROTOTYPE) { + if (copy_to_user(arguser, &msg, sizeof(struct apml_message))) + ret = -EFAULT; + } + return ret; +} + +static const struct file_operations sbrmi_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = sbrmi_ioctl, + .compat_ioctl = sbrmi_ioctl, +}; + +int create_misc_rmi_device(struct apml_sbrmi_device *rmi_dev, + struct device *dev) +{ + int ret; + + rmi_dev->sbrmi_misc_dev.name = devm_kasprintf(dev, + GFP_KERNEL, + "sbrmi-%x", + rmi_dev->dev_static_addr); + rmi_dev->sbrmi_misc_dev.minor = MISC_DYNAMIC_MINOR; + rmi_dev->sbrmi_misc_dev.fops = &sbrmi_fops; + rmi_dev->sbrmi_misc_dev.parent = dev; + rmi_dev->sbrmi_misc_dev.nodename = devm_kasprintf(dev, + GFP_KERNEL, + "sbrmi-%x", + rmi_dev->dev_static_addr); + rmi_dev->sbrmi_misc_dev.mode = 0600; + + ret = misc_register(&rmi_dev->sbrmi_misc_dev); + if (ret) + return ret; + + dev_info(dev, "register %s device\n", rmi_dev->sbrmi_misc_dev.name); + return ret; +} diff --git a/drivers/mfd/sbrmi-core.h b/drivers/mfd/sbrmi-core.h new file mode 100644 index 000000000000..6339931d4eb3 --- /dev/null +++ b/drivers/mfd/sbrmi-core.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2021-2024 Advanced Micro Devices, Inc. + */ + +#ifndef _SBRMI_CORE__H_ +#define _SBRMI_CORE__H_ + +/* SB-RMI registers */ +enum sbrmi_reg { + SBRMI_REV = 0x00, + SBRMI_CTRL, + SBRMI_STATUS, + SBRMI_OUTBNDMSG0 = 0x30, + SBRMI_OUTBNDMSG1, + SBRMI_OUTBNDMSG2, + SBRMI_OUTBNDMSG3, + SBRMI_OUTBNDMSG4, + SBRMI_OUTBNDMSG5, + SBRMI_OUTBNDMSG6, + SBRMI_OUTBNDMSG7, + SBRMI_INBNDMSG0, + SBRMI_INBNDMSG1, + SBRMI_INBNDMSG2, + SBRMI_INBNDMSG3, + SBRMI_INBNDMSG4, + SBRMI_INBNDMSG5, + SBRMI_INBNDMSG6, + SBRMI_INBNDMSG7, + SBRMI_SW_INTERRUPT, + SBRMI_THREAD128CS = 0x4b, +}; + +int create_misc_rmi_device(struct apml_sbrmi_device *rmi_dev, + struct device *dev); +#endif /*_SBRMI_CORE__H_*/ diff --git a/drivers/mfd/sbrmi-i2c.c b/drivers/mfd/sbrmi-i2c.c index bdf15a7a2167..a8dcb7a92af8 100644 --- a/drivers/mfd/sbrmi-i2c.c +++ b/drivers/mfd/sbrmi-i2c.c @@ -12,18 +12,18 @@ #include #include #include -#include #include #include #include +#include "sbrmi-core.h" -#define SBRMI_CTRL 0x1 +#define MAX_WAIT_TIME_SEC (3) static struct mfd_cell apml_sbrmi[] = { { .name = "sbrmi-hwmon" }, }; -static int sbrmi_enable_alert(struct sbrmi_data *data) +static int sbrmi_enable_alert(struct apml_sbrmi_device *rmi_dev) { int ctrl, ret; @@ -31,29 +31,29 @@ static int sbrmi_enable_alert(struct sbrmi_data *data) * Enable the SB-RMI Software alert status * by writing 0 to bit 4 of Control register(0x1) */ - ret = regmap_read(data->regmap, SBRMI_CTRL, &ctrl); + ret = regmap_read(rmi_dev->regmap, SBRMI_CTRL, &ctrl); if (ret < 0) return ret; if (ctrl & 0x10) { ctrl &= ~0x10; - return regmap_write(data->regmap, SBRMI_CTRL, ctrl); + return regmap_write(rmi_dev->regmap, SBRMI_CTRL, ctrl); } return 0; } -static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) +static int sbrmi_get_max_pwr_limit(struct apml_sbrmi_device *rmi_dev) { - struct sbrmi_mailbox_msg msg = { 0 }; + struct apml_message msg = { 0 }; int ret; msg.cmd = SBRMI_READ_PKG_MAX_PWR_LIMIT; - msg.read = true; - ret = rmi_mailbox_xfer(data, &msg); + msg.data_in.reg_in[RD_FLAG_INDEX] = 1; + ret = rmi_mailbox_xfer(rmi_dev, &msg); if (ret < 0) return ret; - data->pwr_limit_max = msg.data_out; + rmi_dev->pwr_limit_max = msg.data_out.mb_out[RD_WR_DATA_INDEX]; return ret; } @@ -61,40 +61,76 @@ static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data) static int sbrmi_i2c_probe(struct i2c_client *client) { struct device *dev = &client->dev; - struct sbrmi_data *data; + struct apml_sbrmi_device *rmi_dev; struct regmap_config sbrmi_i2c_regmap_config = { .reg_bits = 8, .val_bits = 8, }; int ret; - data = devm_kzalloc(dev, sizeof(struct sbrmi_data), GFP_KERNEL); - if (!data) + rmi_dev = devm_kzalloc(dev, sizeof(struct apml_sbrmi_device), GFP_KERNEL); + if (!rmi_dev) return -ENOMEM; - mutex_init(&data->lock); + atomic_set(&rmi_dev->in_progress, 0); + atomic_set(&rmi_dev->no_new_trans, 0); + mutex_init(&rmi_dev->lock); - data->regmap = devm_regmap_init_i2c(client, &sbrmi_i2c_regmap_config); - if (IS_ERR(data->regmap)) - return PTR_ERR(data->regmap); + rmi_dev->regmap = devm_regmap_init_i2c(client, &sbrmi_i2c_regmap_config); + if (IS_ERR(rmi_dev->regmap)) + return PTR_ERR(rmi_dev->regmap); /* Enable alert for SB-RMI sequence */ - ret = sbrmi_enable_alert(data); + ret = sbrmi_enable_alert(rmi_dev); if (ret < 0) return ret; /* Cache maximum power limit */ - ret = sbrmi_get_max_pwr_limit(data); + ret = sbrmi_get_max_pwr_limit(rmi_dev); if (ret < 0) return ret; - dev_set_drvdata(dev, (void *)data); + dev_set_drvdata(dev, (void *)rmi_dev); ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, apml_sbrmi, ARRAY_SIZE(apml_sbrmi), NULL, 0, NULL); - if (ret) + if (ret) { dev_err(dev, "Failed to register for sub-devices: %d\n", ret); - return ret; + return ret; + } + + rmi_dev->dev_static_addr = client->addr; + init_completion(&rmi_dev->misc_fops_done); + return create_misc_rmi_device(rmi_dev, dev); +} + +static void sbrmi_i2c_remove(struct i2c_client *client) +{ + struct apml_sbrmi_device *rmi_dev = dev_get_drvdata(&client->dev); + + if (!rmi_dev) + return; + /* + * Set the no_new_trans so no new transaction can + * occur in sbrmi_ioctl + */ + atomic_set(&rmi_dev->no_new_trans, 1); + /* + * If any transaction is in progress wait for the + * transaction to get complete + * Max wait is 3 sec for any pending transaction to + * complete. + */ + if (atomic_read(&rmi_dev->in_progress)) + wait_for_completion_timeout(&rmi_dev->misc_fops_done, + MAX_WAIT_TIME_SEC * HZ); + misc_deregister(&rmi_dev->sbrmi_misc_dev); + /* Assign fops and parent of misc dev to NULL */ + rmi_dev->sbrmi_misc_dev.fops = NULL; + rmi_dev->sbrmi_misc_dev.parent = NULL; + dev_info(&client->dev, "Removed sbrmi driver\n"); + + return; } static const struct i2c_device_id sbrmi_id[] = { @@ -117,6 +153,7 @@ static struct i2c_driver sbrmi_driver = { .of_match_table = of_match_ptr(sbrmi_of_match), }, .probe = sbrmi_i2c_probe, + .remove = sbrmi_i2c_remove, .id_table = sbrmi_id, }; diff --git a/include/linux/mfd/amd-sb.h b/include/linux/mfd/amd-sb.h index 977b8228ffa1..7bb5b89bb71a 100644 --- a/include/linux/mfd/amd-sb.h +++ b/include/linux/mfd/amd-sb.h @@ -6,8 +6,10 @@ #ifndef _AMD_SB_H_ #define _AMD_SB_H_ +#include #include #include +#include /* * SB-RMI supports soft mailbox service request to MP1 (power management * firmware) through SBRMI inbound/outbound message registers. @@ -20,24 +22,32 @@ enum sbrmi_msg_id { SBRMI_READ_PKG_MAX_PWR_LIMIT, }; -/* Each client has this additional data */ -struct sbrmi_data { +/* + * Each client has this additional data + * in_progress: set during any transaction, mailbox/cpuid/mcamsr/readreg, + * to indicate a transaction is in progress. + * no_new_trans: set in rmmod/unbind path to indicate, + * not to accept new transactions + */ +struct apml_sbrmi_device { + struct completion misc_fops_done; + struct miscdevice sbrmi_misc_dev; struct regmap *regmap; + /* Mutex locking */ struct mutex lock; + atomic_t in_progress; + atomic_t no_new_trans; u32 pwr_limit_max; + u8 dev_static_addr; + u8 rev; } __packed; -struct sbrmi_mailbox_msg { - u8 cmd; - bool read; - u32 data_in; - u32 data_out; -}; - #if IS_ENABLED(CONFIG_MFD_SBRMI_I2C) -int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg); +int rmi_mailbox_xfer(struct apml_sbrmi_device *rmi_dev, + struct apml_message *msg); #else -int rmi_mailbox_xfer(struct sbrmi_data *data, struct sbrmi_mailbox_msg *msg) +int rmi_mailbox_xfer(struct apml_sbrmi_device *rmi_dev, + struct apml_message *msg) { return -EOPNOTSUPP; } diff --git a/include/uapi/linux/amd-apml.h b/include/uapi/linux/amd-apml.h new file mode 100644 index 000000000000..11d34ee83b87 --- /dev/null +++ b/include/uapi/linux/amd-apml.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (C) 2021-2024 Advanced Micro Devices, Inc. + */ +#ifndef _AMD_APML_H_ +#define _AMD_APML_H_ + +#include + +enum apml_protocol { + APML_CPUID = 0x1000, + APML_MCA_MSR, + APML_REG, +}; + +/* These are byte indexes into data_in and data_out arrays */ +#define RD_WR_DATA_INDEX 0 +#define REG_OFF_INDEX 0 +#define REG_VAL_INDEX 4 +#define THREAD_LOW_INDEX 4 +#define THREAD_HI_INDEX 5 +#define EXT_FUNC_INDEX 6 +#define RD_FLAG_INDEX 7 + +#define MB_DATA_SIZE 4 + +struct apml_message { + /* message ids: + * Mailbox Messages: 0x0 ... 0x999 + * APML_CPUID: 0x1000 + * APML_MCA_MSR: 0x1001 + * APML_REG: 0x1002 + */ + __u32 cmd; + + /* + * 8 bit data for reg read, + * 32 bit data in case of mailbox, + * up to 64 bit in case of cpuid and mca msr + */ + union { + __u64 cpu_msr_out; + __u32 mb_out[2]; + __u8 reg_out[8]; + } data_out; + + /* + * [0]...[3] mailbox 32bit input + * cpuid & mca msr, + * rmi rd/wr: reg_offset + * [4][5] cpuid & mca msr: thread + * [4] rmi reg wr: value + * [6] cpuid: ext function & read eax/ebx or ecx/edx + * [7:0] -> bits [7:4] -> ext function & + * bit [0] read eax/ebx or ecx/edx + * [7] read/write functionality + */ + union { + __u64 cpu_msr_in; + __u32 mb_in[2]; + __u8 reg_in[8]; + } data_in; + /* + * Status code is returned in case of CPUID/MCA access + * Error code is returned in case of soft mailbox + */ + __u32 fw_ret_code; +} __attribute__((packed)); + +/* ioctl command for mailbox msgs using generic _IOWR */ +#define SBRMI_BASE_IOCTL_NR 0xF9 +#define SBRMI_IOCTL_CMD _IOWR(SBRMI_BASE_IOCTL_NR, 0, struct apml_message) + +#endif /*_AMD_APML_H_*/