From patchwork Fri Mar 16 16:32:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 887001 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=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=c-s.fr Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 402rgJ63Sgz9sBr for ; Sat, 17 Mar 2018 03:35:56 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 49C14C21E2F; Fri, 16 Mar 2018 16:34:25 +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=none 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 6BF9FC21DEC; Fri, 16 Mar 2018 16:33:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 85431C21E38; Fri, 16 Mar 2018 16:32:51 +0000 (UTC) Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) by lists.denx.de (Postfix) with ESMTPS id C9119C21E34 for ; Fri, 16 Mar 2018 16:32:47 +0000 (UTC) Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 402rbW3bVvz9tvQd; Fri, 16 Mar 2018 17:32:39 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id t-5HLKUkSCva; Fri, 16 Mar 2018 17:32:39 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 402rbW380fz9tvPl; Fri, 16 Mar 2018 17:32:39 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 3E2B78BBB2; Fri, 16 Mar 2018 17:32:47 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id igf4JfhyjXDc; Fri, 16 Mar 2018 17:32:47 +0100 (CET) Received: from po15720vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.30]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 165198BBB1; Fri, 16 Mar 2018 17:32:47 +0100 (CET) Received: by po15720vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 040336F128; Fri, 16 Mar 2018 17:32:47 +0100 (CET) Message-Id: In-Reply-To: References: From: Christophe Leroy To: Tom Rini , Wolfgang Denk , Simon Glass Date: Fri, 16 Mar 2018 17:32:47 +0100 (CET) Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH RFCv2 4/6] drivers: serial: migrate mpc8xx to DM 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" Signed-off-by: Christophe Leroy --- drivers/serial/serial_mpc8xx.c | 77 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/drivers/serial/serial_mpc8xx.c b/drivers/serial/serial_mpc8xx.c index 7a5908f4645..b568e14328f 100644 --- a/drivers/serial/serial_mpc8xx.c +++ b/drivers/serial/serial_mpc8xx.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -36,9 +37,9 @@ struct serialbuffer { uchar txbuf; /* tx buffers */ }; -static void serial_setdivisor(cpm8xx_t __iomem *cp) +static void serial_setdivisor(cpm8xx_t __iomem *cp, int baudrate) { - int divisor = (gd->cpu_clk + 8 * gd->baudrate) / 16 / gd->baudrate; + int divisor = (gd->cpu_clk + 8 * baudrate) / 16 / baudrate; if (divisor / 16 > 0x1000) { /* bad divisor, assume 50MHz clock and 9600 baud */ @@ -72,7 +73,7 @@ static void smc_setbrg(void) out_be32(&cp->cp_simode, 0); - serial_setdivisor(cp); + serial_setdivisor(cp, gd->baudrate); } static int smc_init(void) @@ -187,11 +188,13 @@ static void smc_putc(const char c) WATCHDOG_RESET(); } +#ifndef CONFIG_DM_SERIAL static void smc_puts(const char *s) { while (*s) smc_putc(*s++); } +#endif static int smc_getc(void) { @@ -234,6 +237,7 @@ static int smc_tstc(void) return !(in_be16(&rtx->rxbd.cbd_sc) & BD_SC_EMPTY); } +#ifndef CONFIG_DM_SERIAL struct serial_device serial_smc_device = { .name = "serial_smc", .start = smc_init, @@ -254,3 +258,70 @@ void mpc8xx_serial_initialize(void) { serial_register(&serial_smc_device); } +#endif + +#ifdef CONFIG_DM_SERIAL +static int serial_mpc8xx_setbrg(struct udevice *dev, int baudrate) +{ + immap_t __iomem *im = (immap_t __iomem *)CONFIG_SYS_IMMR; + cpm8xx_t __iomem *cp = &(im->im_cpm); + + /* Set up the baud rate generator. + * See 8xx_io/commproc.c for details. + * + * Wire BRG1 to SMCx + */ + + out_be32(&cp->cp_simode, 0); + + serial_setdivisor(cp, baudrate); + + return 0; +} + +static int serial_mpc8xx_probe(struct udevice *dev) +{ + return smc_init(); +} + +static int serial_mpc8xx_putc(struct udevice *dev, const char ch) +{ + smc_putc(ch); + + return 0; +} + +static int serial_mpc8xx_getc(struct udevice *dev) +{ + return smc_getc(); +} + +static int serial_mpc8xx_pending(struct udevice *dev, bool input) +{ + if (input) + return smc_tstc(); + + return 0; +} + +static const struct dm_serial_ops serial_mpc8xx_ops = { + .putc = serial_mpc8xx_putc, + .pending = serial_mpc8xx_pending, + .getc = serial_mpc8xx_getc, + .setbrg = serial_mpc8xx_setbrg, +}; + +static const struct udevice_id serial_mpc8xx_ids[] = { + { .compatible = "fsl,pq1-smc" }, + { } +}; + +U_BOOT_DRIVER(serial_mpc8xx) = { + .name = "serial_mpc8xx", + .id = UCLASS_SERIAL, + .of_match = serial_mpc8xx_ids, + .probe = serial_mpc8xx_probe, + .ops = &serial_mpc8xx_ops, + .flags = DM_FLAG_PRE_RELOC, +}; +#endif