Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11737088ybi; Thu, 25 Jul 2019 22:42:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5+kGbUCwLZ09eWwBZDjVeyN2MXS1A9D3VDk4+EGBpDYiXT6FiJWZAxUY0QCyMGXOWu0jN X-Received: by 2002:a17:902:82c4:: with SMTP id u4mr94502463plz.196.1564119738379; Thu, 25 Jul 2019 22:42:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564119738; cv=none; d=google.com; s=arc-20160816; b=cf5sj3DLokM1gSCfzw7kOK4Wbi4/hZMjEm75feN8pQtHgI/AL58StCUhqA/ejWy7yi Ql4bHRv3r/NW1XtCODfzjwIma3tA5NxlYegbCTLvh63pBO/vJhjgEKQ20oMLvocUy2eT QQLsMA4uF0j4tbJkOL7gf66P7k0TZEnEx8x5GKIlY1WQgfMMu8VWL7U/gxc7Yj8Dg7Ev 18PkjaElv2ice1qaQ0bPr+dJVOKHXGUJD5DvPK5qTJajw85UVe408a5QIMvQsQSTNkLw AobYr/GVvzS6TWShQIHhslwcx2/q+g0phtNY616FkvtyW366SUwNCZPud5ZqbkBAQKb+ 8iSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=96HDwA1KWSlr19z+QpunC8hx6SLZq+UnHYXQwHcXkFU=; b=e+cbI1JaL8K+oztB4iCG8d9OqU8HJtw1zWGjJlbxFA8zkw6d4XJ+nmGHDD9zbtVHnE rlM7+2PwWX0u8dhbLbWVQCi0DGoDEZ2Oh+ZLwBOtcouR0N72RJ0nNxhl1dkML0ypnu/n mvtAqu4q7BeYIq39bp2/2xd4/bq1NJujiMmO2Wv/ICtj8mEhOQhehwG6TJGhWQifb4Ac B3/XFp6MT6Znlt7rFF8b89f/9LsTbg82RtbG2G5yuFEAt+2/CgsS/PqQADfgJCXFJnOq Gk7kXhF+873/61Lj3YXvaaoS9jO/547JBSV/mSLA9ybGEzxYdvwHQIStPUT+Rynqp7z8 Fjjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aj.id.au header.s=fm3 header.b=PJqh0bvL; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=A53jHgX4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b21si17701360pjo.49.2019.07.25.22.42.03; Thu, 25 Jul 2019 22:42:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@aj.id.au header.s=fm3 header.b=PJqh0bvL; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=A53jHgX4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726606AbfGZFlC (ORCPT + 99 others); Fri, 26 Jul 2019 01:41:02 -0400 Received: from new4-smtp.messagingengine.com ([66.111.4.230]:52113 "EHLO new4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725842AbfGZFlB (ORCPT ); Fri, 26 Jul 2019 01:41:01 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 051FE4355; Fri, 26 Jul 2019 01:41:00 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 26 Jul 2019 01:41:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=96HDwA1KWSlr1 9z+QpunC8hx6SLZq+UnHYXQwHcXkFU=; b=PJqh0bvLeaKgD2NqicKEJ94S/a3LL kFt1pQ5EygtTNHC232CnW/Fd6Ctom6HceFM8fY/lJL9WlVJDSf5XjCN0u/dTH1ys JeGszkZwMKJ2b37ZJWjoct3WkyO1QClIEJ3Vn6ZmpheVPMb6GJAOdI4TrZByi2L2 +OGDG43AmYi0sL4y9fu64ubmZ/FK17ANVZVD02gTd3o/l3g8Q2lWygvanK8qpZBs TFm422rSTFFHsTJJC/HR+wovjrUS9gAgoe91Dq4Vl5DvozuY/MTpucGQ+eAnx3un QAga5IJwZIPi9iX2UbI0nP510oFMk+Fznm4Y4X8xUr3JEPRX9AOxW91bw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=96HDwA1KWSlr19z+QpunC8hx6SLZq+UnHYXQwHcXkFU=; b=A53jHgX4 GwBj4+1G0L9HFs2xkk3MrixMIvd5bKcmLNJFYVxPhsHuBdTBehuffYVGT7EdD8wd qXooMjAnnXmny3clMDeKF1w9lsdx992J0WvaDzj3sNbrlQvG12JWGZv97xzamI1c WHKSIsSmeCP6IY0a3ufQceFqNoLsS94ovzv/ExnBLipcsNjxnEXmS7r4G2GKGrxe 48CG8F1kyjr2zzBiZrmDbkhrV2hzPboqSu+axqLU1xN+LEF/ydOCh70A9CmDGzV7 Y/QI+Z8+dGJmgKFu5fCaUeVBbyzEl4nw3I5/wdt+Z7tMuBI67LXMfpCkqt7xLHe7 qW/nu9QT+uIoHg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrkeefgdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomheptehnughrvgif ucflvghffhgvrhihuceorghnughrvgifsegrjhdrihgurdgruheqnecukfhppedvtddvrd ekuddrudekrdeftdenucfrrghrrghmpehmrghilhhfrhhomheprghnughrvgifsegrjhdr ihgurdgruhenucevlhhushhtvghrufhiiigvpeeg X-ME-Proxy: Received: from mistburn.au.ibm.com (bh02i525f01.au.ibm.com [202.81.18.30]) by mail.messagingengine.com (Postfix) with ESMTPA id BC628380075; Fri, 26 Jul 2019 01:40:55 -0400 (EDT) From: Andrew Jeffery To: linux-aspeed@lists.ozlabs.org Cc: Andrew Jeffery , robh+dt@kernel.org, mark.rutland@arm.com, joel@jms.id.au, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Haiyue Wang , Corey Minyard , Arnd Bergmann , Greg Kroah-Hartman , openipmi-developer@lists.sourceforge.net Subject: [RFC PATCH 15/17] ipmi: kcs: aspeed: Implement v2 bindings Date: Fri, 26 Jul 2019 15:09:57 +0930 Message-Id: <20190726053959.2003-16-andrew@aj.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190726053959.2003-1-andrew@aj.id.au> References: <20190726053959.2003-1-andrew@aj.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The v2 bindings allow us to extract the resources from the devicetree. The table in the driver is retained to derive the channel index, which removes the need for kcs_chan property from the v1 bindings. The v2 bindings allow us to reduce the number of warnings generated by the existing devicetree nodes. Cc: Haiyue Wang Cc: Corey Minyard Cc: Arnd Bergmann Cc: Greg Kroah-Hartman Cc: openipmi-developer@lists.sourceforge.net Signed-off-by: Andrew Jeffery --- drivers/char/ipmi/kcs_bmc_aspeed.c | 156 +++++++++++++++++++++++------ 1 file changed, 127 insertions(+), 29 deletions(-) diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c b/drivers/char/ipmi/kcs_bmc_aspeed.c index e3dd09022589..509e0d3c6eb1 100644 --- a/drivers/char/ipmi/kcs_bmc_aspeed.c +++ b/drivers/char/ipmi/kcs_bmc_aspeed.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -233,38 +234,133 @@ static const struct kcs_ioreg ast_kcs_bmc_ioregs[KCS_CHANNEL_MAX] = { { .idr = LPC_IDR4, .odr = LPC_ODR4, .str = LPC_STR4 }, }; +static struct kcs_bmc *aspeed_kcs_probe_of_v1(struct platform_device *pdev) +{ + struct aspeed_kcs_bmc *priv; + struct device_node *np; + struct kcs_bmc *kcs; + u32 channel; + u32 slave; + int rc; + + np = pdev->dev.of_node; + + rc = of_property_read_u32(np, "kcs_chan", &channel); + if ((rc != 0) || (channel == 0 || channel > KCS_CHANNEL_MAX)) { + dev_err(&pdev->dev, "no valid 'kcs_chan' configured\n"); + return ERR_PTR(-EINVAL); + } + + kcs = kcs_bmc_alloc(&pdev->dev, sizeof(struct aspeed_kcs_bmc), channel); + if (!kcs) + return ERR_PTR(-ENOMEM); + + priv = kcs_bmc_priv(kcs); + priv->map = syscon_node_to_regmap(pdev->dev.parent->of_node); + if (IS_ERR(priv->map)) { + dev_err(&pdev->dev, "Couldn't get regmap\n"); + return ERR_PTR(-ENODEV); + } + + rc = of_property_read_u32(np, "kcs_addr", &slave); + if (rc) { + dev_err(&pdev->dev, "no valid 'kcs_addr' configured\n"); + return ERR_PTR(-EINVAL); + } + + kcs->ioreg = ast_kcs_bmc_ioregs[channel - 1]; + aspeed_kcs_set_address(kcs, slave); + + return 0; +} + +static int aspeed_kcs_calculate_channel(const struct kcs_ioreg *regs) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(ast_kcs_bmc_ioregs); i++) { + if (!memcmp(&ast_kcs_bmc_ioregs[i], regs, sizeof(*regs))) + return i + 1; + } + + return -EINVAL; +} + +static struct kcs_bmc *aspeed_kcs_probe_of_v2(struct platform_device *pdev) +{ + struct aspeed_kcs_bmc *priv; + struct device_node *np; + struct kcs_ioreg ioreg; + struct kcs_bmc *kcs; + const __be32 *reg; + int channel; + u32 slave; + int rc; + + np = pdev->dev.of_node; + + /* Don't translate addresses, we want offsets for the regmaps */ + reg = of_get_address(np, 0, NULL, NULL); + if (!reg) + return ERR_PTR(-EINVAL); + ioreg.idr = be32_to_cpup(reg); + + reg = of_get_address(np, 1, NULL, NULL); + if (!reg) + return ERR_PTR(-EINVAL); + ioreg.odr = be32_to_cpup(reg); + + reg = of_get_address(np, 2, NULL, NULL); + if (!reg) + return ERR_PTR(-EINVAL); + ioreg.str = be32_to_cpup(reg); + + channel = aspeed_kcs_calculate_channel(&ioreg); + if (channel < 0) + return ERR_PTR(channel); + + kcs = kcs_bmc_alloc(&pdev->dev, sizeof(struct aspeed_kcs_bmc), channel); + if (!kcs) + return ERR_PTR(-ENOMEM); + + kcs->ioreg = ioreg; + + priv = kcs_bmc_priv(kcs); + priv->map = syscon_node_to_regmap(pdev->dev.parent->of_node); + if (IS_ERR(priv->map)) { + dev_err(&pdev->dev, "Couldn't get regmap\n"); + return ERR_PTR(-ENODEV); + } + + rc = of_property_read_u32(np, "slave-reg", &slave); + if (rc) + return ERR_PTR(rc); + + aspeed_kcs_set_address(kcs, slave); + + return kcs; +} + static int aspeed_kcs_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct aspeed_kcs_bmc *priv; struct kcs_bmc *kcs_bmc; - u32 chan, addr; + struct device_node *np; int rc; - rc = of_property_read_u32(dev->of_node, "kcs_chan", &chan); - if ((rc != 0) || (chan == 0 || chan > KCS_CHANNEL_MAX)) { - dev_err(dev, "no valid 'kcs_chan' configured\n"); - return -ENODEV; - } + np = pdev->dev.of_node; + if (of_device_is_compatible(np, "aspeed,ast2400-kcs-bmc") || + of_device_is_compatible(np, "aspeed,ast2500-kcs-bmc")) + kcs_bmc = aspeed_kcs_probe_of_v1(pdev); + else if (of_device_is_compatible(np, "aspeed,ast2400-kcs-bmc-v2") || + of_device_is_compatible(np, "aspeed,ast2500-kcs-bmc-v2")) + kcs_bmc = aspeed_kcs_probe_of_v2(pdev); + else + return -EINVAL; + + if (IS_ERR(kcs_bmc)) + return PTR_ERR(kcs_bmc); - rc = of_property_read_u32(dev->of_node, "kcs_addr", &addr); - if (rc) { - dev_err(dev, "no valid 'kcs_addr' configured\n"); - return -ENODEV; - } - - kcs_bmc = kcs_bmc_alloc(dev, sizeof(*priv), chan); - if (!kcs_bmc) - return -ENOMEM; - - priv = kcs_bmc_priv(kcs_bmc); - priv->map = syscon_node_to_regmap(dev->parent->of_node); - if (IS_ERR(priv->map)) { - dev_err(dev, "Couldn't get regmap\n"); - return -ENODEV; - } - - kcs_bmc->ioreg = ast_kcs_bmc_ioregs[chan - 1]; kcs_bmc->io_inputb = aspeed_kcs_inb; kcs_bmc->io_outputb = aspeed_kcs_outb; @@ -274,7 +370,6 @@ static int aspeed_kcs_probe(struct platform_device *pdev) dev_set_drvdata(dev, kcs_bmc); - aspeed_kcs_set_address(kcs_bmc, addr); aspeed_kcs_enable_channel(kcs_bmc, true); rc = misc_register(&kcs_bmc->miscdev); @@ -283,9 +378,10 @@ static int aspeed_kcs_probe(struct platform_device *pdev) return rc; } - pr_info("channel=%u addr=0x%x idr=0x%x odr=0x%x str=0x%x\n", - chan, addr, - kcs_bmc->ioreg.idr, kcs_bmc->ioreg.odr, kcs_bmc->ioreg.str); + dev_dbg(&pdev->dev, + "Probed KCS device %d (IDR=0x%x, ODR=0x%x, STR=0x%x)\n", + kcs_bmc->channel, kcs_bmc->ioreg.idr, kcs_bmc->ioreg.odr, + kcs_bmc->ioreg.str); return 0; } @@ -302,6 +398,8 @@ static int aspeed_kcs_remove(struct platform_device *pdev) static const struct of_device_id ast_kcs_bmc_match[] = { { .compatible = "aspeed,ast2400-kcs-bmc" }, { .compatible = "aspeed,ast2500-kcs-bmc" }, + { .compatible = "aspeed,ast2400-kcs-bmc-v2" }, + { .compatible = "aspeed,ast2500-kcs-bmc-v2" }, { } }; MODULE_DEVICE_TABLE(of, ast_kcs_bmc_match); -- 2.20.1