From patchwork Mon Nov 11 11:29:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Costea X-Patchwork-Id: 842647 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2065.outbound.protection.outlook.com [40.107.20.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9A3619C549; Mon, 11 Nov 2024 11:29:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731324578; cv=fail; b=J+QBT5wuCkRDt9CaVjhUBH27AHrPmqKfi7Dyyy4TXFXcDHAGejWjjOQLOtS5uMEqe/4/NwzdPoKxqCor4MhicKs+dNDYu2nNVRrydZNWqdkbUxNRC+SXd1hciQd3Ah7v/tlvAaqd+L+geOtTUFW5g+aYeA81scc/+43+DdC/utc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731324578; c=relaxed/simple; bh=x+SQ4LkHPihEEdpRbCpmHgA0UzGSE+LNZZr9L6b890s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=jhzesQQdiYBcVfOiWJ4uhB7tkBq4IOMmCTcyNKgyNo+SSKUgExkGFJM490FY5UT5VRRD4VXIok0JiSfXjbp07gPYVB8NxcVQ5bfUqMUnqwMvBxdu5ydCwiLH4hZIvUiiQ+9iwy2jW8joK6RjhdM/r6Y0oGl3dtRyqllfSdMifyI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=JnHhrxFQ; arc=fail smtp.client-ip=40.107.20.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="JnHhrxFQ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=unta92UfXOk3/U1c54CVI7zlgPzX+eO6FTX57+BlJtRoIZyMv2fecpwm3Z8eVcVJHCCVaZ46KgkDoQ455aUYDSgL1SIfFctHHNvzNTqmiFQXkPAdTol/BaX/lRQYtg0gxqT2f+gtOlCkLj9yhmKOPrhZT10eD8S3AFWUBWFVZOmI9fgLWnks5bQYXXA9boMGZ1gMHuCUUwRmR3Z1Br+F+IW0gNlxESnMFnn3bMK7r/R6WeOyRjyLG5GsRQMH8R86TdyuLNKCl0soFHnbFGdTHqB7ifec5xQGj5tobePBatZrgQ9fyYMDrlNC7ngvyJ+i1LRQ9+KIzJvsH5LtVY+6Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=fG+Hj1fahqHiHaIj7XnHjzSDHuLftIqClYYXKEdUchw=; b=IWeRTDlZ6ai0fHQKzX7ylvJ15xNd9jCXEk7dKjQiCMr7X456IoTOD5Vhk1XmtaY/mecnZKERxC7EE2HNJtm2F3CzhflDMqd8lxawTN6SPD5Ind+iLNG7+PgdPC5DC7MsJQPvf5P7CtjFj8N1VjSAj6f8IQthKSGeuCXlhAPnx84P5SAhrMivFwHGHbeRFcyHDelGhWD5p7q35K6jNjbNnomUxt+NY46eoxjCmZA83Ap1UTeX8wSv3hxFgVvCuYov77ePh2wkIxnezVRB0icGNo7hqsBqhbY1H90Hkpe0cl78YX9aZmZUoK7LZ4PSzB6F89VLBx5fKxZY9Hu4Sw8G2Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fG+Hj1fahqHiHaIj7XnHjzSDHuLftIqClYYXKEdUchw=; b=JnHhrxFQIE21h3NJj2fAU9hrTeIAMoar2Spt3tUL1OiZqHT5fl9BnZr69q/I/uzEKYVySVtFmmSDM/nWBrVq4V7iJp958nQK6y3l5B4noNrTyqhMPEE2KMPMXFgPXcSvpfgCn7zuJZyHmakDgFfCddxA3ZkDogLiaGiP60cF6u5QvKkoNlS62FGX5ZkOtlYTucMKdi1Qp0wM3hEuRwaur4Ygu4qgvEj3KJeOd70K8Rs6th7LtViR+rXEYdqM/qPSV+WsjXs6Zs8sxAUNWyH7CG8Fk20xDPL2bgsUKzj5QFOFf+dxIPm7iUvKGpKisEbn7PtkQFeJVUtK07lliQAeaQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9251.eurprd04.prod.outlook.com (2603:10a6:10:352::15) by DB9PR04MB9428.eurprd04.prod.outlook.com (2603:10a6:10:368::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.27; Mon, 11 Nov 2024 11:29:30 +0000 Received: from DU0PR04MB9251.eurprd04.prod.outlook.com ([fe80::708f:69ee:15df:6ebd]) by DU0PR04MB9251.eurprd04.prod.outlook.com ([fe80::708f:69ee:15df:6ebd%6]) with mapi id 15.20.8137.018; Mon, 11 Nov 2024 11:29:30 +0000 From: Ciprian Costea To: Greg Kroah-Hartman , Jiri Slaby , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chester Lin Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, NXP S32 Linux , Christophe Lizzi , Alberto Ruiz , Enric Balletbo , Ciprian Marian Costea Subject: [PATCH v4 2/2] serial: fsl_linflexuart: add clock management Date: Mon, 11 Nov 2024 13:29:21 +0200 Message-ID: <20241111112921.2411242-3-ciprianmarian.costea@oss.nxp.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241111112921.2411242-1-ciprianmarian.costea@oss.nxp.com> References: <20241111112921.2411242-1-ciprianmarian.costea@oss.nxp.com> X-ClientProxiedBy: AS4P190CA0012.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:5de::12) To DU0PR04MB9251.eurprd04.prod.outlook.com (2603:10a6:10:352::15) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9251:EE_|DB9PR04MB9428:EE_ X-MS-Office365-Filtering-Correlation-Id: aea894f7-ec02-472b-d4e0-08dd02441bea X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?gL5Lou09kD+z3QOK6/zMZQKtj48vrlI?= =?utf-8?q?tkf6mO54UhY5B+CtS3y4n0EShDq716fW39M5D+mZs2MjSHXOysRM3eovtHDGY1uqB?= =?utf-8?q?+NKYLROuuCuzzU8wT6H5rojqgEVwXvIzAZm2wmCek4xcNFJDg3gD2xKWB1a5icjK7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A?= =?utf-8?q?Vcdb+qE0CtppB/xBcjuzKJAn+Ve64JIaFq0+uSsoI0W1YmCTQQNO57jhl/vIOMCw6?= =?utf-8?q?DvVjHdtShQhjBL99xgq+9talrFUaeItL2IxuuAGu8eRq7dxz6+cn2r+DGc+7KLyno?= =?utf-8?q?tQtiibS+0jh5mJaOcPT+9Vk33VvGtN26oK0Lh86/A6ocK3ti9WwGYc5tChMolzH9L?= =?utf-8?q?DN39tqjhii18BsELmQgcvXPF9Q8vDQJOcpsdGsFUVUhOzOi90iin7hDmsgzCdIrVe?= =?utf-8?q?utMVmiYJDXlox?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU0PR04MB9251.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(376014)(7416014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?VxOA8PmtfOFRKxRyuzUgjFqFiEcj?= =?utf-8?q?lEJaYQbkClOBbGPIkHfCCEoA8S7nPlmFKcvdxNEXEGFDa+t1e5PapQGHbcwNONDxf?= =?utf-8?q?fiKhQyNsCZdDSAUz3bxElYUa6tj1cmRll756hzif7qsP5GYXomQWKGSzgSSvknRuq?= =?utf-8?q?YkEoi1EMeMz08TOgWsAxQEv5hLqZjs7FvfE1Qo5H37LxUq4ULjgYRFvPLdJpIjaOb?= =?utf-8?q?HSUXPOPIAA/XYxmEvwZ6BEg6SLWVAenJeKYbIBKcrlj/LLWVN3gV52pUsqx/IkF/1?= =?utf-8?q?ytQZdMzqxa/TnLsY2emlvmnil3uR5oCIox5Ubdn1w/4sKF35HCqJ7nLshJT7/3QJU?= =?utf-8?q?oDu+t97mDP/bMIZqTYHXeXR/84goNMIQ4T9JrFuoypP/XSg+XmbYaBatzzw433ch1?= =?utf-8?q?G++0WHNDLVDJKj65RJMVM+f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AY870FJErRxVyct+KvJrgYtA3Pf8AFFqyGJC?= =?utf-8?q?a6CFUNjkzpmoiVBKEpOFrgM5p8NtytCVVGZ+MTIbXW8GHzqz3bes2Fc1zgmHDA786?= =?utf-8?q?/VOEGbmNYHMZdn31lH/RG5K6QlahtERyE580v9q/xrQkF3YvooxotGOwGrQZ+MQai?= =?utf-8?q?2oLdg+6gfuX7OyGSKqwOvsc6n8TbSs8/cSAXlbAswkbbjAA6ebZTeXHiD9oR55W92?= =?utf-8?q?IIF0XjltA1MjNubt0yaiOTw1VbHCidaADg=3D=3D?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: aea894f7-ec02-472b-d4e0-08dd02441bea X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9251.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2024 11:29:30.7392 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: THEt37wruZ42uNy2d1igJcI4r8+5dtZls2J6gDGj+xGoKuRz7I8/mv93VK0ESKTAygvqqRr81be2PLgRQX6YfMZzpAbilLa69/qjWQclyKo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9428 From: Ciprian Marian Costea Add optional clock 'ipg' and 'lin' support to NXP LINFlexD UART driver, which is used by S32G2 and S32G3 SoCs. LINFlex driver should perform clock management and not rely on a previous bootloader configuration. Clocking support is added as optional in order to not break existing support for S32V234 SoC. Therefore, there should be no impact if not providing LINFlexD clocks and continue to rely on a bootloader clock configuration and enablement. Signed-off-by: Ciprian Marian Costea --- drivers/tty/serial/fsl_linflexuart.c | 82 +++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 14 deletions(-) diff --git a/drivers/tty/serial/fsl_linflexuart.c b/drivers/tty/serial/fsl_linflexuart.c index e972df4b188d..66b822f36d06 100644 --- a/drivers/tty/serial/fsl_linflexuart.c +++ b/drivers/tty/serial/fsl_linflexuart.c @@ -3,9 +3,10 @@ * Freescale LINFlexD UART serial port driver * * Copyright 2012-2016 Freescale Semiconductor, Inc. - * Copyright 2017-2019 NXP + * Copyright 2017-2019, 2024 NXP */ +#include #include #include #include @@ -120,9 +121,29 @@ #define PREINIT_DELAY 2000 /* us */ +struct linflex_devtype_data { + const char * const *clks_names; + int n_clks; +}; + +struct linflex_port { + struct uart_port port; + struct clk_bulk_data *clks; + const struct linflex_devtype_data *devtype_data; +}; + +static const char * const s32v234_clk_names[] = { + "ipg", "lin", +}; + +static const struct linflex_devtype_data s32v234_data = { + .clks_names = s32v234_clk_names, + .n_clks = ARRAY_SIZE(s32v234_clk_names), +}; + static const struct of_device_id linflex_dt_ids[] = { { - .compatible = "fsl,s32v234-linflexuart", + .compatible = "fsl,s32v234-linflexuart", .data = &s32v234_data, }, { /* sentinel */ } }; @@ -807,12 +828,13 @@ static struct uart_driver linflex_reg = { static int linflex_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; + struct linflex_port *lfport; struct uart_port *sport; struct resource *res; - int ret; + int i, ret; - sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); - if (!sport) + lfport = devm_kzalloc(&pdev->dev, sizeof(*lfport), GFP_KERNEL); + if (!lfport) return -ENOMEM; ret = of_alias_get_id(np, "serial"); @@ -826,8 +848,14 @@ static int linflex_probe(struct platform_device *pdev) return -ENOMEM; } + sport = &lfport->port; sport->line = ret; + lfport->devtype_data = of_device_get_match_data(&pdev->dev); + if (!lfport->devtype_data) + return dev_err_probe(&pdev->dev, -ENODEV, + "Failed to get linflexuart driver data\n"); + sport->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res); if (IS_ERR(sport->membase)) return PTR_ERR(sport->membase); @@ -844,37 +872,63 @@ static int linflex_probe(struct platform_device *pdev) sport->flags = UPF_BOOT_AUTOCONF; sport->has_sysrq = IS_ENABLED(CONFIG_SERIAL_FSL_LINFLEXUART_CONSOLE); - linflex_ports[sport->line] = sport; + lfport->clks = devm_kmalloc_array(&pdev->dev, lfport->devtype_data->n_clks, + sizeof(*lfport->clks), GFP_KERNEL); + if (!lfport->clks) + return -ENOMEM; + + for (i = 0; i < lfport->devtype_data->n_clks; i++) + lfport->clks[i].id = lfport->devtype_data->clks_names[i]; + + ret = devm_clk_bulk_get_optional(&pdev->dev, + lfport->devtype_data->n_clks, lfport->clks); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "Failed to get linflexuart clocks\n"); + + ret = clk_bulk_prepare_enable(lfport->devtype_data->n_clks, + lfport->clks); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "Failed to enable linflexuart clocks\n"); - platform_set_drvdata(pdev, sport); + linflex_ports[sport->line] = sport; + platform_set_drvdata(pdev, lfport); return uart_add_one_port(&linflex_reg, sport); } static void linflex_remove(struct platform_device *pdev) { - struct uart_port *sport = platform_get_drvdata(pdev); + struct linflex_port *lfport = platform_get_drvdata(pdev); - uart_remove_one_port(&linflex_reg, sport); + uart_remove_one_port(&linflex_reg, &lfport->port); } #ifdef CONFIG_PM_SLEEP static int linflex_suspend(struct device *dev) { - struct uart_port *sport = dev_get_drvdata(dev); + struct linflex_port *lfport = dev_get_drvdata(dev); + + uart_suspend_port(&linflex_reg, &lfport->port); - uart_suspend_port(&linflex_reg, sport); + clk_bulk_disable_unprepare(lfport->devtype_data->n_clks, + lfport->clks); return 0; } static int linflex_resume(struct device *dev) { - struct uart_port *sport = dev_get_drvdata(dev); + struct linflex_port *lfport = dev_get_drvdata(dev); + int ret; - uart_resume_port(&linflex_reg, sport); + ret = clk_bulk_prepare_enable(lfport->devtype_data->n_clks, + lfport->clks); + if (ret) + return ret; - return 0; + return uart_resume_port(&linflex_reg, &lfport->port); } #endif