From patchwork Tue Mar 14 15:29:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 664990 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D588FC6FD1D for ; Tue, 14 Mar 2023 15:30:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231782AbjCNPav (ORCPT ); Tue, 14 Mar 2023 11:30:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231796AbjCNPa2 (ORCPT ); Tue, 14 Mar 2023 11:30:28 -0400 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E866B0BAB for ; Tue, 14 Mar 2023 08:29:32 -0700 (PDT) Received: by mail-qv1-xf2c.google.com with SMTP id o3so11550040qvr.1 for ; Tue, 14 Mar 2023 08:29:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678807770; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EYq3TK0piMvSdh8u6sbDbIfAAHTlrs55q/Bi+N/T6Tg=; b=RgHdUsz/OuJnP7rs4HBCE76HsrbfCtwP02LkIhQFNyZVAV6FJMn/Aw1XU0EmwpcH+E e/up7EbKCrZX8T+BDLhrdm7rY+KzWT5F6DBDCkneU/sJDT5TJWqf8EtPMPngHbOHsZPX fz4TkrCiz95UBzxA0r0ZTfX16pKvwgNHMrCztb9nMH0bY/t+aqWDeK+komMC7agDgLFp wa/4laXM+fSvJx44RNEuyeTeIyMoWaRHGGJkWP+0tvmcH5iXHKpgUcsQU8eAK58us/AB O4QJvvWPDDp09KVyKVaZtz3YvHOax0KZ672Ji8fT+e/ZGKZSpBOtH1YDf9NM0XlEqwLd PLHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678807770; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EYq3TK0piMvSdh8u6sbDbIfAAHTlrs55q/Bi+N/T6Tg=; b=7rOczgBVdAMELcHZtSCMsnpNVvDR5B3xcehQB0MSZsHQ0HQjuJYf2BRCV6esFXOVdu e7n6epgl05SvCAMMxAM41C9ly11gg++fsJVje4vk0Z5AChsVXCD1dkq/cOm/Gp0eyceb EA0eMnDVjCtwumILKmFWYTOx2ZV0/hp0zCD07GmA7NqLI28h6iKZOi13JCg6+z8B6Vzj tfybU/NXmCYrg/CKGOx3SDZDWCFCDW99+O0Lgh5+0e3TnbO2UPRkv7mG8BY9K3jexMd/ X09jB/9/XRpLcxs18QR9AjuXII2f97K4wKWcNuPGA/uvxp6x5NfIHYJ4Wk/YnxS1zTag 680A== X-Gm-Message-State: AO0yUKXELFqvb+wVoyys7Jj3nxh7hFzW1XlZihnID6EfOiM5Xp2DlwT8 ZvCIW2HSp+P8byN2xrjLLUQ4Hon7LOtatK2RWUI= X-Google-Smtp-Source: AK7set81ScLnrbEkyRYwaXDPBwCS3RapglOjf27ds8NmKZXYB0lmC1J+FD2pL0r1mYR8Kyan7kpuAg== X-Received: by 2002:a05:6214:2421:b0:5a3:2814:59c with SMTP id gy1-20020a056214242100b005a32814059cmr19185470qvb.51.1678807770481; Tue, 14 Mar 2023 08:29:30 -0700 (PDT) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id 207-20020a3704d8000000b0074575572030sm1985474qke.1.2023.03.14.08.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 08:29:30 -0700 (PDT) From: William Breathitt Gray To: Wim Van Sebroeck , Guenter Roeck Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Demetrotion , techsupport@winsystems.com, William Breathitt Gray , Andy Shevchenko Subject: [PATCH v2] watchdog: ebc-c384_wdt: Migrate to the regmap API Date: Tue, 14 Mar 2023 11:29:16 -0400 Message-Id: <20230314152916.185939-1-william.gray@linaro.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org The regmap API supports IO port accessors so we can take advantage of regmap abstractions rather than handling access to the device registers directly in the driver. Suggested-by: Andy Shevchenko Signed-off-by: William Breathitt Gray --- Changes in v2: - Utilize watchdog_set_drvdata() and watchdog_get_drvdata() - Map watchdog control registers based on offset 0x1 and adjust regmap configurations accordingly; offset 0x0 is unused in this driver so we should avoid unnecessary exposure of it drivers/watchdog/Kconfig | 1 + drivers/watchdog/ebc-c384_wdt.c | 67 +++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 19 deletions(-) base-commit: fe15c26ee26efa11741a7b632e9f23b01aca4cc6 diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index f0872970daf9..301cfe79263c 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -1089,6 +1089,7 @@ config EBC_C384_WDT tristate "WinSystems EBC-C384 Watchdog Timer" depends on X86 select ISA_BUS_API + select REGMAP_MMIO select WATCHDOG_CORE help Enables watchdog timer support for the watchdog timer on the diff --git a/drivers/watchdog/ebc-c384_wdt.c b/drivers/watchdog/ebc-c384_wdt.c index 8ef4b0df3855..2f9fec5073b3 100644 --- a/drivers/watchdog/ebc-c384_wdt.c +++ b/drivers/watchdog/ebc-c384_wdt.c @@ -3,15 +3,15 @@ * Watchdog timer driver for the WinSystems EBC-C384 * Copyright (C) 2016 William Breathitt Gray */ +#include #include #include -#include -#include -#include +#include #include #include #include #include +#include #include #include @@ -24,8 +24,14 @@ #define WATCHDOG_MAX_TIMEOUT 15300 #define BASE_ADDR 0x564 #define ADDR_EXTENT 5 -#define CFG_ADDR (BASE_ADDR + 1) -#define PET_ADDR (BASE_ADDR + 2) +#define CTRL_BASE_ADDR (BASE_ADDR + 0x1) +#define CTRL_ADDR_EXTENT 2 +#define CTRL_MAX_REGISTER (CTRL_ADDR_EXTENT - 1) +#define CFG_REG 0x0 +#define PET_REG 0x1 +#define CFG_MINUTES 0x00 +#define CFG_SECONDS BIT(7) +#define PET_DISABLED 0x00 static bool nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, bool, 0); @@ -37,43 +43,54 @@ module_param(timeout, uint, 0); MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); +static const struct regmap_range ebc_c384_wdt_wr_ranges[] = { + regmap_reg_range(0x0, 0x1), +}; +static const struct regmap_access_table ebc_c384_wdt_wr_table = { + .yes_ranges = ebc_c384_wdt_wr_ranges, + .n_yes_ranges = ARRAY_SIZE(ebc_c384_wdt_wr_ranges), +}; +static const struct regmap_config ebc_c384_wdt_regmap_config = { + .reg_bits = 8, + .reg_stride = 1, + .val_bits = 8, + .io_port = true, + .max_register = CTRL_MAX_REGISTER, + .wr_table = &ebc_c384_wdt_wr_table, +}; + static int ebc_c384_wdt_start(struct watchdog_device *wdev) { + struct regmap *const map = watchdog_get_drvdata(wdev); unsigned t = wdev->timeout; /* resolution is in minutes for timeouts greater than 255 seconds */ if (t > 255) t = DIV_ROUND_UP(t, 60); - outb(t, PET_ADDR); - - return 0; + return regmap_write(map, PET_REG, t); } static int ebc_c384_wdt_stop(struct watchdog_device *wdev) { - outb(0x00, PET_ADDR); + struct regmap *const map = watchdog_get_drvdata(wdev); - return 0; + return regmap_write(map, PET_REG, PET_DISABLED); } static int ebc_c384_wdt_set_timeout(struct watchdog_device *wdev, unsigned t) { + struct regmap *const map = watchdog_get_drvdata(wdev); + /* resolution is in minutes for timeouts greater than 255 seconds */ if (t > 255) { /* round second resolution up to minute granularity */ wdev->timeout = roundup(t, 60); - - /* set watchdog timer for minutes */ - outb(0x00, CFG_ADDR); - } else { - wdev->timeout = t; - - /* set watchdog timer for seconds */ - outb(0x80, CFG_ADDR); + return regmap_write(map, CFG_REG, CFG_MINUTES); } - return 0; + wdev->timeout = t; + return regmap_write(map, CFG_REG, CFG_SECONDS); } static const struct watchdog_ops ebc_c384_wdt_ops = { @@ -89,6 +106,8 @@ static const struct watchdog_info ebc_c384_wdt_info = { static int ebc_c384_wdt_probe(struct device *dev, unsigned int id) { + void __iomem *regs; + struct regmap *map; struct watchdog_device *wdd; if (!devm_request_region(dev, BASE_ADDR, ADDR_EXTENT, dev_name(dev))) { @@ -97,6 +116,15 @@ static int ebc_c384_wdt_probe(struct device *dev, unsigned int id) return -EBUSY; } + regs = devm_ioport_map(dev, CTRL_BASE_ADDR, CTRL_ADDR_EXTENT); + if (!regs) + return -ENOMEM; + + map = devm_regmap_init_mmio(dev, regs, &ebc_c384_wdt_regmap_config); + if (IS_ERR(map)) + return dev_err_probe(dev, PTR_ERR(map), + "Unable to initialize register map\n"); + wdd = devm_kzalloc(dev, sizeof(*wdd), GFP_KERNEL); if (!wdd) return -ENOMEM; @@ -107,6 +135,7 @@ static int ebc_c384_wdt_probe(struct device *dev, unsigned int id) wdd->min_timeout = 1; wdd->max_timeout = WATCHDOG_MAX_TIMEOUT; + watchdog_set_drvdata(wdd, map); watchdog_set_nowayout(wdd, nowayout); watchdog_init_timeout(wdd, timeout, dev);