Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2229926rdb; Mon, 20 Nov 2023 05:53:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlR0DEEIoVxTJl+T0s/wF2u7xpUqTWRYvdhk0nIcRLNjeWmRvZfydE810/YXgEK121E9p2 X-Received: by 2002:a05:6a00:80a:b0:6cb:910a:c6fe with SMTP id m10-20020a056a00080a00b006cb910ac6femr4613862pfk.7.1700488419415; Mon, 20 Nov 2023 05:53:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700488419; cv=none; d=google.com; s=arc-20160816; b=JzYOahcao0RygyTdLl4KBUTS/aorbBYJvI44Ui3D1W9dlnsWQPSKYsiGPMsxkBRcI9 0yN94vtLB8tWqosBY6LQAiw+LiME3txmzpcLAK1hJ7s5GzpaD6L390OjnNTet31NUOwz irp/7strUgA1+I9FGxnTQLgtQG3VcxSTKvvVa+fXJiLeOuIbb1f0u8gQGMwyZpLJtnvF +O2J6L00jDiuQ5RgciYHw1ftb0R39F5vhsAvy7baTrdi0OCDrANZkclX6OYlMPkfDz0N X4Pt1uk2pwA8lLBOp3pD6IQE7FKR0M/r+rHx9LFWWVKihzngKjDfpLqprWnJOdhueNfm DaAA== 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:to:from :dkim-signature; bh=7KlciZ6HGUzRiM58ultDgzciNJogKhU8Km072RfwAf4=; fh=zPyAtQBIWE/l9hby8g4KTASOZz1Q4ly6b7sYfyUlIrs=; b=TnjAJ+2jWcWUXICx6f1h+0tWbZTZlcNDDLlMwO34rX5eS6ipkHsp28j8wsw9s9HKQ4 u20Un1N3AwWg15D2g9keLsW1Lx9yCNuUm9qrC3S0gdxSLd1Evoc1iddpz7hVrHE6OyQX Pqyg5V5FNFU7OgsE28wwfuZ2DuLRIwbY2EMfp7+8breVEUy+CUnZgibNdF0VdRIkdt0Y xt4XJkkYOCeJ2ewxmh4fI8JGpP4zDPr6lQWNnwsOPwq7t5PG3vZ0r+CPGSMWfrfEWD16 yve6E5O9HKB1R+a9kxMBCYJsyUFAetABsdVZNsRQBE78VBM6zFe+mMtKxBHwB6xpXSB7 EcwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DzOWvVfr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id l23-20020a635b57000000b005aa0e024d63si8213618pgm.791.2023.11.20.05.53.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 05:53:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DzOWvVfr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 26249801E874; Mon, 20 Nov 2023 05:52:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233500AbjKTNwG (ORCPT + 99 others); Mon, 20 Nov 2023 08:52:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233498AbjKTNvk (ORCPT ); Mon, 20 Nov 2023 08:51:40 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C25C510D1; Mon, 20 Nov 2023 05:51:29 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4083740f92dso16080325e9.3; Mon, 20 Nov 2023 05:51:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700488288; x=1701093088; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=7KlciZ6HGUzRiM58ultDgzciNJogKhU8Km072RfwAf4=; b=DzOWvVfrm178CDzV/mmSwdpTxeWYfjw4xLSRh4/7NcSxsrsTEMdLtDxUwYB4H4K14c VHt7GejI75AwRzQLlkUD8oprRaoW2JN20GX3QP272DTZg4oNtnjo5K9kJbBCuL4V8Ivu m2XUwRMbvoSrYNbIEFeSIo0zTMstFtVlO7Ln85DAFlndy3lQlU9KL9VTrjOTuHC9Pj2O Y3AmooLD7HRhaJm3p7JU7b6eRQlkxJ3DM+0qmW7FI90aohrFLuJ6DZmHKgBdfXeGV12G sQcMxhAPay8f/sn7nNnesotJNvxV/vrjqOCuTyHZDU8l4YzGYJp/qLaXH31zizVPPlTL j4Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700488288; x=1701093088; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7KlciZ6HGUzRiM58ultDgzciNJogKhU8Km072RfwAf4=; b=g7XDxOj66xPyly01UZ9P773JGpiwwdYByCmt5EnswTarDR450T9hg579tapTVY3yWd Tm4wRs/WsJp+OrNZg5/jx6gknf0l/cYKcbjL8GdE9Bcbldq/DO/G5iKxgc/ZR9jVo+KC jkM0XPDW6zI67k+TptjM6rgJfCWZnLEMLJB8CquCz+AKhpwqpHDPs/2B2Xz6v2ml8U6T e3tR6iQxNaiFy+FXgMD6WgKRE/bcModXY0Wt38tH1rvklYQzdh3Q+6uSFc5+bxDu1A5D EfZQk44MomjjneYdpxiNpRnTY+CdqQPBDROApPcrAo5HVbSGbZjY3uyME0l2qq/a+uaF xU+w== X-Gm-Message-State: AOJu0YxjcsSSW6dhOKZPCo9e0vaxbCkzU2+ZVF5PyWKmwcerfxs/rnX/ 1Jxr6v5N/2YOCjEuRN0jfZw= X-Received: by 2002:a05:600c:3113:b0:408:e441:1697 with SMTP id g19-20020a05600c311300b00408e4411697mr5904786wmo.39.1700488288141; Mon, 20 Nov 2023 05:51:28 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id j33-20020a05600c1c2100b0040772934b12sm18205846wms.7.2023.11.20.05.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 05:51:27 -0800 (PST) From: Christian Marangi To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Gross , Bjorn Andersson , Konrad Dybcio , Andrew Lunn , Heiner Kallweit , Russell King , Florian Fainelli , Broadcom internal kernel review list , Daniel Golle , Qingfang Deng , SkyLake Huang , Matthias Brugger , AngeloGioacchino Del Regno , David Epping , Vladimir Oltean , Christian Marangi , "Russell King (Oracle)" , Harini Katakam , Simon Horman , Robert Marko , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [net-next RFC PATCH 10/14] net: phy: add support for PHY package MMD read/write Date: Mon, 20 Nov 2023 14:50:37 +0100 Message-Id: <20231120135041.15259-11-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231120135041.15259-1-ansuelsmth@gmail.com> References: <20231120135041.15259-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 05:52:38 -0800 (PST) Some PHY in PHY package may require to read/write MMD regs to correctly configure the PHY package. Add support for these additional required function in both lock and no lock variant. Signed-off-by: Christian Marangi --- include/linux/phy.h | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/include/linux/phy.h b/include/linux/phy.h index dd2381652dd1..90bfaa36689f 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2110,6 +2110,78 @@ static inline int __phy_package_write(struct phy_device *phydev, return __mdiobus_write(phydev->mdio.bus, addr, regnum, val); } +static inline int phy_package_read_mmd(struct phy_device *phydev, + int global_phy_index, int devad, u32 regnum) +{ + struct phy_package_shared *shared = phydev->shared; + struct mii_bus *bus = phydev->mdio.bus; + int addr, val; + + if (!shared || global_phy_index > shared->addrs_num - 1) + return -EIO; + + addr = shared->addrs[global_phy_index]; + + phy_lock_mdio_bus(phydev); + mmd_phy_indirect(bus, addr, devad, regnum); + val = __mdiobus_read(bus, addr, MII_MMD_DATA); + phy_unlock_mdio_bus(phydev); + + return val; +} + +static inline int __phy_package_read_mmd(struct phy_device *phydev, + int global_phy_index, int devad, u32 regnum) +{ + struct phy_package_shared *shared = phydev->shared; + struct mii_bus *bus = phydev->mdio.bus; + int addr; + + if (!shared || global_phy_index > shared->addrs_num - 1) + return -EIO; + + addr = shared->addrs[global_phy_index]; + mmd_phy_indirect(bus, addr, devad, regnum); + return __mdiobus_read(bus, addr, MII_MMD_DATA); +} + +static inline int phy_package_write_mmd(struct phy_device *phydev, + int global_phy_index, int devad, + u32 regnum, u16 val) +{ + struct phy_package_shared *shared = phydev->shared; + struct mii_bus *bus = phydev->mdio.bus; + int addr, ret; + + if (!shared || global_phy_index > shared->addrs_num - 1) + return -EIO; + + addr = shared->addrs[global_phy_index]; + + phy_lock_mdio_bus(phydev); + mmd_phy_indirect(bus, addr, devad, regnum); + ret = __mdiobus_write(bus, addr, MII_MMD_DATA, val); + phy_unlock_mdio_bus(phydev); + + return ret; +} + +static inline int __phy_package_write_mmd(struct phy_device *phydev, + int global_phy_index, int devad, + u32 regnum, u16 val) +{ + struct phy_package_shared *shared = phydev->shared; + struct mii_bus *bus = phydev->mdio.bus; + int addr; + + if (!shared || global_phy_index > shared->addrs_num - 1) + return -EIO; + + addr = shared->addrs[global_phy_index]; + mmd_phy_indirect(bus, addr, devad, regnum); + return __mdiobus_write(bus, addr, MII_MMD_DATA, val); +} + static inline bool __phy_package_set_once(struct phy_device *phydev, unsigned int b) { -- 2.40.1