Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp165493imm; Tue, 10 Jul 2018 23:44:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfSwe6cz1cL9yXXX8ysGaTRJ2XBL/MYH08GSy/HjRxYiwAaSXzwbk3Z+EZ084JjuYtipUR7 X-Received: by 2002:a17:902:530a:: with SMTP id b10-v6mr28069842pli.316.1531291466956; Tue, 10 Jul 2018 23:44:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531291466; cv=none; d=google.com; s=arc-20160816; b=gdknGEvJAkmggUXmHcIW11TVw1accQ9amNKiDbgTs7foxIAGZMM7yprsmrtUdZ8060 K9Lo+NZ6QUHod4+ayIKx3lO5s5UJWl8nUgmVT7j2w9rEhdIeDAUEPpJRmt5ZPG1hHhKY hkGohXg6JG8iQjHtyT01gm/n245lPpte4qmCdnEiJvckhq3Zmj6YtpRric8zNwHNHscv f2PzVjb++hHOKc6LLhPl+9jurWA2639OwmQjVZg11jSpOBys5D7aW9hb/fDOnDMuQ7WW l/fW5dGHfSHnlfCgcUB2JudKHPD4GErB1JqDoAT1sKziuoXrzocTHrvrWYoXfx9MbaRT rk8w== 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=Kk1NIdEUqQNUdAkQnzsaGiJ0PqhvMBtW5S9Ck5kE3mI=; b=s+ZkVVk+iTIxNqa3X9t90xZRgjiiWaheuVi5QBfQx2flSlGB28QupQ7qIG6ecarMIR qjJblPumQp5eH934x+pqE3kSYB2cc0HtWnHkzMPok2eOL5I8C+E9c6dCgHIqc6N+OROZ Clrf7Fx8AuGfG06Uzv0faQNQNDZRqTsExCgo1QoK34oimEXYGty7FwZcJANPEaNhP+ta J8TjeEVOOoyDJ3rAAykukLdlhoJN/ysjnrm9zfpjQOCgVyeMbCe0mDFwzoyg+UlUatwl AZM0zXt7JakqGNfjxlhrUVVUP+95GqsdLHXfVH4Txy/SrdIAutk1uj9znTOa2o428tdq 9N/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@Synaptics.onmicrosoft.com header.s=selector1-synaptics-com header.b=Asn7SdtE; 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 r7-v6si18234928pgl.1.2018.07.10.23.44.11; Tue, 10 Jul 2018 23:44:26 -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=Asn7SdtE; 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 S1726499AbeGKGqV (ORCPT + 99 others); Wed, 11 Jul 2018 02:46:21 -0400 Received: from mail-eopbgr730081.outbound.protection.outlook.com ([40.107.73.81]:43447 "EHLO NAM05-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726294AbeGKGqV (ORCPT ); Wed, 11 Jul 2018 02:46:21 -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=Kk1NIdEUqQNUdAkQnzsaGiJ0PqhvMBtW5S9Ck5kE3mI=; b=Asn7SdtEjFHS3grOmelUoQqSBq75o7eKiBiIGbnDFg8r4UbnDr1SUZxSl0uAi5rqnqmmwpGNa0PjWJCCJU0wnhbcvz7OgyjcRCjdERzILla4fne4IfD+QrL1bVKfcLOjo8kpArwVWlP8SYPrfR+TFDf9Ysu1T7kPxtWY4quSMUQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; Received: from xhacker.debian (124.74.246.114) by BN6PR03MB2627.namprd03.prod.outlook.com (2603:10b6:404:59::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.930.21; Wed, 11 Jul 2018 06:43:26 +0000 Date: Wed, 11 Jul 2018 14:41:25 +0800 From: Jisheng Zhang To: Andy Shevchenko Cc: Greg Kroah-Hartman , Jiri Slaby , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org Subject: Re: [PATCH v4 3/3] serial: 8250_dw: add fractional divisor support Message-ID: <20180711144125.7d4e6a73@xhacker.debian> In-Reply-To: <8c5b6bbbde12b0836e1f833c86b805a817596654.camel@linux.intel.com> References: <20180710110942.5b0a016e@xhacker.debian> <20180710111516.13b8c570@xhacker.debian> <8c5b6bbbde12b0836e1f833c86b805a817596654.camel@linux.intel.com> 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: PR2P264CA0042.FRAP264.PROD.OUTLOOK.COM (2603:10a6:101:1::30) To BN6PR03MB2627.namprd03.prod.outlook.com (2603:10b6:404:59::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bdf2a545-4dc5-42ac-a18d-08d5e6f99c9d X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017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MlWhwviAf5HCBOiKjA5CSCNzn5zLVp9WZr+li45+nEihJzcszjjewVxc281ke3r/dU9lQ8tnrKdgC3nWjc1S2fEm8XDPQ33D9y98Lf0BI2dv0A3SYgRUd5UO15WEgaIEJ1te6NmAEhtZNkDbH/8ew+C59ewWNtNYQrVS7LB2c0GnOU0a5Eb+s3Sh/OqRXMHW1C2FB+hzJEgWuo6IJ869t0R1EJVf35PDVcjkxWkCMKGdnXiEvfet5WDReZ50eA/iSFwYoAyexX44BNoNIPCTwaOJnc3dJslPXgEJvewUKDmALMnQTAInIObNaxUIng3FNRWt0RwW/zyIYjP+EEB8weSVUTWR8CH8GVsZfuqjN3Je3+UZoonN3zCUz1KL8hhQfFcR3miwl0JPL6BdSMXZeYMiaoywAbOPd5coApXd8pxKy;4:cpyP0R57O6VFd4vbIKsu8HQAZhCcOnCK/cr1LSUm/Yi0hsnqnwPse6l6QqR03lJd6ZjvnUQIS2P4lleg0kIjEXUsSCm5fY4SlMth3fElBUejyt9fCu3xer3MVu5P9MlJHamZL82+bqb5iprPHjOObkulx0VJ+F3I6ib8yk4PKyWyD51rt0Rm2Rg4O0V9HsfYVqdFIB7DcQkuUYTCjuJph9tyCELMIZ2X5nIjcZHQ6jmeU5Znxj7r8gVSjyY8qZuzRmPR0mpLqjXSfDNgKkxFSxL672K1BLPGpxg3hsZVgaA9lpFPuRZLFMgFZHvXqb9jf/oVu8q4jGjyFX91JKlfuOqH9PmdAVXcTMyqeNb37snFfw8OnD7cE9E6SAU5TNZ2 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(166708455590820)(788757137089)(192278398808882); 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)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(6072148)(201708071742011)(7699016);SRVR:BN6PR03MB2627;BCL:0;PCL:0;RULEID:;SRVR:BN6PR03MB2627; X-Forefront-PRVS: 0730093765 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(39860400002)(346002)(396003)(376002)(136003)(189003)(199004)(86362001)(106356001)(1076002)(966005)(6116002)(3846002)(105586002)(23726003)(72206003)(6916009)(55016002)(229853002)(5660300001)(6306002)(2906002)(6246003)(50226002)(230700001)(4326008)(97736004)(478600001)(9686003)(50466002)(53936002)(68736007)(386003)(6506007)(316002)(54906003)(8936002)(81156014)(81166006)(8676002)(52116002)(76176011)(16526019)(11346002)(33896004)(7696005)(7736002)(66066001)(14444005)(47776003)(476003)(186003)(305945005)(446003)(956004)(486006)(26005)(25786009)(39210200001);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR03MB2627;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;BN6PR03MB2627;23:bX1PtEzIyUTAj3SZgoT+jFr+1ixGKyvOflHfRaIjZ?= =?us-ascii?Q?Grs9CjWtL26FrbkPJtHSgXpEz+90X9N42ZtcqUrlEJ/28fYirP4Bj7BGjjv6?= =?us-ascii?Q?1S3hg+9giYCeSUoA7C3BPEtWhNyI6NLGAp3rM8bP0pICkNrW5wOAvdmSsYDv?= =?us-ascii?Q?5x4KWAIMmmFHPcGVlV+hH6xgGKLdpa5cA2sLKTcoSBMBaPs1l6oZEh6551VY?= =?us-ascii?Q?udeHrTNxjIPUbjkNYrkc2ymFy72JbuJxpbN0/GUNeIAd4D3WfpwQprqrpDdP?= =?us-ascii?Q?bLUit09szW84POCF0OoKbf9+PqGeixydbreAmv2ONfBIbE0VQ2Q/CLM1sRve?= =?us-ascii?Q?dCBfeIa88Hh1b4WBGrVh7O0VnxHj4RqWSfo/yo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DxTAfgtCsJIIVI6NgcITpLbLwSp2AyqGz21Fj13+U26dmTTHlqf2Gft6hgmBxq9iE22M0HTN7YBczyXc+9uUkwHJy6ULoQSda0j46h/Brl+QI=;24:nc+RWgDD64mJW+eM8C01/Sod6NWLXn303PYIWYbxFkdDjnq3HtEkGBI/yfHdeKV6DQwUWtwto/sO8JcSDzVfhnOQk4ZyrdMAocciYNfmMlU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN6PR03MB2627;7:zXtwCn+Ro3I+2+OZqnvq477KvM6BQC1VSvATH/QIAdz8TUjbI52LYq/0UQIj/wc0m7mifpS23dArOvB3KS4twHj8oPJkILAWegTdAXnLpptXJJMyQzw8HYvmZPrt/oVO6FFxpsQ4qv06hBTN7AwMM3diN6xuPX+IbgrF+wRQNxHqImDdFZhFktGEOvK5x0OUuUTlk+m3OjlLlpP/h9kxh1RXt3b9gH5vZAP7IwwI/WgSStCaHY37IlzB+v90Rvpp X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jul 2018 06:43:26.5032 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bdf2a545-4dc5-42ac-a18d-08d5e6f99c9d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR03MB2627 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, On Tue, 10 Jul 2018 19:19:21 +0300 Andy Shevchenko wrote: > On Tue, 2018-07-10 at 11:15 +0800, Jisheng Zhang wrote: > > 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. > > Thanks for an update, my comments below. > > > +/* > > + * 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 base_baud = baud * 16; Good point. will send a new version. > > > + unsigned int quot, rem; > > + struct dw8250_data *d = p->private_data; > > + > > + quot = p->uartclk / (16 * baud); > > + rem = p->uartclk % (16 * baud); > > + *frac = DIV_ROUND_CLOSEST(rem << d->dlf_size, 16 * baud); > > + > > While it looks indeed better, I would rather like to have a confirmation > it's working as designed. > > For example, when I did some calculus, I cooked a preliminary check in > Python (easy and fast to prototype), for example: > https://gist.github.com/andy-shev/06b084488b3629898121 in Python, or > commit 9df461eca18f ("spi: pxa2xx: replace ugly table by approximation") > in the kernel. > > Or another one here https://gist.github.com/andy-shev/8b2a73aeca2874f4cc > 89 and commits c1a67b48f6a5 ("serial: 8250_pci: replace switch-case by > formula for Intel MID"), 21947ba654a6 ("serial: 8250_pci: replace > switch-case by formula") My python coding skill is limited. So I wrote a simple c program to do the check for common clks and baudrate combination. All passed. I paste the code here: #include #include #include #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #define DIV_ROUND_CLOSEST(x, divisor)( \ { \ typeof(x) __x = x; \ typeof(divisor) __d = divisor; \ (((typeof(x))-1) > 0 || \ ((typeof(divisor))-1) > 0 || \ (((__x) > 0) == ((__d) > 0))) ? \ (((__x) + ((__d) / 2)) / (__d)) : \ (((__x) - ((__d) / 2)) / (__d)); \ } \ ) static unsigned int baud[] = {9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 1843200, 3250000, 4454400, 576000, 1152000, 500000, 1000000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000}; static unsigned int clk[] = {25000000, 50000000, 100000000, 133000000, 200000000}; static void check(int baud, int clk, int dlf_size) { unsigned int rem, frac, quot; unsigned int base_baud = baud * 16; float div, divf; quot = clk / base_baud; rem = clk % base_baud; frac = DIV_ROUND_CLOSEST(rem << dlf_size, base_baud); div = (float)clk / base_baud; divf = div - (int)div; divf *= (1 << dlf_size); assert(quot == (int)div); assert(frac == (int)round(divf)); printf("checked %d %d %d %d %d\n", baud, clk, dlf_size, quot, frac); } int main() { int i, j, k; for (i = 0; i < ARRAY_SIZE(baud); i++) { for (j = 0; j < ARRAY_SIZE(clk); j++) { for (k = 4; k <= 6; k++) { check(baud[i], clk[j], k); } } } return 0; }