Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp190070imm; Wed, 11 Jul 2018 00:15:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcNK5z1CYXXpRMS6PMPKdEvWCe/LhhRVEBohrB70JbT4jlPHMzF4x+hhNaaKSrYgqRs8LXE X-Received: by 2002:a17:902:6105:: with SMTP id t5-v6mr27774302plj.92.1531293323773; Wed, 11 Jul 2018 00:15:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531293323; cv=none; d=google.com; s=arc-20160816; b=z8/vebY73hpp5EJQOVIVhH4fE/6HYsX0zM5C2noQsECC/wjhZud/0Vx4NSThvEhzRV 4a1Y2BQzgVcuabJ5HAEobGpZv/T2/xS1kIMf+Yqz+ZcvUDzlbGJp5Q3t9lLL7tLIsFSq Z5Wd3hgLSs0Qmv2c2hL4f9Wd/HZ1+zqzzkg8IRRhaik+buLbP9SmXEyQzoMWvze/WOye kDHzraQR4D5am+2CpY2qp9o4rckq6tz3HPocdkDtlN9vuHXlyChyK/gSGmfTSkuvlV+k tBwQdDmTQ2c2zIpEx1z2uJiGrSYhTfdlWn/Ox+Scz1+90Y4WW+IJKOc159cdme/Tm/0Z oKAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=EQ99kCLOH+nlmJcUSHCHXSEQQw+mlIb/Wc8fgLp77ew=; b=U+DCWLDNXkibqj+6wqxUkLjLku8jdL60JYQM68D7quETEHdi10H6ccWQsYowlzVkRP BARKDfB7FBLJwqIgDTuGTsVzpFiOlymC6VfL+pM2TQkrMQY2i+dA+iu+Yo1OOEcFJBWc mMz+wTzF/Ztbfsjs22cIVTNVWON7GfxuadT1oaMloBazv25Ozy771glgfqSI885GzueF Ar0oeS8xLpc3SpWjS9rpkDakdpRtijkcB/u0XIThPxwquSJV8/17Cc53kgshyS2lGbvo YZhiHs+KHxnfZbBEsjMCssyG9e6eWLzPj8QTU8RS2XRoFlSfrHaE3QERDPaATDt5iUg/ l4fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@Synaptics.onmicrosoft.com header.s=selector1-synaptics-com header.b=C8P4uIhr; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5-v6si8552860pln.405.2018.07.11.00.15.08; Wed, 11 Jul 2018 00:15:23 -0700 (PDT) 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=pass header.i=@Synaptics.onmicrosoft.com header.s=selector1-synaptics-com header.b=C8P4uIhr; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726718AbeGKHQn (ORCPT + 99 others); Wed, 11 Jul 2018 03:16:43 -0400 Received: from mail-eopbgr720044.outbound.protection.outlook.com ([40.107.72.44]:8172 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726575AbeGKHQm (ORCPT ); Wed, 11 Jul 2018 03:16:42 -0400 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 Cc: , , 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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+5UAfW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KzlEJEamQV/Ovl0E5272GQGmSiFAJV/kW6cwkBInyetGkCxYbQORZKRVa/FnSeTVQ3cj7eeMKQHEDO9JMqnW1Lpoc7wbdQdhrh9kHs3OZ83SLKwruZrGkdpzOvUkXGiGoPL7FiDQ4pTlNLr4USXGNRJ8+0H1IxTuGw3KZCs3ZgX8sJQ4Qq59rDhKvhjI8Mx7bDVisbhIFz01VBZpy2CNHGwOwHkXoNdmcsW8+/YMWJ9Val8UOmKU7wzwsdolDM/O5ilRMkjb/KkeIgLWjeb+ELYRvteAGpMk1yLe;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-Exchange-Diagnostics: =?us-ascii?Q?1;DM5PR03MB2633;23:9jOzWY8CFGWr4c3SX/KJJdMBQaWBsaSIWTezBmtwy?= =?us-ascii?Q?VaF9H/CpN17+nwPG2xsCpU66FxaXK2/4ta0QSMHz7X1564Zg2Eg8r9MOAeMC?= =?us-ascii?Q?J1ej7EIyBKFnqbWrO33e2JC7ECmtBDLGlD4KZpj9y9Jijb2ttB5Z9/Gpv5Pn?= =?us-ascii?Q?ZFG4RlwZ8bztad9zEUOPWugX9091XLlR6EhPVr+QaOKU18Ek6Rotpi80PN3D?= =?us-ascii?Q?Zzh8Z0doJyydQQ1bjFwtKUuZMG/dXCxilQ1Et8lCSplM+WYiUotJsasuD0bJ?= =?us-ascii?Q?iHz4Yjb4tUqoT6HUpG5TN3f1XvTFoJblbhEbsyR/wl5VsaWn5zxPEjV82/Q+?= =?us-ascii?Q?DTgpnoM/iFWvtTVwm5BRVgc7JXtWu80Rg380NF24jjQgwM+jLKKyWo9lwoKq?= =?us-ascii?Q?aT0/3NmWwBRZaFXzWYAbZe2naExqf6Sbfqx9tae+wv5Fn7afYFAY4IdmJQAU?= =?us-ascii?Q?SM1qBszEXbOloezPqd/vPShK+uK5Vy8w3w/cAgAGb5vWZKCrEeYZFDJXDNLY?= =?us-ascii?Q?+Fen8cGSrDNBefd+/rUGMp1BgpplsgZTqPWJZZur6zdEv+ouEgUYdfyOnWG4?= =?us-ascii?Q?zmIhBNkX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OgS37qCmUDs0p9sD7s/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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.18.0