From patchwork Thu Jun 8 09:26:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 9774355 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 81CB560393 for ; Thu, 8 Jun 2017 10:01:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E56E284A4 for ; Thu, 8 Jun 2017 10:01:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63047284D5; Thu, 8 Jun 2017 10:01:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D6043284A4 for ; Thu, 8 Jun 2017 10:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=T49EHAcBE+wnLuf1zgWq1YMqxDfNmyjqMD2Uyo/y+TY=; b=iN0GvsGbEvItuypyGESsew+YSf Uu2McVlhuk8jmCK/3rChJOp8HM/fI8RAOdINstBS75pn0jDtZA1JKJb0y+Zp1Ocb3Wt4v1pkdmv92 eHoiAyLTfeA7AOAd74lFFrHO7POeNHHpzHiSN4DKI2+TBlbW37/xQPSV34tEckQQ2ScwpD4Glby8Y DHXhlbPRGh7BVNdUk+usOVEhmmlt4D1mgoDu+ShPJ2ileqvZy2dFlnPKrD1lCmUbnO7DsK76Rzxfq tqCljAk9K+eXW9JjzidqaTrBrz7e06uOFIy7U1mLh2h4tv2ya/5At20pUYAjFsEmWejEGTv8Fv8gF SEE7qC2A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dIuFy-0008KW-O9; Thu, 08 Jun 2017 10:01:34 +0000 Received: from mail.free-electrons.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dIuFK-0007NF-Ce for linux-arm-kernel@lists.infradead.org; Thu, 08 Jun 2017 10:01:12 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 0949621DA8; Thu, 8 Jun 2017 12:00:22 +0200 (CEST) Received: from localhost (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 2B53121DA1; Thu, 8 Jun 2017 12:00:03 +0200 (CEST) From: Antoine Tenart To: davem@davemloft.net, jason@lakedaemon.net, andrew@lunn.ch, gregory.clement@free-electrons.com, sebastian.hesselbarth@gmail.com, f.fainelli@gmail.com Subject: [PATCH v2 5/8] net: mvmdio: introduce an ops structure Date: Thu, 8 Jun 2017 11:26:50 +0200 Message-Id: <20170608092653.25221-6-antoine.tenart@free-electrons.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170608092653.25221-1-antoine.tenart@free-electrons.com> References: <20170608092653.25221-1-antoine.tenart@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170608_030055_143011_16DA14DA X-CRM114-Status: GOOD ( 15.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thomas.petazzoni@free-electrons.com, netdev@vger.kernel.org, Antoine Tenart , linux@armlinux.org.uk, mw@semihalf.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce an ops structure to add an indirection on functions accessing the registers. This is needed to add the xMDIO support later. Signed-off-by: Antoine Tenart --- drivers/net/ethernet/marvell/mvmdio.c | 71 ++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c index 6cbdb221c1ab..f66b474b382a 100644 --- a/drivers/net/ethernet/marvell/mvmdio.c +++ b/drivers/net/ethernet/marvell/mvmdio.c @@ -64,6 +64,14 @@ struct orion_mdio_dev { wait_queue_head_t smi_busy_wait; }; +struct orion_mdio_ops { + int (*is_done)(struct orion_mdio_dev *); + int (*is_read_valid)(struct orion_mdio_dev *); + void (*start_read)(struct orion_mdio_dev *, int, int); + u16 (*read)(struct orion_mdio_dev *); + void (*write)(struct orion_mdio_dev *, int, int, u16); +}; + static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev) { return !(readl(dev->regs) & MVMDIO_SMI_BUSY); @@ -74,9 +82,42 @@ static int orion_mdio_smi_is_read_valid(struct orion_mdio_dev *dev) return readl(dev->regs) & MVMDIO_SMI_READ_VALID; } +static void orion_mdio_smi_start_read_op(struct orion_mdio_dev *dev, int mii_id, + int regnum) +{ + writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) | + (regnum << MVMDIO_SMI_PHY_REG_SHIFT) | + MVMDIO_SMI_READ_OPERATION), + dev->regs); +} + +static u16 orion_mdio_smi_read_op(struct orion_mdio_dev *dev) +{ + return readl(dev->regs) & GENMASK(15,0); +} + +static void orion_mdio_smi_write_op(struct orion_mdio_dev *dev, int mii_id, + int regnum, u16 value) +{ + writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) | + (regnum << MVMDIO_SMI_PHY_REG_SHIFT) | + MVMDIO_SMI_WRITE_OPERATION | + (value << MVMDIO_SMI_DATA_SHIFT)), + dev->regs); +} + +static const struct orion_mdio_ops orion_mdio_smi_ops = { + .is_done = orion_mdio_smi_is_done, + .is_read_valid = orion_mdio_smi_is_read_valid, + .start_read = orion_mdio_smi_start_read_op, + .read = orion_mdio_smi_read_op, + .write = orion_mdio_smi_write_op, +}; + /* Wait for the SMI unit to be ready for another operation */ -static int orion_mdio_wait_ready(struct mii_bus *bus) +static int orion_mdio_wait_ready(const struct orion_mdio_ops *ops, + struct mii_bus *bus) { struct orion_mdio_dev *dev = bus->priv; unsigned long timeout = usecs_to_jiffies(MVMDIO_SMI_TIMEOUT); @@ -84,7 +125,7 @@ static int orion_mdio_wait_ready(struct mii_bus *bus) int timedout = 0; while (1) { - if (orion_mdio_smi_is_done(dev)) + if (ops->is_done(dev)) return 0; else if (timedout) break; @@ -103,8 +144,7 @@ static int orion_mdio_wait_ready(struct mii_bus *bus) if (timeout < 2) timeout = 2; wait_event_timeout(dev->smi_busy_wait, - orion_mdio_smi_is_done(dev), - timeout); + ops->is_done(dev), timeout); ++timedout; } @@ -118,30 +158,28 @@ static int orion_mdio_read(struct mii_bus *bus, int mii_id, int regnum) { struct orion_mdio_dev *dev = bus->priv; + const struct orion_mdio_ops *ops = &orion_mdio_smi_ops; int ret; mutex_lock(&dev->lock); - ret = orion_mdio_wait_ready(bus); + ret = orion_mdio_wait_ready(ops, bus); if (ret < 0) goto out; - writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) | - (regnum << MVMDIO_SMI_PHY_REG_SHIFT) | - MVMDIO_SMI_READ_OPERATION), - dev->regs); + ops->start_read(dev, mii_id, regnum); - ret = orion_mdio_wait_ready(bus); + ret = orion_mdio_wait_ready(ops, bus); if (ret < 0) goto out; - if (!orion_mdio_smi_is_read_valid(dev)) { + if (!ops->is_read_valid(dev)) { dev_err(bus->parent, "SMI bus read not valid\n"); ret = -ENODEV; goto out; } - ret = readl(dev->regs) & GENMASK(15,0); + ret = ops->read(dev); out: mutex_unlock(&dev->lock); return ret; @@ -151,19 +189,16 @@ static int orion_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value) { struct orion_mdio_dev *dev = bus->priv; + const struct orion_mdio_ops *ops = &orion_mdio_smi_ops; int ret; mutex_lock(&dev->lock); - ret = orion_mdio_wait_ready(bus); + ret = orion_mdio_wait_ready(ops, bus); if (ret < 0) goto out; - writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) | - (regnum << MVMDIO_SMI_PHY_REG_SHIFT) | - MVMDIO_SMI_WRITE_OPERATION | - (value << MVMDIO_SMI_DATA_SHIFT)), - dev->regs); + ops->write(dev, mii_id, regnum, value); out: mutex_unlock(&dev->lock);