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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4C3A0C38142 for ; Mon, 23 Jan 2023 17:21:45 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1594285622; Mon, 23 Jan 2023 18:21:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 5BB1785748; Mon, 23 Jan 2023 18:21:41 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 922EB85351 for ; Mon, 23 Jan 2023 18:21:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A64B4C14; Mon, 23 Jan 2023 09:22:19 -0800 (PST) Received: from [10.1.26.40] (e110479.cambridge.arm.com [10.1.26.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E1CBB3F71E; Mon, 23 Jan 2023 09:21:36 -0800 (PST) Message-ID: Date: Mon, 23 Jan 2023 17:21:25 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v2 1/5] net: sun8i-emac: Add a structure for variant data Content-Language: en-GB To: Samuel Holland , Jagan Teki Cc: Joe Hershberger , Ramon Fried , u-boot@lists.denx.de References: <20230122225107.62464-1-samuel@sholland.org> <20230122225107.62464-2-samuel@sholland.org> From: Andre Przywara In-Reply-To: <20230122225107.62464-2-samuel@sholland.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean On 22/01/2023 22:51, Samuel Holland wrote: > Currently, EMAC variants are distinguished by their identity, but this > gets unwieldy as more overlapping variants are added. Add a structure so > we can describe the individual feature differences between the variants. > > Signed-off-by: Samuel Holland Looks alright, given that this is temporary/preparatory. Reviewed-by: Andre Przywara Cheers, Andre > --- > > Changes in v2: > - New patch for v2 > > drivers/net/sun8i_emac.c | 65 +++++++++++++++++++++++++++------------- > 1 file changed, 45 insertions(+), 20 deletions(-) > > diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c > index e800a326b8..986e565cd8 100644 > --- a/drivers/net/sun8i_emac.c > +++ b/drivers/net/sun8i_emac.c > @@ -127,7 +127,7 @@ > > DECLARE_GLOBAL_DATA_PTR; > > -enum emac_variant { > +enum emac_variant_id { > A83T_EMAC = 1, > H3_EMAC, > A64_EMAC, > @@ -135,6 +135,10 @@ enum emac_variant { > H6_EMAC, > }; > > +struct emac_variant { > + enum emac_variant_id variant; > +}; > + > struct emac_dma_desc { > u32 status; > u32 ctl_size; > @@ -160,7 +164,7 @@ struct emac_eth_dev { > u32 tx_slot; > bool use_internal_phy; > > - enum emac_variant variant; > + const struct emac_variant *variant; > void *mac_reg; > phys_addr_t sysctl_reg; > struct phy_device *phydev; > @@ -317,7 +321,7 @@ static int sun8i_emac_set_syscon(struct sun8i_eth_pdata *pdata, > { > u32 reg; > > - if (priv->variant == R40_GMAC) { > + if (priv->variant->variant == R40_GMAC) { > /* Select RGMII for R40 */ > reg = readl(priv->sysctl_reg + 0x164); > reg |= SC_ETCS_INT_GMII | > @@ -333,9 +337,9 @@ static int sun8i_emac_set_syscon(struct sun8i_eth_pdata *pdata, > reg = sun8i_emac_set_syscon_ephy(priv, reg); > > reg &= ~(SC_ETCS_MASK | SC_EPIT); > - if (priv->variant == H3_EMAC || > - priv->variant == A64_EMAC || > - priv->variant == H6_EMAC) > + if (priv->variant->variant == H3_EMAC || > + priv->variant->variant == A64_EMAC || > + priv->variant->variant == H6_EMAC) > reg &= ~SC_RMII_EN; > > switch (priv->interface) { > @@ -349,9 +353,9 @@ static int sun8i_emac_set_syscon(struct sun8i_eth_pdata *pdata, > reg |= SC_EPIT | SC_ETCS_INT_GMII; > break; > case PHY_INTERFACE_MODE_RMII: > - if (priv->variant == H3_EMAC || > - priv->variant == A64_EMAC || > - priv->variant == H6_EMAC) { > + if (priv->variant->variant == H3_EMAC || > + priv->variant->variant == A64_EMAC || > + priv->variant->variant == H6_EMAC) { > reg |= SC_RMII_EN | SC_ETCS_EXT_GMII; > break; > } > @@ -806,7 +810,7 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev) > return -EINVAL; > } > > - priv->variant = dev_get_driver_data(dev); > + priv->variant = (const void *)dev_get_driver_data(dev); > > if (!priv->variant) { > printf("%s: Missing variant\n", __func__); > @@ -860,7 +864,7 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev) > if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) > return -EINVAL; > > - if (priv->variant == H3_EMAC) { > + if (priv->variant->variant == H3_EMAC) { > ret = sun8i_handle_internal_phy(dev, priv); > if (ret) > return ret; > @@ -900,16 +904,37 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev) > return 0; > } > > +static const struct emac_variant emac_variant_a83t = { > + .variant = A83T_EMAC, > +}; > + > +static const struct emac_variant emac_variant_h3 = { > + .variant = H3_EMAC, > +}; > + > +static const struct emac_variant emac_variant_r40 = { > + .variant = R40_GMAC, > +}; > + > +static const struct emac_variant emac_variant_a64 = { > + .variant = A64_EMAC, > +}; > + > +static const struct emac_variant emac_variant_h6 = { > + .variant = H6_EMAC, > +}; > + > static const struct udevice_id sun8i_emac_eth_ids[] = { > - {.compatible = "allwinner,sun8i-h3-emac", .data = (uintptr_t)H3_EMAC }, > - {.compatible = "allwinner,sun50i-a64-emac", > - .data = (uintptr_t)A64_EMAC }, > - {.compatible = "allwinner,sun8i-a83t-emac", > - .data = (uintptr_t)A83T_EMAC }, > - {.compatible = "allwinner,sun8i-r40-gmac", > - .data = (uintptr_t)R40_GMAC }, > - {.compatible = "allwinner,sun50i-h6-emac", > - .data = (uintptr_t)H6_EMAC }, > + { .compatible = "allwinner,sun8i-a83t-emac", > + .data = (ulong)&emac_variant_a83t }, > + { .compatible = "allwinner,sun8i-h3-emac", > + .data = (ulong)&emac_variant_h3 }, > + { .compatible = "allwinner,sun8i-r40-gmac", > + .data = (ulong)&emac_variant_r40 }, > + { .compatible = "allwinner,sun50i-a64-emac", > + .data = (ulong)&emac_variant_a64 }, > + { .compatible = "allwinner,sun50i-h6-emac", > + .data = (ulong)&emac_variant_h6 }, > { } > }; >