Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3063418rwl; Mon, 27 Mar 2023 08:46:15 -0700 (PDT) X-Google-Smtp-Source: AKy350b6gFkRK3J38n/r/vS+yRQVcVNIQqkrCgRgJJMF8z/XHjH7W6OIN7QxN6/ngoQ6/MyMD6ar X-Received: by 2002:aa7:c947:0:b0:4fc:812a:ec25 with SMTP id h7-20020aa7c947000000b004fc812aec25mr11708157edt.16.1679931975017; Mon, 27 Mar 2023 08:46:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679931975; cv=none; d=google.com; s=arc-20160816; b=m+yosLJ94Lqs2/eBJ8u7DGoHNKb/q5z9xVBDG1yO976tbcRbC3vKrrQQPhgIxNM2aa 7sQ0WF2DODTW0jxkPst/t28KtqXpUBOvpUhFAAIK50OyfQilZp+jnlidNFAEt/PVnbHO ZLKjvIJUuUJ+qaKxCDdUXktkTT7+975ix48RV1CSFwKejks8nxB0aGsFRrowKrXaUl1/ GvxQfr8mY2jM/vBMtG9+IQYarkMlMvkZCdX/JhgiSaQRjk/bPo+YC4GB/Ecuf9BjlHRK sFSPUbMaUaUDA39raf8u/f/UA4NlGRzx2I0H/Vcl1FylpxMGtx4uBPVzPY6oTYoX37Jo ZvtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9LJQ+sDTT7/2B0EHkeJQ+ht/B6QBzU/r9JK7BEbK3O0=; b=OHidfL1+gylGUCUPUzWsuAFjceu+YFmbRAeWwB38IebJHKUeS0wMkt0cBdgAKlfz3d 16gdB5rjSBC6/eMiKsQ4ByuGMF4SDluZJVtE186u0TSmKnG/zzenSk2KrDE/HELWGu8J Tf8m7SDnRJy71SKC0KTAwXU5OpTMNmj2L6N6QIpFFNvYXsA2bybjmM4hMqE1sHl8OBcq p2uptaWvv/FckJ7122vXmyov1Fu7J7VtXOW62AyIWLuhNcfk26juIzwc0FeGsmIzDdDw eJZnDDOT3Me7IpLQhnQuJsfsq++ZEweSowA+Wg2qKEnYuAWkAHV5k3JZyTPawTVXhkYZ a+Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=gsnBO1w8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t26-20020a05640203da00b004fc66bd07dbsi28789091edw.369.2023.03.27.08.45.49; Mon, 27 Mar 2023 08:46:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=gsnBO1w8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233035AbjC0Plx (ORCPT + 99 others); Mon, 27 Mar 2023 11:41:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232699AbjC0Pll (ORCPT ); Mon, 27 Mar 2023 11:41:41 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59D944C05 for ; Mon, 27 Mar 2023 08:41:22 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id l15-20020a05600c4f0f00b003ef6d684102so2356145wmq.3 for ; Mon, 27 Mar 2023 08:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; t=1679931670; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9LJQ+sDTT7/2B0EHkeJQ+ht/B6QBzU/r9JK7BEbK3O0=; b=gsnBO1w8stJaAN7eUarpuZc7OS5QH0TGC6MKgYep6TLC+uFXwo4xtDempXtG5n1bZF +JNz7w2V0NFqcYsH77RIgHPK5dfZKQ9R89lVIXgIiGf5+sNsJyWTR7YyImt7Uft34+8W lGV0GXNUcjgY64KmcvP0SkCduS+ZEH0pMVwWvmjAHrUTcBkO8uUCoHHdPHRnkG9hBanm HBOuQbn6KdxlGJJGRDkltp6YkoSVaR6hsxDzkJdP05pcD/kqQW/D5rHTESHoRWA2K4uf WME0hwdli10iO4wnteJ4DOuoPwdeBHTvYljWe+1wY+fjknoVzqyiVTjqZalJk3WrFBU1 vYkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679931670; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9LJQ+sDTT7/2B0EHkeJQ+ht/B6QBzU/r9JK7BEbK3O0=; b=aURZ2DiPa/B403QcDs/EpdvZmJoJtR2WEewhqwghafg93RrZMVRuier0KiyNEVSmmj VUuRY/k0fBZ6Fn39qfrBWHDko/kTbbTZYq/IAX7P/a56dz8P/aQERk9A7ZADQJIyfchN 6qlQ2NEaJ9HUuH6YjJIgfe+5LpEDcO3hCi7MmVEe1qRDrvcg/u1z/04cAvAWUkGhrGOL x770Lt/SB/dCYCRddUyNqMBgfjn924PIWDrLajQce0BzMf64sEG14wpQ6ULvZ0ccBh1L LqaILpoQZUfhIU9td90L30+Bw2GWeAADmcoE7h/8bevD/69nBzLNDCZsh73Q6melosbl AewQ== X-Gm-Message-State: AO0yUKXBlPRAkpW77eHxZcXVHrNZnq16c8k0NOqVma6atnHI63gs4Q7Y PlQ7CEcg3djUqWShYt8OpZuKtA== X-Received: by 2002:a05:600c:220e:b0:3ee:a205:848f with SMTP id z14-20020a05600c220e00b003eea205848fmr8995855wml.20.1679931670273; Mon, 27 Mar 2023 08:41:10 -0700 (PDT) Received: from baylibre-ThinkPad-T14s-Gen-2i.. (151.31.102.84.rev.sfr.net. [84.102.31.151]) by smtp.gmail.com with ESMTPSA id a18-20020a5d4d52000000b002d1e49cff35sm25277161wru.40.2023.03.27.08.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 08:41:10 -0700 (PDT) From: Julien Panis To: lee@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, corbet@lwn.net, arnd@arndb.de, gregkh@linuxfoundation.org, derek.kiernan@xilinx.com, dragan.cvetic@xilinx.com Cc: eric.auger@redhat.com, jgg@ziepe.ca, razor@blackwall.org, stephen@networkplumber.org, davem@davemloft.net, christian.koenig@amd.com, contact@emersion.fr, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, sterzik@ti.com, u-kumar1@ti.com, eblanc@baylibre.com, jneanne@baylibre.com Subject: [PATCH v4 3/4] misc: tps6594-esm: Add driver for TI TPS6594 ESM Date: Mon, 27 Mar 2023 17:41:00 +0200 Message-Id: <20230327154101.211732-4-jpanis@baylibre.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230327154101.211732-1-jpanis@baylibre.com> References: <20230327154101.211732-1-jpanis@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 patch adds support for TPS6594 ESM (Error Signal Monitor). This device monitors the SoC error output signal at its nERR_SOC input pin. In error condition, ESM toggles its nRSTOUT_SOC pin to reset the SoC. Signed-off-by: Julien Panis --- drivers/misc/Kconfig | 11 ++++ drivers/misc/Makefile | 1 + drivers/misc/tps6594-esm.c | 132 +++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 drivers/misc/tps6594-esm.c diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 433aa4197785..c73c02801330 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -538,6 +538,17 @@ config TMR_INJECT Say N here unless you know what you are doing. +config TPS6594_ESM + tristate "TI TPS6594 Error Signal Monitor support" + depends on MFD_TPS6594 + default MFD_TPS6594 + help + Support ESM (Error Signal Monitor) on TPS6594 PMIC devices. + ESM is used typically to reboot the board in error condition. + + This driver can also be built as a module. If so, the module + will be called tps6594-esm. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig" diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 56de43943cd5..3dc69ec69912 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -65,3 +65,4 @@ obj-$(CONFIG_GP_PCI1XXXX) += mchp_pci1xxxx/ obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o obj-$(CONFIG_TMR_MANAGER) += xilinx_tmr_manager.o obj-$(CONFIG_TMR_INJECT) += xilinx_tmr_inject.o +obj-$(CONFIG_TPS6594_ESM) += tps6594-esm.o diff --git a/drivers/misc/tps6594-esm.c b/drivers/misc/tps6594-esm.c new file mode 100644 index 000000000000..7dc7cd0697ff --- /dev/null +++ b/drivers/misc/tps6594-esm.c @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ESM (Error Signal Monitor) driver for TI TPS6594/TPS6593/LP8764X PMICs + * + * Copyright (C) 2023 BayLibre Incorporated - https://www.baylibre.com/ + */ + +#include +#include +#include +#include +#include + +#include + +static irqreturn_t tps6594_esm_isr(int irq, void *dev_id) +{ + struct platform_device *pdev = dev_id; + int i; + + for (i = 0 ; i < pdev->num_resources ; i++) { + if (irq == platform_get_irq_byname(pdev, pdev->resource[i].name)) { + dev_err(pdev->dev.parent, "%s error detected\n", pdev->resource[i].name); + return IRQ_HANDLED; + } + } + + return IRQ_NONE; +} + +static int tps6594_esm_probe(struct platform_device *pdev) +{ + struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent); + struct device *dev = &pdev->dev; + int irq; + int ret; + int i; + + for (i = 0 ; i < pdev->num_resources ; i++) { + irq = platform_get_irq_byname(pdev, pdev->resource[i].name); + if (irq < 0) + return dev_err_probe(dev, irq, "Failed to get %s irq\n", + pdev->resource[i].name); + + ret = devm_request_threaded_irq(dev, irq, NULL, + tps6594_esm_isr, IRQF_ONESHOT, + pdev->resource[i].name, pdev); + if (ret) + return dev_err_probe(dev, ret, "Failed to request irq\n"); + } + + ret = regmap_set_bits(tps->regmap, TPS6594_REG_ESM_SOC_MODE_CFG, + TPS6594_BIT_ESM_SOC_EN | TPS6594_BIT_ESM_SOC_ENDRV); + if (ret) + return dev_err_probe(dev, ret, "Failed to configure ESM\n"); + + ret = regmap_set_bits(tps->regmap, TPS6594_REG_ESM_SOC_START_REG, + TPS6594_BIT_ESM_SOC_START); + if (ret) + return dev_err_probe(dev, ret, "Failed to start ESM\n"); + + pm_runtime_enable(dev); + pm_runtime_get_sync(dev); + + return 0; +} + +static int tps6594_esm_remove(struct platform_device *pdev) +{ + struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent); + struct device *dev = &pdev->dev; + int ret; + + ret = regmap_clear_bits(tps->regmap, TPS6594_REG_ESM_SOC_START_REG, + TPS6594_BIT_ESM_SOC_START); + if (ret) { + dev_err(dev, "Failed to stop ESM\n"); + goto out; + } + + ret = regmap_clear_bits(tps->regmap, TPS6594_REG_ESM_SOC_MODE_CFG, + TPS6594_BIT_ESM_SOC_EN | TPS6594_BIT_ESM_SOC_ENDRV); + if (ret) + dev_err(dev, "Failed to unconfigure ESM\n"); + +out: + pm_runtime_put_sync(dev); + pm_runtime_disable(dev); + + return ret; +} + +static int tps6594_esm_suspend(struct device *dev) +{ + struct tps6594 *tps = dev_get_drvdata(dev->parent); + int ret; + + ret = regmap_clear_bits(tps->regmap, TPS6594_REG_ESM_SOC_START_REG, + TPS6594_BIT_ESM_SOC_START); + + pm_runtime_put_sync(dev); + + return ret; +} + +static int tps6594_esm_resume(struct device *dev) +{ + struct tps6594 *tps = dev_get_drvdata(dev->parent); + + pm_runtime_get_sync(dev); + + return regmap_set_bits(tps->regmap, TPS6594_REG_ESM_SOC_START_REG, + TPS6594_BIT_ESM_SOC_START); +} + +static DEFINE_SIMPLE_DEV_PM_OPS(tps6594_esm_pm_ops, tps6594_esm_suspend, tps6594_esm_resume); + +static struct platform_driver tps6594_esm_driver = { + .driver = { + .name = "tps6594-esm", + .pm = pm_sleep_ptr(&tps6594_esm_pm_ops), + }, + .probe = tps6594_esm_probe, + .remove = tps6594_esm_remove, +}; + +module_platform_driver(tps6594_esm_driver); + +MODULE_ALIAS("platform:tps6594-esm"); +MODULE_AUTHOR("Julien Panis "); +MODULE_DESCRIPTION("TPS6594 Error Signal Monitor Driver"); +MODULE_LICENSE("GPL"); -- 2.37.3