Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2672533pxb; Tue, 13 Apr 2021 07:32:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvsrUuraKWFFrFfHeHULTLGAYybvzE6QuAm4V7ElTfwFsePyd5QR1AJ7XkO+EVXku2MUTB X-Received: by 2002:a65:63ce:: with SMTP id n14mr32480497pgv.279.1618324364411; Tue, 13 Apr 2021 07:32:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618324364; cv=none; d=google.com; s=arc-20160816; b=nS7dQZONkwvN9ZqNo5DEtJlA/UWAyvAupIl2E2m/Dtj3tzG8vrInoOf+8IFO+f65zM 0n4KP48AB+wclunJP5RJikiLhk0NxeRvBqUJdADSzYloSjmEEbCEZOusg5LJmHsUkPvY qeFOS+5NHb/sLcxP+TjNKK4OgDRWw+86fSkpxi+IBJUujFZwODDURrNoMSzoGenGn2lx swr+1/xJf6HAG+hj4nUkCClF2cWGxUfNd4ibcSvP699lBW4JeBJZ63La42Rw7oZCvkEk ltg+cO07w0HB2gNB9AccCAs5rZw95xCPUxybdLHjTNWoFKaW+2WPWmoQv/TOHYx4Q5UA MGrw== 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=x4IMQk0zP4JRjUU/wuHlwMmMJagZG7q8B2oRzeWGfKo=; b=MD9CtYyZNoyrdT7JwaVPSWEc+UEMdm5XHvh/Rca5+ImpyY71yNYNITmqJoAEuMc+bI 0kCvRHUx9x3oqeQ3CP0tiht7CXO0l3b3+IAwQF0wmI3A+PBCdC7jqhXW8mq62lEmJ2rz P7r5VjOu9PAnE0qsqrYC/KZ61jIKrYLk0OJWGBBk9ube5s2HSPW/7X7dv359VaU/JMo5 FL3UMCnQVLgVqKMuIaZXZx1IC1kaGyPZQFTNr3xNAEE7/Ao1aB7Mro8Q16lK9sjJqow1 m3qu7xxoB9ESs2vp2fv4jPbSyH37gVt3U9rELWzy6mKJ9FhPrJD8SRSowki4+U9/MFjw mXiQ== 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 z14si19550461pgz.360.2021.04.13.07.32.31; Tue, 13 Apr 2021 07:32: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 S1343841AbhDMKsJ (ORCPT + 99 others); Tue, 13 Apr 2021 06:48:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343819AbhDMKrc (ORCPT ); Tue, 13 Apr 2021 06:47:32 -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 03938C061756 for ; Tue, 13 Apr 2021 03:47:13 -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 1lWGZZ-0001WX-3v; Tue, 13 Apr 2021 12:47:09 +0200 Received: from afa by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1lWGZY-000711-RJ; Tue, 13 Apr 2021 12:47:08 +0200 From: Ahmad Fatoum To: Wim Van Sebroeck , Guenter Roeck , linux-watchdog@vger.kernel.org Cc: kernel@pengutronix.de, Ahmad Fatoum , linux-kernel@vger.kernel.org Subject: [RESEND PATCH v3 3/3] watchdog: f71808e_wdt: refactor to platform device/driver pair Date: Tue, 13 Apr 2021 12:46:46 +0200 Message-Id: X-Mailer: git-send-email 2.29.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 5496d2bb0089..e96f2c274b80 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