From patchwork Thu Jun 14 18:08:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 138597 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2441294lji; Thu, 14 Jun 2018 11:13:26 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLigEhg/XWBKKD0SUTQj+lllLcXgwD2MTgO10LOTvCvoBZEWw4JjHcyZ4ROH2KfYZSjpGH4 X-Received: by 2002:a50:9734:: with SMTP id c49-v6mr3421257edb.267.1529000006009; Thu, 14 Jun 2018 11:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529000006; cv=none; d=google.com; s=arc-20160816; b=t192k70lk9FicaG1yEwHgyUBsFEZbWC1EAMsMKf3x9pwrP98tKYMRONSzbwDk512r8 kLX3c91xDhl0LOUTW1G1waW7lY2MkR1fEXVOyCEvCdMFaTHVnnxhZvnwUTYaiRbRNG0D nQYC7QF6zJY+iW5XChQ/xoQEoS+DrzIUg5muajk6afg/aY3hldqN86vLEAXxpaagpv+T hNPgpH0sX12EcVYPkn3qwt7/NKrKT86OswofQ6lF1YbXqAXCesbbp9+AZM+OWCetfd/p cifUzq3cmCdAgOsOXuIFKxrzoakyb62qg3MehuSst95YnBtfrBhr9p4JjtvDo7SqD5xT qduQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=092/ZgNokfTEeHR5/81wjmUVdQF8Qa69vXw+EXYg5Q4=; b=LCskp6doOuq9Ulu3t3Qp5RqRGLd8uUYMLDLTWdjaMEsErh3B+IbHyL1Qyt/cQkJkZb 9R/rsgNWu/M9aTSp+iLAx1SCRO0bAUWJjEsLOfe9ro+xo0LgxqCm36h8xK3iUJjj+X8I 9D4rV4S7CkRBvBOPSlmpxnBEyQnAj/7dcyUCz3AkCVg5U2NYmFZLQpjgIDPHefAYg0BL OdvQttIjq5YYIFhn/g9mPAXshushIFtrooyRRdKSF4LhTrz3y53i9JwZrfeCuzBDYBFp X2DSKYlHzKhKLiSOPbRsUQ7rMwoRgM+9WJ7oBH4hgSTbAMIzQtMbP2oHdpv7lpapiOO4 g79Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PL1NNoRM; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id k32-v6si1337663edc.340.2018.06.14.11.13.25; Thu, 14 Jun 2018 11:13:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PL1NNoRM; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 873EBC21DA2; Thu, 14 Jun 2018 18:11:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=KHOP_BIG_TO_CC, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 883B2C21E29; Thu, 14 Jun 2018 18:11:14 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8EAC5C21DF9; Thu, 14 Jun 2018 18:10:07 +0000 (UTC) Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) by lists.denx.de (Postfix) with ESMTPS id 29D19C21DF3 for ; Thu, 14 Jun 2018 18:10:02 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id h12-v6so3615348pfk.11 for ; Thu, 14 Jun 2018 11:10:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QOVUceVI/lVdpSmneUw53RbFcoBouOKah2KyfR6RS/c=; b=PL1NNoRMaIcBXehIhYT/GVg0Jq7mdipzv7OtrXt9Xg/CpAr1cvRoS5lNIU91o1xJVI ZEZBiJWlFopLGpLx+n/rzSQZOl1i1QiqsxjOwk7d4sOjctXnLuh+aqgALJyC/X7NFEgR IiAGp1+tYqhKHwK7vXW2/NJEz1i9PNkB48IfU= 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=QOVUceVI/lVdpSmneUw53RbFcoBouOKah2KyfR6RS/c=; b=EaRUo7a+nFfJVAriT5lzSwirbShiJVPWfQJckQFfmlS+JCH30+vspDj+TbZmnOpvqo VuFcU6jNfEqrTk/GHIPfEq1eB9M0gmjkKhWlhXdKOcu6rk7yzxgFMxCknFk07lR2SMGg wrN+GQrDrsqCjGYaf7JMIXukpSRF6uQu7HCdWnNSMyU6gKFctCJBzTmlU3+PdPDj6yBR MpmtT8NyHcDONBOwkTjV55zqgdLzZZc9UgLjPC5kTTB7yf/Wwuh2WhH2yvXq11XVkX3x eSeV2+kuZydoy4RhTMbusAzmVG3ya2FTzKnRqzXwBJg89rNQ8bqt85xAoYyH/CIk5DY9 bU8g== X-Gm-Message-State: APt69E2ZFIKHUnaWStoQLlJAXDPKJqViVHqEjIFQTCeOBPvYK9OI5Tvv Z04QjWj3vm8YkfUM6/GZqod2 X-Received: by 2002:a62:3c15:: with SMTP id j21-v6mr10573202pfa.7.1528999800641; Thu, 14 Jun 2018 11:10:00 -0700 (PDT) Received: from localhost.localdomain ([2405:204:70c2:bb29:293b:24bf:4980:3a19]) by smtp.gmail.com with ESMTPSA id c74-v6sm11923363pfd.19.2018.06.14.11.09.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Jun 2018 11:10:00 -0700 (PDT) From: Manivannan Sadhasivam To: albert.u.boot@aribaud.net, sjg@chromium.org, marek.vasut+renesas@gmail.com, u-boot@lists.denx.de Date: Thu, 14 Jun 2018 23:38:38 +0530 Message-Id: <20180614180839.8494-9-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180614180839.8494-1-manivannan.sadhasivam@linaro.org> References: <20180614180839.8494-1-manivannan.sadhasivam@linaro.org> Cc: daniel.thompson@linaro.org, manivannanece23@gmail.com, bdong@ucrobotics.com, Manivannan Sadhasivam , thomas.liau@actions-semi.com, hzhang@ucrobotics.com, amit.kucheria@linaro.org, liuwei@actions-semi.com, afaerber@suse.de, jeff.chen@actions-semi.com, mp-cs@actions-semi.com Subject: [U-Boot] [PATCH v3 8/9] serial: Add Actions Semi OWL UART support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This commit adds Actions Semi OWL family UART support. This driver relies on baudrate configured by primary bootloaders. Signed-off-by: Manivannan Sadhasivam Reviewed-by: Simon Glass --- Changes in v3: * Moved the change log from cover letter Changes in v2: None drivers/serial/Kconfig | 8 +++ drivers/serial/Makefile | 1 + drivers/serial/serial_owl.c | 136 ++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 drivers/serial/serial_owl.c diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 2940bd05dc..766e5ced03 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -625,6 +625,14 @@ config MSM_SERIAL for example APQ8016 and MSM8916. Single baudrate is supported in current implementation (115200). +config OWL_SERIAL + bool "Actions Semi OWL UART" + depends on DM_SERIAL && ARCH_OWL + help + If you have a Actions Semi OWL based board and want to use the on-chip + serial port, say Y to this option. If unsure, say N. + Single baudrate is supported in current implementation (115200). + config PXA_SERIAL bool "PXA serial port support" help diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index e66899489e..9fa81d855d 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile @@ -64,6 +64,7 @@ obj-$(CONFIG_MSM_SERIAL) += serial_msm.o obj-$(CONFIG_MVEBU_A3700_UART) += serial_mvebu_a3700.o obj-$(CONFIG_MPC8XX_CONS) += serial_mpc8xx.o obj-$(CONFIG_NULLDEV_SERIAL) += serial_nulldev.o +obj-$(CONFIG_OWL_SERIAL) += serial_owl.o ifndef CONFIG_SPL_BUILD obj-$(CONFIG_USB_TTY) += usbtty.o diff --git a/drivers/serial/serial_owl.c b/drivers/serial/serial_owl.c new file mode 100644 index 0000000000..6fd97e2502 --- /dev/null +++ b/drivers/serial/serial_owl.c @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Actions Semi OWL SoCs UART driver + * + * Copyright (C) 2015 Actions Semi Co., Ltd. + * Copyright (C) 2018 Manivannan Sadhasivam + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* UART Registers */ +#define OWL_UART_CTL (0x0000) +#define OWL_UART_RXDAT (0x0004) +#define OWL_UART_TXDAT (0x0008) +#define OWL_UART_STAT (0x000C) + +/* UART_CTL Register Definitions */ +#define OWL_UART_CTL_PRS_NONE GENMASK(6, 4) +#define OWL_UART_CTL_STPS BIT(2) +#define OWL_UART_CTL_DWLS 3 + +/* UART_STAT Register Definitions */ +#define OWL_UART_STAT_TFES BIT(10) /* TX FIFO Empty Status */ +#define OWL_UART_STAT_RFFS BIT(9) /* RX FIFO full Status */ +#define OWL_UART_STAT_TFFU BIT(6) /* TX FIFO full Status */ +#define OWL_UART_STAT_RFEM BIT(5) /* RX FIFO Empty Status */ + +struct owl_serial_priv { + phys_addr_t base; +}; + +int owl_serial_setbrg(struct udevice *dev, int baudrate) +{ + /* Driver supports only fixed baudrate */ + return 0; +} + +static int owl_serial_getc(struct udevice *dev) +{ + struct owl_serial_priv *priv = dev_get_priv(dev); + + if (readl(priv->base + OWL_UART_STAT) & OWL_UART_STAT_RFEM) + return -EAGAIN; + + return (int)(readl(priv->base + OWL_UART_RXDAT)); +} + +static int owl_serial_putc(struct udevice *dev, const char ch) +{ + struct owl_serial_priv *priv = dev_get_priv(dev); + + if (readl(priv->base + OWL_UART_STAT) & OWL_UART_STAT_TFFU) + return -EAGAIN; + + writel(ch, priv->base + OWL_UART_TXDAT); + + return 0; +} + +static int owl_serial_pending(struct udevice *dev, bool input) +{ + struct owl_serial_priv *priv = dev_get_priv(dev); + unsigned int stat = readl(priv->base + OWL_UART_STAT); + + if (input) + return !(stat & OWL_UART_STAT_RFEM); + else + return !(stat & OWL_UART_STAT_TFES); +} + +static int owl_serial_probe(struct udevice *dev) +{ + struct owl_serial_priv *priv = dev_get_priv(dev); + struct clk clk; + u32 uart_ctl; + int ret; + + /* Set data, parity and stop bits */ + uart_ctl = readl(priv->base + OWL_UART_CTL); + uart_ctl &= ~(OWL_UART_CTL_PRS_NONE); + uart_ctl &= ~(OWL_UART_CTL_STPS); + uart_ctl |= OWL_UART_CTL_DWLS; + writel(uart_ctl, priv->base + OWL_UART_CTL); + + /* Enable UART clock */ + ret = clk_get_by_index(dev, 0, &clk); + if (ret < 0) + return ret; + + ret = clk_enable(&clk); + if (ret < 0) + return ret; + + return 0; +} + +static int owl_serial_ofdata_to_platdata(struct udevice *dev) +{ + struct owl_serial_priv *priv = dev_get_priv(dev); + + priv->base = dev_read_addr(dev); + if (priv->base == FDT_ADDR_T_NONE) + return -EINVAL; + + return 0; +} + +static const struct dm_serial_ops owl_serial_ops = { + .putc = owl_serial_putc, + .pending = owl_serial_pending, + .getc = owl_serial_getc, + .setbrg = owl_serial_setbrg, +}; + +static const struct udevice_id owl_serial_ids[] = { + { .compatible = "actions,s900-serial" }, + { } +}; + +U_BOOT_DRIVER(serial_owl) = { + .name = "serial_owl", + .id = UCLASS_SERIAL, + .of_match = owl_serial_ids, + .ofdata_to_platdata = owl_serial_ofdata_to_platdata, + .priv_auto_alloc_size = sizeof(struct owl_serial_priv), + .probe = owl_serial_probe, + .ops = &owl_serial_ops, + .flags = DM_FLAG_PRE_RELOC, +};