From nobody Sat May 4 09:00:50 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1559938704; cv=none; d=zoho.com; s=zohoarc; b=cRYa022+C9qUznmHMsuN/2T8EVHuT2xiCKGvFezMgFmFlUnOpl2jTBW99PoRXADa5go+rDYRMosSoMlgpAr84mQTkeVc7THszoOdwGMeYoewCVH15+BkDbYL03yc5VjJny+vJzrg14SGzFEF8uLEMtA7RG/Tku3yxe+8DrqIcW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559938704; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=t0Fz+Srn7D/QoWa1rytj9WX/s2Iv7kWcoW1bwqc0aVU=; b=luOuMVPML3P3XYkAf2u9y9R77LQo7LRYYCiwDbTAu4djwZSDeB9rVzrOZICzDf4APRCYj+1IlI+rTfic+Phwi2980mUEmWiaslbUWL5+cP9JGXlyF71C4V3jyUlT0ZspZYIdGK451iGGPI8yT8dfjCk+7xomzv/tVGIW1sEmQwM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559938704537220.99423082250178; Fri, 7 Jun 2019 13:18:24 -0700 (PDT) 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 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) 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) X-Inumbo-ID: 33d45f09-8961-11e9-8980-bc764e045a96 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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: + */ --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat May 4 09:00:50 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1559938707; cv=none; d=zoho.com; s=zohoarc; b=awtGzhEnfecJ4ORC1E29Tp3Nzhd4rvO3Ibxup79uF8f5AmmUZfMixCr38oyP5Arb5+YW2yiTWypfKrvcHLUTIEJ3tWieoBr9a5NMN5avEBi5BVLfrC2Bz85tunEnWeyEveVUJWvP4e+uEJRzRvxfx2f8hOnx+NqqDMvzGETSlgY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559938707; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=/WwDQy28PRjCkHFgO4H6Ey4OheIYNNYWJ0x8XvA3dtk=; b=ffS0fsc2VLcimsVWlrsvZK19Cce8nhpCCU0Z+L3Qo6iCMMU6liXNKhn7xGq5L248jSYUV0dwZ9TQD5/xCTamrh7GYD28FBN8/gndfDqJR45qkCELGhoRLdOOaiIJnNSvynJ91pCPZo2oEsuiTs4qjQeK27YkkjAfGhVBnl8NfTk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559938707537697.948271119183; Fri, 7 Jun 2019 13:18:27 -0700 (PDT) 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 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) 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) X-Inumbo-ID: 36451464-8961-11e9-8980-bc764e045a96 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Lin= ux 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. =20 +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 +=3D console.o obj-$(CONFIG_HAS_NS16550) +=3D ns16550.o obj-$(CONFIG_HAS_CADENCE_UART) +=3D cadence-uart.o +obj-$(CONFIG_HAS_IMX8MQ) +=3D imx8mq-uart.o obj-$(CONFIG_HAS_PL011) +=3D pl011.o obj-$(CONFIG_HAS_EXYNOS4210) +=3D exynos4210-uart.o obj-$(CONFIG_HAS_MESON) +=3D 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 =3D data; + struct imx8mq_uart *uart =3D port->uart; + uint32_t st1 =3D readl(uart->regs + USR1); + uint32_t st2 =3D 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); =20 + writel(UCR1_UARTEN, uart->regs + UCR1); +} + +static void __init imx8mq_uart_init_preirq(struct serial_port *port) +{ + struct imx8mq_uart *uart =3D 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 =3D port->uart; + + uart->irqaction.handler =3D imx8mq_uart_interrupt; + uart->irqaction.name =3D "imx8mq_uart"; + uart->irqaction.dev_id =3D port; + + if ( setup_irq(uart->irq, 0, &uart->irqaction) !=3D 0 ) + { + printk("Failed to allocated imx8mq_uart IRQ %d\n", uart->irq); + return; + } + + setbits(uart->regs + UCR1, + UCR1_ADEN | UCR1_TRDYEN | UCR1_IDEN=20 + | 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 empt= y 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 =3D port->uart; + + writel(c, uart->regs + UTXD); +} + +static int imx8mq_uart_tx_ready(struct serial_port *port) +{ + struct imx8mq_uart *uart =3D port->uart; + uint32_t reg; + + reg =3D 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 =3D port->uart; + =20 + 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 =3D 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 =3D port->uart; + + return uart->irq; +} + +static const struct vuart_info *imx8mq_vuart_info(struct serial_port *port) +{ + struct imx8mq_uart *uart =3D port->uart; + + return &uart->vuart; +} + +static int imx8mq_uart_getc(struct serial_port *port, char *c) +{ + struct imx8mq_uart *uart =3D port->uart; + + if ( (readl(uart->regs + UTS) & UTS_RXEMPTY) ) + return 0; + + *c =3D readl(uart->regs + URXD) & 0xff; + + return 1; +} + +static struct uart_driver __read_mostly imx8mq_uart_driver =3D { + .init_preirq =3D imx8mq_uart_init_preirq, + .init_postirq =3D imx8mq_uart_init_postirq, + .endboot =3D NULL, + .suspend =3D imx8mq_uart_suspend, + .resume =3D imx8mq_uart_resume, + .putc =3D imx8mq_uart_putc, + .getc =3D imx8mq_uart_getc, + .tx_ready =3D imx8mq_uart_tx_ready, + .stop_tx =3D imx8mq_uart_stop_tx, + .start_tx =3D imx8mq_uart_start_tx, + .irq =3D imx8mq_irq, + .vuart_info =3D imx8mq_vuart_info, +}; + +static int __init imx8mq_uart_init(struct dt_device_node *dev, const void = *data) +{ + const char *config =3D data; + struct imx8mq_uart *uart; + int res; + u64 addr, size; + + if ( strcmp(config, "") ) + printk("WARNING: UART configuration is not supported\n"); + + uart =3D &imx8mq_com; + + res =3D dt_device_get_address(dev, 0, &addr, &size); + if ( res ) + { + printk("imx8mq3700: Unable to retrieve the base address of the UAR= T\n"); + return res; + } + + res =3D platform_get_irq(dev, 0); + if ( res < 0 ) + { + printk("imx8mq: Unable to retrieve the IRQ\n"); + return -EINVAL; + } + + uart->irq =3D res; + + uart->regs =3D ioremap_nocache(addr, size); + if ( !uart->regs ) + { + printk("imx8mq3700: Unable to map the UART memory\n"); + return -ENOMEM; + } + =20 + uart->vuart.base_addr =3D addr; + uart->vuart.size =3D size; + uart->vuart.data_off =3D UCR1; + uart->vuart.status_off =3D UTS; + uart->vuart.status =3D 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 =3D +{ + DT_MATCH_COMPATIBLE("fsl,imx6q-uart"), + DT_MATCH_COMPATIBLE("fsl,imx8mq-uart"), + { /* sentinel */ }, +}; + +DT_DEVICE_START(imx8mq, "NXP imx8mq UART", DEVICE_SERIAL) + .dt_match =3D imx8mq_dt_match, + .init =3D imx8mq_uart_init, +DT_DEVICE_END + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel