From patchwork Mon Sep 22 23:30:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 392182 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 563301400E9 for ; Tue, 23 Sep 2014 09:33:36 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 920EAAB55F; Tue, 23 Sep 2014 01:33:33 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a5dtYJeuOnxe; Tue, 23 Sep 2014 01:33:33 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EB6CFA744B; Tue, 23 Sep 2014 01:33:15 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C03B0AB55C for ; Tue, 23 Sep 2014 01:33:09 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id W+i4j7bQUIK6 for ; Tue, 23 Sep 2014 01:33:09 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f74.google.com (mail-pa0-f74.google.com [209.85.220.74]) by theia.denx.de (Postfix) with ESMTPS id 4B92FAB561 for ; Tue, 23 Sep 2014 01:33:01 +0200 (CEST) Received: by mail-pa0-f74.google.com with SMTP id kx10so930040pab.3 for ; Mon, 22 Sep 2014 16:32:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xq7Rb8Hite6kqLm6q1PxlOB/rWS0+gbzmgoH7ROJkE0=; b=XJNUUzdXE4LN1kYF/W4t6GTZL9XGgvDnfYTyFVg3oWPVjazX1bClaDi+ojx5sDLnfY chgG0hx3hVos1nGJUNWe2ggQFpxqq5JpiiuRn//yH9mrTyJ94fMfGnmf8BfpST/cjkZC ZEpfoJCtK3TcFGJwq7CHWXVZvyU94nm7uKE6XkUZNYUpSEfafwBXfB2S/G7H76li6SC9 ErLdNaps+2E8PQxnwPtG/JZho2iI47nbGcb/M7aUpBcLwjMjXhLKdjTspohzOLcsYZuU 9wmbczzl8x+ek3YljketugYrJB7k8gQCc4WpOkM2EcG8Coq+H+U3lD3AsBvyvDP5RuER Accg== X-Gm-Message-State: ALoCoQncYlcA5qBXzG+x0ODXZ391EgPEFH2yBG6PR0rC0MSbBJi70rQKJClWzbob4MCqcsCc5FSg X-Received: by 10.66.141.70 with SMTP id rm6mr27444208pab.37.1411428779740; Mon, 22 Sep 2014 16:32:59 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id n24si562921yha.6.2014.09.22.16.32.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Sep 2014 16:32:59 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id T6sYAN0t.1; Mon, 22 Sep 2014 16:32:59 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id C12CD2212F2; Mon, 22 Sep 2014 17:32:58 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 22 Sep 2014 17:30:58 -0600 Message-Id: <1411428659-6823-4-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1411428659-6823-1-git-send-email-sjg@chromium.org> References: <1411428659-6823-1-git-send-email-sjg@chromium.org> Subject: [U-Boot] [PATCH 3/4] dm: serial: Support driver model in pl01x driver X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Add driver model support in this driver, using platform data provided by the board. Signed-off-by: Simon Glass --- drivers/serial/serial_pl01x.c | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/drivers/serial/serial_pl01x.c b/drivers/serial/serial_pl01x.c index 665a0e4..e6313ad 100644 --- a/drivers/serial/serial_pl01x.c +++ b/drivers/serial/serial_pl01x.c @@ -12,6 +12,7 @@ /* Simple U-Boot driver for the PrimeCell PL010/PL011 UARTs */ #include +#include #include #include #include @@ -20,12 +21,15 @@ #include #include "serial_pl01x_internal.h" +#ifndef CONFIG_DM_SERIAL + static volatile unsigned char *const port[] = CONFIG_PL01x_PORTS; static enum pl01x_type pl01x_type __attribute__ ((section(".data"))); static struct pl01x_regs *base_regs __attribute__ ((section(".data"))); #define NUM_PORTS (sizeof(port)/sizeof(port[0])) DECLARE_GLOBAL_DATA_PTR; +#endif static int pl01x_putc(struct pl01x_regs *regs, char c) { @@ -274,3 +278,72 @@ __weak struct serial_device *default_serial_console(void) } #endif /* nCONFIG_DM_SERIAL */ + +#ifdef CONFIG_DM_SERIAL + +struct pl01x_priv { + struct pl01x_regs *regs; + enum pl01x_type type; +}; + +static int pl01x_serial_setbrg(struct udevice *dev, int baudrate) +{ + struct pl01x_serial_platdata *plat = dev_get_platdata(dev); + struct pl01x_priv *priv = dev_get_priv(dev); + + pl01x_generic_setbrg(priv->regs, priv->type, plat->clock, baudrate); + + return 0; +} + +static int pl01x_serial_probe(struct udevice *dev) +{ + struct pl01x_serial_platdata *plat = dev_get_platdata(dev); + struct pl01x_priv *priv = dev_get_priv(dev); + + priv->regs = (struct pl01x_regs *)plat->base; + priv->type = plat->type; + return pl01x_generic_serial_init(priv->regs, priv->type); +} + +static int pl01x_serial_getc(struct udevice *dev) +{ + struct pl01x_priv *priv = dev_get_priv(dev); + + return pl01x_getc(priv->regs); +} + +static int pl01x_serial_putc(struct udevice *dev, const char ch) +{ + struct pl01x_priv *priv = dev_get_priv(dev); + + return pl01x_putc(priv->regs, ch); +} + +static int pl01x_serial_pending(struct udevice *dev, bool input) +{ + struct pl01x_priv *priv = dev_get_priv(dev); + unsigned int fr = readl(&priv->regs->fr); + + if (input) + return pl01x_tstc(priv->regs); + else + return fr & UART_PL01x_FR_TXFF ? 0 : 1; +} + +static const struct dm_serial_ops pl01x_serial_ops = { + .putc = pl01x_serial_putc, + .pending = pl01x_serial_pending, + .getc = pl01x_serial_getc, + .setbrg = pl01x_serial_setbrg, +}; + +U_BOOT_DRIVER(serial_pl01x) = { + .name = "serial_pl01x", + .id = UCLASS_SERIAL, + .probe = pl01x_serial_probe, + .ops = &pl01x_serial_ops, + .flags = DM_FLAG_PRE_RELOC, +}; + +#endif