From patchwork Fri Sep 11 12:20:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sperl X-Patchwork-Id: 7160461 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 83FC39F380 for ; Fri, 11 Sep 2015 12:23:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B375E20844 for ; Fri, 11 Sep 2015 12:23:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AE8122081E for ; Fri, 11 Sep 2015 12:23:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZaNKm-0007l0-Kx; Fri, 11 Sep 2015 12:21:40 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZaNKk-0007kN-W5; Fri, 11 Sep 2015 12:21:39 +0000 Received: from 212-186-180-163.dynamic.surfer.at ([212.186.180.163] helo=cgate.sperl.org) by casper.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZaNKi-0001LL-P3; Fri, 11 Sep 2015 12:21:37 +0000 Received: from raspcm.intern.sperl.org (account martin@sperl.org [10.10.10.41] verified) by sperl.org (CommuniGate Pro SMTP 6.1.2) with ESMTPSA id 6343073; Fri, 11 Sep 2015 12:21:03 +0000 From: kernel@martin.sperl.org To: Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Russell King , Stephen Warren , Lee Jones , Greg Kroah-Hartman , Jiri Slaby , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rpi-kernel@lists.infradead.org, linux-serial@vger.kernel.org Subject: [PATCH 1/4] serial: of-serial: allow for a custom clock divider different from 16 Date: Fri, 11 Sep 2015 12:20:50 +0000 Message-Id: <1441974053-2630-2-git-send-email-kernel@martin.sperl.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1441974053-2630-1-git-send-email-kernel@martin.sperl.org> References: <1441974053-2630-1-git-send-email-kernel@martin.sperl.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150911_132136_869559_F30B8FFB X-CRM114-Status: GOOD ( 12.26 ) X-Spam-Score: -0.9 (/) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Sperl MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Sperl The bcm2835 SOC has an auxiliary uart that is compatible to ns16550. the only difference is that it has an internal clock divider of 8 instead of 16. The net result is that the baud-rate is twice the baud-rate requested. This patch allows to configure an alternate clock-divider in the device-tree, which then scales the clock coming from the clock framework to get scaled by 16/divider. Signed-off-by: Martin Sperl --- drivers/tty/serial/of_serial.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c index afae58a..2fcbfee 100644 --- a/drivers/tty/serial/of_serial.c +++ b/drivers/tty/serial/of_serial.c @@ -65,6 +65,7 @@ static int of_platform_serial_setup(struct platform_device *ofdev, struct resource resource; struct device_node *np = ofdev->dev.of_node; u32 clk, spd, prop; + u64 clk_scaled; int ret; memset(port, 0, sizeof *port); @@ -84,6 +85,19 @@ static int of_platform_serial_setup(struct platform_device *ofdev, clk = clk_get_rate(info->clk); } + /* a custom clock divider instead of the default 16 + * this (as of now) does not change the low level behaviour + * but only scales the clock accordingly + */ + if (of_property_read_u32(np, "clock-divider", &spd) == 0) { + clk_scaled = (u64) clk * 16; + do_div(clk_scaled, spd); + dev_info(&ofdev->dev, + "scaling clock %uHz to %uHz to allow a clock divider of %u\n", + clk, (u32)clk_scaled, spd); + clk = (u32) clk_scaled; + } + /* If current-speed was set, then try not to change it. */ if (of_property_read_u32(np, "current-speed", &spd) == 0) port->custom_divisor = clk / (16 * spd);