From patchwork Mon Jul 1 10:54:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?U2t5TGFrZSBIdWFuZyAo6buD5ZWf5r6kKQ==?= X-Patchwork-Id: 13717882 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A8A9DC30653 for ; Mon, 1 Jul 2024 10:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7FPKHFB7DmI7XxahmQ/sdSeFOvPkP2KuVr/PD2r+EoM=; b=L2pG1uu7i3Im/lstBAz5oGX0Ah hzhcoWcsC6ArswZQncMj2phMN3UTA9ydLwOwogWA86U8H9z7qKUGb5syNjxgQkQ9PR/WX4nNNhkKe 1aKcOvE144GYgbR4eD6D5walAaKroMOPlqzws69IkZBQNWmcl3urCKqW13HiD6/EG/9vuhwNCA9Q2 JRpxHc094LKo8tetB6ZVGjvCCKiRZLVs3AG3VQL6k2ig4R+MMYvkBX4krXrrdFyO7u2AvDmJ7Moav djzWMiWkugc7ICv9QIoXvrMQcTAb+KOqTDh0/sWdScIxB20oAnzBFI8NwOXRmkOjXaFDlMC4kTwyf oTYCU/kQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOEju-00000002nn7-1wvE; Mon, 01 Jul 2024 10:58:30 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOEjj-00000002nki-1ZA0; Mon, 01 Jul 2024 10:58:20 +0000 X-UUID: d106650c379811ef9daba96ee3f3cc8c-20240701 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=7FPKHFB7DmI7XxahmQ/sdSeFOvPkP2KuVr/PD2r+EoM=; b=kUbHDk12nkaq30MSsmjJkyKBTYLrgZg8z18XPE5Xc2MEspAzniTnYQEsKgq8MqWIgD8iNrHtF+VIHMLqM1CMxfbvpGx3yCGrBDvwV3vjU0wfUVxXvqTIFEHzWaPCW4FvdnKT6NXdwFYf0dw3LD2Avm1SRCzqXmo3TrDKzSClMR4=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.40,REQID:857a3e96-27a6-4f00-ab8e-da9cf3043b74,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:ba885a6,CLOUDID:0b8cd0d4-0d68-4615-a20f-01d7bd41f0bb,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES :1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-UUID: d106650c379811ef9daba96ee3f3cc8c-20240701 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 745809783; Mon, 01 Jul 2024 03:58:15 -0700 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS09N2.mediatek.inc (172.21.101.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 1 Jul 2024 03:57:19 -0700 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 1 Jul 2024 18:57:19 +0800 From: Sky Huang To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Daniel Golle , Qingfang Deng , SkyLake Huang , Matthias Brugger , AngeloGioacchino Del Regno , , , , CC: Steven Liu , SkyLake.Huang Subject: [PATCH net-next v10 06/13] net: phy: mediatek: Hook LED helper functions in mtk-ge.c Date: Mon, 1 Jul 2024 18:54:10 +0800 Message-ID: <20240701105417.19941-7-SkyLake.Huang@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20240701105417.19941-1-SkyLake.Huang@mediatek.com> References: <20240701105417.19941-1-SkyLake.Huang@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240701_035819_425655_1035F9B0 X-CRM114-Status: GOOD ( 16.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "SkyLake.Huang" We have mtk-phy-lib.c now so that we can use LED helper functions in mtk-ge.c(mt7531 part). It also means that mt7531/mt7981/mt7988's Giga ethernet phys share almost the same HW LED controller design. Also, add probe function for mt7531 so that it can initialize LED state. Signed-off-by: SkyLake.Huang --- Changes in v9: - Led number checking & delay settings are integrated into common code, so just use it. --- drivers/net/phy/mediatek/mtk-ge.c | 100 ++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/drivers/net/phy/mediatek/mtk-ge.c b/drivers/net/phy/mediatek/mtk-ge.c index 9122899..161f2e8 100644 --- a/drivers/net/phy/mediatek/mtk-ge.c +++ b/drivers/net/phy/mediatek/mtk-ge.c @@ -13,6 +13,10 @@ #define MTK_PHY_PAGE_EXTENDED_2A30 0x2a30 #define MTK_PHY_PAGE_EXTENDED_52B5 0x52b5 +struct mtk_gephy_priv { + unsigned long led_state; +}; + static void mtk_gephy_config_init(struct phy_device *phydev) { /* Enable HW auto downshift */ @@ -57,6 +61,96 @@ static int mt7531_phy_config_init(struct phy_device *phydev) return 0; } +static int mt7531_phy_probe(struct phy_device *phydev) +{ + struct mtk_gephy_priv *priv; + + priv = devm_kzalloc(&phydev->mdio.dev, sizeof(struct mtk_gephy_priv), + GFP_KERNEL); + if (!priv) + return -ENOMEM; + + phydev->priv = priv; + + mtk_phy_leds_state_init(phydev); + + return 0; +} + +static int mt753x_phy_led_blink_set(struct phy_device *phydev, u8 index, + unsigned long *delay_on, + unsigned long *delay_off) +{ + struct mtk_gephy_priv *priv = phydev->priv; + bool blinking = false; + int err = 0; + + err = mtk_phy_led_num_dly_cfg(index, delay_on, delay_off, &blinking); + if (err < 0) + return err; + + err = mtk_phy_hw_led_blink_set(phydev, index, &priv->led_state, + blinking); + if (err) + return err; + + return mtk_phy_hw_led_on_set(phydev, index, &priv->led_state, + MTK_GPHY_LED_ON_MASK, false); +} + +static int mt753x_phy_led_brightness_set(struct phy_device *phydev, + u8 index, enum led_brightness value) +{ + struct mtk_gephy_priv *priv = phydev->priv; + int err; + + err = mtk_phy_hw_led_blink_set(phydev, index, &priv->led_state, false); + if (err) + return err; + + return mtk_phy_hw_led_on_set(phydev, index, &priv->led_state, + MTK_GPHY_LED_ON_MASK, (value != LED_OFF)); +} + +static const unsigned long supported_triggers = + (BIT(TRIGGER_NETDEV_FULL_DUPLEX) | + BIT(TRIGGER_NETDEV_HALF_DUPLEX) | + BIT(TRIGGER_NETDEV_LINK) | + BIT(TRIGGER_NETDEV_LINK_10) | + BIT(TRIGGER_NETDEV_LINK_100) | + BIT(TRIGGER_NETDEV_LINK_1000) | + BIT(TRIGGER_NETDEV_RX) | + BIT(TRIGGER_NETDEV_TX)); + +static int mt753x_phy_led_hw_is_supported(struct phy_device *phydev, u8 index, + unsigned long rules) +{ + return mtk_phy_led_hw_is_supported(phydev, index, rules, + supported_triggers); +} + +static int mt753x_phy_led_hw_control_get(struct phy_device *phydev, u8 index, + unsigned long *rules) +{ + struct mtk_gephy_priv *priv = phydev->priv; + + return mtk_phy_led_hw_ctrl_get(phydev, index, rules, &priv->led_state, + MTK_GPHY_LED_ON_SET, + MTK_GPHY_LED_RX_BLINK_SET, + MTK_GPHY_LED_TX_BLINK_SET); +}; + +static int mt753x_phy_led_hw_control_set(struct phy_device *phydev, u8 index, + unsigned long rules) +{ + struct mtk_gephy_priv *priv = phydev->priv; + + return mtk_phy_led_hw_ctrl_set(phydev, index, rules, &priv->led_state, + MTK_GPHY_LED_ON_SET, + MTK_GPHY_LED_RX_BLINK_SET, + MTK_GPHY_LED_TX_BLINK_SET); +}; + static struct phy_driver mtk_gephy_driver[] = { { PHY_ID_MATCH_EXACT(0x03a29412), @@ -75,6 +169,7 @@ static struct phy_driver mtk_gephy_driver[] = { { PHY_ID_MATCH_EXACT(0x03a29441), .name = "MediaTek MT7531 PHY", + .probe = mt7531_phy_probe, .config_init = mt7531_phy_config_init, /* Interrupts are handled by the switch, not the PHY * itself. @@ -85,6 +180,11 @@ static struct phy_driver mtk_gephy_driver[] = { .resume = genphy_resume, .read_page = mtk_phy_read_page, .write_page = mtk_phy_write_page, + .led_blink_set = mt753x_phy_led_blink_set, + .led_brightness_set = mt753x_phy_led_brightness_set, + .led_hw_is_supported = mt753x_phy_led_hw_is_supported, + .led_hw_control_set = mt753x_phy_led_hw_control_set, + .led_hw_control_get = mt753x_phy_led_hw_control_get, }, };