From patchwork Mon Jun 24 03:26:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1121033 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="ZU7o4i+q"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.b="IdoUgqr/"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45XFBB3hbdz9s4Y for ; Mon, 24 Jun 2019 13:28:34 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 3678EC21F07; Mon, 24 Jun 2019 03:28:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 14902C21F18; Mon, 24 Jun 2019 03:28:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1FD68C21F04; Mon, 24 Jun 2019 03:26:42 +0000 (UTC) Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by lists.denx.de (Postfix) with ESMTPS id 17B07C21F1B for ; Mon, 24 Jun 2019 03:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1561346797; x=1592882797; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=slchnvFgbuVYUIYsaFX8kqw1kkN6dW0YyMNH4jpUbLY=; b=ZU7o4i+qFL9QdLcfra4bm6F3YD3ePC9702NnR5EjGZLx7ls5ow2KYWrC 3iOcMzBTvO6xAHOC14GAON6L7+i7SIRZFVv2c4FkfYMLpLymFRySWK2C5 V9ZjE6AMA2UwDfHidyCHJTsN+nil0eAH3egkzLJRAiWZKtMZJPsOn5v8D FtFCFP1oNNdTE8/04L4oj7ZlSSixvOrbRI9JbOMARf1eqIbMuqKBr7ASq 6a44beDgMhZBLbbDys7/Huy37uCDAAEBxT0x4hOfCSdEMaOdvZWMa3A/s aprZ1Hqzzja9ptpgD9QkiQTG1usIqCERAj20+htnoVAv26IyQsRE2md37 Q==; X-IronPort-AV: E=Sophos;i="5.63,410,1557158400"; d="scan'208";a="217713026" Received: from mail-by2nam01lp2054.outbound.protection.outlook.com (HELO NAM01-BY2-obe.outbound.protection.outlook.com) ([104.47.34.54]) by ob1.hgst.iphmx.com with ESMTP; 24 Jun 2019 11:26:34 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=slchnvFgbuVYUIYsaFX8kqw1kkN6dW0YyMNH4jpUbLY=; b=IdoUgqr/pOuwtHGv5axvawWnkCZM4TiGh1D5Ez+Jne7bX4UnXNgZPWK0yhXH2MZ8xTRPdI9qxKps3VQyP9N6zmxXYKcljCj9twcmKN+edm5qTGf3l79cGaIaNgXiljRs5bOCBNmrjIszs7ICy7wIKqxuGhYnz0Gn9s5OlJAhmX8= Received: from MN2PR04MB6061.namprd04.prod.outlook.com (20.178.246.15) by MN2PR04MB5551.namprd04.prod.outlook.com (20.178.248.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2008.16; Mon, 24 Jun 2019 03:26:33 +0000 Received: from MN2PR04MB6061.namprd04.prod.outlook.com ([fe80::84da:b4e7:4612:48b]) by MN2PR04MB6061.namprd04.prod.outlook.com ([fe80::84da:b4e7:4612:48b%7]) with mapi id 15.20.2008.014; Mon, 24 Jun 2019 03:26:33 +0000 From: Anup Patel To: Rick Chen , Bin Meng , Lukas Auer , Simon Glass Thread-Topic: [PATCH v6 6/8] net: macb: Extend MACB driver for SiFive Unleashed board Thread-Index: AQHVKjyfFrVEByDEEESED0MCENaJHQ== Date: Mon, 24 Jun 2019 03:26:33 +0000 Message-ID: <20190624032431.20854-7-anup.patel@wdc.com> References: <20190624032431.20854-1-anup.patel@wdc.com> In-Reply-To: <20190624032431.20854-1-anup.patel@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MA1PR0101CA0057.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:20::19) To MN2PR04MB6061.namprd04.prod.outlook.com (2603:10b6:208:d8::15) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Anup.Patel@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [129.253.179.161] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6c121e02-e73f-49e7-ded0-08d6f853c1b1 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:MN2PR04MB5551; x-ms-traffictypediagnostic: MN2PR04MB5551: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4941; x-forefront-prvs: 007814487B x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6029001)(136003)(396003)(366004)(346002)(376002)(39860400002)(189003)(199004)(256004)(11346002)(316002)(478600001)(72206003)(1076003)(8676002)(54906003)(5660300002)(110136005)(14454004)(50226002)(52116002)(99286004)(7736002)(6436002)(81156014)(81166006)(53936002)(66946007)(66556008)(2906002)(8936002)(66476007)(305945005)(86362001)(73956011)(6512007)(64756008)(66446008)(71190400001)(446003)(2616005)(3846002)(25786009)(4326008)(36756003)(71200400001)(476003)(44832011)(68736007)(6486002)(7416002)(102836004)(6506007)(386003)(26005)(186003)(76176011)(66066001)(6116002)(486006); DIR:OUT; SFP:1102; SCL:1; SRVR:MN2PR04MB5551; H:MN2PR04MB6061.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: uAZbfxE9z7TdpNsODPuHY3+2XnDTU2JW0NDhbe9RxeT8VAhUJGNH+IS4chSBeGByCd+pKqX2Dl0S4jiCzUOsRBGqqdeRY7bAFbRRXs8flKyvEzpiLs05kIra7VN1y2Oe8D3r5u1tbpQ1v22NdMf1htWaatJTaF+jBDpdV89iGpYNEDcUNNm9OsChvxqS/kwONAbIjcSgH9fNeX/LWcKiqwQanhl5J4SkSiVIF3tR7pwYBbp4RsRy6WzfbH4ieKEPNSg4E7ZiI9m8QrJl0QlyRaNBNpjEEBeCLx2SJxjgIfhemhMZdcU5CPqLiYyMhyplbHtLNupwJgRzLm/cYJdct3PhZtUqY3Hm2lRgroeqEgi6V4yXbvOnLqUw1AFLnv4F7fym6SE5hmjLh21OsOqlgGLFT1pJDGSCVUVUjvLfm7A= MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c121e02-e73f-49e7-ded0-08d6f853c1b1 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jun 2019 03:26:33.7686 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Anup.Patel@wdc.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB5551 Cc: U-Boot Mailing List , Palmer Dabbelt , Joe Hershberger , Alistair Francis Subject: [U-Boot] [PATCH v6 6/8] net: macb: Extend MACB driver for SiFive Unleashed board X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" The SiFive MACB ethernet has a custom TX_CLK_SEL register to select different TX clock for 1000mbps vs 10/100mbps. This patch adds SiFive MACB compatible string and extends the MACB ethernet driver to change TX clock using TX_CLK_SEL register for SiFive MACB. Signed-off-by: Anup Patel --- drivers/net/macb.c | 86 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 69 insertions(+), 17 deletions(-) diff --git a/drivers/net/macb.c b/drivers/net/macb.c index c072f99d8f..727cb0bc49 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -83,7 +83,9 @@ struct macb_dma_desc { struct macb_device { void *regs; - unsigned int dma_burst_length; + void *regs1; + + const struct macb_config*config; unsigned int rx_tail; unsigned int tx_head; @@ -123,6 +125,9 @@ struct macb_device { struct macb_config { unsigned int dma_burst_length; + + int (*probe)(struct udevice *dev); + int (*set_tx_clk)(struct udevice *dev, ulong rate); }; #ifndef CONFIG_DM_ETH @@ -483,21 +488,32 @@ static int macb_phy_find(struct macb_device *macb, const char *name) * when operation failed. */ #ifdef CONFIG_DM_ETH +static int macb_sifive_set_tx_clk(struct udevice *dev, ulong rate) +{ + struct macb_device *macb = dev_get_priv(dev); + + if (!macb->regs1) + return -ENODEV; + + /* + * SiFive GEMGXL TX clock operation mode: + * + * 0 = GMII mode. Use 125 MHz gemgxlclk from PRCI in TX logic + * and output clock on GMII output signal GTX_CLK + * 1 = MII mode. Use MII input signal TX_CLK in TX logic + */ + writel(rate != 125000000, macb->regs1); + return 0; +} + int __weak macb_linkspd_cb(struct udevice *dev, unsigned int speed) { #ifdef CONFIG_CLK + struct macb_device *macb = dev_get_priv(dev); struct clk tx_clk; ulong rate; int ret; - /* - * "tx_clk" is an optional clock source for MACB. - * Ignore if it does not exist in DT. - */ - ret = clk_get_by_name(dev, "tx_clk", &tx_clk); - if (ret) - return 0; - switch (speed) { case _10BASET: rate = 2500000; /* 2.5 MHz */ @@ -513,6 +529,17 @@ int __weak macb_linkspd_cb(struct udevice *dev, unsigned int speed) return 0; } + if (macb->config->set_tx_clk) + return macb->config->set_tx_clk(dev, rate); + + /* + * "tx_clk" is an optional clock source for MACB. + * Ignore if it does not exist in DT. + */ + ret = clk_get_by_name(dev, "tx_clk", &tx_clk); + if (ret) + return 0; + if (tx_clk.dev) { ret = clk_set_rate(&tx_clk, rate); if (ret) @@ -701,12 +728,14 @@ static void gmac_configure_dma(struct macb_device *macb) u32 buffer_size; u32 dmacfg; + if (!macb->config->dma_burst_length) + return; + buffer_size = 128 / RX_BUFFER_MULTIPLE; dmacfg = gem_readl(macb, DMACFG) & ~GEM_BF(RXBS, -1L); dmacfg |= GEM_BF(RXBS, buffer_size); - if (macb->dma_burst_length) - dmacfg = GEM_BFINS(FBLDO, macb->dma_burst_length, dmacfg); + dmacfg = GEM_BFINS(FBLDO, macb->config->dma_burst_length, dmacfg); dmacfg |= GEM_BIT(TXPBMS) | GEM_BF(RXBMS, -1L); dmacfg &= ~GEM_BIT(ENDIA_PKT); @@ -1171,13 +1200,25 @@ static const struct macb_config default_gem_config = { .dma_burst_length = 16, }; +static int macb_sifive_probe(struct udevice *dev) +{ + struct macb_device *macb = dev_get_priv(dev); + fdt_addr_t addr; + + addr = dev_read_addr_index(dev, 1); + if (addr == FDT_ADDR_T_NONE) + return -ENODEV; + macb->regs1 = (void __iomem *)addr; + + return 0; +} + static int macb_eth_probe(struct udevice *dev) { - const struct macb_config *macb_config; struct eth_pdata *pdata = dev_get_platdata(dev); struct macb_device *macb = dev_get_priv(dev); const char *phy_mode; - __maybe_unused int ret; + int ret; phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", NULL); @@ -1190,11 +1231,16 @@ static int macb_eth_probe(struct udevice *dev) macb->regs = (void *)pdata->iobase; - macb_config = (struct macb_config *)dev_get_driver_data(dev); - if (!macb_config) - macb_config = &default_gem_config; + macb->config = (struct macb_config *)dev_get_driver_data(dev); + if (!macb->config) + macb->config = &default_gem_config; + + if (macb->config->probe) { + ret = macb->config->probe(dev); + if (ret) + return ret; + } - macb->dma_burst_length = macb_config->dma_burst_length; #ifdef CONFIG_CLK ret = macb_enable_clk(dev); if (ret) @@ -1259,6 +1305,11 @@ static const struct macb_config sama5d4_config = { .dma_burst_length = 4, }; +static const struct macb_config sifive_config = { + .probe = macb_sifive_probe, + .set_tx_clk = macb_sifive_set_tx_clk, +}; + static const struct udevice_id macb_eth_ids[] = { { .compatible = "cdns,macb" }, { .compatible = "cdns,at91sam9260-macb" }, @@ -1266,6 +1317,7 @@ static const struct udevice_id macb_eth_ids[] = { { .compatible = "atmel,sama5d3-gem" }, { .compatible = "atmel,sama5d4-gem", .data = (ulong)&sama5d4_config }, { .compatible = "cdns,zynq-gem" }, + { .compatible = "sifive,fu540-macb", .data = (ulong)&sifive_config }, { } };