From patchwork Mon Jul 9 08:23:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 10513863 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 4471D600CA for ; Mon, 9 Jul 2018 08:25:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EAF428A48 for ; Mon, 9 Jul 2018 08:25:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 217E228A53; Mon, 9 Jul 2018 08:25:32 +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 BBE7D28A48 for ; Mon, 9 Jul 2018 08:25:31 +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=gr/HsRoPEF9zqpvisrJpzdUlqPPYb7fE61XkxgomjfU=; b=BWieRVFbs4dS+2 IoBZ77a3gfZsMmQh2+D0y36oSvGX/S0dDgjB/YT8AeL2aQnQEPmdrbunFvUA03xG0u1K2cDr0QMvc 1axVO46F6IiKGb9MUK/huh4mb0b3gv5cl+9gRC23CqplqSefFk4gccaShR1FJw0G6HwMyOEP5N/yf qFsb8oWGP/zKSrRfqH2vbyEtBwGJBH8yh3dmISNSyzBwgvaCQM0A3BQoV/GLfb03k0Nm4IK07hXN4 E9PgVwMqk5GiVs2B89NDvp8WRYsPVg3/8hcGM9DQEOijvfBmmQkes87EQtlF1hKw7yCSReNajOuCS /QVJjnq6bG7QQAQ+4D9w==; 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 1fcRU7-0003W7-Em; Mon, 09 Jul 2018 08:25:27 +0000 Received: from mail-eopbgr720074.outbound.protection.outlook.com ([40.107.72.74] helo=NAM05-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fcRU4-0002eq-Hy for linux-arm-kernel@lists.infradead.org; Mon, 09 Jul 2018 08:25:26 +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=v6lzufrgKpSWwls8YvcvBETwmqRFtlqVC6eFjR/rF0Q=; b=o2oDj1MlXKWTvyUwiP+9fYBDYybC1jEGXsK+faSZ3MrArryiYBdOhashk3/Rs0goVnzF5McTKQ8+TalwPGSDa67jD159LMYsEcwFGTm9LacbcakDQXtmMYy5WaQqyKSt96h7CtRF5xWRbi2FkXZ3cH0EbaaVvyxHMxMY1qJ+ZPI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; Received: from xhacker.debian (124.74.246.114) by MWHPR03MB2637.namprd03.prod.outlook.com (2603:10b6:300:46::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.930.21; Mon, 9 Jul 2018 08:25:09 +0000 Date: Mon, 9 Jul 2018 16:23:15 +0800 From: Jisheng Zhang To: Andy Shevchenko , Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH v3 3/3] serial: 8250_dw: add fractional divisor support Message-ID: <20180709162315.7f53eb9a@xhacker.debian> In-Reply-To: <20180709160942.11a74f7a@xhacker.debian> References: <20180709160942.11a74f7a@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: TY2PR06CA0001.apcprd06.prod.outlook.com (2603:1096:404:42::13) To MWHPR03MB2637.namprd03.prod.outlook.com (2603:10b6:300:46::7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7b7fb0c1-2e7a-4027-1e75-08d5e5757ca4 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600053)(711020)(2017052603328)(7153060)(7193020); SRVR:MWHPR03MB2637; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2637; 3:VTu7onflysdTGmuaNYbIKZdge93m/xX91tqkvuoEiqaW4nJ9TnvqDsHtBZ/uiwGoPhrC6SrGBuXEPH34iS/6tBmIu9Ldk7QKBlGdpVWMfML/5ksLL2BEN9cN6GY/PPzYfXcUokuC2oVxNqBT0kQbtfSnQIvXb9KfcbIYHweum8xh3g3XD3EWGjxnE1eQy0Jc9BVFKhjn6LQdRm3W95vKvI6LqZ61RXjUyK5IkmENC1/dkOWCvZxeVH7e1KPuHhQt; 25:huAWHSarEXkbggZxhaOo3NtqeWsllNivlAxHGx2DVeR7ruu1olyb60P67fhMItWU2baCS21tkXoZEDC9oF2PtACr4jlGwP0bB4LlUcS7LWmXZbClBV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WSNoUfYr1/C7K8ONBxgGFMQ+iyd2inGVBJkc7leXA2hU5xuzC1aJC1hzEoVe6Oh8nYZweq0XvTLKa09Zc9Di4iCDbJkudD6Y+dz1jWrAjdE1wD4bDl+Iu2IW2ggtIah8DbhJF7lqMe9XIUpgPmc8xBo8T/TzOOJGa77YcqHkOfBbCx+aVD1TmHxuO8Q+Dn6ImS/51MWM7JDgXg3tbWiCmaG6b0W0D6yIQ9tGjc+D6jSOzq9q+bGBI2WybJ+Qt4p4uo7X1x8gvuOLfXlg== 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)(8121501046)(5005006)(93006095)(93001095)(3231311)(944501410)(52105095)(3002001)(10201501046)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123560045)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:MWHPR03MB2637; BCL:0; PCL:0; RULEID:; SRVR:MWHPR03MB2637; X-Forefront-PRVS: 07283408BE X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(136003)(366004)(396003)(39850400004)(346002)(376002)(199004)(189003)(33896004)(5660300001)(2906002)(26005)(386003)(4326008)(25786009)(97736004)(52116002)(6506007)(76176011)(9686003)(305945005)(6666003)(50466002)(7736002)(55016002)(7696005)(53936002)(6116002)(3846002)(86362001)(66066001)(8936002)(11346002)(230700001)(23726003)(8676002)(16526019)(110136005)(68736007)(486006)(47776003)(81156014)(316002)(54906003)(476003)(956004)(446003)(81166006)(478600001)(72206003)(186003)(50226002)(1076002)(106356001)(105586002)(39210200001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR03MB2637; 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-Microso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1j8W96tE2N2iteCJtjPKBWhpgZviTkZnS/gWvLWpormOMTwoMtFPZqZ798l3kcv83/x3EkaU5OReNtZx1Q7A814K3DHZZigTdyS6Cp+PfOrLUlP30I9MbAnv4I2HY3zyq149tutxmxTciHVa+WHEtmFqQHjQx8+6tGY2XV97HlVuGSfiuDLzBEiTI6LOINs2b2pkgMNS+13ULHnyQ5iwL8w7zd9G/PjN27ndCKyGP8YHonmIwTKm2dXEoWKq/RCZkzteJNTupg44oPkYnq+cD2vBARaGmgLDZ+6nO49WP40s2x4C9lRUWVkN8FQVqgiSkl2NjS3j+WEe/4embgFbNNog==; 5:msd1FIKm45CDVKGN3pUwoZBNohIgeRDGJrCABrGq3A/ux2MytpkylwtIQKDSpooR2YuOC7laDbku7i2CFqeHixRjMzh+nJT7RR1gZw54yrDaS4NuL2/gWVivpt9OxT7IQr/Ksx2wV/iYbloxgtsNV5oJz1rf6ScT0od8HiZ++1Y=; 24:GlQek4X0IU9AwWjV4EkgYHIXM8nb85rjIvC5f+bzQBcd5EhBv71SaPJlLObgFJ1lqvyzDqHKWPvNBdpRMpaaqFl43SREdcrjDj+dilTXn3U= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2637; 7:ZxysR+BPzNLqUfZpq7kP0QqXQoaoDYjiKpNoG9AHj4CJDtZrjmI7tDOSVKzZHkhZ2RPUKmSGSdMWTDYuyt4x/ERgEN3UzX78a7kwM22g5UkPsYTUW5oymNkaRSsdnlMqRKphCYRsj5eJiXVFMUDJ0q4DBaJgYZ23RzvVQhY7h/jRtVTizGUWOEtvAQoHxpz50/lG7UXCKWF3IuiTRvK+C5lmlzzpZvnQVYoS5XFb1vu3ivFhSB0rSnCKchcC2phu X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2018 08:25:09.3165 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7b7fb0c1-2e7a-4027-1e75-08d5e5757ca4 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR03MB2637 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180709_012524_647150_22C64E3D X-CRM114-Status: GOOD ( 10.53 ) 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..e90c3d229f00 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 = clk / (16 * baud) = div(I) + div(F) + * "I" means integer, "F" means fractional + * + * 2^dlf_size * clk / (16 * baud) = 2^dlf_size * (div(I) + div(F)) + * so, (clk << (dlf_siz - 4)) / baud = (div(I) + div(F)) << dlf_size + * + * let quot = DIV_ROUND_CLOSEST(clk << (dlf_size - 4), baud), we get + * div(I) = quot >> dlf_size + * div(F) = quot & dlf_mask, where dlf_mask = GENMASK(dlf_size - 1, 0) + */ +static unsigned int dw8250_get_divisor(struct uart_port *p, + unsigned int baud, + unsigned int *frac) +{ + unsigned int quot; + struct dw8250_data *d = p->private_data; + + quot = DIV_ROUND_CLOSEST(p->uartclk << (d->dlf_size - 4), baud); + *frac = quot & GENMASK(d->dlf_size - 1, 0); + + return quot >> d->dlf_size; +} + +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;