Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3710148rwl; Mon, 27 Mar 2023 19:02:50 -0700 (PDT) X-Google-Smtp-Source: AK7set+PHF1GDrhEfVrfffT1i6TJSA/alLA1zns02oPA1zHD3gO93yz9t2zKYZ+ysxFgosBPyfZl X-Received: by 2002:a05:6a20:80c8:b0:db:6026:4393 with SMTP id d8-20020a056a2080c800b000db60264393mr12076947pza.59.1679968969907; Mon, 27 Mar 2023 19:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679968969; cv=none; d=google.com; s=arc-20160816; b=dW8Rmh8kD17RPlSTcQohjvdLJj5vAIdu+TQez+K8eDL2GTnsPdVKi0oYLQT4wi3Hut Pw8RpZYQkO8GUQmfo8cQzJDvXp9BRobVWHrafLLffP7KJdrte1Iw8KO7z7cTg9xeeQwJ VApetFY55Sm7FNT03xjWnFOS6bDJs28Mgc+P1NvsdoXp1ebGijOdtL3D8k8nRMCZbt5R k5/KF237jHYbLSbMUwL1kzugmuXVyW5CU109JFLmQAD6pSgJlf6GPpWhUZe5k2sHEk69 TSv0vkAT0CMZO7TGnmXaPv9EEanuNfzHfSxvTWj4Q9DWqN1mCi+civCzwBYIgAt4lg1d EeQQ== 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=NKs+8fXhqTJfjVIS1poqWe1vyBspCLp4bXvIsT+t6sM=; b=enu87KYJx1Jz4+3AC73ePTUs7Bbj2sJ+q19SGp90bmTTxC7hwihJZaPnvuA7Y9Ua8O lGzN12in6Ocltf06CZS+/B3CF5z67aH3qZed1qpU/20g5YQs02i5JAwUgJdztYIQ6sav 2lFHTsrUBEIwNgkuqeGeAQ0tuTNXeHDHL3+WDQggsgU3Ivby89/1s5Jkt9MpPkbeOOcI C21EJ2Cptf0nr4E5d96kDpFluGdAJL16d4R/5z3+Ou7Uoddxnh2D+n2ssr7TUygtI0ra ertLzXeTLJJsk81C9wfaWySN04z4D7j/kLTLP17eOlkPBhVIxuRVsKroYxyYFUthvxGH Jpbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=fMsxPumt; 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 m4-20020a6545c4000000b005134ad5e99bsi5236748pgr.625.2023.03.27.19.02.37; Mon, 27 Mar 2023 19:02:49 -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=fMsxPumt; 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 S232241AbjC1B7R (ORCPT + 99 others); Mon, 27 Mar 2023 21:59:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229935AbjC1B7M (ORCPT ); Mon, 27 Mar 2023 21:59:12 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8816B2689; Mon, 27 Mar 2023 18:59:02 -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=NKs+8fXhqTJfjVIS1poqWe1vyBspCLp4bXvIsT+t6sM=; b=fMsxPumtXZHfua+/Z+RkRLNzW0 6xLg9V86MTvXecaFQ0IEt6v/BvqFZYom640FJAe+u8sY7h6yIzKGWrI6MC/IocDkmxT90kuxoZs45 5v0AWd4oR0dsiIW3LOe6D63nbyvPPmh/Susd70Mc+PYHA/jNvCaMzgWGs+dlH6mqOkiw=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pgybq-008aTz-AI; Tue, 28 Mar 2023 03:58:50 +0200 Date: Tue, 28 Mar 2023 03:58:50 +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, Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Sean Wang , Landen Chao , DENG Qingfang , Philipp Zabel , Sam Shih , Lorenzo Bianconi , John Crispin , Felix Fietkau Subject: Re: [RFC PATCH net-next 2/2] net: dsa: mt7530: introduce MMIO driver for MT7988 SoC Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 > --- a/drivers/net/dsa/mt7530.c > +++ b/drivers/net/dsa/mt7530.c > @@ -118,6 +118,9 @@ core_write_mmd_indirect(struct mt7530_priv *priv, int prtad, > struct mii_bus *bus = priv->bus; > int ret; > > + if (!bus) > + return 0; > + > /* Write the desired MMD Devad */ > ret = bus->write(bus, 0, MII_MMD_CTRL, devad); > if (ret < 0) > @@ -147,11 +150,13 @@ core_write(struct mt7530_priv *priv, u32 reg, u32 val) > { > struct mii_bus *bus = priv->bus; > > - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); > + if (bus) > + mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); > > core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val); > > - mutex_unlock(&bus->mdio_lock); > + if (bus) > + mutex_unlock(&bus->mdio_lock); > } > > static void > @@ -160,6 +165,9 @@ core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set) > struct mii_bus *bus = priv->bus; > u32 val; > > + if (!bus) > + return; > + > mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); > > val = core_read_mmd_indirect(priv, reg, MDIO_MMD_VEND2); > @@ -189,6 +197,11 @@ mt7530_mii_write(struct mt7530_priv *priv, u32 reg, u32 val) > u16 page, r, lo, hi; > int ret; > > + if (priv->base_addr) { > + iowrite32(val, priv->base_addr + reg); > + return 0; > + } > + > page = (reg >> 6) & 0x3ff; > r = (reg >> 2) & 0xf; > lo = val & 0xffff; > @@ -218,6 +231,9 @@ mt7530_mii_read(struct mt7530_priv *priv, u32 reg) > u16 page, r, lo, hi; > int ret; > > + if (priv->base_addr) > + return ioread32(priv->base_addr + reg); > + > page = (reg >> 6) & 0x3ff; > r = (reg >> 2) & 0xf; > This looks pretty ugly. A much better way to do this is to use regmap. Take a look at xrs700x and how it has both an i2c and an mdio version. Andrew