Received: by 10.223.185.116 with SMTP id b49csp7768016wrg; Thu, 1 Mar 2018 10:45:07 -0800 (PST) X-Google-Smtp-Source: AG47ELsKnopFKpLR/1pgJ4eQuZQFuxO71JjC+xaPfwIekku6lYKRLF4WgrIpwY0cdlLE51hTAjoC X-Received: by 10.98.36.25 with SMTP id r25mr2954600pfj.106.1519929907162; Thu, 01 Mar 2018 10:45:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519929907; cv=none; d=google.com; s=arc-20160816; b=RRiyQc5obVNH90evklb9CifEpBWgq3PSl9nXlDRyfyrcVZ9oCLt780BXsGATxTNvxP dNNAjm1ncPH6isSjlYB3g0d22gf1BQ32EblLWXa99UEOF9m4GXHipHm4IwYB7hVkLCOX kE0ctPWNQbfLEiEj5aziIfOwV6b1v3Dvr38hfnF5bmL1gTv/yZobCq03cEtQpFtolpIv fWY1hhd/WOd7cB/bz7zztIIw1sLBLVaVdQxefiWgQEo0QOVVUy3N2RcRnPGayyEetAM/ MZgAaLSrrK+TNL0r7semeGn/1PAKGqDDd1dd0aQWHC6Qyxi0dRi5KbCxM/+kPQM7qUa5 PaJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date:subject:cc:from :dkim-signature:arc-authentication-results; bh=zesxPuAQO0m1dVV/XoKbe06268DxOqpccjIBauwiHEA=; b=kKpYctvdOmGMPB5vpIDQVakr50pB0CHN2sjathe8GDzlwoN2tvUyDIW1vfMixlE0Sy 6h8KE64yhjOqB933lAEBXfP5pYnNtJZZjGqnGQmFJK/0vkMhz85qlQMiRcg3BxqnLina VrMeAo/k2Isv1/1wrMZvEOCw7A6Rcjct9Xr2dUwOfZ/XohSzLUR9vXWvRCjMwTyYZzUa r3m4zAqnLoceq64XvOsvxZPhRugbfYHYSlqz7fTwdK/OTp1Nc8btekb7vvqRrGP43sRz c/sc+LgWuFm7LM9y/uhruRsQ3QiA9kCAlm+Q1CKg0onZidIkes5gM5QA8sV5IAzhwSYw 4V8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=IK+2A0kz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d8si312840pgt.246.2018.03.01.10.44.52; Thu, 01 Mar 2018 10:45:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=IK+2A0kz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161026AbeCASnq (ORCPT + 99 others); Thu, 1 Mar 2018 13:43:46 -0500 Received: from mail-ot0-f195.google.com ([74.125.82.195]:43979 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1034103AbeCASnk (ORCPT ); Thu, 1 Mar 2018 13:43:40 -0500 Received: by mail-ot0-f195.google.com with SMTP id m22so6495806otf.10 for ; Thu, 01 Mar 2018 10:43:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=zesxPuAQO0m1dVV/XoKbe06268DxOqpccjIBauwiHEA=; b=IK+2A0kzfa98Ghq4HJwQ1NB7sZl1qi2RLcwOmqRuxNH2IAXPke1eRE3QVp6R70rQ8w wo4IaMTsQX9tSyKIumePbqAzNQRfk3LzsFBJsyYZJ+KKaCkC2QMhOXVvttoYN/thtPHx Q6ubC7a/q1hbIQNiom+UbjKFHMA/MtcChhDks= 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; bh=zesxPuAQO0m1dVV/XoKbe06268DxOqpccjIBauwiHEA=; b=igKvdPeyvCn9NlaEM+wxtOcXBMF64pBzvWIfeXlieOxRCIToZdyBqRPGkF2/aHIt1R zsmhtxN6usntUmcoRCy/dUcfhI/tmT0LFSLTld+ykeMheFldslrtgpgru+T+CH/ODkR7 YTghXzM1NNySh6wo13eVW9Nj/kQyc9DiTX/i/zy7P3yQ6MHVyTOLRSr/O3Nza72vY9BN REPCwDrereq2itAaZhA6X2eLTNZYGx+qHWJhjg6eQSXrde//tdKrPzb4ECsn/nAq6HPq FrPuCs4vhWU63OyY/KFgjtcZt1ud9VLIbiKA4Sl1MRNtS9hG2seywlCWdOcHuqKbb2HK 2vgg== X-Gm-Message-State: AElRT7HZqSjuFe259uSym8/b+W1TTpc+Sr6xCNhiYMGVWIM+dXR2xgQ8 66WN4p/XENKPMI/plXYDtB9RpQ== X-Received: by 10.157.50.182 with SMTP id u51mr2129515otb.307.1519929819960; Thu, 01 Mar 2018 10:43:39 -0800 (PST) Received: from djkurtz2.bld.corp.google.com ([2620:15c:183:0:1cfd:61a5:7215:5f9c]) by smtp.gmail.com with ESMTPSA id q12sm2326432oti.6.2018.03.01.10.43.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 10:43:39 -0800 (PST) From: Daniel Kurtz Cc: adurbin@chromium.org, briannorris@chromium.org, Daniel Kurtz , Jonathan Corbet , Greg Kroah-Hartman , Jiri Slaby , Ingo Molnar , Thomas Gleixner , Christoffer Dall , "Paul E. McKenney" , Marc Zyngier , Frederic Weisbecker , David Woodhouse , Tom Saeger , Mimi Zohar , "Levin, Alexander (Sasha Levin)" , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list), linux-serial@vger.kernel.org (open list:SERIAL DRIVERS) Subject: [PATCH v2] earlycon: Allow specifying a uartclk in options Date: Thu, 1 Mar 2018 11:43:33 -0700 Message-Id: <20180301184335.248378-1-djkurtz@chromium.org> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently when an earlycon is registered, the uartclk is assumed to be BASE_BAUD * 16 = 1843200. If a baud rate is specified in the earlycon options, then 8250_early's init_port will program the UART clock divider registers based on this assumed uartclk. However, not all uarts have a UART clock of 1843200. For example, the 8250_dw uart in AMD's CZ/ST uses a fixed 48 MHz clock (as specified in cz_uart_desc in acpi_apd.c). Thus, specifying a baud when using earlycon on such a device will result in incorrect divider values and a wrong UART clock. Fix this by extending the earlycon options parameter to allow specification of a uartclk, like so: earlycon=uart,mmio32,0xfedc6000,115200,48000000 If none is specified, fall-back to prior behavior - 1843200. Signed-off-by: Daniel Kurtz --- Documentation/admin-guide/kernel-parameters.txt | 3 +++ drivers/tty/serial/earlycon.c | 8 ++++++-- include/linux/serial_core.h | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 1d1d53f85ddd..20e72cada38e 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -958,6 +958,9 @@ to be equivalent to 'mmio'. 'options' are specified in the same format described for "console=ttyS"; if unspecified, the h/w is not initialized. + A UART clock rate can also be appended after the baud, + as in = 115200n8,48000000; if unspecified, + the default 1843200 will be used. pl011, pl011,mmio32, diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c index 870e84fb6e39..e846f406a1c6 100644 --- a/drivers/tty/serial/earlycon.c +++ b/drivers/tty/serial/earlycon.c @@ -115,12 +115,17 @@ static int __init parse_options(struct earlycon_device *device, char *options) } if (options) { - device->baud = simple_strtoul(options, NULL, 0); + char *uartclk; + device->baud = simple_strtoul(options, &uartclk, 0); + if (*uartclk++ == ',') + port->uartclk = simple_strtoul(uartclk, NULL, 0); length = min(strcspn(options, " ") + 1, (size_t)(sizeof(device->options))); strlcpy(device->options, options, length); } + port->uartclk = (port->uartclk) ?: BASE_BAUD * 16; + return 0; } @@ -134,7 +139,6 @@ static int __init register_earlycon(char *buf, const struct earlycon_id *match) buf = NULL; spin_lock_init(&port->lock); - port->uartclk = BASE_BAUD * 16; if (port->mapbase) port->membase = earlycon_map(port->mapbase, 64); diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index b32df49a3bd5..b772f0d20b18 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -343,7 +343,7 @@ static inline int uart_poll_timeout(struct uart_port *port) struct earlycon_device { struct console *con; struct uart_port port; - char options[16]; /* e.g., 115200n8 */ + char options[32]; /* e.g., 115200n8,48000000 */ unsigned int baud; }; -- 2.16.2.395.g2e18187dfd-goog