diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/ethernet/freescale/fsl_pq_mdio.c | 50 |
1 files changed, 34 insertions, 16 deletions
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); } } |