Message ID | 20230213200519.889503-4-sergio.paracuellos@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2550989wrn; Mon, 13 Feb 2023 12:13:20 -0800 (PST) X-Google-Smtp-Source: AK7set/DmBN/SJ+pz93pTPanHuKzcJOeAbTyn+rr7++0ipG2lY/hIkaet74RaS6qGTu9Q/Pv7WFu X-Received: by 2002:a17:903:4094:b0:19a:b343:d9ad with SMTP id z20-20020a170903409400b0019ab343d9admr40597plc.55.1676319200069; Mon, 13 Feb 2023 12:13:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676319200; cv=none; d=google.com; s=arc-20160816; b=V1jnJOs/ObfIp4ER/pV3WXryhvsy8i+RXS/MPAA2VXIOlYuatoIpDAX4x2iMoiUYkj 2QubwxGrTeKpWKuo8jOG2Ov+Cqvl4FZP5UlXRWl/YGdSN9z/OmPJuE2ORFNYezz6lLw+ k5BSUu1rzlG41A4Qping38w1jvkfZkiED1dQPgCeY8r0k2Bz5sv8DzF/EoAKxxJHzgp5 y9EIcRk4JfBBM8ngmWw/woluO29KAmoY2EXHWojGzLy4dQ+7M8etN4lqHDRwOU4AddTC Tpnzi8a0mIGEDEjptaXFFUwn7PddeqOT1aNyMg8P1YJXn6vjgYsTBt/PzVeeluajtiUF IBlQ== 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 :dkim-signature; bh=lhlCnihZNb20BPjIHQMYuoRdi3oZ62JfzhHTqCzRQ24=; b=RSAeMheGwR7vDqjCN2ZyJv0bVePXO1OdQPThc0G3DJV5fLVbJ8qLkFNqfvQldauahl z0J32vc0nBFpOKVwbzN0ZDnwGu5cs92pKXSDT5kUGlG1hmtsQu7mUrDlA4FDmy3WUHnf 6SRg2mJS5137/6GYvhNiFgId9FFYW3aE9GGfwN55CVJx/tI1wL8Di0ejU1pNLj+42OXO QCd4XLJpajnx3fkXGDYdHMy8g136ZdnmkvhZ5r2Yt7rtBP7J8p2ccUeeveW7SfXqZrDP JFYgB5AFfiWXNIjjpD6wkCV1dxJStwUmwgh+6OtVWJsSUnPEDbWkAYCPpCUDPXpfqVrz W8cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dNDDKMpM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jx14-20020a170903138e00b0019a99845595si4249635plb.163.2023.02.13.12.13.07; Mon, 13 Feb 2023 12:13:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dNDDKMpM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230286AbjBMUFj (ORCPT <rfc822;tebrre53rla2o@gmail.com> + 99 others); Mon, 13 Feb 2023 15:05:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230105AbjBMUF3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 13 Feb 2023 15:05:29 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B470C1D934; Mon, 13 Feb 2023 12:05:26 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id m16-20020a05600c3b1000b003dc4050c94aso9912809wms.4; Mon, 13 Feb 2023 12:05:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lhlCnihZNb20BPjIHQMYuoRdi3oZ62JfzhHTqCzRQ24=; b=dNDDKMpMHgloJyHwNh90yoMIp0iBvWg/A6xWij6O3F0yy3+V7nnKlJPbE7E4LXsUsd Wykacpe0ojR+DR2/W0SejFA5M4rG9mM8zrz3D3/o+PeM85pIsLV/lg1vr5YawwnYwTzJ MElxtQa2IkbKKVlxnPx3N5YMBa+DOK2c8SDe90tVivpwq2nd0s6xFjDFDhxM6Y4mJ1ZZ fw0krbuevPiUTPbwVcHoBH3WIEmelQnlY3Mvj+8voCMgBhAz2nGeOJ4GX9cj+tqZWykP DsCFE873vogsY0ojvhLKgWkQXY+cUkVl/nYcjgKgN41Alc9CkZ4TXB44qlq9FRAau9Uy UZCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lhlCnihZNb20BPjIHQMYuoRdi3oZ62JfzhHTqCzRQ24=; b=lRWnk4X8LT7wLEmn2yhWE4gL02HylIRUzjkqVCmdCqxkZ5xx8LSGv5ZJmKTIaqPc0U pnRuxVfyYPXJeVnTwPtVmlWQSRCJ7mqzK+i8Bsiw1kU77TA0fs0JnV9qts5uszYM2wNQ HAJUgwQrtoNp7c6pfNtA5TcC/f9H8NHd3JFO70KZ1kB52O4u9NgvBXU10D4oaOJZQrvK 0ELhKvtyRhyy8VvJKdMEY3KPQOUlsGKNbzLkYOKrwdbtFLfFA0p50fxEjcOh0q2VzU0t PkOYLJ6io22C3z0jFZE8WpC05Qizo5I65GQR4wxeuit8OGUV++9Dsi6eGQNFDUZ1BceE ETug== X-Gm-Message-State: AO0yUKXWpBCMdQt3L3ftDg5UaDw6Imvjx+douWGSS8XO1p1nP9bQoDpa nUbDzqFE6NabbmXdBqceW0JHVEDCZbQ= X-Received: by 2002:a05:600c:81b:b0:3c6:e63e:23e9 with SMTP id k27-20020a05600c081b00b003c6e63e23e9mr23363211wmp.24.1676318724833; Mon, 13 Feb 2023 12:05:24 -0800 (PST) Received: from localhost.localdomain (23.red-88-10-60.dynamicip.rima-tde.net. [88.10.60.23]) by smtp.gmail.com with ESMTPSA id c129-20020a1c3587000000b003dc1a525f22sm15591242wma.25.2023.02.13.12.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 12:05:24 -0800 (PST) From: Sergio Paracuellos <sergio.paracuellos@gmail.com> To: linux-watchdog@vger.kernel.org Cc: wim@linux-watchdog.org, linux@roeck-us.net, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, matthias.bgg@gmail.com, arinc.unal@arinc9.com, tsbogend@alpha.franken.de, p.zabel@pengutronix.de, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-mips@vger.kernel.org Subject: [PATCH v6 3/3] watchdog: mt7621-wdt: avoid ralink architecture dependent code Date: Mon, 13 Feb 2023 21:05:19 +0100 Message-Id: <20230213200519.889503-4-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213200519.889503-1-sergio.paracuellos@gmail.com> References: <20230213200519.889503-1-sergio.paracuellos@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757748081388905553?= X-GMAIL-MSGID: =?utf-8?q?1757748081388905553?= |
Series |
watchdog: mt7621-wdt: avoid globals and arch dependencies
|
|
Commit Message
Sergio Paracuellos
Feb. 13, 2023, 8:05 p.m. UTC
MT7621 SoC has a system controller node. Watchdog need to access to reset
status register. Ralink architecture and related driver are old and from
the beggining they are using some architecture dependent operations for
accessing this shared registers through 'asm/mach-ralink/ralink_regs.h'
header file. However this is not ideal from a driver perspective which can
just access to the system controller registers in an arch independent way
using regmap syscon APIs. Update Kconfig accordingly to select new added
dependencies and allow driver to be compile tested.
Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
drivers/watchdog/Kconfig | 4 +++-
drivers/watchdog/mt7621_wdt.c | 18 +++++++++++++-----
2 files changed, 16 insertions(+), 6 deletions(-)
Comments
On 13/02/2023 21:05, Sergio Paracuellos wrote: > MT7621 SoC has a system controller node. Watchdog need to access to reset > status register. Ralink architecture and related driver are old and from > the beggining they are using some architecture dependent operations for > accessing this shared registers through 'asm/mach-ralink/ralink_regs.h' > header file. However this is not ideal from a driver perspective which can > just access to the system controller registers in an arch independent way > using regmap syscon APIs. Update Kconfig accordingly to select new added > dependencies and allow driver to be compile tested. > > Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com> > --- > drivers/watchdog/Kconfig | 4 +++- > drivers/watchdog/mt7621_wdt.c | 18 +++++++++++++----- > 2 files changed, 16 insertions(+), 6 deletions(-) > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig > index b64bc49c7..cf752ad64 100644 > --- a/drivers/watchdog/Kconfig > +++ b/drivers/watchdog/Kconfig > @@ -1865,7 +1865,9 @@ config GXP_WATCHDOG > config MT7621_WDT > tristate "Mediatek SoC watchdog" > select WATCHDOG_CORE > - depends on SOC_MT7620 || SOC_MT7621 > + select REGMAP_MMIO > + select MFD_SYSCON > + depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST > help > Hardware driver for the Mediatek/Ralink MT7621/8 SoC Watchdog Timer. > > diff --git a/drivers/watchdog/mt7621_wdt.c b/drivers/watchdog/mt7621_wdt.c > index 40fb2c9ba..22e979bdd 100644 > --- a/drivers/watchdog/mt7621_wdt.c > +++ b/drivers/watchdog/mt7621_wdt.c > @@ -15,8 +15,8 @@ > #include <linux/moduleparam.h> > #include <linux/platform_device.h> > #include <linux/mod_devicetable.h> > - > -#include <asm/mach-ralink/ralink_regs.h> > +#include <linux/mfd/syscon.h> > +#include <linux/regmap.h> > > #define SYSC_RSTSTAT 0x38 > #define WDT_RST_CAUSE BIT(1) > @@ -34,6 +34,7 @@ > struct mt7621_wdt_data { > void __iomem *base; > struct reset_control *rst; > + struct regmap *sysc; > struct watchdog_device wdt; > }; > > @@ -104,9 +105,12 @@ static int mt7621_wdt_stop(struct watchdog_device *w) > return 0; > } > > -static int mt7621_wdt_bootcause(void) > +static int mt7621_wdt_bootcause(struct mt7621_wdt_data *d) > { > - if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE) > + u32 val; > + > + regmap_read(d->sysc, SYSC_RSTSTAT, &val); > + if (val & WDT_RST_CAUSE) > return WDIOF_CARDRESET; > > return 0; > @@ -143,6 +147,10 @@ static int mt7621_wdt_probe(struct platform_device *pdev) > if (!drvdata) > return -ENOMEM; > > + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); > + if (IS_ERR(drvdata->sysc)) > + return PTR_ERR(drvdata->sysc); This should be the backup/error path for original code using syscon property. Looking up by compatible is really not portable/re-usable. Best regards, Krzysztof
On Tue, Feb 14, 2023 at 9:31 AM Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote: > > On 13/02/2023 21:05, Sergio Paracuellos wrote: > > MT7621 SoC has a system controller node. Watchdog need to access to reset > > status register. Ralink architecture and related driver are old and from > > the beggining they are using some architecture dependent operations for > > accessing this shared registers through 'asm/mach-ralink/ralink_regs.h' > > header file. However this is not ideal from a driver perspective which can > > just access to the system controller registers in an arch independent way > > using regmap syscon APIs. Update Kconfig accordingly to select new added > > dependencies and allow driver to be compile tested. > > > > Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com> > > --- > > drivers/watchdog/Kconfig | 4 +++- > > drivers/watchdog/mt7621_wdt.c | 18 +++++++++++++----- > > 2 files changed, 16 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig > > index b64bc49c7..cf752ad64 100644 > > --- a/drivers/watchdog/Kconfig > > +++ b/drivers/watchdog/Kconfig > > @@ -1865,7 +1865,9 @@ config GXP_WATCHDOG > > config MT7621_WDT > > tristate "Mediatek SoC watchdog" > > select WATCHDOG_CORE > > - depends on SOC_MT7620 || SOC_MT7621 > > + select REGMAP_MMIO > > + select MFD_SYSCON > > + depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST > > help > > Hardware driver for the Mediatek/Ralink MT7621/8 SoC Watchdog Timer. > > > > diff --git a/drivers/watchdog/mt7621_wdt.c b/drivers/watchdog/mt7621_wdt.c > > index 40fb2c9ba..22e979bdd 100644 > > --- a/drivers/watchdog/mt7621_wdt.c > > +++ b/drivers/watchdog/mt7621_wdt.c > > @@ -15,8 +15,8 @@ > > #include <linux/moduleparam.h> > > #include <linux/platform_device.h> > > #include <linux/mod_devicetable.h> > > - > > -#include <asm/mach-ralink/ralink_regs.h> > > +#include <linux/mfd/syscon.h> > > +#include <linux/regmap.h> > > > > #define SYSC_RSTSTAT 0x38 > > #define WDT_RST_CAUSE BIT(1) > > @@ -34,6 +34,7 @@ > > struct mt7621_wdt_data { > > void __iomem *base; > > struct reset_control *rst; > > + struct regmap *sysc; > > struct watchdog_device wdt; > > }; > > > > @@ -104,9 +105,12 @@ static int mt7621_wdt_stop(struct watchdog_device *w) > > return 0; > > } > > > > -static int mt7621_wdt_bootcause(void) > > +static int mt7621_wdt_bootcause(struct mt7621_wdt_data *d) > > { > > - if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE) > > + u32 val; > > + > > + regmap_read(d->sysc, SYSC_RSTSTAT, &val); > > + if (val & WDT_RST_CAUSE) > > return WDIOF_CARDRESET; > > > > return 0; > > @@ -143,6 +147,10 @@ static int mt7621_wdt_probe(struct platform_device *pdev) > > if (!drvdata) > > return -ENOMEM; > > > > + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); > > + if (IS_ERR(drvdata->sysc)) > > + return PTR_ERR(drvdata->sysc); > > This should be the backup/error path for original code using syscon > property. Looking up by compatible is really not portable/re-usable. I can change the code in the way you are pointing out here but... Why is it not re-usable? Compatible is not supposed to be changed since in other cases the DTB ABI will be broken. I am totally lost about what is an ABI breakage, then. Thanks in advance for clarification. Best regards, Sergio Paracuellos > > Best regards, > Krzysztof >
On 14/02/2023 09:54, Sergio Paracuellos wrote: >>> return 0; >>> @@ -143,6 +147,10 @@ static int mt7621_wdt_probe(struct platform_device *pdev) >>> if (!drvdata) >>> return -ENOMEM; >>> >>> + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); >>> + if (IS_ERR(drvdata->sysc)) >>> + return PTR_ERR(drvdata->sysc); >> >> This should be the backup/error path for original code using syscon >> property. Looking up by compatible is really not portable/re-usable. > > I can change the code in the way you are pointing out here but... > Why is it not re-usable? Compatible is not supposed to be changed > since in other cases the DTB ABI will be broken. I am totally lost > about what is an ABI breakage, then. How do you use it on other platform? Best regards, Krzysztof
On Tue, Feb 14, 2023 at 10:33 AM Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote: > > On 14/02/2023 09:54, Sergio Paracuellos wrote: > >>> return 0; > >>> @@ -143,6 +147,10 @@ static int mt7621_wdt_probe(struct platform_device *pdev) > >>> if (!drvdata) > >>> return -ENOMEM; > >>> > >>> + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); > >>> + if (IS_ERR(drvdata->sysc)) > >>> + return PTR_ERR(drvdata->sysc); > >> > >> This should be the backup/error path for original code using syscon > >> property. Looking up by compatible is really not portable/re-usable. > > > > I can change the code in the way you are pointing out here but... > > Why is it not re-usable? Compatible is not supposed to be changed > > since in other cases the DTB ABI will be broken. I am totally lost > > about what is an ABI breakage, then. > > How do you use it on other platform? I see, thanks. So if I am understanding you correctly I have to maintain the 'mediatek,sysctl' phandle and use it in the first instance and if it fails I have to use regmap_loopup_by_compatible() stuff, right? Something like: ... drvdata->sysc = syscon_regmap_lookup_by_phandle(np, "mediatek,sysctl"); if (IS_ERR(drvdata->sysc)) { drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); if (IS_ERR(drvdata->sysc)) return PTR_ERR(drvdata->sysc); } .... So in that case, we can add the new phandle to the bindings without any kind of ABI breakage and we can use old dtbs using new watchdog driver code. I really hope I finally understood this properly. Thanks for your patience, Krzysztof. Best regards, Sergio Paracuellos > > Best regards, > Krzysztof >
On 14/02/2023 10:50, Sergio Paracuellos wrote: > On Tue, Feb 14, 2023 at 10:33 AM Krzysztof Kozlowski > <krzysztof.kozlowski@linaro.org> wrote: >> >> On 14/02/2023 09:54, Sergio Paracuellos wrote: >>>>> return 0; >>>>> @@ -143,6 +147,10 @@ static int mt7621_wdt_probe(struct platform_device *pdev) >>>>> if (!drvdata) >>>>> return -ENOMEM; >>>>> >>>>> + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); >>>>> + if (IS_ERR(drvdata->sysc)) >>>>> + return PTR_ERR(drvdata->sysc); >>>> >>>> This should be the backup/error path for original code using syscon >>>> property. Looking up by compatible is really not portable/re-usable. >>> >>> I can change the code in the way you are pointing out here but... >>> Why is it not re-usable? Compatible is not supposed to be changed >>> since in other cases the DTB ABI will be broken. I am totally lost >>> about what is an ABI breakage, then. >> >> How do you use it on other platform? > > I see, thanks. > > So if I am understanding you correctly I have to maintain the > 'mediatek,sysctl' phandle and use it in the first instance and if it > fails I have to use regmap_loopup_by_compatible() stuff, right? > Something like: > > ... > > drvdata->sysc = syscon_regmap_lookup_by_phandle(np, "mediatek,sysctl"); > if (IS_ERR(drvdata->sysc)) { > drvdata->sysc = > syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); > if (IS_ERR(drvdata->sysc)) > return PTR_ERR(drvdata->sysc); > } > > .... > > So in that case, we can add the new phandle to the bindings without > any kind of ABI breakage and we can use old dtbs using new watchdog > driver code. > Yes. Best regards, Krzysztof
On 2/14/23 00:31, Krzysztof Kozlowski wrote: > On 13/02/2023 21:05, Sergio Paracuellos wrote: >> MT7621 SoC has a system controller node. Watchdog need to access to reset >> status register. Ralink architecture and related driver are old and from >> the beggining they are using some architecture dependent operations for >> accessing this shared registers through 'asm/mach-ralink/ralink_regs.h' >> header file. However this is not ideal from a driver perspective which can >> just access to the system controller registers in an arch independent way >> using regmap syscon APIs. Update Kconfig accordingly to select new added >> dependencies and allow driver to be compile tested. >> >> Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com> >> --- >> drivers/watchdog/Kconfig | 4 +++- >> drivers/watchdog/mt7621_wdt.c | 18 +++++++++++++----- >> 2 files changed, 16 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig >> index b64bc49c7..cf752ad64 100644 >> --- a/drivers/watchdog/Kconfig >> +++ b/drivers/watchdog/Kconfig >> @@ -1865,7 +1865,9 @@ config GXP_WATCHDOG >> config MT7621_WDT >> tristate "Mediatek SoC watchdog" >> select WATCHDOG_CORE >> - depends on SOC_MT7620 || SOC_MT7621 >> + select REGMAP_MMIO >> + select MFD_SYSCON >> + depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST >> help >> Hardware driver for the Mediatek/Ralink MT7621/8 SoC Watchdog Timer. >> >> diff --git a/drivers/watchdog/mt7621_wdt.c b/drivers/watchdog/mt7621_wdt.c >> index 40fb2c9ba..22e979bdd 100644 >> --- a/drivers/watchdog/mt7621_wdt.c >> +++ b/drivers/watchdog/mt7621_wdt.c >> @@ -15,8 +15,8 @@ >> #include <linux/moduleparam.h> >> #include <linux/platform_device.h> >> #include <linux/mod_devicetable.h> >> - >> -#include <asm/mach-ralink/ralink_regs.h> >> +#include <linux/mfd/syscon.h> >> +#include <linux/regmap.h> >> >> #define SYSC_RSTSTAT 0x38 >> #define WDT_RST_CAUSE BIT(1) >> @@ -34,6 +34,7 @@ >> struct mt7621_wdt_data { >> void __iomem *base; >> struct reset_control *rst; >> + struct regmap *sysc; >> struct watchdog_device wdt; >> }; >> >> @@ -104,9 +105,12 @@ static int mt7621_wdt_stop(struct watchdog_device *w) >> return 0; >> } >> >> -static int mt7621_wdt_bootcause(void) >> +static int mt7621_wdt_bootcause(struct mt7621_wdt_data *d) >> { >> - if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE) >> + u32 val; >> + >> + regmap_read(d->sysc, SYSC_RSTSTAT, &val); >> + if (val & WDT_RST_CAUSE) >> return WDIOF_CARDRESET; >> >> return 0; >> @@ -143,6 +147,10 @@ static int mt7621_wdt_probe(struct platform_device *pdev) >> if (!drvdata) >> return -ENOMEM; >> >> + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); >> + if (IS_ERR(drvdata->sysc)) >> + return PTR_ERR(drvdata->sysc); > > This should be the backup/error path for original code using syscon > property. Looking up by compatible is really not portable/re-usable. > I really disagree here. $ git grep syscon_regmap_lookup_by_compatible | wc 90 326 8940 I have not yet reviewed this code, but I do not accept this argument against it. Guenter
On 14/02/2023 13:10, Guenter Roeck wrote: > On 2/14/23 00:31, Krzysztof Kozlowski wrote: >> On 13/02/2023 21:05, Sergio Paracuellos wrote: >>> MT7621 SoC has a system controller node. Watchdog need to access to reset >>> status register. Ralink architecture and related driver are old and from >>> the beggining they are using some architecture dependent operations for >>> accessing this shared registers through 'asm/mach-ralink/ralink_regs.h' >>> header file. However this is not ideal from a driver perspective which can >>> just access to the system controller registers in an arch independent way >>> using regmap syscon APIs. Update Kconfig accordingly to select new added >>> dependencies and allow driver to be compile tested. >>> >>> Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com> >>> --- >>> drivers/watchdog/Kconfig | 4 +++- >>> drivers/watchdog/mt7621_wdt.c | 18 +++++++++++++----- >>> 2 files changed, 16 insertions(+), 6 deletions(-) >>> >>> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig >>> index b64bc49c7..cf752ad64 100644 >>> --- a/drivers/watchdog/Kconfig >>> +++ b/drivers/watchdog/Kconfig >>> @@ -1865,7 +1865,9 @@ config GXP_WATCHDOG >>> config MT7621_WDT >>> tristate "Mediatek SoC watchdog" >>> select WATCHDOG_CORE >>> - depends on SOC_MT7620 || SOC_MT7621 >>> + select REGMAP_MMIO >>> + select MFD_SYSCON >>> + depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST >>> help >>> Hardware driver for the Mediatek/Ralink MT7621/8 SoC Watchdog Timer. >>> >>> diff --git a/drivers/watchdog/mt7621_wdt.c b/drivers/watchdog/mt7621_wdt.c >>> index 40fb2c9ba..22e979bdd 100644 >>> --- a/drivers/watchdog/mt7621_wdt.c >>> +++ b/drivers/watchdog/mt7621_wdt.c >>> @@ -15,8 +15,8 @@ >>> #include <linux/moduleparam.h> >>> #include <linux/platform_device.h> >>> #include <linux/mod_devicetable.h> >>> - >>> -#include <asm/mach-ralink/ralink_regs.h> >>> +#include <linux/mfd/syscon.h> >>> +#include <linux/regmap.h> >>> >>> #define SYSC_RSTSTAT 0x38 >>> #define WDT_RST_CAUSE BIT(1) >>> @@ -34,6 +34,7 @@ >>> struct mt7621_wdt_data { >>> void __iomem *base; >>> struct reset_control *rst; >>> + struct regmap *sysc; >>> struct watchdog_device wdt; >>> }; >>> >>> @@ -104,9 +105,12 @@ static int mt7621_wdt_stop(struct watchdog_device *w) >>> return 0; >>> } >>> >>> -static int mt7621_wdt_bootcause(void) >>> +static int mt7621_wdt_bootcause(struct mt7621_wdt_data *d) >>> { >>> - if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE) >>> + u32 val; >>> + >>> + regmap_read(d->sysc, SYSC_RSTSTAT, &val); >>> + if (val & WDT_RST_CAUSE) >>> return WDIOF_CARDRESET; >>> >>> return 0; >>> @@ -143,6 +147,10 @@ static int mt7621_wdt_probe(struct platform_device *pdev) >>> if (!drvdata) >>> return -ENOMEM; >>> >>> + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); >>> + if (IS_ERR(drvdata->sysc)) >>> + return PTR_ERR(drvdata->sysc); >> >> This should be the backup/error path for original code using syscon >> property. Looking up by compatible is really not portable/re-usable. >> > > I really disagree here. > > $ git grep syscon_regmap_lookup_by_compatible | wc > 90 326 8940 > > I have not yet reviewed this code, but I do not accept this argument against it. First, argument that bad pattern is being used is not an argument to keep it and repeat it. Second, we already had examples that: 1. Author used syscon_regmap_lookup_by_compatible() and assumed "we will never add new variant/soc". 2. Then turns out that new variants are obviously added and syscon_regmap_lookup_by_compatible() stops scaling. Whether any new variant/compatible/platform can appear for this watchdog - I don't know. Third, with syscon_regmap_lookup_by_compatible() you have undocumented (not in the binding) dependency between blocks which: a. stops any reusability, b. affects device links and probe ordering (simply - there is no, device must defer probe), c. is simply undocumented. The usage of syscon_regmap_lookup_by_compatible() has clear drawbacks thus new code should rather use syscon phandles which solve all of above. Best regards, Krzysztof
On 2/14/23 04:15, Krzysztof Kozlowski wrote: > On 14/02/2023 13:10, Guenter Roeck wrote: >> On 2/14/23 00:31, Krzysztof Kozlowski wrote: >>> On 13/02/2023 21:05, Sergio Paracuellos wrote: >>>> MT7621 SoC has a system controller node. Watchdog need to access to reset >>>> status register. Ralink architecture and related driver are old and from >>>> the beggining they are using some architecture dependent operations for >>>> accessing this shared registers through 'asm/mach-ralink/ralink_regs.h' >>>> header file. However this is not ideal from a driver perspective which can >>>> just access to the system controller registers in an arch independent way >>>> using regmap syscon APIs. Update Kconfig accordingly to select new added >>>> dependencies and allow driver to be compile tested. >>>> >>>> Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com> >>>> --- >>>> drivers/watchdog/Kconfig | 4 +++- >>>> drivers/watchdog/mt7621_wdt.c | 18 +++++++++++++----- >>>> 2 files changed, 16 insertions(+), 6 deletions(-) >>>> >>>> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig >>>> index b64bc49c7..cf752ad64 100644 >>>> --- a/drivers/watchdog/Kconfig >>>> +++ b/drivers/watchdog/Kconfig >>>> @@ -1865,7 +1865,9 @@ config GXP_WATCHDOG >>>> config MT7621_WDT >>>> tristate "Mediatek SoC watchdog" >>>> select WATCHDOG_CORE >>>> - depends on SOC_MT7620 || SOC_MT7621 >>>> + select REGMAP_MMIO >>>> + select MFD_SYSCON >>>> + depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST >>>> help >>>> Hardware driver for the Mediatek/Ralink MT7621/8 SoC Watchdog Timer. >>>> >>>> diff --git a/drivers/watchdog/mt7621_wdt.c b/drivers/watchdog/mt7621_wdt.c >>>> index 40fb2c9ba..22e979bdd 100644 >>>> --- a/drivers/watchdog/mt7621_wdt.c >>>> +++ b/drivers/watchdog/mt7621_wdt.c >>>> @@ -15,8 +15,8 @@ >>>> #include <linux/moduleparam.h> >>>> #include <linux/platform_device.h> >>>> #include <linux/mod_devicetable.h> >>>> - >>>> -#include <asm/mach-ralink/ralink_regs.h> >>>> +#include <linux/mfd/syscon.h> >>>> +#include <linux/regmap.h> >>>> >>>> #define SYSC_RSTSTAT 0x38 >>>> #define WDT_RST_CAUSE BIT(1) >>>> @@ -34,6 +34,7 @@ >>>> struct mt7621_wdt_data { >>>> void __iomem *base; >>>> struct reset_control *rst; >>>> + struct regmap *sysc; >>>> struct watchdog_device wdt; >>>> }; >>>> >>>> @@ -104,9 +105,12 @@ static int mt7621_wdt_stop(struct watchdog_device *w) >>>> return 0; >>>> } >>>> >>>> -static int mt7621_wdt_bootcause(void) >>>> +static int mt7621_wdt_bootcause(struct mt7621_wdt_data *d) >>>> { >>>> - if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE) >>>> + u32 val; >>>> + >>>> + regmap_read(d->sysc, SYSC_RSTSTAT, &val); >>>> + if (val & WDT_RST_CAUSE) >>>> return WDIOF_CARDRESET; >>>> >>>> return 0; >>>> @@ -143,6 +147,10 @@ static int mt7621_wdt_probe(struct platform_device *pdev) >>>> if (!drvdata) >>>> return -ENOMEM; >>>> >>>> + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); >>>> + if (IS_ERR(drvdata->sysc)) >>>> + return PTR_ERR(drvdata->sysc); >>> >>> This should be the backup/error path for original code using syscon >>> property. Looking up by compatible is really not portable/re-usable. >>> >> >> I really disagree here. >> >> $ git grep syscon_regmap_lookup_by_compatible | wc >> 90 326 8940 >> >> I have not yet reviewed this code, but I do not accept this argument against it. > > First, argument that bad pattern is being used is not an argument to > keep it and repeat it. > > Second, we already had examples that: > 1. Author used syscon_regmap_lookup_by_compatible() and assumed "we will > never add new variant/soc". > 2. Then turns out that new variants are obviously added and > syscon_regmap_lookup_by_compatible() stops scaling. > Your arguments only applies if 1) there is ever going to be a new Mediatek/Ralink chip with the same watchdog core, and 2) that chip also has the same watchdog related registers in its syscon node. Both is highly unlikely to happen. There already is a more generic watchdog driver for later Mediatek chips (mtk_wdt.c). Even if Mediatek/Ralink ever decides to revive this specific watchdog core for whatever reason, the time to make the code more generic would have been at that time, at the same time ensuring that the more generic code actually works and does have the same syscon registers to obtain the boot status. > Whether any new variant/compatible/platform can appear for this watchdog > - I don't know. > > Third, with syscon_regmap_lookup_by_compatible() you have undocumented > (not in the binding) dependency between blocks which: > a. stops any reusability, > b. affects device links and probe ordering (simply - there is no, device > must defer probe), > c. is simply undocumented. > > The usage of syscon_regmap_lookup_by_compatible() has clear drawbacks > thus new code should rather use syscon phandles which solve all of above. > "new code". Exactly. This isn't new code. In order to make progress, I'll accept v7, assuming its updated devicetree description is going to be accepted, but my argument still stands. Guenter
On 14/02/2023 16:07, Guenter Roeck wrote: > On 2/14/23 04:15, Krzysztof Kozlowski wrote: >> On 14/02/2023 13:10, Guenter Roeck wrote: >>> On 2/14/23 00:31, Krzysztof Kozlowski wrote: >>>> On 13/02/2023 21:05, Sergio Paracuellos wrote: >>>>> MT7621 SoC has a system controller node. Watchdog need to access to reset >>>>> status register. Ralink architecture and related driver are old and from >>>>> the beggining they are using some architecture dependent operations for >>>>> accessing this shared registers through 'asm/mach-ralink/ralink_regs.h' >>>>> header file. However this is not ideal from a driver perspective which can >>>>> just access to the system controller registers in an arch independent way >>>>> using regmap syscon APIs. Update Kconfig accordingly to select new added >>>>> dependencies and allow driver to be compile tested. >>>>> >>>>> Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com> >>>>> --- >>>>> drivers/watchdog/Kconfig | 4 +++- >>>>> drivers/watchdog/mt7621_wdt.c | 18 +++++++++++++----- >>>>> 2 files changed, 16 insertions(+), 6 deletions(-) >>>>> >>>>> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig >>>>> index b64bc49c7..cf752ad64 100644 >>>>> --- a/drivers/watchdog/Kconfig >>>>> +++ b/drivers/watchdog/Kconfig >>>>> @@ -1865,7 +1865,9 @@ config GXP_WATCHDOG >>>>> config MT7621_WDT >>>>> tristate "Mediatek SoC watchdog" >>>>> select WATCHDOG_CORE >>>>> - depends on SOC_MT7620 || SOC_MT7621 >>>>> + select REGMAP_MMIO >>>>> + select MFD_SYSCON >>>>> + depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST >>>>> help >>>>> Hardware driver for the Mediatek/Ralink MT7621/8 SoC Watchdog Timer. >>>>> >>>>> diff --git a/drivers/watchdog/mt7621_wdt.c b/drivers/watchdog/mt7621_wdt.c >>>>> index 40fb2c9ba..22e979bdd 100644 >>>>> --- a/drivers/watchdog/mt7621_wdt.c >>>>> +++ b/drivers/watchdog/mt7621_wdt.c >>>>> @@ -15,8 +15,8 @@ >>>>> #include <linux/moduleparam.h> >>>>> #include <linux/platform_device.h> >>>>> #include <linux/mod_devicetable.h> >>>>> - >>>>> -#include <asm/mach-ralink/ralink_regs.h> >>>>> +#include <linux/mfd/syscon.h> >>>>> +#include <linux/regmap.h> >>>>> >>>>> #define SYSC_RSTSTAT 0x38 >>>>> #define WDT_RST_CAUSE BIT(1) >>>>> @@ -34,6 +34,7 @@ >>>>> struct mt7621_wdt_data { >>>>> void __iomem *base; >>>>> struct reset_control *rst; >>>>> + struct regmap *sysc; >>>>> struct watchdog_device wdt; >>>>> }; >>>>> >>>>> @@ -104,9 +105,12 @@ static int mt7621_wdt_stop(struct watchdog_device *w) >>>>> return 0; >>>>> } >>>>> >>>>> -static int mt7621_wdt_bootcause(void) >>>>> +static int mt7621_wdt_bootcause(struct mt7621_wdt_data *d) >>>>> { >>>>> - if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE) >>>>> + u32 val; >>>>> + >>>>> + regmap_read(d->sysc, SYSC_RSTSTAT, &val); >>>>> + if (val & WDT_RST_CAUSE) >>>>> return WDIOF_CARDRESET; >>>>> >>>>> return 0; >>>>> @@ -143,6 +147,10 @@ static int mt7621_wdt_probe(struct platform_device *pdev) >>>>> if (!drvdata) >>>>> return -ENOMEM; >>>>> >>>>> + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); >>>>> + if (IS_ERR(drvdata->sysc)) >>>>> + return PTR_ERR(drvdata->sysc); >>>> >>>> This should be the backup/error path for original code using syscon >>>> property. Looking up by compatible is really not portable/re-usable. >>>> >>> >>> I really disagree here. >>> >>> $ git grep syscon_regmap_lookup_by_compatible | wc >>> 90 326 8940 >>> >>> I have not yet reviewed this code, but I do not accept this argument against it. >> >> First, argument that bad pattern is being used is not an argument to >> keep it and repeat it. >> >> Second, we already had examples that: >> 1. Author used syscon_regmap_lookup_by_compatible() and assumed "we will >> never add new variant/soc". >> 2. Then turns out that new variants are obviously added and >> syscon_regmap_lookup_by_compatible() stops scaling. >> > > Your arguments only applies if 1) there is ever going to be a new Mediatek/Ralink > chip with the same watchdog core, and 2) that chip also has the same watchdog > related registers in its syscon node. > > Both is highly unlikely to happen. There already is a more generic watchdog > driver for later Mediatek chips (mtk_wdt.c). Even if Mediatek/Ralink ever > decides to revive this specific watchdog core for whatever reason, > the time to make the code more generic would have been at that time, at the same > time ensuring that the more generic code actually works and does have the > same syscon registers to obtain the boot status. Sure. In other cases we experienced, people also claimed that this will not happen. But it happened... I cannot judge whether this will happen here or not, thus I give generic guideline. If you (singular and plural) are sure this will not happen, then the code is fine. > >> Whether any new variant/compatible/platform can appear for this watchdog >> - I don't know. >> >> Third, with syscon_regmap_lookup_by_compatible() you have undocumented >> (not in the binding) dependency between blocks which: >> a. stops any reusability, >> b. affects device links and probe ordering (simply - there is no, device >> must defer probe), >> c. is simply undocumented. >> >> The usage of syscon_regmap_lookup_by_compatible() has clear drawbacks >> thus new code should rather use syscon phandles which solve all of above. >> > > "new code". Exactly. This isn't new code. New code not as "new driver" but new code adding syscon usage. Syscon is new here so we have flexibility to make it differently, and IMHO, one way is better than other (for the reasons I stated). > > In order to make progress, I'll accept v7, assuming its updated devicetree > description is going to be accepted, but my argument still stands. Best regards, Krzysztof
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index b64bc49c7..cf752ad64 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -1865,7 +1865,9 @@ config GXP_WATCHDOG config MT7621_WDT tristate "Mediatek SoC watchdog" select WATCHDOG_CORE - depends on SOC_MT7620 || SOC_MT7621 + select REGMAP_MMIO + select MFD_SYSCON + depends on SOC_MT7620 || SOC_MT7621 || COMPILE_TEST help Hardware driver for the Mediatek/Ralink MT7621/8 SoC Watchdog Timer. diff --git a/drivers/watchdog/mt7621_wdt.c b/drivers/watchdog/mt7621_wdt.c index 40fb2c9ba..22e979bdd 100644 --- a/drivers/watchdog/mt7621_wdt.c +++ b/drivers/watchdog/mt7621_wdt.c @@ -15,8 +15,8 @@ #include <linux/moduleparam.h> #include <linux/platform_device.h> #include <linux/mod_devicetable.h> - -#include <asm/mach-ralink/ralink_regs.h> +#include <linux/mfd/syscon.h> +#include <linux/regmap.h> #define SYSC_RSTSTAT 0x38 #define WDT_RST_CAUSE BIT(1) @@ -34,6 +34,7 @@ struct mt7621_wdt_data { void __iomem *base; struct reset_control *rst; + struct regmap *sysc; struct watchdog_device wdt; }; @@ -104,9 +105,12 @@ static int mt7621_wdt_stop(struct watchdog_device *w) return 0; } -static int mt7621_wdt_bootcause(void) +static int mt7621_wdt_bootcause(struct mt7621_wdt_data *d) { - if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE) + u32 val; + + regmap_read(d->sysc, SYSC_RSTSTAT, &val); + if (val & WDT_RST_CAUSE) return WDIOF_CARDRESET; return 0; @@ -143,6 +147,10 @@ static int mt7621_wdt_probe(struct platform_device *pdev) if (!drvdata) return -ENOMEM; + drvdata->sysc = syscon_regmap_lookup_by_compatible("mediatek,mt7621-sysc"); + if (IS_ERR(drvdata->sysc)) + return PTR_ERR(drvdata->sysc); + drvdata->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(drvdata->base)) return PTR_ERR(drvdata->base); @@ -158,7 +166,7 @@ static int mt7621_wdt_probe(struct platform_device *pdev) mt7621_wdt->max_timeout = 0xfffful / 1000; mt7621_wdt->parent = dev; - mt7621_wdt->bootstatus = mt7621_wdt_bootcause(); + mt7621_wdt->bootstatus = mt7621_wdt_bootcause(drvdata); watchdog_init_timeout(mt7621_wdt, mt7621_wdt->max_timeout, dev); watchdog_set_nowayout(mt7621_wdt, nowayout);