From patchwork Sun Apr 28 01:24:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inochi Amaoto X-Patchwork-Id: 1928555 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=wER0VuWh; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=outlook.com header.i=@outlook.com header.a=rsa-sha256 header.s=selector1 header.b=tw+Y9x/8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VRpf04VMWz23hv for ; Sun, 28 Apr 2024 11:24:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=PRyIFRno65tI6f6cUva5EwnyJ/g1lWj3dvpdvQ5KoDQ=; b=wER0VuWh1rEkJ4 1JJBONjKUNPiNXGwe8x4BhSRNSG5B22ps/qUQIq3TPLtMcjj46us+7mZXyKxLuXYYDKjSk3xQilTk 1oZ/+VVtuqwM7yk7cUYrBpWYSp3HXxrJ6e0Iv2PLWEA+WknqjulL4Rr21uMHAbWMEwZy849UFzs8H 2Nf8wyleRv3sdy8PnhD42b77+8DAbFwv1F4WDdw9xYuCA/j2jmSLLnM6IIDY0sEfAZ3f9WBy6q91S jdvoG36ueHDAcgv3mrAQLcTUsT2onVEvBue4676wGNl1MRKvrj0RxfWr7AU96f6p0rwbbB8RT6UhU LzHweVil+fv6wmhMdBBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s0tGw-0000000GYv5-1o3t; Sun, 28 Apr 2024 01:24:06 +0000 Received: from mail-dm6nam10acsn20805.outbound.protection.outlook.com ([2a01:111:f400:7e88::805] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s0tGs-0000000GYu9-143T for opensbi@lists.infradead.org; Sun, 28 Apr 2024 01:24:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cIHUA74PMWXXrsmjwG3ezRhZEGfu3ZL+OkUvjyslxIoKW4XlBHOniPJ03ny1nvtj5BRs3o/8oD16GNeXhDldJpkuKZLyZDlepHn5/vJ/6/5y7zi6bxO4xMrHSAludlHyHrrSKeuJZn7nWSHKNtHhTzvmWmKSkdvi0Nbg6rq/pjJRrcm0B4EqqIL1jf4Wj29J2GHtJaysH/Q1O7+u5SBTw1XJAuN9E3sf/+gOg34jg1Bax1LTCbrHXIxpHTpMUVGcQZaMrQAEU4UxM2pSnzqUC3vxAMTlxgja3pjhaSekPxjh/6rot5pP59yM4mJ5ZtlKw8Id0xqQayKTru0dQ1/erg== 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=NmuKJt/A8G9nUuK2N2HJkkMcdKuv5RbDoTBHwF11Ub8=; b=PeWgWMAlmPyVb2xwL0vZh1JiRhjLk0c6mlVfkFwyB7Y8BJpKEeJ5cVkLyoZsqeIqtWMZSjjARBzPFI/+YIr6yFHkOgxCyayYGYlaJTTQwWGhRVFwtvPJkPNFdB5Lb7oQOnWfGaI77+zFgGk2sjI3arh/C82SnDU8ILXqISUZ0XkLixMd9l9GmFbQ+buASZy3LFnGiW71uXCNpj/W9dpPZkB83+ygr2zlScKj84eROQQ4LnvUVm5tEiOAYL2pcZQ/jn+zrMcNAcmzjYP84DRQGIJ85imcElmvysGRjXRi+SNSP/rqfKfqSmMgsyi8S24ip0ql1CQHCpDs2sQXMeFnKQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NmuKJt/A8G9nUuK2N2HJkkMcdKuv5RbDoTBHwF11Ub8=; b=tw+Y9x/8L2GxtWk4s/Me0jvS6GflGSdq9bPk+B1pzY6Oq87f08wEdfpvpRavNew4TdsZQUnpsMDs8ozAlf4b+efgQCC1Dk+0N1aMqJiRA9Z8kjtPF+L6zeN9hpbPATdZxvF5lb9EmBLUINfiEQKA2ENXgYFY+EwbkWknUIoqk+MjIRcAJ9kJFW+IrhWZIsRU17FSpyct5n4Q+08hHxIJxQaNuwGsa/fBw9M+kk1qXzTDENmAkUGT9w6TCGD8BcAVo2DbpLAHdBjHNDGn+kh0s0Iw5f1dxDphK8TEo5iwsQtUiWup7GBWlyYtZYxjQt9ADS8KsEGjI2NXLLuuWglpbA== Received: from IA1PR20MB4953.namprd20.prod.outlook.com (2603:10b6:208:3af::19) by CYYPR20MB6663.namprd20.prod.outlook.com (2603:10b6:930:be::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.32; Sun, 28 Apr 2024 01:23:47 +0000 Received: from IA1PR20MB4953.namprd20.prod.outlook.com ([fe80::182f:841b:6e76:b819]) by IA1PR20MB4953.namprd20.prod.outlook.com ([fe80::182f:841b:6e76:b819%2]) with mapi id 15.20.7519.030; Sun, 28 Apr 2024 01:23:46 +0000 From: Inochi Amaoto To: opensbi@lists.infradead.org Cc: Chen Wang , Inochi Amaoto Subject: [PATCH] utils/reset: Add SG2042 hwmon MCU support. Date: Sun, 28 Apr 2024 09:24:10 +0800 Message-ID: X-Mailer: git-send-email 2.44.0 X-TMN: [RN8dK1K800aLW9hn393okR5AnPT4cF2ZnSmiwSXLqHc=] X-ClientProxiedBy: SI2P153CA0017.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::10) To IA1PR20MB4953.namprd20.prod.outlook.com (2603:10b6:208:3af::19) X-Microsoft-Original-Message-ID: <20240428012410.470431-1-inochiama@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA1PR20MB4953:EE_|CYYPR20MB6663:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a138eea-bdc9-4c90-9338-08dc6721d94a X-Microsoft-Antispam: BCL:0;ARA:14566002|461199019|440099019|3412199016|1710799017; X-Microsoft-Antispam-Message-Info: wsZ7ZTljt6OQiQ5LEgHUAROxwP7tqD3IorsJBHfocZPdIGXb+486rcQyVmwZXIL7J+fBsnWVGd3j2hhKV/laUwgcgtLfp6dnEut/gU/Hbt9JU98rosHiE6ji89L8ezcN9cpwB2Tmorx4rciC9p3j2wAXJaHV3LQqaD78Z/YHbBrRQHFi7kjN8NtRGibwkTJXMwcprljrWlMExUwtxlSHW0PK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+F7NPtX83hH5aaSYofPG6kMpjw1e+UNfwuZxcvVSXgcwDID3y9QTnt5ZKTwWokOzEfU1iEe4ZXfxAa/rkfML/8QiA+hrUBQkZeiGTeiBc9BBv2g05sUusmG94dQp/T9Cpurg2dKT6kRpDIvmY0Ld+c46JMmAN914a9RbO8YNH+1EPT11siu1fKwjLNP4J9FYD19p430j8KATgUdia8v7r14aReo8O7VDPl2yGKRnZUERip37yHCzYGpaBEKyjH7ZjB4furh2Vg0leOvPDKEd7PssllE82RHevdFHieKwql0um05ITlmsw++dlDuZuN+eLTfvGA00kTudhXDGBE98GpI1aBctyAHZoluDgBlE1McBr7rQiMdOqflx2UnkhRw69E5Drcgemit09wCsTpsy/CScFxtePPVuOpmzVNgPJKDI7LkIi44sQsTxv8X9iDmDtR32ItKYXQA+gu/WvXnW7PnzthV0jvJLD9VKJ/TEv9/OLvo44GywFYcnfFqT5GR1vBtflecDhr1vutAL29DWy88Hor+4t7j4I12t14RH0ZSZ9mRJM9cVkGST/HoH/YKnIbPX1oWIiJnBFE9M2QK9Jvyjk8VcxDVqRczm6pxuAFay1QyfZMiPLEiHc+61cg6nsvFOo5PqW//CfC3zUlR X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4a138eea-bdc9-4c90-9338-08dc6721d94a X-MS-Exchange-CrossTenant-AuthSource: IA1PR20MB4953.namprd20.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2024 01:23:45.9454 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR20MB6663 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240427_182402_341778_F5AF987E X-CRM114-Status: GOOD ( 14.10 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: SG2042 uses an onboard MCU to provide reset function. Add reset driver to support this onboard MCU. Signed-off-by: Inochi Amaoto --- lib/utils/reset/Kconfig | 4 + lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c | 114 +++++++++++++++++++ lib/utils/reset/objects.mk | 3 + platform/generic/configs/defcon [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 ARC_VALID Message has a valid ARC signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 ARC_SIGNED Message has a ARC signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [inochiama(at)outlook.com] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org SG2042 uses an onboard MCU to provide reset function. Add reset driver to support this onboard MCU. Signed-off-by: Inochi Amaoto Reviewed-by: Anup Patel --- lib/utils/reset/Kconfig | 4 + lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c | 114 +++++++++++++++++++ lib/utils/reset/objects.mk | 3 + platform/generic/configs/defconfig | 1 + 4 files changed, 122 insertions(+) create mode 100644 lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c -- 2.44.0 diff --git a/lib/utils/reset/Kconfig b/lib/utils/reset/Kconfig index b26260d..6c077fe 100644 --- a/lib/utils/reset/Kconfig +++ b/lib/utils/reset/Kconfig @@ -24,6 +24,10 @@ config FDT_RESET_HTIF select SYS_HTIF default n +config FDT_RESET_SG2042_HWMON_MCU + bool "Sophgo SG2042 hwmon MCU FDT reset driver" + default n + config FDT_RESET_SUNXI_WDT bool "Sunxi WDT FDT reset driver" default n diff --git a/lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c b/lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c new file mode 100644 index 0000000..51bd74a --- /dev/null +++ b/lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c @@ -0,0 +1,114 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Lin Chunzhi + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MANGO_BOARD_TYPE_MASK 0x80 + +#define REG_BOARD_TYPE 0x00 +#define REG_CMD 0x03 + +#define CMD_POWEROFF 0x02 +#define CMD_RESET 0x03 +#define CMD_REBOOT 0x07 + +static struct i2c_adapter *mcu_adapter = NULL; +static uint32_t mcu_reg = 0; + +static int sg2042_mcu_reset_check(u32 type, u32 reason) +{ + switch (type) { + case SBI_SRST_RESET_TYPE_SHUTDOWN: + return 1; + case SBI_SRST_RESET_TYPE_COLD_REBOOT: + case SBI_SRST_RESET_TYPE_WARM_REBOOT: + return 255; + } + + return 0; +} + +static void sg2042_mcu_reset(u32 type, u32 reason) +{ + switch (type) { + case SBI_SRST_RESET_TYPE_SHUTDOWN: + i2c_adapter_reg_write(mcu_adapter, mcu_reg, + REG_CMD, CMD_POWEROFF); + break; + case SBI_SRST_RESET_TYPE_COLD_REBOOT: + case SBI_SRST_RESET_TYPE_WARM_REBOOT: + i2c_adapter_reg_write(mcu_adapter, mcu_reg, + REG_CMD, CMD_REBOOT); + break; + } +} + +static struct sbi_system_reset_device sg2042_mcu_reset_device = { + .name = "sg2042-mcu-reset", + .system_reset_check = sg2042_mcu_reset_check, + .system_reset = sg2042_mcu_reset +}; + +static int sg2042_mcu_reset_check_board(struct i2c_adapter *adap, uint32_t reg) +{ + static uint8_t val; + int ret; + + /* check board type */ + ret = i2c_adapter_reg_read(adap, reg, REG_BOARD_TYPE, &val); + if (ret) + return ret; + + if (!(val & MANGO_BOARD_TYPE_MASK)) + return SBI_ENODEV; + + return 0; +} + +static int sg2042_mcu_reset_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + int ret, i2c_bus; + uint64_t addr; + + ret = fdt_get_node_addr_size(fdt, nodeoff, 0, &addr, NULL); + if (ret) + return ret; + + mcu_reg = addr; + + i2c_bus = fdt_parent_offset(fdt, nodeoff); + if (i2c_bus < 0) + return i2c_bus; + + ret = fdt_i2c_adapter_get(fdt, i2c_bus, &mcu_adapter); + if (ret) + return ret; + + ret = sg2042_mcu_reset_check_board(mcu_adapter, mcu_reg); + + sbi_system_reset_add_device(&sg2042_mcu_reset_device); + + return 0; +} + +static const struct fdt_match sg2042_mcu_reset_match[] = { + { .compatible = "sophgo,sg2042-hwmon-mcu", .data = (void *)true}, + { }, +}; + +struct fdt_reset fdt_reset_sg2042_mcu = { + .match_table = sg2042_mcu_reset_match, + .init = sg2042_mcu_reset_init, +}; diff --git a/lib/utils/reset/objects.mk b/lib/utils/reset/objects.mk index b522234..44944ca 100644 --- a/lib/utils/reset/objects.mk +++ b/lib/utils/reset/objects.mk @@ -20,6 +20,9 @@ libsbiutils-objs-$(CONFIG_FDT_RESET_GPIO) += reset/fdt_reset_gpio.o carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_HTIF) += fdt_reset_htif libsbiutils-objs-$(CONFIG_FDT_RESET_HTIF) += reset/fdt_reset_htif.o +carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_SG2042_HWMON_MCU) += fdt_reset_sg2042_mcu +libsbiutils-objs-$(CONFIG_FDT_RESET_SG2042_HWMON_MCU) += reset/fdt_reset_sg2042_hwmon_mcu.o + carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_SUNXI_WDT) += fdt_reset_sunxi_wdt libsbiutils-objs-$(CONFIG_FDT_RESET_SUNXI_WDT) += reset/fdt_reset_sunxi_wdt.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 1ce6a12..079bc4f 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -27,6 +27,7 @@ CONFIG_FDT_RESET_ATCWDT200=y CONFIG_FDT_RESET_GPIO=y CONFIG_FDT_RESET_HTIF=y CONFIG_FDT_RESET_SUNXI_WDT=y +CONFIG_FDT_RESET_SG2042_HWMON_MCU=y CONFIG_FDT_RESET_SYSCON=y CONFIG_FDT_SERIAL=y CONFIG_FDT_SERIAL_CADENCE=y