From patchwork Thu Jul 6 15:48:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henning Schild X-Patchwork-Id: 700009 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 C68BCEB64D9 for ; Thu, 6 Jul 2023 15:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232809AbjGFPtr (ORCPT ); Thu, 6 Jul 2023 11:49:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbjGFPt0 (ORCPT ); Thu, 6 Jul 2023 11:49:26 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2082.outbound.protection.outlook.com [40.107.6.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B18171FEB; Thu, 6 Jul 2023 08:48:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OBVdMU++/2uvRs1BSSxPGwRlBKVk+GXg3GpWo0adpmxeMXuQc8LdHywys/lrbDCZfRSbj+UEOUoTlwikAqSdy/RRVtMPIiECncMH5tcu0sWcaDEBS/1ocbbKPxm6ROV84PWbHBbUuVEv/8JO5+zFwbyX/JYlZnzNI5GVrj88b95X6ZDVOvLsdXxTbE+RZx+1W9SyMJstvoJDXVM+br+LO6Cx7WR6agnKxBI2BlD/6uoB/bNhU+7+oSewmHtUWmiy+kwm/06wPPOQO8k5eiL852z17cEOF+sflSnd3Gm00AJXzE9GVENT3d20xXi4vkzCkOouVvaY2DgbxSzhbBU1mg== 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=S+PwWWr1WQOo/aE7TJWo/8eZI284YYi4aYzCsJx9dSE=; b=a5chj+X7FEcy+ke+PfuowDpzfJaenGPp8G3ISSNH1QSpZXVQnM8kLTpO5vvqWPuI4pNyz/tNGgcVRvJEOcGKl8mzl4edxgBytCcCoT/QBfR8RL++85UFx+YmyaTGX2oFY/nWECYiC/OpoBwUQseHj9Mah4VTVYy9YRTJINBxLx6FR4MMYp8miNDHoNTINaYoEZ9aR3s8I9/0UtXETMz+MpMheBTC2PRwemEONQp4OHmEG5z3IWBtUYebBXUecXY72clwdHaVTv6CfMiozI9IA2BOg+Ur6w88AzfMKNHorI9gtt9S21OGdufPIYlbCBWFAUck5BKwmrHX3ct3+C6Pbg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 194.138.21.75) smtp.rcpttodomain=redhat.com smtp.mailfrom=siemens.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=siemens.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=siemens.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S+PwWWr1WQOo/aE7TJWo/8eZI284YYi4aYzCsJx9dSE=; b=XbRL4CuGIwfuxHOBSrR4mH2eSYpDKTR2JCj5rzR3i288WyeB9JwvMKJ8FDv8AWJfP7ayaRJJZ9n41Sp2raYZ83qK4inXSGV3jTLwEKaaKv8IqGEmB9yPYKMjnQAsWQD7uLQ+esc9HGoyUkCTNQB8/cItFcsL+8XKZ6R9DCtI/D7oY0cGgs+F9Dwbyrjr5238IwO8ko/6oMqtMjZBVz10jApBINHiEaIgmtYqqjK7R03pmiajyGiE8Wk+KeG946duiS1jNHY7lVwqJdrXpLZ8KE4NV0CARwakEKxplPIvIsGn3vbsDcjQLsDirTGOjk7mfI8bpMEOCe6dMkY2EIpqlw== Received: from DUZPR01CA0272.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b9::12) by DB9PR10MB6377.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:3df::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.17; Thu, 6 Jul 2023 15:48:43 +0000 Received: from DB5EUR01FT051.eop-EUR01.prod.protection.outlook.com (2603:10a6:10:4b9:cafe::d2) by DUZPR01CA0272.outlook.office365.com (2603:10a6:10:4b9::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.18 via Frontend Transport; Thu, 6 Jul 2023 15:48:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 194.138.21.75) smtp.mailfrom=siemens.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=siemens.com; Received-SPF: Pass (protection.outlook.com: domain of siemens.com designates 194.138.21.75 as permitted sender) receiver=protection.outlook.com; client-ip=194.138.21.75; helo=hybrid.siemens.com; pr=C Received: from hybrid.siemens.com (194.138.21.75) by DB5EUR01FT051.mail.protection.outlook.com (10.152.5.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.24 via Frontend Transport; Thu, 6 Jul 2023 15:48:43 +0000 Received: from DEMCHDC8WAA.ad011.siemens.net (139.25.226.104) by DEMCHDC8VRA.ad011.siemens.net (194.138.21.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Thu, 6 Jul 2023 17:48:43 +0200 Received: from md1za8fc.ppmd.siemens.net (139.25.69.40) by DEMCHDC8WAA.ad011.siemens.net (139.25.226.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.25; Thu, 6 Jul 2023 17:48:42 +0200 From: Henning Schild To: Hans de Goede , Mark Gross , , CC: Wim Van Sebroeck , Guenter Roeck , Jean Delvare , , , "Tobias Schaffner" , Gerd Haeussler , Henning Schild Subject: [PATCH 1/2] watchdog: simatic-ipc-wdt: make IO region access of one model muxed Date: Thu, 6 Jul 2023 17:48:30 +0200 Message-ID: <20230706154831.19100-2-henning.schild@siemens.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230706154831.19100-1-henning.schild@siemens.com> References: <20230706154831.19100-1-henning.schild@siemens.com> MIME-Version: 1.0 X-Originating-IP: [139.25.69.40] X-ClientProxiedBy: DEMCHDC8WBA.ad011.siemens.net (139.25.226.105) To DEMCHDC8WAA.ad011.siemens.net (139.25.226.104) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB5EUR01FT051:EE_|DB9PR10MB6377:EE_ X-MS-Office365-Filtering-Correlation-Id: da47eda8-79d7-458b-2e52-08db7e387a43 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AZUixaYilKWZHnrI1n5qovndJJfjtn3ynB2T/r14GlhzEjYVCnHI1UFtLai0ejY8k2k1uiz9bNTvrcwPE6d7hQOazAww/JXdALQe4b/gMZD6wbzyce1lWy60XC/Og74z0Iis8NDW/6Khu3fPrgJzk+4Wz3G0ScvHRJFB+hXze7t70pkElytfCLGO3D4REXVB4tjN6fKlSQvfSMHdCU3sP3qcU0OuCP+ukjyApGnNVlT10ao9I+ZvzsMtbUjYP7k7ayT/mipwwVAYZTznzmHFFesunfwCGiWLdUANbP889wWn/eoyLVst/IZuX4xfrgBH7Mj+S3QLizLv29/+iweWdtLAomKAm5k8kROJpr5rAae8u/4mDfpoCJFJKmrsrZmRo+zarxcOX/NiQtJv/ELYZGHdpFFGlTEFPyFJI3nmZlUAnEtn+3jtFJfGc3uUu/Z4hmXtGfT0pPPJYAIXjpYI3SpJqJ1HZJUfaw4+Cosn+wwVLGOgJdrMdcAOWH68sVGnYUI7igbmy3VV7ShE0aPLCLz4WmdRNVrl7vmlTTu8ZkCR/5f0IAuaJZbikn01/7I2FLu6VXvyVv7EpAfB0HSD3DASFJRUoOEsu4flu9owGe9hokpejoXs6KPOoSI5TTHGo5TeWFBh3UpsqtXbDYGXdtN1uQcUqu3QchNX4juRx0GPkCcxEmHc3hpPuiZArpnUy6kHNAxZNThHGNITc8cpXTA5O8XC1/cy3DDZRfZzkKQ1bWbT5fDsdXIs0U4w3juJaCZL8L1TRTSqtO7h2b+CCg== X-Forefront-Antispam-Report: CIP:194.138.21.75; CTRY:DE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:hybrid.siemens.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230028)(4636009)(39860400002)(396003)(136003)(376002)(346002)(451199021)(46966006)(36840700001)(40470700004)(82960400001)(82740400003)(2906002)(40480700001)(54906003)(186003)(82310400005)(110136005)(6666004)(86362001)(478600001)(107886003)(36756003)(16526019)(26005)(1076003)(40460700003)(41300700001)(36860700001)(83380400001)(81166007)(356005)(8936002)(8676002)(5660300002)(2616005)(47076005)(44832011)(336012)(956004)(70206006)(70586007)(4326008)(316002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: siemens.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 15:48:43.6767 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da47eda8-79d7-458b-2e52-08db7e387a43 X-MS-Exchange-CrossTenant-Id: 38ae3bcd-9579-4fd4-adda-b42e1495d55a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=38ae3bcd-9579-4fd4-adda-b42e1495d55a; Ip=[194.138.21.75]; Helo=[hybrid.siemens.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR01FT051.eop-EUR01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR10MB6377 Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org The IO region used for the watchdog also hold CMOS battery monitoring information. Make the access muxed so that a hwmon driver can use the region as well. Signed-off-by: Henning Schild Acked-by: Guenter Roeck --- drivers/watchdog/simatic-ipc-wdt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/watchdog/simatic-ipc-wdt.c b/drivers/watchdog/simatic-ipc-wdt.c index 6599695dc672..cdc1a2e15180 100644 --- a/drivers/watchdog/simatic-ipc-wdt.c +++ b/drivers/watchdog/simatic-ipc-wdt.c @@ -155,9 +155,8 @@ static int simatic_ipc_wdt_probe(struct platform_device *pdev) switch (plat->devmode) { case SIMATIC_IPC_DEVICE_227E: - if (!devm_request_region(dev, gp_status_reg_227e_res.start, - resource_size(&gp_status_reg_227e_res), - KBUILD_MODNAME)) { + res = &gp_status_reg_227e_res; + if (!request_muxed_region(res->start, resource_size(res), res->name)) { dev_err(dev, "Unable to register IO resource at %pR\n", &gp_status_reg_227e_res); @@ -210,6 +209,10 @@ static int simatic_ipc_wdt_probe(struct platform_device *pdev) if (wdd_data.bootstatus) dev_warn(dev, "last reboot caused by watchdog reset\n"); + if (plat->devmode == SIMATIC_IPC_DEVICE_227E) + release_region(gp_status_reg_227e_res.start, + resource_size(&gp_status_reg_227e_res)); + watchdog_set_nowayout(&wdd_data, nowayout); watchdog_stop_on_reboot(&wdd_data); return devm_watchdog_register_device(dev, &wdd_data); From patchwork Thu Jul 6 15:48:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henning Schild X-Patchwork-Id: 700008 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 1F0ADEB64D9 for ; Thu, 6 Jul 2023 15:49:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232924AbjGFPtw (ORCPT ); Thu, 6 Jul 2023 11:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232900AbjGFPtb (ORCPT ); Thu, 6 Jul 2023 11:49:31 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2070.outbound.protection.outlook.com [40.107.20.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96E611FEF; Thu, 6 Jul 2023 08:48:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=REEyBJ24989qHfYTD0qXnO62mU8rcWa7F70vvwI/F6ZTJgciQfFWosRDd31pJY2el/Wgp2dgwIgY44dd7tRvhRZpbA060NvfRGB/ytZvYPxsRjgSWDY868H09paPetYEr+CpgnAMyUHG6NIfiaI4N2mfMvNLOjBisnY76jOkTINxL03822nDj/tbN7prHjPYG2kZwNlt6AZUeHiklh1QBPUTOB3uKp8t4hLDJwEDh4qenYvnZpwLHvt/c9mAgt/xSvLEYah5yIHGB3XQOI7wI3pNA/mE3PJtCVPm2mcUlk4B4yTonzD+KgiNTRVYmNuSY1Hz1/+CPAhibnLGeldJrQ== 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=TjWlAF+q8RylfW4xvo4zUhpgNcdB6LuQlClMClzvLg8=; b=j/OpmLWMihSxIwmJmTWeHqXvuFW3t4tf5R8D+lSF0B5MzFgkBjOyYaqUuzfqVWFrrFithIapLsQfeQ+oCtC12+OWJ+01Bp6/Xh6FZ4mC7aBTzqNlhslmaon/6nDRbAm0UHmIJUUCav5qg/ZiVIuy+gfLHHj/Z5WJqUzK5B58MvML0Mr0WjEu4nJtDPwTVDxI2+iXqREeBDhJQDG8voXaQG7c6Cx9417YbZdd1bv/PBd7WODVGcYGc1idGx9IZ9wbIKWOw5WmIxw4fjEoA4dl1s9C4HEpTi16XAZw2xRpyLXOdDQXiqKbeBeVEww/zU+xNo8O3SMO36OvOlxgXpOmpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 194.138.21.74) smtp.rcpttodomain=redhat.com smtp.mailfrom=siemens.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=siemens.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=siemens.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TjWlAF+q8RylfW4xvo4zUhpgNcdB6LuQlClMClzvLg8=; b=xCoiZN8RGifE4U+mGrvYVf5AMJCT/3vK2i+BBzY4tH6LnYcnO+59HYNL4Ihf2Ed9rzfvi/yO+G0v/XqJfIIMMBMHZY913/MYXbe16PwU5qfvXlp4OAGKBhI+clucnBUlesIeCsRCtiLxcw6ThYAB5cW58KAQ6Q3yija8p1gdGroSMx4Qq8Xc1YCjqMmDe8RByModLZdig/pgrXoGUGOL+FjWfGURAOVI3GGRksEmpNUYswobDvahfyhfmbKmT4Mu+EUvB2YMx9Wb9/n2HRJ3sijcAk61acHTKi/9eR54FmiD1EiJK0iSLyjI8UCJt1bTW0EIkEurAe10kmpz05qAnQ== Received: from GV2PEPF00000105.SWEP280.PROD.OUTLOOK.COM (2603:10a6:144:1:0:1:0:1c) by DU0PR10MB7002.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:41d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.17; Thu, 6 Jul 2023 15:48:44 +0000 Received: from HE1EUR01FT051.eop-EUR01.prod.protection.outlook.com (2a01:111:f400:7e1f::208) by GV2PEPF00000105.outlook.office365.com (2603:1026:900::3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.18 via Frontend Transport; Thu, 6 Jul 2023 15:48:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 194.138.21.74) smtp.mailfrom=siemens.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=siemens.com; Received-SPF: Pass (protection.outlook.com: domain of siemens.com designates 194.138.21.74 as permitted sender) receiver=protection.outlook.com; client-ip=194.138.21.74; helo=hybrid.siemens.com; pr=C Received: from hybrid.siemens.com (194.138.21.74) by HE1EUR01FT051.mail.protection.outlook.com (10.152.1.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.24 via Frontend Transport; Thu, 6 Jul 2023 15:48:43 +0000 Received: from DEMCHDC8WAA.ad011.siemens.net (139.25.226.104) by DEMCHDC8VQA.ad011.siemens.net (194.138.21.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Thu, 6 Jul 2023 17:48:43 +0200 Received: from md1za8fc.ppmd.siemens.net (139.25.69.40) by DEMCHDC8WAA.ad011.siemens.net (139.25.226.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.25; Thu, 6 Jul 2023 17:48:42 +0200 From: Henning Schild To: Hans de Goede , Mark Gross , , CC: Wim Van Sebroeck , Guenter Roeck , Jean Delvare , , , "Tobias Schaffner" , Gerd Haeussler , Henning Schild Subject: [PATCH 2/2] platform/x86: add CMOS battery monitoring for simatic IPCs Date: Thu, 6 Jul 2023 17:48:31 +0200 Message-ID: <20230706154831.19100-3-henning.schild@siemens.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230706154831.19100-1-henning.schild@siemens.com> References: <20230706154831.19100-1-henning.schild@siemens.com> MIME-Version: 1.0 X-Originating-IP: [139.25.69.40] X-ClientProxiedBy: DEMCHDC8WBA.ad011.siemens.net (139.25.226.105) To DEMCHDC8WAA.ad011.siemens.net (139.25.226.104) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1EUR01FT051:EE_|DU0PR10MB7002:EE_ X-MS-Office365-Filtering-Correlation-Id: 72185135-ed13-4537-4ea7-08db7e387a5e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VVh9/wJ/KKbaUWZ5mzJRa4jaT7iYXVVep1keadeww9yXw8b7aXHx7KtF6CtBOKeCgPKTDPQAFdjHpvqC0cZFHFHFbUebzQNQYukoRa/5miRaXrUFR8IbwQCWZGDR6DBc8wZalZ4vbmXna1cUzcf26QFdjXA0HAP5d9BcQB7iGCCFniLYybPgHHVxmEA7ZIvYUGuqtsip80IHpBZcqSh9gRvvBToIYVNPjRN4AmjQpYRdUPsoqA7MBD/cg9gRR7Pviea8py8LLGSnWg5dj5rhYFesMNsNBxMCbqDRplTWxOyHp7Q+fbbbmzYIV7Ym45khDsdj3+eA6YAM/W+lH1aVJyftO4xE6Six/CmYd7iBCrTgCkSWs1zyA4V9W86UuHBvzmBwlWSjYjqlF03GtM2r/uiZvFE4aWXmnpTCAJ2fT/C/Nuvn3CrVuwmof3c4wJyxA95UP6+pkH45wl46dAZ/BaVipksCbxiGli0eI8SnE6ySkoYL81yJaOlJnHgCQ9x3pkZdjoetuyp6LRNzx/VGld12Ged5pEmMRO6RB4N7OITDT1Jju/uUiWsBe8KUSFjFZGvbB+I6j8ITgf43RE49QWsoQDc6CXV5guX80hOZ9K8JN8brhn5Nx5ui2EpgFiYEZkmaYxPUgsOEPQ/nG1zce5YRxpIZ4iQlny9y2bjnTv+OB1p5NiqEfOkCNwY9mrsUzPCiXZLYUVdKi6CCOYcKcZlL4PieKyc2IaEd+pb7xB0BDez5P/BDe9ehgImhmvv3 X-Forefront-Antispam-Report: CIP:194.138.21.74; CTRY:DE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:hybrid.siemens.com; PTR:hybrid.siemens.com; CAT:NONE; SFS:(13230028)(4636009)(136003)(376002)(39860400002)(346002)(396003)(451199021)(40470700004)(36840700001)(46966006)(5660300002)(8936002)(8676002)(70586007)(70206006)(316002)(2906002)(36756003)(4326008)(44832011)(478600001)(30864003)(40460700003)(186003)(41300700001)(336012)(40480700001)(36860700001)(54906003)(110136005)(82310400005)(16526019)(82960400001)(356005)(47076005)(26005)(1076003)(86362001)(6666004)(107886003)(82740400003)(2616005)(7596003)(7636003)(83380400001)(956004); DIR:OUT; SFP:1101; X-OriginatorOrg: siemens.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 15:48:43.8388 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 72185135-ed13-4537-4ea7-08db7e387a5e X-MS-Exchange-CrossTenant-Id: 38ae3bcd-9579-4fd4-adda-b42e1495d55a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=38ae3bcd-9579-4fd4-adda-b42e1495d55a; Ip=[194.138.21.74]; Helo=[hybrid.siemens.com] X-MS-Exchange-CrossTenant-AuthSource: HE1EUR01FT051.eop-EUR01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR10MB7002 Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org Siemens Simatic Industrial PCs can monitor the voltage of the CMOS battery with two bits that indicate low or empty state. This can be GPIO or PortIO based. Here we model that as a hwmon voltage. The core driver does the PortIO and provides boilerplate for the GPIO versions. Which are split out to model runtime dependencies while allowing fine-grained kernel configuration. Signed-off-by: Henning Schild Reviewed-by: Hans de Goede --- drivers/platform/x86/Kconfig | 48 ++++ drivers/platform/x86/Makefile | 6 +- .../x86/simatic-ipc-batt-apollolake.c | 51 ++++ .../x86/simatic-ipc-batt-elkhartlake.c | 51 ++++ .../platform/x86/simatic-ipc-batt-f7188x.c | 70 +++++ drivers/platform/x86/simatic-ipc-batt.c | 250 ++++++++++++++++++ drivers/platform/x86/simatic-ipc-batt.h | 20 ++ drivers/platform/x86/simatic-ipc.c | 65 ++++- .../platform_data/x86/simatic-ipc-base.h | 1 + 9 files changed, 547 insertions(+), 15 deletions(-) create mode 100644 drivers/platform/x86/simatic-ipc-batt-apollolake.c create mode 100644 drivers/platform/x86/simatic-ipc-batt-elkhartlake.c create mode 100644 drivers/platform/x86/simatic-ipc-batt-f7188x.c create mode 100644 drivers/platform/x86/simatic-ipc-batt.c create mode 100644 drivers/platform/x86/simatic-ipc-batt.h diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 49c2c4cd8d00..ad15063e1178 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -1086,6 +1086,54 @@ config SIEMENS_SIMATIC_IPC To compile this driver as a module, choose M here: the module will be called simatic-ipc. +config SIEMENS_SIMATIC_IPC_BATT + tristate "CMOS battery driver for Siemens Simatic IPCs" + depends on HWMON + depends on SIEMENS_SIMATIC_IPC + default SIEMENS_SIMATIC_IPC + help + This option enables support for monitoring the voltage of the CMOS + batteries of several Industrial PCs from Siemens. + + To compile this driver as a module, choose M here: the module + will be called simatic-ipc-batt. + +config SIEMENS_SIMATIC_IPC_BATT_APOLLOLAKE + tristate "CMOS Battery monitoring for Simatic IPCs based on Apollo Lake GPIO" + depends on PINCTRL_BROXTON + depends on SIEMENS_SIMATIC_IPC_BATT + default SIEMENS_SIMATIC_IPC_BATT + help + This option enables CMOS battery monitoring for Simatic Industrial PCs + from Siemens based on Apollo Lake GPIO. + + To compile this driver as a module, choose M here: the module + will be called simatic-ipc-batt-apollolake. + +config SIEMENS_SIMATIC_IPC_BATT_ELKHARTLAKE + tristate "CMOS Battery monitoring for Simatic IPCs based on Elkhart Lake GPIO" + depends on PINCTRL_ELKHARTLAKE + depends on SIEMENS_SIMATIC_IPC_BATT + default SIEMENS_SIMATIC_IPC_BATT + help + This option enables CMOS battery monitoring for Simatic Industrial PCs + from Siemens based on Elkhart Lake GPIO. + + To compile this driver as a module, choose M here: the module + will be called simatic-ipc-batt-elkhartlake. + +config SIEMENS_SIMATIC_IPC_BATT_F7188X + tristate "CMOS Battery monitoring for Simatic IPCs based on Nuvoton GPIO" + depends on GPIO_F7188X + depends on SIEMENS_SIMATIC_IPC_BATT + default SIEMENS_SIMATIC_IPC_BATT + help + This option enables CMOS battery monitoring for Simatic Industrial PCs + from Siemens based on Nuvoton GPIO. + + To compile this driver as a module, choose M here: the module + will be called simatic-ipc-batt-elkhartlake. + config WINMATE_FM07_KEYS tristate "Winmate FM07/FM07P front-panel keys driver" depends on INPUT diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index 52dfdf574ac2..522da0d1584d 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -131,7 +131,11 @@ obj-$(CONFIG_INTEL_SCU_IPC_UTIL) += intel_scu_ipcutil.o obj-$(CONFIG_X86_INTEL_LPSS) += pmc_atom.o # Siemens Simatic Industrial PCs -obj-$(CONFIG_SIEMENS_SIMATIC_IPC) += simatic-ipc.o +obj-$(CONFIG_SIEMENS_SIMATIC_IPC) += simatic-ipc.o +obj-$(CONFIG_SIEMENS_SIMATIC_IPC_BATT) += simatic-ipc-batt.o +obj-$(CONFIG_SIEMENS_SIMATIC_IPC_BATT_APOLLOLAKE) += simatic-ipc-batt-apollolake.o +obj-$(CONFIG_SIEMENS_SIMATIC_IPC_BATT_ELKHARTLAKE) += simatic-ipc-batt-elkhartlake.o +obj-$(CONFIG_SIEMENS_SIMATIC_IPC_BATT_F7188X) += simatic-ipc-batt-f7188x.o # Winmate obj-$(CONFIG_WINMATE_FM07_KEYS) += winmate-fm07-keys.o diff --git a/drivers/platform/x86/simatic-ipc-batt-apollolake.c b/drivers/platform/x86/simatic-ipc-batt-apollolake.c new file mode 100644 index 000000000000..0503cb89d8f8 --- /dev/null +++ b/drivers/platform/x86/simatic-ipc-batt-apollolake.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Siemens SIMATIC IPC driver for CMOS battery monitoring + * + * Copyright (c) Siemens AG, 2023 + * + * Authors: + * Henning Schild + */ + +#include +#include +#include +#include +#include + +#include "simatic-ipc-batt.h" + +struct gpiod_lookup_table simatic_ipc_batt_gpio_table_127e = { + .table = { + GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 55, NULL, 0, GPIO_ACTIVE_HIGH), + GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 61, NULL, 1, GPIO_ACTIVE_HIGH), + GPIO_LOOKUP_IDX("apollolake-pinctrl.1", 41, NULL, 2, GPIO_ACTIVE_HIGH), + {} /* Terminating entry */ + }, +}; + +static int simatic_ipc_batt_apollolake_remove(struct platform_device *pdev) +{ + return simatic_ipc_batt_remove(pdev, &simatic_ipc_batt_gpio_table_127e); +} + +static int simatic_ipc_batt_apollolake_probe(struct platform_device *pdev) +{ + return simatic_ipc_batt_probe(pdev, &simatic_ipc_batt_gpio_table_127e); +} + +static struct platform_driver simatic_ipc_batt_driver = { + .probe = simatic_ipc_batt_apollolake_probe, + .remove = simatic_ipc_batt_apollolake_remove, + .driver = { + .name = KBUILD_MODNAME, + }, +}; + +module_platform_driver(simatic_ipc_batt_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:" KBUILD_MODNAME); +MODULE_SOFTDEP("pre: simatic-ipc-batt platform:apollolake-pinctrl"); +MODULE_AUTHOR("Henning Schild "); diff --git a/drivers/platform/x86/simatic-ipc-batt-elkhartlake.c b/drivers/platform/x86/simatic-ipc-batt-elkhartlake.c new file mode 100644 index 000000000000..ecf5ceb167f9 --- /dev/null +++ b/drivers/platform/x86/simatic-ipc-batt-elkhartlake.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Siemens SIMATIC IPC driver for CMOS battery monitoring + * + * Copyright (c) Siemens AG, 2023 + * + * Authors: + * Henning Schild + */ + +#include +#include +#include +#include +#include + +#include "simatic-ipc-batt.h" + +struct gpiod_lookup_table simatic_ipc_batt_gpio_table_bx_21a = { + .table = { + GPIO_LOOKUP_IDX("INTC1020:04", 18, NULL, 0, GPIO_ACTIVE_HIGH), + GPIO_LOOKUP_IDX("INTC1020:04", 19, NULL, 1, GPIO_ACTIVE_HIGH), + GPIO_LOOKUP_IDX("INTC1020:01", 66, NULL, 2, GPIO_ACTIVE_HIGH), + {} /* Terminating entry */ + }, +}; + +static int simatic_ipc_batt_elkhartlake_remove(struct platform_device *pdev) +{ + return simatic_ipc_batt_remove(pdev, &simatic_ipc_batt_gpio_table_bx_21a); +} + +static int simatic_ipc_batt_elkhartlake_probe(struct platform_device *pdev) +{ + return simatic_ipc_batt_probe(pdev, &simatic_ipc_batt_gpio_table_bx_21a); +} + +static struct platform_driver simatic_ipc_batt_driver = { + .probe = simatic_ipc_batt_elkhartlake_probe, + .remove = simatic_ipc_batt_elkhartlake_remove, + .driver = { + .name = KBUILD_MODNAME, + }, +}; + +module_platform_driver(simatic_ipc_batt_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:" KBUILD_MODNAME); +MODULE_SOFTDEP("pre: simatic-ipc-batt platform:elkhartlake-pinctrl"); +MODULE_AUTHOR("Henning Schild "); diff --git a/drivers/platform/x86/simatic-ipc-batt-f7188x.c b/drivers/platform/x86/simatic-ipc-batt-f7188x.c new file mode 100644 index 000000000000..a0189b9289f6 --- /dev/null +++ b/drivers/platform/x86/simatic-ipc-batt-f7188x.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Siemens SIMATIC IPC driver for CMOS battery monitoring + * + * Copyright (c) Siemens AG, 2023 + * + * Authors: + * Henning Schild + */ + +#include +#include +#include +#include +#include +#include + +#include "simatic-ipc-batt.h" + +struct gpiod_lookup_table simatic_ipc_batt_gpio_table_227g = { + .table = { + GPIO_LOOKUP_IDX("gpio-f7188x-7", 6, NULL, 0, GPIO_ACTIVE_HIGH), + GPIO_LOOKUP_IDX("gpio-f7188x-7", 5, NULL, 1, GPIO_ACTIVE_HIGH), + GPIO_LOOKUP_IDX("INTC1020:01", 66, NULL, 2, GPIO_ACTIVE_HIGH), + {} /* Terminating entry */ + }, +}; + +struct gpiod_lookup_table simatic_ipc_batt_gpio_table_bx_39a = { + .table = { + GPIO_LOOKUP_IDX("gpio-f7188x-6", 4, NULL, 0, GPIO_ACTIVE_HIGH), + GPIO_LOOKUP_IDX("gpio-f7188x-6", 3, NULL, 1, GPIO_ACTIVE_HIGH), + {} /* Terminating entry */ + }, +}; + +static int simatic_ipc_batt_f7188x_remove(struct platform_device *pdev) +{ + const struct simatic_ipc_platform *plat = pdev->dev.platform_data; + + if (plat->devmode == SIMATIC_IPC_DEVICE_227G) + return simatic_ipc_batt_remove(pdev, &simatic_ipc_batt_gpio_table_227g); + + return simatic_ipc_batt_remove(pdev, &simatic_ipc_batt_gpio_table_bx_39a); +} + +static int simatic_ipc_batt_f7188x_probe(struct platform_device *pdev) +{ + const struct simatic_ipc_platform *plat = pdev->dev.platform_data; + + if (plat->devmode == SIMATIC_IPC_DEVICE_227G) + return simatic_ipc_batt_probe(pdev, &simatic_ipc_batt_gpio_table_227g); + + return simatic_ipc_batt_probe(pdev, &simatic_ipc_batt_gpio_table_bx_39a); +} + +static struct platform_driver simatic_ipc_batt_driver = { + .probe = simatic_ipc_batt_f7188x_probe, + .remove = simatic_ipc_batt_f7188x_remove, + .driver = { + .name = KBUILD_MODNAME, + }, +}; + +module_platform_driver(simatic_ipc_batt_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:" KBUILD_MODNAME); +MODULE_SOFTDEP("pre: simatic-ipc-batt gpio_f7188x platform:elkhartlake-pinctrl"); +MODULE_AUTHOR("Henning Schild "); diff --git a/drivers/platform/x86/simatic-ipc-batt.c b/drivers/platform/x86/simatic-ipc-batt.c new file mode 100644 index 000000000000..a83272475b9d --- /dev/null +++ b/drivers/platform/x86/simatic-ipc-batt.c @@ -0,0 +1,250 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Siemens SIMATIC IPC driver for CMOS battery monitoring + * + * Copyright (c) Siemens AG, 2023 + * + * Authors: + * Gerd Haeussler + * Henning Schild + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BATT_DELAY_MS (1000 * 60 * 60 * 24) /* 24 h delay */ + +#define SIMATIC_IPC_BATT_LEVEL_FULL 3000 +#define SIMATIC_IPC_BATT_LEVEL_CRIT 2750 +#define SIMATIC_IPC_BATT_LEVEL_EMPTY 0 + +static struct simatic_ipc_batt { + u8 devmode; + long current_state; + struct gpio_desc *gpios[3]; + unsigned long last_updated_jiffies; +} priv; + +static long simatic_ipc_batt_read_gpio(void) +{ + long r = SIMATIC_IPC_BATT_LEVEL_FULL; + + if (priv.gpios[2]) { + gpiod_set_value(priv.gpios[2], 1); + msleep(150); + } + + if (gpiod_get_value_cansleep(priv.gpios[0])) + r = SIMATIC_IPC_BATT_LEVEL_EMPTY; + else if (gpiod_get_value_cansleep(priv.gpios[1])) + r = SIMATIC_IPC_BATT_LEVEL_CRIT; + + if (priv.gpios[2]) + gpiod_set_value(priv.gpios[2], 0); + + return r; +} + +#define SIMATIC_IPC_BATT_PORT_BASE 0x404D +static struct resource simatic_ipc_batt_io_res = + DEFINE_RES_IO_NAMED(SIMATIC_IPC_BATT_PORT_BASE, SZ_1, KBUILD_MODNAME); + +static long simatic_ipc_batt_read_io(struct device *dev) +{ + long r = SIMATIC_IPC_BATT_LEVEL_FULL; + struct resource *res = &simatic_ipc_batt_io_res; + u8 val; + + if (!request_muxed_region(res->start, resource_size(res), res->name)) { + dev_err(dev, "Unable to register IO resource at %pR\n", res); + return -EBUSY; + } + + val = inb(SIMATIC_IPC_BATT_PORT_BASE); + release_region(simatic_ipc_batt_io_res.start, resource_size(&simatic_ipc_batt_io_res)); + + if (val & (1 << 7)) + r = SIMATIC_IPC_BATT_LEVEL_EMPTY; + else if (val & (1 << 6)) + r = SIMATIC_IPC_BATT_LEVEL_CRIT; + + return r; +} + +static long simatic_ipc_batt_read_value(struct device *dev) +{ + unsigned long next_update; + + next_update = priv.last_updated_jiffies + msecs_to_jiffies(BATT_DELAY_MS); + if (time_after(jiffies, next_update) || !priv.last_updated_jiffies) { + switch (priv.devmode) { + case SIMATIC_IPC_DEVICE_127E: + case SIMATIC_IPC_DEVICE_227G: + case SIMATIC_IPC_DEVICE_BX_39A: + priv.current_state = simatic_ipc_batt_read_gpio(); + break; + case SIMATIC_IPC_DEVICE_227E: + priv.current_state = simatic_ipc_batt_read_io(dev); + break; + } + priv.last_updated_jiffies = jiffies; + if (priv.current_state < SIMATIC_IPC_BATT_LEVEL_FULL) + dev_warn(dev, "CMOS battery needs to be replaced."); + } + + return priv.current_state; +} + +static int simatic_ipc_batt_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + switch (attr) { + case hwmon_in_input: + *val = simatic_ipc_batt_read_value(dev); + break; + case hwmon_in_lcrit: + *val = SIMATIC_IPC_BATT_LEVEL_CRIT; + break; + default: + return -EOPNOTSUPP; + } + + return 0; +} + +static umode_t simatic_ipc_batt_is_visible(const void *data, enum hwmon_sensor_types type, + u32 attr, int channel) +{ + if (attr == hwmon_in_input || attr == hwmon_in_lcrit) + return 0444; + + return 0; +} + +static const struct hwmon_ops simatic_ipc_batt_ops = { + .is_visible = simatic_ipc_batt_is_visible, + .read = simatic_ipc_batt_read, +}; + +static const struct hwmon_channel_info *simatic_ipc_batt_info[] = { + HWMON_CHANNEL_INFO(in, HWMON_I_INPUT | HWMON_I_LCRIT), + NULL +}; + +static const struct hwmon_chip_info simatic_ipc_batt_chip_info = { + .ops = &simatic_ipc_batt_ops, + .info = simatic_ipc_batt_info, +}; + +int simatic_ipc_batt_remove(struct platform_device *pdev, struct gpiod_lookup_table *table) +{ + gpiod_remove_lookup_table(table); + return 0; +} +EXPORT_SYMBOL_GPL(simatic_ipc_batt_remove); + +int simatic_ipc_batt_probe(struct platform_device *pdev, struct gpiod_lookup_table *table) +{ + struct simatic_ipc_platform *plat; + struct device *dev = &pdev->dev; + struct device *hwmon_dev; + int err; + + plat = pdev->dev.platform_data; + priv.devmode = plat->devmode; + + switch (priv.devmode) { + case SIMATIC_IPC_DEVICE_127E: + case SIMATIC_IPC_DEVICE_227G: + case SIMATIC_IPC_DEVICE_BX_39A: + case SIMATIC_IPC_DEVICE_BX_21A: + table->dev_id = dev_name(dev); + gpiod_add_lookup_table(table); + break; + case SIMATIC_IPC_DEVICE_227E: + goto nogpio; + default: + return -ENODEV; + } + + priv.gpios[0] = devm_gpiod_get_index(dev, "CMOSBattery empty", 0, GPIOD_IN); + if (IS_ERR(priv.gpios[0])) { + err = PTR_ERR(priv.gpios[0]); + priv.gpios[0] = NULL; + goto out; + } + priv.gpios[1] = devm_gpiod_get_index(dev, "CMOSBattery low", 1, GPIOD_IN); + if (IS_ERR(priv.gpios[1])) { + err = PTR_ERR(priv.gpios[1]); + priv.gpios[1] = NULL; + goto out; + } + + if (table->table[2].key) { + priv.gpios[2] = devm_gpiod_get_index(dev, "CMOSBattery meter", 2, GPIOD_OUT_HIGH); + if (IS_ERR(priv.gpios[2])) { + err = PTR_ERR(priv.gpios[1]); + priv.gpios[2] = NULL; + goto out; + } + } else { + priv.gpios[2] = NULL; + } + +nogpio: + hwmon_dev = devm_hwmon_device_register_with_info(dev, KBUILD_MODNAME, + &priv, + &simatic_ipc_batt_chip_info, + NULL); + if (IS_ERR(hwmon_dev)) { + err = PTR_ERR(hwmon_dev); + goto out; + } + + /* warn about aging battery even if userspace never reads hwmon */ + simatic_ipc_batt_read_value(dev); + + return 0; +out: + simatic_ipc_batt_remove(pdev, table); + + return err; +} +EXPORT_SYMBOL_GPL(simatic_ipc_batt_probe); + +static int simatic_ipc_batt_io_remove(struct platform_device *pdev) +{ + return simatic_ipc_batt_remove(pdev, NULL); +} + +static int simatic_ipc_batt_io_probe(struct platform_device *pdev) +{ + return simatic_ipc_batt_probe(pdev, NULL); +} + +static struct platform_driver simatic_ipc_batt_driver = { + .probe = simatic_ipc_batt_io_probe, + .remove = simatic_ipc_batt_io_remove, + .driver = { + .name = KBUILD_MODNAME, + }, +}; + +module_platform_driver(simatic_ipc_batt_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:" KBUILD_MODNAME); +MODULE_AUTHOR("Henning Schild "); diff --git a/drivers/platform/x86/simatic-ipc-batt.h b/drivers/platform/x86/simatic-ipc-batt.h new file mode 100644 index 000000000000..4545cd3e3026 --- /dev/null +++ b/drivers/platform/x86/simatic-ipc-batt.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Siemens SIMATIC IPC driver for CMOS battery monitoring + * + * Copyright (c) Siemens AG, 2023 + * + * Author: + * Henning Schild + */ + +#ifndef _SIMATIC_IPC_BATT_H +#define _SIMATIC_IPC_BATT_H + +int simatic_ipc_batt_probe(struct platform_device *pdev, + struct gpiod_lookup_table *table); + +int simatic_ipc_batt_remove(struct platform_device *pdev, + struct gpiod_lookup_table *table); + +#endif /* _SIMATIC_IPC_BATT_H */ diff --git a/drivers/platform/x86/simatic-ipc.c b/drivers/platform/x86/simatic-ipc.c index 4402cd354104..6d2c94c17414 100644 --- a/drivers/platform/x86/simatic-ipc.c +++ b/drivers/platform/x86/simatic-ipc.c @@ -21,6 +21,7 @@ static struct platform_device *ipc_led_platform_device; static struct platform_device *ipc_wdt_platform_device; +static struct platform_device *ipc_batt_platform_device; static const struct dmi_system_id simatic_ipc_whitelist[] = { { @@ -37,38 +38,71 @@ static struct { u32 station_id; u8 led_mode; u8 wdt_mode; + u8 batt_mode; } device_modes[] = { - {SIMATIC_IPC_IPC127E, SIMATIC_IPC_DEVICE_127E, SIMATIC_IPC_DEVICE_NONE}, - {SIMATIC_IPC_IPC227D, SIMATIC_IPC_DEVICE_227D, SIMATIC_IPC_DEVICE_NONE}, - {SIMATIC_IPC_IPC227E, SIMATIC_IPC_DEVICE_427E, SIMATIC_IPC_DEVICE_227E}, - {SIMATIC_IPC_IPC227G, SIMATIC_IPC_DEVICE_227G, SIMATIC_IPC_DEVICE_227G}, - {SIMATIC_IPC_IPC277E, SIMATIC_IPC_DEVICE_NONE, SIMATIC_IPC_DEVICE_227E}, - {SIMATIC_IPC_IPC427D, SIMATIC_IPC_DEVICE_427E, SIMATIC_IPC_DEVICE_NONE}, - {SIMATIC_IPC_IPC427E, SIMATIC_IPC_DEVICE_427E, SIMATIC_IPC_DEVICE_427E}, - {SIMATIC_IPC_IPC477E, SIMATIC_IPC_DEVICE_NONE, SIMATIC_IPC_DEVICE_427E}, - {SIMATIC_IPC_IPCBX_39A, SIMATIC_IPC_DEVICE_227G, SIMATIC_IPC_DEVICE_227G}, - {SIMATIC_IPC_IPCPX_39A, SIMATIC_IPC_DEVICE_NONE, SIMATIC_IPC_DEVICE_227G}, - {SIMATIC_IPC_IPCBX_21A, SIMATIC_IPC_DEVICE_BX_21A, SIMATIC_IPC_DEVICE_NONE}, + {SIMATIC_IPC_IPC127E, + SIMATIC_IPC_DEVICE_127E, SIMATIC_IPC_DEVICE_NONE, SIMATIC_IPC_DEVICE_127E}, + {SIMATIC_IPC_IPC227D, + SIMATIC_IPC_DEVICE_227D, SIMATIC_IPC_DEVICE_NONE, SIMATIC_IPC_DEVICE_NONE}, + {SIMATIC_IPC_IPC227E, + SIMATIC_IPC_DEVICE_427E, SIMATIC_IPC_DEVICE_227E, SIMATIC_IPC_DEVICE_227E}, + {SIMATIC_IPC_IPC227G, + SIMATIC_IPC_DEVICE_227G, SIMATIC_IPC_DEVICE_227G, SIMATIC_IPC_DEVICE_227G}, + {SIMATIC_IPC_IPC277E, + SIMATIC_IPC_DEVICE_NONE, SIMATIC_IPC_DEVICE_227E, SIMATIC_IPC_DEVICE_227E}, + {SIMATIC_IPC_IPC427D, + SIMATIC_IPC_DEVICE_427E, SIMATIC_IPC_DEVICE_NONE, SIMATIC_IPC_DEVICE_NONE}, + {SIMATIC_IPC_IPC427E, + SIMATIC_IPC_DEVICE_427E, SIMATIC_IPC_DEVICE_427E, SIMATIC_IPC_DEVICE_NONE}, + {SIMATIC_IPC_IPC477E, + SIMATIC_IPC_DEVICE_NONE, SIMATIC_IPC_DEVICE_427E, SIMATIC_IPC_DEVICE_NONE}, + {SIMATIC_IPC_IPCBX_39A, + SIMATIC_IPC_DEVICE_227G, SIMATIC_IPC_DEVICE_227G, SIMATIC_IPC_DEVICE_BX_39A}, + {SIMATIC_IPC_IPCPX_39A, + SIMATIC_IPC_DEVICE_NONE, SIMATIC_IPC_DEVICE_227G, SIMATIC_IPC_DEVICE_BX_39A}, + {SIMATIC_IPC_IPCBX_21A, + SIMATIC_IPC_DEVICE_BX_21A, SIMATIC_IPC_DEVICE_NONE, SIMATIC_IPC_DEVICE_BX_21A}, }; static int register_platform_devices(u32 station_id) { u8 ledmode = SIMATIC_IPC_DEVICE_NONE; u8 wdtmode = SIMATIC_IPC_DEVICE_NONE; - char *pdevname = KBUILD_MODNAME "_leds"; + u8 battmode = SIMATIC_IPC_DEVICE_NONE; + char *pdevname; int i; - platform_data.devmode = SIMATIC_IPC_DEVICE_NONE; - for (i = 0; i < ARRAY_SIZE(device_modes); i++) { if (device_modes[i].station_id == station_id) { ledmode = device_modes[i].led_mode; wdtmode = device_modes[i].wdt_mode; + battmode = device_modes[i].batt_mode; break; } } + if (battmode != SIMATIC_IPC_DEVICE_NONE) { + pdevname = KBUILD_MODNAME "_batt"; + if (battmode == SIMATIC_IPC_DEVICE_127E) + pdevname = KBUILD_MODNAME "_batt_apollolake"; + if (battmode == SIMATIC_IPC_DEVICE_BX_21A) + pdevname = KBUILD_MODNAME "_batt_elkhartlake"; + if (battmode == SIMATIC_IPC_DEVICE_227G || battmode == SIMATIC_IPC_DEVICE_BX_39A) + pdevname = KBUILD_MODNAME "_batt_f7188x"; + platform_data.devmode = battmode; + ipc_batt_platform_device = + platform_device_register_data(NULL, pdevname, + PLATFORM_DEVID_NONE, &platform_data, + sizeof(struct simatic_ipc_platform)); + if (IS_ERR(ipc_batt_platform_device)) + return PTR_ERR(ipc_batt_platform_device); + + pr_debug("device=%s created\n", + ipc_batt_platform_device->name); + } + if (ledmode != SIMATIC_IPC_DEVICE_NONE) { + pdevname = KBUILD_MODNAME "_leds"; if (ledmode == SIMATIC_IPC_DEVICE_127E) pdevname = KBUILD_MODNAME "_leds_gpio_apollolake"; if (ledmode == SIMATIC_IPC_DEVICE_227G) @@ -144,6 +178,9 @@ static void __exit simatic_ipc_exit_module(void) platform_device_unregister(ipc_wdt_platform_device); ipc_wdt_platform_device = NULL; + + platform_device_unregister(ipc_batt_platform_device); + ipc_batt_platform_device = NULL; } module_init(simatic_ipc_init_module); diff --git a/include/linux/platform_data/x86/simatic-ipc-base.h b/include/linux/platform_data/x86/simatic-ipc-base.h index 00bf18ecb160..1ba47dd6939e 100644 --- a/include/linux/platform_data/x86/simatic-ipc-base.h +++ b/include/linux/platform_data/x86/simatic-ipc-base.h @@ -21,6 +21,7 @@ #define SIMATIC_IPC_DEVICE_227E 4 #define SIMATIC_IPC_DEVICE_227G 5 #define SIMATIC_IPC_DEVICE_BX_21A 6 +#define SIMATIC_IPC_DEVICE_BX_39A 7 struct simatic_ipc_platform { u8 devmode;