From patchwork Thu Jul 12 01:59:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 10520837 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 C9482602C8 for ; Thu, 12 Jul 2018 02:02:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3EEE2844E for ; Thu, 12 Jul 2018 02:02:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A82D72858A; Thu, 12 Jul 2018 02:02:02 +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 4C00D2844E for ; Thu, 12 Jul 2018 02:02:02 +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=zW96FvadwX0K9vmoJRgZqF6wC4Omnp0etUH/DDW1Tc0=; b=rKA8gl0x1brhh4 B0br8+630MGLkxGieL44y9u2I2kIeRd5NR0GMgaKhoqwI8ig0wC9KMjRqRwHKqKuhK0FiRSHu2/Rd BvJLK98fN2mTryCl/hm08kxzhF9ireYBz9XYaJWJ9B0QdTztpim4ZPU/DrfgKROC+sEhKEnL49M8P r3Ozpi8nB7Yw7XpiEZqM2M3CUDOP34OMgjDXZ7bIOJb6+x1y4LLpnFsNyEXN5z4xsHDGBlaRpZjAP 1zMYlY1cxT2UFpmIz1eVv5x5k8/60VVjXBeJ7UsbSPd/NvPbeOaK2Pugmj4lxq2ayNUxyrnqvG/Ay TPriyJyPINYZntx3KDBg==; 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 1fdQve-0001tr-Nl; Thu, 12 Jul 2018 02:01:58 +0000 Received: from mail-eopbgr690068.outbound.protection.outlook.com ([40.107.69.68] helo=NAM04-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fdQvb-0001qz-Hu for linux-arm-kernel@lists.infradead.org; Thu, 12 Jul 2018 02:01:56 +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=EjT4Y4jqsigNTllH0JnkemM3GlZS/3pcsKL0RroZavE=; b=PUcp890fppHVIh9+z0mzzyVvdirwl7gBUcknJooDeYD4lhbRLHji4gekHglT2kMyb60ZFPEMv72bVEvgu7uPnM5BwKGF/U8ekkd5uNUV+Bm9Jv03fA6JWYnA5W2wH7nQe0rQkQQbris1Q2OIYav0e9xlFrQRqOit9yP76KInO0s= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; Received: from xhacker.debian (124.74.246.114) by CY4PR03MB2629.namprd03.prod.outlook.com (2603:10b6:903:75::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.952.17; Thu, 12 Jul 2018 02:01:39 +0000 Date: Thu, 12 Jul 2018 09:59:40 +0800 From: Jisheng Zhang To: Andy Shevchenko , Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH v6 3/3] serial: 8250_dw: add fractional divisor support Message-ID: <20180712095940.20859423@xhacker.debian> In-Reply-To: <20180712095504.4d9583ce@xhacker.debian> References: <20180712095504.4d9583ce@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: MR2P264CA0023.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:1::35) To CY4PR03MB2629.namprd03.prod.outlook.com (2603:10b6:903:75::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b6a9e9fd-3086-4696-79d4-08d5e79b6a05 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:CY4PR03MB2629; X-Microsoft-Exchange-Diagnostics: 1; CY4PR03MB2629; 3:80/GG2y3RY7UR1vQeutpHW2VTidYZ639UQdcCtjtLsb0cwPrabiuQus09GbkJA/eX/k/ZJbFnNVtb9ife2DWG+6Y/9oNVtV74qQIAN7XRB9wXWLHSsL9rlC7KrhSHo0zQ/JgQORHwlBJK3wl9bMbmkZxOwdjQZhnjRdD0/iNDJjVVP4iTBQe75ECRg8pZl51HWlTcAqMHGhmHIGEGa9aycHwlagT2BJhMqU68lqE6M2ZxoOFDABg70Cii+03UZde; 25:Vy0iaqGFGOFHxFlxShsb96d3xTPpo7y41vnb4b4eVmrU8EuiVKNCUBt/7bZ+luZX+PF9nXqt/MQbQi+/PSV5fmJvK36aSQXBlzjej9RucdrSvsrSU73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tqiJ+8ibu++Hkm+T66z3z7pUgXBW2cfPex40JKiu96Z1Equ4oUMJzYv81j+HCauUdC5jTB+Gr07Nge4e719dLkrGdiTFeRWEj4zTBu+gKc9OlRX65HaPYME227yOKEeTfmcHbaFHCRgQjHoVqKxzKNDuvWTvK5CMiqU4alCuQvvu6xZhRXrtOStCtkQ/y5IyJx4X3yauXfiZ0p5U4HO6k2YpOeOZzDum4BYDBJ8CVK9jsKHnKHVRehbdjc1JdLUfi48XN4ZJZElIIctu7hsX4JvegLSviNEqfQKgWNR4vNOwXPYjJ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(228905959029699); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231311)(944501410)(52105095)(149027)(150027)(6041310)(20161123564045)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011)(7699016); SRVR:CY4PR03MB2629; BCL:0; PCL:0; RULEID:; SRVR:CY4PR03MB2629; X-Forefront-PRVS: 0731AA2DE6 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(136003)(39850400004)(346002)(366004)(376002)(199004)(189003)(110136005)(8936002)(5660300001)(50466002)(8676002)(446003)(81156014)(81166006)(316002)(68736007)(6666003)(486006)(117636001)(106356001)(11346002)(956004)(105586002)(476003)(386003)(6506007)(230700001)(9686003)(25786009)(4326008)(3846002)(1076002)(97876018)(6116002)(23726003)(1970100002)(2906002)(55016002)(16526019)(186003)(7736002)(97736004)(72206003)(70486001)(8266002)(26005)(305945005)(53936002)(47776003)(50226002)(76176011)(86362001)(478600001)(66066001)(33896004)(52116002)(7696005)(39210200001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR03MB2629; 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; CY4PR03MB2629; 23:KAN9UZBBYfHfkNot2S8vRrAiRAsiP+1IP+dQsKsVy?= =?us-ascii?Q?aRYNU0APWfJbthgQraWR3himBoaL2EGlG8C4xF4tKQojeTGfc17K7wfKS875?= =?us-ascii?Q?vgnkM5c/b3SK0qsdis0s6OGeAszt29aWz63OsO4o36m52xDHzKfqErE6Y/dx?= =?us-ascii?Q?CJyRa5k56PdLJqumciGXrjiHTbjQ0nowpV9mgakIX9xZJCLdVElkYXcO/Bdi?= =?us-ascii?Q?4JWvK9nHZX3MItYLoAyYuWBvPbGrFyPdpJOKnNpEApU6rnyvPNIoHCT0OscE?= =?us-ascii?Q?M5TC9M5Ui0JwNUQ4fLhaYJt9yHBXJK6b0H3h34XlPJQLH8zrKqtzvZsvtcvh?= =?us-ascii?Q?4c78O9MzCM51Bwq7QaPIKzn8Tctr+R1nHC5MDe+apWYKwEwcHiXfBtjxwIss?= =?us-ascii?Q?YLBFPRC74vnTtT4p5PWppWgsQrIwEVvyHaMsHihIT5fiiuxQK2p2iho2xFGJ?= =?us-ascii?Q?ZpzvGJUYmKmeM+4G/XPYaAS2Wc3FOjLds5cJUYbY2TDn+oTV0HPLnxswrQnE?= =?us-ascii?Q?DCOhpq3qmrACjnCmyVsaa3c2W00H9L/NXUHjhbQ9/Itb1NSHinwA/w1ODTor?= =?us-ascii?Q?u2gLSg6m3618r3XxnJEijAaM19darQTyTVQYwdFPt18+lgONqFHy+MjD6EvE?= =?us-ascii?Q?MIMvLXB4idyHD90GqvgG1lz8NHEQAYfvcB4SydkwPIiuG4CDmZ3bCdWoL+eS?= =?us-ascii?Q?G07KGdXeH52//3o5GEV2ZCx1wuHrW8833K66tZKvhvBNFOY/Nr5mtG40nPiP?= =?us-ascii?Q?3C5UgvBWbbIlUN7yc0VOkoAnMUq7A1ADMzxiOyQtoUrQoBWJkwK/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H+udA2d4G4w2Enj/lJUxj2ZLCFxZ X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2018 02:01:39.9178 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6a9e9fd-3086-4696-79d4-08d5e79b6a05 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR03MB2629 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180711_190155_635265_E9C5583E X-CRM114-Status: GOOD ( 11.09 ) 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-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@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 Reviewed-by: Andy Shevchenko --- 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;