From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B59CC433E2 for ; Wed, 16 Sep 2020 23:42:47 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9939422207 for ; Wed, 16 Sep 2020 23:42:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XceJH0nl"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=aj.id.au header.i=@aj.id.au header.b="XD0baKQy"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="sDhQRqfv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9939422207 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:To:From:Date:References:In-Reply-To: Message-Id:Mime-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UmTFgHlJyDmPqORF8UuOizEaNIPYHz9yAGzkwBVphHo=; b=XceJH0nlvARkKfVXbFQwLK+f7 vA3g7JSLJ5o9+HZvOFcNY05LNiBY9HOPf3Fk0C0wXi0Dgxop+YsbmriU278gxFnBS92o7P6xxMOHM OZK9AekK4ZWRvJ6AhpNc6eWjWgVtnkDUIuMMVnyIY46Oq3rVzjm99NxN5wVcIzI54pIjfVaCpkR+l qR4l239Qd3GoDrAucvI8YwldAybfDqel7nZpcpOCWJo6A/I1nKLDzmm3hk+o/8htEKO7sdBzVdha6 jQgwMFFto+uCVw7PxMHUHkpCV1FsSLs/fyxekryacPfOaHbtgIqmcObTH+iPY0WqQ/pSzVet2E3TL ZJcFJJQSg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIh2q-00059M-L7; Wed, 16 Sep 2020 23:41:00 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIh2n-00058x-OK for linux-arm-kernel@lists.infradead.org; Wed, 16 Sep 2020 23:40:58 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 455525C0B47; Wed, 16 Sep 2020 19:40:57 -0400 (EDT) Received: from imap2 ([10.202.2.52]) by compute3.internal (MEProxy); Wed, 16 Sep 2020 19:40:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h= mime-version:message-id:in-reply-to:references:date:from:to:cc :subject:content-type; s=fm3; bh=Pp1oa9DT0nuB30pqA8KbMziVzg8MUH9 zMt5rCFr4XLI=; b=XD0baKQyxxfVUl13q9wWqMZhYf51w2a3YXQzVJr7zA5OG00 Fxq4I6jp1SXh+0K9ky+zne7I9kasSiymxrnDajPvKJbqWnF6RbcBHwVH45OOxpj5 Cu0z8AUpyZlDPHyDinJPW9v8aOUwL4vhJN16hAbTwXu8J6r1SxE6fYZf0OStvVGV 6d1Bzw8ATk/VgY143xqrAAlXmTRDrndWozWOYO1HW6bRN8uwnGzlvFwSOZsxfKZd acHDUW6tZTjpg5wdI19BY2w1bJzNGc71/Kr+3JcrMaYtd8kuckwBq75rn4Mhg0m7 TZC0rt9rKa3dfGG3Rqsgbg2kL/CSDvp+lNsQ/Hw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=Pp1oa9 DT0nuB30pqA8KbMziVzg8MUH9zMt5rCFr4XLI=; b=sDhQRqfvvcmP+V7bbnoAYX Q1JHdSXj6SO8h244GElELo92UMUqlVu7HOFlWXM2HjmkgUKxG/oHYvpGTGGfSs2i Asg89FksYCpDzYBOaItt4DUgu4NI7OxAQ3D0lcVihTo3Pe4iIr4WdMCUk9vfjeMT Fs5KAbLtd0lmEUicgXcEAnoZq/J9ZUN+R0rV/kD2UTZBXf/A5yB6qOJ4j2y4vXcB Iij7BrWIdUJD5JKUtyNeSFbZ1AePl839t6pAj3s9wKGUAuy0x0AW5sjhy08VEZ8V vi3V0jw3AK0wtxQZDGEAWhNxHxpX9W8+LQLev+XDVvh+VDESA0D1CVqx6HcyAolg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrtdefgddvgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedftehnughr vgifucflvghffhgvrhihfdcuoegrnhgurhgvfiesrghjrdhiugdrrghuqeenucggtffrrg htthgvrhhnpeehhfefkefgkeduveehffehieehudejfeejveejfedugfefuedtuedvhefh veeuffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvfiesrghjrdhiugdrrghu X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 2751EE00D1; Wed, 16 Sep 2020 19:40:54 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-324-g0f99587-fm-20200916.004-g0f995879 Mime-Version: 1.0 Message-Id: In-Reply-To: <20200916084703.778386-3-joel@jms.id.au> References: <20200916084703.778386-1-joel@jms.id.au> <20200916084703.778386-3-joel@jms.id.au> Date: Thu, 17 Sep 2020 09:10:33 +0930 From: "Andrew Jeffery" To: "Joel Stanley" , "Rob Herring" Subject: Re: [PATCH 2/3] soc: aspeed: Add soc info driver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200916_194057_834517_CAB87F03 X-CRM114-Status: GOOD ( 28.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-aspeed@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 16 Sep 2020, at 18:17, Joel Stanley wrote: > This adds a SOC_BUS info driver for the ASPEED platform. > > The full ID table is preserved in this commit message in case someone > finds a need to change the implemntation in the future. > > { "AST1100-A0", 0x00000200 }, > { "AST1100-A1", 0x00000201 }, > { "AST1100-A2", 0x00000202 }, > { "AST1100-A3", 0x00000202 }, > > { "AST2050-A0", 0x00000200 }, > { "AST2050-A1", 0x00000201 }, > { "AST2050-A2", 0x00000202 }, > { "AST2050-A3", 0x00000202 }, > > { "AST2100-A0", 0x00000300 }, > { "AST2100-A1", 0x00000301 }, > { "AST2100-A2", 0x00000302 }, > { "AST2100-A3", 0x00000302 }, > > { "AST2150-A0", 0x00000202 }, > { "AST2150-A1", 0x00000202 }, > > { "AST2200-A0", 0x00000102 }, > { "AST2200-A1", 0x00000102 }, > > { "AST2300-A0", 0x01000003 }, > { "AST2300-A1", 0x01010303 }, > > { "AST1300-A1", 0x01010003 }, > { "AST1050-A1", 0x01010203 }, > > { "AST2400-A0", 0x02000303 }, > { "AST2400-A1", 0x02010303 }, > { "AST1400-A1", 0x02010103 }, > { "AST1250-A1", 0x02010303 }, > > { "AST2500-A0", 0x04000303 }, > { "AST2510-A0", 0x04000103 }, > { "AST2520-A0", 0x04000203 }, > { "AST2530-A0", 0x04000403 }, > { "AST2500-A1", 0x04010303 }, > { "AST2510-A1", 0x04010103 }, > { "AST2520-A1", 0x04010203 }, > { "AST2530-A1", 0x04010403 }, > { "AST2500-A2", 0x04030303 }, > { "AST2510-A2", 0x04030103 }, > { "AST2520-A2", 0x04030203 }, > { "AST2530-A2", 0x04030403 }, > > { "AST2600-A0", 0x05000303 }, > { "AST2600-A1", 0x05010303 }, > { "AST2600-A2", 0x05020303 }, > { "AST2620-A1", 0x05010203 }, > { "AST2620-A2", 0x05020203 }, > > Signed-off-by: Joel Stanley > --- > drivers/soc/aspeed/Kconfig | 7 ++ > drivers/soc/aspeed/Makefile | 1 + > drivers/soc/aspeed/aspeed-socinfo.c | 141 ++++++++++++++++++++++++++++ > 3 files changed, 149 insertions(+) > create mode 100644 drivers/soc/aspeed/aspeed-socinfo.c > > diff --git a/drivers/soc/aspeed/Kconfig b/drivers/soc/aspeed/Kconfig > index 3c03c255e6e9..be5a29e8b0dc 100644 > --- a/drivers/soc/aspeed/Kconfig > +++ b/drivers/soc/aspeed/Kconfig > @@ -35,6 +35,13 @@ config ASPEED_P2A_CTRL > driver also provides an interface for userspace mappings to a > pre-defined region. > > +config ASPEED_SOCINFO > + bool "ASPEED SoC Information driver" > + default ARCH_ASPEED > + select SOC_BUS > + help > + Say yes to support decoding of ASPEED BMC information. > + > endmenu > > endif > diff --git a/drivers/soc/aspeed/Makefile b/drivers/soc/aspeed/Makefile > index b64be47f2b1f..fcab7192e1a4 100644 > --- a/drivers/soc/aspeed/Makefile > +++ b/drivers/soc/aspeed/Makefile > @@ -2,3 +2,4 @@ > obj-$(CONFIG_ASPEED_LPC_CTRL) += aspeed-lpc-ctrl.o > obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o > obj-$(CONFIG_ASPEED_P2A_CTRL) += aspeed-p2a-ctrl.o > +obj-$(CONFIG_ASPEED_SOCINFO) += aspeed-socinfo.o > diff --git a/drivers/soc/aspeed/aspeed-socinfo.c > b/drivers/soc/aspeed/aspeed-socinfo.c > new file mode 100644 > index 000000000000..b72c449f7ccb > --- /dev/null > +++ b/drivers/soc/aspeed/aspeed-socinfo.c > @@ -0,0 +1,141 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* Copyright 2019 IBM Corp. */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +static struct { > + const char *name; > + const u32 id; > +} const rev_table[] = { > + /* AST2400 */ > + { "AST2400", 0x02000303 }, > + { "AST1400", 0x02010103 }, > + { "AST1250", 0x02010303 }, > + /* AST2500 */ > + { "AST2500", 0x04000303 }, > + { "AST2510", 0x04000103 }, > + { "AST2520", 0x04000203 }, > + { "AST2530", 0x04000403 }, > + /* AST2600 */ > + { "AST2600", 0x05000303 }, > + { "AST2620", 0x05010203 }, > +}; > + > +static const char *siliconid_to_name(u32 siliconid) > +{ > + unsigned int id = siliconid & 0xff00ffff; > + unsigned int i; > + > + for (i = 0 ; i < ARRAY_SIZE(rev_table) ; ++i) { > + if (rev_table[i].id == id) > + return rev_table[i].name; > + } > + > + return "Unknown"; > +} > + > +static const char *siliconid_to_rev(u32 siliconid) > +{ > + unsigned int rev = (siliconid >> 16) & 0xff; > + > + switch (rev) { > + case 0: > + return "A0"; > + case 1: > + return "A1"; > + case 3: > + return "A2"; > + }; > + > + return "??"; > +} > + > +static int __init aspeed_socinfo_init(void) > +{ > + struct soc_device_attribute *attrs; > + struct soc_device *soc_dev; > + struct device_node *np; > + void __iomem *reg; > + bool has_chipid = false; > + u32 siliconid; > + u32 chipid[2]; > + const char *machine = NULL; > + > + np = of_find_compatible_node(NULL, NULL, "aspeed,silicon-id"); > + if (!of_device_is_available(np)) { > + of_node_put(np); > + return -ENODEV; > + } > + > + reg = of_iomap(np, 0); > + if (!reg) > + return -ENODEV; > + siliconid = readl(reg); > + of_node_put(np); > + iounmap(reg); > + > + /* This is optional, the ast2400 does not have it */ > + reg = of_iomap(np, 1); Use of np after of_node_put(np) above. > + if (reg) { > + has_chipid = true; > + chipid[0] = readl(reg); > + chipid[1] = readl(reg + 4); > + iounmap(reg); > + of_node_put(np); Double of_node_put() of np. > + } > + > + attrs = kzalloc(sizeof(*attrs), GFP_KERNEL); > + if (!attrs) > + return -ENODEV; > + > + /* > + * Machine: Romulus BMC > + * Family: AST2500 > + * Revision: A1 > + * SoC ID: raw silicon revision id > + * Serial Nnumber: 64-bit chipid > + */ > + > + np = of_find_node_by_path("/"); > + of_property_read_string(np, "model", &machine); > + if (machine) > + attrs->machine = kstrdup(machine, GFP_KERNEL); > + of_node_put(np); > + > + attrs->family = kasprintf(GFP_KERNEL, "%s", > + siliconid_to_name(siliconid)); > + > + attrs->revision = kasprintf(GFP_KERNEL, "%s", > + siliconid_to_rev(siliconid)); `struct soc_device_attribute` declares these as `const char *` and the strings are constants in the driver, so is there any reason to use kasprintf() here? Andrew > + > + attrs->soc_id = kasprintf(GFP_KERNEL, "%08x", siliconid); > + > + if (has_chipid) { > + attrs->serial_number = kasprintf(GFP_KERNEL, "%08x%08x", > + chipid[1], chipid[0]); > + } > + > + soc_dev = soc_device_register(attrs); > + if (IS_ERR(soc_dev)) { > + kfree(attrs->family); > + kfree(attrs->revision); > + kfree(attrs->soc_id); > + kfree(attrs->serial_number); > + kfree(attrs); > + return PTR_ERR(soc_dev); > + } > + > + pr_info("ASPEED BMC %s rev %s (%s)\n", > + attrs->family, > + attrs->revision, > + attrs->soc_id); > + > + return 0; > +} > +early_initcall(aspeed_socinfo_init); > -- > 2.28.0 > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel