mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Akshay Gupta <akshay.gupta@amd.com>
To: <linux-kernel@vger.kernel.org>, <linux-hwmon@vger.kernel.org>
Cc: <gregkh@linuxfoundation.org>, <arnd@arndb.de>,
	<linux@roeck-us.net>, <Anand.Umarji@amd.com>,
	Akshay Gupta <akshay.gupta@amd.com>,
	"Naveen Krishna Chatradhi" <naveenkrishna.chatradhi@amd.com>
Subject: [PATCH v1 2/5] misc: amd-sbi: Add support for SB-RMI over I3C
Date: Mon, 28 Jul 2025 06:10:30 +0000	[thread overview]
Message-ID: <20250728061033.1604169-2-akshay.gupta@amd.com> (raw)
In-Reply-To: <20250728061033.1604169-1-akshay.gupta@amd.com>

AMD EPYC platforms with zen5 and later support APML(SB-RMI)
connection to the BMC over I3C bus for improved efficiency.
Add the same functionality supported by rmi-i2c.c over I3C bus.

Reviewed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>
Signed-off-by: Akshay Gupta <akshay.gupta@amd.com>
---
 drivers/misc/amd-sbi/Kconfig   |  15 +++-
 drivers/misc/amd-sbi/Makefile  |   2 +
 drivers/misc/amd-sbi/rmi-i3c.c | 133 +++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+), 2 deletions(-)
 create mode 100644 drivers/misc/amd-sbi/rmi-i3c.c

diff --git a/drivers/misc/amd-sbi/Kconfig b/drivers/misc/amd-sbi/Kconfig
index 9b1abeb6ab1a..838cf98805d9 100644
--- a/drivers/misc/amd-sbi/Kconfig
+++ b/drivers/misc/amd-sbi/Kconfig
@@ -15,10 +15,21 @@ config AMD_SBRMI_I2C
 	  This driver can also be built as a module. If so, the module will
 	  be called sbrmi-i2c.
 
+config AMD_SBRMI_I3C
+	tristate "AMD side band RMI support over I3C"
+	depends on I3C
+	select AMD_SBRMI
+	select REGMAP_I3C
+	help
+	  Side band RMI over I3C support for AMD out of band management.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called sbrmi-i3c.
+
 config AMD_SBRMI_HWMON
 	bool "SBRMI hardware monitoring"
-	depends on AMD_SBRMI_I2C && HWMON
-	depends on !(AMD_SBRMI_I2C=y && HWMON=m)
+	depends on (AMD_SBRMI_I2C || AMD_SBRMI_I3C) && HWMON
+	depends on !(AMD_SBRMI_I2C=y && HWMON=m) || !(AMD_SBRMI_I3C=y && HWMON=m)
 	help
 	  This provides support for RMI device hardware monitoring. If enabled,
 	  a hardware monitoring device will be created for each socket in
diff --git a/drivers/misc/amd-sbi/Makefile b/drivers/misc/amd-sbi/Makefile
index 6f3090fb9ff3..e43d4058a0f0 100644
--- a/drivers/misc/amd-sbi/Makefile
+++ b/drivers/misc/amd-sbi/Makefile
@@ -4,3 +4,5 @@ sbrmi_core-y			:= rmi-core.o
 obj-$(CONFIG_AMD_SBRMI_HWMON)	+= rmi-hwmon.o
 sbrmi-i2c-y			:= rmi-i2c.o
 obj-$(CONFIG_AMD_SBRMI_I2C)	+= sbrmi-i2c.o
+sbrmi-i3c-y  			:= rmi-i3c.o
+obj-$(CONFIG_AMD_SBRMI_I3C)	+= sbrmi-i3c.o
diff --git a/drivers/misc/amd-sbi/rmi-i3c.c b/drivers/misc/amd-sbi/rmi-i3c.c
new file mode 100644
index 000000000000..b960743afad1
--- /dev/null
+++ b/drivers/misc/amd-sbi/rmi-i3c.c
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * rmi-i3c.c - Side band RMI over I3C support for AMD out
+ *             of band management
+ *
+ * Copyright (C) 2025 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/i3c/device.h>
+#include <linux/i3c/master.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/regmap.h>
+#include "rmi-core.h"
+
+static int sbrmi_enable_alert(struct sbrmi_data *data)
+{
+	int ctrl, ret;
+
+	/*
+	 * 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);
+	if (ret < 0)
+		return ret;
+
+	if (ctrl & 0x10) {
+		ctrl &= ~0x10;
+		return regmap_write(data->regmap, SBRMI_CTRL, ctrl);
+	}
+
+	return 0;
+}
+
+static int sbrmi_get_max_pwr_limit(struct sbrmi_data *data)
+{
+	struct apml_mbox_msg msg = { 0 };
+	int ret;
+
+	msg.cmd = SBRMI_READ_PKG_MAX_PWR_LIMIT;
+	ret = rmi_mailbox_xfer(data, &msg);
+	if (ret < 0)
+		return ret;
+	data->pwr_limit_max = msg.mb_in_out;
+
+	return ret;
+}
+
+static int sbrmi_i3c_probe(struct i3c_device *i3cdev)
+{
+	struct device *dev = &i3cdev->dev;
+	struct sbrmi_data *data;
+	struct regmap_config sbrmi_i3c_regmap_config = {
+		.reg_bits = 8,
+		.val_bits = 8,
+	};
+	int ret;
+
+	data = devm_kzalloc(dev, sizeof(struct sbrmi_data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	mutex_init(&data->lock);
+
+	data->regmap = devm_regmap_init_i3c(i3cdev, &sbrmi_i3c_regmap_config);
+	if (IS_ERR(data->regmap))
+		return PTR_ERR(data->regmap);
+
+	/* Enable alert for SB-RMI sequence */
+	ret = sbrmi_enable_alert(data);
+	if (ret < 0)
+		return ret;
+
+	/* Cache maximum power limit */
+	ret = sbrmi_get_max_pwr_limit(data);
+	if (ret < 0)
+		return ret;
+
+	/*
+	 * AMD APML I3C devices support static address
+	 */
+	if (i3cdev->desc->info.static_addr)
+		data->dev_static_addr = i3cdev->desc->info.static_addr;
+	else
+		data->dev_static_addr = i3cdev->desc->info.dyn_addr;
+
+	dev_set_drvdata(dev, data);
+
+	ret = create_hwmon_sensor_device(dev, data);
+	if (ret < 0)
+		return ret;
+	return create_misc_rmi_device(data, dev);
+}
+
+static void sbrmi_i3c_remove(struct i3c_device *i3cdev)
+{
+	struct sbrmi_data *data = dev_get_drvdata(&i3cdev->dev);
+
+	misc_deregister(&data->sbrmi_misc_dev);
+	/* Assign fops and parent of misc dev to NULL */
+	data->sbrmi_misc_dev.fops = NULL;
+	data->sbrmi_misc_dev.parent = NULL;
+	dev_info(&i3cdev->dev, "Removed sbrmi-i3c driver\n");
+}
+
+static const struct i3c_device_id sbrmi_i3c_id[] = {
+	/* PID for AMD SBRMI device */
+	I3C_DEVICE_EXTRA_INFO(0x112, 0x0, 0x2, NULL),
+	{}
+};
+MODULE_DEVICE_TABLE(i3c, sbrmi_i3c_id);
+
+static struct i3c_driver sbrmi_i3c_driver = {
+	.driver = {
+		.name = "sbrmi-i3c",
+	},
+	.probe = sbrmi_i3c_probe,
+	.remove = sbrmi_i3c_remove,
+	.id_table = sbrmi_i3c_id,
+};
+
+module_i3c_driver(sbrmi_i3c_driver);
+
+MODULE_IMPORT_NS("AMD_SBRMI");
+MODULE_AUTHOR("Akshay Gupta <akshay.gupta@amd.com>");
+MODULE_AUTHOR("Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>");
+MODULE_DESCRIPTION("AMD SB-RMI driver over I3C");
+MODULE_LICENSE("GPL");
-- 
2.25.1


  reply	other threads:[~2025-07-28  6:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-28  6:10 [PATCH v1 1/5] misc: amd-sbi: Split core driver as separate module Akshay Gupta
2025-07-28  6:10 ` Akshay Gupta [this message]
2025-07-28  6:37   ` [PATCH v1 2/5] misc: amd-sbi: Add support for SB-RMI over I3C Thomas Weißschuh
2025-08-11 11:02     ` Gupta, Akshay
2025-07-29  6:33   ` Krzysztof Kozlowski
2025-08-11 11:03     ` Gupta, Akshay
2025-07-28  6:10 ` [PATCH v1 3/5] dt-bindings: misc: Move amd,sbrmi.yaml from hwmon to misc Akshay Gupta
2025-07-29  6:29   ` Krzysztof Kozlowski
2025-08-11 11:54     ` Gupta, Akshay
2025-08-11 11:56       ` Krzysztof Kozlowski
2025-07-28  6:10 ` [PATCH v1 4/5] dt-bindings: misc: Update the "$id:" to misc path Akshay Gupta
2025-07-29  6:29   ` Krzysztof Kozlowski
2025-07-28  6:10 ` [PATCH v1 5/5] dt-bindings: misc: Add binding document for SB-RMI I3C Akshay Gupta
2025-07-29  6:31   ` Krzysztof Kozlowski
2025-08-11 11:55     ` Gupta, Akshay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250728061033.1604169-2-akshay.gupta@amd.com \
    --to=akshay.gupta@amd.com \
    --cc=Anand.Umarji@amd.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=naveenkrishna.chatradhi@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®