Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp805969pxb; Fri, 21 Jan 2022 03:52:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxf3nxFQoE812qZeg5+GLAQR62ADRDeHhtSSB0SGFeL9VmCpI6S3+z9d2PvgAAfBzHaFh5C X-Received: by 2002:a17:90a:f2ce:: with SMTP id gt14mr405243pjb.160.1642765961017; Fri, 21 Jan 2022 03:52:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1642765961; cv=pass; d=google.com; s=arc-20160816; b=e+WtbHgo9LPHhIZAfoiY8FQYQLPvLTDZZsR00n/6UNz8aILih2ShLBSudQumMfHA7N rOv3Be0vLOIo2cOrjIGnnbSFNgg+sWi8PBWUyip3nQeIVpOq89POn3y+hjj20regFTy6 Awf/jePJXfWSCxDf0DYacwWSQUq6ZsRm6g6NYOBWvHO/M5YT7hWJ0adEnaQ15U9TkULm yVvFAE7GM8g/Ht2d2oC8hsPx+xo0AL1iF1RFTwFJGBhZNzXF0RJBaL3qp8PkZAJTTM+h ysxTN4ph6vD7SF+tIpSeJv4/UZlIAnESlJaP5sFdMcGUeEkpeHvLKzdTBCbbVkwE5lH5 MOJg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:in-reply-to:user-agent:date:message-id:from :references:cc:to:subject:dkim-signature; bh=KHmWyER4mk5iUNw3hHqNE4nvoeuYIt61ua0FBjQcQVw=; b=DcORAmQhWZqpuMoQJbR2i5JjXWs2cIXFOwAjKeXYqz53/pHfYP4gihuGgUgBZVUmoF mVG9n+G0so3MAPVnB1naAw/OBVucRcxllW6QU8RJdIF0K7FQalTcZjP/G+lD4tID+sq9 iPtAIHPYcDgFiuTyV1XyVmnpZHT9zaAVEwhtn3lAcRw/dqFVWcNwS6stEm1C2GtAs3a9 TkdBqB1F+uOjwLNSCG14vZ7Iy+J+o1Z91S+c5abdmHpmifQLwlVqreb+9LtKzN2rLJsw sdxFcLNdswoHHXKQpTMzOu619hPHreBQ5ERmMWhqjkx1bYkRsjMtF4V4FoA5fupPAR4O wfpA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@seco.com header.s=selector2 header.b="Yh9/r0Xi"; arc=pass (i=1 spf=pass spfdomain=seco.com dkim=pass dkdomain=seco.com dmarc=pass fromdomain=seco.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=seco.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x22si5723198pll.382.2022.01.21.03.52.26; Fri, 21 Jan 2022 03:52:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@seco.com header.s=selector2 header.b="Yh9/r0Xi"; arc=pass (i=1 spf=pass spfdomain=seco.com dkim=pass dkdomain=seco.com dmarc=pass fromdomain=seco.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=seco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344884AbiARXqO (ORCPT + 99 others); Tue, 18 Jan 2022 18:46:14 -0500 Received: from mail-eopbgr80072.outbound.protection.outlook.com ([40.107.8.72]:19859 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235592AbiARXqM (ORCPT ); Tue, 18 Jan 2022 18:46:12 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aRENzcs32bIxIGbWGD5CT6NWHjGWSCnbLLaCQn+ff+Qd8YOmcB5pZyoa+Sm/aZ+yh7yq7iotFP1S1YTZGMTfsmf8xlgH+/X4M6DOCiYX4H9nYYgPhbhMr0PELU7MJXTCQYT8485b20dQJ/9T+8yl82iuJMuibcpSnDNJsMbOTN1poXQK+qSUI8MVzg7US3J+kZtwMzuqbHZkUA6aePIZecjI1neSGGss6rkfcXtbpXNppwVSsvz+UCOtqfm8aqjkbNIoBCNQSBYDBfwCRe5BvrBHTI1tZ21RknuuWqDhmvfgBjT/8U3ht9p9SiWIv1YmG8+04yneL9vEorQ08YAHOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KHmWyER4mk5iUNw3hHqNE4nvoeuYIt61ua0FBjQcQVw=; b=Zb1pRVC+WCiuSEhJvhKDP3Quj3ifOIttGHb/HONg/TuuE8JmO/21tt/oyCrJD7Bjb+fnZX6h6u5arbNo2iMyfX+8lSYw06xDMcMnyvADLaMWjz9Nlm7z6vrURFpN9JH6wuLBgTGLr8PBFqwgzr2fA1Qk19RNsS8mowpcF2wp49H6vjIhv9JMKBe/hbhZByPjRfCIQqMbI0jNl7ctxju1CaDmYaEHDnVloRSjhlJYdNgapdtXYtiPDlXVPK+MG5ya1Q11MrU6bxetHwVIqiBZgKr11FS82dbQVL2WJclwBH3dyKzIoeC/9tLCgQeIyAM2H5gWkmOscKM2hvWVGj085g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KHmWyER4mk5iUNw3hHqNE4nvoeuYIt61ua0FBjQcQVw=; b=Yh9/r0Xi9ZzepjxyvE12/xoXeSBZmXnnTsHDC7wMZf9tk5b4DuPY1Nxo3dmEYAm+qFPgfjvUCoKB1x+Hu/KPjokaxb+tGZp5kzWQmZmxHTEE08ONV/ZC2hYaBclSD4uhhfcGFlgdJikeQ9SI0b5iQs7AO6x8cHI8Nm+RjCwJ7XymjZ+bhDBEvtXhWycz6/E9WKLydn4iUDsbLBuALeuV9laeOkkDBh6yjWFjFg3B8cH6fzII8Zkj3gzkOH1khHtS+d+BY3mF5KV7r+1861UkddpxxYyzdjdS6lPec6OAbtn7Xj7n3hT2dwUyeMUsRG7BchuiUTja4y0ZbdZyWltkgQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) by AM9PR03MB7963.eurprd03.prod.outlook.com (2603:10a6:20b:43a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.10; Tue, 18 Jan 2022 23:46:09 +0000 Received: from DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::d47e:81b0:256:3005]) by DB7PR03MB4523.eurprd03.prod.outlook.com ([fe80::d47e:81b0:256:3005%4]) with mapi id 15.20.4888.014; Tue, 18 Jan 2022 23:46:09 +0000 Subject: Re: [PATCH 4/6] usb: dwc3: Handle fractional reference clocks To: Robert Hancock , "gregkh@linuxfoundation.org" , "linux-usb@vger.kernel.org" Cc: "linux-kernel@vger.kernel.org" , "bjagadee@codeaurora.org" , "balbi@kernel.org" , "baruch@tkos.co.il" References: <20220114233904.907918-1-sean.anderson@seco.com> <20220114233904.907918-5-sean.anderson@seco.com> <6124a999dedcfaaac45efe58ffd3ba52dd3b6b82.camel@calian.com> From: Sean Anderson Message-ID: <20d904b3-30e9-eb19-3b7f-6d53d8d2806d@seco.com> Date: Tue, 18 Jan 2022 18:46:05 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 In-Reply-To: <6124a999dedcfaaac45efe58ffd3ba52dd3b6b82.camel@calian.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BL1PR13CA0180.namprd13.prod.outlook.com (2603:10b6:208:2bd::35) To DB7PR03MB4523.eurprd03.prod.outlook.com (2603:10a6:10:19::27) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 04b15633-2dba-4629-9510-08d9dadcb3fc X-MS-TrafficTypeDiagnostic: AM9PR03MB7963:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4sG7E27OScojMXe0naF9co7JDb0PikyLjV4w/lY+JVUgaDdAyju7uMSCN7L1Daw4/qCMzxUKSd0RHnSDxDINHtG7HEqASrp5a3fVMw6cUWWflFKTVZh1BiFDh4tJ30DUornA63mjgU09RMcSCdgf+QpCpVhoZhK0VESidtLe6sUqNvwNgZ9Eu/liyK96N04fPt3U0wDcH64TEwvK75rp5dZzHNzrMVCVIGkFV1OsKdT+86uA6miq7QSTzJsuQLvhSmQVLcQ/+ka4ULb8Oq6kPukdxwsnooxYkj8GK+TJITgW/sleV82v8f/0SjYWmrXPqWw9T9bLQXfPCgGnpryazhaEE2qLGIYV7j5WW+tMAhtyO7iwVkJoqps7S6Y+GxPBIi9L1xDUn6ymxrXO7UOAY/PfdAmiJTwFq/W2ceUztZMyah+LIP/mwFemr5Mhkt6HinfaxykjkiOIIvMH+YXZ0e0xvOS69VfZOax23tcY162UW2KkDtY5CuaILUM1DM4wcZdrNC3TZSp9xN7tRhwhNAbOomoF6xA8cACpPSVk1+0DgAbGp6pq1PWAiy520roaH9Br8FizGiaa246u6Rm6HPJKyCahDypOJw3DkqiU+qUjRXkFgfoPSY/QUaojWTFVg1YXmN7d8YaUxL2b/LMruF5BxzP4Sj/Sj3QeOGmXDjhTKJzYvNSM2o7CF+O2KrFyduF3+86GM8uQqF69ne9FhP8GT0dXwm7bClvXO2JgD4gRvTPNS/d0ND9NK6H3T4iNVtugA8nw2Hy0pgdYM5JjbgbtTcWoy4UJgH/NLvFFrAYChKml3OzOUdW+XYbU+A4vMYODx10z/fcNFj00BZf8Wwphj3sJ941pPMQ7AVwf94o= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR03MB4523.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(316002)(6506007)(53546011)(44832011)(6666004)(52116002)(508600001)(54906003)(2616005)(110136005)(8676002)(966005)(86362001)(83380400001)(8936002)(5660300002)(4326008)(31686004)(36756003)(26005)(38100700002)(38350700002)(6512007)(66556008)(66946007)(6486002)(2906002)(31696002)(186003)(66476007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bG9icWxlc1I0dS9xblFKMjBJUmRLb2FsTitjd0xOREc3NU9ESnBualNJbzg0?= =?utf-8?B?bDRNdnhMWlB3L2hOUlhiNmJld0ZBc1VnZkZWOTcwZ29sY1VmamtMd0hSWTZo?= =?utf-8?B?aFYzVVZTOGRTSnMzWnJVQ1V0ekNiNWRuTWRoMVdiMnYveW4xZUwvQllHcU9P?= =?utf-8?B?SDlGZHBtQXZZUkM4OXZYMDNMb0MwdmJWZldOUEtGcnRVSVA1R0Z3U2hwYXpC?= =?utf-8?B?OFNZQ2w1OVQzZXQ0WUxYc1p1TlhaU3VMeW9ZV0h3S05XQmwyUVMwY0tqcjdr?= =?utf-8?B?UzJvcXVCUGZJ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= =?utf-8?B?cUVoVEhId3NSRWtKVjQzd3M2VmZpME5uK1IxODBpeVBlbVVJdENQL0Ivb1lw?= =?utf-8?Q?YclxqXo11SmS/IL2jCXYYpM=3D?= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04b15633-2dba-4629-9510-08d9dadcb3fc X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4523.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2022 23:46:09.8064 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1E5ilYI467orN9X4kte79vx2wMPTW4YdBob9tb6X0DGQW+y2yXA64jRJf8m+fLhNqT6LJVuGx7X9VlpjSJP5YQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7963 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/14/22 8:09 PM, Robert Hancock wrote: > On Fri, 2022-01-14 at 18:39 -0500, Sean Anderson wrote: >> GUCTL.REFCLKPER can only account for clock frequencies with integer >> periods. To address this, program REFCLK_FLADJ with the relative error >> caused by period truncation. The formula given in the register reference >> has been rearranged to allow calculation based on rate (instead of >> period), and to allow for fixed-point arithmetic. >> >> Signed-off-by: Sean Anderson >> --- >> >> drivers/usb/dwc3/core.c | 25 +++++++++++++++++++++++-- >> drivers/usb/dwc3/core.h | 1 + >> 2 files changed, 24 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c >> index 5214daceda86..48bb3e42cdd0 100644 >> --- a/drivers/usb/dwc3/core.c >> +++ b/drivers/usb/dwc3/core.c >> @@ -348,7 +348,7 @@ static void dwc3_frame_length_adjustment(struct dwc3 >> *dwc) >> static void dwc3_ref_clk_period(struct dwc3 *dwc) >> { >> u32 reg; >> - unsigned long rate, period; >> + unsigned long fladj, rate, period; >> >> if (dwc->ref_clk) { >> rate = clk_get_rate(dwc->ref_clk); >> @@ -357,16 +357,37 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc) >> period = NSEC_PER_SEC / rate; >> } else if (dwc->ref_clk_per) { >> period = dwc->ref_clk_per; >> + rate = NSEC_PER_SEC / period; >> } else { >> return; >> } >> >> + /* >> + * The calculation below is >> + * >> + * 125000 * (NSEC_PER_SEC / (rate * period) - 1) >> + * >> + * but rearranged for fixed-point arithmetic. >> + * >> + * Note that rate * period ~= NSEC_PER_SECOND, minus the number of >> + * nanoseconds of error caused by the truncation which happened during >> + * the division when calculating rate or period (whichever one was >> + * derived from the other). We first calculate the relative error, then >> + * scale it to units of 0.08%. >> + */ >> + fladj = div64_u64(125000ULL * NSEC_PER_SEC, (u64)rate * period); >> + fladj -= 125000; >> + >> reg = dwc3_readl(dwc->regs, DWC3_GUCTL); >> reg &= ~DWC3_GUCTL_REFCLKPER_MASK; >> reg |= FIELD_PREP(DWC3_GUCTL_REFCLKPER_MASK, period); >> dwc3_writel(dwc->regs, DWC3_GUCTL, reg); >> -} >> >> > > dwc3_frame_length_adjustment which also writes to the DWC3_GFLADJ register has > a conditional to skip it if DWC3_VER_IS_PRIOR(DWC3, 250A), not sure if it's > needed for this field or not? That's a good question... The oldest version I found with it is 2.60a [1]. [1] https://www.mouser.com/pdfdocs/silver-celeron-datasheet-vol-2.pdf --Sean