+static int ipq_mdio_reset(struct mii_bus *bus)These !IS_ERR() are pretty ugly. So
+{
+ struct ipq4019_mdio_data *priv = bus->priv;
+ u32 val;
+ int ret;
+
+ /* To indicate CMN_PLL that ethernet_ldo has been ready if platform resource 1
+ * is specified in the device tree.
+ * */
+ if (!IS_ERR(priv->eth_ldo_rdy)) {
+ val = readl(priv->eth_ldo_rdy);
+ val |= BIT(0);
+ writel(val, priv->eth_ldo_rdy);
+ fsleep(IPQ_PHY_SET_DELAY_US);
+ }
+
+ /* Configure MDIO clock source frequency if clock is specified in the device tree */
+ if (!IS_ERR_OR_NULL(priv->mdio_clk)) {
+ ret = clk_set_rate(priv->mdio_clk, IPQ_MDIO_CLK_RATE);
+ if (ret)
+ return ret;
+
+ ret = clk_prepare_enable(priv->mdio_clk);
+ if (ret)
+ return ret;
+ }
@@ -182,14 +221,22 @@ static int ipq4019_mdio_probe(struct platform_device *pdev)If this returns an error, it is a real error. You should not ignore
return -ENOMEM;
priv = bus->priv;
+ priv->eth_ldo_rdy = IOMEM_ERR_PTR(-EINVAL);
priv->membase = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(priv->membase))
return PTR_ERR(priv->membase);
+ priv->mdio_clk = devm_clk_get_optional(&pdev->dev, "gcc_mdio_ahb_clk");
it. Fail the probe returning the error. That then means when the reset
function is called priv->mdio_clk contains either a clock, or NULL,
which the clk API is happy to take. No need for an if.
+platform_get_resource() returns a pointer or NULL. There is no error
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+ if (res)
+ priv->eth_ldo_rdy = devm_ioremap_resource(&pdev->dev, res);
code. So
+ if (!IS_ERR(priv->eth_ldo_rdy)) {is actually wrong, should simply become
+ if (priv->eth_ldo_rdy) {Andrew