Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4928157rdb; Fri, 15 Sep 2023 17:44:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGviufJ0ZzVWJa6U3gRWxx7A0ww9rM15DCwpavy7q411BQJQFryO0mln/nyOL3hbCaI4Xod X-Received: by 2002:a17:903:1109:b0:1c3:bbad:9b7c with SMTP id n9-20020a170903110900b001c3bbad9b7cmr3766317plh.31.1694825043834; Fri, 15 Sep 2023 17:44:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694825043; cv=none; d=google.com; s=arc-20160816; b=K+rxVbqGqEc/zEAvsKtyJhtFsWWfs/PdNwEPppCDMmxnCy3uuvbOPxG52DMCaKYowa rlT+2J055PPEngHpKyon8GTUdCIUTrlZzC6sdkHj8y1MoQi7Ku1SlJdz/AYCumz/GC6y sUf1HWjAI47kXOvwg5CDnW0blf0osxi3tQJImikV8og/u0kzEIsfEZKYN2XFObXr+0+E dy02rx7/4FgDwHoc6Xi6KhK3hAD2B4LJQkwOHHAo1PB83MQbvAehuy78xmsxnCR7zBCk ozHxU8DYpLkj4vzCCBhc0YCKnxZqmkyEPvuOb9t0npey8jI8Sbd+niRADh69zbABaKrO lVaw== 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:sender :dkim-signature; bh=ZAtiGPafozJ8Gn4LX27neNus+M3+xNnQ73f695UuZME=; fh=S9RdpwfKQ5rXEWn1rrM8k4mwVEdXu40CNytibZpR15k=; b=MDyF97s+nPACp8kgZpSqGOQG12H086auH4iruW33Zn6YJQHdyyET7WXzEnVc/7F8FI 49ajzNFWAjUViWkl/37FErltFM40b/xH1piX4gbf2tVozR9KF9HRsId6S86z8cnsxg+R nb0kRNWmnpE110wItYmnial1oJhaNb6j5eompI609tWvfgA2zNYJTpX4RlM+mPGw7S/t drL7PSTWWHPAgiCMTl2Rh7Ji9dQEYA5cn7hBmqBOr9z5zbQyayHvqLZoyiY1LjbU5Bmh WA0pxni7YmI4h1/izzRjCiFT+HX6WZQwdNKxp+oAyiwwkWLd8p05jtSXd316FppD+NYr D3Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ajnQ1nhk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id q13-20020a17090311cd00b001bdd58f685fsi4357303plh.85.2023.09.15.17.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 17:44:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ajnQ1nhk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 66CDB8021770; Fri, 15 Sep 2023 08:23:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236061AbjIOPWx (ORCPT + 99 others); Fri, 15 Sep 2023 11:22:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236057AbjIOPWw (ORCPT ); Fri, 15 Sep 2023 11:22:52 -0400 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23380E6D; Fri, 15 Sep 2023 08:22:45 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-34df2a961a0so7823285ab.2; Fri, 15 Sep 2023 08:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694791364; x=1695396164; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=ZAtiGPafozJ8Gn4LX27neNus+M3+xNnQ73f695UuZME=; b=ajnQ1nhkcm0HF8oqx83ps/MEr7N1R/VpBouAEz7GCKA/06uPYQpKxyMaVEvG/yCWjC 508LqvzkbIojmjpRMDMJw5wndiM1g39r74SO60kQnbfQW5KjM0d+W7Pcfc/vp5iwnjWk BsXBcu75aHEOkjtKpTwHGDyNQRxmV1LqAd2K6chmGix9MROtkBFMGbqKIgtAG7XwlEqw DXZrgfpx5nolRS0utcjMbt5Tl7bl8aIEhHpvwBnUh7UXx+Iap9hamXEw9SxZOktN9CMT OXrgsSlFNGsv6vGDxL6YpRRQ2faOIcpB2jL5tZRODZEGCRpKyngXuCSEgH10yh+x8laQ KPEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694791364; x=1695396164; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ZAtiGPafozJ8Gn4LX27neNus+M3+xNnQ73f695UuZME=; b=KOTBiLdpWVZD0jHs7viN96ajlwi74rI1Cfex5jgoFglTDvH9Xh4PsMgOuOX2AjF1je IhsaJ1g/T4XUXZnZMmlTeZyXYzzViagakOsBhv0KNHup6QaHRZhXEt7tA6Et9wsXqzyu 9pJ6HHhryT/Lr9o1Q2Cl9jhvrfIGGhEUugFxU349IQNBZelBZ75v6L4XdTGPkclc+JKg qCXtk3q8KTQCnsLrwgXx7FeSMh3MGI9nlViwBYqqqjxHtoEl2ZMrkV9IWUtk63PJMXvd +lcsPP7IVY+wSfk/Chh1TK1WLBXARW7kj7DQkTtPIQQry0sRuOSyqGyQKJf5Jt+X/JF9 ZOcA== X-Gm-Message-State: AOJu0Yzaw7M+Zi0ZJXnmbAbfKZ/pFu67nufCSfTNn3oVZRp8pQmoxN/n V8UYxDrcMip0e/gWBtl3Mso= X-Received: by 2002:a05:6e02:1546:b0:34f:6f44:aec4 with SMTP id j6-20020a056e02154600b0034f6f44aec4mr2940164ilu.8.1694791364381; Fri, 15 Sep 2023 08:22:44 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id s27-20020a02cc9b000000b0043321a50c29sm1085612jap.93.2023.09.15.08.22.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 08:22:44 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Alexandre Belloni , John Stultz Cc: Alessandro Zummo , Thomas Gleixner , Stephen Boyd , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, Brian Norris , Guenter Roeck Subject: [PATCH v2 1/2] rtc: Add API function to return alarm time bound by rtc limit Date: Fri, 15 Sep 2023 08:22:37 -0700 Message-Id: <20230915152238.1144706-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230915152238.1144706-1-linux@roeck-us.net> References: <20230915152238.1144706-1-linux@roeck-us.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 15 Sep 2023 08:23:15 -0700 (PDT) Add rtc_bound_alarmtime() to return the requested alarm timeout bound by the maxmum alarm timeout that is supported by a given rtc. Signed-off-by: Guenter Roeck --- v2: Added patch to provide API function include/linux/rtc.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/linux/rtc.h b/include/linux/rtc.h index 4c0bcbeb1f00..5f8e438a0312 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -225,6 +225,23 @@ static inline bool is_leap_year(unsigned int year) return (!(year % 4) && (year % 100)) || !(year % 400); } +/** + * rtc_bound_alarmtime() - Return alarm time bound by rtc limit + * @rtc: Pointer to rtc device structure + * @requested: Requested alarm timeout + * + * Return: Alarm timeout bound by maximum alarm time supported by rtc. + */ +static inline ktime_t rtc_bound_alarmtime(struct rtc_device *rtc, + ktime_t requested) +{ + if (rtc->alarm_offset_max && + rtc->alarm_offset_max * MSEC_PER_SEC < ktime_to_ms(requested)) + return ms_to_ktime(rtc->alarm_offset_max * MSEC_PER_SEC); + + return requested; +} + #define devm_rtc_register_device(device) \ __devm_rtc_register_device(THIS_MODULE, device) -- 2.39.2