From: Christian Marangi <ansuelsmth@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Daniel Golle <daniel@makrotopia.org>,
Qingfang Deng <dqfext@gmail.com>,
SkyLake Huang <SkyLake.Huang@mediatek.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Joris Vaisvila <joey@tinyisr.com>,
Ahmed Naseef <naseefkm@gmail.com>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Subject: Re: [PATCH net-next v4 5/6] net: phy: mediatek: add calibration logic for AN7581
Date: Fri, 6 Nov 2026 13:09:22 +0100 [thread overview]
Message-ID: <6aedc376.79189afa.3a0b25.2405@mx.google.com> (raw)
In-Reply-To: <028a75a3-b69c-4ae8-8f15-3ef855346a0f@lunn.ch>
On Thu, Nov 05, 2026 at 11:47:26PM +0100, Andrew Lunn wrote:
> > +static int airoha_cal_cycle(struct phy_device *phydev, int devad,
> > + u32 regnum, u16 mask, u16 cal_val)
> > +{
> > + struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
> > + struct phy_device *phydev_p0;
> > + int ret;
> > +
> > + phydev_p0 = shared->phydev_p0;
> > +
> > + phy_modify_mmd(phydev, devad, regnum, mask, cal_val);
> > +
> > + ret = mtk_cal_cycle_wait(phydev_p0);
>
>
> > +static int airoha_rext_cal_sw(struct phy_device *phydev)
> > +{
>
> ...
>
> > + phydev_dbg(phydev, "Start REXT SW cal.\n");
> > + first_calib = airoha_cal_cycle(phydev, MDIO_MMD_VEND1, MTK_PHY_RG_ANA_CAL_RG5,
> > + MTK_PHY_RG_REXT_ZCAL_CTRL_MASK, zcal_ctrl);
> > +
>
> > +static int airoha_cal_sw(struct phy_device *phydev, enum CAL_ITEM cal_item,
> > + u8 start_pair, u8 end_pair)
> > +{
> > + u8 pair_n;
> > + int ret;
> > +
> > + for (pair_n = start_pair; pair_n <= end_pair; pair_n++) {
> > + switch (cal_item) {
> > + case REXT:
> > + ret = airoha_rext_cal_sw(phydev);
> > + break;
>
> > +static int airoha_start_cal(struct phy_device *phydev, enum CAL_ITEM cal_item,
> > + enum CAL_MODE cal_mode, u8 start_pair,
> > + u8 end_pair, u32 *buf)
> > +{
> > + int ret;
> > +
> > + switch (cal_mode) {
> > + case SW_M:
> > + ret = airoha_cal_sw(phydev, cal_item, start_pair, end_pair);
>
>
> > +static int airoha_phy_calib(struct phy_device *phydev)
> > +{
> > + phy_package_lock(phydev);
> > + if (!shared->rext_sw_calib_done) {
> > + ret = airoha_start_cal(phydev, REXT, SW_M, NO_PAIR, NO_PAIR, NULL);
> > + if (ret) {
> > + phy_package_unlock(phydev);
> > + return ret;
> > + }
> > +
> > + shared->rext_sw_calib_done = true;
> > + }
> > + phy_package_unlock(phydev);
> > +
> > + ret = airoha_start_cal(phydev, TX_R50, SW_M, PAIR_A, PAIR_D, NULL);
>
>
> > +static int an7581_phy_config_init(struct phy_device *phydev)
> > +{
> > + struct airoha_socphy_shared *shared = phy_package_get_priv(phydev);
> > + struct phy_device *phydev_p0;
> > + u8 phy_offset;
> > + int oldpage;
> > + int ret;
> > +
> > + phydev_p0 = shared->phydev_p0;
> > + phy_offset = phydev->mdio.addr - phydev_p0->mdio.addr;
> > +
> > + if (phy_package_init_once(phydev)) {
> > + ret = an7581_phy_package_config_init_once(phydev);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + ret = airoha_phy_calib(phydev);
>
> > @@ -88,6 +1610,7 @@ static struct phy_driver mtk_socphy_driver[] = {
> > {
> > PHY_ID_MATCH_EXACT(AIROHA_GPHY_ID_AN7581),
> > .name = "Airoha AN7581 PHY",
> > + .config_init = an7581_phy_config_init,
>
> > > There are 4 phys in total, only the phy with mdio address 9 has the
> > > calibration capability. Thus only one phy at the time can perform
> > > the calibration sequence.
>
> config_init -> airoha_phy_calib -> airoha_start_cal -> airoha_cal_sw
> -> airoha_cal_cycle
>
> I cannot say i looked at all the details closely, maybe i missed an ==
> 9 somewhere, but to me, it looks like two config_init can run in
> parallel.
>
Hi Andrew, in v5 I converted the driver to full phy_package_lock/unlock and
I set the base address correctly to the hardcoded value of the SoC.
This permitted me to simplify the validation code instead of saving the
phydev for port0 in the phy_package struct (a much solid implementation in
short)
--
Ansuel
next prev parent reply other threads:[~2026-11-06 12:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 22:14 [PATCH net-next v4 0/6] net: phy: mediatek: calibration for AN7581/3 Christian Marangi
2026-11-03 22:14 ` [PATCH net-next v4 1/6] net: phy: mediatek: export __mtk_tr_write Christian Marangi
2026-11-04 2:32 ` Andrew Lunn
2026-11-03 22:14 ` [PATCH net-next v4 2/6] net: phy: mediatek: move MTK GE SoC registers define to dedicated header Christian Marangi
2026-11-04 2:33 ` Andrew Lunn
2026-11-03 22:14 ` [PATCH net-next v4 3/6] net: phy: mediatek: generalize cal_cycle function for GE SoC Christian Marangi
2026-11-04 2:34 ` Andrew Lunn
2026-11-03 22:14 ` [PATCH net-next v4 4/6] net: phy: mediatek: split Airoha code to dedicated source Christian Marangi
2026-11-04 2:38 ` Andrew Lunn
2026-11-03 22:14 ` [PATCH net-next v4 5/6] net: phy: mediatek: add calibration logic for AN7581 Christian Marangi
2026-11-04 3:47 ` Andrew Lunn
2026-11-04 18:24 ` Christian Marangi
2026-11-04 20:51 ` Andrew Lunn
2026-11-04 22:38 ` Benjamin Larsson
2026-11-05 22:47 ` Andrew Lunn
2026-11-06 12:09 ` Christian Marangi [this message]
2026-11-03 22:14 ` [PATCH net-next v4 6/6] net: phy: mediatek: add calibration logic for AN7583 Christian Marangi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6aedc376.79189afa.3a0b25.2405@mx.google.com \
--to=ansuelsmth@gmail.com \
--cc=SkyLake.Huang@mediatek.com \
--cc=andrew@lunn.ch \
--cc=angelogioacchino.delregno@collabora.com \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=dqfext@gmail.com \
--cc=edumazet@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=joey@tinyisr.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=matthias.bgg@gmail.com \
--cc=naseefkm@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®