Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3257162rwl; Thu, 13 Apr 2023 19:01:34 -0700 (PDT) X-Google-Smtp-Source: AKy350b1YVPlC/guJ7azmIZNxKv7YUmtE42kzD8PNg+LZj100yCtTc+ZgxHFAz2oJWilc3KwqbcG X-Received: by 2002:a05:6a20:4e10:b0:cc:eb3b:56e9 with SMTP id gk16-20020a056a204e1000b000cceb3b56e9mr3971659pzb.1.1681437693917; Thu, 13 Apr 2023 19:01:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681437693; cv=none; d=google.com; s=arc-20160816; b=zNhV/b6Yf1FOyJzh2z28u42bhUBraSRdJ1LPhEZTP4l6LEva38b4WF1+FYmtFN1stQ 8zHNDkPPa2ZfLH5wDm+A+7Q25tiPEv3Qz/izo5ULLJnuI8CgmOeaENSSPbuDbkDdJxW3 Kp/ZsBfoxXhJouynHLVRO5en8SqlDCkLrZDaZZUuQgLnsWQ1Mohi+KzVLvGtfk4+Jqvh hLj7uDnOX7giNdMiv7hNlROCypP9MdjiWx25Q0cREtLAFfqWDJ9I+lvuimC6d3wi4Cxm yzlULG7RV263m+AN0UDDL1kprb/wr6DFN1PzMJDdstLss63ZF+sgpGqWagLe/O3CxAnK BTbQ== 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=E2G2QvD8LSN6zsKrK4x10klW74FtFwbyAIvDGNKBlgI=; b=e+OiCW4FK+s02e3DmDzIlvTBpo3SGHZLerlyVszDdMp65vN+oLR7+hOZW1e20VTT0o P/VX6WgRc7vVdV62e5n7ThqiQuOGHq128js5lA6Ea+OwN1UCzWER+EntTUn2AJO6tem6 OKFyvMfqClBmdPhK64UllsdedacQmnF49ItD8DeYkUSk7LeC51gZJoEmWxGIDRYaysF+ 8t7zXXsuJL62D+PcNOZxl4Eu3hZsoYOD5gzoxaljNyzbmO89CJNhHdyEq36dXjAqwkc8 +Pu6upLak2dWZnMpbJzvtMYdsp9g5PVVHjcdw0OPoPJnMwEQLSgpby9c3CLad9aLZfPA NgGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=mKoGtUTF; 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 b25-20020aa79519000000b00638d9fb0540si3058577pfp.206.2023.04.13.19.01.19; Thu, 13 Apr 2023 19:01:33 -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=mKoGtUTF; 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 S229762AbjDNBtZ (ORCPT + 99 others); Thu, 13 Apr 2023 21:49:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229516AbjDNBtX (ORCPT ); Thu, 13 Apr 2023 21:49:23 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9882A2D5F; Thu, 13 Apr 2023 18:49:21 -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=E2G2QvD8LSN6zsKrK4x10klW74FtFwbyAIvDGNKBlgI=; b=mKoGtUTFW1RJGS3hAqeCxHJJ5A zG4T1dYaG40Nfu1CCGZib5u3IkjqmcT+jBShPe9xtQQfghWSW/OHaOAHOWJsQTOy9l4J9eBKHOsCw HPW9qZFTv1e7UxRIblVwHXOAAhULUz3eydk7O7toklv4Zq3xiEsVo6Oc0k9Gd8bUdDpo=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pn8Ym-00AF4Q-5H; Fri, 14 Apr 2023 03:49:08 +0200 Date: Fri, 14 Apr 2023 03:49:08 +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, Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Qingfang Deng , SkyLake Huang , Matthias Brugger , AngeloGioacchino Del Regno , John Crispin Subject: Re: [PATCH net-next] net: phy: add driver for MediaTek SoC built-in GE PHYs Message-ID: <1295d8aa-35e8-4396-b347-efc8d7557c79@lunn.ch> References: 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 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 > +/* Registers on MDIO_MMD_VEND1 */ > +#define MTK_PHY_MIDDLE_LEVEL_SHAPPER_0TO1 0 > +#define MTK_PHY_1st_OVERSHOOT_LEVEL_0TO1 1 > +#define MTK_PHY_2nd_OVERSHOOT_LEVEL_0TO1 2 > +#define MTK_PHY_1st_OVERSHOOT_LEVEL_1TO0 4 > +#define MTK_PHY_2nd_OVERSHOOT_LEVEL_1TO0 5 /* N means negative */ > +#define MTK_PHY_1st_OVERSHOOT_LEVEL_0TON1 7 > +#define MTK_PHY_2nd_OVERSHOOT_LEVEL_0TON1 8 > +#define MTK_PHY_1st_OVERSHOOT_LEVEL_N1TO0 10 > +#define MTK_PHY_2nd_OVERSHOOT_LEVEL_N1TO0 11 Mixed case like this is very unusual. > +static int tx_amp_fill_result(struct phy_device *phydev, u16 *buf) > +{ > + int i; > + int bias[16] = {0}; > + const int vals_9461[16] = { 7, 1, 4, 7, > + 7, 1, 4, 7, > + 7, 1, 4, 7, > + 7, 1, 4, 7 }; > + const int vals_9481[16] = { 10, 6, 6, 10, > + 10, 6, 6, 10, > + 10, 6, 6, 10, > + 10, 6, 6, 10 }; > + > + switch (phydev->drv->phy_id) { > + case MTK_GPHY_ID_MT7981: > + /* We add some calibration to efuse values > + * due to board level influence. > + * GBE: +7, TBT: +1, HBT: +4, TST: +7 > + */ > + memcpy(bias, (const void *)vals_9461, sizeof(bias)); > + for (i = 0; i <= 12; i += 4) { > + if (likely(buf[i >> 2] + bias[i] >= 32)) { > + bias[i] -= 13; > + } else { > + phy_modify_mmd(phydev, MDIO_MMD_VEND1, > + 0x5c, 0x7 << i, bias[i] << i); > + bias[i + 1] += 13; > + bias[i + 2] += 13; > + bias[i + 3] += 13; How does 13 map to GBE: +7, TBT: +1, HBT: +4, TST: +7 ? > +static inline void mt798x_phy_common_finetune(struct phy_device *phydev) No inline functions in .c files. Let the compiler decide. There appears to be a number of these. And they are big function, too big to make sense to inline. > static struct phy_driver mtk_gephy_driver[] = { > { > - PHY_ID_MATCH_EXACT(0x03a29412), > + PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7530), > .name = "MediaTek MT7530 PHY", > .config_init = mt7530_phy_config_init, > /* Interrupts are handled by the switch, not the PHY > @@ -84,7 +1205,7 @@ static struct phy_driver mtk_gephy_driver[] = { > .write_page = mtk_gephy_write_page, > }, > { > - PHY_ID_MATCH_EXACT(0x03a29441), > + PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7531), > .name = "MediaTek MT7531 PHY", > .config_init = mt7531_phy_config_init, > /* Interrupts are handled by the switch, not the PHY Useful changes, but please put them in a separate patch. > @@ -97,16 +1218,42 @@ static struct phy_driver mtk_gephy_driver[] = { > .read_page = mtk_gephy_read_page, > .write_page = mtk_gephy_write_page, > }, > +#if IS_ENABLED(CONFIG_MEDIATEK_GE_PHY_SOC) > + { > + PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7981), > + .name = "MediaTek MT7981 PHY", > + .probe = mt7981_phy_probe, > + .config_intr = genphy_no_config_intr, > + .handle_interrupt = genphy_handle_interrupt_no_ack, > + .suspend = genphy_suspend, > + .resume = genphy_resume, > + .read_page = mtk_gephy_read_page, > + .write_page = mtk_gephy_write_page, > + }, > + { > + PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7988), > + .name = "MediaTek MT7988 PHY", > + .probe = mt7988_phy_probe, > + .config_intr = genphy_no_config_intr, > + .handle_interrupt = genphy_handle_interrupt_no_ack, > + .suspend = genphy_suspend, > + .resume = genphy_resume, > + .read_page = mtk_gephy_read_page, > + .write_page = mtk_gephy_write_page, So the only thing these two new PHYs share with the other two PHYs is mtk_gephy_read_page and mtk_gephy_write_page? static int mtk_gephy_read_page(struct phy_device *phydev) { return __phy_read(phydev, MTK_EXT_PAGE_ACCESS); } static int mtk_gephy_write_page(struct phy_device *phydev, int page) { return __phy_write(phydev, MTK_EXT_PAGE_ACCESS, page); } Given the size of the new code, maybe consider adding mediatek-ge-soc.c and make a copy these two functions? Andrew