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 CDC21C25B4E for ; Sun, 22 Jan 2023 22:51:26 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C385A85695; Sun, 22 Jan 2023 23:51:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sholland.org header.i=@sholland.org header.b="QSpfR52l"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="sr8/LlC5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EDC9885695; Sun, 22 Jan 2023 23:51:16 +0100 (CET) Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1566B855EF for ; Sun, 22 Jan 2023 23:51:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=samuel@sholland.org Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 66B9D32002E8; Sun, 22 Jan 2023 17:51:09 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sun, 22 Jan 2023 17:51:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1674427869; x=1674514269; bh=LV 2ITr2cmkhq4LatGAYwkRutzoT5N3bxPz4QBYVVKBA=; b=QSpfR52lIOa1CmaeD7 sD2zjwe+YSA+zs2k0oig8kSwW3IA0RamEBJr/7Cs1Rlg4EzzVcuMtyA4BvtHgHof /eDewVSlUsFi3PN8Jb1QtTl2GMbseTRi7eT8UnEmzZMba06x9fNTmHj3ap4Qzr7M BLjCPRhNA7hEwVdA4ZPTLLMrIkr7V1BxSf+35QO6cg3+sSamtOO44hjTkMvouIVW Aw2oDMeM5VMJP0dkiqt1ZP2zBDT4ZD8Hr2Gpb0/g3dBtiInhVDFXAUICAUhVESVZ 4s2wLwgkhw9GWEsAZDflv4xa78GssDnQH4iXYFhGBiRBejBsHvKIyCOWBajl5jkE EpqA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1674427869; x=1674514269; bh=LV2ITr2cmkhq4 LatGAYwkRutzoT5N3bxPz4QBYVVKBA=; b=sr8/LlC5XFIblB8nQcn6aRPqSYt1b +nTkoWJQuHqh9tZnnV8zha4nJuCUm+CtDA1J4799mjcfXO/HzI0yZi2R2EY99UXf AVvaN75GGPbEE7n6FwzLr9S8C+4y1tIaHrT9ZsYQ41/EQppaXYeq2IKrwHml5EUP uMzQPYINUXeH3utXQKjOo/yUMshU8K1LQN9qpPzLBr2E4bs/mW7Dmf2mZy9Z7drW opxlv8Jgd04hOWGGA2ne+nODZ8MzWS3r/Xr+v1owrteVvfVYN8yGXu2RX4G1rGM4 jlzI3UeIUhTPgHPOwrj+Du1nCgAxlckpn4XWR9mJu8wAmpNY0IkZP4o1A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddujedgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepufgrmhhu vghlucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecugg ftrfgrthhtvghrnhepudekteeuudehtdelteevgfduvddvjefhfedulefgudevgeeghefg udefiedtveetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepshgrmhhuvghlsehshhholhhlrghnugdrohhrgh X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 22 Jan 2023 17:51:08 -0500 (EST) From: Samuel Holland To: Andre Przywara , Jagan Teki Cc: Samuel Holland , Joe Hershberger , Ramon Fried , u-boot@lists.denx.de Subject: [PATCH v2 1/5] net: sun8i-emac: Add a structure for variant data Date: Sun, 22 Jan 2023 16:51:02 -0600 Message-Id: <20230122225107.62464-2-samuel@sholland.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20230122225107.62464-1-samuel@sholland.org> References: <20230122225107.62464-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 --- 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 }, { } }; -- 2.37.4