From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=148.163.129.48 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796169172; b=lICAZ3h5A0XvSqPXh105I4WwuYwjgXk/qZEeGvYOvJXI12RlA45qCNG44BM/a/M3H5rz 3PWuqMBqoqyk1sRhrLM74Zdv65lQbx73S19yxVTvBblOTu3AQVll3eRkk8w1hgb/+hWs2 c4bm6+nn6N2oXrDx8hMWd4GCzyOA3SnGkuspL4kBMnYqs2KveJ+ur/QQ7pCrEtZEf3BLi uO6iwJfw2Ydzj47uGa/y7/QhMTBmtfHA4L9Fy6viWUxlVv55D7PisE4D1x4jMi3qFRK5q yYJpShSwWPZ7t0/ytcBuThoFr01nstggOAzxTZfSHG46rLA1KSqJ7azJ60k1UcTUWbw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796169172; h=DMARC-Filter:DKIM-Signature:X-Virus-Scanned:Received:DKIM-Signature: Received:Received:From:To:CC:Subject:Thread-Topic:Thread-Index:Date: Message-ID:References:In-Reply-To:Accept-Language:Content-Language: X-MS-Has-Attach:X-MS-TNEF-Correlator:x-ms-publictraffictype: x-ms-traffictypediagnostic:x-ms-office365-filtering-correlation-id: x-ms-exchange-senderadcheck:x-ms-exchange-antispam-relay: x-microsoft-antispam:x-microsoft-antispam-message-info: x-forefront-antispam-report: x-ms-exchange-antispam-messagedata-chunkcount: x-ms-exchange-antispam-messagedata-0:Content-Type: Content-Transfer-Encoding:MIME-Version: X-Exchange-RoutingPolicyChecked:X-OriginatorOrg: X-MS-Exchange-CrossTenant-AuthAs:X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-originalarrivaltime: X-MS-Exchange-CrossTenant-fromentityheader: X-MS-Exchange-CrossTenant-id:X-MS-Exchange-CrossTenant-mailboxtype: X-MS-Exchange-CrossTenant-userprincipalname: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-MDID:X-PPE-STACK: X-MDID-O:X-PPE-TRUSTED; bh=tL+Dy1B/2dbLae50tR6A6qqnqhvZyzn/txWtaRMxXTE=; b=PND9dprGZWfMx9mW08Jlt2KkmFCJ5zPVC/ACX+FJrYGUHs9b/57sqyrPDHLOaIp5KRhJ eWXGCvIp6d0FNG6CQaOxiykNdpT7oABjEOS2bufvkgPRBF3u05y16paFUCxpGl1mU1e6t wgZlXvsBLi9WQ3vTju3Cnea440YUSslUiVJV6DnScQnspWuEIiasaf6yAzx9PDrHjxEMP k9BaPZolaM2xI0y+JsuCcR9jtFyL1O3rZplRbq4GVD/5aMhhjRgoHJHwPK2N6evTGYpMR W1QQ67smwxWgiA+bAe0tHf5i7qMITO5iJUJGnce15IweAfKBJG81y67aIEXTGJGR7ig== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=sitime.com; spf=pass smtp.mailfrom=sitime.com; dkim=pass header.d=sitime.com header.i=@sitime.com header.a=rsa-sha256 header.s=mail header.b=V4fjhmDC; dkim=pass header.d=Sitime.onmicrosoft.com header.i=@Sitime.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-Sitime-onmicrosoft-com header.b=l7bZMk5r; arc=pass header.oldest-pass=0 smtp.remote-ip=148.163.129.48 Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [148.163.129.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D637606A323; Tue, 1 Dec 2026 23:52:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6D637606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sitime.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sitime.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sitime.com header.i=@sitime.com header.a=rsa-sha256 header.s=mail header.b=V4fjhmDC; dkim=pass (2048-bit key) header.d=Sitime.onmicrosoft.com header.i=@Sitime.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-Sitime-onmicrosoft-com header.b=l7bZMk5r DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sitime.com; h=cc:cc:content-transfer-encoding:content-transfer-encoding:content-type:content-type:date:date:from:from:in-reply-to:in-reply-to:message-id:message-id:mime-version:mime-version:references:references:subject:subject:to:to; s=mail; bh=tL+Dy1B/2dbLae50tR6A6qqnqhvZyzn/txWtaRMxXTE=; b=V4fjhmDCvfRLv4v1CMoZEnQr42la/yJkWcUJtJ3GNVZBrgKZAEqZsfQB+1UBo0Fw70ZyWbtjcXievaQgJZw2bCKVHEVmeHWHRrM7ddLht8DwS/0Mg4kjSei5CHYpgKmQpd97wc0A/gKsxkW1NIDf77hYJwYhAqBMyqxzIS1UD03ZILNeVLwKtu85/HVnLvc3soaVvUrSxpF+zrxkE1MrY9DuBVLMDy8xtjDBH7JCphlYA9TZpXeuRkL4uUrmclbjDkrf8jVzbjmHwH1+6CxmHdX6+AZ4bBsw79+I70Wox5YMbOBE+W1Osw/30FRTA0EIi5UbDAODFBGAVUMrHxL6hw== X-Virus-Scanned: Proofpoint Essentials engine Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11023134.outbound.protection.outlook.com [40.93.201.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1-us1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTPS id 8BB25280079; Tue, 1 Dec 2026 23:52:49 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ESU2czDbL0yFHhOHy4aufAuTsIxuMtLfrGPIisVzvaa/jrRDtO1zIjG5X6eEYWOlzPClQv10U0vncFkssaNKRV9SmcD1DGg9a5czTqNuRek24EwHNqgdjowF3jrMMkRyXzI0lo8hieQJgbeWQHz5K34o4EunEixOQ2+NhS8PcHtIORfuA4WripjqSzcQdNeSQGMDXdhfwTjyLXfNu/WdxopZDMN/jypb72R2Fqb8kHjWLp+xsmismoxDh8tdT5MEoK1B9iujVIaiAWLUxpysY78YptIaQ06AC4Iksgcm9n6Yd+Dxn/wLLbVEqNE1CUQGK1YeAgklpckC/QvbEgDO1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=tL+Dy1B/2dbLae50tR6A6qqnqhvZyzn/txWtaRMxXTE=; b=ZjlhrloAvHd+38eip0lsY5rvhMmp8gBqKSQsLy39WXuwH90rQIfX3xs4FatfT14UHcjkFZZGd40+IcWNjsb1Zz5+sz+jkdFki7mcgGCdIU7de+KDMKPYWvZntu3wTkqQ8OB4N0vQUpI72SfffSM9NJ6ju5rHa+xDbcD1geGcBfF28mrUMblvsexiOoSia/4ToZY4ZRlEGNPNWByndhTzgIwRJXlKTkexT6RplwfIZdkzQdESXsG2Yt3zaWtRcVumqkSSB0jt+p8zfaV2sHBLBrqbkbc1ntjwqPoSz8L3ZpWUiUOQTcwZQOQUvCYbfRT6Nh6s6I1QWAn3FZ5gQiDmBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sitime.com; dmarc=pass action=none header.from=sitime.com; dkim=pass header.d=sitime.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Sitime.onmicrosoft.com; s=selector1-Sitime-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tL+Dy1B/2dbLae50tR6A6qqnqhvZyzn/txWtaRMxXTE=; b=l7bZMk5rzeyOZ8IMlz1xUfI9gldtc8ilMqmmDaG5av12UeR8iByX7AkGQNrZ9yRjWJLpjfUp3X0fDjF8ho1q8RfwTcUNVltBBhJ0YzI0iA5BbRiRh6XZbZQAc7Wst40ZcWw6zq84HtyFyIhDmRvV8GvSBAGPdEftllQkyw2V5vkkadeic76Lz1Z0WMXsE7C13+0RX4lzHhLmb4LuQw7D4coSvt6NcdEK9/DLpw3e3zTbs0XGI4V2GohcVbfnXHRVuD6YS5siGKEsc0U1LhdHP2oaYiR+GwCUoVOt6W4a8DYGSSkYeIOfcOECRIDNRx6i3fdZI+CKbSbb1GEnWO90wg== Received: from LVWPR20MB994915.namprd20.prod.outlook.com (2603:10b6:408:3bf::16) by SJ2PR20MB6330.namprd20.prod.outlook.com (2603:10b6:a03:502::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Tue, 1 Dec 2026 23:52:47 +0000 Received: from LVWPR20MB994915.namprd20.prod.outlook.com ([fe80::9551:3864:128b:8c01]) by LVWPR20MB994915.namprd20.prod.outlook.com ([fe80::9551:3864:128b:8c01%4]) with mapi id 15.21.0688.009; Tue, 1 Dec 2026 23:52:47 +0000 From: Ali Rouhi To: "jiri@resnulli.us" CC: "ivecera@redhat.com" , "vadim.fedorenko@linux.dev" , "arkadiusz.kubalewski@intel.com" , "kuba@kernel.org" , "pabeni@redhat.com" , "robh@kernel.org" , "krzk+dt@kernel.org" , "conor+dt@kernel.org" , "prabhakar.mahadev-lad.rj@bp.renesas.com" , "cjubran@nvidia.com" , "Oleg.Zadorozhnyi@devoxsoftware.com" , "netdev@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH net-next v17 11/13] dpll: sit9531x: add support to adjust output phase Thread-Topic: [PATCH net-next v17 11/13] dpll: sit9531x: add support to adjust output phase Thread-Index: AQHdge75HQW/AVadLEGzJ18q86f4Fg== Date: Tue, 1 Dec 2026 23:52:08 +0000 Message-ID: <20261201235202.97645-12-arouhi@sitime.com> References: <20261201235202.97645-1-arouhi@sitime.com> In-Reply-To: <20261201235202.97645-1-arouhi@sitime.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=sitime.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: LVWPR20MB994915:EE_|SJ2PR20MB6330:EE_ x-ms-office365-filtering-correlation-id: 6f949d89-8d00-4fbc-ae12-08df5006334c x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230040|376014|1800799024|23010399003|366016|38070700021|10067099003|260925021311599003|56012099006|5023799004|260925021911599003|260925022911599003|261022075727099003|261026121527099003|261021123027099003|261022113327099003|261021121427099003|261026140227099003|261022105027099003|261028144727099003|261102123227099003|261009223027099003|22082099003|18002099003|6133799003|3023799007; x-microsoft-antispam-message-info: EYV1PlZKP9TD2KrWK5iJo785P5LMg5Y8cfun/RHyCXWEQLQlYhCGzo3apKiLm23PIZgKWYSRmmVgXiRx1X6adVfb0ocIzkDrdp+fvKY63ws2Y3SdbZ+Ehjys1e4jUcvtvbCU9JQZ5Lh66XUbqU/AjcYl7ePrXlxkXoNTmrCg9ZFUAdKPoWEP+AnhEmTyj/UtfVLyqLKJEVkpR0PoKs80FUsUHMW7WXhEA8qzK7r/xuMvMXOzI19t05YDFvbomNRe0+Nq2QZpyZw+lMnu6Kr9o4NpfTtMqp48L4dCVQDRUutrc7YY46OsUjZoxp0oec3+THRU8yUd9uUCweZSlXKosZjwbmC51kdmD/nQRiKKLqTY5nltH019nr1YFeGPLtm83Ifa7ZG1TmtUtlSP1h/E1ku5QArFO/CyjlymGzWTFri64WyFCKeJVy99AHLFxxvAQSbnmnnxxIraYb/w0KectAM4tg/1Nr1v6PNhzofXq/wSiUpPHZwKLTFB4Dj1e0AkJt4aSWhUEhX4QUT0AzuiTDvHIFWlw16bVJihlxjK/2KPi4D4mvcKdQttO5BtszItCb0HGLuMsG37PFpEuxbLQDM7pI7DPQSqRBEETe7orI3Y0DIvwwmVP817xItNqIyZgyW2drgLVDSFijExydHlde7DlM+1nBFJ0JVBDRQA9XwwsHXjm0OMajmwQdltkZQn2Rt84ScwgGg8tpRtyuRlMsH9/Sj5Y1/UfilIyGrAxvo= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LVWPR20MB994915.namprd20.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(23010399003)(366016)(38070700021)(10067099003)(260925021311599003)(56012099006)(5023799004)(260925021911599003)(260925022911599003)(261022075727099003)(261026121527099003)(261021123027099003)(261022113327099003)(261021121427099003)(261026140227099003)(261022105027099003)(261028144727099003)(261102123227099003)(261009223027099003)(22082099003)(18002099003)(6133799003)(3023799007);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?CIGr0fMw4tU0UJQjBpy2YF6R21MhTnoAysk/2+ZLt6PYTjJBK2PeIbKaFg?= =?iso-8859-1?Q?0JPXt8xasNHuUwA87AiOjvJ8CVwRD8Tf+CwNcmO61FOTePyJkXJNKgkZYH?= =?iso-8859-1?Q?Nxn6mLqjCELTz7JyEAehKnQpmQroZ8VjVFmJ25AVSQryrV/MYkihoW6Y0U?= =?iso-8859-1?Q?Umhn0qC0KZu9iauqpSV/A0ebhTBZQsZrPJ+Sh3fz81Ek3opW3jPpmWNmkG?= =?iso-8859-1?Q?VglE4z28P3fjwQA+AARVxpd4a2GkoAps6JKVZ21PT2N9Lsswuv1B0XGKXP?= =?iso-8859-1?Q?4EKYAnNQcARP4igRyi08tBOYrHVYWke8QPqVvuv8A6c/ufB5STm3OVKLjo?= =?iso-8859-1?Q?eUFFvMqkkhjbssbVUypdowrvB2jOOnTwauKGlQgAPF4yRzgQ48F+yK2lGG?= =?iso-8859-1?Q?iWl6U9yo3w3V2eXCeTnrvJ2OBZE6289eOr2xfJ/avhjTvt70gP633QmCP4?= =?iso-8859-1?Q?vyx6mhLY5gW41Nsv7QODXJoK/F9wDbkaINbmCNBQQl6BGnAABxKq6u27fZ?= =?iso-8859-1?Q?9X11v3OrLC9iFHL4iRN2BxA7tyNkrUJeU6xzsoaWVLSfwJOaLOuvZ+b/h6?= =?iso-8859-1?Q?SJBylWZsUZotd4qVGMy6C2ppPXcHJUa/SpKl1irgWszjUt9Gr/nIpsdDsU?= =?iso-8859-1?Q?z9eC4qmkc2frjWsPvOt1w5Zak1amLN7B4DgLUreUxq5SBhVtjWL5rEdA5x?= =?iso-8859-1?Q?svdVYG7KbCt5aWbSs+/irJyHMBoAcfYFkpD4poRD1mLuUqMBOd/K3WOuhV?= =?iso-8859-1?Q?9YboRkhBFyPH3ncMqqiI1Dc6dHi9Zj9WmAn/OX7SmbXeINgRUCvYmxR6XA?= =?iso-8859-1?Q?UJtyiFzmiqxA/aZ1NGWj63kUY1qJsjyAfWRTesZ/bHv05hOHxUSh19a8L0?= =?iso-8859-1?Q?ITTlXiaVfldnMVmZab0UVhYGYVpcx+VYsXLwpOvj5iRosYEWu41V4g+tdM?= =?iso-8859-1?Q?HUSmmmcdKQdon8EjUhIQyrWqpNNMFsqK05L4Z97UA9ao6oYoaiKz7NBT6D?= =?iso-8859-1?Q?s8b5poPM5c4CHPx6ZpKyrOtd/m8wBkh8x7QLAYMjXLQSzMI+AlsgcBkPeI?= =?iso-8859-1?Q?EurZAfnUWXM19Ppo4/In7pKyIufb1JYP0xIFbUSrKHFgX8Vvbvx1Jvz5js?= =?iso-8859-1?Q?5SluI7+v51a8Er2zu1phk970PutM4EeB5o+MrFwvD8pkydSLZhGFQ5n5Kj?= =?iso-8859-1?Q?CKPK5B/jwZfQf+QNV28sikwWtS3v7PFXyyupjEWwwrQD1v+Fi0sRsu3oec?= =?iso-8859-1?Q?Z9qJiXisWzjqkdcZNs18A69goDjwviWn0XemQcOtzuU7HyiUeIhpSEtjkF?= =?iso-8859-1?Q?SOyHZd+QXYwKdH/4eTm3C37qHxP5SHXznQg0Sx4JqI/0c8QiVPo6VZRnZs?= =?iso-8859-1?Q?qQCvIRj22XjUJPT4Re9r3eeo8biYsv522/trIxZ/cnVmWJYM9Gj63JHWg7?= =?iso-8859-1?Q?AXzvv/KQVmOwRPofg/UOIT/VmU/PX58J7vC8edoXqAaaT7cmqPYxNLBADw?= =?iso-8859-1?Q?bVbzKqpN1yy3SPF1xwOZmhrC7nxTVuceSe5+EqAtt0J3Gn37Nu6Xz24S8X?= =?iso-8859-1?Q?9v7KHuGnIiaPHB4gjG+kUNrxj57rm4l7Bzbm1tyhwzrrN8pa+NWiBJESCm?= =?iso-8859-1?Q?v9S8SdTwJqgeUwzupH/b5wwgkGSdKvn5NrhAFXr9GmNN1wtPIcm/sOnF2B?= =?iso-8859-1?Q?ARrlXxVZoje6Ny4qW9t4yGLk1V4M8KWxOSyOHHguEt6+b2STLr3S5n+pHR?= =?iso-8859-1?Q?uFsJR5ZRqgMa2Z5K7MOe9JfnP8+RFdhljGeeZBE5DKaA4Y?= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-Exchange-RoutingPolicyChecked: fwtZZo0fXARbkXvXuvaB4Hyo7nmHcZdP9oTPmPbZwwR7rHM+PtVAbsNzBW6yPtw9AmddtSMbdzxQoN1083f0v4CEQfad8RyRIdNY1svFR8Wy58rOjd1L9qxYd2RchAeaCwZByNNnb1p8vvxJz2C/5QVbfTJ1opcbFgvwwiPVWVL3XtiEw/UvZym3wzxVrg8cZJvM4yb2eJPlGd6WwX/+fE18ADrziqGZSG8v9vAeU0zCxyIPXKHlhxX38CM2WNMWnfXJYjXp0JT9Zac1rnAQZRISyX47tJbrD/UC5qrigV8L+6BePDJ67FWUcxA/bsq5wcbgMZzpKy+z4La8sopnTg== X-OriginatorOrg: sitime.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: LVWPR20MB994915.namprd20.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f949d89-8d00-4fbc-ae12-08df5006334c X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Dec 2026 23:52:08.1908 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8fb55916-cf10-4b0d-96f4-cf3952657263 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: fPnDvilBgcLlr5AS23Uilgc3Sji22MHC7qkRUdxC05NXQKkezZP4fqWzUB60rn3V1DFnW8Gw7q1ZfDRVio1Jlw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR20MB6330 X-MDID: 1796169170-i_i9d8Sz_Tdy X-PPE-STACK: {"stack":"us1"} X-MDID-O: us1;ut7;1796169170;i_i9d8Sz_Tdy;;ba04557de9d2da8490f5f1e6de07b967 X-PPE-TRUSTED: V=1;DIR=OUT; From: Oleg Zadorozhnyi =0A= =0A= Shift an output in time against the other outputs of its PLL. A delay is=0A= a coarse count of VCO cycles plus a 3-bit fine field in 30 ps steps, so=0A= the grid depends on the PLL's rate; the driver programs the nearest=0A= point and the getter reports what the registers hold.=0A= =0A= The range advertised to the core, +/-1 ms at 1 ps granularity, bounds a=0A= request, not the delay the registers hold. An advance is held as the=0A= complementary positive delay within the output period, and a stored=0A= delay is reported in the form nearer to zero. A delay alone takes a=0A= small-change update and is applied by the PLL's phase flush, or by a PLL=0A= restart where the configuration has the flush off; both restart the=0A= divider phase of the PLL's outputs. A rate change encodes the delay=0A= again for the new period, in the divider's programming window.=0A= =0A= The poll and removal apply a delay waiting for its re-time or update and=0A= finish a flush left partly done. A waiting delay, or Fref * DIVN outside=0A= the PLL's VCO band, has no value and the core leaves the attribute out;=0A= a delay whose flush is pending is reported.=0A= =0A= Suggested-by: Ivan Vecera =0A= Signed-off-by: Oleg Zadorozhnyi =0A= Co-developed-by: Ali Rouhi =0A= Signed-off-by: Ali Rouhi =0A= ---=0A= drivers/dpll/sit9531x/core.c | 862 ++++++++++++++++++++++++++++++++---=0A= drivers/dpll/sit9531x/core.h | 35 ++=0A= drivers/dpll/sit9531x/dpll.c | 130 +++++-=0A= drivers/dpll/sit9531x/prop.c | 16 +=0A= drivers/dpll/sit9531x/regs.h | 29 ++=0A= 5 files changed, 1009 insertions(+), 63 deletions(-)=0A= =0A= diff --git a/drivers/dpll/sit9531x/core.c b/drivers/dpll/sit9531x/core.c=0A= index 3316e3761e16..96d317c9bf37 100644=0A= --- a/drivers/dpll/sit9531x/core.c=0A= +++ b/drivers/dpll/sit9531x/core.c=0A= @@ -246,6 +246,23 @@ static int sit9531x_write_pll_close(struct sit9531x_de= v *sitdev, u8 pll_idx,=0A= offset), val);=0A= }=0A= =0A= +static int sit9531x_update_pll_close(struct sit9531x_dev *sitdev, u8 pll_i= dx,=0A= + u8 offset, u8 mask, u8 val)=0A= +{=0A= + u8 attempt;=0A= + int rc;=0A= +=0A= + for (attempt =3D 0; attempt < SIT9531X_CLOSE_TRIES; attempt++) {=0A= + if (attempt)=0A= + usleep_range(1000, 2000);=0A= + rc =3D sit9531x_update_pll_u8(sitdev, pll_idx, offset, mask, val);=0A= + if (!rc)=0A= + break;=0A= + }=0A= +=0A= + return rc;=0A= +}=0A= +=0A= static void sit9531x_input_get_regs(const struct sit9531x_dev *sitdev,=0A= u8 index,=0A= unsigned int *force_reg,=0A= @@ -1683,6 +1700,72 @@ static int sit9531x_pll_small_update(struct sit9531x= _dev *sitdev, u8 pll_idx)=0A= SIT9531X_SMALL_UPDATE_CMD);=0A= }=0A= =0A= +static int sit9531x_pll_small_update_close(struct sit9531x_dev *sitdev,=0A= + u8 pll_idx)=0A= +{=0A= + return sit9531x_write_pll_close(sitdev, pll_idx,=0A= + SIT9531X_PLL_REG_SMALL_UPDATE,=0A= + SIT9531X_SMALL_UPDATE_CMD);=0A= +}=0A= +=0A= +/*=0A= + * Undo a phase flush: restore the trigger select and the flush enable of = @plls=0A= + * from @armed.=0A= + */=0A= +static int sit9531x_phase_flush_undo(struct sit9531x_dev *sitdev,=0A= + bool ctrl_back, u8 ctrl, u8 plls, u8 armed)=0A= +{=0A= + const u8 en =3D SIT9531X_PLL_PHFL_ON_DEMAND_EN;=0A= + int rc =3D 0, ret;=0A= + u8 i;=0A= +=0A= + if (ctrl_back) {=0A= + rc =3D sit9531x_write_close(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1,=0A= + ctrl);=0A= + sitdev->flush_ctrl_pending =3D !!rc;=0A= + sitdev->flush_ctrl =3D ctrl;=0A= + /* Re-arm after the select is back; the trigger may stay set */=0A= + if (rc) {=0A= + sitdev->flush_arm_pending |=3D plls;=0A= + sitdev->flush_armed &=3D ~plls;=0A= + sitdev->flush_armed |=3D armed & plls;=0A= + return rc;=0A= + }=0A= + }=0A= +=0A= + for (i =3D 0; i < SIT9531X_NUM_PLLS; i++) {=0A= + if (!(plls & BIT(i)))=0A= + continue;=0A= + ret =3D sit9531x_update_pll_close(sitdev, i,=0A= + SIT9531X_PLL_REG_PHFL_CTRL, en,=0A= + (armed & BIT(i)) ? en : 0);=0A= + if (!ret)=0A= + ret =3D sit9531x_pll_small_update_close(sitdev, i);=0A= + if (ret) {=0A= + sitdev->flush_arm_pending |=3D BIT(i);=0A= + sitdev->flush_armed &=3D ~BIT(i);=0A= + sitdev->flush_armed |=3D armed & BIT(i);=0A= + if (!rc)=0A= + rc =3D ret;=0A= + } else {=0A= + sitdev->flush_arm_pending &=3D ~BIT(i);=0A= + }=0A= + }=0A= +=0A= + return rc;=0A= +}=0A= +=0A= +static int sit9531x_phase_flush_undo_retry(struct sit9531x_dev *sitdev)=0A= +{=0A= + if (!sitdev->flush_ctrl_pending && !sitdev->flush_arm_pending)=0A= + return 0;=0A= +=0A= + return sit9531x_phase_flush_undo(sitdev, sitdev->flush_ctrl_pending,=0A= + sitdev->flush_ctrl,=0A= + sitdev->flush_arm_pending,=0A= + sitdev->flush_armed);=0A= +}=0A= +=0A= /*=0A= * Realign the PLL's output dividers with the on-demand phase flush (PHFL)= , or=0A= * restart the PLL when its profile has PHFL off (PLL page 0x47 bit 7 clea= r), as=0A= @@ -1691,24 +1774,36 @@ static int sit9531x_pll_small_update(struct sit9531= x_dev *sitdev, u8 pll_idx)=0A= */=0A= static int sit9531x_output_phase_flush(struct sit9531x_dev *sitdev, u8 pll= _idx)=0A= {=0A= - u8 ctrl, orig, phfl, armed_mask =3D 0, parked =3D 0, i;=0A= + u8 ctrl, orig =3D 0, phfl, armed_mask =3D 0, parked =3D 0, touched, i;=0A= + bool ctrl_back =3D false, armed_here =3D false, fired =3D false;=0A= int rc, ret;=0A= =0A= + /*=0A= + * Retry a pending undo first so the reads below see the profile's=0A= + * settings.=0A= + */=0A= + rc =3D sit9531x_phase_flush_undo_retry(sitdev);=0A= + if (rc)=0A= + goto out;=0A= +=0A= rc =3D sit9531x_read_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_CONFIG47,= =0A= &phfl);=0A= if (rc)=0A= - return rc;=0A= - if (!(phfl & SIT9531X_PLL_CONFIG47_PHFL_EN))=0A= - return sit9531x_write_pll_u8(sitdev, pll_idx,=0A= - SIT9531X_PLL_REG_DIRECTIVES,=0A= - SIT9531X_PLL_DIRECTIVE_RESTART);=0A= + goto out;=0A= + if (!(phfl & SIT9531X_PLL_CONFIG47_PHFL_EN)) {=0A= + rc =3D sit9531x_write_pll_u8(sitdev, pll_idx,=0A= + SIT9531X_PLL_REG_DIRECTIVES,=0A= + SIT9531X_PLL_DIRECTIVE_RESTART);=0A= + fired =3D !rc;=0A= + goto out;=0A= + }=0A= =0A= /* Only the target PLL keeps on-demand flush enabled for the pulse. */=0A= for (i =3D 0; i < SIT9531X_NUM_PLLS; i++) {=0A= rc =3D sit9531x_read_pll_u8(sitdev, i, SIT9531X_PLL_REG_PHFL_CTRL,=0A= &phfl);=0A= if (rc)=0A= - return rc;=0A= + goto out;=0A= if (phfl & SIT9531X_PLL_PHFL_ON_DEMAND_EN)=0A= armed_mask |=3D BIT(i);=0A= }=0A= @@ -1721,18 +1816,19 @@ static int sit9531x_output_phase_flush(struct sit95= 31x_dev *sitdev, u8 pll_idx)=0A= SIT9531X_PLL_REG_PHFL_CTRL,=0A= SIT9531X_PLL_PHFL_ON_DEMAND_EN, 0);=0A= if (rc)=0A= - goto unpark;=0A= + goto undo;=0A= rc =3D sit9531x_pll_small_update(sitdev, i);=0A= if (rc)=0A= - goto unpark;=0A= + goto undo;=0A= }=0A= =0A= + armed_here =3D true;=0A= rc =3D sit9531x_update_pll_u8(sitdev, pll_idx,=0A= SIT9531X_PLL_REG_PHFL_CTRL,=0A= SIT9531X_PLL_PHFL_ON_DEMAND_EN,=0A= SIT9531X_PLL_PHFL_ON_DEMAND_EN);=0A= if (rc)=0A= - goto disarm;=0A= + goto undo;=0A= =0A= /*=0A= * Write the update register whole; a read-modify-write skips the write= =0A= @@ -1740,21 +1836,19 @@ static int sit9531x_output_phase_flush(struct sit95= 31x_dev *sitdev, u8 pll_idx)=0A= */=0A= rc =3D sit9531x_pll_small_update(sitdev, pll_idx);=0A= if (rc)=0A= - goto disarm;=0A= + goto undo;=0A= =0A= - /*=0A= - * Select the in-register phase trigger; the register also holds the OEb= =0A= - * bits.=0A= - */=0A= + /* Select the in-register phase trigger, preserving the OEb bits. */=0A= rc =3D sit9531x_read_u8(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1, &ctrl);=0A= if (rc)=0A= - goto disarm;=0A= + goto undo;=0A= =0A= orig =3D ctrl & ~SIT9531X_DIVO_PHASE_TRIG;=0A= ctrl =3D orig | SIT9531X_DIVO_PHASE_SEL_REG;=0A= + ctrl_back =3D true;=0A= rc =3D sit9531x_write_u8(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1, ctrl);=0A= if (rc)=0A= - goto restore;=0A= + goto undo;=0A= =0A= /*=0A= * No delay between set and clear; one I2C transfer is longer than the=0A= @@ -1763,47 +1857,26 @@ static int sit9531x_output_phase_flush(struct sit95= 31x_dev *sitdev, u8 pll_idx)=0A= rc =3D sit9531x_write_u8(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1,=0A= ctrl | SIT9531X_DIVO_PHASE_TRIG);=0A= if (rc)=0A= - goto restore;=0A= + goto undo;=0A= =0A= /*=0A= * Clear the trigger with the register trigger still selected, as=0A= - * Dely_program_output.py does; the select goes back after it.=0A= + * Dely_program_output.py does; the select goes back in the undo.=0A= */=0A= rc =3D sit9531x_write_close(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1, ctrl);= =0A= -=0A= -restore:=0A= - ret =3D sit9531x_write_u8(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1, orig);=0A= + fired =3D !rc;=0A= +=0A= +undo:=0A= + touched =3D parked;=0A= + if (armed_here && !(armed_mask & BIT(pll_idx)))=0A= + touched |=3D BIT(pll_idx);=0A= + ret =3D sit9531x_phase_flush_undo(sitdev, ctrl_back, orig, touched,=0A= + armed_mask);=0A= if (ret && !rc)=0A= rc =3D ret;=0A= =0A= -disarm:=0A= - /*=0A= - * Restore the profile's flush enable; an armed flush re-flushes every=0A= - * output divider of this PLL on the next trigger.=0A= - */=0A= - if (!(armed_mask & BIT(pll_idx))) {=0A= - ret =3D sit9531x_update_pll_u8(sitdev, pll_idx,=0A= - SIT9531X_PLL_REG_PHFL_CTRL,=0A= - SIT9531X_PLL_PHFL_ON_DEMAND_EN, 0);=0A= - if (!ret)=0A= - ret =3D sit9531x_pll_small_update(sitdev, pll_idx);=0A= - if (ret && !rc)=0A= - rc =3D ret;=0A= - }=0A= -=0A= -unpark:=0A= - for (i =3D 0; i < SIT9531X_NUM_PLLS; i++) {=0A= - if (!(parked & BIT(i)))=0A= - continue;=0A= - ret =3D sit9531x_update_pll_u8(sitdev, i,=0A= - SIT9531X_PLL_REG_PHFL_CTRL,=0A= - SIT9531X_PLL_PHFL_ON_DEMAND_EN,=0A= - SIT9531X_PLL_PHFL_ON_DEMAND_EN);=0A= - if (!ret)=0A= - ret =3D sit9531x_pll_small_update(sitdev, i);=0A= - if (ret && !rc)=0A= - rc =3D ret;=0A= - }=0A= +out:=0A= + sitdev->chan[pll_idx].flush_pending =3D !fired;=0A= =0A= return rc;=0A= }=0A= @@ -1877,7 +1950,7 @@ static int sit9531x_output_divo_write(struct sit9531x= _dev *sitdev, u8 out_idx,=0A= int rc, j, rb_rc;=0A= u8 written =3D 0;=0A= =0A= - *back =3D false;=0A= + *back =3D true;=0A= =0A= slot =3D info->clkout_map[out_idx];=0A= =0A= @@ -1904,6 +1977,7 @@ static int sit9531x_output_divo_write(struct sit9531x= _dev *sitdev, u8 out_idx,=0A= msb_old =3D old_bytes[4];=0A= divo_bytes[4] |=3D msb_old & 0xFC;=0A= =0A= + *back =3D false;=0A= for (j =3D 0; j < 5; j++) {=0A= rc =3D sit9531x_write_u8(sitdev,=0A= SIT9531X_REG(page, base_reg - j),=0A= @@ -1962,12 +2036,361 @@ static int sit9531x_output_divo_read(struct sit953= 1x_dev *sitdev, u8 out_idx,=0A= return *divo ? 0 : -ENODATA;=0A= }=0A= =0A= +/*=0A= + * Phase adjust is a 34-bit coarse delay in VCO cycles plus a 3-bit fine d= elay=0A= + * in 30 ps steps, in bytes PROG6..PROG2. PRG_RST_DELAY is unsigned, so an= =0A= + * advance is written as T_out - |phase|.=0A= + */=0A= +=0A= +/* Register of byte @i (PROG6 first) of an output's PRG_RST_DELAY block. *= /=0A= +static unsigned int sit9531x_output_prg_reg(struct sit9531x_dev *sitdev,= =0A= + u8 out_idx, u8 i)=0A= +{=0A= + u8 slot =3D sitdev->info->clkout_map[out_idx];=0A= + u8 page =3D (slot > SIT9531X_PAGE_OUTSYS0_SLOT_MAX) ?=0A= + SIT9531X_PAGE_OUTSYS1 : SIT9531X_PAGE_OUTSYS0;=0A= + u8 base =3D SIT9531X_OUT_PRG_DELAY_BASE +=0A= + SIT9531X_OUT_PRG_SLOT_STRIDE * (slot % 6);=0A= +=0A= + return SIT9531X_REG(page, base + i);=0A= +}=0A= +=0A= +static int sit9531x_output_phase_bytes_read(struct sit9531x_dev *sitdev,= =0A= + u8 out_idx, u8 *bytes)=0A= +{=0A= + unsigned int reg;=0A= + int rc;=0A= + u8 i;=0A= +=0A= + for (i =3D 0; i < SIT9531X_OUT_PRG_BYTES; i++) {=0A= + reg =3D sit9531x_output_prg_reg(sitdev, out_idx, i);=0A= + rc =3D sit9531x_read_u8(sitdev, reg, &bytes[i]);=0A= + if (rc)=0A= + return rc;=0A= + }=0A= +=0A= + return 0;=0A= +}=0A= +=0A= +/*=0A= + * The register value includes the divider's settling cycles; a value belo= w them=0A= + * means no delay.=0A= + */=0A= +static void sit9531x_output_phase_bytes_decode(const u8 *bytes, u64 *coars= e,=0A= + u8 *fine)=0A= +{=0A= + u64 prg_coarse;=0A= +=0A= + *fine =3D (bytes[0] & SIT9531X_OUT_PRG_FINE_MASK) >>=0A= + SIT9531X_OUT_PRG_FINE_SHIFT;=0A= + prg_coarse =3D (u64)(bytes[0] & SIT9531X_OUT_PRG_COARSE_HI_MASK) << 32;= =0A= + prg_coarse |=3D (u64)bytes[1] << 24;=0A= + prg_coarse |=3D (u64)bytes[2] << 16;=0A= + prg_coarse |=3D (u64)bytes[3] << 8;=0A= + prg_coarse |=3D bytes[4];=0A= + *coarse =3D (prg_coarse > SIT9531X_OUT_PRG_DIVO_CYCLES) ?=0A= + prg_coarse - SIT9531X_OUT_PRG_DIVO_CYCLES : 0;=0A= +}=0A= +=0A= +/*=0A= + * @coarse excludes the divider's two settling cycles; the register value= =0A= + * includes them.=0A= + */=0A= +static void sit9531x_output_phase_bytes_build(const u8 *old_bytes, u64 coa= rse,=0A= + u8 fine, u8 *new_bytes)=0A= +{=0A= + u64 prg_coarse =3D coarse + SIT9531X_OUT_PRG_DIVO_CYCLES;=0A= +=0A= + /* PROG6 RMW: preserve OPSTG_VCASC_BUMP in [7:5] */=0A= + new_bytes[0] =3D old_bytes[0] & SIT9531X_OUT_PRG_OPSTG_MASK;=0A= + new_bytes[0] |=3D (fine << SIT9531X_OUT_PRG_FINE_SHIFT) &=0A= + SIT9531X_OUT_PRG_FINE_MASK;=0A= + new_bytes[0] |=3D (u8)((prg_coarse >> 32) &=0A= + SIT9531X_OUT_PRG_COARSE_HI_MASK);=0A= + new_bytes[1] =3D (u8)((prg_coarse >> 24) & 0xFF);=0A= + new_bytes[2] =3D (u8)((prg_coarse >> 16) & 0xFF);=0A= + new_bytes[3] =3D (u8)((prg_coarse >> 8) & 0xFF);=0A= + new_bytes[4] =3D (u8)(prg_coarse & 0xFF);=0A= +}=0A= +=0A= +/*=0A= + * Caller must hold the debug window open; @back reports whether every byt= e=0A= + * holds its old value.=0A= + */=0A= +static int sit9531x_output_phase_bytes_write(struct sit9531x_dev *sitdev,= =0A= + u8 out_idx, const u8 *new_bytes,=0A= + const u8 *old_bytes, bool *back)=0A= +{=0A= + int rc, ret, rb_rc =3D 0;=0A= + unsigned int reg;=0A= + u8 i;=0A= +=0A= + *back =3D false;=0A= +=0A= + for (i =3D 0; i < SIT9531X_OUT_PRG_BYTES; i++) {=0A= + reg =3D sit9531x_output_prg_reg(sitdev, out_idx, i);=0A= + rc =3D sit9531x_write_u8(sitdev, reg, new_bytes[i]);=0A= + if (rc)=0A= + goto rollback;=0A= + }=0A= +=0A= + return 0;=0A= +=0A= +rollback:=0A= + for (i =3D 0; i < SIT9531X_OUT_PRG_BYTES; i++) {=0A= + reg =3D sit9531x_output_prg_reg(sitdev, out_idx, i);=0A= + ret =3D sit9531x_write_u8(sitdev, reg, old_bytes[i]);=0A= + if (ret && !rb_rc)=0A= + rb_rc =3D ret;=0A= + }=0A= + *back =3D !rb_rc;=0A= + if (rb_rc) {=0A= + dev_err(sitdev->dev,=0A= + "out%u: phase-adjust rollback failed (%d), the delay registers are part= old and part new\n",=0A= + out_idx, rb_rc);=0A= + if (!rc)=0A= + rc =3D rb_rc;=0A= + }=0A= +=0A= + return rc;=0A= +}=0A= +=0A= +/*=0A= + * Return the error of @cycles VCO cycles plus the nearest fine steps (in = @fine)=0A= + * against @abs_ps.=0A= + */=0A= +static u64 sit9531x_output_phase_quant_err(u64 abs_ps, u64 fvco, u64 cycle= s,=0A= + u8 *fine)=0A= +{=0A= + u64 cycles_ps, steps =3D 0;=0A= +=0A= + cycles_ps =3D mul_u64_u64_div_u64(cycles, 1000000000000ULL, fvco);=0A= + if (abs_ps > cycles_ps)=0A= + steps =3D div64_u64(abs_ps - cycles_ps +=0A= + SIT9531X_OUT_PRG_FINE_STEP_PS / 2,=0A= + SIT9531X_OUT_PRG_FINE_STEP_PS);=0A= + *fine =3D min_t(u64, steps, SIT9531X_OUT_PRG_FINE_MAX);=0A= +=0A= + return abs_diff(abs_ps, cycles_ps +=0A= + (u64)*fine * SIT9531X_OUT_PRG_FINE_STEP_PS);=0A= +}=0A= +=0A= +/*=0A= + * Fold @phase_ps into one output period and split it into VCO cycles and = fine=0A= + * steps; @phase_adj gets the realized delay as the readback reports it. P= ure=0A= + * arithmetic, so call it before entering the programming state.=0A= + */=0A= +static int sit9531x_output_phase_encode(u64 fvco, u64 divo, s32 phase_ps,= =0A= + u64 *coarse_out, u8 *fine_out,=0A= + s32 *phase_adj)=0A= +{=0A= + u64 abs_ps, cycles, frac_ps, coarse =3D 0, coarse_ps, t_out_ps;=0A= + s64 phase_norm_ps =3D 0;=0A= + u8 fine =3D 0;=0A= +=0A= + t_out_ps =3D mul_u64_u64_div_u64(divo, 1000000000000ULL, fvco);=0A= + if (!t_out_ps)=0A= + return -EINVAL;=0A= +=0A= + if (!phase_ps) {=0A= + *coarse_out =3D 0;=0A= + *fine_out =3D 0;=0A= + *phase_adj =3D 0;=0A= + return 0;=0A= + }=0A= +=0A= + /*=0A= + * The period is DIVO VCO cycles but often fractional in ps (7812.5 ps=0A= + * at 128 MHz from 5.12 GHz), so fold whole cycles modulo DIVO and carry= =0A= + * the sub-cycle part. The DPLL core limits the request to +/-1 ms.=0A= + */=0A= + abs_ps =3D abs(phase_ps);=0A= + cycles =3D mul_u64_u64_div_u64(abs_ps, fvco, 1000000000000ULL);=0A= + frac_ps =3D abs_ps - mul_u64_u64_div_u64(cycles, 1000000000000ULL, fvco);= =0A= + div64_u64_rem(cycles, divo, &cycles);=0A= + abs_ps =3D mul_u64_u64_div_u64(cycles, 1000000000000ULL, fvco) + frac_ps;= =0A= + /*=0A= + * Truncation can leave a request within 1 ps of a whole period, which=0A= + * is the same edge as no delay.=0A= + */=0A= + if (abs_ps >=3D t_out_ps)=0A= + abs_ps =3D 0;=0A= + phase_norm_ps =3D phase_ps < 0 ? -(s64)abs_ps : (s64)abs_ps;=0A= + abs_ps =3D (phase_ps < 0 && abs_ps) ? t_out_ps - abs_ps : abs_ps;=0A= +=0A= + if (abs_ps) {=0A= + u64 floor_cycles, err, alt_err, realized;=0A= + u8 alt_fine;=0A= +=0A= + /* mul_u64_u64_div_u64(): abs_ps * fvco would overflow. */=0A= + floor_cycles =3D mul_u64_u64_div_u64(abs_ps, fvco,=0A= + 1000000000000ULL);=0A= +=0A= + /*=0A= + * The fine field spans 210 ps, more than one VCO cycle in every=0A= + * band, so take the nearest of floor, floor + 1, and floor - 1=0A= + * with a larger fine code; the floor on a tie.=0A= + */=0A= + coarse =3D floor_cycles;=0A= + err =3D sit9531x_output_phase_quant_err(abs_ps, fvco, coarse,=0A= + &fine);=0A= + alt_err =3D sit9531x_output_phase_quant_err(abs_ps, fvco,=0A= + floor_cycles + 1,=0A= + &alt_fine);=0A= + if (alt_err < err) {=0A= + coarse =3D floor_cycles + 1;=0A= + fine =3D alt_fine;=0A= + err =3D alt_err;=0A= + }=0A= + if (floor_cycles) {=0A= + u64 fewer =3D floor_cycles - 1;=0A= +=0A= + alt_err =3D sit9531x_output_phase_quant_err(abs_ps, fvco,=0A= + fewer,=0A= + &alt_fine);=0A= + if (alt_err < err) {=0A= + coarse =3D fewer;=0A= + fine =3D alt_fine;=0A= + }=0A= + }=0A= +=0A= + /*=0A= + * Program a delay that quantizes to a whole period or more as=0A= + * none, and round one past the advertised range toward the=0A= + * request's side.=0A= + */=0A= + coarse_ps =3D mul_u64_u64_div_u64(coarse, 1000000000000ULL, fvco);=0A= + realized =3D coarse_ps +=0A= + (u64)fine * SIT9531X_OUT_PRG_FINE_STEP_PS;=0A= + if (realized >=3D t_out_ps) {=0A= + coarse =3D 0;=0A= + fine =3D 0;=0A= + } else if (phase_norm_ps < 0 ?=0A= + t_out_ps - realized > SIT9531X_OUT_PHASE_ADJ_MAX_PS :=0A= + realized > SIT9531X_OUT_PHASE_ADJ_MAX_PS) {=0A= + u64 rem;=0A= +=0A= + coarse =3D floor_cycles;=0A= + coarse_ps =3D mul_u64_u64_div_u64(coarse,=0A= + 1000000000000ULL, fvco);=0A= + rem =3D abs_ps - coarse_ps;=0A= + if (phase_norm_ps < 0)=0A= + rem +=3D SIT9531X_OUT_PRG_FINE_STEP_PS - 1;=0A= + fine =3D div_u64(rem, SIT9531X_OUT_PRG_FINE_STEP_PS);=0A= + }=0A= +=0A= + if (coarse + SIT9531X_OUT_PRG_DIVO_CYCLES >=3D=0A= + (1ULL << SIT9531X_OUT_PRG_COARSE_BITS))=0A= + return -ERANGE;=0A= + }=0A= +=0A= + coarse_ps =3D mul_u64_u64_div_u64(coarse, 1000000000000ULL, fvco);=0A= + abs_ps =3D coarse_ps + (u64)fine * SIT9531X_OUT_PRG_FINE_STEP_PS;=0A= + /*=0A= + * Report the form nearer to zero, as the readback does; it is within=0A= + * the range, so it fits the s32 the ABI carries.=0A= + */=0A= + if (abs_ps > t_out_ps - abs_ps)=0A= + *phase_adj =3D -(s32)(t_out_ps - abs_ps);=0A= + else=0A= + *phase_adj =3D (s32)abs_ps;=0A= +=0A= + *coarse_out =3D coarse;=0A= + *fine_out =3D fine;=0A= +=0A= + return 0;=0A= +}=0A= +=0A= +/**=0A= + * sit9531x_output_phase_read - read an output's programmed delay back=0A= + * @sitdev: device pointer=0A= + * @out_idx: logical output index=0A= + * @phase_ps: result in picoseconds=0A= + * @beyond: set when @phase_ps is outside the advertised range=0A= + *=0A= + * An advance is stored as the period minus the advance; the stored delay = reads=0A= + * back in the form nearer to zero, as an advance when it is more than hal= f the=0A= + * period. Caller must hold sitdev->multiop_lock.=0A= + *=0A= + * Return: 0 on success, -ENODATA for an output no PLL drives or whose Fvc= o=0A= + * is unknown, <0 on other errors=0A= + */=0A= +int sit9531x_output_phase_read(struct sit9531x_dev *sitdev, u8 out_idx,=0A= + s64 *phase_ps, bool *beyond)=0A= +{=0A= + const struct sit9531x_chip_info *info =3D sitdev->info;=0A= + u8 bytes[SIT9531X_OUT_PRG_BYTES], fine;=0A= + u64 coarse =3D 0, fvco, ps, divo;=0A= + int rc;=0A= +=0A= + lockdep_assert_held(&sitdev->multiop_lock);=0A= +=0A= + if (out_idx >=3D info->num_outputs)=0A= + return -EINVAL;=0A= +=0A= + *beyond =3D false;=0A= +=0A= + if (!sitdev->out[out_idx].routed)=0A= + return -ENODATA;=0A= +=0A= + rc =3D sit9531x_get_fvco(sitdev, sitdev->out[out_idx].pll_idx, &fvco);=0A= + if (rc)=0A= + return rc;=0A= +=0A= + rc =3D sit9531x_output_phase_bytes_read(sitdev, out_idx, bytes);=0A= + if (rc)=0A= + return rc;=0A= + sit9531x_output_phase_bytes_decode(bytes, &coarse, &fine);=0A= +=0A= + /*=0A= + * Take the period from the divider; the cached rate is unset at probe=0A= + * and whole hertz at best.=0A= + */=0A= + rc =3D sit9531x_output_divo_read(sitdev, out_idx, &divo);=0A= + if (rc && rc !=3D -ENODATA)=0A= + return rc;=0A= +=0A= + /*=0A= + * Fold the cycle count, not the picoseconds; the fine steps can carry=0A= + * the sum a fraction of a cycle past the period.=0A= + */=0A= + if (!rc)=0A= + div64_u64_rem(coarse, divo, &coarse);=0A= +=0A= + ps =3D mul_u64_u64_div_u64(coarse, 1000000000000ULL, fvco);=0A= + ps +=3D (u64)fine * SIT9531X_OUT_PRG_FINE_STEP_PS;=0A= +=0A= + if (!rc) {=0A= + u64 t_out_ps =3D mul_u64_u64_div_u64(divo, 1000000000000ULL,=0A= + fvco);=0A= +=0A= + if (ps >=3D t_out_ps)=0A= + ps -=3D t_out_ps;=0A= + if (ps > t_out_ps - ps &&=0A= + t_out_ps - ps <=3D SIT9531X_OUT_PHASE_ADJ_MAX_PS) {=0A= + *phase_ps =3D -(s64)(t_out_ps - ps);=0A= + return 0;=0A= + }=0A= + }=0A= + *beyond =3D ps > SIT9531X_OUT_PHASE_ADJ_MAX_PS;=0A= + *phase_ps =3D ps;=0A= +=0A= + return 0;=0A= +}=0A= +=0A= int sit9531x_output_freq_set(struct sit9531x_dev *sitdev, u8 out_idx,=0A= u8 pll_idx, u64 frequency)=0A= {=0A= - u64 fvco, divo;=0A= + u8 old_bytes[SIT9531X_OUT_PRG_BYTES], new_bytes[SIT9531X_OUT_PRG_BYTES];= =0A= + bool divo_back =3D false, divo_in, back, landed, encoded =3D false;=0A= + bool retime =3D false, bytes_in =3D false, bytes_back =3D false;=0A= + struct sit9531x_chan *chan =3D &sitdev->chan[pll_idx];=0A= + struct sit9531x_out *out =3D &sitdev->out[out_idx];=0A= + u64 fvco, divo, coarse, old_divo =3D 0;=0A= + s32 phase_adj =3D 0, held =3D 0;=0A= + bool beyond;=0A= int rc, ret;=0A= - bool back;=0A= + u8 fine;=0A= =0A= lockdep_assert_held(&sitdev->multiop_lock);=0A= =0A= @@ -1976,28 +2399,120 @@ int sit9531x_output_freq_set(struct sit9531x_dev *= sitdev, u8 out_idx,=0A= if (rc)=0A= return rc;=0A= =0A= + /* The rate resolved, so a record of no delay value is out of date */=0A= + if ((out->phase_stale || out->phase_none) && !out->retime_pending) {=0A= + s64 phase_ps;=0A= +=0A= + rc =3D sit9531x_output_phase_read(sitdev, out_idx, &phase_ps,=0A= + &beyond);=0A= + if (rc)=0A= + return rc;=0A= + out->phase_adj =3D phase_ps;=0A= + out->phase_armed =3D !beyond && phase_ps;=0A= + out->phase_stale =3D false;=0A= + out->phase_none =3D false;=0A= + }=0A= +=0A= + /*=0A= + * The reset delay counts VCO cycles: encode the pending delay, or=0A= + * out->phase_adj in its form nearer to zero (an advance for a delay=0A= + * above half the old period), again for the new period. Write it in the= =0A= + * divider's programming window; a second flush restarts the dividers.=0A= + */=0A= + rc =3D sit9531x_output_phase_bytes_read(sitdev, out_idx, old_bytes);=0A= + if (rc)=0A= + return rc;=0A= + sit9531x_output_phase_bytes_decode(old_bytes, &coarse, &fine);=0A= + beyond =3D !out->retime_pending && !out->phase_armed && out->phase_adj;= =0A= + if (out->retime_pending || out->phase_armed ||=0A= + ((coarse || fine) && !beyond)) {=0A= + held =3D out->retime_pending ? out->retime_ps : out->phase_adj;=0A= +=0A= + rc =3D sit9531x_output_phase_encode(fvco, divo, held, &coarse,=0A= + &fine, &phase_adj);=0A= + if (rc)=0A= + return rc;=0A= + encoded =3D true;=0A= + sit9531x_output_phase_bytes_build(old_bytes, coarse, fine,=0A= + new_bytes);=0A= + retime =3D memcmp(old_bytes, new_bytes, sizeof(new_bytes)) !=3D 0;=0A= + }=0A= +=0A= + if (retime) {=0A= + rc =3D sit9531x_output_divo_read(sitdev, out_idx, &old_divo);=0A= + if (rc && rc !=3D -ENODATA)=0A= + return rc;=0A= + }=0A= +=0A= rc =3D sit9531x_prg_enter(sitdev);=0A= if (rc)=0A= return rc;=0A= =0A= rc =3D sit9531x_output_divo_write(sitdev, out_idx, divo, &back);=0A= - /* NVM update and loop lock */=0A= - ret =3D sit9531x_prg_commit(sitdev);=0A= + landed =3D !back;=0A= + divo_in =3D !rc;=0A= + if (!rc && retime) {=0A= + rc =3D sit9531x_output_phase_bytes_write(sitdev, out_idx,=0A= + new_bytes, old_bytes,=0A= + &bytes_back);=0A= + if (rc) {=0A= + divo_back =3D bytes_back &&=0A= + !sit9531x_output_divo_write(sitdev, out_idx,=0A= + old_divo, &back);=0A= + landed =3D !divo_back;=0A= + } else {=0A= + bytes_in =3D true;=0A= + }=0A= + }=0A= + /* Leave PRG_CMD; the bank update only for a divider that changed */=0A= + ret =3D landed ? sit9531x_prg_commit(sitdev) :=0A= + sit9531x_prg_relock(sitdev);=0A= if (ret && !rc)=0A= rc =3D ret;=0A= - if (rc)=0A= + if (rc) {=0A= + if (bytes_in || (encoded && !retime && divo_in)) {=0A= + out->phase_adj =3D phase_adj;=0A= + out->phase_armed =3D phase_adj !=3D 0;=0A= + out->phase_stale =3D false;=0A= + out->retime_pending =3D false;=0A= + } else if (retime && landed) {=0A= + out->retime_ps =3D held;=0A= + out->retime_pending =3D true;=0A= + out->phase_stale =3D true;=0A= + } else if (encoded && landed) {=0A= + out->phase_stale =3D true;=0A= + } else if (beyond && landed) {=0A= + out->phase_stale =3D true;=0A= + }=0A= + if (landed)=0A= + chan->flush_pending =3D true;=0A= return rc;=0A= + }=0A= =0A= - /* Flush the output phase so the new DIVO starts aligned */=0A= rc =3D sit9531x_output_phase_flush(sitdev, pll_idx);=0A= - if (rc) {=0A= + if (chan->flush_pending)=0A= dev_warn(sitdev->dev,=0A= - "out%u: rate changed but the divider phase was not realigned (%d)\n",= =0A= + "out%u: rate changed but the divider phase was not realigned (%d), the= poll retries it\n",=0A= out_idx, rc);=0A= - rc =3D 0;=0A= + else if (rc)=0A= + dev_warn(sitdev->dev,=0A= + "out%u: rate changed, the flush left something to put back (%d)\n",=0A= + out_idx, rc);=0A= + if (encoded) {=0A= + out->phase_adj =3D phase_adj;=0A= + out->phase_armed =3D phase_adj !=3D 0;=0A= + out->phase_stale =3D false;=0A= }=0A= =0A= - sitdev->out[out_idx].freq =3D div64_u64(fvco, divo);=0A= + /*=0A= + * A delay beyond the range was not re-timed and now decodes against the= =0A= + * new divider.=0A= + */=0A= + if (beyond)=0A= + out->phase_stale =3D true;=0A= +=0A= + out->freq =3D div64_u64(fvco, divo);=0A= + out->retime_pending =3D false;=0A= =0A= return 0;=0A= }=0A= @@ -2041,6 +2556,137 @@ int sit9531x_output_freq_get(struct sit9531x_dev *s= itdev, u8 out_idx,=0A= return 0;=0A= }=0A= =0A= +int sit9531x_output_phase_adjust_set(struct sit9531x_dev *sitdev,=0A= + u8 out_idx, s32 phase_ps)=0A= +{=0A= + u8 old_bytes[SIT9531X_OUT_PRG_BYTES], new_bytes[SIT9531X_OUT_PRG_BYTES];= =0A= + const struct sit9531x_chip_info *info =3D sitdev->info;=0A= + u64 fvco, divo, coarse, old_coarse;=0A= + bool bytes_back, bytes_in, same;=0A= + u8 pll_idx, fine, old_fine;=0A= + struct sit9531x_chan *chan;=0A= + struct sit9531x_out *out;=0A= + s32 phase_adj;=0A= + int rc;=0A= +=0A= + lockdep_assert_held(&sitdev->multiop_lock);=0A= +=0A= + if (out_idx >=3D info->num_outputs)=0A= + return -EINVAL;=0A= +=0A= + /* An unrouted output has only a placeholder in pll_idx. */=0A= + if (!sitdev->out[out_idx].routed)=0A= + return -ENODEV;=0A= +=0A= + out =3D &sitdev->out[out_idx];=0A= + pll_idx =3D out->pll_idx;=0A= + if (pll_idx >=3D SIT9531X_NUM_PLLS)=0A= + return -EINVAL;=0A= + chan =3D &sitdev->chan[pll_idx];=0A= +=0A= + rc =3D sit9531x_get_fvco(sitdev, pll_idx, &fvco);=0A= + if (rc)=0A= + return rc =3D=3D -ENODATA ? -ENODEV : rc;=0A= +=0A= + /* Take the period from the divider; the cached rate is whole hertz. */= =0A= + rc =3D sit9531x_output_divo_read(sitdev, out_idx, &divo);=0A= + if (rc)=0A= + return rc =3D=3D -ENODATA ? -ENODEV : rc;=0A= +=0A= + rc =3D sit9531x_output_phase_encode(fvco, divo, phase_ps, &coarse, &fine,= =0A= + &phase_adj);=0A= + if (rc)=0A= + return rc;=0A= +=0A= + rc =3D sit9531x_output_phase_bytes_read(sitdev, out_idx, old_bytes);=0A= + if (rc)=0A= + return rc;=0A= + sit9531x_output_phase_bytes_build(old_bytes, coarse, fine, new_bytes);=0A= +=0A= + /*=0A= + * Skip the write if the quantized delay is unchanged; a rewrite=0A= + * restarts the divider phase of every output on the PLL. Every coarse=0A= + * value up to the settling cycles decodes as no delay.=0A= + */=0A= + sit9531x_output_phase_bytes_decode(old_bytes, &old_coarse, &old_fine);=0A= + same =3D old_coarse =3D=3D coarse && old_fine =3D=3D fine && !out->phase_= stale;=0A= + if (same && !chan->flush_pending) {=0A= + rc =3D 0;=0A= + goto cache;=0A= + }=0A= +=0A= + if (!same) {=0A= + /*=0A= + * Order of Dely_program_output.py: the bytes on page 3 or 4=0A= + * under the Page 3 debug key, the small-change update on page 3=0A= + * for either page, then the flush with no wait. Only a divider=0A= + * rewrite needs the programming state.=0A= + */=0A= + rc =3D sit9531x_outsys_debug_open(sitdev);=0A= + if (rc)=0A= + return rc;=0A= +=0A= + rc =3D sit9531x_output_phase_bytes_write(sitdev, out_idx,=0A= + new_bytes, old_bytes,=0A= + &bytes_back);=0A= + bytes_in =3D !rc;=0A= + if (!rc)=0A= + rc =3D sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,=0A= + SIT9531X_SMALL_UPDATE_CMD);=0A= + sit9531x_outsys_debug_close(sitdev);=0A= + if (rc) {=0A= + if (bytes_in) {=0A= + out->phase_stale =3D true;=0A= + out->retime_ps =3D phase_ps;=0A= + out->retime_pending =3D true;=0A= + } else if (!bytes_back) {=0A= + out->phase_stale =3D true;=0A= + chan->flush_pending =3D true;=0A= + }=0A= + return rc;=0A= + }=0A= + }=0A= +=0A= + /*=0A= + * A flush pulse into open loops can be lost when they re-lock, and a=0A= + * bank update after it changes the dividers again.=0A= + */=0A= + if (sitdev->bank_pending || sitdev->loops_open) {=0A= + rc =3D sit9531x_prg_retry(sitdev);=0A= + if (rc) {=0A= + chan->flush_pending =3D true;=0A= + goto cache;=0A= + }=0A= + }=0A= +=0A= + /*=0A= + * Restart the divider phase so the delay applies against a known edge.= =0A= + */=0A= + rc =3D sit9531x_output_phase_flush(sitdev, pll_idx);=0A= +=0A= +cache:=0A= + /* Cache what the registers hold */=0A= + out->phase_adj =3D phase_adj;=0A= + out->phase_stale =3D false;=0A= + out->phase_none =3D false;=0A= + out->retime_pending =3D false;=0A= +=0A= + /*=0A= + * A delay that quantized to zero needs no re-time: the quantum is the=0A= + * VCO cycle, not the output period.=0A= + */=0A= + out->phase_armed =3D phase_adj !=3D 0;=0A= +=0A= + if (chan->flush_pending)=0A= + return rc;=0A= + if (rc)=0A= + dev_warn(sitdev->dev,=0A= + "out%u: delay applied, the flush left something to put back (%d)\n",= =0A= + out_idx, rc);=0A= +=0A= + return 0;=0A= +}=0A= +=0A= /* The latches INTRB reports, each with its sticky bits */=0A= static const struct {=0A= unsigned int reg;=0A= @@ -2597,6 +3243,9 @@ static int sit9531x_dev_state_fetch(struct sit9531x_d= ev *sitdev)=0A= }=0A= =0A= for (i =3D 0; i < sitdev->info->num_outputs; i++) {=0A= + bool beyond;=0A= + s64 phase_ps;=0A= +=0A= mutex_lock(&sitdev->multiop_lock);=0A= rc =3D sit9531x_out_state_fetch(sitdev, i);=0A= mutex_unlock(&sitdev->multiop_lock);=0A= @@ -2605,6 +3254,24 @@ static int sit9531x_dev_state_fetch(struct sit9531x_= dev *sitdev)=0A= "Failed to fetch output %u state: %d\n", i, rc);=0A= return rc;=0A= }=0A= +=0A= + /*=0A= + * The profile can set a delay; read it so a request of 0 ps can=0A= + * clear it.=0A= + */=0A= + mutex_lock(&sitdev->multiop_lock);=0A= + rc =3D sit9531x_output_phase_read(sitdev, i, &phase_ps, &beyond);=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= + sitdev->out[i].phase_none =3D rc =3D=3D -ENODATA;=0A= + if (!rc) {=0A= + sitdev->out[i].phase_adj =3D phase_ps;=0A= + sitdev->out[i].phase_armed =3D !beyond && phase_ps;=0A= + } else if (rc !=3D -ENODATA) {=0A= + dev_err(sitdev->dev,=0A= + "Failed to read output %u delay: %d\n",=0A= + i, rc);=0A= + return rc;=0A= + }=0A= }=0A= =0A= mutex_lock(&sitdev->multiop_lock);=0A= @@ -2743,6 +3410,25 @@ static void sit9531x_ho_release_retry(struct sit9531= x_dev *sitdev, u8 pll_idx)=0A= 'A' + pll_idx);=0A= }=0A= =0A= +/*=0A= + * Apply a delay that waits for its re-time after a rate change or for its= =0A= + * small-change update. Caller must hold sitdev->multiop_lock.=0A= + */=0A= +static void sit9531x_retime_retry(struct sit9531x_dev *sitdev, u8 out_idx)= =0A= +{=0A= + struct sit9531x_out *out =3D &sitdev->out[out_idx];=0A= +=0A= + if (!out->retime_pending)=0A= + return;=0A= +=0A= + if (!sit9531x_output_phase_adjust_set(sitdev, out_idx, out->retime_ps))= =0A= + dev_info(sitdev->dev, "out%u: pending delay applied\n",=0A= + out_idx);=0A= + /* The delay getter reports a value again */=0A= + if (!out->retime_pending)=0A= + out->ntf_pending =3D true;=0A= +}=0A= +=0A= /*=0A= * Write back the priority table after a failed write. Caller must hold=0A= * sitdev->multiop_lock.=0A= @@ -2874,6 +3560,18 @@ static void sit9531x_reselect(struct sit9531x_dev *s= itdev, u8 pll_idx)=0A= 'A' + pll_idx);=0A= }=0A= =0A= +/* Run a pending output-divider flush. Caller must hold sitdev->multiop_lo= ck. */=0A= +static void sit9531x_flush_retry(struct sit9531x_dev *sitdev, u8 pll_idx)= =0A= +{=0A= + if (!sitdev->chan[pll_idx].flush_pending)=0A= + return;=0A= +=0A= + sit9531x_output_phase_flush(sitdev, pll_idx);=0A= + if (!sitdev->chan[pll_idx].flush_pending)=0A= + dev_info(sitdev->dev, "PLL%c: output dividers realigned\n",=0A= + 'A' + pll_idx);=0A= +}=0A= +=0A= /*=0A= * Retry pending writes, then read each PLL's state; return true if any st= ate=0A= * read succeeds.=0A= @@ -2893,12 +3591,21 @@ sit9531x_dev_chan_states_update(struct sit9531x_dev= *sitdev)=0A= } else if (sitdev->outsys_key_pending) {=0A= sit9531x_outsys_debug_close(sitdev);=0A= }=0A= + sit9531x_phase_flush_undo_retry(sitdev);=0A= + for (i =3D 0; i < sitdev->info->num_outputs; i++)=0A= + sit9531x_retime_retry(sitdev, i);=0A= =0A= sit9531x_input_off_retry(sitdev);=0A= for (i =3D 0; i < SIT9531X_NUM_PLLS; i++) {=0A= sit9531x_table_back_retry(sitdev, i);=0A= sit9531x_ho_release_retry(sitdev, i);=0A= sit9531x_debug_back_retry(sitdev, i);=0A= + /*=0A= + * A flush pulse sent into open loops may be lost when they=0A= + * re-lock; a bank update after it changes the dividers again.=0A= + */=0A= + if (!sitdev->loops_open && !sitdev->bank_pending)=0A= + sit9531x_flush_retry(sitdev, i);=0A= rc =3D sit9531x_chan_state_fetch(sitdev, i);=0A= if (rc) {=0A= sitdev->chan[i].stale =3D true;=0A= @@ -3239,6 +3946,10 @@ static void sit9531x_dev_stop(struct sit9531x_dev *s= itdev)=0A= i);=0A= mutex_unlock(&sitdev->multiop_lock);=0A= =0A= + /*=0A= + * Lock the loops first: a re-time ends in a flush, and a flush pulse=0A= + * into open loops can be lost. The undo runs after every flush.=0A= + */=0A= mutex_lock(&sitdev->multiop_lock);=0A= if (sitdev->bank_pending || sitdev->loops_open) {=0A= sit9531x_prg_retry(sitdev);=0A= @@ -3248,8 +3959,35 @@ static void sit9531x_dev_stop(struct sit9531x_dev *s= itdev)=0A= if (sitdev->loops_open)=0A= dev_warn(sitdev->dev,=0A= "output loops left unlocked at removal\n");=0A= - } else if (sitdev->outsys_key_pending) {=0A= + }=0A= + for (i =3D 0; i < sitdev->info->num_outputs; i++) {=0A= + sit9531x_retime_retry(sitdev, i);=0A= + if (sitdev->out[i].retime_pending)=0A= + dev_warn(sitdev->dev,=0A= + "out%u: pending delay not applied at removal\n",=0A= + i);=0A= + }=0A= + /* Last: a re-time opens the debug key again */=0A= + if (sitdev->outsys_key_pending)=0A= sit9531x_outsys_debug_close(sitdev);=0A= + for (i =3D 0; i < SIT9531X_NUM_PLLS; i++) {=0A= + if (!sitdev->loops_open && !sitdev->bank_pending)=0A= + sit9531x_flush_retry(sitdev, i);=0A= + if (sitdev->chan[i].flush_pending)=0A= + dev_warn(sitdev->dev,=0A= + "PLL%c: output dividers left unaligned\n",=0A= + 'A' + i);=0A= + }=0A= + sit9531x_phase_flush_undo_retry(sitdev);=0A= + if (sitdev->flush_ctrl_pending)=0A= + dev_warn(sitdev->dev,=0A= + "phase flush trigger source select not put back\n");=0A= + for (i =3D 0; i < SIT9531X_NUM_PLLS; i++) {=0A= + if (!(sitdev->flush_arm_pending & BIT(i)))=0A= + continue;=0A= + dev_warn(sitdev->dev, "PLL%c: on-demand phase flush left %s\n",=0A= + 'A' + i,=0A= + (sitdev->flush_armed & BIT(i)) ? "parked" : "armed");=0A= }=0A= mutex_unlock(&sitdev->multiop_lock);=0A= }=0A= diff --git a/drivers/dpll/sit9531x/core.h b/drivers/dpll/sit9531x/core.h=0A= index 3c2a312f392c..562c63ee117d 100644=0A= --- a/drivers/dpll/sit9531x/core.h=0A= +++ b/drivers/dpll/sit9531x/core.h=0A= @@ -27,6 +27,8 @@=0A= #define SIT9531X_MAX_INPUTS 8=0A= #define SIT9531X_NUM_INPUT_PAIRS (SIT9531X_MAX_INPUTS / 2)=0A= #define SIT9531X_MAX_OUTPUTS 12=0A= +/* Output phase-adjust range advertised to the core, +/-1 ms in ps */=0A= +#define SIT9531X_OUT_PHASE_ADJ_MAX_PS 1000000000=0A= /*=0A= * Output rates of the datasheet, Table 6: continuous up to 800 MHz, above= it=0A= * 61.44 MHz times 15, 20, 24, 30, 32, 40 or 48.=0A= @@ -128,6 +130,17 @@ struct sit9531x_ref {=0A= * @routed: mapped to @pll_idx by the loaded configuration; an output=0A= * unrouted at probe has no pin=0A= * @pll_idx: PLL driving this output (0-3)=0A= + * @phase_stale: programmed delay may differ from @phase_adj=0A= + * @phase_none: the last delay read found no valid Fvco on the PLL, so the= =0A= + * output has no delay value and the getter leaves the attribute out; a= =0A= + * delay or rate request that finds an Fvco clears it=0A= + * @phase_armed: non-zero in-range delay programmed; a rate change re-time= s it=0A= + * @phase_adj: realized delay in whole VCO cycles plus 30 ps steps, in the= =0A= + * form nearer to zero; an out-of-range profile delay is held as the=0A= + * positive decode=0A= + * @retime_pending: delay not yet applied, after a rate change or with its= =0A= + * small-change update still to be issued; the poll applies @retime_ps= =0A= + * @retime_ps: delay to apply while @retime_pending=0A= */=0A= struct sit9531x_out {=0A= u64 freq;=0A= @@ -140,6 +153,12 @@ struct sit9531x_out {=0A= u8 hiz_state;=0A= bool routed;=0A= u8 pll_idx;=0A= + s64 phase_adj;=0A= + bool phase_armed;=0A= + bool phase_stale;=0A= + bool phase_none;=0A= + bool retime_pending;=0A= + s32 retime_ps;=0A= };=0A= =0A= /*=0A= @@ -181,6 +200,8 @@ struct sit9531x_out {=0A= * @stall_shift: doublings of the stall count, one per re-select it arms, = up=0A= * to SIT9531X_RESELECT_STALL_SHIFT_MAX; cleared when a poll sees the PL= L=0A= * track, when @live_top changes, at probe and on resume=0A= + * @flush_pending: output divider realignment flush not yet triggered afte= r=0A= + * a rate or delay commit=0A= * @table_pending: priority table partly written or not latched; the PLL= =0A= * stays in forced holdover=0A= * @table_back: table reported and to be rewritten while @table_pending=0A= @@ -219,6 +240,7 @@ struct sit9531x_chan {=0A= bool tracked;=0A= u16 stall_polls;=0A= u8 stall_shift;=0A= + bool flush_pending;=0A= bool table_pending;=0A= u8 table_back[SIT9531X_PRIO_MAX_SLOTS];=0A= bool key_pending;=0A= @@ -262,6 +284,10 @@ struct sit9531x_chan {=0A= * @loops_open: output loops not yet re-locked=0A= * @bank_pending: output divider bank update still to be issued=0A= * @outsys_key_pending: output-system debug key not closed=0A= + * @flush_ctrl_pending: @flush_ctrl still to be written back=0A= + * @flush_ctrl: trigger register value to restore=0A= + * @flush_arm_pending: bit per PLL whose flush enable is still to be resto= red=0A= + * @flush_armed: of those, the PLLs the profile arms=0A= */=0A= struct sit9531x_dev {=0A= struct device *dev;=0A= @@ -296,6 +322,10 @@ struct sit9531x_dev {=0A= bool loops_open;=0A= bool bank_pending;=0A= bool outsys_key_pending;=0A= + bool flush_ctrl_pending;=0A= + u8 flush_ctrl;=0A= + u8 flush_arm_pending;=0A= + u8 flush_armed;=0A= };=0A= =0A= int sit9531x_read_u8(struct sit9531x_dev *sitdev, unsigned int reg,=0A= @@ -333,6 +363,11 @@ int sit9531x_output_freq_set(struct sit9531x_dev *sitd= ev, u8 out_idx,=0A= int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx,=0A= u64 *frequency);=0A= =0A= +int sit9531x_output_phase_read(struct sit9531x_dev *sitdev, u8 out_idx,=0A= + s64 *phase_ps, bool *beyond);=0A= +int sit9531x_output_phase_adjust_set(struct sit9531x_dev *sitdev,=0A= + u8 out_idx, s32 phase_ps);=0A= +=0A= static inline u8 sit9531x_pll_page(u8 pll_idx)=0A= {=0A= return SIT9531X_PAGE_PLLA + pll_idx;=0A= diff --git a/drivers/dpll/sit9531x/dpll.c b/drivers/dpll/sit9531x/dpll.c=0A= index b0403c0bc132..502b25f22be4 100644=0A= --- a/drivers/dpll/sit9531x/dpll.c=0A= +++ b/drivers/dpll/sit9531x/dpll.c=0A= @@ -647,6 +647,7 @@ sit9531x_dpll_output_pin_frequency_set(const struct dpl= l_pin *pin,=0A= struct sit9531x_dpll *sitdpll =3D dpll_priv;=0A= struct sit9531x_dev *sitdev =3D sitdpll->dev;=0A= bool moved =3D false;=0A= + s64 phase_was;=0A= u8 actual_pll;=0A= u64 was, hz;=0A= int rc;=0A= @@ -663,9 +664,12 @@ sit9531x_dpll_output_pin_frequency_set(const struct dp= ll_pin *pin,=0A= return -EINVAL;=0A= }=0A= was =3D sitdev->out[dpin->id].freq;=0A= + phase_was =3D sitdev->out[dpin->id].phase_adj;=0A= rc =3D sit9531x_output_freq_set(sitdev, dpin->id, actual_pll,=0A= frequency);=0A= if (rc) {=0A= + moved =3D sitdev->out[dpin->id].phase_stale ||=0A= + sitdev->out[dpin->id].phase_adj !=3D phase_was;=0A= if (sit9531x_output_freq_get(sitdev, dpin->id, &hz))=0A= moved =3D true;=0A= else=0A= @@ -790,12 +794,119 @@ sit9531x_dpll_output_pin_state_on_dpll_set(const str= uct dpll_pin *pin,=0A= return rc;=0A= }=0A= =0A= +/*=0A= + * Report the delay as programmed after quantization, including one whose = flush=0A= + * is pending. An output whose PLL has no valid Fvco has no delay value.= =0A= + */=0A= +static int=0A= +sit9531x_dpll_output_pin_phase_adjust_get(const struct dpll_pin *pin,=0A= + void *pin_priv,=0A= + const struct dpll_device *dpll,=0A= + void *dpll_priv, s32 *phase_adjust,=0A= + struct netlink_ext_ack *extack)=0A= +{=0A= + struct sit9531x_dpll_pin *dpin =3D pin_priv;=0A= + struct sit9531x_dpll *sitdpll =3D dpll_priv;=0A= + struct sit9531x_dev *sitdev =3D sitdpll->dev;=0A= + s64 phase_adj;=0A= + bool none;=0A= + int rc;=0A= +=0A= + mutex_lock(&sitdev->multiop_lock);=0A= + /*=0A= + * A pending re-time has no delay to report: its bytes are for the old=0A= + * rate or wait for their small-change update. With no value the core=0A= + * passes every request on, the old delay included.=0A= + */=0A= + if (sitdev->out[dpin->id].retime_pending) {=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= + return -ENODATA;=0A= + }=0A= + if (sitdev->out[dpin->id].phase_stale) {=0A= + bool beyond;=0A= + s64 phase_ps;=0A= +=0A= + rc =3D sit9531x_output_phase_read(sitdev, dpin->id, &phase_ps,=0A= + &beyond);=0A= + /* -ENODATA: no delay value; another error fails the pin dump */=0A= + if (rc && rc !=3D -ENODATA) {=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= + dev_warn_ratelimited(sitdev->dev,=0A= + "out%u: delay not read back: %d\n",=0A= + dpin->id, rc);=0A= + return -ENODATA;=0A= + }=0A= + sitdev->out[dpin->id].phase_none =3D rc =3D=3D -ENODATA;=0A= + if (!rc) {=0A= + sitdev->out[dpin->id].phase_adj =3D phase_ps;=0A= + sitdev->out[dpin->id].phase_armed =3D !beyond && phase_ps;=0A= + }=0A= + sitdev->out[dpin->id].phase_stale =3D false;=0A= + }=0A= + none =3D sit9531x_out_state_get(sitdev, dpin->id)->phase_none;=0A= + phase_adj =3D sit9531x_out_state_get(sitdev, dpin->id)->phase_adj;=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= +=0A= + /*=0A= + * A delay found on the part is reported as found, also beyond the=0A= + * advertised range, which bounds a request; one beyond the s32=0A= + * attribute is left out.=0A= + */=0A= + if (none || phase_adj > S32_MAX)=0A= + return -ENODATA;=0A= + *phase_adjust =3D phase_adj;=0A= +=0A= + return 0;=0A= +}=0A= +=0A= +/* Program the per-output PRG_RST_DELAY registers */=0A= +static int=0A= +sit9531x_dpll_output_pin_phase_adjust_set(const struct dpll_pin *pin,=0A= + void *pin_priv,=0A= + const struct dpll_device *dpll,=0A= + void *dpll_priv, s32 phase_adjust,=0A= + struct netlink_ext_ack *extack)=0A= +{=0A= + struct sit9531x_dpll_pin *dpin =3D pin_priv;=0A= + struct sit9531x_dpll *sitdpll =3D dpll_priv;=0A= + struct sit9531x_dev *sitdev =3D sitdpll->dev;=0A= + const struct sit9531x_out *out;=0A= + bool moved;=0A= + s64 was;=0A= + int rc;=0A= +=0A= + out =3D sit9531x_out_state_get(sitdev, dpin->id);=0A= +=0A= + mutex_lock(&sitdev->multiop_lock);=0A= + was =3D out->phase_adj;=0A= + rc =3D sit9531x_output_phase_adjust_set(sitdev, dpin->id, phase_adjust);= =0A= + moved =3D out->phase_adj !=3D was || out->phase_stale;=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= +=0A= + if (rc) {=0A= + struct dpll_pin *dpll_pin;=0A= +=0A= + NL_SET_ERR_MSG(extack, "Phase adjust failed");=0A= + /* The core notifies only a request that succeeded */=0A= + dpll_pin =3D READ_ONCE(dpin->dpll_pin);=0A= + if (moved && dpll_pin && __dpll_pin_change_ntf(dpll_pin)) {=0A= + mutex_lock(&sitdev->multiop_lock);=0A= + sitdev->out[dpin->id].ntf_pending =3D true;=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= + }=0A= + }=0A= +=0A= + return rc;=0A= +}=0A= +=0A= static const struct dpll_pin_ops sit9531x_dpll_output_pin_ops =3D {=0A= .direction_get =3D sit9531x_dpll_output_pin_direction_get,=0A= .frequency_get =3D sit9531x_dpll_output_pin_frequency_get,=0A= .frequency_set =3D sit9531x_dpll_output_pin_frequency_set,=0A= .state_on_dpll_get =3D sit9531x_dpll_output_pin_state_on_dpll_get,=0A= .state_on_dpll_set =3D sit9531x_dpll_output_pin_state_on_dpll_set,=0A= + .phase_adjust_get =3D sit9531x_dpll_output_pin_phase_adjust_get,=0A= + .phase_adjust_set =3D sit9531x_dpll_output_pin_phase_adjust_set,=0A= };=0A= =0A= const struct dpll_pin_ops *=0A= @@ -884,7 +995,7 @@ void sit9531x_dpll_pin_baseline(struct sit9531x_dpll_pi= n *pin)=0A= =0A= /*=0A= * Re-read an output with a pending change notification; return true once = the=0A= - * read succeeds. Caller must hold sitdev->multiop_lock.=0A= + * read succeeds or finds no delay. Caller must hold sitdev->multiop_lock.= =0A= */=0A= static bool=0A= sit9531x_dpll_output_ntf_pending(struct sit9531x_dev *sitdev,=0A= @@ -901,6 +1012,23 @@ sit9531x_dpll_output_ntf_pending(struct sit9531x_dev = *sitdev,=0A= return false;=0A= if (out->state_stale && sit9531x_output_state_refresh(sitdev, pin->id))= =0A= return false;=0A= + if (out->phase_stale && !out->retime_pending) {=0A= + bool beyond;=0A= + s64 phase_ps;=0A= + int rc;=0A= +=0A= + /* -ENODATA: the getter leaves the delay out of the message */=0A= + rc =3D sit9531x_output_phase_read(sitdev, pin->id, &phase_ps,=0A= + &beyond);=0A= + if (rc && rc !=3D -ENODATA)=0A= + return false;=0A= + out->phase_none =3D rc =3D=3D -ENODATA;=0A= + if (!rc) {=0A= + out->phase_adj =3D phase_ps;=0A= + out->phase_armed =3D !beyond && phase_ps;=0A= + }=0A= + out->phase_stale =3D false;=0A= + }=0A= =0A= out->ntf_pending =3D false;=0A= =0A= diff --git a/drivers/dpll/sit9531x/prop.c b/drivers/dpll/sit9531x/prop.c=0A= index 15294d07b703..4f4d52dd284d 100644=0A= --- a/drivers/dpll/sit9531x/prop.c=0A= +++ b/drivers/dpll/sit9531x/prop.c=0A= @@ -188,6 +188,22 @@ sit9531x_pin_props_get(struct sit9531x_dev *sitdev,=0A= props->dpll_props.capabilities =3D=0A= DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;=0A= curr_freq =3D 0;=0A= +=0A= + /*=0A= + * The part takes a delay anywhere within the output period;=0A= + * +/-1 ms is a round figure within the s32 ps attribute.=0A= + */=0A= + props->dpll_props.phase_range.min =3D=0A= + -SIT9531X_OUT_PHASE_ADJ_MAX_PS;=0A= + props->dpll_props.phase_range.max =3D=0A= + SIT9531X_OUT_PHASE_ADJ_MAX_PS;=0A= + /*=0A= + * The delay grid is whole VCO cycles of the output's PLL plus=0A= + * 30 ps steps, so it depends on the PLL; a request in 1 ps=0A= + * units is programmed as the nearest grid point within the=0A= + * range, which is reported.=0A= + */=0A= + props->dpll_props.phase_gran =3D 1;=0A= }=0A= =0A= sit9531x_prop_pin_package_label_set(sitdev, props, dir, index);=0A= diff --git a/drivers/dpll/sit9531x/regs.h b/drivers/dpll/sit9531x/regs.h=0A= index 04723097d2b2..bd034abdf875 100644=0A= --- a/drivers/dpll/sit9531x/regs.h=0A= +++ b/drivers/dpll/sit9531x/regs.h=0A= @@ -151,6 +151,35 @@=0A= #define SIT9531X_DEBUG_UNLOCK_VAL 0xC3=0A= #define SIT9531X_DEBUG_LOCK_VAL 0x00=0A= =0A= +/*=0A= + * Per-output phase delay: 34-bit coarse in VCO cycles plus a 3-bit fine= =0A= + * field in 30 ps steps, in a five-byte block PROG6..PROG2:=0A= + *=0A= + * base + 0 PROG6 [7:5] OPSTG_VCASC_BUMP (preserve)=0A= + * [4:2] PRG_RST_FINE_DELAY[2:0]=0A= + * [1:0] PRG_RST_DELAY[33:32]=0A= + * base + 1..4 PROG5..PROG2 PRG_RST_DELAY[31:0], MSB first=0A= + *=0A= + * Block base is 0x15 + 16 * (slot % 6), slot from clkout_map[]; slots 0-5= =0A= + * on page 3, 6-11 on page 4.=0A= + */=0A= +#define SIT9531X_OUT_PRG_DELAY_BASE 0x15=0A= +#define SIT9531X_OUT_PRG_SLOT_STRIDE 0x10=0A= +#define SIT9531X_OUT_PRG_BYTES 5=0A= +#define SIT9531X_OUT_PRG_OPSTG_MASK 0xE0=0A= +#define SIT9531X_OUT_PRG_FINE_SHIFT 2=0A= +#define SIT9531X_OUT_PRG_FINE_MASK 0x1C /* bits [4:2] */=0A= +#define SIT9531X_OUT_PRG_COARSE_HI_MASK 0x03 /* bits [1:0] */=0A= +/*=0A= + * The divider takes two VCO cycles to act on a programmed delay; the enco= ded=0A= + * value includes them, as in the reference flow.=0A= + */=0A= +#define SIT9531X_OUT_PRG_DIVO_CYCLES 2=0A= +=0A= +#define SIT9531X_OUT_PRG_FINE_STEP_PS 30=0A= +#define SIT9531X_OUT_PRG_FINE_MAX 7 /* 3-bit field */=0A= +#define SIT9531X_OUT_PRG_COARSE_BITS 34=0A= +=0A= /*=0A= * Register-triggered phase flush: DIVO_PHASE_SEL_REG selects the register= =0A= * trigger; pulsing DIVO_PHASE_TRIG high then low flushes. Preserve the OE= b=0A= -- =0A= 2.39.2 (Apple Git-143)=0A= =0A=