From patchwork Mon Jul 2 10:06:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 10501181 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 716766035E for ; Mon, 2 Jul 2018 11:37:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E367286D6 for ; Mon, 2 Jul 2018 11:37:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FD67286DB; Mon, 2 Jul 2018 11:37:14 +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 D09D0286D6 for ; Mon, 2 Jul 2018 11:37:13 +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=HdNbVWYp69TFL6OSqNH7lKfXOaTUANDC27Rk8tXmQu8=; b=QYvUn0g9sIdp1V 1BY1YvCahEnMlQlm+ehyU9YTXtDocKGOExu97zCpy15N8lJDFNE3bYJWAVROkS0GPr7GlwlKLAr7q f33BidTcqesG+X6rZLsMyNEF2MDMZ6uuoz4CpWX8a4B5B7+s+jpucNCQ7DgCNWHHMqJR6BOI3s0Wp f4lqGFpg7YZ/NGww1FfjKf2hOWNJJ8jYfGxiymfm6J6aeDSTJ+GMOo2A63xZg2lougHQciDg7lQj4 82ZsF4GUJSYq3pb3GVL669c0ZwGsQ+OBPhNmI7o1RU9B2oqbOPDULAHzCLFUitRX+IWsdP3PSkcn9 RcUbPF/8a2JRUSgfwNUw==; 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 1fZx8n-0006Ib-6Q; Mon, 02 Jul 2018 11:37:09 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fZwdp-0001A6-NU for linux-arm-kernel@bombadil.infradead.org; Mon, 02 Jul 2018 11:05:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To:From:Date:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=lBDDrU3mCCzyGMorricuFF+M8FaNll9BhF+4kdPiXhw=; b=djmJrQpLE7wpCTzLuZPesOmJR9 Y7DXg1wGACV5qnbSHU6TQW4GDnspJ7fUzaFzphUnVLZVnbO3RcbTJAAcOW0S5qX1xzJCBwWBEjseL Epc91mTPYIJrclHK23w0Qg1qG3IjvcDGqsYPWtClb7UXCZZ47xwVuBPmGwUI60zfOgEYdveJ6ylxO lLbiZRs1V+d0ndzpysBHWtVzEfjA5W9KcODiNS/vETz93hHZk4tXBCYB9pnnDy3YH01yW2XoeIS5h 3Otp6vz4no9nFQdtbiLR6ZJyeNxINiQ90PwOnD+SG2bW9zFHrKubgwtj+jmZW/n3cnDr6No/490Zb LdaEpRxw==; Received: from mail-bn3nam01on0054.outbound.protection.outlook.com ([104.47.33.54] helo=NAM01-BN3-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fZvlM-0003sD-En for linux-arm-kernel@lists.infradead.org; Mon, 02 Jul 2018 10:08:53 +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=lBDDrU3mCCzyGMorricuFF+M8FaNll9BhF+4kdPiXhw=; b=pdJ9oARP7SckEJbKbonR3ADlvwAjX+9A1Bg5Rcn3tmkkm0OJKVZlM8rFdyIN/67GQbtmWddsM/YIgJyq5kW2hEH5k/TUu0pP5wpvI0Pd2EMS9CpI0SG4w8AVq6cdvBd6HbJG957tmD189LtITIlPp7PjMLgcf7+WmLSmRnnkHtg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; Received: from xhacker.debian (124.74.246.114) by DM5PR03MB2636.namprd03.prod.outlook.com (2603:10b6:3:43::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.906.24; Mon, 2 Jul 2018 10:08:34 +0000 Date: Mon, 2 Jul 2018 18:06:48 +0800 From: Jisheng Zhang To: Greg Kroah-Hartman , Jiri Slaby , Andy Shevchenko Subject: [PATCH 2/2] serial: 8250_dw: add fractional divisor support Message-ID: <20180702180648.039dcee3@xhacker.debian> In-Reply-To: <20180702180428.331b36c5@xhacker.debian> References: <20180702180428.331b36c5@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: TY2PR02CA0012.apcprd02.prod.outlook.com (2603:1096:404:56::24) To DM5PR03MB2636.namprd03.prod.outlook.com (2603:10b6:3:43::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: db781ae2-1974-4251-404f-08d5e003c65f X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:DM5PR03MB2636; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2636; 3:Qt2DyVELq4nx5voO11Z97GmrodqZqvvLJUUtka3MyUbiX5MHZmhe6EN7RzhT/jHYYP2SKjJLBTDPpy5j0GoLK8HyUJtM7qy+DXtMui9OfEBrUYTY3/VuSaprkg94k1Lw/AUUDfLy6cZuNwadbrbAQZKSn2N6bnow5Bpu7UN5ixpzprHXW9L/w2oBZT07VQS3LT+NIj7p7M8D+vSqaFZI3Legv/znf4IBzPFLHoRnMHBgClP7XETZzO0Xv6x6A0eg; 25:WcnAoFWgFRjSZ+JjPEl5eFj/BqUExITf+eZP2VsxDLNo3GGTv0MHOQ4oomNuVl2SSm9AND+zCZj96Xut7syoq4lvlyz7lW2HQvY1WhZTN8tFEq5d6iuHZEvgK6IWh/dyCMGHCezxrEWZw49iumE2wMd+/51xjOD4OF7UNjwsW8ZAuBMorNaKJsXpa3/wqkuKY2+p/oJFWsA35pau0WwmSwCx1tldadzmIRt+eLVhpaPCZKpu2gpiwrSC83ne5PzwxDAqrc+gGTrWEN0d+SQWHvo41DurwzFzAESxg3T5tOOFdqQrx0ig2yuOPN7cJmSGN97PL1vLcATM1Tvqzt4A0Q==; 31:SMu9+ha+W6ez/rd5neS1bYi36hqp6lwF/Iw8lqJOriBi194DOnadg+mavV6qQKhTdJrdbl/uoiXduAcERPCLnHRzWNtiPz7nAC2Sl4Bl60QPHAtr8Hih2cVduGoB9DzKx8rKRQt83BXOelf6GnOjlQDRzXoEThzUq5HFCk+tXn58CVQNlUgptewa3HUksGjo09iU7MIdBudhXx6oXC//UHtrt2S+L3O+/y4g4SrBTcI= X-MS-TrafficTypeDiagnostic: DM5PR03MB2636: X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2636; 20:ovxXd4sTe1/4w6GkNLwl2XQ4x28rEsovqxBl0l+pNYGWuLs1qvGfV27KE1951D35fJWkvkmy53DlXD0GzuEUn7XESEhMfJL265/R/8MkF1pgi4DcntwX7A667fAvnjGFdf3IGXPEBiQjThRhQWneeXQ6tbouTfLbG8UQhGxt4uVV1brDlTDy+uOY0N0TqiAo6L14hkHyqaS9JnYHBv5NYe+UlmIoff3yOtK+VU6QsRs0LzAeg1MGs4r1jU3m/02vSrq6TOXRKZxd52+lWbFxPFVGCV8RLqgNNAsJZ4JvyhtOylFXcA6Ncrvm30HfFZju4ldKRSGijxvSEHwBfqVXNDPuQmqjd1HDjSqcZ8m+tX35ldAve6qmP1CRxVOn7vTFrXqQxNKLI5MRXp5Hf1jzF3ZS42KUbGIc4FJ2OrQcOU3oPMkqGz+GgJs0hwBlGxPrEFuM6kBmbhe6MO/jVzYohbmbO9r3rhR+3TvbMw0CTVRbUKSCjcz36DjlYvzgq7Jv; 4:Zxlrr8KzxSu3p2PMRpp8thmmKfEX403I76QK97otvOCuFsOQsK/GcbgZn+VR65F9GDb9fyEhfsbx9KUCer37vFBlsnIjQ8NPg6kn4QPOACOeQTeFISSmngAS2wXeTWb6zjtboala9CQ2Yg1HA1xQcxOnQYfTc/THXIUJHk0zdWq8auORmROgp6DmUnaZG1HXCt5cj5YUb4QzafI69/f0U8WqqdRvjjakCDtnoJf0YR4mzpCWZ8IisoEtGwHcg2LnoQJNkBUk96c3LACFUt7ZHA== 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)(3231254)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:DM5PR03MB2636; BCL:0; PCL:0; RULEID:; SRVR:DM5PR03MB2636; X-Forefront-PRVS: 07215D0470 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(366004)(396003)(346002)(136003)(39850400004)(189003)(199004)(25786009)(50226002)(72206003)(446003)(476003)(11346002)(956004)(4326008)(52116002)(7696005)(486006)(105586002)(76176011)(106356001)(305945005)(8936002)(33896004)(7736002)(81156014)(8676002)(55016002)(9686003)(478600001)(81166006)(47776003)(68736007)(230700001)(23726003)(1076002)(6116002)(86362001)(3846002)(6666003)(5660300001)(97736004)(2906002)(6506007)(386003)(186003)(16526019)(316002)(50466002)(26005)(53936002)(66066001)(110136005)(39210200001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB2636; H:xhacker.debian; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: synaptics.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR03MB2636; 23:FXNEIQ2g9+mO6TN0AQE0mKYULplsUJJxEuJSU2QOW?= =?us-ascii?Q?+CwBO0stCLnRaPZFC0iimHACvxBloZCSnaY10attcHu84OJpjllFAUxQ88aR?= =?us-ascii?Q?25BRB5BDPYnxVG49GTNoiu/TxpUpk6yBwO2nlN7SXPQOuzuw2mEKmc1WFIdU?= =?us-ascii?Q?6IKHfM7kQa8FreFvdBwYnPhPFVvyI8I7oYAZLVMbB8BMhUxeIZkHHfAnIdg8?= =?us-ascii?Q?CT3rV+C1D1Zgb7taDJpHiXn41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5OfCCwriiN8HK5miGhNUqjQG98G7SXGgJy+ynqoAYPr4di/Gji/yxe9bw2o7aXB2z4LFbyjm2AWS6VFUghVCGWDx3lrk8qGqcM3Zy4q55Pcndzw5MK/UaQt2QWZRNUdOVKsQKdulFGMsaqufkzoizGJADqbBXVLQz69pamE=; 24:vcX84LUNkpIzFu9lgTypytKnHIQNj69StUY8bkgmoOkU5mZyYNGmoVveGDy4bvMLMDEUxGWlT1Br4PaEAdd20MbuOEv+zzLMJb73vyD9C7U= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2636; 7:sGVZPI3Djf++LFvDWMwFnNW1xQgUwQ7YSsrEq94XOo9xMLnR2H2Mh3jvOac0t2etf6BWbT5Yxp25vj+OMbNIUH9X6oXGkMt4RoIGHTeeWcMDkKaZfh8sin2V2zbnWQtJ+vYd+wgjxxsWI/07+gGa4tfxlLf1f8MgYj3RcgKlt9a3BboNdlwJKJ6D+qRnsevJ7TEQdsHNhTmCqmRkBDoLI1Dg1p8x77/XUdl3PyfnWIbcMTeDILx+k/kCa5I2r2Iq X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2018 10:08:34.2783 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: db781ae2-1974-4251-404f-08d5e003c65f X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2636 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180702_060852_543846_4F3F3597 X-CRM114-Status: GOOD ( 15.17 ) 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-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.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 checks the component version during probe, if version >= 4.00a, then calculates the fractional divisor width, then setups dw specific get_divisor() and set_divisor() hook. Signed-off-by: Jisheng Zhang --- drivers/tty/serial/8250/8250_dw.c | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index aff04f1de3a5..367a73507c5e 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -31,9 +31,12 @@ /* 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 */ +#define DW_FRAC_MIN_VERS 0x3430302A + /* Component Parameter Register bits */ #define DW_UART_CPR_ABP_DATA_WIDTH (3 << 0) #define DW_UART_CPR_AFCE_MODE (1 << 4) @@ -65,6 +68,7 @@ struct dw8250_data { unsigned int skip_autocfg:1; unsigned int uart_16550_compatible:1; + unsigned int dlf_size:3; }; static inline int dw8250_modify_msr(struct uart_port *p, int offset, int value) @@ -351,6 +355,34 @@ static bool dw8250_idma_filter(struct dma_chan *chan, void *param) return param == chan->device->dev->parent; } +/* + * For version >= 4.00a, the dw uarts have a valid divisor latch fraction + * register. Calculate divisor with extra 4bits ~ 6bits fractional portion. + */ +static unsigned int dw8250_get_divisor(struct uart_8250_port *up, + unsigned int baud, + unsigned int *frac) +{ + unsigned int quot; + struct uart_port *p = &up->port; + struct dw8250_data *d = p->private_data; + + quot = DIV_ROUND_CLOSEST(p->uartclk << (d->dlf_size - 4), baud); + *frac = quot & (~0U >> (32 - d->dlf_size)); + + return quot >> d->dlf_size; +} + +static void dw8250_set_divisor(struct uart_8250_port *up, unsigned int baud, + unsigned int quot, unsigned int quot_frac) +{ + struct uart_port *p = &up->port; + + serial_port_out(p, DW_UART_DLF >> p->regshift, quot_frac); + serial_port_out(p, UART_LCR, up->lcr | UART_LCR_DLAB); + serial_dl_write(up, quot); +} + static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data) { if (p->dev->of_node) { @@ -414,6 +446,28 @@ 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); + /* + * For version >= 4.00a, the dw uarts have a valid divisor latch + * fraction register. Calculate the fractional divisor width. + */ + if (reg >= DW_FRAC_MIN_VERS) { + struct dw8250_data *d = p->private_data; + + if (p->iotype == UPIO_MEM32BE) { + iowrite32be(~0U, p->membase + DW_UART_DLF); + reg = ioread32be(p->membase + DW_UART_DLF); + } else { + writel(~0U, p->membase + DW_UART_DLF); + reg = readl(p->membase + DW_UART_DLF); + } + d->dlf_size = fls(reg); + + if (d->dlf_size) { + up->get_divisor = dw8250_get_divisor; + up->set_divisor = dw8250_set_divisor; + } + } + if (p->iotype == UPIO_MEM32BE) reg = ioread32be(p->membase + DW_UART_CPR); else