Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp213261pxk; Thu, 24 Sep 2020 03:57:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzUGWqC0ntViOTLFNT9f0Vb8wIfz7v8kLg4C77PUoha7ts9lv1jrt2xQBtQI1yuFBonVHt X-Received: by 2002:a17:906:3b03:: with SMTP id g3mr349932ejf.506.1600945064971; Thu, 24 Sep 2020 03:57:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600945064; cv=none; d=google.com; s=arc-20160816; b=MbrOq6NUgoE9jn0nJ7r8jH4uYWSVLuiJbwAb58Cuadw4s8VIo0goTdZ/IIXIytIXKN DbihOugP4iijI9TC+RS56+PRQob6hF5ztt25K0byk8nX4P4R9HxhIpl3YXtBTpwo5Tpd 0tluJ1h/jrzhOQC7bm7Jih5/ehGtWLMN/yRgSYCU3C92VeR++HoY7TR5lfDzo3e4mbQk B94AhZ/d9kNtlyZIwNjU1HOtiHLzXRgN+YdSEBGIdN1xmGNxn/wHfojDygsmTnHvMGES 1yCPVmxp1GXwM0rtNBwh1hiiVr+4Rwiz9inoPS3xN7bdn79b0kKot8wg3d1GTc2itFEj GEnQ== 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; bh=HTEpWqv6dOLY3DtCfynThXReirocJGcT3EV3oATF9+8=; b=LaTOblRvL6LOtz0rwgEiRpCDiW2itVXHHD1WNOJ5IwoxWLn2Vo4rsjIccjkFkUSr6w jpFzlA213BUr+7wSCETi82yfaDODAc1JxVuEg0pSonjCvaiNSrjtA0+DzzX4KpfJp5xi BjpsllFzy/IB77QqdNWPfCzuES+kBtXygIAVSylGTjPaZ21PbcHHUUifzXCquVW3Yg64 ZxZMEA/CYOgmyaHFlF6Wx6E1t1LsWIc8Dd8sSWHnkcomk0fZno0/kXBh8PV+XiXyam9D ORHWKDgzdlf8m3NmUqucOivcWLB90Nscx+IAFgGOaG51ZVVBYi9ipV7WgWmmMHkX9Eke 9pag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt14si1765156ejb.133.2020.09.24.03.57.21; Thu, 24 Sep 2020 03:57:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727330AbgIXKxL (ORCPT + 99 others); Thu, 24 Sep 2020 06:53:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726785AbgIXKxI (ORCPT ); Thu, 24 Sep 2020 06:53:08 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4107AC0613D3 for ; Thu, 24 Sep 2020 03:53:08 -0700 (PDT) Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kLOs0-00062R-SC; Thu, 24 Sep 2020 12:53:00 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1kLOrz-0005Ce-07; Thu, 24 Sep 2020 12:52:59 +0200 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Alexandre Belloni , Qiang Zhao , Bruno Thomsen Cc: linux-rtc@vger.kernel.org, a.zummo@towertech.it, linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, kernel@pengutronix.de, Wim Van Sebroeck , Guenter Roeck Subject: [PATCH 1/2] rtc: pcf2127: move watchdog initialisation to a separate function Date: Thu, 24 Sep 2020 12:52:55 +0200 Message-Id: <20200924105256.18162-2-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200924105256.18162-1-u.kleine-koenig@pengutronix.de> References: <20200924074715.GT9675@piout.net> <20200924105256.18162-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The obvious advantages are: - The linker can drop the watchdog functions if CONFIG_WATCHDOG is off. - All watchdog stuff grouped together with only a single function call left in generic code. - Watchdog register is only read when it is actually used. - Less #ifdefery Signed-off-by: Uwe Kleine-König --- drivers/rtc/rtc-pcf2127.c | 56 ++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index ed6316992cbb..5b1f1949b5e5 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -335,6 +335,36 @@ static const struct watchdog_ops pcf2127_watchdog_ops = { .set_timeout = pcf2127_wdt_set_timeout, }; +static int pcf2127_watchdog_init(struct device *dev, struct pcf2127 *pcf2127) +{ + u32 wdd_timeout; + int ret; + + if (!IS_ENABLED(CONFIG_WATCHDOG)) + return 0; + + pcf2127->wdd.parent = dev; + pcf2127->wdd.info = &pcf2127_wdt_info; + pcf2127->wdd.ops = &pcf2127_watchdog_ops; + pcf2127->wdd.min_timeout = PCF2127_WD_VAL_MIN; + pcf2127->wdd.max_timeout = PCF2127_WD_VAL_MAX; + pcf2127->wdd.timeout = PCF2127_WD_VAL_DEFAULT; + pcf2127->wdd.min_hw_heartbeat_ms = 500; + pcf2127->wdd.status = WATCHDOG_NOWAYOUT_INIT_STATUS; + + watchdog_set_drvdata(&pcf2127->wdd, pcf2127); + + /* Test if watchdog timer is started by bootloader */ + ret = regmap_read(pcf2127->regmap, PCF2127_REG_WD_VAL, &wdd_timeout); + if (ret) + return ret; + + if (wdd_timeout) + set_bit(WDOG_HW_RUNNING, &pcf2127->wdd.status); + + return devm_watchdog_register_device(dev, &pcf2127->wdd); +} + /* Alarm */ static int pcf2127_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) { @@ -536,7 +566,6 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, int alarm_irq, const char *name, bool has_nvmem) { struct pcf2127 *pcf2127; - u32 wdd_timeout; int ret = 0; dev_dbg(dev, "%s\n", __func__); @@ -575,17 +604,6 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, pcf2127->rtc->ops = &pcf2127_rtc_alrm_ops; } - pcf2127->wdd.parent = dev; - pcf2127->wdd.info = &pcf2127_wdt_info; - pcf2127->wdd.ops = &pcf2127_watchdog_ops; - pcf2127->wdd.min_timeout = PCF2127_WD_VAL_MIN; - pcf2127->wdd.max_timeout = PCF2127_WD_VAL_MAX; - pcf2127->wdd.timeout = PCF2127_WD_VAL_DEFAULT; - pcf2127->wdd.min_hw_heartbeat_ms = 500; - pcf2127->wdd.status = WATCHDOG_NOWAYOUT_INIT_STATUS; - - watchdog_set_drvdata(&pcf2127->wdd, pcf2127); - if (has_nvmem) { struct nvmem_config nvmem_cfg = { .priv = pcf2127, @@ -615,19 +633,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, return ret; } - /* Test if watchdog timer is started by bootloader */ - ret = regmap_read(pcf2127->regmap, PCF2127_REG_WD_VAL, &wdd_timeout); - if (ret) - return ret; - - if (wdd_timeout) - set_bit(WDOG_HW_RUNNING, &pcf2127->wdd.status); - -#ifdef CONFIG_WATCHDOG - ret = devm_watchdog_register_device(dev, &pcf2127->wdd); - if (ret) - return ret; -#endif /* CONFIG_WATCHDOG */ + pcf2127_watchdog_init(dev, pcf2127); /* * Disable battery low/switch-over timestamp and interrupts. -- 2.28.0