From patchwork Sat Mar 4 16:56:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13159971 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B6248C6FA9E for ; Sat, 4 Mar 2023 16:58:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Jv1qco8mXrrDm5+1cumzSZCDeHdZMct8DQntsmFMEKo=; b=Sej2YGZoTMXe48 AXQWIFiwesxyetuhS5oMeLre6l/WU0aGZj1xfDaed/BgN7b4yNM/HOQk7rtbFTmcVye2w9jvUwqvt dJYKQGrXtGdPw5ULsvz3Jc/pZvpiA+hlI7kOpAABZyx/7yDT6d9CJETisLJiuUexZclpKvSd8JgrC mzteIHi8X6FY4JbQm7f69F4mwGbNBij52TroeNftirPx7uIfZeqBM7MXV39Gr8DMj0J+idl28pdMR I4WKMUw7sfrXpoAzUBLZR+BTZgxVH6pxkCcnS26CYeiwUthm8L6nFLD3oWuTgZSpkrj+jgTURKLxp kLLRqyUT9z/5nS+kOzew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pYVBx-009Gm6-Ly; Sat, 04 Mar 2023 16:57:05 +0000 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pYVBr-009GlW-6Y for linux-arm-kernel@lists.infradead.org; Sat, 04 Mar 2023 16:57:00 +0000 Received: by mail-io1-xd33.google.com with SMTP id b16so2290323iof.11 for ; Sat, 04 Mar 2023 08:56:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677949016; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=tpSFi8oQ8gJhvBK+1ukBO6QMtwZSSdSaUChPuPzBR3c=; b=Rb4ZNyGKUE3v/LdbeL9momfA58G5zQHoFZ3eElXIlCFDv59pTz9zk/d9GAyQGkyd+N PhlywmLX/4G64ibYGXNPjZlQROv50yG7R3b80N2+nEO6gvMc1e4+z3sBH6G1CErZOorn zwyoKlzOfjfXyTB//5jzMpJuJFWwABEqWhHHW34VxfMVWf1lnYsfSMKjm/Ahr7aXmEaE YOjPpujV00eHUCslDs6BPSBzNHYB1a+lqnf/P8R3eSbmlEN+BND1P69wCfCon0IlZX+x DN/eljo8Q46TqPZkI/9aw8M8/ABKX71fvwr4hdOt7fqFbpxffTWo2Ye1hr8GZz3aTa/L R7kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677949016; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tpSFi8oQ8gJhvBK+1ukBO6QMtwZSSdSaUChPuPzBR3c=; b=HG+njQ61CedhZiay3t91Fnaol5nmWlR6Z7qiWaon5Lv+gPs3XQWKJV1acyAzj/ULdl jfJIAEL+bS3x0ZsegZ8X5ArU+ImDUov9KiW8+ye8NWE9bT1+T8bV98AOFmrEO0KwWMml zmF14dwL4CrqpSYC3snZ58k3WqtjBAVnfGlv4r+k66ujZSz3P7C3cQDdtz8ZyWW+WKpn LClGH7D6C1Ki1W4iQ2pVL+A0QJa95BdShNdcbrg5C4qC8K46gJWeCc55EagQByrrlNW8 QJSFvLa7lxuuc0NrcWX/iqE2nURHpj2ZK55RPDPtu39Sc9hC0+UQoL3Z1S01EF7N24hE IxsQ== X-Gm-Message-State: AO0yUKXV3nazX3je55s6HQpQlwRAvCDyzoXETseeRbBFGJoozx25M/Dj AryPNK2npd2lfGXFZly1GXM= X-Google-Smtp-Source: AK7set83oJcNExK3Eb+T8l1q48j5qW46pOyFnowBwt1rO9/RepcMWvXnXt7Dv94AjLnFOwFjhngDLw== X-Received: by 2002:a6b:c993:0:b0:74c:8f72:291c with SMTP id z141-20020a6bc993000000b0074c8f72291cmr7584839iof.2.1677949016532; Sat, 04 Mar 2023 08:56:56 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id f13-20020a5d858d000000b0073f8a470bacsm1672220ioj.16.2023.03.04.08.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Mar 2023 08:56:55 -0800 (PST) From: Guenter Roeck To: Krzysztof Kozlowski Cc: Alim Akhtar , Wim Van Sebroeck , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Subject: [PATCH 1/2] watchdog: s3c2410_wdt: Use Use devm_clk_get[_optional]_enabled() helpers Date: Sat, 4 Mar 2023 08:56:52 -0800 Message-Id: <20230304165653.2179835-1-linux@roeck-us.net> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230304_085659_286950_05D5BE61 X-CRM114-Status: GOOD ( 17.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The devm_clk_get[_optional]_enabled() helpers: - call devm_clk_get[_optional]() - call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource. This simplifies the code and avoids the calls to clk_disable_unprepare(). While at it, use dev_err_probe consistently, and use its return value to return the error code. Cc: Uwe Kleine-König Signed-off-by: Guenter Roeck Reviewed-by: Uwe Kleine-König --- drivers/watchdog/s3c2410_wdt.c | 45 +++++++--------------------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c index 200ba236a72e..a1fcb79b0b7c 100644 --- a/drivers/watchdog/s3c2410_wdt.c +++ b/drivers/watchdog/s3c2410_wdt.c @@ -661,35 +661,17 @@ static int s3c2410wdt_probe(struct platform_device *pdev) if (IS_ERR(wdt->reg_base)) return PTR_ERR(wdt->reg_base); - wdt->bus_clk = devm_clk_get(dev, "watchdog"); - if (IS_ERR(wdt->bus_clk)) { - dev_err(dev, "failed to find bus clock\n"); - return PTR_ERR(wdt->bus_clk); - } - - ret = clk_prepare_enable(wdt->bus_clk); - if (ret < 0) { - dev_err(dev, "failed to enable bus clock\n"); - return ret; - } + wdt->bus_clk = devm_clk_get_enabled(dev, "watchdog"); + if (IS_ERR(wdt->bus_clk)) + return dev_err_probe(dev, PTR_ERR(wdt->bus_clk), "failed to get bus clock\n"); /* * "watchdog_src" clock is optional; if it's not present -- just skip it * and use "watchdog" clock as both bus and source clock. */ - wdt->src_clk = devm_clk_get_optional(dev, "watchdog_src"); - if (IS_ERR(wdt->src_clk)) { - dev_err_probe(dev, PTR_ERR(wdt->src_clk), - "failed to get source clock\n"); - ret = PTR_ERR(wdt->src_clk); - goto err_bus_clk; - } - - ret = clk_prepare_enable(wdt->src_clk); - if (ret) { - dev_err(dev, "failed to enable source clock\n"); - goto err_bus_clk; - } + wdt->src_clk = devm_clk_get_optional_enabled(dev, "watchdog_src"); + if (IS_ERR(wdt->src_clk)) + return dev_err_probe(dev, PTR_ERR(wdt->src_clk), "failed to get source clock\n"); wdt->wdt_device.min_timeout = 1; wdt->wdt_device.max_timeout = s3c2410wdt_max_timeout(wdt); @@ -710,7 +692,7 @@ static int s3c2410wdt_probe(struct platform_device *pdev) S3C2410_WATCHDOG_DEFAULT_TIME); } else { dev_err(dev, "failed to use default timeout\n"); - goto err_src_clk; + return ret; } } @@ -718,7 +700,7 @@ static int s3c2410wdt_probe(struct platform_device *pdev) pdev->name, pdev); if (ret != 0) { dev_err(dev, "failed to install irq (%d)\n", ret); - goto err_src_clk; + return ret; } watchdog_set_nowayout(&wdt->wdt_device, nowayout); @@ -744,7 +726,7 @@ static int s3c2410wdt_probe(struct platform_device *pdev) ret = watchdog_register_device(&wdt->wdt_device); if (ret) - goto err_src_clk; + return ret; ret = s3c2410wdt_enable(wdt, true); if (ret < 0) @@ -766,12 +748,6 @@ static int s3c2410wdt_probe(struct platform_device *pdev) err_unregister: watchdog_unregister_device(&wdt->wdt_device); - err_src_clk: - clk_disable_unprepare(wdt->src_clk); - - err_bus_clk: - clk_disable_unprepare(wdt->bus_clk); - return ret; } @@ -786,9 +762,6 @@ static int s3c2410wdt_remove(struct platform_device *dev) watchdog_unregister_device(&wdt->wdt_device); - clk_disable_unprepare(wdt->src_clk); - clk_disable_unprepare(wdt->bus_clk); - return 0; } From patchwork Sat Mar 4 16:56:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13159970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9F0C2C678DB for ; Sat, 4 Mar 2023 16:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0QF1jdolUl1ebrkWO/Hfwv2OsvpU5uW07ekIbAAGAJM=; b=QtdoKB5bk+uoMf 5mVyW0LAtBKsIfgCNnHa5u5Q2lw0FRrod3lA2cWRvec+/oOZt1SpLsZDWnn9FjXEGtfb2Afw3q1SK CkT28Zl7aBaqy5aaM1zlHRR8wvyuzMdNRskLyocdc/5bqPur020hQ2k7lmRsY60/zJhLHvu4EmCvt ADoiNeztE9zLZ8cfRM6pv5Uy2SoGJhfRCG8QJYG0slHfX/QZv2lwyHoXK5Wx5m+1KoimIZ52DuHJ7 Z/n1GFxJ9agqwaSpevLKfPO8MekQh1la/e/r8lGk1paYgv0WgMc0hYTPVaHXODenj1xqLXf5Id8n6 emQJ+OPJGofUhoXA1iag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pYVC5-009GnV-JG; Sat, 04 Mar 2023 16:57:13 +0000 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pYVBt-009Glb-DQ for linux-arm-kernel@lists.infradead.org; Sat, 04 Mar 2023 16:57:06 +0000 Received: by mail-il1-x12e.google.com with SMTP id k9so3296636ilu.13 for ; Sat, 04 Mar 2023 08:56:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677949018; 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=NHhEJVEVzLbDVPR+ROK20RK4K6MlBOfgj289iHs9gU8=; b=Y1aqvHe5PU4IB69r3bRAP6PbuXYJyil0hzZH2e1oumTsiO0cpIgcSwKJARNBVv+sZ+ wlMkTK3Hfph0qZSPdFkghXdW2uNM+y75lQilOOdUcwXRF2kRKFqrrBldQCRIx2uip2Uq vGfb83a1tDsYGAfdhp18v3UE27yk6YrsceuUqKXAbbyfTvIvcR8FniaBd0vCsJPRq6kz RrTEo4Pavqf6fVgWVELGg1LaskPAxolDuuLehIQY5oEHwhpX45MDHjEOmmYgBckge/Qd iSpJcVVZcDrlwQfv9cJz82JlGVcHRQb7Gl14Eol89njt/HVBaQraUFPVJal3vNn1u6G/ 1y9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677949018; 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=NHhEJVEVzLbDVPR+ROK20RK4K6MlBOfgj289iHs9gU8=; b=ZG1yUP6KhlJ5TnunkDfpkz2ySMt2D8/LAKgVsuGv/kI/Ru9wC4i665JfXxaQyR0TyB 64JkumQqtNC4FQM9gFb6XIhLM1zTHMO2KGL9bhS0EAkn/D+xihpBGxjW+fgJ5Jg9JGTd CHkUUdUnVixuED1gKgw8aIQCrndRpit2kseN2qiPae5q2G4EBR9npV8Avdi1tiVl5W63 Aj7NKVy4wjVhdg6t1E5720uQhfDuUiv3lRf2Yr9NDGH4wxxx+8s+bBWmPBPZesyLFZ0A z/IFPR5PepmgOz2ZDm856MBQbP8bXovrbvP5T+SissFTHUS3Vdp6/cdCJYpjNDrGTRdQ 1ZSQ== X-Gm-Message-State: AO0yUKUS/kcGiAlCbXQW5NYzFODdeCCHiWXn0+YCrfMIVhjKfpRjq5QX eFwzD0bcK2lUr99ceBi6kVo= X-Google-Smtp-Source: AK7set8HNAYpV75qv/aHc3DCVpUZt9UazbUxX9z1XkSHC4ogijZZcyZzS+4Zk0HVYuTj3IRbSOWzXA== X-Received: by 2002:a92:c54f:0:b0:316:dcfd:1b6e with SMTP id a15-20020a92c54f000000b00316dcfd1b6emr5001055ilj.30.1677949018184; Sat, 04 Mar 2023 08:56:58 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id m2-20020a056638224200b003c4f55da7easm1712349jas.45.2023.03.04.08.56.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Mar 2023 08:56:57 -0800 (PST) From: Guenter Roeck To: Krzysztof Kozlowski Cc: Alim Akhtar , Wim Van Sebroeck , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Subject: [PATCH 2/2] watchdog: s3c2410_wdt: Use devm_add_action_or_reset() to disable watchdog Date: Sat, 4 Mar 2023 08:56:53 -0800 Message-Id: <20230304165653.2179835-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230304165653.2179835-1-linux@roeck-us.net> References: <20230304165653.2179835-1-linux@roeck-us.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230304_085705_250773_4BCCE743 X-CRM114-Status: GOOD ( 16.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use devm_add_action_or_reset() to disable the watchdog when the driver is removed to simplify the code. With this in place, we can use devm_watchdog_register_device() to register the watchdog, and the removal function is no longer necessary. Cc: Uwe Kleine-König Signed-off-by: Guenter Roeck Acked-by: Uwe Kleine-König --- drivers/watchdog/s3c2410_wdt.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c index a1fcb79b0b7c..58b262ca4e88 100644 --- a/drivers/watchdog/s3c2410_wdt.c +++ b/drivers/watchdog/s3c2410_wdt.c @@ -623,6 +623,11 @@ s3c2410_get_wdt_drv_data(struct platform_device *pdev) return variant; } +static void s3c2410wdt_wdt_disable_action(void *data) +{ + s3c2410wdt_enable(data, false); +} + static int s3c2410wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -724,13 +729,17 @@ static int s3c2410wdt_probe(struct platform_device *pdev) s3c2410wdt_stop(&wdt->wdt_device); } - ret = watchdog_register_device(&wdt->wdt_device); + ret = devm_watchdog_register_device(dev, &wdt->wdt_device); if (ret) return ret; ret = s3c2410wdt_enable(wdt, true); if (ret < 0) - goto err_unregister; + return ret; + + ret = devm_add_action_or_reset(dev, s3c2410wdt_wdt_disable_action, wdt); + if (ret) + return ret; platform_set_drvdata(pdev, wdt); @@ -744,25 +753,6 @@ static int s3c2410wdt_probe(struct platform_device *pdev) (wtcon & S3C2410_WTCON_INTEN) ? "en" : "dis"); return 0; - - err_unregister: - watchdog_unregister_device(&wdt->wdt_device); - - return ret; -} - -static int s3c2410wdt_remove(struct platform_device *dev) -{ - int ret; - struct s3c2410_wdt *wdt = platform_get_drvdata(dev); - - ret = s3c2410wdt_enable(wdt, false); - if (ret < 0) - return ret; - - watchdog_unregister_device(&wdt->wdt_device); - - return 0; } static void s3c2410wdt_shutdown(struct platform_device *dev) @@ -817,7 +807,6 @@ static DEFINE_SIMPLE_DEV_PM_OPS(s3c2410wdt_pm_ops, static struct platform_driver s3c2410wdt_driver = { .probe = s3c2410wdt_probe, - .remove = s3c2410wdt_remove, .shutdown = s3c2410wdt_shutdown, .id_table = s3c2410_wdt_ids, .driver = {