Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1435379pxp; Sun, 20 Mar 2022 17:22:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTljiHacMh9nWNWkjVBly74koWaIf5k5krgpd/kz69XauS7jq5Ube2M6kL6hGj5zRfjnWk X-Received: by 2002:a17:90b:3a86:b0:1c6:5971:5980 with SMTP id om6-20020a17090b3a8600b001c659715980mr27164675pjb.68.1647822176925; Sun, 20 Mar 2022 17:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647822176; cv=none; d=google.com; s=arc-20160816; b=FV1TtAq2iVLpSLsSxelgq3JMxtX003wdRTaAY2YNKb5b9FYut5gTC249XXJFuybbIJ kwN2W1Hcp/++mbwKR8u0I8NcjcGWbLj9duqKzCYz1FzSjSx86T5bfHEGvPkh0NJCzz5G 399EP4vC1mKkwV8CFLkPQ2Is/b5W7QpsZQHnIaY4AH6FNWSGvj/K1OnDLB6A3atsWjUk uySRsjhs19qIx9pBMiYZKWWn1Tk5XGH+KaBYrUG6aOQXGpxGedUsRGag8OYORrpuMPC1 7jKmK6OLm+4Ka/V3GhfxMiURb1ZFoi7ecamATLTIcquBHkj0W1iEPgqJDE+CqV99yi23 0WUg== 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=/DLo4n9LcEDq3m+ys72xRNV4+0sMmookIoTiaSxWb4Y=; b=UYAvDgDuhMqjuWG8mEg5UgrFE1W6shWMDv5AUKcAZL7Q5Tctik8vTtTsCEJSgFL9fs Uoa8O7UBlcO0dgPRrltTVVR9RXzJE8JuA/iX3mG9H6CjWaakQXwxhlzbGehaHlsGUu8R VuXUQvHVuIDwitGT+0G7mXt7F+OavOTRKA6LszFuUHOfgyiV8ap6BBW5wHASiY7+3M19 YAHYSoPkRRQyWu3f1xr3sMguL6/i0WeI64IS3dwehlfLkCosPjwu/5Q1SY53L38mgnC3 NO09XrsYKcRaIsdKKes15zsaExZW3d0EF/bUYCbjO2XZn5VtBgiIPhhYxRJELr9jVhbb eWiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=HzaHDuVA; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv15-20020a056a00414f00b004e1a25384f6si1384672pfb.3.2022.03.20.17.22.24; Sun, 20 Mar 2022 17:22:56 -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=@walle.cc header.s=mail2016061301 header.b=HzaHDuVA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240564AbiCRUPJ (ORCPT + 99 others); Fri, 18 Mar 2022 16:15:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239948AbiCRUO6 (ORCPT ); Fri, 18 Mar 2022 16:14:58 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE1DE19C5BF; Fri, 18 Mar 2022 13:13:37 -0700 (PDT) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 29670223F0; Fri, 18 Mar 2022 21:13:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1647634416; 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=/DLo4n9LcEDq3m+ys72xRNV4+0sMmookIoTiaSxWb4Y=; b=HzaHDuVAE8+iwwhaowp63U1TPFyre7RwmpUi4gQjsQp30EUulJxZ0AooOJhxb2BVQKzPYR rs6vJYVvu1aZWwJgm06g8yTg21Efc+zq1kNhnuO3/PvHfc7C5JUkNsbi1uYS/P4jwc5loz RE2dUUCqtB2dXk0DUW/h/QqXDa0dPJQ= From: Michael Walle To: "David S . Miller" , Jakub Kicinski , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Heiner Kallweit , Russell King Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Horatiu Vultur , Michael Walle Subject: [PATCH net-next v3 3/3] net: mdio: mscc-miim: add lan966x internal phy reset support Date: Fri, 18 Mar 2022 21:13:24 +0100 Message-Id: <20220318201324.1647416-4-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220318201324.1647416-1-michael@walle.cc> References: <20220318201324.1647416-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 LAN966x has two internal PHYs which are in reset by default. The driver already supported the internal PHYs of the SparX-5. Now add support for the LAN966x, too. Add a new compatible to distinguish them. The LAN966x has additional control bits in this register, thus convert the regmap_write() to regmap_update_bits() to leave the remaining bits untouched. This doesn't change anything for the SparX-5 SoC, because there, the register consists only of reset bits. Signed-off-by: Michael Walle --- drivers/net/mdio/mdio-mscc-miim.c | 67 ++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/drivers/net/mdio/mdio-mscc-miim.c b/drivers/net/mdio/mdio-mscc-miim.c index 2f77bf75288d..c483ba67c21f 100644 --- a/drivers/net/mdio/mdio-mscc-miim.c +++ b/drivers/net/mdio/mdio-mscc-miim.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #define MSCC_MIIM_REG_STATUS 0x0 @@ -36,11 +37,19 @@ #define PHY_CFG_PHY_RESET (BIT(5) | BIT(6) | BIT(7) | BIT(8)) #define MSCC_PHY_REG_PHY_STATUS 0x4 +#define LAN966X_CUPHY_COMMON_CFG 0x0 +#define CUPHY_COMMON_CFG_RESET_N BIT(0) + +struct mscc_miim_info { + unsigned int phy_reset_offset; + unsigned int phy_reset_bits; +}; + struct mscc_miim_dev { struct regmap *regs; int mii_status_offset; struct regmap *phy_regs; - int phy_reset_offset; + const struct mscc_miim_info *info; }; /* When high resolution timers aren't built-in: we can't use usleep_range() as @@ -157,27 +166,29 @@ static int mscc_miim_write(struct mii_bus *bus, int mii_id, static int mscc_miim_reset(struct mii_bus *bus) { struct mscc_miim_dev *miim = bus->priv; - int offset = miim->phy_reset_offset; - int reset_bits = PHY_CFG_PHY_ENA | PHY_CFG_PHY_COMMON_RESET | - PHY_CFG_PHY_RESET; + unsigned int offset, bits; int ret; - if (miim->phy_regs) { - ret = regmap_write(miim->phy_regs, offset, 0); - if (ret < 0) { - WARN_ONCE(1, "mscc reset set error %d\n", ret); - return ret; - } + if (!miim->phy_regs) + return 0; - ret = regmap_write(miim->phy_regs, offset, reset_bits); - if (ret < 0) { - WARN_ONCE(1, "mscc reset clear error %d\n", ret); - return ret; - } + offset = miim->info->phy_reset_offset; + bits = miim->info->phy_reset_bits; + + ret = regmap_update_bits(miim->phy_regs, offset, bits, 0); + if (ret < 0) { + WARN_ONCE(1, "mscc reset set error %d\n", ret); + return ret; + } - mdelay(500); + ret = regmap_update_bits(miim->phy_regs, offset, bits, bits); + if (ret < 0) { + WARN_ONCE(1, "mscc reset clear error %d\n", ret); + return ret; } + mdelay(500); + return 0; } @@ -272,7 +283,10 @@ static int mscc_miim_probe(struct platform_device *pdev) miim = bus->priv; miim->phy_regs = phy_regmap; - miim->phy_reset_offset = MSCC_PHY_REG_PHY_CFG; + + miim->info = device_get_match_data(&pdev->dev); + if (!miim->info) + return -EINVAL; ret = of_mdiobus_register(bus, pdev->dev.of_node); if (ret < 0) { @@ -294,8 +308,25 @@ static int mscc_miim_remove(struct platform_device *pdev) return 0; } +static const struct mscc_miim_info mscc_ocelot_miim_info = { + .phy_reset_offset = MSCC_PHY_REG_PHY_CFG, + .phy_reset_bits = PHY_CFG_PHY_ENA | PHY_CFG_PHY_COMMON_RESET | + PHY_CFG_PHY_RESET, +}; + +static const struct mscc_miim_info microchip_lan966x_miim_info = { + .phy_reset_offset = LAN966X_CUPHY_COMMON_CFG, + .phy_reset_bits = CUPHY_COMMON_CFG_RESET_N, +}; + static const struct of_device_id mscc_miim_match[] = { - { .compatible = "mscc,ocelot-miim" }, + { + .compatible = "mscc,ocelot-miim", + .data = &mscc_ocelot_miim_info + }, { + .compatible = "microchip,lan966x-miim", + .data = µchip_lan966x_miim_info + }, { } }; MODULE_DEVICE_TABLE(of, mscc_miim_match); -- 2.30.2