Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1309452rwd; Tue, 13 Jun 2023 07:33:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5DoVLlcd65ISMRm/sICTgxzDr8o+I8xwE/dmlxrBUqKORet4KL4+OO8bEuxgjsZfJxBzaV X-Received: by 2002:a17:906:da8a:b0:973:d076:67ab with SMTP id xh10-20020a170906da8a00b00973d07667abmr11567395ejb.42.1686666811784; Tue, 13 Jun 2023 07:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686666811; cv=none; d=google.com; s=arc-20160816; b=a7HGnbynKkXAsJtPDD1Q01FcSr6LmKImhBAKb4V/QP4XnAyNPmoRWmhSH4rZjdvAiL X/Oytclx3j/X7twFinz1rLYymMPsDfOfYodRlntX93NdQoVhYN6vHfcFwhYt+8u6YCUX YI+LWyhILMmaGmXvIkLqZds8/KsEKXU/LVGBtAUHFmCLXvpyUmgZf2Ujn0qCp0QQndNL 5GDBl6zF+N9387KYM439bnR2z1IaLWA9RfEnkgsHfzDxQHbPRhrCQtCo5hhPXbMWJTCp b3/CDLxBPhAETzI1IfzYC80tKhteENJOTmpXuS9gwoaUArvmzo0d2nme2kwTDsMfFjU6 8rVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5dUDV/ulY1VwPUL5mH+Lz5QqPr6DjLH8cBAyedpbDYo=; b=l4xVsPT1GIVjq9buKTxipdPQBzfVI7jcAMDliT2uIrevJm0frhHmKjm4cKg36aB6Wm niVkTN8c3tMv3sT1Dbg5mIgmHj4Um7Lhc5u9ipuKZyV/874Uh1M5qM6RAQg0defPOt8B 5CP2dSUKEMDhcvx7S+xxwlsXkoF4qHTxjGRIwTVN9vRr80rDKXBOTx7EFWhuziVD7bYB uhJxByrto14S2/fy9n6inQlCua5ZkbkAo7nc7GZan2MS7ChArO+dRs6G4gibGyOdAe4N eiMTv4PAJbdrnNBY6Wl9kgPzWfjRZ4JCdXpHFnk3/1VQXiFsv8//y/yHUiOv+RWYkfC2 1OnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=iYD6PUga; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id me26-20020a170906aeda00b00978028dabedsi6439794ejb.1001.2023.06.13.07.33.02; Tue, 13 Jun 2023 07:33:31 -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=@lunn.ch header.s=20171124 header.b=iYD6PUga; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240124AbjFMOPH (ORCPT + 99 others); Tue, 13 Jun 2023 10:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240380AbjFMOPF (ORCPT ); Tue, 13 Jun 2023 10:15:05 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01F86EC; Tue, 13 Jun 2023 07:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=5dUDV/ulY1VwPUL5mH+Lz5QqPr6DjLH8cBAyedpbDYo=; b=iYD6PUgaB/68RBS8u9Ym/rotRl FXw1OvFMWOiYd+gt0bp4wsTYby3J9Z85iZkj97SrcFBXrifSj1oiaAnZxTwfzEtELzMoetFthNaX8 ++pqz+HsX9OMSh6EAY7Q/mglNu3XoptYmD/63DJJunhrjHc9Br9OPsfspuSK+HPP5/2o=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1q94nG-00FjYJ-Fe; Tue, 13 Jun 2023 16:14:46 +0200 Date: Tue, 13 Jun 2023 16:14:46 +0200 From: Andrew Lunn To: Daniel Golle Cc: netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AngeloGioacchino Del Regno , Matthias Brugger , Paolo Abeni , Jakub Kicinski , Eric Dumazet , "David S. Miller" , Russell King , Heiner Kallweit , SkyLake Huang , Qingfang Deng Subject: Re: [PATCH net-next] net: phy: mediatek-ge-soc: initialize MT7988 PHY LEDs default state Message-ID: <7fc15ef7-ab5d-4af7-8d9b-bf0928f476a0@lunn.ch> References: <922466fd-bb14-4b6e-ad40-55b4249c571f@lunn.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Tue, Jun 13, 2023 at 02:13:28PM +0100, Daniel Golle wrote: > Hi Andrew, > > On Tue, Jun 13, 2023 at 05:23:25AM +0200, Andrew Lunn wrote: > > > +/* Registers on MDIO_MMD_VEND2 */ > > > +#define MTK_PHY_LED0_ON_CTRL 0x24 > > > +#define MTK_PHY_LED1_ON_CTRL 0x26 > > > +#define MTK_PHY_LED_ON_MASK GENMASK(6, 0) > > > +#define MTK_PHY_LED_ON_LINK1000 BIT(0) > > > +#define MTK_PHY_LED_ON_LINK100 BIT(1) > > > +#define MTK_PHY_LED_ON_LINK10 BIT(2) > > > +#define MTK_PHY_LED_ON_LINKDOWN BIT(3) > > > +#define MTK_PHY_LED_ON_FDX BIT(4) /* Full duplex */ > > > +#define MTK_PHY_LED_ON_HDX BIT(5) /* Half duplex */ > > > +#define MTK_PHY_LED_FORCE_ON BIT(6) > > > +#define MTK_PHY_LED_POLARITY BIT(14) > > > +#define MTK_PHY_LED_ENABLE BIT(15) > The PHY has two LED outputs, LED0 and LED1. Both have an ON_CTRL and > a BLINK_CTRL register each with identical layouts for LED0_ON_CTRL and > LED1_ON_CTRL as well as LED0_BLINK_CTRL as well as LED1_BLINK_CTRL. O.K. So i think the naming could be better #define MTK_PHY_LED0_ON_CTRL 0x24 #define MTK_PHY_LED1_ON_CTRL 0x26 #define MTK_PHY_LEDX_ON_CTRL_MASK GENMASK(6, 0) #define MTK_PHY_LEDX_ON_CTRL_LINK1000 BIT(0) #define MTK_PHY_LEDX_ON_CTRL_LINK100 BIT(1) #define MTK_PHY_LED0_BLINK_CTRL 0x25 #define MTK_PHY_LED1_BLINK_CTRL 0x27 #define MTK_PHY_LEDX_BLINK_CTRL_1000TX BIT(0) #define MTK_PHY_LEDX_BLINK_CTRL_1000RX BIT(1) I've taken over code where i found a few examples of a register write which used the wrong macro for bits because there was no clear indication which register is belonged to. phy_write(phydev, MTK_PHY_LED1_ON_CTRL, MTK_PHY_LEDX_BLINK_CTRL_1000TX | MTK_PHY_LEDX_BLINK_CTRL_1000RX) is pretty obvious it is wrong. > The LED controller of both LEDs are identical. The SoC's pinmux assigns > LED0 as LED_A, LED_B, LED_C and LED_D respectively. And those pins are > used for bootstrapping board configuration bits, and that then implies > the polarity of the connected LED. > > Ie. > -----------------------------+ SoC pin > --------------+-------+ | > port 0 = PHY 0 - LED0 - LED_A > +-------\ LED1 - JTAG_JTDI > port 1 = PHY 1 - LED0 - LED_B > MT7530 +-------\ LED1 - JTAG_JTDO > port 2 = PHY 2 - LED0 - LED_C > +-------\ LED1 - JTAG_JTMS > port 3 = PHY 3 - LED0 - LED_D > --------------+-------\ LED1 - JTAG_JTCLK > 2P5G PHY - LED0 - LED_E > ----------------------\ LED1 - JTAG_JTRST_N > --------------+--------------+ So you can skip the JTAG interface and have two LEDs. This is purely down to pinmux settings. In fact, with careful design, it might be possible to have both LEDs and JTAG. > > > #define MTK_PHY_RG_BG_RASEL 0x115 > > > #define MTK_PHY_RG_BG_RASEL_MASK GENMASK(2, 0) > > > > > > +/* Register in boottrap syscon defining the initial state of the 4 PHY LEDs */ > > > > Should this be bootstrap? You had the same in the commit message. > > > > Also, i'm confused. Here you say 4 PHY LEDs, yet > > > > > +#define MTK_PHY_LED0_ON_CTRL 0x24 > > > +#define MTK_PHY_LED1_ON_CTRL 0x26 > > > > suggests there are two LEDs? > > There are 4 PHYs with two LEDs each. Only LED0 of each PHY is using > a pin which is used for bootstrapping, hence LED polarity is known > only for those, polarity of LED1 is unknown and always set the default > at this point. So hopefully you can see my sources of confusion and can add some comments to make this clearer. > > > +static int mt798x_phy_setup_led(struct phy_device *phydev, bool inverted) > > > +{ > > > + struct pinctrl *pinctrl; > > > + const u16 led_on_ctrl_defaults = MTK_PHY_LED_ENABLE | > > > + MTK_PHY_LED_ON_LINK1000 | > > > + MTK_PHY_LED_ON_LINK100 | > > > + MTK_PHY_LED_ON_LINK10; > > > + const u16 led_blink_defaults = MTK_PHY_LED_1000TX | > > > + MTK_PHY_LED_1000RX | > > > + MTK_PHY_LED_100TX | > > > + MTK_PHY_LED_100RX | > > > + MTK_PHY_LED_10TX | > > > + MTK_PHY_LED_10RX; > > > + > > > + phy_write_mmd(phydev, MDIO_MMD_VEND2, MTK_PHY_LED0_ON_CTRL, > > > + led_on_ctrl_defaults ^ > > > + (inverted ? MTK_PHY_LED_POLARITY : 0)); > > > + > > > + phy_write_mmd(phydev, MDIO_MMD_VEND2, MTK_PHY_LED1_ON_CTRL, > > > + led_on_ctrl_defaults); > > > + > > > > Now i'm even more confused. Both have the same value, expect the > > polarity bit? > > Only LED0 polarity of each PHY is affected by the bootstrap pins > LED_A, LED_B, LED_C and LED_D of the SoC, see above. > Hence we need to XOR polarity only for LED0. However, if there are two LEDs, you are likely to want to configure them to show different things, not identical. You are setting the defaults here which all boards will get. So i would set LED1 to something different, something which makes sense when there are two LEDs. > > > + pinctrl = devm_pinctrl_get_select(&phydev->mdio.dev, "gbe-led"); > > > > This is also very unusual. At minimum, it needs a comment as to why it > > is needed. But more likely, because no other driver in driver/net does > > this, it makes me think it is wrong. > > The reason for not using the "default" pinctrl name is simply that then > the "default" state will already be requested by device model *before* > the LED registers are actually setup. This results in a short but unwanted > blink of the LEDs during setup. > Requesting the pinctrl state only once the setup is done allows avoiding > that, but of course this is of purely aesthetic nature. So i assume the pin can have other functions? Just for an example, say it can also be an I2C clock line, which might be connected to an SFP. The I2C node in DT will have a pinmux to configure the pin for I2C. What happens when the PHY driver loads and executes this? Andrew