aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKishon Vijay Abraham I2017-01-11 06:06:55 -0600
committerKishon Vijay Abraham I2017-02-15 04:15:29 -0600
commitdb20e3928d19966ff8dba445c19e27c21021cd44 (patch)
treefde3dd08acb466ef965f64b550c1edfd8f3d9cb6
parent293e0787e6a426ca24d5a855d4e197cedfe3892e (diff)
downloadlinux-phy-db20e3928d19966ff8dba445c19e27c21021cd44.tar.gz
linux-phy-db20e3928d19966ff8dba445c19e27c21021cd44.tar.xz
linux-phy-db20e3928d19966ff8dba445c19e27c21021cd44.zip
PCI: dra7xx: Group PHY API invocations
No functional change. PHY APIs like phy_init()/phy_power_on() are invoked from multiple places. Group all the PHY APIs in dra7xx_pcie_enable_phy() and dra7xx_pcie_disable_phy() and use these functions for enabling or disabling the PHY. Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
-rw-r--r--drivers/pci/dwc/pci-dra7xx.c92
1 files changed, 51 insertions, 41 deletions
diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c
index af330d723726..ec5617a0e08c 100644
--- a/drivers/pci/dwc/pci-dra7xx.c
+++ b/drivers/pci/dwc/pci-dra7xx.c
@@ -324,6 +324,45 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
324 return 0; 324 return 0;
325} 325}
326 326
327static void dra7xx_pcie_disable_phy(struct dra7xx_pcie *dra7xx)
328{
329 int phy_count = dra7xx->phy_count;
330
331 while (phy_count--) {
332 phy_power_off(dra7xx->phy[phy_count]);
333 phy_exit(dra7xx->phy[phy_count]);
334 }
335}
336
337static int dra7xx_pcie_enable_phy(struct dra7xx_pcie *dra7xx)
338{
339 int phy_count = dra7xx->phy_count;
340 int ret;
341 int i;
342
343 for (i = 0; i < phy_count; i++) {
344 ret = phy_init(dra7xx->phy[i]);
345 if (ret < 0)
346 goto err_phy;
347
348 ret = phy_power_on(dra7xx->phy[i]);
349 if (ret < 0) {
350 phy_exit(dra7xx->phy[i]);
351 goto err_phy;
352 }
353 }
354
355 return 0;
356
357err_phy:
358 while (--i >= 0) {
359 phy_power_off(dra7xx->phy[i]);
360 phy_exit(dra7xx->phy[i]);
361 }
362
363 return ret;
364}
365
327static int __init dra7xx_pcie_probe(struct platform_device *pdev) 366static int __init dra7xx_pcie_probe(struct platform_device *pdev)
328{ 367{
329 u32 reg; 368 u32 reg;
@@ -382,22 +421,18 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
382 phy[i] = devm_phy_get(dev, name); 421 phy[i] = devm_phy_get(dev, name);
383 if (IS_ERR(phy[i])) 422 if (IS_ERR(phy[i]))
384 return PTR_ERR(phy[i]); 423 return PTR_ERR(phy[i]);
385
386 ret = phy_init(phy[i]);
387 if (ret < 0)
388 goto err_phy;
389
390 ret = phy_power_on(phy[i]);
391 if (ret < 0) {
392 phy_exit(phy[i]);
393 goto err_phy;
394 }
395 } 424 }
396 425
397 dra7xx->base = base; 426 dra7xx->base = base;
398 dra7xx->phy = phy; 427 dra7xx->phy = phy;
399 dra7xx->phy_count = phy_count; 428 dra7xx->phy_count = phy_count;
400 429
430 ret = dra7xx_pcie_enable_phy(dra7xx);
431 if (ret) {
432 dev_err(dev, "failed to enable phy\n");
433 return ret;
434 }
435
401 pm_runtime_enable(dev); 436 pm_runtime_enable(dev);
402 ret = pm_runtime_get_sync(dev); 437 ret = pm_runtime_get_sync(dev);
403 if (ret < 0) { 438 if (ret < 0) {
@@ -432,12 +467,7 @@ err_gpio:
432 467
433err_get_sync: 468err_get_sync:
434 pm_runtime_disable(dev); 469 pm_runtime_disable(dev);
435 470 dra7xx_pcie_disable_phy(dra7xx);
436err_phy:
437 while (--i >= 0) {
438 phy_power_off(phy[i]);
439 phy_exit(phy[i]);
440 }
441 471
442 return ret; 472 return ret;
443} 473}
@@ -474,12 +504,8 @@ static int dra7xx_pcie_resume(struct device *dev)
474static int dra7xx_pcie_suspend_noirq(struct device *dev) 504static int dra7xx_pcie_suspend_noirq(struct device *dev)
475{ 505{
476 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev); 506 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
477 int count = dra7xx->phy_count;
478 507
479 while (count--) { 508 dra7xx_pcie_disable_phy(dra7xx);
480 phy_power_off(dra7xx->phy[count]);
481 phy_exit(dra7xx->phy[count]);
482 }
483 509
484 return 0; 510 return 0;
485} 511}
@@ -487,31 +513,15 @@ static int dra7xx_pcie_suspend_noirq(struct device *dev)
487static int dra7xx_pcie_resume_noirq(struct device *dev) 513static int dra7xx_pcie_resume_noirq(struct device *dev)
488{ 514{
489 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev); 515 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
490 int phy_count = dra7xx->phy_count;
491 int ret; 516 int ret;
492 int i;
493
494 for (i = 0; i < phy_count; i++) {
495 ret = phy_init(dra7xx->phy[i]);
496 if (ret < 0)
497 goto err_phy;
498 517
499 ret = phy_power_on(dra7xx->phy[i]); 518 ret = dra7xx_pcie_enable_phy(dra7xx);
500 if (ret < 0) { 519 if (ret) {
501 phy_exit(dra7xx->phy[i]); 520 dev_err(dev, "failed to enable phy\n");
502 goto err_phy; 521 return ret;
503 }
504 } 522 }
505 523
506 return 0; 524 return 0;
507
508err_phy:
509 while (--i >= 0) {
510 phy_power_off(dra7xx->phy[i]);
511 phy_exit(dra7xx->phy[i]);
512 }
513
514 return ret;
515} 525}
516#endif 526#endif
517 527