From patchwork Thu Sep 24 00:59:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Nemirovsky X-Patchwork-Id: 1370184 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cortina-access.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=CortinaAccess.onmicrosoft.com header.i=@CortinaAccess.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-CortinaAccess-onmicrosoft-com header.b=wx99w5kR; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BxcCN4j6jz9sSt for ; Thu, 24 Sep 2020 10:59:54 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5A04C824F5; Thu, 24 Sep 2020 02:59:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=cortina-access.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=CortinaAccess.onmicrosoft.com header.i=@CortinaAccess.onmicrosoft.com header.b="wx99w5kR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7F186824F5; Thu, 24 Sep 2020 02:59:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from KOR01-PS2-obe.outbound.protection.outlook.com (mail-ps2kor01on062e.outbound.protection.outlook.com [IPv6:2a01:111:f400:fead::62e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 75330824F5 for ; Thu, 24 Sep 2020 02:59:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=cortina-access.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=Alex.Nemirovsky@cortina-access.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GKtZhT+XQIuFL00EM2wnb86+nuPbYVc/uyUI1IkdtcZL6/A7kYZs/fvAatDkCDTw+wJZBftF2CLKPQBIe7C8YZ5dyG6UWlf/TuAdTg5G7QO/U+OqBZCxRWKVLT3G7BZyl9/H/5b40F0371oW12PRoFazv//qeqi00mGBYR6bc+DhiQcuBg7QFU5/h5lHmP7VUhfmcSyQbzPslcGy8wk6yMgU9ixz0LCVxQuQ2z6cOVMlE/xpE8vUqrq96NO8IHRHmZrkRVW1VaWe90/U6uDCrllL8H0w4xqbjZutlD46QgqHs0rP/7Te/t60z7LXzAW8yX5tDqaDbhXGgndDgHB9Mw== 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-SenderADCheck; bh=7BkPZmxKnhTicGV2FZgHHHdqYRXDlMXsRflIpJeU1nA=; b=WBk2Txlz3OyOmXxm7gJ3WDf12A1GyGvYYP9H2J0MpbQgxexLlL/CULwuEmTsMoGPOD5Fdhhk4WTH6ebtdv8DRfTVRHuhDEJKtA+hZs2qetpaugFmM7O3JW8TKtnAkO3VAFpRq7nPr2wmYd67ZM7WY+P91ckC7Pk9Rx7SC6rmorq90NeS66OUgdzpPVrFLnxscJ8q3tMOuLN3v1zwPHhl//wOZGCHKoO3rOwRhmZKGEIBBUVv5kYgMSaRDHGJvJmrUikSuCbiaKwWZGcZ9dylBKuyg70kY5IOswKNpHavMTaiBuCMSr7eaUstdZN33Y9sTc8OF9pHgTnCfvI1a0KERw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cortina-access.com; dmarc=pass action=none header.from=cortina-access.com; dkim=pass header.d=cortina-access.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CortinaAccess.onmicrosoft.com; s=selector2-CortinaAccess-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7BkPZmxKnhTicGV2FZgHHHdqYRXDlMXsRflIpJeU1nA=; b=wx99w5kR1+BdpG0ijOk7jzcN2/uMaJhvEqpDff5xfDJQR3mqPttagIe9wlqJS+Qt8aqgJWgdApgMJoHjklN89edJbQ93uKn64Bd/VATVSxzuVFneki6fXbqQeqd5syuK20ZqIY6y/GuNcsLuGNs/kKSjWTgzHBHTqtAVRPOVEQo= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=cortina-access.com; Received: from PU1PR01MB1964.apcprd01.prod.exchangelabs.com (2603:1096:803:1e::16) by PS2PR01MB2230.apcprd01.prod.exchangelabs.com (2603:1096:300:31::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Thu, 24 Sep 2020 00:59:26 +0000 Received: from PU1PR01MB1964.apcprd01.prod.exchangelabs.com ([fe80::1dfa:20b4:753e:68df]) by PU1PR01MB1964.apcprd01.prod.exchangelabs.com ([fe80::1dfa:20b4:753e:68df%7]) with mapi id 15.20.3391.026; Thu, 24 Sep 2020 00:59:26 +0000 From: Alex Nemirovsky To: u-boot@lists.denx.de Cc: Abbie Chang , Alex Nemirovsky , Joe Hershberger , Tom Rini , Aaron Tseng Subject: [PATCH v3 2/3] net: phy: ca_phy: Add driver for CAxxxx SoCs Date: Wed, 23 Sep 2020 17:59:13 -0700 Message-Id: <1600909154-1713-2-git-send-email-alex.nemirovsky@cortina-access.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600909154-1713-1-git-send-email-alex.nemirovsky@cortina-access.com> References: <1600909154-1713-1-git-send-email-alex.nemirovsky@cortina-access.com> X-ClientProxiedBy: MWHPR20CA0005.namprd20.prod.outlook.com (2603:10b6:300:13d::15) To PU1PR01MB1964.apcprd01.prod.exchangelabs.com (2603:1096:803:1e::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from smok.hrh.localdomain (70.58.207.205) by MWHPR20CA0005.namprd20.prod.outlook.com (2603:10b6:300:13d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3391.14 via Frontend Transport; Thu, 24 Sep 2020 00:59:25 +0000 X-Mailer: git-send-email 2.7.4 X-Originating-IP: [70.58.207.205] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 24f4fac5-0985-4b40-11b9-08d860251594 X-MS-TrafficTypeDiagnostic: PS2PR01MB2230: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-LD-Processed: 0694623c-6669-497c-89c3-3a32a9934313,ExtAddr X-MS-Oob-TLC-OOBClassifiers: OLM:59; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2XSWx3VHBzbOcEisPDPCuHz1yoMr4fyld9no3s6lN2sGFAhq9eIk1VEwrP+JEMf9ynxh0spG7sB7moFXdYQUSrdponu6i3+8JBZK+6U3JeqEmH9e5SOEShz3e0c4pfJz/jjuQDIzQP51qmbIWtnd9vezXiM8cHA0kDFFswmoWdQPXPCHhrbPvMi7xsAISKwQKJ7DMVTSSEBTnx9XjiGJou66IiCdtjzMgOJTdyZRmVVAnE0zFCEDL9o/2wpAH0Ju79xMEMjaMh0t5Ymy4d2M+5i1amC4IER/CFymMZuOomAVHJaCJLSpUfSRkyDFsTY7 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PU1PR01MB1964.apcprd01.prod.exchangelabs.com; PTR:; CAT:NONE; SFS:(6029001)(136003)(396003)(39840400004)(376002)(346002)(366004)(66556008)(6486002)(16526019)(86362001)(956004)(5660300002)(2616005)(26005)(54906003)(6506007)(316002)(36756003)(52116002)(186003)(6916009)(44832011)(8676002)(6666004)(478600001)(83380400001)(6512007)(107886003)(66946007)(8936002)(2906002)(4326008)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: dYH8KgivTZ8AUNbmR4TQ9lc52QOYsAHLMPujIIKamcxoooTxygzLqfs8x0CDuKF9kOKc20BrzfYGU4pCi93iuY8lWOzDubmyMdGW9/ykAtI6Ob0jgD/sxVIIBdeUtblMCTcSl2xaWYf4dw2S7cS2SAJtpVx+FNe/ooZ4meWe8fc0fy9p0G+dPv+Ss49DrX59hWXpWiwyR+e51VPim7C3TMqlZ3pSxl7hbKQBuDD7RZkUfQOevoXV2aVuDgYDLuV5nHgaTjHTAVIma9DVoV5WAHVhyhiL4XinhdqwtJaAmqao4Eoi1DCWX26QbRil8G4+oMFKRMmijDHdaXAWuMksMLQ0UGX80KS1aKItxM6H4auAOOyjDOV84Rw2wAk/A3ojASp/Lz6gaX7/hJkRXBVHM5iu3DNDPjlQOJiaxbJDUCxB/a9qf5wCDc3Bt+wjKp7rJLLgznA+/KIi716Hgqe+hzwyEX40cVrbWeR3ht8kkKaSxUYFR3SAUb3xTnQlFokqrn8K2sJtEmW1kh919VF/XOAvcwWXW+vgb0/z8Flc+wHZ8RldCo5hJ3FXN06MdBoQAwwES9Xb6H6jv1VUhP90Di9Vjg5b5UsWJO6vX7AZbmNSMBvX8cbQE1zxlVgtZeSiqKcvZIfyDoECcE7bU3Xtdg== X-OriginatorOrg: CORTINA-ACCESS.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 24f4fac5-0985-4b40-11b9-08d860251594 X-MS-Exchange-CrossTenant-AuthSource: PU1PR01MB1964.apcprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2020 00:59:26.8095 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0694623c-6669-497c-89c3-3a32a9934313 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XW5bom9NYlkbuTCS3hYyK70/wZVlw1SlCNsCTnfNJm6lG+pPJq9w01AE3UPfY5mSTvANBexLfkLji3pUEeeu8BrBqh0OmHp2rcsGp3WpHUSv6y/ElGv+3r5NwSQw7g1r X-MS-Exchange-Transport-CrossTenantHeadersStamped: PS2PR01MB2230 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Abbie Chang Add phy driver support for MACs embedded inside Cortina Access SoCs Signed-off-by: Abbie Chang Signed-off-by: Alex Nemirovsky CC: Joe Hershberger CC: Tom Rini CC: Aaron Tseng Moved out PHY specific code out of Cortina NI Ethernet driver and into a Cortina Access PHY interface driver --- (no changes since v1) MAINTAINERS | 2 + drivers/net/phy/Kconfig | 9 ++++ drivers/net/phy/Makefile | 1 + drivers/net/phy/ca_phy.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 2 + include/phy.h | 1 + 6 files changed, 148 insertions(+) create mode 100644 drivers/net/phy/ca_phy.c diff --git a/MAINTAINERS b/MAINTAINERS index dd4156c..a9ab791 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -199,6 +199,7 @@ F: drivers/i2c/i2c-cortina.c F: drivers/i2c/i2c-cortina.h F: drivers/net/cortina_ni.c F: drivers/net/cortina_ni.h +F: drivers/net/phy/ca_phy.c ARM/CZ.NIC TURRIS MOX SUPPORT M: Marek Behun @@ -785,6 +786,7 @@ F: drivers/i2c/i2c-cortina.c F: drivers/i2c/i2c-cortina.h F: drivers/net/cortina_ni.c F: drivers/net/cortina_ni.h +F: drivers/net/phy/ca_phy.c MIPS MSCC M: Gregory CLEMENT diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 4e1a93b..7aa60be 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -122,6 +122,15 @@ config SYS_CORTINA_FW_IN_SPIFLASH endchoice +config PHY_CORTINA_ACCESS + bool "Cortina Access Ethernet PHYs support" + default y + depends on CORTINA_NI_ENET + help + Cortina Access Ethernet PHYs support + + Cortina Access Ethernet PHYs init process + config PHY_DAVICOM bool "Davicom Ethernet PHYs support" diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index 6e72233..e967f82 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_PHY_AQUANTIA) += aquantia.o obj-$(CONFIG_PHY_ATHEROS) += atheros.o obj-$(CONFIG_PHY_BROADCOM) += broadcom.o obj-$(CONFIG_PHY_CORTINA) += cortina.o +obj-$(CONFIG_PHY_CORTINA_ACCESS) += ca_phy.o obj-$(CONFIG_PHY_DAVICOM) += davicom.o obj-$(CONFIG_PHY_ET1011C) += et1011c.o obj-$(CONFIG_PHY_LXT) += lxt.o diff --git a/drivers/net/phy/ca_phy.c b/drivers/net/phy/ca_phy.c new file mode 100644 index 0000000..d3a49f9 --- /dev/null +++ b/drivers/net/phy/ca_phy.c @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Cortina CS4315/CS4340 10G PHY drivers + * + * Copyright 2014 Freescale Semiconductor, Inc. + * Copyright 2018 NXP + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PHY_ID_RTL8211_EXT 0x001cc910 +#define PHY_ID_RTL8211_INT 0x001cc980 +#define PHY_ID_MASK 0xFFFFFFF0 + +__weak void __internal_phy_init(struct phy_device *phydev, int reset_phy) +{ + u8 phy_addr; + u16 data; + + /* should initialize 4 GPHYs at once */ + for (phy_addr = 4; phy_addr > 0; phy_addr--) { + phydev->addr = phy_addr; + phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0BC6); + phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x0053); + phy_write(phydev, MDIO_DEVAD_NONE, 18, 0x4003); + phy_write(phydev, MDIO_DEVAD_NONE, 22, 0x7e01); + phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0A42); + phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0A40); + phy_write(phydev, MDIO_DEVAD_NONE, 0, 0x1140); + } + + /* workaround to fix GPHY fail */ + for (phy_addr = 1; phy_addr < 5; phy_addr++) { + /* Clear clock fail interrupt */ + phydev->addr = phy_addr; + phy_write(phydev, MDIO_DEVAD_NONE, 31, 0xB90); + data = phy_read(phydev, MDIO_DEVAD_NONE, 19); + if (data == 0x10) { + phy_write(phydev, MDIO_DEVAD_NONE, 31, 0xB90); + data = phy_read(phydev, MDIO_DEVAD_NONE, 19); + printf("%s: read again.\n", __func__); + } + + printf("%s: phy_addr=%d, read register 19, value=0x%x\n", + __func__, phy_addr, data); + } +} + +__weak void __external_phy_init(struct phy_device *phydev, int reset_phy) +{ + u16 val; + + /* Disable response PHYAD=0 function of RTL8211 series PHY */ + /* REG31 write 0x0007, set to extension page */ + phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0007); + + /* REG30 write 0x002C, set to extension page 44 */ + phy_write(phydev, MDIO_DEVAD_NONE, 30, 0x002C); + + /* + * REG27 write bit[2] = 0 disable response PHYAD = 0 function. + * we should read REG27 and clear bit[2], and write back + */ + val = phy_read(phydev, MDIO_DEVAD_NONE, 27); + val &= ~(1 << 2); + phy_write(phydev, MDIO_DEVAD_NONE, 27, val); + + /* REG31 write 0X0000, back to page0 */ + phy_write(phydev, MDIO_DEVAD_NONE, 31, 0x0000); +} + +static int rtl8211_external_config(struct phy_device *phydev) +{ + __external_phy_init(phydev, 0); + printf("%s: initialize RTL8211 external done.\n", __func__); + return 0; +} + +static int rtl8211_internal_config(struct phy_device *phydev) +{ + struct phy_device phydev_init; + + memcpy(&phydev_init, phydev, sizeof(struct phy_device)); + /* should initialize 4 GPHYs at once */ + __internal_phy_init(&phydev_init, 0); + printf("%s: initialize RTL8211 internal done.\n", __func__); + return 0; +} + +static int rtl8211_probe(struct phy_device *phydev) +{ + /* disable reset behavior */ + phydev->flags = PHY_FLAG_BROKEN_RESET; + return 0; +} + +/* Support for RTL8211 External PHY */ +struct phy_driver rtl8211_external_driver = { + .name = "Cortina RTL8211 External", + .uid = PHY_ID_RTL8211_EXT, + .mask = PHY_ID_MASK, + .features = PHY_GBIT_FEATURES, + .config = &rtl8211_external_config, + .probe = &rtl8211_probe, + .startup = &genphy_startup, +}; + +/* Support for RTL8211 Internal PHY */ +struct phy_driver rtl8211_internal_driver = { + .name = "Cortina RTL8211 Inrernal", + .uid = PHY_ID_RTL8211_INT, + .mask = PHY_ID_MASK, + .features = PHY_GBIT_FEATURES, + .config = &rtl8211_internal_config, + .probe = &rtl8211_probe, + .startup = &genphy_startup, +}; + +int phy_cortina_access_init(void) +{ + phy_register(&rtl8211_external_driver); + phy_register(&rtl8211_internal_driver); + return 0; +} diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 6778989..f0b4aa4 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -500,6 +500,8 @@ int phy_init(void) #ifdef CONFIG_PHY_CORTINA phy_cortina_init(); #endif + if (IS_ENABLED(CONFIG_PHY_CORTINA_ACCESS)) + phy_cortina_access_init(); #ifdef CONFIG_PHY_DAVICOM phy_davicom_init(); #endif diff --git a/include/phy.h b/include/phy.h index 1dbbf65..c2ecd70 100644 --- a/include/phy.h +++ b/include/phy.h @@ -493,6 +493,7 @@ int phy_aquantia_init(void); int phy_atheros_init(void); int phy_broadcom_init(void); int phy_cortina_init(void); +int phy_cortina_access_init(void); int phy_davicom_init(void); int phy_et1011c_init(void); int phy_lxt_init(void);