From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A774833B97A for ; Thu, 11 Jun 2026 03:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781149161; cv=none; b=Mg6pMFU1fCj+r5X28EXhjkbTqNMIrMoJMzQUn1/oDkavq5U/IZv0IyHmGASx0ReMqjt8oncFbyZobCR4p3A4itFVOS82TdFbufpw67sBeKleWArFtlLrwqaQP5M/sOmOb6iIpabi+D3Jl2hoi6ZHRuQDyFI9EqqRDOTwAlVRtl8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781149161; c=relaxed/simple; bh=KHFBKElH1lggN2sZB5oI+hYuA6tBhm4+ZNyZCHF4qaU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FZlid1W4rXrGz01nVHnwv3fyEH5Zw3OpLgzUs8NTunuAqqz7vYjQtvDJhsGYzOdqosYhskxaPsl9ZRzfZoDdtLZsVdSvCnp+QhP0sdQreuoJglKe63xymaBM7pFj9Rn+vFvK4fzwWr/o4oEbSO8MnfdghzUkfXsrS85MT+Y+F5w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TqV6TPuU; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TqV6TPuU" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-c85822059d8so4719111a12.1 for ; Wed, 10 Jun 2026 20:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781149159; x=1781753959; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Enn6naQw+wLmV0GhfZ0seolUzIj1ObU+9VW8J0DyP44=; b=TqV6TPuUbgT7qmDT9jHv/gtDGhskne4WdiC/YMANwWjRXUzxPY5JDFpm+rcy4O2ZOM 0eDdFy56sXY6qDzsOpAYAtCPhmuntbXKqm/x/YT63vxloKCGtB8nZz0FTbxoiByeg/06 G297/lVsDU8uF1evMa5/54qtahg+BaHaDjLWsR4dV6sLplIUeYgJgWhJXqShGbWwqXqT BOyPjHYHFWZEahxA3ntddgyx0pY/Ksoy/BtaOAmckRNP+3wCSGAkE9KietrIqe/S3WuC TMIbjeDZboQVxISWpv2sZrKuWrqEbA0OmfE1Hil/zJQFThz2BG/wh1XNZ2ueK6N73SwT V5QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781149159; x=1781753959; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Enn6naQw+wLmV0GhfZ0seolUzIj1ObU+9VW8J0DyP44=; b=VGbQqd0MGFe5iqwYfdachmfmdJ33GdCm5Pws4bTKVeY98XFU8N/5M7yHiWJcJujZTa 0MnmyRPGFLLO+MnFkum+iXd7DW3P8vluniEnCExa5ic2V49HqHdElaa9AGRH1myicRtF kDlE9CUsf5BJBXV0sO9q3QOSYL3QmCraD+WYZHhR8kDOugYcqltWe8WHGn6iRnQXDZLB fpyczsGcbZCrigX244qvhPuWlxm/zWQo/HRjgwTXfH25V//4HMfpdkNHgUDKG8SqRnYJ sxpCqEsp6dl2UIFVMrFCQwOYGQ6i3w7gpCDH0/ecmRVmXELwFf2NOJh3aDSFx95Me63J dXoA== X-Forwarded-Encrypted: i=1; AFNElJ/HyiRjZ1V9jw7FurnctUg/f0muAL9yBDFFaFFwBeVsnVvbwBojmkXmz6iCkYgjwkO7nOTbqECOT3cD6rk=@vger.kernel.org X-Gm-Message-State: AOJu0YxJxDfk08+4N2ypVZ8Z+msT4w88aZdGRspjszGTdRBOaph5hpeM FfMfQAsNHeZ4M1swnBgq3fvGXeSRrV2rfimJh+mn/6QylZyYKJMOIOm7 X-Gm-Gg: Acq92OEtqZMYNaXuvFDcQe9NxwTsO+01g0+UXJ9O3DF0vK/YZZqkwutKsYtCeOY9zin yYd0B69xYwrNfQL/PRx3y+8OlVTrNcv3HnLfpStR1D2POvmGIql7EdQwdPkX1ngZ9tiY0E/mdqN /flCMNGdolV3+PSPGLaN5mnZwX7Y1OuHhofDkT8bOJxoShjYpxCOTot0VhvcXGmyBCKpU4uOzvQ xBr8R4Iih9trfLs14jVkvrNnyKB4ARTJVc3uZ2kxzou6sig66Lj+gHvO9QZlNQvN84WkZfJ1zAj HTow70TsOnsJZnZ9uwrIsgPaWWDQrVoaLxosEOf+wLiWJeF3+hN8rlLySxDl3Le0XDek/k97Nn/ fqGqJMkbiP3jZlHGhWP9wavX7TZwgVpf9QXbshFv4e/WNQ6C6RVja5lXhvQOKSV1tPwOK5jCszG uW2976LItvQmlPeZRXTpCYnsDtHttuRjzKVrT/bqmbq5TtaqNq7H7qz0bRJnYGhrsNBKSgFh/Zi MKIdG8i1mLQNxsyFsVPL+FJcTUif+vHNezDS72mGLLRIqDmAuW08YqT X-Received: by 2002:a05:6a00:1812:b0:842:3801:47b with SMTP id d2e1a72fcca58-84336a29db5mr1024457b3a.18.1781149158983; Wed, 10 Jun 2026 20:39:18 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d:7285:c2ff:fe45:8a32]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84337bb47eesm334548b3a.13.2026.06.10.20.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 20:39:18 -0700 (PDT) From: Rosen Penev To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , linux-kernel@vger.kernel.org (open list:TTY LAYER AND SERIAL DRIVERS), imx@lists.linux.dev (open list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE), linux-arm-kernel@lists.infradead.org (moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE) Subject: [PATCHv3 4/6] serial: mxs-auart: fix IRQ registration ordering and manage console clock Date: Wed, 10 Jun 2026 20:38:54 -0700 Message-ID: <20260611033856.6476-5-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260611033856.6476-1-rosenp@gmail.com> References: <20260611033856.6476-1-rosenp@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Move the main UART IRQ registration after uart_add_one_port so that s->port.state and s->port.lock are initialized before the interrupt handler can run. Mask all UART interrupts before adding the port to prevent spurious IRQs left by the bootloader. After probe succeeds, disable the module clock for non-console ports since startup will re-enable it on port open. For console ports, keep the clock prepared so auart_console_write() can safely call clk_enable() from atomic context. Guard the IRQ handler and get_mctrl with clk_enable/clk_disable since GPIO IRQs and serial-core status queries can fire while the clock is disabled for non-console ports. In remove, disable the clock for console ports to balance the enable done in probe, preventing a clock leak on unbind. Assisted-by: opencode:big-pickle --- drivers/tty/serial/mxs-auart.c | 49 +++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c index 4499e3206e85..e2b656638ab3 100644 --- a/drivers/tty/serial/mxs-auart.c +++ b/drivers/tty/serial/mxs-auart.c @@ -738,9 +738,13 @@ static u32 mxs_auart_modem_status(struct mxs_auart_port *s, u32 mctrl) static u32 mxs_auart_get_mctrl(struct uart_port *u) { struct mxs_auart_port *s = to_auart_port(u); - u32 stat = mxs_read(s, REG_STAT); + u32 stat; u32 mctrl = 0; + clk_enable(s->clk); + stat = mxs_read(s, REG_STAT); + clk_disable(s->clk); + if (stat & AUART_STAT_CTS) mctrl |= TIOCM_CTS; @@ -1079,6 +1083,7 @@ static irqreturn_t mxs_auart_irq_handle(int irq, void *context) struct mxs_auart_port *s = context; u32 mctrl_temp = s->mctrl_prev; + clk_enable(s->clk); uart_port_lock(&s->port); stat = mxs_read(s, REG_STAT); @@ -1118,6 +1123,7 @@ static irqreturn_t mxs_auart_irq_handle(int irq, void *context) } uart_port_unlock(&s->port); + clk_disable(s->clk); return IRQ_HANDLED; } @@ -1603,10 +1609,6 @@ static int mxs_auart_probe(struct platform_device *pdev) } s->port.irq = irq; - ret = devm_request_irq(&pdev->dev, irq, mxs_auart_irq_handle, 0, - dev_name(&pdev->dev), s); - if (ret) - goto out_disable_clk; platform_set_drvdata(pdev, s); @@ -1627,9 +1629,28 @@ static int mxs_auart_probe(struct platform_device *pdev) mxs_auart_reset_deassert(s); + /* Mask all UART interrupts to prevent spurious IRQs from bootloader */ + mxs_write(0, s, REG_INTR); + ret = uart_add_one_port(&auart_driver, &s->port); - if (ret) - goto out_free_qpio_irq; + if (ret) { + auart_port[s->port.line] = NULL; + goto out_disable_clk; + } + + /* + * Request the main IRQ after uart_add_one_port so that + * s->port.state and s->port.lock are initialized before + * the handler can run in response to a bootloader-left + * interrupt. + */ + ret = devm_request_irq(&pdev->dev, irq, mxs_auart_irq_handle, 0, + dev_name(&pdev->dev), s); + if (ret) { + uart_remove_one_port(&auart_driver, &s->port); + auart_port[s->port.line] = NULL; + goto out_disable_clk; + } /* ASM9260 don't have version reg */ if (is_asm9260_auart(s)) { @@ -1641,10 +1662,16 @@ static int mxs_auart_probe(struct platform_device *pdev) (version >> 16) & 0xff, version & 0xffff); } - return 0; + /* + * Disable clock -- startup will re-enable when the port is opened. + * For the console port the clock must stay prepared so that + * auart_console_write() can safely call clk_enable() from + * atomic context. + */ + if (!uart_console(&s->port)) + clk_disable_unprepare(s->clk); -out_free_qpio_irq: - auart_port[s->port.line] = NULL; + return 0; out_disable_clk: clk_disable_unprepare(s->clk); @@ -1657,6 +1684,8 @@ static void mxs_auart_remove(struct platform_device *pdev) uart_remove_one_port(&auart_driver, &s->port); auart_port[s->port.line] = NULL; + if (uart_console(&s->port)) + clk_disable_unprepare(s->clk); } static struct platform_driver mxs_auart_driver = { -- 2.54.0