From patchwork Fri Dec 24 04:13:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quan Nguyen X-Patchwork-Id: 12698791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 079DEC433EF for ; Fri, 24 Dec 2021 04:15:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351343AbhLXEPm (ORCPT ); Thu, 23 Dec 2021 23:15:42 -0500 Received: from mail-co1nam11on2133.outbound.protection.outlook.com ([40.107.220.133]:47600 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1351353AbhLXEPh (ORCPT ); Thu, 23 Dec 2021 23:15:37 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mfNMCkeGOgZ4hpxX0AQoKzsqXTLwFHkeYz3ycDk5T++tTW7BDfKaPn1OC8ZM/+5OZ26ejIM/g9Mz0IU+zZiSJsU7vnPH5EBF5y6aRlsany+1qVn/ctVaZBYbFco4S9mPTnApXrTtfAZkhtd7YLhcOJCo64+TZO8+LVwLGo7nuzU3EQeEpZ3mHejnlloPcKVmBciOlh6iove6D3wV6XfWW+//i/XG0b2qVzHPjcRk5rOCmM8UfxVFrHn88G5UaQ0PGKc0UPETjt3KKNGBFl9oz0LJEo0/+/cSVUrV28zHLv9X7PJ8AelRqqBa9Tub5F1CoL069EJadB2LLXu1wDs7sQ== 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=E1Yw7pQz0XjU9IN3CqqMWxnC6/qGFVtqG7Fo+JdzLeg=; b=cAvjSwcepsqqShbaXxvkxXrIDvoSjnSfgUu4ekYTjnCXxth05vignY5nMEuDI6i9RpBjnbJJw0PCmAfaLj6ich3rKaHofFGNtcB41LaTzxvjU0jDPuNYsjbuOXfNHzaDfP4FcgcAsH+LZ9sypTqJJ4rYeRQChb1FKTbXaWo95xvax+pIcVJ+WWRKKaGfh5eXhEthJj8fmJscZXqu29fFOJi0pXU+OfHyXzNLNC28uplFo5oxUKTT2lTDg/rmfmairF82Gli0Z4Y5H8zgi3uMqtmgGJmuzPdxa6em7nWV4KUsmBuYNz8FBtGmOEtRmAGOzvupBX77gzI1ysDeR+yEeA== 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=E1Yw7pQz0XjU9IN3CqqMWxnC6/qGFVtqG7Fo+JdzLeg=; b=lq1rE3Jj6wXhz/Lkl4HFmknIQYaEkkcUO9teSsvnD55ETbABX+lkzRRwYHGQjUaWIb6Oavm3zJXSZreXNPiTfXdVnPq3wTue66wGq7lQB98v7Sc1uOSFxc1xvPBscyEGP1kpsiYpW02hciYRYCcb2bWDm3V13L+MN++hYmDZbG8= 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 BYAPR01MB5189.prod.exchangelabs.com (2603:10b6:a03:78::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4823.21; Fri, 24 Dec 2021 04:15:35 +0000 Received: from SJ0PR01MB7282.prod.exchangelabs.com ([fe80::f957:680d:69b0:9999]) by SJ0PR01MB7282.prod.exchangelabs.com ([fe80::f957:680d:69b0:9999%4]) with mapi id 15.20.4801.019; Fri, 24 Dec 2021 04:15:35 +0000 From: Quan Nguyen To: Joel Stanley , Andrew Jeffery , Jean Delvare , Guenter Roeck , Rob Herring , Lee Jones , Jonathan Corbet , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-aspeed@lists.ozlabs.org, openbmc@lists.ozlabs.org, Mark Brown , Greg Kroah-Hartman , "Rafael J . Wysocki" , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Gustavo Pimentel Cc: Open Source Submission , Phong Vo , "Thang Q . Nguyen" , Quan Nguyen Subject: [PATCH v6 8/9] misc: smpro-misc: Add Ampere's Altra SMpro misc driver Date: Fri, 24 Dec 2021 11:13:51 +0700 Message-Id: <20211224041352.29405-9-quan@os.amperecomputing.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20211224041352.29405-1-quan@os.amperecomputing.com> References: <20211224041352.29405-1-quan@os.amperecomputing.com> X-ClientProxiedBy: SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) To SJ0PR01MB7282.prod.exchangelabs.com (2603:10b6:a03:3f2::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2755b1eb-dff5-4a23-d22a-08d9c69408b2 X-MS-TrafficTypeDiagnostic: BYAPR01MB5189:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:341; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1JvSoMZOWN28FNS99Omi8aZm//lIrfIZBcz2mUw0RWKLyUlmRfy8nRQR5Ks8IQhhBmn8RW+b0pfR8n60QzbjfbfQaRIo3Jz0kg7gca5tABKJ7DlQLuJ91O+jEXEhLKc0T6C7H8kaDNrcyb0bDZQBv0BFqc2wCCmqzdPyk2KAz6ETwj6ycRVDZcImOBqT5LBL6NpKl51n+XxP3Q20SfPPGMYUwSQWgVO7Ss8BxNvmvqckYC3DemwDQWt4tp7paXswn3Qn3XSUFx/6R29hvfKXq7ZpUirGB0lwI2FonlAueS4ZSTlhaeTJpd/JwmZS1Rv39Q877fO3CV0bV2n0habI7HnurCdpZZCWTBm7CbUHAYrZvQTPIfvU46bWXO9u8w03mSp1Pszm3OFNww2qqTy7OUEIVjsuEAtqlKqfGgqg+9TF9woqAVCjrU8PdP3NJdtqoGCiEre3eK9tuoJeOdi1WWA9HWmG+fIDTjkhaT30/ANodkyzjZUhbgTg4J17RGRvCpNbk+ba3qS8HlLwCUGGHKPTdIV+gRAFS6+OHHrj1jXScWCANVupaWrhX0VOrrEkNFWB3B3Q6UXRV8fb1NneejM5KySAffq0Nt550OQXgB6Q42XnszgDdbS6V0s6+I6IEVElJg/iF8m0V/1MJpBt6DIgfKhOswHdWPQO7tCTh7k0eIUWMFJCVswHluvPDWW3Kjcp5SwUCh5RPIXgAK+hzTRZRgiLMAckSIDLd5QbKR8= 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:(4636009)(366004)(110136005)(54906003)(86362001)(38100700002)(38350700002)(83380400001)(66476007)(52116002)(5660300002)(107886003)(2616005)(8676002)(66946007)(6666004)(66556008)(2906002)(508600001)(1076003)(4326008)(316002)(6506007)(8936002)(6486002)(26005)(186003)(6512007)(7416002)(921005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v8lctm8R+wGZdn9R7uVSEssoxJpMzGNYui8sbMrUN6wy52/FSmooBOwaeaM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C2q1u7j48r85WTBZhX+6Ortfzs0c+6CtkaBeeUSKnmYGHa5UeePAJo26izikQ1v1X3XzzXO8tEKl+RbmxXpAaIDbiy2FBG/6qArdUS1B9vFcQLFa+FrjoSDgFJRDqHH7EtHoSejv4oSRLsa9aVmqTDANItqmXArvdKyD7zOp8SETi2Sv2qGg2/vRTaH1Er+Fj/mfBbzBu2jvuK61sorhzKtmpNPZgefN73EkH6pANUl78IPXNdm1o3BxdoaGDPg/0WPzb0b1UV/XT4ppHJuVWzLsqmQZPMxUYldyqi0xUz+bCpkkPCmDF8R0lk7weEtzLmbfjBp9ZuZ1nLiatEwA0NBeo1ai5brMEN0fXd1J5Skfd2UDdYIge/k/ppQdaU4htK64y7De5xQHZxtnWBZgHXP21arhq1PUcyf6mvUB0MXDZlQH3FIY+Dv3hBnLchm0Xdq3lMd5e540RkHXrHLnc833d4eYGgwYa5LRFTOCNBHF9q34j/ruRXnYAonWlswsQ2r1sQQHia7IXrhdI+99tDVf48whBJ17DrBLpjLF4XxGnzos= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2755b1eb-dff5-4a23-d22a-08d9c69408b2 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR01MB7282.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Dec 2021 04:15:35.6625 (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: BVPfr7N1KS4z8/TUTxlG8mMMuS8Rutb6mWpMxoQZl1MFckIZBrkQmKvKPcRpkv8uWgDk7wqga2NN7nJLLja4yasDPvDxtHvC3awI/Rskgow= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR01MB5189 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@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 --- Change in v6: + First introduced in v6 [Quan] drivers/mfd/smpro-mfd.c | 1 + drivers/misc/Kconfig | 7 ++ drivers/misc/Makefile | 1 + drivers/misc/smpro-misc.c | 177 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 drivers/misc/smpro-misc.c diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c index a7cd64bf9eaa..5611dd30f8f4 100644 --- a/drivers/mfd/smpro-mfd.c +++ b/drivers/mfd/smpro-mfd.c @@ -28,6 +28,7 @@ static const struct regmap_config simple_word_regmap_config = { static const struct mfd_cell smpro_devs[] = { MFD_CELL_NAME("smpro-hwmon"), MFD_CELL_NAME("smpro-errmon"), + MFD_CELL_NAME("smpro-misc"), }; static int smpro_mfd_probe(struct i2c_client *i2c) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 0cbd8a2561a7..df53cbf62931 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 8ec9961b941b..bbfee81499de 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..6fe9d25ce31c --- /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) 2021, 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 int 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 int 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 int 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");