Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2284458pxp; Mon, 21 Mar 2022 15:52:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCfjG7HtfFgEcuD71FhgKwJLmKWS4jRyjUMpsGBcoSgRMGeVCThjr7Af7kjipnCsAMfHzL X-Received: by 2002:a17:902:ea08:b0:154:45ba:9543 with SMTP id s8-20020a170902ea0800b0015445ba9543mr10313754plg.80.1647903159258; Mon, 21 Mar 2022 15:52:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1647903159; cv=pass; d=google.com; s=arc-20160816; b=wLzjtFLimXnN5JYZBY3MWbNjvEf05MpIyQbi5mP1fKkBXkdiALeaKa+UhDwBUYDoEj tewhNwdGGkKTTuEKAKdPp21EbWp4qyirdVSi55ylspMSe31xX8ntLYHIKrmI/vUV0sl3 L6gEtVa98rG3P2lCxHk87ClXytjGE9UdWDjOOlo4CSroykPdCm7iRsV8+eO8tdSROyX+ sFp/mbjs+5TLovEtnieY4lgKRsmHoWQcS4fdUMX7q89BTlt+D8yr3AEqClFW+5gHBnug WOOBkWMVcpETtV0Ui7Q0BvjPLXclP7RhNwvGuVruBOcrvUg0zb5JtjkugMX7WK/w0ai8 cjkA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6gz2V2hUboZee0NoS7N5UB0JFSqluoRrgP3NksaIA48=; b=inkzMQmGdIvfeSyIIXwDHMBCznZ1yVarHnEdLhqt5ZWiNkvIYvhmBA2KkIHsOYKcjG HUO3rmMTU5jOjSHjSqcZSj5/c3U6JpujeZH2gYx//AE+GJbKFi1Q7paoNQ3UMG6Go6nN qgO+zP/udzChctDxab/vU0uMrGOmwqxiuHpugOkqzSLsDSbr2d50F0Az79Ibdujdya0l MzFOWZ/NJClDqeR8Rz3MQyj5fdPOlOJXRxgAJpQrs5IqPxx5Pm9RBrf01V/qNusw4MG0 jG+KhakJQ8huPA+BQSo7CCZJQLAnH97iwZ2coPaZS+avKwpVtYGmothN+tIhFnaJ4ZYh bVbQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=HpTwtRCS; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id r11-20020a170903020b00b00153b2d16582si11185184plh.394.2022.03.21.15.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:52:39 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=HpTwtRCS; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 93BDA3472C3; Mon, 21 Mar 2022 15:00:23 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345158AbiCUIQl (ORCPT + 99 others); Mon, 21 Mar 2022 04:16:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345161AbiCUIQ3 (ORCPT ); Mon, 21 Mar 2022 04:16:29 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2107.outbound.protection.outlook.com [40.107.92.107]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2630160A9B; Mon, 21 Mar 2022 01:15:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n/sxgHUtMo8IoOIQf7MzFS0RdGdTX012rS7Vk5iFDDmT2QgOwXTvodhtWMCF0b6Tsp8EO1PoSjF2PqaPDD4YfZ9Tlwg7uP+uOeNz2h7MVxY5HuI6fuPwWc3kRE27ps1L0x3UGO8zM1hcjYe671BD2gU2N+bC7AfU/ySmIKvEry+1YFsNTcuqrCJohI7zwutzx4w1nnYZW5k4+/wEHwAJTLtY0oBb+qmqzfd3J0mNhtA+HNeRl34r+4nmv56MEzB2jetw8RsrfeLeZKwAEW1CiTd0OXW/v2UtcEaS5FY8a9PfCSoPoDF9x0oL4/QjX/zn3q3xPZE9p2ng/DF2ZJ7kAA== 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=6gz2V2hUboZee0NoS7N5UB0JFSqluoRrgP3NksaIA48=; b=MyzLbxfN606+b1yfrnjrXvzHT9bKDsDVOiTbO3GoeV+KYD2qHDGeteMg29SlXadz/ziEx9lDZWEVlcs8xmA6Ft3zF5TtThPCd2P6K9iinKvtxbE2ce24wkuPNNnvlsU7LSvy8Lmw1DtPLktlKSLDRCyIPf/8B5J1tPnyevqrS+O9qQ8JiIqYWTQxLERdyQqzBpHicH1A3vtt3xQoSeGvQR0UETTX0wtPWD3EcFHLRBJREeeF5A/2oEvf7EFYv2Wwa06MqYwy1PrOjtKPJ6M4fNwwykudNl2m2quNWKdP2HsBaKKezqwXXQP7k/rUlKUr2aNJk+2eb2g1yc5crXdv3Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6gz2V2hUboZee0NoS7N5UB0JFSqluoRrgP3NksaIA48=; b=HpTwtRCSCTkKF8HUICvH55gkFx/J4W1TEZyNR0uEJqrLLs120S+n1K5pfr/XeaaSmr7g2ZstrTU4ofBgaT8y8Ko7sOiP7VlGN1IDjBG+UawQH5IISFWCT9Dvz4/2jkPWaaVWdAbakDhySRqzsAVtwEpyB0QKSWSauyOXK/Ogrvg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from SJ0PR01MB7282.prod.exchangelabs.com (2603:10b6:a03:3f2::24) by BN6PR01MB2738.prod.exchangelabs.com (2603:10b6:404:ce::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14; Mon, 21 Mar 2022 08:15:00 +0000 Received: from SJ0PR01MB7282.prod.exchangelabs.com ([fe80::cd24:39ed:7042:46d6]) by SJ0PR01MB7282.prod.exchangelabs.com ([fe80::cd24:39ed:7042:46d6%8]) with mapi id 15.20.5081.022; Mon, 21 Mar 2022 08:15:00 +0000 From: Quan Nguyen To: Lee Jones , Rob Herring , Krzysztof Kozlowski , Jean Delvare , Guenter Roeck , Jonathan Corbet , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Quan Nguyen , Thu Nguyen , Gustavo Pimentel , linux-kernel@vger.kernel.org (open list), devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-hwmon@vger.kernel.org (open list:HARDWARE MONITORING), linux-doc@vger.kernel.org (open list:DOCUMENTATION), OpenBMC Maillist Cc: Open Source Submission , Phong Vo , "Thang Q . Nguyen" Subject: [PATCH v7 5/9] misc: smpro-misc: Add Ampere's Altra SMpro misc driver Date: Mon, 21 Mar 2022 15:13:51 +0700 Message-Id: <20220321081355.6802-6-quan@os.amperecomputing.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220321081355.6802-1-quan@os.amperecomputing.com> References: <20220321081355.6802-1-quan@os.amperecomputing.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SGXP274CA0010.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::22) To SJ0PR01MB7282.prod.exchangelabs.com (2603:10b6:a03:3f2::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 148c7f75-288b-406b-3f7e-08da0b12e480 X-MS-TrafficTypeDiagnostic: BN6PR01MB2738:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xdEvNxsCgPChJH0X6CZmcZ9QjeemnQKygaFnCBur+LJ2ekcJjwOhuWjoVfO/kz5/kARfdQyXkD1luGJvvVwl28aMqSw+wb09jVSfrojS28yIksrwhlD7mutxxDWPKS+MhfzpxDWbQdBYXPbeWNbdJNg926sk4WFWSEulAsFjzgCU1kY7C8HG/XtKg9e8qGx82BzARdP3J4Lw1CxrGb0N6JfeS5F/hB11SAF0LZBQgMxl4Q48zAlsydyQ8eNlZPiwbdGVTeiiJzcBHQoRaGZJxw2aM4sJxoc8d03Ph1e1SrGph5fJrnu8CkIdqwDD0ZbI/JjvLNxOuyJw3VuyVK4/FQONHFoz2m1wC7hnT+3ocESvbZAx8OwESXrS7m8rZTzRY2VUu1Z2jCn45jJNZ6WpuLnmgpDonGzYFQVJdYKspqvYDQ/IT9Eah/ao3DoLW2WLJX6W4FNfKkGVpnWVBwGoGcYJVTsbpYefWrCES+rK8Y3WlqWS+6AXFyf4DN00Pku3HgT68NQQEmRkmTTaMu/P32FNL/ZIoZBmO2AJTl994DiyHWZdk2yyi0rfzMcyAO30FlOigRWCoO46ES/RdvxV3Y6/yx1Md8S/w79EPGv8rA3B6IJDAD/E01OtxyFn6WLFO1Vq65pE7WvNXojHpvfcC/SmFWXeNuaoBzW9nkf4nsfWKQ4p8EVJg3rQz68xBYCsDQbvA4MA4OqSiZXhS9kntANb2aXbveJ3EhJNpIHkVm4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR01MB7282.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38100700002)(66476007)(66556008)(6512007)(66946007)(7416002)(107886003)(186003)(1076003)(86362001)(38350700002)(4326008)(5660300002)(8676002)(26005)(316002)(52116002)(110136005)(921005)(54906003)(2616005)(2906002)(508600001)(8936002)(6486002)(6506007)(6666004)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?yWVkfcMKFR4UHRZ+Muvv5IZDnrx+faIUKccxRaisJcIRK1yj+Jin16eCbUzB?= =?us-ascii?Q?eFi1TvzZYV18BQZBXlwjlO8GKMtdOXWZsEglDYh2p0jcKrev9jgVfrH/vDu2?= =?us-ascii?Q?zgM239bIJaRACGtLvCVjLe2pOQqSLiGj24xqTPh9KXE1WhprTG5AA2otKBoC?= =?us-ascii?Q?3kO1/2PsoxHvxNKVzHjlsVtOCw8GWB1Sy6HIM3tWBg5O3FA00Yy7rpQMlqu7?= =?us-ascii?Q?y5/s5dF7hwE8mxzxeu5ixO0z/zMqQeyOE8aWYjIqkhi8JS165MybXGP8sY7v?= =?us-ascii?Q?x57nFQC63FGujfxrvBK0DECEKGtREp3FfTSAY8Ecprsi3jDmCUVnzOQrQRax?= =?us-ascii?Q?lE7KcqKCFHrL8sZDtBHH2zEEO8RmnYqb4jR7YtPrpsRPMRDGNhqRQhN6sZht?= =?us-ascii?Q?9m1f4C/6nEk+wgbDBI4JGfcZW2K8iufYs52vFxE+Ts2X34fQYfj9HKdL2LCY?= =?us-ascii?Q?WDztwkWKSw46fb2JfueUEO/YLGoduLV7R9LVSKjVfUGeDGaJ8hsoKaapePA/?= =?us-ascii?Q?CUCrnsr/kJNkSIsUtVLWYgtLygXRofXLb98znEFzWtL76eerHNqEe1uOlr2V?= =?us-ascii?Q?CTJy7TvvUGL8nPCcX58gXbsiFEq0aWPKEC2jIoziqKIBl7rBWj0E/1JjRUul?= =?us-ascii?Q?18Y6E+fCP3PdKeZHw/KuDaDDiWgP2p7kV4cDXu7TWOjZ2pj00ysQXAbR0FxC?= =?us-ascii?Q?F2lBI1fVEZBr9BYliOFh2Og68SuPtZ8YM4FsmwFAhUrlhEzdommIV62L2GtQ?= =?us-ascii?Q?ieyDZzK3XrK7Vr4dRz3b3rALvOoNLabBDvDNHSbT0Z6QjG8VEB4WbTWFMi7q?= =?us-ascii?Q?UutlDao3cZWNodd/84pyRLR0OYSV5rfReCRg3iRnfl5Z79Fjhn8r+k2VsNyZ?= =?us-ascii?Q?5CMvXDZgBaP3iZBKxTl2HICtyGGQRrOcJUylCvnNeJEgTSnDD+5tFJNKTk4k?= =?us-ascii?Q?GAtFrWxVw2yZLFayrHlyNECDU7PfH6Myf+yHhCthivBjLFdiYQIRqr+OIF5O?= =?us-ascii?Q?owA5It+bYh7q2GmCNb08aamVhL19cpL8dnkAF2sBT+h+PPEk25VrxCJiGwMj?= =?us-ascii?Q?mXk5OjD7m+R2ljKMDFwDfyD5shZTNCpTZ3iYk6fAZWEWsxQoF2CRtM2eJgUc?= =?us-ascii?Q?nHLeCYH+FkuVbJWYOWYlTVg9FtLHHYIMivBYAtexpUqJzhcQiUv7Bm5qzJmu?= =?us-ascii?Q?TRPBPZSf9/g1pcxFJWngp/xH1d8mSbCfT66VAF+X8g0cZMyEhkF1FIUFdUpW?= =?us-ascii?Q?7fqnlxUYeeA4M1y2n4J46te9+z+6EdAhlqW+ndAZICFrtk61l2ZAo8Piy+gi?= =?us-ascii?Q?QjmCvJO57rSi9CAlqVk6PUhzvvb0mPGAdSjlhSaVoPEqAr8iqfnq9J1QiSv7?= =?us-ascii?Q?UK15Q4AWb0W86WbQAB6vs1jDRtYbuWyBRGq/ObO0EINPPXAeyDrGIJJHkt5l?= =?us-ascii?Q?TDu7n554WZ2h97uMXGlLz1GVmJyNq1usVGtwEZJJwfi7i3YkjLyiPQ2Oa+Eq?= =?us-ascii?Q?xfgv4eHgyRybpWw=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 148c7f75-288b-406b-3f7e-08da0b12e480 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR01MB7282.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2022 08:15:00.0397 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UnIj6Cj9AiL31QMFUgI+3RwmeAa8Qr+2HyvoacNEP7cU9Y+0ww9FhUf7SRx0VQEl2PZ2+7ohyu0XvaEEucfom1xZmanPdtE63jHfzDZnWTo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR01MB2738 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit adds driver support for accessing various information reported by Ampere's SMpro co-processor such as Boot Progress and other miscellaneous data. Signed-off-by: Quan Nguyen --- Changes in v7: + Fix wrong return type of *_show/store() functions [kernel robot test] + Adjust patch order to remove dependence with smpro-mfd [Lee Jones] Changes in v6: + First introduced in v6 [Quan] drivers/misc/Kconfig | 7 ++ drivers/misc/Makefile | 1 + drivers/misc/smpro-misc.c | 177 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 drivers/misc/smpro-misc.c diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 4e1a0b451f3d..f1371d6584e8 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -183,6 +183,13 @@ config SMPRO_ERRMON If you say yes here you get support for error monitor function provides by Ampere Computing's SoC with SMpro processor. +config SMPRO_MISC + tristate "Ampere Computing SMPro miscellaneous driver" + depends on MFD_SMPRO || COMPILE_TEST + help + If you say yes here you get support for the miscellaleous function + provides by Ampere Computing's SoC with SMpro processor. + config CS5535_MFGPT tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support" depends on MFD_CS5535 diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 483308a6e113..e61e462924d0 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -24,6 +24,7 @@ obj-$(CONFIG_KGDB_TESTS) += kgdbts.o obj-$(CONFIG_SGI_XP) += sgi-xp/ obj-$(CONFIG_SGI_GRU) += sgi-gru/ obj-$(CONFIG_SMPRO_ERRMON) += smpro-errmon.o +obj-$(CONFIG_SMPRO_MISC) += smpro-misc.o obj-$(CONFIG_CS5535_MFGPT) += cs5535-mfgpt.o obj-$(CONFIG_GEHC_ACHC) += gehc-achc.o obj-$(CONFIG_HP_ILO) += hpilo.o diff --git a/drivers/misc/smpro-misc.c b/drivers/misc/smpro-misc.c new file mode 100644 index 000000000000..fadaa66a699e --- /dev/null +++ b/drivers/misc/smpro-misc.c @@ -0,0 +1,177 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Ampere Computing SoC's SMpro Misc Driver + * + * Copyright (c) 2022, Ampere Computing LLC + */ +#include +#include +#include +#include + +/* Boot Stage/Progress Registers */ +#define BOOTSTAGE_SELECT 0xB0 +#define BOOTSTAGE_STATUS_LO 0xB1 +#define BOOTSTAGE_CUR_STAGE 0xB2 +#define BOOTSTAGE_STATUS_HI 0xB3 + +/* SOC State Registers */ +#define SOC_POWER_LIMIT 0xE5 + +/* Boot stages */ +enum { + BOOTSTAGE_SMPRO = 0, + BOOTSTAGE_PMPRO, + BOOTSTAGE_ATF_BL1, + BOOTSTAGE_DDR_INIT, + BOOTSTAGE_DDR_INIT_PROGRESS, + BOOTSTAGE_ATF_BL2, + BOOTSTAGE_ATF_BL31, + BOOTSTAGE_ATF_BL32, + BOOTSTAGE_UEFI, + BOOTSTAGE_OS, + BOOTSTAGE_MAX +}; + +struct smpro_misc { + struct regmap *regmap; +}; + +static ssize_t boot_progress_show(struct device *dev, struct device_attribute *da, char *buf) +{ + struct smpro_misc *misc = dev_get_drvdata(dev); + u32 boot_progress; + u8 current_stage; + u8 boot_status; + u8 boot_stage; + u32 select; + u32 reg_lo; + u32 reg; + int ret; + + /* Read current boot stage */ + ret = regmap_read(misc->regmap, BOOTSTAGE_CUR_STAGE, ®); + if (ret) + return ret; + + current_stage = reg & 0xff; + + /* Read the boot progress */ + ret = regmap_read(misc->regmap, BOOTSTAGE_SELECT, &select); + if (ret) + return ret; + + boot_stage = (select >> 8) & 0xff; + boot_status = select & 0xff; + + if (boot_stage > current_stage) + return -EINVAL; + + ret = regmap_read(misc->regmap, BOOTSTAGE_STATUS_LO, ®_lo); + if (!ret) + ret = regmap_read(misc->regmap, BOOTSTAGE_STATUS_HI, ®); + if (ret) + return ret; + + boot_progress = swab16(reg) << 16 | swab16(reg_lo); + + /* Tell firmware to provide next boot stage next time */ + if (boot_stage < current_stage) { + ret = regmap_write(misc->regmap, BOOTSTAGE_SELECT, ((select & 0xff00) | 0x1)); + if (ret) + return ret; + } + + return snprintf(buf, PAGE_SIZE, "0x%02x 0x%02x 0x%08x\n", + boot_stage, boot_status, boot_progress); +} + +static DEVICE_ATTR_RO(boot_progress); + +static ssize_t soc_power_limit_show(struct device *dev, struct device_attribute *da, char *buf) +{ + struct smpro_misc *misc = dev_get_drvdata(dev); + unsigned int value; + int ret; + + ret = regmap_read(misc->regmap, SOC_POWER_LIMIT, &value); + if (ret) + return ret; + + return snprintf(buf, PAGE_SIZE, "%d\n", value); +} + +static ssize_t soc_power_limit_store(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct smpro_misc *misc = dev_get_drvdata(dev); + unsigned long val; + s32 ret; + + ret = kstrtoul(buf, 0, &val); + if (ret) + return ret; + + ret = regmap_write(misc->regmap, SOC_POWER_LIMIT, (unsigned int)val); + if (ret) + return -EPROTO; + + return count; +} + +static DEVICE_ATTR_RW(soc_power_limit); + +static struct attribute *smpro_misc_attrs[] = { + &dev_attr_boot_progress.attr, + &dev_attr_soc_power_limit.attr, + NULL +}; + +static const struct attribute_group smpro_misc_attr_group = { + .attrs = smpro_misc_attrs +}; + +static int smpro_misc_probe(struct platform_device *pdev) +{ + struct smpro_misc *misc; + int ret; + + misc = devm_kzalloc(&pdev->dev, sizeof(struct smpro_misc), GFP_KERNEL); + if (!misc) + return -ENOMEM; + + platform_set_drvdata(pdev, misc); + + misc->regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!misc->regmap) + return -ENODEV; + + ret = sysfs_create_group(&pdev->dev.kobj, &smpro_misc_attr_group); + if (ret) + dev_err(&pdev->dev, "SMPro misc sysfs registration failed\n"); + + return 0; +} + +static int smpro_misc_remove(struct platform_device *pdev) +{ + sysfs_remove_group(&pdev->dev.kobj, &smpro_misc_attr_group); + pr_info("SMPro misc sysfs entries removed"); + + return 0; +} + +static struct platform_driver smpro_misc_driver = { + .probe = smpro_misc_probe, + .remove = smpro_misc_remove, + .driver = { + .name = "smpro-misc", + }, +}; + +module_platform_driver(smpro_misc_driver); + +MODULE_AUTHOR("Tung Nguyen "); +MODULE_AUTHOR("Quan Nguyen "); +MODULE_DESCRIPTION("Ampere Altra SMpro Misc driver"); +MODULE_LICENSE("GPL"); -- 2.35.1