From owner-svn-src-head@freebsd.org Wed Nov 18 06:24:23 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4C927A3130C; Wed, 18 Nov 2015 06:24:23 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EF1EE18D1; Wed, 18 Nov 2015 06:24:22 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tAI6OLHn080769; Wed, 18 Nov 2015 06:24:21 GMT (envelope-from adrian@FreeBSD.org) Received: (from adrian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tAI6OLB5080767; Wed, 18 Nov 2015 06:24:21 GMT (envelope-from adrian@FreeBSD.org) Message-Id: <201511180624.tAI6OLB5080767@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: adrian set sender to adrian@FreeBSD.org using -f From: Adrian Chadd Date: Wed, 18 Nov 2015 06:24:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r291010 - in head/sys: conf dev/uart X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Nov 2015 06:24:23 -0000 Author: adrian Date: Wed Nov 18 06:24:21 2015 New Revision: 291010 URL: https://svnweb.freebsd.org/changeset/base/291010 Log: uart(4) - make the 8250 uart baudrate tolerance build time tweakable. It turns out on a 16550 w/ a 25MHz SoC reference clock you get a little over 3% error at 115200 baud, which causes this to fail. Just .. cope. Things cope these days. Default to 30 (3.0%) as before, but allow UART_DEV_TOLERANCE_PCT to be set at build time to change that. Modified: head/sys/conf/options head/sys/dev/uart/uart_dev_ns8250.c Modified: head/sys/conf/options ============================================================================== --- head/sys/conf/options Wed Nov 18 02:18:14 2015 (r291009) +++ head/sys/conf/options Wed Nov 18 06:24:21 2015 (r291010) @@ -650,6 +650,7 @@ BKTR_NEW_MSP34XX_DRIVER opt_bktr.h # Options for uart(4) UART_PPS_ON_CTS opt_uart.h UART_POLL_FREQ opt_uart.h +UART_DEV_TOLERANCE_PCT opt_uart.h # options for bus/device framework BUS_DEBUG opt_bus.h Modified: head/sys/dev/uart/uart_dev_ns8250.c ============================================================================== --- head/sys/dev/uart/uart_dev_ns8250.c Wed Nov 18 02:18:14 2015 (r291009) +++ head/sys/dev/uart/uart_dev_ns8250.c Wed Nov 18 06:24:21 2015 (r291010) @@ -25,6 +25,7 @@ */ #include "opt_platform.h" +#include "opt_uart.h" #include __FBSDID("$FreeBSD$"); @@ -57,6 +58,16 @@ __FBSDID("$FreeBSD$"); #define DEFAULT_RCLK 1843200 +/* + * Set the default baudrate tolerance to 3.0%. + * + * Some embedded boards have odd reference clocks (eg 25MHz) + * and we need to handle higher variances in the target baud rate. + */ +#ifndef UART_DEV_TOLERANCE_PCT +#define UART_DEV_TOLERANCE_PCT 30 +#endif /* UART_DEV_TOLERANCE_PCT */ + static int broken_txfifo = 0; SYSCTL_INT(_hw, OID_AUTO, broken_txfifo, CTLFLAG_RWTUN, &broken_txfifo, 0, "UART FIFO has QEMU emulation bug"); @@ -123,8 +134,8 @@ ns8250_divisor(int rclk, int baudrate) /* 10 times error in percent: */ error = ((actual_baud - baudrate) * 2000 / baudrate + 1) >> 1; - /* 3.0% maximum error tolerance: */ - if (error < -30 || error > 30) + /* enforce maximum error tolerance: */ + if (error < -UART_DEV_TOLERANCE_PCT || error > UART_DEV_TOLERANCE_PCT) return (0); return (divisor);