From patchwork Thu Aug 27 12:10:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1352513 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=RV7Ngnoq; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BchPw1SGHz9sT6 for ; Thu, 27 Aug 2020 22:10:27 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 56D3F80422; Thu, 27 Aug 2020 14:10:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="RV7Ngnoq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 53F0D81260; Thu, 27 Aug 2020 14:10:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 84F6B8006D for ; Thu, 27 Aug 2020 14:10:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-wr1-x442.google.com with SMTP id r15so5118108wrp.13 for ; Thu, 27 Aug 2020 05:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RisWIQPg6IPvNhrxfGQIW+nNPYciyGtapErHzs9sreE=; b=RV7Ngnoq5N74IEzZ6peqFIaxwXrEkoSubxG6ZFgmpc8dhmAWCUlM7pnJAJjANPrwQq sFrcdzgr8FyVagL6cQcBf9jcg6YfXQKEbf1i2GOTA/XQFo6S71UE8i8eOyi5+UzHMIVv qu+i1LuzV0nd1jjLTR1tbjGwWbEeN98XK3fkxefQQmws68a8jI1dZrHVc4yyRNYFpjq2 yFDJQp6mnLoZ1UfXbCuGQa6qnQih3DtAXbvFD2qHFbDyswSCCYzRy89+wXF9x5lQvSNf zrDyKCS8piw4nLjVaFehot5HhGnQ7i2zi+Nu+dqiSEZCzFXIbXYwr3EA0bgI9n9LnGpy sMKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=RisWIQPg6IPvNhrxfGQIW+nNPYciyGtapErHzs9sreE=; b=FhnjSAJ183RfyKlybm7gEDO9AGUZqEeTbD/fnIUwHSjHDw1J/F+qi310V1s4phQ412 vh1LLxbP3dzIoPiyjX2VamDXssVXleQvf0U/u9ePISCweeeV7YOhtrgae5RskdUZ24iq 12FKv/etv6mf1hBJuA37IG47myQP9qOLJlX4OFc9wH/Kaw2GH+osuCurz1a2GTnsWxey s7Pdfmx4dBA9yy/L41i/40VlkFzPTvE5iADdAvSAA5w+gonsTBH2jBQD7emc+x0HK0zl ri3ni4BSeMTL5G8Wn7TKTavadf6Cd26gHHbxGB3CaRbLb6HPlpdLU+GEGSMeV0YByaD0 9a3A== X-Gm-Message-State: AOAM532/UAPX2TVrsK4CKkTjrlU9R+GlGdEQrpAmBnC/yRirY7k3n30o cLxOMiXeyu5cfRNiysPCIWsofF8/Z3jSmw== X-Google-Smtp-Source: ABdhPJw3e+DXVopsQyOaUbH+LuM902wlEhFjESa5uIGnYNsc8a7P0wl4rAjDdank6h6fsI59Avg3tg== X-Received: by 2002:adf:81a3:: with SMTP id 32mr421581wra.368.1598530217886; Thu, 27 Aug 2020 05:10:17 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id o66sm5154661wmb.27.2020.08.27.05.10.17 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Aug 2020 05:10:17 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: T Karthik Reddy , Michal Simek Subject: [PATCH] serial: uartlite: Add support to work with any endianness Date: Thu, 27 Aug 2020 14:10:16 +0200 Message-Id: <113756fda74a683fe15728fabdf96f0599750172.1598530214.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: T Karthik Reddy This endinness changes are taken from linux uartlite driver. Reset TX fifo in control register and check TX fifo empty flag in lower byte of the status register to detect if it is a little endian system. Based on this check, program the registers with le32 or be32 through out the driver. Signed-off-by: T Karthik Reddy Signed-off-by: Ashok Reddy Soma Signed-off-by: Michal Simek --- drivers/serial/serial_xuartlite.c | 74 ++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/drivers/serial/serial_xuartlite.c b/drivers/serial/serial_xuartlite.c index 5116d13751de..e16642504b16 100644 --- a/drivers/serial/serial_xuartlite.c +++ b/drivers/serial/serial_xuartlite.c @@ -32,17 +32,64 @@ struct uartlite { struct uartlite_platdata { struct uartlite *regs; + const struct uartlite_reg_ops *reg_ops; }; +struct uartlite_reg_ops { + u32 (*in)(void __iomem *addr); + void (*out)(u32 val, void __iomem *addr); +}; + +static u32 uartlite_inle32(void __iomem *addr) +{ + return in_le32(addr); +} + +static void uartlite_outle32(u32 val, void __iomem *addr) +{ + out_le32(addr, val); +} + +static const struct uartlite_reg_ops uartlite_le = { + .in = uartlite_inle32, + .out = uartlite_outle32, +}; + +static u32 uartlite_inbe32(void __iomem *addr) +{ + return in_be32(addr); +} + +static void uartlite_outbe32(u32 val, void __iomem *addr) +{ + out_be32(addr, val); +} + +static const struct uartlite_reg_ops uartlite_be = { + .in = uartlite_inbe32, + .out = uartlite_outbe32, +}; + +static u32 uart_in32(void __iomem *addr, struct uartlite_platdata *plat) +{ + return plat->reg_ops->in(addr); +} + +static void uart_out32(void __iomem *addr, u32 val, + struct uartlite_platdata *plat) +{ + plat->reg_ops->out(val, addr); +} + static int uartlite_serial_putc(struct udevice *dev, const char ch) { struct uartlite_platdata *plat = dev_get_platdata(dev); struct uartlite *regs = plat->regs; - if (in_be32(®s->status) & SR_TX_FIFO_FULL) + if (uart_in32(®s->status, plat) & SR_TX_FIFO_FULL) return -EAGAIN; - out_be32(®s->tx_fifo, ch & 0xff); + uart_out32(®s->tx_fifo, ch & 0xff, plat); return 0; } @@ -52,10 +99,10 @@ static int uartlite_serial_getc(struct udevice *dev) struct uartlite_platdata *plat = dev_get_platdata(dev); struct uartlite *regs = plat->regs; - if (!(in_be32(®s->status) & SR_RX_FIFO_VALID_DATA)) + if (!(uart_in32(®s->status, plat) & SR_RX_FIFO_VALID_DATA)) return -EAGAIN; - return in_be32(®s->rx_fifo) & 0xff; + return uart_in32(®s->rx_fifo, plat) & 0xff; } static int uartlite_serial_pending(struct udevice *dev, bool input) @@ -64,19 +111,26 @@ static int uartlite_serial_pending(struct udevice *dev, bool input) struct uartlite *regs = plat->regs; if (input) - return in_be32(®s->status) & SR_RX_FIFO_VALID_DATA; + return uart_in32(®s->status, plat) & SR_RX_FIFO_VALID_DATA; - return !(in_be32(®s->status) & SR_TX_FIFO_EMPTY); + return !(uart_in32(®s->status, plat) & SR_TX_FIFO_EMPTY); } static int uartlite_serial_probe(struct udevice *dev) { struct uartlite_platdata *plat = dev_get_platdata(dev); struct uartlite *regs = plat->regs; - - out_be32(®s->control, 0); - out_be32(®s->control, ULITE_CONTROL_RST_RX | ULITE_CONTROL_RST_TX); - in_be32(®s->control); + int ret; + + plat->reg_ops = &uartlite_be; + ret = uart_in32(®s->control, plat); + uart_out32(®s->control, 0, plat); + uart_out32(®s->control, + ULITE_CONTROL_RST_RX | ULITE_CONTROL_RST_TX, plat); + ret = uart_in32(®s->status, plat); + /* Endianness detection */ + if ((ret & SR_TX_FIFO_EMPTY) != SR_TX_FIFO_EMPTY) + plat->reg_ops = &uartlite_le; return 0; }