From patchwork Wed Jul 11 07:11:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 10518853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D03246028E for ; Wed, 11 Jul 2018 07:14:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B954F20069 for ; Wed, 11 Jul 2018 07:14:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA9362621E; Wed, 11 Jul 2018 07:14:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4715F20069 for ; Wed, 11 Jul 2018 07:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SMzbTuqMwPRq/94Ac1R7teq2Pk2571bPBoS3lK7WXK4=; b=ry2eoU1j11m3CR xUoagNUZGxOdRrABSKBShXqQeMp+2eVyaz1L5dwd0ABnPuotJVxckfy+MP5b/V7yOgw34QbhgE5xj wz69cX5JrCKRINsJT8cT1yjqPi1KSsApsnFm6m6NgjGNYcDeWHJYwkEZaFltRt2HbFqeECGa+KsjY OKpnXj+MG2wLPNxIOmBz8TlxdmMZJhik3jVVxzTKt0zp5Kglx7OKcLrLyoi1UtcsAHk5z/QnUxT9/ HW95F2MsSU7vqaBtsJQBLNyKqPTwuzGd4UlEDJIooZzP6hqJ+z7OuroefAJk1sH3p+fNl4z/6aH5+ XT2LqDI/SBVSnQ/OK8uw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fd9KC-00071d-1I; Wed, 11 Jul 2018 07:14:08 +0000 Received: from mail-co1nam05on0615.outbound.protection.outlook.com ([2a01:111:f400:fe50::615] helo=NAM05-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fd9K6-00070A-0w for linux-arm-kernel@lists.infradead.org; Wed, 11 Jul 2018 07:14:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Synaptics.onmicrosoft.com; s=selector1-synaptics-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EQ99kCLOH+nlmJcUSHCHXSEQQw+mlIb/Wc8fgLp77ew=; b=C8P4uIhrnIF3xSIHDZXuKhuMCXEbqHDIUWzSDho2cmxeuOfAConT2URD3NRvmC5LkSXpZ62xCotAgcokt4g48xWDZnB1gvwP2YrTAjEndh0TuLTRFn78da+cea/nRd8MFLci024cJdBhAZ+dxVd7qqJJHYLjU/bAyeR+YT1bSjU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; Received: from xhacker.debian (124.74.246.114) by DM5PR03MB2633.namprd03.prod.outlook.com (2603:10b6:3:43::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.952.17; Wed, 11 Jul 2018 07:13:44 +0000 Date: Wed, 11 Jul 2018 15:11:11 +0800 From: Jisheng Zhang To: Andy Shevchenko , Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH v5 3/3] serial: 8250_dw: add fractional divisor support Message-ID: <20180711151111.6f417020@xhacker.debian> In-Reply-To: <20180710111516.13b8c570@xhacker.debian> References: <20180710110942.5b0a016e@xhacker.debian> <20180710111516.13b8c570@xhacker.debian> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Originating-IP: [124.74.246.114] X-ClientProxiedBy: MR2P264CA0020.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:1::32) To DM5PR03MB2633.namprd03.prod.outlook.com (2603:10b6:3:43::7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 57afed61-0749-4b8a-7830-08d5e6fdd914 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:DM5PR03MB2633; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2633; 3:7hPW7vHj5VJkAYLBlTLlCZPsMpVJVG2Eig287PbfnPp+5UAfWSBgw8VigT6p0TXNcwdDfgBJE9SGxViF+qtH7E9iFIbCeIsSpYT7rnKWCvId8pSONWV4FNKi4NwtRDue4v+YerX6OmTd8CHiCVoC/OZrwPP+P/kfHeGRxkkedI/vfW7rFg9EG+S+fOY6sEtyaVy39IfFpm5/SEeQ/8MdZQkyIAIzOlR2EqyH9MJYOtLaCsJTBmW0+86phYs2dsdM; 25:hdcjhG+iJLZemxTy8gMBImSQU5vXUBTMSzMuvPmGCmnzjKaUfCmkQ5OHMUwrg2zULeFYJ0YldBguYdO3VubrGapXcL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1yLe; 4:1+KAt/+e3UrBdEXLoHEoPuYXwpbnXv1ZopJlSVQUcgONpkNicgWL0fY1q0Tz2HDvXkRGbQ9wjgTIYp1IJeFVQDOWBBARxRNsWMXDMaOSfHVk8+KCIdPHP2ax1fCeX1/f51zZUgJpH06ihdSswoEZ5higQ7s2qw1QFQFzVfJAj/24kSK+jB6GWGu3wNJgPe972cXDQry12sIMBnubc0GiZSgbWOraYJSYC7IyNvdyYCnmySCnOc/lm9myJ2dSUa9nl670lFyOxU9pPUZzBB0fPw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(10201501046)(3231311)(944501410)(52105095)(149027)(150027)(6041310)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:DM5PR03MB2633; BCL:0; PCL:0; RULEID:; SRVR:DM5PR03MB2633; X-Forefront-PRVS: 0730093765 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(376002)(39860400002)(366004)(136003)(396003)(199004)(189003)(81156014)(81166006)(55016002)(8936002)(6506007)(386003)(26005)(186003)(2906002)(4326008)(8676002)(16526019)(9686003)(3846002)(25786009)(23726003)(6116002)(5660300001)(1076002)(6666003)(230700001)(97736004)(54906003)(110136005)(47776003)(50226002)(486006)(476003)(53936002)(105586002)(106356001)(478600001)(446003)(11346002)(956004)(86362001)(68736007)(305945005)(7736002)(66066001)(72206003)(7696005)(76176011)(52116002)(33896004)(316002)(50466002)(39210200001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB2633; H:xhacker.debian; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: synaptics.com does not designate permitted sender hosts) X-Microsoft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M/QzM9QRwG+S3J9sFp6r+IZDrqKKeWQwc7hPcNXqKmYpofn0OE985FmzjT6JaUub41vwGtu9g+ViCHLWBq4BWU55+pRaxteUt4Dd88G67y4PjKp8wWRajTBiStA6gAUu0wXv4iOCQVbzngCpnF/5590Pt0mMl1ZIv0rTx6D75WCiSVXH2CVkdgH8lrKQjWWcdRG3L0rqbW5h29jxrbVR8vt8d0Wt22rU8ZtHgMiWDyhrxt76thiXB5/8YrSq8YarsfQcEKZ2KYyE4e7WCItBBcu6EsNuhroQXX6anw1sVnO4oxb8mp5ACszq8QlDHUzuvL0V1FvJqX9bMs1Ko3647rCTM1Dt8g==; 5:cyGsdkIbYviCATPj4+vfiwxdmDM3WEhAAig6nYFu+db+U/s1q0Xok/xmyS4a2ONziVFYiu/65xBFLIwutbJ/kbaC2XYGFbUK1ysag4OEMA+7WHImkV5SOc/RPtWgzdlE+6Uyj171pYAg3ew5iMCuKm6dGKfh7Z/5IMr2l5hgNqI=; 24:lkEoYRpZ0DlAj/SCPALggYeiVfJYiJHr7fIMqHM44l96rJ+b1RsEGtz5t8S2YgkXt4NAGIavzNkNNx5QEPhHE7HBmRfp3Ac85Ew0kVUMTQQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2633; 7:A/6tPEzy40uBFBfH/XVqMUCuYhAx2rUKNItWUa0fIvlvojDp7dfPkhmniLv17gCqqzOgS37qCmUDs0p9sD7s/gZgCl6DdTnghZ214q31X1/jzqQtpE3MtI4z4TyaLf9DizshPBBnUR9D3e202I3US7k/jKZ/Nf5KBYxg3yP1hFj8+iTYBqtbUMgH22Hf3KUQmdmWv/of65Bv0d9JhcUyPOl25MbmG4DElVzlMvi3CLJSn5Fnn+7SK+S5rlq3ef1m X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jul 2018 07:13:44.9103 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 57afed61-0749-4b8a-7830-08d5e6fdd914 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2633 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180711_001404_648170_F29D8146 X-CRM114-Status: GOOD ( 10.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP For Synopsys DesignWare 8250 uart which version >= 4.00a, there's a valid divisor latch fraction register. The fractional divisor width is 4bits ~ 6bits. Now the preparation is done, it's easy to add the feature support. This patch firstly tries to get the fractional divisor width during probe, then setups dw specific get_divisor() and set_divisor() hook. Signed-off-by: Jisheng Zhang --- drivers/tty/serial/8250/8250_dw.c | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index fa8a00e8c9c6..5a60c4814d62 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -31,6 +31,7 @@ /* Offsets for the DesignWare specific registers */ #define DW_UART_USR 0x1f /* UART Status Register */ +#define DW_UART_DLF 0xc0 /* Divisor Latch Fraction Register */ #define DW_UART_CPR 0xf4 /* Component Parameter Register */ #define DW_UART_UCV 0xf8 /* UART Component Version */ @@ -55,6 +56,7 @@ struct dw8250_data { u8 usr_reg; + u8 dlf_size; int line; int msr_mask_on; int msr_mask_off; @@ -366,6 +368,37 @@ static bool dw8250_idma_filter(struct dma_chan *chan, void *param) return param == chan->device->dev->parent; } +/* + * divisor = div(I) + div(F) + * "I" means integer, "F" means fractional + * quot = div(I) = clk / (16 * baud) + * frac = div(F) * 2^dlf_size + * + * let rem = clk % (16 * baud) + * we have: div(F) * (16 * baud) = rem + * so frac = 2^dlf_size * rem / (16 * baud) = (rem << dlf_size) / (16 * baud) + */ +static unsigned int dw8250_get_divisor(struct uart_port *p, + unsigned int baud, + unsigned int *frac) +{ + unsigned int quot, rem, base_baud = baud * 16; + struct dw8250_data *d = p->private_data; + + quot = p->uartclk / base_baud; + rem = p->uartclk % base_baud; + *frac = DIV_ROUND_CLOSEST(rem << d->dlf_size, base_baud); + + return quot; +} + +static void dw8250_set_divisor(struct uart_port *p, unsigned int baud, + unsigned int quot, unsigned int quot_frac) +{ + dw8250_writel_ext(p, DW_UART_DLF, quot_frac); + serial8250_do_set_divisor(p, baud, quot, quot_frac); +} + static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data) { if (p->dev->of_node) { @@ -426,6 +459,18 @@ static void dw8250_setup_port(struct uart_port *p) dev_dbg(p->dev, "Designware UART version %c.%c%c\n", (reg >> 24) & 0xff, (reg >> 16) & 0xff, (reg >> 8) & 0xff); + dw8250_writel_ext(p, DW_UART_DLF, ~0U); + reg = dw8250_readl_ext(p, DW_UART_DLF); + dw8250_writel_ext(p, DW_UART_DLF, 0); + + if (reg) { + struct dw8250_data *d = p->private_data; + + d->dlf_size = fls(reg); + p->get_divisor = dw8250_get_divisor; + p->set_divisor = dw8250_set_divisor; + } + reg = dw8250_readl_ext(p, DW_UART_CPR); if (!reg) return;