From patchwork Wed Feb 2 15:35: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: 539754 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 8948FC433FE for ; Wed, 2 Feb 2022 15:35:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345494AbiBBPfv (ORCPT ); Wed, 2 Feb 2022 10:35:51 -0500 Received: from mail-co1nam11on2054.outbound.protection.outlook.com ([40.107.220.54]:23373 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1345482AbiBBPfu (ORCPT ); Wed, 2 Feb 2022 10:35:50 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UReawUM4KcnS870tVpHqiIS7Z4I1n1RImVD87D1ksm/vUOtRUyeN0we9c+nQV56Abq4Q1vw9Sjq62fxWmZWEyU5xTjfw+59SCk7LWH/4A2zBhoLDxsgW1AUn1Xe+PZ2eCFVu1cdviiBSgCf7deNsKDPDWKV8CH695LbEVxkZOfUNc/rBMAphghq0uEhlIXfhdIruVKlPtNjCuYsuPM0I66QTi6psFkzlyVhe61AO7BTiuD9nNI46i/MlYWgWDIrabZl5QzjhOpTvnz0nZf3aaTCQX9RnU7EsN26lKpYpOx16gLq9raYHsMGJ+Gme/jTyNdr8CH1Zg6ws1C+DiBNwww== 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=dxFMw00ZYEyf3Xoe58qX77hWZLHxY/f4BDn6OUAnbNvZJVeJXbjsRCTp3zUO1jI4r9UO35mBr4R3RpERxz666NYiiDTXku5fAu4e0EYAySZmg/edUaYKRy977Arw3/KN1HEjMIaINaZoZ23Q7GSRHgotc4Ls9+XHqsArODRtq+mWtKHFwnHXCzq1fwnivEPU7zhKtR3WYPGU0U1Oz4uzPr/zhzB/dcsk9YwjvEfPBk1UbmxOkq/DjDlyiS3V4S16X4q/ChPonc8bWAPxjusrrISwFiVGCok2/zT2eUBfk4YtJrSXQD7x5utY2TU+9YacCLxpGt5z/wb2W4js/iMPbg== 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=r6cpXxftNQP9YKJyEHDzvyuOSUukm7znlQCZDevHqbpdoZMj0pHYfmxf+J4IxsrpYozi6eR7Mnz4ghWmmJGq/AyNmqWZZQ5Rd9HA3yyCAegzLRCzF6JaSG7jIC/foYoJ2ESHlxWayYJVtUcdojC3KN3ERrgTWkAwWTdl8uo98I8= Received: from DM6PR13CA0002.namprd13.prod.outlook.com (2603:10b6:5:bc::15) by BN9PR12MB5035.namprd12.prod.outlook.com (2603:10b6:408:134::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Wed, 2 Feb 2022 15:35:48 +0000 Received: from DM6NAM11FT064.eop-nam11.prod.protection.outlook.com (2603:10b6:5:bc:cafe::b8) by DM6PR13CA0002.outlook.office365.com (2603:10b6:5:bc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.7 via Frontend Transport; Wed, 2 Feb 2022 15:35: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 DM6NAM11FT064.mail.protection.outlook.com (10.13.172.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 15:35:43 +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; Wed, 2 Feb 2022 09:35:41 -0600 From: Terry Bowman To: , , , , , , , CC: , , , , , , , , Subject: [PATCH v5 1/4] Watchdog: sp5100_tco: Move timer initialization into function Date: Wed, 2 Feb 2022 09:35:22 -0600 Message-ID: <20220202153525.1693378-2-terry.bowman@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220202153525.1693378-1-terry.bowman@amd.com> References: <20220202153525.1693378-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: 9f5445f4-c7dc-4f89-32f4-08d9e661acb4 X-MS-TrafficTypeDiagnostic: BN9PR12MB5035: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: K5xtjk/2vcUYoRFzbEdRvxlkGQBsxkyWjVFjQbXBRsjyEEiXqgFPUHMskah58lQsDjCl8CNgMZoNpMLvT0Qe6YANe+QZ40n+3E6rPHwNxpyXYc3DEC176v4iMMCYzmYCJKYLVB6FGoYn95EHhbVlWiDqrBrHVh3vnQayOWTscW7dhS5eavUcmSp9CQiqAjQxtrbl5xw5woCnC4YDPSOyRZBPo2N1nlA2KQNdfNvUdcSDkN2Ofu1EdQv3Jn04xJvOvz7TvpKZWJcXwf7qECEJXlgx7eTsGv/6iW8wD3+Xi7Ib0aGa/ROi9oeuaOC5ulNJTAhOUDnd4wnRkep4H2yZ9zSJ+9qazlLODKntgbxPx1sHggZAYzNqJr0k8GWBNJmjm7g2IF57Rq2tzc7qeiTot11N/RY9L++0/I0bbEHegCK3VJvL7GF8ekd3aUdoz7UseWDBxcva+jbUYJuKyRjYFGdV+r6Hjz0BS317aF2wVkF16URMkPy3c+qXUaHgehIX9D5t9dJW/zz1IbKp4JrBUYSnhfhPaiIUCVX9UeNd6RmHs7sJyNUAu09OLjbWpIemtuPQW8KXJcf2Kurbwyf1bMoJ5Svk1hngzSxa1bSdZmNtNfnJ5cWyUR6tRg5iudZTbiYwJh6y+5A1N5AeqUzw5906XtXkCiszJPgjSMj4TcoJTBK39Y7YOp90YQX3gNxQtx7FEMh6bb0wSNtOUWX/KB7ZQf8k8QM/XxFtR7QfzNE= 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)(36840700001)(46966006)(2616005)(5660300002)(70586007)(4326008)(44832011)(8676002)(2906002)(70206006)(36860700001)(47076005)(7696005)(86362001)(82310400004)(8936002)(40460700003)(6666004)(336012)(508600001)(426003)(356005)(83380400001)(316002)(81166007)(110136005)(36756003)(1076003)(186003)(54906003)(26005)(16526019)(36900700001)(2101003); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2022 15:35:43.2405 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9f5445f4-c7dc-4f89-32f4-08d9e661acb4 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: DM6NAM11FT064.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5035 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 Wed Feb 2 15:35: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: 539492 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 A0B78C433FE for ; Wed, 2 Feb 2022 15:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345506AbiBBPf5 (ORCPT ); Wed, 2 Feb 2022 10:35:57 -0500 Received: from mail-dm6nam12on2049.outbound.protection.outlook.com ([40.107.243.49]:15969 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231365AbiBBPf4 (ORCPT ); Wed, 2 Feb 2022 10:35:56 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R0j/GpVD8DZoMwnElXKsehVo77OQMgnBoJ//8V1iZPvF/qs5fThNTHB0sy7Evz8RSmWWtTAcYedUYjFIwFJTcrUk/nN0LSzeDz41Gnt2xuk4Ib+mkWS3hCXMkBuRFHMtS2vQiPwgJAwByRRqyve/5fXcT7/3a2BuTqd+lBrQrdUcVB6fXVxnLoklGDTtHXjhNF6r8GEU8ThgBDPx5Y9FaqOXSJFu/r8/VY5As2jxXh1RtJOQwvG4T5jdUQMVJC5ubNA3bZRR6nLyXXZpl5ndkidOODt+Zqqsgc/Al4PagDhsxsPLdpj0uqDpRv5BJK9+KwxmHZcfxEIuiQVtcORoSQ== 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=pIYpZ2C5/hnmub6Jg3VC+X/rT71YHEBoBKlluFtcw9c=; b=WHP9F+DVTC1WuIvjers7am2KAyyO8ygN8+Pat2+hb+sXoi5y44sibeKfsmpFF8ahtIauMxdxA+7tvM35rUHeeVO54Ug81sGasoL5WnVcC5HSII+j7sAKIzCG0Otfw/ouSW/oknFvIqwt0N/1Xqicv5UWhnbNhIYtL00UzwsBusONS9i3dcbdAhnYc+Paz3nEs2dYFevQkyhQFbxEgNmf/7t/lYxR09kUuN9ZHdKGS14ZQfFHrwLq3pj9+fHhCUbdkqW+B2Mtwte7+pHUt/t6bZiej5rQPFAEuafma2s/ol5Vn5K2shyXTO79b10FJNVjVrdTdPVHPy+AKrx1rIYdOg== 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=pIYpZ2C5/hnmub6Jg3VC+X/rT71YHEBoBKlluFtcw9c=; b=zvn1VXPUvL/srAvtEjSRdnRAfo/cpnFafy6S4E9bZtoz7CBsGWdW3RXFxVez6zqJ1LdYFqDgM1IJwZ71VeRb8NMJEDXCqSj/sH2Y8sTpFDvBBZue6lEP90hXJDosN6nsbZL3jm87SpLXVgF0FUsMw3I8aBBaMt2o+vVlDoXsBQo= Received: from BN9PR03CA0388.namprd03.prod.outlook.com (2603:10b6:408:f7::33) by DM5PR12MB1148.namprd12.prod.outlook.com (2603:10b6:3:74::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.18; Wed, 2 Feb 2022 15:35:54 +0000 Received: from BN8NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f7:cafe::95) by BN9PR03CA0388.outlook.office365.com (2603:10b6:408:f7::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 15:35:53 +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 BN8NAM11FT037.mail.protection.outlook.com (10.13.177.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 15:35: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; Wed, 2 Feb 2022 09:35:52 -0600 From: Terry Bowman To: , , , , , , , CC: , , , , , , , , Subject: [PATCH v5 2/4] Watchdog: sp5100_tco: Refactor MMIO base address initialization Date: Wed, 2 Feb 2022 09:35:23 -0600 Message-ID: <20220202153525.1693378-3-terry.bowman@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220202153525.1693378-1-terry.bowman@amd.com> References: <20220202153525.1693378-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: b3068aa4-31f1-4682-625b-08d9e661b2ec X-MS-TrafficTypeDiagnostic: DM5PR12MB1148: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: IWtioDEKkYw7E/icfjvX9OsRIpwpomADCexFu4J4GZ5eieBDMxhIIFkdcTx8CQp/djcMR1K9PlpHsx7Gx0xgMQw8wJBRCDKFbmqa5MGPky7KR61un1AEKktOclbtQpsTXTYsOuHoP7JEEvreoIfPsDUNHEbsz+PREG04dZUBANNGHD9hMnppfvKIak83jI+W9ud0k/8nvKoxAGQFexAdB61ukeny1YCBCa0IKxx2eTaliXXVlPlL2tkzsX4BgPNxVERSCF9a83+rAu3oBkaiahLEuCIcm+i/3153VdynUjozoeiOFLXuwtUqQNTJO40AlV7AdlsBAZT8yJ0xJqCbnHtj8/l+MZiH9ostkAfkNC+NkIoIM19BwavOgJ1zcioyMLSmvlEufnXXtc6n+UabXLIUdHlGdhrJ0FFet9Kyv9BsBkFH1WtW85HswSd8acUkDFalUIuzPNg4YCFp2vGYyRsUKLF+XGu+9ftdbfZGTa+o2bPC8qndlr3OyxqGmrKBmhKAyYdJnMB5oKOerGVSsqsk4Qk0ESgk8OQHdrLIYBIymws+dx8sZtn1wjZwdjyTK1W63PS3l40qNvqNSlv0vxK1mamJBseHFQXyWdieBTxZ2Ne/r1Ef9d0Xwq+XnUnPx+L2ej/6Akrp4Z37i9mrz0mPj1m/DcefAPm9ayeQcmSx3b5mRBsrw6mmMx/q1sHlEYaNiFYdEapTqPSjTgr5QfVMQ1P64P0G/0xOXAeVhKw= 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)(44832011)(36756003)(356005)(5660300002)(336012)(81166007)(1076003)(2616005)(40460700003)(426003)(16526019)(186003)(26005)(2906002)(316002)(7696005)(70586007)(8936002)(4326008)(70206006)(110136005)(83380400001)(82310400004)(508600001)(86362001)(54906003)(47076005)(6666004)(36860700001)(8676002)(2101003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2022 15:35:53.7063 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b3068aa4-31f1-4682-625b-08d9e661b2ec 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: BN8NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1148 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 Reviewed-by: Guenter Roeck --- 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..8db7504f0aa4 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", mmio_addr); + + 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 Wed Feb 2 15:35: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: 539753 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 B6842C433FE for ; Wed, 2 Feb 2022 15:36:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231365AbiBBPgI (ORCPT ); Wed, 2 Feb 2022 10:36:08 -0500 Received: from mail-bn7nam10on2051.outbound.protection.outlook.com ([40.107.92.51]:10465 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1345508AbiBBPgH (ORCPT ); Wed, 2 Feb 2022 10:36:07 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i4ovpGtcHua4on9k5WIxe/TrNf2PCgpRpAfcGZroRa7rvWBRZ0wvL19hWYMEDtxFkMKMqwwV9eu3PrexBVr13uczVWGynEmCVOldQtN1wN1B9Fl9PiNgR6YGyMHRw8l1raH1Z0kyLuxCEFzyVLO5BiFePb1WOl7y2ZbN7dA4Jy+7yv1aT8RstwV48t27fDrvYsZrYj4Km2f1QGTpnZq7qx8p1VjHHaxcDVgKBB2wrryuC7qtKIgS5O+OaVcrQbM1Iw1qdoJYd1BTF4iIHQHkRpv6mHbllSZzRVWXzbxxm+k8W1I8CaptLXpv3EwJUIMEMKuiy65fxQ+Jq8P5GYuAxA== 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=hwag+ixwaedXtVY4U+cBGXvd8g4i1bimRYbm4R+rvY4=; b=d9wBq2ztywYP+oMVd2Eg0KUvXjBJ/OqdcSzWiBgpS2FTas8juEnFD08I/8mDTWhuwx9KdPiaxmZWZR3eddL3239PEH+d5uGABW6CEFqcON3xuGPlHpjd0EBe+1fzj9Fgs+3U05EHw1cqIWd9Sby/gFE0tRJubY+OMRHDgM5L6AqeAJSaFKHM6cmHXZ4IOkLM6A1Ea/dFk+KBIhjwyi438DmKtNbyxz+/xupR3kdOGnbW8TswtbtpMQqlHwHqez3jCXBqM1uYCWRlXF4KU1b2fQsnHskye4wjDsu/rwEZwKX7abaYn/DNh1+yv3sT0iU+R75BCQ/YRTQOsE0+u8nA+w== 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=hwag+ixwaedXtVY4U+cBGXvd8g4i1bimRYbm4R+rvY4=; b=dpI3VP3BlWK3U7iQ7RADg9CAecU4vtQK+1yjWiySry/+ypXOOPkzJgDjA4PodTcrr48wgumMqPM8kCPIYNgf1yPX8yPtptK2mDUHHh47okx1F7wIkRhbKE5QhUfzt9CMvCNRT4nTGqwH00dEbYDaSMr0/vTNNg/25SnZBVA9wxY= Received: from BN9PR03CA0923.namprd03.prod.outlook.com (2603:10b6:408:107::28) by CY4PR12MB1335.namprd12.prod.outlook.com (2603:10b6:903:37::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17; Wed, 2 Feb 2022 15:36:05 +0000 Received: from BN8NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:408:107:cafe::91) by BN9PR03CA0923.outlook.office365.com (2603:10b6:408:107::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11 via Frontend Transport; Wed, 2 Feb 2022 15:36: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 BN8NAM11FT063.mail.protection.outlook.com (10.13.177.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 15:36: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; Wed, 2 Feb 2022 09:36:03 -0600 From: Terry Bowman To: , , , , , , , CC: , , , , , , , , Subject: [PATCH v5 3/4] Watchdog: sp5100_tco: Add initialization using EFCH MMIO Date: Wed, 2 Feb 2022 09:35:24 -0600 Message-ID: <20220202153525.1693378-4-terry.bowman@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220202153525.1693378-1-terry.bowman@amd.com> References: <20220202153525.1693378-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: 73514829-90a9-43b1-c70c-08d9e661b98b X-MS-TrafficTypeDiagnostic: CY4PR12MB1335: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: JJSZ7rA0ZzAz0MY535vtv0rK7CWUY3Hp2F42rat7b5Nfu/uD9LQokwLsdr5L3IdZxPyrqZHZ0eExH5MtlP83RXFLaxRkjkKQizh2+a/M3FpGaL05DQ2zd5HfJR+SOv5SunWEhOb5Zc2hmpel1HbEsxU+nWVbvrSR97Le0UwK2R5pWd8wQ0BLjTThpb4Maj2R0aTUgQhPs0GyshyfV5yF29AbmCtiZcxGxwaBh5J4JDPw8SQyee2X6i1pKWmcscxbVp6rNJs7I5SLACzk6+N+tzdGJpQ7Z8qC69P9/BXDIa9322epgkSXO0ctWozPyHZnVWfe+8y9OQS8J/rDu5kD3gtpPg6rKuXDhLlOnQeWJn7+gJlSPe+3lUGK8Y3F/Fph6NSub/Gm4pf28SFg+qgJcD0zV5wnsau9rBwwz2Eak4S0/OInrSVO+bLt4pkrwiuSkAREHBR9nwY/ny5Fqc3UeoW/MCK1CNJtssq11fIO5UyHyWdMe3exZChhUWwrJY5+Nl+uy4KtydssWa7+kstYq7n9LSXPCuChY5s+0kHxBcz/68NywTj0CgwDAs5OSpChVkGH6CK+jcFizj5Dj5u38FwIzInaiBX2ajGT4O24f1F7x9AklvIOrgPPiwPuEaKYwkERfuaNdnEeCK/Z2X1fzoAIuB3jx2ltwNpC/jGL9+RydTb5A2qb79gopjMhgMeJqYOl84EvBjNjN/D6i/Nr3/Yhk8c1vSEPzsNwA0zeuYo= 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)(36840700001)(46966006)(40470700004)(26005)(2616005)(2906002)(186003)(6666004)(82310400004)(47076005)(83380400001)(16526019)(5660300002)(1076003)(44832011)(7696005)(336012)(426003)(110136005)(40460700003)(70586007)(508600001)(86362001)(356005)(316002)(54906003)(70206006)(81166007)(8936002)(4326008)(36756003)(8676002)(36860700001)(36900700001)(2101003); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2022 15:36:04.8016 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 73514829-90a9-43b1-c70c-08d9e661b98b 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: BN8NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1335 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 --- 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 8db7504f0aa4..e02399ea8730 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 Wed Feb 2 15:35: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: 539491 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 9DD6AC433F5 for ; Wed, 2 Feb 2022 15:36:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345508AbiBBPgS (ORCPT ); Wed, 2 Feb 2022 10:36:18 -0500 Received: from mail-bn7nam10on2083.outbound.protection.outlook.com ([40.107.92.83]:3809 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235549AbiBBPgS (ORCPT ); Wed, 2 Feb 2022 10:36:18 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TGIDOoZCsY9d7L6RHmb41KIT3sMOwEi3bUMkWxoMw4TlVlAROX/WMRHQZU6AmVqCJ2ne2aR4p7LuoQToP4ttejIzAVDSNMO6oQAiI1qMI8bzrux6tv4MjiERSZsJWdk895dn3y1lh3MVROBaxeLSIcoRWNrk/Utl5ynZ1XTubqM6lftGeRFkchKqupgeSeg2f6cXaJg34ExTlLZ+3vgDivvN+zraY8Y8A1HmSxz8P72T6/f3hMub8zToZ5EmvV65KGCmrV2qoLMXiFdG6Xo2xYYOCcAlzEG0kImHlRbzrnMdvfTbpZHkx1Z9T6GJ1Pn3UaerAJbhiuSeqhWxMXWV1w== 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=s3tGR+qgL3VHVP/McPMiQGJavS1w09Q2Bvyf2DuiwNU=; b=O+DIxiYlIYfZjALeQjOiFB5/gL0N5vxbWIuMlmGZA0BZl9bMV03C6qsRmW0qkdPTsFaq3h5hwz1m9Of3Hora4sBLGpK4Rndy/IU0E8oNfxxsL2DS9PkpiRLE0acLnE/OpMvBnE0R+gs6Wwvh+XGuTpFrNdoMn0bEKNaIVsG+pvAazDz5FinPCg4dxMy8j68VpdumN7D5nKSmTLqi3mYzM4KbHIF/t1B0DSd7R5Dpk/28kINEzAbXpZveonsS4fyRq4Bp/n5T2CYGeJHUw2TO6NMP4YKbFVayeu5ouNaAl8ggG42ck4+Y7VRG0OYgmlwyHcjfTF9uk/w3e6owhDByxQ== 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=s3tGR+qgL3VHVP/McPMiQGJavS1w09Q2Bvyf2DuiwNU=; b=MybjMVV5Nq9ZLZb0npENJphQbGjhytjY2FynQ1qRxUkgfHy8sAdtmXfZN4VYEzKD2P1JflTExyYuWHNob7YdtwhHcxI2HSwAE2Sil64jQL9Q1vbCsgWf/YTdBBuW3tcNuJi99tdiUJYBuRr4/nlV/Jf54is+vZhfMf93BZ/Q7V0= Received: from BN6PR17CA0014.namprd17.prod.outlook.com (2603:10b6:404:65::24) by DM5PR12MB2422.namprd12.prod.outlook.com (2603:10b6:4:b9::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Wed, 2 Feb 2022 15:36:16 +0000 Received: from BN8NAM11FT056.eop-nam11.prod.protection.outlook.com (2603:10b6:404:65:cafe::9b) by BN6PR17CA0014.outlook.office365.com (2603:10b6:404:65::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 15:36: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 BN8NAM11FT056.mail.protection.outlook.com (10.13.177.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Wed, 2 Feb 2022 15:36: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; Wed, 2 Feb 2022 09:36:14 -0600 From: Terry Bowman To: , , , , , , , CC: , , , , , , , , Subject: [PATCH v5 4/4] Watchdog: sp5100_tco: Enable Family 17h+ CPUs Date: Wed, 2 Feb 2022 09:35:25 -0600 Message-ID: <20220202153525.1693378-5-terry.bowman@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220202153525.1693378-1-terry.bowman@amd.com> References: <20220202153525.1693378-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: 4b977c49-03cb-47e5-c537-08d9e661c021 X-MS-TrafficTypeDiagnostic: DM5PR12MB2422: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: 1B4YzfU7AWm2Kt+Nwf70cvEMsm+Xj1mMYwPSixdVDYZi+QbbBanbIarzYrkX0FEo4v57SKqT+nxL+TtBxxqxiQwuAS4MGUO4CwuQT+BZguIR1qzmEBvp3cWYZvk2IhBtU1S+DYzgGoO4Z6p3zxkqE1o7NT3xzTPfd6htSsbVlJvHqYxdtGI8ng1dS5CsRAsygZ+t2Dc3BqDhoKNXMRs9h0CrGOC+ITI8atg/7i22ozzwe2v/XJV1agUZgo/QPLSFDfdLQTwIzjPkSithcEjF+JzjzH5skUgToWcnN2okfS6iZHDfozNpi1s3DpzXJfhKNL2e63Ca9e9T+4MwdOrCB6grX7WW4gw+c6G5bmT+7aCr/Ucr0dMPPMhm35wnnyM1h3TfA6VU8K1vzcT86M3xIHoygabRJAuaUKNmNDUaZJfS3rMAIGdBMQLSnC2iOMIhGFBgQRYZdXy+IxUMcwMYr4mtF74vDSoh09d8gTOMinH3uVPE+FFW33yxOuwPYba9kr9O26gOkfj4IYza4TVVM1yrYJctmo3r55eIDJuB7iU7vE1d12unHbVmWzXkAcgtAH89Vs+jgngQwWzYWv+ljcsGp8xfRUR8EV+isOcCfdGX8Tlj5WTuvdEN3QyJz8RgHN9MRw2E6VjOhnnGRfUYBli3CsK30hfEQDM22/K6qwpalZ8Rile0sqAIzH13nee/zUNXiWLnzfczLkMGC6oc1ATenj6OYj/H+I1qhX1RdlU= 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)(82310400004)(70586007)(86362001)(356005)(70206006)(40460700003)(36860700001)(4326008)(54906003)(8936002)(8676002)(316002)(81166007)(110136005)(336012)(1076003)(5660300002)(47076005)(26005)(44832011)(83380400001)(426003)(16526019)(2616005)(508600001)(36756003)(186003)(7696005)(6666004)(2906002)(36900700001)(2101003); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2022 15:36:15.8509 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b977c49-03cb-47e5-c537-08d9e661c021 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: BN8NAM11FT056.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2422 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 Reviewed-by: Guenter Roeck --- 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 e02399ea8730..86ffb58fbc85 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