Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2163488lqo; Mon, 13 May 2024 09:29:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWDqt41dtKueyiJc5WfR1swrNeG+BZWKUdEuiC7xr0OVKBUs3P7Dz/k2VTbGIoVVlw/OApFxxH/2Md2gN0CcrbW/bbXOexBOQ+UF4XxBw== X-Google-Smtp-Source: AGHT+IEyKxZgPYgNQO4tMb6+VkUW+DiozPLvAouX917wktNz2XqZkvNlv9LcX6PcleW/r35jkCZh X-Received: by 2002:a17:906:f6da:b0:a5a:1ba1:1e7b with SMTP id a640c23a62f3a-a5a2d584119mr671480866b.19.1715617796665; Mon, 13 May 2024 09:29:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715617796; cv=pass; d=google.com; s=arc-20160816; b=ChPVa1Gb5srygtgkFormQkEIhGkIWEW+d2fDfXwkqVsWZojDuGM22PaAHuonvhjAy4 TtZ5ldljEcjnt4ZWH+R++1TeIoPI80fvbOr3+i/DHksS7w07TIA2bPHhXAeZCJQ80kRs JINeLIVJDKrCNAIlUeBtS//FDw0Ghnk3A4KLnRd2YHs4IoiQis0PHH0S/5xbRWduuXF/ Dv5fgGx8S5zdhEx7JlFAxD4RJNdKxq1sYXzLyIfpnPoq2W3uImGXCW1aIwNEz1qaZGYS ks4kznP65XZHaCQkBX0oP5xoK7Y/1yJq7GkIq40QZjLX7u+C0dKlS5rdVc+ukONHdv8K eccw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=rGyJ9+fBQ8mBfRdwi06YujJsGzmctZRxczZm1z9IHuM=; fh=XtzGX2f1L7a/SbYtfqmFaACN4V99XCWjqrS9dBAXg4U=; b=SB0Aygxbuc0Zq1PmnyBaVI2fpMVnHIcWGqUtlWnN06CKshPhBWQTir8K7O7kDFsYN5 ir5wTcvCjCagKPjSgzwRWpYaPb1o8L1QEO2pSPgRl30rAqkS7fh68xB1E53XztKV4zhF d9L6RRT00KBgJdswiCL3LEGE5pFYE0ph0/FVwReJpVcg0fZhrkhofzYvGy6LOd3gvhWe SD89+AdbHXjDnidgExnzZB3Hhesz+T7MkEizDMQjhXet2+V+allZhgZBEZ6t5Cd0I1S3 Vre09bn3SkQ33xiMofKxqhA9XDgQCJahaltTDZYwSYnA+Deg08gwPkpPKSl5J02wHtZY xqPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Z95o1QHt; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-177832-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177832-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17945f7dsi504967966b.63.2024.05.13.09.29.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 09:29:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177832-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Z95o1QHt; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-177832-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177832-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3BAC91F220F4 for ; Mon, 13 May 2024 16:29:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3ABE155392; Mon, 13 May 2024 16:29:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Z95o1QHt" Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 172A814D2BF; Mon, 13 May 2024 16:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715617790; cv=none; b=Fxh1T1ZI0rEr1wwTC7Dz53BbjdAPwJvgN/WUFrmIyyY8B+dU/Kdo/JfXZwfTSaxmWQcsf0o4IKTOnWSXiPVlt3Yh1YAb6iEzdN0UXip82LDH81qVEqm3CsdAaiapIHPxxw7pI5PP4wM+ZZwr0o/wYiGrl6Iq5Vujx6wew73By2w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715617790; c=relaxed/simple; bh=P5p3YJgaSryQWCWTT7Yw2Cx0iDBf43rEw9xJhuxZSOQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=LfmAw4G2LM0DhQRsGtJPOuZGbVvpc0Z6iGFEtGVdsAIowbAjX2OaASVA8WFNWXt/e28qYkiwqPtEWILj4TiAg5yQPJAtGNn9CaNIyyHezzb907+KtvW3P54sZ+RraONj7iALZx5dZUXf7Q2ZOBuvQNh0sfsRm/K3tHAj/jni4ZY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Z95o1QHt; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 9CFD8C0006; Mon, 13 May 2024 16:29:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715617784; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=rGyJ9+fBQ8mBfRdwi06YujJsGzmctZRxczZm1z9IHuM=; b=Z95o1QHtJyY9muhfAuCZ77XJ226rG84KnkvCO51HCCcAH8QtwR8LrUwze8xucvkTSn3kr9 glKvgzCUnLPZHd+jsPt2KN46k2yEVoTojuspEdwubHLABSo3VwJ/yeWLyilLlQogCSHcFJ 3p2WqWYEPk84g3j0GXZk1Utpn/FplJW0lueaS3OpkaxQlfsmrMRnwpstio0hKOoR3NDZmq S1BlxQLNyicprYr/JAOfNAlhs7ktuUOZVSFlZKgVbEjbhdq5+XMdRhfi0Bo2z8+E1VZHc0 QeBMLIDrSCHFobIiP9yjsvq2p/dKkIaASjakF0QWX8hcXi0BzWe8cxcWI6gjPg== From: Richard Genoud To: Alexandre Belloni Cc: Esteban Blanc , linux-rtc@vger.kernel.org, Lee Jones , linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH] rtc: tps6594: Add power management support Date: Mon, 13 May 2024 18:29:42 +0200 Message-ID: <20240513162942.68484-1-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: richard.genoud@bootlin.com Add power management support to the driver. This allows a SoC to wake from suspend using the nINT provided by the RTC. It takes care of the case when the interrupt has not been caught because the kernel has not yet woke up. (This is the case when only edges interrupt are caught) Signed-off-by: Richard Genoud --- drivers/rtc/rtc-tps6594.c | 46 +++++++++++++++++++++++++++++++++++++ include/linux/mfd/tps6594.h | 1 + 2 files changed, 47 insertions(+) diff --git a/drivers/rtc/rtc-tps6594.c b/drivers/rtc/rtc-tps6594.c index 838ae8562a35..b769d120c624 100644 --- a/drivers/rtc/rtc-tps6594.c +++ b/drivers/rtc/rtc-tps6594.c @@ -415,6 +415,8 @@ static int tps6594_rtc_probe(struct platform_device *pdev) if (irq < 0) return dev_err_probe(dev, irq, "Failed to get irq\n"); + tps->irq_rtc = irq; + ret = devm_request_threaded_irq(dev, irq, NULL, tps6594_rtc_interrupt, IRQF_ONESHOT, TPS6594_IRQ_NAME_ALARM, dev); @@ -434,6 +436,49 @@ static int tps6594_rtc_probe(struct platform_device *pdev) return devm_rtc_register_device(rtc); } +static int tps6594_rtc_resume(struct device *dev) +{ + struct tps6594 *tps = dev_get_drvdata(dev->parent); + struct rtc_device *rtc_dev = dev_get_drvdata(dev); + int ret; + + ret = regmap_test_bits(tps->regmap, TPS6594_REG_INT_STARTUP, + TPS6594_BIT_RTC_INT); + if (ret < 0) { + dev_err(dev, "failed to read REG_INT_STARTUP: %d\n", ret); + goto out; + } + + if (ret > 0) { + /* + * If the alarm bit is set, it means that the IRQ has been + * fired. But, the kernel may not have woke up yet when it + * happened. So, we have to clear it. + */ + ret = regmap_write(tps->regmap, TPS6594_REG_RTC_STATUS, + TPS6594_BIT_ALARM); + if (ret < 0) + dev_err(dev, "error clearing alarm bit: %d", ret); + + rtc_update_irq(rtc_dev, 1, RTC_IRQF | RTC_AF); + } +out: + disable_irq_wake(tps->irq_rtc); + + return 0; +} + +static int tps6594_rtc_suspend(struct device *dev) +{ + struct tps6594 *tps = dev_get_drvdata(dev->parent); + + enable_irq_wake(tps->irq_rtc); + + return 0; +} + +SIMPLE_DEV_PM_OPS(tps6594_rtc_pm_ops, tps6594_rtc_suspend, tps6594_rtc_resume); + static const struct platform_device_id tps6594_rtc_id_table[] = { { "tps6594-rtc", }, {} @@ -444,6 +489,7 @@ static struct platform_driver tps6594_rtc_driver = { .probe = tps6594_rtc_probe, .driver = { .name = "tps6594-rtc", + .pm = pm_sleep_ptr(&tps6594_rtc_pm_ops), }, .id_table = tps6594_rtc_id_table, }; diff --git a/include/linux/mfd/tps6594.h b/include/linux/mfd/tps6594.h index 3f7c5e23cd4c..85933f1519c4 100644 --- a/include/linux/mfd/tps6594.h +++ b/include/linux/mfd/tps6594.h @@ -1011,6 +1011,7 @@ struct tps6594 { bool use_crc; struct regmap *regmap; int irq; + int irq_rtc; struct regmap_irq_chip_data *irq_data; }; -- 2.43.0