From patchwork Tue Jan 7 14:29:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 855648 Received: from mail.systec-electronic.com (mail.systec-electronic.com [77.220.239.22]) (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 E836F1F190E; Tue, 7 Jan 2025 14:29:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.220.239.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736260202; cv=none; b=h75TfzncP1lgWy/wxkgD9Cng6+NFD6mmwfKbRgLSnsyJRKqELOggA8tVMaMSlWzQxGIM2Ayyy2YhtDoRH937nXblbtCHrzUAYPE39BRgfOPzrFl0Gy7xWSHLZpv6Xw8WEj0VKCNGF/58GZawnfzJ1B+HWIJsbdaglflZcY8oW4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736260202; c=relaxed/simple; bh=5udNTovtIvW91CoRKPj1IxA2mdonFGul1jaLiQ3G0TE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=HvWKq9DFuiWGeXyYQ3RMcMmdDkJbFrQd2fpwuDWAdq7U4VcJHvQ6RH0vGskJXlPESb5K3/chbEXNOynDNPiHo58TkcnkY+3JJ+3VI7jsPAuBwLLuW/+A/oDASv8UxZciwY81ZHQ45fKqZU/X9KvWqkna0L9hlT3bdkdBSsQwIc4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=systec-electronic.com; spf=pass smtp.mailfrom=systec-electronic.com; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b=KlI2RocT; arc=none smtp.client-ip=77.220.239.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=systec-electronic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=systec-electronic.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b="KlI2RocT" Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 3DB1A94016AD; Tue, 7 Jan 2025 15:29:50 +0100 (CET) Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10032) with ESMTP id W5gBt2nXpk13; Tue, 7 Jan 2025 15:29:50 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 154B594016B2; Tue, 7 Jan 2025 15:29:50 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com 154B594016B2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1736260190; bh=5nCIec/4jtVJJuHb7SlQlQs/JYbppZp7PbbHAW4D93Y=; h=From:To:Date:Message-ID:MIME-Version; b=KlI2RocTmU08fT3gFYTgOKx7BBc+ZjOBe2Kfnvm+EAxoYm/7F+OZgZIRgHfq39XdR j92csZ0OB2MQW63HWnmiOGCGJPtjJP9jU5OpR/l2ew+EshdMHWqOn45Ncx06rRxBl1 lfNmsdlsDjigsTahMre222Gqwn5bkSA4XoFXWuObAw6LZT6ZAEEdCpNZ0bnheLD/OV jBj6lh/YcbwZ50U8VtkqS8f/KXh6DrqjY9oKvLPkx2RxE65c/DXcClc+rZxGsplBVI 4unOZvoZKUWAC59XXP3Ybbit8d+B5nABK9/5f5VDpheiFdCo0SNdAa8y65wQOauHal 4tkQO+Wi2XRlA== X-Virus-Scanned: amavis at systec-electronic.com Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10026) with ESMTP id zQbqP4NFaxcr; Tue, 7 Jan 2025 15:29:50 +0100 (CET) Received: from ws565760.. (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id A6F6494016AD; Tue, 7 Jan 2025 15:29:49 +0100 (CET) From: Andre Werner To: gregkh@linuxfoundation.org, jirislaby@kernel.org, hvilleneuve@dimonoff.com, andy@kernel.org, devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, lech.perczak@camlingroup.com, krzk+dt@kernel.org, conor+dt@kernel.org, robh@kernel.org, Andre Werner , Krzysztof Kozlowski Subject: [PATCH v3 1/2] dt-bindings: serial: sc16is7xx: Add description for polling mode Date: Tue, 7 Jan 2025 15:29:46 +0100 Message-ID: <20250107142947.327508-1-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.47.1 Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Polling mode is enabled if the "interrupts" property is missing. Thus, this commit deletes "interrupts" entry from "required" section and adds a description for the fallback to polling mode at the "interrupts" entry. Signed-off-by: Andre Werner Acked-by: Krzysztof Kozlowski --- V3: - No changes on source. - Add Acked-By to commit message. --- Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml b/Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml index 88871480018e..ab39b95dae40 100644 --- a/Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml +++ b/Documentation/devicetree/bindings/serial/nxp,sc16is7xx.yaml @@ -23,6 +23,8 @@ properties: maxItems: 1 interrupts: + description: + When missing, device driver uses polling instead. maxItems: 1 clocks: @@ -76,7 +78,6 @@ properties: required: - compatible - reg - - interrupts allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml# From patchwork Tue Jan 7 14:29:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 855912 Received: from mail.systec-electronic.com (mail.systec-electronic.com [77.220.239.22]) (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 E829B1F190A; Tue, 7 Jan 2025 14:29:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.220.239.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736260201; cv=none; b=oyjSlN8ih+008EFtKVMDdeTH92aCPDU/xtM+F5O5CkLTOKqEt5GHCUobRzgx9qgHYOQ72hRL0JmhvBmXrUEj7xUnUSLvfz0epD4oeNlSBzSyPCqA4gPvD5G8TgoMvQOaFKuFVMaYQuB2PzeVmxdQRLRoj/xWPsO6TOf3fy2vW6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736260201; c=relaxed/simple; bh=29V3bJCOF8vsdW9EHS1VvfpqMi+LfwG6voER8itsh2Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FdkUJRV250zwKP2AJAkUuuUi79F5ePaH3tNwUFwI/7T6vsAq73m4Ek5NXklBXH64ITaWJmy8LQnkk3Ko/SbLrvIVHf/Rp3TDUxIu+pZCd+19/ZH/tZOHcTNYo5qOhlgFJFZWB8LNFxrATuuwT1TNTvmeHPlHxpNsET9VHyPPgPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=systec-electronic.com; spf=pass smtp.mailfrom=systec-electronic.com; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b=DnVjxf24; arc=none smtp.client-ip=77.220.239.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=systec-electronic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=systec-electronic.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b="DnVjxf24" Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 8225694016B0; Tue, 7 Jan 2025 15:29:50 +0100 (CET) Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10032) with ESMTP id haWMhQd3bNm8; Tue, 7 Jan 2025 15:29:50 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 5C88494016B2; Tue, 7 Jan 2025 15:29:50 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com 5C88494016B2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1736260190; bh=u1iNfgtj6mwSoixpomtLHRxpohgwvvImlGun5QGjcSs=; h=From:To:Date:Message-ID:MIME-Version; b=DnVjxf24RngGxN4LvXZ4uN9VEzGHazSg0zKxNevKuvgVqPf/kdjHi5lPeIEdKrOId fGzNkp6STdwMeQVJbQtMP/uxxlyoV068fF1qOzDcpE9H4impOTF6kO6fVqmOuFhpR2 XLqhGGoazxA/q6aNQ+R19z5pyiSkDBAc2Qf0/rJrA9z2kQpdHb1QpgM23/1MsiCicR V7qI40jFIPTTjywQkrO6xbErjsDqxtpESNsag3pYs7LneqMV0giB/IVYWnyI7VeNTj IZDMwm2lC5fVjo48EFOHVgrK9FzEukUH+raewb0QfMxzNS7QvYAdsI86f4xbAWc0+G 4vpyyyP7HqyiQ== X-Virus-Scanned: amavis at systec-electronic.com Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10026) with ESMTP id Cgsd-SWaWK0W; Tue, 7 Jan 2025 15:29:50 +0100 (CET) Received: from ws565760.. (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id 0A1DA94016B0; Tue, 7 Jan 2025 15:29:50 +0100 (CET) From: Andre Werner To: gregkh@linuxfoundation.org, jirislaby@kernel.org, hvilleneuve@dimonoff.com, andy@kernel.org, devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, lech.perczak@camlingroup.com, krzk+dt@kernel.org, conor+dt@kernel.org, robh@kernel.org, Andre Werner Subject: [PATCH v3 2/2] serial: sc16is7xx: Add polling feature if no IRQ usage possible Date: Tue, 7 Jan 2025 15:29:47 +0100 Message-ID: <20250107142947.327508-2-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250107142947.327508-1-andre.werner@systec-electronic.com> References: <20250107142947.327508-1-andre.werner@systec-electronic.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fall back to polling mode if no interrupt is configured because not possible. If "interrupts" property is missing in devicetree the driver uses a delayed worker to pull state of interrupt status registers. Signed-off-by: Andre Werner --- V2: - Change warning for polling mode to debug log entry - Correct typo: Resuse -> Reuse - Format define with missing tabs for SC16IS7XX_POLL_PERIOD - Format struct declaration sc16is7xx_one_config with missing tabs for polling and shutdown - Adapt dtbinding with new polling feature V3: - Use suffix with units and drop a comment SC16IS7XX_POLL_PERIOD_MS. Sorry for that miss. - Make Kernel lowercase. --- --- drivers/tty/serial/sc16is7xx.c | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index a3093e09309f..57be5d55205a 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -314,6 +314,7 @@ #define SC16IS7XX_FIFO_SIZE (64) #define SC16IS7XX_GPIOS_PER_BANK 4 +#define SC16IS7XX_POLL_PERIOD_MS 10 #define SC16IS7XX_RECONF_MD BIT(0) #define SC16IS7XX_RECONF_IER BIT(1) #define SC16IS7XX_RECONF_RS485 BIT(2) @@ -348,6 +349,9 @@ struct sc16is7xx_port { u8 mctrl_mask; struct kthread_worker kworker; struct task_struct *kworker_task; + struct kthread_delayed_work poll_work; + bool polling; + bool shutdown; struct sc16is7xx_one p[]; }; @@ -861,6 +865,19 @@ static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) return IRQ_HANDLED; } +static void sc16is7xx_transmission_poll(struct kthread_work *work) +{ + struct sc16is7xx_port *s = container_of(work, struct sc16is7xx_port, poll_work.work); + + /* Reuse standard IRQ handler. Interrupt ID is unused in this context. */ + sc16is7xx_irq(0, s); + + /* Setup delay based on SC16IS7XX_POLL_PERIOD_MS */ + if (!s->shutdown) + kthread_queue_delayed_work(&s->kworker, &s->poll_work, + msecs_to_jiffies(SC16IS7XX_POLL_PERIOD_MS)); +} + static void sc16is7xx_tx_proc(struct kthread_work *ws) { struct uart_port *port = &(to_sc16is7xx_one(ws, tx_work)->port); @@ -1149,6 +1166,7 @@ static int sc16is7xx_config_rs485(struct uart_port *port, struct ktermios *termi static int sc16is7xx_startup(struct uart_port *port) { struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); + struct sc16is7xx_port *s = dev_get_drvdata(port->dev); unsigned int val; unsigned long flags; @@ -1210,6 +1228,11 @@ static int sc16is7xx_startup(struct uart_port *port) uart_port_lock_irqsave(port, &flags); sc16is7xx_enable_ms(port); uart_port_unlock_irqrestore(port, flags); + if (s->polling) { + s->shutdown = false; + kthread_queue_delayed_work(&s->kworker, &s->poll_work, + msecs_to_jiffies(SC16IS7XX_POLL_PERIOD_MS)); + } return 0; } @@ -1232,6 +1255,10 @@ static void sc16is7xx_shutdown(struct uart_port *port) sc16is7xx_power(port, 0); + if (s->polling) { + s->shutdown = true; + kthread_cancel_delayed_work_sync(&s->poll_work); + } kthread_flush_worker(&s->kworker); } @@ -1537,7 +1564,13 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, /* Always ask for fixed clock rate from a property. */ device_property_read_u32(dev, "clock-frequency", &uartclk); + s->polling = !device_property_present(dev, "interrupts"); + if (s->polling) { + dev_dbg(dev, + "No interrupt definition found. Falling back to polling mode.\n"); + irq = 0; + } s->clk = devm_clk_get_optional(dev, NULL); if (IS_ERR(s->clk)) return PTR_ERR(s->clk); @@ -1664,6 +1697,11 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, if (ret) goto out_ports; #endif + if (s->polling) { + /* Initialize kernel thread for polling */ + kthread_init_delayed_work(&s->poll_work, sc16is7xx_transmission_poll); + return 0; + } /* * Setup interrupt. We first try to acquire the IRQ line as level IRQ. @@ -1724,6 +1762,8 @@ void sc16is7xx_remove(struct device *dev) sc16is7xx_power(&s->p[i].port, 0); } + if (s->polling) + kthread_cancel_delayed_work_sync(&s->poll_work); kthread_flush_worker(&s->kworker); kthread_stop(s->kworker_task);