From patchwork Wed Oct 27 21:55:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12588837 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B95F8C433F5 for ; Wed, 27 Oct 2021 21:57:34 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 85C0E61039 for ; Wed, 27 Oct 2021 21:57:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 85C0E61039 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=LPWIsCM8MtbskC2dLFUVrhb5Fdv4J8I4xlstm0TDW20=; b=fZHn3rwjiP2nAr oCOO2zPjNYQ28PG6zyRbaM54GJcQ8Xg6rJOCY8giMKbvyo704RkYIdQrkzUTHPm2tTHWdPLsBePP1 BBpjwqN5YmSkzYEiHNM/cWizsKBB7O5bM+jPJte6fWFs5bnok6LWJU2S71VYs6WSSMreAz/Q3zD5J yypJifS2M99bXmCEX06JRxKEH9XZpw6uw8P1yaIQwyq3jtTTJCIt+T49uqp1Cz+8wHYP8pYq3Bh2N Uepq4oS0SNsv7IkNwEHL9ZRhsQBCK7oTEttwgdTVIzVU3JgBJ5E3FjLKeJnVlzRcKVk9W34FfbbNc u4OvlsAxhsmbGYdqK4hQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfquD-006LBe-G0; Wed, 27 Oct 2021 21:56:21 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfqtv-006L93-69 for linux-arm-kernel@lists.infradead.org; Wed, 27 Oct 2021 21:56:04 +0000 Received: by mail-lf1-x134.google.com with SMTP id bq11so9122295lfb.10 for ; Wed, 27 Oct 2021 14:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z2xk/yYNwT3cyP5MTokWZ18/2f0cF6Zs0eQ+JbtiC/I=; b=li32teQrKORxlW9POadHjR1uJqr331VYCWUBVkouYkgb/gTh7wQByxOMMcep/vbhkK 0o5ZGnkxNVA2GfjYuDon9aXxHfMOP2NavJ4ouOYOgqWgKwAyylNfBUAJRxmU533fAkKS 6io8VRbM7bRQTqoPG+nQplze9ybUSWnTVkr5ws36RIJD/16oTgKs4/h/YbXLlR0tuh1p p/cGxvEnNIvMgVdPkneTeWX6SUvdV9+c2nmLwK9Ox4C/twy76SSX2n6EpebHNYY22u/5 sueQliVytPZFEmsmdMXRqmJ2OWsvl8zqixsLLateH1VmMus5XVpo4meqQVj4w+by8DTd grVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z2xk/yYNwT3cyP5MTokWZ18/2f0cF6Zs0eQ+JbtiC/I=; b=sd3xhteGesvTOhVL6Xz8Hygm74MhHgVUEHPpxbe9FHvSWhm9QGKuRvvA3MTV3/ck8C 4qg2OdG6BuBnN83/AP8RI6kcSMiZ1Krk4Q8RyMGXrOX93pcOWweXsXQGFRPi6Vx+4vkJ mLViplWpz7BC38iJma526KJQbnSqV49m48HhGAKpDPyU17HnfjCqddnDPaPfJgiP1sgR 4PuYGF7I3qeVVY3gzbyZUZUSRBCD2XaJg+iyESaCD22Ejn2ArIQxHC5NUjK4pgVc1rH3 /Hb1u/XYb0xTFnX+f1Mx8V5rdkPkG90r5p8cJiywMNZ1YKEicfUOMlzpkWmKHlrgY+5u lxbA== X-Gm-Message-State: AOAM533WSafh0uR/ROmouXfhbMte05fsow9mVTt3rnzwpNlWJAH3kmZt eqg0JKoXZeYyKyX/qlNcDJU= X-Google-Smtp-Source: ABdhPJz93GVAocPdfrC1yAGHhyWtbF9sRWj1ADWKSAN8YjwzsdbMb4XCM5PdPO8OmuFHdaeVe3G+Zg== X-Received: by 2002:ac2:4543:: with SMTP id j3mr238380lfm.391.1635371761841; Wed, 27 Oct 2021 14:56:01 -0700 (PDT) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id g35sm110207lfv.248.2021.10.27.14.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 14:56:01 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Wim Van Sebroeck , Guenter Roeck , Rob Herring Cc: Florian Fainelli , Thomas Bogendoerfer , bcm-kernel-feedback-list@broadcom.com, linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-mips@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH 3/3] watchdog: bcm63xx_wdt: support BCM4908 Date: Wed, 27 Oct 2021 23:55:31 +0200 Message-Id: <20211027215531.9996-3-zajec5@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211027215531.9996-1-zajec5@gmail.com> References: <20211027215531.9996-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211027_145603_261180_A95063F8 X-CRM114-Status: GOOD ( 24.45 ) 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 From: Rafał Miłecki So far bcm63xx_wdt included support for Broadcom's watchdog block of old MIPS devices only. It was also a fully platform (non-DT) driver. The same block was recently found on BCM4908 with just a slightly different registers layout. Extend this driver to support OF and add support for per-chipset registers offsets. Signed-off-by: Rafał Miłecki --- drivers/watchdog/Kconfig | 2 +- drivers/watchdog/bcm63xx_wdt.c | 63 ++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 913cde027e92..58a2474cd929 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -1711,7 +1711,7 @@ config OCTEON_WDT config BCM63XX_WDT tristate "Broadcom BCM63xx hardware watchdog" - depends on BCM63XX || COMPILE_TEST + depends on ARCH_BCM4908 || BCM63XX || COMPILE_TEST help Watchdog driver for the built in watchdog hardware in Broadcom BCM63xx SoC. diff --git a/drivers/watchdog/bcm63xx_wdt.c b/drivers/watchdog/bcm63xx_wdt.c index 1334e7fe77d8..df3c7dfea00f 100644 --- a/drivers/watchdog/bcm63xx_wdt.c +++ b/drivers/watchdog/bcm63xx_wdt.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -39,7 +40,13 @@ #define WDT_DEFAULT_TIME 30 /* seconds */ #define WDT_MAX_TIME 256 /* seconds */ +enum bcm63xx_wdt_soc { + BCM63XX_WDT_SOC_BCM4908, + BCM63XX_WDT_SOC_BCM63XX, +}; + static struct { + enum bcm63xx_wdt_soc soc; void __iomem *regs; struct timer_list timer; unsigned long inuse; @@ -54,11 +61,41 @@ module_param(nowayout, bool, 0); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); -static void bcm63xx_wdt_write_reg(u32 reg, u32 val) +static const struct of_device_id bcm63xx_wdt_id_table[] = { + { .compatible = "brcm,bcm4908-wdt", .data = (const void *)BCM63XX_WDT_SOC_BCM4908, }, + {}, +}; + +enum bcm63xx_wdt_regs { + BCM63XX_WDT_REG_DEFVAL = 0, + BCM63XX_WDT_REG_CTL, + BCM63XX_WDT_REG_SOFTRESET, +}; + +static const u16 bcm63xx_wdt_regs_bcm4908[] = { + [BCM63XX_WDT_REG_DEFVAL] = 0x28, + [BCM63XX_WDT_REG_CTL] = 0x2c, + [BCM63XX_WDT_REG_SOFTRESET] = 0x34, +}; + +static const u16 bcm63xx_wdt_regs_bcm63xx[] = { + [BCM63XX_WDT_REG_DEFVAL] = WDT_DEFVAL_REG, + [BCM63XX_WDT_REG_CTL] = WDT_CTL_REG, +}; + +static void bcm63xx_wdt_write_reg(enum bcm63xx_wdt_regs reg, u32 val) { void __iomem *addr = bcm63xx_wdt_device.regs; - addr += reg; + switch (bcm63xx_wdt_device.soc) { + case BCM63XX_WDT_SOC_BCM4908: + addr += bcm63xx_wdt_regs_bcm4908[reg]; + break; + case BCM63XX_WDT_SOC_BCM63XX: + addr += bcm63xx_wdt_regs_bcm63xx[reg]; + break; + } + #ifdef BCM63XX bcm_writel(val, addr); #else @@ -69,15 +106,15 @@ static void bcm63xx_wdt_write_reg(u32 reg, u32 val) /* HW functions */ static void bcm63xx_wdt_hw_start(void) { - bcm63xx_wdt_write_reg(WDT_DEFVAL_REG, 0xfffffffe); - bcm63xx_wdt_write_reg(WDT_CTL_REG, WDT_START_1); - bcm63xx_wdt_write_reg(WDT_CTL_REG, WDT_START_2); + bcm63xx_wdt_write_reg(BCM63XX_WDT_REG_DEFVAL, 0xfffffffe); + bcm63xx_wdt_write_reg(BCM63XX_WDT_REG_CTL, WDT_START_1); + bcm63xx_wdt_write_reg(BCM63XX_WDT_REG_CTL, WDT_START_2); } static void bcm63xx_wdt_hw_stop(void) { - bcm63xx_wdt_write_reg(WDT_CTL_REG, WDT_STOP_1); - bcm63xx_wdt_write_reg(WDT_CTL_REG, WDT_STOP_2); + bcm63xx_wdt_write_reg(BCM63XX_WDT_REG_CTL, WDT_STOP_1); + bcm63xx_wdt_write_reg(BCM63XX_WDT_REG_CTL, WDT_STOP_2); } #ifdef BCM63XX @@ -252,9 +289,19 @@ static struct miscdevice bcm63xx_wdt_miscdev = { static int bcm63xx_wdt_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; + const struct of_device_id *of_id; int ret; struct resource *r; + of_id = of_match_device(bcm63xx_wdt_id_table, dev); + if (of_id) { + bcm63xx_wdt_device.soc = (enum bcm63xx_wdt_soc)of_id->data; + } else { + /* Fallback */ + bcm63xx_wdt_device.soc = BCM63XX_WDT_SOC_BCM63XX; + } + timer_setup(&bcm63xx_wdt_device.timer, bcm63xx_timer_tick, 0); r = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -326,6 +373,7 @@ static struct platform_driver bcm63xx_wdt_driver = { .shutdown = bcm63xx_wdt_shutdown, .driver = { .name = "bcm63xx-wdt", + .of_match_table = bcm63xx_wdt_id_table, } }; @@ -333,6 +381,7 @@ module_platform_driver(bcm63xx_wdt_driver); MODULE_AUTHOR("Miguel Gaio "); MODULE_AUTHOR("Florian Fainelli "); +MODULE_DEVICE_TABLE(of, bcm63xx_wdt_id_table); MODULE_DESCRIPTION("Driver for the Broadcom BCM63xx SoC watchdog"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:bcm63xx-wdt");