From patchwork Tue Jun 28 22:13:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 585674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5CF3C433EF for ; Tue, 28 Jun 2022 22:14:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230249AbiF1WOi (ORCPT ); Tue, 28 Jun 2022 18:14:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbiF1WO2 (ORCPT ); Tue, 28 Jun 2022 18:14:28 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80074.outbound.protection.outlook.com [40.107.8.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABDA334BA2; Tue, 28 Jun 2022 15:14:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iPnmcvqNrETsshstt+Gs57zEJDswvWmu2JiN8AgqAkjZbKSyJPBp7I0+S0SfwvRRp/vRHETHpkqibGrFBIS1ICuoSHkOrpjyhzD2m7GG1VEwfFxR54jhvKIuBjC51tsYJ9yczm6/9JVdqahRIPXnltElIdvJYuxPBSwOyZk+on4vIxqpb9WpWOoTEi1JZ9TkWOlSI5GnLjMlpHjSuHwVcei4uSBNxjrqVu8Lerm+HIh6ri+/3GMuSJKO3Ii9bwLV47bd+PVP3XirYcq6GuekKWDO9+QV3d6WIS9nOeLBPSI5lsnG1yAV376K/VzapaysNchnoTnd5D0MrxDURMeqig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oNBB+gwuLH9EjBRC8EkMePDCkfdtxLDNgHDR4IM0L5M=; b=culEfWa2VFHBxww05uf8oa8biLZc9maRQIWlAMC/phMA6uqstfq4Q6lmIQBhjyFOU7f0GaWwcrTU3nAA8jHMXNWc/w8Kh9tbVLwpBakhbxsyob+Ios6Gai2yCUDjTbsJ6rbIqAxZcd/UiyKtpf92tSZdmRNgU2Iji25ibNClSpt1axSxCU7e02bZQfeMe9ZMt451+/dkUtiNnsIcPB2CAJy9BHBTBE/0pUV/EKI3jnj1bv6ElYA8OD5YAT2uH6+5KPtIQpwTk5eZ9Fz/AjvKmYmgDC26cwh1YrpLbLkzz6SfVW3qUIXV0VHmwaO44ui28NyhWGbnAN1/VaIynl/FPg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oNBB+gwuLH9EjBRC8EkMePDCkfdtxLDNgHDR4IM0L5M=; b=JfAvV1dF/2Ja8T6QkO5tk3G5SwLeDc+jGeSdeFqiD+591mdq4+30M624shh0gDpn+tqyg4ZPPIFG+E5Jhni6CLqrixEzIIxBXspD/Nas77LkaNJ5B/o9yb71ofaw7lFD1AhXRUAPC/FrTrVCEV82Bj9StfqnWfJSAZc1Ov9lAnSfxU5BApmEwX7MVgc2GRFfStYuMso6VIYIYDBdVpnIJScPo1IgAnRBqV+lpakCJOgtuId+MFX3si/ekso7JqiyGTtGnIaU9NqxgFixldlxhFS8onhFivnvoJ+ikWC9rZdjrs0fzsAi0PedEFfGmocT/HomEQFQ9THVlFbfqmSySA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) by AS8PR03MB7399.eurprd03.prod.outlook.com (2603:10a6:20b:2e2::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.18; Tue, 28 Jun 2022 22:14:24 +0000 Received: from DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::757e:b75f:3449:45b1]) by DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::757e:b75f:3449:45b1%6]) with mapi id 15.20.5373.018; Tue, 28 Jun 2022 22:14:24 +0000 From: Sean Anderson To: "David S . Miller" , Jakub Kicinski , Madalin Bucur , netdev@vger.kernel.org Cc: Russell King , Paolo Abeni , linux-arm-kernel@lists.infradead.org, Eric Dumazet , linux-kernel@vger.kernel.org, Sean Anderson , Krzysztof Kozlowski , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH net-next v2 03/35] dt-bindings: net: fman: Add additional interface properties Date: Tue, 28 Jun 2022 18:13:32 -0400 Message-Id: <20220628221404.1444200-4-sean.anderson@seco.com> X-Mailer: git-send-email 2.35.1.1320.gc452695387.dirty In-Reply-To: <20220628221404.1444200-1-sean.anderson@seco.com> References: <20220628221404.1444200-1-sean.anderson@seco.com> X-ClientProxiedBy: BL1P222CA0011.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::16) To DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3227cfc8-f545-4e48-d72a-08da59538ec4 X-MS-TrafficTypeDiagnostic: AS8PR03MB7399:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OKOtJAsce2KU+Y37ei39130FhmwDWIv+A7xKvP7qMsLLn66VLOvydqWosEXKT7PGVTsuuze4EKtPvdjcnPM7QmfUk1uZVoRFTyir9oXNNdVyr/djwm+zu6jhI6viAZY67oM9viT9dRjF177JA/XtjwQg7eqbPvd0xIFmXd1sOSG3pOZlWPZ4juw09svKPme8eCTS61eRDx7D4EKu+4Dj1RYTGoJ/WldmActXyamQiq3IUTVUh4LaXKqlZ6Fff7ad/izsg2lNRGVM2NPRkiG1j4s51g8PgjgURSJuvNIG6iZRDrh4SE1MWVTvSJhSD6FH9c/fYdUNVsk/j3G5fNQ0CgE/qJOKjdFDrjd7wMvPERue0hCtK7hPTIT3D6CiNJDlzyGwbX6zMaQMv7eeS1StTBVfEbCrWv6tLdJQ0mYTZW6V2EFuOE9bDHhtTHJsbdUZVOlYwvu+ZJgkI7RCcJGQaY9Ssew9x/0bjxv8SD0K/UWXR+mFziyBnHWGP6eDUGRkqltkty8fuU9niBPuxN//kMmCJ5tKg83GB4YPeCqE2BRICaUE1riq05bEpzdiVtpkwudvdm353+WVt3LcvHp+SEqPf90K45ai7NrEI6y8rqO+t9iw0WM8fpgYuHPVt8f6KO6G+Uv5EinHgv+B63Frz/Y+X/Mu8/HoJ1slg4lV65A0lT6tO2CvtgnbQo/vT1YNORBfTxJ2Yhqj3/TxskQY5IV5KIRdevAZ3PZyWlsi6qJ5uZs4VSMh7TmGxhMYPCBE9VMLnABTuzLfrSLgxewWYArjolZTgRB9q07uDcBGXqc= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4972.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(376002)(136003)(396003)(39850400004)(346002)(366004)(38100700002)(5660300002)(7416002)(44832011)(6512007)(6666004)(186003)(38350700002)(1076003)(83380400001)(86362001)(2906002)(66476007)(8936002)(6486002)(4326008)(41300700001)(8676002)(26005)(52116002)(36756003)(478600001)(66946007)(2616005)(6506007)(316002)(54906003)(66556008)(110136005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /u4+5wr1NlDsyNJMH65UBkqROZmbKtIc52cW21ByLmkVi5iuooQto8zSjpfiwkl5OXOicGoi6/+c1eCcg7JFAW+7gMiAH0ZnxUfnunIDsGc4BuHzqPCB79ONM0xMuVvVpN3RI/ahM7aEyDX2FZy8hGmGXXpa80DE4z9C1m0RAKniHyvX/4eHe+ikD4G4fW3KNuQG2bPiC2U1yS/C8J1dmEmAXTdyQtBl4f2/4QF8ynyatbF33W6SG0dL9PavIAQV8mDS3lGTA/0NmDQF5p5yhqqc6kE7cbQLFtOxD7xQ2XugLMy3BSuVt8rNQcQsrGVro1LiqJnH8jJDGklZIM+SeuckNmV7pNJAmY61XmW3lvg2VpguDNR66puqxTSgxnuonNlRJG7QG/aWq7Gdun/v1pRpUfCMl5SCxjqc2xD1Nopx81Y4K0AU2m4oYLLMT0+XpDMwSifUqVRdGjsQaHWx54PTA5NizRCwMWSdG/Hj/WyEMUO6dBk80Jj/sumeB20cugkPoCYAQCex84WX8/sRMST3rAe6AqeTt23c5i3iY40Fdv47WMNxM7bH8bg1SPuBo2mZPKG/cwoy2sCca6o4jkmGJGcH3SMx18ACZrtxwF4u/yihcwdCZNjSNJpyk8kIlikpmjZ6salEUBCRtj2pB4c9u43YU97/OH5yJV0esQHjwk5JbV+m46bnCBDeWGRjdgeBwjngVNlb4LkruGpSdmmOCu6ahEf7yHe57//eU/TGFpREgrTfJgJrwRXIUMbTmwQaNKEqCAUODARTCs+9E/UYLLFMkohn0roBJ1k+OJhlS5dtDSwUYlb+SenVOCy1l4kGC/D1heOVQh+fplhskuRp2AdVFfgiS40aIvZiMJ1c9mri+cZqzud2U0zns6gZhL7kdg9dQ4LF3hl4O5snFH1iVCoYtdedzowYlrUWJWZ5f8muxhd4MuwfuOXVSFMueM1IbAyCp7vvEzY3gAPSOVZRIFgIGBqWvpdwKQuLU2MUiMR+JqBJDa0ZlMi/jD7WcQUrC3lNKFH3P+WImnZQc3whKenbp0Qu0AtncI9P/T6j+gQ/Kf6dADgCjmd45V4i4WkkpoX+KWcw1HH5Vc7udE+Nh2AD0FPxMFgNhH/4h7vRyoWSMkkZE/z5C3lfBF+yNd8UGXllIaBboHNg2mSSszlerJOeQ4PDNz8qCtZTjLZqggtR3mBM/G39nbQnK9F7D6NRhjrC5Yyht3P7BBiLmj8zTumWoBn5c1vntxVE9EWQ1G2M5000hPcPkge282YLfuX/1nqKD1zw8hQ24wLC3Sllxw3RTE+4aakvHS21UJgmKTrxDuuQl+9ZQkYhBAvC2oHCVZtEKn9w0EohWybww1uS9NpPfFxIpGnwF8g3ZBuD1YeXVZzDM3jtakWm+EZHWoyY9DDe4TLd8TfpkolLZ3EpxfPZxq8LmIqz2ap8isBS4PKR0pMuKnc4HfjGdC7MKWZdCpG81eRrdS0BXI/b4nsQArKPD8ugXJEa6ENCpv72KzEq7YiLdLKfvPU1hrXsU7AV7FM5UZVgMQ1EjuxoItc2CAzjiFAs+aaihbgO0kXRwWa5zdWOFtgMkLghK+ajrrS4fIrEukHu3MgXb4B5qQ== X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3227cfc8-f545-4e48-d72a-08da59538ec4 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4972.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 22:14:24.0800 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: s+S8R0JwA6VofSPTyfjfYDj+riEnyiojUAgNOPwHwzWV3y4Bhv12WCS0DvK7Pn1shdTHyEbLEIKg0SPtvp9NuQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7399 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org At the moment, mEMACs are configured almost completely based on the phy-connection-type. That is, if the phy interface is RGMII, it assumed that RGMII is supported. For some interfaces, it is assumed that the RCW/bootloader has set up the SerDes properly. This is generally OK, but restricts runtime reconfiguration. The actual link state is never reported. To address these shortcomings, the driver will need additional information. First, it needs to know how to access the PCS/PMAs (in order to configure them and get the link status). The SGMII PCS/PMA is the only currently-described PCS/PMA. Add the XFI and QSGMII PCS/PMAs as well. The XFI (and 1GBase-KR) PCS/PMA is a c45 "phy" which sits on the same MDIO bus as SGMII PCS/PMA. By default they will have conflicting addresses, but they are also not enabled at the same time by default. Therefore, we can let the XFI PCS/PMA be the default when phy-connection-type is xgmii. This will allow for backwards-compatibility. QSGMII, however, cannot work with the current binding. This is because the QSGMII PCS/PMAs are only present on one MAC's MDIO bus. At the moment this is worked around by having every MAC write to the PCS/PMA addresses (without checking if they are present). This only works if each MAC has the same configuration, and only if we don't need to know the status. Because the QSGMII PCS/PMA will typically be located on a different MDIO bus than the MAC's SGMII PCS/PMA, there is no fallback for the QSGMII PCS/PMA. mEMACs (across all SoCs) support the following protocols: - MII - RGMII - SGMII, 1000Base-X, and 1000Base-KX - 2500Base-X (aka 2.5G SGMII) - QSGMII - 10GBase-R (aka XFI) and 10GBase-KR - XAUI and HiGig Each line documents a set of orthogonal protocols (e.g. XAUI is supported if and only if HiGig is supported). Additionally, - XAUI implies support for 10GBase-R - 10GBase-R is supported if and only if RGMII is not supported - 2500Base-X implies support for 1000Base-X - MII implies support for RGMII To switch between different protocols, we must reconfigure the SerDes. This is done by using the standard phys property. We can also use it to validate whether different protocols are supported (e.g. using phy_validate). This will work for serial protocols, but not RGMII or MII. Additionally, we still need to be compatible when there is no SerDes. While we can detect 10G support by examining the port speed (as set by fsl,fman-10g-port), we cannot determine support for any of the other protocols based on the existing binding. In fact, the binding works against us in some respects, because pcsphy-handle is required even if there is no possible PCS/PMA for that MAC. To allow for backwards- compatibility, we use a boolean-style property for RGMII (instead of presence/absence-style). When the property for RGMII is missing, we will assume that it is supported. The exception is MII, since no existing device trees use it (as far as I could tell). Unfortunately, QSGMII support will be broken for old device trees. There is nothing we can do about this because of the PCS/PMA situation (as described above). Signed-off-by: Sean Anderson --- Changes in v2: - Better document how we select which PCS to use in the default case .../bindings/net/fsl,fman-dtsec.yaml | 52 +++++++++++++++++-- .../devicetree/bindings/net/fsl-fman.txt | 5 +- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/net/fsl,fman-dtsec.yaml b/Documentation/devicetree/bindings/net/fsl,fman-dtsec.yaml index 809df1589f20..ecb772258164 100644 --- a/Documentation/devicetree/bindings/net/fsl,fman-dtsec.yaml +++ b/Documentation/devicetree/bindings/net/fsl,fman-dtsec.yaml @@ -85,9 +85,41 @@ properties: $ref: /schemas/types.yaml#/definitions/phandle description: A reference to the IEEE1588 timer + phys: + description: A reference to the SerDes lane(s) + maxItems: 1 + + phy-names: + items: + - const: serdes + pcsphy-handle: - $ref: /schemas/types.yaml#/definitions/phandle - description: A reference to the PCS (typically found on the SerDes) + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 1 + maxItems: 3 + description: | + A reference to the various PCSs (typically found on the SerDes). If + pcs-names is absent, and phy-connection-type is "xgmii", then the first + reference will be assumed to be for "xfi". Otherwise, if pcs-names is + absent, then the first reference will be assumed to be for "sgmii". + + pcs-names: + $ref: /schemas/types.yaml#/definitions/string-array + minItems: 1 + maxItems: 3 + contains: + enum: + - sgmii + - qsgmii + - xfi + description: The type of each PCS in pcsphy-handle. + + rgmii: + enum: [0, 1] + description: 1 indicates RGMII is supported, and 0 indicates it is not. + + mii: + description: If present, indicates that MII is supported. tbi-handle: $ref: /schemas/types.yaml#/definitions/phandle @@ -100,6 +132,10 @@ required: - fsl,fman-ports - ptp-timer +dependencies: + pcs-names: [pcsphy-handle] + mii: [rgmii] + allOf: - $ref: "ethernet-controller.yaml#" - if: @@ -117,7 +153,11 @@ allOf: const: fsl,fman-memac then: required: - - pcsphy-handle + - rgmii + else: + properties: + rgmii: false + mii: false unevaluatedProperties: false @@ -138,7 +178,11 @@ examples: reg = <0xe8000 0x1000>; fsl,fman-ports = <&fman0_rx_0x0c &fman0_tx_0x2c>; ptp-timer = <&ptp_timer0>; - pcsphy-handle = <&pcsphy4>; + pcsphy-handle = <&pcsphy4>, <&qsgmiib_pcs1>; + pcs-names = "sgmii", "qsgmii"; + rgmii = <0>; phy-handle = <&sgmii_phy1>; phy-connection-type = "sgmii"; + phys = <&serdes1 1>; + phy-names = "serdes"; }; diff --git a/Documentation/devicetree/bindings/net/fsl-fman.txt b/Documentation/devicetree/bindings/net/fsl-fman.txt index b9055335db3b..bda4b41af074 100644 --- a/Documentation/devicetree/bindings/net/fsl-fman.txt +++ b/Documentation/devicetree/bindings/net/fsl-fman.txt @@ -320,8 +320,9 @@ For internal PHY device on internal mdio bus, a PHY node should be created. See the definition of the PHY node in booting-without-of.txt for an example of how to define a PHY (Internal PHY has no interrupt line). - For "fsl,fman-mdio" compatible internal mdio bus, the PHY is TBI PHY. -- For "fsl,fman-memac-mdio" compatible internal mdio bus, the PHY is PCS PHY, - PCS PHY addr must be '0'. +- For "fsl,fman-memac-mdio" compatible internal mdio bus, the PHY is PCS PHY. + The PCS PHY address should correspond to the value of the appropriate + MDEV_PORT. EXAMPLE From patchwork Tue Jun 28 22:13:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 585673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63E0BC43334 for ; Tue, 28 Jun 2022 22:14:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231140AbiF1WOz (ORCPT ); Tue, 28 Jun 2022 18:14:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230351AbiF1WOw (ORCPT ); Tue, 28 Jun 2022 18:14:52 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80074.outbound.protection.outlook.com [40.107.8.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C110635A9E; Tue, 28 Jun 2022 15:14:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=df/r6V/21G7LPOURnuwXKt+Pythy+OeSta04v06tInJg6nNcFtmQh/f2V2YTqDqCr3o5gl2LL+JWGQtndV3igQkwbW9KdXvxtUgHGYFwjzlRXVKQ6ZbGFqySeiCCVwethPzLXvwXKRWTROdHIcJPU8nkJTRkD4Bm74M553uIGj0er+Db1mBPIlDp9e40KsHE6efHZKm48fL5l0n88uUdf8hGHJYIb/WwWNwympK/p0UUU9YhUxQn/5UCAXrrgaRZEIam2UXkiaei8rD4HDNnwyKcZ9WzPqr1W9TGJg+OJiFKCt1RdylVyNX/y39IeLrE2Jr9F4+NmsLgqiiFV+SBFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=856x6AmWuv6mpao6egh/sVqYqN1m+/CnEDCqvevmQ4Y=; b=afM6mnRR+EdbQclh17n11iAoAld/yFVOiI33ejrap5LIhJsN08rHYRw1eewWRORvIeKkN1LcBfPLa3xPyjvVJe0cmKbVFw2IsITgdpz55flCCB3i6PNI98qHSCi6nuWw+091Icij49kXpZ2lhQjXo2Ng1sWvHszu11/tlVHFGpbtUwnb/cuDhvEMwiGM3di0OeRIIU6Dm8mYZDfz69yAWYMcBASauztKzxMOPxy/w2ZJH6KU5IeLakZ1aVzsN2zFWBLkGnnNQCGU4QeoUpIWgGHXRCYTA5VuDaPXPRNrIF8Jw9tBj0P2ZYtn9iFOXaeGAPpLUANJROXTCfjD7bqQYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=856x6AmWuv6mpao6egh/sVqYqN1m+/CnEDCqvevmQ4Y=; b=vFAlHSZCvfs8gtLC2uP3OEYxTSED7KuOB2J5dtY6jyccVm+4ZNQdA/H3ClWuGuJWT2/74pE8kXyRrdbjQ3SNGEcZaGmU4sxItu2CgOGWawX60BT2wlO/t08Xuxy9TjhBKVbiHFrCm2K0jO7rEs8OZtEAk9GopAr3i78Uk0zcDFhYowxCYd98f7uyyUvPaQnzan6EhP1/+02k441ycA4JVpvBjXmW3OstLyZpGlC/y6eUwlysnJGgsSMyTRFtxJeWN2ukJmaJzNz2/sJvauFkroN3szpVuj7ovBIl3VJ7D9IFLAE9gi/FZW6gcPPzrTwHhu0ss5NmlBmtPAKhk/MI4g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) by AS8PR03MB7399.eurprd03.prod.outlook.com (2603:10a6:20b:2e2::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.18; Tue, 28 Jun 2022 22:14:26 +0000 Received: from DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::757e:b75f:3449:45b1]) by DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::757e:b75f:3449:45b1%6]) with mapi id 15.20.5373.018; Tue, 28 Jun 2022 22:14:26 +0000 From: Sean Anderson To: "David S . Miller" , Jakub Kicinski , Madalin Bucur , netdev@vger.kernel.org Cc: Russell King , Paolo Abeni , linux-arm-kernel@lists.infradead.org, Eric Dumazet , linux-kernel@vger.kernel.org, Sean Anderson , Ioana Ciornei , Jonathan Corbet , Kishon Vijay Abraham I , Krzysztof Kozlowski , Rob Herring , Vinod Koul , devicetree@vger.kernel.org, linux-doc@vger.kernel.org, linux-phy@lists.infradead.org Subject: [PATCH net-next v2 04/35] [RFC] phy: fsl: Add Lynx 10G SerDes driver Date: Tue, 28 Jun 2022 18:13:33 -0400 Message-Id: <20220628221404.1444200-5-sean.anderson@seco.com> X-Mailer: git-send-email 2.35.1.1320.gc452695387.dirty In-Reply-To: <20220628221404.1444200-1-sean.anderson@seco.com> References: <20220628221404.1444200-1-sean.anderson@seco.com> X-ClientProxiedBy: BL1P222CA0011.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::16) To DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7d2e2624-122c-4596-3654-08da5953902f X-MS-TrafficTypeDiagnostic: AS8PR03MB7399:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: euZjQs98V64o15SgfXsaupVBlBsG1n5iJX0PNFT76jqO5Qxp/LmQOfFd7xvrsQzSiRTzwTMD30jyw8/7CL2OcrO2EYbIF0CQKuEKPx9ghUR2I9TzzOpdnjiAr+orEq4OO1TXxEb/4D35MdsF0mtWzdIB4vKQZrYNAyADyuTGjdNbnjLfaWY+TnvKi3YaSkAQiM6IdtBvdI3ymr8U3kZ1+hpzHIrUBM7x33rdLhw1bavlLX6x3quz/2p+0AdjZCBtyCsrMI8BoZ4J8zF4RkW7k2nlscQws0ScO7rCypWrd+v9vhCVo9cJ8MbfgLtbaDB3R/yZsA6BKOzZR+H2JxddTO1oZGYXv1CGhENdwdRfLaGIu2krfFNNyh2bLtua1mubwjGTCTazQ0F1MulK3t5oUz+vxh5xoPWth4lfGB6z3lfC7RC3FSQKCCTf9TKWvo03YyJCptmThaKww99g184W+5JoeaNUwqnaeEGK54OMFBKdbc8vuzPqudhgGlM5i2JEh8MaFkFtllhqbtPy3GdQrJKtc3mBUyG44eGNu84Gl+luCUZYuB3mwJW39FPDnHp1xfCs7qicWBgqVXhyc2HjBmE1GPp3kJAq0PhpEQTqUO3E7eMyofFBXYw5rJJ1z5DuUFuQvl+I0mLRfPeQP1rvITwDzCj2j1+ZcvAG+pfeeTA2nnWNBNexEDTnj9aXeGH+SRaZsAHXyPTg6tZniaYKO8NVBV9rXy7cVmMTDCp+M+wmEw06oteTtaYGBLkGc5bjbnAw095YCX6VKAkmfk/0k+BdNwCouF1MLolso/F44ChtmlSNdaOMFQD2asckGYxN X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4972.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(376002)(136003)(396003)(39850400004)(346002)(366004)(38100700002)(5660300002)(7416002)(44832011)(6512007)(6666004)(186003)(30864003)(38350700002)(1076003)(83380400001)(86362001)(2906002)(66476007)(8936002)(6486002)(4326008)(41300700001)(8676002)(26005)(52116002)(36756003)(478600001)(66946007)(2616005)(6506007)(316002)(54906003)(66556008)(110136005)(21314003)(579004)(559001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xeFxBXF+jsvYf32olORpdkl2BeN5r3Bm40e8JRYXi6Htlqadfz7KwwUPpS2NOvFJvALPdRA+8MldvxxFENgwEo2aHyeaaRJ1X9EbL+1ZbEXT42U/X0hNm4U2uO+RtQETzRo0uj2CCG5PUjAdF/aUyLpUvRv1UwCDkRByvtNxQa+sjCnNbDDsvxpHwiz+U6bz8/0hqhLuR320PQL4lPiHOlp0W5woKe7oItAzXVcSk0ESQP2WyE8583uYz8U6ZAYizGZnPj2Wydpll9jigoUm70PVfwoEdrQS1eOV4dMp+ZzFqZo/nOrhp3/6mZMm2SeGdR/N6BS4xRpbNbpBsj7plr2/zTmmguNWnmOdnRpzdtSaHIo9/xiuMn/M0Fu+iPWOZBdDLlUs18VCSmkrIF4IeiEzDkXz8Gv4/ZuwRZORnZEOiLxeRUH3/Ub5nRT6npB9AejuAf/zIpwO1/WebT2knAi8klH25cyWn4vC3K2DMKFpKBv6lVK4FLTV75Sk/JxDLwsmp0qwpepvgOx8FHGVPlZ9fl7eFwk/2aYb4NXbI3lAcZUZHPXQe4Jjir0LgqHYDGmJ2PIOmsfPqcJLFPDFA5TpWGkiiCg9gS6m8n4dxiX5NcmQxWN5hy9ZUmkfHN6W2cqgcOF3rPfC2xu6SMd1YPBoWScslyFM0Ypb8YU6OufW8Cd+1ej9+oQVbk339hR9T6A5dlwM/lZNF2BKwlf/Znf3jJX38FhRz5vgn8Dp2jS80kK9SMNkEaJopnJWgmdVN2xvHU75uqEYq8P7SYuUfx9prsV57qEaGDKIuvNwBS5pB7uyEdtqGND22gW2CqmIzOP34P1aDddMWRymEgdpFyUOjJ5YPT/TWJl51sotdoAG+0smeVDYOjNfcBiTUSeNJkNqx8fuMxB5WORLiTghBCwo1eoFxT0fbJM9kboP/l0HlJ1EVntuz7KUFs8uEQHxrtJ6HUKJRBp/O9rlME/AQZm142C9tcQv8RTnCSoytndBiTEVhjHEOIAzWJf1QbF7mNvFk71KKljKdL44u6XPxVyFAiEUHcBMyBMmvfxpNaPx6Fgm5zqy8yCqc6nERGRjC9TZxwEydUgJPJ8fEOWsKO51k0odU8dXFS9hEWJc4qGJB7cR6L/1ZDS8uajxgmBTrD/AaKTPAZ1PYLEt5bZzhLxWt5kkpWxIhxNajsDgh+U4Kd0KstAr/7siRROP/2m4fOI3I0NAqyyUDSbXd3V7GnK4nmgV1BDh45sGPuQxej74egegh+rX9aCLQURC6Azzs+SbQI/Q0hfUnpqHYuwfoaLYPAIjmUAWxgUC29NJc0eFxE8uskJ5Qjpz7VMktR+HFJSr+OzWSqVs10P0MLcX+J8sbcgrvWG3XTtSWWeb7d1pyfY6XgDxeXmeqT2+4A/m+UBZtQRA7l57d/g/V/3a9MuLa0XL9+Op/zhYSij9PxL5dDFkiGWZf1FhZ4woFgrOiNL3KHJc7zVZY+M/pxcHHrJUfZsUOcfbaKlu5gjcbzuopFw8KijVLlouhVhHuF8BJjdcmanvdofu7awGCJJqyJRq9n24MJPzkCg4JM9rqKUNInXkAK8axfVAs9ZgwejJcjv39V5IXpqMYzIx5AtK6A== X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d2e2624-122c-4596-3654-08da5953902f X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4972.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 22:14:26.4235 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6evMe7BTkt92U9JminO6gjkVppmDJ/4MI4Bi9MAjkjy7QMuSpIG32UXf4AhnHI8rKoCyM8mmVP7quiKUn2BlSA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7399 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This adds support for the Lynx 10G "SerDes" devices found on various NXP QorIQ SoCs. There may be up to four SerDes devices on each SoC, each supporting up to eight lanes. Protocol support for each SerDes is highly heterogeneous, with each SoC typically having a totally different selection of supported protocols for each lane. Additionally, the SerDes devices on each SoC also have differing support. One SerDes will typically support Ethernet on most lanes, while the other will typically support PCIe on most lanes. There is wide hardware support for this SerDes. I have not done extensive digging, but it seems to be used on almost every QorIQ device, including the AMP and Layerscape series. Because each SoC typically has specific instructions and exceptions for its SerDes, I have limited the initial scope of this module to just the LS1046A. Additionally, I have only added support for Ethernet protocols. There is not a great need for dynamic reconfiguration for other protocols (SATA and PCIe handle rate changes in hardware), so support for them may never be added. Nevertheless, I have tried to provide an obvious path for adding support for other SoCs as well as other protocols. SATA just needs support for configuring LNmSSCR0. PCIe may need to configure the equalization registers. It also uses multiple lanes. I have tried to write the driver with multi-lane support in mind, so there should not need to be any large changes. Although there are 6 protocols supported, I have only tested SGMII and XFI. The rest have been implemented as described in the datasheet. The PLLs are modeled as clocks proper. This lets us take advantage of the existing clock infrastructure. I have not given the same treatment to the lane "clocks" (dividers) because they need to be programmed in-concert with the rest of the lane settings. One tricky thing is that the VCO (pll) rate exceeds 2^32 (maxing out at around 5GHz). This will be a problem on 32-bit platforms, since clock rates are stored as unsigned longs. To work around this, the pll clock rate is generally treated in units of kHz. The PLLs are configured rather interestingly. Instead of the usual direct programming of the appropriate divisors, the input and output clock rates are selected directly. Generally, the only restriction is that the input and output must be integer multiples of each other. This suggests some kind of internal look-up table. The datasheets generally list out the supported combinations explicitly, and not all input/output combinations are documented. I'm not sure if this is due to lack of support, or due to an oversight. If this becomes an issue, then some combinations can be blacklisted (or whitelisted). This may also be necessary for other SoCs which have more stringent clock requirements. The general API call list for this PHY is documented under the driver-api docs. I think this is rather standard, except that most driverts configure the mode (protocol) at xlate-time. Unlike some other phys where e.g. PCIe x4 will use 4 separate phys all configured for PCIe, this driver uses one phy configured to use 4 lanes. This is because while the individual lanes may be configured individually, the protocol selection acts on all lanes at once. Additionally, the order which lanes should be configured in is specified by the datasheet. To coordinate this, lanes are reserved in phy_init, and released in phy_exit. When getting a phy, if a phy already exists for those lanes, it is reused. This is to make things like QSGMII work. Four MACs will all want to ensure that the lane is configured properly, and we need to ensure they can all call phy_init, etc. There is refcounting for phy_init and phy_power_on, so the phy will only be powered on once. However, there is no refcounting for phy_set_mode. A "rogue" MAC could set the mode to something non-QSGMII and break the other MACs. Perhaps there is an opportunity for future enhancement here. This driver was written with reference to the LS1046A reference manual. However, it was informed by reference manuals for all processors with mEMACs, especially the T4240 (which appears to have a "maxed-out" configuration). Signed-off-by: Sean Anderson --- As noted later on in this series (in the phylink conversion patch), this driver does not quite function properly. When the bootloader is instructed to not configure the SerDes, only one lane comes up. Changes in v2: - Clear SGMIIaCR1_PCS_EN during probe - Fix not clearing group->pll after disabling it - Handle 1000Base-KX in lynx_proto_mode_prep - Power off lanes during probe - Rename LYNX_PROTO_UNKNOWN to LYNX_PROTO_NONE - Rename driver to Lynx 10G (etc.) - Support 1 and 2 phy-cells Documentation/driver-api/phy/index.rst | 1 + Documentation/driver-api/phy/qoriq.rst | 93 ++ MAINTAINERS | 6 + drivers/phy/freescale/Kconfig | 19 + drivers/phy/freescale/Makefile | 1 + drivers/phy/freescale/phy-fsl-lynx-10g.c | 1483 ++++++++++++++++++++++ 6 files changed, 1603 insertions(+) create mode 100644 Documentation/driver-api/phy/qoriq.rst create mode 100644 drivers/phy/freescale/phy-fsl-lynx-10g.c diff --git a/Documentation/driver-api/phy/index.rst b/Documentation/driver-api/phy/index.rst index 69ba1216de72..cc7ded8b969c 100644 --- a/Documentation/driver-api/phy/index.rst +++ b/Documentation/driver-api/phy/index.rst @@ -7,6 +7,7 @@ Generic PHY Framework .. toctree:: phy + qoriq samsung-usb2 .. only:: subproject and html diff --git a/Documentation/driver-api/phy/qoriq.rst b/Documentation/driver-api/phy/qoriq.rst new file mode 100644 index 000000000000..cbc2ac9ca4aa --- /dev/null +++ b/Documentation/driver-api/phy/qoriq.rst @@ -0,0 +1,93 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================= +QorIQ SerDes (Lynx 10G) +======================= + +Using this phy +-------------- + +The general order of calls should be:: + + [devm_][of_]phy_get() + phy_init() + phy_power_on() + phy_set_mode[_ext]() + ... + phy_power_off() + phy_exit() + [[of_]phy_put()] + +:c:func:`phy_get` just gets (or creates) a new :c:type:`phy` with the lanes +described in the phandle. :c:func:`phy_init` is what actually reserves the +lanes for use. Unlike some other drivers, when the phy is created, there is no +default protocol. :c:func:`phy_set_mode ` must be called in +order to set the protocol. + +Supporting SoCs +--------------- + +Each new SoC needs a :c:type:`struct lynx_conf ` for each SerDes. +The most important member is `modes`, which is an array of :c:type:`struct +lynx_mode `. Each "mode" represents a configuration which can be +programmed into a protocol control register. Modes can support multiple lanes +(such for PCIe x2 or x4), as well as multiple protocols (such as SGMII and +1000Base-KX). There are several helper macros to make configuring each mode +easier. It is important that the list of modes is complete, even if not all +protocols are supported. This lets the driver know which lanes are available, +and which have been configured by the RCW. + +If a protocol is missing, add it to :c:type:`enum lynx_protocol +`, and to ``UNSUPPORTED_PROTOS``. If the PCCR shifts/masks for +your protocol are missing, you will need to add them to +:c:func:`lynx_proto_mode_mask` and :c:func:`lynx_proto_mode_shift`. + +For example, the configuration for SerDes1 of the LS1046A is:: + + static const struct lynx_mode ls1046a_modes1[] = { + CONF_SINGLE(1, PCIE, 0x0, 1, 0b001), + CONF_1000BASEKX(0, 0x8, 0, 0b001), + CONF_SGMII25KX(1, 0x8, 1, 0b001), + CONF_SGMII25KX(2, 0x8, 2, 0b001), + CONF_SGMII25KX(3, 0x8, 3, 0b001), + CONF_SINGLE(1, QSGMII, 0x9, 2, 0b001), + CONF_XFI(2, 0xB, 0, 0b010), + CONF_XFI(3, 0xB, 1, 0b001), + }; + + static const struct lynx_conf ls1046a_conf1 = { + .modes = ls1046a_modes1, + .mode_count = ARRAY_SIZE(ls1046a_modes1), + .lanes = 4, + .endian = REGMAP_ENDIAN_BIG, + }; + +There is an additional set of configuration for SerDes2, which supports a +different set of modes. Both configurations should be added to the match +table:: + + { .compatible = "fsl,ls1046-serdes-1", .data = &ls1046a_conf1 }, + { .compatible = "fsl,ls1046-serdes-2", .data = &ls1046a_conf2 }, + +Supporting Protocols +-------------------- + +Each protocol is a combination of values which must be programmed into the lane +registers. To add a new protocol, first add it to :c:type:`enum lynx_protocol +`. If it is in ``UNSUPPORTED_PROTOS``, remove it. Add a new +entry to `lynx_proto_params`, and populate the appropriate fields. You may need +to add some new members to support new fields. Modify `lynx_lookup_proto` to +map the :c:type:`enum phy_mode ` to :c:type:`enum lynx_protocol +`. Ensure that :c:func:`lynx_proto_mode_mask` and +:c:func:`lynx_proto_mode_shift` have been updated with support for your +protocol. + +You may need to modify :c:func:`lynx_set_mode` in order to support your +procotol. This can happen when you have added members to :c:type:`struct +lynx_proto_params `. It can also happen if you have specific +clocking requirements, or protocol-specific registers to program. + +Internal API Reference +---------------------- + +.. kernel-doc:: drivers/phy/freescale/phy-fsl-lynx-10g.c diff --git a/MAINTAINERS b/MAINTAINERS index ca95b1833b97..ef65e2acdb48 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7977,6 +7977,12 @@ F: drivers/ptp/ptp_qoriq.c F: drivers/ptp/ptp_qoriq_debugfs.c F: include/linux/fsl/ptp_qoriq.h +FREESCALE QORIQ SERDES DRIVER +M: Sean Anderson +S: Maintained +F: Documentation/driver-api/phy/qoriq.rst +F: drivers/phy/freescale/phy-qoriq.c + FREESCALE QUAD SPI DRIVER M: Han Xu L: linux-spi@vger.kernel.org diff --git a/drivers/phy/freescale/Kconfig b/drivers/phy/freescale/Kconfig index f9c54cd02036..857b4d123515 100644 --- a/drivers/phy/freescale/Kconfig +++ b/drivers/phy/freescale/Kconfig @@ -38,3 +38,22 @@ config PHY_FSL_LYNX_28G found on NXP's Layerscape platforms such as LX2160A. Used to change the protocol running on SerDes lanes at runtime. Only useful for a restricted set of Ethernet protocols. + +config PHY_FSL_LYNX_10G + tristate "Freescale Layerscale Lynx 10G SerDes support" + select GENERIC_PHY + select REGMAP_MMIO + help + This adds support for the Lynx "SerDes" devices found on various QorIQ + SoCs. There may be up to four SerDes devices on each SoC, and each + device supports up to eight lanes. The SerDes is configured by default + by the RCW, but this module is necessary in order to support dynamic + reconfiguration (such as to support 1G and 10G ethernet on the same + interface). The hardware supports a variety of protocols, including + Ethernet, SATA, PCIe, and more exotic links such as Interlaken and + Aurora. This driver only supports Ethernet, but it will try not to + touch lanes configured for other protocols. + + If you have a QorIQ processor and want to dynamically reconfigure your + SerDes, say Y. If this driver is compiled as a module, it will be + named phy-qoriq. diff --git a/drivers/phy/freescale/Makefile b/drivers/phy/freescale/Makefile index 3518d5dbe8a7..aa4374ed217c 100644 --- a/drivers/phy/freescale/Makefile +++ b/drivers/phy/freescale/Makefile @@ -2,4 +2,5 @@ obj-$(CONFIG_PHY_FSL_IMX8MQ_USB) += phy-fsl-imx8mq-usb.o obj-$(CONFIG_PHY_MIXEL_MIPI_DPHY) += phy-fsl-imx8-mipi-dphy.o obj-$(CONFIG_PHY_FSL_IMX8M_PCIE) += phy-fsl-imx8m-pcie.o +obj-$(CONFIG_PHY_FSL_LYNX_10G) += phy-fsl-lynx-10g.o obj-$(CONFIG_PHY_FSL_LYNX_28G) += phy-fsl-lynx-28g.o diff --git a/drivers/phy/freescale/phy-fsl-lynx-10g.c b/drivers/phy/freescale/phy-fsl-lynx-10g.c new file mode 100644 index 000000000000..480bd493fbc2 --- /dev/null +++ b/drivers/phy/freescale/phy-fsl-lynx-10g.c @@ -0,0 +1,1483 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Sean Anderson + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define PLL_STRIDE 0x20 +#define PLLa(a, off) ((a) * PLL_STRIDE + (off)) +#define PLLaRSTCTL(a) PLLa(a, 0x00) +#define PLLaCR0(a) PLLa(a, 0x04) + +#define PLLaRSTCTL_RSTREQ BIT(31) +#define PLLaRSTCTL_RST_DONE BIT(30) +#define PLLaRSTCTL_RST_ERR BIT(29) +#define PLLaRSTCTL_PLLRST_B BIT(7) +#define PLLaRSTCTL_SDRST_B BIT(6) +#define PLLaRSTCTL_SDEN BIT(5) + +#define PLLaCR0_POFF BIT(31) +#define PLLaCR0_RFCLK_SEL GENMASK(30, 28) +#define PLLaCR0_PLL_LCK BIT(23) +#define PLLaCR0_FRATE_SEL GENMASK(19, 16) +#define PLLaCR0_DLYDIV_SEL GENMASK(1, 0) + +#define PCCR_BASE 0x200 +#define PCCR_STRIDE 0x4 +#define PCCRn(n) (PCCR_BASE + n * PCCR_STRIDE) + +#define PCCR0_PEXa_MASK GENMASK(2, 0) +#define PCCR0_PEXa_SHIFT(a) (28 - (a) * 4) + +#define PCCR2_SATAa_MASK GENMASK(2, 0) +#define PCCR2_SATAa_SHIFT(a) (28 - (a) * 4) + +#define PCCR8_SGMIIa_KX BIT(3) +#define PCCR8_SGMIIa_MASK GENMASK(3, 0) +#define PCCR8_SGMIIa_SHIFT(a) (28 - (a) * 4) + +#define PCCR9_QSGMIIa_MASK GENMASK(2, 0) +#define PCCR9_QSGMIIa_SHIFT(a) (28 - (a) * 4) + +#define PCCRB_XFIa_MASK GENMASK(2, 0) +#define PCCRB_XFIa_SHIFT(a) (28 - (a) * 4) + +#define LANE_BASE 0x800 +#define LANE_STRIDE 0x40 +#define LNm(m, off) (LANE_BASE + (m) * LANE_STRIDE + (off)) +#define LNmGCR0(m) LNm(m, 0x00) +#define LNmGCR1(m) LNm(m, 0x04) +#define LNmSSCR0(m) LNm(m, 0x0C) +#define LNmRECR0(m) LNm(m, 0x10) +#define LNmRECR1(m) LNm(m, 0x14) +#define LNmTECR0(m) LNm(m, 0x18) +#define LNmSSCR1(m) LNm(m, 0x1C) +#define LNmTTLCR0(m) LNm(m, 0x20) + +#define LNmGCR0_RPLL_LES BIT(31) +#define LNmGCR0_RRAT_SEL GENMASK(29, 28) +#define LNmGCR0_TPLL_LES BIT(27) +#define LNmGCR0_TRAT_SEL GENMASK(25, 24) +#define LNmGCR0_RRST_B BIT(22) +#define LNmGCR0_TRST_B BIT(21) +#define LNmGCR0_RX_PD BIT(20) +#define LNmGCR0_TX_PD BIT(19) +#define LNmGCR0_IF20BIT_EN BIT(18) +#define LNmGCR0_FIRST_LANE BIT(16) +#define LNmGCR0_TTRM_VM_SEL GENMASK(13, 12) +#define LNmGCR0_PROTS GENMASK(11, 7) + +#define LNmGCR0_RAT_SEL_SAME 0b00 +#define LNmGCR0_RAT_SEL_HALF 0b01 +#define LNmGCR0_RAT_SEL_QUARTER 0b10 +#define LNmGCR0_RAT_SEL_DOUBLE 0b11 + +#define LNmGCR0_PROTS_PCIE 0b00000 +#define LNmGCR0_PROTS_SGMII 0b00001 +#define LNmGCR0_PROTS_SATA 0b00010 +#define LNmGCR0_PROTS_XFI 0b01010 + +#define LNmGCR1_RDAT_INV BIT(31) +#define LNmGCR1_TDAT_INV BIT(30) +#define LNmGCR1_OPAD_CTL BIT(26) +#define LNmGCR1_REIDL_TH GENMASK(22, 20) +#define LNmGCR1_REIDL_EX_SEL GENMASK(19, 18) +#define LNmGCR1_REIDL_ET_SEL GENMASK(17, 16) +#define LNmGCR1_REIDL_EX_MSB BIT(15) +#define LNmGCR1_REIDL_ET_MSB BIT(14) +#define LNmGCR1_REQ_CTL_SNP BIT(13) +#define LNmGCR1_REQ_CDR_SNP BIT(12) +#define LNmGCR1_TRSTDIR BIT(7) +#define LNmGCR1_REQ_BIN_SNP BIT(6) +#define LNmGCR1_ISLEW_RCTL GENMASK(5, 4) +#define LNmGCR1_OSLEW_RCTL GENMASK(1, 0) + +#define LNmRECR0_GK2OVD GENMASK(27, 24) +#define LNmRECR0_GK3OVD GENMASK(19, 16) +#define LNmRECR0_GK2OVD_EN BIT(15) +#define LNmRECR0_GK3OVD_EN BIT(16) +#define LNmRECR0_BASE_WAND GENMASK(11, 10) +#define LNmRECR0_OSETOVD GENMASK(5, 0) + +#define LNmRECR0_BASE_WAND_OFF 0b00 +#define LNmRECR0_BASE_WAND_DEFAULT 0b01 +#define LNmRECR0_BASE_WAND_ALTERNATE 0b10 +#define LNmRECR0_BASE_WAND_OSETOVD 0b11 + +#define LNmTECR0_TEQ_TYPE GENMASK(29, 28) +#define LNmTECR0_SGN_PREQ BIT(26) +#define LNmTECR0_RATIO_PREQ GENMASK(25, 22) +#define LNmTECR0_SGN_POST1Q BIT(21) +#define LNmTECR0_RATIO_PST1Q GENMASK(20, 16) +#define LNmTECR0_ADPT_EQ GENMASK(13, 8) +#define LNmTECR0_AMP_RED GENMASK(5, 0) + +#define LNmTECR0_TEQ_TYPE_NONE 0b00 +#define LNmTECR0_TEQ_TYPE_PRE 0b01 +#define LNmTECR0_TEQ_TYPE_BOTH 0b10 + +#define LNmTTLCR0_FLT_SEL GENMASK(29, 24) + +#define PCS_STRIDE 0x10 +#define CR_STRIDE 0x4 +#define PCSa(a, base, cr) (base + (a) * PCS_STRIDE + (cr) * CR_STRIDE) + +#define PCSaCR1_MDEV_PORT GENMASK(31, 27) + +#define SGMII_BASE 0x1800 +#define SGMIIaCR1(a) PCSa(a, SGMII_BASE, 1) + +#define SGMIIaCR1_SGPCS_EN BIT(11) + +#define QSGMII_OFFSET 0x1880 +#define QSGMIIaCR1(a) PCSa(a, QSGMII_BASE, 1) + +#define XFI_OFFSET 0x1980 +#define XFIaCR1(a) PCSa(a, XFI_BASE, 1) + +/* The maximum number of lanes in a single serdes */ +#define MAX_LANES 8 + +enum lynx_protocol { + LYNX_PROTO_NONE = 0, + LYNX_PROTO_SGMII, + LYNX_PROTO_SGMII25, + LYNX_PROTO_1000BASEKX, + LYNX_PROTO_QSGMII, + LYNX_PROTO_XFI, + LYNX_PROTO_10GKR, + LYNX_PROTO_PCIE, /* Not implemented */ + LYNX_PROTO_SATA, /* Not implemented */ + LYNX_PROTO_LAST, +}; + +static const char lynx_proto_str[][16] = { + [LYNX_PROTO_NONE] = "unknown", + [LYNX_PROTO_SGMII] = "SGMII", + [LYNX_PROTO_SGMII25] = "2.5G SGMII", + [LYNX_PROTO_1000BASEKX] = "1000Base-KX", + [LYNX_PROTO_QSGMII] = "QSGMII", + [LYNX_PROTO_XFI] = "XFI", + [LYNX_PROTO_10GKR] = "10GBase-KR", + [LYNX_PROTO_PCIE] = "PCIe", + [LYNX_PROTO_SATA] = "SATA", +}; + +#define PROTO_MASK(proto) BIT(LYNX_PROTO_##proto) +#define UNSUPPORTED_PROTOS (PROTO_MASK(SATA) | PROTO_MASK(PCIE)) + +/** + * struct lynx_proto_params - Parameters for configuring a protocol + * @frate_khz: The PLL rate, in kHz + * @rat_sel: The divider to get the line rate + * @if20bit: Whether the proto is 20 bits or 10 bits + * @prots: Lane protocol select + * @reidl_th: Receiver electrical idle detection threshold + * @reidl_ex: Exit electrical idle filter + * @reidl_et: Enter idle filter + * @slew: Slew control + * @baseline_wander: Enable baseline wander correction + * @gain: Adaptive equalization gain override + * @offset_override: Adaptive equalization offset override + * @teq: Transmit equalization type (none, precursor, or precursor and + * postcursor). The next few values are only used for appropriate + * equalization types. + * @preq_ratio: Ratio of full swing transition bit to pre-cursor + * @postq_ratio: Ratio of full swing transition bit to first post-cursor. + * @adpt_eq: Transmitter Adjustments for 8G/10G + * @amp_red: Overall TX Amplitude Reduction + * @flt_sel: TTL configuration selector + */ +struct lynx_proto_params { + u32 frate_khz; + u8 rat_sel; + u8 prots; + u8 reidl_th; + u8 reidl_ex; + u8 reidl_et; + u8 slew; + u8 gain; + u8 baseline_wander; + u8 offset_override; + u8 teq; + u8 preq_ratio; + u8 postq_ratio; + u8 adpt_eq; + u8 amp_red; + u8 flt_sel; + bool if20bit; +}; + +static const struct lynx_proto_params lynx_proto_params[] = { + [LYNX_PROTO_SGMII] = { + .frate_khz = 5000000, + .rat_sel = LNmGCR0_RAT_SEL_QUARTER, + .if20bit = false, + .prots = LNmGCR0_PROTS_SGMII, + .reidl_th = 0b001, + .reidl_ex = 0b011, + .reidl_et = 0b100, + .slew = 0b01, + .gain = 0b1111, + .offset_override = 0b0011111, + .teq = LNmTECR0_TEQ_TYPE_NONE, + .adpt_eq = 0b110000, + .amp_red = 0b000110, + .flt_sel = 0b111001, + }, + [LYNX_PROTO_1000BASEKX] = { + .frate_khz = 5000000, + .rat_sel = LNmGCR0_RAT_SEL_QUARTER, + .if20bit = false, + .prots = LNmGCR0_PROTS_SGMII, + .slew = 0b01, + .gain = 0b1111, + .offset_override = 0b0011111, + .teq = LNmTECR0_TEQ_TYPE_NONE, + .adpt_eq = 0b110000, + .flt_sel = 0b111001, + }, + [LYNX_PROTO_SGMII25] = { + .frate_khz = 3125000, + .rat_sel = LNmGCR0_RAT_SEL_SAME, + .if20bit = false, + .prots = LNmGCR0_PROTS_SGMII, + .slew = 0b10, + .offset_override = 0b0011111, + .teq = LNmTECR0_TEQ_TYPE_PRE, + .postq_ratio = 0b00110, + .adpt_eq = 0b110000, + }, + [LYNX_PROTO_QSGMII] = { + .frate_khz = 5000000, + .rat_sel = LNmGCR0_RAT_SEL_SAME, + .if20bit = true, + .prots = LNmGCR0_PROTS_SGMII, + .slew = 0b01, + .offset_override = 0b0011111, + .teq = LNmTECR0_TEQ_TYPE_PRE, + .postq_ratio = 0b00110, + .adpt_eq = 0b110000, + .amp_red = 0b000010, + }, + [LYNX_PROTO_XFI] = { + .frate_khz = 5156250, + .rat_sel = LNmGCR0_RAT_SEL_DOUBLE, + .if20bit = true, + .prots = LNmGCR0_PROTS_XFI, + .slew = 0b01, + .baseline_wander = LNmRECR0_BASE_WAND_DEFAULT, + .offset_override = 0b1011111, + .teq = LNmTECR0_TEQ_TYPE_PRE, + .postq_ratio = 0b00011, + .adpt_eq = 0b110000, + .amp_red = 0b000111, + }, + [LYNX_PROTO_10GKR] = { + .frate_khz = 5156250, + .rat_sel = LNmGCR0_RAT_SEL_DOUBLE, + .prots = LNmGCR0_PROTS_XFI, + .slew = 0b01, + .baseline_wander = LNmRECR0_BASE_WAND_DEFAULT, + .offset_override = 0b1011111, + .teq = LNmTECR0_TEQ_TYPE_BOTH, + .preq_ratio = 0b0011, + .postq_ratio = 0b01100, + .adpt_eq = 0b110000, + }, +}; + +/** + * struct lynx_mode - A single configuration of a protocol controller + * @protos: A bitmask of the &enum lynx_protocol this mode supports + * @lanes: A bitmask of the lanes which will be used when this config is + * selected + * @pccr: The number of the PCCR which contains this mode + * @idx: The index of the protocol controller. For example, SGMIIB would have + * index 1. + * @cfg: The value to program into the controller to select this mode + * + * The serdes has multiple protocol controllers which can be each be selected + * independently. Depending on their configuration, they may use multiple lanes + * at once (e.g. AUI or PCIe x4). Additionally, multiple protocols may be + * supported by a single mode (XFI and 10GKR differ only in their protocol + * parameters). + */ +struct lynx_mode { + u16 protos; + u8 lanes; + u8 pccr; + u8 idx; + u8 cfg; +}; + +static_assert(LYNX_PROTO_LAST - 1 <= + sizeof_field(struct lynx_mode, protos) * BITS_PER_BYTE); +static_assert(MAX_LANES <= + sizeof_field(struct lynx_mode, lanes) * BITS_PER_BYTE); + +#define CONF(_lanes, _protos, _pccr, _idx, _cfg) { \ + .lanes = _lanes, \ + .protos = _protos, \ + .pccr = _pccr, \ + .idx = _idx, \ + .cfg = _cfg, \ +} + +#define CONF_SINGLE(lane, proto, pccr, idx, cfg) \ + CONF(BIT(lane), PROTO_MASK(proto), pccr, idx, cfg) + +#define CONF_1000BASEKX(lane, pccr, idx, cfg) \ + CONF(BIT(lane), PROTO_MASK(SGMII) | PROTO_MASK(1000BASEKX), \ + pccr, idx, cfg) + +#define CONF_SGMII25(lane, pccr, idx, cfg) \ + CONF(BIT(lane), PROTO_MASK(SGMII) | PROTO_MASK(SGMII25), \ + pccr, idx, cfg) + +#define CONF_SGMII25KX(lane, pccr, idx, cfg) \ + CONF(BIT(lane), \ + PROTO_MASK(SGMII) | PROTO_MASK(1000BASEKX) | PROTO_MASK(SGMII25), \ + pccr, idx, cfg) + +#define CONF_XFI(lane, pccr, idx, cfg) \ + CONF(BIT(lane), PROTO_MASK(XFI) | PROTO_MASK(10GKR), pccr, idx, cfg) + +/** + * struct lynx_conf - Configuration for a particular serdes + * @modes: Valid protocol controller configurations + * @mode_count: Number of modes in @modes + * @lanes: Number of lanes + * @endian: Endianness of the registers + */ +struct lynx_conf { + const struct lynx_mode *modes; + size_t mode_count; + unsigned int lanes; + enum regmap_endian endian; +}; + +struct lynx_priv; + +/** + * struct lynx_clk - Driver data for the PLLs + * @hw: The clock hardware + * @serdes: The parent serdes + * @idx: Which PLL this clock is for + */ +struct lynx_clk { + struct clk_hw hw; + struct lynx_priv *serdes; + unsigned int idx; +}; + +static struct lynx_clk *lynx_clk_hw_to_priv(struct clk_hw *hw) +{ + return container_of(hw, struct lynx_clk, hw); +} + +/** + * struct lynx_priv - Driver data for the serdes + * @lock: A lock protecting "common" registers in @regmap, as well as the + * members of this struct. Lane-specific registers are protected by the + * phy's lock. PLL registers are protected by the clock's lock. + * @pll: The PLL clocks + * @ref: The reference clocks for the PLLs + * @dev: The serdes device + * @regmap: The backing regmap + * @conf: The configuration for this serdes + * @used_lanes: Bitmap of the lanes currently used by phys + * @groups: List of the created groups + */ +struct lynx_priv { + struct mutex lock; + struct lynx_clk pll[2]; + struct clk *ref[2]; + struct device *dev; + struct regmap *regmap; + const struct lynx_conf *conf; + unsigned int used_lanes; + struct list_head groups; +}; + +/** + * struct lynx_group - Driver data for a group of lanes + * @groups: List of other groups; protected by @serdes->lock. + * @phy: The associated phy + * @serdes: The parent serdes + * @pll: The currently-used pll + * @first_lane: The first lane in the group + * @last_lane: The last lane in the group + * @proto: The currently-configured protocol + * @users: Number of current users; protected by @serdes->lock. + */ +struct lynx_group { + struct list_head groups; + struct phy *phy; + struct lynx_priv *serdes; + struct clk *pll; + unsigned int first_lane; + unsigned int last_lane; + enum lynx_protocol proto; + unsigned int users; +}; + +static u32 lynx_read(struct lynx_priv *serdes, u32 reg) +{ + unsigned int ret = 0; + + WARN_ON_ONCE(regmap_read(serdes->regmap, reg, &ret)); + return ret; +} + +static void lynx_write(struct lynx_priv *serdes, u32 val, u32 reg) +{ + WARN_ON_ONCE(regmap_write(serdes->regmap, reg, val)); +} + +/* XXX: The output rate is in kHz to avoid overflow on 32-bit arches */ + +static void lynx_pll_disable(struct clk_hw *hw) +{ + struct lynx_clk *clk = lynx_clk_hw_to_priv(hw); + struct lynx_priv *serdes = clk->serdes; + u32 rstctl = lynx_read(serdes, PLLaRSTCTL(clk->idx)); + + dev_dbg(clk->serdes->dev, "%s(pll%d)\n", __func__, clk->idx); + + rstctl &= ~PLLaRSTCTL_SDRST_B; + lynx_write(serdes, rstctl, PLLaRSTCTL(clk->idx)); + ndelay(50); + rstctl &= ~(PLLaRSTCTL_SDEN | PLLaRSTCTL_PLLRST_B); + lynx_write(serdes, rstctl, PLLaRSTCTL(clk->idx)); + ndelay(100); +} + +static int lynx_pll_enable(struct clk_hw *hw) +{ + struct lynx_clk *clk = lynx_clk_hw_to_priv(hw); + struct lynx_priv *serdes = clk->serdes; + u32 rstctl = lynx_read(serdes, PLLaRSTCTL(clk->idx)); + + dev_dbg(clk->serdes->dev, "%s(pll%d)\n", __func__, clk->idx); + + rstctl |= PLLaRSTCTL_RSTREQ; + lynx_write(serdes, rstctl, PLLaRSTCTL(clk->idx)); + + rstctl &= ~PLLaRSTCTL_RSTREQ; + rstctl |= PLLaRSTCTL_SDEN | PLLaRSTCTL_PLLRST_B | PLLaRSTCTL_SDRST_B; + lynx_write(serdes, rstctl, PLLaRSTCTL(clk->idx)); + + /* TODO: wait for the PLL to lock */ + + return 0; +} + +static int lynx_pll_is_enabled(struct clk_hw *hw) +{ + struct lynx_clk *clk = lynx_clk_hw_to_priv(hw); + struct lynx_priv *serdes = clk->serdes; + u32 rstctl = lynx_read(serdes, PLLaRSTCTL(clk->idx)); + + dev_dbg(clk->serdes->dev, "%s(pll%d)\n", __func__, clk->idx); + + return rstctl & PLLaRSTCTL_RST_DONE && !(rstctl & PLLaRSTCTL_RST_ERR); +} + +static const u32 rfclk_sel_map[8] = { + [0b000] = 100000000, + [0b001] = 125000000, + [0b010] = 156250000, + [0b011] = 150000000, +}; + +/** + * lynx_rfclk_to_sel() - Convert a reference clock rate to a selector + * @rate: The reference clock rate + * + * To allow for some variation in the reference clock rate, up to 100ppm of + * error is allowed. + * + * Return: An appropriate selector for @rate, or -%EINVAL. + */ +static int lynx_rfclk_to_sel(u32 rate) +{ + int ret; + + for (ret = 0; ret < ARRAY_SIZE(rfclk_sel_map); ret++) { + u32 rfclk_rate = rfclk_sel_map[ret]; + /* Allow an error of 100ppm */ + u32 error = rfclk_rate / 10000; + + if (rate > rfclk_rate - error && rate < rfclk_rate + error) + return ret; + } + + return -EINVAL; +} + +static const u32 frate_sel_map[16] = { + [0b0000] = 5000000, + [0b0101] = 3750000, + [0b0110] = 5156250, + [0b0111] = 4000000, + [0b1001] = 3125000, + [0b1010] = 3000000, +}; + +/** + * lynx_frate_to_sel() - Convert a VCO clock rate to a selector + * @rate_khz: The VCO frequency, in kHz + * + * Return: An appropriate selector for @rate_khz, or -%EINVAL. + */ +static int lynx_frate_to_sel(u32 rate_khz) +{ + int ret; + + for (ret = 0; ret < ARRAY_SIZE(frate_sel_map); ret++) + if (frate_sel_map[ret] == rate_khz) + return ret; + + return -EINVAL; +} + +static u32 lynx_pll_ratio(u32 frate_sel, u32 rfclk_sel) +{ + u64 frate; + u32 rfclk, error, ratio; + + frate = frate_sel_map[frate_sel] * (u64)HZ_PER_KHZ; + rfclk = rfclk_sel_map[rfclk_sel]; + + if (!frate || !rfclk) + return 0; + + ratio = div_u64_rem(frate, rfclk, &error); + if (!error) + return ratio; + return 0; +} + +static unsigned long lynx_pll_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct lynx_clk *clk = lynx_clk_hw_to_priv(hw); + struct lynx_priv *serdes = clk->serdes; + u32 cr0 = lynx_read(serdes, PLLaCR0(clk->idx)); + u32 frate_sel = FIELD_GET(PLLaCR0_FRATE_SEL, cr0); + u32 rfclk_sel = FIELD_GET(PLLaCR0_RFCLK_SEL, cr0); + unsigned long ret; + + dev_dbg(clk->serdes->dev, "%s(pll%d, %lu)\n", __func__, + clk->idx, parent_rate); + + ret = mult_frac(parent_rate, lynx_pll_ratio(frate_sel, rfclk_sel), + HZ_PER_KHZ); + return ret; +} + +static long lynx_pll_round_rate(struct clk_hw *hw, unsigned long rate_khz, + unsigned long *parent_rate) +{ + int frate_sel, rfclk_sel; + struct lynx_clk *clk = lynx_clk_hw_to_priv(hw); + u32 ratio; + + dev_dbg(clk->serdes->dev, "%s(pll%d, %lu, %lu)\n", __func__, + clk->idx, rate_khz, *parent_rate); + + frate_sel = lynx_frate_to_sel(rate_khz); + if (frate_sel < 0) + return frate_sel; + + rfclk_sel = lynx_rfclk_to_sel(*parent_rate); + if (rfclk_sel >= 0) { + ratio = lynx_pll_ratio(frate_sel, rfclk_sel); + if (ratio) + return mult_frac(*parent_rate, ratio, HZ_PER_KHZ); + } + + for (rfclk_sel = 0; + rfclk_sel < ARRAY_SIZE(rfclk_sel_map); + rfclk_sel++) { + ratio = lynx_pll_ratio(frate_sel, rfclk_sel); + if (ratio) { + *parent_rate = rfclk_sel_map[rfclk_sel]; + return mult_frac(*parent_rate, ratio, HZ_PER_KHZ); + } + } + + return -EINVAL; +} + +static int lynx_pll_set_rate(struct clk_hw *hw, unsigned long rate_khz, + unsigned long parent_rate) +{ + int frate_sel, rfclk_sel, ret; + struct lynx_clk *clk = lynx_clk_hw_to_priv(hw); + struct lynx_priv *serdes = clk->serdes; + u32 ratio, cr0 = lynx_read(serdes, PLLaCR0(clk->idx)); + + dev_dbg(clk->serdes->dev, "%s(pll%d, %lu, %lu)\n", __func__, + clk->idx, rate_khz, parent_rate); + + frate_sel = lynx_frate_to_sel(rate_khz); + if (frate_sel < 0) + return frate_sel; + + /* First try the existing rate */ + rfclk_sel = lynx_rfclk_to_sel(parent_rate); + if (rfclk_sel >= 0) { + ratio = lynx_pll_ratio(frate_sel, rfclk_sel); + if (ratio) + goto got_rfclk; + } + + for (rfclk_sel = 0; + rfclk_sel < ARRAY_SIZE(rfclk_sel_map); + rfclk_sel++) { + ratio = lynx_pll_ratio(frate_sel, rfclk_sel); + if (ratio) { + ret = clk_set_rate(serdes->ref[clk->idx], + rfclk_sel_map[rfclk_sel]); + if (!ret) + goto got_rfclk; + } + } + + return ret; + +got_rfclk: + cr0 &= ~(PLLaCR0_RFCLK_SEL | PLLaCR0_FRATE_SEL); + cr0 |= FIELD_PREP(PLLaCR0_RFCLK_SEL, rfclk_sel); + cr0 |= FIELD_PREP(PLLaCR0_FRATE_SEL, frate_sel); + lynx_write(serdes, cr0, PLLaCR0(clk->idx)); + return 0; +} + +static const struct clk_ops lynx_pll_clk_ops = { + .enable = lynx_pll_enable, + .disable = lynx_pll_disable, + .is_enabled = lynx_pll_is_enabled, + .recalc_rate = lynx_pll_recalc_rate, + .round_rate = lynx_pll_round_rate, + .set_rate = lynx_pll_set_rate, +}; + +static struct clk_hw *lynx_clk_get(struct of_phandle_args *clkspec, void *data) +{ + struct lynx_priv *serdes = data; + + if (clkspec->args_count != 1) + return ERR_PTR(-EINVAL); + + if (clkspec->args[0] > 1) + return ERR_PTR(-EINVAL); + + return &serdes->pll[clkspec->args[0]].hw; +} + +/** + * lynx_lane_bitmap() - Get a bitmap for a group of lanes + * @group: The group of lanes + * + * Return: A mask containing all bits between @group->first and @group->last + */ +static unsigned int lynx_lane_bitmap(struct lynx_group *group) +{ + if (group->first_lane > group->last_lane) + return GENMASK(group->first_lane, group->last_lane); + else + return GENMASK(group->last_lane, group->first_lane); +} + +static int lynx_init(struct phy *phy) +{ + int ret = 0; + struct lynx_group *group = phy_get_drvdata(phy); + struct lynx_priv *serdes = group->serdes; + unsigned int lane_mask = lynx_lane_bitmap(group); + + mutex_lock(&serdes->lock); + if (serdes->used_lanes & lane_mask) + ret = -EBUSY; + else + serdes->used_lanes |= lane_mask; + mutex_unlock(&serdes->lock); + return ret; +} + +static int lynx_exit(struct phy *phy) +{ + struct lynx_group *group = phy_get_drvdata(phy); + struct lynx_priv *serdes = group->serdes; + + clk_disable_unprepare(group->pll); + clk_rate_exclusive_put(group->pll); + group->pll = NULL; + + mutex_lock(&serdes->lock); + serdes->used_lanes &= ~lynx_lane_bitmap(group); + mutex_unlock(&serdes->lock); + return 0; +} + +/* + * This is tricky. If first_lane=1 and last_lane=0, the condition will see 2, + * 1, 0. But the loop body will see 1, 0. We do this to avoid underflow. We + * can't pull the same trick when incrementing, because then we might have to + * start at -1 if (e.g.) first_lane = 0. + */ +#define for_range(val, start, end) \ + for (val = start < end ? start : start + 1; \ + start < end ? val <= end : val-- > end; \ + start < end ? val++ : 0) +#define for_each_lane(lane, group) \ + for_range(lane, group->first_lane, group->last_lane) +#define for_each_lane_reverse(lane, group) \ + for_range(lane, group->last_lane, group->first_lane) + +static int lynx_power_on(struct phy *phy) +{ + int i; + struct lynx_group *group = phy_get_drvdata(phy); + u32 gcr0; + + for_each_lane(i, group) { + gcr0 = lynx_read(group->serdes, LNmGCR0(i)); + gcr0 &= ~(LNmGCR0_RX_PD | LNmGCR0_TX_PD); + lynx_write(group->serdes, gcr0, LNmGCR0(i)); + + usleep_range(15, 30); + gcr0 |= LNmGCR0_RRST_B | LNmGCR0_TRST_B; + lynx_write(group->serdes, gcr0, LNmGCR0(i)); + } + + return 0; +} + +static void lynx_power_off_lane(struct lynx_priv *serdes, unsigned int lane) +{ + u32 gcr0 = lynx_read(serdes, LNmGCR0(lane)); + + gcr0 |= LNmGCR0_RX_PD | LNmGCR0_TX_PD; + gcr0 &= ~(LNmGCR0_RRST_B | LNmGCR0_TRST_B); + lynx_write(serdes, gcr0, LNmGCR0(lane)); +} + +static int lynx_power_off(struct phy *phy) +{ + unsigned int i; + struct lynx_group *group = phy_get_drvdata(phy); + + for_each_lane_reverse(i, group) + lynx_power_off_lane(group->serdes, i); + + return 0; +} + +/** + * lynx_lookup_proto() - Convert a phy-subsystem mode to a protocol + * @mode: The mode to convert + * @submode: The submode of @mode + * + * Return: A corresponding serdes-specific mode + */ +static enum lynx_protocol lynx_lookup_proto(enum phy_mode mode, int submode) +{ + switch (mode) { + case PHY_MODE_ETHERNET: + switch (submode) { + case PHY_INTERFACE_MODE_SGMII: + case PHY_INTERFACE_MODE_1000BASEX: + return LYNX_PROTO_SGMII; + case PHY_INTERFACE_MODE_2500BASEX: + return LYNX_PROTO_SGMII25; + case PHY_INTERFACE_MODE_QSGMII: + return LYNX_PROTO_QSGMII; + case PHY_INTERFACE_MODE_XGMII: + case PHY_INTERFACE_MODE_10GBASER: + return LYNX_PROTO_XFI; + case PHY_INTERFACE_MODE_10GKR: + return LYNX_PROTO_10GKR; + default: + return LYNX_PROTO_NONE; + } + /* Not implemented (yet) */ + case PHY_MODE_PCIE: + case PHY_MODE_SATA: + default: + return LYNX_PROTO_NONE; + } +} + +/** + * lynx_lookup_mode() - Get the mode for a group/protocol combination + * @group: The group of lanes to use + * @proto: The protocol to use + * + * Return: An appropriate mode to use, or %NULL if none match. + */ +static const struct lynx_mode *lynx_lookup_mode(struct lynx_group *group, + enum lynx_protocol proto) +{ + int i; + const struct lynx_conf *conf = group->serdes->conf; + + for (i = 0; i < conf->mode_count; i++) { + const struct lynx_mode *mode = &conf->modes[i]; + + if (BIT(proto) & mode->protos && + lynx_lane_bitmap(group) == mode->lanes) + return mode; + } + + return NULL; +} + +static int lynx_validate(struct phy *phy, enum phy_mode phy_mode, int submode, + union phy_configure_opts *opts) +{ + enum lynx_protocol proto; + struct lynx_group *group = phy_get_drvdata(phy); + const struct lynx_mode *mode; + + proto = lynx_lookup_proto(phy_mode, submode); + if (proto == LYNX_PROTO_NONE) + return -EINVAL; + + /* Nothing to do */ + if (proto == group->proto) + return 0; + + mode = lynx_lookup_mode(group, proto); + if (!mode) + return -EINVAL; + + return 0; +} + +/** + * lynx_proto_mode_mask() - Get the mask for a PCCR config + * @mode: The mode to use + * + * Return: The mask, shifted down to the lsb. + */ +static u32 lynx_proto_mode_mask(const struct lynx_mode *mode) +{ + switch (mode->pccr) { + case 0x0: + if (mode->protos & PROTO_MASK(PCIE)) + return PCCR0_PEXa_MASK; + break; + case 0x2: + if (mode->protos & PROTO_MASK(SATA)) + return PCCR2_SATAa_MASK; + break; + case 0x8: + if (mode->protos & PROTO_MASK(SGMII)) + return PCCR8_SGMIIa_MASK; + break; + case 0x9: + if (mode->protos & PROTO_MASK(QSGMII)) + return PCCR9_QSGMIIa_MASK; + break; + case 0xB: + if (mode->protos & PROTO_MASK(XFI)) + return PCCRB_XFIa_MASK; + break; + } + pr_err("unknown mode PCCR%X %s%c\n", mode->pccr, + lynx_proto_str[mode->protos], 'A' + mode->idx); + return 0; +} + +/** + * lynx_proto_mode_shift() - Get the shift for a PCCR config + * @mode: The mode to use + * + * Return: The amount of bits to shift the mask. + */ +static u32 lynx_proto_mode_shift(const struct lynx_mode *mode) +{ + switch (mode->pccr) { + case 0x0: + if (mode->protos & PROTO_MASK(PCIE)) + return PCCR0_PEXa_SHIFT(mode->idx); + break; + case 0x2: + if (mode->protos & PROTO_MASK(SATA)) + return PCCR2_SATAa_SHIFT(mode->idx); + break; + case 0x8: + if (mode->protos & PROTO_MASK(SGMII)) + return PCCR8_SGMIIa_SHIFT(mode->idx); + break; + case 0x9: + if (mode->protos & PROTO_MASK(QSGMII)) + return PCCR9_QSGMIIa_SHIFT(mode->idx); + break; + case 0xB: + if (mode->protos & PROTO_MASK(XFI)) + return PCCRB_XFIa_SHIFT(mode->idx); + break; + } + pr_err("unknown mode PCCR%X %s%c\n", mode->pccr, + lynx_proto_str[mode->protos], 'A' + mode->idx); + return 0; +} + +/** + * lynx_proto_mode_get() - Get the current config for a PCCR mode + * @mode: The mode to use + * @pccr: The current value of the PCCR + * + * Return: The current value of the PCCR config for this mode + */ +static u32 lynx_proto_mode_get(const struct lynx_mode *mode, u32 pccr) +{ + return (pccr >> lynx_proto_mode_shift(mode)) & + lynx_proto_mode_mask(mode); +} + +/** + * lynx_proto_mode_prep() - Configure a PCCR for a protocol + * @mode: The mode to use + * @pccr: The current value of the PCCR + * @proto: The protocol to configure + * + * This configures a PCCR for a mode and protocol. To disable a mode, pass + * %LYNX_PROTO_NONE as @proto. If @proto is 1000Base-KX, then the KX bit + * will be set. + * + * Return: The new value for the PCCR + */ +static u32 lynx_proto_mode_prep(const struct lynx_mode *mode, u32 pccr, + enum lynx_protocol proto) +{ + u32 shift = lynx_proto_mode_shift(mode); + + pccr &= ~(lynx_proto_mode_mask(mode) << shift); + if (proto != LYNX_PROTO_NONE) + pccr |= mode->cfg << shift; + + if (proto == LYNX_PROTO_1000BASEKX) { + if (mode->pccr == 8) + pccr |= PCCR8_SGMIIa_KX << shift; + else + pr_err("PCCR%X doesn't have a KX bit\n", mode->pccr); + } + + return pccr; +} + +#define abs_diff(a, b) ({ \ + typeof(a) _a = (a); \ + typeof(b) _b = (b); \ + _a > _b ? _a - _b : _b - _a; \ +}) + +static int lynx_set_mode(struct phy *phy, enum phy_mode phy_mode, int submode) +{ + enum lynx_protocol proto; + const struct lynx_proto_params *params; + const struct lynx_mode *old_mode = NULL, *new_mode; + int i, pll, ret; + struct lynx_group *group = phy_get_drvdata(phy); + struct lynx_priv *serdes = group->serdes; + u32 tmp; + u32 gcr0 = 0, gcr1 = 0, recr0 = 0, tecr0 = 0; + u32 gcr0_mask = 0, gcr1_mask = 0, recr0_mask = 0, tecr0_mask = 0; + + proto = lynx_lookup_proto(phy_mode, submode); + if (proto == LYNX_PROTO_NONE) { + dev_dbg(&phy->dev, "unknown mode/submode %d/%d\n", + phy_mode, submode); + return -EINVAL; + } + + /* Nothing to do */ + if (proto == group->proto) + return 0; + + new_mode = lynx_lookup_mode(group, proto); + if (!new_mode) { + dev_dbg(&phy->dev, "could not find mode for %s on lanes %u to %u\n", + lynx_proto_str[proto], group->first_lane, + group->last_lane); + return -EINVAL; + } + + if (group->proto != LYNX_PROTO_NONE) { + old_mode = lynx_lookup_mode(group, group->proto); + if (!old_mode) { + dev_err(&phy->dev, "could not find mode for %s\n", + lynx_proto_str[group->proto]); + return -EBUSY; + } + } + + clk_disable_unprepare(group->pll); + clk_rate_exclusive_put(group->pll); + group->pll = NULL; + + /* First, try to use a PLL which already has the correct rate */ + params = &lynx_proto_params[proto]; + for (pll = 0; pll < ARRAY_SIZE(serdes->pll); pll++) { + struct clk *clk = serdes->pll[pll].hw.clk; + unsigned long rate = clk_get_rate(clk); + unsigned long error = abs_diff(rate, params->frate_khz); + + dev_dbg(&phy->dev, "pll%d has rate %lu\n", pll, rate); + /* Accept up to 100ppm deviation */ + if ((!error || params->frate_khz / error > 10000) && + !clk_set_rate_exclusive(clk, rate)) + goto got_pll; + /* Someone else got a different rate first */ + } + + /* If neither PLL has the right rate, try setting it */ + for (pll = 0; pll < 2; pll++) { + ret = clk_set_rate_exclusive(serdes->pll[pll].hw.clk, + params->frate_khz); + if (!ret) + goto got_pll; + } + + dev_dbg(&phy->dev, "could not get a pll at %ukHz\n", + params->frate_khz); + return ret; + +got_pll: + group->pll = serdes->pll[pll].hw.clk; + clk_prepare_enable(group->pll); + + gcr0_mask |= LNmGCR0_RRAT_SEL | LNmGCR0_TRAT_SEL; + gcr0_mask |= LNmGCR0_RPLL_LES | LNmGCR0_TPLL_LES; + gcr0_mask |= LNmGCR0_RRST_B | LNmGCR0_TRST_B; + gcr0_mask |= LNmGCR0_RX_PD | LNmGCR0_TX_PD; + gcr0_mask |= LNmGCR0_IF20BIT_EN | LNmGCR0_PROTS; + gcr0 |= FIELD_PREP(LNmGCR0_RPLL_LES, !pll); + gcr0 |= FIELD_PREP(LNmGCR0_TPLL_LES, !pll); + gcr0 |= FIELD_PREP(LNmGCR0_RRAT_SEL, params->rat_sel); + gcr0 |= FIELD_PREP(LNmGCR0_TRAT_SEL, params->rat_sel); + gcr0 |= FIELD_PREP(LNmGCR0_IF20BIT_EN, params->if20bit); + gcr0 |= FIELD_PREP(LNmGCR0_PROTS, params->prots); + + gcr1_mask |= LNmGCR1_RDAT_INV | LNmGCR1_TDAT_INV; + gcr1_mask |= LNmGCR1_OPAD_CTL | LNmGCR1_REIDL_TH; + gcr1_mask |= LNmGCR1_REIDL_EX_SEL | LNmGCR1_REIDL_ET_SEL; + gcr1_mask |= LNmGCR1_REIDL_EX_MSB | LNmGCR1_REIDL_ET_MSB; + gcr1_mask |= LNmGCR1_REQ_CTL_SNP | LNmGCR1_REQ_CDR_SNP; + gcr1_mask |= LNmGCR1_TRSTDIR | LNmGCR1_REQ_BIN_SNP; + gcr1_mask |= LNmGCR1_ISLEW_RCTL | LNmGCR1_OSLEW_RCTL; + gcr1 |= FIELD_PREP(LNmGCR1_REIDL_TH, params->reidl_th); + gcr1 |= FIELD_PREP(LNmGCR1_REIDL_EX_SEL, params->reidl_ex & 3); + gcr1 |= FIELD_PREP(LNmGCR1_REIDL_ET_SEL, params->reidl_et & 3); + gcr1 |= FIELD_PREP(LNmGCR1_REIDL_EX_MSB, params->reidl_ex >> 2); + gcr1 |= FIELD_PREP(LNmGCR1_REIDL_ET_MSB, params->reidl_et >> 2); + gcr1 |= FIELD_PREP(LNmGCR1_TRSTDIR, + group->first_lane > group->last_lane); + gcr1 |= FIELD_PREP(LNmGCR1_ISLEW_RCTL, params->slew); + gcr1 |= FIELD_PREP(LNmGCR1_OSLEW_RCTL, params->slew); + + recr0_mask |= LNmRECR0_GK2OVD | LNmRECR0_GK3OVD; + recr0_mask |= LNmRECR0_GK2OVD_EN | LNmRECR0_GK3OVD_EN; + recr0_mask |= LNmRECR0_BASE_WAND | LNmRECR0_OSETOVD; + if (params->gain) { + recr0 |= FIELD_PREP(LNmRECR0_GK2OVD, params->gain); + recr0 |= FIELD_PREP(LNmRECR0_GK3OVD, params->gain); + recr0 |= LNmRECR0_GK2OVD_EN | LNmRECR0_GK3OVD_EN; + } + recr0 |= FIELD_PREP(LNmRECR0_BASE_WAND, params->baseline_wander); + recr0 |= FIELD_PREP(LNmRECR0_OSETOVD, params->offset_override); + + tecr0_mask |= LNmTECR0_TEQ_TYPE; + tecr0_mask |= LNmTECR0_SGN_PREQ | LNmTECR0_RATIO_PREQ; + tecr0_mask |= LNmTECR0_SGN_POST1Q | LNmTECR0_RATIO_PST1Q; + tecr0_mask |= LNmTECR0_ADPT_EQ | LNmTECR0_AMP_RED; + tecr0 |= FIELD_PREP(LNmTECR0_TEQ_TYPE, params->teq); + if (params->preq_ratio) { + tecr0 |= FIELD_PREP(LNmTECR0_SGN_PREQ, 1); + tecr0 |= FIELD_PREP(LNmTECR0_RATIO_PREQ, params->preq_ratio); + } + if (params->postq_ratio) { + tecr0 |= FIELD_PREP(LNmTECR0_SGN_POST1Q, 1); + tecr0 |= FIELD_PREP(LNmTECR0_RATIO_PST1Q, params->postq_ratio); + } + tecr0 |= FIELD_PREP(LNmTECR0_ADPT_EQ, params->adpt_eq); + tecr0 |= FIELD_PREP(LNmTECR0_AMP_RED, params->amp_red); + + mutex_lock(&serdes->lock); + + /* Disable the old controller */ + if (old_mode) { + tmp = lynx_read(serdes, PCCRn(old_mode->pccr)); + tmp = lynx_proto_mode_prep(old_mode, tmp, LYNX_PROTO_NONE); + lynx_write(serdes, tmp, PCCRn(old_mode->pccr)); + + if (old_mode->protos & PROTO_MASK(SGMII)) { + tmp = lynx_read(serdes, SGMIIaCR1(old_mode->idx)); + tmp &= SGMIIaCR1_SGPCS_EN; + lynx_write(serdes, tmp, SGMIIaCR1(old_mode->idx)); + } + } + + for_each_lane_reverse(i, group) { + tmp = lynx_read(serdes, LNmGCR0(i)); + tmp &= ~(LNmGCR0_RRST_B | LNmGCR0_TRST_B); + lynx_write(serdes, tmp, LNmGCR0(i)); + ndelay(50); + + tmp &= ~gcr0_mask; + tmp |= gcr0; + tmp |= FIELD_PREP(LNmGCR0_FIRST_LANE, i == group->first_lane); + lynx_write(serdes, tmp, LNmGCR0(i)); + + tmp = lynx_read(serdes, LNmGCR1(i)); + tmp &= ~gcr1_mask; + tmp |= gcr1; + lynx_write(serdes, tmp, LNmGCR1(i)); + + tmp = lynx_read(serdes, LNmRECR0(i)); + tmp &= ~recr0_mask; + tmp |= recr0; + lynx_write(serdes, tmp, LNmRECR0(i)); + + tmp = lynx_read(serdes, LNmTECR0(i)); + tmp &= ~tecr0_mask; + tmp |= tecr0; + lynx_write(serdes, tmp, LNmTECR0(i)); + + tmp = lynx_read(serdes, LNmTTLCR0(i)); + tmp &= ~LNmTTLCR0_FLT_SEL; + tmp |= FIELD_PREP(LNmTTLCR0_FLT_SEL, params->flt_sel); + lynx_write(serdes, tmp, LNmTTLCR0(i)); + + ndelay(120); + tmp = lynx_read(serdes, LNmGCR0(i)); + tmp |= LNmGCR0_RRST_B | LNmGCR0_TRST_B; + lynx_write(serdes, tmp, LNmGCR0(i)); + } + + if (proto == LYNX_PROTO_1000BASEKX) { + /* FIXME: this races with clock updates */ + tmp = lynx_read(serdes, PLLaCR0(pll)); + tmp &= ~PLLaCR0_DLYDIV_SEL; + tmp |= FIELD_PREP(PLLaCR0_DLYDIV_SEL, 1); + lynx_write(serdes, tmp, PLLaCR0(pll)); + } + + /* Enable the new controller */ + tmp = lynx_read(serdes, PCCRn(new_mode->pccr)); + tmp = lynx_proto_mode_prep(new_mode, tmp, proto); + lynx_write(serdes, tmp, PCCRn(new_mode->pccr)); + + if (new_mode->protos & PROTO_MASK(SGMII)) { + tmp = lynx_read(serdes, SGMIIaCR1(new_mode->idx)); + tmp |= SGMIIaCR1_SGPCS_EN; + lynx_write(serdes, tmp, SGMIIaCR1(new_mode->idx)); + } + + mutex_unlock(&serdes->lock); + + group->proto = proto; + dev_dbg(&phy->dev, "set mode to %s on lanes %u to %u\n", + lynx_proto_str[proto], group->first_lane, group->last_lane); + return 0; +} + +static void lynx_release(struct phy *phy) +{ + struct lynx_group *group = phy_get_drvdata(phy); + struct lynx_priv *serdes = group->serdes; + + mutex_lock(&serdes->lock); + if (--group->users) { + mutex_unlock(&serdes->lock); + return; + } + list_del(&group->groups); + mutex_unlock(&serdes->lock); + + phy_destroy(phy); + kfree(group); +} + +static const struct phy_ops lynx_phy_ops = { + .init = lynx_init, + .exit = lynx_exit, + .power_on = lynx_power_on, + .power_off = lynx_power_off, + .set_mode = lynx_set_mode, + .validate = lynx_validate, + .release = lynx_release, + .owner = THIS_MODULE, +}; + +static struct phy *lynx_xlate(struct device *dev, struct of_phandle_args *args) +{ + struct phy *phy; + struct list_head *head; + struct lynx_group *group; + struct lynx_priv *serdes = dev_get_drvdata(dev); + unsigned int last_lane; + + if (args->args_count == 1) + last_lane = args->args[0]; + else if (args->args_count == 2) + last_lane = args->args[1]; + else + return ERR_PTR(-EINVAL); + + mutex_lock(&serdes->lock); + + /* Look for an existing group */ + list_for_each(head, &serdes->groups) { + group = container_of(head, struct lynx_group, groups); + if (group->first_lane == args->args[0] && + group->last_lane == last_lane) { + group->users++; + return group->phy; + } + } + + /* None found, create our own */ + group = kzalloc(sizeof(*group), GFP_KERNEL); + if (!group) { + mutex_unlock(&serdes->lock); + return ERR_PTR(-ENOMEM); + } + + group->serdes = serdes; + group->first_lane = args->args[0]; + group->last_lane = last_lane; + group->users = 1; + phy = phy_create(dev, NULL, &lynx_phy_ops); + if (IS_ERR(phy)) { + kfree(group); + } else { + group->phy = phy; + phy_set_drvdata(phy, group); + list_add(&group->groups, &serdes->groups); + } + + mutex_unlock(&serdes->lock); + return phy; +} + +static int lynx_probe(struct platform_device *pdev) +{ + bool grabbed_clocks = false; + int i, ret; + struct device *dev = &pdev->dev; + struct lynx_priv *serdes; + struct regmap_config regmap_config = {}; + const struct lynx_conf *conf; + struct resource *res; + void __iomem *base; + + serdes = devm_kzalloc(dev, sizeof(*serdes), GFP_KERNEL); + if (!serdes) + return -ENOMEM; + platform_set_drvdata(pdev, serdes); + mutex_init(&serdes->lock); + INIT_LIST_HEAD(&serdes->groups); + serdes->dev = dev; + + base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); + if (IS_ERR(base)) { + ret = PTR_ERR(base); + dev_err_probe(dev, ret, "could not get/map registers\n"); + return ret; + } + + conf = device_get_match_data(dev); + serdes->conf = conf; + regmap_config.reg_bits = 32; + regmap_config.reg_stride = 4; + regmap_config.val_bits = 32; + regmap_config.val_format_endian = conf->endian; + regmap_config.max_register = res->end - res->start; + regmap_config.disable_locking = true; + serdes->regmap = devm_regmap_init_mmio(dev, base, ®map_config); + if (IS_ERR(serdes->regmap)) { + ret = PTR_ERR(serdes->regmap); + dev_err_probe(dev, ret, "could not create regmap\n"); + return ret; + } + + for (i = 0; i < ARRAY_SIZE(serdes->ref); i++) { + static const char fmt[] = "ref%d"; + char name[sizeof(fmt)]; + + snprintf(name, sizeof(name), fmt, i); + serdes->ref[i] = devm_clk_get(dev, name); + if (IS_ERR(serdes->ref[i])) { + ret = PTR_ERR(serdes->ref[i]); + dev_err_probe(dev, ret, "could not get %s\n", name); + return ret; + } + } + + for (i = 0; i < ARRAY_SIZE(serdes->pll); i++) { + static const char fmt[] = "%s.pll%d"; + char *name; + const struct clk_hw *ref_hw[] = { + __clk_get_hw(serdes->ref[i]), + }; + size_t len; + struct clk_init_data init = {}; + + len = snprintf(NULL, 0, fmt, pdev->name, i); + name = devm_kzalloc(dev, len + 1, GFP_KERNEL); + if (!name) + return -ENOMEM; + + snprintf(name, len + 1, fmt, pdev->name, i); + init.name = name; + init.ops = &lynx_pll_clk_ops; + init.parent_hws = ref_hw; + init.num_parents = 1; + init.flags = CLK_SET_RATE_GATE | CLK_GET_RATE_NOCACHE; + init.flags |= CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE; + + serdes->pll[i].hw.init = &init; + serdes->pll[i].serdes = serdes; + serdes->pll[i].idx = i; + ret = devm_clk_hw_register(dev, &serdes->pll[i].hw); + if (ret) { + dev_err_probe(dev, ret, "could not register %s\n", + name); + return ret; + } + } + + ret = devm_of_clk_add_hw_provider(dev, lynx_clk_get, serdes); + if (ret) { + dev_err_probe(dev, ret, "could not register clock provider\n"); + return ret; + } + + /* Deselect anything configured by the RCW/bootloader */ + for (i = 0; i < conf->mode_count; i++) { + const struct lynx_mode *mode = &conf->modes[i]; + u32 pccr = lynx_read(serdes, PCCRn(mode->pccr)); + + if (lynx_proto_mode_get(mode, pccr) == mode->cfg) { + if (mode->protos & UNSUPPORTED_PROTOS) { + /* Don't mess with modes we don't support */ + serdes->used_lanes |= mode->lanes; + if (grabbed_clocks) + continue; + + grabbed_clocks = true; + clk_prepare_enable(serdes->pll[0].hw.clk); + clk_prepare_enable(serdes->pll[1].hw.clk); + clk_rate_exclusive_get(serdes->pll[0].hw.clk); + clk_rate_exclusive_get(serdes->pll[1].hw.clk); + } else { + /* Otherwise, clear out the existing config */ + pccr = lynx_proto_mode_prep(mode, pccr, + LYNX_PROTO_NONE); + lynx_write(serdes, pccr, PCCRn(mode->pccr)); + } + + /* Disable the SGMII PCS until we're ready for it */ + if (mode->protos & LYNX_PROTO_SGMII) { + u32 cr1; + + cr1 = lynx_read(serdes, SGMIIaCR1(mode->idx)); + cr1 &= ~SGMIIaCR1_SGPCS_EN; + lynx_write(serdes, cr1, SGMIIaCR1(mode->idx)); + } + } + } + + /* Power off all lanes; used ones will be powered on later */ + for (i = 0; i < conf->lanes; i++) + lynx_power_off_lane(serdes, i); + + ret = PTR_ERR_OR_ZERO(devm_of_phy_provider_register(dev, lynx_xlate)); + if (ret) + dev_err_probe(dev, ret, "could not register phy provider\n"); + else + dev_info(dev, "probed with %d lanes\n", conf->lanes); + return ret; +} + +/* + * XXX: For SerDes1, lane A uses pins SD1_RX3_P/N! That is, the lane numbers + * and pin numbers are _reversed_. In addition, the PCCR documentation is + * _inconsistent_ in its usage of these terms! + * + * PCCR "Lane 0" refers to... + * ==== ===================== + * 0 Lane A + * 2 Lane A + * 8 Lane A + * 9 Lane A + * B Lane D! + */ +static const struct lynx_mode ls1046a_modes1[] = { + CONF_SINGLE(1, PCIE, 0x0, 1, 0b001), /* PCIe.1 x1 */ + CONF_1000BASEKX(0, 0x8, 0, 0b001), /* SGMII.6 */ + CONF_SGMII25KX(1, 0x8, 1, 0b001), /* SGMII.5 */ + CONF_SGMII25KX(2, 0x8, 2, 0b001), /* SGMII.10 */ + CONF_SGMII25KX(3, 0x8, 3, 0b001), /* SGMII.9 */ + CONF_SINGLE(1, QSGMII, 0x9, 2, 0b001), /* QSGMII.6,5,10,1 */ + CONF_XFI(2, 0xB, 0, 0b010), /* XFI.10 */ + CONF_XFI(3, 0xB, 1, 0b001), /* XFI.9 */ +}; + +static const struct lynx_conf ls1046a_conf1 = { + .modes = ls1046a_modes1, + .mode_count = ARRAY_SIZE(ls1046a_modes1), + .lanes = 4, + .endian = REGMAP_ENDIAN_BIG, +}; + +static const struct lynx_mode ls1046a_modes2[] = { + CONF_SINGLE(0, PCIE, 0x0, 0, 0b001), /* PCIe.1 x1 */ + CONF(GENMASK(3, 0), PROTO_MASK(PCIE), 0x0, 0, 0b011), /* PCIe.1 x4 */ + CONF_SINGLE(2, PCIE, 0x0, 2, 0b001), /* PCIe.2 x1 */ + CONF(GENMASK(3, 2), PROTO_MASK(PCIE), 0x0, 2, 0b010), /* PCIe.3 x2 */ + CONF_SINGLE(3, PCIE, 0x0, 2, 0b011), /* PCIe.3 x1 */ + CONF_SINGLE(3, SATA, 0x2, 0, 0b001), /* SATA */ + CONF_1000BASEKX(1, 0x8, 1, 0b001), /* SGMII.2 */ +}; + +static const struct lynx_conf ls1046a_conf2 = { + .modes = ls1046a_modes2, + .mode_count = ARRAY_SIZE(ls1046a_modes2), + .lanes = 4, + .endian = REGMAP_ENDIAN_BIG, +}; + +static const struct of_device_id lynx_of_match[] = { + { .compatible = "fsl,ls1046a-serdes-1", .data = &ls1046a_conf1 }, + { .compatible = "fsl,ls1046a-serdes-2", .data = &ls1046a_conf2 }, +}; +MODULE_DEVICE_TABLE(of, lynx_of_match); + +static struct platform_driver lynx_driver = { + .probe = lynx_probe, + .driver = { + .name = "qoriq_serdes", + .of_match_table = lynx_of_match, + }, +}; +module_platform_driver(lynx_driver); + +MODULE_AUTHOR("Sean Anderson "); +MODULE_DESCRIPTION("Lynx 10G SerDes driver"); +MODULE_LICENSE("GPL"); From patchwork Tue Jun 28 22:14:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 585672 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AEB1C433EF for ; Tue, 28 Jun 2022 22:19:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232040AbiF1WTl (ORCPT ); Tue, 28 Jun 2022 18:19:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232042AbiF1WTJ (ORCPT ); Tue, 28 Jun 2022 18:19:09 -0400 Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50053.outbound.protection.outlook.com [40.107.5.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F3F93CA51; Tue, 28 Jun 2022 15:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BZmuwjGfQb5d6RY9sVwT5oD6jZSnbxUbmjH+wYL8A+vSxcw836Jb/YIBIUYb6IcRZeejMG9KfTzJR3TEkXFV5I8wOesAGf+bXWmpaznuiNXbGH6i9e+dhN0hFcu0eWq6m9ySaw4BKQoYpKBONa7M7mww1qwRCMv2ZE0j1A9wPe9SSscPcINYfUithSdr0I2i+kshBz/6/dlH8Nf1U2zl4c3FvGttu3pfOa4qBpD4UVIIXwTpCdmhg9Bq9UnG+vGRquxvt/0JZEv4YptuIPzMZRXs6MxIsP6R3Jjpq48HvF5YKFjgWt7tgnIZLS/sk+OdfL3HMltDklfgFgYUNa5TlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LWMYi4jHuSKoL0PhVCtVd/LenVBaQ7RzU7jnwoLBJQ8=; b=MsBavzD7gFD0kw9t1bQYILG8VRlGJ8i4ZhWxkZS36q+rCG6oMo2Q36IVS3NPT8my8NTg725A24/P3oorQxnHxW21/ikVNkK0E05YZEM63jnX0DBSUrL+eAVsJSt7rTwyudrzufyMm4vPAWywX7lXJRhMuC3PvtnbA8Q33XNTPjc4O2q+4GKZ/EuCmj0URV2YOHs9sTK/SnziT16nHkC/hA8/6B2d1DFSFjwmhsH7XaRgu9TcBknfY0X4wHy6nf8cly2IUeVDOqsWC1MOTF9FjtQ2Faxl9avN8Nz+x2O7jfJlTfzbLp/8bwxD4maW4DGYcOdUDa3gKabUf1EX0yYTZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LWMYi4jHuSKoL0PhVCtVd/LenVBaQ7RzU7jnwoLBJQ8=; b=Vex1goZz6+iOVaBWoKE4J/cUinlqxdKDYhAF7XKicEQREQmIfVCw76Vv0lp2O1kZa4/h5iNpKJIFgxR3bIRueB9w05rwxJrRU7rhYhze4i0KCFgKsAfeJle+pSbXaS4p2Nzu4IEKlXXzL9byON3er6HkifZI9gJtLF6OohcSeu2rD2cmXMiV6P1CoXEcuU84BdlisAFREwfn5Mf1EOpgO9XwQNdL7CzUrCTnDpOibspXu/lVhbBRp5KDF6aJZCKoxGhQhG53/aIRDQfmk5BI+CGK635du1ff2zTxHinPurt2rt90A4JVjHSWDPBRw90Apl4h6SsRDevVyNWiPA4FCw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) by DB7PR03MB3883.eurprd03.prod.outlook.com (2603:10a6:5:34::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.18; Tue, 28 Jun 2022 22:15:37 +0000 Received: from DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::757e:b75f:3449:45b1]) by DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::757e:b75f:3449:45b1%6]) with mapi id 15.20.5373.018; Tue, 28 Jun 2022 22:15:37 +0000 From: Sean Anderson To: "David S . Miller" , Jakub Kicinski , Madalin Bucur , netdev@vger.kernel.org Cc: Russell King , Paolo Abeni , linux-arm-kernel@lists.infradead.org, Eric Dumazet , linux-kernel@vger.kernel.org, Sean Anderson , Krzysztof Kozlowski , Li Yang , Rob Herring , Shawn Guo , devicetree@vger.kernel.org Subject: [PATCH net-next v2 34/35] arm64: dts: ls1046a: Add serdes bindings Date: Tue, 28 Jun 2022 18:14:03 -0400 Message-Id: <20220628221404.1444200-35-sean.anderson@seco.com> X-Mailer: git-send-email 2.35.1.1320.gc452695387.dirty In-Reply-To: <20220628221404.1444200-1-sean.anderson@seco.com> References: <20220628221404.1444200-1-sean.anderson@seco.com> X-ClientProxiedBy: BL1P222CA0011.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::16) To DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 63540b8d-0bf8-4d59-59e6-08da5953ac51 X-MS-TrafficTypeDiagnostic: DB7PR03MB3883:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RNJZMQGfewhIasCgD9M2TMJLLh+QgBwxWOOk5/vMCsdDOO19uV57mvkDkv3ebGOwXWHXBdojbfKcbfU/Pyg7YOVTrDD6KWFkLJGT/pT4gtgHka+C68+NCilZV7l16/N+mHQA4NDvgtZ2+EOkNWeJ7LWXVmNfe2NttYZ4uuC+B/521dnvEs1s4GeDuzja740xeNW7EJ8BRJMwKVmdSVrjog3+ag1HQCBbgKqkmV7hdMZE+Sls3aKE4zLa1n2jcEam06Q1Bz1pMQgxejRnPqEozEJdmAcQ6T3NQDxoSbudzPhE0chQO4NihlZQqE5ry1Gw8AYPTUiqUVbfbFvAVwpr1pCxmw53NzcZhmYI4O/udfXNENG/8fJoG3/aqz/R/NgJYPgOE0Jt/XP6Hzcqjg9dv7jb4afMPS7vNLnKrO7LuOsDPvnCkSn0YjaWw3oRRE64rg2bh9eqMypg8JB6HOD8U2KImN1r9hatYZ2uXeCCu3TZB1dYilNpPcPe9g/X3b2AGKmYwTiY6zjLV1PWCbi4BcrimACR0AT6u6dWT2YarSXzkPPZlPqOZdaKkLc8oaKJIdCs1v5R5iYTqx4QZ+bYuvtTKOBCK+UmTQL3awsRfY0s1sucEXFeD+gdriA7TgogjWOGtZGenkJ4kbWLHKz2VRXXODm0HZIQHznKxHqARaMPHKN2V093G1VMqO9GnRteC+D1IE9L4kcQjK0ksB0REimHxQEYJJn0WFdbLMjAkjpIC4ixu8BX9O8WZIEb6yV291aDtAo69ZT4UDSofPfhcy7CuhQY5t/EJcegBvZYIxY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4972.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(346002)(396003)(366004)(39850400004)(136003)(376002)(52116002)(6512007)(6506007)(8676002)(38100700002)(36756003)(66556008)(66946007)(38350700002)(66476007)(2906002)(26005)(1076003)(7416002)(86362001)(54906003)(41300700001)(83380400001)(2616005)(6486002)(110136005)(316002)(6666004)(186003)(4326008)(44832011)(5660300002)(478600001)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eFt0s94lkOzGzOnsF7+3nVF/8ugleZlcfA9IcVajftCRcQwD0XjWz7UnyaRBnJEo0Oaik1gAhn+BORDxROUNa8b6SaFM8UIkBeirE/EOLFUqfL0H0r9EY113n1gLdVq/g8URIxIgR/EIZaRp5l7H2JlUSzVlEUpYrT1HOmCTur8KgX9v0l+7UhT34gdyl38bNv2wdxFXY+GCPiNa4lkJ7Lj7n3rvn9UvxWBQPeK8LbIxDIYA+IUtWbFqZBGNyrfXDoXHFv/fx7VfWUB2CJJUrcllEyJfslIh8a294V+ZUHvySZDu5exJSGDn4i2wXw1fFt9vHWrwnJXGVLDlLm/5POGA2minGyBFeWAJY+yQOPZfW8aK+e1IrFpcqZXSfFH2spYGFZ4GfdKCAVLV4g9UpSauNKupfWtPamdddnaZ6AJF4tz3nKmqw2U6POv5YZ7NpEmaev7f2K+WbJRMpaOOS6ChP27qPqORw4N2gb1gpwYJqo+Up8xlBVO6WzuDqCzFmEOHFM0VrHB4SuHYNuQ1F7RFud31PNH1q8Gdb0/2z8DCL20Z1raIVEmwwDHTQzEOQcKVERXEMIhSO1rKeS+AugeWCYM12+FavIA0DI11j0Csi9E6mWiJy6VtgepyYIJy7s34ew676tDeTDdMLQBHl0OHz6vuWTfTl/pkHXjf+rNeZDhroKFRBM8e42PLXyf8n4e4Yf4Kd1+KU0skM6goEX/3r5SpcezLQeWP4AnfYkK27BSynfRJpv8r7aZzb01BVvNkiqXeMb7D8hBmS3yeq3Zkg8m90Bgc43odyYGfH/UIEiz0jYWKQF+p9yGBmyknHlaow6/NODrBrqZDVn+/LfmUq+NEE8UciV+LxvW+jFgE1JbujEi7sPi2QojaaQpDcZXcpcUPVJ4tuzLKSfldQLcjTWRr+A5yUi75w0tn0hkthioLo2diXYEaG/+7xMt+FDMv1fQQzAom1E/HbJcAtaUds1V9xDRQRJcfoxtfBAnd92ZW78HK21jj2BLkdwMvOiwygtLazKL/KlVsmt2VL7vUYNgKqzZDst4vzW4V1QErmxmoXBUZaRcGYN3HOevGCF+5Icd3AlRoaPvPc203rQdbZojKdzduK1wU0USZlY8WOlDtAg1ZdGD9M8gMayp31dGAm/4AvAHCIqUQQhE+z/L02/BYct4dL3R9lrnwzXhPV1pMTfa33+56/2c9SfACTQwZ5svIVQuRnRkBFNFsXIvNXVWo5CaozWVX1BSswGEXwxBck1NLgOCvNVRlwLfQ+kS6GTnj684RiGUIMqJ42ulq0GlKD25J1BHd9wmYjg7yQWBeWtWe07d62u3Tg2h1Ves1+89AtC8HaAZ6y4uPAdtMFfsrP59TxuljY1rljr4d5ePIo1T8yaoDOVM9JZrX2DWQ3gZ10B17PPfqwNe3s6piASlVeyWK2yHvihX3Ix6jL1IT0HUBJSKiAXQpcgfRHlZ6ObTYp0I3qcvj2o2KudHyEejMnsGwCAYBXpA/RPRMAnP1rnWB/jQ0aKAJss9dDqVj3Yco5wyX409svtEL9zIuNOWXr1bWdC8E6hezPVKvxSOIM6z4HJu/3hDh9DCSwL/6aDcIVNKVUhgbXpBg3A== X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63540b8d-0bf8-4d59-59e6-08da5953ac51 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4972.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 22:15:13.6547 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wH6TR91AfCtcesfRSvfWYBf3EmHCBR/BD/qGO1BMGAKtxsECLSH+vrxukfjMcB0POFmaBlKwYc0LxRaaUIGiBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR03MB3883 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This adds bindings for the SerDes devices. They are disabled by default to prevent any breakage on existing boards. Signed-off-by: Sean Anderson --- Changes in v2: - Disable SerDes by default to prevent breaking boards inadvertently. - Use one phy cell for SerDes1, since no lanes can be grouped arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi index 0085e83adf65..8b15653607c9 100644 --- a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi +++ b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi @@ -413,6 +413,22 @@ bportals: bman-portals@508000000 { ranges = <0x0 0x5 0x08000000 0x8000000>; }; + serdes1: phy@1ea0000 { + #clock-cells = <1>; + #phy-cells = <1>; + compatible = "fsl,ls1046a-serdes-1"; + reg = <0x0 0x1ea0000 0x0 0x2000>; + status = "disabled"; + }; + + serdes2: phy@1eb0000 { + #clock-cells = <1>; + #phy-cells = <2>; + compatible = "fsl,ls1046a-serdes-2"; + reg = <0x0 0x1eb0000 0x0 0x2000>; + status = "disabled"; + }; + dcfg: dcfg@1ee0000 { compatible = "fsl,ls1046a-dcfg", "syscon"; reg = <0x0 0x1ee0000 0x0 0x1000>; From patchwork Tue Jun 28 22:14:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 585671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 122D9C43334 for ; Tue, 28 Jun 2022 22:20:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230148AbiF1WU0 (ORCPT ); Tue, 28 Jun 2022 18:20:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbiF1WUH (ORCPT ); Tue, 28 Jun 2022 18:20:07 -0400 Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50053.outbound.protection.outlook.com [40.107.5.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A2363D49D; Tue, 28 Jun 2022 15:16:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XMjUJwwxabseaPhgrl3CrS4BJsmFEGlpuAZsV9X0Xzyonw+AU3NErdcjigwDb3V1l8JDM2lopjm94icvJjZmZvCh2JK3bjrbpKvpEt2ZOUij98HNz9TOUxLEqhmbCdJMhIdKm+bku80j5eF+YYQFDz3If7C4rkP1bzF3z6try5wHOArMOoJGadMmpuCnzxsZ6sNrX09aFeh6I/KnIoNraT5vmquJlT7/HuxYw0tx7iwlZmn+0uCS0PDLnnoZptuYV1PPpCOvHFPkmFd7HCFAdXkPtSWbe8ty+g4iRQVI1fTIlyqPjNGGmOjJoarGqo8KvOVlBATq8T3DS64D7DFS5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Mv/fBJyuMJHaKO9E0HqqZzxOLAFdk0n0PbulaXq1z+A=; b=FYKI7++UWZSmmaZGC83rH1yxiLhZgw46q/8JsFmAIeM96ItroZXngIxBSle3KEorIuEd7YCyqmvH6iGv6WgXgYZkSmdZQiTUEGlMEPL6nYpfNEMDTq3UGpLsTxpt44WKp3q78/dczTMD3yL3408OWZETtplFzdsj/FTsmmndTKtK6FEm1dUfGVVt+0UgBacNFANwE72uHVOX1J7XxdA/Seyy+LYLFi8Xbf7Vup46xMRLv8SaUT3/GAX8n2b1jGadLapsCqCD35dr8zfYsLkKFDvPVjkvug2u5BQGIubpX5tFBm/xOaV3a3pzioBPSZJRA9LW6sL7BAw8epyo5OdWug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mv/fBJyuMJHaKO9E0HqqZzxOLAFdk0n0PbulaXq1z+A=; b=DVAH7d1ZbK71g6FyYqnPcSFd+KtxDF+iHPsbWlO+08TOxEIdeFUyXFbwPapLh/Fq5xRMIW1puT4DMFyQJFXrt7ZS0e4JrKBIskbndThlmeM2xqZYAPgXWpFg1RqcbBc+q2l7nqQxxcf2LXzoDqr+OpTeMF30EDUjfAGIDNS8KZ/H9GSIJJvni5BdGVniAx2/usg5qP/OXzdb3Sp/bL/U+6vXVVVOd+n9xQ9TBmTjHqiZtwV9CfMlpk1DPjNrNn/D3cg6JWGROZG9SdbrLNu9EU2Nwu8wltgbmvEVH4nCtCYszPmmcU1Q+6Lw8yyR2oJjtnVHDAGOuhknd2+Upa+e9Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) by DB7PR03MB3883.eurprd03.prod.outlook.com (2603:10a6:5:34::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.18; Tue, 28 Jun 2022 22:15:37 +0000 Received: from DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::757e:b75f:3449:45b1]) by DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::757e:b75f:3449:45b1%6]) with mapi id 15.20.5373.018; Tue, 28 Jun 2022 22:15:37 +0000 From: Sean Anderson To: "David S . Miller" , Jakub Kicinski , Madalin Bucur , netdev@vger.kernel.org Cc: Russell King , Paolo Abeni , linux-arm-kernel@lists.infradead.org, Eric Dumazet , linux-kernel@vger.kernel.org, Sean Anderson , Kishon Vijay Abraham I , Krzysztof Kozlowski , Li Yang , Rob Herring , Shawn Guo , Vinod Koul , devicetree@vger.kernel.org, linux-phy@lists.infradead.org Subject: [PATCH net-next v2 35/35] arm64: dts: ls1046ardb: Add serdes bindings Date: Tue, 28 Jun 2022 18:14:04 -0400 Message-Id: <20220628221404.1444200-36-sean.anderson@seco.com> X-Mailer: git-send-email 2.35.1.1320.gc452695387.dirty In-Reply-To: <20220628221404.1444200-1-sean.anderson@seco.com> References: <20220628221404.1444200-1-sean.anderson@seco.com> X-ClientProxiedBy: BL1P222CA0011.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::16) To DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b05888fd-ea4c-4e44-7fb2-08da5953ada1 X-MS-TrafficTypeDiagnostic: DB7PR03MB3883:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zxaEsr25ORtfqPXxTrJ8IClKEYl82Sl6YhJ1XjuyQgwsnfaJ5tNjhcqvhIzQ1NJiuFhqLf+bDYkC3nvka895EmQ731pfKKBts1zG3I8OJcdz/HMtAEe9QzAGiWPw+S7ytUDcJy0osd0X4q0Mt/ciu0yDUVnjLPrMxgu99GnQgx+c/elVrQLGStDk3I/dOspAwQxQlnffUCCasXP/dlr1XBLqj9Z/J9E1XgIomhv951Hwr56/mAm+aJGNoW1eEmfXnEx5y+aNcsHI6N0wFaH1McQsC6bhLS7wdF9zKD4MTQh2jM94zDXIqgK5DAEfJnfvHm2vuqoGcJg0ggPIWH/gVGYb8g3GpKqYNk7YyCtd3q9tU7rfs8AVxiGVfh9aLUa43huG+SS5LOeb5iBRxW9aUHnYQQy2k6qkgyjODHZvC1AzkSTBtYZFqdvpPAwRUL6ETvY5aFTn4IMEDijush1J817AkAIulutRUa4yeBaeBFe38g/uU0WWXjeTrsJMVqCkgQziowxnon9EnmZpvS44LDWUFM7z5+ky77dBDhJmKazhYRVn5vLT2GrRW/WQqFGmI2jKRlo9rsvJssKd20FAIMxHtqa5tkFb69dFA8hpTlloj3PGI4VtEwKyj0U1mY6FXDhmW9Urh4pGnpQlzdVp+TzI5AzCAXk4nniQEW9AOhNUhJYtD0eYISU0KV9nS31jYtG/GPdVYCLoYJWmUxpNY/cl/WfrYuv5mh7Hvg2HquJdccfWRXgPJhQ+tzJ83kiIz2tYxmdCgiMQtgFpYtV2Nb05bjGo7KwOBcQpHppj/Hw= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4972.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(346002)(396003)(366004)(39850400004)(136003)(376002)(52116002)(6512007)(6506007)(8676002)(38100700002)(36756003)(66556008)(66946007)(38350700002)(66476007)(2906002)(26005)(1076003)(7416002)(86362001)(54906003)(41300700001)(83380400001)(2616005)(6486002)(110136005)(316002)(6666004)(186003)(4326008)(44832011)(5660300002)(478600001)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kwdPNYd2TyQoT0btfaTdgu9Q/tdYdf70Z/x6Qb4STpHFxlXK0lSl0UGxKv/B6C8rS30aMmJxTdLOCuW+wjlkQZUhGlA+sJesg3uxLB/KN3BNvW8xpSSiMwiKpP5PvJzxiteDQMKVSlkppmFTTAP733GIEZU+/dDNfzGGwBrCfm/Xvqc1AZnFWyJ+mKTTmRE1uRsmI6HTcUGtqe4nvFu11yq5fcbiTNaZeZSj0RizGUOYgLhVsL/bB9hj6tO9Ltve3PsbWQbsWGHe0DEUndlVx2L0+nigNhxBb6hwv65YSDdlFGE2p+3mlqxEkHihkw6aZEDXgb7EflF2tYnZqx/EAWDbtXF4/PXMOyko3LUrSmfE3BoFacrJnii4bZoiQyztzfTjgq1B/QFTCuuX63vYbObKmzD0L2ecY5JK+fUgXAymYQIIWGAYoyTGuOmYJ+qnUc+mVtqYNyBK7R7ElWETseufN0N9RH53gGEpyRLOw2kUcQlmNidCOsOS6JKH1Ou6EkF/DG35uOm8W1lG2swJQ22FDq3MKs8Wb4cbw09kEPSIJRwc+0mVtyf3ta51qKz4LS38JBb8x8iN7fzIICKOvelP2VnCCDEiwzIfxpsSiLDKDKqvkonDzEVvqmnQwd/Grlx6zKvNgfgHs0yPIiKYoXavn34s0mO7StQ6ubQC9iNr38T6G7FXdKCAyPtpKe+/oRvimZ/ajmxIdIFvDnam1v7Q0zTTLm6rm2ueJwm47LUQbTHvTNLAee/CBrvvr3Rd4xsmpMuVm71mdCqcycuPhZBfGtVyncJv4aBUkmQ9/SLNdxcfv6SzHHb0cl4+M3he6doAw+0lC5QzkNxNSelYt9+ALBG1hlK00sP/sUjyiJa4k8X20PzZWuPg83w+JVEz2nOsVq/fxYJe9dkkBAhT30lg4+Do5qH0IKK/vnbktDXInNWeIffXqBK59AvVQ2ZTanNF79GJGfKcRHAfCQOyaHq5fuFfj25z1tTyWewMVK6Zx8K+y9eKeq/0mBEH0+vjVbsx05eQcd6+bhzYiOwFumgv6DhiVelzQ3rOBD6w8yVJr5dghzROL5w+04tmytqEHEVHdHPXYr8OynxcjF0Zv/rJyHmra+LvhPttbnULP0UUWkgzzbNlBxtLvNkBfCFKH/crgCmTutFhs6eRsJXnAnYrIs102Go24O5wysHASIU6HzXsF0bsGU03wq9LxFbj8gjFLlReiLNiYtIYnjpxoC9J3Ml+yb31WNXARVrT+dnnZ5J41b4qmeGC77/14lpk9JYkonUrZj9x73l8tV7e94mcxeUkc6P+stZSKimBLL72rqEhTb4o7LloZNql9k6rrTy8X7YcRGzhH5t1LFP1h6egUC1Kao/KSEj8DSsDO0UGsakCyL2pMv/GIWIio0RU/928qLfENTz7osHy4sZJ9tpSPJrcGULCAZUafQhVqNRela2x2Ra2qCW+9C7DwWgSNCBcgLYVNl0GDG//UwdNq5N+R9lx90qitVIbgOspmO6y5U4Cen9qpxq00nGCiBE7f7UxQegY/UhStZP9TVK7ZSR/X5Zbjtf89ipEX51J909sgeg/wd6OqY3iy6buLZYJWlC93mlbSS2IDr2rDFBWeQ== X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: b05888fd-ea4c-4e44-7fb2-08da5953ada1 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4972.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2022 22:15:15.7171 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hVb7q+/nZEJ02O8dpo9Hhi8JshKxEhRizjnueMDtWBwElxRml/dpUCQEn0Ly9k4m9JqC8et33IRDgUFkAoY2XQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR03MB3883 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This adds appropriate bindings for the macs which use the SerDes. The 156.25MHz fixed clock is a crystal. The 100MHz clocks (there are actually 3) come from a Renesas 6V49205B at address 69 on i2c0. There is no driver for this device (and as far as I know all you can do with the 100MHz clocks is gate them), so I have chosen to model it as a single fixed clock. Note: the SerDes1 lane numbering for the LS1046A is *reversed*. This means that Lane A (what the driver thinks is lane 0) uses pins SD1_TX3_P/N. Because this will break ethernet if the serdes is not enabled, enable the serdes driver by default on Layerscape. Signed-off-by: Sean Anderson --- Please let me know if there is a better/more specific config I can use here. (no changes since v1) .../boot/dts/freescale/fsl-ls1046a-rdb.dts | 34 +++++++++++++++++++ drivers/phy/freescale/Kconfig | 1 + 2 files changed, 35 insertions(+) diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dts b/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dts index 7025aad8ae89..4f4dd0ed8c53 100644 --- a/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dts +++ b/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dts @@ -26,6 +26,32 @@ aliases { chosen { stdout-path = "serial0:115200n8"; }; + + clocks { + clk_100mhz: clock-100mhz { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <100000000>; + }; + + clk_156mhz: clock-156mhz { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <156250000>; + }; + }; +}; + +&serdes1 { + clocks = <&clk_100mhz>, <&clk_156mhz>; + clock-names = "ref0", "ref1"; + status = "okay"; +}; + +&serdes2 { + clocks = <&clk_100mhz>, <&clk_100mhz>; + clock-names = "ref0", "ref1"; + status = "okay"; }; &duart0 { @@ -140,21 +166,29 @@ ethernet@e6000 { ethernet@e8000 { phy-handle = <&sgmii_phy1>; phy-connection-type = "sgmii"; + phys = <&serdes1 1>; + phy-names = "serdes"; }; ethernet@ea000 { phy-handle = <&sgmii_phy2>; phy-connection-type = "sgmii"; + phys = <&serdes1 0>; + phy-names = "serdes"; }; ethernet@f0000 { /* 10GEC1 */ phy-handle = <&aqr106_phy>; phy-connection-type = "xgmii"; + phys = <&serdes1 3>; + phy-names = "serdes"; }; ethernet@f2000 { /* 10GEC2 */ fixed-link = <0 1 1000 0 0>; phy-connection-type = "xgmii"; + phys = <&serdes1 2>; + phy-names = "serdes"; }; mdio@fc000 { diff --git a/drivers/phy/freescale/Kconfig b/drivers/phy/freescale/Kconfig index 857b4d123515..c9f687384c13 100644 --- a/drivers/phy/freescale/Kconfig +++ b/drivers/phy/freescale/Kconfig @@ -43,6 +43,7 @@ config PHY_FSL_LYNX_10G tristate "Freescale Layerscale Lynx 10G SerDes support" select GENERIC_PHY select REGMAP_MMIO + default y if ARCH_LAYERSCAPE help This adds support for the Lynx "SerDes" devices found on various QorIQ SoCs. There may be up to four SerDes devices on each SoC, and each