Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2070062rwd; Fri, 26 May 2023 00:58:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6NxcI3NOJkccaMTk57SjaEcemM4lG97tD7T4NIGc+5CJUrVMzUhmMLBWaxrcvXQYJ8Xp+u X-Received: by 2002:a17:902:f543:b0:1a6:45e5:a26a with SMTP id h3-20020a170902f54300b001a645e5a26amr1996870plf.27.1685087901266; Fri, 26 May 2023 00:58:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685087901; cv=none; d=google.com; s=arc-20160816; b=ESlZTd6lcuqy77TEde1dDrCAUPwH+UMFCD8WhjSD+zx2H7haX64bSLO7AMUfjSotIF 4+AQpijkyyYt9C9TrMwsjjlCfVIEoI7TLwWDMZ/5nDKSIy0jMf14aeTpcp3uOnF1lWDu Q4HyLUqjgPvWTcwiiy3S3utq0qxfrbs/q/JDVvlC6JUZdQo0SAT8XexlfWXMVaIHtJq4 5QE28JQ+nEImifu9FTAW0wtm3/FUoYWEb+x+dZiNBM6pK26mRMExAoPcDQ+yI/8paMgt Vgz5BFyDsRPg3ecWetedQItnWmpWTCqxs+VM41v/ntwYVOeU9lZKOOR5rbB/wc10UYz3 CL1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hgk3lxLbNo2xoxXLggeXdKbVXEX79dadPfwJNxSe0cA=; b=digE3Q8Hj8TbS1bNUmy7H3wJLwcbs3b3NGFwiahLNztr5sewb4ZAvb7zmWfvMIaIwb 2g0yo8jFNXgfzm3MbKcnARqHelqoEY8/W68vlhdITwQb7WOqsRDDCY2o4JPcgRkihPs3 6Ta3cPVQ72Y7Hx44N7xrnUN2dpApqXHx/Twi6830e3S9cSW3v1B2n5xQEBNtMweThIUH poJSZBoso+pS6ZX50c6319a4R/bQe5ODdbWwHg4YMcSmUOijAVrZIohFoKcPTBbISkt0 HvBUsjuGu6uDny0HfzsmcAgdCAEyPWfVhrG9KuqKqhFVTwJ/D0BUvbig3qrCpg8CACjE i+Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=mkOtzGgk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n11-20020a170902e54b00b001ab23ced2d2si579143plf.613.2023.05.26.00.58.07; Fri, 26 May 2023 00:58:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=mkOtzGgk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242350AbjEZHnS (ORCPT + 99 others); Fri, 26 May 2023 03:43:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242526AbjEZHnJ (ORCPT ); Fri, 26 May 2023 03:43:09 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42AEB13A; Fri, 26 May 2023 00:43:05 -0700 (PDT) X-GND-Sasl: maxime.chevallier@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1685086981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hgk3lxLbNo2xoxXLggeXdKbVXEX79dadPfwJNxSe0cA=; b=mkOtzGgkABIjstbcWvKTxyhZaqAmZv+d8FI5wxh4Sd+sEHjrN+d2Ohj8CQGuXsOAScbdkX KrSgRa2BVGPJhqcW4uhBAGq8Bn6+qHpCNBTpoTYhQNq7gBl7vCgyTQasKXgmYdDZPr2xd2 7M52u8fCwo15gj6Nd5+15NXXzZ1J13C0MH+t/F6jUpHjcofiNuYH/0DXrcIaiAj529e5YO YnP/OBsOZPOwucoyQVeRBeHS7ygGgvXuEZvTkoz2nwKsBxjXG1CYxFa5FPed+sQQONQ8lC eVKq2RzMWR9YjoV7Rk8gtlaHGQDlCqJJPdHDMtR4dwPM7Gdk9fGjUebPKy5XFg== X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id DD85E1C0006; Fri, 26 May 2023 07:42:59 +0000 (UTC) From: Maxime Chevallier To: Mark Brown , davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, alexis.lothore@bootlin.com, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Florian Fainelli , Heiner Kallweit , Russell King , Vladimir Oltean , Ioana Ciornei , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Maxime Coquelin , Jose Abreu , Alexandre Torgue , Giuseppe Cavallaro , Simon Horman Subject: [PATCH net-next v3 2/4] net: ethernet: altera-tse: Convert to mdio-regmap and use PCS Lynx Date: Fri, 26 May 2023 09:42:50 +0200 Message-Id: <20230526074252.480200-3-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230526074252.480200-1-maxime.chevallier@bootlin.com> References: <20230526074252.480200-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The newly introduced regmap-based MDIO driver allows for an easy mapping of an mdiodevice onto the memory-mapped TSE PCS, which is actually a Lynx PCS. Convert Altera TSE to use this PCS instead of the pcs-altera-tse, which is nothing more than a memory-mapped Lynx PCS. Signed-off-by: Maxime Chevallier --- V2->V3 : No changes V1->V2 : No changes drivers/net/ethernet/altera/altera_tse.h | 1 + drivers/net/ethernet/altera/altera_tse_main.c | 57 +++++++++++++++++-- include/linux/mdio/mdio-regmap.h | 2 + 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/altera/altera_tse.h b/drivers/net/ethernet/altera/altera_tse.h index db5eed06e92d..d50cf440d01b 100644 --- a/drivers/net/ethernet/altera/altera_tse.h +++ b/drivers/net/ethernet/altera/altera_tse.h @@ -477,6 +477,7 @@ struct altera_tse_private { struct phylink *phylink; struct phylink_config phylink_config; struct phylink_pcs *pcs; + struct mdio_device *pcs_mdiodev; }; /* Function prototypes diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c index 190ff1bcd94e..66db6a7d0b22 100644 --- a/drivers/net/ethernet/altera/altera_tse_main.c +++ b/drivers/net/ethernet/altera/altera_tse_main.c @@ -27,14 +27,16 @@ #include #include #include +#include #include #include #include #include #include -#include +#include #include #include +#include #include #include @@ -1134,13 +1136,21 @@ static int altera_tse_probe(struct platform_device *pdev) const struct of_device_id *of_id = NULL; struct altera_tse_private *priv; struct resource *control_port; + struct regmap *pcs_regmap; struct resource *dma_res; struct resource *pcs_res; + struct mii_bus *pcs_bus; struct net_device *ndev; void __iomem *descmap; - int pcs_reg_width = 2; int ret = -ENODEV; + struct regmap_config pcs_regmap_cfg; + + struct mdio_regmap_config mrc = { + .parent = &pdev->dev, + .valid_addr = 0x0, + }; + ndev = alloc_etherdev(sizeof(struct altera_tse_private)); if (!ndev) { dev_err(&pdev->dev, "Could not allocate network device\n"); @@ -1258,10 +1268,29 @@ static int altera_tse_probe(struct platform_device *pdev) ret = request_and_map(pdev, "pcs", &pcs_res, &priv->pcs_base); if (ret) { + /* If we can't find a dedicated resource for the PCS, fallback + * to the internal PCS, that has a different address stride + */ priv->pcs_base = priv->mac_dev + tse_csroffs(mdio_phy0); - pcs_reg_width = 4; + pcs_regmap_cfg.reg_bits = 32; + /* Values are MDIO-like values, on 16 bits */ + pcs_regmap_cfg.val_bits = 16; + pcs_regmap_cfg.reg_shift = REGMAP_UPSHIFT(2); + } else { + pcs_regmap_cfg.reg_bits = 16; + pcs_regmap_cfg.val_bits = 16; + pcs_regmap_cfg.reg_shift = REGMAP_UPSHIFT(1); } + /* Create a regmap for the PCS so that it can be used by the PCS driver */ + pcs_regmap = devm_regmap_init_mmio(&pdev->dev, priv->pcs_base, + &pcs_regmap_cfg); + if (IS_ERR(pcs_regmap)) { + ret = PTR_ERR(pcs_regmap); + goto err_free_netdev; + } + mrc.regmap = pcs_regmap; + /* Rx IRQ */ priv->rx_irq = platform_get_irq_byname(pdev, "rx_irq"); if (priv->rx_irq == -ENXIO) { @@ -1384,7 +1413,20 @@ static int altera_tse_probe(struct platform_device *pdev) (unsigned long) control_port->start, priv->rx_irq, priv->tx_irq); - priv->pcs = alt_tse_pcs_create(ndev, priv->pcs_base, pcs_reg_width); + snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", ndev->name); + pcs_bus = devm_mdio_regmap_register(&pdev->dev, &mrc); + if (IS_ERR(pcs_bus)) { + ret = PTR_ERR(pcs_bus); + goto err_init_phy; + } + + priv->pcs_mdiodev = mdio_device_create(pcs_bus, 0); + + priv->pcs = lynx_pcs_create(priv->pcs_mdiodev); + if (!priv->pcs) { + ret = -ENODEV; + goto err_init_phy; + } priv->phylink_config.dev = &ndev->dev; priv->phylink_config.type = PHYLINK_NETDEV; @@ -1407,11 +1449,12 @@ static int altera_tse_probe(struct platform_device *pdev) if (IS_ERR(priv->phylink)) { dev_err(&pdev->dev, "failed to create phylink\n"); ret = PTR_ERR(priv->phylink); - goto err_init_phy; + goto err_pcs; } return 0; - +err_pcs: + mdio_device_free(priv->pcs_mdiodev); err_init_phy: unregister_netdev(ndev); err_register_netdev: @@ -1433,6 +1476,8 @@ static int altera_tse_remove(struct platform_device *pdev) altera_tse_mdio_destroy(ndev); unregister_netdev(ndev); phylink_destroy(priv->phylink); + mdio_device_free(priv->pcs_mdiodev); + free_netdev(ndev); return 0; diff --git a/include/linux/mdio/mdio-regmap.h b/include/linux/mdio/mdio-regmap.h index b8508f152552..679d9069846b 100644 --- a/include/linux/mdio/mdio-regmap.h +++ b/include/linux/mdio/mdio-regmap.h @@ -7,6 +7,8 @@ #ifndef MDIO_REGMAP_H #define MDIO_REGMAP_H +#include + struct device; struct regmap; -- 2.40.1