From patchwork Mon Jun 20 17:14:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivien Didelot X-Patchwork-Id: 638164 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rYHf16BPVz9ssP for ; Tue, 21 Jun 2016 03:19:21 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933064AbcFTRQK (ORCPT ); Mon, 20 Jun 2016 13:16:10 -0400 Received: from mail.savoirfairelinux.com ([208.88.110.44]:48686 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753647AbcFTRPU (ORCPT ); Mon, 20 Jun 2016 13:15:20 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 3A2F4620F07; Mon, 20 Jun 2016 13:14:27 -0400 (EDT) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id L0vZsLE0ApNH; Mon, 20 Jun 2016 13:14:21 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id EB482620F08; Mon, 20 Jun 2016 13:14:16 -0400 (EDT) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id vfGI1PNIE7jE; Mon, 20 Jun 2016 13:14:16 -0400 (EDT) Received: from ketchup.mtl.sfl (unknown [192.168.48.170]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id A93D9620F07; Mon, 20 Jun 2016 13:14:16 -0400 (EDT) From: Vivien Didelot To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com, "David S. Miller" , Andrew Lunn , Florian Fainelli , Ben Dooks , Sergei Shtylyov , Vivien Didelot Subject: [PATCH v5 net-next v5 10/14] net: dsa: mv88e6xxx: add SMI init helper Date: Mon, 20 Jun 2016 13:14:07 -0400 Message-Id: <20160620171411.13746-11-vivien.didelot@savoirfairelinux.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160620171411.13746-1-vivien.didelot@savoirfairelinux.com> References: <20160620171411.13746-1-vivien.didelot@savoirfairelinux.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add an helper function to isolate SMI specific assignments and checks. This function will later help choosing the different SMI accesses based of the compatible info. Since the chip structure is already allocated in the legacy probe, use the mv88e6xxx_reg_read access routine instead of __mv88e6xxx_reg_read. Signed-off-by: Vivien Didelot Reviewed-by: Andrew Lunn --- drivers/net/dsa/mv88e6xxx.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c index 113092a..4e24ac5 100644 --- a/drivers/net/dsa/mv88e6xxx.c +++ b/drivers/net/dsa/mv88e6xxx.c @@ -3616,6 +3616,19 @@ static struct mv88e6xxx_priv_state *mv88e6xxx_alloc_chip(struct device *dev) return ps; } +static int mv88e6xxx_smi_init(struct mv88e6xxx_priv_state *ps, + struct mii_bus *bus, int sw_addr) +{ + /* ADDR[0] pin is unavailable externally and considered zero */ + if (sw_addr & 0x1) + return -EINVAL; + + ps->bus = bus; + ps->sw_addr = sw_addr; + + return 0; +} + static const char *mv88e6xxx_drv_probe(struct device *dsa_dev, struct device *host_dev, int sw_addr, void **priv) @@ -3635,7 +3648,11 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev, if (!ps) return NULL; - id = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), PORT_SWITCH_ID); + err = mv88e6xxx_smi_init(ps, bus, sw_addr); + if (err) + goto free; + + id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID); if (id < 0) goto free; @@ -3648,8 +3665,6 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev, name = info->name; - ps->bus = bus; - ps->sw_addr = sw_addr; ps->info = info; err = mv88e6xxx_mdio_register(ps, NULL); @@ -3741,8 +3756,9 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) if (!ps) return -ENOMEM; - ps->bus = mdiodev->bus; - ps->sw_addr = mdiodev->addr; + err = mv88e6xxx_smi_init(ps, mdiodev->bus, mdiodev->addr); + if (err) + return err; id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID); if (id < 0)