diff mbox series

[v1,1/4] mfd: ls2kbmc: Introduce Loongson-2K BMC MFD Core driver

Message ID 074e91224f0e48861e11954dc80c92de322906a2.1735550269.git.zhoubinbin@loongson.cn (mailing list archive)
State New
Headers show
Series LoongArch: Add Loongson-2K0500 BMC support | expand

Commit Message

Binbin Zhou Dec. 30, 2024, 9:31 a.m. UTC
The Loongson-2K Board Management Controller provides an PCIe
interface to the host to access the feature implemented in the BMC.

The BMC is assembled on a server similar to the server machine with
Loongson-3C6000 CPUs. It supports multiple sub-devices like DRM.

Co-developed-by: Chong Qiao <qiaochong@loongson.cn>
Signed-off-by: Chong Qiao <qiaochong@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
---
 drivers/mfd/Kconfig       |  15 ++++
 drivers/mfd/Makefile      |   2 +
 drivers/mfd/ls2kbmc-mfd.c | 145 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 162 insertions(+)
 create mode 100644 drivers/mfd/ls2kbmc-mfd.c
diff mbox series

Patch

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index ae23b317a64e..97d9d52b7e8a 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2414,5 +2414,20 @@  config MFD_RSMU_SPI
 	  Additional drivers must be enabled in order to use the functionality
 	  of the device.
 
+config MFD_LS2K_BMC
+	tristate "Loongson-2K Board Management Controller Support"
+	depends on LOONGARCH
+	select MFD_CORE
+	help
+	  Say yes here to add support for the Loongson-2K BMC
+	  which is a Board Management Controller connected to the PCIe bus.
+	  The device supports multiple sub-devices like DRM.
+	  This driver provides common support for accessing the devices;
+	  additional drivers must be enabled in order to use the
+	  functionality of the BMC device.
+
+	  This driver can also be built as a module. If so the module
+	  will be called ls2kbmc-mfd.
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index e057d6d6faef..3faec9638303 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -290,3 +290,5 @@  obj-$(CONFIG_MFD_ATC260X_I2C)	+= atc260x-i2c.o
 
 obj-$(CONFIG_MFD_RSMU_I2C)	+= rsmu_i2c.o rsmu_core.o
 obj-$(CONFIG_MFD_RSMU_SPI)	+= rsmu_spi.o rsmu_core.o
+
+obj-$(CONFIG_MFD_LS2K_BMC)	+= ls2kbmc-mfd.o
diff --git a/drivers/mfd/ls2kbmc-mfd.c b/drivers/mfd/ls2kbmc-mfd.c
new file mode 100644
index 000000000000..2912112c41c8
--- /dev/null
+++ b/drivers/mfd/ls2kbmc-mfd.c
@@ -0,0 +1,145 @@ 
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Loongson-2K Board Management Controller (BMC) MFD Core Driver.
+ *
+ * Copyright (C) 2024 Loongson Technology Corporation Limited.
+ *
+ * Originally written by Chong Qiao <qiaochong@loongson.cn>
+ * Rewritten for mainline by Binbin Zhou <zhoubinbin@loongson.cn>
+ */
+
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/pci_ids.h>
+#include <linux/platform_device.h>
+
+static struct resource ls2k_display_resources[] = {
+	{
+		.name	= "ls2kbmc-simplebuf-res",
+		.start	= SZ_16M + SZ_2M,
+		.end	= SZ_16M + SZ_2M + SZ_4M - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct resource ls2k_ipmi0_resources[] = {
+	{
+		.name	= "ipmi-res0",
+		.start	= SZ_16M + 0x00f00000,
+		.end	= SZ_16M + 0x00f00000 + 0x1c - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct resource ls2k_ipmi1_resources[] = {
+	{
+		.name	= "ipmi-res1",
+		.start	= SZ_16M + 0x00f00000 + 0x1c,
+		.end	= SZ_16M + 0x00f00000 + 0x1c * 2 - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct resource ls2k_ipmi2_resources[] = {
+	{
+		.name	= "ipmi-res2",
+		.start	= SZ_16M + 0x00f00000 + 0x1c * 2,
+		.end	= SZ_16M + 0x00f00000 + 0x1c * 3 - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct resource ls2k_ipmi3_resources[] = {
+	{
+		.name	= "ipmi-res3",
+		.start	= SZ_16M + 0x00f00000 + 0x1c * 3,
+		.end	= SZ_16M + 0x00f00000 + 0x1c * 4 - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct resource ls2k_ipmi4_resources[] = {
+	{
+		.name	= "ipmi-res4",
+		.start	= SZ_16M + 0x00f00000 + 0x1c * 4,
+		.end	= SZ_16M + 0x00f00000 + 0x1c * 5 - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct mfd_cell ls2k_bmc_cells[] = {
+	{
+		.name = "ls2kbmc-framebuffer",
+		.num_resources = ARRAY_SIZE(ls2k_display_resources),
+		.resources = ls2k_display_resources,
+	},
+	{
+		.name = "ls2k-ipmi-si",
+		.num_resources = ARRAY_SIZE(ls2k_ipmi0_resources),
+		.resources = ls2k_ipmi0_resources,
+	},
+	{
+		.name = "ls2k-ipmi-si",
+		.num_resources = ARRAY_SIZE(ls2k_ipmi1_resources),
+		.resources = ls2k_ipmi1_resources,
+	},
+	{
+		.name = "ls2k-ipmi-si",
+		.num_resources = ARRAY_SIZE(ls2k_ipmi2_resources),
+		.resources = ls2k_ipmi2_resources,
+	},
+	{
+		.name = "ls2k-ipmi-si",
+		.num_resources = ARRAY_SIZE(ls2k_ipmi3_resources),
+		.resources = ls2k_ipmi3_resources,
+	},
+	{
+		.name = "ls2k-ipmi-si",
+		.num_resources = ARRAY_SIZE(ls2k_ipmi4_resources),
+		.resources = ls2k_ipmi4_resources,
+	},
+};
+
+static int ls2k_bmc_probe(struct pci_dev *dev, const struct pci_device_id *id)
+{
+	int ret = 0;
+
+	ret = pci_enable_device(dev);
+	if (ret)
+		return ret;
+
+	ls2k_bmc_cells[0].platform_data = &dev;
+	ls2k_bmc_cells[0].pdata_size = sizeof(dev);
+
+	return devm_mfd_add_devices(&dev->dev, PLATFORM_DEVID_AUTO,
+				    ls2k_bmc_cells, ARRAY_SIZE(ls2k_bmc_cells),
+				    &dev->resource[0], 0, NULL);
+}
+
+static void ls2k_bmc_remove(struct pci_dev *dev)
+{
+	pci_disable_device(dev);
+}
+
+static struct pci_device_id ls2k_bmc_devices[] = {
+	{ PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, 0x1a05) },
+	{ }
+};
+MODULE_DEVICE_TABLE(pci, ls2k_bmc_devices);
+
+static struct pci_driver ls2k_bmc_driver = {
+	.name = "ls2k-bmc",
+	.id_table = ls2k_bmc_devices,
+	.probe = ls2k_bmc_probe,
+	.remove = ls2k_bmc_remove,
+};
+
+module_pci_driver(ls2k_bmc_driver);
+
+MODULE_DESCRIPTION("Loongson-2K BMC driver");
+MODULE_AUTHOR("Loongson Technology Corporation Limited");
+MODULE_LICENSE("GPL");