From nobody Sat Oct 4 00:21:54 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE38C2F1FE9 for ; Fri, 22 Aug 2025 09:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856209; cv=none; b=auoh+DN7aVbaEVVyjkv3R+1urpfghV1U8G54n+ZgQZYPuW51QXEFTrDHMF9rc4TyQdE2ENFrVELdkO0Uh6Rq1IIXx8FzgwzqmcSzSBpYTWruEqSqq+aJPThQGma6+Q3EzVzx9PZe/UGezebtX1/P8Neq+sv6h/3EapzakWzwPH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856209; c=relaxed/simple; bh=oV2HxxQkc9L78N0dOZfJP1FvOtUI5qX83WY6+EX8hjU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EXqNKFGAt6MBQbIlDPSzhz/g6FM9YAjHjJVTDYdzVvYb/bnYTRuwUyK3hrBNKpd08sl1HwVq2CMu+po/DFcdHaVU1sOImNk3y8OYbRaLBrTOXiev/j8kuUdCHlA9aW9SUgwefRzutLzUgc5xzwfudd6x0QOII54PfksXSw0+EsM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [223.64.68.89]) by gateway (Coremail) with SMTP id _____8BxG9I0PahoFO4BAA--.3398S3; Fri, 22 Aug 2025 17:49:40 +0800 (CST) Received: from localhost.localdomain (unknown [223.64.68.89]) by front1 (Coremail) with SMTP id qMiowJAxfcEsPahoGeVfAA--.44506S3; Fri, 22 Aug 2025 17:49:38 +0800 (CST) From: Binbin Zhou To: Binbin Zhou , Huacai Chen , Lee Jones , Corey Minyard Cc: Huacai Chen , Xuerui Wang , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, openipmi-developer@lists.sourceforge.net, jeffbai@aosc.io, kexybiscuit@aosc.io, wangyao@lemote.com, Binbin Zhou , Chong Qiao , Corey Minyard Subject: [PATCH v10 1/3] mfd: ls2kbmc: Introduce Loongson-2K BMC core driver Date: Fri, 22 Aug 2025 17:49:23 +0800 Message-ID: <3bc527944947480aba00ee05cb5078080591e4b5.1755853480.git.zhoubinbin@loongson.cn> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJAxfcEsPahoGeVfAA--.44506S3 X-CM-SenderInfo: p2kr3uplqex0o6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBj93XoW3Jw1DWF1rZr1rXw1DKF1rGrX_yoWfWry5p3 WxAay5CF1DJF47Ga9xAr1UuFs3ua9Yv3y5Xa9rJwnI9a13C34DXw4ktFya9ryDJFyvgry2 qF9xJr4UC3ZxJFcCm3ZEXasCq-sJn29KB7ZKAUJUUUUf529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1a6r1DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1ln4kS14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2 x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5 McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr4 1lc7CjxVAaw2AFwI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1l4IxYO2xFxVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI 8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v2 6r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUoEfOUUUUU Content-Type: text/plain; charset="utf-8" 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-3 CPU. It supports multiple sub-devices like DRM and IPMI. Co-developed-by: Chong Qiao Signed-off-by: Chong Qiao Reviewed-by: Huacai Chen Acked-by: Corey Minyard Signed-off-by: Binbin Zhou --- MAINTAINERS | 6 ++ drivers/mfd/Kconfig | 13 +++ drivers/mfd/Makefile | 2 + drivers/mfd/ls2k-bmc-core.c | 189 ++++++++++++++++++++++++++++++++++++ 4 files changed, 210 insertions(+) create mode 100644 drivers/mfd/ls2k-bmc-core.c diff --git a/MAINTAINERS b/MAINTAINERS index fe168477caa4..48783add7a8b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14408,6 +14408,12 @@ S: Maintained F: Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml F: drivers/thermal/loongson2_thermal.c =20 +LOONGSON-2K Board Management Controller (BMC) DRIVER +M: Binbin Zhou +M: Chong Qiao +S: Maintained +F: drivers/mfd/ls2k-bmc-core.c + LOONGSON EDAC DRIVER M: Zhao Qunqin L: linux-edac@vger.kernel.org diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index a403a3daedd5..5c6a7f2e1154 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -2428,6 +2428,19 @@ config MFD_INTEL_M10_BMC_PMCI additional drivers must be enabled in order to use the functionality of the device. =20 +config MFD_LS2K_BMC_CORE + bool "Loongson-2K Board Management Controller Support" + depends on PCI && ACPI_GENERIC_GSI + 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 display and IPMI. This driver provides common + support for accessing the devices. + + The display is enabled by default in the driver, while the IPMI interfa= ce + is enabled independently through the IPMI_LS2K option in the IPMI secti= on. + config MFD_QNAP_MCU tristate "QNAP microcontroller unit core driver" depends on SERIAL_DEV_BUS diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index f7bdedd5a66d..a950e670efba 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -286,6 +286,8 @@ obj-$(CONFIG_MFD_INTEL_M10_BMC_CORE) +=3D intel-m10-b= mc-core.o obj-$(CONFIG_MFD_INTEL_M10_BMC_SPI) +=3D intel-m10-bmc-spi.o obj-$(CONFIG_MFD_INTEL_M10_BMC_PMCI) +=3D intel-m10-bmc-pmci.o =20 +obj-$(CONFIG_MFD_LS2K_BMC_CORE) +=3D ls2k-bmc-core.o + obj-$(CONFIG_MFD_ATC260X) +=3D atc260x-core.o obj-$(CONFIG_MFD_ATC260X_I2C) +=3D atc260x-i2c.o =20 diff --git a/drivers/mfd/ls2k-bmc-core.c b/drivers/mfd/ls2k-bmc-core.c new file mode 100644 index 000000000000..39cc481d9ba1 --- /dev/null +++ b/drivers/mfd/ls2k-bmc-core.c @@ -0,0 +1,189 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Loongson-2K Board Management Controller (BMC) Core Driver. + * + * Copyright (C) 2024-2025 Loongson Technology Corporation Limited. + * + * Authors: + * Chong Qiao + * Binbin Zhou + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* LS2K BMC resources */ +#define LS2K_DISPLAY_RES_START (SZ_16M + SZ_2M) +#define LS2K_IPMI_RES_SIZE 0x1C +#define LS2K_IPMI0_RES_START (SZ_16M + 0xF00000) +#define LS2K_IPMI1_RES_START (LS2K_IPMI0_RES_START + LS2K_IPMI_RES_SIZE) +#define LS2K_IPMI2_RES_START (LS2K_IPMI1_RES_START + LS2K_IPMI_RES_SIZE) +#define LS2K_IPMI3_RES_START (LS2K_IPMI2_RES_START + LS2K_IPMI_RES_SIZE) +#define LS2K_IPMI4_RES_START (LS2K_IPMI3_RES_START + LS2K_IPMI_RES_SIZE) + +enum { + LS2K_BMC_DISPLAY, + LS2K_BMC_IPMI0, + LS2K_BMC_IPMI1, + LS2K_BMC_IPMI2, + LS2K_BMC_IPMI3, + LS2K_BMC_IPMI4, +}; + +static struct resource ls2k_display_resources[] =3D { + DEFINE_RES_MEM_NAMED(LS2K_DISPLAY_RES_START, SZ_4M, "simpledrm-res"), +}; + +static struct resource ls2k_ipmi0_resources[] =3D { + DEFINE_RES_MEM_NAMED(LS2K_IPMI0_RES_START, LS2K_IPMI_RES_SIZE, "ipmi0-res= "), +}; + +static struct resource ls2k_ipmi1_resources[] =3D { + DEFINE_RES_MEM_NAMED(LS2K_IPMI1_RES_START, LS2K_IPMI_RES_SIZE, "ipmi1-res= "), +}; + +static struct resource ls2k_ipmi2_resources[] =3D { + DEFINE_RES_MEM_NAMED(LS2K_IPMI2_RES_START, LS2K_IPMI_RES_SIZE, "ipmi2-res= "), +}; + +static struct resource ls2k_ipmi3_resources[] =3D { + DEFINE_RES_MEM_NAMED(LS2K_IPMI3_RES_START, LS2K_IPMI_RES_SIZE, "ipmi3-res= "), +}; + +static struct resource ls2k_ipmi4_resources[] =3D { + DEFINE_RES_MEM_NAMED(LS2K_IPMI4_RES_START, LS2K_IPMI_RES_SIZE, "ipmi4-res= "), +}; + +static struct mfd_cell ls2k_bmc_cells[] =3D { + [LS2K_BMC_DISPLAY] =3D { + .name =3D "simple-framebuffer", + .num_resources =3D ARRAY_SIZE(ls2k_display_resources), + .resources =3D ls2k_display_resources + }, + [LS2K_BMC_IPMI0] =3D { + .name =3D "ls2k-ipmi-si", + .num_resources =3D ARRAY_SIZE(ls2k_ipmi0_resources), + .resources =3D ls2k_ipmi0_resources + }, + [LS2K_BMC_IPMI1] =3D { + .name =3D "ls2k-ipmi-si", + .num_resources =3D ARRAY_SIZE(ls2k_ipmi1_resources), + .resources =3D ls2k_ipmi1_resources + }, + [LS2K_BMC_IPMI2] =3D { + .name =3D "ls2k-ipmi-si", + .num_resources =3D ARRAY_SIZE(ls2k_ipmi2_resources), + .resources =3D ls2k_ipmi2_resources + }, + [LS2K_BMC_IPMI3] =3D { + .name =3D "ls2k-ipmi-si", + .num_resources =3D ARRAY_SIZE(ls2k_ipmi3_resources), + .resources =3D ls2k_ipmi3_resources + }, + [LS2K_BMC_IPMI4] =3D { + .name =3D "ls2k-ipmi-si", + .num_resources =3D ARRAY_SIZE(ls2k_ipmi4_resources), + .resources =3D ls2k_ipmi4_resources + }, +}; + +/* + * Currently the Loongson-2K BMC hardware does not have an I2C interface t= o adapt to the + * resolution. We set the resolution by presetting "video=3D1280x1024-16@2= M" to the BMC memory. + */ +static int ls2k_bmc_parse_mode(struct pci_dev *pdev, struct simplefb_platf= orm_data *pd) +{ + char *mode; + int depth, ret; + + /* The last 16M of PCI BAR0 is used to store the resolution string. */ + mode =3D devm_ioremap(&pdev->dev, pci_resource_start(pdev, 0) + SZ_16M, S= Z_16M); + if (!mode) + return -ENOMEM; + + /* The resolution field starts with the flag "video=3D". */ + if (!strncmp(mode, "video=3D", 6)) + mode =3D mode + 6; + + ret =3D kstrtoint(strsep(&mode, "x"), 10, &pd->width); + if (ret) + return ret; + + ret =3D kstrtoint(strsep(&mode, "-"), 10, &pd->height); + if (ret) + return ret; + + ret =3D kstrtoint(strsep(&mode, "@"), 10, &depth); + if (ret) + return ret; + + pd->stride =3D pd->width * depth / 8; + pd->format =3D depth =3D=3D 32 ? "a8r8g8b8" : "r5g6b5"; + + return 0; +} + +static int ls2k_bmc_probe(struct pci_dev *dev, const struct pci_device_id = *id) +{ + struct simplefb_platform_data pd; + resource_size_t base; + int ret; + + ret =3D pci_enable_device(dev); + if (ret) + return ret; + + ret =3D ls2k_bmc_parse_mode(dev, &pd); + if (ret) + goto disable_pci; + + ls2k_bmc_cells[LS2K_BMC_DISPLAY].platform_data =3D &pd; + ls2k_bmc_cells[LS2K_BMC_DISPLAY].pdata_size =3D sizeof(pd); + base =3D dev->resource[0].start + LS2K_DISPLAY_RES_START; + + /* Remove conflicting efifb device */ + ret =3D aperture_remove_conflicting_devices(base, SZ_4M, "simple-framebuf= fer"); + if (ret) { + dev_err(&dev->dev, "Failed to removed firmware framebuffers: %d\n", ret); + goto disable_pci; + } + + return devm_mfd_add_devices(&dev->dev, PLATFORM_DEVID_AUTO, + ls2k_bmc_cells, ARRAY_SIZE(ls2k_bmc_cells), + &dev->resource[0], 0, NULL); + +disable_pci: + pci_disable_device(dev); + return ret; +} + +static void ls2k_bmc_remove(struct pci_dev *dev) +{ + pci_disable_device(dev); +} + +static struct pci_device_id ls2k_bmc_devices[] =3D { + { PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, 0x1a05) }, + { } +}; +MODULE_DEVICE_TABLE(pci, ls2k_bmc_devices); + +static struct pci_driver ls2k_bmc_driver =3D { + .name =3D "ls2k-bmc", + .id_table =3D ls2k_bmc_devices, + .probe =3D ls2k_bmc_probe, + .remove =3D ls2k_bmc_remove, +}; +module_pci_driver(ls2k_bmc_driver); + +MODULE_DESCRIPTION("Loongson-2K Board Management Controller (BMC) Core dri= ver"); +MODULE_AUTHOR("Loongson Technology Corporation Limited"); +MODULE_LICENSE("GPL"); --=20 2.47.3