From patchwork Tue Jun 18 14:18:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard GENOUD X-Patchwork-Id: 1949208 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=OTlLKG6E; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-rtc+bounces-1353-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W3Tng2ZPcz20KL for ; Wed, 19 Jun 2024 00:35:51 +1000 (AEST) 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EC333289D2D for ; Tue, 18 Jun 2024 14:35:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9BED156898; Tue, 18 Jun 2024 14:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="OTlLKG6E" X-Original-To: linux-rtc@vger.kernel.org Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 F0A81155A53; Tue, 18 Jun 2024 14:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718720349; cv=none; b=JMgPRGIeWn5Qn17WYrAqcJ2qNYTkI8YmrLqLc/qVD5iOmxyzb03uhxgZFICYjezTJPqTNgTIZhQ+yOQaBLXaxQB1c2y2tRVfsutz9bzu/5NtTPEL+3GdLjZOL86KI/8oElUkzwRuMgHlLZ34B1CMLL7no2UwX5BYLsdNYoL8rcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718720349; c=relaxed/simple; bh=Ggs4LiAIFz6s55sxtqUcaZ2B7cPu/teZ0uahLhWKsNs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uRpfgQQIxgOjQcoFCfvJslwZoX5jOs1hoqyvBtbkSWJ/sf6/6KS9Wyfz+/HUWkMth9TwiJU/QCacWFMaLb/SpdcS6AB14HpDRaStuAHQFsv0zI3sUxUqACINNsyftPYQWqXTWP0HDQ8e0tR72rxSLwEO3/gLRlbiv5sq0vWQn74= 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=OTlLKG6E; arc=none smtp.client-ip=217.70.183.197 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 177BB1C0004; Tue, 18 Jun 2024 14:19:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1718720342; 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: in-reply-to:in-reply-to:references:references; bh=unycStWLNSmZi3IWJRgG9YiHqHREugQ7zxLXwZKoaoM=; b=OTlLKG6EFtlVA3DMngANVrxMygfpi+XMU5YIhVnM7y8eZ+tRGUFh+hLvcLJcSwQ0+nUHke Wq9S+tpGuTSQTAZvbdt/+bCH+u81h+pyAqHGu1k06HnzpgG+bGWsqN8kINBWhv355imwaL HDzJ+3JcM78o9QXZ6d8ivuwyGRgM9Dh4UgZITX8xK0xRuw2lHsTkPwus48q+wNsG3NlAAs Af6Tv1FWZGrCki+YWN+tqDu1gRhUHYlLi7Ym1dRBXnt6WoR7VIrBMhmGjmbV9mL/ak83Xr /dDOFHVTMx49ufRwY0AAG97s0QVbiDucBQ+q49PhH1weg5tGhHHlSP2kb9FB5Q== From: Richard Genoud To: Alexandre Belloni Cc: Thomas Petazzoni , Udit Kumar , Thomas Richard , Gregory CLEMENT , Esteban Blanc , linux-rtc@vger.kernel.org, Lee Jones , linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH v3 1/3] rtc: tps6594: Fix memleak in probe Date: Tue, 18 Jun 2024 16:18:49 +0200 Message-ID: <20240618141851.1810000-2-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240618141851.1810000-1-richard.genoud@bootlin.com> References: <20240618141851.1810000-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-rtc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: richard.genoud@bootlin.com struct rtc_device is allocated twice in probe(), once with devm_kzalloc(), and then with devm_rtc_allocate_device(). The allocation with devm_kzalloc() is lost and superfluous. Fixes: 9f67c1e63976 ("rtc: tps6594: Add driver for TPS6594 RTC") Signed-off-by: Richard Genoud --- drivers/rtc/rtc-tps6594.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/rtc/rtc-tps6594.c b/drivers/rtc/rtc-tps6594.c index 838ae8562a35..bc8dc735aa23 100644 --- a/drivers/rtc/rtc-tps6594.c +++ b/drivers/rtc/rtc-tps6594.c @@ -360,10 +360,6 @@ static int tps6594_rtc_probe(struct platform_device *pdev) int irq; int ret; - rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); - if (!rtc) - return -ENOMEM; - rtc = devm_rtc_allocate_device(dev); if (IS_ERR(rtc)) return PTR_ERR(rtc); From patchwork Tue Jun 18 14:18:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard GENOUD X-Patchwork-Id: 1949206 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=Reu+SU0f; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-rtc+bounces-1352-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W3TnY6Qrmz20KL for ; Wed, 19 Jun 2024 00:35:45 +1000 (AEST) 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 180081C22291 for ; Tue, 18 Jun 2024 14:35:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 529CF156243; Tue, 18 Jun 2024 14:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Reu+SU0f" X-Original-To: linux-rtc@vger.kernel.org Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 387B1155A5C; Tue, 18 Jun 2024 14:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718720349; cv=none; b=rzAbvJFvOPcPQBuP31Cz9ppSlAOxZq1qdsVuBq1AY93TOgV806lQZ5T+t7uKZC1w/1QFtOXW0TnVPAshSUssVeiIZkfq6kUQiidjls4fbgmTpYc/OwtWqsR5rLZRHOWK50X2tf9vYVCTCSwKDD6EOdN2MZAg5QIWfBKyuueRC5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718720349; c=relaxed/simple; bh=MKktt6jC0xa3wSRSarLhyx14GWAY3UF9FUHvUmSqifc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PTYtWUMgnaQjsdoI/0C05HDYD1tEPBbfL/VDYet7uv+m1g4Nvd+nI/xsAnPzxTZVcfEgjvbw99pfHCq/0nCU3mx+AlrqvjNgTAx4tCnBtEHS8IBsu/Cx8fovGJNyPJWxc9PI3mcGMItnbAEW/znVuIhOLpteYy8VsSK1RqdJEOU= 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=Reu+SU0f; arc=none smtp.client-ip=217.70.183.197 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 B52891C000C; Tue, 18 Jun 2024 14:19:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1718720343; 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: in-reply-to:in-reply-to:references:references; bh=hVqw2PBKNw40hzSiggaDbTMUTmRx6HsFHOOvvbNCjNQ=; b=Reu+SU0fbvqv5FomaWVc04pq5muSXDfIxamoSxItlTCxDnmBtwv5hSdmPKqjXLq2Ry+HXm agfRQyh9yxb/qV5rmQ/ESL9VdTdNTV5f/ocOnDHDKbVPvxnNCWf8skU4SPMtui23Dv+FNi Xt5So3gx1trrLJHG0/E8cpUQ+l2x5eAAJ0MNx2sh8+1fX0MkzBnkn/r3WeyqRARK5S7LQa ss+fYw/ItMS/l78MMgQt3CnyUwbCubkT0+4bWEAyCGKXb/kTJ+fVKAF4SPVkLMl+7vxsTD Cwq/GxxaPMaM2/Q69A5Aa+Ma9KL2ifz51GbzyfLyLHFOkogTyplZKOEMV+U+4A== From: Richard Genoud To: Alexandre Belloni Cc: Thomas Petazzoni , Udit Kumar , Thomas Richard , Gregory CLEMENT , Esteban Blanc , linux-rtc@vger.kernel.org, Lee Jones , linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH v3 2/3] rtc: tps6594: introduce private structure as drvdata Date: Tue, 18 Jun 2024 16:18:50 +0200 Message-ID: <20240618141851.1810000-3-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240618141851.1810000-1-richard.genoud@bootlin.com> References: <20240618141851.1810000-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-rtc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: richard.genoud@bootlin.com This patch will prepare for the next one (power management support) by introducing struct tps6594_rtc. No functionnal change. Signed-off-by: Richard Genoud --- drivers/rtc/rtc-tps6594.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/rtc/rtc-tps6594.c b/drivers/rtc/rtc-tps6594.c index bc8dc735aa23..06af177b2d78 100644 --- a/drivers/rtc/rtc-tps6594.c +++ b/drivers/rtc/rtc-tps6594.c @@ -42,6 +42,10 @@ // Multiplier for ppb conversions #define PPB_MULT NANO +struct tps6594_rtc { + struct rtc_device *rtc_dev; +}; + static int tps6594_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) { @@ -325,11 +329,11 @@ static int tps6594_rtc_set_offset(struct device *dev, long offset) return tps6594_rtc_set_calibration(dev, calibration); } -static irqreturn_t tps6594_rtc_interrupt(int irq, void *rtc) +static irqreturn_t tps6594_rtc_interrupt(int irq, void *data) { - struct device *dev = rtc; + struct device *dev = data; struct tps6594 *tps = dev_get_drvdata(dev->parent); - struct rtc_device *rtc_dev = dev_get_drvdata(dev); + struct tps6594_rtc *rtc = dev_get_drvdata(dev); int ret; u32 rtc_reg; @@ -337,7 +341,7 @@ static irqreturn_t tps6594_rtc_interrupt(int irq, void *rtc) if (ret) return IRQ_NONE; - rtc_update_irq(rtc_dev, 1, RTC_IRQF | RTC_AF); + rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF); return IRQ_HANDLED; } @@ -356,13 +360,17 @@ static int tps6594_rtc_probe(struct platform_device *pdev) { struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent); struct device *dev = &pdev->dev; - struct rtc_device *rtc; + struct tps6594_rtc *rtc; int irq; int ret; - rtc = devm_rtc_allocate_device(dev); - if (IS_ERR(rtc)) - return PTR_ERR(rtc); + rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); + if (!rtc) + return -ENOMEM; + + rtc->rtc_dev = devm_rtc_allocate_device(dev); + if (IS_ERR(rtc->rtc_dev)) + return PTR_ERR(rtc->rtc_dev); // Enable crystal oscillator. ret = regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_2, @@ -423,11 +431,11 @@ static int tps6594_rtc_probe(struct platform_device *pdev) return dev_err_probe(dev, ret, "Failed to init rtc as wakeup source\n"); - rtc->ops = &tps6594_rtc_ops; - rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; - rtc->range_max = RTC_TIMESTAMP_END_2099; + rtc->rtc_dev->ops = &tps6594_rtc_ops; + rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_2000; + rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_2099; - return devm_rtc_register_device(rtc); + return devm_rtc_register_device(rtc->rtc_dev); } static const struct platform_device_id tps6594_rtc_id_table[] = { From patchwork Tue Jun 18 14:18:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard GENOUD X-Patchwork-Id: 1949205 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=lIdaiIIi; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-rtc+bounces-1351-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W3TnW48q2z20KL for ; Wed, 19 Jun 2024 00:35:43 +1000 (AEST) 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 23390284065 for ; Tue, 18 Jun 2024 14:35:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11A18155CAF; Tue, 18 Jun 2024 14:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="lIdaiIIi" X-Original-To: linux-rtc@vger.kernel.org Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 F0A11155A3C; Tue, 18 Jun 2024 14:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718720349; cv=none; b=UTw1Ye/OTn/dYiCMCaJ4eyCvlg7yFuxCIUbme6mJR9nlRcierQtNiIqsMqEi8n+jZ0rkIng64qIGoV1IW/21L1K40/pU8tRo9ckaQbgQbC8maMOWmMhsmlt9g2XTKixPcGuOMjUTPDmmLPvNOn11+e6AOwhxBxScNVBI3cMH0fo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718720349; c=relaxed/simple; bh=YfMI02tpu0n8qRSeuJ2M30NKeDZGMK+deHo+6NDawxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KgosdQlhaRzcAQ4YvDTRRIVkRdkm72wQqGAM62qpCOaqjROCr+e0eua8lioWuSmFTj8dHvGdeIOxZhCPgJ7izIGZOI97BhnBpZuqJ7RrQUjTVeQ5c63d+UE/Un2clclQ9aGvWwRARTUcNpRf9eKajyHrZbYZY7H3sILu8qmk9yY= 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=lIdaiIIi; arc=none smtp.client-ip=217.70.183.197 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 6E4E71C000E; Tue, 18 Jun 2024 14:19:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1718720344; 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: in-reply-to:in-reply-to:references:references; bh=0fSZPuWmFvT69TU6yL+a+QbionkgbFOONJgwSOT+Dt8=; b=lIdaiIIiw68mLJjVJxNNKubi/YouJv7qCk+ZwtwpwmNPZAfbkdkHr2FN4bnRLFVreL6knk EWg1UoR9ziMeU+5Kgrf8L0rEy1S+/s4jeRAS/isnelp/XjwgEVcb6oAqZEyGqqLNfxbTlo yymVLBrA/FkYs2rOrqHpgVTC0E3lWQ1n1Ss92PlHXhVnQxgWgO2W145Iqst/Vvsct+rQj9 m5BhR3IExVuvIQcEeRaYPRzxktY/lg3xmebQXOCCfH82VG+Zi4AQR2fu4VFaXXd+wad6X1 yjF6KB+Y/2bJTgLHNplR9IApF+NkrnOohko6SPSWKfUiZbtk0gguol0QS38gtQ== From: Richard Genoud To: Alexandre Belloni Cc: Thomas Petazzoni , Udit Kumar , Thomas Richard , Gregory CLEMENT , Esteban Blanc , linux-rtc@vger.kernel.org, Lee Jones , linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH v3 3/3] rtc: tps6594: Add power management support Date: Tue, 18 Jun 2024 16:18:51 +0200 Message-ID: <20240618141851.1810000-4-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240618141851.1810000-1-richard.genoud@bootlin.com> References: <20240618141851.1810000-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-rtc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/rtc/rtc-tps6594.c b/drivers/rtc/rtc-tps6594.c index 06af177b2d78..e69667634137 100644 --- a/drivers/rtc/rtc-tps6594.c +++ b/drivers/rtc/rtc-tps6594.c @@ -44,6 +44,7 @@ struct tps6594_rtc { struct rtc_device *rtc_dev; + int irq; }; static int tps6594_rtc_alarm_irq_enable(struct device *dev, @@ -419,6 +420,8 @@ static int tps6594_rtc_probe(struct platform_device *pdev) if (irq < 0) return dev_err_probe(dev, irq, "Failed to get irq\n"); + rtc->irq = irq; + ret = devm_request_threaded_irq(dev, irq, NULL, tps6594_rtc_interrupt, IRQF_ONESHOT, TPS6594_IRQ_NAME_ALARM, dev); @@ -438,6 +441,49 @@ static int tps6594_rtc_probe(struct platform_device *pdev) return devm_rtc_register_device(rtc->rtc_dev); } +static int tps6594_rtc_resume(struct device *dev) +{ + struct tps6594 *tps = dev_get_drvdata(dev->parent); + struct tps6594_rtc *rtc = 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->rtc_dev, 1, RTC_IRQF | RTC_AF); + } +out: + disable_irq_wake(rtc->irq); + + return 0; +} + +static int tps6594_rtc_suspend(struct device *dev) +{ + struct tps6594_rtc *rtc = dev_get_drvdata(dev); + + enable_irq_wake(rtc->irq); + + return 0; +} + +static DEFINE_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", }, {} @@ -448,6 +494,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, };