aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeiner Kallweit <hkallweit1@gmail.com>2019-01-19 16:07:34 -0500
committerDavid S. Miller <davem@davemloft.net>2019-01-19 19:09:14 -0500
commitb779daea4aee27d3838a9052e2c3364e28ebaa87 (patch)
treebeed0111bbec18ef81c2299ea4a0e7ada48db8e9
parent703732f0058bd48842aa882217c26a3b3ed30216 (diff)
r8169: factor out getting ether_clk
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>
-rw-r--r--drivers/net/ethernet/realtek/r8169.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 07984f7e3e21..e790a4116f1e 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7155,6 +7155,32 @@ static void rtl_disable_clk(void *data)
7155 clk_disable_unprepare(data); 7155 clk_disable_unprepare(data);
7156} 7156}
7157 7157
7158static int rtl_get_ether_clk(struct rtl8169_private *tp)
7159{
7160 struct device *d = tp_to_dev(tp);
7161 struct clk *clk;
7162 int rc;
7163
7164 clk = devm_clk_get(d, "ether_clk");
7165 if (IS_ERR(clk)) {
7166 rc = PTR_ERR(clk);
7167 if (rc == -ENOENT)
7168 /* clk-core allows NULL (for suspend / resume) */
7169 rc = 0;
7170 else if (rc != -EPROBE_DEFER)
7171 dev_err(d, "failed to get clk: %d\n", rc);
7172 } else {
7173 tp->clk = clk;
7174 rc = clk_prepare_enable(clk);
7175 if (rc)
7176 dev_err(d, "failed to enable clk: %d\n", rc);
7177 else
7178 rc = devm_add_action_or_reset(d, rtl_disable_clk, clk);
7179 }
7180
7181 return rc;
7182}
7183
7158static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 7184static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
7159{ 7185{
7160 const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; 7186 const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data;
@@ -7176,30 +7202,9 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
7176 tp->supports_gmii = cfg->has_gmii; 7202 tp->supports_gmii = cfg->has_gmii;
7177 7203
7178 /* Get the *optional* external "ether_clk" used on some boards */ 7204 /* Get the *optional* external "ether_clk" used on some boards */
7179 tp->clk = devm_clk_get(&pdev->dev, "ether_clk"); 7205 rc = rtl_get_ether_clk(tp);
7180 if (IS_ERR(tp->clk)) { 7206 if (rc)
7181 rc = PTR_ERR(tp->clk); 7207 return rc;
7182 if (rc == -ENOENT) {
7183 /* clk-core allows NULL (for suspend / resume) */
7184 tp->clk = NULL;
7185 } else if (rc == -EPROBE_DEFER) {
7186 return rc;
7187 } else {
7188 dev_err(&pdev->dev, "failed to get clk: %d\n", rc);
7189 return rc;
7190 }
7191 } else {
7192 rc = clk_prepare_enable(tp->clk);
7193 if (rc) {
7194 dev_err(&pdev->dev, "failed to enable clk: %d\n", rc);
7195 return rc;
7196 }
7197
7198 rc = devm_add_action_or_reset(&pdev->dev, rtl_disable_clk,
7199 tp->clk);
7200 if (rc)
7201 return rc;
7202 }
7203 7208
7204 /* enable device (incl. PCI PM wakeup and hotplug setup) */ 7209 /* enable device (incl. PCI PM wakeup and hotplug setup) */
7205 rc = pcim_enable_device(pdev); 7210 rc = pcim_enable_device(pdev);