Received: by 10.213.65.68 with SMTP id h4csp580999imn; Fri, 6 Apr 2018 05:40:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx49uzKQtEbF7bf0AolaZnCfiVc7XKU341k6jIFvFmF6A6QOxM9rSrcjqtCGwUA11qjrTiA3J X-Received: by 10.99.112.70 with SMTP id a6mr17699015pgn.5.1523018433215; Fri, 06 Apr 2018 05:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523018433; cv=none; d=google.com; s=arc-20160816; b=aj6+zcSpkIOqib8p1h0zlsSeYn9ws3n4yhQgXIr2WXnKeLP6Y9ec4bzcdvl6oeRMlP hyeNCsqXhHgkHnyfoogtKYgUMRtPjdDecc4nLM2d9BQt6LzAGXNdbW9mWHKctpbv6oZ8 ajEi5MDGxaXS6PERvpHS8O1y5YXMnSIc/aqIi7ArqSiuFrG8WyhjzhuA12LaAE4K2mng fWJ0QQYdeurg5+rTLDJcARR3geDRwlJk8Ncimvw4Z+tKdW+zZwcIONNAu48k1igjf5W9 8ZobGqO0HiNutPxv1Sf+aihexwmb9Ah4nrZ46b7zSyliDuuV2icFhExnv7DX/zBMIHEC iCtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=/EsJKEJ43VtTTDtzrtUZVHu27XvwmPLu0zg52iPoNYs=; b=v8eTgKq5E4l8qOF6fFoYY9x/IhIiI5EIoV5et75E8/b1CHWrwfwkbjgZauJ0dGpeZg 4TqhQMqi/SnTS4pZSOOfjPK9gcJms+6lzR4e8s2jmitqCdZf555sdFttXRq0wtBhksbu rQmVZto/1sLOPdnAQcCmwLETsL6WiTdKYw5uHQ1ZyXev9Ss9VX3dbf0NTYSMB4baW9/g FSAEKLppaZ9gJEliwz6ryWPqspxGHVLHXagyMjFXlNZ42cP5u3aJvv4GQnYmQWO2hIte qEBs/Wk7zf7q54kVoGe2seEWRmdi8Zag4VvqQyb252GpMFjG3w0mVKOT6m7PxWOojlpO Ftrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=I5du9SNb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u70si7090731pgd.619.2018.04.06.05.40.19; Fri, 06 Apr 2018 05:40:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=I5du9SNb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752571AbeDFMjR (ORCPT + 99 others); Fri, 6 Apr 2018 08:39:17 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:35046 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751579AbeDFMjO (ORCPT ); Fri, 6 Apr 2018 08:39:14 -0400 Received: by mail-lf0-f67.google.com with SMTP id j20-v6so345325lfk.2; Fri, 06 Apr 2018 05:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=/EsJKEJ43VtTTDtzrtUZVHu27XvwmPLu0zg52iPoNYs=; b=I5du9SNbUrmMKf5szl+J2JRp9X4woGufdE4BFog6aObmcKWxpK2XGtd/kSIw7kcGbv ilS7RI6hmVsa0Yvrw+sBkmu+Bj/E8vdk/2bui2HizWx7RO2+6KvbmJICX2J/nhkHoV7A RQ0OgjT9vjMbFOThwg/l2LRBkc1BnhUYYbY1bI3rSIjLFM/W+ndOwfojgfI43BdqZbeS ztKfbEiZE671yHZVEuluh5Rt47GkfSkVV8H2Ug7PgNN5ofnfjx4vKi+mEmbJJjY2A0UM qj95f6e5I5YzSxJoqrZ4OfNMrwZm7psQ53V0EOJLSvDWS5eWNeyXpVi8aSvkFskC9luu +lNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=/EsJKEJ43VtTTDtzrtUZVHu27XvwmPLu0zg52iPoNYs=; b=ZyMV5gmO8uZ0P4LRbE2CaDHfzSzIcZkS+dUBlfO5FkLnXYHXTnKZszNgFuauNcrZlo QC9MN0qf/Z3C3qTfvX9ZOY/UudF+AtQjgmywokxa+ApptiR+tdjddGBmWd7niT/NGwML fgiS41Ue5hWv00IG9geHR5G+rA1+mwD5Dydz/BV3lyle0UeVH5mStL0sMa6bQd3qaz0M xM1kwlzRARJofHLbWhJbmNMmGsdm7E39aoFJR/ZdwPCL3icFiuFzfZwTUGkmdcnvToVr lRJ9QcxAJTmOA3NJtSI/FbWpfqAF4uBPiGuVyJPJE+GZ34M0w/LaofQTHo36yg0rMweU wiZw== X-Gm-Message-State: ALQs6tCzGZDOx3W8u/hjXL9MbrxqEtozXgRsP+x8RgOpjXrxNx9TQ7Q6 KTKs9/qQv3wDdykXrKaI4kCN+QQPqzg= X-Received: by 10.46.134.205 with SMTP id n13mr2763619ljj.115.1523018347578; Fri, 06 Apr 2018 05:39:07 -0700 (PDT) Received: from localhost ([87.54.42.112]) by smtp.gmail.com with ESMTPSA id m18-v6sm2051247lfj.32.2018.04.06.05.39.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 06 Apr 2018 05:39:06 -0700 (PDT) From: Esben Haabendal To: netdev@vger.kernel.org Cc: Esben Haabendal , Claudiu Manoil , Rob Herring , Mark Rutland , "David S. Miller" , "Gustavo A. R. Silva" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] net/fsl_pq_mdio: Allow explicit speficition of TBIPA address Date: Fri, 6 Apr 2018 14:38:34 +0200 Message-Id: <20180406123836.12019-1-esben.haabendal@gmail.com> X-Mailer: git-send-email 2.16.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Esben Haabendal This introduces a simpler and generic method for for finding (and mapping) the TBIPA register. Instead of relying of complicated logic for finding the TBIPA register address based on the MDIO or MII register block base address, which even in some cases relies on undocumented shadow registers, a second "reg" entry for the mdio bus devicetree node specifies the TBIPA register. Backwards compatibility is kept, as the existing logic is applied when only a single "reg" mapping is specified. Signed-off-by: Esben Haabendal --- .../devicetree/bindings/net/fsl-tsec-phy.txt | 6 ++- drivers/net/ethernet/freescale/fsl_pq_mdio.c | 50 +++++++++++++++------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/Documentation/devicetree/bindings/net/fsl-tsec-phy.txt b/Documentation/devicetree/bindings/net/fsl-tsec-phy.txt index 594982c6b9f9..79bf352e659c 100644 --- a/Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +++ b/Documentation/devicetree/bindings/net/fsl-tsec-phy.txt @@ -6,7 +6,11 @@ the definition of the PHY node in booting-without-of.txt for an example of how to define a PHY. Required properties: - - reg : Offset and length of the register set for the device + - reg : Offset and length of the register set for the device, and optionally + the offset and length of the TBIPA register (TBI PHY address + register). If TBIPA register is not specified, the driver will + attempt to infer it from the register set specified (your mileage may + vary). - compatible : Should define the compatible device type for the mdio. Currently supported strings/devices are: - "fsl,gianfar-tbi" diff --git a/drivers/net/ethernet/freescale/fsl_pq_mdio.c b/drivers/net/ethernet/freescale/fsl_pq_mdio.c index 80ad16acf0f1..ac2c3f6a12bc 100644 --- a/drivers/net/ethernet/freescale/fsl_pq_mdio.c +++ b/drivers/net/ethernet/freescale/fsl_pq_mdio.c @@ -377,6 +377,38 @@ static const struct of_device_id fsl_pq_mdio_match[] = { }; MODULE_DEVICE_TABLE(of, fsl_pq_mdio_match); +static void set_tbipa(const u32 tbipa_val, struct platform_device *pdev, + uint32_t __iomem * (*get_tbipa)(void __iomem *), + void __iomem *reg_map, struct resource *reg_res) +{ + struct device_node *np = pdev->dev.of_node; + uint32_t __iomem *tbipa; + bool tbipa_mapped; + + tbipa = of_iomap(np, 1); + if (tbipa) { + tbipa_mapped = true; + } else { + tbipa_mapped = false; + tbipa = (*get_tbipa)(reg_map); + + /* + * Add consistency check to make sure TBI is contained within + * the mapped range (not because we would get a segfault, + * rather to catch bugs in computing TBI address). Print error + * message but continue anyway. + */ + if ((void *)tbipa > reg_map + resource_size(reg_res) - 4) + dev_err(&pdev->dev, "invalid register map (should be at least 0x%04zx to contain TBI address)\n", + ((void *)tbipa - reg_map) + 4); + } + + iowrite32be(be32_to_cpu(tbipa_val), tbipa); + + if (tbipa_mapped) + iounmap(tbipa); +} + static int fsl_pq_mdio_probe(struct platform_device *pdev) { const struct of_device_id *id = @@ -450,8 +482,6 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev) if (tbi) { const u32 *prop = of_get_property(tbi, "reg", NULL); - uint32_t __iomem *tbipa; - if (!prop) { dev_err(&pdev->dev, "missing 'reg' property in node %pOF\n", @@ -459,20 +489,8 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev) err = -EBUSY; goto error; } - - tbipa = data->get_tbipa(priv->map); - - /* - * Add consistency check to make sure TBI is contained - * within the mapped range (not because we would get a - * segfault, rather to catch bugs in computing TBI - * address). Print error message but continue anyway. - */ - if ((void *)tbipa > priv->map + resource_size(&res) - 4) - dev_err(&pdev->dev, "invalid register map (should be at least 0x%04zx to contain TBI address)\n", - ((void *)tbipa - priv->map) + 4); - - iowrite32be(be32_to_cpup(prop), tbipa); + set_tbipa(*prop, pdev, + data->get_tbipa, priv->map, &res); } } -- 2.16.3