Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp408433pxv; Thu, 22 Jul 2021 03:17:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjW3mCl9VBeP9qj0rDyd1ux1/Z8+kAtXg1Rrvo18RAHrnPvxSdaDxJzmCRl79ziXuoqTOb X-Received: by 2002:a17:907:3c16:: with SMTP id gh22mr43525464ejc.158.1626949019888; Thu, 22 Jul 2021 03:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626949019; cv=none; d=google.com; s=arc-20160816; b=UEdU+0jQFxto+JN/nYwK5mdqR1wNFjRB+v4o1pqexjUnjehj8aD5CrT/MxHK7WIg2J dNLxr9SNYJ/VCjpCetd5miE2Lw+vesGeZC4A82ukEiMSutQn6DeYB7Iogmme6OlkQbQZ QS0A415HCeDrxZp4N23SQhdzoacPsQTtW/XHoJv4JaBnka4x1glIv8DQMlFGgddNvHKk +8zED3aW93jMiNUKOgycOgg69IENGRZ1VHNeUQPurICRfd7r+9EdWMjYD8oT29iFdGWD m3nvsoDhO3tdDjKWxU/aFllUC6aNbEGkuUMgQMKn9OwPLOQLNZKR+DNLfpZugITlBzRH tKTg== 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=dAGTMbPH3MOSY1nnrA6IgyuXNpzP1ILOo4kin2biFHA=; b=Q4W5Oa1vhXwDB1HpxJMExbEz3+MAm3zzR73npDrtFXZU7OzAesOQqkrKJI0zpSFwtc 50jq1P8o6SaABeEuuNvkZVmFRePwc1bZzUxE0eOyyvw/cJIBh14ykEY4XPZ1lakrG6yQ QGRGoL/PL+C/w4Ow8fdvuB2RtsFISQHqG1IwT0kryVJIXdsaRwC1uQsNj0YFpMK06xpH hLdvW8hY//GjtItPEQh9F6gSE4gDYNavPEXl8rByJTd/q2VabnadpYFON/oG0fib9w9h fe8wFBhtfNuDWT1+a+kxD4vUb5+sb+oz1PNZZiAyczKAzu+WhaU0iWirp5L43RVjq+Jt MhRQ== 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 i23si28934186ejb.365.2021.07.22.03.16.23; Thu, 22 Jul 2021 03:16:59 -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 S231609AbhGVJeW (ORCPT + 99 others); Thu, 22 Jul 2021 05:34:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231442AbhGVJeU (ORCPT ); Thu, 22 Jul 2021 05:34:20 -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 27E54C061757 for ; Thu, 22 Jul 2021 03:14:55 -0700 (PDT) Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m6Vj8-00019X-Ms; Thu, 22 Jul 2021 12:14:50 +0200 Received: from afa by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1m6Vj7-0001KZ-4w; Thu, 22 Jul 2021 12:14:49 +0200 From: Ahmad Fatoum To: Wim Van Sebroeck , Guenter Roeck , linux-watchdog@vger.kernel.org Cc: kernel@pengutronix.de, linux-kernel@vger.kernel.org, Ahmad Fatoum Subject: [PATCH v4 4/5] watchdog: f71808e_wdt: refactor to platform device/driver pair Date: Thu, 22 Jul 2021 12:14:43 +0200 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: afa@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 Driver so far wasn't ported to the driver model and registered the watchdog device out of the init after probing the I/O ports for a watchdog with correct vendor and device revision. Keep the device detection part at init time, but move watchdog registration to a platform driver probe function. Suggested-by: Guenter Roeck Signed-off-by: Ahmad Fatoum --- drivers/watchdog/f71808e_wdt.c | 42 +++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/drivers/watchdog/f71808e_wdt.c b/drivers/watchdog/f71808e_wdt.c index efc6981d9a9b..d4cae73da002 100644 --- a/drivers/watchdog/f71808e_wdt.c +++ b/drivers/watchdog/f71808e_wdt.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #define DRVNAME "f71808e_wdt" @@ -432,10 +433,18 @@ static const struct watchdog_ops fintek_wdt_ops = { .set_timeout = fintek_wdt_set_timeout, }; -static int __init watchdog_init(int sioaddr) +static int fintek_wdt_probe(struct platform_device *pdev) { struct watchdog_device *wdd; int wdt_conf, err = 0; + struct resource *res; + int sioaddr; + + res = platform_get_resource(pdev, IORESOURCE_IO, 0); + if (!res) + return -ENXIO; + + sioaddr = res->start; watchdog.sioaddr = sioaddr; watchdog.ident.options = WDIOF_SETTIMEOUT @@ -468,6 +477,7 @@ static int __init watchdog_init(int sioaddr) superio_exit(sioaddr); + wdd->parent = &pdev->dev; wdd->info = &watchdog.ident; wdd->ops = &fintek_wdt_ops; wdd->min_timeout = 1; @@ -488,7 +498,7 @@ static int __init watchdog_init(int sioaddr) fintek_wdt_set_timeout(wdd, timeout); fintek_wdt_set_pulse_width(pulse_width); - return watchdog_register_device(wdd); + return devm_watchdog_register_device(&pdev->dev, wdd); } static int __init fintek_wdt_find(int sioaddr) @@ -554,9 +564,19 @@ static int __init fintek_wdt_find(int sioaddr) return err; } +static struct platform_driver fintek_wdt_driver = { + .probe = fintek_wdt_probe, + .driver = { + .name = DRVNAME, + }, +}; + +static struct platform_device *fintek_wdt_pdev; + static int __init fintek_wdt_init(void) { static const unsigned short addrs[] = { 0x2e, 0x4e }; + struct resource wdt_res = {}; int err = -ENODEV; int i; @@ -573,12 +593,26 @@ static int __init fintek_wdt_init(void) if (i == ARRAY_SIZE(addrs)) return err; - return watchdog_init(addrs[i]); + platform_driver_register(&fintek_wdt_driver); + + wdt_res.name = "superio port"; + wdt_res.flags = IORESOURCE_IO; + wdt_res.start = addrs[i]; + wdt_res.end = addrs[i] + 1; + + fintek_wdt_pdev = platform_device_register_simple(DRVNAME, -1, &wdt_res, 1); + if (IS_ERR(fintek_wdt_pdev)) { + platform_driver_unregister(&fintek_wdt_driver); + return PTR_ERR(fintek_wdt_pdev); + } + + return 0; } static void __exit fintek_wdt_exit(void) { - watchdog_unregister_device(&watchdog.wdd); + platform_device_unregister(fintek_wdt_pdev); + platform_driver_unregister(&fintek_wdt_driver); } MODULE_DESCRIPTION("F71808E Watchdog Driver"); -- git-series 0.9.1