From patchwork Wed Oct 29 19:09:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 404781 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 C87E414007D for ; Thu, 30 Oct 2014 06:18:25 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8E9214BA65; Wed, 29 Oct 2014 20:18:23 +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 XbQf8hBoLn1h; Wed, 29 Oct 2014 20:18:23 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BCB374BA5F; Wed, 29 Oct 2014 20:18:22 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9C7EE4BA5F for ; Wed, 29 Oct 2014 20:18:18 +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 ajQQ-EV9WHXr for ; Wed, 29 Oct 2014 20:18:18 +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 mail-yh0-f73.google.com (mail-yh0-f73.google.com [209.85.213.73]) by theia.denx.de (Postfix) with ESMTPS id 4B1AE4BA5C for ; Wed, 29 Oct 2014 20:18:14 +0100 (CET) Received: by mail-yh0-f73.google.com with SMTP id a41so127251yho.2 for ; Wed, 29 Oct 2014 12:18:13 -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=QSDhRrDtBnU+htxleLAukSKT+UH/jL98DPrKqx3Et+s=; b=iAppDKSzvtrOSLItuF9kBMj/jwXkQzJY1aS66e8gRlCfbz5wwwcRmKkk5PIuGsGb2h UF4bHAx8Tb0oAuY1WnTW3DJu+3jLo2k+ONudHRUnjii+IQcWSbTYmWeSPKsJ0qvL4Dk1 2KZ4Y8nRp5Vt5jTAmJZzKyDmyg2nBbVT+xwxHisxzqsYrWCfl5HKJIl7J9aUKezUQAr3 NGmP9VOOgb2AlzFQrxkYSqD2znxPHBO9lmv7/geNC634K688nFy/c+3/psKQibsLlcKT vja35BDApdtzalNtP4KUQhsGUFmM+hhDxPZ6Rly8RMB1FR8VH7ZFZq/IRYLXBP8XkLpZ p6mg== X-Gm-Message-State: ALoCoQnhBDoXrBJ3ucApLZ+f3CLSVAvPa8Rt4UTf+GueCIXZo52W+ws+A2HU0JRONEsGtqb88z70 X-Received: by 10.236.203.49 with SMTP id e37mr2788421yho.50.1414610293580; Wed, 29 Oct 2014 12:18:13 -0700 (PDT) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id n22si321295yhd.1.2014.10.29.12.18.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Oct 2014 12:18:13 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTP id IetvQBGB.1; Wed, 29 Oct 2014 12:18:13 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 16473220472; Wed, 29 Oct 2014 13:09:34 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Wed, 29 Oct 2014 13:09:03 -0600 Message-Id: <1414609743-19092-10-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1414609743-19092-1-git-send-email-sjg@chromium.org> References: <1414609743-19092-1-git-send-email-sjg@chromium.org> Subject: [U-Boot] [PATCH v2 9/9] dm: serial: Support changing the baud rate X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 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 Implement this feature in the uclass so that the baudrate can be changed with 'setenv baudrate '. Signed-off-by: Simon Glass --- Changes in v2: - Add a patch to implement baud rate changes drivers/serial/serial-uclass.c | 67 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index 71f1a5c..632933f 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -22,6 +23,11 @@ DECLARE_GLOBAL_DATA_PTR; /* The currently-selected console serial device */ struct udevice *cur_dev __attribute__ ((section(".data"))); +/* + * Table with supported baudrates (defined in config_xyz.h) + */ +static const unsigned long baudrate_table[] = CONFIG_SYS_BAUDRATE_TABLE; + #ifndef CONFIG_SYS_MALLOC_F_LEN #error "Serial is required before relocation - define CONFIG_SYS_MALLOC_F_LEN to make this work" #endif @@ -177,6 +183,67 @@ int serial_stub_tstc(struct stdio_dev *sdev) return _serial_tstc(sdev->priv); } +/** + * on_baudrate() - Update the actual baudrate when the env var changes + * + * This will check for a valid baudrate and only apply it if valid. + */ +static int on_baudrate(const char *name, const char *value, enum env_op op, + int flags) +{ + int i; + int baudrate; + + switch (op) { + case env_op_create: + case env_op_overwrite: + /* + * Switch to new baudrate if new baudrate is supported + */ + baudrate = simple_strtoul(value, NULL, 10); + + /* Not actually changing */ + if (gd->baudrate == baudrate) + return 0; + + for (i = 0; i < ARRAY_SIZE(baudrate_table); ++i) { + if (baudrate == baudrate_table[i]) + break; + } + if (i == ARRAY_SIZE(baudrate_table)) { + if ((flags & H_FORCE) == 0) + printf("## Baudrate %d bps not supported\n", + baudrate); + return 1; + } + if ((flags & H_INTERACTIVE) != 0) { + printf("## Switch baudrate to %d bps and press ENTER ...\n", + baudrate); + udelay(50000); + } + + gd->baudrate = baudrate; + + serial_setbrg(); + + udelay(50000); + + if ((flags & H_INTERACTIVE) != 0) + while (1) { + if (getc() == '\r') + break; + } + + return 0; + case env_op_delete: + printf("## Baudrate may not be deleted\n"); + return 1; + default: + return 0; + } +} +U_BOOT_ENV_CALLBACK(baudrate, on_baudrate); + static int serial_post_probe(struct udevice *dev) { struct stdio_dev sdev;