From patchwork Fri Jun 7 20:16:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Tomer X-Patchwork-Id: 10982749 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D9B4A92A for ; Fri, 7 Jun 2019 20:19:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C547F27031 for ; Fri, 7 Jun 2019 20:19:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9A6E28BA6; Fri, 7 Jun 2019 20:19:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4628D27031 for ; Fri, 7 Jun 2019 20:19:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hZLIK-0007jE-Jh; Fri, 07 Jun 2019 20:17:00 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hZLIJ-0007j9-W2 for xen-devel@lists.xenproject.org; Fri, 07 Jun 2019 20:17:00 +0000 X-Inumbo-ID: 33d45f09-8961-11e9-8980-bc764e045a96 Received: from mail-pl1-x642.google.com (unknown [2607:f8b0:4864:20::642]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 33d45f09-8961-11e9-8980-bc764e045a96; Fri, 07 Jun 2019 20:16:58 +0000 (UTC) Received: by mail-pl1-x642.google.com with SMTP id a93so1232564pla.7 for ; Fri, 07 Jun 2019 13:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=P+vzjtp1i44txySUhOSs0ClNAsx/SX8KzzDN/ABCcHA=; b=Rq4m8h4RliGU0ykVi+KjpYlzFaE5803cX8T9xqTIXcYqk4OZtC59Z/8LXeJ6kye7+q HtIFpQEBcVl0vL74ugArv64kgW1BcxaDeyETCidPjwOwuHWMzIU79JpOpM0tiBeM+OlM RhLQKpKyN86ZviftTZ8B2n4dcn7HpVX62XRx3yzBVCzwHymUvWqQHbGIO8hCy+kToxWZ 7ED6NTWaTkhNoDIaGzqMLBX0tiDQcj6A3EbjTVqx7fk8p3D8BwJ3boFfzbYc0utqYYUL 3tL2pgt1zDMSikLAdTa8Xrgvi/eVA56MWJeZAVDMuaPlJv9ITTzRsBXBqOJ2RpsD01kU uWhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=P+vzjtp1i44txySUhOSs0ClNAsx/SX8KzzDN/ABCcHA=; b=g+wJTbuTYA1T9lPOBeDfV2K+JbsuFbdstcoujekuiPnv1IElXQMIj9/oN2n0Mi6Vdy LYlSevDQgMHfASkxdzDAPd2x42RbEqUE3PLeMChunWBZgHo+Tc42YG66W39V18iReQ9g b90u+dl4DlVSe7Jg3aOasYg+muorZNxjGZGBEX1UNBGWub3qqQBlfOJkbh+6RDcLaWpS os6i5WBRTcrXPcrjVN5+ibws2wJrGhxFoZ3JceIrwur5MPMWr2rwR/npyAI26FS0vpw8 XwwZQP39kdJDZWOGovaeNjs3ko0xyYK9+nNsHToiHeo58/zfnl9RM5nJzQ6pa4YJr3Wr /Vmg== X-Gm-Message-State: APjAAAX/SlmfhsKNFqwGYCuK4ELF79TIiCnxuYMUAzxbaILwnoN5dclD ko7HyS6mx+IEMd6TPs4FFR6XDuE4 X-Google-Smtp-Source: APXvYqyhr83QMokrjPqmMVUNglnmoksowai/QwtttTkouYNjXvIXJRSHY9ZfREctTqg38/TBwZe9Qw== X-Received: by 2002:a17:902:42a5:: with SMTP id h34mr20024752pld.16.1559938617704; Fri, 07 Jun 2019 13:16:57 -0700 (PDT) Received: from localhost.localdomain ([223.233.80.237]) by smtp.gmail.com with ESMTPSA id a12sm4407502pgq.0.2019.06.07.13.16.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Jun 2019 13:16:56 -0700 (PDT) From: Amit Singh Tomar To: xen-devel@lists.xenproject.org Date: Sat, 8 Jun 2019 01:46:35 +0530 Message-Id: <1559938596-5696-2-git-send-email-amittomer25@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559938596-5696-1-git-send-email-amittomer25@gmail.com> References: <1559938596-5696-1-git-send-email-amittomer25@gmail.com> Subject: [Xen-devel] [RFC PATCH 1/2] xen/arm: Add i.MX8MQ SoCs earlyprintk support X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: andre.przywara@arm.com, julien.grall@arm.com, sstabellini@kernel.org, peng.fan@nxp.com, Amit Singh Tomar MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch adds earlyprintk support for i.MX8MQ SoC based boards. As with most of other debug code for other platforms, uart is initialized by bootloaders(for instance u-boot[1]). [1]:https://github.com/u-boot/u-boot/blob/master/drivers/serial/serial_mxc.c#L141 Signed-off-by: Amit Singh Tomar --- xen/arch/arm/arm64/debug-imx8mq.inc | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 xen/arch/arm/arm64/debug-imx8mq.inc diff --git a/xen/arch/arm/arm64/debug-imx8mq.inc b/xen/arch/arm/arm64/debug-imx8mq.inc new file mode 100644 index 0000000..ec331dc --- /dev/null +++ b/xen/arch/arm/arm64/debug-imx8mq.inc @@ -0,0 +1,54 @@ +/* + * xen/arch/arm/arm64/debug-imx8mq.inc + * + * IMX8MQ specific debug code. + * + * Copyright (c) 2019, Amit Singh Tomar . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see . + */ + +#define UTXD 0x40 +#define UTS 0xb4 +#define UTS_TXEMPTY 3<<1 + +.macro early_uart_init xb, c +/* Uart has already been initialized by bootloader Firmware, for instance by TF-A */ +.endm + +/* + * IMX8MQ UART wait UART to be ready to transmit + * xb: register which contains the UART base address + * c: scratch register + */ +.macro early_uart_ready xb c +1: + ldr w\c, [\xb, #UTS] /* UART Test Register */ + tbz w\c, #UTS_TXEMPTY, 1b /* Check TXEMPTY bit */ +.endm + +/* + * IMX8MQ UART transmit character + * xb: register which contains the UART base address + * wt: register which contains the character to transmit + */ +.macro early_uart_transmit xb wt + str \wt, [\xb, #UTXD] +.endm + +/* + * Local variables: + * mode: ASM + * indent-tabs-mode: nil + * End: + */ From patchwork Fri Jun 7 20:16:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Tomer X-Patchwork-Id: 10982747 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 972101398 for ; Fri, 7 Jun 2019 20:18:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 826C527031 for ; Fri, 7 Jun 2019 20:18:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 760EF28BA6; Fri, 7 Jun 2019 20:18:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 86DD827031 for ; Fri, 7 Jun 2019 20:18:39 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hZLIP-0007jZ-US; Fri, 07 Jun 2019 20:17:05 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hZLIO-0007jU-Sp for xen-devel@lists.xenproject.org; Fri, 07 Jun 2019 20:17:04 +0000 X-Inumbo-ID: 36451464-8961-11e9-8980-bc764e045a96 Received: from mail-pg1-x543.google.com (unknown [2607:f8b0:4864:20::543]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 36451464-8961-11e9-8980-bc764e045a96; Fri, 07 Jun 2019 20:17:03 +0000 (UTC) Received: by mail-pg1-x543.google.com with SMTP id e6so1708948pgd.9 for ; Fri, 07 Jun 2019 13:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ly5R+H10S5abdlkuxBh62hCykSR5MjUgLJv/9fngX3o=; b=iVcxuC8ZHBzyx1B13nnzjSTVHfPBrLzRvgifmo6ryxfOZthK0W1RFBwmGmAowOohG8 oFjSXuOXrd5TNYf5quhLWKvwyGBBPdyUQofQUcZJfEb6Bzzs7BwewgGFBYwioHgjj2YM adn4q57D4+Q2MXNtJOFt5mdoLEz2HnFoypg2ghxxcBzOTZj60sbbqBCWIyYgmUJ12hsJ H6PyBQaIP7+3U9hbnhMnKZ9OA9hy8hAQ7lzqS9Eqcjt1Yo2zhlAuy+m718D/kCePpIni qOu5qrdNgKGc2E7WGpRLmU53H3AViVnkXCiH3i9kaY6AYpjpIMrUKLUt4Iqv/mviHapH VKlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ly5R+H10S5abdlkuxBh62hCykSR5MjUgLJv/9fngX3o=; b=IMPeXLuaoHcZgN5ua1LqLK2SevXLJb3kAPeiWH6ATopFfa1NtO6gY5V02d9nUyE9dj KyU1izirPxPAN+XmKIYheU9h+04VLJsXdxjlpcSVrr7eoV/9atZ3K7mSktNVytZm8meh Nkp1IsJumTfaS5320HLSqqeH2AQhkG4gtz9sXVGVpMDSzEonUwVaCEXrxWA7Yl+Pc3gg dNxb7xPPA+FcMVt4hON0Qp35ocK3QrVi4NibFEbxuAEkMhZQT0wvVvWKdkchOgnJPp5K ydj8jR2u0pOImEhRdKGSkPo5JrQOzFnFPntWrjj6bzKoAIH9VzQlCjcdj2mEfUQW5n2P QACg== X-Gm-Message-State: APjAAAXx3DpMQZFq0IL/eVlXy90LBY0YBt/SnxDqC/3bDaHH/2hd+wx5 xRuW0JKSbJ0yZYJ6VauBPGy9y73N X-Google-Smtp-Source: APXvYqwZH0/pAriyuJ3WXSz13BdJwuBnxFLz9hL1xibqc6kcBcGhSIeRVn+u43w9QFxVvKfhh18eiw== X-Received: by 2002:a62:3287:: with SMTP id y129mr4707152pfy.251.1559938621744; Fri, 07 Jun 2019 13:17:01 -0700 (PDT) Received: from localhost.localdomain ([223.233.80.237]) by smtp.gmail.com with ESMTPSA id a12sm4407502pgq.0.2019.06.07.13.16.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Jun 2019 13:17:00 -0700 (PDT) From: Amit Singh Tomar To: xen-devel@lists.xenproject.org Date: Sat, 8 Jun 2019 01:46:36 +0530 Message-Id: <1559938596-5696-3-git-send-email-amittomer25@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559938596-5696-1-git-send-email-amittomer25@gmail.com> References: <1559938596-5696-1-git-send-email-amittomer25@gmail.com> Subject: [Xen-devel] [RFC PATCH 2/2] xen/arm: Add UART driver for i.MX8MQ SoC X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: andre.przywara@arm.com, julien.grall@arm.com, sstabellini@kernel.org, peng.fan@nxp.com, Amit Singh Tomar MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch adds driver for UART controller found on i.MX8MQ SoC and it has been tested on nitrogen8m board. Controller register defination and some other references has drawn from Linux kernel driver[1] v5.2. [1]:https://github.com/torvalds/linux/blob/master/drivers/tty/serial/imx.c Signed-off-by: Amit Singh Tomar --- xen/drivers/char/Kconfig | 8 ++ xen/drivers/char/Makefile | 1 + xen/drivers/char/imx8mq-uart.c | 306 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 315 insertions(+) create mode 100644 xen/drivers/char/imx8mq-uart.c diff --git a/xen/drivers/char/Kconfig b/xen/drivers/char/Kconfig index b572305..f822af5 100644 --- a/xen/drivers/char/Kconfig +++ b/xen/drivers/char/Kconfig @@ -12,6 +12,14 @@ config HAS_CADENCE_UART This selects the Xilinx Zynq Cadence UART. If you have a Xilinx Zynq based board, say Y. +config HAS_IMX8MQ + bool "i.MX8MQ UART " + default y + depends on ARM_64 + help + This selects the NXP i.MX UART. If you have a NXP i.MX8MQ + based board, say Y. + config HAS_MVEBU bool "Marvell MVEBU UART driver" default y diff --git a/xen/drivers/char/Makefile b/xen/drivers/char/Makefile index 7c646d7..aa1bb29 100644 --- a/xen/drivers/char/Makefile +++ b/xen/drivers/char/Makefile @@ -1,6 +1,7 @@ obj-y += console.o obj-$(CONFIG_HAS_NS16550) += ns16550.o obj-$(CONFIG_HAS_CADENCE_UART) += cadence-uart.o +obj-$(CONFIG_HAS_IMX8MQ) += imx8mq-uart.o obj-$(CONFIG_HAS_PL011) += pl011.o obj-$(CONFIG_HAS_EXYNOS4210) += exynos4210-uart.o obj-$(CONFIG_HAS_MESON) += meson-uart.o diff --git a/xen/drivers/char/imx8mq-uart.c b/xen/drivers/char/imx8mq-uart.c new file mode 100644 index 0000000..90fd649 --- /dev/null +++ b/xen/drivers/char/imx8mq-uart.c @@ -0,0 +1,306 @@ +/* + * xen/drivers/char/imx8mq-uart.c + * + * Driver for i.MX8MQ UART. + * + * Copyright (c) 2019, Amit Singh Tomar . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see . + */ + +#include +#include +#include +#include +#include +#include + +/* Register definitions */ +#define URXD 0x0 /* Receiver Register */ +#define UTXD 0x40 /* Transmitter Register */ +#define UCR1 0x80 /* Control Register 1 */ +#define UCR2 0x84 /* Control Register 2 */ +#define UCR4 0x8c /* Control Register 4 */ +#define USR1 0x94 /* Status Register 1 */ +#define USR2 0x98 /* Status Register 2 */ +#define UBIR 0xa4 /* BRM Incremental Register */ +#define UBMR 0xa8 /* BRM Modulator Register */ +#define UTS 0xb4 /* UART Test Register */ + +/* UART Control Register Bit Fields */ +#define UCR1_ADEN (1<<15) /* Auto dectect interrupt */ +#define UCR1_TRDYEN (1<<13) /* Transmitter ready interrupt enable */ +#define UCR1_IDEN (1<<12) /* Idle condition interrupt */ +#define UCR1_RRDYEN (1<<9) /* Recv ready interrupt enable */ +#define UCR1_TXMPTYEN (1<<6) /* Transimitter empty interrupt enable */ +#define UCR1_RTSDEN (1<<5) /* RTS delta interrupt enable */ +#define UCR1_TDMAEN (1<<3) /* Transmitter ready DMA enable */ +#define UCR1_UARTEN (1<<0) /* UART enabled */ + +#define UCR2_TXEN (1<<2) /* Transmitter enabled */ +#define UCR2_RXEN (1<<1) /* Receiver enabled */ +#define UCR2_IRTS (1<<14) /* Ignore RTS pin */ +#define UCR2_SRST (1<<0) /* SW reset */ +#define UCR2_WS (1<<5) /* Word size */ +#define UCR4_TCEN (1<<3) /* Transmit complete interrupt enable */ +#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */ + +#define UTS_TXEMPTY (1<<6) /* TxFIFO empty */ +#define UTS_RXEMPTY (1<<5) /* RxFIFO empty */ +#define UTS_TXFULL (1<<4) /* TxFIFO full */ + +#define USR1_TRDY (1<<13) /* Transmitter ready interrupt/dma flag */ +#define USR1_RRDY (1<<9) /* Receiver ready interrupt/dma flag */ + +#define USR2_TXDC (1<<3) /* Transmitter complete */ + +#define TXFIFO_SIZE 32 + +#define setbits(addr, set) writel((readl(addr) | (set)), (addr)) +#define clrbits(addr, clear) writel((readl(addr) & ~(clear)), (addr)) + +static struct imx8mq_uart { + unsigned int irq; + void __iomem *regs; + struct irqaction irqaction; + struct vuart_info vuart; +} imx8mq_com; + +static void imx8mq_uart_interrupt(int irq, void *data, + struct cpu_user_regs *regs) +{ + struct serial_port *port = data; + struct imx8mq_uart *uart = port->uart; + uint32_t st1 = readl(uart->regs + USR1); + uint32_t st2 = readl(uart->regs + USR2); + + if ( st1 & (USR1_RRDY) ) + serial_rx_interrupt(port, regs); + + if ( (st1 & USR1_TRDY) || (st2 & USR2_TXDC) ) + serial_tx_interrupt(port, regs); +} + +static void set_baudrate(struct imx8mq_uart *uart) +{ + /* Needed for automatic baud rate detection */ + writel(0xf, uart->regs + UBIR); + writel((25000000 / (2 * 115200)), uart->regs + UBMR); + writel((UCR2_WS | UCR2_IRTS | UCR2_RXEN | UCR2_TXEN | UCR2_SRST), + uart->regs + UCR2); + writel(UCR1_UARTEN, uart->regs + UCR1); +} + +static void __init imx8mq_uart_init_preirq(struct serial_port *port) +{ + struct imx8mq_uart *uart = port->uart; + + clrbits(uart->regs + UCR1, + UCR1_ADEN | UCR1_IDEN | UCR1_RRDYEN | UCR1_RTSDEN); + + /* Disable receiver */ + clrbits(uart->regs + UCR2, UCR2_RXEN); +} + +static void __init imx8mq_uart_init_postirq(struct serial_port *port) +{ + struct imx8mq_uart *uart = port->uart; + + uart->irqaction.handler = imx8mq_uart_interrupt; + uart->irqaction.name = "imx8mq_uart"; + uart->irqaction.dev_id = port; + + if ( setup_irq(uart->irq, 0, &uart->irqaction) != 0 ) + { + printk("Failed to allocated imx8mq_uart IRQ %d\n", uart->irq); + return; + } + + setbits(uart->regs + UCR1, + UCR1_ADEN | UCR1_TRDYEN | UCR1_IDEN + | UCR1_RRDYEN | UCR1_TXMPTYEN | UCR1_RTSDEN); + /* Enable receiver */ + setbits(uart->regs + UCR2, UCR2_RXEN); + /* Generally we do soft reset in preirq stage but here reset does empty the + Tx FIFO and triggers Tx interrupt which should be enabled by now + */ + clrbits(uart->regs + UCR2, UCR2_SRST); + while (!(readl(uart->regs + UCR2) & UCR2_SRST)) + ; + + set_baudrate(uart); +} + +static void imx8mq_uart_suspend(struct serial_port *port) +{ + BUG(); +} + +static void imx8mq_uart_resume(struct serial_port *port) +{ + BUG(); +} + +static void imx8mq_uart_putc(struct serial_port *port, char c) +{ + struct imx8mq_uart *uart = port->uart; + + writel(c, uart->regs + UTXD); +} + +static int imx8mq_uart_tx_ready(struct serial_port *port) +{ + struct imx8mq_uart *uart = port->uart; + uint32_t reg; + + reg = readl(uart->regs + UTS); + + if( reg & UTS_TXEMPTY) + return TXFIFO_SIZE; + if ( reg & UTS_TXFULL) + return 0; + + return 1; +} + +static void imx8mq_uart_stop_tx(struct serial_port *port) +{ + + struct imx8mq_uart *uart = port->uart; + + setbits(uart->regs + UCR1, UCR1_RRDYEN); + clrbits(uart->regs + UCR1, (UCR1_TXMPTYEN | UCR1_TDMAEN)); + clrbits(uart->regs + UCR4, UCR4_TCEN); +} + +static void imx8mq_uart_start_tx(struct serial_port *port) +{ + struct imx8mq_uart *uart = port->uart; + + clrbits(uart->regs + UCR4, UCR4_DREN); + clrbits(uart->regs + UCR1, UCR1_TDMAEN | UCR1_RRDYEN); + setbits(uart->regs + UCR2, UCR2_TXEN | UCR2_RXEN); + setbits(uart->regs + UCR1, UCR1_TXMPTYEN); +} + + +static int __init imx8mq_irq(struct serial_port *port) +{ + struct imx8mq_uart *uart = port->uart; + + return uart->irq; +} + +static const struct vuart_info *imx8mq_vuart_info(struct serial_port *port) +{ + struct imx8mq_uart *uart = port->uart; + + return &uart->vuart; +} + +static int imx8mq_uart_getc(struct serial_port *port, char *c) +{ + struct imx8mq_uart *uart = port->uart; + + if ( (readl(uart->regs + UTS) & UTS_RXEMPTY) ) + return 0; + + *c = readl(uart->regs + URXD) & 0xff; + + return 1; +} + +static struct uart_driver __read_mostly imx8mq_uart_driver = { + .init_preirq = imx8mq_uart_init_preirq, + .init_postirq = imx8mq_uart_init_postirq, + .endboot = NULL, + .suspend = imx8mq_uart_suspend, + .resume = imx8mq_uart_resume, + .putc = imx8mq_uart_putc, + .getc = imx8mq_uart_getc, + .tx_ready = imx8mq_uart_tx_ready, + .stop_tx = imx8mq_uart_stop_tx, + .start_tx = imx8mq_uart_start_tx, + .irq = imx8mq_irq, + .vuart_info = imx8mq_vuart_info, +}; + +static int __init imx8mq_uart_init(struct dt_device_node *dev, const void *data) +{ + const char *config = data; + struct imx8mq_uart *uart; + int res; + u64 addr, size; + + if ( strcmp(config, "") ) + printk("WARNING: UART configuration is not supported\n"); + + uart = &imx8mq_com; + + res = dt_device_get_address(dev, 0, &addr, &size); + if ( res ) + { + printk("imx8mq3700: Unable to retrieve the base address of the UART\n"); + return res; + } + + res = platform_get_irq(dev, 0); + if ( res < 0 ) + { + printk("imx8mq: Unable to retrieve the IRQ\n"); + return -EINVAL; + } + + uart->irq = res; + + uart->regs = ioremap_nocache(addr, size); + if ( !uart->regs ) + { + printk("imx8mq3700: Unable to map the UART memory\n"); + return -ENOMEM; + } + + uart->vuart.base_addr = addr; + uart->vuart.size = size; + uart->vuart.data_off = UCR1; + uart->vuart.status_off = UTS; + uart->vuart.status = USR1; + + /* Register with generic serial driver. */ + serial_register_uart(SERHND_DTUART, &imx8mq_uart_driver, uart); + + dt_device_set_used_by(dev, DOMID_XEN); + + return 0; +} + +static const struct dt_device_match imx8mq_dt_match[] __initconst = +{ + DT_MATCH_COMPATIBLE("fsl,imx6q-uart"), + DT_MATCH_COMPATIBLE("fsl,imx8mq-uart"), + { /* sentinel */ }, +}; + +DT_DEVICE_START(imx8mq, "NXP imx8mq UART", DEVICE_SERIAL) + .dt_match = imx8mq_dt_match, + .init = imx8mq_uart_init, +DT_DEVICE_END + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */