Received: by 10.213.65.68 with SMTP id h4csp781826imn; Tue, 27 Mar 2018 08:39:53 -0700 (PDT) X-Google-Smtp-Source: AG47ELvAK6jYnegOGXAL7/wV1Dn0GxWBwgHx0wu9y6tABOoVImHHq2uDBhrQrlovXDtVm/U6fw6j X-Received: by 2002:a17:902:5409:: with SMTP id d9-v6mr33837054pli.176.1522165193149; Tue, 27 Mar 2018 08:39:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522165193; cv=none; d=google.com; s=arc-20160816; b=Zztt4MjGT+2ZQuRnP4XJjGp7N3Im9AUwVUzYN1BnCHsqwn2J0v1LsmCF3/aWj4Ll7a yolMy7NNMNmN7VI6CKYQnTTvI493rUc4eL2dGJ14UnASTcwBpxggU06d5PznzNwBsdsK DaHQil5VynJFJR7n0g2sPIOSOuoSqggGXLEcKI/7j1lNxIPd+UaECCnn+RqNRUhzIHiA SiBzO6byNYxKNaFdUqPn/fW/7DpLgGz+UTCaRGAvOiMuEs5a2EeWFN26VO2gHbEczCkp WU+prcNsPFLOOyT8iBhmUkGUAInYbEz6QtU95DnLjuz6lJTo6uMLldAGIKu+QAbcPqTI wHcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=jaGS+PHkm0gLiOlDaxREmtfJemHvjfFgRo3s5lXCX1U=; b=b/RncO+KxrMNQow7gySavptqL/G45Opn3DlUvAT66HyeuHd+V8BVpfyzvcL9s/VtkM iTd5ninQmYFOQKCytcG1pUznDZf5VgdRz1ET/O0pMqY4KT97rFwL8RXVJ6Wp94sv1wvh v0jXRGoC1K0yWtRTHj89+FWABr2rSPy9hwd1IJal8agocJ4Rf3dpisq+/Luu/3G6THPz SjPM2ztRm6tN/JMrJfxfnaxyACx7bKKc/Ph5ETJDDVItDuSAdf2lKdC8A/dC7m+EWy1B /A1UuFiGWJHWfZ7pUxgpfUDzU5cb8uTT8lMYJV+PktkHCq90d8Ym+K2nklrE0HfJwff5 JIiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FDl2hqPy; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x13si1092504pfm.281.2018.03.27.08.39.38; Tue, 27 Mar 2018 08:39:53 -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=@gmail.com header.s=20161025 header.b=FDl2hqPy; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752600AbeC0Phz (ORCPT + 99 others); Tue, 27 Mar 2018 11:37:55 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:44668 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752088AbeC0Phw (ORCPT ); Tue, 27 Mar 2018 11:37:52 -0400 Received: by mail-oi0-f66.google.com with SMTP id j143-v6so10639406oih.11 for ; Tue, 27 Mar 2018 08:37:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=jaGS+PHkm0gLiOlDaxREmtfJemHvjfFgRo3s5lXCX1U=; b=FDl2hqPyG83JAGH0lViOV32LDOuHOAS3oiyVDuNM0+pJHM+GhI1JarHz8tPqi+Z5zG wPHjMVA1gSO67me0UBlkCXUf3Fu3l0UoeIcywNYwJZS0qoSDbcj9lbuvydnH9n464k2a DR081G1pkvlKBecxiaCkx69M5eYj5yxXR/3qobCvVfNhT4S4UoPtVTCSaAOMIIWStFUB TG9Ajn4z0+SBFMw74JaoGQ6Pxu1gQdOgEMLUXFKhO0EBYqKUAHjSuvNn/DUu1940iIWe WasxsGavykDfy4RRl/rU6fnkH0YXFl/PVX25fUFaBQUVmrTFokeG/oq5v5M6Q8JXcUK8 NaFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=jaGS+PHkm0gLiOlDaxREmtfJemHvjfFgRo3s5lXCX1U=; b=RC00jFht3xlCnybMTnD3lI6DpHdtHR5pcf4z7Iw3FbIifc+OcDRltZxd+SZX8tzxtc QBpglgkhVsnBOwBqUyBO5mOpHepzu7wlt9NebRJntGpZcCR6rywnp6sXLFfVrQLZz5KD CgIGpmvRIU7PMtGBFXt2W21jZxSatOsI/SqZQl/Wn2loSW/674vZLZzQumPfcRfPV+rd CWhMaOceV0/I6Ak1IntPW3fuAKtuQlQzwNo9WPiz8RvBfUkI8skbXhTt60pSSqBPvHH2 rz0Vd4E2WyP4gFrkaBI83q+Vw+h1yk19bVlZx02dulYXsEyFMutkCtpK14yVmvFVJiE3 NVcw== X-Gm-Message-State: AElRT7FxmMJ+zXUgaieDg0Tv6Zyczj/LjITFnKiwjvAyheN7yk8LppQr 4e2UG9iy4CbL6h6HRjCWSUbKJEeTjr7qAdn+gA== X-Received: by 10.202.92.215 with SMTP id q206mr3130524oib.154.1522165072201; Tue, 27 Mar 2018 08:37:52 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:524:0:0:0:0:0 with HTTP; Tue, 27 Mar 2018 08:37:51 -0700 (PDT) In-Reply-To: <1521723015-19142-1-git-send-email-haiyue.wang@linux.intel.com> References: <1521723015-19142-1-git-send-email-haiyue.wang@linux.intel.com> From: Avi Fishman Date: Tue, 27 Mar 2018 18:37:51 +0300 Message-ID: Subject: Re: [PATCH ipmi/kcs_bmc v1] ipmi: add an NPCM7xx KCS BMC driver To: Haiyue Wang Cc: Corey Minyard , openipmi-developer@lists.sourceforge.net, OpenBMC Maillist , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks Haiyue, this works for us, I am adding Tested-by: Avi Fishman On Thu, Mar 22, 2018 at 3:50 PM, Haiyue Wang wrote: > This driver exposes the Keyboard Controller Style (KCS) interface on > Novoton NPCM7xx SoCs as a character device. Such SOCs are commonly used > as a BaseBoard Management Controller (BMC) on a server board, and KCS > interface is commonly used to perform the in-band IPMI communication > between the server and its BMC. > > Signed-off-by: Avi Fishman Tested-by: Avi Fishman > Signed-off-by: Haiyue Wang > --- > .../devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt | 39 ++++ > drivers/char/ipmi/Kconfig | 15 ++ > drivers/char/ipmi/Makefile | 1 + > drivers/char/ipmi/kcs_bmc_npcm7xx.c | 204 +++++++++++++++++++++ > 4 files changed, 259 insertions(+) > create mode 100644 Documentation/devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt > create mode 100644 drivers/char/ipmi/kcs_bmc_npcm7xx.c > > diff --git a/Documentation/devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt b/Documentation/devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt > new file mode 100644 > index 0000000..3538a21 > --- /dev/null > +++ b/Documentation/devicetree/bindings/ipmi/npcm7xx-kcs-bmc.txt > @@ -0,0 +1,39 @@ > +* Nuvoton NPCM7xx KCS (Keyboard Controller Style) IPMI interface > + > +The Nuvoton SOCs (NPCM7xx) are commonly used as BMCs > +(Baseboard Management Controllers) and the KCS interface can be > +used to perform in-band IPMI communication with their host. > + > +Required properties: > +- compatible : should be one of > + "nuvoton,npcm750-kcs-bmc" > +- interrupts : interrupt generated by the controller > +- kcs_chan : The KCS channel number in the controller > + > +Example: > + > + lpc_kcs: lpc_kcs@f0007000 { > + compatible = "nuvoton,npcm750-lpc-kcs", "simple-mfd", "syscon"; > + reg = <0xf0007000 0x40>; > + reg-io-width = <1>; > + > + #address-cells = <1>; > + #size-cells = <1>; > + ranges = <0x0 0xf0007000 0x40>; > + > + kcs1: kcs1@0 { > + compatible = "nuvoton,npcm750-kcs-bmc"; > + reg = <0x0 0x40>; > + interrupts = <0 9 4>; > + kcs_chan = <1>; > + status = "disabled"; > + }; > + > + kcs2: kcs2@0 { > + compatible = "nuvoton,npcm750-kcs-bmc"; > + reg = <0x0 0x40>; > + interrupts = <0 9 4>; > + kcs_chan = <2>; > + status = "disabled"; > + }; > + }; > \ No newline at end of file > diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig > index 3bda116..470f976 100644 > --- a/drivers/char/ipmi/Kconfig > +++ b/drivers/char/ipmi/Kconfig > @@ -111,6 +111,21 @@ config ASPEED_KCS_IPMI_BMC > The driver implements the BMC side of the KCS contorller, it > provides the access of KCS IO space for BMC side. > > +config NPCM7XX_KCS_IPMI_BMC > + depends on ARCH_NPCM7XX || COMPILE_TEST > + select IPMI_KCS_BMC > + select REGMAP_MMIO > + tristate "NPCM7xx KCS IPMI BMC driver" > + help > + Provides a driver for the KCS (Keyboard Controller Style) IPMI > + interface found on Nuvoton NPCM7xx SOCs. > + > + The driver implements the BMC side of the KCS contorller, it > + provides the access of KCS IO space for BMC side. > + > + This support is also available as a module. If so, the module > + will be called kcs_bmc_npcm7xx. > + > config ASPEED_BT_IPMI_BMC > depends on ARCH_ASPEED || COMPILE_TEST > depends on REGMAP && REGMAP_MMIO && MFD_SYSCON > diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile > index 21e9e87..7a3baf3 100644 > --- a/drivers/char/ipmi/Makefile > +++ b/drivers/char/ipmi/Makefile > @@ -24,3 +24,4 @@ obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o > obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o > obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o > obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o > +obj-$(CONFIG_NPCM7XX_KCS_IPMI_BMC) += kcs_bmc_npcm7xx.o > diff --git a/drivers/char/ipmi/kcs_bmc_npcm7xx.c b/drivers/char/ipmi/kcs_bmc_npcm7xx.c > new file mode 100644 > index 0000000..7bc898c > --- /dev/null > +++ b/drivers/char/ipmi/kcs_bmc_npcm7xx.c > @@ -0,0 +1,204 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (c) 2018, Nuvoton Corporation. > + * Copyright (c) 2018, Intel Corporation. > + */ > + > +#define pr_fmt(fmt) "nuvoton-kcs-bmc: " fmt > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "kcs_bmc.h" > + > +#define DEVICE_NAME "npcm-kcs-bmc" > +#define KCS_CHANNEL_MAX 3 > + > +#define KCS1ST 0x0C > +#define KCS2ST 0x1E > +#define KCS3ST 0x30 > + > +#define KCS1DO 0x0E > +#define KCS2DO 0x20 > +#define KCS3DO 0x32 > + > +#define KCS1DI 0x10 > +#define KCS2DI 0x22 > +#define KCS3DI 0x34 > + > +#define KCS1CTL 0x18 > +#define KCS2CTL 0x2A > +#define KCS3CTL 0x3C > +#define KCS_CTL_IBFIE BIT(0) > + > +/* > + * 7.2.4 Core KCS Registers > + * Registers in this module are 8 bits. An 8-bit register must be accessed > + * by an 8-bit read or write. > + * > + * sts: KCS Channel n Status Register (KCSnST). > + * dob: KCS Channel n Data Out Buffer Register (KCSnDO). > + * dib: KCS Channel n Data In Buffer Register (KCSnDI). > + * ctl: KCS Channel n Control Register (KCSnCTL). > + */ > +struct npcm7xx_kcs_reg { > + u32 sts; > + u32 dob; > + u32 dib; > + u32 ctl; > +}; > + > +struct npcm7xx_kcs_bmc { > + struct regmap *map; > + > + const struct npcm7xx_kcs_reg *reg; > +}; > + > +static const struct npcm7xx_kcs_reg npcm7xx_kcs_reg_tbl[KCS_CHANNEL_MAX] = { > + { .sts = KCS1ST, .dob = KCS1DO, .dib = KCS1DI, .ctl = KCS1CTL }, > + { .sts = KCS2ST, .dob = KCS2DO, .dib = KCS2DI, .ctl = KCS2CTL }, > + { .sts = KCS3ST, .dob = KCS3DO, .dib = KCS3DI, .ctl = KCS3CTL }, > +}; > + > +static u8 npcm7xx_kcs_inb(struct kcs_bmc *kcs_bmc, u32 reg) > +{ > + struct npcm7xx_kcs_bmc *priv = kcs_bmc_priv(kcs_bmc); > + u32 val = 0; > + int rc; > + > + rc = regmap_read(priv->map, reg, &val); > + WARN(rc != 0, "regmap_read() failed: %d\n", rc); > + > + return rc == 0 ? (u8)val : 0; > +} > + > +static void npcm7xx_kcs_outb(struct kcs_bmc *kcs_bmc, u32 reg, u8 data) > +{ > + struct npcm7xx_kcs_bmc *priv = kcs_bmc_priv(kcs_bmc); > + int rc; > + > + rc = regmap_write(priv->map, reg, data); > + WARN(rc != 0, "regmap_write() failed: %d\n", rc); > +} > + > +static void npcm7xx_kcs_enable_channel(struct kcs_bmc *kcs_bmc, bool enable) > +{ > + struct npcm7xx_kcs_bmc *priv = kcs_bmc_priv(kcs_bmc); > + > + regmap_update_bits(priv->map, priv->reg->ctl, KCS_CTL_IBFIE, > + enable ? KCS_CTL_IBFIE : 0); > +} > + > +static irqreturn_t npcm7xx_kcs_irq(int irq, void *arg) > +{ > + struct kcs_bmc *kcs_bmc = arg; > + > + if (!kcs_bmc_handle_event(kcs_bmc)) > + return IRQ_HANDLED; > + > + return IRQ_NONE; > +} > + > +static int npcm7xx_kcs_config_irq(struct kcs_bmc *kcs_bmc, > + struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + int irq; > + > + irq = platform_get_irq(pdev, 0); > + if (irq < 0) > + return irq; > + > + return devm_request_irq(dev, irq, npcm7xx_kcs_irq, IRQF_SHARED, > + dev_name(dev), kcs_bmc); > +} > + > +static int npcm7xx_kcs_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct npcm7xx_kcs_bmc *priv; > + struct kcs_bmc *kcs_bmc; > + u32 chan; > + 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; > + } > + > + 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; > + } > + priv->reg = &npcm7xx_kcs_reg_tbl[chan - 1]; > + > + kcs_bmc->ioreg.idr = priv->reg->dib; > + kcs_bmc->ioreg.odr = priv->reg->dob; > + kcs_bmc->ioreg.str = priv->reg->sts; > + kcs_bmc->io_inputb = npcm7xx_kcs_inb; > + kcs_bmc->io_outputb = npcm7xx_kcs_outb; > + > + dev_set_drvdata(dev, kcs_bmc); > + > + npcm7xx_kcs_enable_channel(kcs_bmc, true); > + rc = npcm7xx_kcs_config_irq(kcs_bmc, pdev); > + if (rc) > + return rc; > + > + rc = misc_register(&kcs_bmc->miscdev); > + if (rc) { > + dev_err(dev, "Unable to register device\n"); > + return rc; > + } > + > + pr_info("channel=%u idr=0x%x odr=0x%x str=0x%x\n", > + chan, > + kcs_bmc->ioreg.idr, kcs_bmc->ioreg.odr, kcs_bmc->ioreg.str); > + > + return 0; > +} > + > +static int npcm7xx_kcs_remove(struct platform_device *pdev) > +{ > + struct kcs_bmc *kcs_bmc = dev_get_drvdata(&pdev->dev); > + > + misc_deregister(&kcs_bmc->miscdev); > + > + return 0; > +} > + > +static const struct of_device_id npcm_kcs_bmc_match[] = { > + { .compatible = "nuvoton,npcm750-kcs-bmc" }, > + { } > +}; > +MODULE_DEVICE_TABLE(of, npcm_kcs_bmc_match); > + > +static struct platform_driver npcm_kcs_bmc_driver = { > + .driver = { > + .name = DEVICE_NAME, > + .of_match_table = npcm_kcs_bmc_match, > + }, > + .probe = npcm7xx_kcs_probe, > + .remove = npcm7xx_kcs_remove, > +}; > +module_platform_driver(npcm_kcs_bmc_driver); > + > +MODULE_LICENSE("GPL v2"); > +MODULE_AUTHOR("Avi Fishman "); > +MODULE_AUTHOR("Haiyue Wang "); > +MODULE_DESCRIPTION("NPCM7xx device interface to the KCS BMC device"); > -- > 2.7.4 >