From patchwork Sun Jan 30 19:12:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terry Bowman X-Patchwork-Id: 538595 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 59EC0C433FE for ; Sun, 30 Jan 2022 19:12:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355675AbiA3TMy (ORCPT ); Sun, 30 Jan 2022 14:12:54 -0500 Received: from mail-dm6nam10on2049.outbound.protection.outlook.com ([40.107.93.49]:30540 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1355834AbiA3TMp (ORCPT ); Sun, 30 Jan 2022 14:12:45 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MV+baaTNmrLvBAPvIgaMDYU7rCDl931bbmQrxlFOyuZWQb2KwDjSE0NygOfObRp/sMk+qAJQz7nKnTDRm61yqdUhEov43QzSM4wI++mzP2hpu2/eOHmVTCsOKUwLuQsutYWsOljcfBCrcdw0BymVKsslwVu2I5l8qsaMJ0fSBOLb27Vr/Z8q6+vHi2ppgxyAtLEdW5IJJadrcdeDLDzWdZGLFF3VJ8IDNowexLLQjgauntvr1QOASOcT/M2YEAbfs24FjnKpWyVM2jmZu2rRAJt/QJqhYz/N0gD+1Y5PcHev9Lew+74/YE5rxyTk5pOZECMFg6KfpgJtxe4KbYsJLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=e5fQV3G+KAPhyTJUpb2BuUgBzXO8OTaQ5aaB0Jis1Mk=; b=imT4YZ3nM8yyne1t+ayzHw1DA8V669J0Yl265OncDMgSow8p2BsNYNAWRgpHrljliHcMc/oSZx/lORtHFAgiQYiw/zAkkVO2udNRuZds06dwCXyR0csSx/P3RE/Z5DPLjKut1pzSS273O41Cy5w3PROt3tgU41rXDac6Tu+ZzDTUaKJpjlfbq2PIwOQAHz1Ni+B+9MFvaWjvrEdcImUiKzWrLkxOKMZUXfIGwtoYgDkvP6NyVR9lPdNOjlxZpAQkbOQhaNgJJT4OV9DST4p86AIgLikEiLAglOYfTXEBxJ2GD3ofUjOGKOvSaVYL9NtqopAXPXzAjHFv6TO4YXvW9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=roeck-us.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=e5fQV3G+KAPhyTJUpb2BuUgBzXO8OTaQ5aaB0Jis1Mk=; b=BihDOv0yTvwwPkrFyANgjDXZ5BDXg4e/BWE6+HDXfujQwqh/nLydB2Q0xfrkBzsoyjEBBHIJKi0jUHqdvDi85yYiJJFj0JNdUp/Gud+CU35CcHiRivUXc5BfRd4IWV4vparMYmuUgjtX0bFG0EAY3amOz1e1RNtWAFNm+SEAxn4= Received: from DM6PR21CA0007.namprd21.prod.outlook.com (2603:10b6:5:174::17) by BY5PR12MB4323.namprd12.prod.outlook.com (2603:10b6:a03:211::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Sun, 30 Jan 2022 19:12:43 +0000 Received: from DM6NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:5:174:cafe::3c) by DM6PR21CA0007.outlook.office365.com (2603:10b6:5:174::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.3 via Frontend Transport; Sun, 30 Jan 2022 19:12:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT055.mail.protection.outlook.com (10.13.173.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Sun, 30 Jan 2022 19:12:42 +0000 Received: from ethanolx7ea3host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Sun, 30 Jan 2022 13:12:41 -0600 From: Terry Bowman To: , , , , , , , CC: , , , , , , , , Subject: [PATCH v4 1/4] Watchdog: sp5100_tco: Move timer initialization into function Date: Sun, 30 Jan 2022 13:12:22 -0600 Message-ID: <20220130191225.303115-2-terry.bowman@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220130191225.303115-1-terry.bowman@amd.com> References: <20220130191225.303115-1-terry.bowman@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 63dc721d-9ab9-4a84-53fd-08d9e4247dc8 X-MS-TrafficTypeDiagnostic: BY5PR12MB4323:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:962; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: da0mx0yuYC8b8s0IHhU6yaKuSxE3nqQjVj9SGFxRkwkZXInlgAaB2ktBbVPEXNpUTJo3Ji2Fot6MrK9Nz5/nHaVpTx7UTxYrCsf5F8uklGqkoNSfkB16PgGIROxtQonnR0tMSo/ZzfuxRtLQpSt4qh8JIgHcp+peTi9//KeokB+cDIDHKtNrlGNE+1c50SkOVaGFzOZJuZi4eb4AQ+XIP95J43disWC13IheE+AjDLp5kX1nrSfRlJFl8YwH0A5ZBPXZOXhaT+R4CNM3s3SSyJFzA+lTndSa2dXSE86zov9YmnBp6z62JVzV8LJrWLNoMG37u2MMVvNgNGdmt2PROF+LkTACVT+VDY+SsXXF+i4r+EN+vFFWtppxSTAnxx0RU7bkiVlxMYGv+0G79uIbr2d3wW14V8BuC61pQSFw1f1lt/1peFF7HCWtwqPVJCxBcStJIsmbmLUqze3QlL9Iy2h6axfsSCrXD3LpnAtKq90f7dPLhr5k+bkV/cUnb3zFqThK/Dw6JILyMrqKVK2tsg46PPMwRb6mOYDNO5BNxNcfbi8CqhVWOamHjBOxFC5Fk9/tiydho+Sijeh1fiTU9Gn/IZO4W4PS77x4PzSM8KkYMevQ4ke1vD7JUyklJimIqnSHMucE63OhSyMqIybczryddu1LVGLWF9GQLrYvhs2COIR23UX61gwSizvI06d9ODfR34miR40eWf51EguoZjyBMuaZrj3ORx1FVKUhpaQ= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(2616005)(40460700003)(1076003)(336012)(426003)(186003)(16526019)(86362001)(26005)(82310400004)(47076005)(83380400001)(5660300002)(44832011)(70586007)(70206006)(36756003)(36860700001)(356005)(81166007)(8936002)(8676002)(508600001)(2906002)(6666004)(7696005)(54906003)(110136005)(316002)(4326008)(2101003)(36900700001)(20210929001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2022 19:12:42.8778 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63dc721d-9ab9-4a84-53fd-08d9e4247dc8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4323 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Refactor driver's timer initialization into new function. This is needed inorder to support adding new device layouts while using common timer initialization. Co-developed-by: Robert Richter Signed-off-by: Robert Richter Signed-off-by: Terry Bowman Tested-by: Jean Delvare Reviewed-by: Jean Delvare --- drivers/watchdog/sp5100_tco.c | 65 +++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c index dd9a744f82f8..b365bbc9ac36 100644 --- a/drivers/watchdog/sp5100_tco.c +++ b/drivers/watchdog/sp5100_tco.c @@ -223,6 +223,41 @@ static u32 sp5100_tco_read_pm_reg32(u8 index) return val; } +static int sp5100_tco_timer_init(struct sp5100_tco *tco) +{ + struct watchdog_device *wdd = &tco->wdd; + struct device *dev = wdd->parent; + u32 val; + + val = readl(SP5100_WDT_CONTROL(tco->tcobase)); + if (val & SP5100_WDT_DISABLED) { + dev_err(dev, "Watchdog hardware is disabled\n"); + return -ENODEV; + } + + /* + * Save WatchDogFired status, because WatchDogFired flag is + * cleared here. + */ + if (val & SP5100_WDT_FIRED) + wdd->bootstatus = WDIOF_CARDRESET; + + /* Set watchdog action to reset the system */ + val &= ~SP5100_WDT_ACTION_RESET; + writel(val, SP5100_WDT_CONTROL(tco->tcobase)); + + /* Set a reasonable heartbeat before we stop the timer */ + tco_timer_set_timeout(wdd, wdd->timeout); + + /* + * Stop the TCO before we change anything so we don't race with + * a zeroed timer. + */ + tco_timer_stop(wdd); + + return 0; +} + static int sp5100_tco_setupdevice(struct device *dev, struct watchdog_device *wdd) { @@ -348,35 +383,7 @@ static int sp5100_tco_setupdevice(struct device *dev, /* Setup the watchdog timer */ tco_timer_enable(tco); - val = readl(SP5100_WDT_CONTROL(tco->tcobase)); - if (val & SP5100_WDT_DISABLED) { - dev_err(dev, "Watchdog hardware is disabled\n"); - ret = -ENODEV; - goto unreg_region; - } - - /* - * Save WatchDogFired status, because WatchDogFired flag is - * cleared here. - */ - if (val & SP5100_WDT_FIRED) - wdd->bootstatus = WDIOF_CARDRESET; - /* Set watchdog action to reset the system */ - val &= ~SP5100_WDT_ACTION_RESET; - writel(val, SP5100_WDT_CONTROL(tco->tcobase)); - - /* Set a reasonable heartbeat before we stop the timer */ - tco_timer_set_timeout(wdd, wdd->timeout); - - /* - * Stop the TCO before we change anything so we don't race with - * a zeroed timer. - */ - tco_timer_stop(wdd); - - release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE); - - return 0; + ret = sp5100_tco_timer_init(tco); unreg_region: release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE); From patchwork Sun Jan 30 19:12:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terry Bowman X-Patchwork-Id: 538335 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 93155C433EF for ; Sun, 30 Jan 2022 19:12:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355811AbiA3TM6 (ORCPT ); Sun, 30 Jan 2022 14:12:58 -0500 Received: from mail-dm6nam11on2082.outbound.protection.outlook.com ([40.107.223.82]:28385 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1355804AbiA3TM5 (ORCPT ); Sun, 30 Jan 2022 14:12:57 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z+Mvmk13sbC+7Y9e8Grb9Dyj3jdePphbTYUZvDQAcaYOKS8/2LSGM26s+vTVfG1CZ3aoRi1q/4wbyEFFXmPBaFrks8xgw4XKFNZnVlvI/BNjZaqCQK06GWwQm+/JZfb/DlaW7p81czclhdhRUWjOIszcx5y5W4PXOciWpSXMDn1aGsPKXR7tdvukcpyD9gyRVw+V4wGCkK6iXTSLtPQHzZjWkU3ZlBgpLG6y9dj/gmyxtwUZHU4tFzxZvh43qIADyKY040jEROeffPLFafYv+uHffRDDBkYeRjYPjtdq6CFk9tkYBlo7ODJNeB28bJk9UJprB55f2+NO7pdRPS4/nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=K+zMAenqjkC48pyQNzWi49C58B3/DS110h62PQY3EuM=; b=g2wUMyt9+ZH3WZNtS5mjUOS3QASXZlH00kcN8OkKyEniz92GGOmm5iU5Sos2YxhPWMvGTvqvTKXg9cv/i/31o8vkecE1RI+ZnLiOFPxKx8wnRRF/Fm6xs4Fj/7t+erXv/8miQeu1AZdNQN30TRKrRKdi2BvAV+TZxnsLKvfD2AfXKc9QTy+z5nf8oaYNutBBrpieG7NBB71RNLeMLzHYypqrdHmrIPbyAcr0vyaF7gwk8Ew/DXwqNTJTMtVgXFSQw3wcHfnhE3uRzRDKKeHzBDmhjvxlAqOK1Nh3i364b4+3KVVnSHSkgoOtImiKKRwHjq9apkoiDAsPxSGqtazybg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=roeck-us.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=K+zMAenqjkC48pyQNzWi49C58B3/DS110h62PQY3EuM=; b=MeuP8+E5AxpNzI+lBggVylpuzPk6g0mQeKc1f6INld5cQTeKjGb1Oh2+Ef6UmO8c9lA9Rw7zLN58RnWdB3T0dh8A7F0OQqskx4stULt+sYShjYvVNUkiRXSZjrRNDVbSOxxdi46ORB7Yu43L56cECZeX7Dx2BIWkZl3Y3mb0mAg= Received: from DM5PR18CA0058.namprd18.prod.outlook.com (2603:10b6:3:22::20) by MN2PR12MB4079.namprd12.prod.outlook.com (2603:10b6:208:1d5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17; Sun, 30 Jan 2022 19:12:54 +0000 Received: from DM6NAM11FT023.eop-nam11.prod.protection.outlook.com (2603:10b6:3:22:cafe::a3) by DM5PR18CA0058.outlook.office365.com (2603:10b6:3:22::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.21 via Frontend Transport; Sun, 30 Jan 2022 19:12:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT023.mail.protection.outlook.com (10.13.173.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Sun, 30 Jan 2022 19:12:53 +0000 Received: from ethanolx7ea3host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Sun, 30 Jan 2022 13:12:52 -0600 From: Terry Bowman To: , , , , , , , CC: , , , , , , , , Subject: [PATCH v4 2/4] Watchdog: sp5100_tco: Refactor MMIO base address initialization Date: Sun, 30 Jan 2022 13:12:23 -0600 Message-ID: <20220130191225.303115-3-terry.bowman@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220130191225.303115-1-terry.bowman@amd.com> References: <20220130191225.303115-1-terry.bowman@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 675fcf2e-208e-4654-6a40-08d9e4248450 X-MS-TrafficTypeDiagnostic: MN2PR12MB4079:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RGzRUcLgT1ApzUdRBmiyJv20ZR0l8qjv1g6iHHMBYWn1WBFHLeC8WVSHRM/Q959PSFQ0TnA4BHrz98DYRRXe/nRJrna2hBXP66Aww2FlFL96VjqmUW1K4rEDWi2rWnSJDhNT8nns1y1AEuEw7IQ9gra/IKDjFnVDjXbk+SHCPf6XiohFeHrACdKycPwLeoyr4cs5fVjLLaxATdwQyFINOX2w8mYZCUpzOc/VBLwyvmftcqQ8b9KRHVQ5J+TLJ4wJeAUqIpNQA757CuvG8gFoTc8e0S3pAZd7kZ5aPhBbHqi1wu3zLQWQfzEA+bPxSZ0qk6LSc1vfiKpbN51JwRMfCPp0e4+IJ6UnSdhEveunpZp2vAV+97NhtfuvlQGHXsOtawI/t4npQtfByviVd8gYmMh6+OsVbMBXALLuRzjjhrMT2FwEQ5EShW5q7Go6Wrl2PN6Gh2VazphMqatLYKjKANzubF8CcGpHePCPWWgOUIPts0D/EIFu2I0oPivvzE3E3JA462qXQUIoaBXVOQgz0i23qeMs/lDgNOJOWU5nFxUXK+WM9qfZ0AsdF3Wvmi7Sf7vicVz6s3ArKUSk3ILu/frfgSM3l1JIcSSSDeUrIA4PkK7lKlvQ4gXzYJV7c4qAzZxd5lKLRpAyb2v999VSVA1mZibqxdgbP/HNdutu9zj7kq+uvVBxpM2KjKVG4by/p/H8fRYivlqiEGaY5JBp/x4JdsQIE1HBASGuhjDkmbg= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(7696005)(6666004)(186003)(26005)(86362001)(336012)(426003)(508600001)(1076003)(16526019)(2616005)(81166007)(82310400004)(356005)(83380400001)(4326008)(36860700001)(47076005)(5660300002)(8676002)(316002)(70206006)(70586007)(40460700003)(36756003)(2906002)(44832011)(54906003)(110136005)(8936002)(2101003)(36900700001)(20210929001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2022 19:12:53.8360 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 675fcf2e-208e-4654-6a40-08d9e4248450 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT023.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4079 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Combine MMIO base address and alternate base address detection. Combine based on layout type. This will simplify the function by eliminating a switch case. Move existing request/release code into functions. This currently only supports port I/O request/release. The move into a separate function will make it ready for adding MMIO region support. Co-developed-by: Robert Richter Signed-off-by: Robert Richter Signed-off-by: Terry Bowman Tested-by: Jean Delvare Reviewed-by: Jean Delvare Reported-by: kernel test robot Reported-by: kernel test robot --- drivers/watchdog/sp5100_tco.c | 155 ++++++++++++++++++---------------- drivers/watchdog/sp5100_tco.h | 1 + 2 files changed, 82 insertions(+), 74 deletions(-) diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c index b365bbc9ac36..16e122d5045e 100644 --- a/drivers/watchdog/sp5100_tco.c +++ b/drivers/watchdog/sp5100_tco.c @@ -223,6 +223,55 @@ static u32 sp5100_tco_read_pm_reg32(u8 index) return val; } +static u32 sp5100_tco_request_region(struct device *dev, + u32 mmio_addr, + const char *dev_name) +{ + if (!devm_request_mem_region(dev, mmio_addr, SP5100_WDT_MEM_MAP_SIZE, + dev_name)) { + dev_dbg(dev, "MMIO address 0x%08x already in use\n", mmio_addr); + return 0; + } + + return mmio_addr; +} + +static u32 sp5100_tco_prepare_base(struct sp5100_tco *tco, + u32 mmio_addr, + u32 alt_mmio_addr, + const char *dev_name) +{ + struct device *dev = tco->wdd.parent; + + dev_dbg(dev, "Got 0x%08x from SBResource_MMIO register\n", mmio_addr); + + if (!mmio_addr && !alt_mmio_addr) + return -ENODEV; + + /* Check for MMIO address and alternate MMIO address conflicts */ + if (mmio_addr) + mmio_addr = sp5100_tco_request_region(dev, mmio_addr, dev_name); + + if (!mmio_addr && alt_mmio_addr) + mmio_addr = sp5100_tco_request_region(dev, alt_mmio_addr, dev_name); + + if (!mmio_addr) { + dev_err(dev, "Failed to reserve MMIO or alternate MMIO region\n"); + return -EBUSY; + } + + tco->tcobase = devm_ioremap(dev, mmio_addr, SP5100_WDT_MEM_MAP_SIZE); + if (!tco->tcobase) { + dev_err(dev, "MMIO address 0x%08x failed mapping\n", mmio_addr); + devm_release_mem_region(dev, mmio_addr, SP5100_WDT_MEM_MAP_SIZE); + return -ENOMEM; + } + + dev_info(dev, "Using 0x%08x for watchdog MMIO address\n", tco->tcobase); + + return 0; +} + static int sp5100_tco_timer_init(struct sp5100_tco *tco) { struct watchdog_device *wdd = &tco->wdd; @@ -264,6 +313,7 @@ static int sp5100_tco_setupdevice(struct device *dev, struct sp5100_tco *tco = watchdog_get_drvdata(wdd); const char *dev_name; u32 mmio_addr = 0, val; + u32 alt_mmio_addr = 0; int ret; /* Request the IO ports used by this driver */ @@ -282,11 +332,32 @@ static int sp5100_tco_setupdevice(struct device *dev, dev_name = SP5100_DEVNAME; mmio_addr = sp5100_tco_read_pm_reg32(SP5100_PM_WATCHDOG_BASE) & 0xfffffff8; + + /* + * Secondly, find the watchdog timer MMIO address + * from SBResource_MMIO register. + */ + + /* Read SBResource_MMIO from PCI config(PCI_Reg: 9Ch) */ + pci_read_config_dword(sp5100_tco_pci, + SP5100_SB_RESOURCE_MMIO_BASE, + &val); + + /* Verify MMIO is enabled and using bar0 */ + if ((val & SB800_ACPI_MMIO_MASK) == SB800_ACPI_MMIO_DECODE_EN) + alt_mmio_addr = (val & ~0xfff) + SB800_PM_WDT_MMIO_OFFSET; break; case sb800: dev_name = SB800_DEVNAME; mmio_addr = sp5100_tco_read_pm_reg32(SB800_PM_WATCHDOG_BASE) & 0xfffffff8; + + /* Read SBResource_MMIO from AcpiMmioEn(PM_Reg: 24h) */ + val = sp5100_tco_read_pm_reg32(SB800_PM_ACPI_MMIO_EN); + + /* Verify MMIO is enabled and using bar0 */ + if ((val & SB800_ACPI_MMIO_MASK) == SB800_ACPI_MMIO_DECODE_EN) + alt_mmio_addr = (val & ~0xfff) + SB800_PM_WDT_MMIO_OFFSET; break; case efch: dev_name = SB800_DEVNAME; @@ -305,87 +376,23 @@ static int sp5100_tco_setupdevice(struct device *dev, val = sp5100_tco_read_pm_reg8(EFCH_PM_DECODEEN); if (val & EFCH_PM_DECODEEN_WDT_TMREN) mmio_addr = EFCH_PM_WDT_ADDR; + + val = sp5100_tco_read_pm_reg8(EFCH_PM_ISACONTROL); + if (val & EFCH_PM_ISACONTROL_MMIOEN) + alt_mmio_addr = EFCH_PM_ACPI_MMIO_ADDR + + EFCH_PM_ACPI_MMIO_WDT_OFFSET; break; default: return -ENODEV; } - /* Check MMIO address conflict */ - if (!mmio_addr || - !devm_request_mem_region(dev, mmio_addr, SP5100_WDT_MEM_MAP_SIZE, - dev_name)) { - if (mmio_addr) - dev_dbg(dev, "MMIO address 0x%08x already in use\n", - mmio_addr); - switch (tco->tco_reg_layout) { - case sp5100: - /* - * Secondly, Find the watchdog timer MMIO address - * from SBResource_MMIO register. - */ - /* Read SBResource_MMIO from PCI config(PCI_Reg: 9Ch) */ - pci_read_config_dword(sp5100_tco_pci, - SP5100_SB_RESOURCE_MMIO_BASE, - &mmio_addr); - if ((mmio_addr & (SB800_ACPI_MMIO_DECODE_EN | - SB800_ACPI_MMIO_SEL)) != - SB800_ACPI_MMIO_DECODE_EN) { - ret = -ENODEV; - goto unreg_region; - } - mmio_addr &= ~0xFFF; - mmio_addr += SB800_PM_WDT_MMIO_OFFSET; - break; - case sb800: - /* Read SBResource_MMIO from AcpiMmioEn(PM_Reg: 24h) */ - mmio_addr = - sp5100_tco_read_pm_reg32(SB800_PM_ACPI_MMIO_EN); - if ((mmio_addr & (SB800_ACPI_MMIO_DECODE_EN | - SB800_ACPI_MMIO_SEL)) != - SB800_ACPI_MMIO_DECODE_EN) { - ret = -ENODEV; - goto unreg_region; - } - mmio_addr &= ~0xFFF; - mmio_addr += SB800_PM_WDT_MMIO_OFFSET; - break; - case efch: - val = sp5100_tco_read_pm_reg8(EFCH_PM_ISACONTROL); - if (!(val & EFCH_PM_ISACONTROL_MMIOEN)) { - ret = -ENODEV; - goto unreg_region; - } - mmio_addr = EFCH_PM_ACPI_MMIO_ADDR + - EFCH_PM_ACPI_MMIO_WDT_OFFSET; - break; - } - dev_dbg(dev, "Got 0x%08x from SBResource_MMIO register\n", - mmio_addr); - if (!devm_request_mem_region(dev, mmio_addr, - SP5100_WDT_MEM_MAP_SIZE, - dev_name)) { - dev_dbg(dev, "MMIO address 0x%08x already in use\n", - mmio_addr); - ret = -EBUSY; - goto unreg_region; - } - } - - tco->tcobase = devm_ioremap(dev, mmio_addr, SP5100_WDT_MEM_MAP_SIZE); - if (!tco->tcobase) { - dev_err(dev, "failed to get tcobase address\n"); - ret = -ENOMEM; - goto unreg_region; + ret = sp5100_tco_prepare_base(tco, mmio_addr, alt_mmio_addr, dev_name); + if (!ret) { + /* Setup the watchdog timer */ + tco_timer_enable(tco); + ret = sp5100_tco_timer_init(tco); } - dev_info(dev, "Using 0x%08x for watchdog MMIO address\n", mmio_addr); - - /* Setup the watchdog timer */ - tco_timer_enable(tco); - - ret = sp5100_tco_timer_init(tco); - -unreg_region: release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE); return ret; } diff --git a/drivers/watchdog/sp5100_tco.h b/drivers/watchdog/sp5100_tco.h index adf015aa4126..daee872f9b71 100644 --- a/drivers/watchdog/sp5100_tco.h +++ b/drivers/watchdog/sp5100_tco.h @@ -58,6 +58,7 @@ #define SB800_PM_WATCHDOG_SECOND_RES GENMASK(1, 0) #define SB800_ACPI_MMIO_DECODE_EN BIT(0) #define SB800_ACPI_MMIO_SEL BIT(1) +#define SB800_ACPI_MMIO_MASK GENMASK(1, 0) #define SB800_PM_WDT_MMIO_OFFSET 0xB00 From patchwork Sun Jan 30 19:12:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terry Bowman X-Patchwork-Id: 538594 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 5B8C7C433FE for ; Sun, 30 Jan 2022 19:13:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355784AbiA3TNJ (ORCPT ); Sun, 30 Jan 2022 14:13:09 -0500 Received: from mail-bn7nam10on2076.outbound.protection.outlook.com ([40.107.92.76]:65280 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1355840AbiA3TNH (ORCPT ); Sun, 30 Jan 2022 14:13:07 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mdLQgoxhdvstIOjBhHqEWyeNMp3KE+LDtoa5xEPrZuJqK968zMo+JIBBpQDkAFT5zADJenUxiWiP2i+WplxqY0r/zFZQjqAI1MLasTaerS7nOPnBsmEajACPMYCc38bcaJPvLOzVDzypJTgXXPobV2s9NgeramDfOF6zi6jD5uqvd4MXpnlra2jrFlbInxUI8K7nXE1SqooMONTRZXbsGgjvyCgiFNhwt+ZCClQzgR8kouKfe0gKeWzeh5X/lTQ/7oznmFBwrRhgS5rknY6c3m/j3E9XRLYW9mlkOx+bZY+KbletI1uBPJtqUIZg0ZwCMKCroKrYgOFvsytMA5jBCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kSikiT7i8hdTWF+rz+8BkWA/ntkQytBCdgRwVWQfhos=; b=THoSKJXk8fq+pDKG8vreLD6X56x/h2Qyn+y6eMxIjut43lwFp5kJFHj59txddfxbzS+Bf7oovGfDIpPlqYJYhVj1GedRbYvJ0in81COopUd9GzqWNw3IfseH9rOSe2Lh4sMSGZJGRQlGS6KXyh2ykX7WUgkM5mGsGLS8j0YEz3b2e1VtkHm6p+MLnmnD+fafY6W0YWuPukS8YUMjCnruBnpROHbpPS2RikpFkqW56QqDCO2m/z0YPgTTBHHuPD/MhefrzmtVtcoei/Ah9GmATvHuPbmNhfIMh5WT1EJDC6pndFm9EESjG0w4pcjjBSq4UZigB1D5zhpAgWykEybsiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=roeck-us.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kSikiT7i8hdTWF+rz+8BkWA/ntkQytBCdgRwVWQfhos=; b=xehBz8+2E6vid/cc9gSkM6MgGTyjtPDrDx7tVi3U9/AR+zlmHQMWgd6KhgGfpuH9PorhuEjZTbR8AVAPyg55HrPr9PHFvheeTdCraBjHDOWUM4mpox61cD+KU9N08SNRDRAseeb444uYWKJIRpzEcbm6l2FSNQoarHJxga11yhE= Received: from DM6PR08CA0028.namprd08.prod.outlook.com (2603:10b6:5:80::41) by MN2PR12MB3904.namprd12.prod.outlook.com (2603:10b6:208:165::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17; Sun, 30 Jan 2022 19:13:05 +0000 Received: from DM6NAM11FT011.eop-nam11.prod.protection.outlook.com (2603:10b6:5:80:cafe::1) by DM6PR08CA0028.outlook.office365.com (2603:10b6:5:80::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.17 via Frontend Transport; Sun, 30 Jan 2022 19:13:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT011.mail.protection.outlook.com (10.13.172.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Sun, 30 Jan 2022 19:13:04 +0000 Received: from ethanolx7ea3host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Sun, 30 Jan 2022 13:13:03 -0600 From: Terry Bowman To: , , , , , , , CC: , , , , , , , , Subject: [PATCH v4 3/4] Watchdog: sp5100_tco: Add initialization using EFCH MMIO Date: Sun, 30 Jan 2022 13:12:24 -0600 Message-ID: <20220130191225.303115-4-terry.bowman@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220130191225.303115-1-terry.bowman@amd.com> References: <20220130191225.303115-1-terry.bowman@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c4964644-f2f6-4fd8-3972-08d9e4248ae4 X-MS-TrafficTypeDiagnostic: MN2PR12MB3904:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tpNd3xT93FGA4RF0UyZvq8KPwO5RRa1Ob89WGa5sWcLI40yPM1ProEW/Ifcuk8/pN2Alrhn0oO3vfjYGXGFa7qnn13nDukbGGlqAt5yfK4+qu4at+9Xj1nQLLOlbsfQlnHLsKxglZkb+B66JBreiZBrgmbT7DaJr52vSY6wbgW4HT932INVHfEFuKHg65qavRBITQ4UKnWdlbQkDRhNjX8iDK7juvryB0HnC1LgejOyf0pJhfU1aNgsdEf4Nx99PlF4dQOa6eSfvprdUd8tsaielhFonLi6B2GZAVefZK+Elp26StqLwl4pQ4Jx3k56SsWC+Q4nVhhx7z4+gp8pbZeIpsZSDo5v0ghAfYST97T2++SAqvmq0xca0LJN+fUPCrFFWcMf8MV16MMiKHpGaNeYoo2I75kEl9dqyLREPUGpoJ5mofIwSmjTJ3Olm+TnZ+rnLvPinztbIJmKDLrbOXYsFWFop5Ie6Dnz6B3blSUkD/W/u/726oY9pK9dUjZf0MfqqWEYTdWlC4TdZWEh7/xURnUZm5po+SHWBa7KyRREfAF3zpspd2dW3DtkF2y7ASG4+iFgee+vEbK+8FBmMzx0LlAn3r2lVaA3rt0a/ppVUsMzhijHNgLe2UAG2mSOUDMv6uUthO0mPqIg0ZNnJ2odV/cGQASfn8IUQ+Bqn7Hxs2VlIJQW+d3e8SarHJP7T516j/aUHAnfcgpTsst1yqTolnGzTkqK4UqbOfWiL2cQ= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(426003)(336012)(26005)(81166007)(2616005)(16526019)(356005)(44832011)(5660300002)(36756003)(2906002)(1076003)(186003)(47076005)(40460700003)(4326008)(8676002)(508600001)(70586007)(82310400004)(8936002)(70206006)(86362001)(36860700001)(7696005)(316002)(6666004)(83380400001)(54906003)(110136005)(2101003)(36900700001)(20210929001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2022 19:13:04.8710 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c4964644-f2f6-4fd8-3972-08d9e4248ae4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT011.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3904 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org cd6h/cd7h port I/O can be disabled on recent AMD hardware. Read accesses to disabled cd6h/cd7h port I/O will return F's and written data is dropped. It is recommended to replace the cd6h/cd7h port I/O with MMIO. Co-developed-by: Robert Richter Signed-off-by: Robert Richter Signed-off-by: Terry Bowman Tested-by: Jean Delvare Reviewed-by: Jean Delvare Reported-by: kernel test robot --- drivers/watchdog/sp5100_tco.c | 100 +++++++++++++++++++++++++++++++++- drivers/watchdog/sp5100_tco.h | 5 ++ 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c index 16e122d5045e..1a5e76d13c3c 100644 --- a/drivers/watchdog/sp5100_tco.c +++ b/drivers/watchdog/sp5100_tco.c @@ -49,7 +49,7 @@ /* internal variables */ enum tco_reg_layout { - sp5100, sb800, efch + sp5100, sb800, efch, efch_mmio }; struct sp5100_tco { @@ -209,6 +209,8 @@ static void tco_timer_enable(struct sp5100_tco *tco) ~EFCH_PM_WATCHDOG_DISABLE, EFCH_PM_DECODEEN_SECOND_RES); break; + default: + break; } } @@ -307,6 +309,99 @@ static int sp5100_tco_timer_init(struct sp5100_tco *tco) return 0; } +static u8 efch_read_pm_reg8(void __iomem *addr, u8 index) +{ + return readb(addr + index); +} + +static void efch_update_pm_reg8(void __iomem *addr, u8 index, u8 reset, u8 set) +{ + u8 val; + + val = readb(addr + index); + val &= reset; + val |= set; + writeb(val, addr + index); +} + +static void tco_timer_enable_mmio(void __iomem *addr) +{ + efch_update_pm_reg8(addr, EFCH_PM_DECODEEN3, + ~EFCH_PM_WATCHDOG_DISABLE, + EFCH_PM_DECODEEN_SECOND_RES); +} + +static int sp5100_tco_setupdevice_mmio(struct device *dev, + struct watchdog_device *wdd) +{ + struct sp5100_tco *tco = watchdog_get_drvdata(wdd); + const char *dev_name = SB800_DEVNAME; + u32 mmio_addr = 0, alt_mmio_addr = 0; + struct resource *res; + void __iomem *addr; + int ret; + u32 val; + + res = request_mem_region_muxed(EFCH_PM_ACPI_MMIO_PM_ADDR, + EFCH_PM_ACPI_MMIO_PM_SIZE, + "sp5100_tco"); + + if (!res) { + dev_err(dev, + "Memory region 0x%08x already in use\n", + EFCH_PM_ACPI_MMIO_PM_ADDR); + return -EBUSY; + } + + addr = ioremap(EFCH_PM_ACPI_MMIO_PM_ADDR, EFCH_PM_ACPI_MMIO_PM_SIZE); + if (!addr) { + dev_err(dev, "Address mapping failed\n"); + ret = -ENOMEM; + goto out; + } + + /* + * EFCH_PM_DECODEEN_WDT_TMREN is dual purpose. This bitfield + * enables sp5100_tco register MMIO space decoding. The bitfield + * also starts the timer operation. Enable if not already enabled. + */ + val = efch_read_pm_reg8(addr, EFCH_PM_DECODEEN); + if (!(val & EFCH_PM_DECODEEN_WDT_TMREN)) { + efch_update_pm_reg8(addr, EFCH_PM_DECODEEN, 0xff, + EFCH_PM_DECODEEN_WDT_TMREN); + } + + /* Error if the timer could not be enabled */ + val = efch_read_pm_reg8(addr, EFCH_PM_DECODEEN); + if (!(val & EFCH_PM_DECODEEN_WDT_TMREN)) { + dev_err(dev, "Failed to enable the timer\n"); + ret = -EFAULT; + goto out; + } + + mmio_addr = EFCH_PM_WDT_ADDR; + + /* Determine alternate MMIO base address */ + val = efch_read_pm_reg8(addr, EFCH_PM_ISACONTROL); + if (val & EFCH_PM_ISACONTROL_MMIOEN) + alt_mmio_addr = EFCH_PM_ACPI_MMIO_ADDR + + EFCH_PM_ACPI_MMIO_WDT_OFFSET; + + ret = sp5100_tco_prepare_base(tco, mmio_addr, alt_mmio_addr, dev_name); + if (!ret) { + tco_timer_enable_mmio(addr); + ret = sp5100_tco_timer_init(tco); + } + +out: + if (addr) + iounmap(addr); + + release_resource(res); + + return ret; +} + static int sp5100_tco_setupdevice(struct device *dev, struct watchdog_device *wdd) { @@ -316,6 +411,9 @@ static int sp5100_tco_setupdevice(struct device *dev, u32 alt_mmio_addr = 0; int ret; + if (tco->tco_reg_layout == efch_mmio) + return sp5100_tco_setupdevice_mmio(dev, wdd); + /* Request the IO ports used by this driver */ if (!request_muxed_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE, "sp5100_tco")) { diff --git a/drivers/watchdog/sp5100_tco.h b/drivers/watchdog/sp5100_tco.h index daee872f9b71..8ca1b215e3ce 100644 --- a/drivers/watchdog/sp5100_tco.h +++ b/drivers/watchdog/sp5100_tco.h @@ -83,4 +83,9 @@ #define EFCH_PM_ISACONTROL_MMIOEN BIT(1) #define EFCH_PM_ACPI_MMIO_ADDR 0xfed80000 +#define EFCH_PM_ACPI_MMIO_PM_OFFSET 0x00000300 #define EFCH_PM_ACPI_MMIO_WDT_OFFSET 0x00000b00 + +#define EFCH_PM_ACPI_MMIO_PM_ADDR (EFCH_PM_ACPI_MMIO_ADDR + \ + EFCH_PM_ACPI_MMIO_PM_OFFSET) +#define EFCH_PM_ACPI_MMIO_PM_SIZE 8 From patchwork Sun Jan 30 19:12:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terry Bowman X-Patchwork-Id: 538334 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 73783C433F5 for ; Sun, 30 Jan 2022 19:13:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229533AbiA3TNZ (ORCPT ); Sun, 30 Jan 2022 14:13:25 -0500 Received: from mail-dm6nam11on2056.outbound.protection.outlook.com ([40.107.223.56]:50080 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229523AbiA3TNZ (ORCPT ); Sun, 30 Jan 2022 14:13:25 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EAsnMQw4hZjEI0WhKHj/p/lAmXFgbks8yMM4HqhBSeC7gU0zTmP0w0uHOS+c1ECqBOJ9SHCt4WxBXtLcTf2IiPqAPO3radID0FHAS2Vp81ghPT50LEUfjwzjGKAlW1lnYdFVVCNBiEEkolTPswwHTUPoTBux34M2vpsCdFYwQEuqynSmt/IO/lFIrHXGtZygUsm9wm96VX5wzXONVr2L9THqH6+FT8nRjLMBMNcToRISIMrXs2UgZzW6Ypi2dvgdAmikKOcvjKKbRTvvj6EvFe1Dq995CG7JSVbzvJ/bIMXdATzMJqK9M58Yge0UNbdFlm6sWGRMPip3Y9+rfR6bsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qTDj/NmjaBZm5KZaYAjxO6m0ymhxBHtNrfFngxEl2k0=; b=PzSQhhhvOYI83mL+vPXygtyojgWJ4Igd57s4aYQwhzPIuWfmXxysvHijh74ooPFqGH9P99oJrb2xEkGIClZ3qoYtJUqW2Qug9I8c3szzz1l1tsHXr1yO/pufopm7hq7/kzwV+P7U4N+HhrWDNe/gQmTaE/shPEsAiE9HOEK+pIVU0Iz/ReKvWR5lGnE5oQJyh8O6GuKVYuNH4UDcPk98Gm9JNcewwoUufyHv6w+yc/ahtZvQrgM/SHhNEiIcdlzYY9ItZJTTB1YMQOCIGh1EPH9PZ0oRvNOdFdFl9a2aDcmMVPUTl5aG5zHsQ/nqZfD+++i3KJA3mEIrBlqeKW3N5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=roeck-us.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qTDj/NmjaBZm5KZaYAjxO6m0ymhxBHtNrfFngxEl2k0=; b=EMA4QgW+1+8wQXiiSm/3k6P6PHTrXx9Kn9JtvL4pd/q5xTJdV3YnO1itAv85dLWIuoIoi26wo6YXuZJUoaa+B6OJhxFgDk4CMk1PlnGYCmMF2+9rEADs1ZjE3fPJ17fNnpKfB3559trwpKGJ9nDqowNZBmxMnk9fjrjPBy3MZdo= Received: from DM5PR16CA0039.namprd16.prod.outlook.com (2603:10b6:4:15::25) by BN8PR12MB3185.namprd12.prod.outlook.com (2603:10b6:408:9a::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Sun, 30 Jan 2022 19:13:16 +0000 Received: from DM6NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:4:15:cafe::f5) by DM5PR16CA0039.outlook.office365.com (2603:10b6:4:15::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.21 via Frontend Transport; Sun, 30 Jan 2022 19:13:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT060.mail.protection.outlook.com (10.13.173.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Sun, 30 Jan 2022 19:13:15 +0000 Received: from ethanolx7ea3host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Sun, 30 Jan 2022 13:13:14 -0600 From: Terry Bowman To: , , , , , , , CC: , , , , , , , , Subject: [PATCH v4 4/4] Watchdog: sp5100_tco: Enable Family 17h+ CPUs Date: Sun, 30 Jan 2022 13:12:25 -0600 Message-ID: <20220130191225.303115-5-terry.bowman@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220130191225.303115-1-terry.bowman@amd.com> References: <20220130191225.303115-1-terry.bowman@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c0079ddd-71b6-45f0-a052-08d9e4249177 X-MS-TrafficTypeDiagnostic: BN8PR12MB3185:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FOBF1qYoeUs1MaNGC0wNmcj3EPfPPSu8TqIRKTD3LEmV9k9xn4bN/UZyXD/9mioziPSCoU5hsFevje5+lyW+xvrGhgUvqmTsVPBsnnkedz2lcmkjOIcCm82v7CKU+qwRhrdYYb1VY/HAufMCuTBv+kVW97kXmq2zkbjMEvXdLKVBC6/LSzzd6wyyqt41cib2kG0kB0r2085QFuS8ATOZ6lK36fIKR4hOkPHqcgcsTj498JFFy11U0T+YnqAtmEOOFfZiI3iG0ZZnTyNFDa2BxMkVhlKA09EyhmnyGrZcq2i5uoZxvTfqqWI72LYvL+IXNOUBRUx2yS7CG3MfZxKST9AV+4WfUadIUsRtLcds16IvVoWOXjV7npkAgzjkOIemnAsmj45JvEbC3ANRziepxhFHAK9bE8B0Trw+GYo42WcGejnsfqmL2i51N6ZLJK5yk9KXKtGhMpPIJ/qi9nWR8yOAHTEx47dim/KhJqCA06LBZ5I3Z6HbGE1ihDfEtB/H7w3vwqxTAxlW1KXtCkdXqAEJrSmz3uSC/ComaTXB6nqUv/xSbLLqVEiJq6ceyNTgjWbZM09dGnLDvT4CH3Syrv+n2KUA0pTxKqpEljTqbE3hDgmK55/tii+PcMpElCgvkLmWbSjwLC+QJJ28NQyrWZRxVvfa8ZVPN9Nz4U16un816twUNQXTXVi5xAEs/qw75Fffjelto9yfEAFH+bvyzpBvQTkRjn11XbKtA9qaFco= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(47076005)(508600001)(36860700001)(356005)(81166007)(86362001)(83380400001)(40460700003)(54906003)(110136005)(36756003)(8676002)(8936002)(70586007)(4326008)(70206006)(316002)(6666004)(44832011)(5660300002)(82310400004)(7696005)(336012)(426003)(16526019)(2616005)(2906002)(186003)(1076003)(26005)(36900700001)(2101003)(20210929001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2022 19:13:15.9033 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c0079ddd-71b6-45f0-a052-08d9e4249177 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3185 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The driver currently uses a CPU family match of 17h to determine EFCH_PM_DECODEEN_WDT_TMREN register support. This family check will not support future AMD CPUs and instead will require driver updates to add support. Remove the family 17h family check and add a check for SMBus PCI revision ID 0x51 or greater. The MMIO access method has been available since at least SMBus controllers using PCI revision 0x51. This revision check will support family 17h and future AMD processors including EFCH functionality without requiring driver changes. Co-developed-by: Robert Richter Signed-off-by: Robert Richter Signed-off-by: Terry Bowman Tested-by: Jean Delvare Reviewed-by: Jean Delvare --- drivers/watchdog/sp5100_tco.c | 16 ++++------------ drivers/watchdog/sp5100_tco.h | 1 + 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c index 1a5e76d13c3c..b25b353fdf36 100644 --- a/drivers/watchdog/sp5100_tco.c +++ b/drivers/watchdog/sp5100_tco.c @@ -86,6 +86,10 @@ static enum tco_reg_layout tco_reg_layout(struct pci_dev *dev) dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS && dev->revision < 0x40) { return sp5100; + } else if (dev->vendor == PCI_VENDOR_ID_AMD && + sp5100_tco_pci->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS && + sp5100_tco_pci->revision >= AMD_ZEN_SMBUS_PCI_REV) { + return efch_mmio; } else if (dev->vendor == PCI_VENDOR_ID_AMD && ((dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS && dev->revision >= 0x41) || @@ -459,18 +463,6 @@ static int sp5100_tco_setupdevice(struct device *dev, break; case efch: dev_name = SB800_DEVNAME; - /* - * On Family 17h devices, the EFCH_PM_DECODEEN_WDT_TMREN bit of - * EFCH_PM_DECODEEN not only enables the EFCH_PM_WDT_ADDR memory - * region, it also enables the watchdog itself. - */ - if (boot_cpu_data.x86 == 0x17) { - val = sp5100_tco_read_pm_reg8(EFCH_PM_DECODEEN); - if (!(val & EFCH_PM_DECODEEN_WDT_TMREN)) { - sp5100_tco_update_pm_reg8(EFCH_PM_DECODEEN, 0xff, - EFCH_PM_DECODEEN_WDT_TMREN); - } - } val = sp5100_tco_read_pm_reg8(EFCH_PM_DECODEEN); if (val & EFCH_PM_DECODEEN_WDT_TMREN) mmio_addr = EFCH_PM_WDT_ADDR; diff --git a/drivers/watchdog/sp5100_tco.h b/drivers/watchdog/sp5100_tco.h index 8ca1b215e3ce..6a0986d2c94b 100644 --- a/drivers/watchdog/sp5100_tco.h +++ b/drivers/watchdog/sp5100_tco.h @@ -89,3 +89,4 @@ #define EFCH_PM_ACPI_MMIO_PM_ADDR (EFCH_PM_ACPI_MMIO_ADDR + \ EFCH_PM_ACPI_MMIO_PM_OFFSET) #define EFCH_PM_ACPI_MMIO_PM_SIZE 8 +#define AMD_ZEN_SMBUS_PCI_REV 0x51