Skip to content

Commit

Permalink
r8169: factor out getting ether_clk
Browse files Browse the repository at this point in the history
rtl_init_one() is complex enough, so we better factor out getting the
ether_clk.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Heiner Kallweit authored and David S. Miller committed Jan 20, 2019
1 parent 703732f commit b779dae
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions drivers/net/ethernet/realtek/r8169.c
Original file line number Diff line number Diff line change
Expand Up @@ -7155,6 +7155,32 @@ static void rtl_disable_clk(void *data)
clk_disable_unprepare(data);
}

static int rtl_get_ether_clk(struct rtl8169_private *tp)
{
struct device *d = tp_to_dev(tp);
struct clk *clk;
int rc;

clk = devm_clk_get(d, "ether_clk");
if (IS_ERR(clk)) {
rc = PTR_ERR(clk);
if (rc == -ENOENT)
/* clk-core allows NULL (for suspend / resume) */
rc = 0;
else if (rc != -EPROBE_DEFER)
dev_err(d, "failed to get clk: %d\n", rc);
} else {
tp->clk = clk;
rc = clk_prepare_enable(clk);
if (rc)
dev_err(d, "failed to enable clk: %d\n", rc);
else
rc = devm_add_action_or_reset(d, rtl_disable_clk, clk);
}

return rc;
}

static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
{
const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data;
Expand All @@ -7176,30 +7202,9 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
tp->supports_gmii = cfg->has_gmii;

/* Get the *optional* external "ether_clk" used on some boards */
tp->clk = devm_clk_get(&pdev->dev, "ether_clk");
if (IS_ERR(tp->clk)) {
rc = PTR_ERR(tp->clk);
if (rc == -ENOENT) {
/* clk-core allows NULL (for suspend / resume) */
tp->clk = NULL;
} else if (rc == -EPROBE_DEFER) {
return rc;
} else {
dev_err(&pdev->dev, "failed to get clk: %d\n", rc);
return rc;
}
} else {
rc = clk_prepare_enable(tp->clk);
if (rc) {
dev_err(&pdev->dev, "failed to enable clk: %d\n", rc);
return rc;
}

rc = devm_add_action_or_reset(&pdev->dev, rtl_disable_clk,
tp->clk);
if (rc)
return rc;
}
rc = rtl_get_ether_clk(tp);
if (rc)
return rc;

/* enable device (incl. PCI PM wakeup and hotplug setup) */
rc = pcim_enable_device(pdev);
Expand Down

0 comments on commit b779dae

Please sign in to comment.