Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=67.231.154.164 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796169142; b=qb4/Q/yWn1VqTD2x9s+LerQaL5k3cZRPVbYZhjoYpLPuXsHbZysVMxTniSMyBeVtzlcH b/BkfhAe2Lrbrf38HDqtlxL6GIEwDEaa6e5u4eLX9tCAQ11L5RqUS9pPkNWQvE0QmDkxj QatW9dmEZST3zpN5lN1OAJDuzrk6YapvYDNvbTqeYpsQ6txAtCM73uBfXr7Q0zfKUA0vN afXSXiURQMSaq9zfitmAjyBN/O3Hl+tMbvPPQr5Rwkta13Ox1RDadeT+9y8e0N/94ACE+ BKbS5P/yMonYnbfbVzf03UgFeZAgzeBcrW9RiyYmjXKUsip0lgoe6+W8btGluDemdzg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796169142; 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=vfog7arn56ZXRpON5ErW/Gl2NUqa9bm8s2u+0nILZKo=; b=wjM1hbJwW7Xh3Rd9EcU4IF/ihiezhiotqTNOy2WIK9yKwlWybGTsFYx5n0x9RbgZxwN9 aOxP3GkZrRWSP2A7qyaxzNoCkLmsHZsi9Ri4dJMJ01mAf3GFq2vYAHqzjvHNOuU8zvenM mzkk++If0U0VQZnh1WTrxcRXQSNtw/BHWIXn2is6DNM1WD2udEyvdu3nChgZOfUjXFksB tGfD5gSw1cCJmHSGCURO0gs1tKcEbn3qZqidVGlyLA0uBI1AeyRNsd9R20rQwr56HrKfN 2C7QZM3fiNqFp2qei23ZwjkPTN0ZjonAuhdop+SF5womRtvgswn7ItabeXNZbm+QUYQ== 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=O6PlsU6D; dkim=pass header.d=Sitime.onmicrosoft.com header.i=@Sitime.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-Sitime-onmicrosoft-com header.b=CVDbrUOc; arc=pass header.oldest-pass=0 smtp.remote-ip=67.231.154.164 Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [67.231.154.164]) (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 0169A606BAE1; Tue, 1 Dec 2026 23:52:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0169A606BAE1 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=O6PlsU6D; 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=CVDbrUOc 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=vfog7arn56ZXRpON5ErW/Gl2NUqa9bm8s2u+0nILZKo=; b=O6PlsU6DQnkmg7YWHvJ9OzPEqxk19VltaoxSmMxa8Im4C/OcW6FKU00BUifWzQW4UbDr/+YjtitOxTrZCIV8fjZsAEDEdlJiC4v7llnChJugAsmZIN6kNpZ1K0WQEH+H1+/iN6KOo54M0XbHf0iT327ftymEaIbtMtTY57EVc5DBcxR/HJYIbNraDWFjp8nwjIROfjinrOcBc9yYu7nL9khPUOVbjApd+wvOPM0sAbrnyv5HzMGA5luaA5KNnwcTX+sNLlLelcqXo7cQ+KXEEXJm6ZdvHue54L5+2M7Tq8bmrRp2RyKx5m96ihWKMit5tsWb848gCMwt8zK1K6A+JA== X-Virus-Scanned: Proofpoint Essentials engine Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11020129.outbound.protection.outlook.com [52.101.201.129]) (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 D426E24006D; Tue, 1 Dec 2026 23:52:18 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Y7RqPk1+L4qJvo4PGHIULEZI+kKJUT8EER3KN1uCCroPdxQRzfkGmFDJozzGMjpbpjRgm3JLevSe8ioYBkX59cZ34FuLBQSIB/hTpmaQrV0KDjuFcHCuiLU29vSjVRqQxHdzOO52kYGMj1NI+47cAGxVX73CVZVpbHSlW/pCH9CptEFYBjte2Us5ZAebReb/dPxa6Nzo9+aSiy9tKzRGVGDRahp+FFm+8GRu3oBDyHsQWqdUQt0DMWcT8VaeQfsP4GDylso4f/k1wu7uzsWPjSRT9YRrBP3jokdPgszq0J6tDKrpP8tXFVMRiM/5b9ULDHEfoezmEbWDZRIlyaAMJw== 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=vfog7arn56ZXRpON5ErW/Gl2NUqa9bm8s2u+0nILZKo=; b=PCE5nMbbnrxU6nVML24skTQPRPbR6SE3WjePL5OqmfFYKDFzfD4j4r0jh40Bfg4QcDCJlyDamzbEZjCl4HLaqrNVAlfFGj55QI/kew0hVFphM0JKa0Y3RkdVYSJ+Rn42hmoQt+xKoXXWUh741Cx1TC/cNQqGKVvNOXHlHNeCV74WRWBNx5Oszp5dsIlGW9L2UYZUGFl+45UhDeKx2QM0XtBCFg0jmvhE0C7V9zmHlww2YgVKNFQ6XJSfH64EOhbOIba4F30WerDv/enoUR3A9f8TwR5VItuI2mqJeqMmN8yJu0bpi5h9iqnseHf95ZH/t7ZbswiXIZX9TNPYLojksQ== 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=vfog7arn56ZXRpON5ErW/Gl2NUqa9bm8s2u+0nILZKo=; b=CVDbrUOcdWQTDf4yJURB14nDea9nCKKiw0IBpMBh3U4Jf51W9WzmMXwQpNb9Oj45cObkdODGEdQPK7suINma1T9vola/hLeJGe2rJcKCx/xpujhkshBk2iQEfYEevkjYP3OACtCKiG7k9w/8ovwyCvJyKandGH3hWZ7zrTl5GctIASCb44xAMAQPkJcYarpo8XUgucv8ORu5fC/dQqWm0PiMmHteVuy0D54km/zu6eDKMXhMpGZFA/t//vnrSvjNxBikDQv3IlxxPUfHMQ/FYJZtcyVY3lyIinMzkiovqNTg4lbJiILTZcJZrwD9Y4iyKTQVlW6K+o64vrZFT1Sk9A== 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:15 +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:15 +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 07/13] dpll: sit9531x: implement input pin state on a DPLL Thread-Topic: [PATCH net-next v17 07/13] dpll: sit9531x: implement input pin state on a DPLL Thread-Index: AQHdge74Je8ZjEY8MEO3SOCvCP9oDA== Date: Tue, 1 Dec 2026 23:52:06 +0000 Message-ID: <20261201235202.97645-8-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: e8985bca-e828-42b7-81ee-08df5006206d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230040|376014|1800799024|23010399003|366016|38070700021|10067099003|56012099006|5023799004|261026135527099003|261022075727099003|261026121527099003|261022115727099003|261021123027099003|261026130827099003|261021135927099003|261022113327099003|261021121427099003|261026140227099003|261022105027099003|261021130227099003|261028144727099003|261102123227099003|261021133027099003|261009223027099003|22082099003|18002099003|6133799003|3023799007; x-microsoft-antispam-message-info: f4rPvWCqKAPJSKT+o2/Pj0eGyZa+TtcWJL7XlDx9KMW67f+jO+f4XJiUcWXOoxbe6uMSp8yA0eHnXhCF7nl/zgtgWlFkskF+T8W9TP+Pb05Z/+BvGYyzSvYkiFKpqq33S4PsZkJcBdDaGDRLAZeVboc5lt7gDYy/iogcdtwXQ5hYAXKapdXRCBzhjl8fT7EVjgsM+tb0yegJCRbdOAtKHWVq92heVpY1AKuti3oITNULz8Zqo82qCxr37vjlCRUh8cQPjz8SNLbZ5KWKLzIKR37dXqGsMeF2H13fG3O9JMTcnTnVAIICfeEiBFEgiyknbfLfctOTojSPT5QMeGCVH43vqR4SH0AJzWhfNFIiH/I+73COj6fX4VqT+e4t7bIZrhmjTOtMa+PGqu8195zintE9wrVQ1noFxQu/iA72hCFIgHJ0amQHXsgaFbGuIE7JjGtvbuanDQOB8YNlfgZ0ZIS5gHYURlh8tspy7r8XPiTW0QsthxagtGRQR5/D7Csd2sMK0g678MYHCHTD6k/joFtBaXW1dR7g+5ZfeQkTghhSzw4GsRjo9gI7H2WM8cuTnT+HAT4Cb8ZCgfKxFaWAoFLwCpksQ2JwsjkmSI5/GMz9tAORiORXnPhshdOEPoTET6IjcjQddp3zjyVDREhYGqhcbH72/+jOcPo0FhgFtdCGLm0EhcRYCFQwcRpD0m2sN+TMdE+8njIwKOvC69I0q3W61U4jGrRjVeZCQv3RYKo= 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)(56012099006)(5023799004)(261026135527099003)(261022075727099003)(261026121527099003)(261022115727099003)(261021123027099003)(261026130827099003)(261021135927099003)(261022113327099003)(261021121427099003)(261026140227099003)(261022105027099003)(261021130227099003)(261028144727099003)(261102123227099003)(261021133027099003)(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?dd3B7XbMOvcMAWcGXXQxgcUiUVsOV45GxEH0e2YmJvWlrlZhBOvUs+iRJ+?= =?iso-8859-1?Q?Go+Yc+MY0wdxTYUJmNbzFv4ObNU5TeSMI9U2dAh2AcLdablztE+f/d6UWS?= =?iso-8859-1?Q?RvTj67Xf37rGpn0IYYxnLWjiCw2584EphRKO/YgksGAAC0zZ//jNLF4obE?= =?iso-8859-1?Q?Wbtw2SIqpNaF+olviLpGB0WzWzx34Jbrb6p8TS3MnRpcO0jimTJ7MeVHxJ?= =?iso-8859-1?Q?K866BwYciaodHn9CWKrkUw4kbP1K/0rfYr3u6O5GJJYbAH4ketztaKoO8p?= =?iso-8859-1?Q?zZIqIuEAp0orPMPJcoh41+lnEHg0mYGSBchJ3yMAjPYLeRMcAEsp5hHEan?= =?iso-8859-1?Q?AkP8D192JQBvA4ZUlh/bxkE8zRrI0qjmYdHc76P/MRZK0t1sZPIATZWBVs?= =?iso-8859-1?Q?uppxkYMuiKM4ozbjKO0Lep3bbyPJUB6bHuOLtnJKRxKu3fwRTs56mdZ/UV?= =?iso-8859-1?Q?tKQc/ZlyYuu3eRZJas9nEofItCdjMZeafBllVEmww4TgHhZiXqyMy14uR0?= =?iso-8859-1?Q?c5dUOVGwfSZRvhRH1jpboNQu5JpOd5N0f+WG7UqP3X3OQeYUVYCua7H8Mt?= =?iso-8859-1?Q?4WD3XYoE/AEuBAjWnzNRH4MrvXuaxD3eVAO2vyzoI/DPvAkdMMD4g6cc6L?= =?iso-8859-1?Q?KEw8YCMlW34pl+0aovoL+1IqWfWkaDU4RAsI4XhvPsFIy+ksocQEkACWen?= =?iso-8859-1?Q?BEQUGEXwWj5EODsX+lNu+zoYgOCvu/9ltbtcYlxwlUoIfTouLNiYCU60Ge?= =?iso-8859-1?Q?Vv6lMUMAMEDusbk2WnlwD1Q1tmFwZVUaXR/qgsKWV5PWVZ7Efd1Y32m1mX?= =?iso-8859-1?Q?C4KZDLBlfgR+TYZcsu+ny34aYx5V/H5Z/TQCtEkNJeXqIR+MBL330jonnN?= =?iso-8859-1?Q?7BAboLnTiK5XAPIORbEIJOa/SPLoVUEj0tU6S64B2yrDwl3JlR9vULjz5D?= =?iso-8859-1?Q?xxGy9dADUNZQSZP1LVWwGbYtMZbQg/fdLDUklAp8YqDNb+yzXTRRI4nsph?= =?iso-8859-1?Q?n4tONtygl95dl1rMeMUbG/xo7hRkK9LohKz+qjzQ0v0PBuM5Cmmb9dS7eD?= =?iso-8859-1?Q?KS3wInMA6zv0FJ+RPzio31dmA2927jBo1yBx52NqvRYlyhnecKx71uls3U?= =?iso-8859-1?Q?PVRjqmmwDvIBn7ZQupCWud4RjxBA+SnCa6HlduDNoO342i7uMgizEyeWAJ?= =?iso-8859-1?Q?8JwsONH3ZcpS2PJBeaqXItugJlkG5eLXOR1dcxaZ0B9deXlgKXRR7L7f9D?= =?iso-8859-1?Q?1l3uJQxw8R1IEMS7Op5A+k9XLO+X4jrhi5obFr18nPTBaCWbZ93zgub6VE?= =?iso-8859-1?Q?GywVwNeK85mC1ZIKmofYAfVpgybmE+xNzgw4D7E/yZhFhxq43pM0M/Furb?= =?iso-8859-1?Q?jUMHFkboxwFlqlPNRDmDKtUbXxaAtFFGcWfzjJ+A44imXm1CpTCpSKYxD6?= =?iso-8859-1?Q?qWbWtgyUvWhgmVXxrt1Lg6oXzCAaSLoeG9FFOnvf4ftKQ9jcUItBrkf1BE?= =?iso-8859-1?Q?cGPz3R0bailThYbGgXWVXRx5i5Z+VCzH3BWxFiYP18tElOKBkvJQgVnmYT?= =?iso-8859-1?Q?xlAJVCbTyPiW74r/KIHl/ytewHlkEet+DBusltw4/Kqo66ucIfNQpISLAg?= =?iso-8859-1?Q?tiO32CC4qUCYaTopMBtKYAJ7SHp1CfH8LiBL9lMv24a1NyFgDSeuWtfILH?= =?iso-8859-1?Q?AbO68mEVaX3Inl66belnYbXHlGxxov2TPSfoNDT4muqfLteEsrweSdz9m2?= =?iso-8859-1?Q?bgTUVQkhJrmogji0vMJdV5zmtWhHM8Rt74hIRRndelxWhP?= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-Exchange-RoutingPolicyChecked: c+JTBXLAgCINq4CSONkGuRQnjwJ3UPm+Pl97bZBv03/sIMHwSaAzK7xvOmQKA/guMtLifev8I+sxQTY30oAouecIqlY2uNl/cmn+S7BvNTxn9Zt2ZMd8YgQQMAfKfkWteVuI4x6vlm4hHNDik6ol1MGv1gG7tigFEQ5Tsk8LnKPEyHQvoU5nwlhyoOHh2qgyA+7tiknZQ+iMEMIdIq3Et+uL+F3dOLGkC4jxX5kcP9CCUDjQULsv0ITxbL8Rehs5tjJvuAS1kX8zNJxCnl4Rd/OanlXtFDyDKl2+hl8FXXQ868w9lCbLY80cGvmFljW5+DJrMy7mppp1Adh/f6IXAg== 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: e8985bca-e828-42b7-81ee-08df5006206d X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Dec 2026 23:52:06.1921 (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: hZRMmgwZhGPUGmfDQdpMyYTZz/9o/Jpu17QjpT8jF6lfnMDBThTSg5/ctsEeizN9DOzNrbAyxWFssmYeW2VBJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR20MB6330 X-MDID: 1796169139-YnBCwVlvv4-P X-PPE-STACK: {"stack":"us1"} X-MDID-O: us1;at1;1796169139;YnBCwVlvv4-P;;ba04557de9d2da8490f5f1e6de07b967 X-PPE-TRUSTED: V=1;DIR=OUT; From: Oleg Zadorozhnyi =0A= =0A= Report and set whether an input takes part in a PLL's reference=0A= selection. The PLL picks its reference from a priority table: an input=0A= in the table is SELECTABLE, one absent is DISCONNECTED, and setting the=0A= state adds or removes it. CONNECTED is refused: the PLL selects by=0A= priority. On manual input select the selected input is CONNECTED and=0A= requests are refused.=0A= =0A= A table write uses the documented procedure: force holdover, write the=0A= slots and the active selection, latch with a small update, release. A=0A= PLL whose table is emptied stays in forced holdover.=0A= =0A= A receiver, shared by the PLLs and by both lanes of a pair, is powered=0A= down while no PLL may select its input; SELECTABLE gives it back to the=0A= loaded configuration, and one it keeps off stays off.=0A= =0A= The poll re-selects a PLL in holdover while a listed source has signal:=0A= after probe and resume, when it finds frozen a PLL that tracked a=0A= reference, and after 10 s frozen. It backs off to eight periods while=0A= the part gives no answer and rate-limits warnings. Probe warns of a pin=0A= node naming no pin. The debug status register is marked precious: each=0A= read advances its latch.=0A= =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 | 1325 ++++++++++++++++++++++++++++++++--=0A= drivers/dpll/sit9531x/core.h | 121 +++-=0A= drivers/dpll/sit9531x/dpll.c | 301 +++++++-=0A= drivers/dpll/sit9531x/dpll.h | 2 +=0A= drivers/dpll/sit9531x/prop.c | 20 +-=0A= drivers/dpll/sit9531x/regs.h | 59 +-=0A= 6 files changed, 1750 insertions(+), 78 deletions(-)=0A= =0A= diff --git a/drivers/dpll/sit9531x/core.c b/drivers/dpll/sit9531x/core.c=0A= index 4ff9e251eb77..d0305cbf12d5 100644=0A= --- a/drivers/dpll/sit9531x/core.c=0A= +++ b/drivers/dpll/sit9531x/core.c=0A= @@ -62,10 +62,21 @@ static const struct sit9531x_chip_info sit9531x_chip_id= s[] =3D {=0A= * One 256-register page is visible at a time, selected by offset 0xFF on = every=0A= * page. The map covers that window, uncached; the accessors select the pa= ge.=0A= */=0A= +/*=0A= + * Each read of the debug status data register advances the status bus lat= ch;=0A= + * marking it precious stops a debugfs dump from reading it.=0A= + */=0A= +static bool sit9531x_precious_reg(struct device *dev __maybe_unused,=0A= + unsigned int reg)=0A= +{=0A= + return reg =3D=3D SIT9531X_PLL_REG_DBG_STATUS_DATA;=0A= +}=0A= +=0A= static const struct regmap_config sit9531x_regmap_config =3D {=0A= .reg_bits =3D 8,=0A= .val_bits =3D 8,=0A= .max_register =3D SIT9531X_PAGE_SEL,=0A= + .precious_reg =3D sit9531x_precious_reg,=0A= .cache_type =3D REGCACHE_NONE,=0A= };=0A= =0A= @@ -175,6 +186,66 @@ int sit9531x_read_pll_u8(struct sit9531x_dev *sitdev, = u8 pll_idx,=0A= return sit9531x_read_u8(sitdev, SIT9531X_REG(page, offset), val);=0A= }=0A= =0A= +int sit9531x_write_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,=0A= + u8 offset, u8 val)=0A= +{=0A= + u8 page =3D sit9531x_pll_page(pll_idx);=0A= +=0A= + return sit9531x_write_u8(sitdev, SIT9531X_REG(page, offset), val);=0A= +}=0A= +=0A= +int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,=0A= + u8 offset, u8 mask, u8 val)=0A= +{=0A= + u8 page =3D sit9531x_pll_page(pll_idx);=0A= + unsigned int reg =3D SIT9531X_REG(page, offset);=0A= + unsigned int orig, tmp;=0A= + int rc;=0A= +=0A= + mutex_lock(&sitdev->page_lock);=0A= + rc =3D sit9531x_read_locked(sitdev, reg, &orig);=0A= + if (!rc) {=0A= + tmp =3D (orig & ~mask) | (val & mask);=0A= + if (tmp !=3D orig)=0A= + rc =3D sit9531x_write_locked(sitdev, reg, tmp);=0A= + }=0A= + mutex_unlock(&sitdev->page_lock);=0A= + if (rc)=0A= + dev_err_ratelimited(sitdev->dev,=0A= + "Failed to update page 0x%02x reg 0x%02x: %d\n",=0A= + page, offset, rc);=0A= +=0A= + return rc;=0A= +}=0A= +=0A= +#define SIT9531X_CLOSE_TRIES 3=0A= +=0A= +/* Write a register, retrying on failure */=0A= +static int sit9531x_write_close(struct sit9531x_dev *sitdev, unsigned int = reg,=0A= + 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_write_u8(sitdev, reg, val);=0A= + if (!rc)=0A= + break;=0A= + }=0A= +=0A= + return rc;=0A= +}=0A= +=0A= +static int sit9531x_write_pll_close(struct sit9531x_dev *sitdev, u8 pll_id= x,=0A= + u8 offset, u8 val)=0A= +{=0A= + return sit9531x_write_close(sitdev,=0A= + SIT9531X_REG(sit9531x_pll_page(pll_idx),=0A= + offset), val);=0A= +}=0A= +=0A= static void sit9531x_input_get_regs(const struct sit9531x_dev *sitdev,=0A= u8 index,=0A= unsigned int *force_reg,=0A= @@ -192,6 +263,75 @@ static void sit9531x_input_get_regs(const struct sit95= 31x_dev *sitdev,=0A= }=0A= }=0A= =0A= +/* Caller must hold sitdev->multiop_lock. */=0A= +int sit9531x_input_disable(struct sit9531x_dev *sitdev, u8 index)=0A= +{=0A= + unsigned int force_reg, state_reg;=0A= + struct sit9531x_ref *ref;=0A= + u8 pair, val;=0A= + int rc;=0A= +=0A= + lockdep_assert_held(&sitdev->multiop_lock);=0A= +=0A= + if (index >=3D SIT9531X_MAX_INPUTS)=0A= + return -EINVAL;=0A= +=0A= + ref =3D &sitdev->ref[index];=0A= + pair =3D sit9531x_input_pair(index);=0A= + sit9531x_input_get_regs(sitdev, index, &force_reg, &state_reg);=0A= +=0A= + /*=0A= + * STATE before FORCE: the override applies the STATE bit as it is, so=0A= + * FORCE is written only once STATE is clear.=0A= + */=0A= + rc =3D sit9531x_read_u8(sitdev, state_reg, &val);=0A= + if (!rc)=0A= + rc =3D sit9531x_write_u8(sitdev, state_reg, val & ~BIT(pair));=0A= + if (!rc)=0A= + rc =3D sit9531x_read_u8(sitdev, force_reg, &val);=0A= + if (!rc)=0A= + rc =3D sit9531x_write_u8(sitdev, force_reg, val | BIT(pair));=0A= +=0A= + ref->enabled =3D false;=0A= + ref->off_pending =3D rc !=3D 0;=0A= +=0A= + return rc;=0A= +}=0A= +=0A= +/*=0A= + * Release the force so the lane uses the loaded configuration, as the=0A= + * input_enable() of input_dsable_control.py does; a receiver the configur= ation=0A= + * keeps off stays off. Caller must hold sitdev->multiop_lock.=0A= + */=0A= +int sit9531x_input_enable(struct sit9531x_dev *sitdev, u8 index)=0A= +{=0A= + unsigned int force_reg, state_reg;=0A= + struct sit9531x_ref *ref;=0A= + u8 pair, val;=0A= + int rc;=0A= +=0A= + lockdep_assert_held(&sitdev->multiop_lock);=0A= +=0A= + if (index >=3D SIT9531X_MAX_INPUTS)=0A= + return -EINVAL;=0A= +=0A= + ref =3D &sitdev->ref[index];=0A= + pair =3D sit9531x_input_pair(index);=0A= + sit9531x_input_get_regs(sitdev, index, &force_reg, &state_reg);=0A= +=0A= + rc =3D sit9531x_read_u8(sitdev, force_reg, &val);=0A= + if (rc)=0A= + return rc;=0A= + rc =3D sit9531x_write_u8(sitdev, force_reg, val & ~BIT(pair));=0A= + if (rc)=0A= + return rc;=0A= +=0A= + ref->enabled =3D true;=0A= + ref->off_pending =3D false;=0A= +=0A= + return 0;=0A= +}=0A= +=0A= /*=0A= * Output Hi-Z control: each slot has three force/state pairs on Page 0x03= ,=0A= * for the differential path and the CMOS OutP and OutN pads. The tri-stat= e=0A= @@ -323,6 +463,16 @@ static int sit9531x_output_forced_hiz(struct sit9531x_= dev *sitdev,=0A= return 0;=0A= }=0A= =0A= +/*=0A= + * Procedure:=0A= + * 1. Force PLL into holdover (PLL page reg 0x6F bit 4)=0A= + * 2. Write priority slots on Page 1=0A= + * 3. Small change update (Page 0 reg 0x0F bit 1)=0A= + * 4. Release holdover, unless something other than this driver forced i= t=0A= + *=0A= + * Caller must hold sitdev->multiop_lock.=0A= + */=0A= +=0A= static u16 sit9531x_prio_reg(u8 pll_idx, u8 slot)=0A= {=0A= return SIT9531X_REG(SIT9531X_PAGE_PRIOSYS,=0A= @@ -340,39 +490,607 @@ static u8 sit9531x_prio_slot_get(u8 val, u8 slot)=0A= return val >> SIT9531X_PRIO_HI_SHIFT;=0A= }=0A= =0A= +static u8 sit9531x_prio_slot_set(u8 val, u8 slot, u8 src)=0A= +{=0A= + if (slot & 1)=0A= + return (val & (SIT9531X_PRIO_NIBBLE_MASK <<=0A= + SIT9531X_PRIO_HI_SHIFT)) |=0A= + (src & SIT9531X_PRIO_NIBBLE_MASK);=0A= +=0A= + return (val & SIT9531X_PRIO_NIBBLE_MASK) |=0A= + ((src & SIT9531X_PRIO_NIBBLE_MASK) <<=0A= + SIT9531X_PRIO_HI_SHIFT);=0A= +}=0A= +=0A= +/*=0A= + * Latch a priority table with a small change update, as in the documented= =0A= + * input_priority_sel() procedure.=0A= + */=0A= +static int sit9531x_prio_prg_commit(struct sit9531x_dev *sitdev)=0A= +{=0A= + int rc;=0A= +=0A= + rc =3D sit9531x_write_close(sitdev, SIT9531X_REG_GLOBAL_UPDATE,=0A= + SIT9531X_SMALL_UPDATE_CMD);=0A= + if (rc)=0A= + return rc;=0A= +=0A= + usleep_range(1000, 2000);=0A= +=0A= + return 0;=0A= +}=0A= +=0A= +/*=0A= + * Four registers carry a nibble per lane: loss of signal and the fine and= =0A= + * coarse frequency-drift flags. Caller must hold sitdev->multiop_lock, or= run=0A= + * before registration.=0A= + */=0A= +static int sit9531x_input_mon_fetch(struct sit9531x_dev *sitdev)=0A= +{=0A= + static const unsigned int regs[] =3D {=0A= + SIT9531X_CLKMON_P_STATUS_01, SIT9531X_CLKMON_P_STATUS_23,=0A= + SIT9531X_CLKMON_N_STATUS_01, SIT9531X_CLKMON_N_STATUS_23,=0A= + };=0A= + u8 val[ARRAY_SIZE(regs)], i, pair, nib;=0A= + int rc;=0A= +=0A= + for (i =3D 0; i < ARRAY_SIZE(regs); i++) {=0A= + rc =3D sit9531x_read_u8(sitdev, regs[i], &val[i]);=0A= + if (rc)=0A= + return rc;=0A= + }=0A= +=0A= + for (i =3D 0; i < sitdev->info->num_inputs && i < SIT9531X_MAX_INPUTS;=0A= + i++) {=0A= + struct sit9531x_ref *ref =3D &sitdev->ref[i];=0A= +=0A= + /* Lane 2k is INkP, 2k + 1 INkN; a register holds two pairs. */=0A= + pair =3D sit9531x_input_pair(i);=0A= + nib =3D val[(sit9531x_input_is_n(i) ? 2 : 0) + pair / 2];=0A= + nib =3D (pair & 1) ? nib >> 4 : nib & 0x0F;=0A= +=0A= + ref->los =3D !!(nib & SIT9531X_CLKMON_LOSS);=0A= + ref->qual_fail =3D !ref->los &&=0A= + !!(nib & (SIT9531X_CLKMON_FINE_DRIFT |=0A= + SIT9531X_CLKMON_COARSE_DRIFT));=0A= + }=0A= +=0A= + return 0;=0A= +}=0A= +=0A= +/*=0A= + * Check if the device can lock to @src now; a differential pair is watche= d=0A= + * through its P lane.=0A= + */=0A= +static bool sit9531x_prio_src_live(const struct sit9531x_dev *sitdev, u8 s= rc)=0A= +{=0A= + u8 index =3D sit9531x_hw_src_input(src);=0A= +=0A= + if (index >=3D sitdev->info->num_inputs)=0A= + return true;=0A= +=0A= + return !sitdev->ref[index].los;=0A= +}=0A= +=0A= +/*=0A= + * Map an N-lane source of a differential pair to its P lane, the lane its= DPLL=0A= + * pin represents.=0A= + */=0A= +static u8 sit9531x_prio_src_canon(const struct sit9531x_dev *sitdev, u8 sr= c)=0A= +{=0A= + u8 index =3D sit9531x_hw_src_input(src);=0A= +=0A= + if (index >=3D sitdev->info->num_inputs)=0A= + return src;=0A= +=0A= + if (sit9531x_input_is_n(index) &&=0A= + sitdev->ref[index].sig_mode =3D=3D SIT9531X_MODE_DE)=0A= + return sit9531x_input_hw_src(index - 1);=0A= +=0A= + return src;=0A= +}=0A= +=0A= +/*=0A= + * @input_idx is in hardware encoding (see sit9531x_input_hw_src()). Calle= r must=0A= + * hold sitdev->multiop_lock.=0A= + */=0A= +bool sit9531x_input_prio_present(struct sit9531x_dev *sitdev, u8 pll_idx,= =0A= + u8 input_idx)=0A= +{=0A= + lockdep_assert_held(&sitdev->multiop_lock);=0A= +=0A= + if (pll_idx >=3D SIT9531X_NUM_PLLS)=0A= + return false;=0A= +=0A= + input_idx =3D sit9531x_prio_src_canon(sitdev, input_idx);=0A= + if (input_idx >=3D SIT9531X_PRIO_NUM_SRC)=0A= + return false;=0A= +=0A= + return !!(sitdev->chan[pll_idx].prio_mask & BIT(input_idx));=0A= +}=0A= +=0A= +/*=0A= + * Take the configured priorities from the hardware table: a listed source= gets=0A= + * the first slot it occupies.=0A= + */=0A= +static void sit9531x_prio_cfg_seed(struct sit9531x_dev *sitdev, u8 pll_idx= ,=0A= + const u8 *srcs)=0A= +{=0A= + struct sit9531x_chan *chan =3D &sitdev->chan[pll_idx];=0A= + u16 seeded =3D 0;=0A= + u8 slot, src;=0A= +=0A= + for (slot =3D 0; slot < SIT9531X_PRIO_MAX_SLOTS; slot++) {=0A= + src =3D srcs[slot] & SIT9531X_PRIO_NIBBLE_MASK;=0A= + if (!sit9531x_prio_src_usable(src))=0A= + continue;=0A= + src =3D sit9531x_prio_src_canon(sitdev, src);=0A= + if (seeded & BIT(src))=0A= + continue;=0A= + seeded |=3D BIT(src);=0A= + chan->cfg_prio[src] =3D slot;=0A= + chan->cfg_known |=3D BIT(src);=0A= + }=0A= +=0A= + for (src =3D 0; src < SIT9531X_PRIO_NUM_SRC; src++) {=0A= + if (chan->cfg_known & BIT(src))=0A= + continue;=0A= + chan->cfg_prio[src] =3D SIT9531X_PRIO_MAX_SLOTS - 1;=0A= + chan->cfg_known |=3D BIT(src);=0A= + }=0A= +=0A= + memcpy(chan->seen_srcs, srcs, sizeof(chan->seen_srcs));=0A= + chan->seen_valid =3D true;=0A= +}=0A= +=0A= +/* Order the members by configured priority */=0A= +static void sit9531x_prio_table_build(struct sit9531x_dev *sitdev, u8 pll_= idx,=0A= + u16 members, u8 *srcs)=0A= +{=0A= + const struct sit9531x_chan *chan =3D &sitdev->chan[pll_idx];=0A= + u8 order[SIT9531X_PRIO_NUM_SRC], n =3D 0, i, j, src;=0A= +=0A= + for (src =3D 0; src < SIT9531X_PRIO_NUM_SRC; src++)=0A= + if (members & BIT(src))=0A= + order[n++] =3D src;=0A= +=0A= + for (i =3D 1; i < n; i++) {=0A= + u8 cur =3D order[i];=0A= +=0A= + for (j =3D i; j > 0; j--) {=0A= + u8 prev =3D order[j - 1];=0A= + u16 kc, kp;=0A= +=0A= + kc =3D (chan->cfg_known & BIT(cur)) ?=0A= + chan->cfg_prio[cur] : U8_MAX;=0A= + kp =3D (chan->cfg_known & BIT(prev)) ?=0A= + chan->cfg_prio[prev] : U8_MAX;=0A= + if (kc =3D=3D kp) {=0A= + /* Keep the hardware order among equals. */=0A= + kc =3D chan->prio_last[cur] ?: U8_MAX;=0A= + kp =3D chan->prio_last[prev] ?: U8_MAX;=0A= + }=0A= + if (kp <=3D kc)=0A= + break;=0A= + order[j] =3D prev;=0A= + }=0A= + order[j] =3D cur;=0A= + }=0A= +=0A= + /* A source keeps the lane code the table last listed it by. */=0A= + for (i =3D 0; i < SIT9531X_PRIO_MAX_SLOTS; i++) {=0A= + if (i >=3D n)=0A= + srcs[i] =3D SIT9531X_PRIO_SRC_NONE;=0A= + else if (chan->lane_known & BIT(order[i]))=0A= + srcs[i] =3D chan->lane_code[order[i]];=0A= + else=0A= + srcs[i] =3D order[i];=0A= + }=0A= +}=0A= +=0A= +/*=0A= + * Refresh the cached membership mask, per-slot copy and first-slot array = of a=0A= + * PLL's priority table.=0A= + */=0A= static void sit9531x_prio_mask_build(struct sit9531x_dev *sitdev, u8 pll_i= dx,=0A= const u8 *srcs)=0A= {=0A= + struct sit9531x_chan *chan =3D &sitdev->chan[pll_idx];=0A= + u8 first[SIT9531X_PRIO_NUM_SRC] =3D { 0 };=0A= + u8 slot, src, src_canon;=0A= u16 mask =3D 0;=0A= - u8 slot;=0A= =0A= for (slot =3D 0; slot < SIT9531X_PRIO_MAX_SLOTS; slot++) {=0A= - u8 src =3D srcs[slot] & SIT9531X_PRIO_NIBBLE_MASK;=0A= + src =3D srcs[slot];=0A= + src &=3D SIT9531X_PRIO_NIBBLE_MASK;=0A= + chan->prio_srcs[slot] =3D src;=0A= + src_canon =3D sit9531x_prio_src_canon(sitdev, src);=0A= + if (!sit9531x_prio_src_usable(src))=0A= + continue;=0A= +=0A= + mask |=3D BIT(src_canon);=0A= + if (!first[src_canon]) {=0A= + first[src_canon] =3D slot + 1;=0A= + chan->lane_code[src_canon] =3D src;=0A= + chan->lane_known |=3D BIT(src_canon);=0A= + }=0A= + }=0A= +=0A= + for (src =3D 0; src < SIT9531X_PRIO_NUM_SRC; src++)=0A= + chan->prio_last[src] =3D first[src];=0A= +=0A= + chan->prio_mask =3D mask;=0A= +}=0A= +=0A= +#define SIT9531X_HO_CLEAR_TRIES 3=0A= +=0A= +static int sit9531x_prio_table_read(struct sit9531x_dev *sitdev, u8 pll_id= x,=0A= + u8 *srcs);=0A= +static int sit9531x_chan_state_fetch(struct sit9531x_dev *sitdev, u8 pll_i= dx);=0A= +=0A= +static u8 sit9531x_prio_top_live(const struct sit9531x_dev *sitdev,=0A= + const u8 *srcs)=0A= +{=0A= + u8 i, src;=0A= +=0A= + for (i =3D 0; i < SIT9531X_PRIO_MAX_SLOTS; i++) {=0A= + src =3D srcs[i] & SIT9531X_PRIO_NIBBLE_MASK;=0A= + src =3D sit9531x_prio_src_canon(sitdev, src);=0A= + if (sit9531x_prio_src_usable(src) &&=0A= + sit9531x_prio_src_live(sitdev, src))=0A= + return src;=0A= + }=0A= +=0A= + return SIT9531X_PRIO_SRC_NONE;=0A= +}=0A= +=0A= +/*=0A= + * Return the code by which a table lists a canonical source, or=0A= + * SIT9531X_PRIO_SRC_NONE. A differential pair may be listed by its N-lane= code.=0A= + */=0A= +static u8 sit9531x_prio_table_code(const struct sit9531x_dev *sitdev,=0A= + const u8 *srcs, u8 canon)=0A= +{=0A= + u8 i, src;=0A= +=0A= + for (i =3D 0; i < SIT9531X_PRIO_MAX_SLOTS; i++) {=0A= + src =3D srcs[i] & SIT9531X_PRIO_NIBBLE_MASK;=0A= + if (sit9531x_prio_src_usable(src) &&=0A= + sit9531x_prio_src_canon(sitdev, src) =3D=3D canon)=0A= + return src;=0A= + }=0A= =0A= - if (sit9531x_prio_src_usable(src))=0A= - mask |=3D BIT(src);=0A= + return SIT9531X_PRIO_SRC_NONE;=0A= +}=0A= +=0A= +/*=0A= + * Pick the active selection to latch. The PLL keeps the selected source= =0A= + * unless the best live source changed; an @idle PLL, found without a=0A= + * reference by the poll, takes the best live source. The pick is the code= =0A= + * the table lists the source by.=0A= + */=0A= +static u8 sit9531x_prio_activesel_pick(struct sit9531x_dev *sitdev,=0A= + const u8 *old, const u8 *srcs, u8 cur,=0A= + bool idle)=0A= +{=0A= + u8 top, code, i;=0A= +=0A= + top =3D sit9531x_prio_top_live(sitdev, srcs);=0A= + if (top !=3D SIT9531X_PRIO_SRC_NONE &&=0A= + (idle || top !=3D sit9531x_prio_top_live(sitdev, old)))=0A= + return sit9531x_prio_table_code(sitdev, srcs, top);=0A= +=0A= + cur =3D sit9531x_prio_src_canon(sitdev, cur & SIT9531X_PRIO_NIBBLE_MASK);= =0A= +=0A= + if (sit9531x_prio_src_usable(cur) &&=0A= + sit9531x_prio_src_live(sitdev, cur)) {=0A= + code =3D sit9531x_prio_table_code(sitdev, srcs, cur);=0A= + if (code !=3D SIT9531X_PRIO_SRC_NONE)=0A= + return code;=0A= + }=0A= +=0A= + if (top !=3D SIT9531X_PRIO_SRC_NONE)=0A= + return sit9531x_prio_table_code(sitdev, srcs, top);=0A= +=0A= + for (i =3D 0; i < SIT9531X_PRIO_MAX_SLOTS; i++)=0A= + if (sit9531x_prio_src_usable(srcs[i]))=0A= + return srcs[i];=0A= +=0A= + return srcs[0];=0A= +}=0A= +=0A= +static int sit9531x_prio_table_commit(struct sit9531x_dev *sitdev, u8 pll_= idx,=0A= + const u8 *srcs, bool reselect)=0A= +{=0A= + u8 now[SIT9531X_PRIO_MAX_SLOTS], back[SIT9531X_PRIO_MAX_SLOTS];=0A= + u8 val, last_old, slot, attempt, top, written =3D 0, restored =3D 0;=0A= + struct sit9531x_chan *chan =3D &sitdev->chan[pll_idx];=0A= + bool pending_before =3D chan->table_pending;=0A= + bool empty, ho_foreign, ho_undo =3D false, pending =3D false;=0A= + int rc =3D 0, prg_rc, ho_rc =3D 0;=0A= + u16 reg;=0A= +=0A= + empty =3D true;=0A= + for (slot =3D 0; slot < SIT9531X_PRIO_MAX_SLOTS; slot++)=0A= + if (sit9531x_prio_src_usable(srcs[slot]))=0A= + empty =3D false;=0A= +=0A= + memcpy(back, chan->table_pending ? chan->table_back : chan->prio_srcs,=0A= + sizeof(back));=0A= +=0A= + /*=0A= + * Treat a forced holdover as set by this driver only when the table is= =0A= + * empty, when the driver kept it for an empty table, or when a release= =0A= + * is pending; leave any other in place.=0A= + */=0A= + rc =3D sit9531x_read_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_HO_CTRL,=0A= + &val);=0A= + if (rc)=0A= + return rc;=0A= +=0A= + if (!(val & BIT(SIT9531X_PLL_HO_FORCE_BIT)))=0A= + chan->ho_kept =3D false;=0A= + ho_foreign =3D (val & BIT(SIT9531X_PLL_HO_FORCE_BIT)) &&=0A= + chan->prio_mask && !chan->ho_kept &&=0A= + !chan->ho_release_pending;=0A= +=0A= + rc =3D sit9531x_write_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_HO_CTRL,= =0A= + val | BIT(SIT9531X_PLL_HO_FORCE_BIT));=0A= + if (rc) {=0A= + /*=0A= + * The write may have reached the part; the release decides the=0A= + * bit as after a table write, from its value before this write.=0A= + */=0A= + ho_undo =3D !(val & BIT(SIT9531X_PLL_HO_FORCE_BIT));=0A= + goto release;=0A= + }=0A= +=0A= + usleep_range(10000, 12000);=0A= +=0A= + for (slot =3D 0; slot + 1 < SIT9531X_PRIO_MAX_SLOTS; slot +=3D 2) {=0A= + reg =3D sit9531x_prio_reg(pll_idx, slot);=0A= +=0A= + val =3D sit9531x_prio_slot_set(0, slot, srcs[slot]);=0A= + val =3D sit9531x_prio_slot_set(val, slot + 1, srcs[slot + 1]);=0A= +=0A= + written =3D slot + 2;=0A= + rc =3D sit9531x_write_u8(sitdev, reg, val);=0A= + if (rc)=0A= + goto rollback;=0A= }=0A= =0A= - sitdev->chan[pll_idx].prio_mask =3D mask;=0A= + /*=0A= + * The last register holds slot 10 in [7:4] and the device's active=0A= + * selection in [3:0], addressed as the slot past the last.=0A= + */=0A= + reg =3D sit9531x_prio_reg(pll_idx, slot);=0A= +=0A= + rc =3D sit9531x_read_u8(sitdev, reg, &last_old);=0A= + if (rc)=0A= + goto rollback;=0A= +=0A= + val =3D sit9531x_prio_slot_set(last_old, slot, srcs[slot]);=0A= +=0A= + if (!empty) {=0A= + u8 sel =3D sit9531x_prio_slot_get(val, slot + 1);=0A= + bool idle;=0A= +=0A= + rc =3D sit9531x_input_mon_fetch(sitdev);=0A= + if (rc)=0A= + goto rollback;=0A= + idle =3D reselect && (!chan->locked || chan->inner_lol ||=0A= + chan->mode || chan->ho_freeze);=0A= + sel =3D sit9531x_prio_activesel_pick(sitdev, chan->prio_srcs,=0A= + srcs, sel, idle);=0A= + val =3D sit9531x_prio_slot_set(val, slot + 1, sel);=0A= + }=0A= +=0A= + written =3D SIT9531X_PRIO_MAX_SLOTS;=0A= + rc =3D sit9531x_write_u8(sitdev, reg, val);=0A= + if (rc)=0A= + goto rollback;=0A= +=0A= +rollback:=0A= + if (rc && written) {=0A= + for (slot =3D 0; slot < written; slot +=3D 2) {=0A= + const u8 *prev =3D &chan->prio_srcs[slot];=0A= + u8 old;=0A= +=0A= + if (slot + 1 < SIT9531X_PRIO_MAX_SLOTS) {=0A= + old =3D sit9531x_prio_slot_set(0, slot, prev[0]);=0A= + old =3D sit9531x_prio_slot_set(old, slot + 1,=0A= + prev[1]);=0A= + } else {=0A= + old =3D last_old;=0A= + }=0A= + if (sit9531x_write_u8(sitdev,=0A= + sit9531x_prio_reg(pll_idx, slot),=0A= + old))=0A= + break;=0A= +=0A= + restored =3D slot + 2;=0A= + }=0A= + pending =3D restored < written;=0A= + written =3D restored;=0A= + }=0A= +=0A= + /*=0A= + * Latch unconditionally: the PLL uses the register contents only after= =0A= + * a latch.=0A= + */=0A= + prg_rc =3D sit9531x_prio_prg_commit(sitdev);=0A= + if (prg_rc && !rc) {=0A= + pending =3D true;=0A= + rc =3D prg_rc;=0A= + }=0A= + /* A latch starts a new acquisition; see sit9531x_reselect(). */=0A= + if (!prg_rc) {=0A= + chan->tracked =3D false;=0A= + chan->stall_polls =3D 0;=0A= + }=0A= +=0A= + if (!rc) {=0A= + sit9531x_prio_mask_build(sitdev, pll_idx, srcs);=0A= + /* Re-select compares against this table's best live source */=0A= + top =3D sit9531x_prio_top_live(sitdev, srcs);=0A= + if (top !=3D chan->live_top)=0A= + chan->stall_shift =3D 0;=0A= + chan->live_top =3D top;=0A= + memcpy(chan->seen_srcs, srcs, sizeof(chan->seen_srcs));=0A= + chan->seen_valid =3D true;=0A= + chan->table_pending =3D false;=0A= + } else if (pending || pending_before) {=0A= + sit9531x_prio_mask_build(sitdev, pll_idx, back);=0A= + memcpy(chan->table_back, back, sizeof(chan->table_back));=0A= + chan->table_pending =3D true;=0A= + } else if (!sit9531x_prio_table_read(sitdev, pll_idx, now)) {=0A= + sit9531x_prio_mask_build(sitdev, pll_idx, now);=0A= + memcpy(chan->seen_srcs, now, sizeof(chan->seen_srcs));=0A= + chan->seen_valid =3D true;=0A= + }=0A= +=0A= +release:=0A= + /*=0A= + * An empty table keeps the forced holdover; the PLL uses the source in= =0A= + * the selection nibble, which still names the old one.=0A= + */=0A= + if (!chan->prio_mask && !ho_undo) {=0A= + dev_dbg(sitdev->dev,=0A= + "PLL%c: no source listed, holdover kept\n",=0A= + 'A' + pll_idx);=0A= + chan->ho_release_pending =3D false;=0A= + chan->ho_kept =3D true;=0A= + goto out;=0A= + }=0A= +=0A= + if (ho_foreign) {=0A= + dev_dbg(sitdev->dev,=0A= + "PLL%c: holdover was forced before the write, left in place\n",=0A= + 'A' + pll_idx);=0A= + goto out;=0A= + }=0A= +=0A= + if (chan->table_pending) {=0A= + dev_dbg(sitdev->dev,=0A= + "PLL%c: priority table restore pending, holdover kept\n",=0A= + 'A' + pll_idx);=0A= + chan->ho_release_pending =3D true;=0A= + goto out;=0A= + }=0A= +=0A= + for (attempt =3D 0; attempt < SIT9531X_HO_CLEAR_TRIES; attempt++) {=0A= + ho_rc =3D sit9531x_update_pll_u8(sitdev, pll_idx,=0A= + SIT9531X_PLL_REG_HO_CTRL,=0A= + BIT(SIT9531X_PLL_HO_FORCE_BIT),=0A= + 0);=0A= + if (!ho_rc)=0A= + break;=0A= + usleep_range(1000, 2000);=0A= + }=0A= + if (ho_rc) {=0A= + dev_err(sitdev->dev, "PLL%c left in forced holdover: %d\n",=0A= + 'A' + pll_idx, ho_rc);=0A= + if (!rc)=0A= + rc =3D ho_rc;=0A= + }=0A= + chan->ho_release_pending =3D !!ho_rc;=0A= + if (!ho_rc)=0A= + chan->ho_kept =3D false;=0A= +=0A= +out:=0A= + /* The core reads the pin getters as soon as the setter returns. */=0A= + if (sit9531x_chan_state_fetch(sitdev, pll_idx))=0A= + chan->stale =3D true;=0A= +=0A= + return rc;=0A= +}=0A= +=0A= +/* Caller must hold sitdev->multiop_lock. */=0A= +static int sit9531x_prio_table_read(struct sit9531x_dev *sitdev, u8 pll_id= x,=0A= + u8 *srcs)=0A= +{=0A= + u8 val, slot;=0A= + int rc;=0A= +=0A= + for (slot =3D 0; slot < SIT9531X_PRIO_MAX_SLOTS; slot++) {=0A= + rc =3D sit9531x_read_u8(sitdev,=0A= + sit9531x_prio_reg(pll_idx, slot), &val);=0A= + if (rc)=0A= + return rc;=0A= +=0A= + srcs[slot] =3D sit9531x_prio_slot_get(val, slot);=0A= + }=0A= +=0A= + return 0;=0A= +}=0A= +=0A= +/*=0A= + * Rewrite a PLL's table for a new member set; skip an unchanged table, si= nce=0A= + * each write forces holdover.=0A= + */=0A= +static int sit9531x_prio_table_apply(struct sit9531x_dev *sitdev, u8 pll_i= dx,=0A= + u16 members)=0A= +{=0A= + u8 srcs[SIT9531X_PRIO_MAX_SLOTS];=0A= +=0A= + if (hweight16(members) > SIT9531X_PRIO_MAX_SLOTS)=0A= + return -ENOSPC;=0A= +=0A= + sit9531x_prio_table_build(sitdev, pll_idx, members, srcs);=0A= + if (!memcmp(srcs, sitdev->chan[pll_idx].prio_srcs, sizeof(srcs)))=0A= + return 0;=0A= +=0A= + return sit9531x_prio_table_commit(sitdev, pll_idx, srcs, false);=0A= +}=0A= +=0A= +/*=0A= + * Removing the last source leaves an empty table, which keeps the PLL in= =0A= + * holdover. Caller must hold sitdev->multiop_lock.=0A= + */=0A= +int sit9531x_input_prio_remove(struct sit9531x_dev *sitdev, u8 pll_idx,=0A= + u8 input_idx)=0A= +{=0A= + struct sit9531x_chan *chan;=0A= +=0A= + lockdep_assert_held(&sitdev->multiop_lock);=0A= +=0A= + if (pll_idx >=3D SIT9531X_NUM_PLLS)=0A= + return -EINVAL;=0A= + input_idx =3D sit9531x_prio_src_canon(sitdev, input_idx);=0A= + if (input_idx >=3D SIT9531X_PRIO_NUM_SRC)=0A= + return -EINVAL;=0A= +=0A= + chan =3D &sitdev->chan[pll_idx];=0A= + if (!(chan->prio_mask & BIT(input_idx)))=0A= + return 0;=0A= +=0A= + return sit9531x_prio_table_apply(sitdev, pll_idx,=0A= + chan->prio_mask & ~BIT(input_idx));=0A= }=0A= =0A= -/* Caller must hold sitdev->multiop_lock. */=0A= -static int sit9531x_prio_table_read(struct sit9531x_dev *sitdev, u8 pll_id= x,=0A= - u8 *srcs)=0A= +/*=0A= + * A source the PLL never listed gets the priority of the last slot. Calle= r must=0A= + * hold sitdev->multiop_lock.=0A= + */=0A= +int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx,=0A= + u8 input_idx)=0A= {=0A= - u8 val, slot;=0A= - int rc;=0A= + struct sit9531x_chan *chan;=0A= =0A= - for (slot =3D 0; slot < SIT9531X_PRIO_MAX_SLOTS; slot++) {=0A= - rc =3D sit9531x_read_u8(sitdev,=0A= - sit9531x_prio_reg(pll_idx, slot), &val);=0A= - if (rc)=0A= - return rc;=0A= + lockdep_assert_held(&sitdev->multiop_lock);=0A= =0A= - srcs[slot] =3D sit9531x_prio_slot_get(val, slot);=0A= - }=0A= + if (pll_idx >=3D SIT9531X_NUM_PLLS)=0A= + return -EINVAL;=0A= + input_idx =3D sit9531x_prio_src_canon(sitdev, input_idx);=0A= + if (input_idx >=3D SIT9531X_PRIO_NUM_SRC)=0A= + return -EINVAL;=0A= =0A= - return 0;=0A= + chan =3D &sitdev->chan[pll_idx];=0A= + if (chan->prio_mask & BIT(input_idx))=0A= + return 0;=0A= +=0A= + return sit9531x_prio_table_apply(sitdev, pll_idx,=0A= + chan->prio_mask | BIT(input_idx));=0A= }=0A= =0A= /* The latches INTRB reports, each with its sticky bits */=0A= @@ -508,7 +1226,8 @@ static int sit9531x_pll_is_active(struct sit9531x_dev = *sitdev, u8 pll_idx,=0A= static int sit9531x_chan_select_fetch(struct sit9531x_dev *sitdev, u8 pll_= idx)=0A= {=0A= struct sit9531x_chan *chan =3D &sitdev->chan[pll_idx];=0A= - bool manual_input =3D false;=0A= + bool manual_input =3D false, manual_any =3D false;=0A= + u8 manual_ref =3D SIT9531X_REF_INVALID;=0A= u8 cfg, misc, sel;=0A= int rc;=0A= =0A= @@ -534,8 +1253,13 @@ static int sit9531x_chan_select_fetch(struct sit9531x= _dev *sitdev, u8 pll_idx)=0A= if (rc)=0A= return rc;=0A= manual_input =3D true;=0A= + manual_any =3D !(sel & SIT9531X_MAN_IN_SEL_FROM_REG) ||=0A= + (sel & SIT9531X_MAN_IN_SEL_INDIRECT);=0A= if (sel & SIT9531X_MAN_IN_SEL_FROM_REG) {=0A= sel =3D FIELD_GET(SIT9531X_MAN_IN_SEL_MASK, sel);=0A= + manual_ref =3D=0A= + sit9531x_hw_src_input(sit9531x_prio_src_canon(sitdev,=0A= + sel));=0A= dev_dbg(sitdev->dev,=0A= "PLL%c: the profile selects its reference from the register, input code= %u; reported as manual\n",=0A= 'A' + pll_idx, sel);=0A= @@ -544,24 +1268,81 @@ static int sit9531x_chan_select_fetch(struct sit9531= x_dev *sitdev, u8 pll_idx)=0A= "PLL%c: the profile selects its reference from the input-select pins; r= eported as manual\n",=0A= 'A' + pll_idx);=0A= }=0A= + /*=0A= + * The select pins and the indirect choice are not read here: a PLL=0A= + * found on them again keeps the input it last tracked.=0A= + */=0A= + if (manual_any && chan->manual_input && chan->manual_any)=0A= + manual_ref =3D chan->manual_ref;=0A= =0A= record:=0A= chan->manual_input =3D manual_input;=0A= + chan->manual_any =3D manual_any;=0A= + chan->manual_ref =3D manual_ref;=0A= =0A= return 0;=0A= }=0A= =0A= +/*=0A= + * Read the reference the device feeds a PLL from the debug status bus; th= e=0A= + * active selection does not change on a fallback. The caller rules out fr= ee-run=0A= + * first and must hold sitdev->multiop_lock.=0A= + */=0A= +static int sit9531x_chan_routed_ref_read(struct sit9531x_dev *sitdev,=0A= + u8 pll_idx, u8 *ref)=0A= +{=0A= + int rc, lock_rc;=0A= + u8 v, i;=0A= +=0A= + lockdep_assert_held(&sitdev->multiop_lock);=0A= +=0A= + rc =3D sit9531x_write_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_DEBUG,=0A= + SIT9531X_PLL_DEBUG_UNLOCK);=0A= + if (rc)=0A= + goto relock;=0A= +=0A= + rc =3D sit9531x_write_pll_u8(sitdev, pll_idx,=0A= + SIT9531X_PLL_REG_DBG_STATUS_ADDR,=0A= + SIT9531X_DBG_STATUS_ROUTED_SRC);=0A= + if (rc)=0A= + goto relock;=0A= +=0A= + /* The first reads return earlier latches; the last is current. */=0A= + for (i =3D 0; i < SIT9531X_DBG_STATUS_READS; i++) {=0A= + rc =3D sit9531x_read_pll_u8(sitdev, pll_idx,=0A= + SIT9531X_PLL_REG_DBG_STATUS_DATA,=0A= + &v);=0A= + if (rc)=0A= + goto relock;=0A= + }=0A= +=0A= + /*=0A= + * Canonicalize like the table entries: a differential pair fed through= =0A= + * its N-lane code is the P-lane pin.=0A= + */=0A= + v =3D sit9531x_prio_src_canon(sitdev, v & SIT9531X_DBG_ROUTED_SRC_MASK);= =0A= + *ref =3D sit9531x_hw_src_input(v);=0A= +=0A= +relock:=0A= + lock_rc =3D sit9531x_write_pll_close(sitdev, pll_idx,=0A= + SIT9531X_PLL_REG_DEBUG,=0A= + SIT9531X_PLL_DEBUG_LOCK);=0A= + sitdev->chan[pll_idx].key_pending =3D !!lock_rc;=0A= +=0A= + return rc ? rc : lock_rc;=0A= +}=0A= +=0A= /*=0A= * Read the PLL's run, lock and holdover state, mode, selection and priori= ty=0A= * table.=0A= */=0A= static int sit9531x_chan_state_fetch(struct sit9531x_dev *sitdev, u8 pll_i= dx)=0A= {=0A= - u8 status, outer_lol, input_sel, inner_lol, ho_freeze, activesel_reg;=0A= + u8 status, outer_lol, inner_lol, ho_freeze, pll_status_1;=0A= struct sit9531x_chan *chan =3D &sitdev->chan[pll_idx];=0A= u8 srcs[SIT9531X_PRIO_MAX_SLOTS];=0A= - u8 pll_status_1;=0A= - bool active;=0A= + u8 routed =3D SIT9531X_REF_INVALID;=0A= + bool active, tracking;=0A= int rc;=0A= =0A= /*=0A= @@ -582,21 +1363,6 @@ static int sit9531x_chan_state_fetch(struct sit9531x_= dev *sitdev, u8 pll_idx)=0A= if (rc)=0A= return rc;=0A= =0A= - /*=0A= - * The active selection is CLK_ACTIVESEL_PLL, the low nibble of the last= =0A= - * register of the PLL's Page 1 priority block. PLL-page 0x29 is a=0A= - * config register.=0A= - */=0A= - activesel_reg =3D SIT9531X_PRIO_BASE_REG +=0A= - SIT9531X_PRIO_REGS_PER_PLL * pll_idx +=0A= - SIT9531X_PRIO_ACTIVESEL_OFF;=0A= - rc =3D sit9531x_read_u8(sitdev,=0A= - SIT9531X_REG(SIT9531X_PAGE_PRIOSYS,=0A= - activesel_reg),=0A= - &input_sel);=0A= - if (rc)=0A= - return rc;=0A= -=0A= rc =3D sit9531x_read_u8(sitdev, SIT9531X_REG_PLL_INNER_LOL_STATUS,=0A= &inner_lol);=0A= if (rc)=0A= @@ -607,23 +1373,48 @@ static int sit9531x_chan_state_fetch(struct sit9531x= _dev *sitdev, u8 pll_idx)=0A= if (rc)=0A= return rc;=0A= =0A= + /*=0A= + * Read the routed reference only while the PLL tracks one; in free-run= =0A= + * it has none.=0A= + */=0A= + tracking =3D active && !(outer_lol & BIT(pll_idx)) &&=0A= + !(status & SIT9531X_PLL_STATUS_OUTER_DIS) &&=0A= + !(ho_freeze & BIT(pll_idx));=0A= + if (tracking) {=0A= + rc =3D sit9531x_chan_routed_ref_read(sitdev, pll_idx, &routed);=0A= + if (rc)=0A= + return rc;=0A= + }=0A= +=0A= rc =3D sit9531x_read_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_STATUS_1,= =0A= &pll_status_1);=0A= if (rc)=0A= return rc;=0A= =0A= - rc =3D sit9531x_prio_table_read(sitdev, pll_idx, srcs);=0A= - if (rc)=0A= - return rc;=0A= + /* Keep the cached table while its write-back is pending */=0A= + if (!chan->table_pending) {=0A= + rc =3D sit9531x_prio_table_read(sitdev, pll_idx, srcs);=0A= + if (rc)=0A= + return rc;=0A= +=0A= + sit9531x_prio_mask_build(sitdev, pll_idx, srcs);=0A= =0A= - sit9531x_prio_mask_build(sitdev, pll_idx, srcs);=0A= + /*=0A= + * A table that differs from the last one written was changed=0A= + * outside the driver; take it as the configuration.=0A= + */=0A= + if (!chan->seen_valid ||=0A= + memcmp(srcs, chan->seen_srcs, sizeof(chan->seen_srcs)))=0A= + sit9531x_prio_cfg_seed(sitdev, pll_idx, srcs);=0A= + }=0A= =0A= /* STATUS_1_GENERIC reports loss of lock, so invert it. */=0A= chan->active =3D active;=0A= chan->locked =3D active && !(outer_lol & BIT(pll_idx));=0A= chan->mode =3D !!(status & SIT9531X_PLL_STATUS_OUTER_DIS);=0A= - chan->selected_ref =3D=0A= - sit9531x_hw_src_input(input_sel & SIT9531X_PRIO_NIBBLE_MASK);=0A= + chan->routed_ref =3D routed;=0A= + if (chan->manual_input && routed !=3D SIT9531X_REF_INVALID)=0A= + chan->manual_ref =3D routed;=0A= chan->inner_lol =3D !!(inner_lol & BIT(pll_idx));=0A= chan->ho_freeze =3D !!(ho_freeze & BIT(pll_idx));=0A= chan->ho_valid =3D !!(pll_status_1 & SIT9531X_PLL_STATUS_1_HO_VALID);=0A= @@ -739,11 +1530,53 @@ static int sit9531x_ref_pll_mask_fetch(struct sit953= 1x_dev *sitdev)=0A= return 0;=0A= }=0A= =0A= +/*=0A= + * Mark the input each manual-select PLL uses, or every input when the dri= ver=0A= + * does not read which; its table need not list it. Caller must hold=0A= + * sitdev->multiop_lock.=0A= + */=0A= +static void sit9531x_manual_claims_add(struct sit9531x_dev *sitdev)=0A= +{=0A= + const struct sit9531x_chan *chan;=0A= + u8 pll_idx, i;=0A= +=0A= + for (pll_idx =3D 0; pll_idx < SIT9531X_NUM_PLLS; pll_idx++) {=0A= + chan =3D &sitdev->chan[pll_idx];=0A= + if (!chan->manual_input)=0A= + continue;=0A= + /*=0A= + * The select pins can move such a PLL to any input at any=0A= + * time, so no receiver is turned off under it.=0A= + */=0A= + if (chan->manual_any) {=0A= + for (i =3D 0; i < sitdev->info->num_inputs; i++)=0A= + sitdev->ref[i].pll_mask |=3D BIT(pll_idx);=0A= + continue;=0A= + }=0A= + if (chan->manual_ref < sitdev->info->num_inputs)=0A= + sitdev->ref[chan->manual_ref].pll_mask |=3D BIT(pll_idx);=0A= + }=0A= +}=0A= +=0A= +/* Arm the one-shot re-select of every PLL; see sit9531x_reselect(). */=0A= +static void sit9531x_reselect_arm(struct sit9531x_dev *sitdev)=0A= +{=0A= + u8 i;=0A= +=0A= + for (i =3D 0; i < SIT9531X_NUM_PLLS; i++) {=0A= + sitdev->chan[i].reselect_armed =3D true;=0A= + sitdev->chan[i].stall_polls =3D 0;=0A= + sitdev->chan[i].stall_shift =3D 0;=0A= + }=0A= +}=0A= +=0A= static int sit9531x_dev_state_fetch(struct sit9531x_dev *sitdev)=0A= {=0A= int rc;=0A= u8 i;=0A= =0A= + sit9531x_reselect_arm(sitdev);=0A= +=0A= /* Detect SE/DE configuration before any per-lane access */=0A= for (i =3D 0; i < sitdev->info->num_inputs / 2; i++) {=0A= rc =3D sit9531x_input_mode_fetch(sitdev, i);=0A= @@ -763,6 +1596,13 @@ static int sit9531x_dev_state_fetch(struct sit9531x_d= ev *sitdev)=0A= }=0A= }=0A= =0A= + rc =3D sit9531x_input_mon_fetch(sitdev);=0A= + if (rc) {=0A= + dev_err(sitdev->dev,=0A= + "Failed to read the input clock monitors: %d\n", rc);=0A= + return rc;=0A= + }=0A= +=0A= for (i =3D 0; i < sitdev->info->num_outputs; i++) {=0A= mutex_lock(&sitdev->multiop_lock);=0A= rc =3D sit9531x_out_state_fetch(sitdev, i);=0A= @@ -798,34 +1638,279 @@ static int sit9531x_dev_state_fetch(struct sit9531x= _dev *sitdev)=0A= return rc;=0A= }=0A= =0A= + /* Needs the select registers and samples read above */=0A= + mutex_lock(&sitdev->multiop_lock);=0A= + sit9531x_manual_claims_add(sitdev);=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= +=0A= return 0;=0A= }=0A= =0A= -static void sit9531x_dev_ref_states_update(struct sit9531x_dev *sitdev)=0A= +/*=0A= + * Read each receiver's enable and every lane's clock monitor; return true= if=0A= + * any read succeeds.=0A= + */=0A= +static bool=0A= +sit9531x_dev_ref_states_update(struct sit9531x_dev *sitdev)=0A= {=0A= + bool answered =3D false;=0A= int i, rc;=0A= =0A= for (i =3D 0; i < sitdev->info->num_inputs; i++) {=0A= rc =3D sit9531x_ref_state_fetch(sitdev, i);=0A= if (rc)=0A= - dev_warn(sitdev->dev,=0A= - "Failed to get REF%u status: %d\n", i, rc);=0A= + dev_warn_ratelimited(sitdev->dev,=0A= + "Failed to get REF%u status: %d\n",=0A= + i, rc);=0A= + else=0A= + answered =3D true;=0A= + }=0A= +=0A= + rc =3D sit9531x_input_mon_fetch(sitdev);=0A= + if (rc)=0A= + dev_warn_ratelimited(sitdev->dev,=0A= + "Failed to read the input clock monitors: %d\n",=0A= + rc);=0A= + else=0A= + answered =3D true;=0A= +=0A= + return answered;=0A= +}=0A= +=0A= +/*=0A= + * Retry turning off a receiver unless a PLL has claimed the input since. = Caller=0A= + * must hold sitdev->multiop_lock.=0A= + */=0A= +static void sit9531x_input_off_retry(struct sit9531x_dev *sitdev)=0A= +{=0A= + u8 i;=0A= +=0A= + for (i =3D 0; i < sitdev->info->num_inputs; i++) {=0A= + struct sit9531x_ref *ref =3D &sitdev->ref[i];=0A= +=0A= + if (!ref->off_pending)=0A= + continue;=0A= + if (ref->pll_mask)=0A= + ref->off_pending =3D false;=0A= + else=0A= + sit9531x_input_disable(sitdev, i);=0A= + }=0A= +}=0A= +=0A= +/*=0A= + * Rebuild pll_mask from the cached priority tables of the PLLs that selec= t by=0A= + * priority and from the manual-select inputs. Caller must hold=0A= + * sitdev->multiop_lock.=0A= + */=0A= +static void sit9531x_ref_pll_mask_rebuild(struct sit9531x_dev *sitdev)=0A= +{=0A= + u8 pll_idx, src, index;=0A= +=0A= + for (index =3D 0; index < sitdev->info->num_inputs; index++)=0A= + sitdev->ref[index].pll_mask =3D 0;=0A= +=0A= + for (pll_idx =3D 0; pll_idx < SIT9531X_NUM_PLLS; pll_idx++) {=0A= + u16 mask =3D sitdev->chan[pll_idx].prio_mask;=0A= +=0A= + /* A PLL on manual input select does not use its table */=0A= + if (sitdev->chan[pll_idx].manual_input)=0A= + continue;=0A= +=0A= + for (src =3D 0; src < SIT9531X_PRIO_NUM_SRC; src++) {=0A= + if (!(mask & BIT(src)))=0A= + continue;=0A= +=0A= + index =3D sit9531x_hw_src_input(src);=0A= + if (index < sitdev->info->num_inputs)=0A= + sitdev->ref[index].pll_mask |=3D BIT(pll_idx);=0A= + }=0A= + }=0A= +=0A= + sit9531x_manual_claims_add(sitdev);=0A= +}=0A= +=0A= +/*=0A= + * Retry a pending forced-holdover release; a pending table write-back rel= eases=0A= + * it instead. Caller must hold sitdev->multiop_lock.=0A= + */=0A= +static void sit9531x_ho_release_retry(struct sit9531x_dev *sitdev, u8 pll_= idx)=0A= +{=0A= + struct sit9531x_chan *chan =3D &sitdev->chan[pll_idx];=0A= +=0A= + if (!chan->ho_release_pending || chan->table_pending)=0A= + return;=0A= +=0A= + if (sit9531x_update_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_HO_CTRL,=0A= + BIT(SIT9531X_PLL_HO_FORCE_BIT), 0))=0A= + return;=0A= +=0A= + chan->ho_release_pending =3D false;=0A= + chan->ho_kept =3D false;=0A= + dev_info(sitdev->dev, "PLL%c: forced holdover released\n",=0A= + 'A' + pll_idx);=0A= +}=0A= +=0A= +/*=0A= + * Write back the priority table after a failed write. Caller must hold=0A= + * sitdev->multiop_lock.=0A= + */=0A= +static void sit9531x_table_back_retry(struct sit9531x_dev *sitdev, u8 pll_= idx)=0A= +{=0A= + u8 back[SIT9531X_PRIO_MAX_SLOTS];=0A= +=0A= + if (!sitdev->chan[pll_idx].table_pending)=0A= + return;=0A= +=0A= + memcpy(back, sitdev->chan[pll_idx].table_back, sizeof(back));=0A= + if (sit9531x_prio_table_commit(sitdev, pll_idx, back, false))=0A= + return;=0A= +=0A= + dev_info(sitdev->dev, "PLL%c: priority table written back\n",=0A= + 'A' + pll_idx);=0A= +}=0A= +=0A= +/* Lock the PLL debug key again. Caller must hold sitdev->multiop_lock. */= =0A= +static void sit9531x_debug_back_retry(struct sit9531x_dev *sitdev, u8 pll_= idx)=0A= +{=0A= + struct sit9531x_chan *chan =3D &sitdev->chan[pll_idx];=0A= +=0A= + if (!chan->key_pending)=0A= + return;=0A= +=0A= + chan->key_pending =3D !!sit9531x_write_pll_close(sitdev, pll_idx,=0A= + SIT9531X_PLL_REG_DEBUG,=0A= + SIT9531X_PLL_DEBUG_LOCK);=0A= +}=0A= +=0A= +/*=0A= + * Frozen polls after which a stalled PLL is re-selected: 20, 10 s, double= d=0A= + * after each such re-select up to 1280, 640 s.=0A= + */=0A= +#define SIT9531X_RESELECT_STALL_POLLS 20=0A= +#define SIT9531X_RESELECT_STALL_SHIFT_MAX 6=0A= +=0A= +/*=0A= + * Rewrite the table of a PLL without a reference while a listed source ha= s=0A= + * signal; the write latches the active selection again. A latch restarts= =0A= + * acquisition: write once on a loss of the reference, on a change of the = best=0A= + * live source and after each stall. Caller must hold sitdev->multiop_lock= .=0A= + */=0A= +static void sit9531x_reselect(struct sit9531x_dev *sitdev, u8 pll_idx)=0A= +{=0A= + struct sit9531x_chan *chan =3D &sitdev->chan[pll_idx];=0A= + bool repeat =3D false;=0A= + u16 stall;=0A= + u8 top;=0A= + int rc;=0A= +=0A= + /*=0A= + * A PLL on manual input select uses no priority table, and an unused=0A= + * PLL, which never goes active, has no acquisition to restart.=0A= + */=0A= + if (chan->manual_input || !chan->active || !chan->prio_mask ||=0A= + chan->mode || chan->ho_release_pending || chan->table_pending)=0A= + return;=0A= +=0A= + /*=0A= + * A PLL that tracked a reference since its last latch and is frozen now= =0A= + * has lost it. The monitors may not show it: after a dropout shorter=0A= + * than the poll period the best live source is the one it was.=0A= + */=0A= + if (sit9531x_chan_tracking(chan)) {=0A= + chan->tracked =3D true;=0A= + chan->stall_polls =3D 0;=0A= + chan->stall_shift =3D 0;=0A= + } else if (chan->tracked && chan->ho_freeze) {=0A= + chan->tracked =3D false;=0A= + chan->reselect_armed =3D true;=0A= + }=0A= +=0A= + top =3D sit9531x_prio_top_live(sitdev, chan->prio_srcs);=0A= + /*=0A= + * A PLL that locks and loses its source between two polls is not seen=0A= + * to track. It stalls when it stays frozen with the best live source=0A= + * unchanged since the last latch; each re-select for a stall doubles=0A= + * the count for the next one.=0A= + */=0A= + stall =3D SIT9531X_RESELECT_STALL_POLLS << chan->stall_shift;=0A= + if (top !=3D chan->live_top) {=0A= + chan->stall_polls =3D 0;=0A= + chan->stall_shift =3D 0;=0A= + } else if (chan->ho_freeze && top !=3D SIT9531X_PRIO_SRC_NONE &&=0A= + chan->stall_polls < stall && ++chan->stall_polls =3D=3D stall) {=0A= + chan->reselect_armed =3D true;=0A= + repeat =3D chan->stall_shift > 0;=0A= + if (chan->stall_shift < SIT9531X_RESELECT_STALL_SHIFT_MAX)=0A= + chan->stall_shift++;=0A= + }=0A= +=0A= + if (chan->reselect_armed) {=0A= + if (top =3D=3D SIT9531X_PRIO_SRC_NONE || !chan->ho_freeze) {=0A= + chan->reselect_armed =3D false;=0A= + chan->live_top =3D top;=0A= + return;=0A= + }=0A= + } else {=0A= + if (top =3D=3D chan->live_top)=0A= + return;=0A= + /*=0A= + * Tracking is locked and not frozen; the two bits are read=0A= + * independently.=0A= + */=0A= + if (top =3D=3D SIT9531X_PRIO_SRC_NONE ||=0A= + (chan->locked && !chan->ho_freeze)) {=0A= + chan->live_top =3D top;=0A= + return;=0A= + }=0A= + }=0A= +=0A= + rc =3D sit9531x_prio_table_commit(sitdev, pll_idx, chan->prio_srcs, true)= ;=0A= + if (rc) {=0A= + dev_warn_ratelimited(sitdev->dev,=0A= + "PLL%c: failed to re-select a returned source: %d\n",=0A= + 'A' + pll_idx, rc);=0A= + return;=0A= }=0A= +=0A= + chan->reselect_armed =3D false;=0A= + if (repeat)=0A= + dev_dbg(sitdev->dev, "PLL%c: re-selecting, still frozen\n",=0A= + 'A' + pll_idx);=0A= + else=0A= + dev_info(sitdev->dev, "PLL%c: re-selecting, a source is back\n",=0A= + 'A' + pll_idx);=0A= }=0A= =0A= -static void sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev)= =0A= +/*=0A= + * Retry pending writes, then read each PLL's state; return true if any st= ate=0A= + * read succeeds.=0A= + */=0A= +static bool=0A= +sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev)=0A= {=0A= + bool answered =3D false;=0A= int i, rc;=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= rc =3D sit9531x_chan_state_fetch(sitdev, i);=0A= if (rc) {=0A= sitdev->chan[i].stale =3D true;=0A= - dev_warn(sitdev->dev,=0A= - "Failed to get PLL%c state: %d\n",=0A= - 'A' + i, rc);=0A= + dev_warn_ratelimited(sitdev->dev,=0A= + "Failed to get PLL%c state: %d\n",=0A= + 'A' + i, rc);=0A= + continue;=0A= }=0A= + answered =3D true;=0A= + sit9531x_reselect(sitdev, i);=0A= }=0A= +=0A= + sit9531x_ref_pll_mask_rebuild(sitdev);=0A= +=0A= + return answered;=0A= }=0A= =0A= static void sit9531x_dev_periodic_work(struct kthread_work *work)=0A= @@ -834,6 +1919,7 @@ static void sit9531x_dev_periodic_work(struct kthread_= work *work)=0A= work.work);=0A= struct sit9531x_dpll *sitdpll;=0A= bool latched;=0A= + bool answered;=0A= int rc;=0A= =0A= /*=0A= @@ -841,8 +1927,8 @@ static void sit9531x_dev_periodic_work(struct kthread_= work *work)=0A= * take DPLL-subsystem locks, which nest outside it.=0A= */=0A= mutex_lock(&sitdev->multiop_lock);=0A= - sit9531x_dev_ref_states_update(sitdev);=0A= - sit9531x_dev_chan_states_update(sitdev);=0A= + answered =3D sit9531x_dev_ref_states_update(sitdev);=0A= + answered |=3D sit9531x_dev_chan_states_update(sitdev);=0A= mutex_unlock(&sitdev->multiop_lock);=0A= =0A= list_for_each_entry(sitdpll, &sitdev->dplls, list)=0A= @@ -860,8 +1946,14 @@ static void sit9531x_dev_periodic_work(struct kthread= _work *work)=0A= "Failed to clear notifications: %d\n",=0A= rc);=0A= =0A= + if (answered || !rc)=0A= + sitdev->poll_fails =3D 0;=0A= + else if (sitdev->poll_fails < SIT9531X_POLL_STRETCH_MAX)=0A= + sitdev->poll_fails++;=0A= +=0A= kthread_queue_delayed_work(sitdev->kworker, &sitdev->work,=0A= - msecs_to_jiffies(SIT9531X_STATUS_POLL_MS));=0A= + msecs_to_jiffies(SIT9531X_STATUS_POLL_MS <<=0A= + sitdev->poll_fails));=0A= }=0A= =0A= /* Queue an immediate poll tick; polling continues as a fallback. */=0A= @@ -1000,6 +2092,63 @@ static void sit9531x_pll_states_report(struct sit953= 1x_dev *sitdev)=0A= }=0A= }=0A= =0A= +static bool sit9531x_input_pin_is_registrable(struct sit9531x_dev *sitdev,= =0A= + u8 index)=0A= +{=0A= + if (index >=3D sitdev->info->num_inputs)=0A= + return false;=0A= +=0A= + /* The N lane of a differential pair is not a standalone input. */=0A= + if (sit9531x_input_is_n(index) &&=0A= + sitdev->ref[index].sig_mode =3D=3D SIT9531X_MODE_DE)=0A= + return false;=0A= +=0A= + return true;=0A= +}=0A= +=0A= +/* Warn about a pin node whose reg names no registrable pin */=0A= +static void sit9531x_pin_nodes_check(struct sit9531x_dev *sitdev)=0A= +{=0A= + struct fwnode_handle *pins, *node;=0A= + bool found;=0A= + u32 reg;=0A= + u8 i;=0A= +=0A= + pins =3D device_get_named_child_node(sitdev->dev, "input-pins");=0A= + fwnode_for_each_child_node(pins, node) {=0A= + if (fwnode_property_read_u32(node, "reg", ®))=0A= + continue;=0A= + if (reg < sitdev->info->num_inputs &&=0A= + sit9531x_input_pin_is_registrable(sitdev, reg))=0A= + continue;=0A= + dev_warn(sitdev->dev,=0A= + "input-pins/%pfwP: reg %u is %s, node ignored\n",=0A= + node, reg,=0A= + reg < sitdev->info->num_inputs ?=0A= + "the N lane of a differential pair" :=0A= + "not an input lane");=0A= + }=0A= + fwnode_handle_put(pins);=0A= +=0A= + pins =3D device_get_named_child_node(sitdev->dev, "output-pins");=0A= + fwnode_for_each_child_node(pins, node) {=0A= + if (fwnode_property_read_u32(node, "reg", ®))=0A= + continue;=0A= + found =3D false;=0A= + for (i =3D 0; i < sitdev->info->num_outputs; i++) {=0A= + if (sitdev->info->clkout_map[i] =3D=3D reg) {=0A= + found =3D true;=0A= + break;=0A= + }=0A= + }=0A= + if (!found)=0A= + dev_warn(sitdev->dev,=0A= + "output-pins/%pfwP: reg %u is not an output of %s, node ignored\n",= =0A= + node, reg, sitdev->info->name);=0A= + }=0A= + fwnode_handle_put(pins);=0A= +}=0A= +=0A= static int sit9531x_dev_start(struct sit9531x_dev *sitdev)=0A= {=0A= struct sit9531x_dpll *sitdpll;=0A= @@ -1014,6 +2163,8 @@ static int sit9531x_dev_start(struct sit9531x_dev *si= tdev)=0A= sit9531x_pll_states_report(sitdev);=0A= mutex_unlock(&sitdev->multiop_lock);=0A= =0A= + sit9531x_pin_nodes_check(sitdev);=0A= +=0A= list_for_each_entry(sitdpll, &sitdev->dplls, list) {=0A= rc =3D sit9531x_dpll_register(sitdpll);=0A= if (rc) {=0A= @@ -1038,6 +2189,7 @@ static int sit9531x_dev_start(struct sit9531x_dev *si= tdev)=0A= static void sit9531x_dev_stop(struct sit9531x_dev *sitdev)=0A= {=0A= struct sit9531x_dpll *sitdpll;=0A= + u8 i;=0A= =0A= kthread_cancel_delayed_work_sync(&sitdev->work);=0A= =0A= @@ -1045,6 +2197,44 @@ static void sit9531x_dev_stop(struct sit9531x_dev *s= itdev)=0A= if (sitdpll->dpll_dev)=0A= sit9531x_dpll_unregister(sitdpll);=0A= }=0A= +=0A= + /*=0A= + * Write back tables first: forced holdover stays set while a table=0A= + * write-back is pending.=0A= + */=0A= + mutex_lock(&sitdev->multiop_lock);=0A= + for (i =3D 0; i < SIT9531X_NUM_PLLS; i++) {=0A= + sit9531x_table_back_retry(sitdev, i);=0A= + if (sitdev->chan[i].table_pending)=0A= + dev_warn(sitdev->dev,=0A= + "PLL%c priority table left as written, holdover kept\n",=0A= + 'A' + i);=0A= + }=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= +=0A= + mutex_lock(&sitdev->multiop_lock);=0A= + for (i =3D 0; i < SIT9531X_NUM_PLLS; i++) {=0A= + sit9531x_ho_release_retry(sitdev, i);=0A= + if (sitdev->chan[i].ho_release_pending &&=0A= + !sitdev->chan[i].table_pending)=0A= + dev_warn(sitdev->dev,=0A= + "PLL%c left in forced holdover\n", 'A' + i);=0A= + sit9531x_debug_back_retry(sitdev, i);=0A= + if (sitdev->chan[i].key_pending)=0A= + dev_warn(sitdev->dev,=0A= + "PLL%c left with its debug window open\n",=0A= + 'A' + i);=0A= + }=0A= +=0A= + /* After the table write-back: the tables give the receiver claims */=0A= + sit9531x_ref_pll_mask_rebuild(sitdev);=0A= + sit9531x_input_off_retry(sitdev);=0A= + for (i =3D 0; i < sitdev->info->num_inputs; i++)=0A= + if (sitdev->ref[i].off_pending)=0A= + dev_warn(sitdev->dev,=0A= + "input %u: receiver gate-off not applied at removal\n",=0A= + i);=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= }=0A= =0A= static struct sit9531x_dpll_pin *=0A= @@ -1088,8 +2278,11 @@ static int sit9531x_dpll_pin_register(struct sit9531= x_dpll_pin *pin,=0A= }=0A= dpll_pin_fwnode_set(pin->dpll_pin, props->fwnode);=0A= =0A= - rc =3D dpll_pin_register(sitdpll->dpll_dev, pin->dpll_pin,=0A= - sit9531x_dpll_pin_ops_get(pin), pin);=0A= + /* Kept for the unregister: resume reads the select mode again */=0A= + pin->ops =3D sit9531x_dpll_pin_ops_get(pin);=0A= +=0A= + rc =3D dpll_pin_register(sitdpll->dpll_dev, pin->dpll_pin, pin->ops,=0A= + pin);=0A= if (rc)=0A= goto err_register;=0A= =0A= @@ -1119,8 +2312,7 @@ static void sit9531x_dpll_pin_unregister(struct sit95= 31x_dpll_pin *pin)=0A= */=0A= pin->dpll_pin =3D NULL;=0A= =0A= - dpll_pin_unregister(sitdpll->dpll_dev, dpll_pin,=0A= - sit9531x_dpll_pin_ops_get(pin), pin);=0A= + dpll_pin_unregister(sitdpll->dpll_dev, dpll_pin, pin->ops, pin);=0A= dpll_pin_put(dpll_pin, &pin->tracker);=0A= =0A= fwnode_handle_put(pin->fwnode);=0A= @@ -1159,10 +2351,15 @@ static bool sit9531x_dpll_pin_is_registrable(struct= sit9531x_dpll *sitdpll,=0A= enum dpll_pin_direction dir,=0A= u8 index)=0A= {=0A= + struct sit9531x_dev *sitdev =3D sitdpll->dev;=0A= +=0A= if (dir !=3D DPLL_PIN_DIRECTION_INPUT)=0A= return false;=0A= =0A= - return index =3D=3D SIT9531X_MAX_INPUTS;=0A= + if (index =3D=3D SIT9531X_MAX_INPUTS)=0A= + return true;=0A= +=0A= + return sit9531x_input_pin_is_registrable(sitdev, index);=0A= }=0A= =0A= static int sit9531x_dpll_pins_register(struct sit9531x_dpll *sitdpll)=0A= @@ -1709,6 +2906,9 @@ static int sit9531x_resume(struct device *dev)=0A= sit9531x_page_cache_drop(sitdev);=0A= =0A= mutex_lock(&sitdev->multiop_lock);=0A= + /* One re-select for a source lost and restored between samples */=0A= + sit9531x_reselect_arm(sitdev);=0A= +=0A= /* Read again the configuration probe read */=0A= for (i =3D 0; i < sitdev->info->num_inputs / 2; i++) {=0A= enum sit9531x_signal_mode mode =3D sitdev->ref[i * 2].sig_mode;=0A= @@ -1720,7 +2920,7 @@ static int sit9531x_resume(struct device *dev)=0A= i, rc);=0A= else if (sitdev->ref[i * 2].sig_mode !=3D mode)=0A= dev_warn(sitdev->dev,=0A= - "CLKIN%u: signal mode changed over suspend\n",=0A= + "CLKIN%u: signal mode changed over suspend; its pins stay as they wer= e registered\n",=0A= i);=0A= }=0A= for (i =3D 0; i < SIT9531X_NUM_PLLS; i++) {=0A= @@ -1730,7 +2930,7 @@ static int sit9531x_resume(struct device *dev)=0A= rc =3D sit9531x_chan_select_fetch(sitdev, i);=0A= if (!rc && chan->manual_input !=3D manual) {=0A= dev_warn(sitdev->dev,=0A= - "PLL%c: select mode changed over suspend\n",=0A= + "PLL%c: select mode changed over suspend; its pins keep the callbacks= of the mode they were registered for; rebind the driver to manage its inpu= ts\n",=0A= 'A' + i);=0A= modes_moved |=3D BIT(i);=0A= }=0A= @@ -1741,8 +2941,13 @@ static int sit9531x_resume(struct device *dev)=0A= "PLL%c: state not read on resume: %d\n",=0A= 'A' + i, rc);=0A= chan->stale =3D true;=0A= + continue;=0A= }=0A= + /* A forced holdover over a listed table is the profile's */=0A= + if (!chan->table_pending && chan->prio_mask)=0A= + chan->ho_kept =3D false;=0A= }=0A= + sit9531x_ref_pll_mask_rebuild(sitdev);=0A= for (i =3D 0; i < sitdev->info->num_outputs; i++) {=0A= struct sit9531x_out *out =3D &sitdev->out[i];=0A= bool routed =3D out->routed;=0A= diff --git a/drivers/dpll/sit9531x/core.h b/drivers/dpll/sit9531x/core.h=0A= index f9bc9cce4ee7..31c7d434978a 100644=0A= --- a/drivers/dpll/sit9531x/core.h=0A= +++ b/drivers/dpll/sit9531x/core.h=0A= @@ -43,8 +43,13 @@=0A= #define SIT9531X_STATUS_POLL_MS 500=0A= /* TSTART: no I2C access is valid until 10 ms after the supplies are up */= =0A= #define SIT9531X_START_US 10000=0A= +/*=0A= + * Consecutive polls with no answer after which the poll period stops doub= ling:=0A= + * eight periods, 4 s.=0A= + */=0A= +#define SIT9531X_POLL_STRETCH_MAX 3=0A= =0A= -/* selected_ref value when the active source is not a registered input */= =0A= +/* routed_ref value when the PLL is fed no registered input */=0A= #define SIT9531X_REF_INVALID 0xFF=0A= =0A= /* SiTime IEEE OUI for EUI-64 generation */=0A= @@ -82,14 +87,21 @@ enum sit9531x_signal_mode {=0A= * struct sit9531x_ref - input reference state=0A= * @freq: configured frequency in Hz=0A= * @enabled: input receiver is on=0A= - * @pll_mask: PLLs this input feeds (bit 0 =3D PLLA)=0A= + * @off_pending: receiver gate-off to retry while no PLL claims the input= =0A= + * @pll_mask: PLLs that list this input and select by priority, or that ma= y=0A= + * use it on manual input select (bit 0 =3D PLLA)=0A= + * @los: clock monitor reports loss of signal=0A= + * @qual_fail: clock monitor reports frequency drift while the input has s= ignal=0A= * @sig_mode: signal mode of the input pair, read from CLKINx_INPUT_MODE a= t=0A= * probe and on resume=0A= */=0A= struct sit9531x_ref {=0A= u64 freq;=0A= bool enabled;=0A= + bool off_pending;=0A= u8 pll_mask;=0A= + bool los;=0A= + bool qual_fail;=0A= enum sit9531x_signal_mode sig_mode;=0A= };=0A= =0A= @@ -121,28 +133,87 @@ struct sit9531x_out {=0A= * @stale: last state read failed; the fields hold the previous sample and= =0A= * are not reported=0A= * @mode: 0 =3D sync (outer loop enabled), 1 =3D free-run=0A= - * @selected_ref: logical index of the selected reference (INTSYNC:=0A= - * SIT9531X_INTSYNC_PIN_ID), or SIT9531X_REF_INVALID for a reserved code= =0A= + * @routed_ref: input the device routes to the PLL, as a logical index=0A= + * (INTSYNC: SIT9531X_INTSYNC_PIN_ID); SIT9531X_REF_INVALID if none=0A= * @inner_lol: inner loop loss of lock=0A= * @ho_freeze: holdover freeze active=0A= * @ho_valid: holdover memory holds a valid estimate=0A= * @manual_input: PLL uses its manual input select (pins or=0A= * GPIO_INPUT_FUNC_CTRL5..8), which table writes do not change; reported= =0A= * as MANUAL=0A= + * @manual_ref: logical input of a manual PLL: the register choice, else t= he=0A= + * input it last tracked; SIT9531X_REF_INVALID if unknown; its receiver= =0A= + * stays claimed for the PLL=0A= + * @manual_any: manual PLL whose input the driver cannot tell from the=0A= + * registers (select pins or the indirect choice); every receiver stays= =0A= + * claimed for it=0A= + * @ho_release_pending: forced holdover not yet released=0A= + * @ho_kept: forced holdover left set by the driver for an empty table=0A= + * @live_top: highest-priority listed source with signal at the last poll,= =0A= + * or SIT9531X_PRIO_SRC_NONE; a change while the PLL tracks no source=0A= + * rewrites the table=0A= + * @reselect_armed: the next poll rewrites the table of a PLL in holdover= =0A= + * while a listed source has signal; set at probe, on resume, when a PLL= =0A= + * that tracked a reference is found frozen and when @stall_polls reache= s=0A= + * SIT9531X_RESELECT_STALL_POLLS doubled @stall_shift times=0A= + * @tracked: a poll saw the PLL track a reference since its table was last= =0A= + * latched=0A= + * @stall_polls: polls that found the PLL frozen with @live_top unchanged= =0A= + * since its table was last latched; cleared at each latch, when a poll = sees=0A= + * the PLL track or finds @live_top changed, at probe and on resume=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= + * @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= + * @key_pending: debug key of the PLL page not locked again=0A= + * @prio_srcs: cached priority table, a source code per slot=0A= + * @prio_last: first slot of each source plus one, 0 if absent=0A= * @prio_mask: bit per canonical source in the priority table read back=0A= * from hardware=0A= + * @lane_code: code the table last listed each canonical source by; a=0A= + * differential pair may be listed by its N-lane code, and a table write= =0A= + * keeps it=0A= + * @lane_known: bit per canonical source that has a @lane_code=0A= + * @cfg_prio: configured priority of each canonical source, listed or not;= =0A= + * the table is built from it=0A= + * @cfg_known: bit per canonical source that has a @cfg_prio=0A= + * @seen_srcs: table last written or read into @cfg_prio; a read-back that= =0A= + * differs reloads @cfg_prio from hardware=0A= + * @seen_valid: @seen_srcs holds a table=0A= */=0A= struct sit9531x_chan {=0A= bool active;=0A= bool locked;=0A= bool stale;=0A= u8 mode;=0A= - u8 selected_ref;=0A= + u8 routed_ref;=0A= bool inner_lol;=0A= bool ho_freeze;=0A= bool ho_valid;=0A= bool manual_input;=0A= + u8 manual_ref;=0A= + bool manual_any;=0A= + bool ho_release_pending;=0A= + bool ho_kept;=0A= + u8 live_top;=0A= + bool reselect_armed;=0A= + bool tracked;=0A= + u16 stall_polls;=0A= + u8 stall_shift;=0A= + bool table_pending;=0A= + u8 table_back[SIT9531X_PRIO_MAX_SLOTS];=0A= + bool key_pending;=0A= + u8 prio_srcs[SIT9531X_PRIO_MAX_SLOTS];=0A= + u8 prio_last[SIT9531X_PRIO_NUM_SRC];=0A= u16 prio_mask;=0A= + u8 lane_code[SIT9531X_PRIO_NUM_SRC];=0A= + u16 lane_known;=0A= + u8 cfg_prio[SIT9531X_PRIO_NUM_SRC];=0A= + u16 cfg_known;=0A= + u8 seen_srcs[SIT9531X_PRIO_MAX_SLOTS];=0A= + bool seen_valid;=0A= };=0A= =0A= /*=0A= @@ -162,6 +233,8 @@ struct sit9531x_chan {=0A= * @xtal_freq: crystal frequency in Hz=0A= * @kworker: poll worker=0A= * @work: poll work=0A= + * @poll_fails: consecutive failed polls, up to SIT9531X_POLL_STRETCH_MAX;= =0A= + * each doubles the period=0A= * @clock_id: clock identifier, from the die ID or the I2C bus and address= =0A= * @clock_id_node: entry in the list of the clock ids of the bound parts= =0A= * @reset_gpio: optional reset line, NULL if absent=0A= @@ -189,6 +262,7 @@ struct sit9531x_dev {=0A= =0A= struct kthread_worker *kworker;=0A= struct kthread_delayed_work work;=0A= + u8 poll_fails;=0A= =0A= u64 clock_id;=0A= struct list_head clock_id_node;=0A= @@ -203,6 +277,20 @@ int sit9531x_write_u8(struct sit9531x_dev *sitdev, uns= igned int reg,=0A= u8 val);=0A= int sit9531x_read_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,=0A= u8 offset, u8 *val);=0A= +int sit9531x_write_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,=0A= + u8 offset, u8 val);=0A= +int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,=0A= + u8 offset, u8 mask, u8 val);=0A= +=0A= +int sit9531x_input_disable(struct sit9531x_dev *sitdev, u8 index);=0A= +int sit9531x_input_enable(struct sit9531x_dev *sitdev, u8 index);=0A= +=0A= +bool sit9531x_input_prio_present(struct sit9531x_dev *sitdev,=0A= + u8 pll_idx, u8 input_idx);=0A= +int sit9531x_input_prio_remove(struct sit9531x_dev *sitdev, u8 pll_idx,=0A= + u8 input_idx);=0A= +int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx,=0A= + u8 input_idx);=0A= =0A= static inline u8 sit9531x_pll_page(u8 pll_idx)=0A= {=0A= @@ -224,6 +312,17 @@ static inline bool sit9531x_input_is_n(u8 index)=0A= return index & 1;=0A= }=0A= =0A= +static inline u8 sit9531x_input_hw_src(u8 index)=0A= +{=0A= + if (index =3D=3D SIT9531X_MAX_INPUTS)=0A= + return SIT9531X_PRIO_SRC_OCXO;=0A= + if (index =3D=3D SIT9531X_INTSYNC_PIN_ID)=0A= + return SIT9531X_PRIO_SRC_INTSYNC;=0A= + if (sit9531x_input_is_n(index))=0A= + return SIT9531X_PRIO_SRC_N_BASE + sit9531x_input_pair(index);=0A= + return sit9531x_input_pair(index);=0A= +}=0A= +=0A= static inline u8 sit9531x_hw_src_input(u8 src)=0A= {=0A= if (src < SIT9531X_NUM_INPUT_PAIRS)=0A= @@ -243,6 +342,12 @@ static inline bool sit9531x_prio_src_usable(u8 src)=0A= return sit9531x_hw_src_input(src) !=3D SIT9531X_REF_INVALID;=0A= }=0A= =0A= +static inline const struct sit9531x_ref *=0A= +sit9531x_ref_state_get(const struct sit9531x_dev *sitdev, u8 index)=0A= +{=0A= + return &sitdev->ref[index];=0A= +}=0A= +=0A= static inline const struct sit9531x_out *=0A= sit9531x_out_state_get(const struct sit9531x_dev *sitdev, u8 index)=0A= {=0A= @@ -255,4 +360,10 @@ sit9531x_chan_state_get(const struct sit9531x_dev *sit= dev, u8 pll_idx)=0A= return &sitdev->chan[pll_idx];=0A= }=0A= =0A= +static inline bool sit9531x_chan_tracking(const struct sit9531x_chan *chan= )=0A= +{=0A= + return chan->locked && !chan->inner_lol && !chan->mode &&=0A= + !chan->ho_freeze && !chan->stale;=0A= +}=0A= +=0A= #endif /* _SIT9531X_CORE_H */=0A= diff --git a/drivers/dpll/sit9531x/dpll.c b/drivers/dpll/sit9531x/dpll.c=0A= index e9952e578fac..5d16183aa1ae 100644=0A= --- a/drivers/dpll/sit9531x/dpll.c=0A= +++ b/drivers/dpll/sit9531x/dpll.c=0A= @@ -34,10 +34,23 @@ sit9531x_dpll_is_xo_pin(const struct sit9531x_dpll_pin = *pin)=0A= pin->id =3D=3D SIT9531X_MAX_INPUTS;=0A= }=0A= =0A= +/*=0A= + * A frozen PLL with an empty table is in forced holdover; report holdover= only=0A= + * while its holdover memory is valid.=0A= + */=0A= +static enum dpll_lock_status=0A= +sit9531x_dpll_frozen_status(const struct sit9531x_chan *chan)=0A= +{=0A= + if (!chan->prio_mask && !chan->ho_valid)=0A= + return DPLL_LOCK_STATUS_UNLOCKED;=0A= +=0A= + return DPLL_LOCK_STATUS_HOLDOVER;=0A= +}=0A= +=0A= /*=0A= * Report the lock status from the last poll: outer LOL (page 0 reg 0x06),= PLL=0A= - * mode (PLL page reg 0x31), inner LOL (reg 0x92), holdover freeze (reg 0x= 0A)=0A= - * and holdover-valid (PLL page reg 0x06).=0A= + * mode (PLL page reg 0x31), inner LOL (reg 0x92), holdover freeze (reg 0x= 0A),=0A= + * holdover-valid (PLL page reg 0x06) and priority table.=0A= */=0A= static int=0A= sit9531x_dpll_lock_status_get(const struct dpll_device *dpll, void *dpll_p= riv,=0A= @@ -71,7 +84,7 @@ sit9531x_dpll_lock_status_get(const struct dpll_device *d= pll, void *dpll_priv,=0A= * The core reports the error detail only with an unlocked or=0A= * holdover status.=0A= */=0A= - *status =3D chan->ho_freeze ? DPLL_LOCK_STATUS_HOLDOVER :=0A= + *status =3D chan->ho_freeze ? sit9531x_dpll_frozen_status(chan) :=0A= DPLL_LOCK_STATUS_UNLOCKED;=0A= } else if (chan->mode) {=0A= /*=0A= @@ -84,8 +97,8 @@ sit9531x_dpll_lock_status_get(const struct dpll_device *d= pll, void *dpll_priv,=0A= * Test freeze before lock: a frozen PLL tracks no reference=0A= * whatever its outer loss-of-lock bit reads.=0A= */=0A= - *status =3D DPLL_LOCK_STATUS_HOLDOVER;=0A= - } else if (chan->locked) {=0A= + *status =3D sit9531x_dpll_frozen_status(chan);=0A= + } else if (sit9531x_chan_tracking(chan)) {=0A= if (chan->ho_valid)=0A= *status =3D DPLL_LOCK_STATUS_LOCKED_HO_ACQ;=0A= else=0A= @@ -156,6 +169,122 @@ const struct dpll_device_ops sit9531x_dpll_device_ops= =3D {=0A= .supported_modes_get =3D sit9531x_dpll_supported_modes_get,=0A= };=0A= =0A= +/*=0A= + * Pin-state contract. An input is SELECTABLE while listed in this PLL's= =0A= + * priority table and DISCONNECTED otherwise; CONNECTED is refused because= the=0A= + * device selects by priority. Operstate is ACTIVE when the device feeds t= he PLL=0A= + * this input (chan->routed_ref), the PLL is tracking and the lane has sig= nal;=0A= + * NO_SIGNAL on loss of signal; QUAL_FAILED on frequency drift; STANDBY=0A= + * otherwise. The routed reference is used because on loss of signal the d= evice=0A= + * falls back to another listed source and leaves the selection naming the= lost=0A= + * one. On manual input select, the selected input is CONNECTED: the one t= he=0A= + * select register names, or the one the PLL last tracked when the select = pins=0A= + * or the indirect choice pick it; a state request is refused. The XO pin = is=0A= + * always CONNECTED.=0A= + */=0A= +=0A= +/* Caller must hold sitdev->multiop_lock. */=0A= +static void=0A= +sit9531x_dpll_selection_state_get(struct sit9531x_dev *sitdev,=0A= + const struct sit9531x_dpll *sitdpll,=0A= + u8 pin_id, enum dpll_pin_state *state)=0A= +{=0A= + const struct sit9531x_chan *chan;=0A= +=0A= + lockdep_assert_held(&sitdev->multiop_lock);=0A= +=0A= + chan =3D sit9531x_chan_state_get(sitdev, sitdpll->id);=0A= +=0A= + if (chan->manual_input) {=0A= + if (chan->manual_ref =3D=3D pin_id)=0A= + *state =3D DPLL_PIN_STATE_CONNECTED;=0A= + else=0A= + *state =3D DPLL_PIN_STATE_DISCONNECTED;=0A= + return;=0A= + }=0A= +=0A= + if (chan->prio_mask & BIT(sit9531x_input_hw_src(pin_id)))=0A= + *state =3D DPLL_PIN_STATE_SELECTABLE;=0A= + else=0A= + *state =3D DPLL_PIN_STATE_DISCONNECTED;=0A= +}=0A= +=0A= +/* Caller must hold sitdev->multiop_lock. */=0A= +static bool=0A= +sit9531x_dpll_selection_active(struct sit9531x_dev *sitdev,=0A= + const struct sit9531x_dpll *sitdpll, u8 pin_id)=0A= +{=0A= + const struct sit9531x_chan *chan;=0A= +=0A= + lockdep_assert_held(&sitdev->multiop_lock);=0A= +=0A= + chan =3D sit9531x_chan_state_get(sitdev, sitdpll->id);=0A= +=0A= + if (chan->routed_ref !=3D pin_id || !sit9531x_chan_tracking(chan))=0A= + return false;=0A= +=0A= + /*=0A= + * Do not report a lane without signal as locked, whatever the lock bit= =0A= + * says; the PLL is about to switch away from it.=0A= + */=0A= + if (pin_id < sitdev->info->num_inputs &&=0A= + sit9531x_ref_state_get(sitdev, pin_id)->los)=0A= + return false;=0A= +=0A= + return true;=0A= +}=0A= +=0A= +/* Caller must hold sitdev->multiop_lock. */=0A= +static void=0A= +sit9531x_dpll_selection_operstate_get(struct sit9531x_dev *sitdev,=0A= + const struct sit9531x_dpll *sitdpll,=0A= + u8 pin_id,=0A= + enum dpll_pin_operstate *operstate)=0A= +{=0A= + const struct sit9531x_ref *ref;=0A= +=0A= + lockdep_assert_held(&sitdev->multiop_lock);=0A= +=0A= + if (sit9531x_dpll_selection_active(sitdev, sitdpll, pin_id)) {=0A= + *operstate =3D DPLL_PIN_OPERSTATE_ACTIVE;=0A= + return;=0A= + }=0A= +=0A= + if (pin_id < sitdev->info->num_inputs) {=0A= + ref =3D sit9531x_ref_state_get(sitdev, pin_id);=0A= + if (ref->los) {=0A= + *operstate =3D DPLL_PIN_OPERSTATE_NO_SIGNAL;=0A= + return;=0A= + }=0A= + if (ref->qual_fail) {=0A= + *operstate =3D DPLL_PIN_OPERSTATE_QUAL_FAILED;=0A= + return;=0A= + }=0A= + }=0A= +=0A= + *operstate =3D DPLL_PIN_OPERSTATE_STANDBY;=0A= +}=0A= +=0A= +static int=0A= +sit9531x_dpll_input_pin_operstate_on_dpll_get(const struct dpll_pin *pin,= =0A= + void *pin_priv,=0A= + const struct dpll_device *dpll,=0A= + void *dpll_priv,=0A= + enum dpll_pin_operstate *state,=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= +=0A= + mutex_lock(&sitdev->multiop_lock);=0A= + sit9531x_dpll_selection_operstate_get(sitdev, sitdpll, dpin->id,=0A= + state);=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= +=0A= + return 0;=0A= +}=0A= +=0A= static int=0A= sit9531x_dpll_input_pin_direction_get(const struct dpll_pin *pin,=0A= void *pin_priv,=0A= @@ -168,8 +297,150 @@ sit9531x_dpll_input_pin_direction_get(const struct dp= ll_pin *pin,=0A= return 0;=0A= }=0A= =0A= +static int=0A= +sit9531x_dpll_input_pin_state_on_dpll_get(const struct dpll_pin *pin,=0A= + void *pin_priv,=0A= + const struct dpll_device *dpll,=0A= + void *dpll_priv,=0A= + enum dpll_pin_state *state,=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= +=0A= + mutex_lock(&sitdev->multiop_lock);=0A= + sit9531x_dpll_selection_state_get(sitdev, sitdpll, dpin->id, state);=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= +=0A= + return 0;=0A= +}=0A= +=0A= +/* A PLL on manual input select takes no state or priority request */=0A= +static int sit9531x_dpll_manual_select_refuse(struct netlink_ext_ack *exta= ck)=0A= +{=0A= + NL_SET_ERR_MSG(extack,=0A= + "PLL on manual input select; the select pins or register choose i= ts input");=0A= +=0A= + return -EOPNOTSUPP;=0A= +}=0A= +=0A= +/*=0A= + * The input receiver is shared by all DPLLs and is switched off when=0A= + * ref->pll_mask becomes empty.=0A= + */=0A= +static int=0A= +sit9531x_dpll_input_pin_state_on_dpll_set(const struct dpll_pin *pin,=0A= + void *pin_priv,=0A= + const struct dpll_device *dpll,=0A= + void *dpll_priv,=0A= + enum dpll_pin_state state,=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= + struct sit9531x_ref *ref =3D &sitdev->ref[dpin->id];=0A= + u8 hw_src =3D sit9531x_input_hw_src(dpin->id);=0A= + u8 pll_bit =3D BIT(sitdpll->id);=0A= + bool enabled_here =3D false;=0A= + int rc;=0A= +=0A= + mutex_lock(&sitdev->multiop_lock);=0A= +=0A= + /* Resume can find the PLL on manual select with these callbacks */=0A= + if (sit9531x_chan_state_get(sitdev, sitdpll->id)->manual_input) {=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= + return sit9531x_dpll_manual_select_refuse(extack);=0A= + }=0A= +=0A= + switch (state) {=0A= + case DPLL_PIN_STATE_DISCONNECTED:=0A= + if (!sit9531x_input_prio_present(sitdev, sitdpll->id, hw_src) &&=0A= + !ref->off_pending) {=0A= + rc =3D 0;=0A= + break;=0A= + }=0A= + rc =3D sit9531x_input_prio_remove(sitdev, sitdpll->id, hw_src);=0A= + if (rc && sit9531x_input_prio_present(sitdev, sitdpll->id,=0A= + hw_src))=0A= + break;=0A= + ref->pll_mask &=3D ~pll_bit;=0A= + if (!ref->pll_mask) {=0A= + int off_rc =3D sit9531x_input_disable(sitdev, dpin->id);=0A= +=0A= + if (off_rc && !rc)=0A= + rc =3D off_rc;=0A= + }=0A= + break;=0A= + case DPLL_PIN_STATE_CONNECTED:=0A= + NL_SET_ERR_MSG(extack,=0A= + "Device selects its reference by priority; use selectable");=0A= + rc =3D -EOPNOTSUPP;=0A= + break;=0A= + case DPLL_PIN_STATE_SELECTABLE:=0A= + /*=0A= + * The receiver can be off even when this PLL already lists the=0A= + * input.=0A= + */=0A= + if (!ref->enabled) {=0A= + rc =3D sit9531x_input_enable(sitdev, dpin->id);=0A= + if (rc)=0A= + break;=0A= + enabled_here =3D true;=0A= + }=0A= + rc =3D sit9531x_input_prio_add(sitdev, sitdpll->id, hw_src);=0A= + if (rc && !sit9531x_input_prio_present(sitdev, sitdpll->id,=0A= + hw_src)) {=0A= + if (enabled_here && !ref->pll_mask)=0A= + sit9531x_input_disable(sitdev, dpin->id);=0A= + break;=0A= + }=0A= + ref->pll_mask |=3D pll_bit;=0A= + break;=0A= + default:=0A= + rc =3D -EINVAL;=0A= + break;=0A= + }=0A= +=0A= + mutex_unlock(&sitdev->multiop_lock);=0A= +=0A= + if (rc =3D=3D -ENOSPC)=0A= + NL_SET_ERR_MSG(extack,=0A= + "Priority table is full of unique sources on this PLL");=0A= + else if (rc && rc !=3D -EOPNOTSUPP && rc !=3D -EINVAL)=0A= + NL_SET_ERR_MSG(extack, "Failed to set input pin state");=0A= +=0A= + return rc;=0A= +}=0A= +=0A= static const struct dpll_pin_ops sit9531x_dpll_input_pin_ops =3D {=0A= .direction_get =3D sit9531x_dpll_input_pin_direction_get,=0A= + .state_on_dpll_get =3D sit9531x_dpll_input_pin_state_on_dpll_get,=0A= + .state_on_dpll_set =3D sit9531x_dpll_input_pin_state_on_dpll_set,=0A= + .operstate_on_dpll_get =3D sit9531x_dpll_input_pin_operstate_on_dpll_get,= =0A= +};=0A= +=0A= +/*=0A= + * For a PLL on manual input select: the select pins or register choose th= e=0A= + * reference, so a state request is refused and the pin has no priority.= =0A= + */=0A= +static int=0A= +sit9531x_dpll_manual_pin_state_on_dpll_set(const struct dpll_pin *pin,=0A= + void *pin_priv,=0A= + const struct dpll_device *dpll,=0A= + void *dpll_priv,=0A= + enum dpll_pin_state state,=0A= + struct netlink_ext_ack *extack)=0A= +{=0A= + return sit9531x_dpll_manual_select_refuse(extack);=0A= +}=0A= +=0A= +static const struct dpll_pin_ops sit9531x_dpll_input_pin_manual_ops =3D {= =0A= + .direction_get =3D sit9531x_dpll_input_pin_direction_get,=0A= + .state_on_dpll_get =3D sit9531x_dpll_input_pin_state_on_dpll_get,=0A= + .state_on_dpll_set =3D sit9531x_dpll_manual_pin_state_on_dpll_set,=0A= + .operstate_on_dpll_get =3D sit9531x_dpll_input_pin_operstate_on_dpll_get,= =0A= };=0A= =0A= /* The XO feeds every PLL and is always connected. */=0A= @@ -210,10 +481,15 @@ static const struct dpll_pin_ops sit9531x_dpll_output= _pin_ops =3D {=0A= const struct dpll_pin_ops *=0A= sit9531x_dpll_pin_ops_get(const struct sit9531x_dpll_pin *pin)=0A= {=0A= + const struct sit9531x_dev *sitdev =3D pin->dpll->dev;=0A= +=0A= if (!sit9531x_dpll_is_input_pin(pin))=0A= return &sit9531x_dpll_output_pin_ops;=0A= if (sit9531x_dpll_is_xo_pin(pin))=0A= return &sit9531x_dpll_xo_pin_ops;=0A= + /* As read at probe, before any pin is registered */=0A= + if (sit9531x_chan_state_get(sitdev, pin->dpll->id)->manual_input)=0A= + return &sit9531x_dpll_input_pin_manual_ops;=0A= return &sit9531x_dpll_input_pin_ops;=0A= }=0A= =0A= @@ -252,11 +528,15 @@ void sit9531x_dpll_changes_check(struct sit9531x_dpll= *sitdpll)=0A= sitdpll->ntf_pending =3D false;=0A= =0A= list_for_each_entry(pin, &sitdpll->pins, list) {=0A= + enum dpll_pin_operstate operstate;=0A= const struct dpll_pin_ops *ops;=0A= enum dpll_pin_state state;=0A= bool changed;=0A= =0A= - /* Only references change state without a request */=0A= + /*=0A= + * Only references change state or operational state without a=0A= + * request.=0A= + */=0A= if (!sit9531x_dpll_is_input_pin(pin) ||=0A= sit9531x_dpll_is_xo_pin(pin))=0A= continue;=0A= @@ -267,9 +547,16 @@ void sit9531x_dpll_changes_check(struct sit9531x_dpll = *sitdpll)=0A= &state, NULL);=0A= if (rc)=0A= continue;=0A= + rc =3D ops->operstate_on_dpll_get(pin->dpll_pin, pin,=0A= + sitdpll->dpll_dev, sitdpll,=0A= + &operstate, NULL);=0A= + if (rc)=0A= + continue;=0A= =0A= - changed =3D pin->seen && state !=3D pin->pin_state;=0A= + changed =3D pin->seen && (state !=3D pin->pin_state ||=0A= + operstate !=3D pin->operstate);=0A= pin->pin_state =3D state;=0A= + pin->operstate =3D operstate;=0A= pin->seen =3D true;=0A= if (changed) {=0A= dev_dbg(sitdev->dev, "%s state changed\n", pin->label);=0A= diff --git a/drivers/dpll/sit9531x/dpll.h b/drivers/dpll/sit9531x/dpll.h=0A= index 92d434200333..f1634ef99602 100644=0A= --- a/drivers/dpll/sit9531x/dpll.h=0A= +++ b/drivers/dpll/sit9531x/dpll.h=0A= @@ -23,12 +23,14 @@ struct sit9531x_dpll_pin {=0A= struct list_head list;=0A= struct sit9531x_dpll *dpll;=0A= struct dpll_pin *dpll_pin;=0A= + const struct dpll_pin_ops *ops; /* as registered */=0A= dpll_tracker tracker;=0A= struct fwnode_handle *fwnode;=0A= char label[8]; /* "IN0", "OUT3" */=0A= enum dpll_pin_direction dir;=0A= u8 id; /* hardware index */=0A= enum dpll_pin_state pin_state;=0A= + enum dpll_pin_operstate operstate;=0A= bool seen; /* baseline taken by the poll */=0A= };=0A= =0A= diff --git a/drivers/dpll/sit9531x/prop.c b/drivers/dpll/sit9531x/prop.c=0A= index 495bed45c238..7cc690d92c60 100644=0A= --- a/drivers/dpll/sit9531x/prop.c=0A= +++ b/drivers/dpll/sit9531x/prop.c=0A= @@ -24,6 +24,22 @@=0A= /* Multiples of SIT9531X_OUT_FREQ_STEP_HZ an output runs above 800 MHz */= =0A= static const u8 sit9531x_out_freq_mult[] =3D { 15, 20, 24, 30, 32, 40, 48 = };=0A= =0A= +/*=0A= + * An input pin is registered with all four PLLs and takes a state request= =0A= + * on those found on automatic input selection at probe.=0A= + */=0A= +static u32 sit9531x_prop_input_caps(const struct sit9531x_dev *sitdev)=0A= +{=0A= + u8 i;=0A= +=0A= + for (i =3D 0; i < SIT9531X_NUM_PLLS; i++) {=0A= + if (!sit9531x_chan_state_get(sitdev, i)->manual_input)=0A= + return DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;=0A= + }=0A= +=0A= + return 0;=0A= +}=0A= +=0A= static void sit9531x_input_pin_label(struct sit9531x_dev *sitdev,=0A= struct sit9531x_pin_props *props, u8 id)=0A= {=0A= @@ -149,7 +165,7 @@ sit9531x_pin_props_get(struct sit9531x_dev *sitdev,=0A= /* INTSYNC destination: a reference the PLL can lock to. */=0A= props->dpll_props.type =3D DPLL_PIN_TYPE_INT_OSCILLATOR;=0A= props->dpll_props.capabilities =3D=0A= - DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;=0A= + sit9531x_prop_input_caps(sitdev);=0A= curr_freq =3D 0;=0A= } else if (sync_out) {=0A= /* INTSYNC source: driving it is not a reference selection */=0A= @@ -164,7 +180,7 @@ sit9531x_pin_props_get(struct sit9531x_dev *sitdev,=0A= } else if (dir =3D=3D DPLL_PIN_DIRECTION_INPUT) {=0A= props->dpll_props.type =3D DPLL_PIN_TYPE_EXT;=0A= props->dpll_props.capabilities =3D=0A= - DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;=0A= + sit9531x_prop_input_caps(sitdev);=0A= curr_freq =3D sitdev->ref[index].freq;=0A= } else {=0A= props->dpll_props.type =3D DPLL_PIN_TYPE_EXT;=0A= diff --git a/drivers/dpll/sit9531x/regs.h b/drivers/dpll/sit9531x/regs.h=0A= index 52515e7e591c..8f0e9593022a 100644=0A= --- a/drivers/dpll/sit9531x/regs.h=0A= +++ b/drivers/dpll/sit9531x/regs.h=0A= @@ -65,16 +65,31 @@=0A= * CLK_ACTIVESEL_PLL.=0A= */=0A= #define SIT9531X_PRIO_MAX_SLOTS 11=0A= +/* Number of source encodings (0-11), unrelated to the slot count */=0A= +#define SIT9531X_PRIO_NUM_SRC 12=0A= #define SIT9531X_PRIO_NIBBLE_MASK 0x0F=0A= #define SIT9531X_PRIO_HI_SHIFT 4=0A= +/* Codes 4 and 11 both mean no source; the driver writes 4 to empty a slot= . */=0A= +#define SIT9531X_PRIO_SRC_NONE 4=0A= #define SIT9531X_PRIO_SRC_OCXO 5=0A= #define SIT9531X_PRIO_SRC_INTSYNC 6=0A= #define SIT9531X_PRIO_SRC_N_BASE 7=0A= +=0A= /*=0A= - * Low nibble of the last priority register: CLK_ACTIVESEL_PLL, the PLL's = active=0A= - * reference, in the same encoding.=0A= + * PRG_Directives_GENERIC_0; every page has a copy at offset 0x0F:=0A= + * bit 6 proceed from the PRG_CMD state to loop lock / active state=0A= + * bit 4 copy the written values into the active NVM bank=0A= + * bit 3 read the efuse into the volatile registers=0A= + * bit 2 program the efuse (the driver never issues it)=0A= + * bit 1 small change update=0A= + * bit 0 escape to the PRG_CMD state=0A= */=0A= -#define SIT9531X_PRIO_ACTIVESEL_OFF 5=0A= +#define SIT9531X_REG_GLOBAL_UPDATE SIT9531X_REG(0x00, 0x0F)=0A= +#define SIT9531X_SMALL_UPDATE_CMD 0x02=0A= +=0A= +/* PLL holdover control (PLL page offset) */=0A= +#define SIT9531X_PLL_REG_HO_CTRL 0x6F=0A= +#define SIT9531X_PLL_HO_FORCE_BIT 4=0A= =0A= /* One bit per input PAIR (bit 0 =3D CLKIN0, ..., bit 3 =3D CLKIN3) */=0A= #define SIT9531X_REG_IN_DE_FORCE SIT9531X_REG(0x02, 0xE8)=0A= @@ -142,6 +157,29 @@=0A= =0A= #define SIT9531X_PLL_STATUS_OUTER_DIS BIT(5)=0A= =0A= +/*=0A= + * Writing the key unlocks the page's debug registers; writing zero locks = them.=0A= + */=0A= +#define SIT9531X_PLL_REG_DEBUG 0xBD=0A= +#define SIT9531X_PLL_DEBUG_UNLOCK 0xC3=0A= +#define SIT9531X_PLL_DEBUG_LOCK 0x00=0A= +=0A= +/*=0A= + * The address register selects the block the data register reports. A dat= a read=0A= + * returns what the previous read latched; the documented procedures read = it=0A= + * three times.=0A= + */=0A= +#define SIT9531X_PLL_REG_DBG_STATUS_ADDR 0xD1=0A= +#define SIT9531X_PLL_REG_DBG_STATUS_DATA 0xD0=0A= +#define SIT9531X_DBG_STATUS_READS 3=0A= +=0A= +/*=0A= + * Low nibble: the source the input subsystem routes to the PLL, in the=0A= + * priority-table encoding.=0A= + */=0A= +#define SIT9531X_DBG_STATUS_ROUTED_SRC 0xB0=0A= +#define SIT9531X_DBG_ROUTED_SRC_MASK GENMASK(3, 0)=0A= +=0A= /*=0A= * PLL_CONFIG1F_PLL bit 6: manual active select, no priority arbitration. = The=0A= * register is GUI generated; the driver only reads it.=0A= @@ -159,9 +197,11 @@=0A= /*=0A= * GPIO_INPUT_FUNC_CTRL5..8, one per PLL: with bit 4 set the manual input = is the=0A= * low nibble, otherwise the input-select pins. Bit 6 enables the indirect= =0A= - * choice and bit 5 picks active or spare; the driver does not decode them= .=0A= + * choice and bit 5 picks active or spare; the driver does not decode them= and=0A= + * takes the input of a PLL on the pins or on the indirect choice as unkno= wn.=0A= */=0A= #define SIT9531X_REG_MAN_IN_SEL(_pll) SIT9531X_REG(0x00, 0xE8 + (_pll))=0A= +#define SIT9531X_MAN_IN_SEL_INDIRECT BIT(6)=0A= #define SIT9531X_MAN_IN_SEL_FROM_REG BIT(4)=0A= #define SIT9531X_MAN_IN_SEL_MASK GENMASK(3, 0)=0A= =0A= @@ -172,6 +212,17 @@=0A= #define SIT9531X_PLL_REG_STATUS_1 0x06=0A= #define SIT9531X_PLL_STATUS_1_HO_VALID BIT(2)=0A= =0A= +/*=0A= + * Clock monitor status, one nibble per input lane; the lower-numbered inp= ut of=0A= + * each register is in the low nibble.=0A= + */=0A= +#define SIT9531X_CLKMON_P_STATUS_01 SIT9531X_REG(0x06, 0x02)=0A= +#define SIT9531X_CLKMON_P_STATUS_23 SIT9531X_REG(0x06, 0x06)=0A= +#define SIT9531X_CLKMON_N_STATUS_01 SIT9531X_REG(0x06, 0x92)=0A= +#define SIT9531X_CLKMON_N_STATUS_23 SIT9531X_REG(0x06, 0x96)=0A= +#define SIT9531X_CLKMON_FINE_DRIFT BIT(0)=0A= +#define SIT9531X_CLKMON_COARSE_DRIFT BIT(1)=0A= +#define SIT9531X_CLKMON_LOSS BIT(2)=0A= #define SIT9531X_CLKMON_P_NOTIF_01 SIT9531X_REG(0x06, 0x03)=0A= #define SIT9531X_CLKMON_P_NOTIF_23 SIT9531X_REG(0x06, 0x07)=0A= =0A= -- =0A= 2.39.2 (Apple Git-143)=0A= =0A=