From patchwork Tue Jan 12 04:28:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhuvanchandra DV X-Patchwork-Id: 566296 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 CB8E71402A1 for ; Tue, 12 Jan 2016 16:30:28 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=toradex.onmicrosoft.com header.i=@toradex.onmicrosoft.com header.b=NiqMxjR+; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 137714BE7D; Tue, 12 Jan 2016 06:30:20 +0100 (CET) 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 avLk5_5T6aKG; Tue, 12 Jan 2016 06:30:19 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7B8C84BE79; Tue, 12 Jan 2016 06:30:01 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AB08D4BE23 for ; Tue, 12 Jan 2016 05:43:48 +0100 (CET) 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 Xx5pP0KqasKa for ; Tue, 12 Jan 2016 05:43:48 +0100 (CET) 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 emea01-db3-obe.outbound.protection.outlook.com (mail-db3on0140.outbound.protection.outlook.com [157.55.234.140]) by theia.denx.de (Postfix) with ESMTPS id 513ED4BE22 for ; Tue, 12 Jan 2016 05:43:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toradex.onmicrosoft.com; s=selector1-toradex-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=t6ON+BSNWek2iHXSBpBxxElufYtGNfe9DTj8DibHLYk=; b=NiqMxjR+5y41GJKuYfZOwmIaRMmq8YmTI9DiBaVHindqxFq/uyAqq031aFM8IHJo+lePeboG8AlIZs+4ESEihqoG2bV9NPLQh85Q/LAnmpIqY0bng4CRi9dhWLtCYsRAnzzUWihmYp7SlcGHDDwM82W/ti7PopGPXZCDyGPCG9Y= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=bhuvanchandra.dv@toradex.com; Received: from linuxdev-in.toradex.int (115.115.225.206) by DB3PR05MB267.eurprd05.prod.outlook.com (10.141.4.26) with Microsoft SMTP Server (TLS) id 15.1.361.13; Tue, 12 Jan 2016 04:28:37 +0000 From: Bhuvanchandra DV To: Date: Tue, 12 Jan 2016 09:58:02 +0530 Message-ID: <1452572889-19254-2-git-send-email-bhuvanchandra.dv@toradex.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1452572889-19254-1-git-send-email-bhuvanchandra.dv@toradex.com> References: <1452572889-19254-1-git-send-email-bhuvanchandra.dv@toradex.com> MIME-Version: 1.0 X-Originating-IP: [115.115.225.206] X-ClientProxiedBy: MA1PR01CA0043.INDPRD01.PROD.OUTLOOK.COM (25.164.116.143) To DB3PR05MB267.eurprd05.prod.outlook.com (10.141.4.26) X-Microsoft-Exchange-Diagnostics: 1; DB3PR05MB267; 2:Bp6NR/fW9pZLDqW42m1xH99ft7LlFFJsUQFAB99AHR4FQpVIa1RCQUOqzfcHnIw6G78OtRORtraBSwcSXhNed8rCMHcLmqkYmKSt5G1CgeFnzztGJTxsyHxzJwWJN9N4kuEMeVSErEy2I8igRcYHDA==; 3:oTnL6ftvCgS9mLA6A8mPtkefij7MT6VGyu5aoblyVTmy0+BnWI+9cIvX1yzTaGENuKwXOBCLVL12VG5CnB3dxJvw1jab+Lqzdwv0IrDozWTAQZ0vzoUXXy25nDikGmbc; 25:I2oGTaKUcY5uiIX40wVc2u7GuhCDJLrz68ZlpjiG/9ShfCrbrqrHVo+XGOWyTp1akoCfSqLJvcLfCh6tQZUR3dtZ1LR8gz0qkLuihZ17QDs8j02BCzXl9KvJUJ7fDq8W+9YNLXr1QaYXFIw7N2Wu/I23RBtHd9dQ137ILwp6tcSyZCCp0nMv6zZ95SluJu7k6pYMy0cSyMio1uoIM5+R3INgu3aAHkgnbs12R7RLbW3SnkK7pitVT0GEjZuyAOGv; 20:1lPkEKvv1SmIKyVvBPkLMpvmsqQM9kWQVyODUg/meiya7ylx1mrWoTpr16Z1n0iUJzC+nOLKGtlsTuYhiTzH9CffOeJRzKaF4xdPTGNtV98tL+dyQ8EHcFitVrpaQBHpjyolEgFXsGbxlsDGXXGLleB/8rvyapdxeL+FisfhH7vfgxwfeehYqAHFsM22SGuDktmNAy9MlQEKfvl60nmXgIqiHWA/3s3OTnvbITgui5c0eHojFOCuS7hZLn0FpuME02zWNPMrDSxiFKMWkzyLG3vUTrQl0VV2cVvN+Fif+Ca1W/LVvSM3D0Bz6qzup/QgMfGW8MilRBRSsz+WbDe+eA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB3PR05MB267; X-MS-Office365-Filtering-Correlation-Id: c44b3cd7-3d4f-43a4-a305-08d31b08d83c X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(520078)(5005006)(10201501046)(3002001); SRVR:DB3PR05MB267; BCL:0; PCL:0; RULEID:; SRVR:DB3PR05MB267; X-Microsoft-Exchange-Diagnostics: 1; DB3PR05MB267; 4:vVWCggRCQIp064X9oqogVKwImQjfnm9UPgUovA8hW1DECcO9fDuMzXVS1Ci0LYFBhzT8nwDnXzuzvihMfwLZRdp4cT5H4i2I4pArQjjxWEMFDxoTdkbe1gjuTCsKcCe7kSk1YU/7LQbXqjBQD0jRxxYz3zYIz55L6u//MMIJITuw6zQAXPDl1v+X7O8SLdbYel3eF215ywD3gndBMTdI1i1XoUpB7VtG3BvtuJMH+FjHz0YRL9OqOoiyeg5OlBtbYqBrHSu6KsZDNNR5dqcJ6iDXUF6CQ9B7NzVTBkrp1rEWG8vmxB4Xxag3tBizmHqQG35N+J9kH+3xhUzRo7zhBNiwkO+TMVOmx+Jb+ZYl/8lfZdBbK1F6T2N8aDwS6zFr X-Forefront-PRVS: 081904387B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(189002)(199003)(3846002)(5008740100001)(50986999)(4326007)(101416001)(4001430100002)(5003940100001)(5001960100002)(2950100001)(105586002)(6116002)(92566002)(106356001)(1096002)(2906002)(586003)(76176999)(48376002)(36756003)(107886002)(19580395003)(69596002)(53416004)(5004730100002)(19580405001)(2351001)(50466002)(110136002)(86362001)(229853001)(81156007)(77096005)(122386002)(97736004)(40100003)(42186005)(189998001)(87976001)(47776003)(33646002)(50226001)(66066001)(7059030); DIR:OUT; SFP:1102; SCL:1; SRVR:DB3PR05MB267; H:linuxdev-in.toradex.int; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: toradex.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB3PR05MB267; 23:L7axAIIkUw6Y5PB1tZ6SxRUh8fPcXrIFArviHJdX8p?= =?us-ascii?Q?d/lhSXBdMgQlYGJp4bsi/xDK3bc80eAmjb07C5Gpc1LeFbuLT3wEhlG1IG2l?= =?us-ascii?Q?nnwZVettGZRDdenVKxP88jT1I5hvSfML87c2kppvf+5nXsG/vIGovQYe1eUT?= =?us-ascii?Q?A2T620tEbw3SDFLCKcHoDxxy3Nou2qLCXdKWI4B1irT51DOUBiFUt2X/sSQ7?= =?us-ascii?Q?817aNSiJf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?= =?us-ascii?Q?blVtddNfHtc+77AQ4Nx3uTg+LF36vGU3GXi68wZudMgFel8QZnerkFBUpmaV?= =?us-ascii?Q?ok7tFZ4j6UK7w=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB3PR05MB267; 5:rnWXs0WDp28O3tWqXnihhHTOPABePfozjWafPyYPevdwKiWDKBFtM5y04E0MoaspgQhOseS+slWsMJMoNLxS9GQmcX2+U8/k/FLg4OnjmA6z7yBtifsbsT9TON3ozb6SaO3BJSDf7HkFj3DZHZgpIg==; 24:mxMF/cITZwH5Jj2zoscScBXVfUTpHp+DCOvyVaJGZCzzitahyQxHaDkG6utvrncHQHN5IQ0nqHZmAz2maGA7ln8EGZg8BU4ZjeTygnrJG9U= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2016 04:28:37.6225 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR05MB267 X-Mailman-Approved-At: Tue, 12 Jan 2016 06:29:52 +0100 Cc: alison.wang@freescale.com, albert.aribaud@3adev.fr, u-boot@lists.denx.de Subject: [U-Boot] [PATCH 1/8] dm: lpuart: Add driver model support for the serial driver X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 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" Convert lpuart driver to driver model and remove the legacy code. Signed-off-by: Bhuvanchandra DV --- arch/arm/include/asm/arch-vf610/serial.h | 16 ++++ drivers/serial/Kconfig | 6 ++ drivers/serial/serial_lpuart.c | 148 ++++++++++++++++--------------- 3 files changed, 97 insertions(+), 73 deletions(-) create mode 100644 arch/arm/include/asm/arch-vf610/serial.h diff --git a/arch/arm/include/asm/arch-vf610/serial.h b/arch/arm/include/asm/arch-vf610/serial.h new file mode 100644 index 0000000..e9ab552 --- /dev/null +++ b/arch/arm/include/asm/arch-vf610/serial.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2016 Toradex, Inc. + * + * Author: Bhuvanchandra DV + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef _LPUART_SERIAL_H +#define _LPUART_SERIAL_H + +struct lpuart_serial_platdata { + uint32_t base_addr; +}; + +#endif diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 1fc287e..56a06a7 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -223,4 +223,10 @@ config UNIPHIER_SERIAL If you have a UniPhier based board and want to use the on-chip serial ports, say Y to this option. If unsure, say N. +config FSL_LPUART + bool "Freescale lpuart serial port support" + depends on DM_SERIAL + help + Support for the on-chip lpuart on some Freescale SOCs. + endmenu diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c index 63fc388..4724f42 100644 --- a/drivers/serial/serial_lpuart.c +++ b/drivers/serial/serial_lpuart.c @@ -5,12 +5,14 @@ */ #include +#include #include #include #include #include #include #include +#include #define US1_TDRE (1 << 7) #define US1_RDRF (1 << 5) @@ -47,26 +49,35 @@ DECLARE_GLOBAL_DATA_PTR; -struct lpuart_fsl *base = (struct lpuart_fsl *)LPUART_BASE; +struct lpuart_serial_priv { + struct lpuart_fsl *lpuart_base; +}; #ifndef CONFIG_LPUART_32B_REG -static void lpuart_serial_setbrg(void) +int lpuart_serial_setbrg(struct udevice *dev, int baudrate) { + struct lpuart_serial_priv *priv = dev_get_priv(dev); + struct lpuart_fsl *base = priv->lpuart_base; u32 clk = mxc_get_clock(MXC_UART_CLK); u16 sbr; if (!gd->baudrate) - gd->baudrate = CONFIG_BAUDRATE; + gd->baudrate = baudrate; sbr = (u16)(clk / (16 * gd->baudrate)); /* place adjustment later - n/32 BRFA */ __raw_writeb(sbr >> 8, &base->ubdh); __raw_writeb(sbr & 0xff, &base->ubdl); + + return 0; } -static int lpuart_serial_getc(void) +static int lpuart_serial_getc(struct udevice *dev) { + struct lpuart_serial_priv *priv = dev_get_priv(dev); + struct lpuart_fsl *base = priv->lpuart_base; + while (!(__raw_readb(&base->us1) & (US1_RDRF | US1_OR))) WATCHDOG_RESET(); @@ -75,8 +86,11 @@ static int lpuart_serial_getc(void) return __raw_readb(&base->ud); } -static void lpuart_serial_putc(const char c) +static int lpuart_serial_putc(struct udevice *dev, const char c) { + struct lpuart_serial_priv *priv = dev_get_priv(dev); + struct lpuart_fsl *base = priv->lpuart_base; + if (c == '\n') serial_putc('\r'); @@ -84,24 +98,15 @@ static void lpuart_serial_putc(const char c) WATCHDOG_RESET(); __raw_writeb(c, &base->ud); -} - -/* - * Test whether a character is in the RX buffer - */ -static int lpuart_serial_tstc(void) -{ - if (__raw_readb(&base->urcfifo) == 0) - return 0; - return 1; + return 0; } /* * Initialise the serial port with the given baudrate. The settings * are always 8 data bits, no parity, 1 stop bit, no start bits. */ -static int lpuart_serial_init(void) +static int lpuart_serial_init(struct lpuart_fsl *base) { u8 ctrl; @@ -118,29 +123,15 @@ static int lpuart_serial_init(void) __raw_writeb(0x0, &base->utwfifo); __raw_writeb(0x1, &base->urwfifo); __raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &base->ucfifo); - - /* provide data bits, parity, stop bit, etc */ - - serial_setbrg(); - __raw_writeb(UC2_RE | UC2_TE, &base->uc2); return 0; } - -static struct serial_device lpuart_serial_drv = { - .name = "lpuart_serial", - .start = lpuart_serial_init, - .stop = NULL, - .setbrg = lpuart_serial_setbrg, - .putc = lpuart_serial_putc, - .puts = default_serial_puts, - .getc = lpuart_serial_getc, - .tstc = lpuart_serial_tstc, -}; -#else -static void lpuart32_serial_setbrg(void) +#else /* CONFIG_LPUART_32B_REG */ +int lpuart32_serial_setbrg(struct udevice *dev, int baudrate) { + struct lpuart_serial_priv *priv = dev_get_priv(dev); + struct lpuart_fsl *base = priv->lpuart_base; u32 clk = CONFIG_SYS_CLK_FREQ; u32 sbr; @@ -151,10 +142,14 @@ static void lpuart32_serial_setbrg(void) /* place adjustment later - n/32 BRFA */ out_be32(&base->baud, sbr); + + return 0; } -static int lpuart32_serial_getc(void) +static int lpuart32_serial_getc(struct udevice *dev) { + struct lpuart_serial_priv *priv = dev_get_priv(dev); + struct lpuart_fsl *base = priv->lpuart_base; u32 stat; while (((stat = in_be32(&base->stat)) & STAT_RDRF) == 0) { @@ -165,8 +160,11 @@ static int lpuart32_serial_getc(void) return in_be32(&base->data) & 0x3ff; } -static void lpuart32_serial_putc(const char c) +static int lpuart32_serial_putc(struct udevice *dev, const char c) { + struct lpuart_serial_priv *priv = dev_get_priv(dev); + struct lpuart_fsl *base = priv->lpuart_base; + if (c == '\n') serial_putc('\r'); @@ -174,24 +172,15 @@ static void lpuart32_serial_putc(const char c) WATCHDOG_RESET(); out_be32(&base->data, c); -} -/* - * Test whether a character is in the RX buffer - */ -static int lpuart32_serial_tstc(void) -{ - if ((in_be32(&base->water) >> 24) == 0) - return 0; - - return 1; + return 0; } /* * Initialise the serial port with the given baudrate. The settings * are always 8 data bits, no parity, 1 stop bit, no start bits. */ -static int lpuart32_serial_init(void) +static int lpuart32_serial_init(struct lpuart_fsl *base) { u8 ctrl; @@ -204,41 +193,54 @@ static int lpuart32_serial_init(void) out_be32(&base->fifo, ~(FIFO_TXFE | FIFO_RXFE)); out_be32(&base->match, 0); - /* provide data bits, parity, stop bit, etc */ - - serial_setbrg(); - out_be32(&base->ctrl, CTRL_RE | CTRL_TE); return 0; } +#endif /* CONFIG_LPUART_32B_REG */ -static struct serial_device lpuart32_serial_drv = { - .name = "lpuart32_serial", - .start = lpuart32_serial_init, - .stop = NULL, - .setbrg = lpuart32_serial_setbrg, - .putc = lpuart32_serial_putc, - .puts = default_serial_puts, - .getc = lpuart32_serial_getc, - .tstc = lpuart32_serial_tstc, -}; -#endif - -void lpuart_serial_initialize(void) +static int lpuart_serial_probe(struct udevice *dev) { -#ifdef CONFIG_LPUART_32B_REG - serial_register(&lpuart32_serial_drv); + struct lpuart_serial_platdata *plat = dev->platdata; + struct lpuart_serial_priv *priv = dev_get_priv(dev); + + priv->lpuart_base = (struct lpuart_fsl *)plat->base_addr; +#ifndef CONFIG_LPUART_32B_REG + lpuart_serial_init(priv->lpuart_base); #else - serial_register(&lpuart_serial_drv); + lpuart32_serial_init(priv->lpuart_base); #endif + return 0; } -__weak struct serial_device *default_serial_console(void) -{ -#ifdef CONFIG_LPUART_32B_REG - return &lpuart32_serial_drv; +#ifndef CONFIG_LPUART_32B_REG +static const struct dm_serial_ops lpuart_serial_ops = { + .putc = lpuart_serial_putc, + .getc = lpuart_serial_getc, + .setbrg = lpuart_serial_setbrg, +}; + +U_BOOT_DRIVER(serial_lpuart) = { + .name = "serial_lpuart", + .id = UCLASS_SERIAL, + .probe = lpuart_serial_probe, + .ops = &lpuart_serial_ops, + .flags = DM_FLAG_PRE_RELOC, + .priv_auto_alloc_size = sizeof(struct lpuart_serial_priv), +}; #else - return &lpuart_serial_drv; +static const struct dm_serial_ops lpuart32_serial_ops = { + .putc = lpuart32_serial_putc, + .getc = lpuart32_serial_getc, + .setbrg = lpuart32_serial_setbrg, +}; + +U_BOOT_DRIVER(serial_lpuart32) = { + .name = "serial_lpuart32", + .id = UCLASS_SERIAL, + .probe = lpuart_serial_probe, + .ops = &lpuart32_serial_ops, + .flags = DM_FLAG_PRE_RELOC, + .priv_auto_alloc_size = sizeof(struct lpuart_serial_priv), +}; #endif -}